Révision 7e72b748
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/ctools/includes/cleanstring.inc | ||
---|---|---|
1 | 1 |
<?php |
2 |
// $Id $ |
|
3 | 2 |
|
4 | 3 |
/** |
5 | 4 |
* @file |
... | ... | |
21 | 20 |
/** |
22 | 21 |
* Matches Unicode character classes. |
23 | 22 |
* |
24 |
* See: http://www.unicode.org/Public/UNIDATA/UCD.html#General_Category_Values |
|
23 |
* See: http://www.unicode.org/Public/UNIDATA/UCD.html#General_Category_Values.
|
|
25 | 24 |
* |
26 | 25 |
* The index only contains the following character classes: |
27 | 26 |
* Lu Letter, Uppercase |
... | ... | |
129 | 128 |
$output = transliteration_get($output); |
130 | 129 |
} |
131 | 130 |
|
132 |
// Reduce to the subset of ASCII96 letters and numbers |
|
131 |
// Reduce to the subset of ASCII96 letters and numbers.
|
|
133 | 132 |
if ($settings['reduce ascii']) { |
134 | 133 |
$pattern = '/[^a-zA-Z0-9\/]+/'; |
135 | 134 |
$output = preg_replace($pattern, $settings['separator'], $output); |
136 | 135 |
} |
137 | 136 |
|
138 |
// Get rid of words that are on the ignore list |
|
137 |
// Get rid of words that are on the ignore list.
|
|
139 | 138 |
if (!empty($settings['ignore words'])) { |
140 | 139 |
$ignore_re = '\b' . preg_replace('/,/', '\b|\b', $settings['ignore words']) . '\b'; |
141 | 140 |
|
... | ... | |
159 | 158 |
else { |
160 | 159 |
$seppattern = '\\' . $settings['separator']; |
161 | 160 |
} |
162 |
// Trim any leading or trailing separators (note the need to |
|
161 |
// Trim any leading or trailing separators (note the need to.
|
|
163 | 162 |
$output = preg_replace("/^$seppattern+|$seppattern+$/", '', $output); |
164 | 163 |
|
165 |
// Replace multiple separators with a single one |
|
164 |
// Replace multiple separators with a single one.
|
|
166 | 165 |
$output = preg_replace("/$seppattern+/", $settings['separator'], $output); |
167 | 166 |
} |
168 | 167 |
|
169 |
// Enforce the maximum component length |
|
168 |
// Enforce the maximum component length.
|
|
170 | 169 |
if (!empty($settings['max length'])) { |
171 | 170 |
$output = ctools_cleanstring_truncate($output, $settings['max length'], $settings['separator']); |
172 | 171 |
} |
... | ... | |
188 | 187 |
* A string which contains the word boundary such as - or _. |
189 | 188 |
* |
190 | 189 |
* @return |
191 |
* The string truncated below the maxlength. |
|
190 |
* The string truncated below the maxlength.
|
|
192 | 191 |
*/ |
193 | 192 |
function ctools_cleanstring_truncate($string, $length, $separator) { |
194 | 193 |
if (drupal_strlen($string) > $length) { |
195 |
$string = drupal_substr($string, 0, $length + 1); // leave one more character |
|
196 |
if ($last_break = strrpos($string, $separator)) { // space exists AND is not on position 0 |
|
194 |
// Leave one more character. |
|
195 |
$string = drupal_substr($string, 0, $length + 1); |
|
196 |
// Space exists AND is not on position 0. |
|
197 |
if ($last_break = strrpos($string, $separator)) { |
|
197 | 198 |
$string = substr($string, 0, $last_break); |
198 | 199 |
} |
199 | 200 |
else { |
Formats disponibles : Unified diff
Weekly update of contrib modules