You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_compile_continue.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Continue
  4. * Compiles the {continue} tag
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Continue Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $optional_attributes = array('levels');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $shorttag_order = array('levels');
  32. /**
  33. * Compiles code for the {continue} tag
  34. *
  35. * @param array $args array with attributes from parser
  36. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. *
  39. * @return string compiled code
  40. * @throws \SmartyCompilerException
  41. */
  42. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
  43. {
  44. static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
  45. // check and get attributes
  46. $_attr = $this->getAttributes($compiler, $args);
  47. if ($_attr['nocache'] === true) {
  48. $compiler->trigger_template_error('nocache option not allowed', null, true);
  49. }
  50. if (isset($_attr['levels'])) {
  51. if (!is_numeric($_attr['levels'])) {
  52. $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
  53. }
  54. $_levels = $_attr['levels'];
  55. } else {
  56. $_levels = 1;
  57. }
  58. $level_count = $_levels;
  59. $stack_count = count($compiler->_tag_stack) - 1;
  60. while ($level_count > 0 && $stack_count >= 0) {
  61. if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
  62. $level_count --;
  63. }
  64. $stack_count --;
  65. }
  66. if ($level_count != 0) {
  67. $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
  68. }
  69. return "<?php continue {$_levels};?>";
  70. }
  71. }