1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37: 38: 39: 40: 41:
42: class Formatter {
43:
44: 45: 46:
47: public static function mbSanitize($text) {
48: $newText = $text;
49: if (!mb_detect_encoding($text, Yii::app()->charset, true)) {
50: $newText = mb_convert_encoding($text, Yii::app()->charset, 'ISO-8859-1');
51: }
52: return $newText;
53: }
54:
55: 56: 57: 58: 59: 60:
61: public static function typeCast($value,$type) {
62: switch($type) {
63: case 'bool':
64: case 'boolean':
65: return (boolean) $value;
66: case 'double':
67: return (double) $value;
68: case 'int':
69: case 'integer':
70: return (integer) $value;
71: default:
72: return (string) $value;
73: }
74: }
75:
76: 77: 78: 79:
80: public static function convertLineBreaks($text, $allowDouble = true, $allowUnlimited = false){
81:
82: if(preg_match("/<br \/>/", $text)){
83: $text = preg_replace("/<\/b>/", "</b><br />", $text, 1);
84: $text = preg_replace("/\s<b>/", "<br /><b>", $text, 1);
85: return $text;
86: }
87:
88: $text = mb_ereg_replace("\r\n", "\n", $text);
89:
90: if(!$allowUnlimited) {
91:
92: $text = mb_ereg_replace("[\r\n]{3,}", "\n\n", $text);
93: }
94:
95: if($allowDouble) {
96:
97: $text = mb_ereg_replace("[\r\n]", '<br />', $text);
98: } else {
99: $text = mb_ereg_replace("[\r\n]+", '<br />', $text);
100: }
101:
102: return $text;
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118:
119: public static function parseFormula($input, array $params = array()){
120: if(strpos($input,'=') !== 0) {
121: return array(false,Yii::t('admin','Formula does not begin with "="'));
122: }
123:
124: $formula = substr($input, 1);
125:
126: $replacementTokens = static::getReplacementTokens ($formula, $params, false, false);
127:
128:
129:
130:
131:
132:
133:
134: foreach(array_keys($replacementTokens) as $token) {
135: $type = gettype($replacementTokens[$token]);
136:
137: if(!in_array($type,array("boolean","integer","double","string","NULL"))) {
138:
139:
140:
141:
142:
143: $replacementTokens[$token] = var_export($token,true);
144:
145: } else if ($type === 'string') {
146:
147: $replacementTokens[$token] = var_export($replacementTokens[$token],true);
148: }
149: }
150:
151:
152: if(strpos($formula, ';') !== strlen($formula) - 1){
153:
154: $formula .= ';';
155: }
156: if(strpos($formula, 'return ') !== 0){
157:
158: $formula = 'return '.$formula;
159: }
160:
161:
162:
163: foreach(array_keys($replacementTokens) as $token) {
164: $shortCodePatterns[] = preg_quote($token,'#');
165: }
166:
167: $charOp = '[\[\]()<>=!^|?:*+%/\-\.]';
168: $charOpOrWhitespace = '(?:'.$charOp.'|\s)';
169: $phpOper = implode ('|', array (
170: $charOpOrWhitespace,
171: $charOpOrWhitespace.'and',
172: $charOpOrWhitespace.'or',
173: $charOpOrWhitespace.'xor',
174: $charOpOrWhitespace.'false',
175: $charOpOrWhitespace.'true',
176: ));
177:
178: $singleQuotedString = '\'\'|\'[^\']*[^\\\\\']\'';
179: $number = $charOpOrWhitespace.'[0-9]+(?:\.[0-9]+)?';
180: $validPattern = '#^return(?:'
181: .self::getSafeWords($charOpOrWhitespace)
182: .(empty($shortCodePatterns)?'':('|'.implode('|',$shortCodePatterns)))
183: .'|'.$phpOper
184: .'|'.$number
185: .'|'.$singleQuotedString.')*;$#i';
186:
187: if(!preg_match($validPattern,$formula)) {
188: return array(
189: false,
190: Yii::t('admin','Input evaluates to an invalid formula: ').
191: strtr($formula,$replacementTokens));
192: }
193:
194: try{
195: $retVal = @eval(strtr($formula,$replacementTokens));
196: }catch(Exception $e){
197: return array(
198: false,
199: Yii::t('admin','Evaluated statement encountered an exception: '.$e->getMessage()));
200: }
201:
202: return array(true,$retVal);
203: }
204:
205: 206: 207: 208: 209: 210: 211: 212: 213:
214: private static function getSafeWords($prefix){
215: $safeWords = array(
216: $prefix.'echo[ (]',
217: $prefix.'time[ (]',
218: );
219: return implode('|',$safeWords);
220: }
221:
222: 223: 224: 225: 226: 227: 228: 229: 230:
231: protected static function getReplacementTokens(
232: $value, array $params, $renderFlag, $makeLinks) {
233:
234: if (!isset ($params['model'])) throw new CException ('Missing model param');
235:
236: $model = $params['model'];
237:
238:
239: $codes = array();
240:
241: $codeTypes = array();
242: $fieldTypes = array_map(function($f){return $f['phpType'];},Fields::getFieldTypes());
243: $fields = $model->getFields(true);
244:
245: preg_match_all('/{([a-z]\w*)(\.[a-z]\w*)*?}/i', trim($value), $matches);
246:
247: if(!empty($matches[0])){
248: foreach($matches[0] as $match){
249: $match = substr($match, 1, -1);
250: $attr = $match;
251: if(strpos($match, '.') !== false){
252:
253:
254: $newModel = $model;
255: $pieces = explode('.',$match);
256: $first = array_shift($pieces);
257:
258: $codes['{'.$match.'}'] = $newModel->getAttribute(
259: $attr, $renderFlag, $makeLinks);
260: $codeTypes[$match] = isset($fields[$attr])
261: && isset($fieldTypes[$fields[$attr]->type])
262: ? $fieldTypes[$fields[$attr]->type]
263: : 'string';
264:
265: }else{
266:
267: if($model->hasAttribute($match)){
268: $codes['{'.$match.'}'] = $model->getAttribute(
269: $match, $renderFlag, $makeLinks);
270: $codeTypes[$match] = isset($fields[$match])
271: && isset($fieldTypes[$fields[$match]->type])
272: ? $fieldTypes[$fields[$match]->type]
273: : 'string';
274:
275: }
276: }
277: }
278: }
279:
280: $codes = self::castReplacementTokenTypes ($codes, $codeTypes);
281:
282: return $codes;
283: }
284:
285: protected static function castReplacementTokenTypes (array $codes, array $codeTypes) {
286:
287: foreach ($codes as $name => $val) {
288: if(!in_array(gettype ($val),array("boolean","integer","double","string","NULL"))) {
289:
290: unset ($codes[$name]);
291: } elseif(isset($codeTypes[$name])) {
292: $codes[$name] = self::typeCast($val, $codeTypes[$name]);
293: }
294: }
295: return $codes;
296: }
297:
298: 299: 300: 301: 302:
303: public static function restoreInsertableAttributes($text) {
304: $characters = array(
305: '%7B' => '{',
306: '%7D' => '}',
307: );
308: return strtr ($text, $characters);
309: }
310:
311:
312:
313: 314: 315: 316: 317: 318: 319:
320: public static function timestampAge($timestamp){
321: $age = time() - strtotime($timestamp);
322:
323: if($age < 60) {
324:
325: return Yii::t('app', 'Just now');
326: }
327: if($age < 3600) {
328:
329: return Yii::t('app', '{n} minutes ago', array('{n}' => floor($age / 60)));
330: }
331: if($age < 86400) {
332:
333: return Yii::t('app', '{n} hours ago', array('{n}' => floor($age / 3600)));
334: }
335:
336:
337: return Yii::t('app', '{n} days ago', array('{n}' => floor($age / 86400)));
338: }
339:
340: 341: 342: 343:
344: public static function formatLongDate($timestamp){
345: if(empty($timestamp)) {
346: return '';
347: } else {
348: return Yii::app()->dateFormatter->format(
349: Yii::app()->locale->getDateFormat('long'), $timestamp);
350: }
351: }
352:
353: 354: 355: 356: 357: 358:
359: public static function yiiDateFormatToJQueryDateFormat ($format) {
360: $tokens = CDateTimeParser::tokenize ($format);
361: $jQueryFormat = '';
362: foreach($tokens as $token) {
363: switch($token) {
364: case 'yyyy':
365: case 'y':
366: $jQueryFormat .= 'yy';
367: break;
368: case 'yy':
369: $jQueryFormat .= 'y';
370: break;
371: case 'MMMM':
372: $jQueryFormat .= $token;
373: break;
374: case 'MMM':
375: $jQueryFormat .= 'M';
376: break;
377: case 'MM':
378: $jQueryFormat .= 'mm';
379: break;
380: case 'M':
381: $jQueryFormat .= 'm';
382: break;
383: case 'dd':
384: $jQueryFormat .= $token;
385: break;
386: case 'd':
387: $jQueryFormat .= $token;
388: break;
389: case 'h':
390: case 'H':
391: $jQueryFormat .= $token;
392: break;
393: case 'hh':
394: case 'HH':
395: $jQueryFormat .= $token;
396: break;
397: case 'm':
398: $jQueryFormat .= $token;
399: break;
400: case 'mm':
401: $jQueryFormat .= $token;
402: break;
403: case 's':
404: $jQueryFormat .= $token;
405: break;
406: case 'ss':
407: $jQueryFormat .= $token;
408: break;
409: case 'a':
410: $jQueryFormat .= $token;
411: break;
412: default:
413: $jQueryFormat .= $token;
414: break;
415: }
416: }
417: return $jQueryFormat;
418: }
419:
420: 421: 422: 423: 424:
425: public static function formatDatePicker($width = ''){
426: if(Yii::app()->locale->getId() == 'en'){
427: if($width == 'medium')
428: return "M d, yy";
429: else
430: return "MM d, yy";
431: } else{
432: $format = self::yiiDateFormatToJQueryDateFormat (
433: Yii::app()->locale->getDateFormat('medium'));
434: return $format;
435: }
436: }
437:
438: public static function secondsToHours ($seconds) {
439: $decHours = $seconds / 3600;
440: return Yii::t(
441: 'app', '{decHours} hours',
442: array ('{decHours}' => sprintf('%0.2f', $decHours)));
443: }
444:
445: 446: 447: 448: 449: 450:
451: public static function formatTimeInterval($start,$end,$style=null) {
452: $duration = $end-$start;
453: $decHours = $duration/3600;
454: $intHours = (int) $decHours;
455: $intMinutes = (int) (($duration % 3600) / 60);
456: if(empty($style)){
457:
458: $style = Yii::t('app', '{decHours} hours, starting {start}');
459: }
460:
461: return strtr($style, array(
462: '{decHours}' => sprintf('%0.2f', $decHours),
463: '{hoursColMinutes}' => sprintf('%d:%d',$intHours,$intMinutes),
464: '{hours}' => $intHours,
465: '{minutes}' => $intMinutes,
466: '{hoursMinutes}' => $intHours ?
467: sprintf('%d %s %d %s', $intHours, Yii::t('app', 'hours'),
468: $intMinutes, Yii::t('app', 'minutes')) :
469: sprintf('%d %s', $intMinutes, Yii::t('app', 'minutes')),
470: '{quarterDecHours}' => sprintf(
471: '%0.2f '.Yii::t('app', 'hours'),
472: round($duration / 900.0) * 0.25),
473: '{start}' => self::formatCompleteDate($start),
474: '{end}' => self::formatCompleteDate($end)
475: ));
476: }
477:
478: 479: 480: 481: 482: 483:
484: public static function formatTimePicker($width = '',$seconds = false){
485: 486: 487:
488: $format = Yii::app()->locale->getTimeFormat($seconds?'medium':'short');
489:
490:
491:
492:
493:
494: $format = str_replace('a', 'TT', $format);
495: return $format;
496: }
497:
498: 499: 500: 501: 502:
503: public static function fullName($firstName,$lastName) {
504: return !empty(Yii::app()->settings->contactNameFormat) ?
505: strtr(Yii::app()->settings->contactNameFormat, compact('lastName', 'firstName')) :
506: "$firstName $lastName";
507: }
508:
509: 510: 511: 512: 513: 514: 515: 516: 517: 518:
519: public static function fullNameSelect($firstNameCol,$lastNameCol,$as=false) {
520: $pre = ':fullName_'.uniqid().'_';
521: $columns = array(
522: 'firstName' => $firstNameCol,
523: 'lastName' => $lastNameCol,
524: );
525: $format = empty(Yii::app()->settings->contactNameFormat)
526: ? 'firstName lastName'
527: : Yii::app()->settings->contactNameFormat;
528: $placeholderPositions = array();
529: foreach($columns as $placeholder => $columnName) {
530: if(($pos = mb_strpos($format,$placeholder)) !== false) {
531: $placeholderPositions[$placeholder] = $pos;
532: }
533: }
534: asort($placeholderPositions);
535: $concatItems = array();
536: $params = array();
537: $lenTot = mb_strlen($format);
538: $n_p = 0;
539: $pos = 0;
540:
541: foreach($placeholderPositions as $placeholder => $position){
542:
543: if($position > $pos){
544: $leadIn = mb_substr($format,$pos,$position-$pos);
545: if(!empty($leadIn)) {
546: $concatItems[] = $param = "{$pre}_inter_$n_p";
547: $params[$param] = $leadIn;
548: $n_p++;
549: }
550: $pos += mb_strlen($leadIn);
551: }
552: $concatItems[] = "`{$columns[$placeholder]}`";
553: $pos += mb_strlen($placeholder);
554: }
555: if($pos < $lenTot-1) {
556: $trailing = mb_substr($format,$pos);
557: $concatItems[] = $param = "{$pre}_trailing";
558: $params[$param] = $trailing;
559: }
560: return array(
561: "CONCAT(".implode(',', $concatItems).")".($as ? " AS `$as`" : ''),
562: $params
563: );
564: }
565:
566: 567: 568:
569: public static function formatAMPM(){
570: if(strstr(Yii::app()->locale->getTimeFormat(), "a") === false) {
571: return false;
572: } 573: 574: 575: else {
576: return true;
577: }
578: }
579:
580:
581:
582: public static function formatFeedTimestamp($timestamp){
583: if (Yii::app()->dateFormatter->format(
584: Yii::app()->locale->getDateFormat('medium'), $timestamp) ==
585: Yii::app()->dateFormatter->format(
586: Yii::app()->locale->getDateFormat('medium'), time())){
587:
588: $str = Yii::t('app', 'Today').' '.
589: Yii::app()->dateFormatter->format(
590: Yii::app()->locale->getTimeFormat('short'), $timestamp);
591: }else{
592: $str =
593: Yii::app()->dateFormatter->format(
594: Yii::app()->locale->getDateFormat('medium'), $timestamp).
595: " ".
596: Yii::app()->dateFormatter->format(
597: Yii::app()->locale->getTimeFormat('short'), $timestamp);
598: }
599: return $str;
600: }
601:
602: 603: 604: 605: 606:
607: public static function formatDateEndOfDay($timestamp){
608: if(empty($timestamp)) {
609: return '';
610: } else if(Yii::app()->locale->getId() == 'en') {
611: return Yii::app()->dateFormatter->format(
612: Yii::app()->locale->getDateFormat('medium').' '.
613: Yii::app()->locale->getTimeFormat('short'),
614: strtotime("tomorrow", $timestamp) - 60);
615: } 616: 617: 618: else {
619: return Yii::app()->dateFormatter->format(
620: Yii::app()->locale->getDateFormat('medium').' '.
621: Yii::app()->locale->getTimeFormat('short'),
622: strtotime("tomorrow", $timestamp) - 60);
623: }
624: }
625:
626: 627: 628: 629: 630: 631: 632:
633: public static function truncateText($str, $length = 30, $encode=false){
634:
635: if(mb_strlen($str, 'UTF-8') > $length - 3){
636: if($length < 3)
637: $str = '';
638: else
639: $str = trim(mb_substr($str, 0, $length - 3, 'UTF-8'));
640: $str .= '...';
641: }
642: return $encode?CHtml::encode($str):$str;
643: }
644:
645: 646: 647: 648: 649:
650: public static function deCamelCase($str){
651: $str = preg_replace("/(([a-z])([A-Z])|([A-Z])([A-Z][a-z]))/", "\\2\\4 \\3\\5", $str);
652: return ucfirst($str);
653: }
654:
655: 656: 657: 658: 659: 660:
661: public static function formatDate($date, $width = 'long', $informal = true){
662: if(empty($date)){
663: return '';
664: }
665: if(!is_numeric($date))
666: $date = strtotime($date);
667:
668: $now = getDate();
669: $due = getDate($date);
670:
671:
672: $ret = '';
673:
674: if($informal && $due['year'] == $now['year']){
675: if($due['yday'] == $now['yday'] && $width == 'long') {
676: $ret = Yii::t('app', 'Today');
677: } else if($due['yday'] == $now['yday'] + 1 && $width == 'long') {
678: $ret = Yii::t('app', 'Tomorrow');
679: } else {
680: $ret = Yii::app()->dateFormatter->format(
681: Yii::app()->locale->getDateFormat($width), $date);
682: }
683: } else{
684: $ret = Yii::app()->dateFormatter->format(
685: Yii::app()->locale->getDateFormat($width), $date);
686: }
687: return $ret;
688: }
689:
690: public static function formatTime($date, $width = 'medium'){
691: return Yii::app()->dateFormatter->formatDateTime($date, null, $width);
692: }
693:
694: public static function formatDueDate($date, $dateWidth='long', $timeWidth='short'){
695: if(!is_numeric($date))
696: $date = strtotime($date);
697: return date('l', $date)." ".
698: Yii::app()->dateFormatter->formatDateTime($date, $dateWidth, null).
699: " - ".Yii::app()->dateFormatter->formatDateTime($date, null, $timeWidth);
700: }
701:
702: public static function formatCompleteDate($date){
703: return Yii::app()->dateFormatter->formatDateTime($date, 'long');
704: }
705:
706: 707: 708: 709:
710: public static function isToday ($date) {
711: return date ('Ymd') === date ('Ymd', $date);
712: }
713:
714: public static function isThisYear ($date) {
715: return date ('Y') === date ('Y', $date);
716: }
717:
718:
719:
720:
721:
722: public static function formatDateDynamic ($date) {
723: if (self::isToday ($date)) {
724: return Yii::app()->dateFormatter->format ('h:mm a', $date);
725: } else if (self::isThisYear ($date)) {
726: return Yii::app()->dateFormatter->format ('MMM d', $date);
727: } else {
728: return Yii::app()->dateFormatter->formatDateTime ($date, 'short', null);
729: }
730: }
731:
732: 733: 734: 735: 736: 737:
738: public static function formatLongDateTime($timestamp){
739: if(empty($timestamp))
740: return '';
741: else
742: return Yii::app()->dateFormatter->formatDateTime($timestamp, 'long', 'medium');
743: }
744:
745: 746: 747: 748: 749:
750: public static function formatDateTime($timestamp){
751: if(empty($timestamp)){
752: return '';
753: }else if(Yii::app()->locale->getId() == 'en'){
754: return Yii::app()->dateFormatter->format(
755: Yii::app()->locale->getDateFormat('medium').' '.
756: Yii::app()->locale->getTimeFormat('short'),
757: $timestamp);
758: }759: 760: 761: else {
762: return Yii::app()->dateFormatter->format(
763: Yii::app()->locale->getDateFormat('medium').' '.
764: Yii::app()->locale->getTimeFormat('short'),
765: $timestamp);
766: }
767: }
768:
769: 770: 771: 772: 773:
774: public static function getPlainAbbrMonthNames() {
775: $months = array_map (
776: function($e) { return rtrim($e,'.'); },
777: Yii::app()->getLocale()->getMonthNames ('abbreviated')
778: );
779: return array_values ($months);
780: }
781:
782: 783: 784: 785: 786: 787:
788: public static function parseDate($date){
789: if(Yii::app()->locale->getId() == 'en')
790: return strtotime($date);
791: else
792: return CDateTimeParser::parse($date, Yii::app()->locale->getDateFormat('medium'));
793: }
794:
795: 796: 797: 798: 799:
800: public static function parseDateTime($date,$dateLength = 'medium', $timeLength = 'short'){
801: if($date === null){
802: return null;
803: }elseif(is_numeric($date)){
804: return $date;
805: }elseif(Yii::app()->locale->getId() == 'en'){
806: return strtotime($date);
807: } else {
808: return CDateTimeParser::parse(
809: $date,
810: Yii::app()->locale->getDateFormat($dateLength).' '.
811: Yii::app()->locale->getTimeFormat($timeLength));
812: }
813: }
814:
815: 816: 817: 818: 819: 820: 821:
822: public static function parseCurrency($str, $keepCents){
823:
824: $cents = '';
825: if($keepCents){
826: $str = mb_ereg_match('[\.,]([0-9]{2})$', $str, $matches);
827: $cents = $matches[1];
828: }
829: $str = mb_ereg_replace('[\.,][0-9]{2}$', '', $str);
830: $str = mb_ereg_replace('[^0-9]', '', $str);
831:
832: if(!empty($cents))
833: $str .= ".$cents";
834:
835: return $str;
836: }
837:
838: 839: 840: 841: 842: 843: 844: 845: 846:
847: public static function parseEmail($str){
848: $str = preg_replace('/<\!--BeginOpenedEmail-->(.*?)<\!--EndOpenedEmail-->/s', '', $str);
849: $str = preg_replace('/<\!--BeginActionHeader-->(.*?)<\!--EndActionHeader-->/s', '', $str);
850: $str = strip_tags($str);
851: return $str;
852: }
853:
854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876:
877: public static function replaceVariables(
878: $value, $params, $type = '', $renderFlag=true, $makeLinks=true){
879:
880: if (!is_array ($params)) {
881: $params = array ('model' => $params);
882: }
883:
884: $matches = array();
885: if($renderFlag && ($type === '' || $type === 'text' || $type === 'richtext')){
886: $renderFlag = true;
887: }else{
888: $renderFlag = false;
889: }
890:
891: $shortCodeValues = static::getReplacementTokens($value, $params, $renderFlag, $makeLinks);
892: return strtr($value,$shortCodeValues);
893: }
894:
895: 896: 897: 898: 899: 900:
901: public static function trimText ($text, $limit = 150) {
902: if(mb_strlen($text,'UTF-8') > $limit) {
903: return mb_substr($text, 0,$limit - 3, 'UTF-8').'...';
904: } else {
905: return $text;
906: }
907: }
908:
909: 910: 911: 912:
913: public static function formatCurrency ($value) {
914: return Yii::app()->locale->numberFormatter->formatCurrency (
915: $value, Yii::app()->params->currency);
916: }
917:
918: public static function ucwordsSpecific($string, $delimiters = '', $encoding = NULL) {
919:
920: if ($encoding === NULL) {
921: $encoding = mb_internal_encoding();
922: }
923:
924: if (is_string($delimiters)) {
925: $delimiters = str_split(str_replace(' ', '', $delimiters));
926: }
927:
928: $delimiters_pattern1 = array();
929: $delimiters_replace1 = array();
930: $delimiters_pattern2 = array();
931: $delimiters_replace2 = array();
932: foreach ($delimiters as $delimiter) {
933: $ucDelimiter = $delimiter;
934: $delimiter = strtolower($delimiter);
935: $uniqid = uniqid();
936: $delimiters_pattern1[] = '/' . preg_quote($delimiter) . '/';
937: $delimiters_replace1[] = $delimiter . $uniqid . ' ';
938: $delimiters_pattern2[] = '/' . preg_quote($ucDelimiter . $uniqid . ' ') . '/';
939: $delimiters_replace2[] = $ucDelimiter;
940: $delimiters_cleanup_replace1[] = '/' . preg_quote($delimiter . $uniqid) . ' ' . '/';
941: $delimiters_cleanup_pattern1[] = $delimiter;
942: }
943: $return_string = mb_strtolower($string, $encoding);
944:
945: $return_string = preg_replace($delimiters_pattern1, $delimiters_replace1, $return_string);
946:
947: $words = explode(' ', $return_string);
948:
949: foreach ($words as $index => $word) {
950: $words[$index] = mb_strtoupper(mb_substr($word, 0, 1, $encoding), $encoding) .
951: mb_substr($word, 1, mb_strlen($word, $encoding), $encoding);
952: }
953: $return_string = implode(' ', $words);
954:
955: $return_string = preg_replace($delimiters_pattern2, $delimiters_replace2, $return_string);
956: $return_string = preg_replace(
957: $delimiters_cleanup_replace1, $delimiters_cleanup_pattern1, $return_string);
958:
959: return $return_string;
960: }
961:
962: public static function isFormula ($val) {
963: return preg_match ('/^=/', $val);
964: }
965:
966: public static function isShortcode ($val) {
967: return preg_match ('/^\{.*\}$/', $val);
968: }
969:
970: }
971:
972: ?>
973: