PEEL Shopping
Open source ecommerce : PEEL Shopping
Core.php
Go to the documentation of this file.
1 <?php
2 
3 if (!defined('ENT_SUBSTITUTE')) {
4  define('ENT_SUBSTITUTE', 8);
5 }
6 
7 /*
8  * This file is part of Twig.
9  *
10  * (c) 2009 Fabien Potencier
11  *
12  * For the full copyright and license information, please view the LICENSE
13  * file that was distributed with this source code.
14  */
16 {
17  protected $dateFormats = array('F j, Y H:i', '%d days');
18  protected $numberFormat = array(0, '.', ',');
19  protected $timezone = null;
20 
27  public function setDateFormat($format = null, $dateIntervalFormat = null)
28  {
29  if (null !== $format) {
30  $this->dateFormats[0] = $format;
31  }
32 
33  if (null !== $dateIntervalFormat) {
34  $this->dateFormats[1] = $dateIntervalFormat;
35  }
36  }
37 
43  public function getDateFormat()
44  {
45  return $this->dateFormats;
46  }
47 
53  public function setTimezone($timezone)
54  {
55  $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
56  }
57 
63  public function getTimezone()
64  {
65  if (null === $this->timezone) {
66  $this->timezone = new DateTimeZone(date_default_timezone_get());
67  }
68 
69  return $this->timezone;
70  }
71 
79  public function setNumberFormat($decimal, $decimalPoint, $thousandSep)
80  {
81  $this->numberFormat = array($decimal, $decimalPoint, $thousandSep);
82  }
83 
89  public function getNumberFormat()
90  {
91  return $this->numberFormat;
92  }
93 
99  public function getTokenParsers()
100  {
101  return array(
102  new Twig_TokenParser_For(),
103  new Twig_TokenParser_If(),
107  new Twig_TokenParser_Use(),
111  new Twig_TokenParser_From(),
112  new Twig_TokenParser_Set(),
115  new Twig_TokenParser_Do(),
117  );
118  }
119 
125  public function getFilters()
126  {
127  $filters = array(
128  // formatting filters
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)),
131  new Twig_SimpleFilter('format', 'sprintf'),
132  new Twig_SimpleFilter('replace', 'strtr'),
133  new Twig_SimpleFilter('number_format', 'twig_number_format_filter', array('needs_environment' => true)),
134  new Twig_SimpleFilter('abs', 'abs'),
135 
136  // encoding
137  new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'),
138  new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'),
139  new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'),
140 
141  // string filters
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)),
144  new Twig_SimpleFilter('upper', 'strtoupper'),
145  new Twig_SimpleFilter('lower', 'strtolower'),
146  new Twig_SimpleFilter('striptags', 'strip_tags'),
147  new Twig_SimpleFilter('trim', 'trim'),
148  new Twig_SimpleFilter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))),
149 
150  // array helpers
151  new Twig_SimpleFilter('join', 'twig_join_filter'),
152  new Twig_SimpleFilter('split', 'twig_split_filter'),
153  new Twig_SimpleFilter('sort', 'twig_sort_filter'),
154  new Twig_SimpleFilter('merge', 'twig_array_merge'),
155  new Twig_SimpleFilter('batch', 'twig_array_batch'),
156 
157  // string/array filters
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)),
162  new Twig_SimpleFilter('last', 'twig_last', array('needs_environment' => true)),
163 
164  // iteration and runtime
165  new Twig_SimpleFilter('default', '_twig_default_filter', array('node_class' => 'Twig_Node_Expression_Filter_Default')),
166  new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'),
167 
168  // escaping
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')),
171  );
172 
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));
176  }
177 
178  return $filters;
179  }
180 
186  public function getFunctions()
187  {
188  return array(
189  new Twig_SimpleFunction('range', 'range'),
190  new Twig_SimpleFunction('constant', 'twig_constant'),
191  new Twig_SimpleFunction('cycle', 'twig_cycle'),
192  new Twig_SimpleFunction('random', 'twig_random', 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'))),
195  );
196  }
197 
203  public function getTests()
204  {
205  return array(
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')),
214  new Twig_SimpleTest('empty', 'twig_test_empty'),
215  new Twig_SimpleTest('iterable', 'twig_test_iterable'),
216  );
217  }
218 
224  public function getOperators()
225  {
226  return array(
227  array(
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'),
231  ),
232  array(
233  'or' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
234  'and' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
235  'b-or' => array('precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
236  'b-xor' => array('precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
237  'b-and' => array('precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
238  '==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
239  '!=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
240  '<' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
241  '>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
242  '>=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
243  '<=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
244  'not in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
245  'in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
246  '..' => array('precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
247  '+' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
248  '-' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
249  '~' => array('precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
250  '*' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
251  '/' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
252  '//' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
253  '%' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
254  'is' => array('precedence' => 100, 'callable' => array($this, 'parseTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
255  'is not' => array('precedence' => 100, 'callable' => array($this, 'parseNotTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
256  '**' => array('precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT),
257  ),
258  );
259  }
260 
261  public function parseNotTestExpression(Twig_Parser $parser, $node)
262  {
263  return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($parser, $node), $parser->getCurrentToken()->getLine());
264  }
265 
266  public function parseTestExpression(Twig_Parser $parser, $node)
267  {
268  $stream = $parser->getStream();
269  $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
270  $arguments = null;
271  if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
272  $arguments = $parser->getExpressionParser()->parseArguments(true);
273  }
274 
275  $class = $this->getTestNodeClass($parser, $name, $node->getLine());
276 
277  return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine());
278  }
279 
280  protected function getTestNodeClass(Twig_Parser $parser, $name, $line)
281  {
282  $env = $parser->getEnvironment();
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));
288  }
289 
290  throw new Twig_Error_Syntax($message, $line, $parser->getFilename());
291  }
292 
293  if ($testMap[$name] instanceof Twig_SimpleTest) {
294  return $testMap[$name]->getNodeClass();
295  }
296 
297  return $testMap[$name] instanceof Twig_Test_Node ? $testMap[$name]->getClass() : 'Twig_Node_Expression_Test';
298  }
299 
305  public function getName()
306  {
307  return 'core';
308  }
309 }
310 
319 function twig_cycle($values, $position)
320 {
321  if (!is_array($values) && !$values instanceof ArrayAccess) {
322  return $values;
323  }
324 
325  return $values[$position % count($values)];
326 }
327 
341 function twig_random(Twig_Environment $env, $values = null)
342 {
343  if (null === $values) {
344  return mt_rand();
345  }
346 
347  if (is_int($values) || is_float($values)) {
348  return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
349  }
350 
351  if ($values instanceof Traversable) {
352  $values = iterator_to_array($values);
353  } elseif (is_string($values)) {
354  if ('' === $values) {
355  return '';
356  }
357  if (null !== $charset = $env->getCharset()) {
358  if ('UTF-8' != $charset) {
359  $values = twig_convert_encoding($values, 'UTF-8', $charset);
360  }
361 
362  // unicode version of str_split()
363  // split at all positions, but not after the start and not before the end
364  $values = preg_split('/(?<!^)(?!$)/u', $values);
365 
366  if ('UTF-8' != $charset) {
367  foreach ($values as $i => $value) {
368  $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8');
369  }
370  }
371  } else {
372  return $values[mt_rand(0, strlen($values) - 1)];
373  }
374  }
375 
376  if (!is_array($values)) {
377  return $values;
378  }
379 
380  if (0 === count($values)) {
381  throw new Twig_Error_Runtime('The random function cannot pick from an empty array.');
382  }
383 
384  return $values[array_rand($values, 1)];
385 }
386 
401 function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null)
402 {
403  if (null === $format) {
404  $formats = $env->getExtension('core')->getDateFormat();
405  $format = $date instanceof DateInterval ? $formats[1] : $formats[0];
406  }
407 
408  if ($date instanceof DateInterval) {
409  return $date->format($format);
410  }
411 
412  return twig_date_converter($env, $date, $timezone)->format($format);
413 }
414 
428 function twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
429 {
430  $date = twig_date_converter($env, $date, false);
431  $date->modify($modifier);
432 
433  return $date;
434 }
435 
451 function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null)
452 {
453  // determine the timezone
454  if (!$timezone) {
455  $defaultTimezone = $env->getExtension('core')->getTimezone();
456  } elseif (!$timezone instanceof DateTimeZone) {
457  $defaultTimezone = new DateTimeZone($timezone);
458  } else {
459  $defaultTimezone = $timezone;
460  }
461 
462  if ($date instanceof DateTime) {
463  $date = clone $date;
464  if (false !== $timezone) {
465  $date->setTimezone($defaultTimezone);
466  }
467 
468  return $date;
469  }
470 
471  $asString = (string) $date;
472  if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
473  $date = '@'.$date;
474  }
475 
476  $date = new DateTime($date, $defaultTimezone);
477  if (false !== $timezone) {
478  $date->setTimezone($defaultTimezone);
479  }
480 
481  return $date;
482 }
483 
499 function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
500 {
501  $defaults = $env->getExtension('core')->getNumberFormat();
502  if (null === $decimal) {
503  $decimal = $defaults[0];
504  }
505 
506  if (null === $decimalPoint) {
507  $decimalPoint = $defaults[1];
508  }
509 
510  if (null === $thousandSep) {
511  $thousandSep = $defaults[2];
512  }
513 
514  return number_format((float) $number, $decimal, $decimalPoint, $thousandSep);
515 }
516 
525 function twig_urlencode_filter($url, $raw = false)
526 {
527  if (is_array($url)) {
528  return http_build_query($url, '', '&');
529  }
530 
531  if ($raw) {
532  return rawurlencode($url);
533  }
534 
535  return urlencode($url);
536 }
537 
538 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
547  function twig_jsonencode_filter($value, $options = 0)
548  {
549  if ($value instanceof Twig_Markup) {
550  $value = (string) $value;
551  } elseif (is_array($value)) {
552  array_walk_recursive($value, '_twig_markup2string');
553  }
554 
555  return json_encode($value);
556  }
557 } else {
566  function twig_jsonencode_filter($value, $options = 0)
567  {
568  if ($value instanceof Twig_Markup) {
569  $value = (string) $value;
570  } elseif (is_array($value)) {
571  array_walk_recursive($value, '_twig_markup2string');
572  }
573 
574  return json_encode($value, $options);
575  }
576 }
577 
578 function _twig_markup2string(&$value)
579 {
580  if ($value instanceof Twig_Markup) {
581  $value = (string) $value;
582  }
583 }
584 
601 function twig_array_merge($arr1, $arr2)
602 {
603  if (!is_array($arr1) || !is_array($arr2)) {
604  throw new Twig_Error_Runtime('The merge filter only works with arrays or hashes.');
605  }
606 
607  return array_merge($arr1, $arr2);
608 }
609 
621 function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false)
622 {
623  if ($item instanceof Traversable) {
624  $item = iterator_to_array($item, false);
625  }
626 
627  if (is_array($item)) {
628  return array_slice($item, $start, $length, $preserveKeys);
629  }
630 
631  $item = (string) $item;
632 
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);
635  }
636 
637  return null === $length ? substr($item, $start) : substr($item, $start, $length);
638 }
639 
648 function twig_first(Twig_Environment $env, $item)
649 {
650  $elements = twig_slice($env, $item, 0, 1, false);
651 
652  return is_string($elements) ? $elements[0] : current($elements);
653 }
654 
663 function twig_last(Twig_Environment $env, $item)
664 {
665  $elements = twig_slice($env, $item, -1, 1, false);
666 
667  return is_string($elements) ? $elements[0] : current($elements);
668 }
669 
688 function twig_join_filter($value, $glue = '')
689 {
690  if ($value instanceof Traversable) {
691  $value = iterator_to_array($value, false);
692  }
693 
694  return implode($glue, (array) $value);
695 }
696 
720 function twig_split_filter($value, $delimiter, $limit = null)
721 {
722  if (empty($delimiter)) {
723  return str_split($value, null === $limit ? 1 : $limit);
724  }
725 
726  return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
727 }
728 
729 // The '_default' filter is used internally to avoid using the ternary operator
730 // which costs a lot for big contexts (before PHP 5.4). So, on average,
731 // a function call is cheaper.
732 function _twig_default_filter($value, $default = '')
733 {
734  if (twig_test_empty($value)) {
735  return $default;
736  }
737 
738  return $value;
739 }
740 
756 function twig_get_array_keys_filter($array)
757 {
758  if (is_object($array) && $array instanceof Traversable) {
759  return array_keys(iterator_to_array($array));
760  }
761 
762  if (!is_array($array)) {
763  return array();
764  }
765 
766  return array_keys($array);
767 }
768 
778 function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false)
779 {
780  if (is_object($item) && $item instanceof Traversable) {
781  return array_reverse(iterator_to_array($item), $preserveKeys);
782  }
783 
784  if (is_array($item)) {
785  return array_reverse($item, $preserveKeys);
786  }
787 
788  if (null !== $charset = $env->getCharset()) {
789  $string = (string) $item;
790 
791  if ('UTF-8' != $charset) {
792  $item = twig_convert_encoding($string, 'UTF-8', $charset);
793  }
794 
795  preg_match_all('/./us', $item, $matches);
796 
797  $string = implode('', array_reverse($matches[0]));
798 
799  if ('UTF-8' != $charset) {
800  $string = twig_convert_encoding($string, $charset, 'UTF-8');
801  }
802 
803  return $string;
804  }
805 
806  return strrev((string) $item);
807 }
808 
814 function twig_sort_filter($array)
815 {
816  asort($array);
817 
818  return $array;
819 }
820 
821 /* used internally */
822 function twig_in_filter($value, $compare)
823 {
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);
829  }
830 
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));
834  }
835 
836  return false;
837 }
838 
848 function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
849 {
850  if ($autoescape && $string instanceof Twig_Markup) {
851  return $string;
852  }
853 
854  if (!is_string($string)) {
855  if (is_object($string) && method_exists($string, '__toString')) {
856  $string = (string) $string;
857  } else {
858  return $string;
859  }
860  }
861 
862  if (null === $charset) {
863  $charset = $env->getCharset();
864  }
865 
866  switch ($strategy) {
867  case 'html':
868  // see http://php.net/htmlspecialchars
869 
870  // Using a static variable to avoid initializing the array
871  // each time the function is called. Moving the declaration on the
872  // top of the function slow downs other escaping strategies.
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,
879  '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,
888  );
889 
890  if (isset($htmlspecialcharsCharsets[$charset])) {
891  return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
892  }
893 
894  if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) {
895  // cache the lowercase variant for future iterations
896  $htmlspecialcharsCharsets[$charset] = true;
897 
898  return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
899  }
900 
901  $string = twig_convert_encoding($string, 'UTF-8', $charset);
902  $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
903 
904  return twig_convert_encoding($string, $charset, 'UTF-8');
905 
906  case 'js':
907  // escape all non-alphanumeric characters
908  // into their \xHH or \uHHHH representations
909  if ('UTF-8' != $charset) {
910  $string = twig_convert_encoding($string, 'UTF-8', $charset);
911  }
912 
913  if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
914  throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
915  }
916 
917  $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string);
918 
919  if ('UTF-8' != $charset) {
920  $string = twig_convert_encoding($string, $charset, 'UTF-8');
921  }
922 
923  return $string;
924 
925  case 'css':
926  if ('UTF-8' != $charset) {
927  $string = twig_convert_encoding($string, 'UTF-8', $charset);
928  }
929 
930  if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
931  throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
932  }
933 
934  $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string);
935 
936  if ('UTF-8' != $charset) {
937  $string = twig_convert_encoding($string, $charset, 'UTF-8');
938  }
939 
940  return $string;
941 
942  case 'html_attr':
943  if ('UTF-8' != $charset) {
944  $string = twig_convert_encoding($string, 'UTF-8', $charset);
945  }
946 
947  if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) {
948  throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.');
949  }
950 
951  $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string);
952 
953  if ('UTF-8' != $charset) {
954  $string = twig_convert_encoding($string, $charset, 'UTF-8');
955  }
956 
957  return $string;
958 
959  case 'url':
960  // hackish test to avoid version_compare that is much slower, this works unless PHP releases a 5.10.*
961  // at that point however PHP 5.2.* support can be removed
962  if (PHP_VERSION < '5.3.0') {
963  return str_replace('%7E', '~', rawurlencode($string));
964  }
965 
966  return rawurlencode($string);
967 
968  default:
969  throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: html, js, url, css, and html_attr).', $strategy));
970  }
971 }
972 
973 /* used internally */
974 function twig_escape_filter_is_safe(Twig_Node $filterArgs)
975 {
976  foreach ($filterArgs as $arg) {
977  if ($arg instanceof Twig_Node_Expression_Constant) {
978  return array($arg->getAttribute('value'));
979  }
980 
981  return array();
982  }
983 
984  return array('html');
985 }
986 
987 if (function_exists('mb_convert_encoding')) {
988  function twig_convert_encoding($string, $to, $from)
989  {
990  return mb_convert_encoding($string, $to, $from);
991  }
992 } elseif (function_exists('iconv')) {
993  function twig_convert_encoding($string, $to, $from)
994  {
995  return iconv($from, $to, $string);
996  }
997 } else {
998  function twig_convert_encoding($string, $to, $from)
999  {
1000  throw new Twig_Error_Runtime('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
1001  }
1002 }
1003 
1004 function _twig_escape_js_callback($matches)
1005 {
1006  $char = $matches[0];
1007 
1008  // \xHH
1009  if (!isset($char[1])) {
1010  return '\\x'.strtoupper(substr('00'.bin2hex($char), -2));
1011  }
1012 
1013  // \uHHHH
1014  $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
1015 
1016  return '\\u'.strtoupper(substr('0000'.bin2hex($char), -4));
1017 }
1018 
1019 function _twig_escape_css_callback($matches)
1020 {
1021  $char = $matches[0];
1022 
1023  // \xHH
1024  if (!isset($char[1])) {
1025  $hex = ltrim(strtoupper(bin2hex($char)), '0');
1026  if (0 === strlen($hex)) {
1027  $hex = '0';
1028  }
1029 
1030  return '\\'.$hex.' ';
1031  }
1032 
1033  // \uHHHH
1034  $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
1035 
1036  return '\\'.ltrim(strtoupper(bin2hex($char)), '0').' ';
1037 }
1038 
1045 function _twig_escape_html_attr_callback($matches)
1046 {
1047  /*
1048  * While HTML supports far more named entities, the lowest common denominator
1049  * has become HTML5's XML Serialisation which is restricted to the those named
1050  * entities that XML supports. Using HTML entities would result in this error:
1051  * XML Parsing Error: undefined entity
1052  */
1053  static $entityMap = array(
1054  34 => 'quot', /* quotation mark */
1055  38 => 'amp', /* ampersand */
1056  60 => 'lt', /* less-than sign */
1057  62 => 'gt', /* greater-than sign */
1058  );
1059 
1060  $chr = $matches[0];
1061  $ord = ord($chr);
1062 
1067  if (($ord <= 0x1f && $chr != "\t" && $chr != "\n" && $chr != "\r") || ($ord >= 0x7f && $ord <= 0x9f)) {
1068  return '&#xFFFD;';
1069  }
1070 
1075  if (strlen($chr) == 1) {
1076  $hex = strtoupper(substr('00'.bin2hex($chr), -2));
1077  } else {
1078  $chr = twig_convert_encoding($chr, 'UTF-16BE', 'UTF-8');
1079  $hex = strtoupper(substr('0000'.bin2hex($chr), -4));
1080  }
1081 
1082  $int = hexdec($hex);
1083  if (array_key_exists($int, $entityMap)) {
1084  return sprintf('&%s;', $entityMap[$int]);
1085  }
1086 
1092  return sprintf('&#x%s;', $hex);
1093 }
1094 
1095 // add multibyte extensions if possible
1096 if (function_exists('mb_get_info')) {
1105  function twig_length_filter(Twig_Environment $env, $thing)
1106  {
1107  return is_scalar($thing) ? mb_strlen($thing, $env->getCharset()) : count($thing);
1108  }
1109 
1118  function twig_upper_filter(Twig_Environment $env, $string)
1119  {
1120  if (null !== ($charset = $env->getCharset())) {
1121  return mb_strtoupper($string, $charset);
1122  }
1123 
1124  return strtoupper($string);
1125  }
1126 
1135  function twig_lower_filter(Twig_Environment $env, $string)
1136  {
1137  if (null !== ($charset = $env->getCharset())) {
1138  return mb_strtolower($string, $charset);
1139  }
1140 
1141  return strtolower($string);
1142  }
1143 
1152  function twig_title_string_filter(Twig_Environment $env, $string)
1153  {
1154  if (null !== ($charset = $env->getCharset())) {
1155  return mb_convert_case($string, MB_CASE_TITLE, $charset);
1156  }
1157 
1158  return ucwords(strtolower($string));
1159  }
1160 
1169  function twig_capitalize_string_filter(Twig_Environment $env, $string)
1170  {
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);
1174  }
1175 
1176  return ucfirst(strtolower($string));
1177  }
1178 }
1179 // and byte fallback
1180 else {
1189  function twig_length_filter(Twig_Environment $env, $thing)
1190  {
1191  return is_scalar($thing) ? strlen($thing) : count($thing);
1192  }
1193 
1202  function twig_title_string_filter(Twig_Environment $env, $string)
1203  {
1204  return ucwords(strtolower($string));
1205  }
1206 
1215  function twig_capitalize_string_filter(Twig_Environment $env, $string)
1216  {
1217  return ucfirst(strtolower($string));
1218  }
1219 }
1220 
1221 /* used internally */
1222 function twig_ensure_traversable($seq)
1223 {
1224  if ($seq instanceof Traversable || is_array($seq)) {
1225  return $seq;
1226  }
1227 
1228  return array();
1229 }
1230 
1245 function twig_test_empty($value)
1246 {
1247  if ($value instanceof Countable) {
1248  return 0 == count($value);
1249  }
1250 
1251  return '' === $value || false === $value || null === $value || array() === $value;
1252 }
1253 
1268 function twig_test_iterable($value)
1269 {
1270  return $value instanceof Traversable || is_array($value);
1271 }
1272 
1284 function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false)
1285 {
1286  if ($withContext) {
1287  $variables = array_merge($context, $variables);
1288  }
1289 
1290  if ($isSandboxed = $sandboxed && $env->hasExtension('sandbox')) {
1291  $sandbox = $env->getExtension('sandbox');
1292  if (!$alreadySandboxed = $sandbox->isSandboxed()) {
1293  $sandbox->enableSandbox();
1294  }
1295  }
1296 
1297  try {
1298  return $env->resolveTemplate($template)->render($variables);
1299  } catch (Twig_Error_Loader $e) {
1300  if (!$ignoreMissing) {
1301  throw $e;
1302  }
1303  }
1304 
1305  if ($isSandboxed && !$alreadySandboxed) {
1306  $sandbox->disableSandbox();
1307  }
1308 }
1309 
1318 function twig_constant($constant, $object = null)
1319 {
1320  if (null !== $object) {
1321  $constant = get_class($object).'::'.$constant;
1322  }
1323 
1324  return constant($constant);
1325 }
1326 
1336 function twig_array_batch($items, $size, $fill = null)
1337 {
1338  if ($items instanceof Traversable) {
1339  $items = iterator_to_array($items, false);
1340  }
1341 
1342  $size = ceil($size);
1343 
1344  $result = array_chunk($items, $size, true);
1345 
1346  if (null !== $fill) {
1347  $last = count($result) - 1;
1348  $result[$last] = array_merge(
1349  $result[$last],
1350  array_fill(0, $size - count($result[$last]), $fill)
1351  );
1352  }
1353 
1354  return $result;
1355 }
getDateFormat()
Gets the default format to be used by the date filter.
Definition: Core.php:43
Flushes the output to the client.
Definition: Flush.php:17
$result
twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
Returns a new date object modified.
Definition: Core.php:428
getNumberFormat()
Get the default format used by the number_format filter.
Definition: Core.php:89
getTimezone()
Gets the default timezone to be used by the date filter.
Definition: Core.php:63
if($rub=fetch_assoc($rub_query)) if(check_if_module_active('url_rewriting')) $class
Definition: index.php:68
setDateFormat($format=null, $dateIntervalFormat=null)
Sets the default format to be used by the date filter.
Definition: Core.php:27
Defines a macro.
Definition: Macro.php:21
getFilename()
Definition: Parser.php:55
resolveTemplate($names)
Represents a node in the AST.
Definition: Node.php:18
Includes a template.
Definition: Include.php:22
Represents a template test as a Node.
Definition: Node.php:18
Represents a template function.
getTestNodeClass(Twig_Parser $parser, $name, $line)
Definition: Core.php:280
getStream()
Gets the token stream.
Definition: Parser.php:347
Filters a section of a template by applying filters.
Definition: Filter.php:21
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
getOperators()
Returns a list of operators to add to the existing list.
Definition: Core.php:224
$start
Definition: attributs.php:22
Embeds a template.
Definition: Embed.php:15
getTokenParsers()
Returns the token parser instance to add to the existing list.
Definition: Core.php:99
Default parser implementation.
Definition: Parser.php:18
getExpressionParser()
Gets the expression parser.
Definition: Parser.php:327
Extends a template by another one.
Definition: Extends.php:20
Defines a variable.
Definition: Set.php:29
Imports macros.
Definition: Import.php:19
getCurrentToken()
Gets the current token.
Definition: Parser.php:357
parseNotTestExpression(Twig_Parser $parser, $node)
Definition: Core.php:261
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))
Definition: chart-data.php:160
Marks a content as safe.
Definition: Markup.php:17
Imports macros.
Definition: From.php:19
getTests()
Returns a list of tests to add to the existing list.
Definition: Core.php:203
parseTestExpression(Twig_Parser $parser, $node)
Definition: Core.php:266
twig_cycle($values, $position)
Cycles over a value.
Definition: Core.php:319
Remove whitespaces between HTML tags.
Definition: Spaceless.php:25
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
Definition: Core.php:451
Loops over each item of a sequence.
Definition: For.php:24
getExtension($name)
Gets an extension by name.
setTimezone($timezone)
Sets the default timezone to be used by the date filter.
Definition: Core.php:53
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.
Definition: Core.php:79
twig_date_format_filter(Twig_Environment $env, $date, $format=null, $timezone=null)
Converts a date to the given format.
Definition: Core.php:401
twig_urlencode_filter($url, $raw=false)
URL encodes a string as a path segment or an array as a query string.
Definition: Core.php:525
Stores the Twig configuration.
Definition: Environment.php:17
getCharset()
Gets the default template charset.
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:341
getEnvironment()
Definition: Parser.php:45
const NAME_TYPE
Definition: Token.php:30
getFunctions()
Returns a list of global functions to add to the existing list.
Definition: Core.php:186
getFilters()
Returns a list of filters to add to the existing list.
Definition: Core.php:125
const PUNCTUATION_TYPE
Definition: Token.php:34
Represents a template test.
Definition: SimpleTest.php:17
Tests a condition.
Definition: If.php:26
Represents a template filter.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
Marks a section of a template as being reusable.
Definition: Block.php:23
Evaluates an expression, discarding the returned value.
Definition: Do.php:15
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:18
twig_number_format_filter(Twig_Environment $env, $number, $decimal=null, $decimalPoint=null, $thousandSep=null)
Number format filter.
Definition: Core.php:499
getName()
Returns the name of the extension.
Definition: Core.php:305
Imports blocks defined in another template into the current template.
Definition: Use.php:26

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.