1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: |
|
15: |
|
16: | use LucidFrame\Console\Command;
|
17: | use LucidFrame\Console\Console;
|
18: | use LucidFrame\Console\ConsoleTable;
|
19: | use LucidFrame\Core\Middleware;
|
20: | use LucidFrame\Core\Pager;
|
21: | use LucidFrame\File\AsynFileUploader;
|
22: | use LucidFrame\File\File;
|
23: | use LucidFrame\Core\SchemaManager;
|
24: | use LucidFrame\Core\App;
|
25: |
|
26: | |
27: | |
28: | |
29: | |
30: | |
31: |
|
32: | function _app($name, $value = null)
|
33: | {
|
34: | if (count(func_get_args()) == 2) {
|
35: | return App::$$name = $value;
|
36: | } else {
|
37: | return App::$$name;
|
38: | }
|
39: | }
|
40: |
|
41: | |
42: | |
43: | |
44: |
|
45: | function _version()
|
46: | {
|
47: | $findIn = array(LIB, ROOT);
|
48: | foreach ($findIn as $dir) {
|
49: | $versionFile = $dir . 'VERSION';
|
50: | if (is_file($versionFile) && file_exists($versionFile)) {
|
51: | return trim(file_get_contents($versionFile));
|
52: | }
|
53: | }
|
54: |
|
55: | return 'Unknown';
|
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: | function _flush($buffer, $phase)
|
82: | {
|
83: | if (function_exists('__flush')) {
|
84: | $buffer = __flush($buffer, $phase);
|
85: | } else {
|
86: | $posHtml = stripos($buffer, '<html');
|
87: | $posHead = stripos($buffer, '<head');
|
88: |
|
89: | $beforeHtmlTag = substr($buffer, 0, $posHtml);
|
90: | $afterHtmlTag = substr($buffer, $posHead);
|
91: | $htmlTag = trim(str_ireplace($beforeHtmlTag, '', substr($buffer, 0, $posHead)));
|
92: |
|
93: | if (trim($htmlTag)) {
|
94: | $htmlTag = trim(ltrim($htmlTag, '<html.<HTML'), '>. ');
|
95: | $attributes = array();
|
96: | $attrList = explode(' ', $htmlTag);
|
97: | foreach ($attrList as $list) {
|
98: | $attr = explode('=', $list);
|
99: | $attr[0] = trim($attr[0]);
|
100: | if (count($attr) == 2) {
|
101: | $attr[1] = trim($attr[1], '".\'');
|
102: | }
|
103: | $attributes[$attr[0]] = $attr;
|
104: | }
|
105: |
|
106: | $IE = false;
|
107: | $IEVersion = '';
|
108: | $userAgent = $_SERVER['HTTP_USER_AGENT'];
|
109: | if (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident') !== false) {
|
110: | $IE = true;
|
111: | if (preg_match('/(MSIE|rv)\s(\d+)/i', $userAgent, $m)) {
|
112: | $IEVersion = 'ie' . $m[2];
|
113: | }
|
114: | }
|
115: |
|
116: | if (array_key_exists('class', $attributes)) {
|
117: |
|
118: | if ($IE) {
|
119: | $attributes['class'][1] .= ' ie ' . $IEVersion;
|
120: | }
|
121: | if (_multilingual()) {
|
122: | $attributes['class'][1] .= ' ' . _lang();
|
123: | }
|
124: | } else {
|
125: |
|
126: | if ($IE || _multilingual()) {
|
127: | $value = array();
|
128: | if ($IE) {
|
129: | $value[] = 'ie ' . $IEVersion;
|
130: | }
|
131: | if (_multilingual()) {
|
132: | $value[] = _lang();
|
133: | }
|
134: | if (count($value)) {
|
135: | $attributes['class'] = array('class', implode(' ', $value));
|
136: | }
|
137: | }
|
138: | }
|
139: |
|
140: | if (_multilingual()) {
|
141: |
|
142: | if (!array_key_exists('lang', $attributes)) {
|
143: |
|
144: | $attributes['lang'] = array('lang', _lang());
|
145: | }
|
146: | }
|
147: |
|
148: | if (!array_key_exists('itemscope', $attributes)) {
|
149: | $attributes['itemscope'] = array('itemscope');
|
150: | }
|
151: |
|
152: | if (!array_key_exists('itemtype', $attributes)) {
|
153: |
|
154: |
|
155: | $attributes['itemtype'] = array('itemtype', "http://schema.org/WebPage");
|
156: | }
|
157: |
|
158: | ksort($attributes);
|
159: | $html = '<html';
|
160: | foreach ($attributes as $key => $value) {
|
161: | $html .= ' '.$key;
|
162: | if (isset($value[1])) {
|
163: |
|
164: | $html .= '="' . $value[1] . '"';
|
165: | }
|
166: | }
|
167: | $html .= '>' . "\r\n";
|
168: | $buffer = $beforeHtmlTag . $html . $afterHtmlTag;
|
169: | }
|
170: | }
|
171: |
|
172: |
|
173: | $buffer = _minifyHTML($buffer);
|
174: |
|
175: | $posDoc = stripos($buffer, '<!DOCTYPE');
|
176: |
|
177: | return substr($buffer, $posDoc);
|
178: | }
|
179: |
|
180: | |
181: | |
182: | |
183: | |
184: |
|
185: | function _minifyHTML($html)
|
186: | {
|
187: | if (_cfg('minifyHTML')) {
|
188: |
|
189: |
|
190: |
|
191: | return preg_replace(array('/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s'), array('>', '<', '\\1'), $html);
|
192: | }
|
193: |
|
194: | return $html;
|
195: | }
|
196: |
|
197: | |
198: | |
199: | |
200: | |
201: |
|
202: | function _dir($name)
|
203: | {
|
204: | switch($name) {
|
205: | case 'inc':
|
206: | return ROOT . 'inc' . _DS_;
|
207: | case 'db':
|
208: | return ROOT . 'db' . _DS_;
|
209: | case 'lib':
|
210: | return ROOT . 'lib' . _DS_;
|
211: | case 'helper':
|
212: | return ROOT . 'lib' . _DS_ . 'helpers' . _DS_;
|
213: | case 'class':
|
214: | return ROOT . 'lib' . _DS_ . 'classes' . _DS_;
|
215: | case 'i18n':
|
216: | return ROOT . 'i18n' . _DS_;
|
217: | case 'vendor':
|
218: | return ROOT . 'vendor' . _DS_;
|
219: | case 'business':
|
220: | return ROOT . 'business' . _DS_;
|
221: | case 'asset':
|
222: | return ROOT . 'assets' . _DS_;
|
223: | case 'image':
|
224: | return ROOT . 'assets' . _DS_ . 'images' . _DS_;
|
225: | case 'file':
|
226: | return ROOT . 'files' . _DS_;
|
227: | case 'cache':
|
228: | return ROOT . 'files' . _DS_ . 'cache' . _DS_;
|
229: | case 'test':
|
230: | return ROOT . 'tests' . _DS_;
|
231: | }
|
232: |
|
233: | return ROOT;
|
234: | }
|
235: |
|
236: | |
237: | |
238: | |
239: | |
240: | |
241: |
|
242: | function _loader($name, $path = HELPER)
|
243: | {
|
244: | global $lc_autoload;
|
245: |
|
246: | $path = rtrim($path, _DS_) . _DS_;
|
247: |
|
248: | $dir = $path . $name . _DS_;
|
249: | if (is_dir($dir)) {
|
250: |
|
251: | $files = scandir($dir);
|
252: | foreach ($files as $fileName) {
|
253: | $dir = rtrim(rtrim($dir, '/'), '\\');
|
254: | $file = $dir . _DS_ . $fileName;
|
255: |
|
256: | if (!in_array(substr($fileName, -3), array('php', 'inc')) || !is_file($file)) {
|
257: | continue;
|
258: | }
|
259: |
|
260: | if (file_exists($file)) {
|
261: | $lc_autoload[] = $file;
|
262: | }
|
263: | }
|
264: | } else {
|
265: |
|
266: | $name = rtrim($name, '.php');
|
267: | $lc_autoload[] = $path . $name . '.php';
|
268: | }
|
269: |
|
270: | $lc_autoload = array_unique($lc_autoload);
|
271: | }
|
272: |
|
273: | |
274: | |
275: | |
276: | |
277: | |
278: |
|
279: | function _unloader($name, $path = HELPER)
|
280: | {
|
281: | global $lc_autoload;
|
282: |
|
283: | $file = $path . $name . '.php';
|
284: | $key = array_search($file, $lc_autoload);
|
285: | if ($key !== false) {
|
286: | unset($lc_autoload[$key]);
|
287: | $lc_autoload = array_values($lc_autoload);
|
288: | }
|
289: | }
|
290: |
|
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: | |
298: | |
299: |
|
300: | function _readyloader($name, $path = HELPER)
|
301: | {
|
302: | global $lc_autoload;
|
303: |
|
304: | if (stripos($name, '.php') === false) {
|
305: | $file = $path . $name . '.php';
|
306: | } else {
|
307: | $file = $name;
|
308: | }
|
309: |
|
310: | return (array_search($file, $lc_autoload) !== false && is_file($file) && file_exists($file)) ? $file : false;
|
311: | }
|
312: |
|
313: | |
314: | |
315: | |
316: | |
317: | |
318: |
|
319: | function _autoloadDir($dir, $scope = '')
|
320: | {
|
321: | $scope = trim($scope, '/');
|
322: |
|
323: | if (is_dir($dir)) {
|
324: | $files = scandir($dir);
|
325: | foreach ($files as $fileName) {
|
326: | $dir = rtrim(rtrim($dir, '/'), '\\');
|
327: | $file = $dir . _DS_ . $fileName;
|
328: |
|
329: | if (!in_array(substr($fileName, -3), array('php', 'inc')) || !is_file($file)) {
|
330: | continue;
|
331: | }
|
332: |
|
333: | if (file_exists($file) && (empty($scope) || $scope == LC_NAMESPACE)) {
|
334: | require_once $file;
|
335: | }
|
336: | }
|
337: | }
|
338: | }
|
339: |
|
340: | |
341: | |
342: | |
343: | |
344: | |
345: |
|
346: | function _script()
|
347: | {
|
348: | $sitewideWarnings = _cfg('sitewideWarnings');
|
349: | $sites = _cfg('sites');
|
350: | $script = '<script type="text/javascript">';
|
351: | $script .= 'var LC = {};';
|
352: | if (WEB_ROOT) {
|
353: | $script .= 'var WEB_ROOT = "'.WEB_ROOT.'";';
|
354: | $script .= 'LC.root = WEB_ROOT;';
|
355: | }
|
356: | if (WEB_APP_ROOT) {
|
357: | $script .= 'var WEB_APP_ROOT = "'.WEB_APP_ROOT.'";';
|
358: | $script .= 'LC.appRoot = WEB_ROOT;';
|
359: | }
|
360: | $script .= 'LC.self = "'._self().'";';
|
361: | $script .= 'LC.lang = "'._lang().'";';
|
362: | $script .= 'LC.baseURL = "'._cfg('baseURL').'/";';
|
363: | $script .= 'LC.route = "'._r().'";';
|
364: | $script .= 'LC.cleanRoute = "'._cfg('cleanRoute').'";';
|
365: | $script .= 'LC.namespace = "'.LC_NAMESPACE.'";';
|
366: | $script .= 'LC.sites = '.(is_array($sites) && count($sites) ? json_encode($sites) : 'false').';';
|
367: | $script .= 'LC.sitewideWarnings = '.json_encode($sitewideWarnings).';';
|
368: |
|
369: | if (function_exists('__script')) {
|
370: | __script();
|
371: | }
|
372: |
|
373: |
|
374: | $jsVars = _cfg('jsVars');
|
375: | $script .= 'LC.vars = {};';
|
376: | $script .= 'LC.vars.baseDir = "' . _cfg('baseDir') . '";';
|
377: | if (count($jsVars)) {
|
378: | foreach ($jsVars as $name => $val) {
|
379: | if (is_object($val)) {
|
380: | $val = (array) $val;
|
381: | }
|
382: |
|
383: | if (is_array($val)) {
|
384: | $script .= 'LC.vars.'.$name.' = '.json_encode($val).';';
|
385: | } elseif (is_numeric($val)) {
|
386: | $script .= 'LC.vars.'.$name.' = '.$val.';';
|
387: | } else {
|
388: | $script .= 'LC.vars.'.$name.' = "'.$val.'";';
|
389: | }
|
390: | }
|
391: | }
|
392: | $script .= '</script>';
|
393: | echo $script;
|
394: | }
|
395: |
|
396: | |
397: | |
398: | |
399: | |
400: |
|
401: | function _addJsVar($name, $value = '')
|
402: | {
|
403: | global $lc_jsVars;
|
404: | $lc_jsVars[$name] = $value;
|
405: | }
|
406: |
|
407: | |
408: | |
409: | |
410: | |
411: | |
412: | |
413: | |
414: | |
415: | |
416: |
|
417: | function _js($file, $subDir = '', $return = false)
|
418: | {
|
419: | $version = '?v' . _cfg('assetVersion');
|
420: |
|
421: | if (stripos($file, 'http') === 0 || stripos($file, '//') === 0) {
|
422: | $html = '<script src="' . $file . '" type="text/javascript"></script>';
|
423: | if ($return) {
|
424: | return $html;
|
425: | }
|
426: |
|
427: | echo $html;
|
428: | return true;
|
429: | }
|
430: |
|
431: | if ($subDir) {
|
432: | $subDir = trim('assets/' . $subDir, '/') . '/';
|
433: | } else {
|
434: | $subDir = 'assets/js/';
|
435: | }
|
436: |
|
437: | $includeFiles = array();
|
438: | if ($file == 'jquery.ui' || $file == 'jquery-ui') {
|
439: |
|
440: | $file = (stripos($file, '.js') !== false) ? $file : 'jquery-ui.min.js';
|
441: | $includeFiles[] = $subDir . 'vendor/jquery-ui/' . $file;
|
442: | } elseif ($file == 'jquery') {
|
443: |
|
444: | $file = (stripos($file, '.js') !== false) ? $file : 'jquery.min.js';
|
445: | $includeFiles[] = $subDir . 'vendor/jquery/' . $file;
|
446: | } else {
|
447: |
|
448: | $includeFiles[] = $subDir . $file;
|
449: | }
|
450: |
|
451: | foreach ($includeFiles as $includeFile) {
|
452: | $includeFile = _i($includeFile);
|
453: | if (stripos($includeFile, 'http') === 0) {
|
454: | if (stripos($includeFile, WEB_APP_ROOT) === 0) {
|
455: | $fileWithSystemPath = APP_ROOT . str_replace(WEB_APP_ROOT, '', $includeFile);
|
456: | } else {
|
457: | $fileWithSystemPath = ROOT . str_replace(WEB_ROOT, '', $includeFile);
|
458: | }
|
459: | if (file_exists($fileWithSystemPath)) {
|
460: | $html = '<script src="' . $includeFile . $version . '" type="text/javascript"></script>';
|
461: | if ($return) {
|
462: | return $html;
|
463: | }
|
464: |
|
465: | echo $html;
|
466: | return true;
|
467: | }
|
468: | }
|
469: | }
|
470: |
|
471: | return false;
|
472: | }
|
473: |
|
474: | |
475: | |
476: | |
477: | |
478: | |
479: | |
480: | |
481: | |
482: | |
483: |
|
484: | function _css($file, $subDir = '', $return = false)
|
485: | {
|
486: | $version = '?v' . _cfg('assetVersion');
|
487: |
|
488: | if (stripos($file, 'http') === 0 || stripos($file, '//') === 0) {
|
489: | $html = '<link href="' . $file . '" rel="stylesheet" type="text/css" />';
|
490: | if ($return) {
|
491: | return $html;
|
492: | }
|
493: |
|
494: | echo $html;
|
495: | return true;
|
496: | }
|
497: |
|
498: | if ($subDir) {
|
499: | $subDir = trim('assets/' . $subDir, '/') . '/';
|
500: | } else {
|
501: | $subDir = 'assets/css/';
|
502: | }
|
503: |
|
504: | $includeFiles = array();
|
505: | if ($file == 'jquery.ui' || $file == 'jquery-ui') {
|
506: |
|
507: | $includeFiles[] = 'assets/js/vendor/jquery-ui/jquery-ui.min.css';
|
508: | } else {
|
509: |
|
510: | $includeFiles[] = $subDir . $file;
|
511: | }
|
512: |
|
513: | foreach ($includeFiles as $includeFile) {
|
514: | $includeFile = _i($includeFile);
|
515: | if (stripos($includeFile, 'http') === 0) {
|
516: | if (stripos($includeFile, WEB_APP_ROOT) === 0) {
|
517: | $fileWithSystemPath = APP_ROOT . str_replace(WEB_APP_ROOT, '', $includeFile);
|
518: | } else {
|
519: | $fileWithSystemPath = ROOT . str_replace(WEB_ROOT, '', $includeFile);
|
520: | }
|
521: |
|
522: | if (file_exists($fileWithSystemPath)) {
|
523: | $html = '<link href="' . $includeFile . $version . '" rel="stylesheet" type="text/css" />';
|
524: | if ($return) {
|
525: | return $html;
|
526: | }
|
527: |
|
528: | echo $html;
|
529: | return true;
|
530: | }
|
531: | }
|
532: | }
|
533: |
|
534: | return false;
|
535: | }
|
536: |
|
537: | |
538: | |
539: | |
540: | |
541: | |
542: |
|
543: | function _img($file)
|
544: | {
|
545: | $fileWithPath = 'assets/images/' . $file;
|
546: | $fileWithPath = _i($fileWithPath);
|
547: |
|
548: | if (empty($fileWithPath)) {
|
549: | return '';
|
550: | }
|
551: |
|
552: | if (stripos($fileWithPath, APP_ROOT) === 0) {
|
553: | return WEB_APP_ROOT . str_replace(APP_ROOT, '', $fileWithPath);
|
554: | } else {
|
555: | return WEB_ROOT . str_replace(ROOT, '', $fileWithPath);
|
556: | }
|
557: | }
|
558: |
|
559: | if (!function_exists('_image')) {
|
560: | |
561: | |
562: | |
563: | |
564: | |
565: | |
566: | |
567: | |
568: | |
569: | |
570: | |
571: | |
572: | |
573: | |
574: |
|
575: | function _image($file, $caption = '', $dimension = '0x0', array $attributes = array())
|
576: | {
|
577: | $directory = array(
|
578: | 'images' => IMAGE,
|
579: | 'files' => FILE,
|
580: | );
|
581: |
|
582: | foreach ($directory as $dir => $path) {
|
583: | $image = $path . $file;
|
584: | if (is_file($image) && file_exists($image)) {
|
585: | list($width, $height) = getimagesize($image);
|
586: | if (strpos($path, 'assets') !== false) {
|
587: | $dir = 'assets/images';
|
588: | }
|
589: | break;
|
590: | }
|
591: | }
|
592: | if (isset($width) && isset($height)) {
|
593: |
|
594: | $image = WEB_ROOT . $dir . '/' . $file;
|
595: | echo File::img($image, $caption, $width.'x'.$height, $dimension, $attributes);
|
596: | } else {
|
597: |
|
598: | echo '<div class="image404" align="center">';
|
599: | echo function_exists('_t') ? _t('No Image') : 'No Image';
|
600: | echo '</div>';
|
601: | }
|
602: | }
|
603: | }
|
604: |
|
605: | if (!function_exists('_pr')) {
|
606: | |
607: | |
608: | |
609: | |
610: | |
611: | |
612: | |
613: | |
614: | |
615: | |
616: |
|
617: | function _pr($input, $pre = true)
|
618: | {
|
619: | if ($pre) {
|
620: | echo '<pre>';
|
621: | }
|
622: | if (is_array($input) || is_object($input)) {
|
623: | print_r($input);
|
624: | } else {
|
625: | if (is_bool($input)) {
|
626: | var_dump($input);
|
627: | } else {
|
628: | echo $input;
|
629: | }
|
630: | if ($pre == false) {
|
631: | echo '<br>';
|
632: | }
|
633: | }
|
634: | if ($pre) {
|
635: | echo '</pre>';
|
636: | }
|
637: | }
|
638: | }
|
639: |
|
640: | if (!function_exists('_dpr')) {
|
641: | |
642: | |
643: | |
644: | |
645: | |
646: | |
647: | |
648: | |
649: | |
650: | |
651: |
|
652: | function _dpr($input, $pre = true)
|
653: | {
|
654: | _pr($input);
|
655: | exit;
|
656: | }
|
657: | }
|
658: |
|
659: | if (!function_exists('_dump')) {
|
660: | |
661: | |
662: | |
663: | |
664: | |
665: | |
666: | |
667: | |
668: |
|
669: | function _dump($input, $pre = true)
|
670: | {
|
671: | if ($pre) {
|
672: | echo '<pre>';
|
673: | }
|
674: | var_dump($input);
|
675: | if ($pre) {
|
676: | echo '</pre>';
|
677: | }
|
678: | }
|
679: | }
|
680: |
|
681: | |
682: | |
683: | |
684: | |
685: | |
686: | |
687: |
|
688: | function _g($key, $value = '')
|
689: | {
|
690: | if (empty($key)) {
|
691: | return null;
|
692: | }
|
693: |
|
694: | if (count(func_get_args()) == 2) {
|
695: | return __dotNotationToArray($key, 'global', $value);
|
696: | } else {
|
697: | return __dotNotationToArray($key);
|
698: | }
|
699: | }
|
700: |
|
701: | |
702: | |
703: | |
704: | |
705: | |
706: |
|
707: | function _h($string)
|
708: | {
|
709: | if (empty($string)) {
|
710: | return $string;
|
711: | }
|
712: |
|
713: | $string = stripslashes($string);
|
714: | $string = htmlspecialchars_decode($string, ENT_QUOTES);
|
715: |
|
716: | return htmlspecialchars($string, ENT_QUOTES);
|
717: | }
|
718: |
|
719: | |
720: | |
721: | |
722: |
|
723: | function _lang()
|
724: | {
|
725: | return _cfg('lang');
|
726: | }
|
727: |
|
728: | |
729: | |
730: | |
731: | |
732: | |
733: | |
734: | |
735: |
|
736: | function _getLang()
|
737: | {
|
738: | if (function_exists('__getLang')) {
|
739: | return __getLang();
|
740: | }
|
741: |
|
742: | $lang = (_arg('lang')) ? _arg('lang') : _defaultLang();
|
743: |
|
744: | return ($lang) ? $lang : _defaultLang();
|
745: | }
|
746: |
|
747: | |
748: | |
749: | |
750: |
|
751: | function _defaultLang()
|
752: | {
|
753: | return _cfg('defaultLang');
|
754: | }
|
755: |
|
756: | |
757: | |
758: | |
759: | |
760: |
|
761: | function _langs($excepts = null)
|
762: | {
|
763: | global $lc_languages;
|
764: |
|
765: | $langs = array();
|
766: | if ($excepts) {
|
767: | foreach ($lc_languages as $lcode => $lname) {
|
768: | if (is_array($excepts) && in_array($lcode, $excepts)) {
|
769: | continue;
|
770: | }
|
771: | if (is_string($excepts) && $lcode == $excepts) {
|
772: | continue;
|
773: | }
|
774: | $langs[$lcode] = $lname;
|
775: | }
|
776: | } else {
|
777: | $langs = $lc_languages;
|
778: | }
|
779: |
|
780: | return count($langs) ? $langs : false;
|
781: | }
|
782: |
|
783: | |
784: | |
785: | |
786: | |
787: |
|
788: | function _queryLang($lang = null)
|
789: | {
|
790: | if (!$lang) {
|
791: | $lang = _cfg('lang');;
|
792: | }
|
793: |
|
794: | return str_replace('-', '_', $lang);
|
795: | }
|
796: |
|
797: | |
798: | |
799: | |
800: | |
801: |
|
802: | function _urlLang($lang = null)
|
803: | {
|
804: | if (!$lang) {
|
805: | $lang = _cfg('lang');
|
806: | }
|
807: |
|
808: | return str_replace('_', '-', $lang);
|
809: | }
|
810: |
|
811: | |
812: | |
813: | |
814: |
|
815: | function _defaultQueryLang()
|
816: | {
|
817: | return str_replace('-', '_', _cfg('defaultLang'));
|
818: | }
|
819: |
|
820: | |
821: | |
822: | |
823: | |
824: | |
825: | |
826: | |
827: | |
828: |
|
829: | function _langName($lang = '')
|
830: | {
|
831: | if (!_multilingual()) {
|
832: | return '';
|
833: | }
|
834: |
|
835: | global $lc_languages;
|
836: | $lang = str_replace('_', '-', $lang);
|
837: |
|
838: | if (isset($lc_languages[$lang])) {
|
839: | return $lc_languages[$lang];
|
840: | } else {
|
841: | return $lc_languages[_cfg('defaultLang')];
|
842: | }
|
843: | }
|
844: |
|
845: | |
846: | |
847: | |
848: |
|
849: | function _multilingual()
|
850: | {
|
851: | if (_cfg('languages')) {
|
852: | return (count(_cfg('languages')) > 1) ? true : false;
|
853: | } else {
|
854: | return false;
|
855: | }
|
856: | }
|
857: |
|
858: | |
859: | |
860: | |
861: | |
862: | |
863: |
|
864: | function _protocol()
|
865: | {
|
866: | $protocol = current(explode('/', $_SERVER['SERVER_PROTOCOL']));
|
867: |
|
868: | return strtolower($protocol);
|
869: | }
|
870: |
|
871: | |
872: | |
873: | |
874: | |
875: |
|
876: | function _ssl()
|
877: | {
|
878: | return _cfg('ssl');
|
879: | }
|
880: |
|
881: | |
882: | |
883: | |
884: | |
885: | |
886: | |
887: | |
888: | |
889: | |
890: |
|
891: | function _r()
|
892: | {
|
893: | return route_path();
|
894: | }
|
895: |
|
896: | |
897: | |
898: | |
899: | |
900: | |
901: | |
902: | |
903: | |
904: | |
905: | |
906: |
|
907: | function _rr()
|
908: | {
|
909: | if (!_isRewriteRule()) {
|
910: | return _r();
|
911: | }
|
912: |
|
913: | $uri = REQUEST_URI;
|
914: | if (strpos($uri, '?') !== false) {
|
915: | $uri = substr($uri, 0, strpos($uri, '?'));
|
916: | }
|
917: |
|
918: | return $uri;
|
919: | }
|
920: |
|
921: | |
922: | |
923: | |
924: | |
925: |
|
926: | function _cr()
|
927: | {
|
928: | return _cfg('cleanRoute');
|
929: | }
|
930: |
|
931: | |
932: | |
933: | |
934: | |
935: | |
936: | |
937: | |
938: | |
939: | |
940: | |
941: | |
942: | |
943: | |
944: | |
945: |
|
946: | function _url($path = null, $queryStr = array(), $lang = '')
|
947: | {
|
948: | return route_url($path, $queryStr, $lang);
|
949: | }
|
950: |
|
951: | |
952: | |
953: | |
954: | |
955: | |
956: | |
957: | |
958: | |
959: | |
960: | |
961: | |
962: | |
963: | |
964: |
|
965: | function _self($queryStr = array(), $lang = '')
|
966: | {
|
967: | return route_url(null, $queryStr, $lang);
|
968: | }
|
969: |
|
970: | |
971: | |
972: | |
973: | |
974: | |
975: |
|
976: | function _header($status, $message = null)
|
977: | {
|
978: | _g('httpStatusCode', $status);
|
979: |
|
980: | if (PHP_SAPI != 'cli' && _cfg('env') != ENV_TEST && __env() != ENV_TEST) {
|
981: | header('HTTP/1.1 ' . $status . ($message ? ' ' . $message : ''));
|
982: | }
|
983: | }
|
984: |
|
985: | |
986: | |
987: | |
988: | |
989: | |
990: | |
991: | |
992: | |
993: | |
994: | |
995: | |
996: | |
997: | |
998: | |
999: | |
1000: | |
1001: |
|
1002: | function _redirect($path = null, $queryStr = array(), $lang = '', $status = null)
|
1003: | {
|
1004: | if (stripos($path, 'http') === 0) {
|
1005: | if ($status === 301) {
|
1006: | _header(301, 'Moved Permanently');
|
1007: | }
|
1008: | header('Location: ' . $path);
|
1009: | exit;
|
1010: | }
|
1011: |
|
1012: | if ($path == 'self') {
|
1013: | $url = _self(null, $lang);
|
1014: | } else {
|
1015: | $url = route_url($path, $queryStr, $lang);
|
1016: | }
|
1017: |
|
1018: | if ($status === 301) {
|
1019: | _header(301, 'Moved Permanently');
|
1020: | }
|
1021: |
|
1022: | header('Location: ' . $url);
|
1023: | exit;
|
1024: | }
|
1025: |
|
1026: | |
1027: | |
1028: | |
1029: | |
1030: | |
1031: | |
1032: | |
1033: | |
1034: | |
1035: | |
1036: | |
1037: | |
1038: | |
1039: | |
1040: |
|
1041: | function _redirect301($path = null, $queryStr = array(), $lang = '')
|
1042: | {
|
1043: | _redirect($path, $queryStr, $lang, 301);
|
1044: | }
|
1045: |
|
1046: | |
1047: | |
1048: | |
1049: | |
1050: |
|
1051: | function _page401($message = '')
|
1052: | {
|
1053: | $message = $message ?: _t('Access Denied');
|
1054: |
|
1055: | if (_isContentType('application/json')) {
|
1056: | _jsonError($message, '', 401);
|
1057: | }
|
1058: |
|
1059: | _cfg('layoutMode', true);
|
1060: | include(INC . 'tpl/401.php');
|
1061: | exit;
|
1062: | }
|
1063: |
|
1064: | |
1065: | |
1066: | |
1067: | |
1068: |
|
1069: | function _page403($message = '')
|
1070: | {
|
1071: | $message = $message ?: _t('403 Forbidden');
|
1072: |
|
1073: | if (_isContentType('application/json')) {
|
1074: | _jsonError($message, '', 403);
|
1075: | }
|
1076: |
|
1077: | _cfg('layoutMode', true);
|
1078: | include(INC . 'tpl/403.php');
|
1079: | exit;
|
1080: | }
|
1081: |
|
1082: | |
1083: | |
1084: | |
1085: | |
1086: | |
1087: |
|
1088: | function _page404($message = '', $entity = '')
|
1089: | {
|
1090: | $message = $message ?: _t('404 Not Found');
|
1091: |
|
1092: | if (_isContentType('application/json')) {
|
1093: | _jsonError($message, $entity, 404);
|
1094: | }
|
1095: |
|
1096: | _cfg('layoutMode', true);
|
1097: | include(INC . 'tpl/404.php');
|
1098: | exit;
|
1099: | }
|
1100: |
|
1101: | |
1102: | |
1103: | |
1104: | |
1105: | |
1106: | |
1107: |
|
1108: | function _error($message, $code, $status = 500)
|
1109: | {
|
1110: | if (_isContentType('application/json')) {
|
1111: | _json(['error' => $message], $status);
|
1112: | }
|
1113: |
|
1114: | _cfg('layoutMode', true);
|
1115: | _g('httpStatusCode', $status);
|
1116: | $type = __kernelErrorTypes($code);
|
1117: |
|
1118: | _header($status);
|
1119: |
|
1120: | include(INC . 'tpl/exception.php');
|
1121: | exit;
|
1122: | }
|
1123: |
|
1124: | |
1125: | |
1126: | |
1127: |
|
1128: | function _isRewriteRule()
|
1129: | {
|
1130: | return (strcasecmp(REQUEST_URI, _r()) !== 0) ? true : false;
|
1131: | }
|
1132: |
|
1133: | |
1134: | |
1135: | |
1136: | |
1137: |
|
1138: | function _canonical($url = null)
|
1139: | {
|
1140: | global $lc_canonical;
|
1141: | if (!is_null($url)) {
|
1142: | $lc_canonical = $url;
|
1143: | } else {
|
1144: | return (_cfg('canonical')) ? _cfg('canonical') : _url();
|
1145: | }
|
1146: | }
|
1147: |
|
1148: | |
1149: | |
1150: | |
1151: |
|
1152: | function _hreflang()
|
1153: | {
|
1154: | global $lc_languages;
|
1155: | if (_multilingual()) {
|
1156: | foreach ($lc_languages as $hrefLang => $langDesc) {
|
1157: | if (_canonical() == _url()) {
|
1158: | $alternate = _url('', null, $hrefLang);
|
1159: | $xdefault = _url('', null, false);
|
1160: | } else {
|
1161: | $alternate = preg_replace('/\/'._lang().'\b/', '/'.$hrefLang, _canonical());
|
1162: | $xdefault = preg_replace('/\/'._lang().'\b/', '', _canonical());
|
1163: | }
|
1164: | echo '<link rel="alternate" hreflang="'.$hrefLang.'" href="'.$alternate.'" />'."\n";
|
1165: | }
|
1166: | echo '<link rel="alternate" hreflang="x-default" href="'.$xdefault.'" />'."\n";
|
1167: | }
|
1168: | }
|
1169: |
|
1170: | |
1171: | |
1172: | |
1173: | |
1174: | |
1175: | |
1176: | |
1177: | |
1178: | |
1179: | |
1180: |
|
1181: | function _getLangInURI()
|
1182: | {
|
1183: | global $lc_languages;
|
1184: |
|
1185: | if (!isset($_SERVER['REQUEST_URI'])) {
|
1186: | return false;
|
1187: | }
|
1188: |
|
1189: | if (!is_array($lc_languages)) {
|
1190: | $lc_languages = array('en' => 'English');
|
1191: | }
|
1192: |
|
1193: | $baseURL = trim(_cfg('baseURL'), '/');
|
1194: | $baseURL = ($baseURL) ? "/$baseURL/" : '/';
|
1195: | $baseURL = str_replace('/', '\/', $baseURL);
|
1196: | $baseURL = str_replace('.', '\.', $baseURL);
|
1197: | $regex = '/^('.$baseURL.')\b('.implode('|', array_keys($lc_languages)).'){1}\b(\/?)/i';
|
1198: |
|
1199: | if (preg_match($regex, $_SERVER['REQUEST_URI'], $matches)) {
|
1200: | return $matches[2];
|
1201: | }
|
1202: |
|
1203: | return false;
|
1204: | }
|
1205: |
|
1206: | |
1207: | |
1208: | |
1209: | |
1210: | |
1211: |
|
1212: | function _validHost($host)
|
1213: | {
|
1214: | return preg_match('/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host);
|
1215: | }
|
1216: |
|
1217: | |
1218: | |
1219: | |
1220: | |
1221: | |
1222: |
|
1223: | function _title()
|
1224: | {
|
1225: | global $lc_siteName;
|
1226: | global $lc_titleSeparator;
|
1227: |
|
1228: | $args = func_get_args();
|
1229: |
|
1230: | if (count($args) == 0) {
|
1231: | $title = _app('title');
|
1232: | if (is_array($title)) {
|
1233: | $args = $title;
|
1234: | }
|
1235: |
|
1236: | if (is_string($title)) {
|
1237: | $args = array($title);
|
1238: | }
|
1239: | }
|
1240: |
|
1241: | if (count($args) == 0) {
|
1242: | return $lc_siteName;
|
1243: | }
|
1244: |
|
1245: | if (count($args) == 1) {
|
1246: | if (is_array($args[0])) {
|
1247: | $args = _filterArrayEmpty($args[0]);
|
1248: | $title = $args;
|
1249: | } else {
|
1250: | $title = ($args[0]) ? array($args[0]) : array();
|
1251: | }
|
1252: | } else {
|
1253: | $args = _filterArrayEmpty($args);
|
1254: | $title = $args;
|
1255: | }
|
1256: |
|
1257: | $lc_titleSeparator = trim($lc_titleSeparator);
|
1258: | if ($lc_titleSeparator) {
|
1259: | $lc_titleSeparator = ' '.$lc_titleSeparator.' ';
|
1260: | } else {
|
1261: | $lc_titleSeparator = ' ';
|
1262: | }
|
1263: |
|
1264: | if (count($title)) {
|
1265: | $title = implode($lc_titleSeparator, $title);
|
1266: | if ($lc_siteName) {
|
1267: | $title .= ' | '.$lc_siteName;
|
1268: | }
|
1269: | return $title;
|
1270: | }
|
1271: |
|
1272: | return $lc_siteName;
|
1273: | }
|
1274: |
|
1275: | |
1276: | |
1277: | |
1278: | |
1279: | |
1280: |
|
1281: | function _filterArrayEmpty($input)
|
1282: | {
|
1283: | return array_filter($input, '_notEmpty');
|
1284: | }
|
1285: |
|
1286: | |
1287: | |
1288: | |
1289: | |
1290: | |
1291: |
|
1292: | function _notEmpty($value)
|
1293: | {
|
1294: | return trim($value) !== '';
|
1295: | }
|
1296: |
|
1297: | |
1298: | |
1299: | |
1300: | |
1301: | |
1302: |
|
1303: | function _breadcrumb()
|
1304: | {
|
1305: | global $lc_breadcrumbSeparator;
|
1306: |
|
1307: | $args = func_get_args();
|
1308: |
|
1309: | if (!$lc_breadcrumbSeparator) {
|
1310: | $lc_breadcrumbSeparator = '»';
|
1311: | }
|
1312: |
|
1313: | if (count($args) == 1 && is_array($args[0])) {
|
1314: | $args = $args[0];
|
1315: | }
|
1316: |
|
1317: | echo implode(" {$lc_breadcrumbSeparator} ", $args);
|
1318: | }
|
1319: |
|
1320: | |
1321: | |
1322: | |
1323: | |
1324: | |
1325: | |
1326: | |
1327: | |
1328: |
|
1329: | function _shorten($str, $length = 50, $trail = '...')
|
1330: | {
|
1331: | if (empty($str)) {
|
1332: | return $str;
|
1333: | }
|
1334: |
|
1335: | $str = strip_tags(trim($str));
|
1336: | if (strlen($str) <= $length) {
|
1337: | return $str;
|
1338: | }
|
1339: |
|
1340: | $short = trim(substr($str, 0, $length));
|
1341: | $lastSpacePos = strrpos($short, ' ');
|
1342: | if ($lastSpacePos !== false) {
|
1343: | $short = substr($short, 0, $lastSpacePos);
|
1344: | }
|
1345: |
|
1346: | if ($trail) {
|
1347: | $short = rtrim($short, '.') . $trail;
|
1348: | }
|
1349: |
|
1350: | return $short;
|
1351: | }
|
1352: |
|
1353: | if (!function_exists('_fstr')) {
|
1354: | |
1355: | |
1356: | |
1357: | |
1358: | |
1359: | |
1360: | |
1361: | |
1362: |
|
1363: | function _fstr($value, $glue = ', ', $lastGlue = 'and')
|
1364: | {
|
1365: | if (empty($value)) {
|
1366: | return $value;
|
1367: | }
|
1368: |
|
1369: | if (!is_array($value)) {
|
1370: | return $value == '' ? _nullFill($value) : nl2br($value);
|
1371: | } elseif (is_array($value) && sizeof($value) > 1) {
|
1372: | $last = array_slice($value, -2, 2);
|
1373: | $lastImplode = implode(' '.$lastGlue.' ', $last);
|
1374: | $first = array_slice($value, 0, sizeof($value)-2);
|
1375: | $firstImplode = implode($glue, $first);
|
1376: |
|
1377: | return $firstImplode ? $firstImplode.$glue.$lastImplode : $lastImplode;
|
1378: | } else {
|
1379: | return nl2br($value[0]);
|
1380: | }
|
1381: | }
|
1382: | }
|
1383: |
|
1384: | if (!function_exists('_fnum')) {
|
1385: | |
1386: | |
1387: | |
1388: | |
1389: | |
1390: | |
1391: | |
1392: | |
1393: |
|
1394: | function _fnum($value, $decimals = 2, $unit = '')
|
1395: | {
|
1396: | if ($value === '') {
|
1397: | return _nullFill($value);
|
1398: | } elseif (is_numeric($value)) {
|
1399: | $value = number_format($value, $decimals, '.', ',');
|
1400: |
|
1401: | return $unit ? $value . ' ' . $unit : $value;
|
1402: | }
|
1403: |
|
1404: | return $value;
|
1405: | }
|
1406: | }
|
1407: |
|
1408: | if (!function_exists('_fnumSmart')) {
|
1409: | |
1410: | |
1411: | |
1412: | |
1413: | |
1414: | |
1415: | |
1416: | |
1417: | |
1418: |
|
1419: | function _fnumSmart($value, $decimals = 2, $unit = '')
|
1420: | {
|
1421: | $value = _fnum($value, $decimals, $unit);
|
1422: | $v = explode('.', $value);
|
1423: | if ($decimals > 0 && isset($v[1])) {
|
1424: | if (preg_match('/0{'.$decimals.'}/i', $v[1])) {
|
1425: | $value = $v[0];
|
1426: | }
|
1427: | }
|
1428: |
|
1429: | return $value;
|
1430: | }
|
1431: | }
|
1432: |
|
1433: | if (!function_exists('_fnumReverse')) {
|
1434: | |
1435: | |
1436: | |
1437: | |
1438: | |
1439: |
|
1440: | function _fnumReverse($num)
|
1441: | {
|
1442: | return str_replace(',', '', $num);
|
1443: | }
|
1444: | }
|
1445: |
|
1446: | if (!function_exists('_fdate')) {
|
1447: | |
1448: | |
1449: | |
1450: | |
1451: | |
1452: | |
1453: |
|
1454: | function _fdate($date = '', $format = '')
|
1455: | {
|
1456: | if (!$format) {
|
1457: | $format = _cfg('dateFormat');
|
1458: | }
|
1459: |
|
1460: | if (func_num_args() === 0) {
|
1461: | return date($format);
|
1462: | }
|
1463: |
|
1464: | if (empty($date)) {
|
1465: | return '';
|
1466: | }
|
1467: |
|
1468: | return is_string($date) ? date($format, strtotime($date)) : date($format, $date);
|
1469: | }
|
1470: | }
|
1471: |
|
1472: | if (!function_exists('_fdatetime')) {
|
1473: | |
1474: | |
1475: | |
1476: | |
1477: | |
1478: | |
1479: |
|
1480: | function _fdatetime($dateTime = '', $format = '')
|
1481: | {
|
1482: | if (!$format) {
|
1483: | $format = _cfg('dateTimeFormat');
|
1484: | }
|
1485: |
|
1486: | if (func_num_args() == 0) {
|
1487: | return date($format);
|
1488: | }
|
1489: |
|
1490: | if (empty($dateTime)) {
|
1491: | return '';
|
1492: | }
|
1493: |
|
1494: | return date($format, strtotime($dateTime));
|
1495: | }
|
1496: | }
|
1497: |
|
1498: | if (!function_exists('_ftimeAgo')) {
|
1499: | |
1500: | |
1501: | |
1502: | |
1503: | |
1504: | |
1505: |
|
1506: | function _ftimeAgo($time, $format = 'M j Y')
|
1507: | {
|
1508: | if (empty($time)) {
|
1509: | return '';
|
1510: | }
|
1511: |
|
1512: | $now = time();
|
1513: | if (!is_numeric($time)) {
|
1514: | $time = strtotime($time);
|
1515: | }
|
1516: |
|
1517: | $secElapsed = $now - $time;
|
1518: | if ($secElapsed <= 60) {
|
1519: | return _t('just now');
|
1520: | } elseif ($secElapsed <= 3540) {
|
1521: | $min = $now - $time;
|
1522: | $min = round($min/60);
|
1523: | return _t('%d minutes ago', $min);
|
1524: | } elseif ($secElapsed <= 3660) {
|
1525: | return _t('1 hour ago');
|
1526: | } elseif (date('j-n-y', $now) == date('j-n-y', $time)) {
|
1527: | return date("g:i a", $time);
|
1528: | } elseif (date('j-n-y', mktime(0, 0, 0, date('n', $now), date('j', $now)-1, date('Y', $now))) == date('j-n-y', $time)) {
|
1529: | return _t('yesterday');
|
1530: | } elseif ($secElapsed <= 345600) {
|
1531: | return date('l', $time);
|
1532: | } else {
|
1533: | return date($format, $time);
|
1534: | }
|
1535: | }
|
1536: | }
|
1537: |
|
1538: | if (!function_exists('_msg')) {
|
1539: | |
1540: | |
1541: | |
1542: | |
1543: | |
1544: | |
1545: | |
1546: | |
1547: | |
1548: | |
1549: | |
1550: |
|
1551: | function _msg($msg, $class = 'error', $return = null, $display = null)
|
1552: | {
|
1553: | $class = $class ?: 'error';
|
1554: | $return = strtolower($return);
|
1555: |
|
1556: | $html = '';
|
1557: | $html .= '<div class="message"';
|
1558: | if ($display) {
|
1559: | $html .= ' style="display:' . $display . '"';
|
1560: | }
|
1561: | $html .= '>';
|
1562: | $html .= '<div class="message-'. $class . ' alert alert-' . ($class == 'error' ? 'danger' : $class) . '">';
|
1563: | if (is_array($msg)) {
|
1564: | if (count($msg) > 0) {
|
1565: | $html .= '<ul>';
|
1566: | foreach ($msg as $m) {
|
1567: | if (is_array($msg) && isset($m['message'])) {
|
1568: | $html .= '<li>'.$m['message'].'</li>';
|
1569: | } else {
|
1570: | $html .= '<li>'.$m.'</li>';
|
1571: | }
|
1572: | }
|
1573: | $html .= '</ul>';
|
1574: | } else {
|
1575: | $html = '';
|
1576: | }
|
1577: | } else {
|
1578: | $html .= $msg;
|
1579: | }
|
1580: |
|
1581: | $html .= '</div></div>';
|
1582: |
|
1583: | if (is_array($msg) && count($msg) == 0) {
|
1584: | $html = '';
|
1585: | }
|
1586: |
|
1587: | if ($return == 'html' || $return === true) {
|
1588: | return $html;
|
1589: | } else {
|
1590: | echo $html;
|
1591: | }
|
1592: |
|
1593: | return '';
|
1594: | }
|
1595: | }
|
1596: |
|
1597: | |
1598: | |
1599: | |
1600: | |
1601: | |
1602: | |
1603: | |
1604: | |
1605: |
|
1606: | function _filesize($file, $digits = 2, $sizes = array("MB","KB","B"))
|
1607: | {
|
1608: | if (is_file($file)) {
|
1609: | $filePath = $file;
|
1610: | if (!realpath($filePath)) {
|
1611: | $filePath = $_SERVER["DOCUMENT_ROOT"].$filePath;
|
1612: | }
|
1613: | $fileSize = filesize($filePath);
|
1614: | $total = count($sizes);
|
1615: | while ($total-- && $fileSize > 1024) {
|
1616: | $fileSize /= 1024;
|
1617: | }
|
1618: |
|
1619: | return round($fileSize, $digits)." ".$sizes[$total];
|
1620: | }
|
1621: |
|
1622: | return false;
|
1623: | }
|
1624: |
|
1625: | if (!function_exists('_randomCode')) {
|
1626: | |
1627: | |
1628: | |
1629: | |
1630: | |
1631: | |
1632: | |
1633: |
|
1634: | function _randomCode($length = 5, $letters = array(), $prefix = '')
|
1635: | {
|
1636: |
|
1637: | if (sizeof($letters) == 0) {
|
1638: | $letters = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
|
1639: | }
|
1640: |
|
1641: | shuffle($letters);
|
1642: | $randArr = array_splice($letters, 0, $length);
|
1643: |
|
1644: | return $prefix . implode('', $randArr);
|
1645: | }
|
1646: | }
|
1647: |
|
1648: | if (!function_exists('_slug')) {
|
1649: | |
1650: | |
1651: | |
1652: | |
1653: | |
1654: | |
1655: | |
1656: | |
1657: |
|
1658: | function _slug($string, $table = '', array $condition = array())
|
1659: | {
|
1660: | $specChars = array(
|
1661: | '`','~','!','@','#','$','%','\^','&',
|
1662: | '*','(',')','=','+','{','}','[',']',
|
1663: | ':',';',"'",'"','<','>','\\','|','?','/',','
|
1664: | );
|
1665: | $table = db_table($table);
|
1666: | $slug = strtolower(trim($string));
|
1667: | $slug = trim($slug, '-');
|
1668: |
|
1669: | $slug = preg_replace('/(&|"|'|<|>)/i', '', $slug);
|
1670: | $slug = str_replace($specChars, '-', $slug);
|
1671: | $slug = str_replace(array(' ', '.'), '-', $slug);
|
1672: | $slug = trim($slug, '-');
|
1673: |
|
1674: | $condition = array_merge(
|
1675: | array('slug' => $slug),
|
1676: | $condition
|
1677: | );
|
1678: |
|
1679: | while (true && $table) {
|
1680: | $count = db_count($table)->where($condition)->fetch();
|
1681: | if ($count == 0) {
|
1682: | break;
|
1683: | }
|
1684: |
|
1685: | $segments = explode('-', $slug);
|
1686: | if (sizeof($segments) > 1 && is_numeric($segments[sizeof($segments)-1])) {
|
1687: | $index = array_pop($segments);
|
1688: | $index++;
|
1689: | } else {
|
1690: | $index = 1;
|
1691: | }
|
1692: |
|
1693: | $segments[] = $index;
|
1694: | $slug = implode('-', $segments);
|
1695: | }
|
1696: |
|
1697: | $slug = preg_replace('/[\-]+/', '-', $slug);
|
1698: |
|
1699: | return trim($slug, '-');
|
1700: | }
|
1701: | }
|
1702: |
|
1703: | |
1704: | |
1705: | |
1706: | |
1707: | |
1708: | |
1709: | |
1710: | |
1711: |
|
1712: | function _sqlDate($date, $givenFormat = 'dmy', $separator = '-')
|
1713: | {
|
1714: | if (empty($date)) {
|
1715: | return null;
|
1716: | }
|
1717: |
|
1718: | $dt = explode($separator, $date);
|
1719: | $format = str_split($givenFormat);
|
1720: | $ft = array_flip($format);
|
1721: |
|
1722: | $y = $dt[$ft['y']];
|
1723: | $m = $dt[$ft['m']];
|
1724: | $d = $dt[$ft['d']];
|
1725: |
|
1726: | return checkdate($m, $d, $y) ? $y . '-' . $m .'-'. $d : null;
|
1727: | }
|
1728: |
|
1729: | |
1730: | |
1731: | |
1732: | |
1733: | |
1734: |
|
1735: | function _encrypt($text)
|
1736: | {
|
1737: | $secret = _cfg('securitySecret');
|
1738: | if (!$secret || !function_exists('openssl_encrypt')) {
|
1739: | return md5($text);
|
1740: | }
|
1741: |
|
1742: | $method = _cipher();
|
1743: | $ivlen = openssl_cipher_iv_length($method);
|
1744: | $iv = openssl_random_pseudo_bytes($ivlen);
|
1745: |
|
1746: | $textRaw = openssl_encrypt($text, $method, $secret, OPENSSL_RAW_DATA, $iv);
|
1747: | $hmac = hash_hmac('sha256', $textRaw, $secret, true);
|
1748: |
|
1749: | return base64_encode($iv . $hmac . $textRaw );
|
1750: | }
|
1751: |
|
1752: | |
1753: | |
1754: | |
1755: | |
1756: | |
1757: | |
1758: |
|
1759: | function _decrypt($encryptedText)
|
1760: | {
|
1761: | $secret = _cfg('securitySecret');
|
1762: | if (!$secret || !function_exists('openssl_decrypt')) {
|
1763: | return $encryptedText;
|
1764: | }
|
1765: |
|
1766: | $method = _cipher();
|
1767: | $sha2len = 32;
|
1768: | $ivlen = openssl_cipher_iv_length($method);
|
1769: | $text = base64_decode($encryptedText);
|
1770: | $iv = substr($text, 0, $ivlen);
|
1771: |
|
1772: | $rawText = substr($text, $ivlen + $sha2len);
|
1773: | $plainText = openssl_decrypt($rawText, $method, $secret, OPENSSL_RAW_DATA, $iv);
|
1774: |
|
1775: | $hmac = substr($text, $ivlen, $sha2len);
|
1776: | $mac = hash_hmac('sha256', $rawText, $secret, true);
|
1777: | if (hash_equals($hmac, $mac)) {
|
1778: | return $plainText;
|
1779: | }
|
1780: |
|
1781: | return $text;
|
1782: | }
|
1783: |
|
1784: | |
1785: | |
1786: | |
1787: |
|
1788: | function _cipher()
|
1789: | {
|
1790: | $method = _cfg('cipher');
|
1791: | if (!in_array($method, openssl_get_cipher_methods())) {
|
1792: | $method = 'AES-256-CBC';
|
1793: | }
|
1794: |
|
1795: | return $method;
|
1796: | }
|
1797: |
|
1798: | |
1799: | |
1800: | |
1801: | |
1802: | |
1803: | |
1804: |
|
1805: | function _meta($key, $value = '')
|
1806: | {
|
1807: | global $_meta;
|
1808: | $value = trim($value);
|
1809: | if (empty($value)) {
|
1810: | return (isset($_meta[$key])) ? $_meta[$key] : '';
|
1811: | } else {
|
1812: | if (in_array($key, array('description', 'og:description', 'twitter:description', 'gp:description'))) {
|
1813: | $value = trim(substr($value, 0, 200));
|
1814: | }
|
1815: | $_meta[$key] = $value;
|
1816: | }
|
1817: | }
|
1818: |
|
1819: | |
1820: | |
1821: | |
1822: |
|
1823: | function _metaSeoTags()
|
1824: | {
|
1825: | if (_meta('description')) {
|
1826: | _cfg('metaDescription', _meta('description'));
|
1827: | }
|
1828: |
|
1829: | if (_meta('keywords')) {
|
1830: | _cfg('metaKeywords', _meta('keywords'));
|
1831: | }
|
1832: |
|
1833: | $tags = array();
|
1834: | $tags['description'] = _cfg('metaDescription');
|
1835: | $tags['keywords'] = _cfg('metaKeywords');
|
1836: |
|
1837: | $tags['og'] = array();
|
1838: | $tags['og']['title'] = _meta('og:title') ? _meta('og:title') : _cfg('siteName');
|
1839: | $tags['og']['url'] = _meta('og:url') ? _meta('og:url') : _url();
|
1840: | $tags['og']['type'] = _meta('og:type') ? _meta('og:type') : 'website';
|
1841: | $tags['og']['image'] = _meta('og:image') ? _meta('og:image') : _img('logo-social.jpg');
|
1842: | $tags['og']['description'] = _meta('og:description') ? _meta('og:description') : _cfg('metaDescription');
|
1843: | $tags['og']['site_name'] = _meta('og:site_name') ? _meta('og:site_name') : _cfg('siteName');
|
1844: |
|
1845: | $tags['twitter'] = array();
|
1846: | $tags['twitter']['card'] = _meta('twitter:card') ? _meta('twitter:card') : 'summary';
|
1847: | $tags['twitter']['site'] = _meta('twitter:site') ? '@'._meta('twitter:site') : '@'._cfg('siteDomain');
|
1848: | $tags['twitter']['title'] = _meta('twitter:title') ? _meta('twitter:title') : _cfg('siteName');
|
1849: | $tags['twitter']['description'] = _meta('twitter:description') ? _meta('twitter:description') : _cfg('metaDescription');
|
1850: | $tags['twitter']['image'] = _meta('twitter:image') ? _meta('twitter:image') : _img('logo-social.jpg');
|
1851: |
|
1852: | if (function_exists('__metaSeoTags')) {
|
1853: | echo __metaSeoTags($tags);
|
1854: | } else {
|
1855: | echo "\n";
|
1856: | foreach ($tags as $name => $tag) {
|
1857: | if ($name == 'og') {
|
1858: | foreach ($tag as $key => $content) {
|
1859: | echo '<meta property="og:' . $key . '" content="' . $content . '" />'."\n";
|
1860: | }
|
1861: | } elseif ($name == 'twitter') {
|
1862: | foreach ($tag as $key => $content) {
|
1863: | echo '<meta name="twitter:' . $key . '" content="' . $content . '" />'."\n";
|
1864: | }
|
1865: | } else {
|
1866: | echo '<meta name="' . $name . '" content="' . $tag . '" />'."\n";
|
1867: | }
|
1868: | }
|
1869: | }
|
1870: | }
|
1871: |
|
1872: | |
1873: | |
1874: | |
1875: | |
1876: | |
1877: | |
1878: | |
1879: | |
1880: | |
1881: | |
1882: | |
1883: | |
1884: | |
1885: | |
1886: | |
1887: | |
1888: | |
1889: |
|
1890: | function _mail($from, $to, $subject = '', $message = '', $cc = '', $bcc = '')
|
1891: | {
|
1892: | $charset = mb_detect_encoding($message);
|
1893: | $message = nl2br(stripslashes($message));
|
1894: |
|
1895: | $EEOL = PHP_EOL;
|
1896: | $headers = 'From: ' . $from . $EEOL;
|
1897: | $headers .= 'MIME-Version: 1.0' . $EEOL;
|
1898: | $headers .= 'Content-type: text/html; charset=' . $charset . $EEOL;
|
1899: | $headers .= 'Reply-To: ' . $from . $EEOL;
|
1900: | $headers .= 'Return-Path:'.$from . $EEOL;
|
1901: | if ($cc) {
|
1902: | $headers .= 'Cc: ' . $cc . $EEOL;
|
1903: | }
|
1904: | if ($bcc) {
|
1905: | $headers .= 'Bcc: ' . $bcc . $EEOL;
|
1906: | }
|
1907: | $headers .= 'X-Mailer: PHP';
|
1908: |
|
1909: | return mail($to, $subject, $message, $headers);
|
1910: | }
|
1911: | |
1912: | |
1913: | |
1914: | |
1915: | |
1916: | |
1917: | |
1918: | |
1919: | |
1920: |
|
1921: | function _postTranslationStrings($post, $fields, $lang = null)
|
1922: | {
|
1923: | global $lc_languages;
|
1924: |
|
1925: | $data = array();
|
1926: | foreach ($fields as $key => $name) {
|
1927: | if ($lang) {
|
1928: | $lcode = _queryLang($lang);
|
1929: | if (isset($post[$name.'_'.$lcode])) {
|
1930: | $data[$key.'_'.$lcode] = $post[$name.'_'.$lcode];
|
1931: | }
|
1932: | } else {
|
1933: | if (isset($post[$name])) {
|
1934: | $data[$key.'_'._defaultLang()] = $post[$name];
|
1935: | }
|
1936: | foreach ($lc_languages as $lcode => $lname) {
|
1937: | $lcode = _queryLang($lcode);
|
1938: | if (isset($post[$name.'_'.$lcode])) {
|
1939: | $data[$key.'_'.$lcode] = $post[$name.'_'.$lcode];
|
1940: | }
|
1941: | }
|
1942: | }
|
1943: | }
|
1944: |
|
1945: | return $data;
|
1946: | }
|
1947: |
|
1948: | |
1949: | |
1950: | |
1951: | |
1952: | |
1953: | |
1954: | |
1955: | |
1956: | |
1957: | |
1958: |
|
1959: | function _getTranslationStrings($data, $fields, $lang = null)
|
1960: | {
|
1961: | global $lc_languages;
|
1962: |
|
1963: | $isObject = is_object($data);
|
1964: | $data = (array) $data;
|
1965: |
|
1966: | if (is_string($fields)) {
|
1967: | $fields = array($fields);
|
1968: | }
|
1969: |
|
1970: | foreach ($fields as $name) {
|
1971: | if ($lang) {
|
1972: | $lcode = _queryLang($lang);
|
1973: | if (isset($data[$name.'_'.$lcode]) && $data[$name.'_'.$lcode]) {
|
1974: | $data[$name.'_i18n'] = $data[$name.'_'.$lcode];
|
1975: | } else {
|
1976: | $data[$name.'_i18n'] = $data[$name];
|
1977: | }
|
1978: | } else {
|
1979: | foreach ($lc_languages as $lcode => $lname) {
|
1980: | $lcode = _queryLang($lcode);
|
1981: | if (isset($data[$name.'_'.$lcode])) {
|
1982: | $data[$name.'_i18n'][$lcode] = $data[$name.'_'.$lcode];
|
1983: | }
|
1984: | }
|
1985: | }
|
1986: | }
|
1987: |
|
1988: | if ($isObject) {
|
1989: | $data = (object) $data;
|
1990: | }
|
1991: |
|
1992: | return $data;
|
1993: | }
|
1994: |
|
1995: | |
1996: | |
1997: | |
1998: | |
1999: |
|
2000: | function _isBot()
|
2001: | {
|
2002: | if (!isset($_SERVER['HTTP_USER_AGENT'])) {
|
2003: | return false;
|
2004: | }
|
2005: |
|
2006: | $userAgent = $_SERVER['HTTP_USER_AGENT'];
|
2007: | if (empty($userAgent)) {
|
2008: | return false;
|
2009: | }
|
2010: |
|
2011: | $bots = array(
|
2012: | 'Googlebot',
|
2013: | 'Slurp',
|
2014: | 'msnbot',
|
2015: | 'bingbot',
|
2016: | 'yahoo',
|
2017: | 'search.msn.com',
|
2018: | 'Baidu',
|
2019: | 'baiduspider',
|
2020: | 'Yandex',
|
2021: | 'nutch',
|
2022: | 'FAST',
|
2023: | 'Sosospider',
|
2024: | 'Exabot',
|
2025: | 'sogou',
|
2026: | 'bot',
|
2027: | 'crawler',
|
2028: | 'spider',
|
2029: | 'Feedfetcher-Google',
|
2030: | 'ASPSeek',
|
2031: | 'simpy',
|
2032: | 'ips-agent',
|
2033: | 'Libwww-perl',
|
2034: | 'ask jeeves',
|
2035: | 'fastcrawler',
|
2036: | 'infoseek',
|
2037: | 'lycos',
|
2038: | 'mediapartners-google',
|
2039: | 'CRAZYWEBCRAWLER',
|
2040: | 'adsbot-google',
|
2041: | 'curious george',
|
2042: | 'ia_archiver',
|
2043: | 'MJ12bot',
|
2044: | 'Uptimebot',
|
2045: | 'Dataprovider.com',
|
2046: | 'Go-http-client',
|
2047: | 'Barkrowler',
|
2048: | 'panscient.com',
|
2049: | 'Symfony BrowserKit',
|
2050: | 'Apache-HttpClient',
|
2051: | 'serpstatbot',
|
2052: | 'BLEXBot',
|
2053: | 'DotBot',
|
2054: | 'AhrefsBot',
|
2055: | );
|
2056: | foreach ($bots as $bot) {
|
2057: | if (false !== strpos(strtolower($userAgent), strtolower($bot))) {
|
2058: | return true;
|
2059: | }
|
2060: | }
|
2061: |
|
2062: | return false;
|
2063: | }
|
2064: |
|
2065: | |
2066: | |
2067: | |
2068: | |
2069: | |
2070: | |
2071: |
|
2072: | function _write($text = '')
|
2073: | {
|
2074: | $args = func_get_args();
|
2075: | $text = array_shift($args);
|
2076: | if ($text) {
|
2077: | echo vsprintf($text, $args);
|
2078: | }
|
2079: | }
|
2080: |
|
2081: | |
2082: | |
2083: | |
2084: | |
2085: | |
2086: | |
2087: |
|
2088: | function _writeln($text = '')
|
2089: | {
|
2090: | $args = func_get_args();
|
2091: | $text = array_shift($args);
|
2092: | if ($text) {
|
2093: | echo vsprintf($text, $args);
|
2094: | }
|
2095: |
|
2096: | echo "\n";
|
2097: | }
|
2098: |
|
2099: | |
2100: | |
2101: | |
2102: | |
2103: | |
2104: |
|
2105: | function _indent($width = 2)
|
2106: | {
|
2107: | return str_repeat(' ', $width);
|
2108: | }
|
2109: |
|
2110: | |
2111: | |
2112: | |
2113: | |
2114: | |
2115: |
|
2116: | function _consoleCommand($command)
|
2117: | {
|
2118: | return new Command($command);
|
2119: | }
|
2120: |
|
2121: | |
2122: | |
2123: | |
2124: | |
2125: |
|
2126: | function _consoleTable()
|
2127: | {
|
2128: | return new ConsoleTable();
|
2129: | }
|
2130: |
|
2131: | |
2132: | |
2133: | |
2134: | |
2135: |
|
2136: | function _consoleCommands()
|
2137: | {
|
2138: | return Console::getCommands();
|
2139: | }
|
2140: |
|
2141: | |
2142: | |
2143: | |
2144: | |
2145: | |
2146: |
|
2147: | function _pager($pageQueryStr = '')
|
2148: | {
|
2149: | return new Pager($pageQueryStr);
|
2150: | }
|
2151: |
|
2152: | |
2153: | |
2154: | |
2155: | |
2156: | |
2157: |
|
2158: | function _fileHelper($fileName = '')
|
2159: | {
|
2160: | return new File($fileName);
|
2161: | }
|
2162: |
|
2163: | |
2164: | |
2165: | |
2166: | |
2167: | |
2168: |
|
2169: | function _asynFileUploader()
|
2170: | {
|
2171: | if (func_num_args()) {
|
2172: | return new AsynFileUploader(func_get_arg(0));
|
2173: | } else {
|
2174: | return new AsynFileUploader();
|
2175: | }
|
2176: | }
|
2177: |
|
2178: | |
2179: | |
2180: | |
2181: | |
2182: | |
2183: | |
2184: |
|
2185: | function _middleware(\Closure $closure, $event = 'before')
|
2186: | {
|
2187: | $middleware = new Middleware();
|
2188: |
|
2189: | return $middleware->register($closure, $event);
|
2190: | }
|
2191: |
|
2192: | |
2193: | |
2194: | |
2195: |
|
2196: | function _view()
|
2197: | {
|
2198: | if (_cfg('view')) {
|
2199: | $viewName = 'view_'._cfg('view');
|
2200: | } elseif (_g('view')) {
|
2201: | $viewName = 'view_'._g('view');
|
2202: | } else {
|
2203: | $viewName = 'view';
|
2204: | }
|
2205: |
|
2206: | return _i(_ds(_cr(), $viewName.'.php'));
|
2207: | }
|
2208: |
|
2209: | |
2210: | |
2211: | |
2212: |
|
2213: | function _ds()
|
2214: | {
|
2215: | return implode(_DS_, func_get_args());
|
2216: | }
|
2217: |
|
2218: | |
2219: | |
2220: | |
2221: |
|
2222: | function _isAjax()
|
2223: | {
|
2224: | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
2225: | strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
|
2226: | return true;
|
2227: | }
|
2228: |
|
2229: | return false;
|
2230: | }
|
2231: |
|
2232: | |
2233: | |
2234: | |
2235: |
|
2236: | function _isHttpPost()
|
2237: | {
|
2238: | return _isRequestMethod('POST') && count($_POST);
|
2239: | }
|
2240: |
|
2241: | |
2242: | |
2243: | |
2244: | |
2245: | |
2246: |
|
2247: | function _json($data = [], $status = 200)
|
2248: | {
|
2249: | if (_isRequestMethod('OPTIONS')) {
|
2250: | _header(200);
|
2251: | exit;
|
2252: | }
|
2253: |
|
2254: | _header($status);
|
2255: |
|
2256: | header('Content-Type: application/json');
|
2257: | if ($status != 204) {
|
2258: | echo json_encode($data);
|
2259: | }
|
2260: |
|
2261: | Middleware::runAfter();
|
2262: | exit;
|
2263: | }
|
2264: |
|
2265: | |
2266: | |
2267: | |
2268: | |
2269: | |
2270: | |
2271: |
|
2272: | function _jsonError($message, $field = '', $status = 400)
|
2273: | {
|
2274: | $errors = [];
|
2275: | if (is_array($message)) {
|
2276: | $errors = $message;
|
2277: | } else {
|
2278: | $errors[] = [
|
2279: | 'field' => $field,
|
2280: | 'message' => $message,
|
2281: | ];
|
2282: |
|
2283: | }
|
2284: |
|
2285: | _json(['error' => $errors], $status);
|
2286: | }
|
2287: |
|
2288: | |
2289: | |
2290: | |
2291: |
|
2292: | function _requestHeaders()
|
2293: | {
|
2294: | if (function_exists('getallheaders')) {
|
2295: | return getallheaders();
|
2296: | }
|
2297: |
|
2298: | if (function_exists('apache_request_headers')) {
|
2299: | return apache_request_headers();
|
2300: | }
|
2301: |
|
2302: | $headers = array();
|
2303: | foreach ($_SERVER as $name => $value) {
|
2304: | $name = strtolower($name);
|
2305: | if (substr($name, 0, 5) == 'http_') {
|
2306: | $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', substr($name, 5))))] = $value;
|
2307: | } elseif ($name == 'content_type') {
|
2308: | $headers['Content-Type'] = $value;
|
2309: | } elseif ($name == 'content_length') {
|
2310: | $headers['Content-Length'] = $value;
|
2311: | }
|
2312: | }
|
2313: |
|
2314: | return $headers;
|
2315: | }
|
2316: |
|
2317: | |
2318: | |
2319: | |
2320: | |
2321: |
|
2322: | function _requestHeader($name)
|
2323: | {
|
2324: | $headers = _requestHeaders();
|
2325: | if (!is_array($headers)) {
|
2326: | return null;
|
2327: | }
|
2328: |
|
2329: | $headers = array_change_key_case($headers);
|
2330: | $name = strtolower($name);
|
2331: |
|
2332: | if (isset($headers[$name])) {
|
2333: | return $headers[$name];
|
2334: | }
|
2335: |
|
2336: | return null;
|
2337: | }
|
2338: |
|
2339: | |
2340: | |
2341: | |
2342: |
|
2343: | function _requestMethod()
|
2344: | {
|
2345: | if (isset($_SERVER['REQUEST_METHOD'])) {
|
2346: | return strtoupper($_SERVER['REQUEST_METHOD']);
|
2347: | }
|
2348: |
|
2349: | return null;
|
2350: | }
|
2351: |
|
2352: | |
2353: | |
2354: | |
2355: | |
2356: |
|
2357: | function _isRequestMethod($method)
|
2358: | {
|
2359: | return _requestMethod() == strtoupper($method);
|
2360: | }
|
2361: |
|
2362: | |
2363: | |
2364: | |
2365: | |
2366: |
|
2367: | function _addFormData($name, array $data)
|
2368: | {
|
2369: | echo '<script>LC.Form.formData["' . $name . '"] = ' . json_encode($data) . ';</script>';
|
2370: | }
|
2371: |
|
2372: | |
2373: | |
2374: | |
2375: | |
2376: | |
2377: |
|
2378: | function _nullFill($value)
|
2379: | {
|
2380: | if (function_exists('__nullFill')) {
|
2381: | return __nullFill($value);
|
2382: | }
|
2383: |
|
2384: | return $value ?: '<span class="null-fill">-</span>';
|
2385: | }
|
2386: |
|
2387: | |
2388: | |
2389: | |
2390: | |
2391: | |
2392: |
|
2393: | function _entity($table, $dbNamespace = null)
|
2394: | {
|
2395: | if (!$dbNamespace) {
|
2396: | $dbNamespace = _cfg('defaultDbSource');
|
2397: | }
|
2398: |
|
2399: | $schema = _schema($dbNamespace, true);
|
2400: |
|
2401: | $entity = array();
|
2402: | if ($schema && isset($schema[$table])) {
|
2403: | $options = array_merge(SchemaManager::$relationships, array('options'));
|
2404: | foreach ($schema[$table] as $field => $def) {
|
2405: | if (in_array($field, $options)) {
|
2406: | continue;
|
2407: | }
|
2408: |
|
2409: | if (isset($def['autoinc'])) {
|
2410: | $value = 0;
|
2411: | } else {
|
2412: | $value = isset($def['null']) ? null : '';
|
2413: | if (isset($def['default'])) {
|
2414: | $value = $def['default'];
|
2415: | }
|
2416: | }
|
2417: |
|
2418: | if ($field == 'created' || $field == 'updated') {
|
2419: | $value = date('Y-m-i H:i:s');
|
2420: | }
|
2421: |
|
2422: | if ($def['type'] == 'array' || $def['type'] == 'json') {
|
2423: | $value = array();
|
2424: | }
|
2425: |
|
2426: | $entity[$field] = $value;
|
2427: | }
|
2428: | }
|
2429: |
|
2430: | return (object) $entity;
|
2431: | }
|
2432: |
|
2433: | |
2434: | |
2435: | |
2436: | |
2437: |
|
2438: | function _addHeadStyle($file)
|
2439: | {
|
2440: | $view = _app('view');
|
2441: | $view->addHeadStyle($file);
|
2442: | }
|
2443: |
|
2444: | |
2445: | |
2446: | |
2447: | |
2448: |
|
2449: | function _addHeadScript($file)
|
2450: | {
|
2451: | $view = _app('view');
|
2452: | $view->addHeadScript($file);
|
2453: | }
|
2454: |
|
2455: | |
2456: | |
2457: | |
2458: | |
2459: |
|
2460: | function _en2myNum($num)
|
2461: | {
|
2462: | $digits = array(
|
2463: | '/0/' => '၀',
|
2464: | '/1/' => '၁',
|
2465: | '/2/' => '၂',
|
2466: | '/3/' => '၃',
|
2467: | '/4/' => '၄',
|
2468: | '/5/' => '၅',
|
2469: | '/6/' => '၆',
|
2470: | '/7/' => '၇',
|
2471: | '/8/' => '၈',
|
2472: | '/9/' => '၉',
|
2473: | );
|
2474: |
|
2475: | return preg_replace(array_keys($digits), array_values($digits), $num);
|
2476: | }
|
2477: |
|
2478: | |
2479: | |
2480: | |
2481: | |
2482: |
|
2483: | function _arrayAssoc(array $arr)
|
2484: | {
|
2485: | if (empty($arr)) {
|
2486: | return false;
|
2487: | }
|
2488: |
|
2489: | return array_keys($arr) !== range(0, count($arr) - 1);
|
2490: | }
|
2491: |
|
2492: | |
2493: | |
2494: | |
2495: | |
2496: |
|
2497: | function _isContentType($type)
|
2498: | {
|
2499: | return isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == $type;
|
2500: | }
|
2501: | |