Changeset 696 for trunk/lib/Utilities.inc.php
- Timestamp:
- Aug 8, 2019 10:03:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r690 r696 122 122 $d = ob_get_contents(); 123 123 ob_end_clean(); 124 return $serialize ? preg_replace('/\s+/m ', ' ', $d) : $d;124 return $serialize ? preg_replace('/\s+/mu', ' ', $d) : $d; 125 125 } 126 126 … … 154 154 $output .= sprintf("%s%s\n", $indent_str, $var); 155 155 } 156 return preg_replace(['/^[ \t]+$/ ', '/\n\n+/', '/^(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(\S )/m'], ['', "\n", '$1$1$2$2$3$3$4$4$5$5$6$6$7$7$8$8$9'], $output);156 return preg_replace(['/^[ \t]+$/u', '/\n\n+/u', '/^(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(?:\S( ))?(\S )/mu'], ['', "\n", '$1$1$2$2$3$3$4$4$5$5$6$6$7$7$8$8$9'], $output); 157 157 } 158 158 … … 189 189 190 190 // Make converted ampersand entities into normal ampersands (they will be done manually later) to retain HTML entities. 191 $search['retain_ampersand'] = '/&/ ';191 $search['retain_ampersand'] = '/&/u'; 192 192 $replace['retain_ampersand'] = '&'; 193 193 194 194 if ($preserve_html) { 195 195 // Convert characters that must remain non-entities for displaying HTML. 196 $search['retain_left_angle'] = '/</ ';196 $search['retain_left_angle'] = '/</u'; 197 197 $replace['retain_left_angle'] = '<'; 198 198 199 $search['retain_right_angle'] = '/>/ ';199 $search['retain_right_angle'] = '/>/u'; 200 200 $replace['retain_right_angle'] = '>'; 201 201 202 $search['retain_single_quote'] = '/'/ ';202 $search['retain_single_quote'] = '/'/u'; 203 203 $replace['retain_single_quote'] = "'"; 204 204 205 $search['retain_double_quote'] = '/"/ ';205 $search['retain_double_quote'] = '/"/u'; 206 206 $replace['retain_double_quote'] = '"'; 207 207 } … … 309 309 // If not truncating, or URL was not truncated. 310 310 // Remove http schemas, and any single trailing / to make the display URL. 311 $display_url = preg_replace(['!^https?://! ', '!^([^/]+)/$!'], ['', '$1'], $url);311 $display_url = preg_replace(['!^https?://!u', '!^([^/]+)/$!u'], ['', '$1'], $url); 312 312 return sprintf('<a href="%s">%s</a>', oTxt($absolute_url), $display_url); 313 313 } else { 314 314 // Truncated URL. 315 315 // Remove http schemas, and any single trailing / to make the display URL. 316 $display_url = preg_replace(['!^https?://! ', '!^([^/]+)/$!'], ['', '$1'], trim($truncated_url));316 $display_url = preg_replace(['!^https?://!u', '!^([^/]+)/$!u'], ['', '$1'], trim($truncated_url)); 317 317 return sprintf('<a href="%s">%s%s</a>', oTxt($absolute_url), $display_url, $delim); 318 318 } … … 337 337 foreach ($words as $w) { 338 338 if ('' != trim($w)) { 339 $search[] = '/\b(' . preg_quote($w) . ')\b/i ';339 $search[] = '/\b(' . preg_quote($w) . ')\b/iu'; 340 340 $replace[] = '<span class="' . $class . '">$1</span>'; 341 341 } … … 368 368 default : 369 369 // Reduce all hex values slightly to avoid all white. 370 array_walk($rgb, create_function('&$v', "\$v = dechex(round(hexdec(\$v) * $n));")); 370 array_walk($rgb, function (&$v) use ($n) { 371 $v = dechex(round(hexdec($v) * $n)); 372 }); 371 373 break; 374 372 375 case 2 : 373 376 foreach ($rgb as $i => $v) { … … 411 414 function encodeEmail($email, $at=' at ', $dot=' dot ') 412 415 { 413 $search = array('/@/ ', '/\./');416 $search = array('/@/u', '/\./u'); 414 417 $replace = array($at, $dot); 415 418 return preg_replace($search, $replace, $email); … … 529 532 function URLSlug($str) 530 533 { 531 $slug = preg_replace(array('/\W+/u', '/^-+|-+$/ '), array('-', ''), $str);534 $slug = preg_replace(array('/\W+/u', '/^-+|-+$/u'), array('-', ''), $str); 532 535 $slug = strtolower($slug); 533 536 return $slug; … … 1138 1141 function hash64($string, $length=18) 1139 1142 { 1140 return mb_substr(preg_replace('/[^\w]/ ', '', base64_encode(hash('sha512', $string, true))), 0, $length);1143 return mb_substr(preg_replace('/[^\w]/u', '', base64_encode(hash('sha512', $string, true))), 0, $length); 1141 1144 } 1142 1145 … … 1168 1171 switch ($app->getParam('signing_method')) { 1169 1172 case 'sha512+base64': 1170 return $val . '-' . mb_substr(preg_replace('/[^\w]/ ', '', base64_encode(hash('sha512', $val . $salt, true))), 0, $length);1173 return $val . '-' . mb_substr(preg_replace('/[^\w]/u', '', base64_encode(hash('sha512', $val . $salt, true))), 0, $length); 1171 1174 1172 1175 case 'md5': … … 1395 1398 function stripQuery($url) 1396 1399 { 1397 return preg_replace('/[?#].*$/ ', '', $url);1400 return preg_replace('/[?#].*$/u', '', $url); 1398 1401 } 1399 1402 … … 1405 1408 function absoluteMe() 1406 1409 { 1407 $safe_http_host = preg_replace('/[^a-z\d.:-]/ ', '', getenv('HTTP_HOST'));1410 $safe_http_host = preg_replace('/[^a-z\d.:-]/u', '', getenv('HTTP_HOST')); 1408 1411 return sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host, getenv('REQUEST_URI')); 1409 1412 } … … 1422 1425 // If one of the hostnames is an IP address, compare only the path of both. 1423 1426 if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($current_url, PHP_URL_HOST)) || preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', parse_url($referrer_url, PHP_URL_HOST))) { 1424 $current_url = preg_replace('@^https?://[^/]+@ ', '', $current_url);1425 $referrer_url = preg_replace('@^https?://[^/]+@ ', '', $referrer_url);1427 $current_url = preg_replace('@^https?://[^/]+@u', '', $current_url); 1428 $referrer_url = preg_replace('@^https?://[^/]+@u', '', $referrer_url); 1426 1429 } 1427 1430
Note: See TracChangeset
for help on using the changeset viewer.