smarty_internal_compile_continue.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Continue
  4. *
  5. * Compiles the {continue} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Continue Class
  13. *
  14. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase {
  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 object $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. * @return string compiled code
  39. */
  40. public function compile($args, $compiler, $parameter)
  41. {
  42. static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
  43. // check and get attributes
  44. $_attr = $this->getAttributes($compiler, $args);
  45. if ($_attr['nocache'] === true) {
  46. $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
  47. }
  48. if (isset($_attr['levels'])) {
  49. if (!is_numeric($_attr['levels'])) {
  50. $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
  51. }
  52. $_levels = $_attr['levels'];
  53. } else {
  54. $_levels = 1;
  55. }
  56. $level_count = $_levels;
  57. $stack_count = count($compiler->_tag_stack) - 1;
  58. while ($level_count > 0 && $stack_count >= 0) {
  59. if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
  60. $level_count--;
  61. }
  62. $stack_count--;
  63. }
  64. if ($level_count != 0) {
  65. $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
  66. }
  67. $compiler->has_code = true;
  68. return "<?php continue {$_levels}?>";
  69. }
  70. }
  71. ?>