Skip to content
Snippets Groups Projects
Commit fce51c0c authored by Rolando Payán Mosqueda's avatar Rolando Payán Mosqueda Committed by Lachlan Ennis
Browse files

Issue #2572385 by bgilhome, rpayanm: Textarea to add internal paths,...

Issue #2572385 by bgilhome, rpayanm: Textarea to add internal paths, automatically include aliases in processing links
parent 804370ab
No related branches found
No related tags found
No related merge requests found
......@@ -64,8 +64,14 @@ function extlink_page_build(&$page) {
'extImgClass' => variable_get('extlink_img_class', 0),
'extIconPlacement' => variable_get('extlink_icon_placement', 'append'),
'extSubdomains' => variable_get('extlink_subdomains', 1),
'extExclude' => variable_get('extlink_exclude', ''),
'extInclude' => variable_get('extlink_include', ''),
'extExclude' => implode('|', array_filter(array(
variable_get('extlink_exclude', ''),
variable_get('extlink_exclude_internal_pattern', ''),
))),
'extInclude' => implode('|', array_filter(array(
variable_get('extlink_include', ''),
variable_get('extlink_include_internal_pattern', ''),
))),
'extCssExclude' => variable_get('extlink_css_exclude', ''),
'extCssExplicit' => variable_get('extlink_css_explicit', ''),
'extAlert' => variable_get('extlink_alert', 0),
......@@ -208,6 +214,13 @@ function extlink_admin_settings() {
'#description' => t('Enter a regular expression for links that you wish to exclude from being considered external.'),
);
$form['patterns']['extlink_exclude_internal'] = [
'#type' => 'textarea',
'#title' => t('Exclude internal paths'),
'#default_value' => variable_get('extlink_exclude_internal', ''),
'#description' => t('Enter internal paths, one per line, that should be excluded, eg. node/1.'),
];
$form['patterns']['extlink_include'] = array(
'#type' => 'textfield',
'#title' => t('Include links matching the pattern'),
......@@ -216,6 +229,13 @@ function extlink_admin_settings() {
'#description' => t('Enter a regular expression for internal links that you wish to be considered external.'),
);
$form['patterns']['extlink_include_internal'] = [
'#type' => 'textarea',
'#title' => t('Include internal paths'),
'#default_value' => variable_get('extlink_include_internal', ''),
'#description' => t('Enter internal paths, one per line, that should be included, eg. node/1.'),
];
$form['css_matching'] = array(
'#tree' => FALSE,
'#type' => 'fieldset',
......@@ -242,6 +262,8 @@ function extlink_admin_settings() {
'#description' => t('Enter a comma-separated list of CSS selectors (ie "#block-block-2 .content, ul.menu")'),
);
$form['#submit'][] = 'extlink_admin_settings_submit';
return system_settings_form($form);
}
......@@ -270,3 +292,34 @@ function extlink_admin_settings_validate($form, &$form_state) {
}
}
}
function extlink_admin_settings_submit($form, &$form_state) {
// Append internal paths & aliases to exclude/include patterns
foreach (['exclude', 'include'] as $type) {
$internal = $form_state['values']['extlink_' . $type . '_internal'];
if ($internal && $internal != variable_get('extlink_' . $type . '_internal')) {
// Get lines
$internal = array_filter(preg_split("/\r\n|\n|\r/", $internal));
// Add aliases
$internal = array_map(function ($v) {
$v = trim($v, '/ ');
$ret = [
$v,
drupal_lookup_path('alias', $v),
];
return implode('|', array_filter($ret));
}, $internal);
if (!empty($internal)) {
// Implode, add base url & escape slashes
global $base_url;
$internal = $base_url . '/(' . implode('|', array_filter($internal)) . ')';
// $internal = addcslashes($internal, '/');
}
else {
$internal = NULL;
}
variable_set('extlink_' . $type . '_internal_pattern', $internal);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment