@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ''; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | - $contenu = $contenu['page'] ?? ''; |
|
| 55 | - } else { |
|
| 56 | - lire_fichier($fichier, $contenu); |
|
| 57 | - } |
|
| 58 | - $arbre = []; |
|
| 59 | - if ($contenu) { |
|
| 60 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | - } |
|
| 50 | + $contenu = ''; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | + $contenu = $contenu['page'] ?? ''; |
|
| 55 | + } else { |
|
| 56 | + lire_fichier($fichier, $contenu); |
|
| 57 | + } |
|
| 58 | + $arbre = []; |
|
| 59 | + if ($contenu) { |
|
| 60 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return count($arbre) ? $arbre : false; |
|
| 63 | + return count($arbre) ? $arbre : false; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 67 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,150 +83,150 @@ discard block |
||
| 83 | 83 | * - false si l'arbre xml ne peut être créé ou est vide |
| 84 | 84 | **/ |
| 85 | 85 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 86 | - $out = []; |
|
| 87 | - // enlever les commentaires |
|
| 88 | - $charset = 'AUTO'; |
|
| 89 | - if ($clean === true) { |
|
| 90 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | - $charset = $regs[2]; |
|
| 92 | - } |
|
| 93 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | - include_spip('inc/charsets'); |
|
| 96 | - $clean = $charset; |
|
| 97 | - //$texte = importer_charset($texte,$charset); |
|
| 98 | - } |
|
| 99 | - if (is_string($clean)) { |
|
| 100 | - $charset = $clean; |
|
| 101 | - } |
|
| 102 | - $txt = $texte; |
|
| 86 | + $out = []; |
|
| 87 | + // enlever les commentaires |
|
| 88 | + $charset = 'AUTO'; |
|
| 89 | + if ($clean === true) { |
|
| 90 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | + $charset = $regs[2]; |
|
| 92 | + } |
|
| 93 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | + include_spip('inc/charsets'); |
|
| 96 | + $clean = $charset; |
|
| 97 | + //$texte = importer_charset($texte,$charset); |
|
| 98 | + } |
|
| 99 | + if (is_string($clean)) { |
|
| 100 | + $charset = $clean; |
|
| 101 | + } |
|
| 102 | + $txt = $texte; |
|
| 103 | 103 | |
| 104 | - // tant qu'il y a des tags |
|
| 105 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | - // tag ouvrant |
|
| 108 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 104 | + // tant qu'il y a des tags |
|
| 105 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | + // tag ouvrant |
|
| 108 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 109 | 109 | |
| 110 | - // $before doit etre vide ou des espaces uniquements! |
|
| 111 | - $before = trim($chars[0]); |
|
| 110 | + // $before doit etre vide ou des espaces uniquements! |
|
| 111 | + $before = trim($chars[0]); |
|
| 112 | 112 | |
| 113 | - if (strlen($before) > 0) { |
|
| 114 | - return importer_charset($texte, $charset); |
|
| 115 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 113 | + if (strlen($before) > 0) { |
|
| 114 | + return importer_charset($texte, $charset); |
|
| 115 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 116 | 116 | |
| 117 | - $tag = rtrim($chars[1]); |
|
| 118 | - $txt = $chars[2]; |
|
| 117 | + $tag = rtrim($chars[1]); |
|
| 118 | + $txt = $chars[2]; |
|
| 119 | 119 | |
| 120 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | - return importer_charset($texte, $charset); |
|
| 122 | - }//$texte; |
|
| 123 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | - $out[$tag][] = ''; |
|
| 126 | - } else { |
|
| 127 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | - $closing_tag = reset($closing_tag); |
|
| 129 | - // tag fermant |
|
| 130 | - $ncclos = strlen("</$closing_tag>"); |
|
| 131 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | - if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | - $nclose = 0; |
|
| 134 | - $nopen = 0; |
|
| 135 | - $d = 0; |
|
| 136 | - while ( |
|
| 137 | - $p !== false |
|
| 138 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | - and (($nopen += preg_match_all( |
|
| 140 | - '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | - $morceau, |
|
| 142 | - $matches, |
|
| 143 | - PREG_SET_ORDER |
|
| 144 | - )) > $nclose) |
|
| 145 | - ) { |
|
| 146 | - $nclose++; |
|
| 147 | - $d = $p + $ncclos; |
|
| 148 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - if ($p === false) { |
|
| 152 | - if ($strict) { |
|
| 153 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 120 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | + return importer_charset($texte, $charset); |
|
| 122 | + }//$texte; |
|
| 123 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | + $out[$tag][] = ''; |
|
| 126 | + } else { |
|
| 127 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | + $closing_tag = reset($closing_tag); |
|
| 129 | + // tag fermant |
|
| 130 | + $ncclos = strlen("</$closing_tag>"); |
|
| 131 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | + if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | + $nclose = 0; |
|
| 134 | + $nopen = 0; |
|
| 135 | + $d = 0; |
|
| 136 | + while ( |
|
| 137 | + $p !== false |
|
| 138 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | + and (($nopen += preg_match_all( |
|
| 140 | + '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | + $morceau, |
|
| 142 | + $matches, |
|
| 143 | + PREG_SET_ORDER |
|
| 144 | + )) > $nclose) |
|
| 145 | + ) { |
|
| 146 | + $nclose++; |
|
| 147 | + $d = $p + $ncclos; |
|
| 148 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + if ($p === false) { |
|
| 152 | + if ($strict) { |
|
| 153 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 154 | 154 | |
| 155 | - return $out; |
|
| 156 | - } else { |
|
| 157 | - return importer_charset($texte, $charset); |
|
| 158 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | - } |
|
| 160 | - $content = substr($txt, 0, $p); |
|
| 161 | - $txt = substr($txt, $p + $ncclos); |
|
| 162 | - if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile |
|
| 163 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | - }//$content; |
|
| 165 | - else { |
|
| 166 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | - } |
|
| 171 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | - return $out; |
|
| 173 | - } else { |
|
| 174 | - return importer_charset($texte, $charset); |
|
| 175 | - }//$texte; |
|
| 155 | + return $out; |
|
| 156 | + } else { |
|
| 157 | + return importer_charset($texte, $charset); |
|
| 158 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | + } |
|
| 160 | + $content = substr($txt, 0, $p); |
|
| 161 | + $txt = substr($txt, $p + $ncclos); |
|
| 162 | + if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile |
|
| 163 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | + }//$content; |
|
| 165 | + else { |
|
| 166 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | + } |
|
| 171 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | + return $out; |
|
| 173 | + } else { |
|
| 174 | + return importer_charset($texte, $charset); |
|
| 175 | + }//$texte; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 179 | - $s = ''; |
|
| 180 | - if (is_array($arbre)) { |
|
| 181 | - foreach ($arbre as $tag => $feuille) { |
|
| 182 | - if (is_array($feuille)) { |
|
| 183 | - if ($tag !== intval($tag)) { |
|
| 184 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | - if (strlen($f)) { |
|
| 186 | - $tagf = explode(' ', $tag); |
|
| 187 | - $tagf = $tagf[0]; |
|
| 188 | - $s .= "<$tag>$f</$tagf>"; |
|
| 189 | - } else { |
|
| 190 | - $s .= "<$tag />"; |
|
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - $s .= spip_xml_aplatit($feuille); |
|
| 194 | - } |
|
| 195 | - $s .= $separateur; |
|
| 196 | - } else { |
|
| 197 | - $s .= "$feuille$separateur"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 179 | + $s = ''; |
|
| 180 | + if (is_array($arbre)) { |
|
| 181 | + foreach ($arbre as $tag => $feuille) { |
|
| 182 | + if (is_array($feuille)) { |
|
| 183 | + if ($tag !== intval($tag)) { |
|
| 184 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | + if (strlen($f)) { |
|
| 186 | + $tagf = explode(' ', $tag); |
|
| 187 | + $tagf = $tagf[0]; |
|
| 188 | + $s .= "<$tag>$f</$tagf>"; |
|
| 189 | + } else { |
|
| 190 | + $s .= "<$tag />"; |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + $s .= spip_xml_aplatit($feuille); |
|
| 194 | + } |
|
| 195 | + $s .= $separateur; |
|
| 196 | + } else { |
|
| 197 | + $s .= "$feuille$separateur"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 202 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function spip_xml_tagname($tag) { |
| 206 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | - return $reg[1]; |
|
| 208 | - } |
|
| 206 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | + return $reg[1]; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return ''; |
|
| 210 | + return ''; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | function spip_xml_decompose_tag($tag) { |
| 214 | - $tagname = spip_xml_tagname($tag); |
|
| 215 | - $liste = []; |
|
| 216 | - $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag[0]; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 214 | + $tagname = spip_xml_tagname($tag); |
|
| 215 | + $liste = []; |
|
| 216 | + $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag[0]; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return [$tagname, $liste]; |
|
| 229 | + return [$tagname, $liste]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = []; |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = []; |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 269 | 269 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/serial'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * en droit de l'éliminer |
| 28 | 28 | */ |
| 29 | 29 | if (!defined('_AGE_CACHE_ATIME')) { |
| 30 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | * @return int Taille approximative en octets |
| 41 | 41 | **/ |
| 42 | 42 | function taille_du_cache() { |
| 43 | - # check dirs until we reach > 500 files |
|
| 44 | - $t = 0; |
|
| 45 | - $n = 0; |
|
| 46 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | - for ($i = 0; $i < 256; $i++) { |
|
| 48 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | - while (($f = readdir($d)) !== false) { |
|
| 51 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | - $n++; |
|
| 53 | - if ($a['mtime'] >= $time) { |
|
| 54 | - if ($a['blocks'] > 0) { |
|
| 55 | - $t += 512 * $a['blocks']; |
|
| 56 | - } else { |
|
| 57 | - $t += $a['size']; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - if ($n > 500) { |
|
| 64 | - return intval(256 * $t / (1 + $i)); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $t; |
|
| 43 | + # check dirs until we reach > 500 files |
|
| 44 | + $t = 0; |
|
| 45 | + $n = 0; |
|
| 46 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | + for ($i = 0; $i < 256; $i++) { |
|
| 48 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | + while (($f = readdir($d)) !== false) { |
|
| 51 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | + $n++; |
|
| 53 | + if ($a['mtime'] >= $time) { |
|
| 54 | + if ($a['blocks'] > 0) { |
|
| 55 | + $t += 512 * $a['blocks']; |
|
| 56 | + } else { |
|
| 57 | + $t += $a['size']; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + if ($n > 500) { |
|
| 64 | + return intval(256 * $t / (1 + $i)); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -91,30 +91,30 @@ discard block |
||
| 91 | 91 | * Inutilisé |
| 92 | 92 | **/ |
| 93 | 93 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 94 | - if (!$modif) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // determiner l'objet modifie : forum, article, etc |
|
| 99 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | - $objet = objet_type($r[1]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | - if (isset($objet)) { |
|
| 105 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | - ecrire_meta('derniere_modif', time()); |
|
| 113 | - } |
|
| 114 | - } // sinon, cas standard, toujours affecter la meta |
|
| 115 | - else { |
|
| 116 | - ecrire_meta('derniere_modif', time()); |
|
| 117 | - } |
|
| 94 | + if (!$modif) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // determiner l'objet modifie : forum, article, etc |
|
| 99 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | + $objet = objet_type($r[1]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | + if (isset($objet)) { |
|
| 105 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | + ecrire_meta('derniere_modif', time()); |
|
| 113 | + } |
|
| 114 | + } // sinon, cas standard, toujours affecter la meta |
|
| 115 | + else { |
|
| 116 | + ecrire_meta('derniere_modif', time()); |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -139,57 +139,57 @@ discard block |
||
| 139 | 139 | * Nombre de fichiers supprimés |
| 140 | 140 | **/ |
| 141 | 141 | function purger_repertoire($dir, $options = []) { |
| 142 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | - return 0; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | - return 0; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $handle = opendir($dir); |
|
| 153 | - if (!$handle) { |
|
| 154 | - return 0; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $total = 0; |
|
| 158 | - |
|
| 159 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | - if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | - continue; |
|
| 163 | - } |
|
| 164 | - $chemin = "$dir/$fichier"; |
|
| 165 | - if (is_file($chemin)) { |
|
| 166 | - if ( |
|
| 167 | - (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | - ) { |
|
| 170 | - supprimer_fichier($chemin); |
|
| 171 | - $total++; |
|
| 172 | - } |
|
| 173 | - } else { |
|
| 174 | - if (is_dir($chemin)) { |
|
| 175 | - $opts = $options; |
|
| 176 | - if (isset($options['limit'])) { |
|
| 177 | - $opts['limit'] = $options['limit'] - $total; |
|
| 178 | - } |
|
| 179 | - $total += purger_repertoire($chemin, $opts); |
|
| 180 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | - spip_unlink($chemin); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - closedir($handle); |
|
| 191 | - |
|
| 192 | - return $total; |
|
| 142 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | + return 0; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | + return 0; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $handle = opendir($dir); |
|
| 153 | + if (!$handle) { |
|
| 154 | + return 0; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $total = 0; |
|
| 158 | + |
|
| 159 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | + if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 164 | + $chemin = "$dir/$fichier"; |
|
| 165 | + if (is_file($chemin)) { |
|
| 166 | + if ( |
|
| 167 | + (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | + ) { |
|
| 170 | + supprimer_fichier($chemin); |
|
| 171 | + $total++; |
|
| 172 | + } |
|
| 173 | + } else { |
|
| 174 | + if (is_dir($chemin)) { |
|
| 175 | + $opts = $options; |
|
| 176 | + if (isset($options['limit'])) { |
|
| 177 | + $opts['limit'] = $options['limit'] - $total; |
|
| 178 | + } |
|
| 179 | + $total += purger_repertoire($chemin, $opts); |
|
| 180 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | + spip_unlink($chemin); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + closedir($handle); |
|
| 191 | + |
|
| 192 | + return $total; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -200,26 +200,26 @@ discard block |
||
| 200 | 200 | // Securite : est sur que c'est un cache |
| 201 | 201 | function retire_cache($cache) { |
| 202 | 202 | |
| 203 | - if ( |
|
| 204 | - preg_match( |
|
| 205 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | - $cache |
|
| 207 | - ) |
|
| 208 | - ) { |
|
| 209 | - // supprimer le fichier (de facon propre) |
|
| 210 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | - } else { |
|
| 212 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | - } |
|
| 203 | + if ( |
|
| 204 | + preg_match( |
|
| 205 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | + $cache |
|
| 207 | + ) |
|
| 208 | + ) { |
|
| 209 | + // supprimer le fichier (de facon propre) |
|
| 210 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | + } else { |
|
| 212 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Supprimer les caches marques "x" |
| 217 | 217 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 218 | 218 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 219 | 219 | function inc_retire_caches_dist($chemin = '') { |
| 220 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | - effacer_meta('invalider_caches'); |
|
| 222 | - } # concurrence |
|
| 220 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | + effacer_meta('invalider_caches'); |
|
| 222 | + } # concurrence |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | ####################################################################### |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | ## |
| 231 | 231 | |
| 232 | 232 | function retire_caches($chemin = '') { |
| 233 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | - return $retire_caches($chemin); |
|
| 235 | - } |
|
| 233 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | + return $retire_caches($chemin); |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | // (note: si absente, n'est pas appellee) |
| 241 | 241 | |
| 242 | 242 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 243 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | - } |
|
| 246 | - return $corps; |
|
| 243 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | + } |
|
| 246 | + return $corps; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -252,41 +252,41 @@ discard block |
||
| 252 | 252 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 253 | 253 | // |
| 254 | 254 | function supprime_invalideurs() { |
| 255 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | - return $supprime_invalideurs(); |
|
| 257 | - } |
|
| 255 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | + return $supprime_invalideurs(); |
|
| 257 | + } |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 262 | 262 | function maj_invalideurs($fichier, &$page) { |
| 263 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | - return $maj_invalideurs($fichier, $page); |
|
| 265 | - } |
|
| 263 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | + return $maj_invalideurs($fichier, $page); |
|
| 265 | + } |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | // les invalideurs sont de la forme "objet/id_objet" |
| 270 | 270 | function insere_invalideur($inval, $fichier) { |
| 271 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | - return $insere_invalideur($inval, $fichier); |
|
| 273 | - } |
|
| 271 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | + return $insere_invalideur($inval, $fichier); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // |
| 277 | 277 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 278 | 278 | // |
| 279 | 279 | function applique_invalideur($depart) { |
| 280 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | - return $applique_invalideur($depart); |
|
| 282 | - } |
|
| 280 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | + return $applique_invalideur($depart); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // |
| 286 | 286 | // Invalider les caches liés à telle condition |
| 287 | 287 | // |
| 288 | 288 | function suivre_invalideur($cond, $modif = true) { |
| 289 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | - return $suivre_invalideur($cond, $modif); |
|
| 291 | - } |
|
| 289 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | + return $suivre_invalideur($cond, $modif); |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -11,55 +11,55 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | class IndenteurXML { |
| 18 | 18 | |
| 19 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | - xml_debutElement($this, $name, $attrs); |
|
| 21 | - } |
|
| 19 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | + xml_debutElement($this, $name, $attrs); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function finElement($phraseur, $name) { |
|
| 24 | - xml_finElement($this, $name); |
|
| 25 | - } |
|
| 23 | + public function finElement($phraseur, $name) { |
|
| 24 | + xml_finElement($this, $name); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function textElement($phraseur, $data) { |
|
| 28 | - xml_textElement($this, $data); |
|
| 29 | - } |
|
| 27 | + public function textElement($phraseur, $data) { |
|
| 28 | + xml_textElement($this, $data); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function piElement($phraseur, $target, $data) { |
|
| 32 | - xml_PiElement($this, $target, $data); |
|
| 33 | - } |
|
| 31 | + public function piElement($phraseur, $target, $data) { |
|
| 32 | + xml_PiElement($this, $target, $data); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function defaultElement($phraseur, $data) { |
|
| 36 | - xml_defaultElement($this, $data); |
|
| 37 | - } |
|
| 35 | + public function defaultElement($phraseur, $data) { |
|
| 36 | + xml_defaultElement($this, $data); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function phraserTout($phraseur, $data) { |
|
| 40 | - xml_parsestring($this, $data); |
|
| 41 | - } |
|
| 39 | + public function phraserTout($phraseur, $data) { |
|
| 40 | + xml_parsestring($this, $data); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public $depth = ''; |
|
| 44 | - public $res = ''; |
|
| 45 | - public $err = []; |
|
| 46 | - public $contenu = []; |
|
| 47 | - public $ouvrant = []; |
|
| 48 | - public $reperes = []; |
|
| 49 | - public $entete = ''; |
|
| 50 | - public $page = ''; |
|
| 51 | - public $dtc = null; |
|
| 52 | - public $sax = null; |
|
| 43 | + public $depth = ''; |
|
| 44 | + public $res = ''; |
|
| 45 | + public $err = []; |
|
| 46 | + public $contenu = []; |
|
| 47 | + public $ouvrant = []; |
|
| 48 | + public $reperes = []; |
|
| 49 | + public $entete = ''; |
|
| 50 | + public $page = ''; |
|
| 51 | + public $dtc = null; |
|
| 52 | + public $sax = null; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function xml_indenter_dist($page, $apply = false) { |
| 56 | - $sax = charger_fonction('sax', 'xml'); |
|
| 57 | - $f = new IndenteurXML(); |
|
| 58 | - $sax($page, $apply, $f); |
|
| 59 | - if (!$f->err) { |
|
| 60 | - return $f->entete . $f->res; |
|
| 61 | - } |
|
| 62 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 56 | + $sax = charger_fonction('sax', 'xml'); |
|
| 57 | + $f = new IndenteurXML(); |
|
| 58 | + $sax($page, $apply, $f); |
|
| 59 | + if (!$f->err) { |
|
| 60 | + return $f->entete . $f->res; |
|
| 61 | + } |
|
| 62 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 63 | 63 | |
| 64 | - return $f->entete . $f->page; |
|
| 64 | + return $f->entete . $f->page; |
|
| 65 | 65 | } |
@@ -11,58 +11,58 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 20 | - $r = null; |
|
| 21 | - static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return []; |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC(); |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = []; |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $dtd[$grammaire] = $dtc; |
|
| 64 | - |
|
| 65 | - return $dtc; |
|
| 20 | + $r = null; |
|
| 21 | + static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return []; |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC(); |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = []; |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $dtd[$grammaire] = $dtc; |
|
| 64 | + |
|
| 65 | + return $dtc; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -74,153 +74,153 @@ discard block |
||
| 74 | 74 | // et parentheser le tout pour que | + * ? s'applique dessus. |
| 75 | 75 | |
| 76 | 76 | function compilerRegle($val) { |
| 77 | - $x = str_replace( |
|
| 78 | - '()', |
|
| 79 | - '', |
|
| 80 | - preg_replace( |
|
| 81 | - '/\s*,\s*/', |
|
| 82 | - '', |
|
| 83 | - preg_replace( |
|
| 84 | - '/(\w+)\s*/', |
|
| 85 | - '(?:\1 )', |
|
| 86 | - preg_replace( |
|
| 87 | - '/\s*\)/', |
|
| 88 | - ')', |
|
| 89 | - preg_replace( |
|
| 90 | - '/\s*([(+*|?])\s*/', |
|
| 91 | - '\1', |
|
| 92 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | - ) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - return $x; |
|
| 77 | + $x = str_replace( |
|
| 78 | + '()', |
|
| 79 | + '', |
|
| 80 | + preg_replace( |
|
| 81 | + '/\s*,\s*/', |
|
| 82 | + '', |
|
| 83 | + preg_replace( |
|
| 84 | + '/(\w+)\s*/', |
|
| 85 | + '(?:\1 )', |
|
| 86 | + preg_replace( |
|
| 87 | + '/\s*\)/', |
|
| 88 | + ')', |
|
| 89 | + preg_replace( |
|
| 90 | + '/\s*([(+*|?])\s*/', |
|
| 91 | + '\1', |
|
| 92 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | + ) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + return $x; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | function analyser_dtd($loc, $avail, &$dtc) { |
| 104 | - // creer le repertoire de cache si ce n'est fait |
|
| 105 | - // (utile aussi pour le resultat de la compil) |
|
| 106 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | - if ($avail == 'SYSTEM') { |
|
| 109 | - $file = $loc; |
|
| 110 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | - } |
|
| 113 | - $file = find_in_path($file); |
|
| 114 | - } else { |
|
| 115 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $dtd = ''; |
|
| 119 | - if (@is_readable($file)) { |
|
| 120 | - lire_fichier($file, $dtd); |
|
| 121 | - } else { |
|
| 122 | - if ($avail == 'PUBLIC') { |
|
| 123 | - include_spip('inc/distant'); |
|
| 124 | - $dtd = recuperer_url($loc); |
|
| 125 | - $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | - if ($dtd) { |
|
| 127 | - ecrire_fichier($file, $dtd, true); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $dtd = ltrim($dtd); |
|
| 133 | - if (!$dtd) { |
|
| 134 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | - |
|
| 136 | - return false; |
|
| 137 | - } else { |
|
| 138 | - spip_log("analyse de la DTD $loc "); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - while ($dtd) { |
|
| 142 | - if ($dtd[0] != '<') { |
|
| 143 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | - } elseif ($dtd[1] != '!') { |
|
| 145 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | - } elseif ($dtd[2] == '[') { |
|
| 147 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | - } else { |
|
| 149 | - switch ($dtd[3]) { |
|
| 150 | - case '%': |
|
| 151 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | - break; |
|
| 153 | - case 'T': |
|
| 154 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | - break; |
|
| 156 | - case 'L': |
|
| 157 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | - break; |
|
| 159 | - case 'N': |
|
| 160 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | - break; |
|
| 162 | - case 'O': |
|
| 163 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | - break; |
|
| 165 | - case '-': |
|
| 166 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | - break; |
|
| 168 | - default: |
|
| 169 | - $r = -1; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - if (!is_string($r)) { |
|
| 173 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | - |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 177 | - $dtd = $r; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return true; |
|
| 104 | + // creer le repertoire de cache si ce n'est fait |
|
| 105 | + // (utile aussi pour le resultat de la compil) |
|
| 106 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | + if ($avail == 'SYSTEM') { |
|
| 109 | + $file = $loc; |
|
| 110 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | + } |
|
| 113 | + $file = find_in_path($file); |
|
| 114 | + } else { |
|
| 115 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $dtd = ''; |
|
| 119 | + if (@is_readable($file)) { |
|
| 120 | + lire_fichier($file, $dtd); |
|
| 121 | + } else { |
|
| 122 | + if ($avail == 'PUBLIC') { |
|
| 123 | + include_spip('inc/distant'); |
|
| 124 | + $dtd = recuperer_url($loc); |
|
| 125 | + $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | + if ($dtd) { |
|
| 127 | + ecrire_fichier($file, $dtd, true); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $dtd = ltrim($dtd); |
|
| 133 | + if (!$dtd) { |
|
| 134 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | + |
|
| 136 | + return false; |
|
| 137 | + } else { |
|
| 138 | + spip_log("analyse de la DTD $loc "); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + while ($dtd) { |
|
| 142 | + if ($dtd[0] != '<') { |
|
| 143 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | + } elseif ($dtd[1] != '!') { |
|
| 145 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | + } elseif ($dtd[2] == '[') { |
|
| 147 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | + } else { |
|
| 149 | + switch ($dtd[3]) { |
|
| 150 | + case '%': |
|
| 151 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | + break; |
|
| 153 | + case 'T': |
|
| 154 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | + break; |
|
| 156 | + case 'L': |
|
| 157 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | + break; |
|
| 159 | + case 'N': |
|
| 160 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | + break; |
|
| 162 | + case 'O': |
|
| 163 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | + break; |
|
| 165 | + case '-': |
|
| 166 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | + break; |
|
| 168 | + default: |
|
| 169 | + $r = -1; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + if (!is_string($r)) { |
|
| 173 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | + |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | + $dtd = $r; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return true; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 184 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | - // Option /s car sur plusieurs lignes parfois |
|
| 184 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | + // Option /s car sur plusieurs lignes parfois |
|
| 186 | 186 | |
| 187 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | - return -6; |
|
| 189 | - } |
|
| 187 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | + return -6; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - return $m[1]; |
|
| 191 | + return $m[1]; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 195 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | - return -10; |
|
| 197 | - } |
|
| 195 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | + return -10; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $m[1]; |
|
| 199 | + return $m[1]; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 203 | 203 | |
| 204 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | - return -9; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - [, $s] = $m; |
|
| 209 | - $n = $dtc->macros[$s]; |
|
| 210 | - |
|
| 211 | - if (is_array($n)) { |
|
| 212 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | - if ( |
|
| 215 | - ($n[0] == 'PUBLIC') |
|
| 216 | - and !tester_url_absolue($n[1]) |
|
| 217 | - ) { |
|
| 218 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | - } |
|
| 220 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 204 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | + return -9; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + [, $s] = $m; |
|
| 209 | + $n = $dtc->macros[$s]; |
|
| 210 | + |
|
| 211 | + if (is_array($n)) { |
|
| 212 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | + if ( |
|
| 215 | + ($n[0] == 'PUBLIC') |
|
| 216 | + and !tester_url_absolue($n[1]) |
|
| 217 | + ) { |
|
| 218 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | + } |
|
| 220 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -228,83 +228,83 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 230 | 230 | |
| 231 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | - return -11; |
|
| 233 | - } |
|
| 234 | - if ( |
|
| 235 | - !preg_match( |
|
| 236 | - '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | - $m[2], |
|
| 238 | - $r |
|
| 239 | - ) |
|
| 240 | - ) { |
|
| 241 | - return -12; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | - } else { |
|
| 247 | - $retour = substr($m[2], strlen($r[0])); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $retour; |
|
| 231 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | + return -11; |
|
| 233 | + } |
|
| 234 | + if ( |
|
| 235 | + !preg_match( |
|
| 236 | + '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | + $m[2], |
|
| 238 | + $r |
|
| 239 | + ) |
|
| 240 | + ) { |
|
| 241 | + return -12; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | + } else { |
|
| 247 | + $retour = substr($m[2], strlen($r[0])); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $retour; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 254 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | - return -8; |
|
| 256 | - } |
|
| 257 | - spip_log('analyser_dtd_notation a ecrire'); |
|
| 254 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | + return -8; |
|
| 256 | + } |
|
| 257 | + spip_log('analyser_dtd_notation a ecrire'); |
|
| 258 | 258 | |
| 259 | - return $m[1]; |
|
| 259 | + return $m[1]; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 263 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | - return -2; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | - |
|
| 269 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | - return $dtd; |
|
| 271 | - } |
|
| 272 | - if (isset($dtc->entites[$nom])) { |
|
| 273 | - spip_log("redefinition de l'entite $nom"); |
|
| 274 | - } |
|
| 275 | - if ($k6) { |
|
| 276 | - return $k6 . $dtd; |
|
| 277 | - } // cas du synonyme complet |
|
| 278 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | - |
|
| 280 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | - [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if (!$term) { |
|
| 286 | - $dtc->entites[$nom] = $val; |
|
| 287 | - } elseif (!$type) { |
|
| 288 | - $dtc->macros[$nom] = $val; |
|
| 289 | - } else { |
|
| 290 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | - $alt = $val; |
|
| 292 | - } |
|
| 293 | - if (!$alt) { |
|
| 294 | - $dtc->macros[$nom] = $val; |
|
| 295 | - } else { |
|
| 296 | - if ( |
|
| 297 | - ($type == 'PUBLIC') |
|
| 298 | - and (strpos($alt, '/') === false) |
|
| 299 | - ) { |
|
| 300 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | - . $alt; |
|
| 302 | - } |
|
| 303 | - $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $dtd; |
|
| 263 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | + return -2; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | + |
|
| 269 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | + return $dtd; |
|
| 271 | + } |
|
| 272 | + if (isset($dtc->entites[$nom])) { |
|
| 273 | + spip_log("redefinition de l'entite $nom"); |
|
| 274 | + } |
|
| 275 | + if ($k6) { |
|
| 276 | + return $k6 . $dtd; |
|
| 277 | + } // cas du synonyme complet |
|
| 278 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | + |
|
| 280 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | + [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if (!$term) { |
|
| 286 | + $dtc->entites[$nom] = $val; |
|
| 287 | + } elseif (!$type) { |
|
| 288 | + $dtc->macros[$nom] = $val; |
|
| 289 | + } else { |
|
| 290 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | + $alt = $val; |
|
| 292 | + } |
|
| 293 | + if (!$alt) { |
|
| 294 | + $dtc->macros[$nom] = $val; |
|
| 295 | + } else { |
|
| 296 | + if ( |
|
| 297 | + ($type == 'PUBLIC') |
|
| 298 | + and (strpos($alt, '/') === false) |
|
| 299 | + ) { |
|
| 300 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | + . $alt; |
|
| 302 | + } |
|
| 303 | + $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $dtd; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Dresser le tableau des filles potentielles de l'element |
@@ -317,76 +317,76 @@ discard block |
||
| 317 | 317 | // Fin du controle en finElement |
| 318 | 318 | |
| 319 | 319 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 320 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | - return -3; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - [, $nom, $contenu, $dtd] = $m; |
|
| 325 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | - |
|
| 327 | - if (isset($dtc->elements[$nom])) { |
|
| 328 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | - |
|
| 330 | - return -4; |
|
| 331 | - } |
|
| 332 | - $filles = []; |
|
| 333 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | - if ($val == '(?:EMPTY )') { |
|
| 336 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | - } elseif ($val == '(?:ANY )') { |
|
| 338 | - $dtc->regles[$nom] = 'ANY'; |
|
| 339 | - } else { |
|
| 340 | - $last = substr($val, -1); |
|
| 341 | - if ( |
|
| 342 | - preg_match('/ \w/', $val) |
|
| 343 | - or (!empty($last) and strpos('*+?', $last) === false) |
|
| 344 | - ) { |
|
| 345 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | - } else { |
|
| 347 | - $dtc->regles[$nom] = $last; |
|
| 348 | - } |
|
| 349 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | - |
|
| 351 | - foreach ($filles as $k) { |
|
| 352 | - if (!isset($dtc->peres[$k])) { |
|
| 353 | - $dtc->peres[$k] = []; |
|
| 354 | - } |
|
| 355 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | - $dtc->peres[$k][] = $nom; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | - $dtc->elements[$nom] = $filles; |
|
| 362 | - |
|
| 363 | - return $dtd; |
|
| 320 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | + return -3; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + [, $nom, $contenu, $dtd] = $m; |
|
| 325 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | + |
|
| 327 | + if (isset($dtc->elements[$nom])) { |
|
| 328 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | + |
|
| 330 | + return -4; |
|
| 331 | + } |
|
| 332 | + $filles = []; |
|
| 333 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | + if ($val == '(?:EMPTY )') { |
|
| 336 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | + } elseif ($val == '(?:ANY )') { |
|
| 338 | + $dtc->regles[$nom] = 'ANY'; |
|
| 339 | + } else { |
|
| 340 | + $last = substr($val, -1); |
|
| 341 | + if ( |
|
| 342 | + preg_match('/ \w/', $val) |
|
| 343 | + or (!empty($last) and strpos('*+?', $last) === false) |
|
| 344 | + ) { |
|
| 345 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | + } else { |
|
| 347 | + $dtc->regles[$nom] = $last; |
|
| 348 | + } |
|
| 349 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | + |
|
| 351 | + foreach ($filles as $k) { |
|
| 352 | + if (!isset($dtc->peres[$k])) { |
|
| 353 | + $dtc->peres[$k] = []; |
|
| 354 | + } |
|
| 355 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | + $dtc->peres[$k][] = $nom; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | + $dtc->elements[$nom] = $filles; |
|
| 362 | + |
|
| 363 | + return $dtd; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 368 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | - return -5; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - [, $nom, $val, $dtd] = $m; |
|
| 373 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | - $val = expanserEntite($val, $dtc->macros); |
|
| 375 | - if (!isset($dtc->attributs[$nom])) { |
|
| 376 | - $dtc->attributs[$nom] = []; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | - foreach ($r2 as $m2) { |
|
| 381 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | - $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $dtd; |
|
| 368 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | + return -5; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + [, $nom, $val, $dtd] = $m; |
|
| 373 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | + $val = expanserEntite($val, $dtc->macros); |
|
| 375 | + if (!isset($dtc->attributs[$nom])) { |
|
| 376 | + $dtc->attributs[$nom] = []; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | + foreach ($r2 as $m2) { |
|
| 381 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | + $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $dtd; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -402,26 +402,26 @@ discard block |
||
| 402 | 402 | * @return string|array |
| 403 | 403 | **/ |
| 404 | 404 | function expanserEntite($val, $macros = []) { |
| 405 | - static $vu = []; |
|
| 406 | - if (!is_string($val)) { |
|
| 407 | - return $vu; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | - foreach ($r as $m) { |
|
| 412 | - $ent = $m[1]; |
|
| 413 | - // il peut valoir "" |
|
| 414 | - if (!isset($macros[$ent])) { |
|
| 415 | - spip_log("Entite $ent inconnu"); |
|
| 416 | - } else { |
|
| 417 | - if (!isset($vu[$ent])) { |
|
| 418 | - $vu[$ent] = 0; |
|
| 419 | - } |
|
| 420 | - ++$vu[$ent]; |
|
| 421 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 405 | + static $vu = []; |
|
| 406 | + if (!is_string($val)) { |
|
| 407 | + return $vu; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | + foreach ($r as $m) { |
|
| 412 | + $ent = $m[1]; |
|
| 413 | + // il peut valoir "" |
|
| 414 | + if (!isset($macros[$ent])) { |
|
| 415 | + spip_log("Entite $ent inconnu"); |
|
| 416 | + } else { |
|
| 417 | + if (!isset($vu[$ent])) { |
|
| 418 | + $vu[$ent] = 0; |
|
| 419 | + } |
|
| 420 | + ++$vu[$ent]; |
|
| 421 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 427 | 427 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | 27 | function generer_nom_fichier_cache($contexte, $page) { |
| 28 | - $u = md5(var_export([$contexte, $page], true)); |
|
| 28 | + $u = md5(var_export([$contexte, $page], true)); |
|
| 29 | 29 | |
| 30 | - return $u . '.cache'; |
|
| 30 | + return $u . '.cache'; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -43,26 +43,26 @@ discard block |
||
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | 45 | function cache_chemin_fichier($nom_cache, $ecrire = false) { |
| 46 | - static $l1, $l2; |
|
| 47 | - if (is_null($l1)) { |
|
| 48 | - $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 49 | - $l1 = intval(floor($length / 2)); |
|
| 50 | - $l2 = $length - $l1; |
|
| 51 | - } |
|
| 52 | - $d = substr($nom_cache, 0, $l1); |
|
| 53 | - $u = substr($nom_cache, $l1, $l2); |
|
| 54 | - |
|
| 55 | - if ($ecrire) { |
|
| 56 | - $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 57 | - $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 58 | - $rep = sous_repertoire($rep, $d, false, true); |
|
| 59 | - } |
|
| 60 | - else { |
|
| 61 | - // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 62 | - $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $rep . $u . '.cache'; |
|
| 46 | + static $l1, $l2; |
|
| 47 | + if (is_null($l1)) { |
|
| 48 | + $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 49 | + $l1 = intval(floor($length / 2)); |
|
| 50 | + $l2 = $length - $l1; |
|
| 51 | + } |
|
| 52 | + $d = substr($nom_cache, 0, $l1); |
|
| 53 | + $u = substr($nom_cache, $l1, $l2); |
|
| 54 | + |
|
| 55 | + if ($ecrire) { |
|
| 56 | + $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 57 | + $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 58 | + $rep = sous_repertoire($rep, $d, false, true); |
|
| 59 | + } |
|
| 60 | + else { |
|
| 61 | + // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 62 | + $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $rep . $u . '.cache'; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | function ecrire_cache($nom_cache, $valeur) { |
| 76 | - return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 76 | + return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,38 +83,38 @@ discard block |
||
| 83 | 83 | * @return mixed |
| 84 | 84 | */ |
| 85 | 85 | function lire_cache($nom_cache) { |
| 86 | - $tmp = []; |
|
| 87 | - if ( |
|
| 88 | - file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 89 | - and lire_fichier($f, $tmp) |
|
| 90 | - and $tmp = unserialize($tmp) |
|
| 91 | - and $tmp['nom_cache'] == $nom_cache |
|
| 92 | - and isset($tmp['valeur']) |
|
| 93 | - ) { |
|
| 94 | - return $tmp['valeur']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return false; |
|
| 86 | + $tmp = []; |
|
| 87 | + if ( |
|
| 88 | + file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 89 | + and lire_fichier($f, $tmp) |
|
| 90 | + and $tmp = unserialize($tmp) |
|
| 91 | + and $tmp['nom_cache'] == $nom_cache |
|
| 92 | + and isset($tmp['valeur']) |
|
| 93 | + ) { |
|
| 94 | + return $tmp['valeur']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return false; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Parano : on signe le cache, afin d'interdire un hack d'injection |
| 101 | 101 | // dans notre memcache |
| 102 | 102 | function cache_signature(&$page) { |
| 103 | - if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 104 | - include_spip('inc/acces'); |
|
| 105 | - include_spip('auth/sha256.inc'); |
|
| 106 | - ecrire_meta( |
|
| 107 | - 'cache_signature', |
|
| 108 | - spip_sha256( |
|
| 109 | - $_SERVER['DOCUMENT_ROOT'] |
|
| 110 | - . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 111 | - . creer_uniqid() |
|
| 112 | - ), |
|
| 113 | - 'non' |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 103 | + if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 104 | + include_spip('inc/acces'); |
|
| 105 | + include_spip('auth/sha256.inc'); |
|
| 106 | + ecrire_meta( |
|
| 107 | + 'cache_signature', |
|
| 108 | + spip_sha256( |
|
| 109 | + $_SERVER['DOCUMENT_ROOT'] |
|
| 110 | + . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 111 | + . creer_uniqid() |
|
| 112 | + ), |
|
| 113 | + 'non' |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | 129 | function gzip_page($page) { |
| 130 | - if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 131 | - $page['gz'] = true; |
|
| 132 | - $page['texte'] = gzcompress($page['texte']); |
|
| 133 | - } else { |
|
| 134 | - $page['gz'] = false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $page; |
|
| 130 | + if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 131 | + $page['gz'] = true; |
|
| 132 | + $page['texte'] = gzcompress($page['texte']); |
|
| 133 | + } else { |
|
| 134 | + $page['gz'] = false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $page; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | 149 | function gunzip_page(&$page) { |
| 150 | - if ($page['gz']) { |
|
| 151 | - $page['texte'] = gzuncompress($page['texte']); |
|
| 152 | - $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 153 | - } |
|
| 150 | + if ($page['gz']) { |
|
| 151 | + $page['texte'] = gzuncompress($page['texte']); |
|
| 152 | + $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,72 +165,72 @@ discard block |
||
| 165 | 165 | * -1 si il faut calculer sans stocker en cache |
| 166 | 166 | */ |
| 167 | 167 | function cache_valide(&$page, $date) { |
| 168 | - $now = $_SERVER['REQUEST_TIME']; |
|
| 169 | - |
|
| 170 | - // Apparition d'un nouvel article post-date ? |
|
| 171 | - if ( |
|
| 172 | - isset($GLOBALS['meta']['post_dates']) |
|
| 173 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 174 | - and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 176 | - ) { |
|
| 177 | - spip_log('Un article post-date invalide le cache'); |
|
| 178 | - include_spip('inc/rubriques'); |
|
| 179 | - calculer_prochain_postdate(true); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 183 | - return -1; |
|
| 184 | - } |
|
| 185 | - if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 186 | - return -1; |
|
| 187 | - } |
|
| 188 | - if (defined('_NO_CACHE')) { |
|
| 189 | - return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 193 | - if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 194 | - return _IS_BOT ? -1 : 1; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // controle de la signature |
|
| 198 | - if ($page['sig'] !== cache_signature($page)) { |
|
| 199 | - return _IS_BOT ? -1 : 1; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 203 | - // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 204 | - if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 205 | - // Cache invalide par la meta 'derniere_modif' |
|
| 206 | - // sauf pour les bots, qui utilisent toujours le cache |
|
| 207 | - if ( |
|
| 208 | - !_IS_BOT |
|
| 209 | - and $GLOBALS['derniere_modif_invalide'] |
|
| 210 | - and isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | - and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | - ) { |
|
| 213 | - return 1; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | - $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 219 | - $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | - if ($duree == 0) { #CACHE{0} |
|
| 221 | - return -1; |
|
| 222 | - } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | - else { |
|
| 224 | - if ( |
|
| 225 | - (!_IS_BOT and $date + $duree < $now) |
|
| 226 | - # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 227 | - or $date < $cache_mark |
|
| 228 | - ) { |
|
| 229 | - return _IS_BOT ? -1 : 1; |
|
| 230 | - } else { |
|
| 231 | - return 0; |
|
| 232 | - } |
|
| 233 | - } |
|
| 168 | + $now = $_SERVER['REQUEST_TIME']; |
|
| 169 | + |
|
| 170 | + // Apparition d'un nouvel article post-date ? |
|
| 171 | + if ( |
|
| 172 | + isset($GLOBALS['meta']['post_dates']) |
|
| 173 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 174 | + and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 176 | + ) { |
|
| 177 | + spip_log('Un article post-date invalide le cache'); |
|
| 178 | + include_spip('inc/rubriques'); |
|
| 179 | + calculer_prochain_postdate(true); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 183 | + return -1; |
|
| 184 | + } |
|
| 185 | + if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 186 | + return -1; |
|
| 187 | + } |
|
| 188 | + if (defined('_NO_CACHE')) { |
|
| 189 | + return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 193 | + if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 194 | + return _IS_BOT ? -1 : 1; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // controle de la signature |
|
| 198 | + if ($page['sig'] !== cache_signature($page)) { |
|
| 199 | + return _IS_BOT ? -1 : 1; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 203 | + // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 204 | + if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 205 | + // Cache invalide par la meta 'derniere_modif' |
|
| 206 | + // sauf pour les bots, qui utilisent toujours le cache |
|
| 207 | + if ( |
|
| 208 | + !_IS_BOT |
|
| 209 | + and $GLOBALS['derniere_modif_invalide'] |
|
| 210 | + and isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | + and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | + ) { |
|
| 213 | + return 1; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | + $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 219 | + $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | + if ($duree == 0) { #CACHE{0} |
|
| 221 | + return -1; |
|
| 222 | + } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | + else { |
|
| 224 | + if ( |
|
| 225 | + (!_IS_BOT and $date + $duree < $now) |
|
| 226 | + # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 227 | + or $date < $cache_mark |
|
| 228 | + ) { |
|
| 229 | + return _IS_BOT ? -1 : 1; |
|
| 230 | + } else { |
|
| 231 | + return 0; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -243,59 +243,59 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | function creer_cache(&$page, &$chemin_cache) { |
| 245 | 245 | |
| 246 | - // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 247 | - // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 248 | - // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 249 | - // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 250 | - if ( |
|
| 251 | - (defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 252 | - or defined('spip_interdire_cache') |
|
| 253 | - ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 258 | - // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 259 | - if ( |
|
| 260 | - isset($page['invalideurs']) |
|
| 261 | - and isset($page['invalideurs']['session']) |
|
| 262 | - ) { |
|
| 263 | - // on verifie que le contenu du chemin cache indique seulement |
|
| 264 | - // "cache sessionne" ; sa date indique la date de validite |
|
| 265 | - // des caches sessionnes |
|
| 266 | - if (!$tmp = lire_cache($chemin_cache)) { |
|
| 267 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 268 | - $tmp = [ |
|
| 269 | - 'invalideurs' => ['session' => ''], |
|
| 270 | - 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 271 | - ]; |
|
| 272 | - ecrire_cache($chemin_cache, $tmp); |
|
| 273 | - } |
|
| 274 | - $chemin_cache = generer_nom_fichier_cache( |
|
| 275 | - ['chemin_cache' => $chemin_cache], |
|
| 276 | - ['session' => $page['invalideurs']['session']] |
|
| 277 | - ); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // ajouter la date de production dans le cache lui meme |
|
| 281 | - // (qui contient deja sa duree de validite) |
|
| 282 | - $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 283 | - |
|
| 284 | - // compresser le contenu si besoin |
|
| 285 | - $pagez = gzip_page($page); |
|
| 286 | - |
|
| 287 | - // signer le contenu |
|
| 288 | - $pagez['sig'] = cache_signature($pagez); |
|
| 289 | - |
|
| 290 | - // l'enregistrer, compresse ou non... |
|
| 291 | - $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 292 | - |
|
| 293 | - spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 294 | - . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 295 | - |
|
| 296 | - // Inserer ses invalideurs |
|
| 297 | - include_spip('inc/invalideur'); |
|
| 298 | - maj_invalideurs($chemin_cache, $page); |
|
| 246 | + // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 247 | + // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 248 | + // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 249 | + // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 250 | + if ( |
|
| 251 | + (defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 252 | + or defined('spip_interdire_cache') |
|
| 253 | + ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 258 | + // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 259 | + if ( |
|
| 260 | + isset($page['invalideurs']) |
|
| 261 | + and isset($page['invalideurs']['session']) |
|
| 262 | + ) { |
|
| 263 | + // on verifie que le contenu du chemin cache indique seulement |
|
| 264 | + // "cache sessionne" ; sa date indique la date de validite |
|
| 265 | + // des caches sessionnes |
|
| 266 | + if (!$tmp = lire_cache($chemin_cache)) { |
|
| 267 | + spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 268 | + $tmp = [ |
|
| 269 | + 'invalideurs' => ['session' => ''], |
|
| 270 | + 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 271 | + ]; |
|
| 272 | + ecrire_cache($chemin_cache, $tmp); |
|
| 273 | + } |
|
| 274 | + $chemin_cache = generer_nom_fichier_cache( |
|
| 275 | + ['chemin_cache' => $chemin_cache], |
|
| 276 | + ['session' => $page['invalideurs']['session']] |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + // ajouter la date de production dans le cache lui meme |
|
| 281 | + // (qui contient deja sa duree de validite) |
|
| 282 | + $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 283 | + |
|
| 284 | + // compresser le contenu si besoin |
|
| 285 | + $pagez = gzip_page($page); |
|
| 286 | + |
|
| 287 | + // signer le contenu |
|
| 288 | + $pagez['sig'] = cache_signature($pagez); |
|
| 289 | + |
|
| 290 | + // l'enregistrer, compresse ou non... |
|
| 291 | + $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 292 | + |
|
| 293 | + spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 294 | + . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 295 | + |
|
| 296 | + // Inserer ses invalideurs |
|
| 297 | + include_spip('inc/invalideur'); |
|
| 298 | + maj_invalideurs($chemin_cache, $page); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -308,15 +308,15 @@ discard block |
||
| 308 | 308 | * @return void |
| 309 | 309 | */ |
| 310 | 310 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 311 | - // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 312 | - $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 313 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 314 | - foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 315 | - if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 316 | - spip_unlink($f); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 311 | + // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 312 | + $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 313 | + if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 314 | + foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 315 | + if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 316 | + spip_unlink($f); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -344,133 +344,133 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) { |
| 346 | 346 | |
| 347 | - # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 348 | - # $use_cache = -1; return; |
|
| 349 | - |
|
| 350 | - // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 351 | - if (isset($chemin_cache)) { |
|
| 352 | - return creer_cache($page, $chemin_cache); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // Toute la suite correspond au premier appel |
|
| 356 | - $contexte_implicite = $page['contexte_implicite']; |
|
| 357 | - |
|
| 358 | - // Cas ignorant le cache car completement dynamique |
|
| 359 | - if ( |
|
| 360 | - (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'POST') |
|
| 361 | - or _request('connect') |
|
| 362 | - ) { |
|
| 363 | - $use_cache = -1; |
|
| 364 | - $lastmodified = 0; |
|
| 365 | - $chemin_cache = ''; |
|
| 366 | - $page = []; |
|
| 367 | - |
|
| 368 | - return; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // Controler l'existence d'un cache nous correspondant |
|
| 372 | - $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 373 | - $lastmodified = 0; |
|
| 374 | - |
|
| 375 | - // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 376 | - if (!$page = lire_cache($chemin_cache)) { |
|
| 377 | - $page = []; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - // s'il est sessionne, charger celui correspondant a notre session |
|
| 381 | - if ( |
|
| 382 | - isset($page['invalideurs']) |
|
| 383 | - and isset($page['invalideurs']['session']) |
|
| 384 | - ) { |
|
| 385 | - $chemin_cache_session = generer_nom_fichier_cache( |
|
| 386 | - ['chemin_cache' => $chemin_cache], |
|
| 387 | - ['session' => spip_session()] |
|
| 388 | - ); |
|
| 389 | - if ( |
|
| 390 | - $page_session = lire_cache($chemin_cache_session) |
|
| 391 | - and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 392 | - ) { |
|
| 393 | - $page = $page_session; |
|
| 394 | - } else { |
|
| 395 | - $page = []; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 401 | - if (isset($GLOBALS['meta']['invalider'])) { |
|
| 402 | - // ne le faire que si la base est disponible |
|
| 403 | - if (spip_connect()) { |
|
| 404 | - include_spip('inc/invalideur'); |
|
| 405 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 406 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 407 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 408 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 414 | - // on supprime le cache |
|
| 415 | - if ( |
|
| 416 | - defined('_VAR_MODE') && |
|
| 417 | - _VAR_MODE && |
|
| 418 | - (isset($_COOKIE['spip_session']) || |
|
| 419 | - isset($_COOKIE['spip_admin']) || |
|
| 420 | - @file_exists(_ACCESS_FILE_NAME)) |
|
| 421 | - ) { |
|
| 422 | - $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 423 | - include_spip('inc/invalideur'); |
|
| 424 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 425 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 426 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 427 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // $delais par defaut |
|
| 432 | - // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 433 | - // qui sont a cache nul par defaut |
|
| 434 | - if (!isset($GLOBALS['delais'])) { |
|
| 435 | - if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 436 | - define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 437 | - } |
|
| 438 | - $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - // determiner la validite de la page |
|
| 442 | - if ($page) { |
|
| 443 | - $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 444 | - // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 445 | - // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 446 | - $page['contexte_implicite'] = $contexte_implicite; |
|
| 447 | - if (!$use_cache) { |
|
| 448 | - // $page est un cache utilisable |
|
| 449 | - gunzip_page($page); |
|
| 450 | - |
|
| 451 | - return; |
|
| 452 | - } |
|
| 453 | - } else { |
|
| 454 | - $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 455 | - $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 459 | - if (!spip_connect()) { |
|
| 460 | - if (isset($page['texte'])) { |
|
| 461 | - gunzip_page($page); |
|
| 462 | - $use_cache = 0; |
|
| 463 | - } else { |
|
| 464 | - spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 465 | - include_spip('inc/minipres'); |
|
| 466 | - |
|
| 467 | - return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($use_cache < 0) { |
|
| 472 | - $chemin_cache = ''; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - return; |
|
| 347 | + # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 348 | + # $use_cache = -1; return; |
|
| 349 | + |
|
| 350 | + // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 351 | + if (isset($chemin_cache)) { |
|
| 352 | + return creer_cache($page, $chemin_cache); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // Toute la suite correspond au premier appel |
|
| 356 | + $contexte_implicite = $page['contexte_implicite']; |
|
| 357 | + |
|
| 358 | + // Cas ignorant le cache car completement dynamique |
|
| 359 | + if ( |
|
| 360 | + (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'POST') |
|
| 361 | + or _request('connect') |
|
| 362 | + ) { |
|
| 363 | + $use_cache = -1; |
|
| 364 | + $lastmodified = 0; |
|
| 365 | + $chemin_cache = ''; |
|
| 366 | + $page = []; |
|
| 367 | + |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // Controler l'existence d'un cache nous correspondant |
|
| 372 | + $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 373 | + $lastmodified = 0; |
|
| 374 | + |
|
| 375 | + // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 376 | + if (!$page = lire_cache($chemin_cache)) { |
|
| 377 | + $page = []; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + // s'il est sessionne, charger celui correspondant a notre session |
|
| 381 | + if ( |
|
| 382 | + isset($page['invalideurs']) |
|
| 383 | + and isset($page['invalideurs']['session']) |
|
| 384 | + ) { |
|
| 385 | + $chemin_cache_session = generer_nom_fichier_cache( |
|
| 386 | + ['chemin_cache' => $chemin_cache], |
|
| 387 | + ['session' => spip_session()] |
|
| 388 | + ); |
|
| 389 | + if ( |
|
| 390 | + $page_session = lire_cache($chemin_cache_session) |
|
| 391 | + and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 392 | + ) { |
|
| 393 | + $page = $page_session; |
|
| 394 | + } else { |
|
| 395 | + $page = []; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 401 | + if (isset($GLOBALS['meta']['invalider'])) { |
|
| 402 | + // ne le faire que si la base est disponible |
|
| 403 | + if (spip_connect()) { |
|
| 404 | + include_spip('inc/invalideur'); |
|
| 405 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 406 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 407 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 408 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 414 | + // on supprime le cache |
|
| 415 | + if ( |
|
| 416 | + defined('_VAR_MODE') && |
|
| 417 | + _VAR_MODE && |
|
| 418 | + (isset($_COOKIE['spip_session']) || |
|
| 419 | + isset($_COOKIE['spip_admin']) || |
|
| 420 | + @file_exists(_ACCESS_FILE_NAME)) |
|
| 421 | + ) { |
|
| 422 | + $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 423 | + include_spip('inc/invalideur'); |
|
| 424 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 425 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 426 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 427 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // $delais par defaut |
|
| 432 | + // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 433 | + // qui sont a cache nul par defaut |
|
| 434 | + if (!isset($GLOBALS['delais'])) { |
|
| 435 | + if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 436 | + define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 437 | + } |
|
| 438 | + $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + // determiner la validite de la page |
|
| 442 | + if ($page) { |
|
| 443 | + $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 444 | + // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 445 | + // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 446 | + $page['contexte_implicite'] = $contexte_implicite; |
|
| 447 | + if (!$use_cache) { |
|
| 448 | + // $page est un cache utilisable |
|
| 449 | + gunzip_page($page); |
|
| 450 | + |
|
| 451 | + return; |
|
| 452 | + } |
|
| 453 | + } else { |
|
| 454 | + $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 455 | + $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 459 | + if (!spip_connect()) { |
|
| 460 | + if (isset($page['texte'])) { |
|
| 461 | + gunzip_page($page); |
|
| 462 | + $use_cache = 0; |
|
| 463 | + } else { |
|
| 464 | + spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 465 | + include_spip('inc/minipres'); |
|
| 466 | + |
|
| 467 | + return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($use_cache < 0) { |
|
| 472 | + $chemin_cache = ''; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + return; |
|
| 476 | 476 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,77 +237,77 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - if ($excep) { |
|
| 258 | - $joker = false; // indiquer a l'appelant |
|
| 259 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | - } // pas d'alias. Le champ existe t'il ? |
|
| 261 | - else { |
|
| 262 | - // le champ est réellement présent, on le prend. |
|
| 263 | - if (isset($desc['field'][$nom_champ])) { |
|
| 264 | - $t = $boucles[$idb]->id_table; |
|
| 265 | - $joker = false; // indiquer a l'appelant |
|
| 266 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | - } |
|
| 268 | - // Tous les champs sont-ils acceptés ? |
|
| 269 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | - elseif ( |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + if ($excep) { |
|
| 258 | + $joker = false; // indiquer a l'appelant |
|
| 259 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | + } // pas d'alias. Le champ existe t'il ? |
|
| 261 | + else { |
|
| 262 | + // le champ est réellement présent, on le prend. |
|
| 263 | + if (isset($desc['field'][$nom_champ])) { |
|
| 264 | + $t = $boucles[$idb]->id_table; |
|
| 265 | + $joker = false; // indiquer a l'appelant |
|
| 266 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | + } |
|
| 268 | + // Tous les champs sont-ils acceptés ? |
|
| 269 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | + elseif ( |
|
| 274 | 274 | /*$joker AND */ |
| 275 | - isset($desc['field']['*']) |
|
| 276 | - ) { |
|
| 277 | - $joker = true; // indiquer a l'appelant |
|
| 278 | - return [$nom_champ, $nom_champ]; |
|
| 279 | - } |
|
| 280 | - // pas d'alias, pas de champ, pas de joker... |
|
| 281 | - // tenter via une jointure... |
|
| 282 | - else { |
|
| 283 | - $joker = false; // indiquer a l'appelant |
|
| 284 | - // regarder si le champ est deja dans une jointure existante |
|
| 285 | - // sinon, si il y a des joitures explicites, la construire |
|
| 286 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | - // mais est-ce ce qu'on veut ? |
|
| 291 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($t) { |
|
| 298 | - // si on a trouvé une jointure possible, on fait comme |
|
| 299 | - // si c'était une exception pour le champ demandé |
|
| 300 | - return index_exception( |
|
| 301 | - $boucles[$idb], |
|
| 302 | - $desc, |
|
| 303 | - $nom_champ, |
|
| 304 | - [$t[1]['id_table'], reset($t[2])] |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return ['', '']; |
|
| 309 | - } |
|
| 310 | - } |
|
| 275 | + isset($desc['field']['*']) |
|
| 276 | + ) { |
|
| 277 | + $joker = true; // indiquer a l'appelant |
|
| 278 | + return [$nom_champ, $nom_champ]; |
|
| 279 | + } |
|
| 280 | + // pas d'alias, pas de champ, pas de joker... |
|
| 281 | + // tenter via une jointure... |
|
| 282 | + else { |
|
| 283 | + $joker = false; // indiquer a l'appelant |
|
| 284 | + // regarder si le champ est deja dans une jointure existante |
|
| 285 | + // sinon, si il y a des joitures explicites, la construire |
|
| 286 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | + // mais est-ce ce qu'on veut ? |
|
| 291 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($t) { |
|
| 298 | + // si on a trouvé une jointure possible, on fait comme |
|
| 299 | + // si c'était une exception pour le champ demandé |
|
| 300 | + return index_exception( |
|
| 301 | + $boucles[$idb], |
|
| 302 | + $desc, |
|
| 303 | + $nom_champ, |
|
| 304 | + [$t[1]['id_table'], reset($t[2])] |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return ['', '']; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -335,52 +335,52 @@ discard block |
||
| 335 | 335 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 336 | 336 | **/ |
| 337 | 337 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 338 | - static $trouver_table; |
|
| 339 | - if (!$trouver_table) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - if (is_array($excep)) { |
|
| 344 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | - $t = null; |
|
| 346 | - if (count($excep) == 3) { |
|
| 347 | - $index_exception_derogatoire = array_pop($excep); |
|
| 348 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | - } |
|
| 350 | - if ($t == null) { |
|
| 351 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | - if (!$j) { |
|
| 355 | - return ['', '']; |
|
| 356 | - } |
|
| 357 | - $e = $j['table']; |
|
| 358 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | - $k = $j['key']['PRIMARY KEY']; |
|
| 360 | - if (strpos($k, ',')) { |
|
| 361 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | - if (!in_array($k, $l)) { |
|
| 364 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | - |
|
| 366 | - return ['', '']; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | - fabrique_jointures($boucle, [$k]); |
|
| 371 | - $t = array_search($e, $boucle->from); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } else { |
|
| 375 | - $t = $boucle->id_table; |
|
| 376 | - } |
|
| 377 | - // demander a SQL de gerer le synonyme |
|
| 378 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | - if ($excep != $nom_champ) { |
|
| 380 | - $excep .= ' AS ' . $nom_champ; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return ["$t.$excep", $nom_champ]; |
|
| 338 | + static $trouver_table; |
|
| 339 | + if (!$trouver_table) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + if (is_array($excep)) { |
|
| 344 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | + $t = null; |
|
| 346 | + if (count($excep) == 3) { |
|
| 347 | + $index_exception_derogatoire = array_pop($excep); |
|
| 348 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | + } |
|
| 350 | + if ($t == null) { |
|
| 351 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | + if (!$j) { |
|
| 355 | + return ['', '']; |
|
| 356 | + } |
|
| 357 | + $e = $j['table']; |
|
| 358 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | + $k = $j['key']['PRIMARY KEY']; |
|
| 360 | + if (strpos($k, ',')) { |
|
| 361 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | + if (!in_array($k, $l)) { |
|
| 364 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | + |
|
| 366 | + return ['', '']; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | + fabrique_jointures($boucle, [$k]); |
|
| 371 | + $t = array_search($e, $boucle->from); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } else { |
|
| 375 | + $t = $boucle->id_table; |
|
| 376 | + } |
|
| 377 | + // demander a SQL de gerer le synonyme |
|
| 378 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | + if ($excep != $nom_champ) { |
|
| 380 | + $excep .= ' AS ' . $nom_champ; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return ["$t.$excep", $nom_champ]; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * Code PHP pour retrouver le champ |
| 406 | 406 | */ |
| 407 | 407 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 408 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 408 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 426 | 426 | **/ |
| 427 | 427 | function calculer_champ($p) { |
| 428 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 428 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 429 | 429 | |
| 430 | - return applique_filtres($p); |
|
| 430 | + return applique_filtres($p); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_balise(string $nom, \Champ $p): \Champ { |
| 466 | 466 | |
| 467 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | - $p->balise_calculee = true; |
|
| 470 | - $res = $f($p); |
|
| 471 | - if ($res !== null and is_object($res)) { |
|
| 472 | - return $res; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Certaines des balises comportant un _ sont generiques |
|
| 477 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | - $res = $balise_generique['fonction_generique']($p); |
|
| 479 | - if ($res !== null and is_object($res)) { |
|
| 480 | - return $res; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | - |
|
| 486 | - return $f($nom, $p); |
|
| 467 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | + $p->balise_calculee = true; |
|
| 470 | + $res = $f($p); |
|
| 471 | + if ($res !== null and is_object($res)) { |
|
| 472 | + return $res; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Certaines des balises comportant un _ sont generiques |
|
| 477 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | + $res = $balise_generique['fonction_generique']($p); |
|
| 479 | + if ($res !== null and is_object($res)) { |
|
| 480 | + return $res; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | + |
|
| 486 | + return $f($nom, $p); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -511,37 +511,37 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 513 | 513 | |
| 514 | - // ca pourrait etre un champ SQL homonyme, |
|
| 515 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | - |
|
| 517 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | - $code = addslashes($p->fonctions[0][1]); |
|
| 521 | - $p->code .= " . '$code'"; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | - if (strpos($nom, 'ID_') === 0) { |
|
| 526 | - $p->interdire_scripts = false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | - // SI le champ SQL n'est pas trouve |
|
| 531 | - // ET si la balise a une forme de couleur |
|
| 532 | - // ET s'il n'y a ni filtre ni etoile |
|
| 533 | - // ALORS retourner la couleur. |
|
| 534 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | - if ( |
|
| 536 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | - and !$p->etoile |
|
| 538 | - and !$p->fonctions |
|
| 539 | - ) { |
|
| 540 | - $p->code = "'#$nom'"; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return $p; |
|
| 514 | + // ca pourrait etre un champ SQL homonyme, |
|
| 515 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | + |
|
| 517 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | + $code = addslashes($p->fonctions[0][1]); |
|
| 521 | + $p->code .= " . '$code'"; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | + if (strpos($nom, 'ID_') === 0) { |
|
| 526 | + $p->interdire_scripts = false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | + // SI le champ SQL n'est pas trouve |
|
| 531 | + // ET si la balise a une forme de couleur |
|
| 532 | + // ET s'il n'y a ni filtre ni etoile |
|
| 533 | + // ALORS retourner la couleur. |
|
| 534 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | + if ( |
|
| 536 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | + and !$p->etoile |
|
| 538 | + and !$p->fonctions |
|
| 539 | + ) { |
|
| 540 | + $p->code = "'#$nom'"; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -584,39 +584,39 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 586 | 586 | |
| 587 | - if (!balise_distante_interdite($p)) { |
|
| 588 | - $p->code = "''"; |
|
| 589 | - |
|
| 590 | - return $p; |
|
| 591 | - } |
|
| 592 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | - $p->fonctions = null; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if ($p->param and ($c = $p->param[0])) { |
|
| 599 | - // liste d'arguments commence toujours par la chaine vide |
|
| 600 | - array_shift($c); |
|
| 601 | - // construire la liste d'arguments comme pour un filtre |
|
| 602 | - $param = compose_filtres_args($p, $c, ','); |
|
| 603 | - } else { |
|
| 604 | - $param = ''; |
|
| 605 | - } |
|
| 606 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | - |
|
| 608 | - $p->code = sprintf( |
|
| 609 | - CODE_EXECUTER_BALISE, |
|
| 610 | - $nom, |
|
| 611 | - join(',', $collecte), |
|
| 612 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | - memoriser_contexte_compil($p), |
|
| 614 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | - ); |
|
| 616 | - |
|
| 617 | - $p->interdire_scripts = false; |
|
| 618 | - |
|
| 619 | - return $p; |
|
| 587 | + if (!balise_distante_interdite($p)) { |
|
| 588 | + $p->code = "''"; |
|
| 589 | + |
|
| 590 | + return $p; |
|
| 591 | + } |
|
| 592 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | + $p->fonctions = null; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if ($p->param and ($c = $p->param[0])) { |
|
| 599 | + // liste d'arguments commence toujours par la chaine vide |
|
| 600 | + array_shift($c); |
|
| 601 | + // construire la liste d'arguments comme pour un filtre |
|
| 602 | + $param = compose_filtres_args($p, $c, ','); |
|
| 603 | + } else { |
|
| 604 | + $param = ''; |
|
| 605 | + } |
|
| 606 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | + |
|
| 608 | + $p->code = sprintf( |
|
| 609 | + CODE_EXECUTER_BALISE, |
|
| 610 | + $nom, |
|
| 611 | + join(',', $collecte), |
|
| 612 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | + memoriser_contexte_compil($p), |
|
| 614 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | + ); |
|
| 616 | + |
|
| 617 | + $p->interdire_scripts = false; |
|
| 618 | + |
|
| 619 | + return $p; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | |
@@ -646,17 +646,17 @@ discard block |
||
| 646 | 646 | * Liste des codes PHP d'éxecution des balises collectées |
| 647 | 647 | **/ |
| 648 | 648 | function collecter_balise_dynamique(array $l, \Champ &$p, string $nom): array { |
| 649 | - $args = []; |
|
| 650 | - foreach ($l as $c) { |
|
| 651 | - if ($c === null) { |
|
| 652 | - $args[] = 'null'; |
|
| 653 | - } else { |
|
| 654 | - $x = calculer_balise($c, $p); |
|
| 655 | - $args[] = $x->code; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - return $args; |
|
| 649 | + $args = []; |
|
| 650 | + foreach ($l as $c) { |
|
| 651 | + if ($c === null) { |
|
| 652 | + $args[] = 'null'; |
|
| 653 | + } else { |
|
| 654 | + $x = calculer_balise($c, $p); |
|
| 655 | + $args[] = $x->code; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + return $args; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | |
@@ -671,22 +671,22 @@ discard block |
||
| 671 | 671 | * Nom de la connexion |
| 672 | 672 | **/ |
| 673 | 673 | function trouver_nom_serveur_distant($p) { |
| 674 | - $nom = $p->id_boucle; |
|
| 675 | - if ( |
|
| 676 | - $nom |
|
| 677 | - and isset($p->boucles[$nom]) |
|
| 678 | - ) { |
|
| 679 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 680 | - if ( |
|
| 681 | - strlen($s) |
|
| 682 | - and strlen($serveur = strtolower($s)) |
|
| 683 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 684 | - ) { |
|
| 685 | - return $serveur; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return ''; |
|
| 674 | + $nom = $p->id_boucle; |
|
| 675 | + if ( |
|
| 676 | + $nom |
|
| 677 | + and isset($p->boucles[$nom]) |
|
| 678 | + ) { |
|
| 679 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 680 | + if ( |
|
| 681 | + strlen($s) |
|
| 682 | + and strlen($serveur = strtolower($s)) |
|
| 683 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 684 | + ) { |
|
| 685 | + return $serveur; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return ''; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | |
@@ -710,15 +710,15 @@ discard block |
||
| 710 | 710 | * - false : La balise est interdite car le serveur est distant |
| 711 | 711 | **/ |
| 712 | 712 | function balise_distante_interdite($p) { |
| 713 | - $nom = $p->id_boucle; |
|
| 713 | + $nom = $p->id_boucle; |
|
| 714 | 714 | |
| 715 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 716 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 715 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 716 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 717 | 717 | |
| 718 | - return false; |
|
| 719 | - } |
|
| 718 | + return false; |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - return true; |
|
| 721 | + return true; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | |
@@ -728,84 +728,84 @@ discard block |
||
| 728 | 728 | // |
| 729 | 729 | function champs_traitements($p) { |
| 730 | 730 | |
| 731 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 732 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 733 | - } else { |
|
| 734 | - // quand on utilise un traitement catch-all * |
|
| 735 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 736 | - // leur propre securite |
|
| 737 | - if (!$p->balise_calculee) { |
|
| 738 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 739 | - } else { |
|
| 740 | - $ps = false; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - if (is_array($ps)) { |
|
| 745 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 746 | - $idb = index_boucle($p); |
|
| 747 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 748 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 749 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 753 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 754 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 755 | - |
|
| 756 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 757 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 758 | - $type_alias = $type_requete; |
|
| 759 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 760 | - } else { |
|
| 761 | - $type_alias = false; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 765 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 766 | - $ps = $ps[$table_sql]; |
|
| 767 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 768 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 769 | - $ps = $ps[$type_requete]; |
|
| 770 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 771 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 772 | - $ps = $ps[$type_alias]; |
|
| 773 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 774 | - elseif (isset($ps[0])) { |
|
| 775 | - $ps = $ps[0]; |
|
| 776 | - } else { |
|
| 777 | - $ps = false; |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if (!$ps) { |
|
| 782 | - return $p->code; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 786 | - // ou si in INCLURE contient {doublons} |
|
| 787 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 788 | - // dans les filtres propre() ou typo() |
|
| 789 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 790 | - |
|
| 791 | - if ( |
|
| 792 | - isset($p->descr['documents']) |
|
| 793 | - and |
|
| 794 | - $p->descr['documents'] |
|
| 795 | - and ( |
|
| 796 | - (strpos($ps, 'propre') !== false) |
|
| 797 | - or |
|
| 798 | - (strpos($ps, 'typo') !== false) |
|
| 799 | - ) |
|
| 800 | - ) { |
|
| 801 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 805 | - // dans la declaration des traitements des champs sensibles |
|
| 806 | - |
|
| 807 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 808 | - return str_replace('%s', $p->code, $ps); |
|
| 731 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 732 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 733 | + } else { |
|
| 734 | + // quand on utilise un traitement catch-all * |
|
| 735 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 736 | + // leur propre securite |
|
| 737 | + if (!$p->balise_calculee) { |
|
| 738 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 739 | + } else { |
|
| 740 | + $ps = false; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + if (is_array($ps)) { |
|
| 745 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 746 | + $idb = index_boucle($p); |
|
| 747 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 748 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 749 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 753 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 754 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 755 | + |
|
| 756 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 757 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 758 | + $type_alias = $type_requete; |
|
| 759 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 760 | + } else { |
|
| 761 | + $type_alias = false; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 765 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 766 | + $ps = $ps[$table_sql]; |
|
| 767 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 768 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 769 | + $ps = $ps[$type_requete]; |
|
| 770 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 771 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 772 | + $ps = $ps[$type_alias]; |
|
| 773 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 774 | + elseif (isset($ps[0])) { |
|
| 775 | + $ps = $ps[0]; |
|
| 776 | + } else { |
|
| 777 | + $ps = false; |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if (!$ps) { |
|
| 782 | + return $p->code; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 786 | + // ou si in INCLURE contient {doublons} |
|
| 787 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 788 | + // dans les filtres propre() ou typo() |
|
| 789 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 790 | + |
|
| 791 | + if ( |
|
| 792 | + isset($p->descr['documents']) |
|
| 793 | + and |
|
| 794 | + $p->descr['documents'] |
|
| 795 | + and ( |
|
| 796 | + (strpos($ps, 'propre') !== false) |
|
| 797 | + or |
|
| 798 | + (strpos($ps, 'typo') !== false) |
|
| 799 | + ) |
|
| 800 | + ) { |
|
| 801 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 805 | + // dans la declaration des traitements des champs sensibles |
|
| 806 | + |
|
| 807 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 808 | + return str_replace('%s', $p->code, $ps); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -817,110 +817,110 @@ discard block |
||
| 817 | 817 | // |
| 818 | 818 | function applique_filtres($p) { |
| 819 | 819 | |
| 820 | - // Traitements standards (cf. supra) |
|
| 821 | - if ($p->etoile == '') { |
|
| 822 | - $code = champs_traitements($p); |
|
| 823 | - } else { |
|
| 824 | - $code = $p->code; |
|
| 825 | - } |
|
| 820 | + // Traitements standards (cf. supra) |
|
| 821 | + if ($p->etoile == '') { |
|
| 822 | + $code = champs_traitements($p); |
|
| 823 | + } else { |
|
| 824 | + $code = $p->code; |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | - // Appliquer les filtres perso |
|
| 828 | - if ($p->param) { |
|
| 829 | - $code = compose_filtres($p, $code); |
|
| 830 | - } |
|
| 827 | + // Appliquer les filtres perso |
|
| 828 | + if ($p->param) { |
|
| 829 | + $code = compose_filtres($p, $code); |
|
| 830 | + } |
|
| 831 | 831 | |
| 832 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 833 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 834 | - if (isset($p->descr['session'])) { |
|
| 835 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 836 | - } |
|
| 832 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 833 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 834 | + if (isset($p->descr['session'])) { |
|
| 835 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 838 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 839 | 839 | |
| 840 | - return $code; |
|
| 840 | + return $code; |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 844 | 844 | function compose_filtres(&$p, $code) { |
| 845 | 845 | |
| 846 | - $image_miette = false; |
|
| 847 | - foreach ($p->param as $filtre) { |
|
| 848 | - $fonc = array_shift($filtre); |
|
| 849 | - if (!$fonc) { |
|
| 850 | - continue; |
|
| 851 | - } // normalement qu'au premier tour. |
|
| 852 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 853 | - if ($image_miette and !$is_filtre_image) { |
|
| 854 | - // il faut graver maintenant car apres le filtre en cours |
|
| 855 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 856 | - $code = "filtrer('image_graver', $code)"; |
|
| 857 | - $image_miette = false; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - // recuperer les arguments du filtre, |
|
| 861 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 862 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 863 | - if ($fonc !== '?') { |
|
| 864 | - $sep = ','; |
|
| 865 | - } else { |
|
| 866 | - $sep = ':'; |
|
| 867 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 868 | - if ($countfiltre != 2) { |
|
| 869 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 870 | - $countfiltre = 2; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 874 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 875 | - if ($logique) { |
|
| 876 | - $code = $logique; |
|
| 877 | - } else { |
|
| 878 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 879 | - if ($is_filtre_image) { |
|
| 880 | - $image_miette = true; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 885 | - if ($image_miette) { |
|
| 886 | - $code = "filtrer('image_graver',$code)"; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - return $code; |
|
| 846 | + $image_miette = false; |
|
| 847 | + foreach ($p->param as $filtre) { |
|
| 848 | + $fonc = array_shift($filtre); |
|
| 849 | + if (!$fonc) { |
|
| 850 | + continue; |
|
| 851 | + } // normalement qu'au premier tour. |
|
| 852 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 853 | + if ($image_miette and !$is_filtre_image) { |
|
| 854 | + // il faut graver maintenant car apres le filtre en cours |
|
| 855 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 856 | + $code = "filtrer('image_graver', $code)"; |
|
| 857 | + $image_miette = false; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + // recuperer les arguments du filtre, |
|
| 861 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 862 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 863 | + if ($fonc !== '?') { |
|
| 864 | + $sep = ','; |
|
| 865 | + } else { |
|
| 866 | + $sep = ':'; |
|
| 867 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 868 | + if ($countfiltre != 2) { |
|
| 869 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 870 | + $countfiltre = 2; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 874 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 875 | + if ($logique) { |
|
| 876 | + $code = $logique; |
|
| 877 | + } else { |
|
| 878 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 879 | + if ($is_filtre_image) { |
|
| 880 | + $image_miette = true; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 885 | + if ($image_miette) { |
|
| 886 | + $code = "filtrer('image_graver',$code)"; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + return $code; |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 893 | 893 | // et comparateurs |
| 894 | 894 | function filtre_logique($fonc, $code, $arg) { |
| 895 | 895 | |
| 896 | - switch (true) { |
|
| 897 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 898 | - return "($code $fonc $arg)"; |
|
| 899 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 900 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 901 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 902 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 903 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 904 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 905 | - case ($fonc == 'sinon'): |
|
| 906 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 907 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 908 | - return "(($code) ?'' :' ')"; |
|
| 909 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 910 | - return "(($code) ?' ' :'')"; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - return ''; |
|
| 896 | + switch (true) { |
|
| 897 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 898 | + return "($code $fonc $arg)"; |
|
| 899 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 900 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 901 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 902 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 903 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 904 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 905 | + case ($fonc == 'sinon'): |
|
| 906 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 907 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 908 | + return "(($code) ?'' :' ')"; |
|
| 909 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 910 | + return "(($code) ?' ' :'')"; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + return ''; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | function compose_filtres_args($p, $args, $sep) { |
| 917 | - $arglist = ''; |
|
| 918 | - foreach ($args as $arg) { |
|
| 919 | - $arglist .= $sep . |
|
| 920 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | - } |
|
| 917 | + $arglist = ''; |
|
| 918 | + foreach ($args as $arg) { |
|
| 919 | + $arglist .= $sep . |
|
| 920 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | - return $arglist; |
|
| 923 | + return $arglist; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -938,15 +938,15 @@ discard block |
||
| 938 | 938 | **/ |
| 939 | 939 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 940 | 940 | |
| 941 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | - if ($boucles[$idb]->externe) { |
|
| 943 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | - // on ignore le defaut fourni dans ce cas |
|
| 946 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | - } |
|
| 941 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | + if ($boucles[$idb]->externe) { |
|
| 943 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | + // on ignore le defaut fourni dans ce cas |
|
| 946 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | + } |
|
| 948 | 948 | |
| 949 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 949 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | // |
@@ -960,30 +960,30 @@ discard block |
||
| 960 | 960 | // |
| 961 | 961 | |
| 962 | 962 | function rindex_pile($p, $champ, $motif) { |
| 963 | - $n = 0; |
|
| 964 | - $b = $p->id_boucle; |
|
| 965 | - $p->code = ''; |
|
| 966 | - while ($b != '') { |
|
| 967 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 968 | - if ($critere->op == $motif) { |
|
| 969 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 970 | - "]['$champ']"; |
|
| 971 | - $b = ''; |
|
| 972 | - break 2; |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - $n++; |
|
| 976 | - $b = $p->boucles[$b]->id_parent; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 980 | - if (!$p->code) { |
|
| 981 | - $p->code = "''"; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - $p->interdire_scripts = false; |
|
| 985 | - |
|
| 986 | - return $p; |
|
| 963 | + $n = 0; |
|
| 964 | + $b = $p->id_boucle; |
|
| 965 | + $p->code = ''; |
|
| 966 | + while ($b != '') { |
|
| 967 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 968 | + if ($critere->op == $motif) { |
|
| 969 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 970 | + "]['$champ']"; |
|
| 971 | + $b = ''; |
|
| 972 | + break 2; |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + $n++; |
|
| 976 | + $b = $p->boucles[$b]->id_parent; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 980 | + if (!$p->code) { |
|
| 981 | + $p->code = "''"; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + $p->interdire_scripts = false; |
|
| 985 | + |
|
| 986 | + return $p; |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | /** |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 994 | 994 | */ |
| 995 | 995 | function zbug_presenter_champ($p, $champ = '') { |
| 996 | - $balise = $champ ?: $p->nom_champ; |
|
| 997 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 998 | - return "#{$explicite}{$balise}"; |
|
| 996 | + $balise = $champ ?: $p->nom_champ; |
|
| 997 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 998 | + return "#{$explicite}{$balise}"; |
|
| 999 | 999 | } |
@@ -11,187 +11,187 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function trace_query_start() { |
| 18 | - static $trace = '?'; |
|
| 19 | - if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 20 | - if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 21 | - $trace = true; |
|
| 22 | - } |
|
| 23 | - else { |
|
| 24 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 25 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 26 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 27 | - // ou une requete SQL faite avant chargement de la session |
|
| 28 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 29 | - } |
|
| 30 | - else { |
|
| 31 | - include_spip('inc/autoriser'); |
|
| 32 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 33 | - // A fortiori quand on demande une trace |
|
| 34 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 35 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - return $trace ? microtime() : 0; |
|
| 18 | + static $trace = '?'; |
|
| 19 | + if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 20 | + if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 21 | + $trace = true; |
|
| 22 | + } |
|
| 23 | + else { |
|
| 24 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 25 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 26 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 27 | + // ou une requete SQL faite avant chargement de la session |
|
| 28 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 29 | + } |
|
| 30 | + else { |
|
| 31 | + include_spip('inc/autoriser'); |
|
| 32 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 33 | + // A fortiori quand on demande une trace |
|
| 34 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 35 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + return $trace ? microtime() : 0; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 44 | - static $trace = '?'; |
|
| 45 | - if ($trace === '?') { |
|
| 46 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 47 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 48 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 49 | - // ou une requete SQL faite avant chargement de la session |
|
| 50 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 51 | - } |
|
| 52 | - else { |
|
| 53 | - include_spip('inc/autoriser'); |
|
| 54 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 55 | - // A fortiori quand on demande une trace |
|
| 56 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 57 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - if ($start) { |
|
| 61 | - $end = microtime(); |
|
| 62 | - [$usec, $sec] = explode(' ', $start); |
|
| 63 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 64 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 65 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 66 | - if ($trace) { |
|
| 67 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 71 | - if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 72 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $result; |
|
| 44 | + static $trace = '?'; |
|
| 45 | + if ($trace === '?') { |
|
| 46 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 47 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 48 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 49 | + // ou une requete SQL faite avant chargement de la session |
|
| 50 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 51 | + } |
|
| 52 | + else { |
|
| 53 | + include_spip('inc/autoriser'); |
|
| 54 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 55 | + // A fortiori quand on demande une trace |
|
| 56 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 57 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + if ($start) { |
|
| 61 | + $end = microtime(); |
|
| 62 | + [$usec, $sec] = explode(' ', $start); |
|
| 63 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 64 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 65 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 66 | + if ($trace) { |
|
| 67 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 71 | + if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 72 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $result; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 79 | - include_spip('inc/filtres_mini'); |
|
| 80 | - static $tt = 0, $nb = 0; |
|
| 81 | - |
|
| 82 | - $x = _request('var_mode_objet'); |
|
| 83 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 84 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 85 | - if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - if ($serveur) { |
|
| 89 | - $boucle .= " ($serveur)"; |
|
| 90 | - } |
|
| 91 | - $boucle = "<b>$boucle</b>"; |
|
| 92 | - } else { |
|
| 93 | - if ($x) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - $boucle = $contexte = ''; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $tt += $dt; |
|
| 100 | - $nb++; |
|
| 101 | - |
|
| 102 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 103 | - $e = sql_explain($query, $serveur); |
|
| 104 | - $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 105 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 79 | + include_spip('inc/filtres_mini'); |
|
| 80 | + static $tt = 0, $nb = 0; |
|
| 81 | + |
|
| 82 | + $x = _request('var_mode_objet'); |
|
| 83 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 84 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 85 | + if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + if ($serveur) { |
|
| 89 | + $boucle .= " ($serveur)"; |
|
| 90 | + } |
|
| 91 | + $boucle = "<b>$boucle</b>"; |
|
| 92 | + } else { |
|
| 93 | + if ($x) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + $boucle = $contexte = ''; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $tt += $dt; |
|
| 100 | + $nb++; |
|
| 101 | + |
|
| 102 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 103 | + $e = sql_explain($query, $serveur); |
|
| 104 | + $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 105 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | function chrono_requete($temps) { |
| 110 | - $total = 0; |
|
| 111 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 112 | - $t = $q = $n = $d = []; |
|
| 113 | - // Totaliser les temps et completer le Explain |
|
| 114 | - foreach ($temps as $key => $v) { |
|
| 115 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 116 | - if (is_array($contexte)) { |
|
| 117 | - $k = ($contexte[0] . " $boucle"); |
|
| 118 | - include_spip('public/compiler'); |
|
| 119 | - $env = reconstruire_contexte_compil($contexte); |
|
| 120 | - } else { |
|
| 121 | - $k = $env = $boucle; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $total += $dt; |
|
| 125 | - $t[$key] = $dt; |
|
| 126 | - $q[$key] = $nb; |
|
| 127 | - if (!isset($d[$k])) { |
|
| 128 | - $d[$k] = 0; |
|
| 129 | - $n[$k] = 0; |
|
| 130 | - } |
|
| 131 | - $d[$k] += $dt; |
|
| 132 | - ++$n[$k]; |
|
| 133 | - |
|
| 134 | - if (!is_array($explain)) { |
|
| 135 | - $explain = []; |
|
| 136 | - } |
|
| 137 | - foreach ($explain as $j => $v) { |
|
| 138 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 139 | - . str_replace(';', '<br />', $v) |
|
| 140 | - . '</td></tr>'; |
|
| 141 | - } |
|
| 142 | - $e = "<table class='explain'>" |
|
| 143 | - . '<caption>' |
|
| 144 | - . $query |
|
| 145 | - . '</caption>' |
|
| 146 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 147 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 148 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 149 | - . join('', $explain) |
|
| 150 | - . '</table>'; |
|
| 151 | - |
|
| 152 | - $temps[$key] = [$e, $env, $k]; |
|
| 153 | - } |
|
| 154 | - // Trier par temps d'execution decroissant |
|
| 155 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 156 | - arsort($d); |
|
| 157 | - $i = 1; |
|
| 158 | - $t = []; |
|
| 159 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 160 | - foreach ($temps as $k => $v) { |
|
| 161 | - $titre = strip_tags($v[2]); |
|
| 162 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 163 | - $href = str_replace("\\'", ''', $href); |
|
| 164 | - |
|
| 165 | - if (!isset($t[$v[2]])) { |
|
| 166 | - $t[$v[2]] = []; |
|
| 167 | - } |
|
| 168 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 169 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 170 | - . '</span>' |
|
| 171 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 172 | - $i++; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($d['']) { |
|
| 176 | - $d[$hors] = $d['']; |
|
| 177 | - $n[$hors] = $n['']; |
|
| 178 | - $t[$hors] = $t['']; |
|
| 179 | - } |
|
| 180 | - unset($d['']); |
|
| 181 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 182 | - foreach ($d as $k => $v) { |
|
| 183 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 184 | - . join('', $t[$k]); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $navigation = [ |
|
| 188 | - _T('zbug_statistiques'), |
|
| 189 | - '<tr><td>' |
|
| 190 | - . join("</td></tr>\n<tr><td>", $d) |
|
| 191 | - . "</td></tr>\n" |
|
| 192 | - . (# _request('var_mode_objet') ? '' : |
|
| 193 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 194 | - ]; |
|
| 195 | - |
|
| 196 | - return [$temps, $navigation]; |
|
| 110 | + $total = 0; |
|
| 111 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 112 | + $t = $q = $n = $d = []; |
|
| 113 | + // Totaliser les temps et completer le Explain |
|
| 114 | + foreach ($temps as $key => $v) { |
|
| 115 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 116 | + if (is_array($contexte)) { |
|
| 117 | + $k = ($contexte[0] . " $boucle"); |
|
| 118 | + include_spip('public/compiler'); |
|
| 119 | + $env = reconstruire_contexte_compil($contexte); |
|
| 120 | + } else { |
|
| 121 | + $k = $env = $boucle; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $total += $dt; |
|
| 125 | + $t[$key] = $dt; |
|
| 126 | + $q[$key] = $nb; |
|
| 127 | + if (!isset($d[$k])) { |
|
| 128 | + $d[$k] = 0; |
|
| 129 | + $n[$k] = 0; |
|
| 130 | + } |
|
| 131 | + $d[$k] += $dt; |
|
| 132 | + ++$n[$k]; |
|
| 133 | + |
|
| 134 | + if (!is_array($explain)) { |
|
| 135 | + $explain = []; |
|
| 136 | + } |
|
| 137 | + foreach ($explain as $j => $v) { |
|
| 138 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 139 | + . str_replace(';', '<br />', $v) |
|
| 140 | + . '</td></tr>'; |
|
| 141 | + } |
|
| 142 | + $e = "<table class='explain'>" |
|
| 143 | + . '<caption>' |
|
| 144 | + . $query |
|
| 145 | + . '</caption>' |
|
| 146 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 147 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 148 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 149 | + . join('', $explain) |
|
| 150 | + . '</table>'; |
|
| 151 | + |
|
| 152 | + $temps[$key] = [$e, $env, $k]; |
|
| 153 | + } |
|
| 154 | + // Trier par temps d'execution decroissant |
|
| 155 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 156 | + arsort($d); |
|
| 157 | + $i = 1; |
|
| 158 | + $t = []; |
|
| 159 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 160 | + foreach ($temps as $k => $v) { |
|
| 161 | + $titre = strip_tags($v[2]); |
|
| 162 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 163 | + $href = str_replace("\\'", ''', $href); |
|
| 164 | + |
|
| 165 | + if (!isset($t[$v[2]])) { |
|
| 166 | + $t[$v[2]] = []; |
|
| 167 | + } |
|
| 168 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 169 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 170 | + . '</span>' |
|
| 171 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 172 | + $i++; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($d['']) { |
|
| 176 | + $d[$hors] = $d['']; |
|
| 177 | + $n[$hors] = $n['']; |
|
| 178 | + $t[$hors] = $t['']; |
|
| 179 | + } |
|
| 180 | + unset($d['']); |
|
| 181 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 182 | + foreach ($d as $k => $v) { |
|
| 183 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 184 | + . join('', $t[$k]); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $navigation = [ |
|
| 188 | + _T('zbug_statistiques'), |
|
| 189 | + '<tr><td>' |
|
| 190 | + . join("</td></tr>\n<tr><td>", $d) |
|
| 191 | + . "</td></tr>\n" |
|
| 192 | + . (# _request('var_mode_objet') ? '' : |
|
| 193 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 194 | + ]; |
|
| 195 | + |
|
| 196 | + return [$temps, $navigation]; |
|
| 197 | 197 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** Début de la partie principale d'une boucle */ |
@@ -64,82 +64,82 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
| 67 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | - $match = array_pad($match, 3, null); |
|
| 69 | - $p = strpos($texte, (string) $match[0]); |
|
| 70 | - $debut = substr($texte, 0, $p); |
|
| 71 | - if ($p) { |
|
| 72 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | - } |
|
| 74 | - $ligne += substr_count($debut, "\n"); |
|
| 75 | - $champ = new Inclure(); |
|
| 76 | - $champ->ligne = $ligne; |
|
| 77 | - $ligne += substr_count($match[0], "\n"); |
|
| 78 | - $fichier = $match[2]; |
|
| 79 | - # assurer ici la migration .php3 => .php |
|
| 80 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | - $fichier = $r[1]; |
|
| 83 | - } |
|
| 84 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | - $pos_apres = 0; |
|
| 88 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | - $result[] = $champ; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 67 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | + $match = array_pad($match, 3, null); |
|
| 69 | + $p = strpos($texte, (string) $match[0]); |
|
| 70 | + $debut = substr($texte, 0, $p); |
|
| 71 | + if ($p) { |
|
| 72 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | + } |
|
| 74 | + $ligne += substr_count($debut, "\n"); |
|
| 75 | + $champ = new Inclure(); |
|
| 76 | + $champ->ligne = $ligne; |
|
| 77 | + $ligne += substr_count($match[0], "\n"); |
|
| 78 | + $fichier = $match[2]; |
|
| 79 | + # assurer ici la migration .php3 => .php |
|
| 80 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | + $fichier = $r[1]; |
|
| 83 | + } |
|
| 84 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | + $pos_apres = 0; |
|
| 88 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | + $result[] = $champ; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function phraser_polyglotte($texte, $ligne, $result) { |
| 104 | 104 | |
| 105 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | - foreach ($m as $match) { |
|
| 107 | - $p = strpos($texte, (string) $match[0]); |
|
| 108 | - $debut = substr($texte, 0, $p); |
|
| 109 | - if ($p) { |
|
| 110 | - $champ = new Texte(); |
|
| 111 | - $champ->texte = $debut; |
|
| 112 | - $champ->ligne = $ligne; |
|
| 113 | - $result[] = $champ; |
|
| 114 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $champ = new Polyglotte(); |
|
| 118 | - $champ->ligne = $ligne; |
|
| 119 | - $ligne += substr_count($match[0], "\n"); |
|
| 120 | - $lang = ''; |
|
| 121 | - $bloc = $match[1]; |
|
| 122 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | - $trad = $regs[1]; |
|
| 125 | - if ($trad or $lang) { |
|
| 126 | - $champ->traductions[$lang] = $trad; |
|
| 127 | - } |
|
| 128 | - $lang = $regs[2]; |
|
| 129 | - $bloc = $regs[3]; |
|
| 130 | - } |
|
| 131 | - $champ->traductions[$lang] = $bloc; |
|
| 132 | - $result[] = $champ; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if ($texte !== '') { |
|
| 136 | - $champ = new Texte(); |
|
| 137 | - $champ->texte = $texte; |
|
| 138 | - $champ->ligne = $ligne; |
|
| 139 | - $result[] = $champ; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $result; |
|
| 105 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | + foreach ($m as $match) { |
|
| 107 | + $p = strpos($texte, (string) $match[0]); |
|
| 108 | + $debut = substr($texte, 0, $p); |
|
| 109 | + if ($p) { |
|
| 110 | + $champ = new Texte(); |
|
| 111 | + $champ->texte = $debut; |
|
| 112 | + $champ->ligne = $ligne; |
|
| 113 | + $result[] = $champ; |
|
| 114 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $champ = new Polyglotte(); |
|
| 118 | + $champ->ligne = $ligne; |
|
| 119 | + $ligne += substr_count($match[0], "\n"); |
|
| 120 | + $lang = ''; |
|
| 121 | + $bloc = $match[1]; |
|
| 122 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | + $trad = $regs[1]; |
|
| 125 | + if ($trad or $lang) { |
|
| 126 | + $champ->traductions[$lang] = $trad; |
|
| 127 | + } |
|
| 128 | + $lang = $regs[2]; |
|
| 129 | + $bloc = $regs[3]; |
|
| 130 | + } |
|
| 131 | + $champ->traductions[$lang] = $bloc; |
|
| 132 | + $result[] = $champ; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if ($texte !== '') { |
|
| 136 | + $champ = new Texte(); |
|
| 137 | + $champ->texte = $texte; |
|
| 138 | + $champ->ligne = $ligne; |
|
| 139 | + $result[] = $champ; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $result; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -161,43 +161,43 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | **/ |
| 163 | 163 | function phraser_idiomes($texte, $ligne, $result) { |
| 164 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | - $match = array_pad($match, 8, null); |
|
| 166 | - $p = strpos($texte, (string) $match[0]); |
|
| 167 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | - if ($debut) { |
|
| 170 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | - } |
|
| 172 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | - $ligne += substr_count($debut, "\n"); |
|
| 174 | - if ($ko) { |
|
| 175 | - continue; |
|
| 176 | - } // faux idiome |
|
| 177 | - $champ = new Idiome(); |
|
| 178 | - $champ->ligne = $ligne; |
|
| 179 | - $ligne += substr_count($match[0], "\n"); |
|
| 180 | - // Stocker les arguments de la balise de traduction |
|
| 181 | - $args = []; |
|
| 182 | - $largs = $match[5]; |
|
| 183 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | - $largs = substr($largs, strlen($r[0])); |
|
| 186 | - } |
|
| 187 | - $champ->arg = $args; |
|
| 188 | - $champ->nom_champ = strtolower($match[3]); |
|
| 189 | - $champ->module = $match[2]; |
|
| 190 | - // pas d'imbrication pour les filtres sur langue |
|
| 191 | - $pos_apres = 0; |
|
| 192 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== '') { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $result; |
|
| 164 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | + $match = array_pad($match, 8, null); |
|
| 166 | + $p = strpos($texte, (string) $match[0]); |
|
| 167 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | + if ($debut) { |
|
| 170 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | + } |
|
| 172 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | + $ligne += substr_count($debut, "\n"); |
|
| 174 | + if ($ko) { |
|
| 175 | + continue; |
|
| 176 | + } // faux idiome |
|
| 177 | + $champ = new Idiome(); |
|
| 178 | + $champ->ligne = $ligne; |
|
| 179 | + $ligne += substr_count($match[0], "\n"); |
|
| 180 | + // Stocker les arguments de la balise de traduction |
|
| 181 | + $args = []; |
|
| 182 | + $largs = $match[5]; |
|
| 183 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | + $largs = substr($largs, strlen($r[0])); |
|
| 186 | + } |
|
| 187 | + $champ->arg = $args; |
|
| 188 | + $champ->nom_champ = strtolower($match[3]); |
|
| 189 | + $champ->module = $match[2]; |
|
| 190 | + // pas d'imbrication pour les filtres sur langue |
|
| 191 | + $pos_apres = 0; |
|
| 192 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | + $result[] = $champ; |
|
| 195 | + } |
|
| 196 | + if ($texte !== '') { |
|
| 197 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $result; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | - $p = strpos($texte, (string) $match[0]); |
|
| 220 | - // texte après la balise |
|
| 221 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | - |
|
| 223 | - $debut = substr($texte, 0, $p); |
|
| 224 | - if ($p) { |
|
| 225 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | - } |
|
| 227 | - $ligne += substr_count($debut, "\n"); |
|
| 228 | - $champ = new Champ(); |
|
| 229 | - $champ->ligne = $ligne; |
|
| 230 | - $ligne += substr_count($match[0], "\n"); |
|
| 231 | - $champ->nom_boucle = $match[2]; |
|
| 232 | - $champ->nom_champ = $match[3]; |
|
| 233 | - $champ->etoile = $match[5]; |
|
| 234 | - |
|
| 235 | - if ($suite and $suite[0] == '{') { |
|
| 236 | - phraser_arg($suite, '', [], $champ); |
|
| 237 | - // ce ltrim est une ereur de conception |
|
| 238 | - // mais on le conserve par souci de compatibilite |
|
| 239 | - $texte = ltrim($suite); |
|
| 240 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 218 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | + $p = strpos($texte, (string) $match[0]); |
|
| 220 | + // texte après la balise |
|
| 221 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | + |
|
| 223 | + $debut = substr($texte, 0, $p); |
|
| 224 | + if ($p) { |
|
| 225 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | + } |
|
| 227 | + $ligne += substr_count($debut, "\n"); |
|
| 228 | + $champ = new Champ(); |
|
| 229 | + $champ->ligne = $ligne; |
|
| 230 | + $ligne += substr_count($match[0], "\n"); |
|
| 231 | + $champ->nom_boucle = $match[2]; |
|
| 232 | + $champ->nom_champ = $match[3]; |
|
| 233 | + $champ->etoile = $match[5]; |
|
| 234 | + |
|
| 235 | + if ($suite and $suite[0] == '{') { |
|
| 236 | + phraser_arg($suite, '', [], $champ); |
|
| 237 | + // ce ltrim est une ereur de conception |
|
| 238 | + // mais on le conserve par souci de compatibilite |
|
| 239 | + $texte = ltrim($suite); |
|
| 240 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 243 | 243 | if ($n = (strlen($suite) - strlen($texte))) { |
| 244 | 244 | $champ->apres = array(new Texte); |
| 245 | 245 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 246 | 246 | } |
| 247 | 247 | */ |
| 248 | - } else { |
|
| 249 | - $texte = $suite; |
|
| 250 | - } |
|
| 251 | - phraser_vieux($champ); |
|
| 252 | - $result[] = $champ; |
|
| 253 | - } |
|
| 254 | - if ($texte !== '') { |
|
| 255 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $result; |
|
| 248 | + } else { |
|
| 249 | + $texte = $suite; |
|
| 250 | + } |
|
| 251 | + phraser_vieux($champ); |
|
| 252 | + $result[] = $champ; |
|
| 253 | + } |
|
| 254 | + if ($texte !== '') { |
|
| 255 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $result; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Gestion des imbrications: |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 265 | |
| 266 | 266 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 267 | - if ($texte === '') { |
|
| 268 | - return $result; |
|
| 269 | - } |
|
| 270 | - $sep = '##'; |
|
| 271 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | - $sep .= '#'; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 267 | + if ($texte === '') { |
|
| 268 | + return $result; |
|
| 269 | + } |
|
| 270 | + $sep = '##'; |
|
| 271 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | + $sep .= '#'; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -291,275 +291,275 @@ discard block |
||
| 291 | 291 | * @return array |
| 292 | 292 | */ |
| 293 | 293 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 294 | - $length = strlen($texte); |
|
| 295 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | - $pos_debut++; |
|
| 297 | - } |
|
| 298 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | - $st = substr($texte, $pos_debut); |
|
| 301 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | - $pos_debut = $length - strlen($st); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $result; |
|
| 294 | + $length = strlen($texte); |
|
| 295 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | + $pos_debut++; |
|
| 297 | + } |
|
| 298 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | + $st = substr($texte, $pos_debut); |
|
| 301 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | + $pos_debut = $length - strlen($st); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $result; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 312 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | - $suite = ltrim($match[2]); |
|
| 314 | - $fonc = trim($match[1]); |
|
| 315 | - if ($fonc && $fonc[0] == '|') { |
|
| 316 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | - } |
|
| 318 | - $res = [$fonc]; |
|
| 319 | - $err_f = ''; |
|
| 320 | - // cas du filtre sans argument ou du critere / |
|
| 321 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | - if (!$match[1]) { |
|
| 324 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | - $texte = ''; |
|
| 327 | - } else { |
|
| 328 | - $texte = $suite; |
|
| 329 | - } |
|
| 330 | - if ($err_f) { |
|
| 331 | - $pointeur_champ->param = false; |
|
| 332 | - } elseif ($fonc !== '') { |
|
| 333 | - $pointeur_champ->param[] = $res; |
|
| 334 | - } |
|
| 335 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | - |
|
| 338 | - return $result; |
|
| 339 | - } |
|
| 340 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | - $collecte = []; |
|
| 342 | - while ($args && $args[0] != '}') { |
|
| 343 | - if ($args[0] == '"') { |
|
| 344 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | - } elseif ($args[0] == "'") { |
|
| 346 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | - } else { |
|
| 348 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | - $champ = new Texte(); |
|
| 353 | - $champ->apres = $champ->avant = $args = ''; |
|
| 354 | - break; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $arg = $regs[2]; |
|
| 358 | - if (trim($regs[1])) { |
|
| 359 | - $champ = new Texte(); |
|
| 360 | - $champ->texte = $arg; |
|
| 361 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | - $result[] = $champ; |
|
| 363 | - $collecte[] = $champ; |
|
| 364 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | - } else { |
|
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | - // 0 est un aveu d'impuissance. A completer |
|
| 368 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | - |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - $collecte = array_merge($collecte, $arg); |
|
| 372 | - $result = array_merge($result, $arg); |
|
| 373 | - } else { |
|
| 374 | - $n = strpos($args, (string) $r[0]); |
|
| 375 | - $pred = substr($args, 0, $n); |
|
| 376 | - $par = ',}'; |
|
| 377 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | - $pred = $m[1]; |
|
| 379 | - $par = ')'; |
|
| 380 | - } |
|
| 381 | - if ($pred) { |
|
| 382 | - $champ = new Texte(); |
|
| 383 | - $champ->texte = $pred; |
|
| 384 | - $champ->apres = $champ->avant = ''; |
|
| 385 | - $result[] = $champ; |
|
| 386 | - $collecte[] = $champ; |
|
| 387 | - } |
|
| 388 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | - $champ = new Champ(); |
|
| 390 | - $champ->nom_boucle = $r[2]; |
|
| 391 | - $champ->nom_champ = $r[3]; |
|
| 392 | - $champ->etoile = $r[5]; |
|
| 393 | - $next = $r[6]; |
|
| 394 | - while ($next == '{') { |
|
| 395 | - phraser_arg($rec, $sep, [], $champ); |
|
| 396 | - $args = ltrim($rec); |
|
| 397 | - $next = $args[0] ?? ''; |
|
| 398 | - } |
|
| 399 | - while ($next == '|') { |
|
| 400 | - $pos_apres = 0; |
|
| 401 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | - $args = substr($rec, $pos_apres); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | - if ($champ->param === false) { |
|
| 407 | - $err_f = true; |
|
| 408 | - } else { |
|
| 409 | - phraser_vieux($champ); |
|
| 410 | - } |
|
| 411 | - if ($par == ')') { |
|
| 412 | - $args = substr($args, 1); |
|
| 413 | - } |
|
| 414 | - $collecte[] = $champ; |
|
| 415 | - $result[] = $champ; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | - $args = ltrim(substr($args, 1)); |
|
| 420 | - if ($collecte) { |
|
| 421 | - $res[] = $collecte; |
|
| 422 | - $collecte = []; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - $texte = substr($args, 1); |
|
| 431 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | - // propager les erreurs, et ignorer les param vides |
|
| 433 | - if ($pointeur_champ->param !== false) { |
|
| 434 | - if ($err_f) { |
|
| 435 | - $pointeur_champ->param = false; |
|
| 436 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | - $pointeur_champ->param[] = $res; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | - |
|
| 443 | - return $result; |
|
| 312 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | + $suite = ltrim($match[2]); |
|
| 314 | + $fonc = trim($match[1]); |
|
| 315 | + if ($fonc && $fonc[0] == '|') { |
|
| 316 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | + } |
|
| 318 | + $res = [$fonc]; |
|
| 319 | + $err_f = ''; |
|
| 320 | + // cas du filtre sans argument ou du critere / |
|
| 321 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | + if (!$match[1]) { |
|
| 324 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | + $texte = ''; |
|
| 327 | + } else { |
|
| 328 | + $texte = $suite; |
|
| 329 | + } |
|
| 330 | + if ($err_f) { |
|
| 331 | + $pointeur_champ->param = false; |
|
| 332 | + } elseif ($fonc !== '') { |
|
| 333 | + $pointeur_champ->param[] = $res; |
|
| 334 | + } |
|
| 335 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | + |
|
| 338 | + return $result; |
|
| 339 | + } |
|
| 340 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | + $collecte = []; |
|
| 342 | + while ($args && $args[0] != '}') { |
|
| 343 | + if ($args[0] == '"') { |
|
| 344 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | + } elseif ($args[0] == "'") { |
|
| 346 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | + } else { |
|
| 348 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | + $champ = new Texte(); |
|
| 353 | + $champ->apres = $champ->avant = $args = ''; |
|
| 354 | + break; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $arg = $regs[2]; |
|
| 358 | + if (trim($regs[1])) { |
|
| 359 | + $champ = new Texte(); |
|
| 360 | + $champ->texte = $arg; |
|
| 361 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | + $result[] = $champ; |
|
| 363 | + $collecte[] = $champ; |
|
| 364 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | + } else { |
|
| 366 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | + // 0 est un aveu d'impuissance. A completer |
|
| 368 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | + |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + $collecte = array_merge($collecte, $arg); |
|
| 372 | + $result = array_merge($result, $arg); |
|
| 373 | + } else { |
|
| 374 | + $n = strpos($args, (string) $r[0]); |
|
| 375 | + $pred = substr($args, 0, $n); |
|
| 376 | + $par = ',}'; |
|
| 377 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | + $pred = $m[1]; |
|
| 379 | + $par = ')'; |
|
| 380 | + } |
|
| 381 | + if ($pred) { |
|
| 382 | + $champ = new Texte(); |
|
| 383 | + $champ->texte = $pred; |
|
| 384 | + $champ->apres = $champ->avant = ''; |
|
| 385 | + $result[] = $champ; |
|
| 386 | + $collecte[] = $champ; |
|
| 387 | + } |
|
| 388 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | + $champ = new Champ(); |
|
| 390 | + $champ->nom_boucle = $r[2]; |
|
| 391 | + $champ->nom_champ = $r[3]; |
|
| 392 | + $champ->etoile = $r[5]; |
|
| 393 | + $next = $r[6]; |
|
| 394 | + while ($next == '{') { |
|
| 395 | + phraser_arg($rec, $sep, [], $champ); |
|
| 396 | + $args = ltrim($rec); |
|
| 397 | + $next = $args[0] ?? ''; |
|
| 398 | + } |
|
| 399 | + while ($next == '|') { |
|
| 400 | + $pos_apres = 0; |
|
| 401 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | + $args = substr($rec, $pos_apres); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | + if ($champ->param === false) { |
|
| 407 | + $err_f = true; |
|
| 408 | + } else { |
|
| 409 | + phraser_vieux($champ); |
|
| 410 | + } |
|
| 411 | + if ($par == ')') { |
|
| 412 | + $args = substr($args, 1); |
|
| 413 | + } |
|
| 414 | + $collecte[] = $champ; |
|
| 415 | + $result[] = $champ; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | + $args = ltrim(substr($args, 1)); |
|
| 420 | + if ($collecte) { |
|
| 421 | + $res[] = $collecte; |
|
| 422 | + $collecte = []; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + $texte = substr($args, 1); |
|
| 431 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | + // propager les erreurs, et ignorer les param vides |
|
| 433 | + if ($pointeur_champ->param !== false) { |
|
| 434 | + if ($err_f) { |
|
| 435 | + $pointeur_champ->param = false; |
|
| 436 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | + $pointeur_champ->param[] = $res; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | + |
|
| 443 | + return $result; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | - $res = []; |
|
| 449 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | - break; |
|
| 452 | - } |
|
| 453 | - $debut = substr($texte, 0, $p); |
|
| 454 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | - if ($p) { |
|
| 456 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | - } |
|
| 458 | - $ligne += substr_count($debut, "\n"); |
|
| 459 | - $res[] = $nested[$m[1]]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 448 | + $res = []; |
|
| 449 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | + break; |
|
| 452 | + } |
|
| 453 | + $debut = substr($texte, 0, $p); |
|
| 454 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | + if ($p) { |
|
| 456 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | + } |
|
| 458 | + $ligne += substr_count($debut, "\n"); |
|
| 459 | + $res[] = $nested[$m[1]]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | - $i = 0; // en fait count($result) |
|
| 467 | - $x = ''; |
|
| 468 | - |
|
| 469 | - while (true) { |
|
| 470 | - $j = $i; |
|
| 471 | - $n = $ligne; |
|
| 472 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | - $p = strpos($texte, (string) $match[0]); |
|
| 474 | - $debut = substr($texte, 0, $p); |
|
| 475 | - if ($p) { |
|
| 476 | - $result[$i] = $debut; |
|
| 477 | - $i++; |
|
| 478 | - } |
|
| 479 | - $nom = $match[4]; |
|
| 480 | - $champ = new Champ(); |
|
| 481 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | - $champ->nom_boucle = $match[3]; |
|
| 484 | - $champ->nom_champ = $nom; |
|
| 485 | - $champ->etoile = $match[6]; |
|
| 486 | - // phraser_args indiquera ou commence apres |
|
| 487 | - $pos_apres = 0; |
|
| 488 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | - phraser_vieux($champ); |
|
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | - if (!empty($debut)) { |
|
| 493 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | - } |
|
| 495 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | - |
|
| 497 | - // reinjecter la boucle si c'en est une |
|
| 498 | - phraser_boucle_placeholder($champ); |
|
| 499 | - |
|
| 500 | - $result[$i] = $champ; |
|
| 501 | - $i++; |
|
| 502 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | - } |
|
| 504 | - if ($texte !== '') { |
|
| 505 | - $result[$i] = $texte; |
|
| 506 | - $i++; |
|
| 507 | - } |
|
| 508 | - $x = ''; |
|
| 509 | - |
|
| 510 | - while ($j < $i) { |
|
| 511 | - $z = $result[$j]; |
|
| 512 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | - if (is_object($z)) { |
|
| 514 | - $x .= "%$sep$j@"; |
|
| 515 | - } else { |
|
| 516 | - $x .= $z; |
|
| 517 | - } |
|
| 518 | - $j++; |
|
| 519 | - } |
|
| 520 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | - $texte = $x; |
|
| 522 | - } else { |
|
| 523 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | - } |
|
| 525 | - } |
|
| 466 | + $i = 0; // en fait count($result) |
|
| 467 | + $x = ''; |
|
| 468 | + |
|
| 469 | + while (true) { |
|
| 470 | + $j = $i; |
|
| 471 | + $n = $ligne; |
|
| 472 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | + $p = strpos($texte, (string) $match[0]); |
|
| 474 | + $debut = substr($texte, 0, $p); |
|
| 475 | + if ($p) { |
|
| 476 | + $result[$i] = $debut; |
|
| 477 | + $i++; |
|
| 478 | + } |
|
| 479 | + $nom = $match[4]; |
|
| 480 | + $champ = new Champ(); |
|
| 481 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | + $champ->nom_boucle = $match[3]; |
|
| 484 | + $champ->nom_champ = $nom; |
|
| 485 | + $champ->etoile = $match[6]; |
|
| 486 | + // phraser_args indiquera ou commence apres |
|
| 487 | + $pos_apres = 0; |
|
| 488 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | + phraser_vieux($champ); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | + if (!empty($debut)) { |
|
| 493 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | + } |
|
| 495 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | + |
|
| 497 | + // reinjecter la boucle si c'en est une |
|
| 498 | + phraser_boucle_placeholder($champ); |
|
| 499 | + |
|
| 500 | + $result[$i] = $champ; |
|
| 501 | + $i++; |
|
| 502 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | + } |
|
| 504 | + if ($texte !== '') { |
|
| 505 | + $result[$i] = $texte; |
|
| 506 | + $i++; |
|
| 507 | + } |
|
| 508 | + $x = ''; |
|
| 509 | + |
|
| 510 | + while ($j < $i) { |
|
| 511 | + $z = $result[$j]; |
|
| 512 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | + if (is_object($z)) { |
|
| 514 | + $x .= "%$sep$j@"; |
|
| 515 | + } else { |
|
| 516 | + $x .= $z; |
|
| 517 | + } |
|
| 518 | + $j++; |
|
| 519 | + } |
|
| 520 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | + $texte = $x; |
|
| 522 | + } else { |
|
| 523 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | function phraser_vieux(&$champ) { |
| 529 | - $nom = $champ->nom_champ; |
|
| 530 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | - include_spip('public/normaliser'); |
|
| 533 | - } |
|
| 534 | - phraser_vieux_emb($champ); |
|
| 535 | - } elseif ($nom == 'EXPOSER') { |
|
| 536 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | - include_spip('public/normaliser'); |
|
| 538 | - } |
|
| 539 | - phraser_vieux_exposer($champ); |
|
| 540 | - } elseif ($champ->param) { |
|
| 541 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | - include_spip('public/normaliser'); |
|
| 544 | - } |
|
| 545 | - phraser_vieux_recherche($champ); |
|
| 546 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | - include_spip('public/normaliser'); |
|
| 549 | - } |
|
| 550 | - phraser_vieux_logos($champ); |
|
| 551 | - } elseif ($nom == 'MODELE') { |
|
| 552 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | - include_spip('public/normaliser'); |
|
| 554 | - } |
|
| 555 | - phraser_vieux_modele($champ); |
|
| 556 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | - include_spip('public/normaliser'); |
|
| 559 | - } |
|
| 560 | - phraser_vieux_inclu($champ); |
|
| 561 | - } |
|
| 562 | - } |
|
| 529 | + $nom = $champ->nom_champ; |
|
| 530 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | + include_spip('public/normaliser'); |
|
| 533 | + } |
|
| 534 | + phraser_vieux_emb($champ); |
|
| 535 | + } elseif ($nom == 'EXPOSER') { |
|
| 536 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | + include_spip('public/normaliser'); |
|
| 538 | + } |
|
| 539 | + phraser_vieux_exposer($champ); |
|
| 540 | + } elseif ($champ->param) { |
|
| 541 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | + include_spip('public/normaliser'); |
|
| 544 | + } |
|
| 545 | + phraser_vieux_recherche($champ); |
|
| 546 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | + include_spip('public/normaliser'); |
|
| 549 | + } |
|
| 550 | + phraser_vieux_logos($champ); |
|
| 551 | + } elseif ($nom == 'MODELE') { |
|
| 552 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | + include_spip('public/normaliser'); |
|
| 554 | + } |
|
| 555 | + phraser_vieux_modele($champ); |
|
| 556 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | + include_spip('public/normaliser'); |
|
| 559 | + } |
|
| 560 | + phraser_vieux_inclu($champ); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | |
@@ -587,200 +587,200 @@ discard block |
||
| 587 | 587 | **/ |
| 588 | 588 | function phraser_criteres($params, &$result) { |
| 589 | 589 | |
| 590 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | - $args = []; |
|
| 592 | - $type = $result->type_requete; |
|
| 593 | - $doublons = []; |
|
| 594 | - foreach ($params as $v) { |
|
| 595 | - $var = $v[1][0]; |
|
| 596 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | - // plus d'un argument et pas le critere IN: |
|
| 599 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | - if ( |
|
| 601 | - $var->type != 'texte' |
|
| 602 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | - ) { |
|
| 604 | - $op = ','; |
|
| 605 | - $not = ''; |
|
| 606 | - $cond = false; |
|
| 607 | - } else { |
|
| 608 | - // Le debut du premier argument est l'operateur |
|
| 609 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | - $op = $m[2]; |
|
| 611 | - $not = $m[1]; |
|
| 612 | - $cond = $m[3]; |
|
| 613 | - // virer le premier argument, |
|
| 614 | - // et mettre son reliquat eventuel |
|
| 615 | - // Recopier pour ne pas alterer le texte source |
|
| 616 | - // utile au debusqueur |
|
| 617 | - if ($m[4]) { |
|
| 618 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | - $c = null; |
|
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 622 | - if (isset($c)) { |
|
| 623 | - $m[4] = $c; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - $texte = new Texte(); |
|
| 627 | - $texte->texte = $m[4]; |
|
| 628 | - $v[1][0] = $texte; |
|
| 629 | - } else { |
|
| 630 | - array_shift($v[1]); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - array_shift($v); // $v[O] est vide |
|
| 634 | - $crit = new Critere(); |
|
| 635 | - $crit->op = $op; |
|
| 636 | - $crit->not = $not; |
|
| 637 | - $crit->cond = $cond; |
|
| 638 | - $crit->exclus = ''; |
|
| 639 | - $crit->param = $v; |
|
| 640 | - $args[] = $crit; |
|
| 641 | - } else { |
|
| 642 | - if ($var->type != 'texte') { |
|
| 643 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | - // erreur ou critere infixe "/" |
|
| 645 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | - $err_ci = [ |
|
| 647 | - 'zbug_critere_inconnu', |
|
| 648 | - ['critere' => $var->nom_champ] |
|
| 649 | - ]; |
|
| 650 | - erreur_squelette($err_ci, $result); |
|
| 651 | - } else { |
|
| 652 | - $crit = new Critere(); |
|
| 653 | - $crit->op = '/'; |
|
| 654 | - $crit->not = ''; |
|
| 655 | - $crit->exclus = ''; |
|
| 656 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | - $args[] = $crit; |
|
| 658 | - } |
|
| 659 | - } else { |
|
| 660 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | - // les separateurs |
|
| 662 | - if ($var->apres) { |
|
| 663 | - $result->separateur[] = $param; |
|
| 664 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | - $result->modificateur['tout'] = true; |
|
| 666 | - } elseif ($param == 'plat') { |
|
| 667 | - $result->modificateur['plat'] = true; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | - // ceux-ci pour avoir la rubrique mere... |
|
| 673 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | - // traités normalement. |
|
| 675 | - elseif ( |
|
| 676 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | - ) { |
|
| 680 | - $result->modificateur['tout'] = true; |
|
| 681 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | - // rien a faire sur {id_rubrique} tout seul |
|
| 683 | - } else { |
|
| 684 | - // pas d'emplacement statique, faut un dynamique |
|
| 685 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | - // cette variable sera inseree dans le code |
|
| 688 | - // et son nom sert d'indicateur des maintenant |
|
| 689 | - $result->doublons = '$doublons_index'; |
|
| 690 | - if ($param == 'unique') { |
|
| 691 | - $param = 'doublons'; |
|
| 692 | - } |
|
| 693 | - } elseif ($param == 'recherche') { |
|
| 694 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | - $result->hash = ' '; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | - } elseif ( |
|
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | - ) { |
|
| 704 | - $a2 = trim($m[8]); |
|
| 705 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | - $a2 = substr($a2, 1, -1); |
|
| 707 | - } |
|
| 708 | - $crit = phraser_critere_infixe( |
|
| 709 | - $m[2], |
|
| 710 | - $a2, |
|
| 711 | - $v, |
|
| 712 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | - $m[6], |
|
| 714 | - $m[5] |
|
| 715 | - ); |
|
| 716 | - $crit->exclus = $m[1]; |
|
| 717 | - } elseif ( |
|
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 720 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | - ) { |
|
| 722 | - // contient aussi les comparaisons implicites ! |
|
| 723 | - // Comme ci-dessus: |
|
| 724 | - // le premier arg contient l'operateur |
|
| 725 | - array_shift($v); |
|
| 726 | - if ($m[6]) { |
|
| 727 | - $v[0][0] = new Texte(); |
|
| 728 | - $v[0][0]->texte = $m[6]; |
|
| 729 | - } else { |
|
| 730 | - array_shift($v[0]); |
|
| 731 | - if (!$v[0]) { |
|
| 732 | - array_shift($v); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - $crit = new Critere(); |
|
| 736 | - $crit->op = $m[2]; |
|
| 737 | - $crit->param = $v; |
|
| 738 | - $crit->not = $m[1]; |
|
| 739 | - $crit->cond = $m[5]; |
|
| 740 | - } else { |
|
| 741 | - $err_ci = [ |
|
| 742 | - 'zbug_critere_inconnu', |
|
| 743 | - ['critere' => $param] |
|
| 744 | - ]; |
|
| 745 | - erreur_squelette($err_ci, $result); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | - $args[] = $crit; |
|
| 750 | - } else { |
|
| 751 | - $doublons[] = $crit; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // les doublons non nies doivent etre le dernier critere |
|
| 759 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | - // cf critere_doublon |
|
| 761 | - if ($doublons) { |
|
| 762 | - $args = [...$args, ...$doublons]; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | - if (!$err_ci) { |
|
| 767 | - $result->criteres = $args; |
|
| 768 | - } |
|
| 590 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | + $args = []; |
|
| 592 | + $type = $result->type_requete; |
|
| 593 | + $doublons = []; |
|
| 594 | + foreach ($params as $v) { |
|
| 595 | + $var = $v[1][0]; |
|
| 596 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | + // plus d'un argument et pas le critere IN: |
|
| 599 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | + if ( |
|
| 601 | + $var->type != 'texte' |
|
| 602 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | + ) { |
|
| 604 | + $op = ','; |
|
| 605 | + $not = ''; |
|
| 606 | + $cond = false; |
|
| 607 | + } else { |
|
| 608 | + // Le debut du premier argument est l'operateur |
|
| 609 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | + $op = $m[2]; |
|
| 611 | + $not = $m[1]; |
|
| 612 | + $cond = $m[3]; |
|
| 613 | + // virer le premier argument, |
|
| 614 | + // et mettre son reliquat eventuel |
|
| 615 | + // Recopier pour ne pas alterer le texte source |
|
| 616 | + // utile au debusqueur |
|
| 617 | + if ($m[4]) { |
|
| 618 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | + $c = null; |
|
| 621 | + eval('$c = ' . $m[4] . ';'); |
|
| 622 | + if (isset($c)) { |
|
| 623 | + $m[4] = $c; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + $texte = new Texte(); |
|
| 627 | + $texte->texte = $m[4]; |
|
| 628 | + $v[1][0] = $texte; |
|
| 629 | + } else { |
|
| 630 | + array_shift($v[1]); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + array_shift($v); // $v[O] est vide |
|
| 634 | + $crit = new Critere(); |
|
| 635 | + $crit->op = $op; |
|
| 636 | + $crit->not = $not; |
|
| 637 | + $crit->cond = $cond; |
|
| 638 | + $crit->exclus = ''; |
|
| 639 | + $crit->param = $v; |
|
| 640 | + $args[] = $crit; |
|
| 641 | + } else { |
|
| 642 | + if ($var->type != 'texte') { |
|
| 643 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | + // erreur ou critere infixe "/" |
|
| 645 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | + $err_ci = [ |
|
| 647 | + 'zbug_critere_inconnu', |
|
| 648 | + ['critere' => $var->nom_champ] |
|
| 649 | + ]; |
|
| 650 | + erreur_squelette($err_ci, $result); |
|
| 651 | + } else { |
|
| 652 | + $crit = new Critere(); |
|
| 653 | + $crit->op = '/'; |
|
| 654 | + $crit->not = ''; |
|
| 655 | + $crit->exclus = ''; |
|
| 656 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | + $args[] = $crit; |
|
| 658 | + } |
|
| 659 | + } else { |
|
| 660 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | + // les separateurs |
|
| 662 | + if ($var->apres) { |
|
| 663 | + $result->separateur[] = $param; |
|
| 664 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | + $result->modificateur['tout'] = true; |
|
| 666 | + } elseif ($param == 'plat') { |
|
| 667 | + $result->modificateur['plat'] = true; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | + // ceux-ci pour avoir la rubrique mere... |
|
| 673 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | + // traités normalement. |
|
| 675 | + elseif ( |
|
| 676 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | + ) { |
|
| 680 | + $result->modificateur['tout'] = true; |
|
| 681 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | + // rien a faire sur {id_rubrique} tout seul |
|
| 683 | + } else { |
|
| 684 | + // pas d'emplacement statique, faut un dynamique |
|
| 685 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | + // cette variable sera inseree dans le code |
|
| 688 | + // et son nom sert d'indicateur des maintenant |
|
| 689 | + $result->doublons = '$doublons_index'; |
|
| 690 | + if ($param == 'unique') { |
|
| 691 | + $param = 'doublons'; |
|
| 692 | + } |
|
| 693 | + } elseif ($param == 'recherche') { |
|
| 694 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | + $result->hash = ' '; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | + } elseif ( |
|
| 701 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | + ) { |
|
| 704 | + $a2 = trim($m[8]); |
|
| 705 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | + $a2 = substr($a2, 1, -1); |
|
| 707 | + } |
|
| 708 | + $crit = phraser_critere_infixe( |
|
| 709 | + $m[2], |
|
| 710 | + $a2, |
|
| 711 | + $v, |
|
| 712 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | + $m[6], |
|
| 714 | + $m[5] |
|
| 715 | + ); |
|
| 716 | + $crit->exclus = $m[1]; |
|
| 717 | + } elseif ( |
|
| 718 | + preg_match('/^([!]?)\s*(' . |
|
| 719 | + CHAMP_SQL_PLUS_FONC . |
|
| 720 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | + ) { |
|
| 722 | + // contient aussi les comparaisons implicites ! |
|
| 723 | + // Comme ci-dessus: |
|
| 724 | + // le premier arg contient l'operateur |
|
| 725 | + array_shift($v); |
|
| 726 | + if ($m[6]) { |
|
| 727 | + $v[0][0] = new Texte(); |
|
| 728 | + $v[0][0]->texte = $m[6]; |
|
| 729 | + } else { |
|
| 730 | + array_shift($v[0]); |
|
| 731 | + if (!$v[0]) { |
|
| 732 | + array_shift($v); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + $crit = new Critere(); |
|
| 736 | + $crit->op = $m[2]; |
|
| 737 | + $crit->param = $v; |
|
| 738 | + $crit->not = $m[1]; |
|
| 739 | + $crit->cond = $m[5]; |
|
| 740 | + } else { |
|
| 741 | + $err_ci = [ |
|
| 742 | + 'zbug_critere_inconnu', |
|
| 743 | + ['critere' => $param] |
|
| 744 | + ]; |
|
| 745 | + erreur_squelette($err_ci, $result); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | + $args[] = $crit; |
|
| 750 | + } else { |
|
| 751 | + $doublons[] = $crit; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // les doublons non nies doivent etre le dernier critere |
|
| 759 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | + // cf critere_doublon |
|
| 761 | + if ($doublons) { |
|
| 762 | + $args = [...$args, ...$doublons]; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | + if (!$err_ci) { |
|
| 767 | + $result->criteres = $args; |
|
| 768 | + } |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 772 | - $args[0] = new Texte(); |
|
| 773 | - $args[0]->texte = $arg1; |
|
| 774 | - $args[0] = [$args[0]]; |
|
| 775 | - $args[1][0] = new Texte(); |
|
| 776 | - $args[1][0]->texte = $arg2; |
|
| 777 | - $crit = new Critere(); |
|
| 778 | - $crit->op = $op; |
|
| 779 | - $crit->not = $not; |
|
| 780 | - $crit->cond = $cond; |
|
| 781 | - $crit->param = $args; |
|
| 782 | - |
|
| 783 | - return $crit; |
|
| 772 | + $args[0] = new Texte(); |
|
| 773 | + $args[0]->texte = $arg1; |
|
| 774 | + $args[0] = [$args[0]]; |
|
| 775 | + $args[1][0] = new Texte(); |
|
| 776 | + $args[1][0]->texte = $arg2; |
|
| 777 | + $crit = new Critere(); |
|
| 778 | + $crit->op = $op; |
|
| 779 | + $crit->not = $not; |
|
| 780 | + $crit->cond = $cond; |
|
| 781 | + $crit->param = $args; |
|
| 782 | + |
|
| 783 | + return $crit; |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -791,12 +791,12 @@ discard block |
||
| 791 | 791 | * @return int |
| 792 | 792 | */ |
| 793 | 793 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 794 | - if (is_null($fin)) { |
|
| 795 | - return substr_count($texte, "\n", $debut); |
|
| 796 | - } |
|
| 797 | - else { |
|
| 798 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | - } |
|
| 794 | + if (is_null($fin)) { |
|
| 795 | + return substr_count($texte, "\n", $debut); |
|
| 796 | + } |
|
| 797 | + else { |
|
| 798 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | + } |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | |
@@ -812,87 +812,87 @@ discard block |
||
| 812 | 812 | * @return array|null |
| 813 | 813 | */ |
| 814 | 814 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 815 | - $premiere_boucle = null; |
|
| 816 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | - |
|
| 818 | - $current_pos = $pos_debut_texte; |
|
| 819 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | - $current_pos = $pos_boucle + 1; |
|
| 821 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | - |
|
| 823 | - $id_boucle = ''; |
|
| 824 | - if ($pos_parent !== false) { |
|
| 825 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | - } |
|
| 827 | - if ( |
|
| 828 | - $pos_parent === false |
|
| 829 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | - ) { |
|
| 831 | - $result = new Boucle(); |
|
| 832 | - $result->id_parent = $id_parent; |
|
| 833 | - $result->descr = $descr; |
|
| 834 | - |
|
| 835 | - // un id_boucle pour l'affichage de l'erreur |
|
| 836 | - if (!strlen($id_boucle)) { |
|
| 837 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | - } |
|
| 839 | - $result->id_boucle = $id_boucle; |
|
| 840 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | - erreur_squelette($err_b, $result); |
|
| 842 | - |
|
| 843 | - continue; |
|
| 844 | - } |
|
| 845 | - else { |
|
| 846 | - $boucle = [ |
|
| 847 | - 'id_boucle' => $id_boucle, |
|
| 848 | - 'id_boucle_err' => $id_boucle, |
|
| 849 | - 'debut_boucle' => $pos_boucle, |
|
| 850 | - 'pos_boucle' => $pos_boucle, |
|
| 851 | - 'pos_parent' => $pos_parent, |
|
| 852 | - 'pos_precond' => false, |
|
| 853 | - 'pos_precond_inside' => false, |
|
| 854 | - 'pos_preaff' => false, |
|
| 855 | - 'pos_preaff_inside' => false, |
|
| 856 | - ]; |
|
| 857 | - |
|
| 858 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | - if (!strlen($id_boucle)) { |
|
| 860 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | - if ( |
|
| 867 | - $pos_precond !== false |
|
| 868 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | - ) { |
|
| 870 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | - $boucle['pos_precond'] = $pos_precond; |
|
| 872 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | - if ( |
|
| 878 | - $pos_preaff !== false |
|
| 879 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | - ) { |
|
| 881 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | - } |
|
| 885 | - if (!strlen($id_boucle)) { |
|
| 886 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | - $premiere_boucle = $boucle; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $premiere_boucle; |
|
| 815 | + $premiere_boucle = null; |
|
| 816 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | + |
|
| 818 | + $current_pos = $pos_debut_texte; |
|
| 819 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | + $current_pos = $pos_boucle + 1; |
|
| 821 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | + |
|
| 823 | + $id_boucle = ''; |
|
| 824 | + if ($pos_parent !== false) { |
|
| 825 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | + } |
|
| 827 | + if ( |
|
| 828 | + $pos_parent === false |
|
| 829 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | + ) { |
|
| 831 | + $result = new Boucle(); |
|
| 832 | + $result->id_parent = $id_parent; |
|
| 833 | + $result->descr = $descr; |
|
| 834 | + |
|
| 835 | + // un id_boucle pour l'affichage de l'erreur |
|
| 836 | + if (!strlen($id_boucle)) { |
|
| 837 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | + } |
|
| 839 | + $result->id_boucle = $id_boucle; |
|
| 840 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | + erreur_squelette($err_b, $result); |
|
| 842 | + |
|
| 843 | + continue; |
|
| 844 | + } |
|
| 845 | + else { |
|
| 846 | + $boucle = [ |
|
| 847 | + 'id_boucle' => $id_boucle, |
|
| 848 | + 'id_boucle_err' => $id_boucle, |
|
| 849 | + 'debut_boucle' => $pos_boucle, |
|
| 850 | + 'pos_boucle' => $pos_boucle, |
|
| 851 | + 'pos_parent' => $pos_parent, |
|
| 852 | + 'pos_precond' => false, |
|
| 853 | + 'pos_precond_inside' => false, |
|
| 854 | + 'pos_preaff' => false, |
|
| 855 | + 'pos_preaff_inside' => false, |
|
| 856 | + ]; |
|
| 857 | + |
|
| 858 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | + if (!strlen($id_boucle)) { |
|
| 860 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | + if ( |
|
| 867 | + $pos_precond !== false |
|
| 868 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | + ) { |
|
| 870 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | + $boucle['pos_precond'] = $pos_precond; |
|
| 872 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | + if ( |
|
| 878 | + $pos_preaff !== false |
|
| 879 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | + ) { |
|
| 881 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | + } |
|
| 885 | + if (!strlen($id_boucle)) { |
|
| 886 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | + $premiere_boucle = $boucle; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $premiere_boucle; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -907,68 +907,68 @@ discard block |
||
| 907 | 907 | * @return mixed |
| 908 | 908 | */ |
| 909 | 909 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 910 | - $id_boucle = $boucle['id_boucle']; |
|
| 911 | - $pos_courante = $pos_debut_texte; |
|
| 912 | - |
|
| 913 | - $boucle['pos_postcond'] = false; |
|
| 914 | - $boucle['pos_postcond_inside'] = false; |
|
| 915 | - $boucle['pos_altern'] = false; |
|
| 916 | - $boucle['pos_altern_inside'] = false; |
|
| 917 | - $boucle['pos_postaff'] = false; |
|
| 918 | - $boucle['pos_postaff_inside'] = false; |
|
| 919 | - |
|
| 920 | - $pos_anonyme_next = null; |
|
| 921 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | - if (!strlen($id_boucle)) { |
|
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // |
|
| 927 | - // 1. Recuperer la partie conditionnelle apres |
|
| 928 | - // |
|
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | - if ( |
|
| 932 | - $pos_apres !== false |
|
| 933 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | - ) { |
|
| 935 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | - $pos_apres += strlen($apres_boucle); |
|
| 937 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | - $pos_courante = $pos_apres ; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // |
|
| 942 | - // 2. Récuperer la partie alternative apres |
|
| 943 | - // |
|
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | - if ( |
|
| 947 | - $pos_altern !== false |
|
| 948 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | - ) { |
|
| 950 | - $boucle['pos_altern'] = $pos_altern; |
|
| 951 | - $pos_altern += strlen($altern_boucle); |
|
| 952 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | - $pos_courante = $pos_altern; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // |
|
| 957 | - // 3. Recuperer la partie footer non alternative |
|
| 958 | - // |
|
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | - if ( |
|
| 962 | - $pos_postaff !== false |
|
| 963 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | - ) { |
|
| 965 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | - $pos_postaff += strlen($postaff_boucle); |
|
| 967 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | - $pos_courante = $pos_postaff ; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - return $boucle; |
|
| 910 | + $id_boucle = $boucle['id_boucle']; |
|
| 911 | + $pos_courante = $pos_debut_texte; |
|
| 912 | + |
|
| 913 | + $boucle['pos_postcond'] = false; |
|
| 914 | + $boucle['pos_postcond_inside'] = false; |
|
| 915 | + $boucle['pos_altern'] = false; |
|
| 916 | + $boucle['pos_altern_inside'] = false; |
|
| 917 | + $boucle['pos_postaff'] = false; |
|
| 918 | + $boucle['pos_postaff_inside'] = false; |
|
| 919 | + |
|
| 920 | + $pos_anonyme_next = null; |
|
| 921 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | + if (!strlen($id_boucle)) { |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // |
|
| 927 | + // 1. Recuperer la partie conditionnelle apres |
|
| 928 | + // |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | + if ( |
|
| 932 | + $pos_apres !== false |
|
| 933 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | + ) { |
|
| 935 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | + $pos_apres += strlen($apres_boucle); |
|
| 937 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | + $pos_courante = $pos_apres ; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // |
|
| 942 | + // 2. Récuperer la partie alternative apres |
|
| 943 | + // |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | + if ( |
|
| 947 | + $pos_altern !== false |
|
| 948 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | + ) { |
|
| 950 | + $boucle['pos_altern'] = $pos_altern; |
|
| 951 | + $pos_altern += strlen($altern_boucle); |
|
| 952 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | + $pos_courante = $pos_altern; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // |
|
| 957 | + // 3. Recuperer la partie footer non alternative |
|
| 958 | + // |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | + if ( |
|
| 962 | + $pos_postaff !== false |
|
| 963 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | + ) { |
|
| 965 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | + $pos_postaff += strlen($postaff_boucle); |
|
| 967 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | + $pos_courante = $pos_postaff ; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + return $boucle; |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | |
@@ -978,21 +978,21 @@ discard block |
||
| 978 | 978 | * @param null|object $boucle |
| 979 | 979 | */ |
| 980 | 980 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 981 | - static $boucles_connues = []; |
|
| 982 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | - } |
|
| 986 | - else { |
|
| 987 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | - $placeholder = $champ->nom_champ; |
|
| 989 | - $id = reset($champ->param[0][1]); |
|
| 990 | - $id = $id->texte; |
|
| 991 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 981 | + static $boucles_connues = []; |
|
| 982 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | + } |
|
| 986 | + else { |
|
| 987 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | + $placeholder = $champ->nom_champ; |
|
| 989 | + $id = reset($champ->param[0][1]); |
|
| 990 | + $id = $id->texte; |
|
| 991 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1005,274 +1005,274 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | - //memoriser la boucle a reinjecter |
|
| 1010 | - $id_boucle = "$id_boucle"; |
|
| 1011 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | - return $placeholder; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | + //memoriser la boucle a reinjecter |
|
| 1010 | + $id_boucle = "$id_boucle"; |
|
| 1011 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | + return $placeholder; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1016 | 1016 | |
| 1017 | - $all_res = []; |
|
| 1018 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | - if (is_null($boucle_placeholder)) { |
|
| 1020 | - do { |
|
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | - $pos_debut_texte = 0; |
|
| 1027 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | - $result = new Boucle(); |
|
| 1030 | - $result->id_parent = $id_parent; |
|
| 1031 | - $result->descr = $descr; |
|
| 1032 | - |
|
| 1033 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | - $pos_parent = $boucle['pos_parent']; |
|
| 1035 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | - |
|
| 1037 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | - |
|
| 1039 | - // boucle anonyme ? |
|
| 1040 | - if (!strlen($id_boucle)) { |
|
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - $pos_debut_boucle = $pos_courante; |
|
| 1045 | - |
|
| 1046 | - $pos_milieu = $pos_parent; |
|
| 1047 | - |
|
| 1048 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | - if ($boucle['pos_precond'] !== false) { |
|
| 1050 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | - |
|
| 1052 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | - $end_preaff = $pos_debut_boucle; |
|
| 1060 | - |
|
| 1061 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $result->id_boucle = $id_boucle; |
|
| 1067 | - |
|
| 1068 | - if ( |
|
| 1069 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | - or $pos_match > $pos_milieu |
|
| 1072 | - ) { |
|
| 1073 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | - erreur_squelette($err_b, $result); |
|
| 1075 | - |
|
| 1076 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | - continue; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $result->type_requete = $match[0]; |
|
| 1082 | - $pos_milieu += strlen($match[0]); |
|
| 1083 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | - |
|
| 1085 | - $type = $match[1]; |
|
| 1086 | - $jointures = trim($match[2]); |
|
| 1087 | - $table_optionnelle = ($match[3]); |
|
| 1088 | - if ($jointures) { |
|
| 1089 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | - // ou elles seront completees des jointures declarees |
|
| 1091 | - $result->jointures_explicites = $jointures; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if ($table_optionnelle) { |
|
| 1095 | - $result->table_optionnelle = $type; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | - // Resultat mis dans result->param |
|
| 1100 | - $pos_fin_criteres = $pos_milieu; |
|
| 1101 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | - |
|
| 1103 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | - // pour l'instant on met le source (chaine) : |
|
| 1105 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | - $pos_milieu = $pos_fin_criteres; |
|
| 1109 | - |
|
| 1110 | - // |
|
| 1111 | - // Recuperer la fin : |
|
| 1112 | - // |
|
| 1113 | - if ($texte[$pos_milieu] === '/') { |
|
| 1114 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | - $pos_courante += 2; |
|
| 1116 | - $result->milieu = ''; |
|
| 1117 | - } else { |
|
| 1118 | - $pos_milieu += 1; |
|
| 1119 | - |
|
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | - if ($pos_fin === false) { |
|
| 1123 | - $err_b = [ |
|
| 1124 | - 'zbug_erreur_boucle_fermant', |
|
| 1125 | - ['id' => $id_boucle] |
|
| 1126 | - ]; |
|
| 1127 | - erreur_squelette($err_b, $result); |
|
| 1128 | - $pos_courante += strlen($fin_boucle); |
|
| 1129 | - } |
|
| 1130 | - else { |
|
| 1131 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | - $search_from = $pos_milieu; |
|
| 1135 | - $nb_open = 1; |
|
| 1136 | - $nb_close = 1; |
|
| 1137 | - $maxiter = 0; |
|
| 1138 | - do { |
|
| 1139 | - while ( |
|
| 1140 | - $nb_close < $nb_open |
|
| 1141 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | - ) { |
|
| 1143 | - $nb_close++; |
|
| 1144 | - $pos_fin = $p; |
|
| 1145 | - } |
|
| 1146 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | - if ($nb_close < $nb_open) { |
|
| 1148 | - break; |
|
| 1149 | - } |
|
| 1150 | - while ( |
|
| 1151 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | - and $p < $pos_fin |
|
| 1153 | - ) { |
|
| 1154 | - $nb_open++; |
|
| 1155 | - $search_from = $p + 1; |
|
| 1156 | - } |
|
| 1157 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | - |
|
| 1159 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | - } |
|
| 1161 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | - |
|
| 1167 | - // |
|
| 1168 | - // 1. Partie conditionnelle apres ? |
|
| 1169 | - // |
|
| 1170 | - if ($boucle['pos_postcond']) { |
|
| 1171 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - // |
|
| 1178 | - // 2. Partie alternative apres ? |
|
| 1179 | - // |
|
| 1180 | - $ligne_altern = $ligne_suite; |
|
| 1181 | - if ($boucle['pos_altern']) { |
|
| 1182 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // |
|
| 1188 | - // 3. Partie footer non alternative ? |
|
| 1189 | - // |
|
| 1190 | - $ligne_postaff = $ligne_suite; |
|
| 1191 | - if ($boucle['pos_postaff']) { |
|
| 1192 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $result->ligne = $ligne_preaff; |
|
| 1198 | - |
|
| 1199 | - if ($p = strpos($type, ':')) { |
|
| 1200 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | - $type = substr($type, $p + 1); |
|
| 1202 | - } |
|
| 1203 | - $soustype = strtolower($type); |
|
| 1204 | - |
|
| 1205 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | - $soustype = $type; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $result->type_requete = $soustype; |
|
| 1210 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | - if (!is_array($result->param)) { |
|
| 1212 | - $err_b = true; |
|
| 1213 | - } else { |
|
| 1214 | - phraser_criteres($result->param, $result); |
|
| 1215 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | - $args = $result->param; |
|
| 1218 | - array_unshift( |
|
| 1219 | - $args, |
|
| 1220 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | - ); |
|
| 1222 | - $result->param = $args; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | - if (empty($boucles[$id_boucle])) { |
|
| 1232 | - $boucles[$id_boucle] = null; |
|
| 1233 | - } |
|
| 1234 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | - |
|
| 1240 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | - if ($err_b) { |
|
| 1242 | - $result->type_requete = false; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - // Verifier qu'il n'y a pas double definition |
|
| 1246 | - // apres analyse des sous-parties (pas avant). |
|
| 1247 | - if (!empty($boucles[$id_boucle])) { |
|
| 1248 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | - $err_b_d = [ |
|
| 1250 | - 'zbug_erreur_boucle_double', |
|
| 1251 | - ['id' => $id_boucle] |
|
| 1252 | - ]; |
|
| 1253 | - erreur_squelette($err_b_d, $result); |
|
| 1254 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | - } |
|
| 1257 | - } else { |
|
| 1258 | - $boucles[$id_boucle] = $result; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | - |
|
| 1267 | - // phraser la partie avant le debut de la boucle |
|
| 1268 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | - |
|
| 1271 | - $ligne_debut_texte = $ligne_suite; |
|
| 1272 | - $pos_debut_texte = $pos_courante; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | - |
|
| 1277 | - return $all_res; |
|
| 1017 | + $all_res = []; |
|
| 1018 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | + if (is_null($boucle_placeholder)) { |
|
| 1020 | + do { |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | + $pos_debut_texte = 0; |
|
| 1027 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | + $result = new Boucle(); |
|
| 1030 | + $result->id_parent = $id_parent; |
|
| 1031 | + $result->descr = $descr; |
|
| 1032 | + |
|
| 1033 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | + $pos_parent = $boucle['pos_parent']; |
|
| 1035 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | + |
|
| 1037 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | + |
|
| 1039 | + // boucle anonyme ? |
|
| 1040 | + if (!strlen($id_boucle)) { |
|
| 1041 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + $pos_debut_boucle = $pos_courante; |
|
| 1045 | + |
|
| 1046 | + $pos_milieu = $pos_parent; |
|
| 1047 | + |
|
| 1048 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | + if ($boucle['pos_precond'] !== false) { |
|
| 1050 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | + |
|
| 1052 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | + $end_preaff = $pos_debut_boucle; |
|
| 1060 | + |
|
| 1061 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $result->id_boucle = $id_boucle; |
|
| 1067 | + |
|
| 1068 | + if ( |
|
| 1069 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | + or $pos_match > $pos_milieu |
|
| 1072 | + ) { |
|
| 1073 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | + erreur_squelette($err_b, $result); |
|
| 1075 | + |
|
| 1076 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | + continue; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $result->type_requete = $match[0]; |
|
| 1082 | + $pos_milieu += strlen($match[0]); |
|
| 1083 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | + |
|
| 1085 | + $type = $match[1]; |
|
| 1086 | + $jointures = trim($match[2]); |
|
| 1087 | + $table_optionnelle = ($match[3]); |
|
| 1088 | + if ($jointures) { |
|
| 1089 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | + // ou elles seront completees des jointures declarees |
|
| 1091 | + $result->jointures_explicites = $jointures; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if ($table_optionnelle) { |
|
| 1095 | + $result->table_optionnelle = $type; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | + // Resultat mis dans result->param |
|
| 1100 | + $pos_fin_criteres = $pos_milieu; |
|
| 1101 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | + |
|
| 1103 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | + // pour l'instant on met le source (chaine) : |
|
| 1105 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | + $pos_milieu = $pos_fin_criteres; |
|
| 1109 | + |
|
| 1110 | + // |
|
| 1111 | + // Recuperer la fin : |
|
| 1112 | + // |
|
| 1113 | + if ($texte[$pos_milieu] === '/') { |
|
| 1114 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | + $pos_courante += 2; |
|
| 1116 | + $result->milieu = ''; |
|
| 1117 | + } else { |
|
| 1118 | + $pos_milieu += 1; |
|
| 1119 | + |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | + if ($pos_fin === false) { |
|
| 1123 | + $err_b = [ |
|
| 1124 | + 'zbug_erreur_boucle_fermant', |
|
| 1125 | + ['id' => $id_boucle] |
|
| 1126 | + ]; |
|
| 1127 | + erreur_squelette($err_b, $result); |
|
| 1128 | + $pos_courante += strlen($fin_boucle); |
|
| 1129 | + } |
|
| 1130 | + else { |
|
| 1131 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | + $search_from = $pos_milieu; |
|
| 1135 | + $nb_open = 1; |
|
| 1136 | + $nb_close = 1; |
|
| 1137 | + $maxiter = 0; |
|
| 1138 | + do { |
|
| 1139 | + while ( |
|
| 1140 | + $nb_close < $nb_open |
|
| 1141 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | + ) { |
|
| 1143 | + $nb_close++; |
|
| 1144 | + $pos_fin = $p; |
|
| 1145 | + } |
|
| 1146 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | + if ($nb_close < $nb_open) { |
|
| 1148 | + break; |
|
| 1149 | + } |
|
| 1150 | + while ( |
|
| 1151 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | + and $p < $pos_fin |
|
| 1153 | + ) { |
|
| 1154 | + $nb_open++; |
|
| 1155 | + $search_from = $p + 1; |
|
| 1156 | + } |
|
| 1157 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | + |
|
| 1159 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | + } |
|
| 1161 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | + |
|
| 1167 | + // |
|
| 1168 | + // 1. Partie conditionnelle apres ? |
|
| 1169 | + // |
|
| 1170 | + if ($boucle['pos_postcond']) { |
|
| 1171 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + // |
|
| 1178 | + // 2. Partie alternative apres ? |
|
| 1179 | + // |
|
| 1180 | + $ligne_altern = $ligne_suite; |
|
| 1181 | + if ($boucle['pos_altern']) { |
|
| 1182 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // |
|
| 1188 | + // 3. Partie footer non alternative ? |
|
| 1189 | + // |
|
| 1190 | + $ligne_postaff = $ligne_suite; |
|
| 1191 | + if ($boucle['pos_postaff']) { |
|
| 1192 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $result->ligne = $ligne_preaff; |
|
| 1198 | + |
|
| 1199 | + if ($p = strpos($type, ':')) { |
|
| 1200 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | + $type = substr($type, $p + 1); |
|
| 1202 | + } |
|
| 1203 | + $soustype = strtolower($type); |
|
| 1204 | + |
|
| 1205 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | + $soustype = $type; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $result->type_requete = $soustype; |
|
| 1210 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | + if (!is_array($result->param)) { |
|
| 1212 | + $err_b = true; |
|
| 1213 | + } else { |
|
| 1214 | + phraser_criteres($result->param, $result); |
|
| 1215 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | + $args = $result->param; |
|
| 1218 | + array_unshift( |
|
| 1219 | + $args, |
|
| 1220 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | + ); |
|
| 1222 | + $result->param = $args; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | + if (empty($boucles[$id_boucle])) { |
|
| 1232 | + $boucles[$id_boucle] = null; |
|
| 1233 | + } |
|
| 1234 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | + |
|
| 1240 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | + if ($err_b) { |
|
| 1242 | + $result->type_requete = false; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + // Verifier qu'il n'y a pas double definition |
|
| 1246 | + // apres analyse des sous-parties (pas avant). |
|
| 1247 | + if (!empty($boucles[$id_boucle])) { |
|
| 1248 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | + $err_b_d = [ |
|
| 1250 | + 'zbug_erreur_boucle_double', |
|
| 1251 | + ['id' => $id_boucle] |
|
| 1252 | + ]; |
|
| 1253 | + erreur_squelette($err_b_d, $result); |
|
| 1254 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | + } |
|
| 1257 | + } else { |
|
| 1258 | + $boucles[$id_boucle] = $result; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | + |
|
| 1267 | + // phraser la partie avant le debut de la boucle |
|
| 1268 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | + |
|
| 1271 | + $ligne_debut_texte = $ligne_suite; |
|
| 1272 | + $pos_debut_texte = $pos_courante; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | + |
|
| 1277 | + return $all_res; |
|
| 1278 | 1278 | } |
@@ -11,96 +11,96 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('auth/ldap'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_ldap4_dist() { |
| 20 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | - $login_ldap = _request('login_ldap'); |
|
| 22 | - $pass_ldap = _request('pass_ldap'); |
|
| 23 | - $port_ldap = _request('port_ldap'); |
|
| 24 | - $base_ldap = _request('base_ldap'); |
|
| 25 | - $base_ldap_text = _request('base_ldap_text'); |
|
| 26 | - if (!$base_ldap) { |
|
| 27 | - $base_ldap = $base_ldap_text; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 31 | - |
|
| 32 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 33 | - @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 34 | - |
|
| 35 | - // Essayer de verifier le chemin fourni |
|
| 36 | - $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 37 | - $fail = (ldap_errno($ldap_link) == 32); |
|
| 38 | - |
|
| 39 | - if ($fail) { |
|
| 40 | - echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 41 | - info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 42 | - "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 43 | - ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 44 | - } else { |
|
| 45 | - info_etape(_T('info_reglage_ldap')); |
|
| 46 | - echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 47 | - |
|
| 48 | - $statuts = liste_statuts_ldap(); |
|
| 49 | - $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 50 | - ? _INSTALL_STATUT_LDAP |
|
| 51 | - : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 55 | - . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 56 | - . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 57 | - . fieldset( |
|
| 58 | - _T('info_statut_utilisateurs_1'), |
|
| 59 | - [ |
|
| 60 | - 'statut_ldap' => [ |
|
| 61 | - 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 62 | - 'valeur' => $statut_ldap, |
|
| 63 | - 'alternatives' => $statuts |
|
| 64 | - ] |
|
| 65 | - ] |
|
| 66 | - ) |
|
| 67 | - . install_ldap_correspondances() |
|
| 68 | - . bouton_suivant(); |
|
| 69 | - |
|
| 70 | - echo generer_form_ecrire('install', $res); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - echo install_fin_html(); |
|
| 20 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | + $login_ldap = _request('login_ldap'); |
|
| 22 | + $pass_ldap = _request('pass_ldap'); |
|
| 23 | + $port_ldap = _request('port_ldap'); |
|
| 24 | + $base_ldap = _request('base_ldap'); |
|
| 25 | + $base_ldap_text = _request('base_ldap_text'); |
|
| 26 | + if (!$base_ldap) { |
|
| 27 | + $base_ldap = $base_ldap_text; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 31 | + |
|
| 32 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 33 | + @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 34 | + |
|
| 35 | + // Essayer de verifier le chemin fourni |
|
| 36 | + $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 37 | + $fail = (ldap_errno($ldap_link) == 32); |
|
| 38 | + |
|
| 39 | + if ($fail) { |
|
| 40 | + echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 41 | + info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 42 | + "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 43 | + ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 44 | + } else { |
|
| 45 | + info_etape(_T('info_reglage_ldap')); |
|
| 46 | + echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 47 | + |
|
| 48 | + $statuts = liste_statuts_ldap(); |
|
| 49 | + $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 50 | + ? _INSTALL_STATUT_LDAP |
|
| 51 | + : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 55 | + . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 56 | + . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 57 | + . fieldset( |
|
| 58 | + _T('info_statut_utilisateurs_1'), |
|
| 59 | + [ |
|
| 60 | + 'statut_ldap' => [ |
|
| 61 | + 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 62 | + 'valeur' => $statut_ldap, |
|
| 63 | + 'alternatives' => $statuts |
|
| 64 | + ] |
|
| 65 | + ] |
|
| 66 | + ) |
|
| 67 | + . install_ldap_correspondances() |
|
| 68 | + . bouton_suivant(); |
|
| 69 | + |
|
| 70 | + echo generer_form_ecrire('install', $res); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + echo install_fin_html(); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | function liste_statuts_ldap() { |
| 77 | - $recom = [ |
|
| 78 | - 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 79 | - 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 80 | - 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 81 | - ]; |
|
| 82 | - |
|
| 83 | - $res = []; |
|
| 84 | - foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 85 | - if (isset($recom[$k])) { |
|
| 86 | - $res[$v] = $recom[$k]; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $res; |
|
| 77 | + $recom = [ |
|
| 78 | + 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 79 | + 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 80 | + 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 81 | + ]; |
|
| 82 | + |
|
| 83 | + $res = []; |
|
| 84 | + foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 85 | + if (isset($recom[$k])) { |
|
| 86 | + $res[$v] = $recom[$k]; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $res; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | function install_ldap_correspondances() { |
| 94 | - $champs = []; |
|
| 95 | - foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 96 | - $nom = 'ldap_' . $champ; |
|
| 97 | - $val = is_array($v) ? join(',', $v) : strval($v); |
|
| 98 | - $champs[$nom] = [ |
|
| 99 | - 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 100 | - 'valeur' => $val |
|
| 101 | - ]; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return !$champs ? |
|
| 105 | - '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />'); |
|
| 94 | + $champs = []; |
|
| 95 | + foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 96 | + $nom = 'ldap_' . $champ; |
|
| 97 | + $val = is_array($v) ? join(',', $v) : strval($v); |
|
| 98 | + $champs[$nom] = [ |
|
| 99 | + 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 100 | + 'valeur' => $val |
|
| 101 | + ]; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return !$champs ? |
|
| 105 | + '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />'); |
|
| 106 | 106 | } |