smarty_internal_compile_continue.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 object $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. *
  39. * @return string compiled code
  40. */
  41. public function compile($args, $compiler, $parameter)
  42. {
  43. static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
  44. // check and get attributes
  45. $_attr = $this->getAttributes($compiler, $args);
  46. if ($_attr['nocache'] === true) {
  47. $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
  48. }
  49. if (isset($_attr['levels'])) {
  50. if (!is_numeric($_attr['levels'])) {
  51. $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
  52. }
  53. $_levels = $_attr['levels'];
  54. } else {
  55. $_levels = 1;
  56. }
  57. $level_count = $_levels;
  58. $stack_count = count($compiler->_tag_stack) - 1;
  59. while ($level_count > 0 && $stack_count >= 0) {
  60. if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
  61. $level_count --;
  62. }
  63. $stack_count --;
  64. }
  65. if ($level_count != 0) {
  66. $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
  67. }
  68. return "<?php continue {$_levels};?>";
  69. }
  70. }