-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccessibletargetblankfilter.module
More file actions
95 lines (79 loc) · 3.3 KB
/
Copy pathaccessibletargetblankfilter.module
File metadata and controls
95 lines (79 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @file
* Provides the ability for a link tags with target="_blank" to be
* automatically converted to a more accessible format, by alerting users via
* the use of text that the link will open in a new window.
*
* The text to be displayed can be changed via the filter settings form
*/
function accessibletargetblankfilter_init() {
drupal_add_css(drupal_get_path('module', 'accessibletargetblankfilter') . '/accessibletargetblankfilter.css');
drupal_add_js(drupal_get_path('module', 'accessibletargetblankfilter') . '/accessibletargetblankfilter.js', 'module', 'header', TRUE);
}
function accessibletargetblank_getDefaultText() {
return 'This link will open in a new window';
}
/**
* Implementation of hook_filter_tips().
*/
function accessibletargetblankfilter_filter_tips($delta, $format, $long = FALSE) {
$textToAdd = variable_get('accessibletargetblankfilter_texttoadd', accessibletargetblank_getDefaultText());
if ($long) {
return t('Text to be added to the link tag to denote that it will open in a new window. The current text is ' . $textToAdd);
}
else {
return t('Text to be added to the link tag to denote that it will open in a new window. The current text is ' . $textToAdd);
}
}
/**
* Implementation of hook_filter().
*/
function accessibletargetblankfilter_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Accessible Target Blank Filter'));
case 'description':
$textToAdd = variable_get('accessibletargetblankfilter_texttoadd', accessibletargetblank_getDefaultText());
return t('Text to be added to the link tag to denote that it will open in a new window. The current text is ' . $textToAdd);
case 'settings':
return _accessibletargetblankfilter_settings();
case 'process':
$textToAdd = variable_get('accessibletargetblankfilter_texttoadd', accessibletargetblank_getDefaultText());
$pattern = '~<a\s++[^>]*?\btarget\s*+=\s*+([\'"])_blank\1[^>]*+>\K((?:[^<]++|<++(?!/a>))*+)~is';
$text = preg_replace($pattern, "$2<span class=\"linkTargetBlank\">" . $textToAdd . "</span>", $text);
return $text;
default:
return $text;
}
}
/**
* Processes highlight by adding span tag.
*/
/*
function accessibletargetblankfilter_process($text) {
$textToAdd = variable_get('accessibletargetblankfilter_texttoadd', accessibletargetblank_getDefaultText());
return '<span class="linkTargetBlankParent">' . $text . ' </span><span class="linkTargetBlank">(' . $textToAdd . ')</span>';
}
*/
/**
* The settings form for this filter. Default text is set as
* "This link will open in a new window"
*
*/
function _accessibletargetblankfilter_settings() {
$form['accessibletargetblankfilter'] = array(
'#type' => 'fieldset',
'#title' => t('Accessible Target Blank Filter'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['accessibletargetblankfilter']['accessibletargetblankfilter_texttoadd'] = array(
'#title' => t('Text to Add'),
'#description' => t('Text to be added to the link tag to denote that it will open in a new window'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => variable_get('accessibletargetblankfilter_texttoadd', accessibletargetblank_getDefaultText()),
);
return $form;
}