/php-lib/div.php
PHP | 7863 lines | 6206 code | 802 blank | 855 comment | 1077 complexity | 196bfc3d1ac8a7d77e5a643527217da6 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * [[]] Div PHP Template Engine
- *
- * Div (division) is a template engine for PHP 5.x or higher and it is a social project
- * without spirit of lucre financed by Pragres (http://pragres.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program as the file LICENSE.txt; if not, please see
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
- *
- * @author Rafael Rodriguez Ramirez <rafa@pragres.com>
- * @version : 4.5
- * @link http://divengine.com
- */
- /**
- * Constants
- *
- * PACKAGES The path of templates's root directory.
- * DIV_DEFAULT_TPL_FILE_EXT The default extension for template files
- * DIV_DEFAULT_DATA_FILE_EXT The default extension for data files
- * DIV_MAX_PARSE_CYCLES The max number of cycles of the parser (to prevent infinite loop and more)
- * DIV_MAX_FILENAME_SIZE The max size of file name or dir name in your operating system
- */
- if (! defined('PACKAGES'))
- define('PACKAGES', './');
- if (! defined('DIV_DEFAULT_TPL_FILE_EXT'))
- define('DIV_DEFAULT_TPL_FILE_EXT', 'tpl');
- if (! defined('DIV_DEFAULT_DATA_FILE_EXT'))
- define('DIV_DEFAULT_DATA_FILE_EXT', 'json');
- if (! defined('DIV_MAX_PARSE_CYCLES'))
- define('DIV_MAX_PARSE_CYCLES', 100);
- if (! defined('DIV_MAX_FILENAME_SIZE'))
- define('DIV_MAX_FILENAME_SIZE', 250);
- define('DIV_PHP_ALLOWED_FUNCTIONS', 'isset,empty,is_null,is_numeric,is_bool,is_integer,is_double,' . 'sizeof,is_finite,is_float,is_infinite,is_int,is_long,is_nan,' . 'is_real,is_scalar,is_string,mt_rand,mt_srand,mt_getrandmax,' . 'rand,urlencode,urldecode,uniqid,date,time,intval,htmlspecialchars,' . 'htmlspecialchars_decode,strtr,strpos,str_replace,str_ireplace,' . 'substr,sprintf,abs,acos,acosh,asin,atan2,atanh,base_convert,' . 'bindec,ceil,cos,cosh,decbin,dechex,decoct,deg2rad,exp,expm1,' . 'floor,fmod,getrandmax,hexdec,hypot,lcg_value,log10,log1p,log,' . 'max,min,octdec,pi,pow,rad2deg,rand,round,sin,sinh,sqrt,srand,' . 'tan,tanh,cal_days_in_month,cal_from_jd,cal_info,cal_to_jd,' . 'easter_date,easter_days,frenchtojd,gregoriantojd,jddayofweek,' . 'jdmonthname,jdtofrench,jdtogregorian,jdtojewish,jdtojulian,' . 'jdtounix,jewishtojd,jewishtojd,unixtojd,checkdate,' . 'date_default_timezone_get,strtotime,date_sunset,gmdate,gmmktime,' . 'gmstrftime,idate,microtime,mktime,strftime,strptime,strtotime,' . 'timezone_name_from_abbr,timezone_version_get,bcadd,bccomp,' . 'bcdiv,bcmod,bcmul,bcpow,bcpowmod,bcscale,bcsqrt,bcsub,addcslashes,' . 'addslashes,bin2hex,chop,chr,chunk_split,convert_cyr_string,' . 'convert_uudecode,convert_uuencode,count,count_chars,crc32,crypt,' . 'hebrev,hebrevc,hex2bin,html_entity_decode,htmlentities,' . 'htmlspecialchars_decode,htmlspecialchars,lcfirst,levenshtein,' . 'ltrim,md5,metaphone,money_format,nl_langinfo,nl2br,number_format,' . 'ord,quoted_printable_decode,quoted_printable_encode,quotemeta,' . 'rtrim,sha1,similar_text,soundex,sprintf,str_pad,str_repeat,' . 'str_rot13,str_shuffle,strcasecmp,strchr,strcmp,strcoll,strcspn,' . 'strip_tags,stripcslashes,stripos,stripslashes,stristr,strlen,' . 'strnatcasecmp,strnatcmp,strncasecmp,strncmp,strpbrk,strrchr,' . 'strrev,strripos,strrpos,strspn,strtolower,strtoupper,strtr,' . 'substr_compare,substr_count,substr_replace,trim,ucfirst,ucwords,' . 'wordwrap,floatval,strval,implode,explode');
- define('DIV_PHP_VALID_TOKENS_FOR_EXPRESSIONS', 'T_ARRAY,T_ARRAY_CAST,T_BOOLEAN_AND,T_BOOLEAN_OR,T_BOOL_CAST,' . 'T_CHARACTER,T_CONSTANT_ENCAPSED_STRING,T_DNUMBER,T_DOUBLE_CAST,' . 'T_EMPTY,T_INT_CAST,T_ISSET,T_IS_EQUAL,T_IS_GREATER_OR_EQUAL,' . 'T_SR,T_IS_IDENTICAL,T_IS_NOT_EQUAL,T_IS_NOT_IDENTICAL,' . 'T_IS_SMALLER_OR_EQUAL,T_LNUMBER,T_LOGICAL_AND,T_LOGICAL_OR,T_LOGICAL_XOR,' . 'T_SL,T_SL_EQUAL,T_SR_EQUAL,T_STRING_CAST,T_STRING_VARNAME,T_VARIABLE,' . 'T_WHITESPACE,T_CURLY_OPEN,T_INC,T_COMMENT,T_DOUBLE_ARROW,' . 'T_ENCAPSED_AND_WHITESPACE');
- define('DIV_PHP_VALID_TOKENS_FOR_MACROS', 'T_AS,T_DO,T_DOUBLE_COLON,T_ECHO,T_ELSE,T_ELSEIF,T_FOR,T_FOREACH,T_IF,' . 'T_MOD_EQUAL,T_MUL_EQUAL,T_OBJECT_OPERATOR,T_NUM_STRING,T_OR_EQUAL,' . 'T_PAAMAYIM_NEKUDOTAYIM,T_PLUS_EQUAL,T_PRINT,' . 'T_START_HEREDOC,T_SWITCH,T_WHILE,' . 'T_ENDIF,T_ENDFOR,T_ENDFOREACH,T_ENDSWITCH,T_ENDWHILE,T_END_HEREDOC,' . 'T_PAAMAYIM_NEKUDOTAYIM');
- define('DIV_PHP_ALLOWED_METHODS', 'getRanges,asThis,atLeastOneString,getLastKeyOfArray,getCountOfParagraphs,getCountOfSentences,getCountOfWords,' . 'htmlToText,isArrayOfArray,isArrayOfObjects,isCli,isNumericList,jsonDecode,jsonEncode,isString,mixedBool');
- define('DIV_ERROR_WARNING', 'WARNING');
- define('DIV_ERROR_FATAL', 'FATAL');
- define('DIV_METHOD_NOT_EXISTS', 'DIV_METHOD_NOT_EXISTS');
- define('DIV_UNICODE_ERROR', - 1);
- define('DIV_MOMENT_BEFORE_PARSE', 'DIV_MOMENT_BEFORE_PARSE');
- define('DIV_MOMENT_AFTER_PARSE', 'DIV_MOMENT_AFTER_PARSE');
- define('DIV_MOMENT_AFTER_INCLUDE', 'DIV_MOMENT_AFTER_INCLUDE');
- define('DIV_MOMENT_AFTER_REPLACE', 'DIV_MOMENT_AFTER_REPLACE');
- // ------------------------------------- D E F A U L T D I A L E C T --------------------------------------//
- if (! defined('DIV_TAG_REPLACEMENT_PREFIX'))
- define('DIV_TAG_REPLACEMENT_PREFIX', '{'); // Variables
- if (! defined('DIV_TAG_REPLACEMENT_SUFFIX'))
- define('DIV_TAG_REPLACEMENT_SUFFIX', '}');
- if (! defined('DIV_TAG_MULTI_MODIFIERS_PREFIX'))
- define('DIV_TAG_MULTI_MODIFIERS_PREFIX', '{$');
- if (! defined('DIV_TAG_MULTI_MODIFIERS_OPERATOR'))
- define('DIV_TAG_MULTI_MODIFIERS_OPERATOR', '|');
- if (! defined('DIV_TAG_MULTI_MODIFIERS_SEPARATOR'))
- define('DIV_TAG_MULTI_MODIFIERS_SEPARATOR', '|');
- if (! defined('DIV_TAG_MULTI_MODIFIERS_SUFFIX'))
- define('DIV_TAG_MULTI_MODIFIERS_SUFFIX', '|}');
- if (! defined('DIV_TAG_SUBMATCH_SEPARATOR'))
- define('DIV_TAG_SUBMATCH_SEPARATOR', ':');
- if (! defined('DIV_TAG_MODIFIER_SIMPLE'))
- define('DIV_TAG_MODIFIER_SIMPLE', '$'); // Variable's modifiers
- if (! defined('DIV_TAG_MODIFIER_CAPITALIZE_FIRST'))
- define('DIV_TAG_MODIFIER_CAPITALIZE_FIRST', '^');
- if (! defined('DIV_TAG_MODIFIER_CAPITALIZE_WORDS'))
- define('DIV_TAG_MODIFIER_CAPITALIZE_WORDS', '^^');
- if (! defined('DIV_TAG_MODIFIER_UPPERCASE'))
- define('DIV_TAG_MODIFIER_UPPERCASE', '^^^');
- if (! defined('DIV_TAG_MODIFIER_LOWERCASE'))
- define('DIV_TAG_MODIFIER_LOWERCASE', '_');
- if (! defined('DIV_TAG_MODIFIER_LENGTH'))
- define('DIV_TAG_MODIFIER_LENGTH', '%');
- if (! defined('DIV_TAG_MODIFIER_COUNT_WORDS'))
- define('DIV_TAG_MODIFIER_COUNT_WORDS', '%%');
- if (! defined('DIV_TAG_MODIFIER_COUNT_SENTENCES'))
- define('DIV_TAG_MODIFIER_COUNT_SENTENCES', '%%%');
- if (! defined('DIV_TAG_MODIFIER_COUNT_PARAGRAPHS'))
- define('DIV_TAG_MODIFIER_COUNT_PARAGRAPHS', '%%%%');
- if (! defined('DIV_TAG_MODIFIER_ENCODE_URL'))
- define('DIV_TAG_MODIFIER_ENCODE_URL', '&');
- if (! defined('DIV_TAG_MODIFIER_ENCODE_RAW_URL'))
- define('DIV_TAG_MODIFIER_ENCODE_RAW_URL', '&&');
- if (! defined('DIV_TAG_MODIFIER_ENCODE_JSON'))
- define('DIV_TAG_MODIFIER_ENCODE_JSON', 'json:');
- if (! defined('DIV_TAG_MODIFIER_HTML_ENTITIES'))
- define('DIV_TAG_MODIFIER_HTML_ENTITIES', 'html:');
- if (! defined('DIV_TAG_MODIFIER_NL2BR'))
- define('DIV_TAG_MODIFIER_NL2BR', 'br:');
- if (! defined('DIV_TAG_MODIFIER_TRUNCATE'))
- define('DIV_TAG_MODIFIER_TRUNCATE', '~');
- if (! defined('DIV_TAG_MODIFIER_WORDWRAP'))
- define('DIV_TAG_MODIFIER_WORDWRAP', '/');
- if (! defined('DIV_TAG_MODIFIER_SUBSTRING_SEPARATOR'))
- define('DIV_TAG_MODIFIER_SUBSTRING_SEPARATOR', ',');
- if (! defined('DIV_TAG_MODIFIER_SINGLE_QUOTES'))
- define('DIV_TAG_MODIFIER_SINGLE_QUOTES', "'");
- if (! defined('DIV_TAG_MODIFIER_JS'))
- define('DIV_TAG_MODIFIER_JS', "js:");
- if (! defined('DIV_TAG_MODIFIER_FORMAT'))
- define('DIV_TAG_MODIFIER_FORMAT', '');
- if (! defined('DIV_TAG_DATE_FORMAT_PREFIX'))
- define('DIV_TAG_DATE_FORMAT_PREFIX', '{/'); // Data format
- if (! defined('DIV_TAG_DATE_FORMAT_SUFFIX'))
- define('DIV_TAG_DATE_FORMAT_SUFFIX', '/}');
- if (! defined('DIV_TAG_DATE_FORMAT_SEPARATOR'))
- define('DIV_TAG_DATE_FORMAT_SEPARATOR', ':');
- if (! defined('DIV_TAG_NUMBER_FORMAT_PREFIX'))
- define('DIV_TAG_NUMBER_FORMAT_PREFIX', '{#');
- if (! defined('DIV_TAG_NUMBER_FORMAT_SUFFIX'))
- define('DIV_TAG_NUMBER_FORMAT_SUFFIX', '#}');
- if (! defined('DIV_TAG_NUMBER_FORMAT_SEPARATOR'))
- define('DIV_TAG_NUMBER_FORMAT_SEPARATOR', ':');
- if (! defined('DIV_TAG_FORMULA_BEGIN'))
- define('DIV_TAG_FORMULA_BEGIN', '(#'); // Formulas
- if (! defined('DIV_TAG_FORMULA_END'))
- define('DIV_TAG_FORMULA_END', '#)');
- if (! defined('DIV_TAG_FORMULA_FORMAT_SEPARATOR'))
- define('DIV_TAG_FORMULA_FORMAT_SEPARATOR', ':');
- if (! defined('DIV_TAG_SUBPARSER_BEGIN_PREFIX'))
- define('DIV_TAG_SUBPARSER_BEGIN_PREFIX', '{'); // Sub-parsers
- if (! defined('DIV_TAG_SUBPARSER_BEGIN_SUFFIX'))
- define('DIV_TAG_SUBPARSER_BEGIN_SUFFIX', '}');
- if (! defined('DIV_TAG_SUBPARSER_END_PREFIX'))
- define('DIV_TAG_SUBPARSER_END_PREFIX', '{/');
- if (! defined('DIV_TAG_SUBPARSER_END_SUFFIX'))
- define('DIV_TAG_SUBPARSER_END_SUFFIX', '}');
- if (! defined('DIV_TAG_IGNORE_BEGIN'))
- define('DIV_TAG_IGNORE_BEGIN', '{ignore}'); // Ignored parts
- if (! defined('DIV_TAG_IGNORE_END'))
- define('DIV_TAG_IGNORE_END', '{/ignore}');
- if (! defined('DIV_TAG_COMMENT_BEGIN'))
- define('DIV_TAG_COMMENT_BEGIN', '<!--{'); // Comments
- if (! defined('DIV_TAG_COMMENT_END'))
- define('DIV_TAG_COMMENT_END', '}-->');
- if (! defined('DIV_TAG_TXT_BEGIN'))
- define('DIV_TAG_TXT_BEGIN', '{txt}'); // HTML to Plain text
- if (! defined('DIV_TAG_TXT_END'))
- define('DIV_TAG_TXT_END', '{/txt}');
- if (! defined('DIV_TAG_TXT_WIDTH_SEPARATOR'))
- define('DIV_TAG_TXT_WIDTH_SEPARATOR', '=>');
- if (! defined('DIV_TAG_STRIP_BEGIN'))
- define('DIV_TAG_STRIP_BEGIN', '{strip}'); // Strip
- if (! defined('DIV_TAG_STRIP_END'))
- define('DIV_TAG_STRIP_END', '{/strip}');
- if (! defined('DIV_TAG_LOOP_BEGIN_PREFIX'))
- define('DIV_TAG_LOOP_BEGIN_PREFIX', '[$'); // Loops
- if (! defined('DIV_TAG_LOOP_BEGIN_SUFFIX'))
- define('DIV_TAG_LOOP_BEGIN_SUFFIX', ']');
- if (! defined('DIV_TAG_LOOP_END_PREFIX'))
- define('DIV_TAG_LOOP_END_PREFIX', '[/$');
- if (! defined('DIV_TAG_LOOP_END_SUFFIX'))
- define('DIV_TAG_LOOP_END_SUFFIX', ']');
- if (! defined('DIV_TAG_EMPTY'))
- define('DIV_TAG_EMPTY', '@empty@');
- if (! defined('DIV_TAG_BREAK'))
- define('DIV_TAG_BREAK', '@break@');
- if (! defined('DIV_TAG_LOOP_VAR_SEPARATOR'))
- define('DIV_TAG_LOOP_VAR_SEPARATOR', '=>');
- if (! defined('DIV_TAG_ITERATION_BEGIN_PREFIX'))
- define('DIV_TAG_ITERATION_BEGIN_PREFIX', '[:'); // Iterations
- if (! defined('DIV_TAG_ITERATION_BEGIN_SUFFIX'))
- define('DIV_TAG_ITERATION_BEGIN_SUFFIX', ':]');
- if (! defined('DIV_TAG_ITERATION_END'))
- define('DIV_TAG_ITERATION_END', '[/]');
- if (! defined('DIV_TAG_ITERATION_PARAM_SEPARATOR'))
- define('DIV_TAG_ITERATION_PARAM_SEPARATOR', ',');
- if (! defined('DIV_TAG_CONDITIONAL_TRUE_BEGIN_PREFIX'))
- define('DIV_TAG_CONDITIONAL_TRUE_BEGIN_PREFIX', '?$'); // Conditional parts
- if (! defined('DIV_TAG_CONDITIONAL_TRUE_BEGIN_SUFFIX'))
- define('DIV_TAG_CONDITIONAL_TRUE_BEGIN_SUFFIX', '');
- if (! defined('DIV_TAG_CONDITIONAL_TRUE_END_PREFIX'))
- define('DIV_TAG_CONDITIONAL_TRUE_END_PREFIX', '$');
- if (! defined('DIV_TAG_CONDITIONAL_TRUE_END_SUFFIX'))
- define('DIV_TAG_CONDITIONAL_TRUE_END_SUFFIX', '?');
- if (! defined('DIV_TAG_CONDITIONAL_FALSE_BEGIN_PREFIX'))
- define('DIV_TAG_CONDITIONAL_FALSE_BEGIN_PREFIX', '!$');
- if (! defined('DIV_TAG_CONDITIONAL_FALSE_BEGIN_SUFFIX'))
- define('DIV_TAG_CONDITIONAL_FALSE_BEGIN_SUFFIX', '');
- if (! defined('DIV_TAG_CONDITIONAL_FALSE_END_PREFIX'))
- define('DIV_TAG_CONDITIONAL_FALSE_END_PREFIX', '$');
- if (! defined('DIV_TAG_CONDITIONAL_FALSE_END_SUFFIX'))
- define('DIV_TAG_CONDITIONAL_FALSE_END_SUFFIX', '!');
- if (! defined('DIV_TAG_ELSE'))
- define('DIV_TAG_ELSE', '@else@');
- if (! defined('DIV_TAG_CONDITIONS_BEGIN_PREFIX'))
- define('DIV_TAG_CONDITIONS_BEGIN_PREFIX', '{?('); // Conditions
- if (! defined('DIV_TAG_CONDITIONS_BEGIN_SUFFIX'))
- define('DIV_TAG_CONDITIONS_BEGIN_SUFFIX', ')?}');
- if (! defined('DIV_TAG_CONDITIONS_END'))
- define('DIV_TAG_CONDITIONS_END', '{/?}');
- if (! defined('DIV_TAG_TPLVAR_BEGIN'))
- define('DIV_TAG_TPLVAR_BEGIN', '{='); // Template vars
- if (! defined('DIV_TAG_TPLVAR_END'))
- define('DIV_TAG_TPLVAR_END', '=}');
- if (! defined('DIV_TAG_TPLVAR_ASSIGN_OPERATOR'))
- define('DIV_TAG_TPLVAR_ASSIGN_OPERATOR', ':');
- if (! defined('DIV_TAG_TPLVAR_PROTECTOR'))
- define('DIV_TAG_TPLVAR_PROTECTOR', '*');
- if (! defined('DIV_TAG_DEFAULT_REPLACEMENT_BEGIN'))
- define('DIV_TAG_DEFAULT_REPLACEMENT_BEGIN', '{@'); // Default replacement
- if (! defined('DIV_TAG_DEFAULT_REPLACEMENT_END'))
- define('DIV_TAG_DEFAULT_REPLACEMENT_END', '@}');
- if (! defined('DIV_TAG_INCLUDE_BEGIN'))
- define('DIV_TAG_INCLUDE_BEGIN', '{% '); // Includes
- if (! defined('DIV_TAG_INCLUDE_END'))
- define('DIV_TAG_INCLUDE_END', ' %}');
- if (! defined('DIV_TAG_PREPROCESSED_BEGIN'))
- define('DIV_TAG_PREPROCESSED_BEGIN', '{%% '); // Pre-processed
- if (! defined('DIV_TAG_PREPROCESSED_END'))
- define('DIV_TAG_PREPROCESSED_END', ' %%}');
- if (! defined('DIV_TAG_CAPSULE_BEGIN_PREFIX'))
- define('DIV_TAG_CAPSULE_BEGIN_PREFIX', '[['); // Capsules
- if (! defined('DIV_TAG_CAPSULE_BEGIN_SUFFIX'))
- define('DIV_TAG_CAPSULE_BEGIN_SUFFIX', '');
- if (! defined('DIV_TAG_CAPSULE_END_PREFIX'))
- define('DIV_TAG_CAPSULE_END_PREFIX', '');
- if (! defined('DIV_TAG_CAPSULE_END_SUFFIX'))
- define('DIV_TAG_CAPSULE_END_SUFFIX', ']]');
- if (! defined('DIV_TAG_MULTI_REPLACEMENT_BEGIN_PREFIX'))
- define('DIV_TAG_MULTI_REPLACEMENT_BEGIN_PREFIX', '{:'); // Multi replacements
- if (! defined('DIV_TAG_MULTI_REPLACEMENT_BEGIN_SUFFIX'))
- define('DIV_TAG_MULTI_REPLACEMENT_BEGIN_SUFFIX', '}');
- if (! defined('DIV_TAG_MULTI_REPLACEMENT_END_PREFIX'))
- define('DIV_TAG_MULTI_REPLACEMENT_END_PREFIX', '{:/');
- if (! defined('DIV_TAG_MULTI_REPLACEMENT_END_SUFFIX'))
- define('DIV_TAG_MULTI_REPLACEMENT_END_SUFFIX', '}');
- if (! defined('DIV_TAG_FRIENDLY_BEGIN'))
- define('DIV_TAG_FRIENDLY_BEGIN', '<!--|'); // Friendly tags
- if (! defined('DIV_TAG_FRIENDLY_END'))
- define('DIV_TAG_FRIENDLY_END', '|-->');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_COUNT'))
- define('DIV_TAG_AGGREGATE_FUNCTION_COUNT', 'count'); // Aggregate functions
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_MAX'))
- define('DIV_TAG_AGGREGATE_FUNCTION_MAX', 'max');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_MIN'))
- define('DIV_TAG_AGGREGATE_FUNCTION_MIN', 'min');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_SUM'))
- define('DIV_TAG_AGGREGATE_FUNCTION_SUM', 'sum');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_AVG'))
- define('DIV_TAG_AGGREGATE_FUNCTION_AVG', 'avg');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_SEPARATOR'))
- define('DIV_TAG_AGGREGATE_FUNCTION_SEPARATOR', ':');
- if (! defined('DIV_TAG_AGGREGATE_FUNCTION_PROPERTY_SEPARATOR'))
- define('DIV_TAG_AGGREGATE_FUNCTION_PROPERTY_SEPARATOR', '-');
- if (! defined('DIV_TAG_LOCATION_BEGIN'))
- define('DIV_TAG_LOCATION_BEGIN', '(( '); // Locations
- if (! defined('DIV_TAG_LOCATION_END'))
- define('DIV_TAG_LOCATION_END', ' ))');
- if (! defined('DIV_TAG_LOCATION_CONTENT_BEGIN_PREFIX'))
- define('DIV_TAG_LOCATION_CONTENT_BEGIN_PREFIX', '{{');
- if (! defined('DIV_TAG_LOCATION_CONTENT_BEGIN_SUFFIX'))
- define('DIV_TAG_LOCATION_CONTENT_BEGIN_SUFFIX', '');
- if (! defined('DIV_TAG_LOCATION_CONTENT_END_PREFIX'))
- define('DIV_TAG_LOCATION_CONTENT_END_PREFIX', '');
- if (! defined('DIV_TAG_LOCATION_CONTENT_END_SUFFIX'))
- define('DIV_TAG_LOCATION_CONTENT_END_SUFFIX', '}}');
- if (! defined('DIV_TAG_MACRO_BEGIN'))
- define('DIV_TAG_MACRO_BEGIN', '<?'); // Macros
- if (! defined('DIV_TAG_MACRO_END'))
- define('DIV_TAG_MACRO_END', '?>');
- if (! defined('DIV_TAG_SPECIAL_REPLACE_NEW_LINE'))
- define('DIV_TAG_SPECIAL_REPLACE_NEW_LINE', '{\n}'); // Special replacements
- if (! defined('DIV_TAG_SPECIAL_REPLACE_CAR_RETURN'))
- define('DIV_TAG_SPECIAL_REPLACE_CAR_RETURN', '{\r}');
- if (! defined('DIV_TAG_SPECIAL_REPLACE_HORIZONTAL_TAB'))
- define('DIV_TAG_SPECIAL_REPLACE_HORIZONTAL_TAB', '{\t}');
- if (! defined('DIV_TAG_SPECIAL_REPLACE_VERTICAL_TAB'))
- define('DIV_TAG_SPECIAL_REPLACE_VERTICAL_TAB', '{\v}');
- if (! defined('DIV_TAG_SPECIAL_REPLACE_NEXT_PAGE'))
- define('DIV_TAG_SPECIAL_REPLACE_NEXT_PAGE', '{\f}');
- if (! defined('DIV_TAG_SPECIAL_REPLACE_DOLLAR_SYMBOL'))
- define('DIV_TAG_SPECIAL_REPLACE_DOLLAR_SYMBOL', '{\$}');
- if (! defined('DIV_TAG_TEASER_BREAK'))
- define('DIV_TAG_TEASER_BREAK', '<!--break-->');
- define('DIV_DEFAULT_DIALECT', '{
- \'DIV_TAG_REPLACEMENT_PREFIX\' : \'{\', \'DIV_TAG_REPLACEMENT_SUFFIX\' : \'}\',
- \'DIV_TAG_MULTI_MODIFIERS_PREFIX\' : \'{$\', \'DIV_TAG_MULTI_MODIFIERS_SEPARATOR\' : \'|\',
- \'DIV_TAG_MULTI_MODIFIERS_OPERATOR\' : \'|\', \'DIV_TAG_MULTI_MODIFIERS_SUFFIX\' : \'|}\',
- \'DIV_TAG_SUBMATCH_SEPARATOR\' : \':\', \'DIV_TAG_MODIFIER_SIMPLE\' : \'$\',
- \'DIV_TAG_MODIFIER_CAPITALIZE_FIRST\' : \'^\', \'DIV_TAG_MODIFIER_CAPITALIZE_WORDS\' : \'^^\',
- \'DIV_TAG_MODIFIER_UPPERCASE\' : \'^^^\', \'DIV_TAG_MODIFIER_LOWERCASE\' : \'_\',
- \'DIV_TAG_MODIFIER_LENGTH\' : \'%\', \'DIV_TAG_MODIFIER_COUNT_WORDS\' : \'%%\',
- \'DIV_TAG_MODIFIER_COUNT_SENTENCES\' : \'%%%\', \'DIV_TAG_MODIFIER_COUNT_PARAGRAPHS\' : \'%%%%\',
- \'DIV_TAG_MODIFIER_ENCODE_URL\' : \'&\', \'DIV_TAG_MODIFIER_ENCODE_RAW_URL\' : \'&&\',
- \'DIV_TAG_MODIFIER_ENCODE_JSON\' : \'json:\', \'DIV_TAG_MODIFIER_HTML_ENTITIES\' : \'html:\',
- \'DIV_TAG_MODIFIER_NL2BR\' : \'br:\', \'DIV_TAG_MODIFIER_TRUNCATE\' : \'~\',
- \'DIV_TAG_MODIFIER_WORDWRAP\' : \'/\', \'DIV_TAG_MODIFIER_SUBSTRING_SEPARATOR\' : \',\',
- \'DIV_TAG_MODIFIER_SINGLE_QUOTES\' : "\'", \'DIV_TAG_MODIFIER_JS\' : \'js:\',
- \'DIV_TAG_MODIFIER_FORMAT\' : \'\', \'DIV_TAG_DATE_FORMAT_PREFIX\' : \'{/\',
- \'DIV_TAG_DATE_FORMAT_SUFFIX\' : \'/}\', \'DIV_TAG_DATE_FORMAT_SEPARATOR\' : \':\',
- \'DIV_TAG_NUMBER_FORMAT_PREFIX\' : \'{#\', \'DIV_TAG_NUMBER_FORMAT_SUFFIX\' : \'#}\',
- \'DIV_TAG_NUMBER_FORMAT_SEPARATOR\' : \':\', \'DIV_TAG_FORMULA_BEGIN\' : \'(#\',
- \'DIV_TAG_FORMULA_END\' : \'#)\', \'DIV_TAG_FORMULA_FORMAT_SEPARATOR\' : \':\',
- \'DIV_TAG_SUBPARSER_BEGIN_PREFIX\' : \'{\', \'DIV_TAG_SUBPARSER_BEGIN_SUFFIX\' : \'}\',
- \'DIV_TAG_SUBPARSER_END_PREFIX\' : \'{/\', \'DIV_TAG_SUBPARSER_END_SUFFIX\' : \'}\',
- \'DIV_TAG_IGNORE_BEGIN\' : \'{ignore}\', \'DIV_TAG_IGNORE_END\' : \'{/ignore}\',
- \'DIV_TAG_COMMENT_BEGIN\' : \'<!--{\', \'DIV_TAG_COMMENT_END\' : \'}-->\',
- \'DIV_TAG_TXT_BEGIN\' : \'{txt}\', \'DIV_TAG_TXT_END\' : \'{/txt}\',
- \'DIV_TAG_TXT_WIDTH_SEPARATOR\' : \'=>\', \'DIV_TAG_STRIP_BEGIN\' : \'{strip}\',
- \'DIV_TAG_STRIP_END\' : \'{/strip}\', \'DIV_TAG_LOOP_BEGIN_PREFIX\' : \'[$\',
- \'DIV_TAG_LOOP_BEGIN_SUFFIX\' : \']\', \'DIV_TAG_LOOP_END_PREFIX\' : \'[/$\',
- \'DIV_TAG_LOOP_END_SUFFIX\' : \']\', \'DIV_TAG_EMPTY\' : \'@empty@\',
- \'DIV_TAG_BREAK\' : \'@break@\', \'DIV_TAG_LOOP_VAR_SEPARATOR\' : \'=>\',
- \'DIV_TAG_ITERATION_BEGIN_PREFIX\' : \'[:\', \'DIV_TAG_ITERATION_BEGIN_SUFFIX\' : \':]\',
- \'DIV_TAG_ITERATION_END\' : \'[/]\', \'DIV_TAG_ITERATION_PARAM_SEPARATOR\' : \',\',
- \'DIV_TAG_CONDITIONAL_TRUE_BEGIN_PREFIX\' : \'?$\', \'DIV_TAG_CONDITIONAL_TRUE_BEGIN_SUFFIX\' : \'\',
- \'DIV_TAG_CONDITIONAL_TRUE_END_PREFIX\' : \'$\', \'DIV_TAG_CONDITIONAL_TRUE_END_SUFFIX\' : \'?\',
- \'DIV_TAG_CONDITIONAL_FALSE_BEGIN_PREFIX\' : \'!$\', \'DIV_TAG_CONDITIONAL_FALSE_BEGIN_SUFFIX\' : \'\',
- \'DIV_TAG_CONDITIONAL_FALSE_END_PREFIX\' : \'$\', \'DIV_TAG_CONDITIONAL_FALSE_END_SUFFIX\' : \'!\',
- \'DIV_TAG_ELSE\' : \'@else@\', \'DIV_TAG_CONDITIONS_BEGIN_PREFIX\' : \'{?(\',
- \'DIV_TAG_CONDITIONS_BEGIN_SUFFIX\' : \')?}\', \'DIV_TAG_CONDITIONS_END\' : \'{/?}\',
- \'DIV_TAG_TPLVAR_BEGIN\' : \'{=\', \'DIV_TAG_TPLVAR_END\' : \'=}\',
- \'DIV_TAG_TPLVAR_ASSIGN_OPERATOR\' : \':\', \'DIV_TAG_TPLVAR_PROTECTOR\' : \'*\',
- \'DIV_TAG_DEFAULT_REPLACEMENT_BEGIN\' : \'{@\', \'DIV_TAG_DEFAULT_REPLACEMENT_END\' : \'@}\',
- \'DIV_TAG_INCLUDE_BEGIN\' : \'{% \', \'DIV_TAG_INCLUDE_END\' : \' %}\',
- \'DIV_TAG_PREPROCESSED_BEGIN\' : \'{%% \', \'DIV_TAG_PREPROCESSED_END\' : \' %%}\',
- \'DIV_TAG_CAPSULE_BEGIN_PREFIX\' : \'[[\', \'DIV_TAG_CAPSULE_BEGIN_SUFFIX\' : \'\',
- \'DIV_TAG_CAPSULE_END_PREFIX\' : \'\', \'DIV_TAG_CAPSULE_END_SUFFIX\' : \']]\',
- \'DIV_TAG_MULTI_REPLACEMENT_BEGIN_PREFIX\' : \'{:\', \'DIV_TAG_MULTI_REPLACEMENT_BEGIN_SUFFIX\' : \'}\',
- \'DIV_TAG_MULTI_REPLACEMENT_END_PREFIX\' : \'{:/\', \'DIV_TAG_MULTI_REPLACEMENT_END_SUFFIX\' : \'}\',
- \'DIV_TAG_FRIENDLY_BEGIN\' : \'<!--|\', \'DIV_TAG_FRIENDLY_END\' : \'|-->\',
- \'DIV_TAG_AGGREGATE_FUNCTION_COUNT\' : \'count\', \'DIV_TAG_AGGREGATE_FUNCTION_MAX\' : \'max\',
- \'DIV_TAG_AGGREGATE_FUNCTION_MIN\' : \'min\', \'DIV_TAG_AGGREGATE_FUNCTION_SUM\' : \'sum\',
- \'DIV_TAG_AGGREGATE_FUNCTION_AVG\' : \'avg\', \'DIV_TAG_AGGREGATE_FUNCTION_SEPARATOR\' : \':\',
- \'DIV_TAG_AGGREGATE_FUNCTION_PROPERTY_SEPARATOR\' : \'-\', \'DIV_TAG_LOCATION_BEGIN\' : \'(( \',
- \'DIV_TAG_LOCATION_END\' : \' ))\', \'DIV_TAG_LOCATION_CONTENT_BEGIN_PREFIX\' : \'{{\',
- \'DIV_TAG_LOCATION_CONTENT_BEGIN_SUFFIX\' : \'\', \'DIV_TAG_LOCATION_CONTENT_END_PREFIX\' : \'\',
- \'DIV_TAG_LOCATION_CONTENT_END_SUFFIX\' : \'}}\', \'DIV_TAG_MACRO_BEGIN\' : \'<?\',
- \'DIV_TAG_MACRO_END\' : \'?>\', \'DIV_TAG_SPECIAL_REPLACE_NEW_LINE\' : \'{\\n}\',
- \'DIV_TAG_SPECIAL_REPLACE_CAR_RETURN\' : \'{\\r}\', \'DIV_TAG_SPECIAL_REPLACE_HORIZONTAL_TAB\' : \'{\\t}\',
- \'DIV_TAG_SPECIAL_REPLACE_VERTICAL_TAB\' : \'{\\v}\', \'DIV_TAG_SPECIAL_REPLACE_NEXT_PAGE\' : \'{\\f}\',
- \'DIV_TAG_SPECIAL_REPLACE_DOLLAR_SYMBOL\' : \'{\\$}\', \'DIV_TAG_TEASER_BREAK\' : \'<!--break-->\'
- }');
- // --------------------------------------------------------------------------------------------------------------------------------------//
- define('DIV_TEMPLATE_FOR_DOCS', '
- @_DIALECT = ' . uniqid() . '
- <html>
- <head>
- <title>{$title}</title>
- <style type="text/css">
- body {background: #656565; font-family: Verdana;}
- div.section {background: white; margin-top: 20px; padding: 10px; width: 780px;}
- .section h2 {color: white; font-size: 24px;font-weight: bold; margin-left: -30px;padding-bottom: 5px; padding-left: 30px;padding-top: 5px; background: black; border-left: 10px solid gray;}
- h1 {color: white;}
- table.data td {padding: 5px;border-bottom: 1px solid gray; border-right: 1px solid gray;}
- table.data th {padding: 5px;color: white; background: black;}
- .code {padding: 0px; margin: 0px; background: #eeeeee; color: black; font-family: "Courier New"; text-align: left; font-size: 13px;}
- .code .line {text-align:right; background: gray; color: white; border-right: 2px solid black; padding-right: 5px;}
- table.index, table.index a, table.index a:visited {color:white;}
- div.header {color: white;}
- .template-description{background: #eeeeee; padding: 10px;}
- </style>
- </head>
- <body>
- <label><a href="#header" style="position: fixed; bottom: 5px; right: 5px;color: white;">Index</a></label>
- <table width="750" align="center"><tr><td valign="top">
- <div id = "header" class = "header">
- <h1>{$title}</h1>
- <p>Generated by Div at {/div.now:Y-m-d H:i:s/}</p>
- <h2>Index</h2>
- <table class="index data" width="100%">
- <tr><th></th><th>Name</th><th>Description</th><th>Version</th></tr>
- [$docs]
- <tr><td>{$_order}</td>
- <td><a href="#{$_key}">?$name {$name} $name?</a></td>
- <td>?$description {$description} $description?</td>
- <td>?$version {$version} $version?</td></tr>
- [/$docs]
- </table>
- </div>
-
- {= repl1: [["<",""],[">",""]] =}
-
- [$docs]
- <div class="section">
- <h2 id = "{$_key}">?$icon {$icon} $icon? {$name}</h2>
- <table width="100%">
- <tr><td align="right">Path:</td><td>{$_key} </td></tr>
- ?$type <tr><td align="right" width="150">Type:</td><td><b>{$type}</b></td></tr>$type?
- ?$author <tr><td align="right" width="150">Author:</td><td><b>{html:author}</b></td></tr> $author?
- ?$version <tr><td align="right" width="150">Version:</td><td><b>{$version}</b></td></tr> $version?
- ?$update <tr><td align="right" width="150">Last update:</td><td>{$update} </td></tr>$update?
- </table>
- <br/>
- ?$description <p class="template-description">{$description}</p>$description?
- ?$vars
- <h3>Template\'s Variables ({$vars})</h3>
- <table class="data">
- <tr><th></th><th></th><th>Type</th><th>Name</th><th>Description</th></tr>
- [$vars]
-
- {?( trim("{\'value}") !== "" )?}
- <?
- $value = trim(str_replace(array("\t","\n","\r")," ", $value));
- while(strpos($value, " ")) $value = str_replace(" "," ", $value);
- $pars = explode(" ", $value, 4);
- ?>
- <tr>
- <td>{$_order}</td>
- [$pars]
- <td>{:repl1}{$value}{:/repl1}</td>
- [/$pars]
- </tr>
- {/?}
- [/$vars]
- </table>
- $vars?
- ?$include
- <h3>Include:</h3>
- [$include]
- {$_order}. <a href="#{$value}">{$value}</a><br/>
- [/$include]
- $include?
- ?$example
- <h3>Example:</h3>
- <table width = "100%" class="code" cellspacing="0" cellpadding="0">
- [$example]
- <tr>
- <td class="line" width="30">{$_order}</td>
- <td><pre class="code">{html_wysiwyg:afterReplace}{$value}{/html_wysiwyg:afterReplace}</pre></td>
- </tr>
- [/$example]
- </table>
- $example?
- </div>
- [/$docs]
- </td></tr></table>
- </body>
- </html>');
- /**
- * The div class is the complete implementation of Div.
- *
- * See the following example:
- *
- * echo new div('Hello {$name}', array('name' => 'Peter Pan'));
- */
- class div {
-
- // Public
- public $__src = null;
- // template source
- public $__src_original = null;
- // original template source
- public $__items = array();
- // template variables
- public $__items_orig = array();
- // original template variables
- public $__memory = array();
- // to remember the template variables
- public $__path = '';
- // path to current template file
- public $__ignore = array();
- // template variables to ignore
- public $__restore = array();
- // template's parts to restore after parse
- public $__packages = PACKAGES;
- // path of current templates's root folder
- public $__properties = array();
- // properties of the template
- // Private
- private $__id = null;
- // template id
- private $__temp = array();
- // temporal vars
- private $__crc = null;
- // template cheksum
- // Globals
- private static $__custom_modifiers = array();
- // custom variable's modifiers
- private static $__globals = array();
- // global template's variables
- private static $__globals_design = array();
- // global template's variables defined in the design
- private static $__globals_design_protected = array();
- // global and protected template variables defined in the design
- private static $__defaults = array();
- // default value for another value
- private static $__defaults_by_var = array();
- // default value for another value by variable
- private static $__system_data = null;
- // system data
- private static $__system_data_allowed = array(
- 'div.version' => true,
- 'div.post' => true,
- 'div.get' => true,
- 'div.now' => true
- );
- private static $__discard_file_system = false;
- // do not load code from files
- private static $__allowed_functions = array();
- // list of allowed custom functions
- private static $__allowed_methods = null;
- // list of allowed class's methods
- private static $__sub_parsers = array();
- // list of subparsers
- private static $__docs = array();
- // template's documentation
- private static $__docs_on = false;
- // on/off documentation
- private static $__includes_historial = array();
- // includes's historial
- // Internals
- private static $__version = '4.5';
- // current version of Div
- private static $__super_class = null;
- // name of the super class
- private static $__parent_method_names = array();
- // name of parent class's methods
- private static $__method_names = null;
- // name of current methods
- private static $__parse_duration = null;
- // duration of parser
- private static $__parse_level = 0;
- // current level of parser
- private static $__engine = null;
- // auxiliary engine
- private static $__modifiers = array( // variable's modifiers
- DIV_TAG_MODIFIER_SIMPLE,
- DIV_TAG_MODIFIER_CAPITALIZE_FIRST,
- DIV_TAG_MODIFIER_CAPITALIZE_WORDS,
- DIV_TAG_MODIFIER_UPPERCASE,
- DIV_TAG_MODIFIER_LOWERCASE,
- DIV_TAG_MODIFIER_LENGTH,
- DIV_TAG_MODIFIER_COUNT_WORDS,
- DIV_TAG_MODIFIER_COUNT_SENTENCES,
- DIV_TAG_MODIFIER_COUNT_PARAGRAPHS,
- DIV_TAG_MODIFIER_ENCODE_URL,
- DIV_TAG_MODIFIER_ENCODE_RAW_URL,
- DIV_TAG_MODIFIER_HTML_ENTITIES,
- DIV_TAG_MODIFIER_NL2BR,
- DIV_TAG_MODIFIER_ENCODE_JSON,
- DIV_TAG_MODIFIER_SINGLE_QUOTES,
- DIV_TAG_MODIFIER_JS
- );
- private static $__dialect_checked = false;
- // is current dialect checked?
- private static $__allowed_php_functions = null;
- // allowed PHP functions
- private static $__log_mode = false;
- // is log mode?
- private static $__log_file = null;
- // the log filename
- private static $__is_cli = null;
- // is PHP cli?
- private static $__ignored_parts = array();
- // ignored parts
- private static $__last_id = 0;
- // last template id
- private static $__remember = array();
- // remember previous work
- private static $__dont_remember_it = array();
- // do not remember it work
- private static $__errors = array();
- // errors historial
- private static $__include_paths = null;
- private static $__packages_by_class = array();
-
- /**
- * Constructor
- *
- * @param string $src
- * @param mixed $items
- * @param array $ignore
- * @return div
- */
- public function __construct($src = null, $items = null, $ignore = array()){
-
- // Validate the current dialect
- if (self::$__dialect_checked == false) {
- $r = self::isValidCurrentDialect();
- if ($r !== true)
- self::error('Current dialect is invalid: ' . $r, DIV_ERROR_FATAL);
- self::$__dialect_checked = true;
- }
-
- $classname = get_class($this);
-
- self::$__packages_by_class[$classname] = $this->__packages;
-
- if (is_null(self::$__super_class))
- self::$__super_class = $this->getSuperParent();
- if (is_null(self::$__parent_method_names))
- self::$__parent_method_names = get_class_methods(self::$__super_class);
-
- $this->__id = ++ self::$__last_id;
-
- if (self::$__log_mode)
- $this->logger('Building instance #' . $this->__id . ' of ' . $classname . '...');
-
- // Calling the beforeBuild hook
- $this->beforeBuild($src, $items);
-
- if (is_null($items) && ! is_null($this->__items))
- $items = $this->__items;
-
- $this->__items_orig = $items;
-
- $decode = true;
-
- $discardfs = self::$__discard_file_system;
-
- if (is_null($src)) {
- if ($classname != self::$__super_class && is_null($this->__src))
- $src = $classname;
- if (! is_null($this->__src))
- $src = $this->__src;
- }
-
- if (is_null($items)) {
- $items = $src;
- $items = str_replace('.' . DIV_DEFAULT_TPL_FILE_EXT, '', $items);
- $decode = false;
- }
-
- if (! $discardfs) {
- if (self::isString($items))
- if (strlen($items . '.' . DIV_DEFAULT_DATA_FILE_EXT) < 255) {
- $exists = false;
-
- if (self::fileExists($items)) {
- $items = self::getFileContents($items);
- $exists = true;
- } elseif (self::fileExists($items . '.' . DIV_DEFAULT_DATA_FILE_EXT)) {
- $items = self::getFileContents($items . '.' . DIV_DEFAULT_DATA_FILE_EXT);
- $exists = true;
- }
-
- if ($exists === true || $decode === true)
- $items = self::jsonDecode($items);
- if ($exists === true)
- break;
- }
- }
-
- if (is_object($items)) {
- if (method_exists($items, '__toString')) {
- $itemstr = "$items";
- if (! isset($items->value))
- $items->value = $itemstr;
- $items->_to_string = $itemstr;
- }
- $items = get_object_vars($items);
- }
-
- if (! $discardfs)
- $src = $this->loadTemplate($src);
-
- if (! is_array($items))
- $items = array();
-
- $this->__src = $src;
- $this->__src_original = $src;
- $this->__items = $items;
-
- if (self::isString($ignore))
- $ignore = explode(',', $ignore);
- if (isset($ignore[0]))
- foreach ( $ignore as $key => $val )
- $this->__ignore[$val] = true;
-
- // Calling the afterBuild hook
- $this->afterBuild();
-
- // Enabling methods
- if (is_null(self::$__allowed_methods)) {
- $keys = explode(",", DIV_PHP_ALLOWED_METHODS);
- ;
- self::$__allowed_methods = array_combine($keys, $keys);
-
- if (self::$__super_class != $classname) {
- $keys = array_diff(get_class_methods($classname), get_class_methods(self::$__super_class));
- if (isset($keys[0]))
- self::$__allowed_methods = array_merge(self::$__allowed_methods, array_combine($keys, $keys));
- }
- }
-
- // Pre-defined subparsers
-
- self::setSubParser('parse', 'subParse_parse');
- self::setSubParser('html_wysiwyg', 'subParse_html_wysiwyg');
- }
-
- /**
- * Return a list of include_path setting + the PACKAGES
- *
- * @return array
- */
- final static function getIncludePaths($packages = PACKAGES){
- if (is_null(self::$__include_paths)) {
- $os = self::getOperatingSystem();
- self::$__include_paths = explode(($os == "win32" ? ";" : ":"), ini_get("include_path"));
- self::$__include_paths[] = $packages;
- }
- return self::$__include_paths;
- }
-
- /**
- * Return the current operating system
- *
- * @return string (win32/linux/unix)
- */
- final static function getOperatingSystem(){
- if (isset($_SERVER['SERVER_SOFTWARE'])) {
- if (isset($_SERVER['WINDIR']) || strpos($_SERVER['SERVER_SOFTWARE'], 'Win32') !== FALSE)
- return "win32";
- if (! isset($_SERVER['WINDIR']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Linux') !== FALSE)
- return "linux";
- }
-
- if (file_exists("C:\Windows"))
- return "win32";
-
- return "unix";
- }
-
- /**
- * Return the super parent class name
- *
- * @param string $classname
- * @return string
- */
- final public function getSuperParent($classname = null){
- if (is_null($classname))
- $classname = get_class($this);
- $parent = get_parent_class($classname);
- if ($parent === false)
- return $classname;
- return $this->getSuperParent($parent);
- ;
- }
-
- /**
- * Return the current template's id
- *
- * @return integer
- */
- final public function getId(){
- return $this->__id;
- }
-
- /**
- * Create an auxiliar instance (as singleton)
- *
- * @param string $classname
- */
- final static function createAuxiliarEngine(&$from = null){
- if (is_null($from))
- $classname = self::$__super_class;
- else
- $classname = get_class($from);
- if (! is_null(self::$__engine))
- if (get_class(self::$__engine) != $classname)
- self::$__engine = null;
- if (is_null(self::$__engine)) {
- if (self::$__log_mode)
- self::log("createAuxiliarEngine: A new $classname instance will be created ...");
- $tmp = self::$__discard_file_system;
- self::$__discard_file_system = true;
- self::$__engine = new $classname("", array());
- if (! is_null($from)) {
- self::$__engine->__items = $from->__items;
- self::$__engine->__items_orig = $from->__items_orig;
- }
- self::$__discard_file_system = $tmp;
- }
- }
-
- /**
- * Create a clone of auxiliary
- *
- * @return div
- */
- final static function getAuxiliaryEngineClone(&$items = null, &$items_orig = null){
- $obj = clone self::$__engine;
-
- if (self::$__log_mode)
- self::log("getAuxiliaryEngineClone: New auxiliary #" . $obj->getId());
- if (! is_null($items))
- $obj->__items = $items;
- if (! is_null($items_orig))
- $obj->__items_orig = $items_orig;
-
- return $obj;
- }
-
- /**
- * Save parser's operationsd
- *
- * @param array $params
- */
- final public function saveOperation($params = array()){
- if (! isset(self::$__remember[$this->__crc]))
- self::$__remember[$this->__crc] = array();
- $id = crc32(serialize($params));
- if (! isset(self::$__remember[$this->__crc][$id]))
- self::$__remember[$this->__crc][$id] = $params;
- }
-
- /**
- * Add a custom variable's modifier
- *
- * @param string $prefix
- * @param string $function
- */
- final static function addCustomModifier($prefix, $function){
- self::$__custom_modifiers[$prefix] = array(
- $prefix,
- $function
- );
- self::$__modifiers[] = $prefix;
- }
-
- /**
- * Enable system var for utility
- *
- * @param string $var
- */
- final static function enableSystemVar($var){
- self::$__system_data_allowed[$var] = true;
- }
-
- /**
- * Disable system var for performance
- *
- * @param string $var
- */
- final static function disableSystemVar($var){
- if (isset(self::$__system_data_allowed[$var]))
- unset(self::$__system_data_allowed[$var]);
- }
-
- /**
- * Return the loaded data from the system
- *
- * @return array
- */
- final static function getSystemData(){
- if (self::$__system_data == null) {
- self::$__system_data = array();
- if (isset(self::$__system_data_allowed['div.ascii'])) {
- $ascii = array();
- for($i = 0; $i <= 255; $i ++)
- $ascii[$i] = chr($i);
- self::$__system_data['div.ascii'] = $ascii;
- }
- if (isset(self::$__system_data_allowed['div.now']))
- self::$__system_data['div.now'] = time();
- if (isset(self::$__system_data_allowed['div.post']))
- self::$__system_data['div.post'] = $_POST;
- if (isset(self::$__system_data_allowed['div.get']))
- self::$__system_data['div.get'] = $_GET;
- if (isset(self::$__system_data_allowed['div.server']))
- self::$__system_data['div.server'] = $_SERVER;
- if (isset(self::$__system_data_allowed['div.session']))
- self::$__system_data['div.session'] = isset($_SESSION) ? $_SESSION : array();
- if (isset(self::$__system_data_allowed['div.version']))
- self::$__system_data['div.version'] = self::$__version;
- if (isset(self::$__system_data_allowed['div.script_name'])) {
- $script_name = explode('/', $_SERVER['SCRIPT_NAME']);
- $script_name = $script_name[count($script_name) - 1];
- self::$__system_data['div.script_name'] = $script_name;
- }
- }
- return self::$__system_data;
- }
-
- /**
- * Set allowed function
- *
- * @param string $funcname
- */
- final static function setAllowedFunction($funcname){
- self::$__allowed_functions[$funcname] = true;
- }
-
- /**
- * Unset allowed function
- *
- * @param string $funcname
- */
- final static function unsetAllowedFunction($funcname){
- self::$__allowed_functions[$funcname] = false;
- }
-
- /**
- * Add or set a global var
- *
- * @param string $var
- * @param mixed $value
- */
- final static function setGlobal($var, $value){
- self::$__globals[$var] = $value;
- }
-
- /**
- * Remove a global var
- *
- * @param string $var
- */
- final static function delGlobal($var){
- unset(self::$__globals[$var]);
- }
-
- /**
- * Add or set a default replacement of value
- *
- * @param mixed $search
- * @param mixed $replace
- */
- final static function setDefault($search, $replace){
- self::$__defaults[serialize($search)] = $replace;
- }
-
- /**
- * Add or set a default replacement of value for a specific var
- *
- * @param string $var
- * @param mixed $search
- * @param mixed $replace
- * @param boolean $update
- */
- final static function setDefaultByVar($var, $search, $replace, $update = true){
- $id = serialize($search);
- if (! isset(self::$__defaults_by_var[$var]))
- self::$__defaults_by_var[$var] = array();
- if (! isset(self::$__defaults_by_var[$var][$id]) && $update === true)
- self::$__defaults_by_var[$var][$id] = $replace;
- }
-
- /**
- * Set a sub-parser
- *
- * @param string $name
- * @param string $function
- */
- final static function setSubParser($name, $function = null){
- if (is_array($name)) {
- if (is_null($function)) {
- foreach ( $name as $key => $value ) {
- if (is_numeric($key))
- self::$__sub_parsers[$value] = $value;
- else
- self::$__sub_parsers[$key] = $value;
- }
- } elseif (is_array($function)) {
- foreach ( $name as $key => $value )
- self::$__sub_parsers[$value] = $function[$key];
- } else {
- foreach ( $name as $key => $value )
- self::$__sub_parsers[$value] = $function;
- }
- } else {
- if (is_null($function))
- $function = $name;
- self::$__sub_parsers[$name] = $function;
- }
- self::repairSubparsers();
- }
-
- /**
- * Repair the subparsers and their events
- */
- final static function repairSubparsers(){
- $events = array(
- 'beforeParse',
- 'afterInclude',
- 'afterParse',
- 'afterReplace'
- );
- $news = array();
-
- foreach ( self::$__sub_parsers as $parser => $function ) {
- $arr = explode(":", $parser);
-
- if (isset($arr[1])) {
- $last = array_pop($arr);
- if (array_search($last, $events) !== false)
- continue;
- }
-
- foreach ( $events as $event )
- if (! isset(self::$__sub_parsers["$parser:$event"])) {
- $news["$parser:$event"] = $function;
- }
- }
-
- self::$__sub_parsers = array_merge(self::$__sub_parsers, $news);
- }
-
- /**
- * Load template from filesystem
- *
- * @param string $path
- * @return string
- */
- final public function loadTemplate($path){
- if (self::$__log_mode === true)
- $this->logger("Loading the template: $path");
-
- $src = $path;
-
- if (strlen($path) < 255) {
- $paths = array(
- $path,
- $path . '.' . DIV_DEFAULT_TPL_FILE_EXT,
- $path,
- $path . '.' . DIV_DEFAULT_TPL_FILE_EXT
- );
-
- foreach ( $paths as $pathx ) {
- if (strlen($pathx) < 255)
- if (self::fileExists($pathx)) {
- $src = self::getFileContents($pathx);
- $this->__path = $pathx;
- break;
- }
- }
- }
-
- return $src;
- }
-
- /**
- * Change the template and the original template
- *
- * @param string $src
- */
- final public function changeTemplate($src = null){
- $decode = true;
- $classname = get_class($this);
- $discardfs = self::$__discard_file_system;
-
- if (is_null($src)) {
- if ($classname != self::$__super_class && is_null($this->__src))
- $src = $classname;
- if (! is_null($this->__src))
- $src = $this->__src;
- }
-
- if (! $discardfs)
- $src = $this->loadTemplate($src);
-
- $this->__src = $src;
- $this->__src_original = $src;
- }
-
- /**
- * Return the code of current template
- *
- * @return string
- */
- final public function getTemplate(){
- return $this->__src;
- }
-
- /**
- * Return the original code of template
- *
- * @return string
- */
- final public function getOriginalTemplate(){
- return $this->__src_original;
- }
-
- /**
- * Remove a default replacement
- *
- * @param mixed $search
- */
- final static function delDefault($search){
- $id = serialize($search);
- if (isset(self::$__defaults[$id]))
- unset(self::$__defaults[$id]);
- }
-
- /**
- * Remove a default replacement by var
- *
- * @param string $var
- * @param mixed $search
- */
- final static function delDefaultByVar($var, $search){
- if (isset(self::$__defaults_by_var[$var])) {
- $id = serialize($search);
- if (isset(self::$__defaults_by_var[$var][$id]))
- unset(self::$__defaults_by_var[$var][$id]);
- }
- }
-
- /**
- * Add or Set item of information
- *
- * @param string $var
- * @param mixed $value
- * @return mixed
- */
- final public function setItem($var, $value = null){
- if (is_array($var)) {
- $r = array();
- foreach ( $var as $idx => $val ) {
- if (self::issetVar($idx, $this->__items))
- $r[$idx] = self::getVarValue($idx, $this->__items);
- else
- $r[$idx] = null;
-
- self::setVarValue($idx, $val, $this->__items);
- }
-
- return $r;
- }
-
- if (self::issetVar($var, $this->__items))
- $item = self::getVarValue($var, $this->__items);
- else
- $item = null;
-
- self::setVarValue($var, $value, $this->__items);
-
- return $item;
- }
-
- /**
- * Delete an item of information
- *
- * @param string $var
- * @return boolean
- */
- final public function delItem($var){
- return self::unsetVar($var, $this->__items);
- }
-
- /**
- * Return an item
- *
- * @param array $array
- * @param mixed $index
- * @param mixed $default
- * @return mixed
- */
- final public function getItem($var, $default = null){
- if (! self::issetVar($var, $this->__items))
- return $default;
- return self::getVarValue($var, $this->__items);
- }
-
- /**
- * Return a list of block's ranges
- *
- * @param string $tagini
- * @param string $tagend
- * @param boolean $onlyfirst
- * @param integer $pos
- * @return array
- */
- final public function getRanges($tagini, $tagend, $src = null, $onlyfirst = false, $pos = 0){
- $ranges = array();
- if (is_null($src))
- if (isset($this))
- $src = $this->__src;
- if (! is_null($src))
- if (isset($src[0]) && ! empty($src)) {
- $ltagini = strlen($tagini);
- $ltagend = strlen($tagend);
- do {
- $ini = strpos($src, $tagini, $pos);
- if ($ini !== false) {
- if (isset($src[$ini + $ltagini])) {
- $fin = strpos($src, $tagend, $ini + $ltagini);
- if ($fin !== false) {
- $l = strlen($src);
- $last_pos = - 1;
- while ( true ) {
- $ini = strpos($src, $tagini, $pos);
- if ($ini === false || ($ini !== false && $pos == $last_pos))
- break;
- $end = false;
- $plus = 1;
- $posi = $ini + $ltagini;
- $last_posi = $posi - 1;
-
- while ( true ) {
- $open = strpos($src, $tagini, $posi);
- $close = strpos($src, $tagend, $posi);
-
- if ($open === false && $close === false)
- break; // not open and not close
- if ($open === false && $close !== false && $posi === $last_posi)
- break; // close and not open
- if ($open !== false && $close === false && $posi === $last_posi)
- break; // open and not close
-
- if ($open !== false || $close !== false) { // open or close
- if (($close < $open || $open === false) && $close !== false) { // close if is closed and before open or not open
- $last_posi = $posi;
- $posi = $close + $ltagend;
- $plus --;
- // IMPORTANT! Don't separate elseif
- } elseif (($open < $close || $close === false) && $open !== false) { // open if is opened and before close or not close
- $last_posi = $posi;
- $posi = $open + $ltagini;
- $plus ++;
- }
- }
-
- if ($plus === 0) { // all opens are closed
- $end = $close;
- break;
- }
-
- if ($open >= $l)
- break;
- }
-
- $last_pos = $pos;
-
- if ($end != false) {
- $ranges[] = array(
- $ini,
- $end
- );
- if ($onlyfirst == true)
- break;
- $pos = $ini + $ltagini;
- continue;
- }
- }
- }
- }
- }
-
- if (! isset($ranges[0]) && $ini !== false) {
- if (self::$__log_mode)
- if (isset($this)) {
- foreach ( $this->__items as $key => $value )
- if (strpos($tagini, $key) !== false) {
- $this->logger('Unclosed tag ' . $tagini . ' at ' . $ini . ' character', DIV_ERROR_WARNING);
- break;
- }
- }
-
- $pos = $ini + 1;
-
- continue;
- }
-
- break;
- } while ( true );
- }
- return $ranges;
- }
-
- /**
- * Return a list of ranges of blocks
- *
- * @param string $src
- * @param string $begin_prefix
- * @param string $begin_suffix
- * @param string $end_prefix
- * @param string $end_suffix
- * @param integer $after
- * @param integer $before
- * @return array
- */
- final public function getBlockRanges($src = null, $begin_prefix = '{', $begin_suffix = '}', $end_prefix = '{/', $end_suffix = '}', $after = 0, $before = null, $onlyfirst = false){
- if (is_null($src))
- $src = $this->__src;
- if (! is_null($before))
- $src = substr($src, 0, $before);
-
- $l = strlen($src);
- $l1 = strlen($begin_prefix);
- $tagsya = array();
- $ranges = array();
- $from = $after;
-
- do {
- $prefix_pos = strpos($src, $begin_prefix, $from);
- if ($prefix_pos !== false) {
- if (isset($src[$prefix_pos + 1])) {
-
- if ($begin_suffix != '' && ! is_null($begin_suffix)) {
- $suffix_pos = strpos($src, $begin_suffix, $prefix_pos + 1);
- } else {
-
- $stopchars = array(
- ' ',
- "\n",
- "\r",
- "\t",
- "<",
- ">"
- );
- $stoppos = array();
-
- foreach ( $stopchars as $k => $v ) {
- $pp = strpos($src, $v, $prefix_pos);
- if ($pp === false)
- continue;
- $stoppos[] = $pp;
- }
-
- $suffix_pos = false;
- if (count($stoppos) > 0)
- $suffix_pos = min($stoppos);
- }
-
- $key = '';
- if ($suffix_pos < $l && $suffix_pos !== false) {
- $key = substr($src, $prefix_pos + $l1, $suffix_pos - $prefix_pos - $l1);
- }
-
- if ($key !== '' && ! isset($tagsya[$key])) {
- $tag_begin = $begin_prefix . $key . $begin_suffix;
- $tag_end = $end_prefix . $key . $end_suffix;
- $rs = $this->getRanges($tag_begin, $tag_end, $src, $onlyfirst, $from);
- $l2 = strlen($tag_begin);
- foreach ( $rs as $k => $v ) {
- $rs[$k][2] = $key;
- $rs[$k][3] = substr($src, $v[0] + $l2, $v[1] - $v[0] - $l2);
- }
- $ranges = array_merge($ranges, $rs);
-
- // Only the first...
- if ($onlyfirst)
- if (isset($ranges[0]))
- break;
-
- $tagsya[$key] = true;
- }
- }
- $from = $prefix_pos + 1;
- }
- } while ( $prefix_pos !== false );
-
- return $ranges;
- }
-
- /**
- * Return a default replacement of value
- *
- * @param mixed $value
- * @return mixed
- */
- final static function getDefault($value){
- $id = serialize($value);
- if (isset(self::$__defaults[$id]))
- return self::$__defaults[$id];
- return $value;
- }
-
- /**
- * Return a default replacement of value by var
- *
- * @param string $var
- * @param mixed $value
- * @return mixed
- */
- final static function getDefaultByVar($var, $value){
- if (isset(self::$__defaults_by_var[$var])) {
- $id = serialize($value);
- if (isset(self::$__defaults_by_var[$var][$id])…
Large files files are truncated, but you can click here to view the full file