Révision 39a181a4
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/link/views/link_views_handler_filter_protocol.inc | ||
---|---|---|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* Filter handler for limiting a view to URLs of a certain protocol. |
10 |
* |
|
11 |
* @codingStandardsIgnoreStart |
|
10 | 12 |
*/ |
11 | 13 |
class link_views_handler_filter_protocol extends views_handler_filter_string { |
14 |
|
|
12 | 15 |
/** |
13 | 16 |
* Set defaults for the filter options. |
17 |
* |
|
18 |
* @codingStandardsIgnoreEnd |
|
14 | 19 |
*/ |
15 |
function options(&$options) { |
|
16 |
parent::options($options); |
|
20 |
function option_definition() { |
|
21 |
$options = parent::option_definition(); |
|
22 |
|
|
17 | 23 |
$options['operator'] = 'OR'; |
18 | 24 |
$options['value'] = 'http'; |
19 | 25 |
$options['case'] = 0; |
26 |
|
|
27 |
return $options; |
|
20 | 28 |
} |
21 | 29 |
|
22 | 30 |
/** |
23 | 31 |
* Define the operators supported for protocols. |
24 | 32 |
*/ |
25 |
function operators() { |
|
33 |
public function operators() {
|
|
26 | 34 |
$operators = array( |
27 | 35 |
'OR' => array( |
28 | 36 |
'title' => t('Is one of'), |
... | ... | |
35 | 43 |
return $operators; |
36 | 44 |
} |
37 | 45 |
|
38 |
function options_form(&$form, &$form_state) { |
|
46 |
/** |
|
47 |
* Options form. |
|
48 |
* |
|
49 |
* @codingStandardsIgnoreStart |
|
50 |
*/ |
|
51 |
public function options_form(&$form, &$form_state) { |
|
52 |
//@codingStandardsIgnoreEnd |
|
39 | 53 |
parent::options_form($form, $form_state); |
40 | 54 |
$form['case'] = array( |
41 | 55 |
'#type' => 'value', |
... | ... | |
45 | 59 |
|
46 | 60 |
/** |
47 | 61 |
* Provide a select list to choose the desired protocols. |
62 |
* |
|
63 |
* @codingStandardsIgnoreStart |
|
48 | 64 |
*/ |
49 |
function value_form(&$form, &$form_state) { |
|
65 |
public function value_form(&$form, &$form_state) { |
|
66 |
// @codingStandardsIgnoreEnd |
|
50 | 67 |
// We have to make some choices when creating this as an exposed |
51 | 68 |
// filter form. For example, if the operator is locked and thus |
52 | 69 |
// not rendered, we can't render dependencies; instead we only |
... | ... | |
61 | 78 |
'#type' => 'select', |
62 | 79 |
'#title' => t('Protocol'), |
63 | 80 |
'#default_value' => $this->value, |
64 |
'#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'))), |
|
81 |
'#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array( |
|
82 |
'http', |
|
83 |
'https', |
|
84 |
'ftp', |
|
85 |
'news', |
|
86 |
'nntp', |
|
87 |
'telnet', |
|
88 |
'mailto', |
|
89 |
'irc', |
|
90 |
'ssh', |
|
91 |
'sftp', |
|
92 |
'webcal', |
|
93 |
))), |
|
65 | 94 |
'#multiple' => 1, |
66 | 95 |
'#size' => 4, |
67 | 96 |
'#description' => t('The protocols displayed here are those globally available. You may add more protocols by modifying the <em>filter_allowed_protocols</em> variable in your installation.'), |
... | ... | |
71 | 100 |
|
72 | 101 |
/** |
73 | 102 |
* Filter down the query to include only the selected protocols. |
103 |
* |
|
104 |
* @codingStandardsIgnoreStart |
|
74 | 105 |
*/ |
75 |
function op_protocol($field, $upper) { |
|
106 |
public function op_protocol($field, $upper) { |
|
107 |
// @codingStandardsIgnoreEnd |
|
76 | 108 |
$db_type = db_driver(); |
77 | 109 |
|
78 | 110 |
$protocols = $this->value; |
... | ... | |
82 | 114 |
// Simple case, the URL begins with the specified protocol. |
83 | 115 |
$condition = $field . ' LIKE \'' . $protocol . '%\''; |
84 | 116 |
|
85 |
// More complex case, no protocol specified but is automatically cleaned up
|
|
86 |
// by link_cleanup_url(). RegEx is required for this search operation. |
|
117 |
// More complex case, no protocol specified but is automatically cleaned |
|
118 |
// up by link_cleanup_url(). RegEx is required for this search operation.
|
|
87 | 119 |
if ($protocol == 'http') { |
88 |
$LINK_DOMAINS = _link_domains();
|
|
120 |
$link_domains = _link_domains();
|
|
89 | 121 |
if ($db_type == 'pgsql') { |
90 |
// PostGreSQL code has NOT been tested. Please report any problems to the link issue queue. |
|
91 |
// pgSQL requires all slashes to be double escaped in regular expressions. |
|
122 |
// PostGreSQL code has NOT been tested. Please report any problems to |
|
123 |
// the link issue queue. |
|
124 |
// pgSQL requires all slashes to be double escaped in regular |
|
125 |
// expressions. |
|
126 |
// @codingStandardsIgnoreLine |
|
92 | 127 |
// See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP |
93 |
$condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
|
|
128 |
$condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
|
|
94 | 129 |
} |
95 | 130 |
else { |
96 |
// mySQL requires backslashes to be double (triple?) escaped within character classes. |
|
131 |
// mySQL requires backslashes to be double (triple?) escaped within |
|
132 |
// character classes. |
|
133 |
// @codingStandardsIgnoreLine |
|
97 | 134 |
// See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp |
98 |
$condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
|
|
135 |
$condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
|
|
99 | 136 |
} |
100 | 137 |
} |
101 | 138 |
|
... | ... | |
104 | 141 |
|
105 | 142 |
$this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions)); |
106 | 143 |
} |
144 |
|
|
107 | 145 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules