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