<?php
if (!defined('ENT_SUBSTITUTE')) {
define('ENT_SUBSTITUTE', 8);
}
class Twig_Extension_Core extends Twig_Extension {
protected $dateFormats = array(
'F j, Y H:i',
'%d days',
);
protected $numberFormat = array(
0,
'.',
',',
);
protected $timezone = null;
public function setDateFormat($format = null, $dateIntervalFormat = null) {
if (null !== $format) {
$this->dateFormats[0] = $format;
}
if (null !== $dateIntervalFormat) {
$this->dateFormats[1] = $dateIntervalFormat;
}
}
public function getDateFormat() {
return $this->dateFormats;
}
public function setTimezone($timezone) {
$this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
}
public function getTimezone() {
if (null === $this->timezone) {
$this->timezone = new DateTimeZone(date_default_timezone_get());
}
return $this->timezone;
}
public function setNumberFormat($decimal, $decimalPoint, $thousandSep) {
$this->numberFormat = array(
$decimal,
$decimalPoint,
$thousandSep,
);
}
public function getNumberFormat() {
return $this->numberFormat;
}
public function getTokenParsers() {
return array(
new Twig_TokenParser_For(),
new Twig_TokenParser_If(),
new Twig_TokenParser_Extends(),
new Twig_TokenParser_Include(),
new Twig_TokenParser_Block(),
new Twig_TokenParser_Use(),
new Twig_TokenParser_Filter(),
new Twig_TokenParser_Macro(),
new Twig_TokenParser_Import(),
new Twig_TokenParser_From(),
new Twig_TokenParser_Set(),
new Twig_TokenParser_Spaceless(),
new Twig_TokenParser_Flush(),
new Twig_TokenParser_Do(),
new Twig_TokenParser_Embed(),
);
}
public function getFilters() {
$filters = array(
new Twig_SimpleFilter('date', 'twig_date_format_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('format', 'sprintf'),
new Twig_SimpleFilter('replace', 'strtr'),
new Twig_SimpleFilter('number_format', 'twig_number_format_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('abs', 'abs'),
new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'),
new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'),
new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'),
new Twig_SimpleFilter('title', 'twig_title_string_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('upper', 'strtoupper'),
new Twig_SimpleFilter('lower', 'strtolower'),
new Twig_SimpleFilter('striptags', 'strip_tags'),
new Twig_SimpleFilter('trim', 'trim'),
new Twig_SimpleFilter('nl2br', 'nl2br', array(
'pre_escape' => 'html',
'is_safe' => array(
'html',
),
)),
new Twig_SimpleFilter('join', 'twig_join_filter'),
new Twig_SimpleFilter('split', 'twig_split_filter'),
new Twig_SimpleFilter('sort', 'twig_sort_filter'),
new Twig_SimpleFilter('merge', 'twig_array_merge'),
new Twig_SimpleFilter('batch', 'twig_array_batch'),
new Twig_SimpleFilter('reverse', 'twig_reverse_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('length', 'twig_length_filter', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('slice', 'twig_slice', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('first', 'twig_first', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('last', 'twig_last', array(
'needs_environment' => true,
)),
new Twig_SimpleFilter('default', '_twig_default_filter', array(
'node_class' => 'Twig_Node_Expression_Filter_Default',
)),
new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'),
new Twig_SimpleFilter('escape', 'twig_escape_filter', array(
'needs_environment' => true,
'is_safe_callback' => 'twig_escape_filter_is_safe',
)),
new Twig_SimpleFilter('e', 'twig_escape_filter', array(
'needs_environment' => true,
'is_safe_callback' => 'twig_escape_filter_is_safe',
)),
);
if (function_exists('mb_get_info')) {
$filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', array(
'needs_environment' => true,
));
$filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', array(
'needs_environment' => true,
));
}
return $filters;
}
public function getFunctions() {
return array(
new Twig_SimpleFunction('range', 'range'),
new Twig_SimpleFunction('constant', 'twig_constant'),
new Twig_SimpleFunction('cycle', 'twig_cycle'),
new Twig_SimpleFunction('random', 'twig_random', array(
'needs_environment' => true,
)),
new Twig_SimpleFunction('date', 'twig_date_converter', array(
'needs_environment' => true,
)),
new Twig_SimpleFunction('include', 'twig_include', array(
'needs_environment' => true,
'needs_context' => true,
)),
);
}
public function getTests() {
return array(
new Twig_SimpleTest('even', null, array(
'node_class' => 'Twig_Node_Expression_Test_Even',
)),
new Twig_SimpleTest('odd', null, array(
'node_class' => 'Twig_Node_Expression_Test_Odd',
)),
new Twig_SimpleTest('defined', null, array(
'node_class' => 'Twig_Node_Expression_Test_Defined',
)),
new Twig_SimpleTest('sameas', null, array(
'node_class' => 'Twig_Node_Expression_Test_Sameas',
)),
new Twig_SimpleTest('none', null, array(
'node_class' => 'Twig_Node_Expression_Test_Null',
)),
new Twig_SimpleTest('null', null, array(
'node_class' => 'Twig_Node_Expression_Test_Null',
)),
new Twig_SimpleTest('divisibleby', null, array(
'node_class' => 'Twig_Node_Expression_Test_Divisibleby',
)),
new Twig_SimpleTest('constant', null, array(
'node_class' => 'Twig_Node_Expression_Test_Constant',
)),
new Twig_SimpleTest('empty', 'twig_test_empty'),
new Twig_SimpleTest('iterable', 'twig_test_iterable'),
);
}
public function getOperators() {
return array(
array(
'not' => array(
'precedence' => 50,
'class' => 'Twig_Node_Expression_Unary_Not',
),
'-' => array(
'precedence' => 500,
'class' => 'Twig_Node_Expression_Unary_Neg',
),
'+' => array(
'precedence' => 500,
'class' => 'Twig_Node_Expression_Unary_Pos',
),
),
array(
'or' => array(
'precedence' => 10,
'class' => 'Twig_Node_Expression_Binary_Or',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'and' => array(
'precedence' => 15,
'class' => 'Twig_Node_Expression_Binary_And',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'b-or' => array(
'precedence' => 16,
'class' => 'Twig_Node_Expression_Binary_BitwiseOr',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'b-xor' => array(
'precedence' => 17,
'class' => 'Twig_Node_Expression_Binary_BitwiseXor',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'b-and' => array(
'precedence' => 18,
'class' => 'Twig_Node_Expression_Binary_BitwiseAnd',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'==' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_Equal',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'!=' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_NotEqual',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'<' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_Less',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'>' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_Greater',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'>=' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_GreaterEqual',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'<=' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_LessEqual',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'not in' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_NotIn',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'in' => array(
'precedence' => 20,
'class' => 'Twig_Node_Expression_Binary_In',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'..' => array(
'precedence' => 25,
'class' => 'Twig_Node_Expression_Binary_Range',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'+' => array(
'precedence' => 30,
'class' => 'Twig_Node_Expression_Binary_Add',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'-' => array(
'precedence' => 30,
'class' => 'Twig_Node_Expression_Binary_Sub',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'~' => array(
'precedence' => 40,
'class' => 'Twig_Node_Expression_Binary_Concat',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'*' => array(
'precedence' => 60,
'class' => 'Twig_Node_Expression_Binary_Mul',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'/' => array(
'precedence' => 60,
'class' => 'Twig_Node_Expression_Binary_Div',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'//' => array(
'precedence' => 60,
'class' => 'Twig_Node_Expression_Binary_FloorDiv',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'%' => array(
'precedence' => 60,
'class' => 'Twig_Node_Expression_Binary_Mod',
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'is' => array(
'precedence' => 100,
'callable' => array(
$this,
'parseTestExpression',
),
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'is not' => array(
'precedence' => 100,
'callable' => array(
$this,
'parseNotTestExpression',
),
'associativity' => Twig_ExpressionParser::OPERATOR_LEFT,
),
'**' => array(
'precedence' => 200,
'class' => 'Twig_Node_Expression_Binary_Power',
'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT,
),
),
);
}
public function parseNotTestExpression(Twig_Parser $parser, $node) {
return new Twig_Node_Expression_Unary_Not($this
->parseTestExpression($parser, $node), $parser
->getCurrentToken()
->getLine());
}
public function parseTestExpression(Twig_Parser $parser, $node) {
$stream = $parser
->getStream();
$name = $stream
->expect(Twig_Token::NAME_TYPE)
->getValue();
$arguments = null;
if ($stream
->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
$arguments = $parser
->getExpressionParser()
->parseArguments(true);
}
$class = $this
->getTestNodeClass($parser, $name, $node
->getLine());
return new $class($node, $name, $arguments, $parser
->getCurrentToken()
->getLine());
}
protected function getTestNodeClass(Twig_Parser $parser, $name, $line) {
$env = $parser
->getEnvironment();
$testMap = $env
->getTests();
if (!isset($testMap[$name])) {
$message = sprintf('The test "%s" does not exist', $name);
if ($alternatives = $env
->computeAlternatives($name, array_keys($env
->getTests()))) {
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
}
throw new Twig_Error_Syntax($message, $line, $parser
->getFilename());
}
if ($testMap[$name] instanceof Twig_SimpleTest) {
return $testMap[$name]
->getNodeClass();
}
return $testMap[$name] instanceof Twig_Test_Node ? $testMap[$name]
->getClass() : 'Twig_Node_Expression_Test';
}
public function getName() {
return 'core';
}
}
function twig_cycle($values, $position) {
if (!is_array($values) && !$values instanceof ArrayAccess) {
return $values;
}
return $values[$position % count($values)];
}
function twig_random(Twig_Environment $env, $values = null) {
if (null === $values) {
return mt_rand();
}
if (is_int($values) || is_float($values)) {
return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
}
if ($values instanceof Traversable) {
$values = iterator_to_array($values);
}
elseif (is_string($values)) {
if ('' === $values) {
return '';
}
if (null !== ($charset = $env
->getCharset())) {
if ('UTF-8' != $charset) {
$values = twig_convert_encoding($values, 'UTF-8', $charset);
}
$values = preg_split('/(?<!^)(?!$)/u', $values);
if ('UTF-8' != $charset) {
foreach ($values as $i => $value) {
$values[$i] = twig_convert_encoding($value, $charset, 'UTF-8');
}
}
}
else {
return $values[mt_rand(0, strlen($values) - 1)];
}
}
if (!is_array($values)) {
return $values;
}
if (0 === count($values)) {
throw new Twig_Error_Runtime('The random function cannot pick from an empty array.');
}
return $values[array_rand($values, 1)];
}
function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) {
if (null === $format) {
$formats = $env
->getExtension('core')
->getDateFormat();
$format = $date instanceof DateInterval ? $formats[1] : $formats[0];
}
if ($date instanceof DateInterval) {
return $date
->format($format);
}
return twig_date_converter($env, $date, $timezone)
->format($format);
}
function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) {
$date = twig_date_converter($env, $date, false);
$date
->modify($modifier);
return $date;
}
function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) {
if (!$timezone) {
$defaultTimezone = $env
->getExtension('core')
->getTimezone();
}
elseif (!$timezone instanceof DateTimeZone) {
$defaultTimezone = new DateTimeZone($timezone);
}
else {
$defaultTimezone = $timezone;
}
if ($date instanceof DateTime) {
$date = clone $date;
if (false !== $timezone) {
$date
->setTimezone($defaultTimezone);
}
return $date;
}
$asString = (string) $date;
if (ctype_digit($asString) || !empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1))) {
$date = '@' . $date;
}
$date = new DateTime($date, $defaultTimezone);
if (false !== $timezone) {
$date
->setTimezone($defaultTimezone);
}
return $date;
}
function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) {
$defaults = $env
->getExtension('core')
->getNumberFormat();
if (null === $decimal) {
$decimal = $defaults[0];
}
if (null === $decimalPoint) {
$decimalPoint = $defaults[1];
}
if (null === $thousandSep) {
$thousandSep = $defaults[2];
}
return number_format((double) $number, $decimal, $decimalPoint, $thousandSep);
}
function twig_urlencode_filter($url, $raw = false) {
if (is_array($url)) {
return http_build_query($url, '', '&');
}
if ($raw) {
return rawurlencode($url);
}
return urlencode($url);
}
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
function twig_jsonencode_filter($value, $options = 0) {
if ($value instanceof Twig_Markup) {
$value = (string) $value;
}
elseif (is_array($value)) {
array_walk_recursive($value, '_twig_markup2string');
}
return json_encode($value);
}
}
else {
function twig_jsonencode_filter($value, $options = 0) {
if ($value instanceof Twig_Markup) {
$value = (string) $value;
}
elseif (is_array($value)) {
array_walk_recursive($value, '_twig_markup2string');
}
return json_encode($value, $options);
}
}
function _twig_markup2string(&$value) {
if ($value instanceof Twig_Markup) {
$value = (string) $value;
}
}
function twig_array_merge($arr1, $arr2) {
if (!is_array($arr1) || !is_array($arr2)) {
throw new Twig_Error_Runtime('The merge filter only works with arrays or hashes.');
}
return array_merge($arr1, $arr2);
}
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) {
if ($item instanceof Traversable) {
$item = iterator_to_array($item, false);
}
if (is_array($item)) {
return array_slice($item, $start, $length, $preserveKeys);
}
$item = (string) $item;
if (function_exists('mb_get_info') && null !== ($charset = $env
->getCharset())) {
return mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
}
return null === $length ? substr($item, $start) : substr($item, $start, $length);
}
function twig_first(Twig_Environment $env, $item) {
$elements = twig_slice($env, $item, 0, 1, false);
return is_string($elements) ? $elements[0] : current($elements);
}
function twig_last(Twig_Environment $env, $item) {
$elements = twig_slice($env, $item, -1, 1, false);
return is_string($elements) ? $elements[0] : current($elements);
}
function twig_join_filter($value, $glue = '') {
if ($value instanceof Traversable) {
$value = iterator_to_array($value, false);
}
return implode($glue, (array) $value);
}
function twig_split_filter($value, $delimiter, $limit = null) {
if (empty($delimiter)) {
return str_split($value, null === $limit ? 1 : $limit);
}
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
}
function _twig_default_filter($value, $default = '') {
if (twig_test_empty($value)) {
return $default;
}
return $value;
}
function twig_get_array_keys_filter($array) {
if (is_object($array) && $array instanceof Traversable) {
return array_keys(iterator_to_array($array));
}
if (!is_array($array)) {
return array();
}
return array_keys($array);
}
function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false) {
if (is_object($item) && $item instanceof Traversable) {
return array_reverse(iterator_to_array($item), $preserveKeys);
}
if (is_array($item)) {
return array_reverse($item, $preserveKeys);
}
if (null !== ($charset = $env
->getCharset())) {
$string = (string) $item;
if ('UTF-8' != $charset) {
$item = twig_convert_encoding($string, 'UTF-8', $charset);
}
preg_match_all('/./us', $item, $matches);
$string = implode('', array_reverse($matches[0]));
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, $charset, 'UTF-8');
}
return $string;
}
return strrev((string) $item);
}
function twig_sort_filter($array) {
asort($array);
return $array;
}
function twig_in_filter($value, $compare) {
if (is_array($compare)) {
return in_array($value, $compare, is_object($value));
}
elseif (is_string($compare)) {
if (!strlen($value)) {
return empty($compare);
}
return false !== strpos($compare, (string) $value);
}
elseif ($compare instanceof Traversable) {
return in_array($value, iterator_to_array($compare, false), is_object($value));
}
return false;
}
function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) {
if ($autoescape && is_object($string) && $string instanceof Twig_Markup) {
return $string;
}
if (!is_string($string) && !(is_object($string) && method_exists($string, '__toString'))) {
return $string;
}
if (null === $charset) {
$charset = $env
->getCharset();
}
$string = (string) $string;
switch ($strategy) {
case 'js':
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
}
if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9,\\._]#Su', '_twig_escape_js_callback', $string);
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, $charset, 'UTF-8');
}
return $string;
case 'css':
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
}
if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string);
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, $charset, 'UTF-8');
}
return $string;
case 'html_attr':
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, 'UTF-8', $charset);
}
if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9,\\.\\-_]#Su', '_twig_escape_html_attr_callback', $string);
if ('UTF-8' != $charset) {
$string = twig_convert_encoding($string, $charset, 'UTF-8');
}
return $string;
case 'html':
static $htmlspecialcharsCharsets = array(
'iso-8859-1' => true,
'iso8859-1' => true,
'iso-8859-15' => true,
'iso8859-15' => true,
'utf-8' => true,
'cp866' => true,
'ibm866' => true,
'866' => true,
'cp1251' => true,
'windows-1251' => true,
'win-1251' => true,
'1251' => true,
'cp1252' => true,
'windows-1252' => true,
'1252' => true,
'koi8-r' => true,
'koi8-ru' => true,
'koi8r' => true,
'big5' => true,
'950' => true,
'gb2312' => true,
'936' => true,
'big5-hkscs' => true,
'shift_jis' => true,
'sjis' => true,
'932' => true,
'euc-jp' => true,
'eucjp' => true,
'iso8859-5' => true,
'iso-8859-5' => true,
'macroman' => true,
);
if (isset($htmlspecialcharsCharsets[strtolower($charset)])) {
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
}
$string = twig_convert_encoding($string, 'UTF-8', $charset);
$string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
return twig_convert_encoding($string, $charset, 'UTF-8');
case 'url':
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
return str_replace('%7E', '~', rawurlencode($string));
}
return rawurlencode($string);
default:
throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: html, js, url, css, and html_attr).', $strategy));
}
}
function twig_escape_filter_is_safe(Twig_Node $filterArgs) {
foreach ($filterArgs as $arg) {
if ($arg instanceof Twig_Node_Expression_Constant) {
return array(
$arg
->getAttribute('value'),
);
}
return array();
}
return array(
'html',
);
}
if (function_exists('mb_convert_encoding')) {
function twig_convert_encoding($string, $to, $from) {
return mb_convert_encoding($string, $to, $from);
}
}
elseif (function_exists('iconv')) {
function twig_convert_encoding($string, $to, $from) {
return iconv($from, $to, $string);
}
}
else {
function twig_convert_encoding($string, $to, $from) {
throw new Twig_Error_Runtime('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
}
}
function _twig_escape_js_callback($matches) {
$char = $matches[0];
if (!isset($char[1])) {
return '\\x' . strtoupper(substr('00' . bin2hex($char), -2));
}
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
return '\\u' . strtoupper(substr('0000' . bin2hex($char), -4));
}
function _twig_escape_css_callback($matches) {
$char = $matches[0];
if (!isset($char[1])) {
$hex = ltrim(strtoupper(bin2hex($char)), '0');
if (0 === strlen($hex)) {
$hex = '0';
}
return '\\' . $hex . ' ';
}
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
return '\\' . ltrim(strtoupper(bin2hex($char)), '0') . ' ';
}
function _twig_escape_html_attr_callback($matches) {
static $entityMap = array(
34 => 'quot',
38 => 'amp',
60 => 'lt',
62 => 'gt',
);
$chr = $matches[0];
$ord = ord($chr);
if ($ord <= 0x1f && $chr != "\t" && $chr != "\n" && $chr != "\r" || $ord >= 0x7f && $ord <= 0x9f) {
return '�';
}
if (strlen($chr) == 1) {
$hex = strtoupper(substr('00' . bin2hex($chr), -2));
}
else {
$chr = twig_convert_encoding($chr, 'UTF-16BE', 'UTF-8');
$hex = strtoupper(substr('0000' . bin2hex($chr), -4));
}
$int = hexdec($hex);
if (array_key_exists($int, $entityMap)) {
return sprintf('&%s;', $entityMap[$int]);
}
return sprintf('&#x%s;', $hex);
}
if (function_exists('mb_get_info')) {
function twig_length_filter(Twig_Environment $env, $thing) {
return is_scalar($thing) ? mb_strlen($thing, $env
->getCharset()) : count($thing);
}
function twig_upper_filter(Twig_Environment $env, $string) {
if (null !== ($charset = $env
->getCharset())) {
return mb_strtoupper($string, $charset);
}
return strtoupper($string);
}
function twig_lower_filter(Twig_Environment $env, $string) {
if (null !== ($charset = $env
->getCharset())) {
return mb_strtolower($string, $charset);
}
return strtolower($string);
}
function twig_title_string_filter(Twig_Environment $env, $string) {
if (null !== ($charset = $env
->getCharset())) {
return mb_convert_case($string, MB_CASE_TITLE, $charset);
}
return ucwords(strtolower($string));
}
function twig_capitalize_string_filter(Twig_Environment $env, $string) {
if (null !== ($charset = $env
->getCharset())) {
return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset) . mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset);
}
return ucfirst(strtolower($string));
}
}
else {
function twig_length_filter(Twig_Environment $env, $thing) {
return is_scalar($thing) ? strlen($thing) : count($thing);
}
function twig_title_string_filter(Twig_Environment $env, $string) {
return ucwords(strtolower($string));
}
function twig_capitalize_string_filter(Twig_Environment $env, $string) {
return ucfirst(strtolower($string));
}
}
function twig_ensure_traversable($seq) {
if ($seq instanceof Traversable || is_array($seq)) {
return $seq;
}
return array();
}
function twig_test_empty($value) {
if ($value instanceof Countable) {
return 0 == count($value);
}
return '' === $value || false === $value || null === $value || array() === $value;
}
function twig_test_iterable($value) {
return $value instanceof Traversable || is_array($value);
}
function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) {
if ($withContext) {
$variables = array_merge($context, $variables);
}
if ($isSandboxed = $sandboxed && $env
->hasExtension('sandbox')) {
$sandbox = $env
->getExtension('sandbox');
if (!($alreadySandboxed = $sandbox
->isSandboxed())) {
$sandbox
->enableSandbox();
}
}
try {
return $env
->resolveTemplate($template)
->display($variables);
} catch (Twig_Error_Loader $e) {
if (!$ignoreMissing) {
throw $e;
}
}
if ($isSandboxed && !$alreadySandboxed) {
$sandbox
->disableSandbox();
}
}
function twig_constant($constant, $object = null) {
if (null !== $object) {
$constant = get_class($object) . '::' . $constant;
}
return constant($constant);
}
function twig_array_batch($items, $size, $fill = null) {
if ($items instanceof Traversable) {
$items = iterator_to_array($items, false);
}
$size = ceil($size);
$result = array_chunk($items, $size, true);
if (null !== $fill) {
$last = count($result) - 1;
$result[$last] = array_merge($result[$last], array_fill(0, $size - count($result[$last]), $fill));
}
return $result;
}