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.

67 lines
2.3 KiB

  1. <?php
  2. /**
  3. * Balises SPIP génériques supplémentaires, du genre Bonux
  4. *
  5. * @copyright 2015-2016
  6. * @author JLuc chez no-log.org
  7. * @licence GPL
  8. */
  9. // gestion du niveau d'imbrication
  10. function switchcase_niveau($add = false) {
  11. static $niveau = 0;
  12. if ($add) $niveau += $add;
  13. if ($niveau < 0) $niveau = 0;
  14. return $niveau;
  15. }
  16. function balise_SWITCH_dist($p) {
  17. $_val = interprete_argument_balise(1, $p);
  18. if ($_val === NULL) {
  19. // sans argument, renvoie la valeur testée (ou vide hors contexte)
  20. $p->code = "(isset(\$Pile['vars']['_switch_']) ? \$Pile['vars']['_switch_'] : '')";
  21. // $err = array('zbug_balise_sans_argument', array('balise' => ' #SWITCH'));
  22. // erreur_squelette($err, $p);
  23. }
  24. else {
  25. $p->code =
  26. "(vide(\$Pile['vars']['_switch_'] = \$Pile['vars']['_switch_'.switchcase_niveau(1)] = $_val)"
  27. . ".vide(\$Pile['vars']['_switch_matched_'] = \$Pile['vars']['_switch_matched_'.switchcase_niveau()] = ''))";
  28. // #GET{_switch_} renvoie maintenant la valeur testée
  29. // et #GET{_switch_matched_} indique si un test #CASE a déjà été satisfait
  30. }
  31. $p->interdire_script = false;
  32. return $p;
  33. }
  34. function balise_CASE_dist($p) {
  35. $tested = interprete_argument_balise(1, $p);
  36. if ($tested === NULL) {
  37. // sans argument, renvoie ' ' si la valeur a été trouvée, '' sinon
  38. $p->code = "(isset(\$Pile['vars']['_switch_matched_']) ? \$Pile['vars']['_switch_matched_'] : '')";
  39. // $err = array('zbug_balise_sans_argument', array('balise' => ' #CASE'));
  40. // erreur_squelette($err, $p);
  41. }
  42. else {
  43. $p->code = "(($tested == \$Pile['vars']['_switch_'])"
  44. . " ? ' '.vide(\$Pile['vars']['_switch_matched_'] = \$Pile['vars']['_switch_matched_'.switchcase_niveau()] = ' ')"
  45. . " : '')";
  46. };
  47. $p->interdire_script = false;
  48. return $p;
  49. }
  50. function balise_CASE_DEFAULT_dist($p) {
  51. $p->code = "(\$Pile['vars']['_switch_matched_'] ? '' : ' ')";
  52. $p->interdire_script = false;
  53. return $p;
  54. }
  55. function balise_SWITCH_END_dist($p) {
  56. $p->code =
  57. "(!switchcase_niveau(-1) ? vide(\$Pile['vars']['_switch_'] = \$Pile['vars']['_switch_matched_'] = '')"
  58. . " : (vide(\$Pile['vars']['_switch_'] = \$Pile['vars']['_switch_'.switchcase_niveau()])"
  59. . ".vide(\$Pile['vars']['_switch_matched_'] = \$Pile['vars']['_switch_matched_'.switchcase_niveau()])))";
  60. $p->interdire_script = false;
  61. return $p;
  62. }