32 define(
'PCRE_URI',
'(?:([a-z][-+.a-z0-9]*):)?' .
34 '(?:((?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'();:\&=+$,])*)@)?' .
35 '(?:((?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)*[a-z](?:[a-z0-9]+)?\.?)' .
36 '|([0-9]{1,3}(?:\.[0-9]{1,3}){3}))' .
38 '((?:/(?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'():@\&=+$,;])*)*/?)?' .
40 '(?:\#((?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'();/?:@\&=+$,])*))?');
43 define (
'CAMEL_CASE_HEAD_UP', 0x01);
44 define (
'CAMEL_CASE_HEAD_DOWN', 0x02);
55 if (self::hasMBString() && !defined(
'ENABLE_MBSTRING')) {
57 define(
'ENABLE_MBSTRING',
true);
61 mb_internal_encoding($clientCharset);
62 mb_substitute_character(
'63');
67 if (!defined(
'PCRE_UTF8')) {
68 if ($clientCharset ==
'utf-8' && self::hasPCREUTF8()) {
69 define(
'PCRE_UTF8',
'u');
71 define(
'PCRE_UTF8',
'');
82 if (isset($hasMBString))
return $hasMBString;
87 if (ini_get(
'mbstring.func_overload') && defined(
'MB_OVERLOAD_STRING')) {
91 extension_loaded(
'mbstring') &&
92 function_exists(
'mb_strlen') &&
93 function_exists(
'mb_strpos') &&
94 function_exists(
'mb_strrpos') &&
95 function_exists(
'mb_substr') &&
96 function_exists(
'mb_strtolower') &&
97 function_exists(
'mb_strtoupper') &&
98 function_exists(
'mb_substr_count') &&
99 function_exists(
'mb_send_mail')
112 if (@preg_match(
'//u',
'')) {
129 return Stringy\Stringy::create($string)->length();
139 static function strpos($haystack, $needle, $offset = 0) {
140 return Stringy\Stringy::create($haystack)->indexOf($needle, $offset);
150 return Stringy\Stringy::create($haystack)->indexOfLast($needle);
160 static function substr($string, $start, $length =
null) {
161 return (
string) Stringy\Stringy::create($string)->substr($start, $length);
170 return (
string) Stringy\Stringy::create($string)->toLowerCase();
179 return (
string) Stringy\Stringy::create($string)->toUpperCase();
188 return (
string) Stringy\Stringy::create($string)->upperCaseFirst();
198 return Stringy\Stringy::create($haystack)->countSubstring($needle);
207 if (defined(
'ENABLE_MBSTRING')) {
208 return mb_encode_mimeheader($string, mb_internal_encoding(),
'B', MAIL_EOL);
226 return preg_quote($string, $delimiter);
236 return preg_grep($pattern . PCRE_UTF8, $input);
246 return preg_match($pattern . PCRE_UTF8, $subject);
257 return preg_match($pattern . PCRE_UTF8, $subject, $matches);
268 return preg_match_all($pattern . PCRE_UTF8, $subject, $matches);
280 return preg_replace($pattern . PCRE_UTF8, $replacement, $subject, $limit);
292 return preg_replace_callback($pattern . PCRE_UTF8, $callback, $subject, $limit);
303 return preg_split($pattern . PCRE_UTF8, $subject, $limit);
315 if (function_exists(
'finfo_open')) {
318 $fi = finfo_open(FILEINFO_MIME,
Config::getVar(
'finfo',
'mime_database_path'));
321 $result = strtok(finfo_file($fi, $filename),
' ;');
325 if (!$result && function_exists(
'mime_content_type')) {
329 if (($i =
strpos($result,
';')) !==
false) {
330 $result = trim(
substr($result, 0, $i));
336 $f = escapeshellarg($filename);
337 $result = trim(`file --brief --mime $f`);
339 if (($i =
strpos($result,
';')) !==
false) {
340 $result = trim(
substr($result, 0, $i));
345 $exploded = explode(
'.',$filename);
346 $ext = array_pop($exploded);
347 if ($suggestedExtension) {
348 $ext = $suggestedExtension;
351 $ambiguities = array(
352 'html:text/xml' =>
'text/html',
353 'css:text/x-c' =>
'text/css',
354 'css:text/plain' =>
'text/css',
355 'xlsx:application/zip' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
356 'xltx:application/zip' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
357 'potx:application/zip' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
358 'ppsx:application/zip' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
359 'pptx:application/zip' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
360 'sldx:application/zip' =>
'application/vnd.openxmlformats-officedocument.presentationml.slide',
361 'docx:application/zip' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
362 'dotx:application/zip' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
364 if (isset($ambiguities[
strtolower($ext.
':'.$result)])) {
365 $result = $ambiguities[
strtolower($ext.
':'.$result)];
379 if (!isset($purifier)) {
380 $config = HTMLPurifier_Config::createDefault();
381 $config->set(
'Core.Encoding',
Config::getVar(
'i18n',
'client_charset'));
382 $config->set(
'HTML.Doctype',
'HTML 4.01 Transitional');
383 $config->set(
'HTML.Allowed',
Config::getVar(
'security',
'allowed_html'));
384 $config->set(
'Cache.SerializerPath',
'cache');
385 $purifier =
new HTMLPurifier($config);
387 return $purifier->purify($input);
400 $html = html_entity_decode(strip_tags($html), ENT_COMPAT,
'UTF-8');
413 $avoidColonChars = array(
'?',
'!',
'/',
'&');
419 if (in_array(
substr($fields[0], -1, 1), $avoidColonChars)) {
420 $fullTitle = join(
' ', $fields);
422 $fullTitle = join(
': ', $fields);
435 static function camelize($string, $type = CAMEL_CASE_HEAD_UP) {
436 assert($type == CAMEL_CASE_HEAD_UP || $type == CAMEL_CASE_HEAD_DOWN);
439 $string = implode(array_map(
'ucfirst_codesafe', explode(
'-', $string)));
442 if ($type == CAMEL_CASE_HEAD_DOWN) {
456 assert(!empty($string));
464 assert(isset($words[0]) && !empty($words[0]) &&
strlen(implode(
'', $words[0])) ==
strlen($string));
474 return chr(ord(
'A') + $steps);
482 mt_srand((
double)microtime()*10000);
483 $charid =
strtoupper(md5(uniqid(rand(),
true)));
485 $uuid =
substr($charid, 0, 8).$hyphen
486 .substr($charid, 8, 4).$hyphen
487 .
'4'.
substr($charid,13, 3).$hyphen
488 .strtoupper(dechex(hexdec(ord(
substr($charid,16,1))) % 4 + 8)).substr($charid,17, 3).$hyphen
489 .substr($charid,20,12);
556 $datepickerFormat =
"";
559 for ($i = 0; $i <
strlen($phpFormat); $i++) {
560 $char = $phpFormat[$i];
563 $datepickerFormat .= $escaping ? $phpFormat[$i] :
'\'' . $phpFormat[$i];
568 $datepickerFormat .=
"'";
572 $datepickerFormat .= isset($symbols[$char]) ? $symbols[$char] : $char;
577 return $datepickerFormat;