@@ -80,6 +80,9 @@ discard block |
||
| 80 | 80 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 81 | 81 | // echappe est un div ou un span |
| 82 | 82 | // http://code.spip.net/@code_echappement |
| 83 | +/** |
|
| 84 | + * @param string $mode |
|
| 85 | + */ |
|
| 83 | 86 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 84 | 87 | if (!strlen($rempl)) { |
| 85 | 88 | return ''; |
@@ -284,6 +287,9 @@ discard block |
||
| 284 | 287 | // Reinserer le javascript de confiance (venant des modeles) |
| 285 | 288 | |
| 286 | 289 | // http://code.spip.net/@echappe_retour_modeles |
| 290 | +/** |
|
| 291 | + * @param string $letexte |
|
| 292 | + */ |
|
| 287 | 293 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 288 | 294 | $letexte = echappe_retour($letexte); |
| 289 | 295 | |
@@ -433,6 +439,9 @@ discard block |
||
| 433 | 439 | } |
| 434 | 440 | |
| 435 | 441 | |
| 442 | +/** |
|
| 443 | + * @param string $letexte |
|
| 444 | + */ |
|
| 436 | 445 | function echapper_faux_tags($letexte) { |
| 437 | 446 | if (strpos($letexte, '<') === false) { |
| 438 | 447 | return $letexte; |
@@ -384,10 +384,12 @@ |
||
| 384 | 384 | $texte = $court; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 387 | + if (strpos($texte, "\n")) { |
|
| 388 | + // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 388 | 389 | { |
| 389 | 390 | $points = ''; |
| 390 | 391 | } |
| 392 | + } |
|
| 391 | 393 | |
| 392 | 394 | // remettre les paragraphes |
| 393 | 395 | $texte = preg_replace("/\r+/", "\n\n", $texte); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define('_BALISES_BLOCS', |
|
| 65 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 66 | - ); |
|
| 64 | + define('_BALISES_BLOCS', |
|
| 65 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 66 | + ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | // echappe est un div ou un span |
| 80 | 80 | // http://code.spip.net/@code_echappement |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ""; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ""; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,64 +106,64 @@ discard block |
||
| 106 | 106 | // Echapper les <html>...</ html> |
| 107 | 107 | // http://code.spip.net/@traiter_echap_html_dist |
| 108 | 108 | function traiter_echap_html_dist($regs) { |
| 109 | - return $regs[3]; |
|
| 109 | + return $regs[3]; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Echapper les <code>...</ code> |
| 113 | 113 | // http://code.spip.net/@traiter_echap_code_dist |
| 114 | 114 | function traiter_echap_code_dist($regs) { |
| 115 | - list(, , $att, $corps) = $regs; |
|
| 116 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 117 | - |
|
| 118 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 119 | - if (is_int(strpos($echap, "\n"))) { |
|
| 120 | - // supprimer les sauts de ligne debut/fin |
|
| 121 | - // (mais pas les espaces => ascii art). |
|
| 122 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 123 | - $echap = nl2br($echap); |
|
| 124 | - $echap = "<div style='text-align: left;' " |
|
| 125 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 126 | - . $echap . "</code></div>"; |
|
| 127 | - } else { |
|
| 128 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $echap = str_replace("\t", " ", $echap); |
|
| 132 | - $echap = str_replace(" ", " ", $echap); |
|
| 133 | - |
|
| 134 | - return $echap; |
|
| 115 | + list(, , $att, $corps) = $regs; |
|
| 116 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 117 | + |
|
| 118 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 119 | + if (is_int(strpos($echap, "\n"))) { |
|
| 120 | + // supprimer les sauts de ligne debut/fin |
|
| 121 | + // (mais pas les espaces => ascii art). |
|
| 122 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 123 | + $echap = nl2br($echap); |
|
| 124 | + $echap = "<div style='text-align: left;' " |
|
| 125 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 126 | + . $echap . "</code></div>"; |
|
| 127 | + } else { |
|
| 128 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $echap = str_replace("\t", " ", $echap); |
|
| 132 | + $echap = str_replace(" ", " ", $echap); |
|
| 133 | + |
|
| 134 | + return $echap; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 138 | 138 | // http://code.spip.net/@traiter_echap_cadre_dist |
| 139 | 139 | function traiter_echap_cadre_dist($regs) { |
| 140 | - $echap = trim(entites_html($regs[3])); |
|
| 141 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 142 | - $lignes = explode("\n", trim($echap)); |
|
| 143 | - $n = 0; |
|
| 144 | - foreach ($lignes as $l) { |
|
| 145 | - $n += floor(strlen($l) / 60) + 1; |
|
| 146 | - } |
|
| 147 | - $n = max($n, 2); |
|
| 148 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 149 | - |
|
| 150 | - return $echap; |
|
| 140 | + $echap = trim(entites_html($regs[3])); |
|
| 141 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 142 | + $lignes = explode("\n", trim($echap)); |
|
| 143 | + $n = 0; |
|
| 144 | + foreach ($lignes as $l) { |
|
| 145 | + $n += floor(strlen($l) / 60) + 1; |
|
| 146 | + } |
|
| 147 | + $n = max($n, 2); |
|
| 148 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 149 | + |
|
| 150 | + return $echap; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // http://code.spip.net/@traiter_echap_frame_dist |
| 154 | 154 | function traiter_echap_frame_dist($regs) { |
| 155 | - return traiter_echap_cadre_dist($regs); |
|
| 155 | + return traiter_echap_cadre_dist($regs); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // http://code.spip.net/@traiter_echap_script_dist |
| 159 | 159 | function traiter_echap_script_dist($regs) { |
| 160 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 161 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 162 | - return highlight_string($regs[0], true); |
|
| 163 | - } |
|
| 160 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 161 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 162 | + return highlight_string($regs[0], true); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Cas normal : le script passe tel quel |
|
| 166 | - return $regs[0]; |
|
| 165 | + // Cas normal : le script passe tel quel |
|
| 166 | + return $regs[0]; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | define('_PROTEGE_BLOCS', ',<(html|code|cadre|frame|script|style)(\s[^>]*)?>(.*)</\1>,UimsS'); |
@@ -172,71 +172,71 @@ discard block |
||
| 172 | 172 | // - pour $no_transform voir le filtre post_autobr dans inc/filtres |
| 173 | 173 | // http://code.spip.net/@echappe_html |
| 174 | 174 | function echappe_html( |
| 175 | - $letexte, |
|
| 176 | - $source = '', |
|
| 177 | - $no_transform = false, |
|
| 178 | - $preg = '' |
|
| 175 | + $letexte, |
|
| 176 | + $source = '', |
|
| 177 | + $no_transform = false, |
|
| 178 | + $preg = '' |
|
| 179 | 179 | ) { |
| 180 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 181 | - return $letexte; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // si le texte recu est long PCRE risque d'exploser, on |
|
| 185 | - // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 186 | - if (($len = strlen($letexte)) > 100000) { |
|
| 187 | - if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 188 | - $old = 100000; |
|
| 189 | - } |
|
| 190 | - if ($len > $old) { |
|
| 191 | - $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 192 | - spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (($preg or strpos($letexte, "<") !== false) |
|
| 197 | - and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 198 | - ) { |
|
| 199 | - foreach ($matches as $regs) { |
|
| 200 | - // echappements tels quels ? |
|
| 201 | - if ($no_transform) { |
|
| 202 | - $echap = $regs[0]; |
|
| 203 | - } // sinon les traiter selon le cas |
|
| 204 | - else { |
|
| 205 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 206 | - $echap = $f($regs); |
|
| 207 | - } else { |
|
| 208 | - if (function_exists($f = $f . '_dist')) { |
|
| 209 | - $echap = $f($regs); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $p = strpos($letexte, $regs[0]); |
|
| 215 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if ($no_transform) { |
|
| 220 | - return $letexte; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 224 | - // seulement si on a echappe les <script> |
|
| 225 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 226 | - // dans une callback autonommee |
|
| 227 | - if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 228 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | - $letexte, $matches, PREG_SET_ORDER) |
|
| 230 | - ) { |
|
| 231 | - foreach ($matches as $regs) { |
|
| 232 | - $letexte = str_replace($regs[0], |
|
| 233 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 234 | - $letexte); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $letexte; |
|
| 180 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 181 | + return $letexte; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // si le texte recu est long PCRE risque d'exploser, on |
|
| 185 | + // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 186 | + if (($len = strlen($letexte)) > 100000) { |
|
| 187 | + if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 188 | + $old = 100000; |
|
| 189 | + } |
|
| 190 | + if ($len > $old) { |
|
| 191 | + $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 192 | + spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (($preg or strpos($letexte, "<") !== false) |
|
| 197 | + and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 198 | + ) { |
|
| 199 | + foreach ($matches as $regs) { |
|
| 200 | + // echappements tels quels ? |
|
| 201 | + if ($no_transform) { |
|
| 202 | + $echap = $regs[0]; |
|
| 203 | + } // sinon les traiter selon le cas |
|
| 204 | + else { |
|
| 205 | + if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 206 | + $echap = $f($regs); |
|
| 207 | + } else { |
|
| 208 | + if (function_exists($f = $f . '_dist')) { |
|
| 209 | + $echap = $f($regs); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $p = strpos($letexte, $regs[0]); |
|
| 215 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if ($no_transform) { |
|
| 220 | + return $letexte; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 224 | + // seulement si on a echappe les <script> |
|
| 225 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 226 | + // dans une callback autonommee |
|
| 227 | + if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 228 | + if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | + $letexte, $matches, PREG_SET_ORDER) |
|
| 230 | + ) { |
|
| 231 | + foreach ($matches as $regs) { |
|
| 232 | + $letexte = str_replace($regs[0], |
|
| 233 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 234 | + $letexte); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $letexte; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // |
@@ -245,52 +245,52 @@ discard block |
||
| 245 | 245 | // par propre() : exemple dans multi et dans typo() |
| 246 | 246 | // http://code.spip.net/@echappe_retour |
| 247 | 247 | function echappe_retour($letexte, $source = '', $filtre = "") { |
| 248 | - if (strpos($letexte, "base64$source")) { |
|
| 249 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 250 | - $max_prof = 5; |
|
| 251 | - while (strpos($letexte, "<") !== false |
|
| 252 | - and |
|
| 253 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | - $letexte, $regs, PREG_SET_ORDER) |
|
| 255 | - and $max_prof--) { |
|
| 256 | - foreach ($regs as $reg) { |
|
| 257 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 258 | - // recherche d'attributs supplementaires |
|
| 259 | - $at = array(); |
|
| 260 | - foreach (array('lang', 'dir') as $attr) { |
|
| 261 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 262 | - $at[$attr] = $a; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - if ($at) { |
|
| 266 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 267 | - foreach ($at as $attr => $a) { |
|
| 268 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - if ($filtre) { |
|
| 272 | - $rempl = $filtre($rempl); |
|
| 273 | - } |
|
| 274 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $letexte; |
|
| 248 | + if (strpos($letexte, "base64$source")) { |
|
| 249 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 250 | + $max_prof = 5; |
|
| 251 | + while (strpos($letexte, "<") !== false |
|
| 252 | + and |
|
| 253 | + preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | + $letexte, $regs, PREG_SET_ORDER) |
|
| 255 | + and $max_prof--) { |
|
| 256 | + foreach ($regs as $reg) { |
|
| 257 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 258 | + // recherche d'attributs supplementaires |
|
| 259 | + $at = array(); |
|
| 260 | + foreach (array('lang', 'dir') as $attr) { |
|
| 261 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 262 | + $at[$attr] = $a; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + if ($at) { |
|
| 266 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 267 | + foreach ($at as $attr => $a) { |
|
| 268 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + if ($filtre) { |
|
| 272 | + $rempl = $filtre($rempl); |
|
| 273 | + } |
|
| 274 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $letexte; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // Reinserer le javascript de confiance (venant des modeles) |
| 283 | 283 | |
| 284 | 284 | // http://code.spip.net/@echappe_retour_modeles |
| 285 | 285 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 286 | - $letexte = echappe_retour($letexte); |
|
| 286 | + $letexte = echappe_retour($letexte); |
|
| 287 | 287 | |
| 288 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 289 | - if ($interdire_scripts) { |
|
| 290 | - $letexte = interdire_scripts($letexte); |
|
| 291 | - } |
|
| 288 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 289 | + if ($interdire_scripts) { |
|
| 290 | + $letexte = interdire_scripts($letexte); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return trim($letexte); |
|
| 293 | + return trim($letexte); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -318,130 +318,130 @@ discard block |
||
| 318 | 318 | * Texte coupé |
| 319 | 319 | **/ |
| 320 | 320 | function couper($texte, $taille = 50, $suite = null) { |
| 321 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 322 | - return ''; |
|
| 323 | - } |
|
| 324 | - $offset = 400 + 2 * $taille; |
|
| 325 | - while ($offset < $length |
|
| 326 | - and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 327 | - $offset = 2 * $offset; |
|
| 328 | - } |
|
| 329 | - if ($offset < $length |
|
| 330 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 331 | - ) { |
|
| 332 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 333 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 334 | - $offset = $p_tag_fermant + 1; |
|
| 335 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 336 | - } |
|
| 337 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 338 | - |
|
| 339 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 340 | - include_spip('inc/lien'); |
|
| 341 | - } |
|
| 342 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 343 | - |
|
| 344 | - // balises de sauts de ligne et paragraphe |
|
| 345 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 347 | - |
|
| 348 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 349 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 350 | - |
|
| 351 | - // supprimer les tags |
|
| 352 | - $texte = supprimer_tags($texte); |
|
| 353 | - $texte = trim(str_replace("\n", " ", $texte)); |
|
| 354 | - $texte .= "\n"; // marquer la fin |
|
| 355 | - |
|
| 356 | - // corriger la longueur de coupe |
|
| 357 | - // en fonction de la presence de caracteres utf |
|
| 358 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 359 | - $long = charset2unicode($texte); |
|
| 360 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 361 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 362 | - $taille += $nbcharutf; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - // couper au mot precedent |
|
| 367 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 368 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 369 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 370 | - if (is_null($suite)) { |
|
| 371 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 372 | - } |
|
| 373 | - $points = $suite; |
|
| 374 | - |
|
| 375 | - // trop court ? ne pas faire de (...) |
|
| 376 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 377 | - $points = ''; |
|
| 378 | - $long = spip_substr($texte, 0, $taille); |
|
| 379 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 380 | - // encore trop court ? couper au caractere |
|
| 381 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 382 | - $texte = $long; |
|
| 383 | - } |
|
| 384 | - } else { |
|
| 385 | - $texte = $court; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 389 | - { |
|
| 390 | - $points = ''; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // remettre les paragraphes |
|
| 394 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 395 | - |
|
| 396 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 397 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 398 | - |
|
| 399 | - return quote_amp(trim($texte)) . $points; |
|
| 321 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 322 | + return ''; |
|
| 323 | + } |
|
| 324 | + $offset = 400 + 2 * $taille; |
|
| 325 | + while ($offset < $length |
|
| 326 | + and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 327 | + $offset = 2 * $offset; |
|
| 328 | + } |
|
| 329 | + if ($offset < $length |
|
| 330 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 331 | + ) { |
|
| 332 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 333 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 334 | + $offset = $p_tag_fermant + 1; |
|
| 335 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 336 | + } |
|
| 337 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 338 | + |
|
| 339 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 340 | + include_spip('inc/lien'); |
|
| 341 | + } |
|
| 342 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 343 | + |
|
| 344 | + // balises de sauts de ligne et paragraphe |
|
| 345 | + $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | + $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 347 | + |
|
| 348 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 349 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 350 | + |
|
| 351 | + // supprimer les tags |
|
| 352 | + $texte = supprimer_tags($texte); |
|
| 353 | + $texte = trim(str_replace("\n", " ", $texte)); |
|
| 354 | + $texte .= "\n"; // marquer la fin |
|
| 355 | + |
|
| 356 | + // corriger la longueur de coupe |
|
| 357 | + // en fonction de la presence de caracteres utf |
|
| 358 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 359 | + $long = charset2unicode($texte); |
|
| 360 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 361 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 362 | + $taille += $nbcharutf; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + // couper au mot precedent |
|
| 367 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 368 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 369 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 370 | + if (is_null($suite)) { |
|
| 371 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 372 | + } |
|
| 373 | + $points = $suite; |
|
| 374 | + |
|
| 375 | + // trop court ? ne pas faire de (...) |
|
| 376 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 377 | + $points = ''; |
|
| 378 | + $long = spip_substr($texte, 0, $taille); |
|
| 379 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 380 | + // encore trop court ? couper au caractere |
|
| 381 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 382 | + $texte = $long; |
|
| 383 | + } |
|
| 384 | + } else { |
|
| 385 | + $texte = $court; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 389 | + { |
|
| 390 | + $points = ''; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // remettre les paragraphes |
|
| 394 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 395 | + |
|
| 396 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 397 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 398 | + |
|
| 399 | + return quote_amp(trim($texte)) . $points; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
| 403 | 403 | // http://code.spip.net/@protege_js_modeles |
| 404 | 404 | function protege_js_modeles($t) { |
| 405 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 406 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 407 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 408 | - include_spip('inc/acces'); |
|
| 409 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 410 | - } |
|
| 411 | - foreach ($r as $regs) { |
|
| 412 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 417 | - include_spip('inc/acces'); |
|
| 418 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 419 | - } |
|
| 420 | - foreach ($r as $regs) { |
|
| 421 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return $t; |
|
| 405 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 406 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 407 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 408 | + include_spip('inc/acces'); |
|
| 409 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 410 | + } |
|
| 411 | + foreach ($r as $regs) { |
|
| 412 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 417 | + include_spip('inc/acces'); |
|
| 418 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 419 | + } |
|
| 420 | + foreach ($r as $regs) { |
|
| 421 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return $t; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
| 430 | 430 | function echapper_faux_tags($letexte) { |
| 431 | - if (strpos($letexte, '<') === false) { |
|
| 432 | - return $letexte; |
|
| 433 | - } |
|
| 434 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 435 | - |
|
| 436 | - $letexte = ""; |
|
| 437 | - while (count($textMatches)) { |
|
| 438 | - // un texte a echapper |
|
| 439 | - $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 440 | - // un tag html qui a servit a faite le split |
|
| 441 | - $letexte .= array_shift($textMatches); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return $letexte; |
|
| 431 | + if (strpos($letexte, '<') === false) { |
|
| 432 | + return $letexte; |
|
| 433 | + } |
|
| 434 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 435 | + |
|
| 436 | + $letexte = ""; |
|
| 437 | + while (count($textMatches)) { |
|
| 438 | + // un texte a echapper |
|
| 439 | + $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 440 | + // un tag html qui a servit a faite le split |
|
| 441 | + $letexte .= array_shift($textMatches); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return $letexte; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -454,44 +454,44 @@ discard block |
||
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | 456 | function echapper_html_suspect($texte, $strict=true) { |
| 457 | - static $echapper_html_suspect; |
|
| 458 | - if (!$texte or !is_string($texte)) { |
|
| 459 | - return $texte; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - if (!isset($echapper_html_suspect)) { |
|
| 463 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 464 | - } |
|
| 465 | - // si fonction personalisee, on delegue |
|
| 466 | - if ($echapper_html_suspect) { |
|
| 467 | - return $echapper_html_suspect($texte, $strict); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - if (strpos($texte, '<') === false |
|
| 471 | - or strpos($texte, '=') === false) { |
|
| 472 | - return $texte; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 476 | - // car sinon on declenche sur les modeles ou ressources |
|
| 477 | - if (!$strict and |
|
| 478 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | - ){ |
|
| 480 | - return $texte; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 484 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 485 | - // donc un test d'egalite est trop strict |
|
| 486 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 487 | - $texte = str_replace("<", "<", $texte); |
|
| 488 | - if (!function_exists('attribut_html')) { |
|
| 489 | - include_spip('inc/filtres'); |
|
| 490 | - } |
|
| 491 | - $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $texte; |
|
| 457 | + static $echapper_html_suspect; |
|
| 458 | + if (!$texte or !is_string($texte)) { |
|
| 459 | + return $texte; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if (!isset($echapper_html_suspect)) { |
|
| 463 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 464 | + } |
|
| 465 | + // si fonction personalisee, on delegue |
|
| 466 | + if ($echapper_html_suspect) { |
|
| 467 | + return $echapper_html_suspect($texte, $strict); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + if (strpos($texte, '<') === false |
|
| 471 | + or strpos($texte, '=') === false) { |
|
| 472 | + return $texte; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 476 | + // car sinon on declenche sur les modeles ou ressources |
|
| 477 | + if (!$strict and |
|
| 478 | + (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | + ){ |
|
| 480 | + return $texte; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 484 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 485 | + // donc un test d'egalite est trop strict |
|
| 486 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 487 | + $texte = str_replace("<", "<", $texte); |
|
| 488 | + if (!function_exists('attribut_html')) { |
|
| 489 | + include_spip('inc/filtres'); |
|
| 490 | + } |
|
| 491 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $texte; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
@@ -512,27 +512,27 @@ discard block |
||
| 512 | 512 | * Texte sécurisé |
| 513 | 513 | **/ |
| 514 | 514 | function safehtml($t) { |
| 515 | - static $safehtml; |
|
| 516 | - |
|
| 517 | - if (!$t or !is_string($t)) { |
|
| 518 | - return $t; |
|
| 519 | - } |
|
| 520 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 521 | - if (strpos($t, '<') === false) { |
|
| 522 | - return str_replace("\x00", '', $t); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $t = interdire_scripts($t); // jolifier le php |
|
| 526 | - $t = echappe_js($t); |
|
| 527 | - |
|
| 528 | - if (!isset($safehtml)) { |
|
| 529 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 530 | - } |
|
| 531 | - if ($safehtml) { |
|
| 532 | - $t = $safehtml($t); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 515 | + static $safehtml; |
|
| 516 | + |
|
| 517 | + if (!$t or !is_string($t)) { |
|
| 518 | + return $t; |
|
| 519 | + } |
|
| 520 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 521 | + if (strpos($t, '<') === false) { |
|
| 522 | + return str_replace("\x00", '', $t); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $t = interdire_scripts($t); // jolifier le php |
|
| 526 | + $t = echappe_js($t); |
|
| 527 | + |
|
| 528 | + if (!isset($safehtml)) { |
|
| 529 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 530 | + } |
|
| 531 | + if ($safehtml) { |
|
| 532 | + $t = $safehtml($t); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | * Texte sans les modèles d'image |
| 555 | 555 | **/ |
| 556 | 556 | function supprime_img($letexte, $message = null) { |
| 557 | - if ($message === null) { |
|
| 558 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 559 | - } |
|
| 557 | + if ($message === null) { |
|
| 558 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 562 | - $message, $letexte); |
|
| 561 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 562 | + $message, $letexte); |
|
| 563 | 563 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | // celle du texte) et public (spip_lang est la langue du texte) |
| 45 | 45 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 48 | 48 | if ($dir == 'rtl') { |
| 49 | 49 | $p .= '_rtl'; |
| 50 | 50 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Tester si on echappe en span ou en div |
| 87 | 87 | if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 88 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | // Echapper les <code>...</ code> |
| 113 | 113 | // http://code.spip.net/@traiter_echap_code_dist |
| 114 | 114 | function traiter_echap_code_dist($regs) { |
| 115 | - list(, , $att, $corps) = $regs; |
|
| 115 | + list(,, $att, $corps) = $regs; |
|
| 116 | 116 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 117 | 117 | |
| 118 | 118 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | $echap = nl2br($echap); |
| 124 | 124 | $echap = "<div style='text-align: left;' " |
| 125 | 125 | . "class='spip_code' dir='ltr'><code$att>" |
| 126 | - . $echap . "</code></div>"; |
|
| 126 | + . $echap."</code></div>"; |
|
| 127 | 127 | } else { |
| 128 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 128 | + $echap = "<code$att class='spip_code' dir='ltr'>".$echap."</code>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $echap = str_replace("\t", " ", $echap); |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | $echap = $regs[0]; |
| 203 | 203 | } // sinon les traiter selon le cas |
| 204 | 204 | else { |
| 205 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 205 | + if (function_exists($f = 'traiter_echap_'.strtolower($regs[1]))) { |
|
| 206 | 206 | $echap = $f($regs); |
| 207 | 207 | } else { |
| 208 | - if (function_exists($f = $f . '_dist')) { |
|
| 208 | + if (function_exists($f = $f.'_dist')) { |
|
| 209 | 209 | $echap = $f($regs); |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | // (derogatoire car on ne peut pas faire passer < ? ... ? > |
| 226 | 226 | // dans une callback autonommee |
| 227 | 227 | if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
| 228 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 228 | + if (strpos($letexte, "<"."?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | 229 | $letexte, $matches, PREG_SET_ORDER) |
| 230 | 230 | ) { |
| 231 | 231 | foreach ($matches as $regs) { |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $max_prof = 5; |
| 251 | 251 | while (strpos($letexte, "<") !== false |
| 252 | 252 | and |
| 253 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 253 | + preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | 254 | $letexte, $regs, PREG_SET_ORDER) |
| 255 | 255 | and $max_prof--) { |
| 256 | 256 | foreach ($regs as $reg) { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | if ($at) { |
| 266 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 266 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 267 | 267 | foreach ($at as $attr => $a) { |
| 268 | 268 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 269 | 269 | } |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | $texte = nettoyer_raccourcis_typo($texte); |
| 343 | 343 | |
| 344 | 344 | // balises de sauts de ligne et paragraphe |
| 345 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 345 | + $texte = preg_replace("/<p( [^>]*)?".">/", "\r", $texte); |
|
| 346 | + $texte = preg_replace("/<br( [^>]*)?".">/", "\n", $texte); |
|
| 347 | 347 | |
| 348 | 348 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 349 | 349 | $texte = str_replace("\n\n", "\r", $texte); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | // supprimer les tags |
| 352 | 352 | $texte = supprimer_tags($texte); |
| 353 | 353 | $texte = trim(str_replace("\n", " ", $texte)); |
| 354 | - $texte .= "\n"; // marquer la fin |
|
| 354 | + $texte .= "\n"; // marquer la fin |
|
| 355 | 355 | |
| 356 | 356 | // corriger la longueur de coupe |
| 357 | 357 | // en fonction de la presence de caracteres utf |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | // couper au mot precedent |
| 367 | 367 | $long = spip_substr($texte, 0, max($taille - 4, 1)); |
| 368 | 368 | $u = $GLOBALS['meta']['pcre_u']; |
| 369 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 369 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 370 | 370 | if (is_null($suite)) { |
| 371 | 371 | $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
| 372 | 372 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 377 | 377 | $points = ''; |
| 378 | 378 | $long = spip_substr($texte, 0, $taille); |
| 379 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 379 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 380 | 380 | // encore trop court ? couper au caractere |
| 381 | 381 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 382 | 382 | $texte = $long; |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | // supprimer l'eventuelle entite finale mal coupee |
| 397 | 397 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 398 | 398 | |
| 399 | - return quote_amp(trim($texte)) . $points; |
|
| 399 | + return quote_amp(trim($texte)).$points; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -409,16 +409,16 @@ discard block |
||
| 409 | 409 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 410 | 410 | } |
| 411 | 411 | foreach ($r as $regs) { |
| 412 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 412 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 415 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | 416 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 417 | 417 | include_spip('inc/acces'); |
| 418 | 418 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 419 | 419 | } |
| 420 | 420 | foreach ($r as $regs) { |
| 421 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 421 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | * @param bool $strict |
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | -function echapper_html_suspect($texte, $strict=true) { |
|
| 456 | +function echapper_html_suspect($texte, $strict = true) { |
|
| 457 | 457 | static $echapper_html_suspect; |
| 458 | 458 | if (!$texte or !is_string($texte)) { |
| 459 | 459 | return $texte; |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
| 476 | 476 | // car sinon on declenche sur les modeles ou ressources |
| 477 | 477 | if (!$strict and |
| 478 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | - ){ |
|
| 478 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | + ) { |
|
| 480 | 480 | return $texte; |
| 481 | 481 | } |
| 482 | 482 | |
@@ -555,9 +555,9 @@ discard block |
||
| 555 | 555 | **/ |
| 556 | 556 | function supprime_img($letexte, $message = null) { |
| 557 | 557 | if ($message === null) { |
| 558 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 558 | + $message = '('._T('img_indisponible').')'; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 561 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 562 | 562 | $message, $letexte); |
| 563 | 563 | } |
@@ -98,6 +98,10 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // http://code.spip.net/@phraser_polyglotte |
| 101 | +/** |
|
| 102 | + * @param string $texte |
|
| 103 | + * @param integer $ligne |
|
| 104 | + */ |
|
| 101 | 105 | function phraser_polyglotte($texte, $ligne, $result) { |
| 102 | 106 | |
| 103 | 107 | if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
@@ -260,6 +264,9 @@ discard block |
||
| 260 | 264 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 261 | 265 | |
| 262 | 266 | // http://code.spip.net/@phraser_champs_etendus |
| 267 | +/** |
|
| 268 | + * @param integer $ligne |
|
| 269 | + */ |
|
| 263 | 270 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 264 | 271 | if ($texte === "") { |
| 265 | 272 | return $result; |
@@ -279,6 +286,9 @@ discard block |
||
| 279 | 286 | // Tres chevelu |
| 280 | 287 | |
| 281 | 288 | // http://code.spip.net/@phraser_args |
| 289 | +/** |
|
| 290 | + * @param string $fin |
|
| 291 | + */ |
|
| 282 | 292 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) { |
| 283 | 293 | $texte = ltrim($texte); |
| 284 | 294 | while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
@@ -293,6 +303,9 @@ discard block |
||
| 293 | 303 | } |
| 294 | 304 | |
| 295 | 305 | // http://code.spip.net/@phraser_arg |
| 306 | +/** |
|
| 307 | + * @param string $texte |
|
| 308 | + */ |
|
| 296 | 309 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 297 | 310 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 298 | 311 | $suite = ltrim($match[2]); |
@@ -430,6 +443,9 @@ discard block |
||
| 430 | 443 | |
| 431 | 444 | |
| 432 | 445 | // http://code.spip.net/@phraser_champs_exterieurs |
| 446 | +/** |
|
| 447 | + * @param string $texte |
|
| 448 | + */ |
|
| 433 | 449 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 434 | 450 | $res = array(); |
| 435 | 451 | while (($p = strpos($texte, "%$sep")) !== false) { |
@@ -449,6 +465,9 @@ discard block |
||
| 449 | 465 | } |
| 450 | 466 | |
| 451 | 467 | // http://code.spip.net/@phraser_champs_interieurs |
| 468 | +/** |
|
| 469 | + * @param string $sep |
|
| 470 | + */ |
|
| 452 | 471 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 453 | 472 | $i = 0; // en fait count($result) |
| 454 | 473 | $x = ""; |
@@ -742,6 +761,10 @@ discard block |
||
| 742 | 761 | } |
| 743 | 762 | |
| 744 | 763 | // http://code.spip.net/@phraser_critere_infixe |
| 764 | +/** |
|
| 765 | + * @param string $arg1 |
|
| 766 | + * @param string $arg2 |
|
| 767 | + */ |
|
| 745 | 768 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 746 | 769 | $args[0] = new Texte; |
| 747 | 770 | $args[0]->texte = $arg1; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** Début de la partie principale d'une boucle */ |
@@ -61,83 +61,83 @@ discard block |
||
| 61 | 61 | // http://code.spip.net/@phraser_inclure |
| 62 | 62 | function phraser_inclure($texte, $ligne, $result) { |
| 63 | 63 | |
| 64 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 65 | - $match = array_pad($match, 3, null); |
|
| 66 | - $p = strpos($texte, $match[0]); |
|
| 67 | - $debut = substr($texte, 0, $p); |
|
| 68 | - if ($p) { |
|
| 69 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 70 | - } |
|
| 71 | - $ligne += substr_count($debut, "\n"); |
|
| 72 | - $champ = new Inclure; |
|
| 73 | - $champ->ligne = $ligne; |
|
| 74 | - $ligne += substr_count($match[0], "\n"); |
|
| 75 | - $fichier = $match[2]; |
|
| 76 | - # assurer ici la migration .php3 => .php |
|
| 77 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 78 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 79 | - $fichier = $r[1]; |
|
| 80 | - } |
|
| 81 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 82 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 83 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 84 | - phraser_args($texte, "/>", "", $result, $champ); |
|
| 85 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 86 | - if (!function_exists('normaliser_inclure')) { |
|
| 87 | - include_spip('public/normaliser'); |
|
| 88 | - } |
|
| 89 | - normaliser_inclure($champ); |
|
| 90 | - } |
|
| 91 | - $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 92 | - $champ->apres = ""; |
|
| 93 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 94 | - $result[] = $champ; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return (($texte === "") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 64 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 65 | + $match = array_pad($match, 3, null); |
|
| 66 | + $p = strpos($texte, $match[0]); |
|
| 67 | + $debut = substr($texte, 0, $p); |
|
| 68 | + if ($p) { |
|
| 69 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 70 | + } |
|
| 71 | + $ligne += substr_count($debut, "\n"); |
|
| 72 | + $champ = new Inclure; |
|
| 73 | + $champ->ligne = $ligne; |
|
| 74 | + $ligne += substr_count($match[0], "\n"); |
|
| 75 | + $fichier = $match[2]; |
|
| 76 | + # assurer ici la migration .php3 => .php |
|
| 77 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 78 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 79 | + $fichier = $r[1]; |
|
| 80 | + } |
|
| 81 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 82 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 83 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 84 | + phraser_args($texte, "/>", "", $result, $champ); |
|
| 85 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 86 | + if (!function_exists('normaliser_inclure')) { |
|
| 87 | + include_spip('public/normaliser'); |
|
| 88 | + } |
|
| 89 | + normaliser_inclure($champ); |
|
| 90 | + } |
|
| 91 | + $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 92 | + $champ->apres = ""; |
|
| 93 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 94 | + $result[] = $champ; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return (($texte === "") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // http://code.spip.net/@phraser_polyglotte |
| 101 | 101 | function phraser_polyglotte($texte, $ligne, $result) { |
| 102 | 102 | |
| 103 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 104 | - foreach ($m as $match) { |
|
| 105 | - $p = strpos($texte, $match[0]); |
|
| 106 | - $debut = substr($texte, 0, $p); |
|
| 107 | - if ($p) { |
|
| 108 | - $champ = new Texte; |
|
| 109 | - $champ->texte = $debut; |
|
| 110 | - $champ->ligne = $ligne; |
|
| 111 | - $result[] = $champ; |
|
| 112 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $champ = new Polyglotte; |
|
| 116 | - $champ->ligne = $ligne; |
|
| 117 | - $ligne += substr_count($match[0], "\n"); |
|
| 118 | - $lang = ''; |
|
| 119 | - $bloc = $match[1]; |
|
| 120 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 121 | - while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)) { |
|
| 122 | - $trad = $regs[1]; |
|
| 123 | - if ($trad or $lang) { |
|
| 124 | - $champ->traductions[$lang] = $trad; |
|
| 125 | - } |
|
| 126 | - $lang = $regs[2]; |
|
| 127 | - $bloc = $regs[3]; |
|
| 128 | - } |
|
| 129 | - $champ->traductions[$lang] = $bloc; |
|
| 130 | - $result[] = $champ; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($texte !== "") { |
|
| 134 | - $champ = new Texte; |
|
| 135 | - $champ->texte = $texte; |
|
| 136 | - $champ->ligne = $ligne; |
|
| 137 | - $result[] = $champ; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $result; |
|
| 103 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 104 | + foreach ($m as $match) { |
|
| 105 | + $p = strpos($texte, $match[0]); |
|
| 106 | + $debut = substr($texte, 0, $p); |
|
| 107 | + if ($p) { |
|
| 108 | + $champ = new Texte; |
|
| 109 | + $champ->texte = $debut; |
|
| 110 | + $champ->ligne = $ligne; |
|
| 111 | + $result[] = $champ; |
|
| 112 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $champ = new Polyglotte; |
|
| 116 | + $champ->ligne = $ligne; |
|
| 117 | + $ligne += substr_count($match[0], "\n"); |
|
| 118 | + $lang = ''; |
|
| 119 | + $bloc = $match[1]; |
|
| 120 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 121 | + while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)) { |
|
| 122 | + $trad = $regs[1]; |
|
| 123 | + if ($trad or $lang) { |
|
| 124 | + $champ->traductions[$lang] = $trad; |
|
| 125 | + } |
|
| 126 | + $lang = $regs[2]; |
|
| 127 | + $bloc = $regs[3]; |
|
| 128 | + } |
|
| 129 | + $champ->traductions[$lang] = $bloc; |
|
| 130 | + $result[] = $champ; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($texte !== "") { |
|
| 134 | + $champ = new Texte; |
|
| 135 | + $champ->texte = $texte; |
|
| 136 | + $champ->ligne = $ligne; |
|
| 137 | + $result[] = $champ; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $result; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -159,41 +159,41 @@ discard block |
||
| 159 | 159 | * @return array |
| 160 | 160 | **/ |
| 161 | 161 | function phraser_idiomes($texte, $ligne, $result) { |
| 162 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 163 | - $match = array_pad($match, 8, null); |
|
| 164 | - $p = strpos($texte, $match[0]); |
|
| 165 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 166 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 167 | - if ($debut) { |
|
| 168 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 169 | - } |
|
| 170 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 171 | - $ligne += substr_count($debut, "\n"); |
|
| 172 | - if ($ko) { |
|
| 173 | - continue; |
|
| 174 | - } // faux idiome |
|
| 175 | - $champ = new Idiome; |
|
| 176 | - $champ->ligne = $ligne; |
|
| 177 | - $ligne += substr_count($match[0], "\n"); |
|
| 178 | - // Stocker les arguments de la balise de traduction |
|
| 179 | - $args = array(); |
|
| 180 | - $largs = $match[5]; |
|
| 181 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 182 | - $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 183 | - $largs = substr($largs, strlen($r[0])); |
|
| 184 | - } |
|
| 185 | - $champ->arg = $args; |
|
| 186 | - $champ->nom_champ = strtolower($match[3]); |
|
| 187 | - $champ->module = $match[2]; |
|
| 188 | - // pas d'imbrication pour les filtres sur langue |
|
| 189 | - phraser_args($match[7], ":", '', array(), $champ); |
|
| 190 | - $result[] = $champ; |
|
| 191 | - } |
|
| 192 | - if ($texte !== "") { |
|
| 193 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $result; |
|
| 162 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 163 | + $match = array_pad($match, 8, null); |
|
| 164 | + $p = strpos($texte, $match[0]); |
|
| 165 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 166 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 167 | + if ($debut) { |
|
| 168 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 169 | + } |
|
| 170 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 171 | + $ligne += substr_count($debut, "\n"); |
|
| 172 | + if ($ko) { |
|
| 173 | + continue; |
|
| 174 | + } // faux idiome |
|
| 175 | + $champ = new Idiome; |
|
| 176 | + $champ->ligne = $ligne; |
|
| 177 | + $ligne += substr_count($match[0], "\n"); |
|
| 178 | + // Stocker les arguments de la balise de traduction |
|
| 179 | + $args = array(); |
|
| 180 | + $largs = $match[5]; |
|
| 181 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 182 | + $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 183 | + $largs = substr($largs, strlen($r[0])); |
|
| 184 | + } |
|
| 185 | + $champ->arg = $args; |
|
| 186 | + $champ->nom_champ = strtolower($match[3]); |
|
| 187 | + $champ->module = $match[2]; |
|
| 188 | + // pas d'imbrication pour les filtres sur langue |
|
| 189 | + phraser_args($match[7], ":", '', array(), $champ); |
|
| 190 | + $result[] = $champ; |
|
| 191 | + } |
|
| 192 | + if ($texte !== "") { |
|
| 193 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $result; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -211,47 +211,47 @@ discard block |
||
| 211 | 211 | * @return array |
| 212 | 212 | **/ |
| 213 | 213 | function phraser_champs($texte, $ligne, $result) { |
| 214 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 215 | - $p = strpos($texte, $match[0]); |
|
| 216 | - // texte après la balise |
|
| 217 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 218 | - |
|
| 219 | - $debut = substr($texte, 0, $p); |
|
| 220 | - if ($p) { |
|
| 221 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 222 | - } |
|
| 223 | - $ligne += substr_count($debut, "\n"); |
|
| 224 | - $champ = new Champ; |
|
| 225 | - $champ->ligne = $ligne; |
|
| 226 | - $ligne += substr_count($match[0], "\n"); |
|
| 227 | - $champ->nom_boucle = $match[2]; |
|
| 228 | - $champ->nom_champ = $match[3]; |
|
| 229 | - $champ->etoile = $match[5]; |
|
| 230 | - |
|
| 231 | - if ($suite and $suite[0] == '{') { |
|
| 232 | - phraser_arg($suite, '', array(), $champ); |
|
| 233 | - // ce ltrim est une ereur de conception |
|
| 234 | - // mais on le conserve par souci de compatibilite |
|
| 235 | - $texte = ltrim($suite); |
|
| 236 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 237 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 238 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 214 | + while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 215 | + $p = strpos($texte, $match[0]); |
|
| 216 | + // texte après la balise |
|
| 217 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 218 | + |
|
| 219 | + $debut = substr($texte, 0, $p); |
|
| 220 | + if ($p) { |
|
| 221 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 222 | + } |
|
| 223 | + $ligne += substr_count($debut, "\n"); |
|
| 224 | + $champ = new Champ; |
|
| 225 | + $champ->ligne = $ligne; |
|
| 226 | + $ligne += substr_count($match[0], "\n"); |
|
| 227 | + $champ->nom_boucle = $match[2]; |
|
| 228 | + $champ->nom_champ = $match[3]; |
|
| 229 | + $champ->etoile = $match[5]; |
|
| 230 | + |
|
| 231 | + if ($suite and $suite[0] == '{') { |
|
| 232 | + phraser_arg($suite, '', array(), $champ); |
|
| 233 | + // ce ltrim est une ereur de conception |
|
| 234 | + // mais on le conserve par souci de compatibilite |
|
| 235 | + $texte = ltrim($suite); |
|
| 236 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 237 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 238 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 239 | 239 | if ($n = (strlen($suite) - strlen($texte))) { |
| 240 | 240 | $champ->apres = array(new Texte); |
| 241 | 241 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 242 | 242 | } |
| 243 | 243 | */ |
| 244 | - } else { |
|
| 245 | - $texte = $suite; |
|
| 246 | - } |
|
| 247 | - phraser_vieux($champ); |
|
| 248 | - $result[] = $champ; |
|
| 249 | - } |
|
| 250 | - if ($texte !== "") { |
|
| 251 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $result; |
|
| 244 | + } else { |
|
| 245 | + $texte = $suite; |
|
| 246 | + } |
|
| 247 | + phraser_vieux($champ); |
|
| 248 | + $result[] = $champ; |
|
| 249 | + } |
|
| 250 | + if ($texte !== "") { |
|
| 251 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $result; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // Gestion des imbrications: |
@@ -261,15 +261,15 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | // http://code.spip.net/@phraser_champs_etendus |
| 263 | 263 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 264 | - if ($texte === "") { |
|
| 265 | - return $result; |
|
| 266 | - } |
|
| 267 | - $sep = '##'; |
|
| 268 | - while (strpos($texte, $sep) !== false) { |
|
| 269 | - $sep .= '#'; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 264 | + if ($texte === "") { |
|
| 265 | + return $result; |
|
| 266 | + } |
|
| 267 | + $sep = '##'; |
|
| 268 | + while (strpos($texte, $sep) !== false) { |
|
| 269 | + $sep .= '#'; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Analyse les filtres d'un champ etendu et affecte le resultat |
@@ -280,270 +280,270 @@ discard block |
||
| 280 | 280 | |
| 281 | 281 | // http://code.spip.net/@phraser_args |
| 282 | 282 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) { |
| 283 | - $texte = ltrim($texte); |
|
| 284 | - while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 285 | - $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 286 | - $texte = ltrim($texte); |
|
| 287 | - } |
|
| 283 | + $texte = ltrim($texte); |
|
| 284 | + while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 285 | + $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 286 | + $texte = ltrim($texte); |
|
| 287 | + } |
|
| 288 | 288 | # mettre ici la suite du texte, |
| 289 | 289 | # notamment pour que l'appelant vire le caractere fermant si besoin |
| 290 | - $pointeur_champ->apres = $texte; |
|
| 290 | + $pointeur_champ->apres = $texte; |
|
| 291 | 291 | |
| 292 | - return $result; |
|
| 292 | + return $result; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // http://code.spip.net/@phraser_arg |
| 296 | 296 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 297 | - preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 298 | - $suite = ltrim($match[2]); |
|
| 299 | - $fonc = trim($match[1]); |
|
| 300 | - if ($fonc && $fonc[0] == "|") { |
|
| 301 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 302 | - } |
|
| 303 | - $res = array($fonc); |
|
| 304 | - $err_f = ''; |
|
| 305 | - // cas du filtre sans argument ou du critere / |
|
| 306 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 307 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 308 | - if (!$match[1]) { |
|
| 309 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 310 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 311 | - $texte = ''; |
|
| 312 | - } else { |
|
| 313 | - $texte = $suite; |
|
| 314 | - } |
|
| 315 | - if ($err_f) { |
|
| 316 | - $pointeur_champ->param = false; |
|
| 317 | - } elseif ($fonc !== '') { |
|
| 318 | - $pointeur_champ->param[] = $res; |
|
| 319 | - } |
|
| 320 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 321 | - $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 322 | - |
|
| 323 | - return $result; |
|
| 324 | - } |
|
| 325 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 326 | - $collecte = array(); |
|
| 327 | - while ($args && $args[0] != '}') { |
|
| 328 | - if ($args[0] == '"') { |
|
| 329 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 330 | - } elseif ($args[0] == "'") { |
|
| 331 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 332 | - } else { |
|
| 333 | - preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 334 | - if (!strlen($regs[2])) { |
|
| 335 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 336 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 337 | - $champ = new Texte; |
|
| 338 | - $champ->apres = $champ->avant = $args = ""; |
|
| 339 | - break; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - $arg = $regs[2]; |
|
| 343 | - if (trim($regs[1])) { |
|
| 344 | - $champ = new Texte; |
|
| 345 | - $champ->texte = $arg; |
|
| 346 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 347 | - $result[] = $champ; |
|
| 348 | - $collecte[] = $champ; |
|
| 349 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 350 | - } else { |
|
| 351 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 352 | - // 0 est un aveu d'impuissance. A completer |
|
| 353 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 354 | - |
|
| 355 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 356 | - $collecte = array_merge($collecte, $arg); |
|
| 357 | - $result = array_merge($result, $arg); |
|
| 358 | - } else { |
|
| 359 | - $n = strpos($args, $r[0]); |
|
| 360 | - $pred = substr($args, 0, $n); |
|
| 361 | - $par = ',}'; |
|
| 362 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 363 | - $pred = $m[1]; |
|
| 364 | - $par = ')'; |
|
| 365 | - } |
|
| 366 | - if ($pred) { |
|
| 367 | - $champ = new Texte; |
|
| 368 | - $champ->texte = $pred; |
|
| 369 | - $champ->apres = $champ->avant = ""; |
|
| 370 | - $result[] = $champ; |
|
| 371 | - $collecte[] = $champ; |
|
| 372 | - } |
|
| 373 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 374 | - $champ = new Champ; |
|
| 375 | - $champ->nom_boucle = $r[2]; |
|
| 376 | - $champ->nom_champ = $r[3]; |
|
| 377 | - $champ->etoile = $r[5]; |
|
| 378 | - $next = $r[6]; |
|
| 379 | - while ($next == '{') { |
|
| 380 | - phraser_arg($rec, $sep, array(), $champ); |
|
| 381 | - $args = ltrim($rec); |
|
| 382 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 383 | - } |
|
| 384 | - while ($next == '|') { |
|
| 385 | - phraser_args($rec, $par, $sep, array(), $champ); |
|
| 386 | - $args = $champ->apres; |
|
| 387 | - $champ->apres = ''; |
|
| 388 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 389 | - } |
|
| 390 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 391 | - if ($champ->param === false) { |
|
| 392 | - $err_f = true; |
|
| 393 | - } else { |
|
| 394 | - phraser_vieux($champ); |
|
| 395 | - } |
|
| 396 | - if ($par == ')') { |
|
| 397 | - $args = substr($args, 1); |
|
| 398 | - } |
|
| 399 | - $collecte[] = $champ; |
|
| 400 | - $result[] = $champ; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 404 | - $args = ltrim(substr($args, 1)); |
|
| 405 | - if ($collecte) { |
|
| 406 | - $res[] = $collecte; |
|
| 407 | - $collecte = array(); |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - if ($collecte) { |
|
| 412 | - $res[] = $collecte; |
|
| 413 | - $collecte = array(); |
|
| 414 | - } |
|
| 415 | - $texte = substr($args, 1); |
|
| 416 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 417 | - // propager les erreurs, et ignorer les param vides |
|
| 418 | - if ($pointeur_champ->param !== false) { |
|
| 419 | - if ($err_f) { |
|
| 420 | - $pointeur_champ->param = false; |
|
| 421 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 422 | - $pointeur_champ->param[] = $res; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 426 | - $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 427 | - |
|
| 428 | - return $result; |
|
| 297 | + preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 298 | + $suite = ltrim($match[2]); |
|
| 299 | + $fonc = trim($match[1]); |
|
| 300 | + if ($fonc && $fonc[0] == "|") { |
|
| 301 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 302 | + } |
|
| 303 | + $res = array($fonc); |
|
| 304 | + $err_f = ''; |
|
| 305 | + // cas du filtre sans argument ou du critere / |
|
| 306 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 307 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 308 | + if (!$match[1]) { |
|
| 309 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 310 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 311 | + $texte = ''; |
|
| 312 | + } else { |
|
| 313 | + $texte = $suite; |
|
| 314 | + } |
|
| 315 | + if ($err_f) { |
|
| 316 | + $pointeur_champ->param = false; |
|
| 317 | + } elseif ($fonc !== '') { |
|
| 318 | + $pointeur_champ->param[] = $res; |
|
| 319 | + } |
|
| 320 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 321 | + $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 322 | + |
|
| 323 | + return $result; |
|
| 324 | + } |
|
| 325 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 326 | + $collecte = array(); |
|
| 327 | + while ($args && $args[0] != '}') { |
|
| 328 | + if ($args[0] == '"') { |
|
| 329 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 330 | + } elseif ($args[0] == "'") { |
|
| 331 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 332 | + } else { |
|
| 333 | + preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 334 | + if (!strlen($regs[2])) { |
|
| 335 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 336 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 337 | + $champ = new Texte; |
|
| 338 | + $champ->apres = $champ->avant = $args = ""; |
|
| 339 | + break; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + $arg = $regs[2]; |
|
| 343 | + if (trim($regs[1])) { |
|
| 344 | + $champ = new Texte; |
|
| 345 | + $champ->texte = $arg; |
|
| 346 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 347 | + $result[] = $champ; |
|
| 348 | + $collecte[] = $champ; |
|
| 349 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 350 | + } else { |
|
| 351 | + if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 352 | + // 0 est un aveu d'impuissance. A completer |
|
| 353 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 354 | + |
|
| 355 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 356 | + $collecte = array_merge($collecte, $arg); |
|
| 357 | + $result = array_merge($result, $arg); |
|
| 358 | + } else { |
|
| 359 | + $n = strpos($args, $r[0]); |
|
| 360 | + $pred = substr($args, 0, $n); |
|
| 361 | + $par = ',}'; |
|
| 362 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 363 | + $pred = $m[1]; |
|
| 364 | + $par = ')'; |
|
| 365 | + } |
|
| 366 | + if ($pred) { |
|
| 367 | + $champ = new Texte; |
|
| 368 | + $champ->texte = $pred; |
|
| 369 | + $champ->apres = $champ->avant = ""; |
|
| 370 | + $result[] = $champ; |
|
| 371 | + $collecte[] = $champ; |
|
| 372 | + } |
|
| 373 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 374 | + $champ = new Champ; |
|
| 375 | + $champ->nom_boucle = $r[2]; |
|
| 376 | + $champ->nom_champ = $r[3]; |
|
| 377 | + $champ->etoile = $r[5]; |
|
| 378 | + $next = $r[6]; |
|
| 379 | + while ($next == '{') { |
|
| 380 | + phraser_arg($rec, $sep, array(), $champ); |
|
| 381 | + $args = ltrim($rec); |
|
| 382 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 383 | + } |
|
| 384 | + while ($next == '|') { |
|
| 385 | + phraser_args($rec, $par, $sep, array(), $champ); |
|
| 386 | + $args = $champ->apres; |
|
| 387 | + $champ->apres = ''; |
|
| 388 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 389 | + } |
|
| 390 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 391 | + if ($champ->param === false) { |
|
| 392 | + $err_f = true; |
|
| 393 | + } else { |
|
| 394 | + phraser_vieux($champ); |
|
| 395 | + } |
|
| 396 | + if ($par == ')') { |
|
| 397 | + $args = substr($args, 1); |
|
| 398 | + } |
|
| 399 | + $collecte[] = $champ; |
|
| 400 | + $result[] = $champ; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 404 | + $args = ltrim(substr($args, 1)); |
|
| 405 | + if ($collecte) { |
|
| 406 | + $res[] = $collecte; |
|
| 407 | + $collecte = array(); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + if ($collecte) { |
|
| 412 | + $res[] = $collecte; |
|
| 413 | + $collecte = array(); |
|
| 414 | + } |
|
| 415 | + $texte = substr($args, 1); |
|
| 416 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 417 | + // propager les erreurs, et ignorer les param vides |
|
| 418 | + if ($pointeur_champ->param !== false) { |
|
| 419 | + if ($err_f) { |
|
| 420 | + $pointeur_champ->param = false; |
|
| 421 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 422 | + $pointeur_champ->param[] = $res; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 426 | + $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 427 | + |
|
| 428 | + return $result; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
| 432 | 432 | // http://code.spip.net/@phraser_champs_exterieurs |
| 433 | 433 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 434 | - $res = array(); |
|
| 435 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 436 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 437 | - break; |
|
| 438 | - } |
|
| 439 | - $debut = substr($texte, 0, $p); |
|
| 440 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 441 | - if ($p) { |
|
| 442 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 443 | - } |
|
| 444 | - $ligne += substr_count($debut, "\n"); |
|
| 445 | - $res[] = $nested[$m[1]]; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 434 | + $res = array(); |
|
| 435 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 436 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 437 | + break; |
|
| 438 | + } |
|
| 439 | + $debut = substr($texte, 0, $p); |
|
| 440 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 441 | + if ($p) { |
|
| 442 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 443 | + } |
|
| 444 | + $ligne += substr_count($debut, "\n"); |
|
| 445 | + $res[] = $nested[$m[1]]; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // http://code.spip.net/@phraser_champs_interieurs |
| 452 | 452 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 453 | - $i = 0; // en fait count($result) |
|
| 454 | - $x = ""; |
|
| 455 | - |
|
| 456 | - while (true) { |
|
| 457 | - $j = $i; |
|
| 458 | - $n = $ligne; |
|
| 459 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 460 | - $p = strpos($texte, $match[0]); |
|
| 461 | - $debut = substr($texte, 0, $p); |
|
| 462 | - if ($p) { |
|
| 463 | - $result[$i] = $debut; |
|
| 464 | - $i++; |
|
| 465 | - } |
|
| 466 | - $nom = $match[4]; |
|
| 467 | - $champ = new Champ; |
|
| 468 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 469 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 470 | - $champ->nom_boucle = $match[3]; |
|
| 471 | - $champ->nom_champ = $nom; |
|
| 472 | - $champ->etoile = $match[6]; |
|
| 473 | - // phraser_args indiquera ou commence apres |
|
| 474 | - $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 475 | - phraser_vieux($champ); |
|
| 476 | - $champ->avant = |
|
| 477 | - phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 478 | - $debut = substr($champ->apres, 1); |
|
| 479 | - if (!empty($debut)) { |
|
| 480 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 481 | - } |
|
| 482 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 483 | - |
|
| 484 | - $result[$i] = $champ; |
|
| 485 | - $i++; |
|
| 486 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 487 | - } |
|
| 488 | - if ($texte !== "") { |
|
| 489 | - $result[$i] = $texte; |
|
| 490 | - $i++; |
|
| 491 | - } |
|
| 492 | - $x = ''; |
|
| 493 | - |
|
| 494 | - while ($j < $i) { |
|
| 495 | - $z = $result[$j]; |
|
| 496 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 497 | - if (is_object($z)) { |
|
| 498 | - $x .= "%$sep$j@"; |
|
| 499 | - } else { |
|
| 500 | - $x .= $z; |
|
| 501 | - } |
|
| 502 | - $j++; |
|
| 503 | - } |
|
| 504 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 505 | - $texte = $x; |
|
| 506 | - } else { |
|
| 507 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 508 | - } |
|
| 509 | - } |
|
| 453 | + $i = 0; // en fait count($result) |
|
| 454 | + $x = ""; |
|
| 455 | + |
|
| 456 | + while (true) { |
|
| 457 | + $j = $i; |
|
| 458 | + $n = $ligne; |
|
| 459 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 460 | + $p = strpos($texte, $match[0]); |
|
| 461 | + $debut = substr($texte, 0, $p); |
|
| 462 | + if ($p) { |
|
| 463 | + $result[$i] = $debut; |
|
| 464 | + $i++; |
|
| 465 | + } |
|
| 466 | + $nom = $match[4]; |
|
| 467 | + $champ = new Champ; |
|
| 468 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 469 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 470 | + $champ->nom_boucle = $match[3]; |
|
| 471 | + $champ->nom_champ = $nom; |
|
| 472 | + $champ->etoile = $match[6]; |
|
| 473 | + // phraser_args indiquera ou commence apres |
|
| 474 | + $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 475 | + phraser_vieux($champ); |
|
| 476 | + $champ->avant = |
|
| 477 | + phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 478 | + $debut = substr($champ->apres, 1); |
|
| 479 | + if (!empty($debut)) { |
|
| 480 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 481 | + } |
|
| 482 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 483 | + |
|
| 484 | + $result[$i] = $champ; |
|
| 485 | + $i++; |
|
| 486 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 487 | + } |
|
| 488 | + if ($texte !== "") { |
|
| 489 | + $result[$i] = $texte; |
|
| 490 | + $i++; |
|
| 491 | + } |
|
| 492 | + $x = ''; |
|
| 493 | + |
|
| 494 | + while ($j < $i) { |
|
| 495 | + $z = $result[$j]; |
|
| 496 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 497 | + if (is_object($z)) { |
|
| 498 | + $x .= "%$sep$j@"; |
|
| 499 | + } else { |
|
| 500 | + $x .= $z; |
|
| 501 | + } |
|
| 502 | + $j++; |
|
| 503 | + } |
|
| 504 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 505 | + $texte = $x; |
|
| 506 | + } else { |
|
| 507 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | function phraser_vieux(&$champ) { |
| 513 | - $nom = $champ->nom_champ; |
|
| 514 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 515 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 516 | - include_spip('public/normaliser'); |
|
| 517 | - } |
|
| 518 | - phraser_vieux_emb($champ); |
|
| 519 | - } elseif ($nom == 'EXPOSER') { |
|
| 520 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 521 | - include_spip('public/normaliser'); |
|
| 522 | - } |
|
| 523 | - phraser_vieux_exposer($champ); |
|
| 524 | - } elseif ($champ->param) { |
|
| 525 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 526 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 527 | - include_spip('public/normaliser'); |
|
| 528 | - } |
|
| 529 | - phraser_vieux_recherche($champ); |
|
| 530 | - } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 531 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 532 | - include_spip('public/normaliser'); |
|
| 533 | - } |
|
| 534 | - phraser_vieux_logos($champ); |
|
| 535 | - } elseif ($nom == 'MODELE') { |
|
| 536 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 537 | - include_spip('public/normaliser'); |
|
| 538 | - } |
|
| 539 | - phraser_vieux_modele($champ); |
|
| 540 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 541 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 542 | - include_spip('public/normaliser'); |
|
| 543 | - } |
|
| 544 | - phraser_vieux_inclu($champ); |
|
| 545 | - } |
|
| 546 | - } |
|
| 513 | + $nom = $champ->nom_champ; |
|
| 514 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 515 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 516 | + include_spip('public/normaliser'); |
|
| 517 | + } |
|
| 518 | + phraser_vieux_emb($champ); |
|
| 519 | + } elseif ($nom == 'EXPOSER') { |
|
| 520 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 521 | + include_spip('public/normaliser'); |
|
| 522 | + } |
|
| 523 | + phraser_vieux_exposer($champ); |
|
| 524 | + } elseif ($champ->param) { |
|
| 525 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 526 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 527 | + include_spip('public/normaliser'); |
|
| 528 | + } |
|
| 529 | + phraser_vieux_recherche($champ); |
|
| 530 | + } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 531 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 532 | + include_spip('public/normaliser'); |
|
| 533 | + } |
|
| 534 | + phraser_vieux_logos($champ); |
|
| 535 | + } elseif ($nom == 'MODELE') { |
|
| 536 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 537 | + include_spip('public/normaliser'); |
|
| 538 | + } |
|
| 539 | + phraser_vieux_modele($champ); |
|
| 540 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 541 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 542 | + include_spip('public/normaliser'); |
|
| 543 | + } |
|
| 544 | + phraser_vieux_inclu($champ); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
@@ -571,369 +571,369 @@ discard block |
||
| 571 | 571 | **/ |
| 572 | 572 | function phraser_criteres($params, &$result) { |
| 573 | 573 | |
| 574 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 575 | - $args = array(); |
|
| 576 | - $type = $result->type_requete; |
|
| 577 | - $doublons = array(); |
|
| 578 | - foreach ($params as $v) { |
|
| 579 | - $var = $v[1][0]; |
|
| 580 | - $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 581 | - if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 582 | - // plus d'un argument et pas le critere IN: |
|
| 583 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 584 | - if ($var->type != 'texte' |
|
| 585 | - or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 586 | - ) { |
|
| 587 | - $op = ','; |
|
| 588 | - $not = ""; |
|
| 589 | - $cond = false; |
|
| 590 | - } else { |
|
| 591 | - // Le debut du premier argument est l'operateur |
|
| 592 | - preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 593 | - $op = $m[2]; |
|
| 594 | - $not = $m[1]; |
|
| 595 | - $cond = $m[3]; |
|
| 596 | - // virer le premier argument, |
|
| 597 | - // et mettre son reliquat eventuel |
|
| 598 | - // Recopier pour ne pas alterer le texte source |
|
| 599 | - // utile au debusqueur |
|
| 600 | - if ($m[4]) { |
|
| 601 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 602 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 603 | - $c = null; |
|
| 604 | - eval('$c = ' . $m[4] . ';'); |
|
| 605 | - if (isset($c)) { |
|
| 606 | - $m[4] = $c; |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - $texte = new Texte; |
|
| 610 | - $texte->texte = $m[4]; |
|
| 611 | - $v[1][0] = $texte; |
|
| 612 | - } else { |
|
| 613 | - array_shift($v[1]); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - array_shift($v); // $v[O] est vide |
|
| 617 | - $crit = new Critere; |
|
| 618 | - $crit->op = $op; |
|
| 619 | - $crit->not = $not; |
|
| 620 | - $crit->cond = $cond; |
|
| 621 | - $crit->exclus = ""; |
|
| 622 | - $crit->param = $v; |
|
| 623 | - $args[] = $crit; |
|
| 624 | - } else { |
|
| 625 | - if ($var->type != 'texte') { |
|
| 626 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 627 | - // erreur ou critere infixe "/" |
|
| 628 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 629 | - $err_ci = array( |
|
| 630 | - 'zbug_critere_inconnu', |
|
| 631 | - array('critere' => $var->nom_champ) |
|
| 632 | - ); |
|
| 633 | - erreur_squelette($err_ci, $result); |
|
| 634 | - } else { |
|
| 635 | - $crit = new Critere; |
|
| 636 | - $crit->op = '/'; |
|
| 637 | - $crit->not = ""; |
|
| 638 | - $crit->exclus = ""; |
|
| 639 | - $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 640 | - $args[] = $crit; |
|
| 641 | - } |
|
| 642 | - } else { |
|
| 643 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 644 | - // les separateurs |
|
| 645 | - if ($var->apres) { |
|
| 646 | - $result->separateur[] = $param; |
|
| 647 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 648 | - $result->modificateur['tout'] = true; |
|
| 649 | - } elseif ($param == 'plat') { |
|
| 650 | - $result->modificateur['plat'] = true; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 654 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 655 | - // ceux-ci pour avoir la rubrique mere... |
|
| 656 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 657 | - // traités normalement. |
|
| 658 | - elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 659 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 660 | - and preg_match(",^id_\w+\s*$,", $param) |
|
| 661 | - ) { |
|
| 662 | - $result->modificateur['tout'] = true; |
|
| 663 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 664 | - // rien a faire sur {id_rubrique} tout seul |
|
| 665 | - } else { |
|
| 666 | - // pas d'emplacement statique, faut un dynamique |
|
| 667 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 668 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 669 | - // cette variable sera inseree dans le code |
|
| 670 | - // et son nom sert d'indicateur des maintenant |
|
| 671 | - $result->doublons = '$doublons_index'; |
|
| 672 | - if ($param == 'unique') { |
|
| 673 | - $param = 'doublons'; |
|
| 674 | - } |
|
| 675 | - } elseif ($param == 'recherche') { |
|
| 676 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 677 | - $result->hash = ' '; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 681 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 682 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 683 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 684 | - $a2 = trim($m[8]); |
|
| 685 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 686 | - $a2 = substr($a2, 1, -1); |
|
| 687 | - } |
|
| 688 | - $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 689 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 690 | - $m[6], $m[5]); |
|
| 691 | - $crit->exclus = $m[1]; |
|
| 692 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 693 | - CHAMP_SQL_PLUS_FONC . |
|
| 694 | - ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 695 | - // contient aussi les comparaisons implicites ! |
|
| 696 | - // Comme ci-dessus: |
|
| 697 | - // le premier arg contient l'operateur |
|
| 698 | - array_shift($v); |
|
| 699 | - if ($m[6]) { |
|
| 700 | - $v[0][0] = new Texte; |
|
| 701 | - $v[0][0]->texte = $m[6]; |
|
| 702 | - } else { |
|
| 703 | - array_shift($v[0]); |
|
| 704 | - if (!$v[0]) { |
|
| 705 | - array_shift($v); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - $crit = new Critere; |
|
| 709 | - $crit->op = $m[2]; |
|
| 710 | - $crit->param = $v; |
|
| 711 | - $crit->not = $m[1]; |
|
| 712 | - $crit->cond = $m[5]; |
|
| 713 | - } else { |
|
| 714 | - $err_ci = array( |
|
| 715 | - 'zbug_critere_inconnu', |
|
| 716 | - array('critere' => $param) |
|
| 717 | - ); |
|
| 718 | - erreur_squelette($err_ci, $result); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 722 | - $args[] = $crit; |
|
| 723 | - } else { |
|
| 724 | - $doublons[] = $crit; |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - // les doublons non nies doivent etre le dernier critere |
|
| 732 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 733 | - // cf critere_doublon |
|
| 734 | - if ($doublons) { |
|
| 735 | - $args = array_merge($args, $doublons); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 739 | - if (!$err_ci) { |
|
| 740 | - $result->criteres = $args; |
|
| 741 | - } |
|
| 574 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 575 | + $args = array(); |
|
| 576 | + $type = $result->type_requete; |
|
| 577 | + $doublons = array(); |
|
| 578 | + foreach ($params as $v) { |
|
| 579 | + $var = $v[1][0]; |
|
| 580 | + $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 581 | + if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 582 | + // plus d'un argument et pas le critere IN: |
|
| 583 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 584 | + if ($var->type != 'texte' |
|
| 585 | + or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 586 | + ) { |
|
| 587 | + $op = ','; |
|
| 588 | + $not = ""; |
|
| 589 | + $cond = false; |
|
| 590 | + } else { |
|
| 591 | + // Le debut du premier argument est l'operateur |
|
| 592 | + preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 593 | + $op = $m[2]; |
|
| 594 | + $not = $m[1]; |
|
| 595 | + $cond = $m[3]; |
|
| 596 | + // virer le premier argument, |
|
| 597 | + // et mettre son reliquat eventuel |
|
| 598 | + // Recopier pour ne pas alterer le texte source |
|
| 599 | + // utile au debusqueur |
|
| 600 | + if ($m[4]) { |
|
| 601 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 602 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 603 | + $c = null; |
|
| 604 | + eval('$c = ' . $m[4] . ';'); |
|
| 605 | + if (isset($c)) { |
|
| 606 | + $m[4] = $c; |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + $texte = new Texte; |
|
| 610 | + $texte->texte = $m[4]; |
|
| 611 | + $v[1][0] = $texte; |
|
| 612 | + } else { |
|
| 613 | + array_shift($v[1]); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + array_shift($v); // $v[O] est vide |
|
| 617 | + $crit = new Critere; |
|
| 618 | + $crit->op = $op; |
|
| 619 | + $crit->not = $not; |
|
| 620 | + $crit->cond = $cond; |
|
| 621 | + $crit->exclus = ""; |
|
| 622 | + $crit->param = $v; |
|
| 623 | + $args[] = $crit; |
|
| 624 | + } else { |
|
| 625 | + if ($var->type != 'texte') { |
|
| 626 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 627 | + // erreur ou critere infixe "/" |
|
| 628 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 629 | + $err_ci = array( |
|
| 630 | + 'zbug_critere_inconnu', |
|
| 631 | + array('critere' => $var->nom_champ) |
|
| 632 | + ); |
|
| 633 | + erreur_squelette($err_ci, $result); |
|
| 634 | + } else { |
|
| 635 | + $crit = new Critere; |
|
| 636 | + $crit->op = '/'; |
|
| 637 | + $crit->not = ""; |
|
| 638 | + $crit->exclus = ""; |
|
| 639 | + $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 640 | + $args[] = $crit; |
|
| 641 | + } |
|
| 642 | + } else { |
|
| 643 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 644 | + // les separateurs |
|
| 645 | + if ($var->apres) { |
|
| 646 | + $result->separateur[] = $param; |
|
| 647 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 648 | + $result->modificateur['tout'] = true; |
|
| 649 | + } elseif ($param == 'plat') { |
|
| 650 | + $result->modificateur['plat'] = true; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 654 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 655 | + // ceux-ci pour avoir la rubrique mere... |
|
| 656 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 657 | + // traités normalement. |
|
| 658 | + elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 659 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 660 | + and preg_match(",^id_\w+\s*$,", $param) |
|
| 661 | + ) { |
|
| 662 | + $result->modificateur['tout'] = true; |
|
| 663 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 664 | + // rien a faire sur {id_rubrique} tout seul |
|
| 665 | + } else { |
|
| 666 | + // pas d'emplacement statique, faut un dynamique |
|
| 667 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 668 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 669 | + // cette variable sera inseree dans le code |
|
| 670 | + // et son nom sert d'indicateur des maintenant |
|
| 671 | + $result->doublons = '$doublons_index'; |
|
| 672 | + if ($param == 'unique') { |
|
| 673 | + $param = 'doublons'; |
|
| 674 | + } |
|
| 675 | + } elseif ($param == 'recherche') { |
|
| 676 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 677 | + $result->hash = ' '; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 681 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 682 | + } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 683 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 684 | + $a2 = trim($m[8]); |
|
| 685 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 686 | + $a2 = substr($a2, 1, -1); |
|
| 687 | + } |
|
| 688 | + $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 689 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 690 | + $m[6], $m[5]); |
|
| 691 | + $crit->exclus = $m[1]; |
|
| 692 | + } elseif (preg_match("/^([!]?)\s*(" . |
|
| 693 | + CHAMP_SQL_PLUS_FONC . |
|
| 694 | + ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 695 | + // contient aussi les comparaisons implicites ! |
|
| 696 | + // Comme ci-dessus: |
|
| 697 | + // le premier arg contient l'operateur |
|
| 698 | + array_shift($v); |
|
| 699 | + if ($m[6]) { |
|
| 700 | + $v[0][0] = new Texte; |
|
| 701 | + $v[0][0]->texte = $m[6]; |
|
| 702 | + } else { |
|
| 703 | + array_shift($v[0]); |
|
| 704 | + if (!$v[0]) { |
|
| 705 | + array_shift($v); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + $crit = new Critere; |
|
| 709 | + $crit->op = $m[2]; |
|
| 710 | + $crit->param = $v; |
|
| 711 | + $crit->not = $m[1]; |
|
| 712 | + $crit->cond = $m[5]; |
|
| 713 | + } else { |
|
| 714 | + $err_ci = array( |
|
| 715 | + 'zbug_critere_inconnu', |
|
| 716 | + array('critere' => $param) |
|
| 717 | + ); |
|
| 718 | + erreur_squelette($err_ci, $result); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 722 | + $args[] = $crit; |
|
| 723 | + } else { |
|
| 724 | + $doublons[] = $crit; |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + // les doublons non nies doivent etre le dernier critere |
|
| 732 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 733 | + // cf critere_doublon |
|
| 734 | + if ($doublons) { |
|
| 735 | + $args = array_merge($args, $doublons); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 739 | + if (!$err_ci) { |
|
| 740 | + $result->criteres = $args; |
|
| 741 | + } |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // http://code.spip.net/@phraser_critere_infixe |
| 745 | 745 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 746 | - $args[0] = new Texte; |
|
| 747 | - $args[0]->texte = $arg1; |
|
| 748 | - $args[0] = array($args[0]); |
|
| 749 | - $args[1][0] = new Texte; |
|
| 750 | - $args[1][0]->texte = $arg2; |
|
| 751 | - $crit = new Critere; |
|
| 752 | - $crit->op = $op; |
|
| 753 | - $crit->not = $not; |
|
| 754 | - $crit->cond = $cond; |
|
| 755 | - $crit->param = $args; |
|
| 756 | - |
|
| 757 | - return $crit; |
|
| 746 | + $args[0] = new Texte; |
|
| 747 | + $args[0]->texte = $arg1; |
|
| 748 | + $args[0] = array($args[0]); |
|
| 749 | + $args[1][0] = new Texte; |
|
| 750 | + $args[1][0]->texte = $arg2; |
|
| 751 | + $crit = new Critere; |
|
| 752 | + $crit->op = $op; |
|
| 753 | + $crit->not = $not; |
|
| 754 | + $crit->cond = $cond; |
|
| 755 | + $crit->param = $args; |
|
| 756 | + |
|
| 757 | + return $crit; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1) { |
| 761 | 761 | |
| 762 | - $all_res = array(); |
|
| 762 | + $all_res = array(); |
|
| 763 | 763 | |
| 764 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE)) !== false) { |
|
| 764 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE)) !== false) { |
|
| 765 | 765 | |
| 766 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 767 | - $result = new Boucle; |
|
| 768 | - $result->id_parent = $id_parent; |
|
| 769 | - $result->descr = $descr; |
|
| 766 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 767 | + $result = new Boucle; |
|
| 768 | + $result->id_parent = $id_parent; |
|
| 769 | + $result->descr = $descr; |
|
| 770 | 770 | # attention: reperer la premiere des 2 balises: pre_boucle ou boucle |
| 771 | 771 | |
| 772 | - if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 773 | - or ($n = strpos($texte, $r[0])) === false |
|
| 774 | - or ($n > $pos_boucle) |
|
| 775 | - ) { |
|
| 776 | - $debut = substr($texte, 0, $pos_boucle); |
|
| 777 | - $milieu = substr($texte, $pos_boucle); |
|
| 778 | - $k = strpos($milieu, '('); |
|
| 779 | - $id_boucle = trim(substr($milieu, |
|
| 780 | - strlen(BALISE_BOUCLE), |
|
| 781 | - $k - strlen(BALISE_BOUCLE))); |
|
| 782 | - $milieu = substr($milieu, $k); |
|
| 783 | - |
|
| 784 | - } else { |
|
| 785 | - $debut = substr($texte, 0, $n); |
|
| 786 | - $milieu = substr($texte, $n); |
|
| 787 | - $k = strpos($milieu, '>'); |
|
| 788 | - $id_boucle = substr($milieu, |
|
| 789 | - strlen(BALISE_PRE_BOUCLE), |
|
| 790 | - $k - strlen(BALISE_PRE_BOUCLE)); |
|
| 791 | - |
|
| 792 | - if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)) { |
|
| 793 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 794 | - erreur_squelette($err_b, $result); |
|
| 795 | - $texte = substr($texte, $n + 1); |
|
| 796 | - continue; |
|
| 797 | - } else { |
|
| 798 | - $pos_boucle = $n; |
|
| 799 | - $n = strpos($milieu, $r[0]); |
|
| 800 | - $result->avant = substr($milieu, $k + 1, $n - $k - 1); |
|
| 801 | - $milieu = substr($milieu, $n + strlen($id_boucle) + strlen(BALISE_BOUCLE)); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $result->id_boucle = $id_boucle; |
|
| 805 | - |
|
| 806 | - preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 807 | - $result->type_requete = $match[0]; |
|
| 808 | - $milieu = substr($milieu, strlen($match[0])); |
|
| 809 | - $type = $match[1]; |
|
| 810 | - $jointures = trim($match[2]); |
|
| 811 | - $table_optionnelle = ($match[3]); |
|
| 812 | - if ($jointures) { |
|
| 813 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 814 | - // ou elles seront completees des jointures declarees |
|
| 815 | - $result->jointures_explicites = $jointures; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($table_optionnelle) { |
|
| 819 | - $result->table_optionnelle = $type; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 823 | - // Resultat mis dans result->param |
|
| 824 | - phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 825 | - |
|
| 826 | - // En 2e passe result->criteres contiendra un tableau |
|
| 827 | - // pour l'instant on met le source (chaine) : |
|
| 828 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 829 | - $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 830 | - $milieu = $result->apres; |
|
| 831 | - $result->apres = ""; |
|
| 832 | - |
|
| 833 | - // |
|
| 834 | - // Recuperer la fin : |
|
| 835 | - // |
|
| 836 | - if ($milieu[0] === '/') { |
|
| 837 | - $suite = substr($milieu, 2); |
|
| 838 | - $milieu = ''; |
|
| 839 | - } else { |
|
| 840 | - $milieu = substr($milieu, 1); |
|
| 841 | - $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 842 | - $p = strpos($milieu, $s); |
|
| 843 | - if ($p === false) { |
|
| 844 | - $err_b = array( |
|
| 845 | - 'zbug_erreur_boucle_fermant', |
|
| 846 | - array('id' => $id_boucle) |
|
| 847 | - ); |
|
| 848 | - erreur_squelette($err_b, $result); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - $suite = substr($milieu, $p + strlen($s)); |
|
| 852 | - $milieu = substr($milieu, 0, $p); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - $result->milieu = $milieu; |
|
| 856 | - |
|
| 857 | - // |
|
| 858 | - // 1. Recuperer la partie conditionnelle apres |
|
| 859 | - // |
|
| 860 | - $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 861 | - $p = strpos($suite, $s); |
|
| 862 | - if ($p !== false) { |
|
| 863 | - $result->apres = substr($suite, 0, $p); |
|
| 864 | - $suite = substr($suite, $p + strlen($s)); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - // |
|
| 868 | - // 2. Recuperer la partie alternative |
|
| 869 | - // |
|
| 870 | - $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 871 | - $p = strpos($suite, $s); |
|
| 872 | - if ($p !== false) { |
|
| 873 | - $result->altern = substr($suite, 0, $p); |
|
| 874 | - $suite = substr($suite, $p + strlen($s)); |
|
| 875 | - } |
|
| 876 | - $result->ligne = $ligne + substr_count($debut, "\n"); |
|
| 877 | - $m = substr_count($milieu, "\n"); |
|
| 878 | - $b = substr_count($result->avant, "\n"); |
|
| 879 | - $a = substr_count($result->apres, "\n"); |
|
| 880 | - |
|
| 881 | - if ($p = strpos($type, ':')) { |
|
| 882 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 883 | - $type = substr($type, $p + 1); |
|
| 884 | - } |
|
| 885 | - $soustype = strtolower($type); |
|
| 886 | - |
|
| 887 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 888 | - $soustype = $type; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $result->type_requete = $soustype; |
|
| 892 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 893 | - if (!is_array($result->param)) { |
|
| 894 | - $err_b = true; |
|
| 895 | - } else { |
|
| 896 | - phraser_criteres($result->param, $result); |
|
| 897 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 898 | - $result->type_requete = TYPE_RECURSIF; |
|
| 899 | - $args = $result->param; |
|
| 900 | - array_unshift($args, |
|
| 901 | - substr($type, strlen(TYPE_RECURSIF))); |
|
| 902 | - $result->param = $args; |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 907 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne + $b + $m); |
|
| 908 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne + $a + $m + $b); |
|
| 909 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne + $b); |
|
| 910 | - |
|
| 911 | - // Prevenir le generateur de code que le squelette est faux |
|
| 912 | - if ($err_b) { |
|
| 913 | - $result->type_requete = false; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - // Verifier qu'il n'y a pas double definition |
|
| 917 | - // apres analyse des sous-parties (pas avant). |
|
| 918 | - |
|
| 919 | - if (isset($boucles[$id_boucle])) { |
|
| 920 | - $err_b_d = array( |
|
| 921 | - 'zbug_erreur_boucle_double', |
|
| 922 | - array('id' => $id_boucle) |
|
| 923 | - ); |
|
| 924 | - erreur_squelette($err_b_d, $result); |
|
| 925 | - // Prevenir le generateur de code que le squelette est faux |
|
| 926 | - $boucles[$id_boucle]->type_requete = false; |
|
| 927 | - } else { |
|
| 928 | - $boucles[$id_boucle] = $result; |
|
| 929 | - } |
|
| 930 | - $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 931 | - $all_res[] = &$boucles[$id_boucle]; |
|
| 932 | - if (!empty($suite)) { |
|
| 933 | - $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 934 | - } |
|
| 935 | - $texte = $suite; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 772 | + if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 773 | + or ($n = strpos($texte, $r[0])) === false |
|
| 774 | + or ($n > $pos_boucle) |
|
| 775 | + ) { |
|
| 776 | + $debut = substr($texte, 0, $pos_boucle); |
|
| 777 | + $milieu = substr($texte, $pos_boucle); |
|
| 778 | + $k = strpos($milieu, '('); |
|
| 779 | + $id_boucle = trim(substr($milieu, |
|
| 780 | + strlen(BALISE_BOUCLE), |
|
| 781 | + $k - strlen(BALISE_BOUCLE))); |
|
| 782 | + $milieu = substr($milieu, $k); |
|
| 783 | + |
|
| 784 | + } else { |
|
| 785 | + $debut = substr($texte, 0, $n); |
|
| 786 | + $milieu = substr($texte, $n); |
|
| 787 | + $k = strpos($milieu, '>'); |
|
| 788 | + $id_boucle = substr($milieu, |
|
| 789 | + strlen(BALISE_PRE_BOUCLE), |
|
| 790 | + $k - strlen(BALISE_PRE_BOUCLE)); |
|
| 791 | + |
|
| 792 | + if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)) { |
|
| 793 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 794 | + erreur_squelette($err_b, $result); |
|
| 795 | + $texte = substr($texte, $n + 1); |
|
| 796 | + continue; |
|
| 797 | + } else { |
|
| 798 | + $pos_boucle = $n; |
|
| 799 | + $n = strpos($milieu, $r[0]); |
|
| 800 | + $result->avant = substr($milieu, $k + 1, $n - $k - 1); |
|
| 801 | + $milieu = substr($milieu, $n + strlen($id_boucle) + strlen(BALISE_BOUCLE)); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $result->id_boucle = $id_boucle; |
|
| 805 | + |
|
| 806 | + preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 807 | + $result->type_requete = $match[0]; |
|
| 808 | + $milieu = substr($milieu, strlen($match[0])); |
|
| 809 | + $type = $match[1]; |
|
| 810 | + $jointures = trim($match[2]); |
|
| 811 | + $table_optionnelle = ($match[3]); |
|
| 812 | + if ($jointures) { |
|
| 813 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 814 | + // ou elles seront completees des jointures declarees |
|
| 815 | + $result->jointures_explicites = $jointures; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($table_optionnelle) { |
|
| 819 | + $result->table_optionnelle = $type; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 823 | + // Resultat mis dans result->param |
|
| 824 | + phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 825 | + |
|
| 826 | + // En 2e passe result->criteres contiendra un tableau |
|
| 827 | + // pour l'instant on met le source (chaine) : |
|
| 828 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 829 | + $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 830 | + $milieu = $result->apres; |
|
| 831 | + $result->apres = ""; |
|
| 832 | + |
|
| 833 | + // |
|
| 834 | + // Recuperer la fin : |
|
| 835 | + // |
|
| 836 | + if ($milieu[0] === '/') { |
|
| 837 | + $suite = substr($milieu, 2); |
|
| 838 | + $milieu = ''; |
|
| 839 | + } else { |
|
| 840 | + $milieu = substr($milieu, 1); |
|
| 841 | + $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 842 | + $p = strpos($milieu, $s); |
|
| 843 | + if ($p === false) { |
|
| 844 | + $err_b = array( |
|
| 845 | + 'zbug_erreur_boucle_fermant', |
|
| 846 | + array('id' => $id_boucle) |
|
| 847 | + ); |
|
| 848 | + erreur_squelette($err_b, $result); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + $suite = substr($milieu, $p + strlen($s)); |
|
| 852 | + $milieu = substr($milieu, 0, $p); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + $result->milieu = $milieu; |
|
| 856 | + |
|
| 857 | + // |
|
| 858 | + // 1. Recuperer la partie conditionnelle apres |
|
| 859 | + // |
|
| 860 | + $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 861 | + $p = strpos($suite, $s); |
|
| 862 | + if ($p !== false) { |
|
| 863 | + $result->apres = substr($suite, 0, $p); |
|
| 864 | + $suite = substr($suite, $p + strlen($s)); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + // |
|
| 868 | + // 2. Recuperer la partie alternative |
|
| 869 | + // |
|
| 870 | + $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 871 | + $p = strpos($suite, $s); |
|
| 872 | + if ($p !== false) { |
|
| 873 | + $result->altern = substr($suite, 0, $p); |
|
| 874 | + $suite = substr($suite, $p + strlen($s)); |
|
| 875 | + } |
|
| 876 | + $result->ligne = $ligne + substr_count($debut, "\n"); |
|
| 877 | + $m = substr_count($milieu, "\n"); |
|
| 878 | + $b = substr_count($result->avant, "\n"); |
|
| 879 | + $a = substr_count($result->apres, "\n"); |
|
| 880 | + |
|
| 881 | + if ($p = strpos($type, ':')) { |
|
| 882 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 883 | + $type = substr($type, $p + 1); |
|
| 884 | + } |
|
| 885 | + $soustype = strtolower($type); |
|
| 886 | + |
|
| 887 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 888 | + $soustype = $type; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $result->type_requete = $soustype; |
|
| 892 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 893 | + if (!is_array($result->param)) { |
|
| 894 | + $err_b = true; |
|
| 895 | + } else { |
|
| 896 | + phraser_criteres($result->param, $result); |
|
| 897 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 898 | + $result->type_requete = TYPE_RECURSIF; |
|
| 899 | + $args = $result->param; |
|
| 900 | + array_unshift($args, |
|
| 901 | + substr($type, strlen(TYPE_RECURSIF))); |
|
| 902 | + $result->param = $args; |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 907 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne + $b + $m); |
|
| 908 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne + $a + $m + $b); |
|
| 909 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne + $b); |
|
| 910 | + |
|
| 911 | + // Prevenir le generateur de code que le squelette est faux |
|
| 912 | + if ($err_b) { |
|
| 913 | + $result->type_requete = false; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + // Verifier qu'il n'y a pas double definition |
|
| 917 | + // apres analyse des sous-parties (pas avant). |
|
| 918 | + |
|
| 919 | + if (isset($boucles[$id_boucle])) { |
|
| 920 | + $err_b_d = array( |
|
| 921 | + 'zbug_erreur_boucle_double', |
|
| 922 | + array('id' => $id_boucle) |
|
| 923 | + ); |
|
| 924 | + erreur_squelette($err_b_d, $result); |
|
| 925 | + // Prevenir le generateur de code que le squelette est faux |
|
| 926 | + $boucles[$id_boucle]->type_requete = false; |
|
| 927 | + } else { |
|
| 928 | + $boucles[$id_boucle] = $result; |
|
| 929 | + } |
|
| 930 | + $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 931 | + $all_res[] = &$boucles[$id_boucle]; |
|
| 932 | + if (!empty($suite)) { |
|
| 933 | + $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 934 | + } |
|
| 935 | + $texte = $suite; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 939 | 939 | } |
@@ -44,19 +44,19 @@ discard block |
||
| 44 | 44 | * Nom d'une balise #TOTO |
| 45 | 45 | * |
| 46 | 46 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 47 | -define('NOM_DE_CHAMP', "#((" . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 47 | +define('NOM_DE_CHAMP', "#((".NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 48 | 48 | /** Balise complète [...(#TOTO) ... ] */ |
| 49 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 49 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 50 | 50 | |
| 51 | 51 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 52 | 52 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 53 | 53 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 54 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 54 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 55 | 55 | |
| 56 | 56 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 57 | 57 | define('SQL_ARGS', '(\([^)]*\))'); |
| 58 | 58 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 59 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 59 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@phraser_inclure |
| 62 | 62 | function phraser_inclure($texte, $ligne, $result) { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @return array |
| 212 | 212 | **/ |
| 213 | 213 | function phraser_champs($texte, $ligne, $result) { |
| 214 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 214 | + while (preg_match("/".NOM_DE_CHAMP."/S", $texte, $match)) { |
|
| 215 | 215 | $p = strpos($texte, $match[0]); |
| 216 | 216 | // texte après la balise |
| 217 | 217 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $collecte[] = $champ; |
| 349 | 349 | $args = ltrim($regs[count($regs) - 1]); |
| 350 | 350 | } else { |
| 351 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 351 | + if (!preg_match("/".NOM_DE_CHAMP."([{|])/", $arg, $r)) { |
|
| 352 | 352 | // 0 est un aveu d'impuissance. A completer |
| 353 | 353 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 354 | 354 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 434 | 434 | $res = array(); |
| 435 | 435 | while (($p = strpos($texte, "%$sep")) !== false) { |
| 436 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 436 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 437 | 437 | break; |
| 438 | 438 | } |
| 439 | 439 | $debut = substr($texte, 0, $p); |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 602 | 602 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 603 | 603 | $c = null; |
| 604 | - eval('$c = ' . $m[4] . ';'); |
|
| 604 | + eval('$c = '.$m[4].';'); |
|
| 605 | 605 | if (isset($c)) { |
| 606 | 606 | $m[4] = $c; |
| 607 | 607 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | |
| 680 | 680 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 681 | 681 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 682 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 682 | + } elseif (preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 683 | 683 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
| 684 | 684 | $a2 = trim($m[8]); |
| 685 | 685 | if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
@@ -689,8 +689,8 @@ discard block |
||
| 689 | 689 | (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
| 690 | 690 | $m[6], $m[5]); |
| 691 | 691 | $crit->exclus = $m[1]; |
| 692 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 693 | - CHAMP_SQL_PLUS_FONC . |
|
| 692 | + } elseif (preg_match("/^([!]?)\s*(". |
|
| 693 | + CHAMP_SQL_PLUS_FONC. |
|
| 694 | 694 | ")\s*(\??)(.*)$/is", $param, $m)) { |
| 695 | 695 | // contient aussi les comparaisons implicites ! |
| 696 | 696 | // Comme ci-dessus: |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | $result->descr = $descr; |
| 770 | 770 | # attention: reperer la premiere des 2 balises: pre_boucle ou boucle |
| 771 | 771 | |
| 772 | - if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 772 | + if (!preg_match(",".BALISE_PRE_BOUCLE.'[0-9_],', $texte, $r) |
|
| 773 | 773 | or ($n = strpos($texte, $r[0])) === false |
| 774 | 774 | or ($n > $pos_boucle) |
| 775 | 775 | ) { |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | strlen(BALISE_PRE_BOUCLE), |
| 790 | 790 | $k - strlen(BALISE_PRE_BOUCLE)); |
| 791 | 791 | |
| 792 | - if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)) { |
|
| 792 | + if (!preg_match(",".BALISE_BOUCLE.$id_boucle."[[:space:]]*\(,", $milieu, $r)) { |
|
| 793 | 793 | $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
| 794 | 794 | erreur_squelette($err_b, $result); |
| 795 | 795 | $texte = substr($texte, $n + 1); |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | $milieu = ''; |
| 839 | 839 | } else { |
| 840 | 840 | $milieu = substr($milieu, 1); |
| 841 | - $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 841 | + $s = BALISE_FIN_BOUCLE.$id_boucle.">"; |
|
| 842 | 842 | $p = strpos($milieu, $s); |
| 843 | 843 | if ($p === false) { |
| 844 | 844 | $err_b = array( |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | // |
| 858 | 858 | // 1. Recuperer la partie conditionnelle apres |
| 859 | 859 | // |
| 860 | - $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 860 | + $s = BALISE_POST_BOUCLE.$id_boucle.">"; |
|
| 861 | 861 | $p = strpos($suite, $s); |
| 862 | 862 | if ($p !== false) { |
| 863 | 863 | $result->apres = substr($suite, 0, $p); |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | // |
| 868 | 868 | // 2. Recuperer la partie alternative |
| 869 | 869 | // |
| 870 | - $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 870 | + $s = BALISE_ALT_BOUCLE.$id_boucle.">"; |
|
| 871 | 871 | $p = strpos($suite, $s); |
| 872 | 872 | if ($p !== false) { |
| 873 | 873 | $result->altern = substr($suite, 0, $p); |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | * @param string|array $select Champs sélectionnés |
| 338 | 338 | * @param string|array $from Tables sélectionnées |
| 339 | 339 | * @param string|array $where Contraintes |
| 340 | - * @param string|array $groupby Regroupements |
|
| 341 | - * @param string|array $orderby Tris |
|
| 340 | + * @param string $groupby Regroupements |
|
| 341 | + * @param string $orderby Tris |
|
| 342 | 342 | * @param string $limit Limites de résultats |
| 343 | 343 | * @param string|array $having Contraintes posts sélections |
| 344 | 344 | * @param string $serveur Nom de la connexion |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | * @param int $row_number Position. Déplacer le pointeur à cette ligne |
| 971 | 971 | * @param string $serveur Nom de la connexion |
| 972 | 972 | * @param bool $requeter Inutilisé |
| 973 | - * @return bool True si déplacement réussi, false sinon. |
|
| 973 | + * @return boolean|null True si déplacement réussi, false sinon. |
|
| 974 | 974 | **/ |
| 975 | 975 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 976 | 976 | if ($r and mysqli_num_rows($r)) { |
@@ -50,11 +50,9 @@ |
||
| 50 | 50 | $port and !is_numeric($socket = $port) |
| 51 | 51 | and (!$host or $host=='localhost')) { |
| 52 | 52 | $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 53 | + } elseif ($port) { |
|
| 55 | 54 | $link = @mysqli_connect($host, $login, $pass, '', $port); |
| 56 | - } |
|
| 57 | - else { |
|
| 55 | + } else { |
|
| 58 | 56 | $link = @mysqli_connect($host, $login, $pass); |
| 59 | 57 | } |
| 60 | 58 | |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('_MYSQL_NOPLANES')) { |
| 27 | - define('_MYSQL_NOPLANES', true); |
|
| 27 | + define('_MYSQL_NOPLANES', true); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -41,104 +41,104 @@ discard block |
||
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | */ |
| 43 | 43 | function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
| 44 | - if (!extension_loaded('mysqli')) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host=='localhost')) { |
|
| 52 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$link) { |
|
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | - |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - $last = ''; |
|
| 67 | - if (!$db) { |
|
| 68 | - $ok = $link; |
|
| 69 | - $db = 'spip'; |
|
| 70 | - } else { |
|
| 71 | - $ok = mysqli_select_db($link, $db); |
|
| 72 | - if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | - ) { |
|
| 75 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | - _LOG_DEBUG); |
|
| 81 | - |
|
| 82 | - return !$ok ? false : array( |
|
| 83 | - 'db' => $db, |
|
| 84 | - 'last' => $last, |
|
| 85 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | - 'link' => $link, |
|
| 87 | - 'total_requetes' => 0, |
|
| 88 | - ); |
|
| 44 | + if (!extension_loaded('mysqli')) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host=='localhost')) { |
|
| 52 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | + } |
|
| 54 | + elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$link) { |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | + |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + $last = ''; |
|
| 67 | + if (!$db) { |
|
| 68 | + $ok = $link; |
|
| 69 | + $db = 'spip'; |
|
| 70 | + } else { |
|
| 71 | + $ok = mysqli_select_db($link, $db); |
|
| 72 | + if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | + ) { |
|
| 75 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | + _LOG_DEBUG); |
|
| 81 | + |
|
| 82 | + return !$ok ? false : array( |
|
| 83 | + 'db' => $db, |
|
| 84 | + 'last' => $last, |
|
| 85 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | + 'link' => $link, |
|
| 87 | + 'total_requetes' => 0, |
|
| 88 | + ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | $GLOBALS['spip_mysql_functions_1'] = array( |
| 93 | - 'alter' => 'spip_mysql_alter', |
|
| 94 | - 'count' => 'spip_mysql_count', |
|
| 95 | - 'countsel' => 'spip_mysql_countsel', |
|
| 96 | - 'create' => 'spip_mysql_create', |
|
| 97 | - 'create_base' => 'spip_mysql_create_base', |
|
| 98 | - 'create_view' => 'spip_mysql_create_view', |
|
| 99 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | - 'delete' => 'spip_mysql_delete', |
|
| 101 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | - 'errno' => 'spip_mysql_errno', |
|
| 104 | - 'error' => 'spip_mysql_error', |
|
| 105 | - 'explain' => 'spip_mysql_explain', |
|
| 106 | - 'fetch' => 'spip_mysql_fetch', |
|
| 107 | - 'seek' => 'spip_mysql_seek', |
|
| 108 | - 'free' => 'spip_mysql_free', |
|
| 109 | - 'hex' => 'spip_mysql_hex', |
|
| 110 | - 'in' => 'spip_mysql_in', |
|
| 111 | - 'insert' => 'spip_mysql_insert', |
|
| 112 | - 'insertq' => 'spip_mysql_insertq', |
|
| 113 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | - 'multi' => 'spip_mysql_multi', |
|
| 116 | - 'optimize' => 'spip_mysql_optimize', |
|
| 117 | - 'query' => 'spip_mysql_query', |
|
| 118 | - 'quote' => 'spip_mysql_quote', |
|
| 119 | - 'replace' => 'spip_mysql_replace', |
|
| 120 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | - 'repair' => 'spip_mysql_repair', |
|
| 122 | - 'select' => 'spip_mysql_select', |
|
| 123 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | - 'showbase' => 'spip_mysql_showbase', |
|
| 127 | - 'showtable' => 'spip_mysql_showtable', |
|
| 128 | - 'update' => 'spip_mysql_update', |
|
| 129 | - 'updateq' => 'spip_mysql_updateq', |
|
| 130 | - |
|
| 131 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | - 'charsets' => array( |
|
| 133 | - 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | - 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | - 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | - 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 93 | + 'alter' => 'spip_mysql_alter', |
|
| 94 | + 'count' => 'spip_mysql_count', |
|
| 95 | + 'countsel' => 'spip_mysql_countsel', |
|
| 96 | + 'create' => 'spip_mysql_create', |
|
| 97 | + 'create_base' => 'spip_mysql_create_base', |
|
| 98 | + 'create_view' => 'spip_mysql_create_view', |
|
| 99 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | + 'delete' => 'spip_mysql_delete', |
|
| 101 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | + 'errno' => 'spip_mysql_errno', |
|
| 104 | + 'error' => 'spip_mysql_error', |
|
| 105 | + 'explain' => 'spip_mysql_explain', |
|
| 106 | + 'fetch' => 'spip_mysql_fetch', |
|
| 107 | + 'seek' => 'spip_mysql_seek', |
|
| 108 | + 'free' => 'spip_mysql_free', |
|
| 109 | + 'hex' => 'spip_mysql_hex', |
|
| 110 | + 'in' => 'spip_mysql_in', |
|
| 111 | + 'insert' => 'spip_mysql_insert', |
|
| 112 | + 'insertq' => 'spip_mysql_insertq', |
|
| 113 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | + 'multi' => 'spip_mysql_multi', |
|
| 116 | + 'optimize' => 'spip_mysql_optimize', |
|
| 117 | + 'query' => 'spip_mysql_query', |
|
| 118 | + 'quote' => 'spip_mysql_quote', |
|
| 119 | + 'replace' => 'spip_mysql_replace', |
|
| 120 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | + 'repair' => 'spip_mysql_repair', |
|
| 122 | + 'select' => 'spip_mysql_select', |
|
| 123 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | + 'showbase' => 'spip_mysql_showbase', |
|
| 127 | + 'showtable' => 'spip_mysql_showtable', |
|
| 128 | + 'update' => 'spip_mysql_update', |
|
| 129 | + 'updateq' => 'spip_mysql_updateq', |
|
| 130 | + |
|
| 131 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | + 'charsets' => array( |
|
| 133 | + 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | + 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | + 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | + 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 137 | 137 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 138 | - 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 138 | + 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 139 | 139 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 140 | - 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | - ) |
|
| 140 | + 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | + ) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | * @return Object Information de connexion pour mysqli |
| 150 | 150 | */ |
| 151 | 151 | function _mysql_link($serveur = '') { |
| 152 | - $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 152 | + $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 153 | 153 | |
| 154 | - return $link; |
|
| 154 | + return $link; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @return resource Ressource de résultats pour fetch() |
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 167 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | + spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @return array Description du charset (son nom est dans 'charset') |
| 181 | 181 | */ |
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | - $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 183 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | + $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | + . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 187 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Resource Ressource pour fetch() |
| 200 | 200 | **/ |
| 201 | 201 | function spip_query_db($query, $serveur = '', $requeter = true) { |
| 202 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 202 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -216,61 +216,61 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 218 | 218 | |
| 219 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | - $prefixe = $connexion['prefixe']; |
|
| 221 | - $link = $connexion['link']; |
|
| 222 | - $db = $connexion['db']; |
|
| 223 | - |
|
| 224 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | - |
|
| 226 | - // renvoyer la requete inerte si demandee |
|
| 227 | - if (!$requeter) { |
|
| 228 | - return $query; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if (isset($_GET['var_profile'])) { |
|
| 232 | - include_spip('public/tracer'); |
|
| 233 | - $t = trace_query_start(); |
|
| 234 | - } else { |
|
| 235 | - $t = 0; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $connexion['last'] = $query; |
|
| 239 | - $connexion['total_requetes']++; |
|
| 240 | - |
|
| 241 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | - $debug = ''; |
|
| 243 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . $infos[0] . " | "; |
|
| 247 | - } |
|
| 248 | - $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $r = mysqli_query($link, $query . $debug); |
|
| 253 | - |
|
| 254 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 255 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 256 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 257 | - //Fermer la connexion defaillante |
|
| 258 | - mysqli_close($connexion['link']); |
|
| 259 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 260 | - //Relancer une connexion vierge |
|
| 261 | - spip_connect($serveur); |
|
| 262 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 263 | - $link = $connexion['link']; |
|
| 264 | - //On retente au cas où |
|
| 265 | - $r = mysqli_query($link, $query . $debug); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Log de l'erreur eventuelle |
|
| 270 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 271 | - $e .= spip_mysql_error($query, $serveur); |
|
| 272 | - } // et du fautif |
|
| 273 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 219 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | + $prefixe = $connexion['prefixe']; |
|
| 221 | + $link = $connexion['link']; |
|
| 222 | + $db = $connexion['db']; |
|
| 223 | + |
|
| 224 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | + |
|
| 226 | + // renvoyer la requete inerte si demandee |
|
| 227 | + if (!$requeter) { |
|
| 228 | + return $query; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if (isset($_GET['var_profile'])) { |
|
| 232 | + include_spip('public/tracer'); |
|
| 233 | + $t = trace_query_start(); |
|
| 234 | + } else { |
|
| 235 | + $t = 0; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $connexion['last'] = $query; |
|
| 239 | + $connexion['total_requetes']++; |
|
| 240 | + |
|
| 241 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | + $debug = ''; |
|
| 243 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | + list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ " . $infos[0] . " | "; |
|
| 247 | + } |
|
| 248 | + $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $r = mysqli_query($link, $query . $debug); |
|
| 253 | + |
|
| 254 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 255 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 256 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 257 | + //Fermer la connexion defaillante |
|
| 258 | + mysqli_close($connexion['link']); |
|
| 259 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 260 | + //Relancer une connexion vierge |
|
| 261 | + spip_connect($serveur); |
|
| 262 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 263 | + $link = $connexion['link']; |
|
| 264 | + //On retente au cas où |
|
| 265 | + $r = mysqli_query($link, $query . $debug); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Log de l'erreur eventuelle |
|
| 270 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 271 | + $e .= spip_mysql_error($query, $serveur); |
|
| 272 | + } // et du fautif |
|
| 273 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -285,12 +285,12 @@ discard block |
||
| 285 | 285 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 286 | 286 | */ |
| 287 | 287 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 288 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 289 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 290 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 291 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 288 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 289 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 290 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 291 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 292 | 292 | |
| 293 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 293 | + return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | * @return bool Toujours true |
| 304 | 304 | */ |
| 305 | 305 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 306 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 306 | + spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 307 | 307 | |
| 308 | - return true; |
|
| 308 | + return true; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -318,18 +318,18 @@ discard block |
||
| 318 | 318 | * @return array Tableau de l'explication |
| 319 | 319 | */ |
| 320 | 320 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 321 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 322 | - return array(); |
|
| 323 | - } |
|
| 324 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 325 | - $prefixe = $connexion['prefixe']; |
|
| 326 | - $link = $connexion['link']; |
|
| 327 | - $db = $connexion['db']; |
|
| 328 | - |
|
| 329 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 330 | - $r = mysqli_query($link, $query); |
|
| 331 | - |
|
| 332 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 321 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 322 | + return array(); |
|
| 323 | + } |
|
| 324 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 325 | + $prefixe = $connexion['prefixe']; |
|
| 326 | + $link = $connexion['link']; |
|
| 327 | + $db = $connexion['db']; |
|
| 328 | + |
|
| 329 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 330 | + $r = mysqli_query($link, $query); |
|
| 331 | + |
|
| 332 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -358,35 +358,35 @@ discard block |
||
| 358 | 358 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 359 | 359 | */ |
| 360 | 360 | function spip_mysql_select( |
| 361 | - $select, |
|
| 362 | - $from, |
|
| 363 | - $where = '', |
|
| 364 | - $groupby = '', |
|
| 365 | - $orderby = '', |
|
| 366 | - $limit = '', |
|
| 367 | - $having = '', |
|
| 368 | - $serveur = '', |
|
| 369 | - $requeter = true |
|
| 361 | + $select, |
|
| 362 | + $from, |
|
| 363 | + $where = '', |
|
| 364 | + $groupby = '', |
|
| 365 | + $orderby = '', |
|
| 366 | + $limit = '', |
|
| 367 | + $having = '', |
|
| 368 | + $serveur = '', |
|
| 369 | + $requeter = true |
|
| 370 | 370 | ) { |
| 371 | 371 | |
| 372 | 372 | |
| 373 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 374 | - $query = |
|
| 375 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 376 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 377 | - . calculer_mysql_expression('WHERE', $where) |
|
| 378 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 379 | - . calculer_mysql_expression('HAVING', $having) |
|
| 380 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 381 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 373 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 374 | + $query = |
|
| 375 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 376 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 377 | + . calculer_mysql_expression('WHERE', $where) |
|
| 378 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 379 | + . calculer_mysql_expression('HAVING', $having) |
|
| 380 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 381 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 382 | 382 | |
| 383 | - // renvoyer la requete inerte si demandee |
|
| 384 | - if ($requeter === false) { |
|
| 385 | - return $query; |
|
| 386 | - } |
|
| 387 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 383 | + // renvoyer la requete inerte si demandee |
|
| 384 | + if ($requeter === false) { |
|
| 385 | + return $query; |
|
| 386 | + } |
|
| 387 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 388 | 388 | |
| 389 | - return $r ? $r : $query; |
|
| 389 | + return $r ? $r : $query; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @return string Texte du orderby préparé |
| 404 | 404 | */ |
| 405 | 405 | function spip_mysql_order($orderby) { |
| 406 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 406 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -426,26 +426,26 @@ discard block |
||
| 426 | 426 | * Contrainte pour clause WHERE |
| 427 | 427 | */ |
| 428 | 428 | function calculer_mysql_where($v) { |
| 429 | - if (!is_array($v)) { |
|
| 430 | - return $v; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - $op = array_shift($v); |
|
| 434 | - if (!($n = count($v))) { |
|
| 435 | - return $op; |
|
| 436 | - } else { |
|
| 437 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 438 | - if ($n == 1) { |
|
| 439 | - return "$op($arg)"; |
|
| 440 | - } else { |
|
| 441 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 442 | - if ($n == 2) { |
|
| 443 | - return "($arg $op $arg2)"; |
|
| 444 | - } else { |
|
| 445 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - } |
|
| 429 | + if (!is_array($v)) { |
|
| 430 | + return $v; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + $op = array_shift($v); |
|
| 434 | + if (!($n = count($v))) { |
|
| 435 | + return $op; |
|
| 436 | + } else { |
|
| 437 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 438 | + if ($n == 1) { |
|
| 439 | + return "$op($arg)"; |
|
| 440 | + } else { |
|
| 441 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 442 | + if ($n == 2) { |
|
| 443 | + return "($arg $op $arg2)"; |
|
| 444 | + } else { |
|
| 445 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,21 +460,21 @@ discard block |
||
| 460 | 460 | * @return string Texte de l'expression, une partie donc, du texte la requête. |
| 461 | 461 | */ |
| 462 | 462 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 463 | - if (empty($v)) { |
|
| 464 | - return ''; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $exp = "\n$expression "; |
|
| 468 | - |
|
| 469 | - if (!is_array($v)) { |
|
| 470 | - return $exp . $v; |
|
| 471 | - } else { |
|
| 472 | - if (strtoupper($join) === 'AND') { |
|
| 473 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | - } else { |
|
| 475 | - return $exp . join($join, $v); |
|
| 476 | - } |
|
| 477 | - } |
|
| 463 | + if (empty($v)) { |
|
| 464 | + return ''; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $exp = "\n$expression "; |
|
| 468 | + |
|
| 469 | + if (!is_array($v)) { |
|
| 470 | + return $exp . $v; |
|
| 471 | + } else { |
|
| 472 | + if (strtoupper($join) === 'AND') { |
|
| 473 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | + } else { |
|
| 475 | + return $exp . join($join, $v); |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | |
@@ -485,26 +485,26 @@ discard block |
||
| 485 | 485 | * @return string Sélection de colonnes pour une clause SELECT |
| 486 | 486 | */ |
| 487 | 487 | function spip_mysql_select_as($args) { |
| 488 | - $res = ''; |
|
| 489 | - foreach ($args as $k => $v) { |
|
| 490 | - if (substr($k, -1) == '@') { |
|
| 491 | - // c'est une jointure qui se refere au from precedent |
|
| 492 | - // pas de virgule |
|
| 493 | - $res .= ' ' . $v; |
|
| 494 | - } else { |
|
| 495 | - if (!is_numeric($k)) { |
|
| 496 | - $p = strpos($v, " "); |
|
| 497 | - if ($p) { |
|
| 498 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 499 | - } else { |
|
| 500 | - $v .= " AS `$k`"; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - $res .= ', ' . $v; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return substr($res, 2); |
|
| 488 | + $res = ''; |
|
| 489 | + foreach ($args as $k => $v) { |
|
| 490 | + if (substr($k, -1) == '@') { |
|
| 491 | + // c'est une jointure qui se refere au from precedent |
|
| 492 | + // pas de virgule |
|
| 493 | + $res .= ' ' . $v; |
|
| 494 | + } else { |
|
| 495 | + if (!is_numeric($k)) { |
|
| 496 | + $p = strpos($v, " "); |
|
| 497 | + if ($p) { |
|
| 498 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 499 | + } else { |
|
| 500 | + $v .= " AS `$k`"; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + $res .= ', ' . $v; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + return substr($res, 2); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | |
@@ -528,42 +528,42 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 530 | 530 | |
| 531 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 532 | - $pref = '`' . $db . '`.'; |
|
| 533 | - } else { |
|
| 534 | - $pref = ''; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - if ($prefixe) { |
|
| 538 | - $pref .= $prefixe . "_"; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 542 | - $suite = ''; |
|
| 543 | - } else { |
|
| 544 | - $suite = strstr($query, $regs[0]); |
|
| 545 | - $query = substr($query, 0, -strlen($suite)); |
|
| 546 | - // propager le prefixe en cas de requete imbriquee |
|
| 547 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 548 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 549 | - if (stripos($suite, "SELECT") !== false) { |
|
| 550 | - list($suite, $textes) = query_echappe_textes($suite); |
|
| 551 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 552 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | - } |
|
| 554 | - $suite = query_reinjecte_textes($suite, $textes); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 558 | - |
|
| 559 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 560 | - if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
|
| 561 | - include_spip('inc/charsets'); |
|
| 562 | - $r = utf8_noplanes($r); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 566 | - return $r; |
|
| 531 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 532 | + $pref = '`' . $db . '`.'; |
|
| 533 | + } else { |
|
| 534 | + $pref = ''; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + if ($prefixe) { |
|
| 538 | + $pref .= $prefixe . "_"; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 542 | + $suite = ''; |
|
| 543 | + } else { |
|
| 544 | + $suite = strstr($query, $regs[0]); |
|
| 545 | + $query = substr($query, 0, -strlen($suite)); |
|
| 546 | + // propager le prefixe en cas de requete imbriquee |
|
| 547 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 548 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 549 | + if (stripos($suite, "SELECT") !== false) { |
|
| 550 | + list($suite, $textes) = query_echappe_textes($suite); |
|
| 551 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 552 | + $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | + } |
|
| 554 | + $suite = query_reinjecte_textes($suite, $textes); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 558 | + |
|
| 559 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 560 | + if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
|
| 561 | + include_spip('inc/charsets'); |
|
| 562 | + $r = utf8_noplanes($r); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 566 | + return $r; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | * - False en cas d'erreur. |
| 582 | 582 | **/ |
| 583 | 583 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 584 | - $link = _mysql_link($serveur); |
|
| 585 | - $ok = mysqli_select_db($link, $db); |
|
| 586 | - if (!$ok) { |
|
| 587 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 588 | - } |
|
| 584 | + $link = _mysql_link($serveur); |
|
| 585 | + $ok = mysqli_select_db($link, $db); |
|
| 586 | + if (!$ok) { |
|
| 587 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - return $ok; |
|
| 590 | + return $ok; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -608,14 +608,14 @@ discard block |
||
| 608 | 608 | * Liste de noms de bases de données |
| 609 | 609 | **/ |
| 610 | 610 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 611 | - $dbs = array(); |
|
| 612 | - if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 613 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 614 | - $dbs[] = $row['Database']; |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return $dbs; |
|
| 611 | + $dbs = array(); |
|
| 612 | + if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 613 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 614 | + $dbs[] = $row['Database']; |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return $dbs; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -638,72 +638,72 @@ discard block |
||
| 638 | 638 | * - true si la requête réussie, false sinon. |
| 639 | 639 | */ |
| 640 | 640 | function spip_mysql_create( |
| 641 | - $nom, |
|
| 642 | - $champs, |
|
| 643 | - $cles, |
|
| 644 | - $autoinc = false, |
|
| 645 | - $temporary = false, |
|
| 646 | - $serveur = '', |
|
| 647 | - $requeter = true |
|
| 641 | + $nom, |
|
| 642 | + $champs, |
|
| 643 | + $cles, |
|
| 644 | + $autoinc = false, |
|
| 645 | + $temporary = false, |
|
| 646 | + $serveur = '', |
|
| 647 | + $requeter = true |
|
| 648 | 648 | ) { |
| 649 | 649 | |
| 650 | - $query = ''; |
|
| 651 | - $keys = ''; |
|
| 652 | - $s = ''; |
|
| 653 | - $p = ''; |
|
| 654 | - |
|
| 655 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 656 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 657 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 658 | - return; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 662 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 663 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - foreach ($cles as $k => $v) { |
|
| 667 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 668 | - if ($k == "PRIMARY KEY") { |
|
| 669 | - $p = $v; |
|
| 670 | - } |
|
| 671 | - $s = ","; |
|
| 672 | - } |
|
| 673 | - $s = ''; |
|
| 674 | - |
|
| 675 | - $character_set = ""; |
|
| 676 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 677 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 678 | - } |
|
| 679 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 680 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - foreach ($champs as $k => $v) { |
|
| 684 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 685 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 686 | - if (preg_match(',(char|text),i', $defs[1]) |
|
| 687 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 688 | - ) { |
|
| 689 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $query .= "$s\n\t\t$k $v" |
|
| 694 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 695 | - ? " auto_increment" |
|
| 696 | - : '' |
|
| 697 | - ); |
|
| 698 | - $s = ","; |
|
| 699 | - } |
|
| 700 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 701 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 702 | - . " ENGINE=MyISAM" |
|
| 703 | - . ($character_set ? " DEFAULT $character_set" : "") |
|
| 704 | - . "\n"; |
|
| 705 | - |
|
| 706 | - return spip_mysql_query($q, $serveur); |
|
| 650 | + $query = ''; |
|
| 651 | + $keys = ''; |
|
| 652 | + $s = ''; |
|
| 653 | + $p = ''; |
|
| 654 | + |
|
| 655 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 656 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 657 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 658 | + return; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 662 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 663 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + foreach ($cles as $k => $v) { |
|
| 667 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 668 | + if ($k == "PRIMARY KEY") { |
|
| 669 | + $p = $v; |
|
| 670 | + } |
|
| 671 | + $s = ","; |
|
| 672 | + } |
|
| 673 | + $s = ''; |
|
| 674 | + |
|
| 675 | + $character_set = ""; |
|
| 676 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 677 | + $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 678 | + } |
|
| 679 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 680 | + $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + foreach ($champs as $k => $v) { |
|
| 684 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 685 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 686 | + if (preg_match(',(char|text),i', $defs[1]) |
|
| 687 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 688 | + ) { |
|
| 689 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $query .= "$s\n\t\t$k $v" |
|
| 694 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 695 | + ? " auto_increment" |
|
| 696 | + : '' |
|
| 697 | + ); |
|
| 698 | + $s = ","; |
|
| 699 | + } |
|
| 700 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 701 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 702 | + . " ENGINE=MyISAM" |
|
| 703 | + . ($character_set ? " DEFAULT $character_set" : "") |
|
| 704 | + . "\n"; |
|
| 705 | + |
|
| 706 | + return spip_mysql_query($q, $serveur); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | |
@@ -716,17 +716,17 @@ discard block |
||
| 716 | 716 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 717 | 717 | */ |
| 718 | 718 | function _mysql_remplacements_definitions_table($query) { |
| 719 | - // quelques remplacements |
|
| 720 | - $num = "(\s*\([0-9]*\))?"; |
|
| 721 | - $enum = "(\s*\([^\)]*\))?"; |
|
| 719 | + // quelques remplacements |
|
| 720 | + $num = "(\s*\([0-9]*\))?"; |
|
| 721 | + $enum = "(\s*\([^\)]*\))?"; |
|
| 722 | 722 | |
| 723 | - $remplace = array( |
|
| 724 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 725 | - ); |
|
| 723 | + $remplace = array( |
|
| 724 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 725 | + ); |
|
| 726 | 726 | |
| 727 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 727 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 728 | 728 | |
| 729 | - return $query; |
|
| 729 | + return $query; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * @return bool true si la base est créee. |
| 740 | 740 | **/ |
| 741 | 741 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 742 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 742 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | |
@@ -760,19 +760,19 @@ discard block |
||
| 760 | 760 | * - string texte de la requête si $requeter vaut false |
| 761 | 761 | */ |
| 762 | 762 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 763 | - if (!$query_select) { |
|
| 764 | - return false; |
|
| 765 | - } |
|
| 766 | - // vue deja presente |
|
| 767 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 768 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 763 | + if (!$query_select) { |
|
| 764 | + return false; |
|
| 765 | + } |
|
| 766 | + // vue deja presente |
|
| 767 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 768 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 769 | 769 | |
| 770 | - return false; |
|
| 771 | - } |
|
| 770 | + return false; |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 773 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 774 | 774 | |
| 775 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 775 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * - true si la requête a réussie, false sinon |
| 789 | 789 | */ |
| 790 | 790 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 791 | - if ($exist) { |
|
| 792 | - $exist = " IF EXISTS"; |
|
| 793 | - } |
|
| 791 | + if ($exist) { |
|
| 792 | + $exist = " IF EXISTS"; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 795 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -807,11 +807,11 @@ discard block |
||
| 807 | 807 | * - true si la requête a réussie, false sinon |
| 808 | 808 | */ |
| 809 | 809 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 810 | - if ($exist) { |
|
| 811 | - $exist = " IF EXISTS"; |
|
| 812 | - } |
|
| 810 | + if ($exist) { |
|
| 811 | + $exist = " IF EXISTS"; |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 814 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | /** |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | * Ressource à utiliser avec sql_fetch() |
| 829 | 829 | **/ |
| 830 | 830 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 831 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 831 | + return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | * - true si la requête a réussie, false sinon |
| 845 | 845 | */ |
| 846 | 846 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 847 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 847 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -868,86 +868,86 @@ discard block |
||
| 868 | 868 | * - array description de la table sinon |
| 869 | 869 | */ |
| 870 | 870 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 871 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 872 | - if (!$s) { |
|
| 873 | - return ''; |
|
| 874 | - } |
|
| 875 | - if (!$requeter) { |
|
| 876 | - return $s; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 880 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 881 | - $desc = $r[1]; |
|
| 882 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 883 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 884 | - if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 885 | - $namedkeys = $r[2]; |
|
| 886 | - $desc = $r[1]; |
|
| 887 | - } else { |
|
| 888 | - $namedkeys = ""; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $fields = array(); |
|
| 892 | - foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 893 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 894 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 895 | - } |
|
| 896 | - $keys = array(); |
|
| 897 | - |
|
| 898 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 899 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 900 | - $k = str_replace("`", '', trim($r[1])); |
|
| 901 | - $t = strtolower(str_replace("`", '', $r[2])); |
|
| 902 | - if ($k && !isset($keys[$k])) { |
|
| 903 | - $keys[$k] = $t; |
|
| 904 | - } else { |
|
| 905 | - $keys[] = $t; |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - spip_mysql_free($s); |
|
| 910 | - |
|
| 911 | - return array('field' => $fields, 'key' => $keys); |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 915 | - if ($res) { |
|
| 916 | - $nfields = array(); |
|
| 917 | - $nkeys = array(); |
|
| 918 | - while ($val = spip_mysql_fetch($res)) { |
|
| 919 | - $nfields[$val["Field"]] = $val['Type']; |
|
| 920 | - if ($val['Null'] == 'NO') { |
|
| 921 | - $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 922 | - } |
|
| 923 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 924 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 925 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 926 | - } else { |
|
| 927 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - if ($val['Extra']) { |
|
| 931 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 932 | - } |
|
| 933 | - if ($val['Key'] == 'PRI') { |
|
| 934 | - $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 935 | - } else { |
|
| 936 | - if ($val['Key'] == 'MUL') { |
|
| 937 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 938 | - } else { |
|
| 939 | - if ($val['Key'] == 'UNI') { |
|
| 940 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - spip_mysql_free($res); |
|
| 946 | - |
|
| 947 | - return array('field' => $nfields, 'key' => $nkeys); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return ""; |
|
| 871 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 872 | + if (!$s) { |
|
| 873 | + return ''; |
|
| 874 | + } |
|
| 875 | + if (!$requeter) { |
|
| 876 | + return $s; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 880 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 881 | + $desc = $r[1]; |
|
| 882 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 883 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 884 | + if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 885 | + $namedkeys = $r[2]; |
|
| 886 | + $desc = $r[1]; |
|
| 887 | + } else { |
|
| 888 | + $namedkeys = ""; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $fields = array(); |
|
| 892 | + foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 893 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 894 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 895 | + } |
|
| 896 | + $keys = array(); |
|
| 897 | + |
|
| 898 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 899 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 900 | + $k = str_replace("`", '', trim($r[1])); |
|
| 901 | + $t = strtolower(str_replace("`", '', $r[2])); |
|
| 902 | + if ($k && !isset($keys[$k])) { |
|
| 903 | + $keys[$k] = $t; |
|
| 904 | + } else { |
|
| 905 | + $keys[] = $t; |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + spip_mysql_free($s); |
|
| 910 | + |
|
| 911 | + return array('field' => $fields, 'key' => $keys); |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 915 | + if ($res) { |
|
| 916 | + $nfields = array(); |
|
| 917 | + $nkeys = array(); |
|
| 918 | + while ($val = spip_mysql_fetch($res)) { |
|
| 919 | + $nfields[$val["Field"]] = $val['Type']; |
|
| 920 | + if ($val['Null'] == 'NO') { |
|
| 921 | + $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 922 | + } |
|
| 923 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 924 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 925 | + $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 926 | + } else { |
|
| 927 | + $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + if ($val['Extra']) { |
|
| 931 | + $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 932 | + } |
|
| 933 | + if ($val['Key'] == 'PRI') { |
|
| 934 | + $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 935 | + } else { |
|
| 936 | + if ($val['Key'] == 'MUL') { |
|
| 937 | + $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 938 | + } else { |
|
| 939 | + if ($val['Key'] == 'UNI') { |
|
| 940 | + $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + spip_mysql_free($res); |
|
| 946 | + |
|
| 947 | + return array('field' => $nfields, 'key' => $nkeys); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return ""; |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | |
@@ -963,12 +963,12 @@ discard block |
||
| 963 | 963 | * @return array Ligne de résultat |
| 964 | 964 | */ |
| 965 | 965 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 966 | - if (!$t) { |
|
| 967 | - $t = MYSQLI_ASSOC; |
|
| 968 | - } |
|
| 969 | - if ($r) { |
|
| 970 | - return mysqli_fetch_array($r, $t); |
|
| 971 | - } |
|
| 966 | + if (!$t) { |
|
| 967 | + $t = MYSQLI_ASSOC; |
|
| 968 | + } |
|
| 969 | + if ($r) { |
|
| 970 | + return mysqli_fetch_array($r, $t); |
|
| 971 | + } |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | /** |
@@ -981,9 +981,9 @@ discard block |
||
| 981 | 981 | * @return bool True si déplacement réussi, false sinon. |
| 982 | 982 | **/ |
| 983 | 983 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 984 | - if ($r and mysqli_num_rows($r)) { |
|
| 985 | - return mysqli_data_seek($r, $row_number); |
|
| 986 | - } |
|
| 984 | + if ($r and mysqli_num_rows($r)) { |
|
| 985 | + return mysqli_data_seek($r, $row_number); |
|
| 986 | + } |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | |
@@ -1001,26 +1001,26 @@ discard block |
||
| 1001 | 1001 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1002 | 1002 | **/ |
| 1003 | 1003 | function spip_mysql_countsel( |
| 1004 | - $from = array(), |
|
| 1005 | - $where = array(), |
|
| 1006 | - $groupby = '', |
|
| 1007 | - $having = array(), |
|
| 1008 | - $serveur = '', |
|
| 1009 | - $requeter = true |
|
| 1004 | + $from = array(), |
|
| 1005 | + $where = array(), |
|
| 1006 | + $groupby = '', |
|
| 1007 | + $having = array(), |
|
| 1008 | + $serveur = '', |
|
| 1009 | + $requeter = true |
|
| 1010 | 1010 | ) { |
| 1011 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | - |
|
| 1013 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1014 | - if (!$requeter) { |
|
| 1015 | - return $r; |
|
| 1016 | - } |
|
| 1017 | - if (!$r instanceof mysqli_result) { |
|
| 1018 | - return 0; |
|
| 1019 | - } |
|
| 1020 | - list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1021 | - mysqli_free_result($r); |
|
| 1022 | - |
|
| 1023 | - return $c; |
|
| 1011 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | + |
|
| 1013 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1014 | + if (!$requeter) { |
|
| 1015 | + return $r; |
|
| 1016 | + } |
|
| 1017 | + if (!$r instanceof mysqli_result) { |
|
| 1018 | + return 0; |
|
| 1019 | + } |
|
| 1020 | + list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1021 | + mysqli_free_result($r); |
|
| 1022 | + |
|
| 1023 | + return $c; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1043,16 +1043,16 @@ discard block |
||
| 1043 | 1043 | * Erreur eventuelle |
| 1044 | 1044 | **/ |
| 1045 | 1045 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1046 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1047 | - $s = mysqli_error($link); |
|
| 1048 | - if ($s) { |
|
| 1049 | - $trace = debug_backtrace(); |
|
| 1050 | - if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1051 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return $s; |
|
| 1046 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1047 | + $s = mysqli_error($link); |
|
| 1048 | + if ($s) { |
|
| 1049 | + $trace = debug_backtrace(); |
|
| 1050 | + if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1051 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return $s; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | |
@@ -1067,18 +1067,18 @@ discard block |
||
| 1067 | 1067 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1070 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1071 | - $s = mysqli_errno($link); |
|
| 1072 | - // 2006 MySQL server has gone away |
|
| 1073 | - // 2013 Lost connection to MySQL server during query |
|
| 1074 | - if (in_array($s, array(2006, 2013))) { |
|
| 1075 | - define('spip_interdire_cache', true); |
|
| 1076 | - } |
|
| 1077 | - if ($s) { |
|
| 1078 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - return $s; |
|
| 1070 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1071 | + $s = mysqli_errno($link); |
|
| 1072 | + // 2006 MySQL server has gone away |
|
| 1073 | + // 2013 Lost connection to MySQL server during query |
|
| 1074 | + if (in_array($s, array(2006, 2013))) { |
|
| 1075 | + define('spip_interdire_cache', true); |
|
| 1076 | + } |
|
| 1077 | + if ($s) { |
|
| 1078 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + return $s; |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | |
@@ -1092,9 +1092,9 @@ discard block |
||
| 1092 | 1092 | * @return int Nombre de lignes |
| 1093 | 1093 | */ |
| 1094 | 1094 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1095 | - if ($r) { |
|
| 1096 | - return mysqli_num_rows($r); |
|
| 1097 | - } |
|
| 1095 | + if ($r) { |
|
| 1096 | + return mysqli_num_rows($r); |
|
| 1097 | + } |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | * @return bool True si réussi |
| 1111 | 1111 | */ |
| 1112 | 1112 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1113 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1113 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | |
@@ -1138,38 +1138,38 @@ discard block |
||
| 1138 | 1138 | **/ |
| 1139 | 1139 | function spip_mysql_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 1140 | 1140 | |
| 1141 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1142 | - $link = $connexion['link']; |
|
| 1143 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1144 | - |
|
| 1145 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1146 | - if (!$requeter) { |
|
| 1147 | - return $query; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - if (isset($_GET['var_profile'])) { |
|
| 1151 | - include_spip('public/tracer'); |
|
| 1152 | - $t = trace_query_start(); |
|
| 1153 | - $e = ''; |
|
| 1154 | - } else { |
|
| 1155 | - $t = 0; |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - $connexion['last'] = $query; |
|
| 1159 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1160 | - $r = false; |
|
| 1161 | - if (mysqli_query($link, $query)) { |
|
| 1162 | - $r = mysqli_insert_id($link); |
|
| 1163 | - } else { |
|
| 1164 | - // Log de l'erreur eventuelle |
|
| 1165 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1166 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1167 | - } // et du fautif |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1171 | - |
|
| 1172 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1141 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1142 | + $link = $connexion['link']; |
|
| 1143 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1144 | + |
|
| 1145 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1146 | + if (!$requeter) { |
|
| 1147 | + return $query; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + if (isset($_GET['var_profile'])) { |
|
| 1151 | + include_spip('public/tracer'); |
|
| 1152 | + $t = trace_query_start(); |
|
| 1153 | + $e = ''; |
|
| 1154 | + } else { |
|
| 1155 | + $t = 0; |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + $connexion['last'] = $query; |
|
| 1159 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1160 | + $r = false; |
|
| 1161 | + if (mysqli_query($link, $query)) { |
|
| 1162 | + $r = mysqli_insert_id($link); |
|
| 1163 | + } else { |
|
| 1164 | + // Log de l'erreur eventuelle |
|
| 1165 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1166 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1167 | + } // et du fautif |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1171 | + |
|
| 1172 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | /** |
@@ -1194,20 +1194,20 @@ discard block |
||
| 1194 | 1194 | **/ |
| 1195 | 1195 | function spip_mysql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1196 | 1196 | |
| 1197 | - if (!$desc) { |
|
| 1198 | - $desc = description_table($table, $serveur); |
|
| 1199 | - } |
|
| 1200 | - if (!$desc) { |
|
| 1201 | - $couples = array(); |
|
| 1202 | - } |
|
| 1203 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1197 | + if (!$desc) { |
|
| 1198 | + $desc = description_table($table, $serveur); |
|
| 1199 | + } |
|
| 1200 | + if (!$desc) { |
|
| 1201 | + $couples = array(); |
|
| 1202 | + } |
|
| 1203 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1204 | 1204 | |
| 1205 | - foreach ($couples as $champ => $val) { |
|
| 1206 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1207 | - } |
|
| 1205 | + foreach ($couples as $champ => $val) { |
|
| 1206 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1207 | + } |
|
| 1208 | 1208 | |
| 1209 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1210 | - $serveur, $requeter); |
|
| 1209 | + return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1210 | + $serveur, $requeter); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | |
@@ -1232,34 +1232,34 @@ discard block |
||
| 1232 | 1232 | **/ |
| 1233 | 1233 | function spip_mysql_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1234 | 1234 | |
| 1235 | - if (!$desc) { |
|
| 1236 | - $desc = description_table($table, $serveur); |
|
| 1237 | - } |
|
| 1238 | - if (!$desc) { |
|
| 1239 | - $tab_couples = array(); |
|
| 1240 | - } |
|
| 1241 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1242 | - |
|
| 1243 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1244 | - $valeurs = array(); |
|
| 1245 | - $r = false; |
|
| 1246 | - |
|
| 1247 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1248 | - foreach ($tab_couples as $couples) { |
|
| 1249 | - foreach ($couples as $champ => $val) { |
|
| 1250 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1251 | - } |
|
| 1252 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1253 | - if (count($valeurs) >= 100) { |
|
| 1254 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1255 | - $valeurs = array(); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - if (count($valeurs)) { |
|
| 1259 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1235 | + if (!$desc) { |
|
| 1236 | + $desc = description_table($table, $serveur); |
|
| 1237 | + } |
|
| 1238 | + if (!$desc) { |
|
| 1239 | + $tab_couples = array(); |
|
| 1240 | + } |
|
| 1241 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1242 | + |
|
| 1243 | + $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1244 | + $valeurs = array(); |
|
| 1245 | + $r = false; |
|
| 1246 | + |
|
| 1247 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1248 | + foreach ($tab_couples as $couples) { |
|
| 1249 | + foreach ($couples as $champ => $val) { |
|
| 1250 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1251 | + } |
|
| 1252 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1253 | + if (count($valeurs) >= 100) { |
|
| 1254 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1255 | + $valeurs = array(); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + if (count($valeurs)) { |
|
| 1259 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | /** |
@@ -1284,17 +1284,17 @@ discard block |
||
| 1284 | 1284 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1285 | 1285 | */ |
| 1286 | 1286 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1287 | - $set = array(); |
|
| 1288 | - foreach ($champs as $champ => $val) { |
|
| 1289 | - $set[] = $champ . "=$val"; |
|
| 1290 | - } |
|
| 1291 | - if (!empty($set)) { |
|
| 1292 | - return spip_mysql_query( |
|
| 1293 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1294 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1295 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1296 | - $serveur, $requeter); |
|
| 1297 | - } |
|
| 1287 | + $set = array(); |
|
| 1288 | + foreach ($champs as $champ => $val) { |
|
| 1289 | + $set[] = $champ . "=$val"; |
|
| 1290 | + } |
|
| 1291 | + if (!empty($set)) { |
|
| 1292 | + return spip_mysql_query( |
|
| 1293 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1294 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1295 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1296 | + $serveur, $requeter); |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1327,27 +1327,27 @@ discard block |
||
| 1327 | 1327 | */ |
| 1328 | 1328 | function spip_mysql_updateq($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1329 | 1329 | |
| 1330 | - if (!$champs) { |
|
| 1331 | - return; |
|
| 1332 | - } |
|
| 1333 | - if (!$desc) { |
|
| 1334 | - $desc = description_table($table, $serveur); |
|
| 1335 | - } |
|
| 1336 | - if (!$desc) { |
|
| 1337 | - $champs = array(); |
|
| 1338 | - } else { |
|
| 1339 | - $fields = $desc['field']; |
|
| 1340 | - } |
|
| 1341 | - $set = array(); |
|
| 1342 | - foreach ($champs as $champ => $val) { |
|
| 1343 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - return spip_mysql_query( |
|
| 1347 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1348 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1349 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1350 | - $serveur, $requeter); |
|
| 1330 | + if (!$champs) { |
|
| 1331 | + return; |
|
| 1332 | + } |
|
| 1333 | + if (!$desc) { |
|
| 1334 | + $desc = description_table($table, $serveur); |
|
| 1335 | + } |
|
| 1336 | + if (!$desc) { |
|
| 1337 | + $champs = array(); |
|
| 1338 | + } else { |
|
| 1339 | + $fields = $desc['field']; |
|
| 1340 | + } |
|
| 1341 | + $set = array(); |
|
| 1342 | + foreach ($champs as $champ => $val) { |
|
| 1343 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + return spip_mysql_query( |
|
| 1347 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1348 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1349 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1350 | + $serveur, $requeter); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | /** |
@@ -1363,20 +1363,20 @@ discard block |
||
| 1363 | 1363 | * - False en cas d'erreur. |
| 1364 | 1364 | **/ |
| 1365 | 1365 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1366 | - $res = spip_mysql_query( |
|
| 1367 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1368 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1369 | - $serveur, $requeter); |
|
| 1370 | - if (!$requeter) { |
|
| 1371 | - return $res; |
|
| 1372 | - } |
|
| 1373 | - if ($res) { |
|
| 1374 | - $link = _mysql_link($serveur); |
|
| 1375 | - |
|
| 1376 | - return mysqli_affected_rows($link); |
|
| 1377 | - } else { |
|
| 1378 | - return false; |
|
| 1379 | - } |
|
| 1366 | + $res = spip_mysql_query( |
|
| 1367 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1368 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1369 | + $serveur, $requeter); |
|
| 1370 | + if (!$requeter) { |
|
| 1371 | + return $res; |
|
| 1372 | + } |
|
| 1373 | + if ($res) { |
|
| 1374 | + $link = _mysql_link($serveur); |
|
| 1375 | + |
|
| 1376 | + return mysqli_affected_rows($link); |
|
| 1377 | + } else { |
|
| 1378 | + return false; |
|
| 1379 | + } |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | |
@@ -1405,8 +1405,8 @@ discard block |
||
| 1405 | 1405 | * - False en cas d'erreur. |
| 1406 | 1406 | **/ |
| 1407 | 1407 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1408 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1408 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | + array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | |
@@ -1435,14 +1435,14 @@ discard block |
||
| 1435 | 1435 | * - False en cas d'erreur. |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1438 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1439 | - $valeurs = array(); |
|
| 1440 | - foreach ($tab_couples as $couples) { |
|
| 1441 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1442 | - } |
|
| 1443 | - $valeurs = implode(', ', $valeurs); |
|
| 1444 | - |
|
| 1445 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1438 | + $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1439 | + $valeurs = array(); |
|
| 1440 | + foreach ($tab_couples as $couples) { |
|
| 1441 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1442 | + } |
|
| 1443 | + $valeurs = implode(', ', $valeurs); |
|
| 1444 | + |
|
| 1445 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | |
@@ -1457,32 +1457,32 @@ discard block |
||
| 1457 | 1457 | * @return string Texte de sélection pour la requête |
| 1458 | 1458 | */ |
| 1459 | 1459 | function spip_mysql_multi($objet, $lang) { |
| 1460 | - $lengthlang = strlen("[$lang]"); |
|
| 1461 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1467 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1468 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1470 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1471 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1472 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | - " TRIM(" . $objet . "), " . |
|
| 1474 | - " CONCAT( " . |
|
| 1475 | - " $debutchaine, " . |
|
| 1476 | - " IF( " . |
|
| 1477 | - " $poslang = 0, " . |
|
| 1478 | - " $chainemulti, " . |
|
| 1479 | - " $chainelang" . |
|
| 1480 | - " ), " . |
|
| 1481 | - " $finchaine" . |
|
| 1482 | - " ) " . |
|
| 1483 | - "))) AS multi"; |
|
| 1484 | - |
|
| 1485 | - return $retour; |
|
| 1460 | + $lengthlang = strlen("[$lang]"); |
|
| 1461 | + $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | + $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | + $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | + $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | + $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1467 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1468 | + $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | + $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1470 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1471 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1472 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | + " TRIM(" . $objet . "), " . |
|
| 1474 | + " CONCAT( " . |
|
| 1475 | + " $debutchaine, " . |
|
| 1476 | + " IF( " . |
|
| 1477 | + " $poslang = 0, " . |
|
| 1478 | + " $chainemulti, " . |
|
| 1479 | + " $chainelang" . |
|
| 1480 | + " ), " . |
|
| 1481 | + " $finchaine" . |
|
| 1482 | + " ) " . |
|
| 1483 | + "))) AS multi"; |
|
| 1484 | + |
|
| 1485 | + return $retour; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | /** |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * Valeur hexadécimale pour MySQL |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function spip_mysql_hex($v) { |
| 1499 | - return "0x" . $v; |
|
| 1499 | + return "0x" . $v; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | /** |
@@ -1512,22 +1512,22 @@ discard block |
||
| 1512 | 1512 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1513 | 1513 | */ |
| 1514 | 1514 | function spip_mysql_quote($v, $type = '') { |
| 1515 | - if ($type) { |
|
| 1516 | - if (!is_array($v)) { |
|
| 1517 | - return spip_mysql_cite($v, $type); |
|
| 1518 | - } |
|
| 1519 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1520 | - foreach ($v as $k => $r) { |
|
| 1521 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - return $v; |
|
| 1525 | - } |
|
| 1526 | - // si on ne connait pas le type, s'en remettre a _q : |
|
| 1527 | - // on ne fera pas mieux |
|
| 1528 | - else { |
|
| 1529 | - return _q($v); |
|
| 1530 | - } |
|
| 1515 | + if ($type) { |
|
| 1516 | + if (!is_array($v)) { |
|
| 1517 | + return spip_mysql_cite($v, $type); |
|
| 1518 | + } |
|
| 1519 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1520 | + foreach ($v as $k => $r) { |
|
| 1521 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + return $v; |
|
| 1525 | + } |
|
| 1526 | + // si on ne connait pas le type, s'en remettre a _q : |
|
| 1527 | + // on ne fera pas mieux |
|
| 1528 | + else { |
|
| 1529 | + return _q($v); |
|
| 1530 | + } |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | /** |
@@ -1543,17 +1543,17 @@ discard block |
||
| 1543 | 1543 | * Expression SQL |
| 1544 | 1544 | **/ |
| 1545 | 1545 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1546 | - return '(' |
|
| 1547 | - . $champ |
|
| 1548 | - . (($interval <= 0) ? '>' : '<') |
|
| 1549 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1550 | - . '(' |
|
| 1551 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1552 | - . ', INTERVAL ' |
|
| 1553 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1554 | - . ' ' |
|
| 1555 | - . $unite |
|
| 1556 | - . '))'; |
|
| 1546 | + return '(' |
|
| 1547 | + . $champ |
|
| 1548 | + . (($interval <= 0) ? '>' : '<') |
|
| 1549 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1550 | + . '(' |
|
| 1551 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1552 | + . ', INTERVAL ' |
|
| 1553 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1554 | + . ' ' |
|
| 1555 | + . $unite |
|
| 1556 | + . '))'; |
|
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | |
@@ -1577,21 +1577,21 @@ discard block |
||
| 1577 | 1577 | * Expression de requête SQL |
| 1578 | 1578 | **/ |
| 1579 | 1579 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1580 | - $n = $i = 0; |
|
| 1581 | - $in_sql = ""; |
|
| 1582 | - while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1583 | - if ((++$i) >= 255) { |
|
| 1584 | - $in_sql .= "($val $not IN (" . |
|
| 1585 | - substr($valeurs, 0, $n) . |
|
| 1586 | - "))\n" . |
|
| 1587 | - ($not ? "AND\t" : "OR\t"); |
|
| 1588 | - $valeurs = substr($valeurs, $n + 1); |
|
| 1589 | - $i = $n = 0; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1593 | - |
|
| 1594 | - return "($in_sql)"; |
|
| 1580 | + $n = $i = 0; |
|
| 1581 | + $in_sql = ""; |
|
| 1582 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1583 | + if ((++$i) >= 255) { |
|
| 1584 | + $in_sql .= "($val $not IN (" . |
|
| 1585 | + substr($valeurs, 0, $n) . |
|
| 1586 | + "))\n" . |
|
| 1587 | + ($not ? "AND\t" : "OR\t"); |
|
| 1588 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1589 | + $i = $n = 0; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1593 | + |
|
| 1594 | + return "($in_sql)"; |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | |
@@ -1608,16 +1608,16 @@ discard block |
||
| 1608 | 1608 | * @return string Expression de requête SQL |
| 1609 | 1609 | */ |
| 1610 | 1610 | function calcul_mysql_in($val, $valeurs, $not = '') { |
| 1611 | - if (is_array($valeurs)) { |
|
| 1612 | - $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1613 | - } elseif ($valeurs[0] === ',') { |
|
| 1614 | - $valeurs = substr($valeurs, 1); |
|
| 1615 | - } |
|
| 1616 | - if (!strlen(trim($valeurs))) { |
|
| 1617 | - return ($not ? "0=0" : '0=1'); |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - return spip_mysql_in($val, $valeurs, $not); |
|
| 1611 | + if (is_array($valeurs)) { |
|
| 1612 | + $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1613 | + } elseif ($valeurs[0] === ',') { |
|
| 1614 | + $valeurs = substr($valeurs, 1); |
|
| 1615 | + } |
|
| 1616 | + if (!strlen(trim($valeurs))) { |
|
| 1617 | + return ($not ? "0=0" : '0=1'); |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + return spip_mysql_in($val, $valeurs, $not); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | |
@@ -1629,26 +1629,26 @@ discard block |
||
| 1629 | 1629 | * @return string|number Texte ou nombre échappé |
| 1630 | 1630 | */ |
| 1631 | 1631 | function spip_mysql_cite($v, $type) { |
| 1632 | - if (is_null($v) |
|
| 1633 | - and stripos($type, "NOT NULL") === false |
|
| 1634 | - ) { |
|
| 1635 | - return 'NULL'; |
|
| 1636 | - } // null php se traduit en NULL SQL |
|
| 1637 | - if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1638 | - return $v; |
|
| 1639 | - } |
|
| 1640 | - if (sql_test_int($type)) { |
|
| 1641 | - if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1642 | - and $v[0] == '0' and $v[1] == 'x') |
|
| 1643 | - ) { |
|
| 1644 | - return $v; |
|
| 1645 | - } // si pas numerique, forcer le intval |
|
| 1646 | - else { |
|
| 1647 | - return intval($v); |
|
| 1648 | - } |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - return ("'" . addslashes($v) . "'"); |
|
| 1632 | + if (is_null($v) |
|
| 1633 | + and stripos($type, "NOT NULL") === false |
|
| 1634 | + ) { |
|
| 1635 | + return 'NULL'; |
|
| 1636 | + } // null php se traduit en NULL SQL |
|
| 1637 | + if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1638 | + return $v; |
|
| 1639 | + } |
|
| 1640 | + if (sql_test_int($type)) { |
|
| 1641 | + if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1642 | + and $v[0] == '0' and $v[1] == 'x') |
|
| 1643 | + ) { |
|
| 1644 | + return $v; |
|
| 1645 | + } // si pas numerique, forcer le intval |
|
| 1646 | + else { |
|
| 1647 | + return intval($v); |
|
| 1648 | + } |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + return ("'" . addslashes($v) . "'"); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | |
@@ -1672,21 +1672,21 @@ discard block |
||
| 1672 | 1672 | */ |
| 1673 | 1673 | function spip_get_lock($nom, $timeout = 0) { |
| 1674 | 1674 | |
| 1675 | - define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1675 | + define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1676 | 1676 | |
| 1677 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1678 | - $bd = $connexion['db']; |
|
| 1679 | - $prefixe = $connexion['prefixe']; |
|
| 1680 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1677 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1678 | + $bd = $connexion['db']; |
|
| 1679 | + $prefixe = $connexion['prefixe']; |
|
| 1680 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1681 | 1681 | |
| 1682 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1682 | + $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1683 | 1683 | |
| 1684 | - $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1685 | - if (!$q) { |
|
| 1686 | - spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1687 | - } |
|
| 1684 | + $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1685 | + if (!$q) { |
|
| 1686 | + spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1687 | + } |
|
| 1688 | 1688 | |
| 1689 | - return $q['n']; |
|
| 1689 | + return $q['n']; |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | |
@@ -1703,13 +1703,13 @@ discard block |
||
| 1703 | 1703 | */ |
| 1704 | 1704 | function spip_release_lock($nom) { |
| 1705 | 1705 | |
| 1706 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1707 | - $bd = $connexion['db']; |
|
| 1708 | - $prefixe = $connexion['prefixe']; |
|
| 1709 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1706 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1707 | + $bd = $connexion['db']; |
|
| 1708 | + $prefixe = $connexion['prefixe']; |
|
| 1709 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1710 | 1710 | |
| 1711 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1712 | - mysqli_query(_mysql_link(), $q); |
|
| 1711 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1712 | + mysqli_query(_mysql_link(), $q); |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | |
@@ -1720,7 +1720,7 @@ discard block |
||
| 1720 | 1720 | * True si on a les fonctions, false sinon |
| 1721 | 1721 | */ |
| 1722 | 1722 | function spip_versions_mysql() { |
| 1723 | - return function_exists('mysqli_query'); |
|
| 1723 | + return function_exists('mysqli_query'); |
|
| 1724 | 1724 | } |
| 1725 | 1725 | |
| 1726 | 1726 | |
@@ -1733,20 +1733,20 @@ discard block |
||
| 1733 | 1733 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1734 | 1734 | */ |
| 1735 | 1735 | function test_rappel_nom_base_mysql($server_db) { |
| 1736 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1737 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1738 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1736 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1737 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1738 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1739 | 1739 | |
| 1740 | - if ($ok) { |
|
| 1741 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1740 | + if ($ok) { |
|
| 1741 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1742 | 1742 | |
| 1743 | - return ''; |
|
| 1744 | - } else { |
|
| 1745 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1743 | + return ''; |
|
| 1744 | + } else { |
|
| 1745 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1746 | 1746 | |
| 1747 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1748 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1749 | - } |
|
| 1747 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1748 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1749 | + } |
|
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | /** |
@@ -1760,13 +1760,13 @@ discard block |
||
| 1760 | 1760 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1761 | 1761 | */ |
| 1762 | 1762 | function test_sql_mode_mysql($server_db) { |
| 1763 | - $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1764 | - $row = sql_fetch($res, $server_db); |
|
| 1765 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1766 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1763 | + $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1764 | + $row = sql_fetch($res, $server_db); |
|
| 1765 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1766 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1767 | 1767 | |
| 1768 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1769 | - } |
|
| 1768 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1769 | + } |
|
| 1770 | 1770 | |
| 1771 | - return ''; |
|
| 1771 | + return ''; |
|
| 1772 | 1772 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
| 49 | 49 | if ( |
| 50 | 50 | $port and !is_numeric($socket = $port) |
| 51 | - and (!$host or $host=='localhost')) { |
|
| 51 | + and (!$host or $host == 'localhost')) { |
|
| 52 | 52 | $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
| 53 | 53 | } |
| 54 | 54 | elseif ($port) { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if (!$link) { |
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 63 | 63 | |
| 64 | 64 | return false; |
| 65 | 65 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? "operationnelle" : 'impossible'), |
|
| 80 | 80 | _LOG_DEBUG); |
| 81 | 81 | |
| 82 | 82 | return !$ok ? false : array( |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | 167 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 168 | + spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES "._q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | 183 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 184 | 184 | $connexion['last'] = $c = "SHOW CHARACTER SET" |
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 185 | + . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | 187 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 188 | 188 | } |
@@ -242,14 +242,14 @@ discard block |
||
| 242 | 242 | $debug = ''; |
| 243 | 243 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 244 | 244 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . $infos[0] . " | "; |
|
| 245 | + list(, $id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ ".$infos[0]." | "; |
|
| 247 | 247 | } |
| 248 | - $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 248 | + $debug .= $_SERVER['REQUEST_URI'].' + '.$GLOBALS['ip']; |
|
| 249 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $r = mysqli_query($link, $query . $debug); |
|
| 252 | + $r = mysqli_query($link, $query.$debug); |
|
| 253 | 253 | |
| 254 | 254 | //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
| 255 | 255 | if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 263 | 263 | $link = $connexion['link']; |
| 264 | 264 | //On retente au cas où |
| 265 | - $r = mysqli_query($link, $query . $debug); |
|
| 265 | + $r = mysqli_query($link, $query.$debug); |
|
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 291 | 291 | $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
| 292 | 292 | |
| 293 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 293 | + return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @return bool Toujours true |
| 304 | 304 | */ |
| 305 | 305 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 306 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 306 | + spip_mysql_query("OPTIMIZE TABLE ".$table); |
|
| 307 | 307 | |
| 308 | 308 | return true; |
| 309 | 309 | } |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $link = $connexion['link']; |
| 327 | 327 | $db = $connexion['db']; |
| 328 | 328 | |
| 329 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 329 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 330 | 330 | $r = mysqli_query($link, $query); |
| 331 | 331 | |
| 332 | 332 | return spip_mysql_fetch($r, null, $serveur); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | . calculer_mysql_expression('WHERE', $where) |
| 378 | 378 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 379 | 379 | . calculer_mysql_expression('HAVING', $having) |
| 380 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 380 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 381 | 381 | . ($limit ? "\nLIMIT $limit" : ''); |
| 382 | 382 | |
| 383 | 383 | // renvoyer la requete inerte si demandee |
@@ -467,12 +467,12 @@ discard block |
||
| 467 | 467 | $exp = "\n$expression "; |
| 468 | 468 | |
| 469 | 469 | if (!is_array($v)) { |
| 470 | - return $exp . $v; |
|
| 470 | + return $exp.$v; |
|
| 471 | 471 | } else { |
| 472 | 472 | if (strtoupper($join) === 'AND') { |
| 473 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 473 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | 474 | } else { |
| 475 | - return $exp . join($join, $v); |
|
| 475 | + return $exp.join($join, $v); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
@@ -490,17 +490,17 @@ discard block |
||
| 490 | 490 | if (substr($k, -1) == '@') { |
| 491 | 491 | // c'est une jointure qui se refere au from precedent |
| 492 | 492 | // pas de virgule |
| 493 | - $res .= ' ' . $v; |
|
| 493 | + $res .= ' '.$v; |
|
| 494 | 494 | } else { |
| 495 | 495 | if (!is_numeric($k)) { |
| 496 | 496 | $p = strpos($v, " "); |
| 497 | 497 | if ($p) { |
| 498 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 498 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 499 | 499 | } else { |
| 500 | 500 | $v .= " AS `$k`"; |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | - $res .= ', ' . $v; |
|
| 503 | + $res .= ', '.$v; |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 530 | 530 | |
| 531 | 531 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 532 | - $pref = '`' . $db . '`.'; |
|
| 532 | + $pref = '`'.$db.'`.'; |
|
| 533 | 533 | } else { |
| 534 | 534 | $pref = ''; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | if ($prefixe) { |
| 538 | - $pref .= $prefixe . "_"; |
|
| 538 | + $pref .= $prefixe."_"; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -549,12 +549,12 @@ discard block |
||
| 549 | 549 | if (stripos($suite, "SELECT") !== false) { |
| 550 | 550 | list($suite, $textes) = query_echappe_textes($suite); |
| 551 | 551 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
| 552 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 552 | + $suite = $r[1]._mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | 553 | } |
| 554 | 554 | $suite = query_reinjecte_textes($suite, $textes); |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 557 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 558 | 558 | |
| 559 | 559 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 560 | 560 | if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | $link = _mysql_link($serveur); |
| 585 | 585 | $ok = mysqli_select_db($link, $db); |
| 586 | 586 | if (!$ok) { |
| 587 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 587 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | return $ok; |
@@ -674,10 +674,10 @@ discard block |
||
| 674 | 674 | |
| 675 | 675 | $character_set = ""; |
| 676 | 676 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 677 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 677 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 678 | 678 | } |
| 679 | 679 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 680 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 680 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | foreach ($champs as $k => $v) { |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | if (preg_match(',(char|text),i', $defs[1]) |
| 687 | 687 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 688 | 688 | ) { |
| 689 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 689 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | $s = ","; |
| 699 | 699 | } |
| 700 | 700 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 701 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 701 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').")" |
|
| 702 | 702 | . " ENGINE=MyISAM" |
| 703 | 703 | . ($character_set ? " DEFAULT $character_set" : "") |
| 704 | 704 | . "\n"; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | return false; |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 773 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 774 | 774 | |
| 775 | 775 | return spip_mysql_query($query, $serveur, $requeter); |
| 776 | 776 | } |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | * Ressource à utiliser avec sql_fetch() |
| 829 | 829 | **/ |
| 830 | 830 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 831 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 831 | + return spip_mysql_query("SHOW TABLES LIKE "._q($match), $serveur, $requeter); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -922,22 +922,22 @@ discard block |
||
| 922 | 922 | } |
| 923 | 923 | if ($val['Default'] === '0' || $val['Default']) { |
| 924 | 924 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 925 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 925 | + $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
|
| 926 | 926 | } else { |
| 927 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 927 | + $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
|
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | if ($val['Extra']) { |
| 931 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 931 | + $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 932 | 932 | } |
| 933 | 933 | if ($val['Key'] == 'PRI') { |
| 934 | 934 | $nkeys['PRIMARY KEY'] = $val["Field"]; |
| 935 | 935 | } else { |
| 936 | 936 | if ($val['Key'] == 'MUL') { |
| 937 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 937 | + $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
|
| 938 | 938 | } else { |
| 939 | 939 | if ($val['Key'] == 'UNI') { |
| 940 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 940 | + $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
|
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | } |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | $serveur = '', |
| 1009 | 1009 | $requeter = true |
| 1010 | 1010 | ) { |
| 1011 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1011 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | 1012 | |
| 1013 | 1013 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1014 | 1014 | if (!$requeter) { |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | if ($s) { |
| 1049 | 1049 | $trace = debug_backtrace(); |
| 1050 | 1050 | if ($trace[0]['function'] != "spip_mysql_error") { |
| 1051 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1051 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1209 | + return spip_mysql_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, |
|
| 1210 | 1210 | $serveur, $requeter); |
| 1211 | 1211 | } |
| 1212 | 1212 | |
@@ -1240,7 +1240,7 @@ discard block |
||
| 1240 | 1240 | } |
| 1241 | 1241 | $fields = isset($desc['field']) ? $desc['field'] : array(); |
| 1242 | 1242 | |
| 1243 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1243 | + $cles = "(".join(',', array_keys(reset($tab_couples))).')'; |
|
| 1244 | 1244 | $valeurs = array(); |
| 1245 | 1245 | $r = false; |
| 1246 | 1246 | |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | foreach ($couples as $champ => $val) { |
| 1250 | 1250 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1251 | 1251 | } |
| 1252 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1252 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1253 | 1253 | if (count($valeurs) >= 100) { |
| 1254 | 1254 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1255 | 1255 | $valeurs = array(); |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1287 | 1287 | $set = array(); |
| 1288 | 1288 | foreach ($champs as $champ => $val) { |
| 1289 | - $set[] = $champ . "=$val"; |
|
| 1289 | + $set[] = $champ."=$val"; |
|
| 1290 | 1290 | } |
| 1291 | 1291 | if (!empty($set)) { |
| 1292 | 1292 | return spip_mysql_query( |
@@ -1340,7 +1340,7 @@ discard block |
||
| 1340 | 1340 | } |
| 1341 | 1341 | $set = array(); |
| 1342 | 1342 | foreach ($champs as $champ => $val) { |
| 1343 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1343 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | return spip_mysql_query( |
@@ -1405,8 +1405,8 @@ discard block |
||
| 1405 | 1405 | * - False en cas d'erreur. |
| 1406 | 1406 | **/ |
| 1407 | 1407 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1408 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1408 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join(',', |
|
| 1409 | + array_map('_q', $couples)).')', $serveur, $requeter); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | |
@@ -1435,10 +1435,10 @@ discard block |
||
| 1435 | 1435 | * - False en cas d'erreur. |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1438 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1438 | + $cles = "(".join(',', array_keys($tab_couples[0])).')'; |
|
| 1439 | 1439 | $valeurs = array(); |
| 1440 | 1440 | foreach ($tab_couples as $couples) { |
| 1441 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1441 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1442 | 1442 | } |
| 1443 | 1443 | $valeurs = implode(', ', $valeurs); |
| 1444 | 1444 | |
@@ -1458,28 +1458,28 @@ discard block |
||
| 1458 | 1458 | */ |
| 1459 | 1459 | function spip_mysql_multi($objet, $lang) { |
| 1460 | 1460 | $lengthlang = strlen("[$lang]"); |
| 1461 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1461 | + $posmulti = "INSTR(".$objet.", '<multi>')"; |
|
| 1462 | + $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
|
| 1463 | + $debutchaine = "LEFT(".$objet.", $posmulti-1)"; |
|
| 1464 | + $finchaine = "RIGHT(".$objet.", CHAR_LENGTH(".$objet.") -(7+$posfinmulti))"; |
|
| 1465 | + $chainemulti = "TRIM(SUBSTRING(".$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1467 | 1467 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1468 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1468 | + $chainelang = "TRIM(SUBSTRING(".$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | + $posfinlang = "INSTR(".$chainelang.", '[')"; |
|
| 1470 | 1470 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1471 | 1471 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1472 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | - " TRIM(" . $objet . "), " . |
|
| 1474 | - " CONCAT( " . |
|
| 1475 | - " $debutchaine, " . |
|
| 1476 | - " IF( " . |
|
| 1477 | - " $poslang = 0, " . |
|
| 1478 | - " $chainemulti, " . |
|
| 1479 | - " $chainelang" . |
|
| 1480 | - " ), " . |
|
| 1481 | - " $finchaine" . |
|
| 1482 | - " ) " . |
|
| 1472 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1473 | + " TRIM(".$objet."), ". |
|
| 1474 | + " CONCAT( ". |
|
| 1475 | + " $debutchaine, ". |
|
| 1476 | + " IF( ". |
|
| 1477 | + " $poslang = 0, ". |
|
| 1478 | + " $chainemulti, ". |
|
| 1479 | + " $chainelang". |
|
| 1480 | + " ), ". |
|
| 1481 | + " $finchaine". |
|
| 1482 | + " ) ". |
|
| 1483 | 1483 | "))) AS multi"; |
| 1484 | 1484 | |
| 1485 | 1485 | return $retour; |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * Valeur hexadécimale pour MySQL |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function spip_mysql_hex($v) { |
| 1499 | - return "0x" . $v; |
|
| 1499 | + return "0x".$v; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | /** |
@@ -1581,9 +1581,9 @@ discard block |
||
| 1581 | 1581 | $in_sql = ""; |
| 1582 | 1582 | while ($n = strpos($valeurs, ',', $n + 1)) { |
| 1583 | 1583 | if ((++$i) >= 255) { |
| 1584 | - $in_sql .= "($val $not IN (" . |
|
| 1585 | - substr($valeurs, 0, $n) . |
|
| 1586 | - "))\n" . |
|
| 1584 | + $in_sql .= "($val $not IN (". |
|
| 1585 | + substr($valeurs, 0, $n). |
|
| 1586 | + "))\n". |
|
| 1587 | 1587 | ($not ? "AND\t" : "OR\t"); |
| 1588 | 1588 | $valeurs = substr($valeurs, $n + 1); |
| 1589 | 1589 | $i = $n = 0; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | } |
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | - return ("'" . addslashes($v) . "'"); |
|
| 1651 | + return ("'".addslashes($v)."'"); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | |
@@ -1677,9 +1677,9 @@ discard block |
||
| 1677 | 1677 | $connexion = &$GLOBALS['connexions'][0]; |
| 1678 | 1678 | $bd = $connexion['db']; |
| 1679 | 1679 | $prefixe = $connexion['prefixe']; |
| 1680 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1680 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1681 | 1681 | |
| 1682 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1682 | + $connexion['last'] = $q = "SELECT GET_LOCK("._q($nom).", $timeout) AS n"; |
|
| 1683 | 1683 | |
| 1684 | 1684 | $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
| 1685 | 1685 | if (!$q) { |
@@ -1706,9 +1706,9 @@ discard block |
||
| 1706 | 1706 | $connexion = &$GLOBALS['connexions'][0]; |
| 1707 | 1707 | $bd = $connexion['db']; |
| 1708 | 1708 | $prefixe = $connexion['prefixe']; |
| 1709 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1709 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1710 | 1710 | |
| 1711 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1711 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK("._q($nom).")"; |
|
| 1712 | 1712 | mysqli_query(_mysql_link(), $q); |
| 1713 | 1713 | } |
| 1714 | 1714 | |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | } else { |
| 1745 | 1745 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1746 | 1746 | |
| 1747 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1747 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1748 | 1748 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1749 | 1749 | } |
| 1750 | 1750 | } |
@@ -319,7 +319,7 @@ |
||
| 319 | 319 | /** |
| 320 | 320 | * Constructeur |
| 321 | 321 | * |
| 322 | - * @param array $process ? |
|
| 322 | + * @param boolean $process ? |
|
| 323 | 323 | **/ |
| 324 | 324 | public function __construct($process = array()) { |
| 325 | 325 | if (is_array($process)) { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,333 +23,333 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | 25 | |
| 26 | - // http://code.spip.net/@validerElement |
|
| 27 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | - if ($p = strpos($name, ':')) { |
|
| 30 | - $name = substr($name, $p + 1); |
|
| 31 | - $p = isset($this->dtc->elements[$name]); |
|
| 32 | - } |
|
| 33 | - if (!$p) { |
|
| 34 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | - . _T('zxml_inconnu_balise')); |
|
| 36 | - |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - // controler les filles illegitimes, ca suffit |
|
| 41 | - $depth = $this->depth; |
|
| 42 | - $ouvrant = $this->ouvrant; |
|
| 43 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | - if (isset($ouvrant[$depth])) { |
|
| 45 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | - $pere = $r[1]; |
|
| 47 | - #spip_log("pere $pere"); |
|
| 48 | - if (isset($this->dtc->elements[$pere])) { |
|
| 49 | - $fils = $this->dtc->elements[$pere]; |
|
| 50 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | - if (!($p = @in_array($name, $fils))) { |
|
| 52 | - if ($p = strpos($name, ':')) { |
|
| 53 | - $p = substr($name, $p + 1); |
|
| 54 | - $p = @in_array($p, $fils); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - if (!$p) { |
|
| 58 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | - . _T('zxml_non_fils') |
|
| 61 | - . ' <b>' |
|
| 62 | - . $pere |
|
| 63 | - . '</b>' |
|
| 64 | - . (!$bons_peres ? '' |
|
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | - $frat = substr($depth, 2); |
|
| 68 | - if (!isset($this->fratrie[$frat])) { |
|
| 69 | - $this->fratrie[$frat] = ''; |
|
| 70 | - } |
|
| 71 | - $this->fratrie[$frat] .= "$name "; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | - $this->fratrie[$depth] = ''; |
|
| 79 | - } |
|
| 80 | - if (isset($this->dtc->attributs[$name])) { |
|
| 81 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | - . ' : ' |
|
| 85 | - . _T('zxml_obligatoire_attribut') |
|
| 86 | - . " <b>$name</b>"); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // http://code.spip.net/@validerAttribut |
|
| 93 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | - // Si la balise est inconnue, eviter d'insister |
|
| 95 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $a = $this->dtc->attributs[$bal]; |
|
| 100 | - if (!isset($a[$name])) { |
|
| 101 | - $bons = join(', ', array_keys($a)); |
|
| 102 | - if ($bons) { |
|
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 107 | - "'"; |
|
| 108 | - } |
|
| 109 | - $bons .= " style='font-weight: bold'"; |
|
| 110 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | - . " <a$bons>$bal</a> (" |
|
| 113 | - . _T('zxml_survoler') |
|
| 114 | - . ")"); |
|
| 115 | - } else { |
|
| 116 | - $type = $a[$name][0]; |
|
| 117 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | - } else { |
|
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // http://code.spip.net/@validerAttribut_ID |
|
| 137 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | - if (isset($this->ids[$val])) { |
|
| 139 | - list($l, $c) = $this->ids[$val]; |
|
| 140 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | - . _T('zxml_valeur_attribut') |
|
| 142 | - . " <b>$name</b> " |
|
| 143 | - . _T('zxml_de') |
|
| 144 | - . " <b>$bal</b> " |
|
| 145 | - . _T('zxml_vu') |
|
| 146 | - . " (L$l,C$c)"); |
|
| 147 | - } else { |
|
| 148 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | - $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // http://code.spip.net/@validerAttribut_IDREF |
|
| 154 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // http://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | - $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // http://code.spip.net/@valider_motif |
|
| 164 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | - if (!preg_match($motif, $val)) { |
|
| 166 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | - . _T('zxml_valeur_attribut') |
|
| 168 | - . " <b>$name</b> " |
|
| 169 | - . _T('zxml_de') |
|
| 170 | - . " <b>$bal</b> " |
|
| 171 | - . _T('zxml_non_conforme') |
|
| 172 | - . "</p><p>" |
|
| 173 | - . "<b>" . $motif . "</b>"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // http://code.spip.net/@valider_idref |
|
| 178 | - public function valider_idref($nom, $ligne, $col) { |
|
| 179 | - if (!isset($this->ids[$nom])) { |
|
| 180 | - $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // http://code.spip.net/@valider_passe2 |
|
| 185 | - public function valider_passe2() { |
|
| 186 | - if (!$this->err) { |
|
| 187 | - foreach ($this->idrefs as $idref) { |
|
| 188 | - list($nom, $ligne, $col) = $idref; |
|
| 189 | - $this->valider_idref($nom, $ligne, $col); |
|
| 190 | - } |
|
| 191 | - foreach ($this->idrefss as $idref) { |
|
| 192 | - list($noms, $ligne, $col) = $idref; |
|
| 193 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | - $this->valider_idref($nom, $ligne, $col); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // http://code.spip.net/@debutElement |
|
| 201 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | - if ($this->dtc->elements) { |
|
| 203 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($f = $this->process['debut']) { |
|
| 207 | - $f($this, $name, $attrs); |
|
| 208 | - } |
|
| 209 | - $depth = $this->depth; |
|
| 210 | - $this->debuts[$depth] = strlen($this->res); |
|
| 211 | - foreach ($attrs as $k => $v) { |
|
| 212 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // http://code.spip.net/@finElement |
|
| 217 | - public function finElement($phraseur, $name) { |
|
| 218 | - $depth = $this->depth; |
|
| 219 | - $contenu = $this->contenu; |
|
| 220 | - |
|
| 221 | - $n = strlen($this->res); |
|
| 222 | - $c = strlen(trim($contenu[$depth])); |
|
| 223 | - $k = $this->debuts[$depth]; |
|
| 224 | - |
|
| 225 | - $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | - $vide = ($regle == 'EMPTY'); |
|
| 227 | - // controler que les balises devant etre vides le sont |
|
| 228 | - if ($vide) { |
|
| 229 | - if ($n <> ($k + $c)) { |
|
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | - } |
|
| 232 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | - } elseif ($regle and ($regle != '*')) { |
|
| 234 | - if ($regle == '+') { |
|
| 235 | - // iteration de disjonction non vide: 1 balise au - |
|
| 236 | - if ($n == $k) { |
|
| 237 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | - . _T('zxml_vide_balise')); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | - coordonnees_erreur($this, |
|
| 244 | - " <p>\n<b>$name</b> " |
|
| 245 | - . _T('zxml_succession_fils_incorrecte') |
|
| 246 | - . ' : <b>' |
|
| 247 | - . $f |
|
| 248 | - . '</b>'); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - } |
|
| 253 | - if ($f = $this->process['fin']) { |
|
| 254 | - $f($this, $name, $vide); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // http://code.spip.net/@textElement |
|
| 259 | - public function textElement($phraseur, $data) { |
|
| 260 | - if (trim($data)) { |
|
| 261 | - $d = $this->depth; |
|
| 262 | - $d = $this->ouvrant[$d]; |
|
| 263 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | - coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | - . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - if ($f = $this->process['text']) { |
|
| 271 | - $f($this, $data); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function piElement($phraseur, $target, $data) { |
|
| 276 | - if ($f = $this->process['pi']) { |
|
| 277 | - $f($this, $target, $data); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Denonciation des entitees XML inconnues |
|
| 282 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | - // le source de la page laisse legitimement supposer. |
|
| 287 | - |
|
| 288 | - // http://code.spip.net/@defautElement |
|
| 289 | - public function defaultElement($phraseur, $data) { |
|
| 290 | - if (!preg_match('/^<!--/', $data) |
|
| 291 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | - ) { |
|
| 293 | - foreach ($r as $m) { |
|
| 294 | - list($t, $e) = $m; |
|
| 295 | - if (!isset($this->dtc->entites[$e])) { |
|
| 296 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | - . _T('zxml_inconnu_entite') |
|
| 298 | - . ' ' |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | - $f($this, $data); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // http://code.spip.net/@phraserTout |
|
| 309 | - public function phraserTout($phraseur, $data) { |
|
| 310 | - xml_parsestring($this, $data); |
|
| 311 | - |
|
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | - $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | - } else { |
|
| 315 | - $this->valider_passe2($this); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Constructeur |
|
| 321 | - * |
|
| 322 | - * @param array $process ? |
|
| 323 | - **/ |
|
| 324 | - public function __construct($process = array()) { |
|
| 325 | - if (is_array($process)) { |
|
| 326 | - $this->process = $process; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public $ids = array(); |
|
| 331 | - public $idrefs = array(); |
|
| 332 | - public $idrefss = array(); |
|
| 333 | - public $debuts = array(); |
|
| 334 | - public $fratrie = array(); |
|
| 335 | - |
|
| 336 | - public $dtc = null; |
|
| 337 | - public $sax = null; |
|
| 338 | - public $depth = ""; |
|
| 339 | - public $entete = ''; |
|
| 340 | - public $page = ''; |
|
| 341 | - public $res = ""; |
|
| 342 | - public $err = array(); |
|
| 343 | - public $contenu = array(); |
|
| 344 | - public $ouvrant = array(); |
|
| 345 | - public $reperes = array(); |
|
| 346 | - public $process = array( |
|
| 347 | - 'debut' => 'xml_debutElement', |
|
| 348 | - 'fin' => 'xml_finElement', |
|
| 349 | - 'text' => 'xml_textElement', |
|
| 350 | - 'pi' => 'xml_piElement', |
|
| 351 | - 'default' => 'xml_defaultElement' |
|
| 352 | - ); |
|
| 26 | + // http://code.spip.net/@validerElement |
|
| 27 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | + if ($p = strpos($name, ':')) { |
|
| 30 | + $name = substr($name, $p + 1); |
|
| 31 | + $p = isset($this->dtc->elements[$name]); |
|
| 32 | + } |
|
| 33 | + if (!$p) { |
|
| 34 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | + . _T('zxml_inconnu_balise')); |
|
| 36 | + |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + // controler les filles illegitimes, ca suffit |
|
| 41 | + $depth = $this->depth; |
|
| 42 | + $ouvrant = $this->ouvrant; |
|
| 43 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | + if (isset($ouvrant[$depth])) { |
|
| 45 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | + $pere = $r[1]; |
|
| 47 | + #spip_log("pere $pere"); |
|
| 48 | + if (isset($this->dtc->elements[$pere])) { |
|
| 49 | + $fils = $this->dtc->elements[$pere]; |
|
| 50 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | + if (!($p = @in_array($name, $fils))) { |
|
| 52 | + if ($p = strpos($name, ':')) { |
|
| 53 | + $p = substr($name, $p + 1); |
|
| 54 | + $p = @in_array($p, $fils); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if (!$p) { |
|
| 58 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | + . _T('zxml_non_fils') |
|
| 61 | + . ' <b>' |
|
| 62 | + . $pere |
|
| 63 | + . '</b>' |
|
| 64 | + . (!$bons_peres ? '' |
|
| 65 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | + $frat = substr($depth, 2); |
|
| 68 | + if (!isset($this->fratrie[$frat])) { |
|
| 69 | + $this->fratrie[$frat] = ''; |
|
| 70 | + } |
|
| 71 | + $this->fratrie[$frat] .= "$name "; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | + $this->fratrie[$depth] = ''; |
|
| 79 | + } |
|
| 80 | + if (isset($this->dtc->attributs[$name])) { |
|
| 81 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | + . ' : ' |
|
| 85 | + . _T('zxml_obligatoire_attribut') |
|
| 86 | + . " <b>$name</b>"); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // http://code.spip.net/@validerAttribut |
|
| 93 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | + // Si la balise est inconnue, eviter d'insister |
|
| 95 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $a = $this->dtc->attributs[$bal]; |
|
| 100 | + if (!isset($a[$name])) { |
|
| 101 | + $bons = join(', ', array_keys($a)); |
|
| 102 | + if ($bons) { |
|
| 103 | + $bons = " title=' " . |
|
| 104 | + _T('zxml_connus_attributs') . |
|
| 105 | + ' : ' . |
|
| 106 | + $bons . |
|
| 107 | + "'"; |
|
| 108 | + } |
|
| 109 | + $bons .= " style='font-weight: bold'"; |
|
| 110 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | + . " <a$bons>$bal</a> (" |
|
| 113 | + . _T('zxml_survoler') |
|
| 114 | + . ")"); |
|
| 115 | + } else { |
|
| 116 | + $type = $a[$name][0]; |
|
| 117 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | + } else { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // http://code.spip.net/@validerAttribut_ID |
|
| 137 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | + if (isset($this->ids[$val])) { |
|
| 139 | + list($l, $c) = $this->ids[$val]; |
|
| 140 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | + . _T('zxml_valeur_attribut') |
|
| 142 | + . " <b>$name</b> " |
|
| 143 | + . _T('zxml_de') |
|
| 144 | + . " <b>$bal</b> " |
|
| 145 | + . _T('zxml_vu') |
|
| 146 | + . " (L$l,C$c)"); |
|
| 147 | + } else { |
|
| 148 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | + $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // http://code.spip.net/@validerAttribut_IDREF |
|
| 154 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // http://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | + $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // http://code.spip.net/@valider_motif |
|
| 164 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | + if (!preg_match($motif, $val)) { |
|
| 166 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | + . _T('zxml_valeur_attribut') |
|
| 168 | + . " <b>$name</b> " |
|
| 169 | + . _T('zxml_de') |
|
| 170 | + . " <b>$bal</b> " |
|
| 171 | + . _T('zxml_non_conforme') |
|
| 172 | + . "</p><p>" |
|
| 173 | + . "<b>" . $motif . "</b>"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // http://code.spip.net/@valider_idref |
|
| 178 | + public function valider_idref($nom, $ligne, $col) { |
|
| 179 | + if (!isset($this->ids[$nom])) { |
|
| 180 | + $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // http://code.spip.net/@valider_passe2 |
|
| 185 | + public function valider_passe2() { |
|
| 186 | + if (!$this->err) { |
|
| 187 | + foreach ($this->idrefs as $idref) { |
|
| 188 | + list($nom, $ligne, $col) = $idref; |
|
| 189 | + $this->valider_idref($nom, $ligne, $col); |
|
| 190 | + } |
|
| 191 | + foreach ($this->idrefss as $idref) { |
|
| 192 | + list($noms, $ligne, $col) = $idref; |
|
| 193 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | + $this->valider_idref($nom, $ligne, $col); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // http://code.spip.net/@debutElement |
|
| 201 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | + if ($this->dtc->elements) { |
|
| 203 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($f = $this->process['debut']) { |
|
| 207 | + $f($this, $name, $attrs); |
|
| 208 | + } |
|
| 209 | + $depth = $this->depth; |
|
| 210 | + $this->debuts[$depth] = strlen($this->res); |
|
| 211 | + foreach ($attrs as $k => $v) { |
|
| 212 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // http://code.spip.net/@finElement |
|
| 217 | + public function finElement($phraseur, $name) { |
|
| 218 | + $depth = $this->depth; |
|
| 219 | + $contenu = $this->contenu; |
|
| 220 | + |
|
| 221 | + $n = strlen($this->res); |
|
| 222 | + $c = strlen(trim($contenu[$depth])); |
|
| 223 | + $k = $this->debuts[$depth]; |
|
| 224 | + |
|
| 225 | + $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | + $vide = ($regle == 'EMPTY'); |
|
| 227 | + // controler que les balises devant etre vides le sont |
|
| 228 | + if ($vide) { |
|
| 229 | + if ($n <> ($k + $c)) { |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | + } |
|
| 232 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | + } elseif ($regle and ($regle != '*')) { |
|
| 234 | + if ($regle == '+') { |
|
| 235 | + // iteration de disjonction non vide: 1 balise au - |
|
| 236 | + if ($n == $k) { |
|
| 237 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | + . _T('zxml_vide_balise')); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | + coordonnees_erreur($this, |
|
| 244 | + " <p>\n<b>$name</b> " |
|
| 245 | + . _T('zxml_succession_fils_incorrecte') |
|
| 246 | + . ' : <b>' |
|
| 247 | + . $f |
|
| 248 | + . '</b>'); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + } |
|
| 253 | + if ($f = $this->process['fin']) { |
|
| 254 | + $f($this, $name, $vide); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // http://code.spip.net/@textElement |
|
| 259 | + public function textElement($phraseur, $data) { |
|
| 260 | + if (trim($data)) { |
|
| 261 | + $d = $this->depth; |
|
| 262 | + $d = $this->ouvrant[$d]; |
|
| 263 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | + coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | + . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + if ($f = $this->process['text']) { |
|
| 271 | + $f($this, $data); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function piElement($phraseur, $target, $data) { |
|
| 276 | + if ($f = $this->process['pi']) { |
|
| 277 | + $f($this, $target, $data); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Denonciation des entitees XML inconnues |
|
| 282 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | + // le source de la page laisse legitimement supposer. |
|
| 287 | + |
|
| 288 | + // http://code.spip.net/@defautElement |
|
| 289 | + public function defaultElement($phraseur, $data) { |
|
| 290 | + if (!preg_match('/^<!--/', $data) |
|
| 291 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | + ) { |
|
| 293 | + foreach ($r as $m) { |
|
| 294 | + list($t, $e) = $m; |
|
| 295 | + if (!isset($this->dtc->entites[$e])) { |
|
| 296 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | + . _T('zxml_inconnu_entite') |
|
| 298 | + . ' ' |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | + $f($this, $data); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // http://code.spip.net/@phraserTout |
|
| 309 | + public function phraserTout($phraseur, $data) { |
|
| 310 | + xml_parsestring($this, $data); |
|
| 311 | + |
|
| 312 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | + $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | + } else { |
|
| 315 | + $this->valider_passe2($this); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Constructeur |
|
| 321 | + * |
|
| 322 | + * @param array $process ? |
|
| 323 | + **/ |
|
| 324 | + public function __construct($process = array()) { |
|
| 325 | + if (is_array($process)) { |
|
| 326 | + $this->process = $process; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public $ids = array(); |
|
| 331 | + public $idrefs = array(); |
|
| 332 | + public $idrefss = array(); |
|
| 333 | + public $debuts = array(); |
|
| 334 | + public $fratrie = array(); |
|
| 335 | + |
|
| 336 | + public $dtc = null; |
|
| 337 | + public $sax = null; |
|
| 338 | + public $depth = ""; |
|
| 339 | + public $entete = ''; |
|
| 340 | + public $page = ''; |
|
| 341 | + public $res = ""; |
|
| 342 | + public $err = array(); |
|
| 343 | + public $contenu = array(); |
|
| 344 | + public $ouvrant = array(); |
|
| 345 | + public $reperes = array(); |
|
| 346 | + public $process = array( |
|
| 347 | + 'debut' => 'xml_debutElement', |
|
| 348 | + 'fin' => 'xml_finElement', |
|
| 349 | + 'text' => 'xml_textElement', |
|
| 350 | + 'pi' => 'xml_piElement', |
|
| 351 | + 'default' => 'xml_defaultElement' |
|
| 352 | + ); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | **/ |
| 361 | 361 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 362 | - $f = new ValidateurXML($process); |
|
| 363 | - $sax = charger_fonction('sax', 'xml'); |
|
| 362 | + $f = new ValidateurXML($process); |
|
| 363 | + $sax = charger_fonction('sax', 'xml'); |
|
| 364 | 364 | |
| 365 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 365 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 366 | 366 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | . $pere |
| 63 | 63 | . '</b>' |
| 64 | 64 | . (!$bons_peres ? '' |
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + : ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>'))); |
|
| 66 | 66 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 67 | 67 | $frat = substr($depth, 2); |
| 68 | 68 | if (!isset($this->fratrie[$frat])) { |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | if (!isset($a[$name])) { |
| 101 | 101 | $bons = join(', ', array_keys($a)); |
| 102 | 102 | if ($bons) { |
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 103 | + $bons = " title=' ". |
|
| 104 | + _T('zxml_connus_attributs'). |
|
| 105 | + ' : '. |
|
| 106 | + $bons. |
|
| 107 | 107 | "'"; |
| 108 | 108 | } |
| 109 | 109 | $bons .= " style='font-weight: bold'"; |
| 110 | 110 | coordonnees_erreur($this, " <b>$name</b> " |
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 111 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 112 | 112 | . " <a$bons>$bal</a> (" |
| 113 | 113 | . _T('zxml_survoler') |
| 114 | 114 | . ")"); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | if (!preg_match('/^\w+$/', $type)) { |
| 118 | 118 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 119 | 119 | } else { |
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 121 | 121 | $this->$f($phraseur, $name, $val, $bal); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | . " <b>$bal</b> " |
| 171 | 171 | . _T('zxml_non_conforme') |
| 172 | 172 | . "</p><p>" |
| 173 | - . "<b>" . $motif . "</b>"); |
|
| 173 | + . "<b>".$motif."</b>"); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // http://code.spip.net/@valider_idref |
| 178 | 178 | public function valider_idref($nom, $ligne, $col) { |
| 179 | 179 | if (!isset($this->ids[$nom])) { |
| 180 | - $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 180 | + $this->err[] = array(" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // controler que les balises devant etre vides le sont |
| 228 | 228 | if ($vide) { |
| 229 | 229 | if ($n <> ($k + $c)) { |
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 231 | 231 | } |
| 232 | 232 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 233 | 233 | } elseif ($regle and ($regle != '*')) { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $d = $this->ouvrant[$d]; |
| 263 | 263 | preg_match('/^\s*(\S+)/', $d, $m); |
| 264 | 264 | if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
| 265 | - coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 265 | + coordonnees_erreur($this, " <p><b>".$m[1]."</b> " |
|
| 266 | 266 | . _T('zxml_nonvide_balise') // message a affiner |
| 267 | 267 | ); |
| 268 | 268 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function phraserTout($phraseur, $data) { |
| 310 | 310 | xml_parsestring($this, $data); |
| 311 | 311 | |
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 312 | + if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) { |
|
| 313 | 313 | $this->err[] = array('DOCTYPE ?', 0, 0); |
| 314 | 314 | } else { |
| 315 | 315 | $this->valider_passe2($this); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param int $id_rubrique |
| 161 | 161 | * Identifiant de la rubrique parente |
| 162 | 162 | * @param array|null $set |
| 163 | - * @return int |
|
| 163 | + * @return boolean|string |
|
| 164 | 164 | * Identifiant du nouvel article |
| 165 | 165 | * |
| 166 | 166 | */ |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @param int $id_rubrique |
| 535 | 535 | * Identifiant de la rubrique |
| 536 | - * @return int |
|
| 536 | + * @return boolean|string |
|
| 537 | 537 | * Identifiant du nouvel article |
| 538 | 538 | */ |
| 539 | 539 | function insert_article($id_rubrique) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -40,36 +40,36 @@ discard block |
||
| 40 | 40 | * Liste (identifiant de l'article, Texte d'erreur éventuel) |
| 41 | 41 | */ |
| 42 | 42 | function action_editer_article_dist($arg = null) { |
| 43 | - include_spip('inc/autoriser'); |
|
| 44 | - $err = ""; |
|
| 45 | - if (is_null($arg)) { |
|
| 46 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | - $arg = $securiser_action(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id_article = intval($arg)) { |
|
| 53 | - $id_parent = _request('id_parent'); |
|
| 54 | - if (!$id_parent) { |
|
| 55 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 56 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 57 | - $err = _T("info_creerdansrubrique_non_autorise"); |
|
| 58 | - } else { |
|
| 59 | - $id_article = article_inserer($id_parent); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Enregistre l'envoi dans la BD |
|
| 64 | - if ($id_article > 0) { |
|
| 65 | - $err = article_modifier($id_article); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($err) { |
|
| 69 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array($id_article, $err); |
|
| 43 | + include_spip('inc/autoriser'); |
|
| 44 | + $err = ""; |
|
| 45 | + if (is_null($arg)) { |
|
| 46 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | + $arg = $securiser_action(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id_article = intval($arg)) { |
|
| 53 | + $id_parent = _request('id_parent'); |
|
| 54 | + if (!$id_parent) { |
|
| 55 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 56 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 57 | + $err = _T("info_creerdansrubrique_non_autorise"); |
|
| 58 | + } else { |
|
| 59 | + $id_article = article_inserer($id_parent); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Enregistre l'envoi dans la BD |
|
| 64 | + if ($id_article > 0) { |
|
| 65 | + $err = article_modifier($id_article); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($err) { |
|
| 69 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array($id_article, $err); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -91,46 +91,46 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function article_modifier($id_article, $set = null) { |
| 93 | 93 | |
| 94 | - // unifier $texte en cas de texte trop long |
|
| 95 | - trop_longs_articles(); |
|
| 96 | - |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - include_spip('inc/filtres'); |
|
| 99 | - $c = collecter_requests( |
|
| 100 | - // white list |
|
| 101 | - objet_info('article', 'champs_editables'), |
|
| 102 | - // black list |
|
| 103 | - array('date', 'statut', 'id_parent'), |
|
| 104 | - // donnees eventuellement fournies |
|
| 105 | - $set |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 109 | - $t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article)); |
|
| 110 | - $invalideur = $indexation = false; |
|
| 111 | - if ($t == 'publie') { |
|
| 112 | - $invalideur = "id='article/$id_article'"; |
|
| 113 | - $indexation = true; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ($err = objet_modifier_champs('article', $id_article, |
|
| 117 | - array( |
|
| 118 | - 'data' => $set, |
|
| 119 | - 'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article), |
|
| 120 | - 'invalideur' => $invalideur, |
|
| 121 | - 'indexation' => $indexation, |
|
| 122 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 123 | - ), |
|
| 124 | - $c) |
|
| 125 | - ) { |
|
| 126 | - return $err; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Modification de statut, changement de rubrique ? |
|
| 130 | - $c = collecter_requests(array('date', 'statut', 'id_parent'), array(), $set); |
|
| 131 | - $err = article_instituer($id_article, $c); |
|
| 132 | - |
|
| 133 | - return $err; |
|
| 94 | + // unifier $texte en cas de texte trop long |
|
| 95 | + trop_longs_articles(); |
|
| 96 | + |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + include_spip('inc/filtres'); |
|
| 99 | + $c = collecter_requests( |
|
| 100 | + // white list |
|
| 101 | + objet_info('article', 'champs_editables'), |
|
| 102 | + // black list |
|
| 103 | + array('date', 'statut', 'id_parent'), |
|
| 104 | + // donnees eventuellement fournies |
|
| 105 | + $set |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 109 | + $t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article)); |
|
| 110 | + $invalideur = $indexation = false; |
|
| 111 | + if ($t == 'publie') { |
|
| 112 | + $invalideur = "id='article/$id_article'"; |
|
| 113 | + $indexation = true; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ($err = objet_modifier_champs('article', $id_article, |
|
| 117 | + array( |
|
| 118 | + 'data' => $set, |
|
| 119 | + 'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article), |
|
| 120 | + 'invalideur' => $invalideur, |
|
| 121 | + 'indexation' => $indexation, |
|
| 122 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 123 | + ), |
|
| 124 | + $c) |
|
| 125 | + ) { |
|
| 126 | + return $err; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Modification de statut, changement de rubrique ? |
|
| 130 | + $c = collecter_requests(array('date', 'statut', 'id_parent'), array(), $set); |
|
| 131 | + $err = article_instituer($id_article, $c); |
|
| 132 | + |
|
| 133 | + return $err; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -166,90 +166,90 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | function article_inserer($id_rubrique, $set = null) { |
| 168 | 168 | |
| 169 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 170 | - // dans la premiere rubrique racine |
|
| 171 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 172 | - $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1"); |
|
| 173 | - $id_rubrique = $row['id_rubrique']; |
|
| 174 | - } else { |
|
| 175 | - $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 179 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 180 | - $id_secteur = isset($row['id_secteur']) ? $row['id_secteur'] : 0; |
|
| 181 | - |
|
| 182 | - $lang_rub = $row['lang']; |
|
| 183 | - |
|
| 184 | - $lang = ""; |
|
| 185 | - $choisie = 'non'; |
|
| 186 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 187 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 188 | - // ou a defaut celle de la rubrique |
|
| 189 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 190 | - if (!empty($GLOBALS['meta']['multi_objets']) and in_array('spip_articles', |
|
| 191 | - explode(',', $GLOBALS['meta']['multi_objets'])) |
|
| 192 | - ) { |
|
| 193 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 194 | - if (in_array($GLOBALS['spip_lang'], |
|
| 195 | - explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 196 | - $lang = $GLOBALS['spip_lang']; |
|
| 197 | - $choisie = 'oui'; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if (!$lang) { |
|
| 202 | - $choisie = 'non'; |
|
| 203 | - $lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $champs = array( |
|
| 207 | - 'id_rubrique' => $id_rubrique, |
|
| 208 | - 'id_secteur' => $id_secteur, |
|
| 209 | - 'statut' => 'prepa', |
|
| 210 | - 'date' => date('Y-m-d H:i:s'), |
|
| 211 | - 'lang' => $lang, |
|
| 212 | - 'langue_choisie' => $choisie |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - if ($set) { |
|
| 216 | - $champs = array_merge($champs, $set); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Envoyer aux plugins |
|
| 220 | - $champs = pipeline('pre_insertion', |
|
| 221 | - array( |
|
| 222 | - 'args' => array( |
|
| 223 | - 'table' => 'spip_articles', |
|
| 224 | - ), |
|
| 225 | - 'data' => $champs |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - |
|
| 229 | - $id_article = sql_insertq("spip_articles", $champs); |
|
| 230 | - |
|
| 231 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 232 | - if ($id_article > 0) { |
|
| 233 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 234 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 235 | - : _request('id_auteur')); |
|
| 236 | - if ($id_auteur) { |
|
| 237 | - include_spip('action/editer_auteur'); |
|
| 238 | - auteur_associer($id_auteur, array('article' => $id_article)); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - pipeline('post_insertion', |
|
| 243 | - array( |
|
| 244 | - 'args' => array( |
|
| 245 | - 'table' => 'spip_articles', |
|
| 246 | - 'id_objet' => $id_article |
|
| 247 | - ), |
|
| 248 | - 'data' => $champs |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - |
|
| 252 | - return $id_article; |
|
| 169 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 170 | + // dans la premiere rubrique racine |
|
| 171 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 172 | + $row = sql_fetsel("id_rubrique, id_secteur, lang", "spip_rubriques", "id_parent=0", '', '0+titre,titre', "1"); |
|
| 173 | + $id_rubrique = $row['id_rubrique']; |
|
| 174 | + } else { |
|
| 175 | + $row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 179 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 180 | + $id_secteur = isset($row['id_secteur']) ? $row['id_secteur'] : 0; |
|
| 181 | + |
|
| 182 | + $lang_rub = $row['lang']; |
|
| 183 | + |
|
| 184 | + $lang = ""; |
|
| 185 | + $choisie = 'non'; |
|
| 186 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 187 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 188 | + // ou a defaut celle de la rubrique |
|
| 189 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 190 | + if (!empty($GLOBALS['meta']['multi_objets']) and in_array('spip_articles', |
|
| 191 | + explode(',', $GLOBALS['meta']['multi_objets'])) |
|
| 192 | + ) { |
|
| 193 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 194 | + if (in_array($GLOBALS['spip_lang'], |
|
| 195 | + explode(',', $GLOBALS['meta']['langues_multilingue']))) { |
|
| 196 | + $lang = $GLOBALS['spip_lang']; |
|
| 197 | + $choisie = 'oui'; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if (!$lang) { |
|
| 202 | + $choisie = 'non'; |
|
| 203 | + $lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $champs = array( |
|
| 207 | + 'id_rubrique' => $id_rubrique, |
|
| 208 | + 'id_secteur' => $id_secteur, |
|
| 209 | + 'statut' => 'prepa', |
|
| 210 | + 'date' => date('Y-m-d H:i:s'), |
|
| 211 | + 'lang' => $lang, |
|
| 212 | + 'langue_choisie' => $choisie |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + if ($set) { |
|
| 216 | + $champs = array_merge($champs, $set); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Envoyer aux plugins |
|
| 220 | + $champs = pipeline('pre_insertion', |
|
| 221 | + array( |
|
| 222 | + 'args' => array( |
|
| 223 | + 'table' => 'spip_articles', |
|
| 224 | + ), |
|
| 225 | + 'data' => $champs |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + |
|
| 229 | + $id_article = sql_insertq("spip_articles", $champs); |
|
| 230 | + |
|
| 231 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 232 | + if ($id_article > 0) { |
|
| 233 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 234 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 235 | + : _request('id_auteur')); |
|
| 236 | + if ($id_auteur) { |
|
| 237 | + include_spip('action/editer_auteur'); |
|
| 238 | + auteur_associer($id_auteur, array('article' => $id_article)); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + pipeline('post_insertion', |
|
| 243 | + array( |
|
| 244 | + 'args' => array( |
|
| 245 | + 'table' => 'spip_articles', |
|
| 246 | + 'id_objet' => $id_article |
|
| 247 | + ), |
|
| 248 | + 'data' => $champs |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + |
|
| 252 | + return $id_article; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -277,120 +277,120 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 279 | 279 | |
| 280 | - include_spip('inc/autoriser'); |
|
| 281 | - include_spip('inc/rubriques'); |
|
| 282 | - include_spip('inc/modifier'); |
|
| 283 | - |
|
| 284 | - $row = sql_fetsel("statut, date, id_rubrique", "spip_articles", "id_article=$id_article"); |
|
| 285 | - $id_rubrique = $row['id_rubrique']; |
|
| 286 | - $statut_ancien = $statut = $row['statut']; |
|
| 287 | - $date_ancienne = $date = $row['date']; |
|
| 288 | - $champs = array(); |
|
| 289 | - |
|
| 290 | - $d = isset($c['date']) ? $c['date'] : null; |
|
| 291 | - $s = isset($c['statut']) ? $c['statut'] : $statut; |
|
| 292 | - |
|
| 293 | - // cf autorisations dans inc/instituer_article |
|
| 294 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 295 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 296 | - $statut = $champs['statut'] = $s; |
|
| 297 | - } else { |
|
| 298 | - if (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 299 | - $statut = $champs['statut'] = $s; |
|
| 300 | - } else { |
|
| 301 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // En cas de publication, fixer la date a "maintenant" |
|
| 306 | - // sauf si $c commande autre chose |
|
| 307 | - // ou si l'article est deja date dans le futur |
|
| 308 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 309 | - if ($champs['statut'] == 'publie' |
|
| 310 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, array('publie', 'prop')))) |
|
| 311 | - ) { |
|
| 312 | - if ($d or strtotime($d = $date) > time()) { |
|
| 313 | - $champs['date'] = $date = $d; |
|
| 314 | - } else { |
|
| 315 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - // Verifier que la rubrique demandee existe et est differente |
|
| 321 | - // de la rubrique actuelle |
|
| 322 | - if (isset($c['id_parent']) |
|
| 323 | - and $id_parent = $c['id_parent'] |
|
| 324 | - and $id_parent != $id_rubrique |
|
| 325 | - and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 326 | - ) { |
|
| 327 | - $champs['id_rubrique'] = $id_parent; |
|
| 328 | - |
|
| 329 | - // si l'article etait publie |
|
| 330 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 331 | - // repasser l'article en statut 'propose'. |
|
| 332 | - if ($statut == 'publie' |
|
| 333 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 334 | - ) { |
|
| 335 | - $champs['statut'] = 'prop'; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Envoyer aux plugins |
|
| 340 | - $champs = pipeline('pre_edition', |
|
| 341 | - array( |
|
| 342 | - 'args' => array( |
|
| 343 | - 'table' => 'spip_articles', |
|
| 344 | - 'id_objet' => $id_article, |
|
| 345 | - 'action' => 'instituer', |
|
| 346 | - 'statut_ancien' => $statut_ancien, |
|
| 347 | - 'date_ancienne' => $date_ancienne, |
|
| 348 | - ), |
|
| 349 | - 'data' => $champs |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - |
|
| 353 | - if (!count($champs)) { |
|
| 354 | - return ''; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // Envoyer les modifs. |
|
| 358 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 359 | - |
|
| 360 | - // Invalider les caches |
|
| 361 | - include_spip('inc/invalideur'); |
|
| 362 | - suivre_invalideur("id='article/$id_article'"); |
|
| 363 | - |
|
| 364 | - if ($date) { |
|
| 365 | - $t = strtotime($date); |
|
| 366 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 367 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 368 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Pipeline |
|
| 373 | - pipeline('post_edition', |
|
| 374 | - array( |
|
| 375 | - 'args' => array( |
|
| 376 | - 'table' => 'spip_articles', |
|
| 377 | - 'id_objet' => $id_article, |
|
| 378 | - 'action' => 'instituer', |
|
| 379 | - 'statut_ancien' => $statut_ancien, |
|
| 380 | - 'date_ancienne' => $date_ancienne, |
|
| 381 | - ), |
|
| 382 | - 'data' => $champs |
|
| 383 | - ) |
|
| 384 | - ); |
|
| 385 | - |
|
| 386 | - // Notifications |
|
| 387 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 388 | - $notifications('instituerarticle', $id_article, |
|
| 389 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - return ''; // pas d'erreur |
|
| 280 | + include_spip('inc/autoriser'); |
|
| 281 | + include_spip('inc/rubriques'); |
|
| 282 | + include_spip('inc/modifier'); |
|
| 283 | + |
|
| 284 | + $row = sql_fetsel("statut, date, id_rubrique", "spip_articles", "id_article=$id_article"); |
|
| 285 | + $id_rubrique = $row['id_rubrique']; |
|
| 286 | + $statut_ancien = $statut = $row['statut']; |
|
| 287 | + $date_ancienne = $date = $row['date']; |
|
| 288 | + $champs = array(); |
|
| 289 | + |
|
| 290 | + $d = isset($c['date']) ? $c['date'] : null; |
|
| 291 | + $s = isset($c['statut']) ? $c['statut'] : $statut; |
|
| 292 | + |
|
| 293 | + // cf autorisations dans inc/instituer_article |
|
| 294 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 295 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 296 | + $statut = $champs['statut'] = $s; |
|
| 297 | + } else { |
|
| 298 | + if (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 299 | + $statut = $champs['statut'] = $s; |
|
| 300 | + } else { |
|
| 301 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // En cas de publication, fixer la date a "maintenant" |
|
| 306 | + // sauf si $c commande autre chose |
|
| 307 | + // ou si l'article est deja date dans le futur |
|
| 308 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 309 | + if ($champs['statut'] == 'publie' |
|
| 310 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, array('publie', 'prop')))) |
|
| 311 | + ) { |
|
| 312 | + if ($d or strtotime($d = $date) > time()) { |
|
| 313 | + $champs['date'] = $date = $d; |
|
| 314 | + } else { |
|
| 315 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + // Verifier que la rubrique demandee existe et est differente |
|
| 321 | + // de la rubrique actuelle |
|
| 322 | + if (isset($c['id_parent']) |
|
| 323 | + and $id_parent = $c['id_parent'] |
|
| 324 | + and $id_parent != $id_rubrique |
|
| 325 | + and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 326 | + ) { |
|
| 327 | + $champs['id_rubrique'] = $id_parent; |
|
| 328 | + |
|
| 329 | + // si l'article etait publie |
|
| 330 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 331 | + // repasser l'article en statut 'propose'. |
|
| 332 | + if ($statut == 'publie' |
|
| 333 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 334 | + ) { |
|
| 335 | + $champs['statut'] = 'prop'; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Envoyer aux plugins |
|
| 340 | + $champs = pipeline('pre_edition', |
|
| 341 | + array( |
|
| 342 | + 'args' => array( |
|
| 343 | + 'table' => 'spip_articles', |
|
| 344 | + 'id_objet' => $id_article, |
|
| 345 | + 'action' => 'instituer', |
|
| 346 | + 'statut_ancien' => $statut_ancien, |
|
| 347 | + 'date_ancienne' => $date_ancienne, |
|
| 348 | + ), |
|
| 349 | + 'data' => $champs |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + |
|
| 353 | + if (!count($champs)) { |
|
| 354 | + return ''; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // Envoyer les modifs. |
|
| 358 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 359 | + |
|
| 360 | + // Invalider les caches |
|
| 361 | + include_spip('inc/invalideur'); |
|
| 362 | + suivre_invalideur("id='article/$id_article'"); |
|
| 363 | + |
|
| 364 | + if ($date) { |
|
| 365 | + $t = strtotime($date); |
|
| 366 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 367 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 368 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Pipeline |
|
| 373 | + pipeline('post_edition', |
|
| 374 | + array( |
|
| 375 | + 'args' => array( |
|
| 376 | + 'table' => 'spip_articles', |
|
| 377 | + 'id_objet' => $id_article, |
|
| 378 | + 'action' => 'instituer', |
|
| 379 | + 'statut_ancien' => $statut_ancien, |
|
| 380 | + 'date_ancienne' => $date_ancienne, |
|
| 381 | + ), |
|
| 382 | + 'data' => $champs |
|
| 383 | + ) |
|
| 384 | + ); |
|
| 385 | + |
|
| 386 | + // Notifications |
|
| 387 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 388 | + $notifications('instituerarticle', $id_article, |
|
| 389 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + return ''; // pas d'erreur |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -415,33 +415,33 @@ discard block |
||
| 415 | 415 | */ |
| 416 | 416 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 417 | 417 | |
| 418 | - // Si on deplace l'article |
|
| 419 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 420 | - if (isset($champs['id_rubrique'])) { |
|
| 418 | + // Si on deplace l'article |
|
| 419 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 420 | + if (isset($champs['id_rubrique'])) { |
|
| 421 | 421 | |
| 422 | - $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 422 | + $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 423 | 423 | |
| 424 | - $langue = $row_rub['lang']; |
|
| 425 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 426 | - if (sql_fetsel('1', 'spip_articles', |
|
| 427 | - "id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 428 | - $champs['lang'] = $langue; |
|
| 429 | - } |
|
| 430 | - } |
|
| 424 | + $langue = $row_rub['lang']; |
|
| 425 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 426 | + if (sql_fetsel('1', 'spip_articles', |
|
| 427 | + "id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 428 | + $champs['lang'] = $langue; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - if (!$champs) { |
|
| 433 | - return; |
|
| 434 | - } |
|
| 432 | + if (!$champs) { |
|
| 433 | + return; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article)); |
|
| 436 | + sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article)); |
|
| 437 | 437 | |
| 438 | - // Changer le statut des rubriques concernees |
|
| 438 | + // Changer le statut des rubriques concernees |
|
| 439 | 439 | |
| 440 | - if ($cond) { |
|
| 441 | - include_spip('inc/rubriques'); |
|
| 442 | - $postdate = ($GLOBALS['meta']["post_dates"] == "non" and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 443 | - calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 444 | - } |
|
| 440 | + if ($cond) { |
|
| 441 | + include_spip('inc/rubriques'); |
|
| 442 | + $postdate = ($GLOBALS['meta']["post_dates"] == "non" and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 443 | + calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 444 | + } |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | * @return void |
| 451 | 451 | */ |
| 452 | 452 | function trop_longs_articles() { |
| 453 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 454 | - foreach ($plus as $n => $t) { |
|
| 455 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t); |
|
| 456 | - } |
|
| 457 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 458 | - } |
|
| 453 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 454 | + foreach ($plus as $n => $t) { |
|
| 455 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t); |
|
| 456 | + } |
|
| 457 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * Chaîne contenant un texte d'erreur sinon. |
| 481 | 481 | */ |
| 482 | 482 | function revisions_articles($id_article, $c = false) { |
| 483 | - return article_modifier($id_article, $c); |
|
| 483 | + return article_modifier($id_article, $c); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * Chaîne contenant un texte d'erreur sinon. |
| 502 | 502 | */ |
| 503 | 503 | function revision_article($id_article, $c = false) { |
| 504 | - return article_modifier($id_article, $c); |
|
| 504 | + return article_modifier($id_article, $c); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | * Chaîne contenant un texte d'erreur sinon. |
| 523 | 523 | */ |
| 524 | 524 | function articles_set($id_article, $set = null) { |
| 525 | - return article_modifier($id_article, $set); |
|
| 525 | + return article_modifier($id_article, $set); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * Identifiant du nouvel article |
| 538 | 538 | */ |
| 539 | 539 | function insert_article($id_rubrique) { |
| 540 | - return article_inserer($id_rubrique); |
|
| 540 | + return article_inserer($id_rubrique); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -559,5 +559,5 @@ discard block |
||
| 559 | 559 | * Chaîne vide |
| 560 | 560 | */ |
| 561 | 561 | function instituer_article($id_article, $c, $calcul_rub = true) { |
| 562 | - return article_instituer($id_article, $c, $calcul_rub); |
|
| 562 | + return article_instituer($id_article, $c, $calcul_rub); |
|
| 563 | 563 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | // Si l'article est publie, invalider les caches et demander sa reindexation |
| 109 | - $t = sql_getfetsel("statut", "spip_articles", "id_article=" . intval($id_article)); |
|
| 109 | + $t = sql_getfetsel("statut", "spip_articles", "id_article=".intval($id_article)); |
|
| 110 | 110 | $invalideur = $indexation = false; |
| 111 | 111 | if ($t == 'publie') { |
| 112 | 112 | $invalideur = "id='article/$id_article'"; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | if ($err = objet_modifier_champs('article', $id_article, |
| 117 | 117 | array( |
| 118 | 118 | 'data' => $set, |
| 119 | - 'nonvide' => array('titre' => _T('info_nouvel_article') . " " . _T('info_numero_abbreviation') . $id_article), |
|
| 119 | + 'nonvide' => array('titre' => _T('info_nouvel_article')." "._T('info_numero_abbreviation').$id_article), |
|
| 120 | 120 | 'invalideur' => $invalideur, |
| 121 | 121 | 'indexation' => $indexation, |
| 122 | 122 | 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | if (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
| 299 | 299 | $statut = $champs['statut'] = $s; |
| 300 | 300 | } else { |
| 301 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 301 | + spip_log("editer_article $id_article refus ".join(' ', $c)); |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | if (isset($c['id_parent']) |
| 323 | 323 | and $id_parent = $c['id_parent'] |
| 324 | 324 | and $id_parent != $id_rubrique |
| 325 | - and (sql_fetsel('1', "spip_rubriques", "id_rubrique=" . intval($id_parent))) |
|
| 325 | + and (sql_fetsel('1', "spip_rubriques", "id_rubrique=".intval($id_parent))) |
|
| 326 | 326 | ) { |
| 327 | 327 | $champs['id_rubrique'] = $id_parent; |
| 328 | 328 | |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | // changer aussi son secteur et sa langue (si heritee) |
| 420 | 420 | if (isset($champs['id_rubrique'])) { |
| 421 | 421 | |
| 422 | - $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=" . sql_quote($champs['id_rubrique'])); |
|
| 422 | + $row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique=".sql_quote($champs['id_rubrique'])); |
|
| 423 | 423 | |
| 424 | 424 | $langue = $row_rub['lang']; |
| 425 | 425 | $champs['id_secteur'] = $row_rub['id_secteur']; |
| 426 | 426 | if (sql_fetsel('1', 'spip_articles', |
| 427 | - "id_article=" . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue))) { |
|
| 427 | + "id_article=".intval($id_article)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue))) { |
|
| 428 | 428 | $champs['lang'] = $langue; |
| 429 | 429 | } |
| 430 | 430 | } |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | return; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - sql_updateq('spip_articles', $champs, "id_article=" . intval($id_article)); |
|
| 436 | + sql_updateq('spip_articles', $champs, "id_article=".intval($id_article)); |
|
| 437 | 437 | |
| 438 | 438 | // Changer le statut des rubriques concernees |
| 439 | 439 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | foreach ($plus as $n => $t) { |
| 455 | 455 | $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", "", $t); |
| 456 | 456 | } |
| 457 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 457 | + set_request('texte', join('', $plus)._request('texte')); |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | |
@@ -207,7 +207,7 @@ |
||
| 207 | 207 | * |
| 208 | 208 | * @api |
| 209 | 209 | * @param array $objets_source |
| 210 | - * @param array|string $objets_lies |
|
| 210 | + * @param string $objets_lies |
|
| 211 | 211 | * @return int |
| 212 | 212 | */ |
| 213 | 213 | function objet_optimiser_liens($objets_source, $objets_lies) { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // charger la gestion les rôles sur les objets |
@@ -47,21 +47,21 @@ discard block |
||
| 47 | 47 | * - array(clé primaire, nom de la table de lien) si associable |
| 48 | 48 | */ |
| 49 | 49 | function objet_associable($objet) { |
| 50 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | - $table_sql = table_objet_sql($objet); |
|
| 50 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | + $table_sql = table_objet_sql($objet); |
|
| 52 | 52 | |
| 53 | - $l = ""; |
|
| 54 | - if ($primary = id_table_objet($objet) |
|
| 55 | - and $trouver_table($l = $table_sql . "_liens") |
|
| 56 | - and !preg_match(',[^\w],', $primary) |
|
| 57 | - and !preg_match(',[^\w],', $l) |
|
| 58 | - ) { |
|
| 59 | - return array($primary, $l); |
|
| 60 | - } |
|
| 53 | + $l = ""; |
|
| 54 | + if ($primary = id_table_objet($objet) |
|
| 55 | + and $trouver_table($l = $table_sql . "_liens") |
|
| 56 | + and !preg_match(',[^\w],', $primary) |
|
| 57 | + and !preg_match(',[^\w],', $l) |
|
| 58 | + ) { |
|
| 59 | + return array($primary, $l); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 62 | + spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 63 | 63 | |
| 64 | - return false; |
|
| 64 | + return false; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | * @return bool|int |
| 88 | 88 | */ |
| 89 | 89 | function objet_associer($objets_source, $objets_lies, $qualif = null) { |
| 90 | - $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 90 | + $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 91 | 91 | |
| 92 | - if ($qualif) { |
|
| 93 | - objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 94 | - } |
|
| 92 | + if ($qualif) { |
|
| 93 | + objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - return $modifs; // pas d'erreur |
|
| 96 | + return $modifs; // pas d'erreur |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return bool|int |
| 128 | 128 | */ |
| 129 | 129 | function objet_dissocier($objets_source, $objets_lies, $cond = null) { |
| 130 | - return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 130 | + return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @return bool|int |
| 153 | 153 | */ |
| 154 | 154 | function objet_qualifier_liens($objets_source, $objets_lies, $qualif) { |
| 155 | - return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 155 | + return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * Liste des trouvailles |
| 188 | 188 | */ |
| 189 | 189 | function objet_trouver_liens($objets_source, $objets_lies, $cond = null) { |
| 190 | - return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 190 | + return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @return int |
| 212 | 212 | */ |
| 213 | 213 | function objet_optimiser_liens($objets_source, $objets_lies) { |
| 214 | - return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 214 | + return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -231,32 +231,32 @@ discard block |
||
| 231 | 231 | * Nombre de liens copiés |
| 232 | 232 | */ |
| 233 | 233 | function objet_dupliquer_liens($objet, $id_source, $id_cible, $types = null, $exclure_types = null) { |
| 234 | - include_spip('base/objets'); |
|
| 235 | - $tables = lister_tables_objets_sql(); |
|
| 236 | - $n = 0; |
|
| 237 | - foreach ($tables as $table_sql => $infos) { |
|
| 238 | - if ( |
|
| 239 | - (is_null($types) or in_array($infos['type'], $types)) |
|
| 240 | - and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 241 | - ) { |
|
| 242 | - if (objet_associable($infos['type'])) { |
|
| 243 | - $liens = (($infos['type'] == $objet) ? |
|
| 244 | - objet_trouver_liens(array($objet => $id_source), '*') |
|
| 245 | - : |
|
| 246 | - objet_trouver_liens(array($infos['type'] => '*'), array($objet => $id_source))); |
|
| 247 | - foreach ($liens as $lien) { |
|
| 248 | - $n++; |
|
| 249 | - if ($infos['type'] == $objet) { |
|
| 250 | - objet_associer(array($objet => $id_cible), array($lien['objet'] => $lien[$lien['objet']]), $lien); |
|
| 251 | - } else { |
|
| 252 | - objet_associer(array($infos['type'] => $lien[$infos['type']]), array($objet => $id_cible), $lien); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $n; |
|
| 234 | + include_spip('base/objets'); |
|
| 235 | + $tables = lister_tables_objets_sql(); |
|
| 236 | + $n = 0; |
|
| 237 | + foreach ($tables as $table_sql => $infos) { |
|
| 238 | + if ( |
|
| 239 | + (is_null($types) or in_array($infos['type'], $types)) |
|
| 240 | + and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 241 | + ) { |
|
| 242 | + if (objet_associable($infos['type'])) { |
|
| 243 | + $liens = (($infos['type'] == $objet) ? |
|
| 244 | + objet_trouver_liens(array($objet => $id_source), '*') |
|
| 245 | + : |
|
| 246 | + objet_trouver_liens(array($infos['type'] => '*'), array($objet => $id_source))); |
|
| 247 | + foreach ($liens as $lien) { |
|
| 248 | + $n++; |
|
| 249 | + if ($infos['type'] == $objet) { |
|
| 250 | + objet_associer(array($objet => $id_cible), array($lien['objet'] => $lien[$lien['objet']]), $lien); |
|
| 251 | + } else { |
|
| 252 | + objet_associer(array($infos['type'] => $lien[$infos['type']]), array($objet => $id_cible), $lien); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $n; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -298,38 +298,38 @@ discard block |
||
| 298 | 298 | * @return bool|int|array |
| 299 | 299 | */ |
| 300 | 300 | function objet_traiter_liaisons($operation, $objets_source, $objets_lies, $set = null) { |
| 301 | - // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 302 | - if ($objets_lies == '*') { |
|
| 303 | - $objets_lies = array('*' => '*'); |
|
| 304 | - } |
|
| 305 | - $modifs = 0; // compter le nombre de modifications |
|
| 306 | - $echec = null; |
|
| 307 | - foreach ($objets_source as $objet => $ids) { |
|
| 308 | - if ($a = objet_associable($objet)) { |
|
| 309 | - list($primary, $l) = $a; |
|
| 310 | - if (!is_array($ids)) { |
|
| 311 | - $ids = array($ids); |
|
| 312 | - } elseif (reset($ids) == "NOT") { |
|
| 313 | - // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 314 | - $where = lien_where($primary, $ids, '*', '*'); |
|
| 315 | - $ids = sql_allfetsel($primary, $l, $where); |
|
| 316 | - $ids = array_map('reset', $ids); |
|
| 317 | - } |
|
| 318 | - foreach ($ids as $id) { |
|
| 319 | - $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 320 | - if ($res === false) { |
|
| 321 | - spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 322 | - $echec = true; |
|
| 323 | - } else { |
|
| 324 | - $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - $echec = true; |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - return ($echec ? false : $modifs); // pas d'erreur |
|
| 301 | + // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 302 | + if ($objets_lies == '*') { |
|
| 303 | + $objets_lies = array('*' => '*'); |
|
| 304 | + } |
|
| 305 | + $modifs = 0; // compter le nombre de modifications |
|
| 306 | + $echec = null; |
|
| 307 | + foreach ($objets_source as $objet => $ids) { |
|
| 308 | + if ($a = objet_associable($objet)) { |
|
| 309 | + list($primary, $l) = $a; |
|
| 310 | + if (!is_array($ids)) { |
|
| 311 | + $ids = array($ids); |
|
| 312 | + } elseif (reset($ids) == "NOT") { |
|
| 313 | + // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 314 | + $where = lien_where($primary, $ids, '*', '*'); |
|
| 315 | + $ids = sql_allfetsel($primary, $l, $where); |
|
| 316 | + $ids = array_map('reset', $ids); |
|
| 317 | + } |
|
| 318 | + foreach ($ids as $id) { |
|
| 319 | + $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 320 | + if ($res === false) { |
|
| 321 | + spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 322 | + $echec = true; |
|
| 323 | + } else { |
|
| 324 | + $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + $echec = true; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + return ($echec ? false : $modifs); // pas d'erreur |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -358,81 +358,81 @@ discard block |
||
| 358 | 358 | * Nombre d'insertions faites, false si échec. |
| 359 | 359 | */ |
| 360 | 360 | function lien_insert($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 361 | - $ins = 0; |
|
| 362 | - $echec = null; |
|
| 363 | - if (is_null($qualif)) { |
|
| 364 | - $qualif = array(); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - foreach ($objets as $objet => $id_objets) { |
|
| 368 | - if (!is_array($id_objets)) { |
|
| 369 | - $id_objets = array($id_objets); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // role, colonne, where par défaut |
|
| 373 | - list($role, $colonne_role, $cond) = |
|
| 374 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 375 | - |
|
| 376 | - foreach ($id_objets as $id_objet) { |
|
| 377 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 378 | - |
|
| 379 | - $insertions = array( |
|
| 380 | - 'id_objet' => $id_objet, |
|
| 381 | - 'objet' => $objet, |
|
| 382 | - $primary => $id |
|
| 383 | - ); |
|
| 384 | - // rôle en plus s'il est défini |
|
| 385 | - if ($role) { |
|
| 386 | - $insertions += array( |
|
| 387 | - $colonne_role => $role |
|
| 388 | - ); |
|
| 389 | - } |
|
| 390 | - $args = array( |
|
| 391 | - 'table_lien' => $table_lien, |
|
| 392 | - 'objet_source' => $objet_source, |
|
| 393 | - 'id_objet_source' => $id, |
|
| 394 | - 'objet' => $objet, |
|
| 395 | - 'id_objet' => $id_objet, |
|
| 396 | - 'role' => $role, |
|
| 397 | - 'colonne_role' => $colonne_role, |
|
| 398 | - 'action' => 'insert', |
|
| 399 | - ); |
|
| 400 | - |
|
| 401 | - // Envoyer aux plugins |
|
| 402 | - $insertions = pipeline('pre_edition_lien', |
|
| 403 | - array( |
|
| 404 | - 'args' => $args, |
|
| 405 | - 'data' => $insertions |
|
| 406 | - ) |
|
| 407 | - ); |
|
| 408 | - $args['id_objet'] = $insertions['id_objet']; |
|
| 409 | - |
|
| 410 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 411 | - |
|
| 412 | - if ($id_objet = intval($insertions['id_objet']) |
|
| 413 | - and !sql_getfetsel($primary, $table_lien, $where) |
|
| 414 | - ) { |
|
| 415 | - |
|
| 416 | - $e = sql_insertq($table_lien, $insertions); |
|
| 417 | - if ($e !== false) { |
|
| 418 | - $ins++; |
|
| 419 | - lien_propage_date_modif($objet, $id_objet); |
|
| 420 | - lien_propage_date_modif($objet_source, $id); |
|
| 421 | - // Envoyer aux plugins |
|
| 422 | - pipeline('post_edition_lien', |
|
| 423 | - array( |
|
| 424 | - 'args' => $args, |
|
| 425 | - 'data' => $insertions |
|
| 426 | - ) |
|
| 427 | - ); |
|
| 428 | - } else { |
|
| 429 | - $echec = true; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return ($echec ? false : $ins); |
|
| 361 | + $ins = 0; |
|
| 362 | + $echec = null; |
|
| 363 | + if (is_null($qualif)) { |
|
| 364 | + $qualif = array(); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + foreach ($objets as $objet => $id_objets) { |
|
| 368 | + if (!is_array($id_objets)) { |
|
| 369 | + $id_objets = array($id_objets); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // role, colonne, where par défaut |
|
| 373 | + list($role, $colonne_role, $cond) = |
|
| 374 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 375 | + |
|
| 376 | + foreach ($id_objets as $id_objet) { |
|
| 377 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 378 | + |
|
| 379 | + $insertions = array( |
|
| 380 | + 'id_objet' => $id_objet, |
|
| 381 | + 'objet' => $objet, |
|
| 382 | + $primary => $id |
|
| 383 | + ); |
|
| 384 | + // rôle en plus s'il est défini |
|
| 385 | + if ($role) { |
|
| 386 | + $insertions += array( |
|
| 387 | + $colonne_role => $role |
|
| 388 | + ); |
|
| 389 | + } |
|
| 390 | + $args = array( |
|
| 391 | + 'table_lien' => $table_lien, |
|
| 392 | + 'objet_source' => $objet_source, |
|
| 393 | + 'id_objet_source' => $id, |
|
| 394 | + 'objet' => $objet, |
|
| 395 | + 'id_objet' => $id_objet, |
|
| 396 | + 'role' => $role, |
|
| 397 | + 'colonne_role' => $colonne_role, |
|
| 398 | + 'action' => 'insert', |
|
| 399 | + ); |
|
| 400 | + |
|
| 401 | + // Envoyer aux plugins |
|
| 402 | + $insertions = pipeline('pre_edition_lien', |
|
| 403 | + array( |
|
| 404 | + 'args' => $args, |
|
| 405 | + 'data' => $insertions |
|
| 406 | + ) |
|
| 407 | + ); |
|
| 408 | + $args['id_objet'] = $insertions['id_objet']; |
|
| 409 | + |
|
| 410 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 411 | + |
|
| 412 | + if ($id_objet = intval($insertions['id_objet']) |
|
| 413 | + and !sql_getfetsel($primary, $table_lien, $where) |
|
| 414 | + ) { |
|
| 415 | + |
|
| 416 | + $e = sql_insertq($table_lien, $insertions); |
|
| 417 | + if ($e !== false) { |
|
| 418 | + $ins++; |
|
| 419 | + lien_propage_date_modif($objet, $id_objet); |
|
| 420 | + lien_propage_date_modif($objet_source, $id); |
|
| 421 | + // Envoyer aux plugins |
|
| 422 | + pipeline('post_edition_lien', |
|
| 423 | + array( |
|
| 424 | + 'args' => $args, |
|
| 425 | + 'data' => $insertions |
|
| 426 | + ) |
|
| 427 | + ); |
|
| 428 | + } else { |
|
| 429 | + $echec = true; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return ($echec ? false : $ins); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -447,45 +447,45 @@ discard block |
||
| 447 | 447 | * @return array Liste des conditions |
| 448 | 448 | */ |
| 449 | 449 | function lien_where($primary, $id_source, $objet, $id_objet, $cond = array()) { |
| 450 | - if ((!is_array($id_source) and !strlen($id_source)) |
|
| 451 | - or !strlen($objet) |
|
| 452 | - or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 453 | - ) { |
|
| 454 | - return array("0=1"); |
|
| 455 | - } // securite |
|
| 456 | - |
|
| 457 | - $not = ""; |
|
| 458 | - if (is_array($id_source) and reset($id_source) == "NOT") { |
|
| 459 | - $not = array_shift($id_source); |
|
| 460 | - $id_source = reset($id_source); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - $where = $cond; |
|
| 464 | - |
|
| 465 | - if ($id_source !== '*') { |
|
| 466 | - $where[] = (is_array($id_source) ? sql_in(addslashes($primary), array_map('intval', $id_source), |
|
| 467 | - $not) : addslashes($primary) . ($not ? "<>" : "=") . intval($id_source)); |
|
| 468 | - } elseif ($not) { |
|
| 469 | - $where[] = "0=1"; |
|
| 470 | - } // idiot mais quand meme |
|
| 471 | - |
|
| 472 | - $not = ""; |
|
| 473 | - if (is_array($id_objet) and reset($id_objet) == "NOT") { |
|
| 474 | - $not = array_shift($id_objet); |
|
| 475 | - $id_objet = reset($id_objet); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($objet !== '*') { |
|
| 479 | - $where[] = "objet=" . sql_quote($objet); |
|
| 480 | - } |
|
| 481 | - if ($id_objet !== '*') { |
|
| 482 | - $where[] = (is_array($id_objet) ? sql_in('id_objet', array_map('intval', $id_objet), |
|
| 483 | - $not) : "id_objet" . ($not ? "<>" : "=") . intval($id_objet)); |
|
| 484 | - } elseif ($not) { |
|
| 485 | - $where[] = "0=1"; |
|
| 486 | - } // idiot mais quand meme |
|
| 487 | - |
|
| 488 | - return $where; |
|
| 450 | + if ((!is_array($id_source) and !strlen($id_source)) |
|
| 451 | + or !strlen($objet) |
|
| 452 | + or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 453 | + ) { |
|
| 454 | + return array("0=1"); |
|
| 455 | + } // securite |
|
| 456 | + |
|
| 457 | + $not = ""; |
|
| 458 | + if (is_array($id_source) and reset($id_source) == "NOT") { |
|
| 459 | + $not = array_shift($id_source); |
|
| 460 | + $id_source = reset($id_source); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + $where = $cond; |
|
| 464 | + |
|
| 465 | + if ($id_source !== '*') { |
|
| 466 | + $where[] = (is_array($id_source) ? sql_in(addslashes($primary), array_map('intval', $id_source), |
|
| 467 | + $not) : addslashes($primary) . ($not ? "<>" : "=") . intval($id_source)); |
|
| 468 | + } elseif ($not) { |
|
| 469 | + $where[] = "0=1"; |
|
| 470 | + } // idiot mais quand meme |
|
| 471 | + |
|
| 472 | + $not = ""; |
|
| 473 | + if (is_array($id_objet) and reset($id_objet) == "NOT") { |
|
| 474 | + $not = array_shift($id_objet); |
|
| 475 | + $id_objet = reset($id_objet); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($objet !== '*') { |
|
| 479 | + $where[] = "objet=" . sql_quote($objet); |
|
| 480 | + } |
|
| 481 | + if ($id_objet !== '*') { |
|
| 482 | + $where[] = (is_array($id_objet) ? sql_in('id_objet', array_map('intval', $id_objet), |
|
| 483 | + $not) : "id_objet" . ($not ? "<>" : "=") . intval($id_objet)); |
|
| 484 | + } elseif ($not) { |
|
| 485 | + $where[] = "0=1"; |
|
| 486 | + } // idiot mais quand meme |
|
| 487 | + |
|
| 488 | + return $where; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -516,85 +516,85 @@ discard block |
||
| 516 | 516 | */ |
| 517 | 517 | function lien_delete($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 518 | 518 | |
| 519 | - $retire = array(); |
|
| 520 | - $dels = 0; |
|
| 521 | - $echec = false; |
|
| 522 | - if (is_null($cond)) { |
|
| 523 | - $cond = array(); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - foreach ($objets as $objet => $id_objets) { |
|
| 527 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 528 | - if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 529 | - $id_objets = array($id_objets); |
|
| 530 | - } |
|
| 531 | - foreach ($id_objets as $id_objet) { |
|
| 532 | - list($cond, $colonne_role, $role) = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 533 | - // id_objet peut valoir '*' |
|
| 534 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 535 | - |
|
| 536 | - // lire les liens existants pour propager la date de modif |
|
| 537 | - $select = "$primary,id_objet,objet"; |
|
| 538 | - if ($colonne_role) { |
|
| 539 | - $select .= ",$colonne_role"; |
|
| 540 | - } |
|
| 541 | - $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 542 | - |
|
| 543 | - // iterer sur les liens pour permettre aux plugins de gerer |
|
| 544 | - foreach ($liens as $l) { |
|
| 545 | - |
|
| 546 | - $args = array( |
|
| 547 | - 'table_lien' => $table_lien, |
|
| 548 | - 'objet_source' => $objet_source, |
|
| 549 | - 'id_objet_source' => $l[$primary], |
|
| 550 | - 'objet' => $l['objet'], |
|
| 551 | - 'id_objet' => $l['id_objet'], |
|
| 552 | - 'colonne_role' => $colonne_role, |
|
| 553 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 554 | - 'action' => 'delete', |
|
| 555 | - ); |
|
| 556 | - |
|
| 557 | - // Envoyer aux plugins |
|
| 558 | - $l = pipeline('pre_edition_lien', |
|
| 559 | - array( |
|
| 560 | - 'args' => $args, |
|
| 561 | - 'data' => $l |
|
| 562 | - ) |
|
| 563 | - ); |
|
| 564 | - $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 565 | - |
|
| 566 | - if ($id_o = intval($l['id_objet'])) { |
|
| 567 | - $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 568 | - $e = sql_delete($table_lien, $where); |
|
| 569 | - if ($e !== false) { |
|
| 570 | - $dels += $e; |
|
| 571 | - lien_propage_date_modif($l['objet'], $id_o); |
|
| 572 | - lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 573 | - } else { |
|
| 574 | - $echec = true; |
|
| 575 | - } |
|
| 576 | - $retire[] = array( |
|
| 577 | - 'source' => array($objet_source => $l[$primary]), |
|
| 578 | - 'lien' => array($l['objet'] => $id_o), |
|
| 579 | - 'type' => $l['objet'], |
|
| 580 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 581 | - 'id' => $id_o |
|
| 582 | - ); |
|
| 583 | - // Envoyer aux plugins |
|
| 584 | - pipeline('post_edition_lien', |
|
| 585 | - array( |
|
| 586 | - 'args' => $args, |
|
| 587 | - 'data' => $l |
|
| 588 | - ) |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - pipeline('trig_supprimer_objets_lies', $retire); |
|
| 596 | - |
|
| 597 | - return ($echec ? false : $dels); |
|
| 519 | + $retire = array(); |
|
| 520 | + $dels = 0; |
|
| 521 | + $echec = false; |
|
| 522 | + if (is_null($cond)) { |
|
| 523 | + $cond = array(); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + foreach ($objets as $objet => $id_objets) { |
|
| 527 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 528 | + if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 529 | + $id_objets = array($id_objets); |
|
| 530 | + } |
|
| 531 | + foreach ($id_objets as $id_objet) { |
|
| 532 | + list($cond, $colonne_role, $role) = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 533 | + // id_objet peut valoir '*' |
|
| 534 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 535 | + |
|
| 536 | + // lire les liens existants pour propager la date de modif |
|
| 537 | + $select = "$primary,id_objet,objet"; |
|
| 538 | + if ($colonne_role) { |
|
| 539 | + $select .= ",$colonne_role"; |
|
| 540 | + } |
|
| 541 | + $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 542 | + |
|
| 543 | + // iterer sur les liens pour permettre aux plugins de gerer |
|
| 544 | + foreach ($liens as $l) { |
|
| 545 | + |
|
| 546 | + $args = array( |
|
| 547 | + 'table_lien' => $table_lien, |
|
| 548 | + 'objet_source' => $objet_source, |
|
| 549 | + 'id_objet_source' => $l[$primary], |
|
| 550 | + 'objet' => $l['objet'], |
|
| 551 | + 'id_objet' => $l['id_objet'], |
|
| 552 | + 'colonne_role' => $colonne_role, |
|
| 553 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 554 | + 'action' => 'delete', |
|
| 555 | + ); |
|
| 556 | + |
|
| 557 | + // Envoyer aux plugins |
|
| 558 | + $l = pipeline('pre_edition_lien', |
|
| 559 | + array( |
|
| 560 | + 'args' => $args, |
|
| 561 | + 'data' => $l |
|
| 562 | + ) |
|
| 563 | + ); |
|
| 564 | + $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 565 | + |
|
| 566 | + if ($id_o = intval($l['id_objet'])) { |
|
| 567 | + $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 568 | + $e = sql_delete($table_lien, $where); |
|
| 569 | + if ($e !== false) { |
|
| 570 | + $dels += $e; |
|
| 571 | + lien_propage_date_modif($l['objet'], $id_o); |
|
| 572 | + lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 573 | + } else { |
|
| 574 | + $echec = true; |
|
| 575 | + } |
|
| 576 | + $retire[] = array( |
|
| 577 | + 'source' => array($objet_source => $l[$primary]), |
|
| 578 | + 'lien' => array($l['objet'] => $id_o), |
|
| 579 | + 'type' => $l['objet'], |
|
| 580 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 581 | + 'id' => $id_o |
|
| 582 | + ); |
|
| 583 | + // Envoyer aux plugins |
|
| 584 | + pipeline('post_edition_lien', |
|
| 585 | + array( |
|
| 586 | + 'args' => $args, |
|
| 587 | + 'data' => $l |
|
| 588 | + ) |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + pipeline('trig_supprimer_objets_lies', $retire); |
|
| 596 | + |
|
| 597 | + return ($echec ? false : $dels); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
@@ -617,56 +617,56 @@ discard block |
||
| 617 | 617 | * @return bool|int |
| 618 | 618 | */ |
| 619 | 619 | function lien_optimise($objet_source, $primary, $table_lien, $id, $objets) { |
| 620 | - include_spip('genie/optimiser'); |
|
| 621 | - $echec = false; |
|
| 622 | - $dels = 0; |
|
| 623 | - foreach ($objets as $objet => $id_objets) { |
|
| 624 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 625 | - if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 626 | - $id_objets = array($id_objets); |
|
| 627 | - } |
|
| 628 | - foreach ($id_objets as $id_objet) { |
|
| 629 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 630 | - # les liens vers un objet inexistant |
|
| 631 | - $r = sql_select("DISTINCT objet", $table_lien, $where); |
|
| 632 | - while ($t = sql_fetch($r)) { |
|
| 633 | - $type = $t['objet']; |
|
| 634 | - $spip_table_objet = table_objet_sql($type); |
|
| 635 | - $id_table_objet = id_table_objet($type); |
|
| 636 | - $res = sql_select("L.$primary AS id,L.id_objet", |
|
| 637 | - // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 638 | - // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 639 | - // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 640 | - "$table_lien AS L |
|
| 620 | + include_spip('genie/optimiser'); |
|
| 621 | + $echec = false; |
|
| 622 | + $dels = 0; |
|
| 623 | + foreach ($objets as $objet => $id_objets) { |
|
| 624 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 625 | + if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 626 | + $id_objets = array($id_objets); |
|
| 627 | + } |
|
| 628 | + foreach ($id_objets as $id_objet) { |
|
| 629 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 630 | + # les liens vers un objet inexistant |
|
| 631 | + $r = sql_select("DISTINCT objet", $table_lien, $where); |
|
| 632 | + while ($t = sql_fetch($r)) { |
|
| 633 | + $type = $t['objet']; |
|
| 634 | + $spip_table_objet = table_objet_sql($type); |
|
| 635 | + $id_table_objet = id_table_objet($type); |
|
| 636 | + $res = sql_select("L.$primary AS id,L.id_objet", |
|
| 637 | + // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 638 | + // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 639 | + // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 640 | + "$table_lien AS L |
|
| 641 | 641 | LEFT JOIN $spip_table_objet AS O |
| 642 | 642 | ON (O.$id_table_objet=L.id_objet AND L.objet=" . sql_quote($type) . ")", |
| 643 | - "L.objet=" . sql_quote($type) . " AND O.$id_table_objet IS NULL"); |
|
| 644 | - // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 645 | - while ($row = sql_fetch($res)) { |
|
| 646 | - $e = sql_delete($table_lien, |
|
| 647 | - array("$primary=" . $row['id'], "id_objet=" . $row['id_objet'], "objet=" . sql_quote($type))); |
|
| 648 | - if ($e != false) { |
|
| 649 | - $dels += $e; |
|
| 650 | - spip_log("Entree " . $row['id'] . "/" . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 651 | - _LOG_INFO_IMPORTANTE); |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - # les liens depuis un objet inexistant |
|
| 657 | - $table_source = table_objet_sql($objet_source); |
|
| 658 | - // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 659 | - // (en general '*' pour chaque) |
|
| 660 | - $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 661 | - $where[] = "O.$primary IS NULL"; |
|
| 662 | - $res = sql_select("L.$primary AS id", |
|
| 663 | - "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 664 | - $where); |
|
| 665 | - $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - return ($echec ? false : $dels); |
|
| 643 | + "L.objet=" . sql_quote($type) . " AND O.$id_table_objet IS NULL"); |
|
| 644 | + // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 645 | + while ($row = sql_fetch($res)) { |
|
| 646 | + $e = sql_delete($table_lien, |
|
| 647 | + array("$primary=" . $row['id'], "id_objet=" . $row['id_objet'], "objet=" . sql_quote($type))); |
|
| 648 | + if ($e != false) { |
|
| 649 | + $dels += $e; |
|
| 650 | + spip_log("Entree " . $row['id'] . "/" . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 651 | + _LOG_INFO_IMPORTANTE); |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + # les liens depuis un objet inexistant |
|
| 657 | + $table_source = table_objet_sql($objet_source); |
|
| 658 | + // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 659 | + // (en general '*' pour chaque) |
|
| 660 | + $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 661 | + $where[] = "O.$primary IS NULL"; |
|
| 662 | + $res = sql_select("L.$primary AS id", |
|
| 663 | + "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 664 | + $where); |
|
| 665 | + $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + return ($echec ? false : $dels); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | |
@@ -698,70 +698,70 @@ discard block |
||
| 698 | 698 | * Nombre de modifications faites, false si échec. |
| 699 | 699 | */ |
| 700 | 700 | function lien_set($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 701 | - $echec = null; |
|
| 702 | - $ok = 0; |
|
| 703 | - if (!$qualif) { |
|
| 704 | - return false; |
|
| 705 | - } |
|
| 706 | - // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 707 | - unset($qualif[$primary]); |
|
| 708 | - unset($qualif[$objet_source]); |
|
| 709 | - if (isset($qualif['objet'])) { |
|
| 710 | - unset($qualif[$qualif['objet']]); |
|
| 711 | - } |
|
| 712 | - unset($qualif['objet']); |
|
| 713 | - unset($qualif['id_objet']); |
|
| 714 | - foreach ($objets as $objet => $id_objets) { |
|
| 715 | - |
|
| 716 | - // role, colonne, where par défaut |
|
| 717 | - list($role, $colonne_role, $cond) = |
|
| 718 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 719 | - |
|
| 720 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 721 | - if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 722 | - $id_objets = array($id_objets); |
|
| 723 | - } |
|
| 724 | - foreach ($id_objets as $id_objet) { |
|
| 725 | - |
|
| 726 | - $args = array( |
|
| 727 | - 'table_lien' => $table_lien, |
|
| 728 | - 'objet_source' => $objet_source, |
|
| 729 | - 'id_objet_source' => $id, |
|
| 730 | - 'objet' => $objet, |
|
| 731 | - 'id_objet' => $id_objet, |
|
| 732 | - 'role' => $role, |
|
| 733 | - 'colonne_role' => $colonne_role, |
|
| 734 | - 'action' => 'modifier', |
|
| 735 | - ); |
|
| 736 | - |
|
| 737 | - // Envoyer aux plugins |
|
| 738 | - $qualif = pipeline('pre_edition_lien', |
|
| 739 | - array( |
|
| 740 | - 'args' => $args, |
|
| 741 | - 'data' => $qualif, |
|
| 742 | - ) |
|
| 743 | - ); |
|
| 744 | - $args['id_objet'] = $id_objet; |
|
| 745 | - |
|
| 746 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 747 | - $e = sql_updateq($table_lien, $qualif, $where); |
|
| 748 | - |
|
| 749 | - if ($e === false) { |
|
| 750 | - $echec = true; |
|
| 751 | - } else { |
|
| 752 | - // Envoyer aux plugins |
|
| 753 | - pipeline('post_edition_lien', |
|
| 754 | - array( |
|
| 755 | - 'args' => $args, |
|
| 756 | - 'data' => $qualif |
|
| 757 | - ) |
|
| 758 | - ); |
|
| 759 | - $ok++; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return ($echec ? false : $ok); |
|
| 701 | + $echec = null; |
|
| 702 | + $ok = 0; |
|
| 703 | + if (!$qualif) { |
|
| 704 | + return false; |
|
| 705 | + } |
|
| 706 | + // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 707 | + unset($qualif[$primary]); |
|
| 708 | + unset($qualif[$objet_source]); |
|
| 709 | + if (isset($qualif['objet'])) { |
|
| 710 | + unset($qualif[$qualif['objet']]); |
|
| 711 | + } |
|
| 712 | + unset($qualif['objet']); |
|
| 713 | + unset($qualif['id_objet']); |
|
| 714 | + foreach ($objets as $objet => $id_objets) { |
|
| 715 | + |
|
| 716 | + // role, colonne, where par défaut |
|
| 717 | + list($role, $colonne_role, $cond) = |
|
| 718 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 719 | + |
|
| 720 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 721 | + if (!is_array($id_objets) or reset($id_objets) == "NOT") { |
|
| 722 | + $id_objets = array($id_objets); |
|
| 723 | + } |
|
| 724 | + foreach ($id_objets as $id_objet) { |
|
| 725 | + |
|
| 726 | + $args = array( |
|
| 727 | + 'table_lien' => $table_lien, |
|
| 728 | + 'objet_source' => $objet_source, |
|
| 729 | + 'id_objet_source' => $id, |
|
| 730 | + 'objet' => $objet, |
|
| 731 | + 'id_objet' => $id_objet, |
|
| 732 | + 'role' => $role, |
|
| 733 | + 'colonne_role' => $colonne_role, |
|
| 734 | + 'action' => 'modifier', |
|
| 735 | + ); |
|
| 736 | + |
|
| 737 | + // Envoyer aux plugins |
|
| 738 | + $qualif = pipeline('pre_edition_lien', |
|
| 739 | + array( |
|
| 740 | + 'args' => $args, |
|
| 741 | + 'data' => $qualif, |
|
| 742 | + ) |
|
| 743 | + ); |
|
| 744 | + $args['id_objet'] = $id_objet; |
|
| 745 | + |
|
| 746 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 747 | + $e = sql_updateq($table_lien, $qualif, $where); |
|
| 748 | + |
|
| 749 | + if ($e === false) { |
|
| 750 | + $echec = true; |
|
| 751 | + } else { |
|
| 752 | + // Envoyer aux plugins |
|
| 753 | + pipeline('post_edition_lien', |
|
| 754 | + array( |
|
| 755 | + 'args' => $args, |
|
| 756 | + 'data' => $qualif |
|
| 757 | + ) |
|
| 758 | + ); |
|
| 759 | + $ok++; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return ($echec ? false : $ok); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -791,23 +791,23 @@ discard block |
||
| 791 | 791 | * @return array |
| 792 | 792 | */ |
| 793 | 793 | function lien_find($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 794 | - $trouve = array(); |
|
| 795 | - foreach ($objets as $objet => $id_objets) { |
|
| 796 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 797 | - // gerer les roles s'il y en a dans $cond |
|
| 798 | - list($cond) = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 799 | - // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 800 | - $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 801 | - $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 802 | - // ajouter les entrees objet_source et objet cible par convenance |
|
| 803 | - foreach ($liens as $l) { |
|
| 804 | - $l[$objet_source] = $l[$primary]; |
|
| 805 | - $l[$objet] = $l['id_objet']; |
|
| 806 | - $trouve[] = $l; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - return $trouve; |
|
| 794 | + $trouve = array(); |
|
| 795 | + foreach ($objets as $objet => $id_objets) { |
|
| 796 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 797 | + // gerer les roles s'il y en a dans $cond |
|
| 798 | + list($cond) = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 799 | + // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 800 | + $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 801 | + $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 802 | + // ajouter les entrees objet_source et objet cible par convenance |
|
| 803 | + foreach ($liens as $l) { |
|
| 804 | + $l[$objet_source] = $l[$primary]; |
|
| 805 | + $l[$objet] = $l['id_objet']; |
|
| 806 | + $trouve[] = $l; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + return $trouve; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
@@ -818,25 +818,25 @@ discard block |
||
| 818 | 818 | * @param array|int $ids |
| 819 | 819 | */ |
| 820 | 820 | function lien_propage_date_modif($objet, $ids) { |
| 821 | - static $done = array(); |
|
| 822 | - $hash = md5($objet . serialize($ids)); |
|
| 823 | - |
|
| 824 | - // sql_updateq, peut être un rien lent. |
|
| 825 | - // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 826 | - if (isset($done[$hash])) { |
|
| 827 | - return; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 831 | - |
|
| 832 | - $table = table_objet_sql($objet); |
|
| 833 | - if ($desc = $trouver_table($table) |
|
| 834 | - and isset($desc['field']['date_modif']) |
|
| 835 | - ) { |
|
| 836 | - $primary = id_table_objet($objet); |
|
| 837 | - $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 838 | - sql_updateq($table, array('date_modif' => date('Y-m-d H:i:s')), $where); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - $done[$hash] = true; |
|
| 821 | + static $done = array(); |
|
| 822 | + $hash = md5($objet . serialize($ids)); |
|
| 823 | + |
|
| 824 | + // sql_updateq, peut être un rien lent. |
|
| 825 | + // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 826 | + if (isset($done[$hash])) { |
|
| 827 | + return; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 831 | + |
|
| 832 | + $table = table_objet_sql($objet); |
|
| 833 | + if ($desc = $trouver_table($table) |
|
| 834 | + and isset($desc['field']['date_modif']) |
|
| 835 | + ) { |
|
| 836 | + $primary = id_table_objet($objet); |
|
| 837 | + $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 838 | + sql_updateq($table, array('date_modif' => date('Y-m-d H:i:s')), $where); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + $done[$hash] = true; |
|
| 842 | 842 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $l = ""; |
| 54 | 54 | if ($primary = id_table_objet($objet) |
| 55 | - and $trouver_table($l = $table_sql . "_liens") |
|
| 55 | + and $trouver_table($l = $table_sql."_liens") |
|
| 56 | 56 | and !preg_match(',[^\w],', $primary) |
| 57 | 57 | and !preg_match(',[^\w],', $l) |
| 58 | 58 | ) { |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | |
| 465 | 465 | if ($id_source !== '*') { |
| 466 | 466 | $where[] = (is_array($id_source) ? sql_in(addslashes($primary), array_map('intval', $id_source), |
| 467 | - $not) : addslashes($primary) . ($not ? "<>" : "=") . intval($id_source)); |
|
| 467 | + $not) : addslashes($primary).($not ? "<>" : "=").intval($id_source)); |
|
| 468 | 468 | } elseif ($not) { |
| 469 | 469 | $where[] = "0=1"; |
| 470 | 470 | } // idiot mais quand meme |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | if ($objet !== '*') { |
| 479 | - $where[] = "objet=" . sql_quote($objet); |
|
| 479 | + $where[] = "objet=".sql_quote($objet); |
|
| 480 | 480 | } |
| 481 | 481 | if ($id_objet !== '*') { |
| 482 | 482 | $where[] = (is_array($id_objet) ? sql_in('id_objet', array_map('intval', $id_objet), |
| 483 | - $not) : "id_objet" . ($not ? "<>" : "=") . intval($id_objet)); |
|
| 483 | + $not) : "id_objet".($not ? "<>" : "=").intval($id_objet)); |
|
| 484 | 484 | } elseif ($not) { |
| 485 | 485 | $where[] = "0=1"; |
| 486 | 486 | } // idiot mais quand meme |
@@ -639,15 +639,15 @@ discard block |
||
| 639 | 639 | // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
| 640 | 640 | "$table_lien AS L |
| 641 | 641 | LEFT JOIN $spip_table_objet AS O |
| 642 | - ON (O.$id_table_objet=L.id_objet AND L.objet=" . sql_quote($type) . ")", |
|
| 643 | - "L.objet=" . sql_quote($type) . " AND O.$id_table_objet IS NULL"); |
|
| 642 | + ON (O.$id_table_objet=L.id_objet AND L.objet=".sql_quote($type).")", |
|
| 643 | + "L.objet=".sql_quote($type)." AND O.$id_table_objet IS NULL"); |
|
| 644 | 644 | // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
| 645 | 645 | while ($row = sql_fetch($res)) { |
| 646 | 646 | $e = sql_delete($table_lien, |
| 647 | - array("$primary=" . $row['id'], "id_objet=" . $row['id_objet'], "objet=" . sql_quote($type))); |
|
| 647 | + array("$primary=".$row['id'], "id_objet=".$row['id_objet'], "objet=".sql_quote($type))); |
|
| 648 | 648 | if ($e != false) { |
| 649 | 649 | $dels += $e; |
| 650 | - spip_log("Entree " . $row['id'] . "/" . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 650 | + spip_log("Entree ".$row['id']."/".$row['id_objet']."/$type supprimee dans la table $table_lien", |
|
| 651 | 651 | _LOG_INFO_IMPORTANTE); |
| 652 | 652 | } |
| 653 | 653 | } |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | */ |
| 820 | 820 | function lien_propage_date_modif($objet, $ids) { |
| 821 | 821 | static $done = array(); |
| 822 | - $hash = md5($objet . serialize($ids)); |
|
| 822 | + $hash = md5($objet.serialize($ids)); |
|
| 823 | 823 | |
| 824 | 824 | // sql_updateq, peut être un rien lent. |
| 825 | 825 | // On évite de l'appeler 2 fois sur les mêmes choses |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | and isset($desc['field']['date_modif']) |
| 835 | 835 | ) { |
| 836 | 836 | $primary = id_table_objet($objet); |
| 837 | - $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 837 | + $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=".intval($ids)); |
|
| 838 | 838 | sql_updateq($table, array('date_modif' => date('Y-m-d H:i:s')), $where); |
| 839 | 839 | } |
| 840 | 840 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * the constructor |
| 89 | 89 | * |
| 90 | 90 | * @param array $options |
| 91 | - * @return boolean |
|
| 91 | + * @return boolean|null |
|
| 92 | 92 | * @since 0.5.2 |
| 93 | 93 | */ |
| 94 | 94 | public function __construct($options = false) |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | /** |
| 394 | 394 | * Use this method to get the last error ocurred |
| 395 | 395 | * @param void |
| 396 | - * @return string The last error, that occured |
|
| 396 | + * @return boolean The last error, that occured |
|
| 397 | 397 | */ |
| 398 | 398 | public function get_last_error() |
| 399 | 399 | { |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | /** |
| 404 | 404 | * The actual decoding algorithm |
| 405 | 405 | * @param string |
| 406 | - * @return mixed |
|
| 406 | + * @return false|string |
|
| 407 | 407 | */ |
| 408 | 408 | protected function _decode($encoded) |
| 409 | 409 | { |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | /** |
| 465 | 465 | * The actual encoding algorithm |
| 466 | 466 | * @param string |
| 467 | - * @return mixed |
|
| 467 | + * @return false|string |
|
| 468 | 468 | */ |
| 469 | 469 | protected function _encode($decoded) |
| 470 | 470 | { |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | * Decomposes a Hangul syllable |
| 700 | 700 | * (see http://www.unicode.org/unicode/reports/tr15/#Hangul |
| 701 | 701 | * @param integer 32bit UCS4 code point |
| 702 | - * @return array Either Hangul Syllable decomposed or original 32bit value as one value array |
|
| 702 | + * @return integer[] Either Hangul Syllable decomposed or original 32bit value as one value array |
|
| 703 | 703 | */ |
| 704 | 704 | protected function _hangul_decompose($char) |
| 705 | 705 | { |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | protected $_lcount = 19; |
| 74 | 74 | protected $_vcount = 21; |
| 75 | 75 | protected $_tcount = 28; |
| 76 | - protected $_ncount = 588; // _vcount * _tcount |
|
| 76 | + protected $_ncount = 588; // _vcount * _tcount |
|
| 77 | 77 | protected $_scount = 11172; // _lcount * _tcount * _vcount |
| 78 | 78 | protected $_error = false; |
| 79 | 79 | protected static $_mb_string_overload = null; |
| 80 | 80 | // See {@link set_paramter()} for details of how to change the following |
| 81 | 81 | // settings from within your script / application |
| 82 | - protected $_api_encoding = 'utf8'; // Default input charset is UTF-8 |
|
| 83 | - protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden |
|
| 84 | - protected $_strict_mode = false; // Behave strict or not |
|
| 85 | - protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008 |
|
| 82 | + protected $_api_encoding = 'utf8'; // Default input charset is UTF-8 |
|
| 83 | + protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden |
|
| 84 | + protected $_strict_mode = false; // Behave strict or not |
|
| 85 | + protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008 |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * the constructor |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $this->_api_encoding = $v; |
| 141 | 141 | break; |
| 142 | 142 | default: |
| 143 | - $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k); |
|
| 143 | + $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | break; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | if (in_array($v, array('2003', '2008'))) { |
| 155 | 155 | $this->_idn_version = $v; |
| 156 | 156 | } else { |
| 157 | - $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k); |
|
| 157 | + $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); |
|
| 158 | 158 | } |
| 159 | 159 | break; |
| 160 | 160 | case 'encode_german_sz': // Deprecated |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | break; |
| 167 | 167 | default: |
| 168 | - $this->_error('Set Parameter: Unknown option ' . $k); |
|
| 168 | + $this->_error('Set Parameter: Unknown option '.$k); |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | case 'ucs4_array': |
| 189 | 189 | break; |
| 190 | 190 | default: |
| 191 | - $this->_error('Unknown encoding ' . $one_time_encoding); |
|
| 191 | + $this->_error('Unknown encoding '.$one_time_encoding); |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | list ($email_pref, $input) = explode('@', $input, 2); |
| 207 | 207 | $arr = explode('.', $input); |
| 208 | 208 | foreach ($arr as $k => $v) { |
| 209 | - if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { |
|
| 209 | + if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) { |
|
| 210 | 210 | $conv = $this->_decode($v); |
| 211 | 211 | if ($conv) { |
| 212 | 212 | $arr[$k] = $conv; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $input = join('.', $arr); |
| 217 | 217 | $arr = explode('.', $email_pref); |
| 218 | 218 | foreach ($arr as $k => $v) { |
| 219 | - if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { |
|
| 219 | + if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) { |
|
| 220 | 220 | $conv = $this->_decode($v); |
| 221 | 221 | if ($conv) { |
| 222 | 222 | $arr[$k] = $conv; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | $email_pref = join('.', $arr); |
| 227 | - $return = $email_pref . '@' . $input; |
|
| 227 | + $return = $email_pref.'@'.$input; |
|
| 228 | 228 | } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters) |
| 229 | 229 | // No no in strict mode |
| 230 | 230 | if ($this->_strict_mode) { |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | $parsed['host'] = join('.', $arr); |
| 244 | - $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 245 | - (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@'). |
|
| 244 | + $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 245 | + (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@'). |
|
| 246 | 246 | $parsed['host']. |
| 247 | - (empty($parsed['port']) ? '' : ':' . $parsed['port']). |
|
| 247 | + (empty($parsed['port']) ? '' : ':'.$parsed['port']). |
|
| 248 | 248 | (empty($parsed['path']) ? '' : $parsed['path']). |
| 249 | - (empty($parsed['query']) ? '' : '?' . $parsed['query']). |
|
| 250 | - (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']); |
|
| 249 | + (empty($parsed['query']) ? '' : '?'.$parsed['query']). |
|
| 250 | + (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); |
|
| 251 | 251 | } else { // parse_url seems to have failed, try without it |
| 252 | 252 | $arr = explode('.', $input); |
| 253 | 253 | foreach ($arr as $k => $v) { |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | // The output is UTF-8 by default, other output formats need conversion here |
| 266 | 266 | // If one time encoding is given, use this, else the objects property |
| 267 | 267 | switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) { |
| 268 | - case 'utf8': return $return; // break; |
|
| 269 | - case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break; |
|
| 268 | + case 'utf8' : return $return; // break; |
|
| 269 | + case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break; |
|
| 270 | 270 | case 'ucs4_array': return $this->_utf8_to_ucs4($return); // break; |
| 271 | 271 | default: $this->_error('Unsupported output format'); return false; |
| 272 | 272 | } |
@@ -283,15 +283,14 @@ discard block |
||
| 283 | 283 | // Forcing conversion of input to UCS4 array |
| 284 | 284 | // If one time encoding is given, use this, else the objects property |
| 285 | 285 | switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) { |
| 286 | - case 'utf8': |
|
| 287 | - $decoded = $this->_utf8_to_ucs4($decoded); |
|
| 286 | + case 'utf8' : $decoded = $this->_utf8_to_ucs4($decoded); |
|
| 288 | 287 | break; |
| 289 | 288 | case 'ucs4_string': |
| 290 | 289 | $decoded = $this->_ucs4_string_to_ucs4($decoded); |
| 291 | 290 | case 'ucs4_array': |
| 292 | 291 | break; |
| 293 | 292 | default: |
| 294 | - $this->_error('Unsupported input format: ' . ($one_time_encoding ? $one_time_encoding : $this->_api_encoding)); |
|
| 293 | + $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding)); |
|
| 295 | 294 | return false; |
| 296 | 295 | } |
| 297 | 296 | |
@@ -380,13 +379,13 @@ discard block |
||
| 380 | 379 | } |
| 381 | 380 | } |
| 382 | 381 | $parsed['host'] = join('.', $arr); |
| 383 | - $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 384 | - (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@'). |
|
| 382 | + $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 383 | + (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@'). |
|
| 385 | 384 | $parsed['host']. |
| 386 | - (empty($parsed['port']) ? '' : ':' . $parsed['port']). |
|
| 385 | + (empty($parsed['port']) ? '' : ':'.$parsed['port']). |
|
| 387 | 386 | (empty($parsed['path']) ? '' : $parsed['path']). |
| 388 | - (empty($parsed['query']) ? '' : '?' . $parsed['query']). |
|
| 389 | - (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']); |
|
| 387 | + (empty($parsed['query']) ? '' : '?'.$parsed['query']). |
|
| 388 | + (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); |
|
| 390 | 389 | return $return; |
| 391 | 390 | } |
| 392 | 391 | |
@@ -409,11 +408,11 @@ discard block |
||
| 409 | 408 | { |
| 410 | 409 | $decoded = array(); |
| 411 | 410 | // find the Punycode prefix |
| 412 | - if (!preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $encoded)) { |
|
| 411 | + if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) { |
|
| 413 | 412 | $this->_error('This is not a punycode string'); |
| 414 | 413 | return false; |
| 415 | 414 | } |
| 416 | - $encode_test = preg_replace('!^' . preg_quote($this->_punycode_prefix, '!') . '!', '', $encoded); |
|
| 415 | + $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded); |
|
| 417 | 416 | // If nothing left after removing the prefix, it is hopeless |
| 418 | 417 | if (!$encode_test) { |
| 419 | 418 | $this->_error('The given encoded string was empty'); |
@@ -439,8 +438,7 @@ discard block |
||
| 439 | 438 | for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) { |
| 440 | 439 | $digit = $this->_decode_digit($encoded{$enco_idx++}); |
| 441 | 440 | $idx += $digit * $w; |
| 442 | - $t = ($k <= $bias) ? $this->_tmin : |
|
| 443 | - (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); |
|
| 441 | + $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); |
|
| 444 | 442 | if ($digit < $t) { |
| 445 | 443 | break; |
| 446 | 444 | } |
@@ -513,7 +511,7 @@ discard block |
||
| 513 | 511 | return $encoded; // All codepoints were basic ones |
| 514 | 512 | } |
| 515 | 513 | // Start with the prefix; copy it to output |
| 516 | - $encoded = $this->_punycode_prefix . $encoded; |
|
| 514 | + $encoded = $this->_punycode_prefix.$encoded; |
|
| 517 | 515 | // If we have basic code points in output, add an hyphen to the end |
| 518 | 516 | if ($codecount) { |
| 519 | 517 | $encoded .= '-'; |
@@ -540,8 +538,7 @@ discard block |
||
| 540 | 538 | $delta++; |
| 541 | 539 | } elseif ($decoded[$i] == $cur_code) { |
| 542 | 540 | for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) { |
| 543 | - $t = ($k <= $bias) ? $this->_tmin : |
|
| 544 | - (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); |
|
| 541 | + $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); |
|
| 545 | 542 | if ($q < $t) { |
| 546 | 543 | break; |
| 547 | 544 | } |
@@ -628,12 +625,12 @@ discard block |
||
| 628 | 625 | } |
| 629 | 626 | // Try to find prohibited input |
| 630 | 627 | if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) { |
| 631 | - $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v)); |
|
| 628 | + $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v)); |
|
| 632 | 629 | return false; |
| 633 | 630 | } |
| 634 | 631 | foreach (self::$NP['prohibit_ranges'] as $range) { |
| 635 | 632 | if ($range[0] <= $v && $v <= $range[1]) { |
| 636 | - $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v)); |
|
| 633 | + $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v)); |
|
| 637 | 634 | return false; |
| 638 | 635 | } |
| 639 | 636 | } |
@@ -869,7 +866,7 @@ discard block |
||
| 869 | 866 | $output[$out_len] = $v; |
| 870 | 867 | ++$out_len; |
| 871 | 868 | if ('add' == $mode) { |
| 872 | - $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); |
|
| 869 | + $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k); |
|
| 873 | 870 | return false; |
| 874 | 871 | } |
| 875 | 872 | continue; |
@@ -894,7 +891,7 @@ discard block |
||
| 894 | 891 | $next_byte = 4; |
| 895 | 892 | $v = ($v - 252) << 30; |
| 896 | 893 | } else { |
| 897 | - $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k); |
|
| 894 | + $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k); |
|
| 898 | 895 | return false; |
| 899 | 896 | } |
| 900 | 897 | if ('add' == $mode) { |
@@ -907,7 +904,7 @@ discard block |
||
| 907 | 904 | if (!$this->_allow_overlong && $test == 'range') { |
| 908 | 905 | $test = 'none'; |
| 909 | 906 | if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) { |
| 910 | - $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k); |
|
| 907 | + $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k); |
|
| 911 | 908 | return false; |
| 912 | 909 | } |
| 913 | 910 | } |
@@ -916,7 +913,7 @@ discard block |
||
| 916 | 913 | $output[($out_len - 1)] += $v; |
| 917 | 914 | --$next_byte; |
| 918 | 915 | } else { |
| 919 | - $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); |
|
| 916 | + $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k); |
|
| 920 | 917 | return false; |
| 921 | 918 | } |
| 922 | 919 | if ($next_byte < 0) { |
@@ -940,13 +937,13 @@ discard block |
||
| 940 | 937 | if ($v < 128) { // 7bit are transferred literally |
| 941 | 938 | $output .= chr($v); |
| 942 | 939 | } elseif ($v < (1 << 11)) { // 2 bytes |
| 943 | - $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63)); |
|
| 940 | + $output .= chr(192 + ($v >> 6)).chr(128 + ($v & 63)); |
|
| 944 | 941 | } elseif ($v < (1 << 16)) { // 3 bytes |
| 945 | - $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 942 | + $output .= chr(224 + ($v >> 12)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63)); |
|
| 946 | 943 | } elseif ($v < (1 << 21)) { // 4 bytes |
| 947 | - $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 944 | + $output .= chr(240 + ($v >> 18)).chr(128 + (($v >> 12) & 63)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63)); |
|
| 948 | 945 | } else { |
| 949 | - $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte ' . $k); |
|
| 946 | + $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k); |
|
| 950 | 947 | return false; |
| 951 | 948 | } |
| 952 | 949 | } |
@@ -965,7 +962,7 @@ discard block |
||
| 965 | 962 | // Take array values and split output to 4 bytes per value |
| 966 | 963 | // The bit mask is 255, which reads &11111111 |
| 967 | 964 | foreach ($input as $v) { |
| 968 | - $output .= chr(($v >> 24) & 255) . chr(($v >> 16) & 255) . chr(($v >> 8) & 255) . chr($v & 255); |
|
| 965 | + $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255); |
|
| 969 | 966 | } |
| 970 | 967 | return $output; |
| 971 | 968 | } |
@@ -995,7 +992,7 @@ discard block |
||
| 995 | 992 | $out_len++; |
| 996 | 993 | $output[$out_len] = 0; |
| 997 | 994 | } |
| 998 | - $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) ); |
|
| 995 | + $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4))); |
|
| 999 | 996 | } |
| 1000 | 997 | return $output; |
| 1001 | 998 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string|null $source |
| 86 | 86 | * D'où provient l'auteur créé ? par défaut 'spip', mais peut être 'ldap' ou autre. |
| 87 | 87 | * @param array|null $set |
| 88 | - * @return int |
|
| 88 | + * @return boolean|string |
|
| 89 | 89 | * Identifiant de l'auteur créé |
| 90 | 90 | */ |
| 91 | 91 | function auteur_inserer($source = null, $set = null) { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param bool $force_update |
| 141 | 141 | * Permet de forcer la maj en base des champs fournis, sans passer par instancier. |
| 142 | 142 | * Utilise par auth/spip |
| 143 | - * @return string|null |
|
| 143 | + * @return string|false |
|
| 144 | 144 | * |
| 145 | 145 | * - Chaîne vide si aucune erreur, |
| 146 | 146 | * - Chaîne contenant un texte d'erreur sinon. |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * Couples (colonne => valeur) des données à instituer |
| 305 | 305 | * @param bool $force_webmestre |
| 306 | 306 | * Autoriser un auteur à passer webmestre (force l'autorisation) |
| 307 | - * @return bool|string |
|
| 307 | + * @return false|string |
|
| 308 | 308 | */ |
| 309 | 309 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 310 | 310 | if (!$id_auteur = intval($id_auteur)) { |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * @see auteur_inserer() |
| 450 | 450 | * |
| 451 | 451 | * @param string|null $source |
| 452 | - * @return int |
|
| 452 | + * @return boolean|string |
|
| 453 | 453 | */ |
| 454 | 454 | function insert_auteur($source = null) { |
| 455 | 455 | return auteur_inserer($source); |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | * |
| 464 | 464 | * @param int $id_auteur |
| 465 | 465 | * @param array|null $set |
| 466 | - * @return string|null |
|
| 466 | + * @return string|false |
|
| 467 | 467 | */ |
| 468 | 468 | function auteurs_set($id_auteur, $set = null) { |
| 469 | 469 | return auteur_modifier($id_auteur, $set); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | * @param int $id_auteur |
| 479 | 479 | * @param array $c |
| 480 | 480 | * @param bool $force_webmestre |
| 481 | - * @return bool|string |
|
| 481 | + * @return false|string |
|
| 482 | 482 | */ |
| 483 | 483 | function instituer_auteur($id_auteur, $c, $force_webmestre = false) { |
| 484 | 484 | return auteur_instituer($id_auteur, $c, $force_webmestre); |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * |
| 493 | 493 | * @param int $id_auteur |
| 494 | 494 | * @param array $c |
| 495 | - * @return string|null |
|
| 495 | + * @return string|false |
|
| 496 | 496 | */ |
| 497 | 497 | function revision_auteur($id_auteur, $c = false) { |
| 498 | 498 | return auteur_modifier($id_auteur, $c); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,43 +37,43 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - |
|
| 49 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 50 | - |
|
| 51 | - # cf. GROS HACK |
|
| 52 | - # recuperer l'eventuel logo charge avant la creation |
|
| 53 | - # ils ont un id = 0-id_auteur de la session |
|
| 54 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 55 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 56 | - foreach (array('on', 'off') as $type) { |
|
| 57 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 58 | - if ($logo = reset($logo)) { |
|
| 59 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // Enregistre l'envoi dans la BD |
|
| 67 | - $err = ""; |
|
| 68 | - if ($id_auteur > 0) { |
|
| 69 | - $err = auteur_modifier($id_auteur); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if ($err) { |
|
| 73 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return array($id_auteur, $err); |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + |
|
| 49 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 50 | + |
|
| 51 | + # cf. GROS HACK |
|
| 52 | + # recuperer l'eventuel logo charge avant la creation |
|
| 53 | + # ils ont un id = 0-id_auteur de la session |
|
| 54 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 55 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 56 | + foreach (array('on', 'off') as $type) { |
|
| 57 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 58 | + if ($logo = reset($logo)) { |
|
| 59 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // Enregistre l'envoi dans la BD |
|
| 67 | + $err = ""; |
|
| 68 | + if ($id_auteur > 0) { |
|
| 69 | + $err = auteur_modifier($id_auteur); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if ($err) { |
|
| 73 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return array($id_auteur, $err); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -90,39 +90,39 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | function auteur_inserer($source = null, $set = null) { |
| 92 | 92 | |
| 93 | - // Ce qu'on va demander comme modifications |
|
| 94 | - $champs = array(); |
|
| 95 | - $champs['source'] = $source ? $source : 'spip'; |
|
| 96 | - |
|
| 97 | - $champs['login'] = ''; |
|
| 98 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 99 | - $champs['webmestre'] = 'non'; |
|
| 100 | - |
|
| 101 | - if ($set) { |
|
| 102 | - $champs = array_merge($champs, $set); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Envoyer aux plugins |
|
| 106 | - $champs = pipeline('pre_insertion', |
|
| 107 | - array( |
|
| 108 | - 'args' => array( |
|
| 109 | - 'table' => 'spip_auteurs', |
|
| 110 | - ), |
|
| 111 | - 'data' => $champs |
|
| 112 | - ) |
|
| 113 | - ); |
|
| 114 | - $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 115 | - pipeline('post_insertion', |
|
| 116 | - array( |
|
| 117 | - 'args' => array( |
|
| 118 | - 'table' => 'spip_auteurs', |
|
| 119 | - 'id_objet' => $id_auteur |
|
| 120 | - ), |
|
| 121 | - 'data' => $champs |
|
| 122 | - ) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - return $id_auteur; |
|
| 93 | + // Ce qu'on va demander comme modifications |
|
| 94 | + $champs = array(); |
|
| 95 | + $champs['source'] = $source ? $source : 'spip'; |
|
| 96 | + |
|
| 97 | + $champs['login'] = ''; |
|
| 98 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 99 | + $champs['webmestre'] = 'non'; |
|
| 100 | + |
|
| 101 | + if ($set) { |
|
| 102 | + $champs = array_merge($champs, $set); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Envoyer aux plugins |
|
| 106 | + $champs = pipeline('pre_insertion', |
|
| 107 | + array( |
|
| 108 | + 'args' => array( |
|
| 109 | + 'table' => 'spip_auteurs', |
|
| 110 | + ), |
|
| 111 | + 'data' => $champs |
|
| 112 | + ) |
|
| 113 | + ); |
|
| 114 | + $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 115 | + pipeline('post_insertion', |
|
| 116 | + array( |
|
| 117 | + 'args' => array( |
|
| 118 | + 'table' => 'spip_auteurs', |
|
| 119 | + 'id_objet' => $id_auteur |
|
| 120 | + ), |
|
| 121 | + 'data' => $champs |
|
| 122 | + ) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + return $id_auteur; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,66 +147,66 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 149 | 149 | |
| 150 | - include_spip('inc/modifier'); |
|
| 151 | - include_spip('inc/filtres'); |
|
| 152 | - $c = collecter_requests( |
|
| 153 | - // white list |
|
| 154 | - objet_info('auteur', 'champs_editables'), |
|
| 155 | - // black list |
|
| 156 | - $force_update ? array() : array('webmestre', 'pass', 'login'), |
|
| 157 | - // donnees eventuellement fournies |
|
| 158 | - $set |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 162 | - array( |
|
| 163 | - 'data' => $set, |
|
| 164 | - 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 165 | - ), |
|
| 166 | - $c) |
|
| 167 | - ) { |
|
| 168 | - return $err; |
|
| 169 | - } |
|
| 170 | - $session = $c; |
|
| 171 | - |
|
| 172 | - $err = ''; |
|
| 173 | - if (!$force_update) { |
|
| 174 | - // Modification de statut, changement de rubrique ? |
|
| 175 | - $c = collecter_requests( |
|
| 176 | - // white list |
|
| 177 | - array( |
|
| 178 | - 'statut', |
|
| 179 | - 'new_login', |
|
| 180 | - 'new_pass', |
|
| 181 | - 'login', |
|
| 182 | - 'pass', |
|
| 183 | - 'webmestre', |
|
| 184 | - 'restreintes', |
|
| 185 | - 'id_parent' |
|
| 186 | - ), |
|
| 187 | - // black list |
|
| 188 | - array(), |
|
| 189 | - // donnees eventuellement fournies |
|
| 190 | - $set |
|
| 191 | - ); |
|
| 192 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 193 | - $c['login'] = $c['new_login']; |
|
| 194 | - } |
|
| 195 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 196 | - $c['pass'] = $c['new_pass']; |
|
| 197 | - } |
|
| 198 | - $err = auteur_instituer($id_auteur, $c); |
|
| 199 | - $session = array_merge($session, $c); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // .. mettre a jour les sessions de cet auteur |
|
| 203 | - include_spip('inc/session'); |
|
| 204 | - $session['id_auteur'] = $id_auteur; |
|
| 205 | - unset($session['new_login']); |
|
| 206 | - unset($session['new_pass']); |
|
| 207 | - actualiser_sessions($session); |
|
| 208 | - |
|
| 209 | - return $err; |
|
| 150 | + include_spip('inc/modifier'); |
|
| 151 | + include_spip('inc/filtres'); |
|
| 152 | + $c = collecter_requests( |
|
| 153 | + // white list |
|
| 154 | + objet_info('auteur', 'champs_editables'), |
|
| 155 | + // black list |
|
| 156 | + $force_update ? array() : array('webmestre', 'pass', 'login'), |
|
| 157 | + // donnees eventuellement fournies |
|
| 158 | + $set |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 162 | + array( |
|
| 163 | + 'data' => $set, |
|
| 164 | + 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 165 | + ), |
|
| 166 | + $c) |
|
| 167 | + ) { |
|
| 168 | + return $err; |
|
| 169 | + } |
|
| 170 | + $session = $c; |
|
| 171 | + |
|
| 172 | + $err = ''; |
|
| 173 | + if (!$force_update) { |
|
| 174 | + // Modification de statut, changement de rubrique ? |
|
| 175 | + $c = collecter_requests( |
|
| 176 | + // white list |
|
| 177 | + array( |
|
| 178 | + 'statut', |
|
| 179 | + 'new_login', |
|
| 180 | + 'new_pass', |
|
| 181 | + 'login', |
|
| 182 | + 'pass', |
|
| 183 | + 'webmestre', |
|
| 184 | + 'restreintes', |
|
| 185 | + 'id_parent' |
|
| 186 | + ), |
|
| 187 | + // black list |
|
| 188 | + array(), |
|
| 189 | + // donnees eventuellement fournies |
|
| 190 | + $set |
|
| 191 | + ); |
|
| 192 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 193 | + $c['login'] = $c['new_login']; |
|
| 194 | + } |
|
| 195 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 196 | + $c['pass'] = $c['new_pass']; |
|
| 197 | + } |
|
| 198 | + $err = auteur_instituer($id_auteur, $c); |
|
| 199 | + $session = array_merge($session, $c); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // .. mettre a jour les sessions de cet auteur |
|
| 203 | + include_spip('inc/session'); |
|
| 204 | + $session['id_auteur'] = $id_auteur; |
|
| 205 | + unset($session['new_login']); |
|
| 206 | + unset($session['new_pass']); |
|
| 207 | + actualiser_sessions($session); |
|
| 208 | + |
|
| 209 | + return $err; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 230 | - include_spip('action/editer_liens'); |
|
| 230 | + include_spip('action/editer_liens'); |
|
| 231 | 231 | |
| 232 | - return objet_associer(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 232 | + return objet_associer(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @return string |
| 245 | 245 | */ |
| 246 | 246 | function auteur_referent($id_auteur, $c) { |
| 247 | - return auteur_associer($id_auteur, $c); |
|
| 247 | + return auteur_associer($id_auteur, $c); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | 265 | function auteur_dissocier($id_auteur, $objets) { |
| 266 | - include_spip('action/editer_liens'); |
|
| 266 | + include_spip('action/editer_liens'); |
|
| 267 | 267 | |
| 268 | - return objet_dissocier(array('auteur' => $id_auteur), $objets); |
|
| 268 | + return objet_dissocier(array('auteur' => $id_auteur), $objets); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -286,9 +286,9 @@ discard block |
||
| 286 | 286 | * @return bool|int |
| 287 | 287 | */ |
| 288 | 288 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 289 | - include_spip('action/editer_liens'); |
|
| 289 | + include_spip('action/editer_liens'); |
|
| 290 | 290 | |
| 291 | - return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 291 | + return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
@@ -307,133 +307,133 @@ discard block |
||
| 307 | 307 | * @return bool|string |
| 308 | 308 | */ |
| 309 | 309 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 310 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 314 | - $champs = array(); |
|
| 315 | - |
|
| 316 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 317 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 318 | - $champs['login'] = $c['login']; |
|
| 319 | - } |
|
| 320 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 321 | - $champs['pass'] = $c['pass']; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 325 | - |
|
| 326 | - if (isset($c['statut']) |
|
| 327 | - and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut']))) |
|
| 328 | - ) { |
|
| 329 | - $statut = $champs['statut'] = $c['statut']; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // Restreindre avant de declarer l'auteur |
|
| 333 | - // (section critique sur les droits) |
|
| 334 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 335 | - if (is_array($c['restreintes'])) { |
|
| 336 | - $c['restreintes'][] = $c['id_parent']; |
|
| 337 | - } else { |
|
| 338 | - $c['restreintes'] = array($c['id_parent']); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if (isset($c['webmestre']) |
|
| 343 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?'))) |
|
| 344 | - ) { |
|
| 345 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 349 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 350 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // Envoyer aux plugins |
|
| 354 | - $champs = pipeline('pre_edition', |
|
| 355 | - array( |
|
| 356 | - 'args' => array( |
|
| 357 | - 'table' => 'spip_auteurs', |
|
| 358 | - 'id_objet' => $id_auteur, |
|
| 359 | - 'action' => 'instituer', |
|
| 360 | - 'statut_ancien' => $statut_ancien, |
|
| 361 | - ), |
|
| 362 | - 'data' => $champs |
|
| 363 | - ) |
|
| 364 | - ); |
|
| 365 | - |
|
| 366 | - if (isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 367 | - and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes'])) |
|
| 368 | - ) { |
|
| 369 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 370 | - $rubriques = array_unique($rubriques); |
|
| 371 | - $rubriques = array_diff($rubriques, array(0)); |
|
| 372 | - auteur_dissocier($id_auteur, array('rubrique' => '*')); |
|
| 373 | - auteur_associer($id_auteur, array('rubrique' => $rubriques)); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - $flag_ecrire_acces = false; |
|
| 377 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 378 | - // avant les autres ecritures en base |
|
| 379 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 380 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 381 | - include_spip('inc/auth'); |
|
| 382 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 383 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 384 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 388 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 389 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 390 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - unset($champs['login']); |
|
| 394 | - unset($champs['pass']); |
|
| 395 | - $flag_ecrire_acces = true; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if (!count($champs)) { |
|
| 399 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 400 | - } |
|
| 401 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 402 | - |
|
| 403 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 404 | - if ($flag_ecrire_acces |
|
| 405 | - or isset($champs['statut']) |
|
| 406 | - ) { |
|
| 407 | - include_spip('inc/acces'); |
|
| 408 | - ecrire_acces(); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // Invalider les caches |
|
| 412 | - include_spip('inc/invalideur'); |
|
| 413 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 414 | - |
|
| 415 | - // Pipeline |
|
| 416 | - pipeline('post_edition', |
|
| 417 | - array( |
|
| 418 | - 'args' => array( |
|
| 419 | - 'table' => 'spip_auteurs', |
|
| 420 | - 'id_objet' => $id_auteur, |
|
| 421 | - 'action' => 'instituer', |
|
| 422 | - 'statut_ancien' => $statut_ancien, |
|
| 423 | - ), |
|
| 424 | - 'data' => $champs |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - // Notifications |
|
| 430 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 431 | - $notifications('instituerauteur', $id_auteur, |
|
| 432 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 310 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 314 | + $champs = array(); |
|
| 315 | + |
|
| 316 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 317 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 318 | + $champs['login'] = $c['login']; |
|
| 319 | + } |
|
| 320 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 321 | + $champs['pass'] = $c['pass']; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 325 | + |
|
| 326 | + if (isset($c['statut']) |
|
| 327 | + and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut']))) |
|
| 328 | + ) { |
|
| 329 | + $statut = $champs['statut'] = $c['statut']; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // Restreindre avant de declarer l'auteur |
|
| 333 | + // (section critique sur les droits) |
|
| 334 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 335 | + if (is_array($c['restreintes'])) { |
|
| 336 | + $c['restreintes'][] = $c['id_parent']; |
|
| 337 | + } else { |
|
| 338 | + $c['restreintes'] = array($c['id_parent']); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if (isset($c['webmestre']) |
|
| 343 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?'))) |
|
| 344 | + ) { |
|
| 345 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 349 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 350 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // Envoyer aux plugins |
|
| 354 | + $champs = pipeline('pre_edition', |
|
| 355 | + array( |
|
| 356 | + 'args' => array( |
|
| 357 | + 'table' => 'spip_auteurs', |
|
| 358 | + 'id_objet' => $id_auteur, |
|
| 359 | + 'action' => 'instituer', |
|
| 360 | + 'statut_ancien' => $statut_ancien, |
|
| 361 | + ), |
|
| 362 | + 'data' => $champs |
|
| 363 | + ) |
|
| 364 | + ); |
|
| 365 | + |
|
| 366 | + if (isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 367 | + and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes'])) |
|
| 368 | + ) { |
|
| 369 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 370 | + $rubriques = array_unique($rubriques); |
|
| 371 | + $rubriques = array_diff($rubriques, array(0)); |
|
| 372 | + auteur_dissocier($id_auteur, array('rubrique' => '*')); |
|
| 373 | + auteur_associer($id_auteur, array('rubrique' => $rubriques)); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + $flag_ecrire_acces = false; |
|
| 377 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 378 | + // avant les autres ecritures en base |
|
| 379 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 380 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 381 | + include_spip('inc/auth'); |
|
| 382 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 383 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 384 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 388 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 389 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 390 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + unset($champs['login']); |
|
| 394 | + unset($champs['pass']); |
|
| 395 | + $flag_ecrire_acces = true; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if (!count($champs)) { |
|
| 399 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 400 | + } |
|
| 401 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 402 | + |
|
| 403 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 404 | + if ($flag_ecrire_acces |
|
| 405 | + or isset($champs['statut']) |
|
| 406 | + ) { |
|
| 407 | + include_spip('inc/acces'); |
|
| 408 | + ecrire_acces(); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // Invalider les caches |
|
| 412 | + include_spip('inc/invalideur'); |
|
| 413 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 414 | + |
|
| 415 | + // Pipeline |
|
| 416 | + pipeline('post_edition', |
|
| 417 | + array( |
|
| 418 | + 'args' => array( |
|
| 419 | + 'table' => 'spip_auteurs', |
|
| 420 | + 'id_objet' => $id_auteur, |
|
| 421 | + 'action' => 'instituer', |
|
| 422 | + 'statut_ancien' => $statut_ancien, |
|
| 423 | + ), |
|
| 424 | + 'data' => $champs |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + // Notifications |
|
| 430 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 431 | + $notifications('instituerauteur', $id_auteur, |
|
| 432 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 437 | 437 | |
| 438 | 438 | } |
| 439 | 439 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * @return int |
| 453 | 453 | */ |
| 454 | 454 | function insert_auteur($source = null) { |
| 455 | - return auteur_inserer($source); |
|
| 455 | + return auteur_inserer($source); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @return string|null |
| 467 | 467 | */ |
| 468 | 468 | function auteurs_set($id_auteur, $set = null) { |
| 469 | - return auteur_modifier($id_auteur, $set); |
|
| 469 | + return auteur_modifier($id_auteur, $set); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @return bool|string |
| 482 | 482 | */ |
| 483 | 483 | function instituer_auteur($id_auteur, $c, $force_webmestre = false) { |
| 484 | - return auteur_instituer($id_auteur, $c, $force_webmestre); |
|
| 484 | + return auteur_instituer($id_auteur, $c, $force_webmestre); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -495,5 +495,5 @@ discard block |
||
| 495 | 495 | * @return string|null |
| 496 | 496 | */ |
| 497 | 497 | function revision_auteur($id_auteur, $c = false) { |
| 498 | - return auteur_modifier($id_auteur, $c); |
|
| 498 | + return auteur_modifier($id_auteur, $c); |
|
| 499 | 499 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $champs['source'] = $source ? $source : 'spip'; |
| 96 | 96 | |
| 97 | 97 | $champs['login'] = ''; |
| 98 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 98 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 99 | 99 | $champs['webmestre'] = 'non'; |
| 100 | 100 | |
| 101 | 101 | if ($set) { |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $champs['pass'] = $c['pass']; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 324 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 325 | 325 | |
| 326 | 326 | if (isset($c['statut']) |
| 327 | 327 | and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut']))) |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | // commencer par traiter les cas particuliers des logins et pass |
| 378 | 378 | // avant les autres ecritures en base |
| 379 | 379 | if (isset($champs['login']) or isset($champs['pass'])) { |
| 380 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 380 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 381 | 381 | include_spip('inc/auth'); |
| 382 | 382 | if (isset($champs['login']) and strlen($champs['login'])) { |
| 383 | 383 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | if (isset($champs['pass']) and strlen($champs['pass'])) { |
| 388 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 388 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 389 | 389 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
| 390 | 390 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 391 | 391 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | if (!count($champs)) { |
| 399 | 399 | return implode(' ', array_map('_T', $erreurs)); |
| 400 | 400 | } |
| 401 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 401 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 402 | 402 | |
| 403 | 403 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 404 | 404 | if ($flag_ecrire_acces |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * Identifiant de la rubrique parente. |
| 74 | 74 | * 0 pour la racine. |
| 75 | 75 | * @param array|null $set |
| 76 | - * @return int |
|
| 76 | + * @return boolean|string |
|
| 77 | 77 | * Identifiant de la rubrique crée |
| 78 | 78 | */ |
| 79 | 79 | function rubrique_inserer($id_parent, $set = null) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * Identifiant de la rubrique modifiée |
| 121 | 121 | * @param array|null $set |
| 122 | 122 | * Tableau qu'on peut proposer en lieu et place de _request() |
| 123 | - * @return bool|string |
|
| 123 | + * @return string|false |
|
| 124 | 124 | * - false : Aucune modification, aucun champ n'est à modifier |
| 125 | 125 | * - chaîne vide : Vide si tout s'est bien passé |
| 126 | 126 | * - chaîne : Texte d'un message d'erreur |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @param int $id_parent |
| 278 | 278 | * Identifiant de la rubrique parente. |
| 279 | 279 | * 0 pour la racine. |
| 280 | - * @return int |
|
| 280 | + * @return boolean|string |
|
| 281 | 281 | * Identifiant de la rubrique crée |
| 282 | 282 | **/ |
| 283 | 283 | function insert_rubrique($id_parent) { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * Identifiant de la rubrique à instituer |
| 297 | 297 | * @param array|null $set |
| 298 | 298 | * Tableau qu'on peut proposer en lieu et place de _request() |
| 299 | - * @return bool|string |
|
| 299 | + * @return string|false |
|
| 300 | 300 | * - false : Aucune modification, aucun champ n'est à modifier |
| 301 | 301 | * - chaîne vide : Vide si tout s'est bien passé |
| 302 | 302 | * - chaîne : Texte d'un message d'erreur |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,31 +38,31 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | 55 | |
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', $id_rubrique, '&'); |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', $id_rubrique, '&'); |
|
| 60 | 60 | |
| 61 | - include_spip('inc/headers'); |
|
| 62 | - redirige_par_entete($redirect); |
|
| 63 | - } |
|
| 61 | + include_spip('inc/headers'); |
|
| 62 | + redirige_par_entete($redirect); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return array($id_rubrique, $err); |
|
| 65 | + return array($id_rubrique, $err); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * Identifiant de la rubrique crée |
| 78 | 78 | */ |
| 79 | 79 | function rubrique_inserer($id_parent, $set = null) { |
| 80 | - $champs = array( |
|
| 81 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 82 | - 'id_parent' => intval($id_parent), |
|
| 83 | - 'statut' => 'prepa' |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - if ($set) { |
|
| 87 | - $champs = array_merge($champs, $set); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Envoyer aux plugins |
|
| 91 | - $champs = pipeline('pre_insertion', |
|
| 92 | - array( |
|
| 93 | - 'args' => array( |
|
| 94 | - 'table' => 'spip_rubriques', |
|
| 95 | - ), |
|
| 96 | - 'data' => $champs |
|
| 97 | - ) |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - $id_rubrique = sql_insertq("spip_rubriques", $champs); |
|
| 101 | - pipeline('post_insertion', |
|
| 102 | - array( |
|
| 103 | - 'args' => array( |
|
| 104 | - 'table' => 'spip_rubriques', |
|
| 105 | - 'id_objet' => $id_rubrique |
|
| 106 | - ), |
|
| 107 | - 'data' => $champs |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - propager_les_secteurs(); |
|
| 111 | - calculer_langues_rubriques(); |
|
| 112 | - |
|
| 113 | - return $id_rubrique; |
|
| 80 | + $champs = array( |
|
| 81 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 82 | + 'id_parent' => intval($id_parent), |
|
| 83 | + 'statut' => 'prepa' |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + if ($set) { |
|
| 87 | + $champs = array_merge($champs, $set); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Envoyer aux plugins |
|
| 91 | + $champs = pipeline('pre_insertion', |
|
| 92 | + array( |
|
| 93 | + 'args' => array( |
|
| 94 | + 'table' => 'spip_rubriques', |
|
| 95 | + ), |
|
| 96 | + 'data' => $champs |
|
| 97 | + ) |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + $id_rubrique = sql_insertq("spip_rubriques", $champs); |
|
| 101 | + pipeline('post_insertion', |
|
| 102 | + array( |
|
| 103 | + 'args' => array( |
|
| 104 | + 'table' => 'spip_rubriques', |
|
| 105 | + 'id_objet' => $id_rubrique |
|
| 106 | + ), |
|
| 107 | + 'data' => $champs |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + propager_les_secteurs(); |
|
| 111 | + calculer_langues_rubriques(); |
|
| 112 | + |
|
| 113 | + return $id_rubrique; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -126,42 +126,42 @@ discard block |
||
| 126 | 126 | * - chaîne : Texte d'un message d'erreur |
| 127 | 127 | */ |
| 128 | 128 | function rubrique_modifier($id_rubrique, $set = null) { |
| 129 | - include_spip('inc/autoriser'); |
|
| 130 | - include_spip('inc/filtres'); |
|
| 131 | - |
|
| 132 | - include_spip('inc/modifier'); |
|
| 133 | - $c = collecter_requests( |
|
| 134 | - // white list |
|
| 135 | - objet_info('rubrique', 'champs_editables'), |
|
| 136 | - // black list |
|
| 137 | - array('id_parent', 'confirme_deplace'), |
|
| 138 | - // donnees eventuellement fournies |
|
| 139 | - $set |
|
| 140 | - ); |
|
| 141 | - |
|
| 142 | - if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
|
| 143 | - array( |
|
| 144 | - 'data' => $set, |
|
| 145 | - 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 146 | - ), |
|
| 147 | - $c) |
|
| 148 | - ) { |
|
| 149 | - return $err; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set); |
|
| 153 | - // Deplacer la rubrique |
|
| 154 | - if (isset($c['id_parent'])) { |
|
| 155 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // invalider les caches marques de cette rubrique |
|
| 159 | - include_spip('inc/invalideur'); |
|
| 160 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 161 | - // et celui de menu_rubriques |
|
| 162 | - effacer_meta("date_calcul_rubriques"); |
|
| 163 | - |
|
| 164 | - return $err; |
|
| 129 | + include_spip('inc/autoriser'); |
|
| 130 | + include_spip('inc/filtres'); |
|
| 131 | + |
|
| 132 | + include_spip('inc/modifier'); |
|
| 133 | + $c = collecter_requests( |
|
| 134 | + // white list |
|
| 135 | + objet_info('rubrique', 'champs_editables'), |
|
| 136 | + // black list |
|
| 137 | + array('id_parent', 'confirme_deplace'), |
|
| 138 | + // donnees eventuellement fournies |
|
| 139 | + $set |
|
| 140 | + ); |
|
| 141 | + |
|
| 142 | + if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
|
| 143 | + array( |
|
| 144 | + 'data' => $set, |
|
| 145 | + 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 146 | + ), |
|
| 147 | + $c) |
|
| 148 | + ) { |
|
| 149 | + return $err; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $c = collecter_requests(array('id_parent', 'confirme_deplace'), array(), $set); |
|
| 153 | + // Deplacer la rubrique |
|
| 154 | + if (isset($c['id_parent'])) { |
|
| 155 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // invalider les caches marques de cette rubrique |
|
| 159 | + include_spip('inc/invalideur'); |
|
| 160 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 161 | + // et celui de menu_rubriques |
|
| 162 | + effacer_meta("date_calcul_rubriques"); |
|
| 163 | + |
|
| 164 | + return $err; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -184,21 +184,21 @@ discard block |
||
| 184 | 184 | * false si la confirmation du déplacement n'est pas présente |
| 185 | 185 | */ |
| 186 | 186 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = array()) { |
| 187 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 187 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 191 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - if ($id_secteur = sql_getfetsel("id_secteur", |
|
| 196 | - "spip_rubriques", "id_rubrique=$id_parent") |
|
| 197 | - ) { |
|
| 198 | - sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique"); |
|
| 199 | - } |
|
| 195 | + if ($id_secteur = sql_getfetsel("id_secteur", |
|
| 196 | + "spip_rubriques", "id_rubrique=$id_parent") |
|
| 197 | + ) { |
|
| 198 | + sql_updateq("spip_breves", array("id_rubrique" => $id_secteur), "id_rubrique=$id_rubrique"); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return true; |
|
| 201 | + return true; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -220,51 +220,51 @@ discard block |
||
| 220 | 220 | * Chaîne : Texte du message d'erreur |
| 221 | 221 | */ |
| 222 | 222 | function rubrique_instituer($id_rubrique, $c) { |
| 223 | - // traitement de la rubrique parente |
|
| 224 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 225 | - // qu'on n'administre pas. |
|
| 226 | - |
|
| 227 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 228 | - $id_parent = intval($id_parent); |
|
| 229 | - $filles = calcul_branche_in($id_rubrique); |
|
| 230 | - if (strpos(",$id_parent,", ",$filles,") !== false) { |
|
| 231 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 232 | - } else { |
|
| 233 | - $s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 234 | - $old_parent = $s['id_parent']; |
|
| 235 | - |
|
| 236 | - if (!($id_parent != $old_parent |
|
| 237 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 238 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 239 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 240 | - ) |
|
| 241 | - ) { |
|
| 242 | - if ($s['statut'] != 'new') { |
|
| 243 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 244 | - } |
|
| 245 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 246 | - $statut_ancien = $s['statut']; |
|
| 247 | - sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique"); |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - propager_les_secteurs(); |
|
| 251 | - |
|
| 252 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 253 | - if ($statut_ancien == 'publie') { |
|
| 254 | - calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien); |
|
| 255 | - } |
|
| 256 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 257 | - // invalider le cache de leur menu |
|
| 258 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 259 | - effacer_meta("date_calcul_rubriques"); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - calculer_langues_rubriques(); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return ''; // pas d'erreur |
|
| 223 | + // traitement de la rubrique parente |
|
| 224 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 225 | + // qu'on n'administre pas. |
|
| 226 | + |
|
| 227 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 228 | + $id_parent = intval($id_parent); |
|
| 229 | + $filles = calcul_branche_in($id_rubrique); |
|
| 230 | + if (strpos(",$id_parent,", ",$filles,") !== false) { |
|
| 231 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 232 | + } else { |
|
| 233 | + $s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique"); |
|
| 234 | + $old_parent = $s['id_parent']; |
|
| 235 | + |
|
| 236 | + if (!($id_parent != $old_parent |
|
| 237 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 238 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 239 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 240 | + ) |
|
| 241 | + ) { |
|
| 242 | + if ($s['statut'] != 'new') { |
|
| 243 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 244 | + } |
|
| 245 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 246 | + $statut_ancien = $s['statut']; |
|
| 247 | + sql_updateq('spip_rubriques', array('id_parent' => $id_parent), "id_rubrique=$id_rubrique"); |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + propager_les_secteurs(); |
|
| 251 | + |
|
| 252 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 253 | + if ($statut_ancien == 'publie') { |
|
| 254 | + calculer_rubriques_if($old_parent, array('id_rubrique' => $id_parent), $statut_ancien); |
|
| 255 | + } |
|
| 256 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 257 | + // invalider le cache de leur menu |
|
| 258 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 259 | + effacer_meta("date_calcul_rubriques"); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + calculer_langues_rubriques(); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return ''; // pas d'erreur |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * Identifiant de la rubrique crée |
| 282 | 282 | **/ |
| 283 | 283 | function insert_rubrique($id_parent) { |
| 284 | - return rubrique_inserer($id_parent); |
|
| 284 | + return rubrique_inserer($id_parent); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * - chaîne : Texte d'un message d'erreur |
| 303 | 303 | **/ |
| 304 | 304 | function revisions_rubriques($id_rubrique, $set = null) { |
| 305 | - return rubrique_modifier($id_rubrique, $set); |
|
| 305 | + return rubrique_modifier($id_rubrique, $set); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -321,5 +321,5 @@ discard block |
||
| 321 | 321 | * Chaîne : Texte du message d'erreur |
| 322 | 322 | **/ |
| 323 | 323 | function instituer_rubrique($id_rubrique, $c) { |
| 324 | - return rubrique_instituer($id_rubrique, $c); |
|
| 324 | + return rubrique_instituer($id_rubrique, $c); |
|
| 325 | 325 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if ($err = objet_modifier_champs('rubrique', $id_rubrique, |
| 143 | 143 | array( |
| 144 | 144 | 'data' => $set, |
| 145 | - 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique') . " " . _T('info_numero_abbreviation') . $id_rubrique) |
|
| 145 | + 'nonvide' => array('titre' => _T('titre_nouvelle_rubrique')." "._T('info_numero_abbreviation').$id_rubrique) |
|
| 146 | 146 | ), |
| 147 | 147 | $c) |
| 148 | 148 | ) { |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | ) |
| 241 | 241 | ) { |
| 242 | 242 | if ($s['statut'] != 'new') { |
| 243 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 243 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']); |
|
| 244 | 244 | } |
| 245 | 245 | } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
| 246 | 246 | $statut_ancien = $s['statut']; |