@@ -1,4 +1,4 @@ |
||
| 1 | 1 | <?php |
| 2 | - # appel SPIP |
|
| 3 | - include ('spip.php'); |
|
| 2 | + # appel SPIP |
|
| 3 | + include ('spip.php'); |
|
| 4 | 4 | ?> |
@@ -16,107 +16,107 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | function decompiler_boucle($struct, $fmt='', $prof=0) |
| 18 | 18 | { |
| 19 | - $nom = $struct->id_boucle; |
|
| 20 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 21 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 22 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 23 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 24 | - |
|
| 25 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 26 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 27 | - $struct->table_optionnelle); |
|
| 28 | - |
|
| 29 | - if ($struct->jointures_explicites) |
|
| 30 | - $type .= " " . $struct->jointures_explicites; |
|
| 31 | - if ($struct->table_optionnelle) |
|
| 32 | - $type .= "?"; |
|
| 33 | - // Revoir le cas de la boucle recursive |
|
| 34 | - |
|
| 35 | - $crit = $struct->param; |
|
| 36 | - if ($crit AND !is_array($crit[0])) { |
|
| 37 | - $type = strtolower($type) . array_shift($crit); |
|
| 38 | - } |
|
| 39 | - $crit = decompiler_criteres($struct, $fmt, $prof) ; |
|
| 40 | - |
|
| 41 | - $f = 'format_boucle_' . $fmt; |
|
| 42 | - return $f($avant, $nom, $type, $crit, $milieu, $apres, $altern, $prof); |
|
| 19 | + $nom = $struct->id_boucle; |
|
| 20 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 21 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 22 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 23 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 24 | + |
|
| 25 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 26 | + $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 27 | + $struct->table_optionnelle); |
|
| 28 | + |
|
| 29 | + if ($struct->jointures_explicites) |
|
| 30 | + $type .= " " . $struct->jointures_explicites; |
|
| 31 | + if ($struct->table_optionnelle) |
|
| 32 | + $type .= "?"; |
|
| 33 | + // Revoir le cas de la boucle recursive |
|
| 34 | + |
|
| 35 | + $crit = $struct->param; |
|
| 36 | + if ($crit AND !is_array($crit[0])) { |
|
| 37 | + $type = strtolower($type) . array_shift($crit); |
|
| 38 | + } |
|
| 39 | + $crit = decompiler_criteres($struct, $fmt, $prof) ; |
|
| 40 | + |
|
| 41 | + $f = 'format_boucle_' . $fmt; |
|
| 42 | + return $f($avant, $nom, $type, $crit, $milieu, $apres, $altern, $prof); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function decompiler_include($struct, $fmt='', $prof=0) |
| 46 | 46 | { |
| 47 | - $res = array(); |
|
| 48 | - foreach($struct->param ? $struct->param : array() as $couple) { |
|
| 49 | - array_shift($couple); |
|
| 50 | - foreach($couple as $v) { |
|
| 51 | - $res[]= decompiler_($v, $fmt, $prof); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 55 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 56 | - $f = 'format_inclure_' . $fmt; |
|
| 57 | - return $f($file, $res, $prof); |
|
| 47 | + $res = array(); |
|
| 48 | + foreach($struct->param ? $struct->param : array() as $couple) { |
|
| 49 | + array_shift($couple); |
|
| 50 | + foreach($couple as $v) { |
|
| 51 | + $res[]= decompiler_($v, $fmt, $prof); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 55 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 56 | + $f = 'format_inclure_' . $fmt; |
|
| 57 | + return $f($file, $res, $prof); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | function decompiler_texte($struct, $fmt='', $prof=0) |
| 61 | 61 | { |
| 62 | - $f = 'format_texte_' . $fmt; |
|
| 63 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 62 | + $f = 'format_texte_' . $fmt; |
|
| 63 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function decompiler_polyglotte($struct, $fmt='', $prof=0) |
| 67 | 67 | { |
| 68 | - $f = 'format_polyglotte_' . $fmt; |
|
| 69 | - return $f($struct->traductions, $prof); |
|
| 68 | + $f = 'format_polyglotte_' . $fmt; |
|
| 69 | + return $f($struct->traductions, $prof); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function decompiler_idiome($struct, $fmt='', $prof=0) |
| 73 | 73 | { |
| 74 | - $args = array(); |
|
| 75 | - foreach ($struct->arg as $k => $v) { |
|
| 76 | - $args[$k]= public_decompiler($v, $fmt, $prof); |
|
| 77 | - } |
|
| 74 | + $args = array(); |
|
| 75 | + foreach ($struct->arg as $k => $v) { |
|
| 76 | + $args[$k]= public_decompiler($v, $fmt, $prof); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 79 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 80 | 80 | |
| 81 | - $f = 'format_idiome_' . $fmt; |
|
| 82 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 81 | + $f = 'format_idiome_' . $fmt; |
|
| 82 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | function decompiler_champ($struct, $fmt='', $prof=0) |
| 86 | 86 | { |
| 87 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 88 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 89 | - $args = $filtres = ''; |
|
| 90 | - if ($p = $struct->param) { |
|
| 91 | - if ($p[0][0]==='') |
|
| 92 | - $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 93 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 94 | - } |
|
| 95 | - $f = 'format_champ_' . $fmt; |
|
| 96 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 87 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 88 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 89 | + $args = $filtres = ''; |
|
| 90 | + if ($p = $struct->param) { |
|
| 91 | + if ($p[0][0]==='') |
|
| 92 | + $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 93 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 94 | + } |
|
| 95 | + $f = 'format_champ_' . $fmt; |
|
| 96 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | function decompiler_liste($sources, $fmt='', $prof=0) { |
| 100 | - if (!is_array($sources)) return ''; |
|
| 101 | - $f = 'format_liste_' . $fmt; |
|
| 102 | - $res = ''; |
|
| 103 | - foreach($sources as $arg) { |
|
| 104 | - if (!is_array($arg)) { |
|
| 105 | - continue; // ne devrait pas arriver. |
|
| 106 | - } else {$r = array_shift($arg);} |
|
| 107 | - $args = array(); |
|
| 108 | - foreach($arg as $v) { |
|
| 109 | - // cas des arguments entoures de ' ou " |
|
| 110 | - if ((count($v) == 1) |
|
| 111 | - AND $v[0]->type=='texte' |
|
| 112 | - AND (strlen($v[0]->apres) == 1) |
|
| 113 | - AND $v[0]->apres == $v[0]->avant) |
|
| 114 | - $args[]= $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 115 | - else $args[]= decompiler_($v, $fmt, 0-$prof); |
|
| 116 | - } |
|
| 117 | - if (($r!=='') OR $args) $res .= $f($r, $args, $prof); |
|
| 118 | - } |
|
| 119 | - return $res; |
|
| 100 | + if (!is_array($sources)) return ''; |
|
| 101 | + $f = 'format_liste_' . $fmt; |
|
| 102 | + $res = ''; |
|
| 103 | + foreach($sources as $arg) { |
|
| 104 | + if (!is_array($arg)) { |
|
| 105 | + continue; // ne devrait pas arriver. |
|
| 106 | + } else {$r = array_shift($arg);} |
|
| 107 | + $args = array(); |
|
| 108 | + foreach($arg as $v) { |
|
| 109 | + // cas des arguments entoures de ' ou " |
|
| 110 | + if ((count($v) == 1) |
|
| 111 | + AND $v[0]->type=='texte' |
|
| 112 | + AND (strlen($v[0]->apres) == 1) |
|
| 113 | + AND $v[0]->apres == $v[0]->avant) |
|
| 114 | + $args[]= $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 115 | + else $args[]= decompiler_($v, $fmt, 0-$prof); |
|
| 116 | + } |
|
| 117 | + if (($r!=='') OR $args) $res .= $f($r, $args, $prof); |
|
| 118 | + } |
|
| 119 | + return $res; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Decompilation des criteres: on triche et on deroge: |
@@ -124,76 +124,76 @@ discard block |
||
| 124 | 124 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 125 | 125 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 126 | 126 | function decompiler_criteres($boucle, $fmt='', $prof=0) { |
| 127 | - $sources = $boucle->param; |
|
| 128 | - if (!is_array($sources)) return ''; |
|
| 129 | - $res = ''; |
|
| 130 | - $f = 'format_critere_' . $fmt; |
|
| 131 | - foreach($sources as $crit) { |
|
| 132 | - if (!is_array($crit)) continue; // boucle recursive |
|
| 133 | - array_shift($crit); |
|
| 134 | - $args = array(); |
|
| 135 | - foreach($crit as $i => $v) { |
|
| 136 | - if ((count($v) == 1) |
|
| 137 | - AND $v[0]->type=='texte' |
|
| 138 | - AND $v[0]->apres) |
|
| 139 | - $args[]= array(array('texte', ( $v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 140 | - else { |
|
| 141 | - $res2 = array(); |
|
| 142 | - foreach($v as $k => $p) { |
|
| 143 | - if (isset($p->type) |
|
| 144 | - AND function_exists($d = 'decompiler_' . $p->type)) { |
|
| 145 | - $r = $d($p, $fmt, (0-$prof), @$v[$k+1]); |
|
| 146 | - $res2[]= array($p->type, $r); |
|
| 147 | - } else spip_log("critere $i / $k mal forme"); |
|
| 148 | - } |
|
| 149 | - $args[]= $res2; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $res .= $f($args); |
|
| 153 | - } |
|
| 154 | - return $res; |
|
| 127 | + $sources = $boucle->param; |
|
| 128 | + if (!is_array($sources)) return ''; |
|
| 129 | + $res = ''; |
|
| 130 | + $f = 'format_critere_' . $fmt; |
|
| 131 | + foreach($sources as $crit) { |
|
| 132 | + if (!is_array($crit)) continue; // boucle recursive |
|
| 133 | + array_shift($crit); |
|
| 134 | + $args = array(); |
|
| 135 | + foreach($crit as $i => $v) { |
|
| 136 | + if ((count($v) == 1) |
|
| 137 | + AND $v[0]->type=='texte' |
|
| 138 | + AND $v[0]->apres) |
|
| 139 | + $args[]= array(array('texte', ( $v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 140 | + else { |
|
| 141 | + $res2 = array(); |
|
| 142 | + foreach($v as $k => $p) { |
|
| 143 | + if (isset($p->type) |
|
| 144 | + AND function_exists($d = 'decompiler_' . $p->type)) { |
|
| 145 | + $r = $d($p, $fmt, (0-$prof), @$v[$k+1]); |
|
| 146 | + $res2[]= array($p->type, $r); |
|
| 147 | + } else spip_log("critere $i / $k mal forme"); |
|
| 148 | + } |
|
| 149 | + $args[]= $res2; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $res .= $f($args); |
|
| 153 | + } |
|
| 154 | + return $res; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | function decompiler_($liste, $fmt='', $prof=0) |
| 159 | 159 | { |
| 160 | - if (!is_array($liste)) return ''; |
|
| 161 | - $prof2 = ($prof < 0) ? ($prof-1) : ($prof+1); |
|
| 162 | - $contenu = array(); |
|
| 163 | - foreach($liste as $k => $p) { |
|
| 164 | - if (!isset($p->type)) continue; #?????? |
|
| 165 | - $d = 'decompiler_' . $p->type; |
|
| 166 | - $next = isset($liste[$k+1]) ? $liste[$k+1] : false; |
|
| 167 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 168 | - // contenait des args et s'il est suivi d'espaces, |
|
| 169 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 170 | - |
|
| 171 | - if ($next |
|
| 172 | - AND ($next->type == 'texte') |
|
| 173 | - AND $p->type == 'champ' |
|
| 174 | - AND !$p->apres |
|
| 175 | - AND !$p->avant |
|
| 176 | - AND $p->fonctions) { |
|
| 177 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 178 | - if ($n) { |
|
| 179 | - $champ = new Texte; |
|
| 180 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 181 | - $champ->ligne = $p->ligne; |
|
| 182 | - $p->apres = array($champ); |
|
| 183 | - $next->texte = substr($next->texte, $n); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - $f = 'format_suite_' . $fmt; |
|
| 190 | - return $f($contenu); |
|
| 160 | + if (!is_array($liste)) return ''; |
|
| 161 | + $prof2 = ($prof < 0) ? ($prof-1) : ($prof+1); |
|
| 162 | + $contenu = array(); |
|
| 163 | + foreach($liste as $k => $p) { |
|
| 164 | + if (!isset($p->type)) continue; #?????? |
|
| 165 | + $d = 'decompiler_' . $p->type; |
|
| 166 | + $next = isset($liste[$k+1]) ? $liste[$k+1] : false; |
|
| 167 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 168 | + // contenait des args et s'il est suivi d'espaces, |
|
| 169 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 170 | + |
|
| 171 | + if ($next |
|
| 172 | + AND ($next->type == 'texte') |
|
| 173 | + AND $p->type == 'champ' |
|
| 174 | + AND !$p->apres |
|
| 175 | + AND !$p->avant |
|
| 176 | + AND $p->fonctions) { |
|
| 177 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 178 | + if ($n) { |
|
| 179 | + $champ = new Texte; |
|
| 180 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 181 | + $champ->ligne = $p->ligne; |
|
| 182 | + $p->apres = array($champ); |
|
| 183 | + $next->texte = substr($next->texte, $n); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + $f = 'format_suite_' . $fmt; |
|
| 190 | + return $f($contenu); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | function public_decompiler($liste, $fmt='', $prof=0, $quoi='') |
| 194 | 194 | { |
| 195 | - if (!include_spip('public/format_' . $fmt)) return "'$fmt'?"; |
|
| 196 | - $f = 'decompiler_' . $quoi; |
|
| 197 | - return $f($liste, $fmt, $prof); |
|
| 195 | + if (!include_spip('public/format_' . $fmt)) return "'$fmt'?"; |
|
| 196 | + $f = 'decompiler_' . $quoi; |
|
| 197 | + return $f($liste, $fmt, $prof); |
|
| 198 | 198 | } |
| 199 | 199 | ?> |
@@ -31,70 +31,70 @@ |
||
| 31 | 31 | // Cas d'une page contenant du PHP : |
| 32 | 32 | if ($page['process_ins'] != 'html') { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Teste si on a déjà évalué du PHP |
|
| 36 | - * |
|
| 37 | - * Inclure inc/lang la première fois pour définir spip_lang |
|
| 38 | - * si ça n'a pas encore été fait. |
|
| 39 | - */ |
|
| 40 | - if (!defined('_EVALUER_PAGE_PHP')) { |
|
| 41 | - define('_EVALUER_PAGE_PHP', true); |
|
| 42 | - include_spip('inc/lang'); |
|
| 43 | - } |
|
| 34 | + /** |
|
| 35 | + * Teste si on a déjà évalué du PHP |
|
| 36 | + * |
|
| 37 | + * Inclure inc/lang la première fois pour définir spip_lang |
|
| 38 | + * si ça n'a pas encore été fait. |
|
| 39 | + */ |
|
| 40 | + if (!defined('_EVALUER_PAGE_PHP')) { |
|
| 41 | + define('_EVALUER_PAGE_PHP', true); |
|
| 42 | + include_spip('inc/lang'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // restaurer l'etat des notes avant calcul |
|
| 46 | - if (isset($page['notes']) |
|
| 47 | - AND $page['notes'] |
|
| 48 | - AND $notes = charger_fonction("notes","inc",true)){ |
|
| 49 | - $notes($page['notes'],'restaurer_etat'); |
|
| 50 | - } |
|
| 51 | - ob_start(); |
|
| 52 | - if (strpos($page['texte'],'?xml')!==false) |
|
| 53 | - $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']); |
|
| 45 | + // restaurer l'etat des notes avant calcul |
|
| 46 | + if (isset($page['notes']) |
|
| 47 | + AND $page['notes'] |
|
| 48 | + AND $notes = charger_fonction("notes","inc",true)){ |
|
| 49 | + $notes($page['notes'],'restaurer_etat'); |
|
| 50 | + } |
|
| 51 | + ob_start(); |
|
| 52 | + if (strpos($page['texte'],'?xml')!==false) |
|
| 53 | + $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']); |
|
| 54 | 54 | |
| 55 | - try { |
|
| 56 | - $res = eval('?' . '>' . $page['texte']); |
|
| 57 | - // error catching 5.2<=PHP<7 |
|
| 58 | - if ($res === false |
|
| 59 | - and function_exists('error_get_last') |
|
| 60 | - and ($erreur = error_get_last()) ) { |
|
| 61 | - $code = $page['texte']; |
|
| 62 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 63 | - if (!function_exists('numerote_ligne_php')){ |
|
| 64 | - function numerote_ligne_php($match){ |
|
| 65 | - $GLOBALS['numero_ligne_php']++; |
|
| 66 | - return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/"; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code); |
|
| 70 | - $code = trim(highlight_string($code,true)); |
|
| 71 | - erreur_squelette("L".$erreur['line'].": ".$erreur['message']."<br />".$code,array($page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang'])); |
|
| 72 | - $page['texte'] = "<!-- Erreur -->"; |
|
| 73 | - } |
|
| 74 | - else { |
|
| 75 | - $page['texte'] = ob_get_contents(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - catch (Exception $e){ |
|
| 79 | - $code = $page['texte']; |
|
| 80 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 81 | - if (!function_exists('numerote_ligne_php')){ |
|
| 82 | - function numerote_ligne_php($match){ |
|
| 83 | - $GLOBALS['numero_ligne_php']++; |
|
| 84 | - return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/"; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code); |
|
| 88 | - $code = trim(highlight_string($code,true)); |
|
| 89 | - erreur_squelette("L".$e->getLine().": ".$e->getMessage()."<br />".$code,array($page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang'])); |
|
| 90 | - $page['texte'] = "<!-- Erreur -->"; |
|
| 91 | - } |
|
| 92 | - ob_end_clean(); |
|
| 55 | + try { |
|
| 56 | + $res = eval('?' . '>' . $page['texte']); |
|
| 57 | + // error catching 5.2<=PHP<7 |
|
| 58 | + if ($res === false |
|
| 59 | + and function_exists('error_get_last') |
|
| 60 | + and ($erreur = error_get_last()) ) { |
|
| 61 | + $code = $page['texte']; |
|
| 62 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 63 | + if (!function_exists('numerote_ligne_php')){ |
|
| 64 | + function numerote_ligne_php($match){ |
|
| 65 | + $GLOBALS['numero_ligne_php']++; |
|
| 66 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/"; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code); |
|
| 70 | + $code = trim(highlight_string($code,true)); |
|
| 71 | + erreur_squelette("L".$erreur['line'].": ".$erreur['message']."<br />".$code,array($page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang'])); |
|
| 72 | + $page['texte'] = "<!-- Erreur -->"; |
|
| 73 | + } |
|
| 74 | + else { |
|
| 75 | + $page['texte'] = ob_get_contents(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + catch (Exception $e){ |
|
| 79 | + $code = $page['texte']; |
|
| 80 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 81 | + if (!function_exists('numerote_ligne_php')){ |
|
| 82 | + function numerote_ligne_php($match){ |
|
| 83 | + $GLOBALS['numero_ligne_php']++; |
|
| 84 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/"; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code); |
|
| 88 | + $code = trim(highlight_string($code,true)); |
|
| 89 | + erreur_squelette("L".$e->getLine().": ".$e->getMessage()."<br />".$code,array($page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang'])); |
|
| 90 | + $page['texte'] = "<!-- Erreur -->"; |
|
| 91 | + } |
|
| 92 | + ob_end_clean(); |
|
| 93 | 93 | |
| 94 | - $page['process_ins'] = 'html'; |
|
| 94 | + $page['process_ins'] = 'html'; |
|
| 95 | 95 | |
| 96 | - if (strpos($page['texte'],'?xml')!==false) |
|
| 97 | - $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']); |
|
| 96 | + if (strpos($page['texte'],'?xml')!==false) |
|
| 97 | + $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | page_base_href($page['texte']); |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function index_boucle($p){ |
| 31 | 31 | |
| 32 | - $idb = $p->id_boucle; |
|
| 33 | - $explicite = $p->nom_boucle; |
|
| 32 | + $idb = $p->id_boucle; |
|
| 33 | + $explicite = $p->nom_boucle; |
|
| 34 | 34 | |
| 35 | - if (strlen($explicite)) { |
|
| 36 | - // Recherche d'un champ dans un etage superieur |
|
| 37 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 38 | - $idb = $p->boucles[$idb]->id_parent; |
|
| 39 | - } |
|
| 40 | - } |
|
| 35 | + if (strlen($explicite)) { |
|
| 36 | + // Recherche d'un champ dans un etage superieur |
|
| 37 | + while (($idb !== $explicite) && ($idb !=='')) { |
|
| 38 | + $idb = $p->boucles[$idb]->id_parent; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $idb; |
|
| 42 | + return $idb; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -65,52 +65,52 @@ discard block |
||
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | 67 | function index_pile($idb, $nom_champ, &$boucles, $explicite='', $defaut=null, $remonte_pile=true) { |
| 68 | - if (!is_string($defaut)) |
|
| 69 | - $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 70 | - |
|
| 71 | - $i = 0; |
|
| 72 | - if (strlen($explicite)) { |
|
| 73 | - // Recherche d'un champ dans un etage superieur |
|
| 74 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 75 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 76 | - $i++; |
|
| 77 | - $idb = $boucles[$idb]->id_parent; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 82 | - $nom_champ = strtolower($nom_champ); |
|
| 83 | - $conditionnel = array(); |
|
| 84 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 85 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 86 | - while (isset($boucles[$idb])) { |
|
| 87 | - $joker = true; |
|
| 88 | - list ($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 89 | - if ($t) { |
|
| 90 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 91 | - $boucles[$idb]->select[] = $t; |
|
| 92 | - } |
|
| 93 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 94 | - if (!$joker) |
|
| 95 | - return index_compose($conditionnel,$champ); |
|
| 96 | - |
|
| 97 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($remonte_pile){ |
|
| 101 | - # spip_log("On remonte vers $i"); |
|
| 102 | - // Sinon on remonte d'un cran |
|
| 103 | - $idb = $boucles[$idb]->id_parent; |
|
| 104 | - $i++; |
|
| 105 | - } |
|
| 106 | - else |
|
| 107 | - $idb = null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - # spip_log("Pas vu $nom_champ"); |
|
| 111 | - // esperons qu'il y sera |
|
| 112 | - // on qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 113 | - return index_compose($conditionnel,$defaut); |
|
| 68 | + if (!is_string($defaut)) |
|
| 69 | + $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 70 | + |
|
| 71 | + $i = 0; |
|
| 72 | + if (strlen($explicite)) { |
|
| 73 | + // Recherche d'un champ dans un etage superieur |
|
| 74 | + while (($idb !== $explicite) && ($idb !=='')) { |
|
| 75 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 76 | + $i++; |
|
| 77 | + $idb = $boucles[$idb]->id_parent; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 82 | + $nom_champ = strtolower($nom_champ); |
|
| 83 | + $conditionnel = array(); |
|
| 84 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 85 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 86 | + while (isset($boucles[$idb])) { |
|
| 87 | + $joker = true; |
|
| 88 | + list ($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 89 | + if ($t) { |
|
| 90 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 91 | + $boucles[$idb]->select[] = $t; |
|
| 92 | + } |
|
| 93 | + $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 94 | + if (!$joker) |
|
| 95 | + return index_compose($conditionnel,$champ); |
|
| 96 | + |
|
| 97 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($remonte_pile){ |
|
| 101 | + # spip_log("On remonte vers $i"); |
|
| 102 | + // Sinon on remonte d'un cran |
|
| 103 | + $idb = $boucles[$idb]->id_parent; |
|
| 104 | + $i++; |
|
| 105 | + } |
|
| 106 | + else |
|
| 107 | + $idb = null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + # spip_log("Pas vu $nom_champ"); |
|
| 111 | + // esperons qu'il y sera |
|
| 112 | + // on qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 113 | + return index_compose($conditionnel,$defaut); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -123,59 +123,59 @@ discard block |
||
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | 125 | function index_compose($conditionnel,$defaut){ |
| 126 | - while ($c = array_pop($conditionnel)) |
|
| 127 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 128 | - $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
|
| 129 | - return $defaut; |
|
| 126 | + while ($c = array_pop($conditionnel)) |
|
| 127 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 128 | + $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
|
| 129 | + return $defaut; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // http://doc.spip.org/@index_tables_en_pile |
| 133 | 133 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 134 | - global $exceptions_des_tables; |
|
| 135 | - |
|
| 136 | - $r = $boucles[$idb]->type_requete; |
|
| 137 | - |
|
| 138 | - if ($r == 'boucle') return array(); |
|
| 139 | - if (!$r) { |
|
| 140 | - $joker = false; // indiquer a l'appelant |
|
| 141 | - # continuer pour chercher l'erreur suivante |
|
| 142 | - return array("'#" . $r . ':' . $nom_champ . "'",''); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $desc = $boucles[$idb]->show; |
|
| 146 | - $excep = isset($exceptions_des_tables[$r]) ? $exceptions_des_tables[$r] : ''; |
|
| 147 | - if ($excep) |
|
| 148 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 149 | - if ($excep) { |
|
| 150 | - $joker = false; // indiquer a l'appelant |
|
| 151 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 152 | - } |
|
| 153 | - else { |
|
| 154 | - if (isset($desc['field'][$nom_champ])) { |
|
| 155 | - $t = $boucles[$idb]->id_table; |
|
| 156 | - $joker = false; // indiquer a l'appelant |
|
| 157 | - return array("$t.$nom_champ", $nom_champ); |
|
| 158 | - } |
|
| 159 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 160 | - elseif (/*$joker AND */isset($desc['field']['*'])) { |
|
| 161 | - $joker = true; // indiquer a l'appelant |
|
| 162 | - return array($nom_champ, $nom_champ); |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $joker = false; // indiquer a l'appelant |
|
| 166 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 167 | - $t = trouver_champ_exterieur($nom_champ, |
|
| 168 | - $boucles[$idb]->jointures, |
|
| 169 | - $boucles[$idb]); |
|
| 170 | - if ($t) |
|
| 171 | - return index_exception($boucles[$idb], |
|
| 172 | - $desc, |
|
| 173 | - $nom_champ, |
|
| 174 | - array($t[1]['id_table'], $nom_champ)); |
|
| 175 | - } |
|
| 176 | - return array('',''); |
|
| 177 | - } |
|
| 178 | - } |
|
| 134 | + global $exceptions_des_tables; |
|
| 135 | + |
|
| 136 | + $r = $boucles[$idb]->type_requete; |
|
| 137 | + |
|
| 138 | + if ($r == 'boucle') return array(); |
|
| 139 | + if (!$r) { |
|
| 140 | + $joker = false; // indiquer a l'appelant |
|
| 141 | + # continuer pour chercher l'erreur suivante |
|
| 142 | + return array("'#" . $r . ':' . $nom_champ . "'",''); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $desc = $boucles[$idb]->show; |
|
| 146 | + $excep = isset($exceptions_des_tables[$r]) ? $exceptions_des_tables[$r] : ''; |
|
| 147 | + if ($excep) |
|
| 148 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 149 | + if ($excep) { |
|
| 150 | + $joker = false; // indiquer a l'appelant |
|
| 151 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 152 | + } |
|
| 153 | + else { |
|
| 154 | + if (isset($desc['field'][$nom_champ])) { |
|
| 155 | + $t = $boucles[$idb]->id_table; |
|
| 156 | + $joker = false; // indiquer a l'appelant |
|
| 157 | + return array("$t.$nom_champ", $nom_champ); |
|
| 158 | + } |
|
| 159 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 160 | + elseif (/*$joker AND */isset($desc['field']['*'])) { |
|
| 161 | + $joker = true; // indiquer a l'appelant |
|
| 162 | + return array($nom_champ, $nom_champ); |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $joker = false; // indiquer a l'appelant |
|
| 166 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 167 | + $t = trouver_champ_exterieur($nom_champ, |
|
| 168 | + $boucles[$idb]->jointures, |
|
| 169 | + $boucles[$idb]); |
|
| 170 | + if ($t) |
|
| 171 | + return index_exception($boucles[$idb], |
|
| 172 | + $desc, |
|
| 173 | + $nom_champ, |
|
| 174 | + array($t[1]['id_table'], $nom_champ)); |
|
| 175 | + } |
|
| 176 | + return array('',''); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Reference a une entite SPIP alias d'un champ SQL |
@@ -185,44 +185,44 @@ discard block |
||
| 185 | 185 | // http://doc.spip.org/@index_exception |
| 186 | 186 | function index_exception(&$boucle, $desc, $nom_champ, $excep) |
| 187 | 187 | { |
| 188 | - static $trouver_table; |
|
| 189 | - if (!$trouver_table) |
|
| 190 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 191 | - |
|
| 192 | - if (is_array($excep)) { |
|
| 193 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 194 | - $t = NULL; |
|
| 195 | - if (count($excep)==3){ |
|
| 196 | - $index_exception_derogatoire = array_pop($excep); |
|
| 197 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 198 | - } |
|
| 199 | - if ($t == NULL) { |
|
| 200 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 202 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 203 | - if (!$j) return array('',''); |
|
| 204 | - $e = $j['table']; |
|
| 205 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 206 | - $k = $j['key']['PRIMARY KEY']; |
|
| 207 | - if (strpos($k,',')) { |
|
| 208 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 209 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 210 | - if (!in_array($k, $l)) { |
|
| 211 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 212 | - return array('',''); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - $k = array($boucle->id_table, array($e), $k); |
|
| 216 | - fabrique_jointures($boucle, array($k)); |
|
| 217 | - $t = array_search($e, $boucle->from); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - else $t = $boucle->id_table; |
|
| 222 | - // demander a SQL de gerer le synonyme |
|
| 223 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 224 | - if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 225 | - return array("$t.$excep", $nom_champ); |
|
| 188 | + static $trouver_table; |
|
| 189 | + if (!$trouver_table) |
|
| 190 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 191 | + |
|
| 192 | + if (is_array($excep)) { |
|
| 193 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 194 | + $t = NULL; |
|
| 195 | + if (count($excep)==3){ |
|
| 196 | + $index_exception_derogatoire = array_pop($excep); |
|
| 197 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 198 | + } |
|
| 199 | + if ($t == NULL) { |
|
| 200 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 202 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 203 | + if (!$j) return array('',''); |
|
| 204 | + $e = $j['table']; |
|
| 205 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 206 | + $k = $j['key']['PRIMARY KEY']; |
|
| 207 | + if (strpos($k,',')) { |
|
| 208 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 209 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 210 | + if (!in_array($k, $l)) { |
|
| 211 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 212 | + return array('',''); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + $k = array($boucle->id_table, array($e), $k); |
|
| 216 | + fabrique_jointures($boucle, array($k)); |
|
| 217 | + $t = array_search($e, $boucle->from); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + else $t = $boucle->id_table; |
|
| 222 | + // demander a SQL de gerer le synonyme |
|
| 223 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 224 | + if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 225 | + return array("$t.$excep", $nom_champ); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 244 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 244 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // cette fonction sert d'API pour demander une balise Spip avec filtres |
| 248 | 248 | |
| 249 | 249 | // http://doc.spip.org/@calculer_champ |
| 250 | 250 | function calculer_champ($p) { |
| 251 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 252 | - return applique_filtres($p); |
|
| 251 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 252 | + return applique_filtres($p); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // Cette fonction sert d'API pour demander une balise SPIP sans filtres. |
@@ -264,57 +264,57 @@ discard block |
||
| 264 | 264 | // http://doc.spip.org/@calculer_balise |
| 265 | 265 | function calculer_balise($nom, $p) { |
| 266 | 266 | |
| 267 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 268 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 269 | - $p->balise_calculee = true; |
|
| 270 | - $res = $f($p); |
|
| 271 | - if ($res !== NULL) |
|
| 272 | - return $res; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Certaines des balises comportant un _ sont generiques |
|
| 276 | - if ($f = strpos($nom, '_') |
|
| 277 | - AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
|
| 278 | - $res = $f($p); |
|
| 279 | - if ($res !== NULL) |
|
| 280 | - return $res; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 284 | - |
|
| 285 | - return $f($nom, $p); |
|
| 267 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 268 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 269 | + $p->balise_calculee = true; |
|
| 270 | + $res = $f($p); |
|
| 271 | + if ($res !== NULL) |
|
| 272 | + return $res; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Certaines des balises comportant un _ sont generiques |
|
| 276 | + if ($f = strpos($nom, '_') |
|
| 277 | + AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
|
| 278 | + $res = $f($p); |
|
| 279 | + if ($res !== NULL) |
|
| 280 | + return $res; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 284 | + |
|
| 285 | + return $f($nom, $p); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 289 | 289 | |
| 290 | - // ca pourrait etre un champ SQL homonyme, |
|
| 291 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 292 | - |
|
| 293 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 294 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 295 | - if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 296 | - $code = addslashes($p->fonctions[0][1]); |
|
| 297 | - $p->code .= " . '$code'"; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 301 | - if (strpos($nom, 'ID_') === 0) |
|
| 302 | - $p->interdire_scripts = false; |
|
| 303 | - |
|
| 304 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 305 | - // SI le champ SQL n'est pas trouve |
|
| 306 | - // ET si la balise a une forme de couleur |
|
| 307 | - // ET s'il n'y a ni filtre ni etoile |
|
| 308 | - // ALORS retourner la couleur. |
|
| 309 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 310 | - if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 311 | - AND !$p->etoile |
|
| 312 | - AND !$p->fonctions) { |
|
| 313 | - $p->code = "'#$nom'"; |
|
| 314 | - $p->interdire_scripts = false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return $p; |
|
| 290 | + // ca pourrait etre un champ SQL homonyme, |
|
| 291 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 292 | + |
|
| 293 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 294 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 295 | + if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 296 | + $code = addslashes($p->fonctions[0][1]); |
|
| 297 | + $p->code .= " . '$code'"; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 301 | + if (strpos($nom, 'ID_') === 0) |
|
| 302 | + $p->interdire_scripts = false; |
|
| 303 | + |
|
| 304 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 305 | + // SI le champ SQL n'est pas trouve |
|
| 306 | + // ET si la balise a une forme de couleur |
|
| 307 | + // ET s'il n'y a ni filtre ni etoile |
|
| 308 | + // ALORS retourner la couleur. |
|
| 309 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 310 | + if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 311 | + AND !$p->etoile |
|
| 312 | + AND !$p->fonctions) { |
|
| 313 | + $p->code = "'#$nom'"; |
|
| 314 | + $p->interdire_scripts = false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return $p; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -334,32 +334,32 @@ discard block |
||
| 334 | 334 | // http://doc.spip.org/@calculer_balise_dynamique |
| 335 | 335 | function calculer_balise_dynamique($p, $nom, $l, $supp=array()) { |
| 336 | 336 | |
| 337 | - if (!balise_distante_interdite($p)) { |
|
| 338 | - $p->code = "''"; |
|
| 339 | - return $p; |
|
| 340 | - } |
|
| 341 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 342 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 343 | - if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 344 | - $p->fonctions = null; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - if ($p->param AND ($c = $p->param[0])) { |
|
| 348 | - // liste d'arguments commence toujours par la chaine vide |
|
| 349 | - array_shift($c); |
|
| 350 | - // construire la liste d'arguments comme pour un filtre |
|
| 351 | - $param = compose_filtres_args($p, $c, ','); |
|
| 352 | - } else $param = ""; |
|
| 353 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 354 | - |
|
| 355 | - $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 356 | - join(',', $collecte), |
|
| 357 | - ($collecte ? $param : substr($param,1)), # virer la virgule |
|
| 358 | - memoriser_contexte_compil($p), |
|
| 359 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 360 | - |
|
| 361 | - $p->interdire_scripts = false; |
|
| 362 | - return $p; |
|
| 337 | + if (!balise_distante_interdite($p)) { |
|
| 338 | + $p->code = "''"; |
|
| 339 | + return $p; |
|
| 340 | + } |
|
| 341 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 342 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 343 | + if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 344 | + $p->fonctions = null; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + if ($p->param AND ($c = $p->param[0])) { |
|
| 348 | + // liste d'arguments commence toujours par la chaine vide |
|
| 349 | + array_shift($c); |
|
| 350 | + // construire la liste d'arguments comme pour un filtre |
|
| 351 | + $param = compose_filtres_args($p, $c, ','); |
|
| 352 | + } else $param = ""; |
|
| 353 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 354 | + |
|
| 355 | + $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 356 | + join(',', $collecte), |
|
| 357 | + ($collecte ? $param : substr($param,1)), # virer la virgule |
|
| 358 | + memoriser_contexte_compil($p), |
|
| 359 | + (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 360 | + |
|
| 361 | + $p->interdire_scripts = false; |
|
| 362 | + return $p; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // Construction du tableau des arguments d'une balise dynamique. |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | // http://doc.spip.org/@collecter_balise_dynamique |
| 372 | 372 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 373 | - $args = array(); |
|
| 374 | - foreach($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code;} |
|
| 375 | - return $args; |
|
| 373 | + $args = array(); |
|
| 374 | + foreach($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code;} |
|
| 375 | + return $args; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
@@ -389,17 +389,17 @@ discard block |
||
| 389 | 389 | * Nom de la connexion |
| 390 | 390 | **/ |
| 391 | 391 | function trouver_nom_serveur_distant($p) { |
| 392 | - $nom = $p->id_boucle; |
|
| 393 | - if ($nom |
|
| 394 | - AND isset($p->boucles[$nom])) { |
|
| 395 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 396 | - if (strlen($s) |
|
| 397 | - AND strlen($serveur = strtolower($s)) |
|
| 398 | - AND !in_array($serveur,$GLOBALS['exception_des_connect'])) { |
|
| 399 | - return $serveur; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - return ""; |
|
| 392 | + $nom = $p->id_boucle; |
|
| 393 | + if ($nom |
|
| 394 | + AND isset($p->boucles[$nom])) { |
|
| 395 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 396 | + if (strlen($s) |
|
| 397 | + AND strlen($serveur = strtolower($s)) |
|
| 398 | + AND !in_array($serveur,$GLOBALS['exception_des_connect'])) { |
|
| 399 | + return $serveur; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + return ""; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -422,13 +422,13 @@ discard block |
||
| 422 | 422 | * - false : La balise est interdite car le serveur est distant |
| 423 | 423 | **/ |
| 424 | 424 | function balise_distante_interdite($p) { |
| 425 | - $nom = $p->id_boucle; |
|
| 425 | + $nom = $p->id_boucle; |
|
| 426 | 426 | |
| 427 | - if ($nom AND trouver_nom_serveur_distant($p)) { |
|
| 428 | - spip_log( $nom .':' . $p->nom_champ .' '._T('zbug_distant_interdit')); |
|
| 429 | - return false; |
|
| 430 | - } |
|
| 431 | - return true; |
|
| 427 | + if ($nom AND trouver_nom_serveur_distant($p)) { |
|
| 428 | + spip_log( $nom .':' . $p->nom_champ .' '._T('zbug_distant_interdit')); |
|
| 429 | + return false; |
|
| 430 | + } |
|
| 431 | + return true; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -438,63 +438,63 @@ discard block |
||
| 438 | 438 | // |
| 439 | 439 | // http://doc.spip.org/@champs_traitements |
| 440 | 440 | function champs_traitements ($p) { |
| 441 | - global $table_des_traitements; |
|
| 442 | - |
|
| 443 | - if (isset($table_des_traitements[$p->nom_champ])) |
|
| 444 | - $ps = $table_des_traitements[$p->nom_champ]; |
|
| 445 | - else { |
|
| 446 | - // quand on utilise un traitement catch-all * |
|
| 447 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 448 | - // leur propre securite |
|
| 449 | - if (!$p->balise_calculee) |
|
| 450 | - $ps = $table_des_traitements['*']; |
|
| 451 | - else |
|
| 452 | - $ps = false; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if (is_array($ps)) { |
|
| 456 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 457 | - $idb = index_boucle($p); |
|
| 458 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 459 | - $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 460 | - $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
|
| 461 | - |
|
| 462 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 463 | - if ($table_sql AND isset($ps[$table_sql])) |
|
| 464 | - $ps = $ps[$table_sql]; |
|
| 465 | - // ou pour une boucle en particulier "DATA","articles" |
|
| 466 | - elseif ($type_requete AND isset($ps[$type_requete])) |
|
| 467 | - $ps = $ps[$type_requete]; |
|
| 468 | - // ou pour indiferrement quelle que soit la boucle |
|
| 469 | - elseif(isset($ps[0])) |
|
| 470 | - $ps = $ps[0]; |
|
| 471 | - else |
|
| 472 | - $ps=false; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - if (!$ps) return $p->code; |
|
| 476 | - |
|
| 477 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 478 | - // ou si in INCLURE contient {doublons} |
|
| 479 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 480 | - // dans les filtres propre() ou typo() |
|
| 481 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 482 | - |
|
| 483 | - if (isset($p->descr['documents']) |
|
| 484 | - AND |
|
| 485 | - $p->descr['documents'] |
|
| 486 | - AND ( |
|
| 487 | - (strpos($ps,'propre') !== false) |
|
| 488 | - OR |
|
| 489 | - (strpos($ps,'typo') !== false) |
|
| 490 | - )) |
|
| 491 | - $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 492 | - |
|
| 493 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 494 | - // dans la declaration des traitements des champs sensibles |
|
| 495 | - |
|
| 496 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 497 | - return str_replace('%s', $p->code, $ps); |
|
| 441 | + global $table_des_traitements; |
|
| 442 | + |
|
| 443 | + if (isset($table_des_traitements[$p->nom_champ])) |
|
| 444 | + $ps = $table_des_traitements[$p->nom_champ]; |
|
| 445 | + else { |
|
| 446 | + // quand on utilise un traitement catch-all * |
|
| 447 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 448 | + // leur propre securite |
|
| 449 | + if (!$p->balise_calculee) |
|
| 450 | + $ps = $table_des_traitements['*']; |
|
| 451 | + else |
|
| 452 | + $ps = false; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if (is_array($ps)) { |
|
| 456 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 457 | + $idb = index_boucle($p); |
|
| 458 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 459 | + $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 460 | + $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
|
| 461 | + |
|
| 462 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 463 | + if ($table_sql AND isset($ps[$table_sql])) |
|
| 464 | + $ps = $ps[$table_sql]; |
|
| 465 | + // ou pour une boucle en particulier "DATA","articles" |
|
| 466 | + elseif ($type_requete AND isset($ps[$type_requete])) |
|
| 467 | + $ps = $ps[$type_requete]; |
|
| 468 | + // ou pour indiferrement quelle que soit la boucle |
|
| 469 | + elseif(isset($ps[0])) |
|
| 470 | + $ps = $ps[0]; |
|
| 471 | + else |
|
| 472 | + $ps=false; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + if (!$ps) return $p->code; |
|
| 476 | + |
|
| 477 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 478 | + // ou si in INCLURE contient {doublons} |
|
| 479 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 480 | + // dans les filtres propre() ou typo() |
|
| 481 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 482 | + |
|
| 483 | + if (isset($p->descr['documents']) |
|
| 484 | + AND |
|
| 485 | + $p->descr['documents'] |
|
| 486 | + AND ( |
|
| 487 | + (strpos($ps,'propre') !== false) |
|
| 488 | + OR |
|
| 489 | + (strpos($ps,'typo') !== false) |
|
| 490 | + )) |
|
| 491 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 492 | + |
|
| 493 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 494 | + // dans la declaration des traitements des champs sensibles |
|
| 495 | + |
|
| 496 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 497 | + return str_replace('%s', $p->code, $ps); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -507,98 +507,98 @@ discard block |
||
| 507 | 507 | // http://doc.spip.org/@applique_filtres |
| 508 | 508 | function applique_filtres($p) { |
| 509 | 509 | |
| 510 | - // Traitements standards (cf. supra) |
|
| 511 | - if ($p->etoile == '') |
|
| 512 | - $code = champs_traitements($p); |
|
| 513 | - else |
|
| 514 | - $code = $p->code; |
|
| 510 | + // Traitements standards (cf. supra) |
|
| 511 | + if ($p->etoile == '') |
|
| 512 | + $code = champs_traitements($p); |
|
| 513 | + else |
|
| 514 | + $code = $p->code; |
|
| 515 | 515 | |
| 516 | - // Appliquer les filtres perso |
|
| 517 | - if ($p->param) |
|
| 518 | - $code = compose_filtres($p, $code); |
|
| 516 | + // Appliquer les filtres perso |
|
| 517 | + if ($p->param) |
|
| 518 | + $code = compose_filtres($p, $code); |
|
| 519 | 519 | |
| 520 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 521 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 522 | - if (isset($p->descr['session'])) |
|
| 523 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 520 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 521 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 522 | + if (isset($p->descr['session'])) |
|
| 523 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 524 | 524 | |
| 525 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 526 | - return $code; |
|
| 525 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 526 | + return $code; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 530 | 530 | // http://doc.spip.org/@compose_filtres |
| 531 | 531 | function compose_filtres(&$p, $code) { |
| 532 | 532 | |
| 533 | - $image_miette = false; |
|
| 534 | - foreach($p->param as $filtre) { |
|
| 535 | - $fonc = array_shift($filtre); |
|
| 536 | - if (!$fonc) continue; // normalement qu'au premier tour. |
|
| 537 | - $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
|
| 538 | - if ($image_miette AND !$is_filtre_image){ |
|
| 539 | - // il faut graver maintenant car apres le filtre en cours |
|
| 540 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 541 | - $code = "filtrer('image_graver', $code)"; |
|
| 542 | - $image_miette = false; |
|
| 543 | - } |
|
| 544 | - // recuperer les arguments du filtre, |
|
| 545 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 546 | - if ($fonc !== '?') { |
|
| 547 | - $sep = ','; |
|
| 548 | - } else {$sep = ':'; |
|
| 549 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 550 | - if (count($filtre) != 2) |
|
| 551 | - $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 552 | - } |
|
| 553 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 554 | - $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
|
| 555 | - if ($logique) |
|
| 556 | - $code = $logique; |
|
| 557 | - else { |
|
| 558 | - $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
|
| 559 | - if ($is_filtre_image) $image_miette = true; |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 563 | - if ($image_miette) |
|
| 564 | - $code = "filtrer('image_graver',$code)"; |
|
| 565 | - |
|
| 566 | - return $code; |
|
| 533 | + $image_miette = false; |
|
| 534 | + foreach($p->param as $filtre) { |
|
| 535 | + $fonc = array_shift($filtre); |
|
| 536 | + if (!$fonc) continue; // normalement qu'au premier tour. |
|
| 537 | + $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
|
| 538 | + if ($image_miette AND !$is_filtre_image){ |
|
| 539 | + // il faut graver maintenant car apres le filtre en cours |
|
| 540 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 541 | + $code = "filtrer('image_graver', $code)"; |
|
| 542 | + $image_miette = false; |
|
| 543 | + } |
|
| 544 | + // recuperer les arguments du filtre, |
|
| 545 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 546 | + if ($fonc !== '?') { |
|
| 547 | + $sep = ','; |
|
| 548 | + } else {$sep = ':'; |
|
| 549 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 550 | + if (count($filtre) != 2) |
|
| 551 | + $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 552 | + } |
|
| 553 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 554 | + $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
|
| 555 | + if ($logique) |
|
| 556 | + $code = $logique; |
|
| 557 | + else { |
|
| 558 | + $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
|
| 559 | + if ($is_filtre_image) $image_miette = true; |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 563 | + if ($image_miette) |
|
| 564 | + $code = "filtrer('image_graver',$code)"; |
|
| 565 | + |
|
| 566 | + return $code; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 570 | 570 | // et comparateurs |
| 571 | 571 | function filtre_logique($fonc, $code, $arg) |
| 572 | 572 | { |
| 573 | - global $table_criteres_infixes; |
|
| 574 | - switch (true) { |
|
| 575 | - case in_array($fonc, $table_criteres_infixes): |
|
| 576 | - return "($code $fonc $arg)"; |
|
| 577 | - case ($fonc == 'and') OR ($fonc == 'et'): |
|
| 578 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 579 | - case ($fonc == 'or') OR ($fonc == 'ou'): |
|
| 580 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 581 | - case ($fonc == 'xor') OR ($fonc == 'xou'): |
|
| 582 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 583 | - case ($fonc == 'sinon'): |
|
| 584 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 585 | - case ($fonc == 'not') OR ($fonc == 'non'): |
|
| 586 | - return "(($code) ?'' :' ')"; |
|
| 587 | - case ($fonc == 'yes') OR ($fonc == 'oui'): |
|
| 588 | - return "(($code) ?' ' :'')"; |
|
| 589 | - } |
|
| 590 | - return ''; |
|
| 573 | + global $table_criteres_infixes; |
|
| 574 | + switch (true) { |
|
| 575 | + case in_array($fonc, $table_criteres_infixes): |
|
| 576 | + return "($code $fonc $arg)"; |
|
| 577 | + case ($fonc == 'and') OR ($fonc == 'et'): |
|
| 578 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 579 | + case ($fonc == 'or') OR ($fonc == 'ou'): |
|
| 580 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 581 | + case ($fonc == 'xor') OR ($fonc == 'xou'): |
|
| 582 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 583 | + case ($fonc == 'sinon'): |
|
| 584 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 585 | + case ($fonc == 'not') OR ($fonc == 'non'): |
|
| 586 | + return "(($code) ?'' :' ')"; |
|
| 587 | + case ($fonc == 'yes') OR ($fonc == 'oui'): |
|
| 588 | + return "(($code) ?' ' :'')"; |
|
| 589 | + } |
|
| 590 | + return ''; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // http://doc.spip.org/@compose_filtres_args |
| 594 | 594 | function compose_filtres_args($p, $args, $sep) |
| 595 | 595 | { |
| 596 | - $arglist = ""; |
|
| 597 | - foreach ($args as $arg) { |
|
| 598 | - $arglist .= $sep . |
|
| 599 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 600 | - } |
|
| 601 | - return $arglist; |
|
| 596 | + $arglist = ""; |
|
| 597 | + foreach ($args as $arg) { |
|
| 598 | + $arglist .= $sep . |
|
| 599 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 600 | + } |
|
| 601 | + return $arglist; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | // |
@@ -609,15 +609,15 @@ discard block |
||
| 609 | 609 | // http://doc.spip.org/@calculer_argument_precedent |
| 610 | 610 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut=null) { |
| 611 | 611 | |
| 612 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 613 | - if ($boucles[$idb]->externe) { |
|
| 614 | - index_pile ($idb, $nom_champ, $boucles,'', $defaut); |
|
| 615 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 616 | - // on ignore le defaut fourni dans ce cas |
|
| 617 | - $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 618 | - } |
|
| 612 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 613 | + if ($boucles[$idb]->externe) { |
|
| 614 | + index_pile ($idb, $nom_champ, $boucles,'', $defaut); |
|
| 615 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 616 | + // on ignore le defaut fourni dans ce cas |
|
| 617 | + $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles,'', $defaut); |
|
| 620 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles,'', $defaut); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | // |
@@ -633,28 +633,28 @@ discard block |
||
| 633 | 633 | // http://doc.spip.org/@rindex_pile |
| 634 | 634 | function rindex_pile($p, $champ, $motif) |
| 635 | 635 | { |
| 636 | - $n = 0; |
|
| 637 | - $b = $p->id_boucle; |
|
| 638 | - $p->code = ''; |
|
| 639 | - while ($b != '') { |
|
| 640 | - foreach($p->boucles[$b]->criteres as $critere) { |
|
| 641 | - if ($critere->op == $motif) { |
|
| 642 | - $p->code = '$Pile[$SP' . (($n==0) ? "" : "-$n") . |
|
| 643 | - "]['$champ']"; |
|
| 644 | - $b = ''; |
|
| 645 | - break 2; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - $n++; |
|
| 649 | - $b = $p->boucles[$b]->id_parent; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 653 | - if (!$p->code) |
|
| 654 | - $p->code = "''"; |
|
| 655 | - |
|
| 656 | - $p->interdire_scripts = false; |
|
| 657 | - return $p; |
|
| 636 | + $n = 0; |
|
| 637 | + $b = $p->id_boucle; |
|
| 638 | + $p->code = ''; |
|
| 639 | + while ($b != '') { |
|
| 640 | + foreach($p->boucles[$b]->criteres as $critere) { |
|
| 641 | + if ($critere->op == $motif) { |
|
| 642 | + $p->code = '$Pile[$SP' . (($n==0) ? "" : "-$n") . |
|
| 643 | + "]['$champ']"; |
|
| 644 | + $b = ''; |
|
| 645 | + break 2; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + $n++; |
|
| 649 | + $b = $p->boucles[$b]->id_parent; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 653 | + if (!$p->code) |
|
| 654 | + $p->code = "''"; |
|
| 655 | + |
|
| 656 | + $p->interdire_scripts = false; |
|
| 657 | + return $p; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | ?> |
@@ -20,164 +20,164 @@ discard block |
||
| 20 | 20 | * @return array |
| 21 | 21 | */ |
| 22 | 22 | function public_styliser_par_z_dist($flux){ |
| 23 | - static $prefix_path=null; |
|
| 24 | - static $prefix_length; |
|
| 25 | - static $z_blocs; |
|
| 26 | - static $apl_constant; |
|
| 27 | - static $page; |
|
| 28 | - static $disponible = array(); |
|
| 29 | - static $echafauder; |
|
| 30 | - static $prepend = ""; |
|
| 23 | + static $prefix_path=null; |
|
| 24 | + static $prefix_length; |
|
| 25 | + static $z_blocs; |
|
| 26 | + static $apl_constant; |
|
| 27 | + static $page; |
|
| 28 | + static $disponible = array(); |
|
| 29 | + static $echafauder; |
|
| 30 | + static $prepend = ""; |
|
| 31 | 31 | |
| 32 | - if (!isset($prefix_path)) { |
|
| 33 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 34 | - if (test_espace_prive ()){ |
|
| 35 | - $prefix_path = "prive/squelettes/"; |
|
| 36 | - $prefix_length = strlen($prefix_path); |
|
| 37 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 38 | - $page = 'exec'; |
|
| 39 | - $echafauder = charger_fonction('echafauder','prive',true); |
|
| 40 | - define('_ZCORE_EXCLURE_PATH',''); |
|
| 41 | - } |
|
| 42 | - else { |
|
| 43 | - $prefix_path = ""; |
|
| 44 | - $prefix_length = 0; |
|
| 45 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 46 | - $page = _SPIP_PAGE; |
|
| 47 | - $echafauder = charger_fonction('echafauder','public',true); |
|
| 48 | - define('_ZCORE_EXCLURE_PATH','\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST')?'|\b'.rtrim(_DIR_PLUGIN_DIST,'/'):'')); |
|
| 49 | - } |
|
| 50 | - $prepend = (defined('_Z_PREPEND_PATH')?_Z_PREPEND_PATH:""); |
|
| 51 | - } |
|
| 52 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 32 | + if (!isset($prefix_path)) { |
|
| 33 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 34 | + if (test_espace_prive ()){ |
|
| 35 | + $prefix_path = "prive/squelettes/"; |
|
| 36 | + $prefix_length = strlen($prefix_path); |
|
| 37 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 38 | + $page = 'exec'; |
|
| 39 | + $echafauder = charger_fonction('echafauder','prive',true); |
|
| 40 | + define('_ZCORE_EXCLURE_PATH',''); |
|
| 41 | + } |
|
| 42 | + else { |
|
| 43 | + $prefix_path = ""; |
|
| 44 | + $prefix_length = 0; |
|
| 45 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 46 | + $page = _SPIP_PAGE; |
|
| 47 | + $echafauder = charger_fonction('echafauder','public',true); |
|
| 48 | + define('_ZCORE_EXCLURE_PATH','\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST')?'|\b'.rtrim(_DIR_PLUGIN_DIST,'/'):'')); |
|
| 49 | + } |
|
| 50 | + $prepend = (defined('_Z_PREPEND_PATH')?_Z_PREPEND_PATH:""); |
|
| 51 | + } |
|
| 52 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 53 | 53 | |
| 54 | - $fond = $flux['args']['fond']; |
|
| 54 | + $fond = $flux['args']['fond']; |
|
| 55 | 55 | |
| 56 | - if ($prepend OR strncmp($fond,$prefix_path,$prefix_length)==0) { |
|
| 57 | - $fond = substr($fond, $prefix_length); |
|
| 58 | - $squelette = $flux['data']; |
|
| 59 | - $ext = $flux['args']['ext']; |
|
| 60 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 61 | - if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 62 | - AND $dir = explode('/',$fond) |
|
| 63 | - AND count($dir)==2 // pas un sous repertoire |
|
| 64 | - AND $dir = reset($dir) |
|
| 65 | - AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 66 | - AND defined($apl_constant) |
|
| 67 | - AND in_array($dir,explode(',',constant($apl_constant))) // et dans un demande en APL |
|
| 68 | - AND $pipe = z_trouver_bloc($prefix_path.$prepend,$dir,'z_apl',$ext) // et qui contient le squelette APL |
|
| 69 | - ){ |
|
| 70 | - $flux['data'] = $pipe; |
|
| 71 | - return $flux; |
|
| 72 | - } |
|
| 56 | + if ($prepend OR strncmp($fond,$prefix_path,$prefix_length)==0) { |
|
| 57 | + $fond = substr($fond, $prefix_length); |
|
| 58 | + $squelette = $flux['data']; |
|
| 59 | + $ext = $flux['args']['ext']; |
|
| 60 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 61 | + if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 62 | + AND $dir = explode('/',$fond) |
|
| 63 | + AND count($dir)==2 // pas un sous repertoire |
|
| 64 | + AND $dir = reset($dir) |
|
| 65 | + AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 66 | + AND defined($apl_constant) |
|
| 67 | + AND in_array($dir,explode(',',constant($apl_constant))) // et dans un demande en APL |
|
| 68 | + AND $pipe = z_trouver_bloc($prefix_path.$prepend,$dir,'z_apl',$ext) // et qui contient le squelette APL |
|
| 69 | + ){ |
|
| 70 | + $flux['data'] = $pipe; |
|
| 71 | + return $flux; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 75 | - if ($squelette AND !z_fond_valide($squelette)){ |
|
| 76 | - $squelette = ""; |
|
| 77 | - $echafauder = ""; |
|
| 78 | - } |
|
| 79 | - if ($prepend){ |
|
| 80 | - $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
|
| 81 | - if ($squelette) |
|
| 82 | - $flux['data'] = $squelette; |
|
| 83 | - } |
|
| 74 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 75 | + if ($squelette AND !z_fond_valide($squelette)){ |
|
| 76 | + $squelette = ""; |
|
| 77 | + $echafauder = ""; |
|
| 78 | + } |
|
| 79 | + if ($prepend){ |
|
| 80 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
|
| 81 | + if ($squelette) |
|
| 82 | + $flux['data'] = $squelette; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // gerer les squelettes non trouves |
|
| 86 | - // -> router vers les /dist.html |
|
| 87 | - // ou scaffolding ou page automatique les contenus |
|
| 88 | - if (!$squelette){ |
|
| 85 | + // gerer les squelettes non trouves |
|
| 86 | + // -> router vers les /dist.html |
|
| 87 | + // ou scaffolding ou page automatique les contenus |
|
| 88 | + if (!$squelette){ |
|
| 89 | 89 | |
| 90 | - // si on est sur un ?page=XX non trouve |
|
| 91 | - if ($flux['args']['contexte'][$page] == $fond |
|
| 92 | - OR $flux['args']['contexte']['type-page'] == $fond |
|
| 93 | - OR ($fond=='sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 90 | + // si on est sur un ?page=XX non trouve |
|
| 91 | + if ($flux['args']['contexte'][$page] == $fond |
|
| 92 | + OR $flux['args']['contexte']['type-page'] == $fond |
|
| 93 | + OR ($fond=='sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 94 | 94 | |
| 95 | - // si on est sur un ?page=XX non trouve |
|
| 96 | - // se brancher sur contenu/xx si il existe |
|
| 97 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 98 | - if (!isset($disponible[$fond])) |
|
| 99 | - $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 95 | + // si on est sur un ?page=XX non trouve |
|
| 96 | + // se brancher sur contenu/xx si il existe |
|
| 97 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 98 | + if (!isset($disponible[$fond])) |
|
| 99 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 100 | 100 | |
| 101 | - if ($disponible[$fond]) |
|
| 102 | - $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 103 | - } |
|
| 101 | + if ($disponible[$fond]) |
|
| 102 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - // echafaudage : |
|
| 106 | - // si c'est un fond de contenu d'un objet en base |
|
| 107 | - // generer un fond automatique a la volee pour les webmestres |
|
| 108 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
|
| 109 | - $type = substr($fond,strlen($z_contenu)+1); |
|
| 110 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | - $type = $flux['args']['contexte'][$page]; |
|
| 112 | - if (!isset($disponible[$type])) |
|
| 113 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 114 | - if (is_string($disponible[$type])) { |
|
| 115 | - $flux['data'] = $disponible[$type]; |
|
| 116 | - } |
|
| 117 | - elseif ($echafauder |
|
| 118 | - AND include_spip('inc/autoriser') |
|
| 119 | - AND isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 120 | - AND autoriser('echafauder',$type) |
|
| 121 | - AND $is = $disponible[$type] |
|
| 122 | - AND is_array($is)) { |
|
| 123 | - $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
|
| 124 | - } |
|
| 125 | - else{ |
|
| 126 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
|
| 127 | - } |
|
| 128 | - } |
|
| 105 | + // echafaudage : |
|
| 106 | + // si c'est un fond de contenu d'un objet en base |
|
| 107 | + // generer un fond automatique a la volee pour les webmestres |
|
| 108 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
|
| 109 | + $type = substr($fond,strlen($z_contenu)+1); |
|
| 110 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | + $type = $flux['args']['contexte'][$page]; |
|
| 112 | + if (!isset($disponible[$type])) |
|
| 113 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 114 | + if (is_string($disponible[$type])) { |
|
| 115 | + $flux['data'] = $disponible[$type]; |
|
| 116 | + } |
|
| 117 | + elseif ($echafauder |
|
| 118 | + AND include_spip('inc/autoriser') |
|
| 119 | + AND isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 120 | + AND autoriser('echafauder',$type) |
|
| 121 | + AND $is = $disponible[$type] |
|
| 122 | + AND is_array($is)) { |
|
| 123 | + $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
|
| 124 | + } |
|
| 125 | + else{ |
|
| 126 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 131 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 132 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 133 | - else{ |
|
| 134 | - if ( $dir = explode('/',$fond) |
|
| 135 | - AND $dir = reset($dir) |
|
| 136 | - AND $dir !== $z_contenu |
|
| 137 | - AND in_array($dir,$z_blocs)){ |
|
| 138 | - $type = substr($fond,strlen("$dir/")); |
|
| 139 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | - $type = $flux['args']['contexte'][$page]; |
|
| 141 | - if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | - if ($type=='page' OR $disponible[$type]) |
|
| 144 | - $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $squelette = $flux['data']; |
|
| 148 | - } |
|
| 149 | - // layout specifiques par type et compositions : |
|
| 150 | - // body-article.html |
|
| 151 | - // body-sommaire.html |
|
| 152 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 153 | - // meme dossier que body.html |
|
| 154 | - if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){ |
|
| 155 | - if (isset($flux['args']['contexte']['type-page']) |
|
| 156 | - AND ( |
|
| 157 | - (isset($flux['args']['contexte']['composition']) |
|
| 158 | - AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 159 | - OR |
|
| 160 | - file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 161 | - )) |
|
| 162 | - $flux['data'] = $f; |
|
| 163 | - } |
|
| 164 | - elseif ($fond=='structure' |
|
| 165 | - AND z_sanitize_var_zajax() |
|
| 166 | - AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
|
| 167 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 168 | - } |
|
| 169 | - // chercher le fond correspondant a la composition |
|
| 170 | - elseif (isset($flux['args']['contexte']['composition']) |
|
| 171 | - AND (basename($fond)=='page' OR ($squelette AND substr($squelette,-strlen($fond))==$fond)) |
|
| 172 | - AND $dir = substr($fond,$prefix_length) |
|
| 173 | - AND $dir = explode('/',$dir) |
|
| 174 | - AND $dir = reset($dir) |
|
| 175 | - AND in_array($dir,$z_blocs) |
|
| 176 | - AND $f=find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")){ |
|
| 177 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return $flux; |
|
| 130 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 131 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 132 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 133 | + else{ |
|
| 134 | + if ( $dir = explode('/',$fond) |
|
| 135 | + AND $dir = reset($dir) |
|
| 136 | + AND $dir !== $z_contenu |
|
| 137 | + AND in_array($dir,$z_blocs)){ |
|
| 138 | + $type = substr($fond,strlen("$dir/")); |
|
| 139 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | + $type = $flux['args']['contexte'][$page]; |
|
| 141 | + if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | + if ($type=='page' OR $disponible[$type]) |
|
| 144 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $squelette = $flux['data']; |
|
| 148 | + } |
|
| 149 | + // layout specifiques par type et compositions : |
|
| 150 | + // body-article.html |
|
| 151 | + // body-sommaire.html |
|
| 152 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 153 | + // meme dossier que body.html |
|
| 154 | + if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){ |
|
| 155 | + if (isset($flux['args']['contexte']['type-page']) |
|
| 156 | + AND ( |
|
| 157 | + (isset($flux['args']['contexte']['composition']) |
|
| 158 | + AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 159 | + OR |
|
| 160 | + file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 161 | + )) |
|
| 162 | + $flux['data'] = $f; |
|
| 163 | + } |
|
| 164 | + elseif ($fond=='structure' |
|
| 165 | + AND z_sanitize_var_zajax() |
|
| 166 | + AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
|
| 167 | + $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 168 | + } |
|
| 169 | + // chercher le fond correspondant a la composition |
|
| 170 | + elseif (isset($flux['args']['contexte']['composition']) |
|
| 171 | + AND (basename($fond)=='page' OR ($squelette AND substr($squelette,-strlen($fond))==$fond)) |
|
| 172 | + AND $dir = substr($fond,$prefix_length) |
|
| 173 | + AND $dir = explode('/',$dir) |
|
| 174 | + AND $dir = reset($dir) |
|
| 175 | + AND in_array($dir,$z_blocs) |
|
| 176 | + AND $f=find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")){ |
|
| 177 | + $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return $flux; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function z_blocs($espace_prive=false) { |
| 190 | - if ($espace_prive) |
|
| 191 | - return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 192 | - return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
|
| 190 | + if ($espace_prive) |
|
| 191 | + return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 192 | + return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | * @return mixed |
| 205 | 205 | */ |
| 206 | 206 | function z_contenu_disponible($prefix_path,$z_contenu,$type,$ext,$echafauder=true){ |
| 207 | - if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 208 | - return $d; |
|
| 209 | - return $echafauder?z_echafaudable($type):false; |
|
| 207 | + if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 208 | + return $d; |
|
| 209 | + return $echafauder?z_echafaudable($type):false; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function z_fond_valide($squelette){ |
| 213 | - if (!_ZCORE_EXCLURE_PATH |
|
| 214 | - OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 215 | - return true; |
|
| 216 | - return false; |
|
| 213 | + if (!_ZCORE_EXCLURE_PATH |
|
| 214 | + OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 215 | + return true; |
|
| 216 | + return false; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | * @return string |
| 234 | 234 | */ |
| 235 | 235 | function z_trouver_bloc($prefix_path,$bloc,$fond,$ext){ |
| 236 | - if ( |
|
| 237 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') AND $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") AND z_fond_valide($f)) |
|
| 238 | - OR ($f = find_in_path("$prefix_path$bloc/$fond.$ext") AND z_fond_valide($f)) |
|
| 239 | - ){ |
|
| 240 | - return substr($f, 0, - strlen(".$ext")); |
|
| 241 | - } |
|
| 242 | - return ""; |
|
| 236 | + if ( |
|
| 237 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') AND $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") AND z_fond_valide($f)) |
|
| 238 | + OR ($f = find_in_path("$prefix_path$bloc/$fond.$ext") AND z_fond_valide($f)) |
|
| 239 | + ){ |
|
| 240 | + return substr($f, 0, - strlen(".$ext")); |
|
| 241 | + } |
|
| 242 | + return ""; |
|
| 243 | 243 | } |
| 244 | 244 | /** |
| 245 | 245 | * Tester si un type est echafaudable |
@@ -250,43 +250,43 @@ discard block |
||
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | 252 | function z_echafaudable($type){ |
| 253 | - static $pages = null; |
|
| 254 | - static $echafaudable = array(); |
|
| 255 | - if (isset($echafaudable[$type])) |
|
| 256 | - return $echafaudable[$type]; |
|
| 257 | - if (preg_match(',[^\w],',$type)) |
|
| 258 | - return $echafaudable[$type] = false; |
|
| 253 | + static $pages = null; |
|
| 254 | + static $echafaudable = array(); |
|
| 255 | + if (isset($echafaudable[$type])) |
|
| 256 | + return $echafaudable[$type]; |
|
| 257 | + if (preg_match(',[^\w],',$type)) |
|
| 258 | + return $echafaudable[$type] = false; |
|
| 259 | 259 | |
| 260 | - if (test_espace_prive()){ |
|
| 261 | - if (!function_exists('trouver_objet_exec')) |
|
| 262 | - include_spip('inc/pipelines_ecrire'); |
|
| 263 | - if ($e=trouver_objet_exec($type)){ |
|
| 264 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
|
| 265 | - } |
|
| 266 | - else { |
|
| 267 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 268 | - if (($t=objet_type($type,false))!==$type |
|
| 269 | - AND $e=trouver_objet_exec($t)){ |
|
| 270 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - else { |
|
| 275 | - if (is_null($pages)) { |
|
| 276 | - $pages = array(); |
|
| 277 | - $liste = lister_tables_objets_sql(); |
|
| 278 | - foreach($liste as $t=>$d) |
|
| 279 | - if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 280 | - } |
|
| 281 | - if (!isset($pages[$type])) |
|
| 282 | - return $echafaudable[$type] = false; |
|
| 283 | - if (count($pages[$type])==2){ |
|
| 284 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 285 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 286 | - } |
|
| 287 | - return $echafaudable[$type] = $pages[$type]; |
|
| 288 | - } |
|
| 289 | - return $echafaudable[$type] = false; |
|
| 260 | + if (test_espace_prive()){ |
|
| 261 | + if (!function_exists('trouver_objet_exec')) |
|
| 262 | + include_spip('inc/pipelines_ecrire'); |
|
| 263 | + if ($e=trouver_objet_exec($type)){ |
|
| 264 | + return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
|
| 265 | + } |
|
| 266 | + else { |
|
| 267 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 268 | + if (($t=objet_type($type,false))!==$type |
|
| 269 | + AND $e=trouver_objet_exec($t)){ |
|
| 270 | + return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + else { |
|
| 275 | + if (is_null($pages)) { |
|
| 276 | + $pages = array(); |
|
| 277 | + $liste = lister_tables_objets_sql(); |
|
| 278 | + foreach($liste as $t=>$d) |
|
| 279 | + if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 280 | + } |
|
| 281 | + if (!isset($pages[$type])) |
|
| 282 | + return $echafaudable[$type] = false; |
|
| 283 | + if (count($pages[$type])==2){ |
|
| 284 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 285 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 286 | + } |
|
| 287 | + return $echafaudable[$type] = $pages[$type]; |
|
| 288 | + } |
|
| 289 | + return $echafaudable[$type] = false; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
@@ -303,45 +303,45 @@ discard block |
||
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | 305 | function prive_echafauder_dist($exec,$table,$table_sql,$desc_exec,$ext){ |
| 306 | - $scaffold = ""; |
|
| 306 | + $scaffold = ""; |
|
| 307 | 307 | |
| 308 | - // page objet ou objet_edit |
|
| 309 | - if (is_array($desc_exec)) { |
|
| 310 | - $type = $desc_exec['type']; |
|
| 311 | - $primary = $desc_exec['id_table_objet']; |
|
| 308 | + // page objet ou objet_edit |
|
| 309 | + if (is_array($desc_exec)) { |
|
| 310 | + $type = $desc_exec['type']; |
|
| 311 | + $primary = $desc_exec['id_table_objet']; |
|
| 312 | 312 | |
| 313 | - if ($desc_exec['edition']===false) |
|
| 314 | - $fond = "objet"; |
|
| 315 | - else { |
|
| 316 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 317 | - $desc = $trouver_table($table_sql); |
|
| 318 | - if (isset($desc['field']['id_rubrique'])) |
|
| 319 | - $fond = 'objet_edit'; |
|
| 320 | - else |
|
| 321 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 322 | - } |
|
| 323 | - $dir = z_blocs(test_espace_prive()); |
|
| 324 | - $dir = reset($dir); |
|
| 325 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 326 | - } |
|
| 327 | - // page objets |
|
| 328 | - elseif($type = $desc_exec AND strpos($type,"/")===false){ |
|
| 329 | - $dir = z_blocs(test_espace_prive()); |
|
| 330 | - $dir = reset($dir); |
|
| 331 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 332 | - } |
|
| 333 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 334 | - // et objet et tire de $table |
|
| 335 | - elseif($fond = $desc_exec){ |
|
| 336 | - $dir = md5(dirname($fond)); |
|
| 337 | - $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 338 | - } |
|
| 313 | + if ($desc_exec['edition']===false) |
|
| 314 | + $fond = "objet"; |
|
| 315 | + else { |
|
| 316 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 317 | + $desc = $trouver_table($table_sql); |
|
| 318 | + if (isset($desc['field']['id_rubrique'])) |
|
| 319 | + $fond = 'objet_edit'; |
|
| 320 | + else |
|
| 321 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 322 | + } |
|
| 323 | + $dir = z_blocs(test_espace_prive()); |
|
| 324 | + $dir = reset($dir); |
|
| 325 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 326 | + } |
|
| 327 | + // page objets |
|
| 328 | + elseif($type = $desc_exec AND strpos($type,"/")===false){ |
|
| 329 | + $dir = z_blocs(test_espace_prive()); |
|
| 330 | + $dir = reset($dir); |
|
| 331 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 332 | + } |
|
| 333 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 334 | + // et objet et tire de $table |
|
| 335 | + elseif($fond = $desc_exec){ |
|
| 336 | + $dir = md5(dirname($fond)); |
|
| 337 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - $base_dir = sous_repertoire(_DIR_CACHE,"scaffold",false); |
|
| 341 | - $base_dir = sous_repertoire($base_dir,$dir,false); |
|
| 342 | - $f = $base_dir."$exec"; |
|
| 343 | - ecrire_fichier("$f.$ext",$scaffold); |
|
| 344 | - return $f; |
|
| 340 | + $base_dir = sous_repertoire(_DIR_CACHE,"scaffold",false); |
|
| 341 | + $base_dir = sous_repertoire($base_dir,$dir,false); |
|
| 342 | + $f = $base_dir."$exec"; |
|
| 343 | + ecrire_fichier("$f.$ext",$scaffold); |
|
| 344 | + return $f; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | * @return bool|string |
| 350 | 350 | */ |
| 351 | 351 | function z_sanitize_var_zajax(){ |
| 352 | - $z_ajax = _request('var_zajax'); |
|
| 353 | - if (!$z_ajax) return false; |
|
| 354 | - if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 355 | - OR !in_array($z_ajax,$z_blocs)) { |
|
| 356 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 357 | - $z_ajax = false; |
|
| 358 | - } |
|
| 359 | - return $z_ajax; |
|
| 352 | + $z_ajax = _request('var_zajax'); |
|
| 353 | + if (!$z_ajax) return false; |
|
| 354 | + if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 355 | + OR !in_array($z_ajax,$z_blocs)) { |
|
| 356 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 357 | + $z_ajax = false; |
|
| 358 | + } |
|
| 359 | + return $z_ajax; |
|
| 360 | 360 | } |
| 361 | 361 | ?> |
@@ -14,109 +14,109 @@ |
||
| 14 | 14 | |
| 15 | 15 | function format_boucle_html ($avant, $nom, $type, $crit, $corps, $apres, $altern, $prof) |
| 16 | 16 | { |
| 17 | - $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 18 | - $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 19 | - $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 20 | - if (!$corps) $corps = " />"; else $corps = ">$corps</BOUCLE$nom>"; |
|
| 21 | - return "$avant<BOUCLE$nom($type)$crit$corps$apres$altern"; |
|
| 17 | + $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 18 | + $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 19 | + $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 20 | + if (!$corps) $corps = " />"; else $corps = ">$corps</BOUCLE$nom>"; |
|
| 21 | + return "$avant<BOUCLE$nom($type)$crit$corps$apres$altern"; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function format_inclure_html ($file, $args, $prof) |
| 25 | 25 | { |
| 26 | - if (strpos($file, '#')===false) |
|
| 27 | - $t = $file ? ("(" . $file . ")") : "" ; |
|
| 28 | - else { |
|
| 29 | - $t = "{fond=" . $file . '}'; |
|
| 30 | - } |
|
| 31 | - $args = !$args ? '' : ("{" . join(", ",$args) . "}"); |
|
| 32 | - return ("<INCLURE" . $t . $args . ">"); |
|
| 26 | + if (strpos($file, '#')===false) |
|
| 27 | + $t = $file ? ("(" . $file . ")") : "" ; |
|
| 28 | + else { |
|
| 29 | + $t = "{fond=" . $file . '}'; |
|
| 30 | + } |
|
| 31 | + $args = !$args ? '' : ("{" . join(", ",$args) . "}"); |
|
| 32 | + return ("<INCLURE" . $t . $args . ">"); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | function format_polyglotte_html ($args, $prof) |
| 36 | 36 | { |
| 37 | - $contenu = array(); |
|
| 38 | - foreach($args as $l=>$t) |
|
| 39 | - $contenu[]= ($l ? "[$l]" : '') . $t; |
|
| 40 | - return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 37 | + $contenu = array(); |
|
| 38 | + foreach($args as $l=>$t) |
|
| 39 | + $contenu[]= ($l ? "[$l]" : '') . $t; |
|
| 40 | + return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_idiome_html ($nom, $module, $args, $filtres, $prof) |
| 44 | 44 | { |
| 45 | - foreach ($args as $k => $v) $args[$k] = "$k=$v"; |
|
| 46 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 47 | - return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 45 | + foreach ($args as $k => $v) $args[$k] = "$k=$v"; |
|
| 46 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 47 | + return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function format_champ_html ($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) |
| 51 | 51 | { |
| 52 | - $nom = "#" |
|
| 53 | - . ($boucle ? ($boucle . ":") : "") |
|
| 54 | - . $nom |
|
| 55 | - . $etoile |
|
| 56 | - . $args |
|
| 57 | - . $filtres; |
|
| 52 | + $nom = "#" |
|
| 53 | + . ($boucle ? ($boucle . ":") : "") |
|
| 54 | + . $nom |
|
| 55 | + . $etoile |
|
| 56 | + . $args |
|
| 57 | + . $filtres; |
|
| 58 | 58 | |
| 59 | - // Determiner si c'est un champ etendu, |
|
| 59 | + // Determiner si c'est un champ etendu, |
|
| 60 | 60 | |
| 61 | - $s = ($avant OR $apres OR $filtres |
|
| 62 | - OR (strpos($args, '(#') !==false)); |
|
| 61 | + $s = ($avant OR $apres OR $filtres |
|
| 62 | + OR (strpos($args, '(#') !==false)); |
|
| 63 | 63 | |
| 64 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 64 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | function format_critere_html ($critere) |
| 68 | 68 | { |
| 69 | - foreach ($critere as $k => $crit) { |
|
| 70 | - $crit_s = ''; |
|
| 71 | - foreach ($crit as $operande) { |
|
| 72 | - list($type, $valeur) = $operande; |
|
| 73 | - if ($type == 'champ' AND $valeur[0]=='[') { |
|
| 74 | - $valeur = substr($valeur,1,-1); |
|
| 75 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) |
|
| 76 | - $valeur = substr($valeur,1,-1); |
|
| 77 | - } |
|
| 78 | - $crit_s .= $valeur; |
|
| 79 | - } |
|
| 80 | - $critere[$k] = $crit_s; |
|
| 81 | - } |
|
| 82 | - return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 69 | + foreach ($critere as $k => $crit) { |
|
| 70 | + $crit_s = ''; |
|
| 71 | + foreach ($crit as $operande) { |
|
| 72 | + list($type, $valeur) = $operande; |
|
| 73 | + if ($type == 'champ' AND $valeur[0]=='[') { |
|
| 74 | + $valeur = substr($valeur,1,-1); |
|
| 75 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) |
|
| 76 | + $valeur = substr($valeur,1,-1); |
|
| 77 | + } |
|
| 78 | + $crit_s .= $valeur; |
|
| 79 | + } |
|
| 80 | + $critere[$k] = $crit_s; |
|
| 81 | + } |
|
| 82 | + return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | function format_liste_html ($fonc, $args, $prof) |
| 86 | 86 | { |
| 87 | - return ((($fonc!=='') ? "|$fonc" : $fonc) |
|
| 88 | - . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 87 | + return ((($fonc!=='') ? "|$fonc" : $fonc) |
|
| 88 | + . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 92 | 92 | function format_suite_html ($args) |
| 93 | 93 | { |
| 94 | - for($i=0; $i < count($args)-1; $i++) { |
|
| 95 | - list($texte, $type) = $args[$i]; |
|
| 96 | - list($texte2, $type2) = $args[$i+1]; |
|
| 97 | - if (!$texte OR !$texte2) continue; |
|
| 98 | - $c1 = substr($texte,-1); |
|
| 99 | - if ($type2 !== 'texte') { |
|
| 100 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 101 | - // ou assimiles, forcer la notation pleine |
|
| 102 | - if ($c1 == '(' AND substr($texte2,0,1) == '#') |
|
| 103 | - $args[$i+1][0] = '[(' . $texte2 . ')]'; |
|
| 104 | - } else { |
|
| 105 | - if ($type == 'texte') continue; |
|
| 106 | - // si un champ ou assimiles est suivi d'un texte |
|
| 107 | - // et si celui-ci commence par un caractere de champ |
|
| 108 | - // forcer la notation pleine |
|
| 109 | - if (($c1 == '}' AND substr(ltrim($texte2),0,1) == '|') |
|
| 110 | - OR (preg_match('/[\w\d_*]/', $c1) AND preg_match('/^[\w\d_*{|]/', $texte2))) |
|
| 111 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - return join("", array_map('array_shift', $args)); |
|
| 94 | + for($i=0; $i < count($args)-1; $i++) { |
|
| 95 | + list($texte, $type) = $args[$i]; |
|
| 96 | + list($texte2, $type2) = $args[$i+1]; |
|
| 97 | + if (!$texte OR !$texte2) continue; |
|
| 98 | + $c1 = substr($texte,-1); |
|
| 99 | + if ($type2 !== 'texte') { |
|
| 100 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 101 | + // ou assimiles, forcer la notation pleine |
|
| 102 | + if ($c1 == '(' AND substr($texte2,0,1) == '#') |
|
| 103 | + $args[$i+1][0] = '[(' . $texte2 . ')]'; |
|
| 104 | + } else { |
|
| 105 | + if ($type == 'texte') continue; |
|
| 106 | + // si un champ ou assimiles est suivi d'un texte |
|
| 107 | + // et si celui-ci commence par un caractere de champ |
|
| 108 | + // forcer la notation pleine |
|
| 109 | + if (($c1 == '}' AND substr(ltrim($texte2),0,1) == '|') |
|
| 110 | + OR (preg_match('/[\w\d_*]/', $c1) AND preg_match('/^[\w\d_*{|]/', $texte2))) |
|
| 111 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + return join("", array_map('array_shift', $args)); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | function format_texte_html ($texte) |
| 118 | 118 | { |
| 119 | - return $texte; |
|
| 119 | + return $texte; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | ?> |
@@ -58,62 +58,62 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@argumenter_inclure |
| 60 | 60 | function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap=true, $lang = '', $fond1=false){ |
| 61 | - $l = array(); |
|
| 62 | - $erreur_p_i_i = ''; |
|
| 63 | - if (!is_array($params)) return $l; |
|
| 64 | - foreach($params as $k => $couple) { |
|
| 65 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 66 | - $filtre = array_shift($couple); |
|
| 67 | - if ($filtre) break; |
|
| 68 | - foreach($couple as $n => $val) { |
|
| 69 | - $var = $val[0]; |
|
| 70 | - if ($var->type != 'texte') { |
|
| 71 | - if ($n OR $k OR $fond1) { |
|
| 72 | - $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 73 | - array('param' => $var->nom_champ)); |
|
| 74 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 78 | - } else { |
|
| 79 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
|
| 80 | - $var = $m[1]; |
|
| 81 | - $auto = false;; |
|
| 82 | - if ($m[2]) { |
|
| 83 | - $v = $m[3]; |
|
| 84 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
|
| 85 | - $val[0] = new Texte; |
|
| 86 | - $val[0]->texte = $v; |
|
| 87 | - } elseif ($k OR $n OR $fond1) { |
|
| 88 | - $auto = true; |
|
| 89 | - } else $var = 1; |
|
| 90 | - |
|
| 91 | - if ($var == 'lang') { |
|
| 92 | - $lang = !$auto |
|
| 93 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 94 | - : '$GLOBALS["spip_lang"]'; |
|
| 95 | - } else { |
|
| 96 | - $val = $auto |
|
| 97 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 98 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 99 | - if ($var !== 1) |
|
| 100 | - $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | - . $val . ($echap? ") . '":" "); |
|
| 102 | - else $val = $echap ? "'.$val.'" : $val; |
|
| 103 | - $l[$var] = $val; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - if ($erreur_p_i_i) return false; |
|
| 109 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 110 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 111 | - // sauf si on n'en veut pas |
|
| 112 | - if ($lang === false) return $l; |
|
| 113 | - if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
|
| 114 | - $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
|
| 115 | - |
|
| 116 | - return $l; |
|
| 61 | + $l = array(); |
|
| 62 | + $erreur_p_i_i = ''; |
|
| 63 | + if (!is_array($params)) return $l; |
|
| 64 | + foreach($params as $k => $couple) { |
|
| 65 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 66 | + $filtre = array_shift($couple); |
|
| 67 | + if ($filtre) break; |
|
| 68 | + foreach($couple as $n => $val) { |
|
| 69 | + $var = $val[0]; |
|
| 70 | + if ($var->type != 'texte') { |
|
| 71 | + if ($n OR $k OR $fond1) { |
|
| 72 | + $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 73 | + array('param' => $var->nom_champ)); |
|
| 74 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 78 | + } else { |
|
| 79 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
|
| 80 | + $var = $m[1]; |
|
| 81 | + $auto = false;; |
|
| 82 | + if ($m[2]) { |
|
| 83 | + $v = $m[3]; |
|
| 84 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
|
| 85 | + $val[0] = new Texte; |
|
| 86 | + $val[0]->texte = $v; |
|
| 87 | + } elseif ($k OR $n OR $fond1) { |
|
| 88 | + $auto = true; |
|
| 89 | + } else $var = 1; |
|
| 90 | + |
|
| 91 | + if ($var == 'lang') { |
|
| 92 | + $lang = !$auto |
|
| 93 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 94 | + : '$GLOBALS["spip_lang"]'; |
|
| 95 | + } else { |
|
| 96 | + $val = $auto |
|
| 97 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 98 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 99 | + if ($var !== 1) |
|
| 100 | + $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | + . $val . ($echap? ") . '":" "); |
|
| 102 | + else $val = $echap ? "'.$val.'" : $val; |
|
| 103 | + $l[$var] = $val; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + if ($erreur_p_i_i) return false; |
|
| 109 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 110 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 111 | + // sauf si on n'en veut pas |
|
| 112 | + if ($lang === false) return $l; |
|
| 113 | + if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
|
| 114 | + $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
|
| 115 | + |
|
| 116 | + return $l; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -137,64 +137,64 @@ discard block |
||
| 137 | 137 | **/ |
| 138 | 138 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 139 | 139 | |
| 140 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 141 | - if (is_string($p->texte)) { |
|
| 142 | - $fichier = $p->texte; |
|
| 143 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 144 | - |
|
| 145 | - } else { |
|
| 146 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 147 | - if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) |
|
| 148 | - $fichier = $r[1]; |
|
| 149 | - else $fichier = ''; |
|
| 150 | - } |
|
| 151 | - if (!$code OR $code === '""') { |
|
| 152 | - $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 153 | - array('param' => $code)); |
|
| 154 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 158 | - |
|
| 159 | - if (is_array($_contexte)) { |
|
| 160 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 161 | - if ($env = (isset($_contexte['env'])|| isset($_contexte['self']))) { |
|
| 162 | - unset($_contexte['env']); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // noter les doublons dans l'appel a public.php |
|
| 166 | - if (isset($_contexte['doublons'])) { |
|
| 167 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($ajax = isset($_contexte['ajax'])){ |
|
| 171 | - $ajax = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 172 | - unset($_contexte['ajax']); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $_contexte = join(",\n\t", $_contexte); |
|
| 176 | - } |
|
| 177 | - else |
|
| 178 | - return false; // j'aurais voulu toucher le fond ... |
|
| 140 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 141 | + if (is_string($p->texte)) { |
|
| 142 | + $fichier = $p->texte; |
|
| 143 | + $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 144 | + |
|
| 145 | + } else { |
|
| 146 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 147 | + if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) |
|
| 148 | + $fichier = $r[1]; |
|
| 149 | + else $fichier = ''; |
|
| 150 | + } |
|
| 151 | + if (!$code OR $code === '""') { |
|
| 152 | + $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 153 | + array('param' => $code)); |
|
| 154 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 158 | + |
|
| 159 | + if (is_array($_contexte)) { |
|
| 160 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 161 | + if ($env = (isset($_contexte['env'])|| isset($_contexte['self']))) { |
|
| 162 | + unset($_contexte['env']); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // noter les doublons dans l'appel a public.php |
|
| 166 | + if (isset($_contexte['doublons'])) { |
|
| 167 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($ajax = isset($_contexte['ajax'])){ |
|
| 171 | + $ajax = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 172 | + unset($_contexte['ajax']); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $_contexte = join(",\n\t", $_contexte); |
|
| 176 | + } |
|
| 177 | + else |
|
| 178 | + return false; // j'aurais voulu toucher le fond ... |
|
| 179 | 179 | |
| 180 | - $contexte = 'array(' . $_contexte .')'; |
|
| 181 | - |
|
| 182 | - if ($env) { |
|
| 183 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 187 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 188 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 189 | - } else { |
|
| 190 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 191 | - if ($ajax) |
|
| 192 | - $_options[] = $ajax; |
|
| 193 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 194 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return "\n'<'.'". "?php ". $code . "\n?'." . "'>'"; |
|
| 180 | + $contexte = 'array(' . $_contexte .')'; |
|
| 181 | + |
|
| 182 | + if ($env) { |
|
| 183 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 187 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 188 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 189 | + } else { |
|
| 190 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 191 | + if ($ajax) |
|
| 192 | + $_options[] = $ajax; |
|
| 193 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 194 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return "\n'<'.'". "?php ". $code . "\n?'." . "'>'"; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 213 | 213 | */ |
| 214 | 214 | function instituer_boucle(&$boucle, $echapper=true, $ignore_previsu=false){ |
| 215 | - /* |
|
| 215 | + /* |
|
| 216 | 216 | $show['statut'][] = array( |
| 217 | 217 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 218 | 218 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -236,71 +236,71 @@ discard block |
||
| 236 | 236 | champstatut est alors le champ statut sur la tablen |
| 237 | 237 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 238 | 238 | */ |
| 239 | - $id_table = $boucle->id_table; |
|
| 240 | - $show = $boucle->show; |
|
| 241 | - if (isset($show['statut']) AND $show['statut']){ |
|
| 242 | - foreach($show['statut'] as $k=>$s){ |
|
| 243 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 244 | - $filtrer = true; |
|
| 245 | - if (isset($s['exception'])) { |
|
| 246 | - foreach(is_array($s['exception'])?$s['exception']:array($s['exception']) as $m) { |
|
| 247 | - if (isset($boucle->modificateur[$m]) OR isset($boucle->modificateur['criteres'][$m])) { |
|
| 248 | - $filtrer = false; |
|
| 249 | - break; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if ($filtrer) { |
|
| 255 | - if (is_array($s['champ'])){ |
|
| 256 | - $statut = preg_replace(',\W,','',array_pop($s['champ'])); // securite |
|
| 257 | - $jointures = array(); |
|
| 258 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 259 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 260 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 261 | - foreach($s['champ'] as $j) { |
|
| 262 | - $id = reset($j); |
|
| 263 | - $def = $trouver_table($id); |
|
| 264 | - $jointures[] = array('',array($id,$def),end($j)); |
|
| 265 | - } |
|
| 266 | - $jointures[0][0] = $id_table; |
|
| 267 | - if (!array_search($id, $boucle->from)){ |
|
| 268 | - include_spip('public/jointures'); |
|
| 269 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 270 | - } |
|
| 271 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 272 | - $id = array_search($id, $boucle->from); |
|
| 273 | - } |
|
| 274 | - else { |
|
| 275 | - $id = $id_table; |
|
| 276 | - $statut = preg_replace(',\W,','',$s['champ']); // securite |
|
| 277 | - } |
|
| 278 | - $mstatut = $id .'.'.$statut; |
|
| 279 | - |
|
| 280 | - $arg_ignore_previsu=($ignore_previsu?",true":''); |
|
| 281 | - include_spip('public/quete'); |
|
| 282 | - if (isset($s['post_date']) AND $s['post_date'] |
|
| 283 | - AND $GLOBALS['meta']["post_dates"] == 'non'){ |
|
| 284 | - $date = $id.'.'.preg_replace(',\W,','',$s['post_date']); // securite |
|
| 285 | - array_unshift($boucle->where, |
|
| 286 | - $echapper ? |
|
| 287 | - "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 288 | - : |
|
| 289 | - quete_condition_postdates($date,$boucle->sql_serveur,$ignore_previsu) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - array_unshift($boucle->where, |
|
| 293 | - $echapper ? |
|
| 294 | - "\nquete_condition_statut('$mstatut'," |
|
| 295 | - . _q($s['previsu'])."," |
|
| 296 | - ._q($s['publie'])."," |
|
| 297 | - ._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 298 | - : |
|
| 299 | - quete_condition_statut($mstatut,$s['previsu'],$s['publie'],$boucle->sql_serveur,$ignore_previsu) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 239 | + $id_table = $boucle->id_table; |
|
| 240 | + $show = $boucle->show; |
|
| 241 | + if (isset($show['statut']) AND $show['statut']){ |
|
| 242 | + foreach($show['statut'] as $k=>$s){ |
|
| 243 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 244 | + $filtrer = true; |
|
| 245 | + if (isset($s['exception'])) { |
|
| 246 | + foreach(is_array($s['exception'])?$s['exception']:array($s['exception']) as $m) { |
|
| 247 | + if (isset($boucle->modificateur[$m]) OR isset($boucle->modificateur['criteres'][$m])) { |
|
| 248 | + $filtrer = false; |
|
| 249 | + break; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if ($filtrer) { |
|
| 255 | + if (is_array($s['champ'])){ |
|
| 256 | + $statut = preg_replace(',\W,','',array_pop($s['champ'])); // securite |
|
| 257 | + $jointures = array(); |
|
| 258 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 259 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 260 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 261 | + foreach($s['champ'] as $j) { |
|
| 262 | + $id = reset($j); |
|
| 263 | + $def = $trouver_table($id); |
|
| 264 | + $jointures[] = array('',array($id,$def),end($j)); |
|
| 265 | + } |
|
| 266 | + $jointures[0][0] = $id_table; |
|
| 267 | + if (!array_search($id, $boucle->from)){ |
|
| 268 | + include_spip('public/jointures'); |
|
| 269 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 270 | + } |
|
| 271 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 272 | + $id = array_search($id, $boucle->from); |
|
| 273 | + } |
|
| 274 | + else { |
|
| 275 | + $id = $id_table; |
|
| 276 | + $statut = preg_replace(',\W,','',$s['champ']); // securite |
|
| 277 | + } |
|
| 278 | + $mstatut = $id .'.'.$statut; |
|
| 279 | + |
|
| 280 | + $arg_ignore_previsu=($ignore_previsu?",true":''); |
|
| 281 | + include_spip('public/quete'); |
|
| 282 | + if (isset($s['post_date']) AND $s['post_date'] |
|
| 283 | + AND $GLOBALS['meta']["post_dates"] == 'non'){ |
|
| 284 | + $date = $id.'.'.preg_replace(',\W,','',$s['post_date']); // securite |
|
| 285 | + array_unshift($boucle->where, |
|
| 286 | + $echapper ? |
|
| 287 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 288 | + : |
|
| 289 | + quete_condition_postdates($date,$boucle->sql_serveur,$ignore_previsu) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + array_unshift($boucle->where, |
|
| 293 | + $echapper ? |
|
| 294 | + "\nquete_condition_statut('$mstatut'," |
|
| 295 | + . _q($s['previsu'])."," |
|
| 296 | + ._q($s['publie'])."," |
|
| 297 | + ._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 298 | + : |
|
| 299 | + quete_condition_statut($mstatut,$s['previsu'],$s['publie'],$boucle->sql_serveur,$ignore_previsu) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -319,22 +319,22 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | function calculer_boucle($id_boucle, &$boucles) { |
| 321 | 321 | |
| 322 | - $boucle = &$boucles[$id_boucle]; |
|
| 323 | - instituer_boucle($boucle); |
|
| 324 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 325 | - |
|
| 326 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 327 | - // mais pas tous, sinon ca pete. |
|
| 328 | - if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | - $trace = ''; |
|
| 330 | - else { |
|
| 331 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 332 | - $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 322 | + $boucle = &$boucles[$id_boucle]; |
|
| 323 | + instituer_boucle($boucle); |
|
| 324 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 325 | + |
|
| 326 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 327 | + // mais pas tous, sinon ca pete. |
|
| 328 | + if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | + $trace = ''; |
|
| 330 | + else { |
|
| 331 | + $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 332 | + $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 333 | 333 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 334 | - } |
|
| 335 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 336 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 337 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 334 | + } |
|
| 335 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 336 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 337 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
@@ -357,14 +357,14 @@ discard block |
||
| 357 | 357 | * Code PHP compilé de la boucle récursive |
| 358 | 358 | **/ |
| 359 | 359 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 360 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 361 | - return |
|
| 362 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 363 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 364 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 365 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 366 | - . $trace |
|
| 367 | - . "\n\treturn \$t0;"; |
|
| 360 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 361 | + return |
|
| 362 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 363 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 364 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 365 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 366 | + . $trace |
|
| 367 | + . "\n\treturn \$t0;"; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -417,154 +417,154 @@ discard block |
||
| 417 | 417 | **/ |
| 418 | 418 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 419 | 419 | |
| 420 | - $boucle = &$boucles[$id_boucle]; |
|
| 421 | - $return = $boucle->return; |
|
| 422 | - $type_boucle = $boucle->type_requete; |
|
| 423 | - $primary = $boucle->primary; |
|
| 424 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'",'', $return)); |
|
| 425 | - $flag_cpt = $boucle->mode_partie ||$boucle->cptrows; |
|
| 426 | - $corps = ''; |
|
| 427 | - |
|
| 428 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 429 | - // et puis faire un [] plutot qu'un "','." |
|
| 430 | - if ($boucle->doublons) |
|
| 431 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 432 | - index_pile($id_boucle, $primary, $boucles) |
|
| 433 | - . "; // doublons\n"; |
|
| 434 | - |
|
| 435 | - // La boucle doit-elle selectionner la langue ? |
|
| 436 | - // - par defaut, les boucles suivantes le font |
|
| 437 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 438 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 439 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 440 | - (($boucle->lang_select == 'oui') || |
|
| 441 | - in_array($type_boucle, array( |
|
| 442 | - 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 443 | - ))) |
|
| 444 | - ) { |
|
| 445 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 446 | - // afin que le corps de boucle affecte la globale directement |
|
| 447 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 448 | - $fin_lang = "lang_select();\n\t"; |
|
| 449 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 450 | - |
|
| 451 | - $corps .= |
|
| 452 | - "\n\t\tlang_select_public(" |
|
| 453 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 454 | - . ", '".$boucle->lang_select."'" |
|
| 455 | - . (in_array($type_boucle, array( |
|
| 456 | - 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 457 | - )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 458 | - . ');'; |
|
| 459 | - } |
|
| 460 | - else { |
|
| 461 | - $init_lang = ''; |
|
| 462 | - $fin_lang = ''; |
|
| 463 | - $fin_lang_select_public = ''; |
|
| 464 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 465 | - if (strpos($return, '?php') === false |
|
| 466 | - AND preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r)) { |
|
| 467 | - $i = 1; |
|
| 468 | - foreach($r[1] as $t) { |
|
| 469 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 470 | - $return = str_replace($t, "\$l$i", $return); |
|
| 471 | - $i++; |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // gestion optimale des separateurs et des boucles constantes |
|
| 477 | - if (count($boucle->separateur)) |
|
| 478 | - $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 479 | - |
|
| 480 | - $corps .= |
|
| 481 | - ((!$boucle->separateur) ? |
|
| 482 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 483 | - (($return==="''") ? '' : |
|
| 484 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 485 | - ("\n\t\t\$t1 " . |
|
| 486 | - ((strpos($return, '$t1.') === 0) ? |
|
| 487 | - (".=" . substr($return,4)) : |
|
| 488 | - ('= ' . $return)) . |
|
| 489 | - ";\n\t\t" . |
|
| 490 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 420 | + $boucle = &$boucles[$id_boucle]; |
|
| 421 | + $return = $boucle->return; |
|
| 422 | + $type_boucle = $boucle->type_requete; |
|
| 423 | + $primary = $boucle->primary; |
|
| 424 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'",'', $return)); |
|
| 425 | + $flag_cpt = $boucle->mode_partie ||$boucle->cptrows; |
|
| 426 | + $corps = ''; |
|
| 427 | + |
|
| 428 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 429 | + // et puis faire un [] plutot qu'un "','." |
|
| 430 | + if ($boucle->doublons) |
|
| 431 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 432 | + index_pile($id_boucle, $primary, $boucles) |
|
| 433 | + . "; // doublons\n"; |
|
| 434 | + |
|
| 435 | + // La boucle doit-elle selectionner la langue ? |
|
| 436 | + // - par defaut, les boucles suivantes le font |
|
| 437 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 438 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 439 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 440 | + (($boucle->lang_select == 'oui') || |
|
| 441 | + in_array($type_boucle, array( |
|
| 442 | + 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 443 | + ))) |
|
| 444 | + ) { |
|
| 445 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 446 | + // afin que le corps de boucle affecte la globale directement |
|
| 447 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 448 | + $fin_lang = "lang_select();\n\t"; |
|
| 449 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 450 | + |
|
| 451 | + $corps .= |
|
| 452 | + "\n\t\tlang_select_public(" |
|
| 453 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 454 | + . ", '".$boucle->lang_select."'" |
|
| 455 | + . (in_array($type_boucle, array( |
|
| 456 | + 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 457 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 458 | + . ');'; |
|
| 459 | + } |
|
| 460 | + else { |
|
| 461 | + $init_lang = ''; |
|
| 462 | + $fin_lang = ''; |
|
| 463 | + $fin_lang_select_public = ''; |
|
| 464 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 465 | + if (strpos($return, '?php') === false |
|
| 466 | + AND preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r)) { |
|
| 467 | + $i = 1; |
|
| 468 | + foreach($r[1] as $t) { |
|
| 469 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 470 | + $return = str_replace($t, "\$l$i", $return); |
|
| 471 | + $i++; |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // gestion optimale des separateurs et des boucles constantes |
|
| 477 | + if (count($boucle->separateur)) |
|
| 478 | + $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 479 | + |
|
| 480 | + $corps .= |
|
| 481 | + ((!$boucle->separateur) ? |
|
| 482 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 483 | + (($return==="''") ? '' : |
|
| 484 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 485 | + ("\n\t\t\$t1 " . |
|
| 486 | + ((strpos($return, '$t1.') === 0) ? |
|
| 487 | + (".=" . substr($return,4)) : |
|
| 488 | + ('= ' . $return)) . |
|
| 489 | + ";\n\t\t" . |
|
| 490 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 491 | 491 | |
| 492 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 493 | - // souhaite invalider ces elements |
|
| 494 | - if (!$constant AND $primary) { |
|
| 495 | - include_spip('inc/invalideur'); |
|
| 496 | - if (function_exists($i = 'calcul_invalideurs')) |
|
| 497 | - $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // gerer le compteur de boucle |
|
| 501 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 502 | - |
|
| 503 | - if ($boucle->partie OR $boucle->cptrows) |
|
| 504 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 505 | - . $boucle->partie |
|
| 506 | - . $corps; |
|
| 507 | - |
|
| 508 | - // depiler la lang de la boucle si besoin |
|
| 509 | - $corps .= $fin_lang_select_public; |
|
| 510 | - |
|
| 511 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 512 | - |
|
| 513 | - if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
|
| 514 | - if (!isset($r[2]) OR (!$r[2])) { |
|
| 515 | - if (!$boucle->numrows) |
|
| 516 | - return "\n\t\$t0 = '';"; |
|
| 517 | - else |
|
| 518 | - $corps = ""; |
|
| 519 | - } else { |
|
| 520 | - $boucle->numrows = true; |
|
| 521 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 522 | - } |
|
| 523 | - } else $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 524 | - |
|
| 525 | - $count = ''; |
|
| 526 | - if (!$boucle->select) { |
|
| 527 | - if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
|
| 528 | - $count = '1'; |
|
| 529 | - else $count = 'count(*)'; |
|
| 530 | - $boucles[$id_boucle]->select[]= $count; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - if ($flag_cpt) |
|
| 534 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 535 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 536 | - else $nums = ''; |
|
| 537 | - |
|
| 538 | - if ($boucle->numrows OR $boucle->mode_partie) { |
|
| 539 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 540 | - . $boucle->mode_partie |
|
| 541 | - . "\n\t"; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Ne calculer la requete que maintenant |
|
| 545 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 546 | - |
|
| 547 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 548 | - ? ("\n\t$init = array();") : '') |
|
| 549 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 550 | - |
|
| 551 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 552 | - |
|
| 553 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 554 | - $init, |
|
| 555 | - $boucle->iterateur, |
|
| 556 | - "\$command", |
|
| 557 | - $contexte, |
|
| 558 | - $nums, |
|
| 559 | - $init_lang, |
|
| 560 | - $corps, |
|
| 561 | - $fin_lang, |
|
| 562 | - $trace, |
|
| 563 | - 'BOUCLE'.$id_boucle .' @ '.($boucle->descr['sourcefile']) |
|
| 564 | - ); |
|
| 492 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 493 | + // souhaite invalider ces elements |
|
| 494 | + if (!$constant AND $primary) { |
|
| 495 | + include_spip('inc/invalideur'); |
|
| 496 | + if (function_exists($i = 'calcul_invalideurs')) |
|
| 497 | + $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // gerer le compteur de boucle |
|
| 501 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 502 | + |
|
| 503 | + if ($boucle->partie OR $boucle->cptrows) |
|
| 504 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 505 | + . $boucle->partie |
|
| 506 | + . $corps; |
|
| 507 | + |
|
| 508 | + // depiler la lang de la boucle si besoin |
|
| 509 | + $corps .= $fin_lang_select_public; |
|
| 510 | + |
|
| 511 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 512 | + |
|
| 513 | + if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
|
| 514 | + if (!isset($r[2]) OR (!$r[2])) { |
|
| 515 | + if (!$boucle->numrows) |
|
| 516 | + return "\n\t\$t0 = '';"; |
|
| 517 | + else |
|
| 518 | + $corps = ""; |
|
| 519 | + } else { |
|
| 520 | + $boucle->numrows = true; |
|
| 521 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 522 | + } |
|
| 523 | + } else $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 524 | + |
|
| 525 | + $count = ''; |
|
| 526 | + if (!$boucle->select) { |
|
| 527 | + if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
|
| 528 | + $count = '1'; |
|
| 529 | + else $count = 'count(*)'; |
|
| 530 | + $boucles[$id_boucle]->select[]= $count; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + if ($flag_cpt) |
|
| 534 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 535 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 536 | + else $nums = ''; |
|
| 537 | + |
|
| 538 | + if ($boucle->numrows OR $boucle->mode_partie) { |
|
| 539 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 540 | + . $boucle->mode_partie |
|
| 541 | + . "\n\t"; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Ne calculer la requete que maintenant |
|
| 545 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 546 | + |
|
| 547 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 548 | + ? ("\n\t$init = array();") : '') |
|
| 549 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 550 | + |
|
| 551 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 552 | + |
|
| 553 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 554 | + $init, |
|
| 555 | + $boucle->iterateur, |
|
| 556 | + "\$command", |
|
| 557 | + $contexte, |
|
| 558 | + $nums, |
|
| 559 | + $init_lang, |
|
| 560 | + $corps, |
|
| 561 | + $fin_lang, |
|
| 562 | + $trace, |
|
| 563 | + 'BOUCLE'.$id_boucle .' @ '.($boucle->descr['sourcefile']) |
|
| 564 | + ); |
|
| 565 | 565 | |
| 566 | 566 | # var_dump($a);exit; |
| 567 | - return $a; |
|
| 567 | + return $a; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -581,38 +581,38 @@ discard block |
||
| 581 | 581 | **/ |
| 582 | 582 | function calculer_requete_sql($boucle) |
| 583 | 583 | { |
| 584 | - $init = array(); |
|
| 585 | - $init[] = calculer_dec('table', "'" . $boucle->id_table ."'"); |
|
| 586 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle ."'"); |
|
| 587 | - # En absence de champ c'est un decompte : |
|
| 588 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 589 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 590 | - $init[] = calculer_dec('groupby', 'array(' . (($g=join("\",\n\t\t\"",$boucle->group))?'"'.$g.'"':'') . ")"); |
|
| 591 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select). "\")"); |
|
| 592 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 593 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 594 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 595 | - $init[] = calculer_dec('limit', |
|
| 596 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 597 | - "'".$boucle->limit."'" |
|
| 598 | - : |
|
| 599 | - $boucle->limit)); |
|
| 600 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 601 | - $s = $d = ""; |
|
| 602 | - foreach ($init as $i){ |
|
| 603 | - if (reset($i)) |
|
| 604 | - $s .= "\n\t\t".end($i); |
|
| 605 | - else |
|
| 606 | - $d .= "\n\t".end($i); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 610 | - . $boucle->in |
|
| 611 | - . $boucle->hash |
|
| 612 | - . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 613 | - . $s |
|
| 614 | - . "\n\t}" |
|
| 615 | - . $d; |
|
| 584 | + $init = array(); |
|
| 585 | + $init[] = calculer_dec('table', "'" . $boucle->id_table ."'"); |
|
| 586 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle ."'"); |
|
| 587 | + # En absence de champ c'est un decompte : |
|
| 588 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 589 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 590 | + $init[] = calculer_dec('groupby', 'array(' . (($g=join("\",\n\t\t\"",$boucle->group))?'"'.$g.'"':'') . ")"); |
|
| 591 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select). "\")"); |
|
| 592 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 593 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 594 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 595 | + $init[] = calculer_dec('limit', |
|
| 596 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 597 | + "'".$boucle->limit."'" |
|
| 598 | + : |
|
| 599 | + $boucle->limit)); |
|
| 600 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 601 | + $s = $d = ""; |
|
| 602 | + foreach ($init as $i){ |
|
| 603 | + if (reset($i)) |
|
| 604 | + $s .= "\n\t\t".end($i); |
|
| 605 | + else |
|
| 606 | + $d .= "\n\t".end($i); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 610 | + . $boucle->in |
|
| 611 | + . $boucle->hash |
|
| 612 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 613 | + . $s |
|
| 614 | + . "\n\t}" |
|
| 615 | + . $d; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -630,12 +630,12 @@ discard block |
||
| 630 | 630 | * qui peut être utilisé pour la production d'un tableau array() |
| 631 | 631 | **/ |
| 632 | 632 | function memoriser_contexte_compil($p) { |
| 633 | - return join(',', array( |
|
| 634 | - _q($p->descr['sourcefile']), |
|
| 635 | - _q($p->descr['nom']), |
|
| 636 | - @_q($p->id_boucle), |
|
| 637 | - intval($p->ligne), |
|
| 638 | - '$GLOBALS[\'spip_lang\']')); |
|
| 633 | + return join(',', array( |
|
| 634 | + _q($p->descr['sourcefile']), |
|
| 635 | + _q($p->descr['nom']), |
|
| 636 | + @_q($p->id_boucle), |
|
| 637 | + intval($p->ligne), |
|
| 638 | + '$GLOBALS[\'spip_lang\']')); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -654,25 +654,25 @@ discard block |
||
| 654 | 654 | **/ |
| 655 | 655 | function reconstruire_contexte_compil($context_compil) |
| 656 | 656 | { |
| 657 | - if (!is_array($context_compil)) return $context_compil; |
|
| 658 | - $p = new Contexte; |
|
| 659 | - $p->descr = array('sourcefile' => $context_compil[0], |
|
| 660 | - 'nom' => $context_compil[1]); |
|
| 661 | - $p->id_boucle = $context_compil[2]; |
|
| 662 | - $p->ligne = $context_compil[3]; |
|
| 663 | - $p->lang = $context_compil[4]; |
|
| 664 | - return $p; |
|
| 657 | + if (!is_array($context_compil)) return $context_compil; |
|
| 658 | + $p = new Contexte; |
|
| 659 | + $p->descr = array('sourcefile' => $context_compil[0], |
|
| 660 | + 'nom' => $context_compil[1]); |
|
| 661 | + $p->id_boucle = $context_compil[2]; |
|
| 662 | + $p->ligne = $context_compil[3]; |
|
| 663 | + $p->lang = $context_compil[4]; |
|
| 664 | + return $p; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | // http://doc.spip.org/@calculer_dec |
| 668 | 668 | function calculer_dec($nom, $val) |
| 669 | 669 | { |
| 670 | - $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 671 | - // si une variable apparait dans le calcul de la clause |
|
| 672 | - // il faut la re-evaluer a chaque passage |
|
| 673 | - if ( |
|
| 674 | - strpos($val, '$') !== false |
|
| 675 | - /* |
|
| 670 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 671 | + // si une variable apparait dans le calcul de la clause |
|
| 672 | + // il faut la re-evaluer a chaque passage |
|
| 673 | + if ( |
|
| 674 | + strpos($val, '$') !== false |
|
| 675 | + /* |
|
| 676 | 676 | OR strpos($val, 'sql_') !== false |
| 677 | 677 | OR ( |
| 678 | 678 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -680,67 +680,67 @@ discard block |
||
| 680 | 680 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 681 | 681 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 682 | 682 | )*/ |
| 683 | - ) |
|
| 684 | - $static = ""; |
|
| 683 | + ) |
|
| 684 | + $static = ""; |
|
| 685 | 685 | |
| 686 | - return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
|
| 686 | + return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // http://doc.spip.org/@calculer_dump_array |
| 690 | 690 | function calculer_dump_array($a) |
| 691 | 691 | { |
| 692 | - if (!is_array($a)) return $a ; |
|
| 693 | - $res = ""; |
|
| 694 | - if ($a AND $a[0] == "'?'") |
|
| 692 | + if (!is_array($a)) return $a ; |
|
| 693 | + $res = ""; |
|
| 694 | + if ($a AND $a[0] == "'?'") |
|
| 695 | 695 | return ("(" . calculer_dump_array($a[1]) . |
| 696 | - " ? " . calculer_dump_array($a[2]) . |
|
| 697 | - " : " . calculer_dump_array($a[3]) . |
|
| 698 | - ")"); |
|
| 699 | - else { |
|
| 696 | + " ? " . calculer_dump_array($a[2]) . |
|
| 697 | + " : " . calculer_dump_array($a[3]) . |
|
| 698 | + ")"); |
|
| 699 | + else { |
|
| 700 | 700 | foreach($a as $v) $res .= ", " . calculer_dump_array($v); |
| 701 | 701 | return "\n\t\t\tarray(" . substr($res,2) . ')'; |
| 702 | - } |
|
| 702 | + } |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | // http://doc.spip.org/@calculer_dump_join |
| 706 | 706 | function calculer_dump_join($a) |
| 707 | 707 | { |
| 708 | - $res = ""; |
|
| 709 | - foreach($a as $k => $v) |
|
| 710 | - $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 711 | - return 'array(' . substr($res,2) . ')'; |
|
| 708 | + $res = ""; |
|
| 709 | + foreach($a as $k => $v) |
|
| 710 | + $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 711 | + return 'array(' . substr($res,2) . ')'; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | // http://doc.spip.org/@calculer_from |
| 715 | 715 | function calculer_from(&$boucle) |
| 716 | 716 | { |
| 717 | - $res = ""; |
|
| 718 | - foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 719 | - return 'array(' . substr($res,1) . ')'; |
|
| 717 | + $res = ""; |
|
| 718 | + foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 719 | + return 'array(' . substr($res,1) . ')'; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // http://doc.spip.org/@calculer_from_type |
| 723 | 723 | function calculer_from_type(&$boucle) |
| 724 | 724 | { |
| 725 | - $res = ""; |
|
| 726 | - foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 727 | - return 'array(' . substr($res,1) . ')'; |
|
| 725 | + $res = ""; |
|
| 726 | + foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 727 | + return 'array(' . substr($res,1) . ')'; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | // http://doc.spip.org/@calculer_order |
| 731 | 731 | function calculer_order(&$boucle) |
| 732 | 732 | { |
| 733 | - if (!$order = $boucle->order |
|
| 734 | - AND !$order = $boucle->default_order) |
|
| 735 | - $order = array(); |
|
| 733 | + if (!$order = $boucle->order |
|
| 734 | + AND !$order = $boucle->default_order) |
|
| 735 | + $order = array(); |
|
| 736 | 736 | |
| 737 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 737 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 738 | 738 | $col = "." . $boucle->modificateur['collate']; |
| 739 | 739 | foreach($order as $k=>$o) |
| 740 | 740 | if (strpos($order[$k],'COLLATE')===false) |
| 741 | 741 | $order[$k].= $col; |
| 742 | 742 | }*/ |
| 743 | - return join(', ', $order); |
|
| 743 | + return join(', ', $order); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -750,32 +750,32 @@ discard block |
||
| 750 | 750 | |
| 751 | 751 | // http://doc.spip.org/@calculer_liste |
| 752 | 752 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle='') { |
| 753 | - if (!$tableau) return "''"; |
|
| 754 | - if (!isset($descr['niv'])) $descr['niv'] = 0; |
|
| 755 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 756 | - if ($codes === false) return false; |
|
| 757 | - $n = count($codes); |
|
| 758 | - if (!$n) return "''"; |
|
| 759 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 760 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 761 | - if ($n==1) |
|
| 762 | - return $codes[0]; |
|
| 763 | - else { |
|
| 764 | - $res = ''; |
|
| 765 | - foreach($codes as $code) { |
|
| 766 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 767 | - OR substr($res,-1,1)!=="'") |
|
| 768 | - $res .= " .\n$tab$code"; |
|
| 769 | - else { |
|
| 770 | - $res = substr($res,0,-1) . substr($code,1); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - return '(' . substr($res,2+$descr['niv']) . ')'; |
|
| 774 | - } |
|
| 775 | - } else { |
|
| 776 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv']?$descr['niv']:''); |
|
| 777 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", $codes) . ")))"; |
|
| 778 | - } |
|
| 753 | + if (!$tableau) return "''"; |
|
| 754 | + if (!isset($descr['niv'])) $descr['niv'] = 0; |
|
| 755 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 756 | + if ($codes === false) return false; |
|
| 757 | + $n = count($codes); |
|
| 758 | + if (!$n) return "''"; |
|
| 759 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 760 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 761 | + if ($n==1) |
|
| 762 | + return $codes[0]; |
|
| 763 | + else { |
|
| 764 | + $res = ''; |
|
| 765 | + foreach($codes as $code) { |
|
| 766 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 767 | + OR substr($res,-1,1)!=="'") |
|
| 768 | + $res .= " .\n$tab$code"; |
|
| 769 | + else { |
|
| 770 | + $res = substr($res,0,-1) . substr($code,1); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + return '(' . substr($res,2+$descr['niv']) . ')'; |
|
| 774 | + } |
|
| 775 | + } else { |
|
| 776 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv']?$descr['niv']:''); |
|
| 777 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", $codes) . ")))"; |
|
| 778 | + } |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | define('_REGEXP_COND_VIDE_NONVIDE',"/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
@@ -786,173 +786,173 @@ discard block |
||
| 786 | 786 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 787 | 787 | |
| 788 | 788 | $codes = array(); |
| 789 | - // cas de la boucle recursive |
|
| 790 | - if (is_array($id_boucle)) |
|
| 791 | - $id_boucle = $id_boucle[0]; |
|
| 792 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 793 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 794 | - $mode = _request('var_mode_affiche'); |
|
| 795 | - $err_e_c = ''; |
|
| 796 | - // chaque commentaire introduit dans le code doit commencer |
|
| 797 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 798 | - foreach ($tableau as $p) { |
|
| 799 | - |
|
| 800 | - switch($p->type) { |
|
| 801 | - // texte seul |
|
| 802 | - case 'texte': |
|
| 803 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | - $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | - $avant=''; |
|
| 806 | - $apres=''; |
|
| 807 | - $altern = "''"; |
|
| 808 | - break; |
|
| 809 | - |
|
| 810 | - case 'polyglotte': |
|
| 811 | - $code = ""; |
|
| 812 | - foreach($p->traductions as $k => $v) { |
|
| 813 | - $code .= ",'" . |
|
| 814 | - str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | - "' => '" . |
|
| 816 | - str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | - "'"; |
|
| 818 | - } |
|
| 819 | - $code = "choisir_traduction(array(" . |
|
| 820 | - substr($code,1) . |
|
| 821 | - "))"; |
|
| 822 | - $commentaire= '&'; |
|
| 823 | - $avant=''; |
|
| 824 | - $apres=''; |
|
| 825 | - $altern = "''"; |
|
| 826 | - break; |
|
| 827 | - |
|
| 828 | - // inclure |
|
| 829 | - case 'include': |
|
| 830 | - $p->descr = $descr; |
|
| 831 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | - if ($code === false) { |
|
| 833 | - $err_e_c = true; |
|
| 834 | - $code = "''"; |
|
| 835 | - } else { |
|
| 836 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | - $avant=''; |
|
| 838 | - $apres=''; |
|
| 839 | - $altern = "''"; |
|
| 840 | - } |
|
| 841 | - break; |
|
| 842 | - |
|
| 843 | - // boucle |
|
| 844 | - case TYPE_RECURSIF: |
|
| 845 | - $nom = $p->id_boucle; |
|
| 846 | - $newdescr = $descr; |
|
| 847 | - $newdescr['id_mere'] = $nom; |
|
| 848 | - $newdescr['niv']++; |
|
| 849 | - $avant = calculer_liste($p->avant, |
|
| 850 | - $newdescr, $boucles, $id_boucle); |
|
| 851 | - $apres = calculer_liste($p->apres, |
|
| 852 | - $newdescr, $boucles, $id_boucle); |
|
| 853 | - $newdescr['niv']--; |
|
| 854 | - $altern = calculer_liste($p->altern, |
|
| 855 | - $newdescr, $boucles, $id_boucle); |
|
| 856 | - if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | - $err_e_c = true; |
|
| 858 | - $code = "''"; |
|
| 859 | - } else { |
|
| 860 | - $code = 'BOUCLE' . |
|
| 861 | - str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | - $commentaire= "?$nom"; |
|
| 864 | - if (!$boucles[$nom]->milieu |
|
| 865 | - AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | - if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | - if ($avant<>"''" OR $apres<>"''") |
|
| 868 | - spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | - $avant = $apres = $altern = "''"; |
|
| 870 | - } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | - } |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case 'idiome': |
|
| 875 | - $l = array(); |
|
| 876 | - $code = ''; |
|
| 877 | - foreach ($p->arg as $k => $v) { |
|
| 878 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | - if ($k) { |
|
| 880 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | - } else { |
|
| 882 | - $code = $_v; |
|
| 883 | - } |
|
| 884 | - } |
|
| 885 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | - if ($p->module) { |
|
| 887 | - $m = $p->module .':'.$p->nom_champ; |
|
| 888 | - } elseif ($p->nom_champ) { |
|
| 889 | - $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | - } else { |
|
| 891 | - $m = ''; |
|
| 892 | - } |
|
| 893 | - $code = (!$code ? "'$m'" : |
|
| 894 | - ($m ? "'$m' . $code" : |
|
| 895 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | - $code = "_T($code)"; |
|
| 898 | - if ($p->param) { |
|
| 899 | - $p->id_boucle = $id_boucle; |
|
| 900 | - $p->boucles = &$boucles; |
|
| 901 | - $code = compose_filtres($p, $code); |
|
| 902 | - } |
|
| 903 | - $commentaire = ":"; |
|
| 904 | - $avant=''; |
|
| 905 | - $apres=''; |
|
| 906 | - $altern = "''"; |
|
| 907 | - break; |
|
| 908 | - |
|
| 909 | - case 'champ': |
|
| 910 | - |
|
| 911 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | - $p->id_boucle = $id_boucle; |
|
| 913 | - $p->boucles = &$boucles; |
|
| 914 | - $p->descr = $descr; |
|
| 915 | - #$p->interdire_scripts = true; |
|
| 916 | - $p->type_requete = $type; |
|
| 917 | - |
|
| 918 | - $code = calculer_champ($p); |
|
| 919 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | - $avant = calculer_liste($p->avant, |
|
| 921 | - $descr, $boucles, $id_boucle); |
|
| 922 | - $apres = calculer_liste($p->apres, |
|
| 923 | - $descr, $boucles, $id_boucle); |
|
| 924 | - $altern = "''"; |
|
| 925 | - // Si la valeur est destinee a une comparaison a '' |
|
| 926 | - // forcer la conversion en une chaine par strval |
|
| 927 | - // si ca peut etre autre chose qu'une chaine |
|
| 928 | - if (($avant != "''" OR $apres != "''") |
|
| 929 | - AND $code[0]!= "'" |
|
| 789 | + // cas de la boucle recursive |
|
| 790 | + if (is_array($id_boucle)) |
|
| 791 | + $id_boucle = $id_boucle[0]; |
|
| 792 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 793 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 794 | + $mode = _request('var_mode_affiche'); |
|
| 795 | + $err_e_c = ''; |
|
| 796 | + // chaque commentaire introduit dans le code doit commencer |
|
| 797 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 798 | + foreach ($tableau as $p) { |
|
| 799 | + |
|
| 800 | + switch($p->type) { |
|
| 801 | + // texte seul |
|
| 802 | + case 'texte': |
|
| 803 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | + $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | + $avant=''; |
|
| 806 | + $apres=''; |
|
| 807 | + $altern = "''"; |
|
| 808 | + break; |
|
| 809 | + |
|
| 810 | + case 'polyglotte': |
|
| 811 | + $code = ""; |
|
| 812 | + foreach($p->traductions as $k => $v) { |
|
| 813 | + $code .= ",'" . |
|
| 814 | + str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | + "' => '" . |
|
| 816 | + str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | + "'"; |
|
| 818 | + } |
|
| 819 | + $code = "choisir_traduction(array(" . |
|
| 820 | + substr($code,1) . |
|
| 821 | + "))"; |
|
| 822 | + $commentaire= '&'; |
|
| 823 | + $avant=''; |
|
| 824 | + $apres=''; |
|
| 825 | + $altern = "''"; |
|
| 826 | + break; |
|
| 827 | + |
|
| 828 | + // inclure |
|
| 829 | + case 'include': |
|
| 830 | + $p->descr = $descr; |
|
| 831 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | + if ($code === false) { |
|
| 833 | + $err_e_c = true; |
|
| 834 | + $code = "''"; |
|
| 835 | + } else { |
|
| 836 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | + $avant=''; |
|
| 838 | + $apres=''; |
|
| 839 | + $altern = "''"; |
|
| 840 | + } |
|
| 841 | + break; |
|
| 842 | + |
|
| 843 | + // boucle |
|
| 844 | + case TYPE_RECURSIF: |
|
| 845 | + $nom = $p->id_boucle; |
|
| 846 | + $newdescr = $descr; |
|
| 847 | + $newdescr['id_mere'] = $nom; |
|
| 848 | + $newdescr['niv']++; |
|
| 849 | + $avant = calculer_liste($p->avant, |
|
| 850 | + $newdescr, $boucles, $id_boucle); |
|
| 851 | + $apres = calculer_liste($p->apres, |
|
| 852 | + $newdescr, $boucles, $id_boucle); |
|
| 853 | + $newdescr['niv']--; |
|
| 854 | + $altern = calculer_liste($p->altern, |
|
| 855 | + $newdescr, $boucles, $id_boucle); |
|
| 856 | + if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | + $err_e_c = true; |
|
| 858 | + $code = "''"; |
|
| 859 | + } else { |
|
| 860 | + $code = 'BOUCLE' . |
|
| 861 | + str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | + $commentaire= "?$nom"; |
|
| 864 | + if (!$boucles[$nom]->milieu |
|
| 865 | + AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | + if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | + if ($avant<>"''" OR $apres<>"''") |
|
| 868 | + spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | + $avant = $apres = $altern = "''"; |
|
| 870 | + } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | + } |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case 'idiome': |
|
| 875 | + $l = array(); |
|
| 876 | + $code = ''; |
|
| 877 | + foreach ($p->arg as $k => $v) { |
|
| 878 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | + if ($k) { |
|
| 880 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | + } else { |
|
| 882 | + $code = $_v; |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | + if ($p->module) { |
|
| 887 | + $m = $p->module .':'.$p->nom_champ; |
|
| 888 | + } elseif ($p->nom_champ) { |
|
| 889 | + $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | + } else { |
|
| 891 | + $m = ''; |
|
| 892 | + } |
|
| 893 | + $code = (!$code ? "'$m'" : |
|
| 894 | + ($m ? "'$m' . $code" : |
|
| 895 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | + $code = "_T($code)"; |
|
| 898 | + if ($p->param) { |
|
| 899 | + $p->id_boucle = $id_boucle; |
|
| 900 | + $p->boucles = &$boucles; |
|
| 901 | + $code = compose_filtres($p, $code); |
|
| 902 | + } |
|
| 903 | + $commentaire = ":"; |
|
| 904 | + $avant=''; |
|
| 905 | + $apres=''; |
|
| 906 | + $altern = "''"; |
|
| 907 | + break; |
|
| 908 | + |
|
| 909 | + case 'champ': |
|
| 910 | + |
|
| 911 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | + $p->id_boucle = $id_boucle; |
|
| 913 | + $p->boucles = &$boucles; |
|
| 914 | + $p->descr = $descr; |
|
| 915 | + #$p->interdire_scripts = true; |
|
| 916 | + $p->type_requete = $type; |
|
| 917 | + |
|
| 918 | + $code = calculer_champ($p); |
|
| 919 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | + $avant = calculer_liste($p->avant, |
|
| 921 | + $descr, $boucles, $id_boucle); |
|
| 922 | + $apres = calculer_liste($p->apres, |
|
| 923 | + $descr, $boucles, $id_boucle); |
|
| 924 | + $altern = "''"; |
|
| 925 | + // Si la valeur est destinee a une comparaison a '' |
|
| 926 | + // forcer la conversion en une chaine par strval |
|
| 927 | + // si ca peut etre autre chose qu'une chaine |
|
| 928 | + if (($avant != "''" OR $apres != "''") |
|
| 929 | + AND $code[0]!= "'" |
|
| 930 | 930 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 931 | - AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | - AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | - AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | - $code = "strval($code)"; |
|
| 935 | - break; |
|
| 936 | - |
|
| 937 | - default: |
|
| 938 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | - $code = "''"; |
|
| 940 | - $p->descr = $descr; |
|
| 941 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | - erreur_squelette($err_e_c, $p); |
|
| 943 | - } // switch |
|
| 944 | - |
|
| 945 | - if ($code != "''") { |
|
| 946 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 947 | - $codes[]= (($mode == 'validation') ? |
|
| 948 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 949 | - : (($mode == 'code') ? |
|
| 950 | - "\n// $commentaire\n$code" : |
|
| 951 | - $code)); |
|
| 952 | - } |
|
| 953 | - } // foreach |
|
| 954 | - |
|
| 955 | - return $err_e_c ? false : $codes; |
|
| 931 | + AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | + AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | + AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | + $code = "strval($code)"; |
|
| 935 | + break; |
|
| 936 | + |
|
| 937 | + default: |
|
| 938 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | + $code = "''"; |
|
| 940 | + $p->descr = $descr; |
|
| 941 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | + erreur_squelette($err_e_c, $p); |
|
| 943 | + } // switch |
|
| 944 | + |
|
| 945 | + if ($code != "''") { |
|
| 946 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 947 | + $codes[]= (($mode == 'validation') ? |
|
| 948 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 949 | + : (($mode == 'code') ? |
|
| 950 | + "\n// $commentaire\n$code" : |
|
| 951 | + $code)); |
|
| 952 | + } |
|
| 953 | + } // foreach |
|
| 954 | + |
|
| 955 | + return $err_e_c ? false : $codes; |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | // production d'une expression conditionnelle ((v=EXP) ? (p . v .s) : a) |
@@ -962,41 +962,41 @@ discard block |
||
| 962 | 962 | // http://doc.spip.org/@compile_retour |
| 963 | 963 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) |
| 964 | 964 | { |
| 965 | - if ($avant == "''") $avant = ''; |
|
| 966 | - if ($apres == "''") $apres = ''; |
|
| 967 | - if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 968 | - |
|
| 969 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 970 | - $t = $code; |
|
| 971 | - $cond = ''; |
|
| 972 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE,$code, $r)) { |
|
| 973 | - $t = $r[2]; |
|
| 974 | - $cond = '!' . $r[1]; |
|
| 975 | - } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE,$code, $r)) { |
|
| 976 | - $t = $r[2]; |
|
| 977 | - $cond = $r[1]; |
|
| 978 | - } else { |
|
| 979 | - $t = '$t' . $n; |
|
| 980 | - $cond = "($t = $code)!==''"; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 984 | - $t . |
|
| 985 | - (!$apres ? "" : " . $apres"); |
|
| 986 | - |
|
| 987 | - if ($res !== $t) $res = "($res)"; |
|
| 988 | - return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 965 | + if ($avant == "''") $avant = ''; |
|
| 966 | + if ($apres == "''") $apres = ''; |
|
| 967 | + if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 968 | + |
|
| 969 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 970 | + $t = $code; |
|
| 971 | + $cond = ''; |
|
| 972 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE,$code, $r)) { |
|
| 973 | + $t = $r[2]; |
|
| 974 | + $cond = '!' . $r[1]; |
|
| 975 | + } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE,$code, $r)) { |
|
| 976 | + $t = $r[2]; |
|
| 977 | + $cond = $r[1]; |
|
| 978 | + } else { |
|
| 979 | + $t = '$t' . $n; |
|
| 980 | + $cond = "($t = $code)!==''"; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 984 | + $t . |
|
| 985 | + (!$apres ? "" : " . $apres"); |
|
| 986 | + |
|
| 987 | + if ($res !== $t) $res = "($res)"; |
|
| 988 | + return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | |
| 992 | 992 | function compile_inclure_doublons($lexemes) |
| 993 | 993 | { |
| 994 | - foreach($lexemes as $v) |
|
| 995 | - if($v->type === 'include' AND $v->param) |
|
| 996 | - foreach($v->param as $r) |
|
| 997 | - if (trim($r[0]) === 'doublons') |
|
| 998 | - return true; |
|
| 999 | - return false; |
|
| 994 | + foreach($lexemes as $v) |
|
| 995 | + if($v->type === 'include' AND $v->param) |
|
| 996 | + foreach($v->param as $r) |
|
| 997 | + if (trim($r[0]) === 'doublons') |
|
| 998 | + return true; |
|
| 999 | + return false; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1016,296 +1016,296 @@ discard block |
||
| 1016 | 1016 | |
| 1017 | 1017 | // http://doc.spip.org/@public_compiler_dist |
| 1018 | 1018 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect=''){ |
| 1019 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1020 | - // Bonus : supprime le BOM |
|
| 1021 | - include_spip('inc/charsets'); |
|
| 1022 | - $squelette = transcoder_page($squelette); |
|
| 1023 | - |
|
| 1024 | - // rendre inertes les echappements de #[](){}<> |
|
| 1025 | - $i = 0; |
|
| 1026 | - while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1027 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1028 | - create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
|
| 1029 | - |
|
| 1030 | - $descr = array('nom' => $nom, |
|
| 1031 | - 'gram' => $gram, |
|
| 1032 | - 'sourcefile' => $sourcefile, |
|
| 1033 | - 'squelette' => $squelette); |
|
| 1034 | - |
|
| 1035 | - // Phraser le squelette, selon sa grammaire |
|
| 1036 | - |
|
| 1037 | - $boucles = array(); |
|
| 1038 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1039 | - |
|
| 1040 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1041 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1042 | - |
|
| 1043 | - // restituer les echappements |
|
| 1044 | - if ($esc) |
|
| 1045 | - foreach($boucles as $i=>$boucle) { |
|
| 1046 | - $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
|
| 1047 | - $boucle->return); |
|
| 1048 | - $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
|
| 1049 | - $boucle->descr['squelette']); |
|
| 1050 | - } |
|
| 1019 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1020 | + // Bonus : supprime le BOM |
|
| 1021 | + include_spip('inc/charsets'); |
|
| 1022 | + $squelette = transcoder_page($squelette); |
|
| 1023 | + |
|
| 1024 | + // rendre inertes les echappements de #[](){}<> |
|
| 1025 | + $i = 0; |
|
| 1026 | + while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1027 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1028 | + create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
|
| 1029 | + |
|
| 1030 | + $descr = array('nom' => $nom, |
|
| 1031 | + 'gram' => $gram, |
|
| 1032 | + 'sourcefile' => $sourcefile, |
|
| 1033 | + 'squelette' => $squelette); |
|
| 1034 | + |
|
| 1035 | + // Phraser le squelette, selon sa grammaire |
|
| 1036 | + |
|
| 1037 | + $boucles = array(); |
|
| 1038 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1039 | + |
|
| 1040 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1041 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1042 | + |
|
| 1043 | + // restituer les echappements |
|
| 1044 | + if ($esc) |
|
| 1045 | + foreach($boucles as $i=>$boucle) { |
|
| 1046 | + $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
|
| 1047 | + $boucle->return); |
|
| 1048 | + $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
|
| 1049 | + $boucle->descr['squelette']); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - $debug = ($boucles AND defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 1053 | - if ($debug) { |
|
| 1054 | - include_spip('public/decompiler'); |
|
| 1055 | - foreach($boucles as $id => $boucle) { |
|
| 1056 | - if ($id) |
|
| 1057 | - $decomp = "\n/* BOUCLE " . |
|
| 1058 | - $boucle->type_requete . |
|
| 1059 | - " " . |
|
| 1060 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1061 | - " */\n"; |
|
| 1062 | - else $decomp = ("\n/*\n" . |
|
| 1063 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1064 | - . "\n*/"); |
|
| 1065 | - $boucles[$id]->return = $decomp .$boucle->return; |
|
| 1066 | - $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - return $boucles; |
|
| 1052 | + $debug = ($boucles AND defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 1053 | + if ($debug) { |
|
| 1054 | + include_spip('public/decompiler'); |
|
| 1055 | + foreach($boucles as $id => $boucle) { |
|
| 1056 | + if ($id) |
|
| 1057 | + $decomp = "\n/* BOUCLE " . |
|
| 1058 | + $boucle->type_requete . |
|
| 1059 | + " " . |
|
| 1060 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1061 | + " */\n"; |
|
| 1062 | + else $decomp = ("\n/*\n" . |
|
| 1063 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1064 | + . "\n*/"); |
|
| 1065 | + $boucles[$id]->return = $decomp .$boucle->return; |
|
| 1066 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + return $boucles; |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1074 | 1074 | // Autres specifications comme ci-dessus |
| 1075 | 1075 | |
| 1076 | 1076 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect=''){ |
| 1077 | - static $trouver_table; |
|
| 1078 | - spip_timer('calcul_skel'); |
|
| 1079 | - |
|
| 1080 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 1081 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1082 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1083 | - |
|
| 1084 | - if (!isset($GLOBALS['debug_objets']['principal'])) |
|
| 1085 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1086 | - } |
|
| 1087 | - foreach ($boucles as $id => $boucle) { |
|
| 1088 | - $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1089 | - } |
|
| 1090 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1091 | - |
|
| 1092 | - // Demander la description des tables une fois pour toutes |
|
| 1093 | - // et reperer si les doublons sont demandes |
|
| 1094 | - // pour un inclure ou une boucle document |
|
| 1095 | - // c'est utile a la fonction champs_traitements |
|
| 1096 | - if (!$trouver_table) |
|
| 1097 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1098 | - |
|
| 1099 | - foreach($boucles as $id => $boucle) { |
|
| 1100 | - if (!($type = $boucle->type_requete)) continue; |
|
| 1101 | - if (!$descr['documents'] AND ( |
|
| 1102 | - (($type == 'documents') AND $boucle->doublons) OR |
|
| 1103 | - compile_inclure_doublons($boucle->avant) OR |
|
| 1104 | - compile_inclure_doublons($boucle->apres) OR |
|
| 1105 | - compile_inclure_doublons($boucle->milieu) OR |
|
| 1106 | - compile_inclure_doublons($boucle->altern))) |
|
| 1107 | - $descr['documents'] = true; |
|
| 1108 | - if ($type != TYPE_RECURSIF) { |
|
| 1109 | - if (!$boucles[$id]->sql_serveur AND $connect) |
|
| 1110 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1111 | - |
|
| 1112 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1113 | - if ($g = charger_fonction( |
|
| 1114 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true)) { |
|
| 1115 | - $boucles[$id] = $g($boucle); |
|
| 1116 | - |
|
| 1117 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1118 | - // utiliser les informations donnees par le requeteur |
|
| 1119 | - // cas "php:xx" et "data:xx". |
|
| 1120 | - } else if ($boucle->sql_serveur AND $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1121 | - $requeteur($boucles, $boucle, $id); |
|
| 1122 | - |
|
| 1123 | - // utiliser la description des champs transmis |
|
| 1124 | - } else { |
|
| 1125 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1126 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1127 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1128 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1129 | - if (!$show |
|
| 1130 | - AND $show=$trouver_table($type, strtolower($type))) { |
|
| 1131 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1132 | - } |
|
| 1133 | - if ($show) { |
|
| 1134 | - $boucles[$id]->show = $show; |
|
| 1135 | - // recopie les infos les plus importantes |
|
| 1136 | - $boucles[$id]->primary = $show['key']["PRIMARY KEY"]; |
|
| 1137 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,","",$show['id_table']); |
|
| 1138 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1139 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1140 | - |
|
| 1141 | - $boucles[$id]->descr = &$descr; |
|
| 1142 | - if ((!$boucles[$id]->jointures) |
|
| 1143 | - AND is_array($show['tables_jointures']) |
|
| 1144 | - AND count($x = $show['tables_jointures'])) |
|
| 1145 | - $boucles[$id]->jointures = $x; |
|
| 1146 | - if ($boucles[$id]->jointures_explicites){ |
|
| 1147 | - $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
|
| 1148 | - while ($j=array_pop($jointures)) |
|
| 1149 | - array_unshift($boucles[$id]->jointures,$j); |
|
| 1150 | - } |
|
| 1151 | - } else { |
|
| 1152 | - // Pas une erreur si la table est optionnelle |
|
| 1153 | - if ($boucles[$id]->table_optionnelle) |
|
| 1154 | - $boucles[$id]->type_requete = ''; |
|
| 1155 | - else { |
|
| 1156 | - $boucles[$id]->type_requete = false; |
|
| 1157 | - $boucle = $boucles[$id]; |
|
| 1158 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1159 | - ($boucle->sql_serveur . ":")) . |
|
| 1160 | - $type; |
|
| 1161 | - $msg = array('zbug_table_inconnue', |
|
| 1162 | - array('table' => $x)); |
|
| 1163 | - erreur_squelette($msg, $boucle); |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1171 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1172 | - foreach($boucles as $id => $boucle) { |
|
| 1173 | - if ($boucle->type_requete == TYPE_RECURSIF AND $boucle->param) { |
|
| 1174 | - $boucles[$id]->descr = &$descr; |
|
| 1175 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1176 | - if (!$rec) { |
|
| 1177 | - $msg = array('zbug_boucle_recursive_undef', |
|
| 1178 | - array('nom' => $boucle->param[0])); |
|
| 1179 | - erreur_squelette($msg, $boucle); |
|
| 1180 | - $boucles[$id]->type_requete = false; |
|
| 1181 | - } else { |
|
| 1182 | - $rec->externe = $id; |
|
| 1183 | - $descr['id_mere'] = $id; |
|
| 1184 | - $boucles[$id]->return = |
|
| 1185 | - calculer_liste(array($rec), |
|
| 1186 | - $descr, |
|
| 1187 | - $boucles, |
|
| 1188 | - $boucle->param); |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - foreach($boucles as $id => $boucle) { |
|
| 1193 | - $id = strval($id); // attention au type dans index_pile |
|
| 1194 | - $type = $boucle->type_requete; |
|
| 1195 | - if ($type AND $type != TYPE_RECURSIF) { |
|
| 1196 | - $res = ''; |
|
| 1197 | - if ($boucle->param) { |
|
| 1198 | - // retourne un tableau en cas d'erreur |
|
| 1199 | - $res = calculer_criteres($id, $boucles); |
|
| 1200 | - } |
|
| 1201 | - $descr['id_mere'] = $id; |
|
| 1202 | - $boucles[$id]->return = |
|
| 1203 | - calculer_liste($boucle->milieu, |
|
| 1204 | - $descr, |
|
| 1205 | - $boucles, |
|
| 1206 | - $id); |
|
| 1207 | - // Si les criteres se sont mal compiles |
|
| 1208 | - // ne pas tenter d'assembler le code final |
|
| 1209 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1210 | - if (is_array($res)) { |
|
| 1211 | - $boucles[$id]->type_requete = false; |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // idem pour la racine |
|
| 1217 | - $descr['id_mere'] = ''; |
|
| 1218 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1223 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1224 | - // de'terminables seulement maintenant |
|
| 1225 | - |
|
| 1226 | - foreach($boucles as $id => $boucle) { |
|
| 1227 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1228 | - if ($boucle->return === false) {$corps = false; continue;} |
|
| 1229 | - // appeler la fonction de definition de la boucle |
|
| 1230 | - |
|
| 1231 | - if ($req = $boucle->type_requete) { |
|
| 1232 | - // boucle personnalisée ? |
|
| 1233 | - $table = strtoupper($boucle->type_requete); |
|
| 1234 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1235 | - if ( |
|
| 1236 | - // fonction de boucle avec serveur & table |
|
| 1237 | - (!$serveur OR |
|
| 1238 | - ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1239 | - AND (!function_exists($f = $f."_dist")) |
|
| 1240 | - ) |
|
| 1241 | - ) |
|
| 1242 | - // fonction de boucle avec table |
|
| 1243 | - AND (!function_exists($f = "boucle_".$table)) |
|
| 1244 | - AND (!function_exists($f = $f."_dist")) |
|
| 1245 | - ){ |
|
| 1246 | - // fonction de boucle standard |
|
| 1247 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1248 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1253 | - "static \$connect;\n\t" . |
|
| 1254 | - "\$command['connect'] = \$connect = " . |
|
| 1255 | - _q($boucle->sql_serveur) . |
|
| 1256 | - ";" . |
|
| 1257 | - $f($id, $boucles); |
|
| 1258 | - } else $req = ("\n\treturn '';"); |
|
| 1259 | - |
|
| 1260 | - $boucles[$id]->return = |
|
| 1261 | - "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
|
| 1262 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1263 | - $req . |
|
| 1264 | - "\n}\n"; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1268 | - // retourner False, sinon inserer leur decompilation |
|
| 1269 | - if (is_bool($corps)) return false; |
|
| 1270 | - |
|
| 1271 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1077 | + static $trouver_table; |
|
| 1078 | + spip_timer('calcul_skel'); |
|
| 1079 | + |
|
| 1080 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 1081 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1082 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1083 | + |
|
| 1084 | + if (!isset($GLOBALS['debug_objets']['principal'])) |
|
| 1085 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1086 | + } |
|
| 1087 | + foreach ($boucles as $id => $boucle) { |
|
| 1088 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1089 | + } |
|
| 1090 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1091 | + |
|
| 1092 | + // Demander la description des tables une fois pour toutes |
|
| 1093 | + // et reperer si les doublons sont demandes |
|
| 1094 | + // pour un inclure ou une boucle document |
|
| 1095 | + // c'est utile a la fonction champs_traitements |
|
| 1096 | + if (!$trouver_table) |
|
| 1097 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1098 | + |
|
| 1099 | + foreach($boucles as $id => $boucle) { |
|
| 1100 | + if (!($type = $boucle->type_requete)) continue; |
|
| 1101 | + if (!$descr['documents'] AND ( |
|
| 1102 | + (($type == 'documents') AND $boucle->doublons) OR |
|
| 1103 | + compile_inclure_doublons($boucle->avant) OR |
|
| 1104 | + compile_inclure_doublons($boucle->apres) OR |
|
| 1105 | + compile_inclure_doublons($boucle->milieu) OR |
|
| 1106 | + compile_inclure_doublons($boucle->altern))) |
|
| 1107 | + $descr['documents'] = true; |
|
| 1108 | + if ($type != TYPE_RECURSIF) { |
|
| 1109 | + if (!$boucles[$id]->sql_serveur AND $connect) |
|
| 1110 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1111 | + |
|
| 1112 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1113 | + if ($g = charger_fonction( |
|
| 1114 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true)) { |
|
| 1115 | + $boucles[$id] = $g($boucle); |
|
| 1116 | + |
|
| 1117 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1118 | + // utiliser les informations donnees par le requeteur |
|
| 1119 | + // cas "php:xx" et "data:xx". |
|
| 1120 | + } else if ($boucle->sql_serveur AND $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1121 | + $requeteur($boucles, $boucle, $id); |
|
| 1122 | + |
|
| 1123 | + // utiliser la description des champs transmis |
|
| 1124 | + } else { |
|
| 1125 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1126 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1127 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1128 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1129 | + if (!$show |
|
| 1130 | + AND $show=$trouver_table($type, strtolower($type))) { |
|
| 1131 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1132 | + } |
|
| 1133 | + if ($show) { |
|
| 1134 | + $boucles[$id]->show = $show; |
|
| 1135 | + // recopie les infos les plus importantes |
|
| 1136 | + $boucles[$id]->primary = $show['key']["PRIMARY KEY"]; |
|
| 1137 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,","",$show['id_table']); |
|
| 1138 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1139 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1140 | + |
|
| 1141 | + $boucles[$id]->descr = &$descr; |
|
| 1142 | + if ((!$boucles[$id]->jointures) |
|
| 1143 | + AND is_array($show['tables_jointures']) |
|
| 1144 | + AND count($x = $show['tables_jointures'])) |
|
| 1145 | + $boucles[$id]->jointures = $x; |
|
| 1146 | + if ($boucles[$id]->jointures_explicites){ |
|
| 1147 | + $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
|
| 1148 | + while ($j=array_pop($jointures)) |
|
| 1149 | + array_unshift($boucles[$id]->jointures,$j); |
|
| 1150 | + } |
|
| 1151 | + } else { |
|
| 1152 | + // Pas une erreur si la table est optionnelle |
|
| 1153 | + if ($boucles[$id]->table_optionnelle) |
|
| 1154 | + $boucles[$id]->type_requete = ''; |
|
| 1155 | + else { |
|
| 1156 | + $boucles[$id]->type_requete = false; |
|
| 1157 | + $boucle = $boucles[$id]; |
|
| 1158 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1159 | + ($boucle->sql_serveur . ":")) . |
|
| 1160 | + $type; |
|
| 1161 | + $msg = array('zbug_table_inconnue', |
|
| 1162 | + array('table' => $x)); |
|
| 1163 | + erreur_squelette($msg, $boucle); |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1171 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1172 | + foreach($boucles as $id => $boucle) { |
|
| 1173 | + if ($boucle->type_requete == TYPE_RECURSIF AND $boucle->param) { |
|
| 1174 | + $boucles[$id]->descr = &$descr; |
|
| 1175 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1176 | + if (!$rec) { |
|
| 1177 | + $msg = array('zbug_boucle_recursive_undef', |
|
| 1178 | + array('nom' => $boucle->param[0])); |
|
| 1179 | + erreur_squelette($msg, $boucle); |
|
| 1180 | + $boucles[$id]->type_requete = false; |
|
| 1181 | + } else { |
|
| 1182 | + $rec->externe = $id; |
|
| 1183 | + $descr['id_mere'] = $id; |
|
| 1184 | + $boucles[$id]->return = |
|
| 1185 | + calculer_liste(array($rec), |
|
| 1186 | + $descr, |
|
| 1187 | + $boucles, |
|
| 1188 | + $boucle->param); |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + foreach($boucles as $id => $boucle) { |
|
| 1193 | + $id = strval($id); // attention au type dans index_pile |
|
| 1194 | + $type = $boucle->type_requete; |
|
| 1195 | + if ($type AND $type != TYPE_RECURSIF) { |
|
| 1196 | + $res = ''; |
|
| 1197 | + if ($boucle->param) { |
|
| 1198 | + // retourne un tableau en cas d'erreur |
|
| 1199 | + $res = calculer_criteres($id, $boucles); |
|
| 1200 | + } |
|
| 1201 | + $descr['id_mere'] = $id; |
|
| 1202 | + $boucles[$id]->return = |
|
| 1203 | + calculer_liste($boucle->milieu, |
|
| 1204 | + $descr, |
|
| 1205 | + $boucles, |
|
| 1206 | + $id); |
|
| 1207 | + // Si les criteres se sont mal compiles |
|
| 1208 | + // ne pas tenter d'assembler le code final |
|
| 1209 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1210 | + if (is_array($res)) { |
|
| 1211 | + $boucles[$id]->type_requete = false; |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // idem pour la racine |
|
| 1217 | + $descr['id_mere'] = ''; |
|
| 1218 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1223 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1224 | + // de'terminables seulement maintenant |
|
| 1225 | + |
|
| 1226 | + foreach($boucles as $id => $boucle) { |
|
| 1227 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1228 | + if ($boucle->return === false) {$corps = false; continue;} |
|
| 1229 | + // appeler la fonction de definition de la boucle |
|
| 1230 | + |
|
| 1231 | + if ($req = $boucle->type_requete) { |
|
| 1232 | + // boucle personnalisée ? |
|
| 1233 | + $table = strtoupper($boucle->type_requete); |
|
| 1234 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1235 | + if ( |
|
| 1236 | + // fonction de boucle avec serveur & table |
|
| 1237 | + (!$serveur OR |
|
| 1238 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1239 | + AND (!function_exists($f = $f."_dist")) |
|
| 1240 | + ) |
|
| 1241 | + ) |
|
| 1242 | + // fonction de boucle avec table |
|
| 1243 | + AND (!function_exists($f = "boucle_".$table)) |
|
| 1244 | + AND (!function_exists($f = $f."_dist")) |
|
| 1245 | + ){ |
|
| 1246 | + // fonction de boucle standard |
|
| 1247 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1248 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1253 | + "static \$connect;\n\t" . |
|
| 1254 | + "\$command['connect'] = \$connect = " . |
|
| 1255 | + _q($boucle->sql_serveur) . |
|
| 1256 | + ";" . |
|
| 1257 | + $f($id, $boucles); |
|
| 1258 | + } else $req = ("\n\treturn '';"); |
|
| 1259 | + |
|
| 1260 | + $boucles[$id]->return = |
|
| 1261 | + "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
|
| 1262 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1263 | + $req . |
|
| 1264 | + "\n}\n"; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1268 | + // retourner False, sinon inserer leur decompilation |
|
| 1269 | + if (is_bool($corps)) return false; |
|
| 1270 | + |
|
| 1271 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1272 | 1272 | ' |
| 1273 | - // reporter de maniere securisee les doublons inclus |
|
| 1273 | + // reporter de maniere securisee les doublons inclus |
|
| 1274 | 1274 | .' |
| 1275 | 1275 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1276 | 1276 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1277 | 1277 | |
| 1278 | 1278 | $connect = ' . |
| 1279 | - _q($connect) . '; |
|
| 1279 | + _q($connect) . '; |
|
| 1280 | 1280 | $page = ' . |
| 1281 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1282 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1283 | - // avant de referencer $Cache |
|
| 1284 | - $corps . "; |
|
| 1281 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1282 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1283 | + // avant de referencer $Cache |
|
| 1284 | + $corps . "; |
|
| 1285 | 1285 | |
| 1286 | 1286 | return analyse_resultat_skel(".var_export($nom,true) |
| 1287 | - .", \$Cache, \$page, ".var_export($sourcefile,true)."); |
|
| 1287 | + .", \$Cache, \$page, ".var_export($sourcefile,true)."); |
|
| 1288 | 1288 | }"; |
| 1289 | 1289 | |
| 1290 | - $secondes = spip_timer('calcul_skel'); |
|
| 1291 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1292 | - // $connect n'est pas sûr : on nettoie |
|
| 1293 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1290 | + $secondes = spip_timer('calcul_skel'); |
|
| 1291 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1292 | + // $connect n'est pas sûr : on nettoie |
|
| 1293 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1294 | 1294 | |
| 1295 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1296 | - $code = new Boucle; |
|
| 1297 | - $code->descr = $descr; |
|
| 1298 | - $code->return = ' |
|
| 1295 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1296 | + $code = new Boucle; |
|
| 1297 | + $code->descr = $descr; |
|
| 1298 | + $code->return = ' |
|
| 1299 | 1299 | // |
| 1300 | 1300 | // Fonction principale du squelette ' . |
| 1301 | - $sourcefile . |
|
| 1302 | - ($connect ? " pour $connect" : '') . |
|
| 1303 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1304 | - "\n//\n" . |
|
| 1305 | - $principal; |
|
| 1306 | - |
|
| 1307 | - $boucles[''] = $code; |
|
| 1308 | - return $boucles; |
|
| 1301 | + $sourcefile . |
|
| 1302 | + ($connect ? " pour $connect" : '') . |
|
| 1303 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1304 | + "\n//\n" . |
|
| 1305 | + $principal; |
|
| 1306 | + |
|
| 1307 | + $boucles[''] = $code; |
|
| 1308 | + return $boucles; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | |
@@ -1322,16 +1322,16 @@ discard block |
||
| 1322 | 1322 | * |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1325 | - if (class_exists($boucle->type_requete)) { |
|
| 1326 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1327 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1328 | - } else { |
|
| 1329 | - $x = $boucle->type_requete; |
|
| 1330 | - $boucle->type_requete = false; |
|
| 1331 | - $msg = array('zbug_iterateur_inconnu', |
|
| 1332 | - array('iterateur' => $x)); |
|
| 1333 | - erreur_squelette($msg, $boucle); |
|
| 1334 | - } |
|
| 1325 | + if (class_exists($boucle->type_requete)) { |
|
| 1326 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1327 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1328 | + } else { |
|
| 1329 | + $x = $boucle->type_requete; |
|
| 1330 | + $boucle->type_requete = false; |
|
| 1331 | + $msg = array('zbug_iterateur_inconnu', |
|
| 1332 | + array('iterateur' => $x)); |
|
| 1333 | + erreur_squelette($msg, $boucle); |
|
| 1334 | + } |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | |
@@ -1349,23 +1349,23 @@ discard block |
||
| 1349 | 1349 | * |
| 1350 | 1350 | **/ |
| 1351 | 1351 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1352 | - include_spip('iterateur/data'); |
|
| 1353 | - if ($h = charger_fonction($boucle->type_requete . '_to_array' , 'inc', true)) { |
|
| 1354 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1355 | - $boucles[$id] = $g($boucle); |
|
| 1356 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1357 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1352 | + include_spip('iterateur/data'); |
|
| 1353 | + if ($h = charger_fonction($boucle->type_requete . '_to_array' , 'inc', true)) { |
|
| 1354 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1355 | + $boucles[$id] = $g($boucle); |
|
| 1356 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1357 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1358 | 1358 | |
| 1359 | - } else { |
|
| 1360 | - $x = $boucle->type_requete; |
|
| 1361 | - $boucle->type_requete = false; |
|
| 1362 | - $msg = array('zbug_requeteur_inconnu', |
|
| 1363 | - array( |
|
| 1364 | - 'requeteur' => 'data', |
|
| 1365 | - 'type' => $x |
|
| 1366 | - )); |
|
| 1367 | - erreur_squelette($msg, $boucle); |
|
| 1368 | - } |
|
| 1359 | + } else { |
|
| 1360 | + $x = $boucle->type_requete; |
|
| 1361 | + $boucle->type_requete = false; |
|
| 1362 | + $msg = array('zbug_requeteur_inconnu', |
|
| 1363 | + array( |
|
| 1364 | + 'requeteur' => 'data', |
|
| 1365 | + 'type' => $x |
|
| 1366 | + )); |
|
| 1367 | + erreur_squelette($msg, $boucle); |
|
| 1368 | + } |
|
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | 1371 | ?> |
@@ -33,93 +33,93 @@ discard block |
||
| 33 | 33 | // http://doc.spip.org/@public_composer_dist |
| 34 | 34 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect='') { |
| 35 | 35 | |
| 36 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 37 | - |
|
| 38 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 39 | - if (function_exists($nom)) return $nom; |
|
| 40 | - |
|
| 41 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
|
| 42 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 43 | - |
|
| 44 | - $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
|
| 45 | - |
|
| 46 | - // si squelette est deja compile et perenne, le charger |
|
| 47 | - if (!squelette_obsolete($phpfile, $source)){ |
|
| 48 | - include_once $phpfile; |
|
| 49 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 50 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 51 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 52 | - ## eval('?'.'>'.$skel_code); |
|
| 53 | - # spip_log($skel_code, 'comp') |
|
| 54 | - #} |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if (file_exists($lib = $squelette . '_fonctions'.'.php')){ |
|
| 58 | - include_once $lib; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 62 | - |
|
| 63 | - if (function_exists($nom)) return $nom; |
|
| 64 | - |
|
| 65 | - // charger le source, si possible, et compiler |
|
| 66 | - if (lire_fichier ($source, $skel)) { |
|
| 67 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 68 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 72 | - if (!$skel_code) return false; |
|
| 73 | - |
|
| 74 | - foreach($skel_code as $id => $boucle) { |
|
| 75 | - $f = $boucle->return; |
|
| 76 | - if (@eval("return true; $f ;") === false) { |
|
| 77 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 78 | - $msg = _T('zbug_erreur_compilation'); |
|
| 79 | - erreur_squelette($msg, $boucle); |
|
| 80 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 81 | - // mais prevenir que c'est mort |
|
| 82 | - $nom = ''; |
|
| 83 | - } |
|
| 84 | - // Contexte de compil inutile a present |
|
| 85 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 86 | - $skel_code[$id] = $f; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if ($nom) { |
|
| 90 | - // Si le code est bon, concatener et mettre en cache |
|
| 91 | - if (function_exists($nom)) |
|
| 92 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 93 | - else { |
|
| 94 | - // code semantiquement faux: bug du compilateur |
|
| 95 | - // $boucle est en fait ici la fct principale du squelette |
|
| 96 | - $msg = _T('zbug_erreur_compilation'); |
|
| 97 | - erreur_squelette($msg, $boucle); |
|
| 98 | - $nom = ''; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 103 | - |
|
| 104 | - // Tracer ce qui vient d'etre compile |
|
| 105 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 106 | - |
|
| 107 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 108 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 109 | - AND (_request('var_mode_objet') == $nom) |
|
| 110 | - AND (_request('var_mode_affiche') == 'code') ) |
|
| 111 | - erreur_squelette(); |
|
| 112 | - } |
|
| 113 | - return $nom ? $nom : false; |
|
| 36 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 37 | + |
|
| 38 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 39 | + if (function_exists($nom)) return $nom; |
|
| 40 | + |
|
| 41 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
|
| 42 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 43 | + |
|
| 44 | + $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
|
| 45 | + |
|
| 46 | + // si squelette est deja compile et perenne, le charger |
|
| 47 | + if (!squelette_obsolete($phpfile, $source)){ |
|
| 48 | + include_once $phpfile; |
|
| 49 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 50 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 51 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 52 | + ## eval('?'.'>'.$skel_code); |
|
| 53 | + # spip_log($skel_code, 'comp') |
|
| 54 | + #} |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if (file_exists($lib = $squelette . '_fonctions'.'.php')){ |
|
| 58 | + include_once $lib; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 62 | + |
|
| 63 | + if (function_exists($nom)) return $nom; |
|
| 64 | + |
|
| 65 | + // charger le source, si possible, et compiler |
|
| 66 | + if (lire_fichier ($source, $skel)) { |
|
| 67 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 68 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 72 | + if (!$skel_code) return false; |
|
| 73 | + |
|
| 74 | + foreach($skel_code as $id => $boucle) { |
|
| 75 | + $f = $boucle->return; |
|
| 76 | + if (@eval("return true; $f ;") === false) { |
|
| 77 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 78 | + $msg = _T('zbug_erreur_compilation'); |
|
| 79 | + erreur_squelette($msg, $boucle); |
|
| 80 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 81 | + // mais prevenir que c'est mort |
|
| 82 | + $nom = ''; |
|
| 83 | + } |
|
| 84 | + // Contexte de compil inutile a present |
|
| 85 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 86 | + $skel_code[$id] = $f; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if ($nom) { |
|
| 90 | + // Si le code est bon, concatener et mettre en cache |
|
| 91 | + if (function_exists($nom)) |
|
| 92 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 93 | + else { |
|
| 94 | + // code semantiquement faux: bug du compilateur |
|
| 95 | + // $boucle est en fait ici la fct principale du squelette |
|
| 96 | + $msg = _T('zbug_erreur_compilation'); |
|
| 97 | + erreur_squelette($msg, $boucle); |
|
| 98 | + $nom = ''; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 103 | + |
|
| 104 | + // Tracer ce qui vient d'etre compile |
|
| 105 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 106 | + |
|
| 107 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 108 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 109 | + AND (_request('var_mode_objet') == $nom) |
|
| 110 | + AND (_request('var_mode_affiche') == 'code') ) |
|
| 111 | + erreur_squelette(); |
|
| 112 | + } |
|
| 113 | + return $nom ? $nom : false; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) |
| 117 | 117 | { |
| 118 | 118 | |
| 119 | - // Le dernier index est '' (fonction principale) |
|
| 120 | - $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
|
| 121 | - if (CODE_COMMENTE) |
|
| 122 | - $code = " |
|
| 119 | + // Le dernier index est '' (fonction principale) |
|
| 120 | + $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
|
| 121 | + if (CODE_COMMENTE) |
|
| 122 | + $code = " |
|
| 123 | 123 | /* |
| 124 | 124 | * Squelette : $sourcefile |
| 125 | 125 | * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
@@ -127,97 +127,97 @@ discard block |
||
| 127 | 127 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) ." |
| 128 | 128 | */ " ; |
| 129 | 129 | |
| 130 | - $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
|
| 131 | - if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
|
| 132 | - ecrire_fichier($phpfile, $code); |
|
| 133 | - return $code; |
|
| 130 | + $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
|
| 131 | + if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
|
| 132 | + ecrire_fichier($phpfile, $code); |
|
| 133 | + return $code; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Le squelette compile est-il trop vieux ? |
| 137 | 137 | // http://doc.spip.org/@squelette_obsolete |
| 138 | 138 | function squelette_obsolete($skel, $squelette) { |
| 139 | - static $date_change = null; |
|
| 140 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 141 | - // par hit |
|
| 142 | - if (is_null($date_change)){ |
|
| 143 | - if (@file_exists($fonc = 'mes_fonctions.php')) |
|
| 144 | - $date_change = @filemtime($fonc); # compatibilite |
|
| 145 | - if (defined('_FILE_OPTIONS')) |
|
| 146 | - $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 147 | - } |
|
| 148 | - return ( |
|
| 149 | - (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
|
| 150 | - OR !@file_exists($skel) |
|
| 151 | - OR ((@file_exists($squelette)?@filemtime($squelette):0) |
|
| 152 | - > ($date = @filemtime($skel))) |
|
| 153 | - OR ($date_change > $date) |
|
| 154 | - ); |
|
| 139 | + static $date_change = null; |
|
| 140 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 141 | + // par hit |
|
| 142 | + if (is_null($date_change)){ |
|
| 143 | + if (@file_exists($fonc = 'mes_fonctions.php')) |
|
| 144 | + $date_change = @filemtime($fonc); # compatibilite |
|
| 145 | + if (defined('_FILE_OPTIONS')) |
|
| 146 | + $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 147 | + } |
|
| 148 | + return ( |
|
| 149 | + (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
|
| 150 | + OR !@file_exists($skel) |
|
| 151 | + OR ((@file_exists($squelette)?@filemtime($squelette):0) |
|
| 152 | + > ($date = @filemtime($skel))) |
|
| 153 | + OR ($date_change > $date) |
|
| 154 | + ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Activer l'invalideur de session |
| 158 | 158 | // http://doc.spip.org/@invalideur_session |
| 159 | 159 | function invalideur_session(&$Cache, $code=NULL) { |
| 160 | - $Cache['session']=spip_session(); |
|
| 161 | - return $code; |
|
| 160 | + $Cache['session']=spip_session(); |
|
| 161 | + return $code; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | // http://doc.spip.org/@analyse_resultat_skel |
| 166 | 166 | function analyse_resultat_skel($nom, $cache, $corps, $source='') { |
| 167 | - static $filtres = array(); |
|
| 168 | - $headers = array(); |
|
| 169 | - |
|
| 170 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 171 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 172 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 173 | - if (stripos($corps,'header')!==false |
|
| 174 | - AND preg_match_all( |
|
| 175 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 176 | - $corps, $regs, PREG_SET_ORDER)){ |
|
| 177 | - foreach ($regs as $r) { |
|
| 178 | - $corps = str_replace($r[0], '', $corps); |
|
| 179 | - # $j = Content-Type, et pas content-TYPE. |
|
| 180 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 181 | - |
|
| 182 | - if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | - $headers[$j].="|".$r[3]; |
|
| 184 | - else |
|
| 185 | - $headers[$j] = $r[3]; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 189 | - $process_ins = ( |
|
| 190 | - strpos($corps,'<'.'?') === false |
|
| 191 | - OR |
|
| 192 | - (strpos($corps,'<'.'?xml')!==false AND |
|
| 193 | - strpos(str_replace('<'.'?xml', '', $corps),'<'.'?') === false) |
|
| 194 | - ) |
|
| 195 | - ? 'html' |
|
| 196 | - : 'php'; |
|
| 197 | - |
|
| 198 | - $skel = array( |
|
| 199 | - 'squelette' => $nom, |
|
| 200 | - 'source' => $source, |
|
| 201 | - 'process_ins' => $process_ins, |
|
| 202 | - 'invalideurs' => $cache, |
|
| 203 | - 'entetes' => $headers, |
|
| 204 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 205 | - ); |
|
| 206 | - |
|
| 207 | - // traiter #FILTRE{} et filtres |
|
| 208 | - if (!isset($filtres[$nom])) { |
|
| 209 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes',array('args'=>$skel,'data'=>array())); |
|
| 210 | - } |
|
| 211 | - if (count($filtres[$nom]) OR (isset($headers['X-Spip-Filtre']) AND strlen($headers['X-Spip-Filtre']))) { |
|
| 212 | - include_spip('public/sandbox'); |
|
| 213 | - $corps = sandbox_filtrer_squelette($skel,$corps,strlen($headers['X-Spip-Filtre'])?explode('|', $headers['X-Spip-Filtre']):array(),$filtres[$nom]); |
|
| 214 | - unset($headers['X-Spip-Filtre']); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $skel['entetes'] = $headers; |
|
| 218 | - $skel['texte'] = $corps; |
|
| 219 | - |
|
| 220 | - return $skel; |
|
| 167 | + static $filtres = array(); |
|
| 168 | + $headers = array(); |
|
| 169 | + |
|
| 170 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 171 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 172 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 173 | + if (stripos($corps,'header')!==false |
|
| 174 | + AND preg_match_all( |
|
| 175 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 176 | + $corps, $regs, PREG_SET_ORDER)){ |
|
| 177 | + foreach ($regs as $r) { |
|
| 178 | + $corps = str_replace($r[0], '', $corps); |
|
| 179 | + # $j = Content-Type, et pas content-TYPE. |
|
| 180 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 181 | + |
|
| 182 | + if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | + $headers[$j].="|".$r[3]; |
|
| 184 | + else |
|
| 185 | + $headers[$j] = $r[3]; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 189 | + $process_ins = ( |
|
| 190 | + strpos($corps,'<'.'?') === false |
|
| 191 | + OR |
|
| 192 | + (strpos($corps,'<'.'?xml')!==false AND |
|
| 193 | + strpos(str_replace('<'.'?xml', '', $corps),'<'.'?') === false) |
|
| 194 | + ) |
|
| 195 | + ? 'html' |
|
| 196 | + : 'php'; |
|
| 197 | + |
|
| 198 | + $skel = array( |
|
| 199 | + 'squelette' => $nom, |
|
| 200 | + 'source' => $source, |
|
| 201 | + 'process_ins' => $process_ins, |
|
| 202 | + 'invalideurs' => $cache, |
|
| 203 | + 'entetes' => $headers, |
|
| 204 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 205 | + ); |
|
| 206 | + |
|
| 207 | + // traiter #FILTRE{} et filtres |
|
| 208 | + if (!isset($filtres[$nom])) { |
|
| 209 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes',array('args'=>$skel,'data'=>array())); |
|
| 210 | + } |
|
| 211 | + if (count($filtres[$nom]) OR (isset($headers['X-Spip-Filtre']) AND strlen($headers['X-Spip-Filtre']))) { |
|
| 212 | + include_spip('public/sandbox'); |
|
| 213 | + $corps = sandbox_filtrer_squelette($skel,$corps,strlen($headers['X-Spip-Filtre'])?explode('|', $headers['X-Spip-Filtre']):array(),$filtres[$nom]); |
|
| 214 | + unset($headers['X-Spip-Filtre']); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $skel['entetes'] = $headers; |
|
| 218 | + $skel['texte'] = $corps; |
|
| 219 | + |
|
| 220 | + return $skel; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // |
@@ -236,62 +236,62 @@ discard block |
||
| 236 | 236 | // |
| 237 | 237 | // http://doc.spip.org/@filtre_introduction_dist |
| 238 | 238 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect) { |
| 239 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 240 | - if (strlen($descriptif)) |
|
| 241 | - return propre($descriptif,$connect); |
|
| 242 | - |
|
| 243 | - // De preference ce qui est marque <intro>...</intro> |
|
| 244 | - $intro = ''; |
|
| 245 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 246 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 247 | - $zone = substr($texte, 0, $fin); |
|
| 248 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 249 | - if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") |
|
| 250 | - $zone = substr($zone, $deb + 7); |
|
| 251 | - $intro .= $zone; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 255 | - // qui inclus raccourcis et modeles |
|
| 256 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 257 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 258 | - // des surcharges et enrichissement de propre |
|
| 259 | - // couper doit se faire apres propre |
|
| 260 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 261 | - |
|
| 262 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 263 | - // large et en se mefiant des tableaux #1323 |
|
| 264 | - |
|
| 265 | - if (strlen($intro)) |
|
| 266 | - $texte = $intro; |
|
| 267 | - |
|
| 268 | - else |
|
| 269 | - if (strpos("\n".$texte, "\n|")===false |
|
| 270 | - AND strlen($texte) > 2.5*$longueur){ |
|
| 271 | - if (strpos($texte,"<multi")!==false) |
|
| 272 | - $texte = extraire_multi($texte); |
|
| 273 | - $texte = couper($texte, 2*$longueur); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // ne pas tenir compte des notes |
|
| 277 | - if ($notes = charger_fonction('notes', 'inc', true)) |
|
| 278 | - $notes('','empiler'); |
|
| 279 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 280 | - // dans l'introduction. |
|
| 281 | - $texte = supprime_img($texte, ''); |
|
| 282 | - $texte = propre($texte,$connect); |
|
| 283 | - if ($notes) |
|
| 284 | - $notes('','depiler'); |
|
| 285 | - |
|
| 286 | - if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 287 | - $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
|
| 288 | - |
|
| 289 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 290 | - if ($GLOBALS['toujours_paragrapher']) |
|
| 291 | - // Fermer les paragraphes |
|
| 292 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 293 | - |
|
| 294 | - return $texte; |
|
| 239 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 240 | + if (strlen($descriptif)) |
|
| 241 | + return propre($descriptif,$connect); |
|
| 242 | + |
|
| 243 | + // De preference ce qui est marque <intro>...</intro> |
|
| 244 | + $intro = ''; |
|
| 245 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 246 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 247 | + $zone = substr($texte, 0, $fin); |
|
| 248 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 249 | + if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") |
|
| 250 | + $zone = substr($zone, $deb + 7); |
|
| 251 | + $intro .= $zone; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 255 | + // qui inclus raccourcis et modeles |
|
| 256 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 257 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 258 | + // des surcharges et enrichissement de propre |
|
| 259 | + // couper doit se faire apres propre |
|
| 260 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 261 | + |
|
| 262 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 263 | + // large et en se mefiant des tableaux #1323 |
|
| 264 | + |
|
| 265 | + if (strlen($intro)) |
|
| 266 | + $texte = $intro; |
|
| 267 | + |
|
| 268 | + else |
|
| 269 | + if (strpos("\n".$texte, "\n|")===false |
|
| 270 | + AND strlen($texte) > 2.5*$longueur){ |
|
| 271 | + if (strpos($texte,"<multi")!==false) |
|
| 272 | + $texte = extraire_multi($texte); |
|
| 273 | + $texte = couper($texte, 2*$longueur); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // ne pas tenir compte des notes |
|
| 277 | + if ($notes = charger_fonction('notes', 'inc', true)) |
|
| 278 | + $notes('','empiler'); |
|
| 279 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 280 | + // dans l'introduction. |
|
| 281 | + $texte = supprime_img($texte, ''); |
|
| 282 | + $texte = propre($texte,$connect); |
|
| 283 | + if ($notes) |
|
| 284 | + $notes('','depiler'); |
|
| 285 | + |
|
| 286 | + if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 287 | + $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
|
| 288 | + |
|
| 289 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 290 | + if ($GLOBALS['toujours_paragrapher']) |
|
| 291 | + // Fermer les paragraphes |
|
| 292 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 293 | + |
|
| 294 | + return $texte; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // |
@@ -307,137 +307,137 @@ discard block |
||
| 307 | 307 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 308 | 308 | if ($lang_select) lang_select(); |
| 309 | 309 | ?' |
| 310 | - .'>'); |
|
| 310 | + .'>'); |
|
| 311 | 311 | |
| 312 | 312 | |
| 313 | 313 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 314 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 315 | - $file, |
|
| 316 | - $context_compil[4]?$context_compil[4]:'', |
|
| 317 | - $nom, |
|
| 318 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 319 | - join(', ', array_map('_q', $context_compil))); |
|
| 320 | - return $r; |
|
| 314 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 315 | + $file, |
|
| 316 | + $context_compil[4]?$context_compil[4]:'', |
|
| 317 | + $nom, |
|
| 318 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 319 | + join(', ', array_map('_q', $context_compil))); |
|
| 320 | + return $r; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // http://doc.spip.org/@argumenter_squelette |
| 324 | 324 | function argumenter_squelette($v) { |
| 325 | 325 | |
| 326 | - if (!is_array($v)) |
|
| 327 | - return "'" . texte_script($v) . "'"; |
|
| 328 | - else { |
|
| 329 | - $out = array(); |
|
| 330 | - foreach($v as $k=>$val) |
|
| 331 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 332 | - return 'array(' . join(", ", $out) . ')'; |
|
| 333 | - } |
|
| 326 | + if (!is_array($v)) |
|
| 327 | + return "'" . texte_script($v) . "'"; |
|
| 328 | + else { |
|
| 329 | + $out = array(); |
|
| 330 | + foreach($v as $k=>$val) |
|
| 331 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 332 | + return 'array(' . join(", ", $out) . ')'; |
|
| 333 | + } |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // verifier leurs arguments et filtres, et calculer le code a inclure |
| 337 | 337 | // http://doc.spip.org/@executer_balise_dynamique |
| 338 | 338 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 339 | - $p = strpos($nom,"_"); |
|
| 340 | - $nomfonction = $nom; |
|
| 341 | - $nomfonction_generique = substr($nom,0,$p+1); |
|
| 342 | - if (!$file = include_spip("balise/". strtolower($nomfonction))) { |
|
| 343 | - // pas de fichier associe, passer au traitement generique |
|
| 344 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 345 | - if ($file) { |
|
| 346 | - // et injecter en premier arg le nom de la balise |
|
| 347 | - array_unshift($args,$nom); |
|
| 348 | - // et passer sur la fonction generique pour la suite |
|
| 349 | - $nomfonction = $nomfonction_generique; |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 353 | - erreur_squelette($msg, $context_compil); |
|
| 354 | - return ''; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 358 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 359 | - |
|
| 360 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 361 | - |
|
| 362 | - if (!is_array($r)) return $r; |
|
| 363 | - |
|
| 364 | - // verifier que la fonction dyn est la, |
|
| 365 | - // sinon se replier sur la generique si elle existe |
|
| 366 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 367 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 368 | - if (function_exists('balise_' . $nomfonction_generique . '_dyn')) { |
|
| 369 | - // et lui injecter en premier arg le nom de la balise |
|
| 370 | - array_unshift($r,$nom); |
|
| 371 | - $nomfonction = $nomfonction_generique; |
|
| 372 | - } else { |
|
| 373 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 374 | - erreur_squelette($msg, $context_compil); |
|
| 375 | - return ''; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (!_DIR_RESTREINT) |
|
| 380 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 381 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 339 | + $p = strpos($nom,"_"); |
|
| 340 | + $nomfonction = $nom; |
|
| 341 | + $nomfonction_generique = substr($nom,0,$p+1); |
|
| 342 | + if (!$file = include_spip("balise/". strtolower($nomfonction))) { |
|
| 343 | + // pas de fichier associe, passer au traitement generique |
|
| 344 | + $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 345 | + if ($file) { |
|
| 346 | + // et injecter en premier arg le nom de la balise |
|
| 347 | + array_unshift($args,$nom); |
|
| 348 | + // et passer sur la fonction generique pour la suite |
|
| 349 | + $nomfonction = $nomfonction_generique; |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 353 | + erreur_squelette($msg, $context_compil); |
|
| 354 | + return ''; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 358 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 359 | + |
|
| 360 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 361 | + |
|
| 362 | + if (!is_array($r)) return $r; |
|
| 363 | + |
|
| 364 | + // verifier que la fonction dyn est la, |
|
| 365 | + // sinon se replier sur la generique si elle existe |
|
| 366 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 367 | + $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 368 | + if (function_exists('balise_' . $nomfonction_generique . '_dyn')) { |
|
| 369 | + // et lui injecter en premier arg le nom de la balise |
|
| 370 | + array_unshift($r,$nom); |
|
| 371 | + $nomfonction = $nomfonction_generique; |
|
| 372 | + } else { |
|
| 373 | + $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 374 | + erreur_squelette($msg, $context_compil); |
|
| 375 | + return ''; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (!_DIR_RESTREINT) |
|
| 380 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 381 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // http://doc.spip.org/@lister_objets_avec_logos |
| 385 | 385 | function lister_objets_avec_logos ($type) { |
| 386 | - global $formats_logos; |
|
| 387 | - $logos = array(); |
|
| 388 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 389 | - $type = '/' |
|
| 390 | - . type_du_logo($type) |
|
| 391 | - . "on(\d+)\.(" |
|
| 392 | - . join('|',$formats_logos) |
|
| 393 | - . ")$/"; |
|
| 394 | - |
|
| 395 | - if ($d = @opendir(_DIR_LOGOS)) { |
|
| 396 | - while($f = readdir($d)) { |
|
| 397 | - if (preg_match($type, $f, $r)) |
|
| 398 | - $logos[] = $r[1]; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - @closedir($d); |
|
| 402 | - return join(',',$logos); |
|
| 386 | + global $formats_logos; |
|
| 387 | + $logos = array(); |
|
| 388 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 389 | + $type = '/' |
|
| 390 | + . type_du_logo($type) |
|
| 391 | + . "on(\d+)\.(" |
|
| 392 | + . join('|',$formats_logos) |
|
| 393 | + . ")$/"; |
|
| 394 | + |
|
| 395 | + if ($d = @opendir(_DIR_LOGOS)) { |
|
| 396 | + while($f = readdir($d)) { |
|
| 397 | + if (preg_match($type, $f, $r)) |
|
| 398 | + $logos[] = $r[1]; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + @closedir($d); |
|
| 402 | + return join(',',$logos); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // fonction appelee par la balise #NOTES |
| 406 | 406 | // Renvoyer l'etat courant des notes, le purger et en preparer un nouveau |
| 407 | 407 | // http://doc.spip.org/@calculer_notes |
| 408 | 408 | function calculer_notes() { |
| 409 | - $r=''; |
|
| 410 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 411 | - $r = $notes(array()); |
|
| 412 | - $notes('','depiler'); |
|
| 413 | - $notes('','empiler'); |
|
| 414 | - } |
|
| 415 | - return $r; |
|
| 409 | + $r=''; |
|
| 410 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 411 | + $r = $notes(array()); |
|
| 412 | + $notes('','depiler'); |
|
| 413 | + $notes('','empiler'); |
|
| 414 | + } |
|
| 415 | + return $r; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Selectionner la langue de l'objet dans la boucle, sauf dans les |
| 419 | 419 | // cas ou il ne le faut pas :-) |
| 420 | 420 | function lang_select_public($lang, $lang_select, $titre=null) { |
| 421 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 422 | - if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
|
| 423 | - AND $lang_select !== 'oui') |
|
| 424 | - $lang = $GLOBALS['spip_lang']; |
|
| 425 | - |
|
| 426 | - // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 427 | - elseif (!strlen($lang)) |
|
| 428 | - $lang = $GLOBALS['spip_lang']; |
|
| 429 | - |
|
| 430 | - // Cas 3. l'objet est multilingue ! |
|
| 431 | - elseif ($lang_select !== 'oui' |
|
| 432 | - AND strlen($titre) > 10 |
|
| 433 | - AND strpos($titre, '<multi>') !== false |
|
| 434 | - AND strpos(echappe_html($titre), '<multi>') !== false) |
|
| 435 | - $lang = $GLOBALS['spip_lang']; |
|
| 436 | - |
|
| 437 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 438 | - lang_select($lang); |
|
| 439 | - |
|
| 440 | - return; |
|
| 421 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 422 | + if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
|
| 423 | + AND $lang_select !== 'oui') |
|
| 424 | + $lang = $GLOBALS['spip_lang']; |
|
| 425 | + |
|
| 426 | + // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 427 | + elseif (!strlen($lang)) |
|
| 428 | + $lang = $GLOBALS['spip_lang']; |
|
| 429 | + |
|
| 430 | + // Cas 3. l'objet est multilingue ! |
|
| 431 | + elseif ($lang_select !== 'oui' |
|
| 432 | + AND strlen($titre) > 10 |
|
| 433 | + AND strpos($titre, '<multi>') !== false |
|
| 434 | + AND strpos(echappe_html($titre), '<multi>') !== false) |
|
| 435 | + $lang = $GLOBALS['spip_lang']; |
|
| 436 | + |
|
| 437 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 438 | + lang_select($lang); |
|
| 439 | + |
|
| 440 | + return; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -445,48 +445,48 @@ discard block |
||
| 445 | 445 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 446 | 446 | // http://doc.spip.org/@nettoyer_env_doublons |
| 447 | 447 | function nettoyer_env_doublons($envd) { |
| 448 | - foreach ($envd as $table => $liste) { |
|
| 449 | - $n = ''; |
|
| 450 | - foreach(explode(',',$liste) as $val) { |
|
| 451 | - if ($a = intval($val) AND $val === strval($a)) |
|
| 452 | - $n.= ','.$val; |
|
| 453 | - } |
|
| 454 | - if (strlen($n)) |
|
| 455 | - $envd[$table] = $n; |
|
| 456 | - else |
|
| 457 | - unset($envd[$table]); |
|
| 458 | - } |
|
| 459 | - return $envd; |
|
| 448 | + foreach ($envd as $table => $liste) { |
|
| 449 | + $n = ''; |
|
| 450 | + foreach(explode(',',$liste) as $val) { |
|
| 451 | + if ($a = intval($val) AND $val === strval($a)) |
|
| 452 | + $n.= ','.$val; |
|
| 453 | + } |
|
| 454 | + if (strlen($n)) |
|
| 455 | + $envd[$table] = $n; |
|
| 456 | + else |
|
| 457 | + unset($envd[$table]); |
|
| 458 | + } |
|
| 459 | + return $envd; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // http://doc.spip.org/@match_self |
| 463 | 463 | function match_self($w){ |
| 464 | - if (is_string($w)) return false; |
|
| 465 | - if (is_array($w)) { |
|
| 466 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | - foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | - if ($m=match_self($sw)) return $m; |
|
| 469 | - } |
|
| 470 | - return false; |
|
| 464 | + if (is_string($w)) return false; |
|
| 465 | + if (is_array($w)) { |
|
| 466 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | + foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | + if ($m=match_self($sw)) return $m; |
|
| 469 | + } |
|
| 470 | + return false; |
|
| 471 | 471 | } |
| 472 | 472 | // http://doc.spip.org/@remplace_sous_requete |
| 473 | 473 | function remplace_sous_requete($w,$sousrequete){ |
| 474 | - if (is_array($w)) { |
|
| 475 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | - foreach($w as $k=>$sw) |
|
| 477 | - $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 478 | - } |
|
| 479 | - return $w; |
|
| 474 | + if (is_array($w)) { |
|
| 475 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | + foreach($w as $k=>$sw) |
|
| 477 | + $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 478 | + } |
|
| 479 | + return $w; |
|
| 480 | 480 | } |
| 481 | 481 | // http://doc.spip.org/@trouver_sous_requetes |
| 482 | 482 | function trouver_sous_requetes($where){ |
| 483 | - $where_simples = array(); |
|
| 484 | - $where_sous = array(); |
|
| 485 | - foreach($where as $k=>$w){ |
|
| 486 | - if (match_self($w)) $where_sous[$k] = $w; |
|
| 487 | - else $where_simples[$k] = $w; |
|
| 488 | - } |
|
| 489 | - return array($where_simples,$where_sous); |
|
| 483 | + $where_simples = array(); |
|
| 484 | + $where_sous = array(); |
|
| 485 | + foreach($where as $k=>$w){ |
|
| 486 | + if (match_self($w)) $where_sous[$k] = $w; |
|
| 487 | + else $where_simples[$k] = $w; |
|
| 488 | + } |
|
| 489 | + return array($where_simples,$where_sous); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -511,224 +511,224 @@ discard block |
||
| 511 | 511 | * @return resource |
| 512 | 512 | */ |
| 513 | 513 | function calculer_select ($select = array(), $from = array(), |
| 514 | - $from_type = array(), |
|
| 515 | - $where = array(), $join=array(), |
|
| 516 | - $groupby = array(), $orderby = array(), $limit = '', |
|
| 517 | - $having=array(), $table = '', $id = '', $serveur='', $requeter=true) { |
|
| 518 | - |
|
| 519 | - // retirer les criteres vides: |
|
| 520 | - // {X ?} avec X absent de l'URL |
|
| 521 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 522 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 523 | - $menage = false; |
|
| 524 | - foreach($where as $k => $v) { |
|
| 525 | - if (is_array($v)){ |
|
| 526 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 528 | - else $op = $v[0] ? $v[0] : $v; |
|
| 529 | - } else $op = $v; |
|
| 530 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 531 | - unset($where[$k]); |
|
| 532 | - $menage = true; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 537 | - $groupby = array_diff($groupby,array('')); |
|
| 538 | - |
|
| 539 | - // remplacer les sous requetes recursives au calcul |
|
| 540 | - list($where_simples,$where_sous) = trouver_sous_requetes($where); |
|
| 541 | - foreach($where_sous as $k=>$w) { |
|
| 542 | - $menage = true; |
|
| 543 | - // on recupere la sous requete |
|
| 544 | - $sous = match_self($w); |
|
| 545 | - if ($sous[0]=='SELF') { |
|
| 546 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 547 | - array_push($where_simples,$sous[2]); |
|
| 548 | - $wheresub = array($sous[2],'0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 549 | - $jsub = $join; |
|
| 550 | - // trouver les jointures utiles a |
|
| 551 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 552 | - // ie L1.objet='article' |
|
| 553 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 554 | - $i = 0; |
|
| 555 | - do { |
|
| 556 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 557 | - array($sous[1]." AS id"), |
|
| 558 | - $from, |
|
| 559 | - $from_type, |
|
| 560 | - $wheresub, |
|
| 561 | - $jsub, |
|
| 562 | - array(),array(),'', |
|
| 563 | - $having,$table,$id,$serveur,false).")"); |
|
| 564 | - if (!$i){ |
|
| 565 | - $i = 1; |
|
| 566 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 567 | - foreach ($join as $cle=>$wj){ |
|
| 568 | - if (count($wj)==4 |
|
| 569 | - AND strpos($wherestring,"{$cle}.")!==FALSE |
|
| 570 | - ){ |
|
| 571 | - $i = 0; |
|
| 572 | - $wheresub[] = $wj[3]; |
|
| 573 | - unset($jsub[$cle][3]); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } while ($i++<1); |
|
| 578 | - } |
|
| 579 | - if ($sous[0]=='SUBSELECT') { |
|
| 580 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 581 | - array_push($where_simples,$sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 583 | - $sous[1], # select |
|
| 584 | - $sous[2], #from |
|
| 585 | - array(), #from_type |
|
| 586 | - $sous[3]?(is_array($sous[3])?$sous[3]:array($sous[3])):array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 587 | - array(), #join |
|
| 588 | - $sous[4]?$sous[4]:array(), #groupby |
|
| 589 | - $sous[5]?$sous[5]:array(), #orderby |
|
| 590 | - $sous[6], #limit |
|
| 591 | - $sous[7]?$sous[7]:array(), #having |
|
| 592 | - $table,$id,$serveur,false |
|
| 593 | - ).")"); |
|
| 594 | - } |
|
| 595 | - array_pop($where_simples); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - foreach($having as $k => $v) { |
|
| 599 | - if ((!$v) OR ($v==1) OR ($v=='0=0')) { |
|
| 600 | - unset($having[$k]); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - // Installer les jointures. |
|
| 605 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 606 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 607 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 514 | + $from_type = array(), |
|
| 515 | + $where = array(), $join=array(), |
|
| 516 | + $groupby = array(), $orderby = array(), $limit = '', |
|
| 517 | + $having=array(), $table = '', $id = '', $serveur='', $requeter=true) { |
|
| 518 | + |
|
| 519 | + // retirer les criteres vides: |
|
| 520 | + // {X ?} avec X absent de l'URL |
|
| 521 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 522 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 523 | + $menage = false; |
|
| 524 | + foreach($where as $k => $v) { |
|
| 525 | + if (is_array($v)){ |
|
| 526 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | + elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 528 | + else $op = $v[0] ? $v[0] : $v; |
|
| 529 | + } else $op = $v; |
|
| 530 | + if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 531 | + unset($where[$k]); |
|
| 532 | + $menage = true; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 537 | + $groupby = array_diff($groupby,array('')); |
|
| 538 | + |
|
| 539 | + // remplacer les sous requetes recursives au calcul |
|
| 540 | + list($where_simples,$where_sous) = trouver_sous_requetes($where); |
|
| 541 | + foreach($where_sous as $k=>$w) { |
|
| 542 | + $menage = true; |
|
| 543 | + // on recupere la sous requete |
|
| 544 | + $sous = match_self($w); |
|
| 545 | + if ($sous[0]=='SELF') { |
|
| 546 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 547 | + array_push($where_simples,$sous[2]); |
|
| 548 | + $wheresub = array($sous[2],'0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 549 | + $jsub = $join; |
|
| 550 | + // trouver les jointures utiles a |
|
| 551 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 552 | + // ie L1.objet='article' |
|
| 553 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 554 | + $i = 0; |
|
| 555 | + do { |
|
| 556 | + $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 557 | + array($sous[1]." AS id"), |
|
| 558 | + $from, |
|
| 559 | + $from_type, |
|
| 560 | + $wheresub, |
|
| 561 | + $jsub, |
|
| 562 | + array(),array(),'', |
|
| 563 | + $having,$table,$id,$serveur,false).")"); |
|
| 564 | + if (!$i){ |
|
| 565 | + $i = 1; |
|
| 566 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 567 | + foreach ($join as $cle=>$wj){ |
|
| 568 | + if (count($wj)==4 |
|
| 569 | + AND strpos($wherestring,"{$cle}.")!==FALSE |
|
| 570 | + ){ |
|
| 571 | + $i = 0; |
|
| 572 | + $wheresub[] = $wj[3]; |
|
| 573 | + unset($jsub[$cle][3]); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } while ($i++<1); |
|
| 578 | + } |
|
| 579 | + if ($sous[0]=='SUBSELECT') { |
|
| 580 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 581 | + array_push($where_simples,$sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | + $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 583 | + $sous[1], # select |
|
| 584 | + $sous[2], #from |
|
| 585 | + array(), #from_type |
|
| 586 | + $sous[3]?(is_array($sous[3])?$sous[3]:array($sous[3])):array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 587 | + array(), #join |
|
| 588 | + $sous[4]?$sous[4]:array(), #groupby |
|
| 589 | + $sous[5]?$sous[5]:array(), #orderby |
|
| 590 | + $sous[6], #limit |
|
| 591 | + $sous[7]?$sous[7]:array(), #having |
|
| 592 | + $table,$id,$serveur,false |
|
| 593 | + ).")"); |
|
| 594 | + } |
|
| 595 | + array_pop($where_simples); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + foreach($having as $k => $v) { |
|
| 599 | + if ((!$v) OR ($v==1) OR ($v=='0=0')) { |
|
| 600 | + unset($having[$k]); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + // Installer les jointures. |
|
| 605 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 606 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 607 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 608 | 608 | |
| 609 | - $afrom = array(); |
|
| 610 | - $equiv = array(); |
|
| 611 | - $k = count($join); |
|
| 612 | - foreach(array_reverse($join,true) as $cledef=>$j) { |
|
| 613 | - $cle = $cledef; |
|
| 614 | - // le format de join est : |
|
| 615 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 616 | - if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | - if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 618 | - list($t,$c,$carr,$and) = $join[$cle]; |
|
| 619 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 620 | - // pour compat avec ancienne convention |
|
| 621 | - if (is_numeric($cle)) |
|
| 622 | - $cle = "L$k"; |
|
| 623 | - if (!$menage |
|
| 624 | - OR isset($afrom[$cle]) |
|
| 625 | - OR calculer_jointnul($cle, $select) |
|
| 626 | - OR calculer_jointnul($cle, array_diff_key($join, array($cle=>$join[$cle]))) |
|
| 627 | - OR calculer_jointnul($cle, $having) |
|
| 628 | - OR calculer_jointnul($cle, $where_simples)) { |
|
| 629 | - // corriger les references non explicites dans select |
|
| 630 | - // ou groupby |
|
| 631 | - foreach($select as $i=>$s) { |
|
| 632 | - if ($s == $c) { |
|
| 633 | - $select[$i] = "$cle.$c AS $c"; |
|
| 634 | - break; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - foreach($groupby as $i=>$g) { |
|
| 638 | - if ($g == $c) { |
|
| 639 | - $groupby[$i] = "$cle.$c"; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 644 | - // sans recours a preg_match |
|
| 645 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 646 | - $afrom[$t][$cle] = array("\n" . |
|
| 647 | - (isset($from_type[$cle])?$from_type[$cle]:"INNER")." JOIN", |
|
| 648 | - $from[$cle], |
|
| 649 | - "AS $cle", |
|
| 650 | - "ON (", |
|
| 651 | - "$cle.$c", |
|
| 652 | - "=", |
|
| 653 | - "$t.$carr", |
|
| 654 | - ($and ? "AND ". $and:"") . |
|
| 655 | - ")"); |
|
| 656 | - if (isset($afrom[$cle])){ |
|
| 657 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 658 | - unset($afrom[$cle]); |
|
| 659 | - } |
|
| 660 | - $equiv[]= $carr; |
|
| 661 | - } else { unset($join[$cledef]);} |
|
| 662 | - unset($from[$cle]); |
|
| 663 | - $k--; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - if (count($afrom)) { |
|
| 667 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 668 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 669 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 670 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 671 | - // ou dans |
|
| 672 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 673 | - // qui comporte plusieurs jointures |
|
| 674 | - // ou dans |
|
| 675 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 676 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 677 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 678 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 679 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 680 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 609 | + $afrom = array(); |
|
| 610 | + $equiv = array(); |
|
| 611 | + $k = count($join); |
|
| 612 | + foreach(array_reverse($join,true) as $cledef=>$j) { |
|
| 613 | + $cle = $cledef; |
|
| 614 | + // le format de join est : |
|
| 615 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 616 | + if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | + if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 618 | + list($t,$c,$carr,$and) = $join[$cle]; |
|
| 619 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 620 | + // pour compat avec ancienne convention |
|
| 621 | + if (is_numeric($cle)) |
|
| 622 | + $cle = "L$k"; |
|
| 623 | + if (!$menage |
|
| 624 | + OR isset($afrom[$cle]) |
|
| 625 | + OR calculer_jointnul($cle, $select) |
|
| 626 | + OR calculer_jointnul($cle, array_diff_key($join, array($cle=>$join[$cle]))) |
|
| 627 | + OR calculer_jointnul($cle, $having) |
|
| 628 | + OR calculer_jointnul($cle, $where_simples)) { |
|
| 629 | + // corriger les references non explicites dans select |
|
| 630 | + // ou groupby |
|
| 631 | + foreach($select as $i=>$s) { |
|
| 632 | + if ($s == $c) { |
|
| 633 | + $select[$i] = "$cle.$c AS $c"; |
|
| 634 | + break; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + foreach($groupby as $i=>$g) { |
|
| 638 | + if ($g == $c) { |
|
| 639 | + $groupby[$i] = "$cle.$c"; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 644 | + // sans recours a preg_match |
|
| 645 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 646 | + $afrom[$t][$cle] = array("\n" . |
|
| 647 | + (isset($from_type[$cle])?$from_type[$cle]:"INNER")." JOIN", |
|
| 648 | + $from[$cle], |
|
| 649 | + "AS $cle", |
|
| 650 | + "ON (", |
|
| 651 | + "$cle.$c", |
|
| 652 | + "=", |
|
| 653 | + "$t.$carr", |
|
| 654 | + ($and ? "AND ". $and:"") . |
|
| 655 | + ")"); |
|
| 656 | + if (isset($afrom[$cle])){ |
|
| 657 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 658 | + unset($afrom[$cle]); |
|
| 659 | + } |
|
| 660 | + $equiv[]= $carr; |
|
| 661 | + } else { unset($join[$cledef]);} |
|
| 662 | + unset($from[$cle]); |
|
| 663 | + $k--; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + if (count($afrom)) { |
|
| 667 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 668 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 669 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 670 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 671 | + // ou dans |
|
| 672 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 673 | + // qui comporte plusieurs jointures |
|
| 674 | + // ou dans |
|
| 675 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 676 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 677 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 678 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 679 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 680 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 681 | 681 | |
| 682 | - list($t,$c) = each($from); |
|
| 683 | - reset($from); |
|
| 684 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 685 | - if (!(strpos($t, ' ') OR // jointure des le depart cf boucle_doc |
|
| 686 | - calculer_jointnul($t, $select, $e) OR |
|
| 687 | - calculer_jointnul($t, $join, $e) OR |
|
| 688 | - calculer_jointnul($t, $where, $e) OR |
|
| 689 | - calculer_jointnul($t, $orderby, $e) OR |
|
| 690 | - calculer_jointnul($t, $groupby, $e) OR |
|
| 691 | - calculer_jointnul($t, $having, $e)) |
|
| 692 | - && count($afrom[$t])) { |
|
| 693 | - reset($afrom[$t]); |
|
| 694 | - list($nt,$nfrom) = each($afrom[$t]); |
|
| 695 | - unset($from[$t]); |
|
| 696 | - $from[$nt] = $nfrom[1]; |
|
| 697 | - unset($afrom[$t][$nt]); |
|
| 698 | - $afrom[$nt] = $afrom[$t]; |
|
| 699 | - unset($afrom[$t]); |
|
| 700 | - $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 701 | - $t = $nfrom[4]; |
|
| 702 | - $alias = ""; |
|
| 703 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 704 | - $oldcle = explode('.',$nfrom[6]); |
|
| 705 | - $oldcle = end($oldcle); |
|
| 706 | - $newcle = explode('.',$nfrom[4]); |
|
| 707 | - $newcle = end($newcle); |
|
| 708 | - if ($newcle!=$oldcle){ |
|
| 709 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 710 | - // reprendre simplement ce AS |
|
| 711 | - $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 712 | - if (preg_match($as,implode(',',$select),$m)){ |
|
| 713 | - $alias = ""; |
|
| 714 | - } |
|
| 715 | - else |
|
| 716 | - $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 717 | - } |
|
| 718 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 719 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 720 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 721 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 722 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 723 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 724 | - } |
|
| 725 | - $from = reinjecte_joint($afrom, $from); |
|
| 726 | - } |
|
| 727 | - $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur, $requeter); |
|
| 728 | - $r = sql_select($select, $from, $where, |
|
| 729 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 730 | - unset($GLOBALS['debug']['aucasou']); |
|
| 731 | - return $r; |
|
| 682 | + list($t,$c) = each($from); |
|
| 683 | + reset($from); |
|
| 684 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 685 | + if (!(strpos($t, ' ') OR // jointure des le depart cf boucle_doc |
|
| 686 | + calculer_jointnul($t, $select, $e) OR |
|
| 687 | + calculer_jointnul($t, $join, $e) OR |
|
| 688 | + calculer_jointnul($t, $where, $e) OR |
|
| 689 | + calculer_jointnul($t, $orderby, $e) OR |
|
| 690 | + calculer_jointnul($t, $groupby, $e) OR |
|
| 691 | + calculer_jointnul($t, $having, $e)) |
|
| 692 | + && count($afrom[$t])) { |
|
| 693 | + reset($afrom[$t]); |
|
| 694 | + list($nt,$nfrom) = each($afrom[$t]); |
|
| 695 | + unset($from[$t]); |
|
| 696 | + $from[$nt] = $nfrom[1]; |
|
| 697 | + unset($afrom[$t][$nt]); |
|
| 698 | + $afrom[$nt] = $afrom[$t]; |
|
| 699 | + unset($afrom[$t]); |
|
| 700 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 701 | + $t = $nfrom[4]; |
|
| 702 | + $alias = ""; |
|
| 703 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 704 | + $oldcle = explode('.',$nfrom[6]); |
|
| 705 | + $oldcle = end($oldcle); |
|
| 706 | + $newcle = explode('.',$nfrom[4]); |
|
| 707 | + $newcle = end($newcle); |
|
| 708 | + if ($newcle!=$oldcle){ |
|
| 709 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 710 | + // reprendre simplement ce AS |
|
| 711 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 712 | + if (preg_match($as,implode(',',$select),$m)){ |
|
| 713 | + $alias = ""; |
|
| 714 | + } |
|
| 715 | + else |
|
| 716 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 717 | + } |
|
| 718 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 719 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 720 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 721 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 722 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 723 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 724 | + } |
|
| 725 | + $from = reinjecte_joint($afrom, $from); |
|
| 726 | + } |
|
| 727 | + $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur, $requeter); |
|
| 728 | + $r = sql_select($select, $from, $where, |
|
| 729 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 730 | + unset($GLOBALS['debug']['aucasou']); |
|
| 731 | + return $r; |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -738,18 +738,18 @@ discard block |
||
| 738 | 738 | * @return string |
| 739 | 739 | */ |
| 740 | 740 | function calculer_where_to_string($v, $join = 'AND'){ |
| 741 | - if (empty($v)) |
|
| 742 | - return ''; |
|
| 743 | - |
|
| 744 | - if (!is_array($v)) { |
|
| 745 | - return $v; |
|
| 746 | - } else { |
|
| 747 | - $exp = ""; |
|
| 748 | - if (strtoupper($join) === 'AND') |
|
| 749 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | - else |
|
| 751 | - return $exp . join($join, $v); |
|
| 752 | - } |
|
| 741 | + if (empty($v)) |
|
| 742 | + return ''; |
|
| 743 | + |
|
| 744 | + if (!is_array($v)) { |
|
| 745 | + return $v; |
|
| 746 | + } else { |
|
| 747 | + $exp = ""; |
|
| 748 | + if (strtoupper($join) === 'AND') |
|
| 749 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | + else |
|
| 751 | + return $exp . join($join, $v); |
|
| 752 | + } |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -758,55 +758,55 @@ discard block |
||
| 758 | 758 | // http://doc.spip.org/@calculer_jointnul |
| 759 | 759 | function calculer_jointnul($cle, $exp, $equiv='') |
| 760 | 760 | { |
| 761 | - if (!is_array($exp)) { |
|
| 762 | - if ($equiv) $exp = preg_replace($equiv, '', $exp); |
|
| 763 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 764 | - } else { |
|
| 765 | - foreach($exp as $v) { |
|
| 766 | - if (calculer_jointnul($cle, $v, $equiv)) return true; |
|
| 767 | - } |
|
| 768 | - return false; |
|
| 769 | - } |
|
| 761 | + if (!is_array($exp)) { |
|
| 762 | + if ($equiv) $exp = preg_replace($equiv, '', $exp); |
|
| 763 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 764 | + } else { |
|
| 765 | + foreach($exp as $v) { |
|
| 766 | + if (calculer_jointnul($cle, $v, $equiv)) return true; |
|
| 767 | + } |
|
| 768 | + return false; |
|
| 769 | + } |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // http://doc.spip.org/@reinjecte_joint |
| 773 | 773 | function reinjecte_joint($afrom, $from) |
| 774 | 774 | { |
| 775 | - $from_synth = array(); |
|
| 776 | - foreach($from as $k=>$v){ |
|
| 777 | - $from_synth[$k]=$from[$k]; |
|
| 778 | - if (isset($afrom[$k])) { |
|
| 779 | - foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 780 | - $from_synth["$k@"]= implode(' ',$afrom[$k]); |
|
| 781 | - unset($afrom[$k]); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - return $from_synth; |
|
| 775 | + $from_synth = array(); |
|
| 776 | + foreach($from as $k=>$v){ |
|
| 777 | + $from_synth[$k]=$from[$k]; |
|
| 778 | + if (isset($afrom[$k])) { |
|
| 779 | + foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 780 | + $from_synth["$k@"]= implode(' ',$afrom[$k]); |
|
| 781 | + unset($afrom[$k]); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + return $from_synth; |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // http://doc.spip.org/@remplacer_jointnul |
| 788 | 788 | function remplacer_jointnul($cle, $exp, $equiv='') |
| 789 | 789 | { |
| 790 | - if (!is_array($exp)) { |
|
| 791 | - return preg_replace($equiv, $cle, $exp); |
|
| 792 | - } else { |
|
| 793 | - foreach($exp as $k => $v) { |
|
| 794 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 795 | - } |
|
| 796 | - return $exp; |
|
| 797 | - } |
|
| 790 | + if (!is_array($exp)) { |
|
| 791 | + return preg_replace($equiv, $cle, $exp); |
|
| 792 | + } else { |
|
| 793 | + foreach($exp as $k => $v) { |
|
| 794 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 795 | + } |
|
| 796 | + return $exp; |
|
| 797 | + } |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | // calcul du nom du squelette |
| 801 | 801 | // http://doc.spip.org/@calculer_nom_fonction_squel |
| 802 | 802 | function calculer_nom_fonction_squel($skel, $mime_type='html', $connect='') |
| 803 | 803 | { |
| 804 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 805 | - if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | - $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 807 | - return $mime_type |
|
| 808 | - . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
|
| 809 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
|
| 804 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 805 | + if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | + $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 807 | + return $mime_type |
|
| 808 | + . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
|
| 809 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | ?> |
@@ -15,135 +15,135 @@ |
||
| 15 | 15 | // http://doc.spip.org/@trace_query_start |
| 16 | 16 | function trace_query_start() |
| 17 | 17 | { |
| 18 | - static $trace = '?'; |
|
| 19 | - if ($trace === '?') { |
|
| 20 | - include_spip('inc/autoriser'); |
|
| 21 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 22 | - // A fortiori quand on demande une trace |
|
| 23 | - $trace = isset($_GET['var_profile']) AND (autoriser('debug')); |
|
| 24 | - } |
|
| 25 | - return $trace ? microtime() : 0; |
|
| 18 | + static $trace = '?'; |
|
| 19 | + if ($trace === '?') { |
|
| 20 | + include_spip('inc/autoriser'); |
|
| 21 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 22 | + // A fortiori quand on demande une trace |
|
| 23 | + $trace = isset($_GET['var_profile']) AND (autoriser('debug')); |
|
| 24 | + } |
|
| 25 | + return $trace ? microtime() : 0; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // http://doc.spip.org/@trace_query_end |
| 29 | 29 | function trace_query_end($query, $start, $result, $erreur, $serveur=''){ |
| 30 | - if ($start) |
|
| 31 | - trace_query_chrono($start, microtime(), $query, $result, $serveur); |
|
| 32 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 33 | - if ($erreur AND !preg_match('/^select\b/i', $query)) |
|
| 34 | - erreur_squelette(array(sql_errno($serveur), $erreur, $query)); |
|
| 35 | - return $result; |
|
| 30 | + if ($start) |
|
| 31 | + trace_query_chrono($start, microtime(), $query, $result, $serveur); |
|
| 32 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 33 | + if ($erreur AND !preg_match('/^select\b/i', $query)) |
|
| 34 | + erreur_squelette(array(sql_errno($serveur), $erreur, $query)); |
|
| 35 | + return $result; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // http://doc.spip.org/@trace_query_chrono |
| 39 | 39 | function trace_query_chrono($m1, $m2, $query, $result, $serveur='') |
| 40 | 40 | { |
| 41 | - static $tt = 0, $nb=0; |
|
| 42 | - global $tableau_des_temps; |
|
| 43 | - |
|
| 44 | - include_spip('inc/filtres_mini'); |
|
| 45 | - |
|
| 46 | - $x = _request('var_mode_objet'); |
|
| 47 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 48 | - list(, $boucle, $serveur, $contexte) = $GLOBALS['debug']['aucasou']; |
|
| 49 | - if ($x AND !preg_match("/$boucle\$/", $x)) |
|
| 50 | - return; |
|
| 51 | - if ($serveur) $boucle .= " ($serveur)"; |
|
| 52 | - $boucle = "<b>$boucle</b>"; |
|
| 53 | - } else { |
|
| 54 | - if ($x) return; |
|
| 55 | - $boucle = $contexte = ''; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - list($usec, $sec) = explode(" ", $m1); |
|
| 59 | - list($usec2, $sec2) = explode(" ", $m2); |
|
| 60 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 61 | - $tt += $dt; |
|
| 62 | - $nb++; |
|
| 63 | - |
|
| 64 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2",spip_htmlentities($query)); |
|
| 65 | - $e = sql_explain($query, $serveur); |
|
| 66 | - $r = str_replace('Resource id ','',(is_object($result)?get_class($result):$result)); |
|
| 67 | - $tableau_des_temps[] = array($dt, $nb, $boucle, $q, $e, $r, $contexte); |
|
| 41 | + static $tt = 0, $nb=0; |
|
| 42 | + global $tableau_des_temps; |
|
| 43 | + |
|
| 44 | + include_spip('inc/filtres_mini'); |
|
| 45 | + |
|
| 46 | + $x = _request('var_mode_objet'); |
|
| 47 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 48 | + list(, $boucle, $serveur, $contexte) = $GLOBALS['debug']['aucasou']; |
|
| 49 | + if ($x AND !preg_match("/$boucle\$/", $x)) |
|
| 50 | + return; |
|
| 51 | + if ($serveur) $boucle .= " ($serveur)"; |
|
| 52 | + $boucle = "<b>$boucle</b>"; |
|
| 53 | + } else { |
|
| 54 | + if ($x) return; |
|
| 55 | + $boucle = $contexte = ''; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + list($usec, $sec) = explode(" ", $m1); |
|
| 59 | + list($usec2, $sec2) = explode(" ", $m2); |
|
| 60 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 61 | + $tt += $dt; |
|
| 62 | + $nb++; |
|
| 63 | + |
|
| 64 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2",spip_htmlentities($query)); |
|
| 65 | + $e = sql_explain($query, $serveur); |
|
| 66 | + $r = str_replace('Resource id ','',(is_object($result)?get_class($result):$result)); |
|
| 67 | + $tableau_des_temps[] = array($dt, $nb, $boucle, $q, $e, $r, $contexte); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | function chrono_requete($temps) |
| 72 | 72 | { |
| 73 | - $total = 0; |
|
| 74 | - $hors = "<i>" . _T('zbug_hors_compilation') . "</i>"; |
|
| 75 | - $t = $q = $n = $d = array(); |
|
| 76 | - // Totaliser les temps et completer le Explain |
|
| 77 | - foreach ($temps as $key => $v) { |
|
| 78 | - list($dt, $nb, $boucle, $query, $explain, $res, $contexte) = $v; |
|
| 79 | - if (is_array($contexte)) { |
|
| 80 | - $k = ($contexte[0] . " $boucle"); |
|
| 81 | - include_spip('public/compiler'); |
|
| 82 | - $env = reconstruire_contexte_compil($contexte); |
|
| 83 | - } else $k = $env = $boucle; |
|
| 84 | - |
|
| 85 | - $total += $dt; |
|
| 86 | - $t[$key] = $dt; |
|
| 87 | - $q[$key] = $nb; |
|
| 88 | - $d[$k]+= $dt; |
|
| 89 | - if ($k) @++$n[$k]; |
|
| 90 | - |
|
| 91 | - if (!is_array($explain)) |
|
| 92 | - $explain = array(); |
|
| 93 | - foreach($explain as $j => $v) { |
|
| 94 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 95 | - . str_replace(';','<br />',$v) |
|
| 96 | - . "</td></tr>"; |
|
| 97 | - } |
|
| 98 | - $e = "<table class='explain'>" |
|
| 99 | - . "<caption>" |
|
| 100 | - . $query |
|
| 101 | - . "</caption>" |
|
| 102 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 103 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 104 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 105 | - . join('', $explain) |
|
| 106 | - . "</table>"; |
|
| 107 | - |
|
| 108 | - $temps[$key] = array($e, $env, $k); |
|
| 109 | - } |
|
| 110 | - // Trier par temps d'execution decroissant |
|
| 111 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 112 | - arsort($d); |
|
| 113 | - $i = 1; |
|
| 114 | - $t = array(); |
|
| 115 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 116 | - foreach($temps as $k => $v) { |
|
| 117 | - $titre = strip_tags($v[2]); |
|
| 118 | - $href = quote_amp($GLOBALS['REQUEST_URI'])."#req$i"; |
|
| 119 | - |
|
| 120 | - $t[$v[2]][]= "<span class='spip-debug-arg'> " |
|
| 121 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 122 | - . '</span>' |
|
| 123 | - . ((count($t[$v[2]]) % 10 == 9) ? "<br />" : ''); |
|
| 124 | - $i++; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if ($d['']) { |
|
| 128 | - $d[$hors] = $d['']; |
|
| 129 | - $n[$hors] = $n['']; |
|
| 130 | - $t[$hors] = $t['']; |
|
| 131 | - } |
|
| 132 | - unset($d['']); |
|
| 133 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 134 | - foreach ($d as $k => $v) { |
|
| 135 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 136 | - . join('',$t[$k]); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $navigation = array(_T('zbug_statistiques'), |
|
| 140 | - "<tr><td>" |
|
| 141 | - . join("</td></tr>\n<tr><td>", $d) |
|
| 142 | - . "</td></tr>\n" |
|
| 143 | - . (# _request('var_mode_objet') ? '' : |
|
| 144 | - ("<tr><td>" . count($temps) . "</td><td>" . _T('info_total') . '</td><td class="time">' . $total . "</td><td></td></tr>"))); |
|
| 73 | + $total = 0; |
|
| 74 | + $hors = "<i>" . _T('zbug_hors_compilation') . "</i>"; |
|
| 75 | + $t = $q = $n = $d = array(); |
|
| 76 | + // Totaliser les temps et completer le Explain |
|
| 77 | + foreach ($temps as $key => $v) { |
|
| 78 | + list($dt, $nb, $boucle, $query, $explain, $res, $contexte) = $v; |
|
| 79 | + if (is_array($contexte)) { |
|
| 80 | + $k = ($contexte[0] . " $boucle"); |
|
| 81 | + include_spip('public/compiler'); |
|
| 82 | + $env = reconstruire_contexte_compil($contexte); |
|
| 83 | + } else $k = $env = $boucle; |
|
| 84 | + |
|
| 85 | + $total += $dt; |
|
| 86 | + $t[$key] = $dt; |
|
| 87 | + $q[$key] = $nb; |
|
| 88 | + $d[$k]+= $dt; |
|
| 89 | + if ($k) @++$n[$k]; |
|
| 90 | + |
|
| 91 | + if (!is_array($explain)) |
|
| 92 | + $explain = array(); |
|
| 93 | + foreach($explain as $j => $v) { |
|
| 94 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 95 | + . str_replace(';','<br />',$v) |
|
| 96 | + . "</td></tr>"; |
|
| 97 | + } |
|
| 98 | + $e = "<table class='explain'>" |
|
| 99 | + . "<caption>" |
|
| 100 | + . $query |
|
| 101 | + . "</caption>" |
|
| 102 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 103 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 104 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 105 | + . join('', $explain) |
|
| 106 | + . "</table>"; |
|
| 107 | + |
|
| 108 | + $temps[$key] = array($e, $env, $k); |
|
| 109 | + } |
|
| 110 | + // Trier par temps d'execution decroissant |
|
| 111 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 112 | + arsort($d); |
|
| 113 | + $i = 1; |
|
| 114 | + $t = array(); |
|
| 115 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 116 | + foreach($temps as $k => $v) { |
|
| 117 | + $titre = strip_tags($v[2]); |
|
| 118 | + $href = quote_amp($GLOBALS['REQUEST_URI'])."#req$i"; |
|
| 119 | + |
|
| 120 | + $t[$v[2]][]= "<span class='spip-debug-arg'> " |
|
| 121 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 122 | + . '</span>' |
|
| 123 | + . ((count($t[$v[2]]) % 10 == 9) ? "<br />" : ''); |
|
| 124 | + $i++; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if ($d['']) { |
|
| 128 | + $d[$hors] = $d['']; |
|
| 129 | + $n[$hors] = $n['']; |
|
| 130 | + $t[$hors] = $t['']; |
|
| 131 | + } |
|
| 132 | + unset($d['']); |
|
| 133 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 134 | + foreach ($d as $k => $v) { |
|
| 135 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 136 | + . join('',$t[$k]); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $navigation = array(_T('zbug_statistiques'), |
|
| 140 | + "<tr><td>" |
|
| 141 | + . join("</td></tr>\n<tr><td>", $d) |
|
| 142 | + . "</td></tr>\n" |
|
| 143 | + . (# _request('var_mode_objet') ? '' : |
|
| 144 | + ("<tr><td>" . count($temps) . "</td><td>" . _T('info_total') . '</td><td class="time">' . $total . "</td><td></td></tr>"))); |
|
| 145 | 145 | |
| 146 | - return array($temps, $navigation); |
|
| 146 | + return array($temps, $navigation); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | ?> |