3 if (!defined(
'ENT_SUBSTITUTE')) {
4 define(
'ENT_SUBSTITUTE', 8);
27 public function setDateFormat($format = null, $dateIntervalFormat = null)
29 if (null !== $format) {
30 $this->dateFormats[0] = $format;
33 if (null !== $dateIntervalFormat) {
34 $this->dateFormats[1] = $dateIntervalFormat;
65 if (null === $this->timezone) {
66 $this->timezone =
new DateTimeZone(date_default_timezone_get());
81 $this->numberFormat = array($decimal, $decimalPoint, $thousandSep);
129 new Twig_SimpleFilter(
'date',
'twig_date_format_filter', array(
'needs_environment' =>
true)),
130 new Twig_SimpleFilter(
'date_modify',
'twig_date_modify_filter', array(
'needs_environment' =>
true)),
133 new Twig_SimpleFilter(
'number_format',
'twig_number_format_filter', array(
'needs_environment' =>
true)),
142 new Twig_SimpleFilter(
'title',
'twig_title_string_filter', array(
'needs_environment' =>
true)),
143 new Twig_SimpleFilter(
'capitalize',
'twig_capitalize_string_filter', array(
'needs_environment' =>
true)),
148 new Twig_SimpleFilter(
'nl2br',
'nl2br', array(
'pre_escape' =>
'html',
'is_safe' => array(
'html'))),
158 new Twig_SimpleFilter(
'reverse',
'twig_reverse_filter', array(
'needs_environment' =>
true)),
159 new Twig_SimpleFilter(
'length',
'twig_length_filter', array(
'needs_environment' =>
true)),
160 new Twig_SimpleFilter(
'slice',
'twig_slice', array(
'needs_environment' =>
true)),
161 new Twig_SimpleFilter(
'first',
'twig_first', array(
'needs_environment' =>
true)),
165 new Twig_SimpleFilter(
'default',
'_twig_default_filter', array(
'node_class' =>
'Twig_Node_Expression_Filter_Default')),
169 new Twig_SimpleFilter(
'escape',
'twig_escape_filter', array(
'needs_environment' =>
true,
'is_safe_callback' =>
'twig_escape_filter_is_safe')),
170 new Twig_SimpleFilter(
'e',
'twig_escape_filter', array(
'needs_environment' =>
true,
'is_safe_callback' =>
'twig_escape_filter_is_safe')),
173 if (function_exists(
'mb_get_info')) {
174 $filters[] =
new Twig_SimpleFilter(
'upper',
'twig_upper_filter', array(
'needs_environment' =>
true));
175 $filters[] =
new Twig_SimpleFilter(
'lower',
'twig_lower_filter', array(
'needs_environment' =>
true));
193 new Twig_SimpleFunction(
'date',
'twig_date_converter', array(
'needs_environment' =>
true)),
194 new Twig_SimpleFunction(
'include',
'twig_include', array(
'needs_environment' =>
true,
'needs_context' =>
true,
'is_safe' => array(
'all'))),
206 new Twig_SimpleTest(
'even', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Even')),
207 new Twig_SimpleTest(
'odd', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Odd')),
208 new Twig_SimpleTest(
'defined', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Defined')),
209 new Twig_SimpleTest(
'sameas', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Sameas')),
210 new Twig_SimpleTest(
'none', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Null')),
211 new Twig_SimpleTest(
'null', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Null')),
212 new Twig_SimpleTest(
'divisibleby', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Divisibleby')),
213 new Twig_SimpleTest(
'constant', null, array(
'node_class' =>
'Twig_Node_Expression_Test_Constant')),
228 'not' => array(
'precedence' => 50,
'class' =>
'Twig_Node_Expression_Unary_Not'),
229 '-' => array(
'precedence' => 500,
'class' =>
'Twig_Node_Expression_Unary_Neg'),
230 '+' => array(
'precedence' => 500,
'class' =>
'Twig_Node_Expression_Unary_Pos'),
283 $testMap = $env->getTests();
284 if (!isset($testMap[$name])) {
285 $message = sprintf(
'The test "%s" does not exist', $name);
286 if ($alternatives = $env->computeAlternatives($name, array_keys($env->getTests()))) {
287 $message = sprintf(
'%s. Did you mean "%s"', $message, implode(
'", "', $alternatives));
294 return $testMap[$name]->getNodeClass();
297 return $testMap[$name] instanceof
Twig_Test_Node ? $testMap[$name]->
getClass() :
'Twig_Node_Expression_Test';
321 if (!is_array($values) && !$values instanceof ArrayAccess) {
325 return $values[$position % count($values)];
343 if (null === $values) {
347 if (is_int($values) || is_float($values)) {
348 return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
351 if ($values instanceof Traversable) {
352 $values = iterator_to_array($values);
353 }
elseif (is_string($values)) {
354 if (
'' === $values) {
358 if (
'UTF-8' != $charset) {
359 $values = twig_convert_encoding($values,
'UTF-8', $charset);
364 $values = preg_split(
'/(?<!^)(?!$)/u', $values);
366 if (
'UTF-8' != $charset) {
367 foreach ($values as
$i => $value) {
368 $values[
$i] = twig_convert_encoding($value, $charset,
'UTF-8');
372 return $values[mt_rand(0, strlen($values) - 1)];
376 if (!is_array($values)) {
380 if (0 === count($values)) {
384 return $values[array_rand($values, 1)];
403 if (null === $format) {
405 $format = $date instanceof DateInterval ? $formats[1] : $formats[0];
408 if ($date instanceof DateInterval) {
409 return $date->format($format);
431 $date->modify($modifier);
455 $defaultTimezone = $env->
getExtension(
'core')->getTimezone();
456 }
elseif (!$timezone instanceof DateTimeZone) {
457 $defaultTimezone =
new DateTimeZone($timezone);
459 $defaultTimezone = $timezone;
462 if ($date instanceof DateTime) {
464 if (
false !== $timezone) {
465 $date->setTimezone($defaultTimezone);
471 $asString = (string) $date;
472 if (ctype_digit($asString) || (!empty($asString) &&
'-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
476 $date =
new DateTime($date, $defaultTimezone);
477 if (
false !== $timezone) {
478 $date->setTimezone($defaultTimezone);
501 $defaults = $env->
getExtension(
'core')->getNumberFormat();
502 if (null === $decimal) {
503 $decimal = $defaults[0];
506 if (null === $decimalPoint) {
507 $decimalPoint = $defaults[1];
510 if (null === $thousandSep) {
511 $thousandSep = $defaults[2];
514 return number_format((
float) $number, $decimal, $decimalPoint, $thousandSep);
527 if (is_array(
$url)) {
528 return http_build_query(
$url,
'',
'&');
532 return rawurlencode(
$url);
535 return urlencode(
$url);
538 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
547 function twig_jsonencode_filter($value, $options = 0)
550 $value = (string) $value;
551 }
elseif (is_array($value)) {
552 array_walk_recursive($value,
'_twig_markup2string');
555 return json_encode($value);
566 function twig_jsonencode_filter($value, $options = 0)
569 $value = (string) $value;
570 }
elseif (is_array($value)) {
571 array_walk_recursive($value,
'_twig_markup2string');
574 return json_encode($value, $options);
578 function _twig_markup2string(&$value)
581 $value = (string) $value;
601 function twig_array_merge($arr1, $arr2)
603 if (!is_array($arr1) || !is_array($arr2)) {
607 return array_merge($arr1, $arr2);
623 if ($item instanceof Traversable) {
624 $item = iterator_to_array($item,
false);
627 if (is_array($item)) {
628 return array_slice($item,
$start, $length, $preserveKeys);
631 $item = (string) $item;
633 if (function_exists(
'mb_get_info') && null !== $charset = $env->
getCharset()) {
634 return mb_substr($item,
$start, null === $length ? mb_strlen($item, $charset) -
$start : $length, $charset);
637 return null === $length ? substr($item,
$start) : substr($item,
$start, $length);
650 $elements = twig_slice($env, $item, 0, 1,
false);
652 return is_string($elements) ? $elements[0] : current($elements);
665 $elements = twig_slice($env, $item, -1, 1,
false);
667 return is_string($elements) ? $elements[0] : current($elements);
688 function twig_join_filter($value, $glue =
'')
690 if ($value instanceof Traversable) {
691 $value = iterator_to_array($value,
false);
694 return implode($glue, (array) $value);
720 function twig_split_filter($value, $delimiter, $limit = null)
722 if (empty($delimiter)) {
723 return str_split($value, null === $limit ? 1 : $limit);
726 return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
732 function _twig_default_filter($value, $default =
'')
734 if (twig_test_empty($value)) {
756 function twig_get_array_keys_filter($array)
758 if (is_object($array) && $array instanceof Traversable) {
759 return array_keys(iterator_to_array($array));
762 if (!is_array($array)) {
766 return array_keys($array);
778 function twig_reverse_filter(
Twig_Environment $env, $item, $preserveKeys =
false)
780 if (is_object($item) && $item instanceof Traversable) {
781 return array_reverse(iterator_to_array($item), $preserveKeys);
784 if (is_array($item)) {
785 return array_reverse($item, $preserveKeys);
789 $string = (string) $item;
791 if (
'UTF-8' != $charset) {
792 $item = twig_convert_encoding($string,
'UTF-8', $charset);
795 preg_match_all(
'/./us', $item, $matches);
797 $string = implode(
'', array_reverse($matches[0]));
799 if (
'UTF-8' != $charset) {
800 $string = twig_convert_encoding($string, $charset,
'UTF-8');
806 return strrev((
string) $item);
814 function twig_sort_filter($array)
822 function twig_in_filter($value, $compare)
824 if (is_array($compare)) {
825 return in_array($value, $compare, is_object($value));
826 }
elseif (is_string($compare)) {
827 if (!strlen($value)) {
828 return empty($compare);
831 return false !== strpos($compare, (
string) $value);
832 }
elseif ($compare instanceof Traversable) {
833 return in_array($value, iterator_to_array($compare,
false), is_object($value));
848 function twig_escape_filter(
Twig_Environment $env, $string, $strategy =
'html', $charset = null, $autoescape =
false)
850 if ($autoescape && $string instanceof
Twig_Markup) {
854 if (!is_string($string)) {
855 if (is_object($string) && method_exists($string,
'__toString')) {
856 $string = (string) $string;
862 if (null === $charset) {
873 static $htmlspecialcharsCharsets = array(
874 'ISO-8859-1' =>
true,
'ISO8859-1' =>
true,
875 'ISO-8859-15' =>
true,
'ISO8859-15' =>
true,
876 'utf-8' =>
true,
'UTF-8' =>
true,
877 'CP866' =>
true,
'IBM866' =>
true,
'866' =>
true,
878 'CP1251' =>
true,
'WINDOWS-1251' =>
true,
'WIN-1251' =>
true,
880 'CP1252' =>
true,
'WINDOWS-1252' =>
true,
'1252' =>
true,
881 'KOI8-R' =>
true,
'KOI8-RU' =>
true,
'KOI8R' =>
true,
882 'BIG5' =>
true,
'950' =>
true,
883 'GB2312' =>
true,
'936' =>
true,
884 'BIG5-HKSCS' =>
true,
885 'SHIFT_JIS' =>
true,
'SJIS' =>
true,
'932' =>
true,
886 'EUC-JP' =>
true,
'EUCJP' =>
true,
887 'ISO8859-5' =>
true,
'ISO-8859-5' =>
true,
'MACROMAN' =>
true,
890 if (isset($htmlspecialcharsCharsets[$charset])) {
891 return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
894 if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) {
896 $htmlspecialcharsCharsets[$charset] =
true;
898 return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
901 $string = twig_convert_encoding($string,
'UTF-8', $charset);
902 $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8');
904 return twig_convert_encoding($string, $charset,
'UTF-8');
909 if (
'UTF-8' != $charset) {
910 $string = twig_convert_encoding($string,
'UTF-8', $charset);
913 if (0 == strlen($string) ?
false : (1 == preg_match(
'/^./su', $string) ?
false :
true)) {
917 $string = preg_replace_callback(
'#[^a-zA-Z0-9,\._]#Su',
'_twig_escape_js_callback', $string);
919 if (
'UTF-8' != $charset) {
920 $string = twig_convert_encoding($string, $charset,
'UTF-8');
926 if (
'UTF-8' != $charset) {
927 $string = twig_convert_encoding($string,
'UTF-8', $charset);
930 if (0 == strlen($string) ?
false : (1 == preg_match(
'/^./su', $string) ?
false :
true)) {
934 $string = preg_replace_callback(
'#[^a-zA-Z0-9]#Su',
'_twig_escape_css_callback', $string);
936 if (
'UTF-8' != $charset) {
937 $string = twig_convert_encoding($string, $charset,
'UTF-8');
943 if (
'UTF-8' != $charset) {
944 $string = twig_convert_encoding($string,
'UTF-8', $charset);
947 if (0 == strlen($string) ?
false : (1 == preg_match(
'/^./su', $string) ?
false :
true)) {
951 $string = preg_replace_callback(
'#[^a-zA-Z0-9,\.\-_]#Su',
'_twig_escape_html_attr_callback', $string);
953 if (
'UTF-8' != $charset) {
954 $string = twig_convert_encoding($string, $charset,
'UTF-8');
962 if (PHP_VERSION <
'5.3.0') {
963 return str_replace(
'%7E',
'~', rawurlencode($string));
966 return rawurlencode($string);
969 throw new Twig_Error_Runtime(sprintf(
'Invalid escaping strategy "%s" (valid ones: html, js, url, css, and html_attr).', $strategy));
974 function twig_escape_filter_is_safe(
Twig_Node $filterArgs)
976 foreach ($filterArgs as $arg) {
978 return array($arg->getAttribute(
'value'));
984 return array(
'html');
987 if (function_exists(
'mb_convert_encoding')) {
988 function twig_convert_encoding($string, $to, $from)
990 return mb_convert_encoding($string, $to, $from);
992 }
elseif (function_exists(
'iconv')) {
993 function twig_convert_encoding($string, $to, $from)
995 return iconv($from, $to, $string);
998 function twig_convert_encoding($string, $to, $from)
1000 throw new Twig_Error_Runtime(
'No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
1004 function _twig_escape_js_callback($matches)
1006 $char = $matches[0];
1009 if (!isset($char[1])) {
1010 return '\\x'.strtoupper(substr(
'00'.bin2hex($char), -2));
1014 $char = twig_convert_encoding($char,
'UTF-16BE',
'UTF-8');
1016 return '\\u'.strtoupper(substr(
'0000'.bin2hex($char), -4));
1019 function _twig_escape_css_callback($matches)
1021 $char = $matches[0];
1024 if (!isset($char[1])) {
1025 $hex = ltrim(strtoupper(bin2hex($char)),
'0');
1026 if (0 === strlen($hex)) {
1030 return '\\'.$hex.
' ';
1034 $char = twig_convert_encoding($char,
'UTF-16BE',
'UTF-8');
1036 return '\\'.ltrim(strtoupper(bin2hex($char)),
'0').
' ';
1045 function _twig_escape_html_attr_callback($matches)
1053 static $entityMap = array(
1067 if (($ord <= 0x1f && $chr !=
"\t" && $chr !=
"\n" && $chr !=
"\r") || ($ord >= 0x7f && $ord <= 0x9f)) {
1075 if (strlen($chr) == 1) {
1076 $hex = strtoupper(substr(
'00'.bin2hex($chr), -2));
1078 $chr = twig_convert_encoding($chr,
'UTF-16BE',
'UTF-8');
1079 $hex = strtoupper(substr(
'0000'.bin2hex($chr), -4));
1082 $int = hexdec($hex);
1083 if (array_key_exists($int, $entityMap)) {
1084 return sprintf(
'&%s;', $entityMap[$int]);
1092 return sprintf(
'&#x%s;', $hex);
1096 if (function_exists(
'mb_get_info')) {
1107 return is_scalar($thing) ? mb_strlen($thing, $env->
getCharset()) : count($thing);
1120 if (null !== ($charset = $env->
getCharset())) {
1121 return mb_strtoupper($string, $charset);
1124 return strtoupper($string);
1137 if (null !== ($charset = $env->
getCharset())) {
1138 return mb_strtolower($string, $charset);
1141 return strtolower($string);
1154 if (null !== ($charset = $env->
getCharset())) {
1155 return mb_convert_case($string, MB_CASE_TITLE, $charset);
1158 return ucwords(strtolower($string));
1171 if (null !== ($charset = $env->
getCharset())) {
1172 return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).
1173 mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset);
1176 return ucfirst(strtolower($string));
1191 return is_scalar($thing) ? strlen($thing) : count($thing);
1204 return ucwords(strtolower($string));
1217 return ucfirst(strtolower($string));
1222 function twig_ensure_traversable($seq)
1224 if ($seq instanceof Traversable || is_array($seq)) {
1245 function twig_test_empty($value)
1247 if ($value instanceof Countable) {
1248 return 0 == count($value);
1251 return '' === $value ||
false === $value || null === $value || array() === $value;
1268 function twig_test_iterable($value)
1270 return $value instanceof Traversable || is_array($value);
1284 function twig_include(
Twig_Environment $env, $context, $template, $variables = array(), $withContext =
true, $ignoreMissing =
false, $sandboxed =
false)
1287 $variables = array_merge($context, $variables);
1290 if ($isSandboxed = $sandboxed && $env->
hasExtension(
'sandbox')) {
1292 if (!$alreadySandboxed = $sandbox->isSandboxed()) {
1293 $sandbox->enableSandbox();
1300 if (!$ignoreMissing) {
1305 if ($isSandboxed && !$alreadySandboxed) {
1306 $sandbox->disableSandbox();
1318 function twig_constant($constant, $object = null)
1320 if (null !== $object) {
1321 $constant = get_class($object).
'::'.$constant;
1324 return constant($constant);
1336 function twig_array_batch($items, $size, $fill = null)
1338 if ($items instanceof Traversable) {
1339 $items = iterator_to_array($items,
false);
1342 $size = ceil($size);
1344 $result = array_chunk($items, $size,
true);
1346 if (null !== $fill) {
1350 array_fill(0, $size - count(
$result[$last]), $fill)
getDateFormat()
Gets the default format to be used by the date filter.
Flushes the output to the client.
twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
Returns a new date object modified.
getNumberFormat()
Get the default format used by the number_format filter.
getTimezone()
Gets the default timezone to be used by the date filter.
if($rub=fetch_assoc($rub_query)) if(check_if_module_active('url_rewriting')) $class
setDateFormat($format=null, $dateIntervalFormat=null)
Sets the default format to be used by the date filter.
Represents a node in the AST.
Represents a template test as a Node.
Represents a template function.
getTestNodeClass(Twig_Parser $parser, $name, $line)
getStream()
Gets the token stream.
Filters a section of a template by applying filters.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
getOperators()
Returns a list of operators to add to the existing list.
getTokenParsers()
Returns the token parser instance to add to the existing list.
Default parser implementation.
getExpressionParser()
Gets the expression parser.
Extends a template by another one.
getCurrentToken()
Gets the current token.
parseNotTestExpression(Twig_Parser $parser, $node)
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
getTests()
Returns a list of tests to add to the existing list.
parseTestExpression(Twig_Parser $parser, $node)
twig_cycle($values, $position)
Cycles over a value.
Remove whitespaces between HTML tags.
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
Loops over each item of a sequence.
getExtension($name)
Gets an extension by name.
setTimezone($timezone)
Sets the default timezone to be used by the date filter.
hasExtension($name)
Returns true if the given extension is registered.
setNumberFormat($decimal, $decimalPoint, $thousandSep)
Sets the default format to be used by the number_format filter.
twig_date_format_filter(Twig_Environment $env, $date, $format=null, $timezone=null)
Converts a date to the given format.
twig_urlencode_filter($url, $raw=false)
URL encodes a string as a path segment or an array as a query string.
Stores the Twig configuration.
getCharset()
Gets the default template charset.
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
getFunctions()
Returns a list of global functions to add to the existing list.
getFilters()
Returns a list of filters to add to the existing list.
Represents a template test.
Represents a template filter.
Exception thrown when an error occurs during template loading.
Marks a section of a template as being reusable.
Evaluates an expression, discarding the returned value.
Exception thrown when an error occurs at runtime.
twig_number_format_filter(Twig_Environment $env, $number, $decimal=null, $decimalPoint=null, $thousandSep=null)
Number format filter.
getName()
Returns the name of the extension.
Imports blocks defined in another template into the current template.