PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/spip/ecrire/public/normaliser.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 200 lines | 154 code | 24 blank | 22 comment | 27 complexity | 8716d1bac23e2ad471673272ddc08714 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. // Les fonctions de ce fichier sont appelees en certains points
  13. // de l'analyseur syntaxique afin de normaliser de vieilles syntaxes,
  14. // pour fournir au compilateur un arbre de syntaxe abstraite homogene
  15. // Cas des pseudos filtres |fichier et |lien qui donnent le chemin du fichier
  16. // et son URL, remplaces par ** et *: LOGO_XXX** et LOGO_XXX*
  17. // Il y a aussi le futur attribut align et l'ecriture #LOGO|#URL
  18. // qui passent en arguments de la balise: #LOGO{left,#URL...}
  19. // -> http://www.spip.net/fr_article901.html
  20. function phraser_vieux_logos(&$p)
  21. {
  22. if ($p->param[0][0])
  23. $args = array('');
  24. else {
  25. $args = array_shift($p->param);
  26. }
  27. foreach($p->param as $couple) {
  28. $nom = trim($couple[0]);
  29. if ($nom == '') {array_shift($p->param); break;}
  30. $r = phraser_logo_faux_filtres($nom);
  31. if ($r === 0) {
  32. $c = new Texte;
  33. $c->texte = $nom;
  34. $args[] = array($c);
  35. array_shift($p->param);
  36. spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
  37. } elseif ($r === 2) {
  38. $p->etoile = '**';
  39. array_shift($p->param);
  40. spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
  41. } elseif ($r === 1) {
  42. array_shift($p->param);
  43. $p->etoile = '*';
  44. spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
  45. } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) {
  46. $champ = new Champ();
  47. $champ->nom_boucle = $m[2];
  48. $champ->nom_champ = $m[3];
  49. $champ->etoile = $m[5];
  50. $champ = array($champ);
  51. if ($m[6]) {
  52. $r = new Texte;
  53. $r->texte = $m[6];
  54. $champ[]= $r;
  55. }
  56. $args[]= $champ;
  57. array_shift($p->param);
  58. spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
  59. } // le cas else est la seule incompatibilite
  60. }
  61. array_unshift($p->param, $args);
  62. }
  63. function phraser_logo_faux_filtres($nom)
  64. {
  65. switch($nom) {
  66. case 'top':
  67. case 'left':
  68. case 'right':
  69. case 'center':
  70. case 'bottom': return 0;
  71. case 'lien': return 1;
  72. case 'fichier': return 2;
  73. default: return $nom;
  74. }
  75. }
  76. // La balise embed_document est a present le modele emb
  77. function phraser_vieux_emb(&$p)
  78. {
  79. if (!is_array($p->param))
  80. $p->param=array();
  81. // Produire le premier argument {emb}
  82. $texte = new Texte;
  83. $texte->texte='emb';
  84. $param = array('', array($texte));
  85. // Transformer les filtres en arguments
  86. for ($i=0; $i<count($p->param); $i++) {
  87. if ($p->param[$i][0]) {
  88. if (!strstr($p->param[$i][0], '='))
  89. break;# on a rencontre un vrai filtre, c'est fini
  90. $texte = new Texte;
  91. $texte->texte=$p->param[$i][0];
  92. $param[] = array($texte);
  93. }
  94. array_shift($p->param);
  95. }
  96. array_unshift($p->param, $param);
  97. spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs');
  98. $p->nom_champ = 'MODELE';
  99. }
  100. // Vieux formulaire de recherch
  101. function phraser_vieux_recherche($p)
  102. {
  103. if ($p->param[0][0]) {
  104. $c = new Texte;
  105. $c->texte = $p->param[0][0];
  106. $p->param[0][1] = array($c);
  107. $p->param[0][0] = '';
  108. $p->fonctions = array();
  109. spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs');
  110. }
  111. }
  112. // Gerer la notation [(#EXPOSER|on,off)]
  113. function phraser_vieux_exposer($p)
  114. {
  115. if ($a = $p->fonctions) {
  116. preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs);
  117. $args = array();
  118. if ($regs[1]) {
  119. $a = new Texte;
  120. $a->texte = $regs[1];
  121. $args = array('', array($a));
  122. if ($regs[3]) {
  123. $a = new Texte;
  124. $a->texte = $regs[3];
  125. $args[] = array($a);
  126. }
  127. }
  128. $p->param[0] = $args;
  129. $p->fonctions = array();
  130. $p->nom_champ = 'EXPOSE';
  131. }
  132. }
  133. function phraser_vieux_modele($p) {normaliser_args_inclumodel($p);}
  134. function phraser_vieux_inclu($p) {normaliser_args_inclumodel($p);}
  135. function normaliser_args_inclumodel($p)
  136. {
  137. $params = $p->param;
  138. if (!$params) return;
  139. $args = $params[0];
  140. if ($args[0]) return; // filtre immediat
  141. array_shift($p->param);
  142. foreach ($p->param as $l) {
  143. if (!array_shift($l)) {
  144. $args = array_merge($args, $l);
  145. array_shift($p->param);
  146. } else break; // filtre
  147. }
  148. array_unshift($p->param, $args);
  149. }
  150. function normaliser_inclure($champ)
  151. {
  152. normaliser_args_inclumodel($champ);
  153. $l = $champ->param[0];
  154. if (is_array($l) AND !$l[0]) {
  155. foreach ($l as $k => $p) {
  156. if ($p AND $p[0]->type == 'texte' AND !strpos($p[0]->texte,'=')) {
  157. $p[0]->texte = trim($p[0]->texte);
  158. }
  159. }
  160. foreach ($l as $k => $p) {
  161. if (!$p OR $p[0]->type != 'texte' OR
  162. !preg_match('/^fond\s*=\s*(.*)$/',$p[0]->texte, $r))
  163. continue;
  164. if ($r[1])
  165. $p[0]->texte = $r[1];
  166. else unset($p[0]);
  167. $champ->texte = $p;
  168. unset($champ->param[0][$k]);
  169. if (count($champ->param[0]) ==1)
  170. array_shift($champ->param);
  171. return;
  172. }
  173. }
  174. spip_log("inclure sans fond ni fichier");
  175. }
  176. ?>