@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -22,317 +22,317 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | class ValidateurXML |
| 24 | 24 | { |
| 25 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | - if ($p = strpos($name, ':')) { |
|
| 28 | - $name = substr($name, $p + 1); |
|
| 29 | - $p = isset($this->dtc->elements[$name]); |
|
| 30 | - } |
|
| 31 | - if (!$p) { |
|
| 32 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | - . _T('zxml_inconnu_balise')); |
|
| 34 | - |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - // controler les filles illegitimes, ca suffit |
|
| 39 | - $depth = $this->depth; |
|
| 40 | - $ouvrant = $this->ouvrant; |
|
| 41 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | - if (isset($ouvrant[$depth]) && preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 43 | - $pere = $r[1]; |
|
| 44 | - #spip_log("pere $pere"); |
|
| 45 | - if (isset($this->dtc->elements[$pere])) { |
|
| 46 | - $fils = $this->dtc->elements[$pere]; |
|
| 47 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 48 | - if (!($p = @in_array($name, $fils)) && ($p = strpos($name, ':'))) { |
|
| 49 | - $p = substr($name, $p + 1); |
|
| 50 | - $p = @in_array($p, $fils); |
|
| 51 | - } |
|
| 52 | - if (!$p) { |
|
| 53 | - $bons_peres = @implode('</b>, <b>', $this->dtc->peres[$name]); |
|
| 54 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 55 | - . _T('zxml_non_fils') |
|
| 56 | - . ' <b>' |
|
| 57 | - . $pere |
|
| 58 | - . '</b>' |
|
| 59 | - . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 60 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 61 | - $frat = substr($depth, 2); |
|
| 62 | - if (!isset($this->fratrie[$frat])) { |
|
| 63 | - $this->fratrie[$frat] = ''; |
|
| 64 | - } |
|
| 65 | - $this->fratrie[$frat] .= "$name "; |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 70 | - if ($this->dtc->regles[$name] && $this->dtc->regles[$name][0] == '/') { |
|
| 71 | - $this->fratrie[$depth] = ''; |
|
| 72 | - } |
|
| 73 | - if (isset($this->dtc->attributs[$name])) { |
|
| 74 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 75 | - if ($v[1] == '#REQUIRED' && !isset($attrs[$n])) { |
|
| 76 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 77 | - . ' : ' |
|
| 78 | - . _T('zxml_obligatoire_attribut') |
|
| 79 | - . " <b>$name</b>"); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 86 | - // Si la balise est inconnue, eviter d'insister |
|
| 87 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $a = $this->dtc->attributs[$bal]; |
|
| 92 | - if (!isset($a[$name])) { |
|
| 93 | - $bons = implode(', ', array_keys($a)); |
|
| 94 | - if ($bons) { |
|
| 95 | - $bons = " title=' " . |
|
| 96 | - _T('zxml_connus_attributs') . |
|
| 97 | - ' : ' . |
|
| 98 | - $bons . |
|
| 99 | - "'"; |
|
| 100 | - } |
|
| 101 | - $bons .= " style='font-weight: bold'"; |
|
| 102 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 103 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 104 | - . " <a$bons>$bal</a> (" |
|
| 105 | - . _T('zxml_survoler') |
|
| 106 | - . ')'); |
|
| 107 | - } else { |
|
| 108 | - $type = $a[$name][0]; |
|
| 109 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 110 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 111 | - } else { |
|
| 112 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 113 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 121 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 125 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 129 | - if (isset($this->ids[$val])) { |
|
| 130 | - [$l, $c] = $this->ids[$val]; |
|
| 131 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 132 | - . _T('zxml_valeur_attribut') |
|
| 133 | - . " <b>$name</b> " |
|
| 134 | - . _T('zxml_de') |
|
| 135 | - . " <b>$bal</b> " |
|
| 136 | - . _T('zxml_vu') |
|
| 137 | - . " (L$l,C$c)"); |
|
| 138 | - } else { |
|
| 139 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 140 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 145 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 149 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 153 | - if (!preg_match($motif, $val)) { |
|
| 154 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 155 | - . _T('zxml_valeur_attribut') |
|
| 156 | - . " <b>$name</b> " |
|
| 157 | - . _T('zxml_de') |
|
| 158 | - . " <b>$bal</b> " |
|
| 159 | - . _T('zxml_non_conforme') |
|
| 160 | - . '</p><p>' |
|
| 161 | - . '<b>' . $motif . '</b>'); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - public function valider_idref($nom, $ligne, $col) { |
|
| 166 | - if (!isset($this->ids[$nom])) { |
|
| 167 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function valider_passe2() { |
|
| 172 | - if (!$this->err) { |
|
| 173 | - foreach ($this->idrefs as $idref) { |
|
| 174 | - [$nom, $ligne, $col] = $idref; |
|
| 175 | - $this->valider_idref($nom, $ligne, $col); |
|
| 176 | - } |
|
| 177 | - foreach ($this->idrefss as $idref) { |
|
| 178 | - [$noms, $ligne, $col] = $idref; |
|
| 179 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 180 | - $this->valider_idref($nom, $ligne, $col); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 187 | - if ($this->dtc->elements) { |
|
| 188 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ($f = $this->process['debut']) { |
|
| 192 | - $f($this, $name, $attrs); |
|
| 193 | - } |
|
| 194 | - $depth = $this->depth; |
|
| 195 | - $this->debuts[$depth] = strlen($this->res); |
|
| 196 | - foreach ($attrs as $k => $v) { |
|
| 197 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function finElement($phraseur, $name) { |
|
| 202 | - $depth = $this->depth; |
|
| 203 | - $contenu = $this->contenu; |
|
| 204 | - |
|
| 205 | - $n = strlen($this->res); |
|
| 206 | - $c = strlen(trim($contenu[$depth])); |
|
| 207 | - $k = $this->debuts[$depth]; |
|
| 208 | - |
|
| 209 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 210 | - $vide = ($regle == 'EMPTY'); |
|
| 211 | - // controler que les balises devant etre vides le sont |
|
| 212 | - if ($vide) { |
|
| 213 | - if ($n != $k + $c) { |
|
| 214 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 215 | - } |
|
| 216 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 217 | - } elseif ($regle && $regle != '*') { |
|
| 218 | - if ($regle == '+') { |
|
| 219 | - // iteration de disjonction non vide: 1 balise au - |
|
| 220 | - if ($n == $k) { |
|
| 221 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 222 | - . _T('zxml_vide_balise')); |
|
| 223 | - } |
|
| 224 | - } else { |
|
| 225 | - $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 226 | - if (is_null($f) || !preg_match($regle, $f)) { |
|
| 227 | - coordonnees_erreur( |
|
| 228 | - $this, |
|
| 229 | - " <p>\n<b>$name</b> " |
|
| 230 | - . _T('zxml_succession_fils_incorrecte') |
|
| 231 | - . ' : <b>' |
|
| 232 | - . $f |
|
| 233 | - . '</b>' |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - if ($f = $this->process['fin']) { |
|
| 239 | - $f($this, $name, $vide); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function textElement($phraseur, $data) { |
|
| 244 | - if (trim($data)) { |
|
| 245 | - $d = $this->depth; |
|
| 246 | - $d = $this->ouvrant[$d]; |
|
| 247 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 248 | - if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
|
| 249 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 250 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - if ($f = $this->process['text']) { |
|
| 254 | - $f($this, $data); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - public function piElement($phraseur, $target, $data) { |
|
| 259 | - if ($f = $this->process['pi']) { |
|
| 260 | - $f($this, $target, $data); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // Denonciation des entitees XML inconnues |
|
| 265 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 266 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 267 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 268 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 269 | - // le source de la page laisse legitimement supposer. |
|
| 270 | - |
|
| 271 | - public function defaultElement($phraseur, $data) { |
|
| 272 | - if ( |
|
| 273 | - !preg_match('/^<!--/', $data) |
|
| 274 | - && preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER) |
|
| 275 | - ) { |
|
| 276 | - foreach ($r as $m) { |
|
| 277 | - [$t, $e] = $m; |
|
| 278 | - if (!isset($this->dtc->entites[$e])) { |
|
| 279 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 280 | - . _T('zxml_inconnu_entite') |
|
| 281 | - . ' '); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - if (isset($this->process['default']) && ($f = $this->process['default'])) { |
|
| 286 | - $f($this, $data); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - public function phraserTout($phraseur, $data) { |
|
| 291 | - xml_parsestring($this, $data); |
|
| 292 | - |
|
| 293 | - if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 294 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 295 | - } else { |
|
| 296 | - $this->valider_passe2(); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Constructeur |
|
| 302 | - * |
|
| 303 | - * @param array $process ? |
|
| 304 | - **/ |
|
| 305 | - public function __construct($process = []) { |
|
| 306 | - if (is_array($process)) { |
|
| 307 | - $this->process = $process; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - public $ids = []; |
|
| 312 | - public $idrefs = []; |
|
| 313 | - public $idrefss = []; |
|
| 314 | - public $debuts = []; |
|
| 315 | - public $fratrie = []; |
|
| 316 | - |
|
| 317 | - public $dtc = null; |
|
| 318 | - public $sax = null; |
|
| 319 | - public $depth = ''; |
|
| 320 | - public $entete = ''; |
|
| 321 | - public $page = ''; |
|
| 322 | - public $res = ''; |
|
| 323 | - public array $err = []; |
|
| 324 | - public array $contenu = []; |
|
| 325 | - public array $versions = []; |
|
| 326 | - |
|
| 327 | - public array $ouvrant = []; |
|
| 328 | - public array $reperes = []; |
|
| 329 | - public array $process = [ |
|
| 330 | - 'debut' => 'xml_debutElement', |
|
| 331 | - 'fin' => 'xml_finElement', |
|
| 332 | - 'text' => 'xml_textElement', |
|
| 333 | - 'pi' => 'xml_piElement', |
|
| 334 | - 'default' => 'xml_defaultElement' |
|
| 335 | - ]; |
|
| 25 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | + if ($p = strpos($name, ':')) { |
|
| 28 | + $name = substr($name, $p + 1); |
|
| 29 | + $p = isset($this->dtc->elements[$name]); |
|
| 30 | + } |
|
| 31 | + if (!$p) { |
|
| 32 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | + . _T('zxml_inconnu_balise')); |
|
| 34 | + |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + // controler les filles illegitimes, ca suffit |
|
| 39 | + $depth = $this->depth; |
|
| 40 | + $ouvrant = $this->ouvrant; |
|
| 41 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | + if (isset($ouvrant[$depth]) && preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 43 | + $pere = $r[1]; |
|
| 44 | + #spip_log("pere $pere"); |
|
| 45 | + if (isset($this->dtc->elements[$pere])) { |
|
| 46 | + $fils = $this->dtc->elements[$pere]; |
|
| 47 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 48 | + if (!($p = @in_array($name, $fils)) && ($p = strpos($name, ':'))) { |
|
| 49 | + $p = substr($name, $p + 1); |
|
| 50 | + $p = @in_array($p, $fils); |
|
| 51 | + } |
|
| 52 | + if (!$p) { |
|
| 53 | + $bons_peres = @implode('</b>, <b>', $this->dtc->peres[$name]); |
|
| 54 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 55 | + . _T('zxml_non_fils') |
|
| 56 | + . ' <b>' |
|
| 57 | + . $pere |
|
| 58 | + . '</b>' |
|
| 59 | + . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 60 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 61 | + $frat = substr($depth, 2); |
|
| 62 | + if (!isset($this->fratrie[$frat])) { |
|
| 63 | + $this->fratrie[$frat] = ''; |
|
| 64 | + } |
|
| 65 | + $this->fratrie[$frat] .= "$name "; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 70 | + if ($this->dtc->regles[$name] && $this->dtc->regles[$name][0] == '/') { |
|
| 71 | + $this->fratrie[$depth] = ''; |
|
| 72 | + } |
|
| 73 | + if (isset($this->dtc->attributs[$name])) { |
|
| 74 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 75 | + if ($v[1] == '#REQUIRED' && !isset($attrs[$n])) { |
|
| 76 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 77 | + . ' : ' |
|
| 78 | + . _T('zxml_obligatoire_attribut') |
|
| 79 | + . " <b>$name</b>"); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 86 | + // Si la balise est inconnue, eviter d'insister |
|
| 87 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $a = $this->dtc->attributs[$bal]; |
|
| 92 | + if (!isset($a[$name])) { |
|
| 93 | + $bons = implode(', ', array_keys($a)); |
|
| 94 | + if ($bons) { |
|
| 95 | + $bons = " title=' " . |
|
| 96 | + _T('zxml_connus_attributs') . |
|
| 97 | + ' : ' . |
|
| 98 | + $bons . |
|
| 99 | + "'"; |
|
| 100 | + } |
|
| 101 | + $bons .= " style='font-weight: bold'"; |
|
| 102 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 103 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 104 | + . " <a$bons>$bal</a> (" |
|
| 105 | + . _T('zxml_survoler') |
|
| 106 | + . ')'); |
|
| 107 | + } else { |
|
| 108 | + $type = $a[$name][0]; |
|
| 109 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 110 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 111 | + } else { |
|
| 112 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 113 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 121 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 125 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 129 | + if (isset($this->ids[$val])) { |
|
| 130 | + [$l, $c] = $this->ids[$val]; |
|
| 131 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 132 | + . _T('zxml_valeur_attribut') |
|
| 133 | + . " <b>$name</b> " |
|
| 134 | + . _T('zxml_de') |
|
| 135 | + . " <b>$bal</b> " |
|
| 136 | + . _T('zxml_vu') |
|
| 137 | + . " (L$l,C$c)"); |
|
| 138 | + } else { |
|
| 139 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 140 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 145 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 149 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 153 | + if (!preg_match($motif, $val)) { |
|
| 154 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 155 | + . _T('zxml_valeur_attribut') |
|
| 156 | + . " <b>$name</b> " |
|
| 157 | + . _T('zxml_de') |
|
| 158 | + . " <b>$bal</b> " |
|
| 159 | + . _T('zxml_non_conforme') |
|
| 160 | + . '</p><p>' |
|
| 161 | + . '<b>' . $motif . '</b>'); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + public function valider_idref($nom, $ligne, $col) { |
|
| 166 | + if (!isset($this->ids[$nom])) { |
|
| 167 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function valider_passe2() { |
|
| 172 | + if (!$this->err) { |
|
| 173 | + foreach ($this->idrefs as $idref) { |
|
| 174 | + [$nom, $ligne, $col] = $idref; |
|
| 175 | + $this->valider_idref($nom, $ligne, $col); |
|
| 176 | + } |
|
| 177 | + foreach ($this->idrefss as $idref) { |
|
| 178 | + [$noms, $ligne, $col] = $idref; |
|
| 179 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 180 | + $this->valider_idref($nom, $ligne, $col); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 187 | + if ($this->dtc->elements) { |
|
| 188 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ($f = $this->process['debut']) { |
|
| 192 | + $f($this, $name, $attrs); |
|
| 193 | + } |
|
| 194 | + $depth = $this->depth; |
|
| 195 | + $this->debuts[$depth] = strlen($this->res); |
|
| 196 | + foreach ($attrs as $k => $v) { |
|
| 197 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function finElement($phraseur, $name) { |
|
| 202 | + $depth = $this->depth; |
|
| 203 | + $contenu = $this->contenu; |
|
| 204 | + |
|
| 205 | + $n = strlen($this->res); |
|
| 206 | + $c = strlen(trim($contenu[$depth])); |
|
| 207 | + $k = $this->debuts[$depth]; |
|
| 208 | + |
|
| 209 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 210 | + $vide = ($regle == 'EMPTY'); |
|
| 211 | + // controler que les balises devant etre vides le sont |
|
| 212 | + if ($vide) { |
|
| 213 | + if ($n != $k + $c) { |
|
| 214 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 215 | + } |
|
| 216 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 217 | + } elseif ($regle && $regle != '*') { |
|
| 218 | + if ($regle == '+') { |
|
| 219 | + // iteration de disjonction non vide: 1 balise au - |
|
| 220 | + if ($n == $k) { |
|
| 221 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 222 | + . _T('zxml_vide_balise')); |
|
| 223 | + } |
|
| 224 | + } else { |
|
| 225 | + $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 226 | + if (is_null($f) || !preg_match($regle, $f)) { |
|
| 227 | + coordonnees_erreur( |
|
| 228 | + $this, |
|
| 229 | + " <p>\n<b>$name</b> " |
|
| 230 | + . _T('zxml_succession_fils_incorrecte') |
|
| 231 | + . ' : <b>' |
|
| 232 | + . $f |
|
| 233 | + . '</b>' |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + if ($f = $this->process['fin']) { |
|
| 239 | + $f($this, $name, $vide); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function textElement($phraseur, $data) { |
|
| 244 | + if (trim($data)) { |
|
| 245 | + $d = $this->depth; |
|
| 246 | + $d = $this->ouvrant[$d]; |
|
| 247 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 248 | + if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
|
| 249 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 250 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + if ($f = $this->process['text']) { |
|
| 254 | + $f($this, $data); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + public function piElement($phraseur, $target, $data) { |
|
| 259 | + if ($f = $this->process['pi']) { |
|
| 260 | + $f($this, $target, $data); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // Denonciation des entitees XML inconnues |
|
| 265 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 266 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 267 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 268 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 269 | + // le source de la page laisse legitimement supposer. |
|
| 270 | + |
|
| 271 | + public function defaultElement($phraseur, $data) { |
|
| 272 | + if ( |
|
| 273 | + !preg_match('/^<!--/', $data) |
|
| 274 | + && preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER) |
|
| 275 | + ) { |
|
| 276 | + foreach ($r as $m) { |
|
| 277 | + [$t, $e] = $m; |
|
| 278 | + if (!isset($this->dtc->entites[$e])) { |
|
| 279 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 280 | + . _T('zxml_inconnu_entite') |
|
| 281 | + . ' '); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + if (isset($this->process['default']) && ($f = $this->process['default'])) { |
|
| 286 | + $f($this, $data); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + public function phraserTout($phraseur, $data) { |
|
| 291 | + xml_parsestring($this, $data); |
|
| 292 | + |
|
| 293 | + if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 294 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 295 | + } else { |
|
| 296 | + $this->valider_passe2(); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Constructeur |
|
| 302 | + * |
|
| 303 | + * @param array $process ? |
|
| 304 | + **/ |
|
| 305 | + public function __construct($process = []) { |
|
| 306 | + if (is_array($process)) { |
|
| 307 | + $this->process = $process; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + public $ids = []; |
|
| 312 | + public $idrefs = []; |
|
| 313 | + public $idrefss = []; |
|
| 314 | + public $debuts = []; |
|
| 315 | + public $fratrie = []; |
|
| 316 | + |
|
| 317 | + public $dtc = null; |
|
| 318 | + public $sax = null; |
|
| 319 | + public $depth = ''; |
|
| 320 | + public $entete = ''; |
|
| 321 | + public $page = ''; |
|
| 322 | + public $res = ''; |
|
| 323 | + public array $err = []; |
|
| 324 | + public array $contenu = []; |
|
| 325 | + public array $versions = []; |
|
| 326 | + |
|
| 327 | + public array $ouvrant = []; |
|
| 328 | + public array $reperes = []; |
|
| 329 | + public array $process = [ |
|
| 330 | + 'debut' => 'xml_debutElement', |
|
| 331 | + 'fin' => 'xml_finElement', |
|
| 332 | + 'text' => 'xml_textElement', |
|
| 333 | + 'pi' => 'xml_piElement', |
|
| 334 | + 'default' => 'xml_defaultElement' |
|
| 335 | + ]; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | **/ |
| 344 | 344 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 345 | - $f = new ValidateurXML($process); |
|
| 346 | - $sax = charger_fonction('sax', 'xml'); |
|
| 345 | + $f = new ValidateurXML($process); |
|
| 346 | + $sax = charger_fonction('sax', 'xml'); |
|
| 347 | 347 | |
| 348 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 348 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 349 | 349 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | . ' <b>' |
| 57 | 57 | . $pere |
| 58 | 58 | . '</b>' |
| 59 | - . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 59 | + . ($bons_peres ? '<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>' : '')); |
|
| 60 | 60 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 61 | 61 | $frat = substr($depth, 2); |
| 62 | 62 | if (!isset($this->fratrie[$frat])) { |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | if (!isset($a[$name])) { |
| 93 | 93 | $bons = implode(', ', array_keys($a)); |
| 94 | 94 | if ($bons) { |
| 95 | - $bons = " title=' " . |
|
| 96 | - _T('zxml_connus_attributs') . |
|
| 97 | - ' : ' . |
|
| 98 | - $bons . |
|
| 95 | + $bons = " title=' ". |
|
| 96 | + _T('zxml_connus_attributs'). |
|
| 97 | + ' : '. |
|
| 98 | + $bons. |
|
| 99 | 99 | "'"; |
| 100 | 100 | } |
| 101 | 101 | $bons .= " style='font-weight: bold'"; |
| 102 | 102 | coordonnees_erreur($this, " <b>$name</b> " |
| 103 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 103 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 104 | 104 | . " <a$bons>$bal</a> (" |
| 105 | 105 | . _T('zxml_survoler') |
| 106 | 106 | . ')'); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if (!preg_match('/^\w+$/', $type)) { |
| 110 | 110 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 111 | 111 | } else { |
| 112 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 112 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 113 | 113 | $this->$f($phraseur, $name, $val, $bal); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | . " <b>$bal</b> " |
| 159 | 159 | . _T('zxml_non_conforme') |
| 160 | 160 | . '</p><p>' |
| 161 | - . '<b>' . $motif . '</b>'); |
|
| 161 | + . '<b>'.$motif.'</b>'); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function valider_idref($nom, $ligne, $col) { |
| 166 | 166 | if (!isset($this->ids[$nom])) { |
| 167 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 167 | + $this->err[] = [" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | // controler que les balises devant etre vides le sont |
| 212 | 212 | if ($vide) { |
| 213 | 213 | if ($n != $k + $c) { |
| 214 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 214 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 215 | 215 | } |
| 216 | 216 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 217 | 217 | } elseif ($regle && $regle != '*') { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $d = $this->ouvrant[$d]; |
| 247 | 247 | preg_match('/^\s*(\S+)/', $d, $m); |
| 248 | 248 | if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
| 249 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 249 | + coordonnees_erreur($this, ' <p><b>'.$m[1].'</b> ' |
|
| 250 | 250 | . _T('zxml_nonvide_balise')); // message a affiner |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | public function phraserTout($phraseur, $data) { |
| 291 | 291 | xml_parsestring($this, $data); |
| 292 | 292 | |
| 293 | - if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 293 | + if (!$this->dtc || preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) { |
|
| 294 | 294 | $this->err[] = ['DOCTYPE ?', 0, 0]; |
| 295 | 295 | } else { |
| 296 | 296 | $this->valider_passe2(); |
@@ -10,58 +10,58 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('xml/interfaces'); |
| 17 | 17 | |
| 18 | 18 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 19 | - $r = null; |
|
| 20 | - static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 21 | - |
|
| 22 | - if (isset($dtd[$grammaire])) { |
|
| 23 | - return $dtd[$grammaire]; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - if ($avail == 'SYSTEM') { |
|
| 27 | - $grammaire = find_in_path($grammaire); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 31 | - |
|
| 32 | - if (lire_fichier($file, $r)) { |
|
| 33 | - if (!$grammaire) { |
|
| 34 | - return []; |
|
| 35 | - } |
|
| 36 | - if ($avail == 'SYSTEM' && filemtime($file) < filemtime($grammaire)) { |
|
| 37 | - $r = false; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($r) { |
|
| 42 | - $dtc = unserialize($r); |
|
| 43 | - } else { |
|
| 44 | - spip_timer('dtd'); |
|
| 45 | - $dtc = new DTC(); |
|
| 46 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 47 | - // Retourner vide en cas d'echec |
|
| 48 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 49 | - $dtc = []; |
|
| 50 | - } else { |
|
| 51 | - // tri final pour presenter les suggestions de corrections |
|
| 52 | - foreach ($dtc->peres as $k => $v) { |
|
| 53 | - asort($v); |
|
| 54 | - $dtc->peres[$k] = $v; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 58 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 59 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - $dtd[$grammaire] = $dtc; |
|
| 63 | - |
|
| 64 | - return $dtc; |
|
| 19 | + $r = null; |
|
| 20 | + static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 21 | + |
|
| 22 | + if (isset($dtd[$grammaire])) { |
|
| 23 | + return $dtd[$grammaire]; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + if ($avail == 'SYSTEM') { |
|
| 27 | + $grammaire = find_in_path($grammaire); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 31 | + |
|
| 32 | + if (lire_fichier($file, $r)) { |
|
| 33 | + if (!$grammaire) { |
|
| 34 | + return []; |
|
| 35 | + } |
|
| 36 | + if ($avail == 'SYSTEM' && filemtime($file) < filemtime($grammaire)) { |
|
| 37 | + $r = false; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($r) { |
|
| 42 | + $dtc = unserialize($r); |
|
| 43 | + } else { |
|
| 44 | + spip_timer('dtd'); |
|
| 45 | + $dtc = new DTC(); |
|
| 46 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 47 | + // Retourner vide en cas d'echec |
|
| 48 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 49 | + $dtc = []; |
|
| 50 | + } else { |
|
| 51 | + // tri final pour presenter les suggestions de corrections |
|
| 52 | + foreach ($dtc->peres as $k => $v) { |
|
| 53 | + asort($v); |
|
| 54 | + $dtc->peres[$k] = $v; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 58 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 59 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + $dtd[$grammaire] = $dtc; |
|
| 63 | + |
|
| 64 | + return $dtc; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -73,137 +73,137 @@ discard block |
||
| 73 | 73 | // et parentheser le tout pour que | + * ? s'applique dessus. |
| 74 | 74 | |
| 75 | 75 | function compilerRegle($val) { |
| 76 | - return str_replace( |
|
| 77 | - '()', |
|
| 78 | - '', |
|
| 79 | - preg_replace( |
|
| 80 | - '/\s*,\s*/', |
|
| 81 | - '', |
|
| 82 | - preg_replace( |
|
| 83 | - '/(\w+)\s*/', |
|
| 84 | - '(?:\1 )', |
|
| 85 | - preg_replace( |
|
| 86 | - '/\s*\)/', |
|
| 87 | - ')', |
|
| 88 | - preg_replace( |
|
| 89 | - '/\s*([(+*|?])\s*/', |
|
| 90 | - '\1', |
|
| 91 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 92 | - ) |
|
| 93 | - ) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ); |
|
| 76 | + return str_replace( |
|
| 77 | + '()', |
|
| 78 | + '', |
|
| 79 | + preg_replace( |
|
| 80 | + '/\s*,\s*/', |
|
| 81 | + '', |
|
| 82 | + preg_replace( |
|
| 83 | + '/(\w+)\s*/', |
|
| 84 | + '(?:\1 )', |
|
| 85 | + preg_replace( |
|
| 86 | + '/\s*\)/', |
|
| 87 | + ')', |
|
| 88 | + preg_replace( |
|
| 89 | + '/\s*([(+*|?])\s*/', |
|
| 90 | + '\1', |
|
| 91 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 92 | + ) |
|
| 93 | + ) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | function analyser_dtd($loc, $avail, &$dtc) { |
| 101 | - // creer le repertoire de cache si ce n'est fait |
|
| 102 | - // (utile aussi pour le resultat de la compil) |
|
| 103 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 104 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 105 | - if ($avail == 'SYSTEM') { |
|
| 106 | - $file = $loc; |
|
| 107 | - if (_DIR_RACINE && str_starts_with($file, _DIR_RACINE)) { |
|
| 108 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 109 | - } |
|
| 110 | - $file = find_in_path($file); |
|
| 111 | - } else { |
|
| 112 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $dtd = ''; |
|
| 116 | - if (@is_readable($file)) { |
|
| 117 | - lire_fichier($file, $dtd); |
|
| 118 | - } else { |
|
| 119 | - if ($avail == 'PUBLIC') { |
|
| 120 | - include_spip('inc/distant'); |
|
| 121 | - $dtd = recuperer_url($loc); |
|
| 122 | - $dtd = trim($dtd['page'] ?? ''); |
|
| 123 | - if ($dtd) { |
|
| 124 | - ecrire_fichier($file, $dtd, true); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $dtd = ltrim($dtd); |
|
| 130 | - if (!$dtd) { |
|
| 131 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 132 | - |
|
| 133 | - return false; |
|
| 134 | - } else { |
|
| 135 | - spip_log("analyse de la DTD $loc "); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - while ($dtd) { |
|
| 139 | - if ($dtd[0] != '<') { |
|
| 140 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 141 | - } elseif ($dtd[1] != '!') { |
|
| 142 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 143 | - } elseif ($dtd[2] == '[') { |
|
| 144 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 145 | - } else { |
|
| 146 | - $r = match ($dtd[3]) { |
|
| 147 | - '%' => analyser_dtd_data($dtd, $dtc, $loc), |
|
| 148 | - 'T' => analyser_dtd_attlist($dtd, $dtc, $loc), |
|
| 149 | - 'L' => analyser_dtd_element($dtd, $dtc, $loc), |
|
| 150 | - 'N' => analyser_dtd_entity($dtd, $dtc, $loc), |
|
| 151 | - 'O' => analyser_dtd_notation($dtd, $dtc, $loc), |
|
| 152 | - '-' => analyser_dtd_comment($dtd, $dtc, $loc), |
|
| 153 | - default => -1, |
|
| 154 | - }; |
|
| 155 | - } |
|
| 156 | - if (!is_string($r)) { |
|
| 157 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 158 | - |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 161 | - $dtd = $r; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return true; |
|
| 101 | + // creer le repertoire de cache si ce n'est fait |
|
| 102 | + // (utile aussi pour le resultat de la compil) |
|
| 103 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 104 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 105 | + if ($avail == 'SYSTEM') { |
|
| 106 | + $file = $loc; |
|
| 107 | + if (_DIR_RACINE && str_starts_with($file, _DIR_RACINE)) { |
|
| 108 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 109 | + } |
|
| 110 | + $file = find_in_path($file); |
|
| 111 | + } else { |
|
| 112 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $dtd = ''; |
|
| 116 | + if (@is_readable($file)) { |
|
| 117 | + lire_fichier($file, $dtd); |
|
| 118 | + } else { |
|
| 119 | + if ($avail == 'PUBLIC') { |
|
| 120 | + include_spip('inc/distant'); |
|
| 121 | + $dtd = recuperer_url($loc); |
|
| 122 | + $dtd = trim($dtd['page'] ?? ''); |
|
| 123 | + if ($dtd) { |
|
| 124 | + ecrire_fichier($file, $dtd, true); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $dtd = ltrim($dtd); |
|
| 130 | + if (!$dtd) { |
|
| 131 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 132 | + |
|
| 133 | + return false; |
|
| 134 | + } else { |
|
| 135 | + spip_log("analyse de la DTD $loc "); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + while ($dtd) { |
|
| 139 | + if ($dtd[0] != '<') { |
|
| 140 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 141 | + } elseif ($dtd[1] != '!') { |
|
| 142 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 143 | + } elseif ($dtd[2] == '[') { |
|
| 144 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 145 | + } else { |
|
| 146 | + $r = match ($dtd[3]) { |
|
| 147 | + '%' => analyser_dtd_data($dtd, $dtc, $loc), |
|
| 148 | + 'T' => analyser_dtd_attlist($dtd, $dtc, $loc), |
|
| 149 | + 'L' => analyser_dtd_element($dtd, $dtc, $loc), |
|
| 150 | + 'N' => analyser_dtd_entity($dtd, $dtc, $loc), |
|
| 151 | + 'O' => analyser_dtd_notation($dtd, $dtc, $loc), |
|
| 152 | + '-' => analyser_dtd_comment($dtd, $dtc, $loc), |
|
| 153 | + default => -1, |
|
| 154 | + }; |
|
| 155 | + } |
|
| 156 | + if (!is_string($r)) { |
|
| 157 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 158 | + |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | + $dtd = $r; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return true; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 168 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 169 | - // Option /s car sur plusieurs lignes parfois |
|
| 168 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 169 | + // Option /s car sur plusieurs lignes parfois |
|
| 170 | 170 | |
| 171 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 172 | - return -6; |
|
| 173 | - } |
|
| 171 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 172 | + return -6; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - return $m[1]; |
|
| 175 | + return $m[1]; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 179 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 180 | - return -10; |
|
| 181 | - } |
|
| 179 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 180 | + return -10; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $m[1]; |
|
| 183 | + return $m[1]; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 187 | 187 | |
| 188 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 189 | - return -9; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - [, $s] = $m; |
|
| 193 | - $n = $dtc->macros[$s]; |
|
| 194 | - |
|
| 195 | - if (is_array($n)) { |
|
| 196 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 197 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 198 | - if ( |
|
| 199 | - $n[0] == 'PUBLIC' && !tester_url_absolue($n[1]) |
|
| 200 | - ) { |
|
| 201 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 202 | - } |
|
| 203 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 188 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 189 | + return -9; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + [, $s] = $m; |
|
| 193 | + $n = $dtc->macros[$s]; |
|
| 194 | + |
|
| 195 | + if (is_array($n)) { |
|
| 196 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 197 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 198 | + if ( |
|
| 199 | + $n[0] == 'PUBLIC' && !tester_url_absolue($n[1]) |
|
| 200 | + ) { |
|
| 201 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 202 | + } |
|
| 203 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -211,78 +211,78 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 213 | 213 | |
| 214 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 215 | - return -11; |
|
| 216 | - } |
|
| 217 | - if ( |
|
| 218 | - !preg_match( |
|
| 219 | - '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 220 | - $m[2], |
|
| 221 | - $r |
|
| 222 | - ) |
|
| 223 | - ) { |
|
| 224 | - return -12; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $dtc->macros[$m[1]] == 'INCLUDE' |
|
| 228 | - ? $r[1] . substr($m[2], strlen($r[0])) |
|
| 229 | - : substr($m[2], strlen($r[0])); |
|
| 214 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 215 | + return -11; |
|
| 216 | + } |
|
| 217 | + if ( |
|
| 218 | + !preg_match( |
|
| 219 | + '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 220 | + $m[2], |
|
| 221 | + $r |
|
| 222 | + ) |
|
| 223 | + ) { |
|
| 224 | + return -12; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $dtc->macros[$m[1]] == 'INCLUDE' |
|
| 228 | + ? $r[1] . substr($m[2], strlen($r[0])) |
|
| 229 | + : substr($m[2], strlen($r[0])); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 233 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 234 | - return -8; |
|
| 235 | - } |
|
| 236 | - spip_log('analyser_dtd_notation a ecrire'); |
|
| 233 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 234 | + return -8; |
|
| 235 | + } |
|
| 236 | + spip_log('analyser_dtd_notation a ecrire'); |
|
| 237 | 237 | |
| 238 | - return $m[1]; |
|
| 238 | + return $m[1]; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 242 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 243 | - return -2; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 247 | - |
|
| 248 | - if (isset($dtc->macros[$nom]) && $dtc->macros[$nom]) { |
|
| 249 | - return $dtd; |
|
| 250 | - } |
|
| 251 | - if (isset($dtc->entites[$nom])) { |
|
| 252 | - spip_log("redefinition de l'entite $nom"); |
|
| 253 | - } |
|
| 254 | - if ($k6) { |
|
| 255 | - return $k6 . $dtd; |
|
| 256 | - } // cas du synonyme complet |
|
| 257 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 258 | - |
|
| 259 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 260 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 261 | - [$t, $type, $val, $q, $alt] = $r; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if (!$term) { |
|
| 265 | - $dtc->entites[$nom] = $val; |
|
| 266 | - } elseif (!$type) { |
|
| 267 | - $dtc->macros[$nom] = $val; |
|
| 268 | - } else { |
|
| 269 | - if ($type == 'SYSTEM' && !$alt) { |
|
| 270 | - $alt = $val; |
|
| 271 | - } |
|
| 272 | - if (!$alt) { |
|
| 273 | - $dtc->macros[$nom] = $val; |
|
| 274 | - } else { |
|
| 275 | - if ( |
|
| 276 | - $type == 'PUBLIC' && !str_contains($alt, '/') |
|
| 277 | - ) { |
|
| 278 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 279 | - . $alt; |
|
| 280 | - } |
|
| 281 | - $dtc->macros[$nom] = [$type, $alt]; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $dtd; |
|
| 242 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 243 | + return -2; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 247 | + |
|
| 248 | + if (isset($dtc->macros[$nom]) && $dtc->macros[$nom]) { |
|
| 249 | + return $dtd; |
|
| 250 | + } |
|
| 251 | + if (isset($dtc->entites[$nom])) { |
|
| 252 | + spip_log("redefinition de l'entite $nom"); |
|
| 253 | + } |
|
| 254 | + if ($k6) { |
|
| 255 | + return $k6 . $dtd; |
|
| 256 | + } // cas du synonyme complet |
|
| 257 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 258 | + |
|
| 259 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 260 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 261 | + [$t, $type, $val, $q, $alt] = $r; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if (!$term) { |
|
| 265 | + $dtc->entites[$nom] = $val; |
|
| 266 | + } elseif (!$type) { |
|
| 267 | + $dtc->macros[$nom] = $val; |
|
| 268 | + } else { |
|
| 269 | + if ($type == 'SYSTEM' && !$alt) { |
|
| 270 | + $alt = $val; |
|
| 271 | + } |
|
| 272 | + if (!$alt) { |
|
| 273 | + $dtc->macros[$nom] = $val; |
|
| 274 | + } else { |
|
| 275 | + if ( |
|
| 276 | + $type == 'PUBLIC' && !str_contains($alt, '/') |
|
| 277 | + ) { |
|
| 278 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 279 | + . $alt; |
|
| 280 | + } |
|
| 281 | + $dtc->macros[$nom] = [$type, $alt]; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $dtd; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Dresser le tableau des filles potentielles de l'element |
@@ -295,71 +295,71 @@ discard block |
||
| 295 | 295 | // Fin du controle en finElement |
| 296 | 296 | |
| 297 | 297 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 298 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 299 | - return -3; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - [, $nom, $contenu, $dtd] = $m; |
|
| 303 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 304 | - |
|
| 305 | - if (isset($dtc->elements[$nom])) { |
|
| 306 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 307 | - |
|
| 308 | - return -4; |
|
| 309 | - } |
|
| 310 | - $filles = []; |
|
| 311 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 312 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 313 | - if ($val == '(?:EMPTY )') { |
|
| 314 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 315 | - } elseif ($val == '(?:ANY )') { |
|
| 316 | - $dtc->regles[$nom] = 'ANY'; |
|
| 317 | - } else { |
|
| 318 | - $last = substr($val, -1); |
|
| 319 | - $dtc->regles[$nom] = preg_match('/ \w/', $val) || (!empty($last) && !str_contains('*+?', $last)) |
|
| 320 | - ? "/^$val$/" |
|
| 321 | - : $last; |
|
| 322 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 323 | - |
|
| 324 | - foreach ($filles as $k) { |
|
| 325 | - if (!isset($dtc->peres[$k])) { |
|
| 326 | - $dtc->peres[$k] = []; |
|
| 327 | - } |
|
| 328 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 329 | - $dtc->peres[$k][] = $nom; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - $dtc->pcdata[$nom] = (!str_contains($contenu, '#PCDATA')); |
|
| 334 | - $dtc->elements[$nom] = $filles; |
|
| 335 | - |
|
| 336 | - return $dtd; |
|
| 298 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 299 | + return -3; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + [, $nom, $contenu, $dtd] = $m; |
|
| 303 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 304 | + |
|
| 305 | + if (isset($dtc->elements[$nom])) { |
|
| 306 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 307 | + |
|
| 308 | + return -4; |
|
| 309 | + } |
|
| 310 | + $filles = []; |
|
| 311 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 312 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 313 | + if ($val == '(?:EMPTY )') { |
|
| 314 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 315 | + } elseif ($val == '(?:ANY )') { |
|
| 316 | + $dtc->regles[$nom] = 'ANY'; |
|
| 317 | + } else { |
|
| 318 | + $last = substr($val, -1); |
|
| 319 | + $dtc->regles[$nom] = preg_match('/ \w/', $val) || (!empty($last) && !str_contains('*+?', $last)) |
|
| 320 | + ? "/^$val$/" |
|
| 321 | + : $last; |
|
| 322 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 323 | + |
|
| 324 | + foreach ($filles as $k) { |
|
| 325 | + if (!isset($dtc->peres[$k])) { |
|
| 326 | + $dtc->peres[$k] = []; |
|
| 327 | + } |
|
| 328 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 329 | + $dtc->peres[$k][] = $nom; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + $dtc->pcdata[$nom] = (!str_contains($contenu, '#PCDATA')); |
|
| 334 | + $dtc->elements[$nom] = $filles; |
|
| 335 | + |
|
| 336 | + return $dtd; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | |
| 340 | 340 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 341 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 342 | - return -5; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - [, $nom, $val, $dtd] = $m; |
|
| 346 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 347 | - $val = expanserEntite($val, $dtc->macros); |
|
| 348 | - if (!isset($dtc->attributs[$nom])) { |
|
| 349 | - $dtc->attributs[$nom] = []; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 353 | - foreach ($r2 as $m2) { |
|
| 354 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 355 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 356 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 357 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 358 | - $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $dtd; |
|
| 341 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 342 | + return -5; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + [, $nom, $val, $dtd] = $m; |
|
| 346 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 347 | + $val = expanserEntite($val, $dtc->macros); |
|
| 348 | + if (!isset($dtc->attributs[$nom])) { |
|
| 349 | + $dtc->attributs[$nom] = []; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 353 | + foreach ($r2 as $m2) { |
|
| 354 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 355 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 356 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 357 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 358 | + $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $dtd; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -375,26 +375,26 @@ discard block |
||
| 375 | 375 | * @return string|array |
| 376 | 376 | **/ |
| 377 | 377 | function expanserEntite($val, $macros = []) { |
| 378 | - static $vu = []; |
|
| 379 | - if (!is_string($val)) { |
|
| 380 | - return $vu; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 384 | - foreach ($r as $m) { |
|
| 385 | - $ent = $m[1]; |
|
| 386 | - // il peut valoir "" |
|
| 387 | - if (!isset($macros[$ent])) { |
|
| 388 | - spip_log("Entite $ent inconnu"); |
|
| 389 | - } else { |
|
| 390 | - if (!isset($vu[$ent])) { |
|
| 391 | - $vu[$ent] = 0; |
|
| 392 | - } |
|
| 393 | - ++$vu[$ent]; |
|
| 394 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 378 | + static $vu = []; |
|
| 379 | + if (!is_string($val)) { |
|
| 380 | + return $vu; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 384 | + foreach ($r as $m) { |
|
| 385 | + $ent = $m[1]; |
|
| 386 | + // il peut valoir "" |
|
| 387 | + if (!isset($macros[$ent])) { |
|
| 388 | + spip_log("Entite $ent inconnu"); |
|
| 389 | + } else { |
|
| 390 | + if (!isset($vu[$ent])) { |
|
| 391 | + $vu[$ent] = 0; |
|
| 392 | + } |
|
| 393 | + ++$vu[$ent]; |
|
| 394 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 400 | 400 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $grammaire = find_in_path($grammaire); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 30 | + $file = _DIR_CACHE_XML.preg_replace('/[^\w.]/', '_', $rotlvl).'.gz'; |
|
| 31 | 31 | |
| 32 | 32 | if (lire_fichier($file, $r)) { |
| 33 | 33 | if (!$grammaire) { |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $dtc->peres[$k] = $v; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 57 | + spip_log("Analyser DTD $avail $grammaire (".spip_timer('dtd').') '.(is_countable($dtc->macros) ? count($dtc->macros) : 0).' macros, '.(is_countable($dtc->elements) ? count($dtc->elements) : 0).' elements, '.(is_countable($dtc->attributs) ? count($dtc->attributs) : 0)." listes d'attributs, ".(is_countable($dtc->entites) ? count($dtc->entites) : 0).' entites'); |
|
| 58 | 58 | # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
| 59 | 59 | ecrire_fichier($file, serialize($dtc), true); |
| 60 | 60 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | }; |
| 155 | 155 | } |
| 156 | 156 | if (!is_string($r)) { |
| 157 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 157 | + spip_log("erreur $r dans la DTD ".substr($dtd, 0, 80).'.....'); |
|
| 158 | 158 | |
| 159 | 159 | return false; |
| 160 | 160 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | if ( |
| 199 | 199 | $n[0] == 'PUBLIC' && !tester_url_absolue($n[1]) |
| 200 | 200 | ) { |
| 201 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 201 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1).$n[1]; |
|
| 202 | 202 | } |
| 203 | 203 | analyser_dtd($n[1], $n[0], $dtc); |
| 204 | 204 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return $dtc->macros[$m[1]] == 'INCLUDE' |
| 228 | - ? $r[1] . substr($m[2], strlen($r[0])) |
|
| 228 | + ? $r[1].substr($m[2], strlen($r[0])) |
|
| 229 | 229 | : substr($m[2], strlen($r[0])); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | spip_log("redefinition de l'entite $nom"); |
| 253 | 253 | } |
| 254 | 254 | if ($k6) { |
| 255 | - return $k6 . $dtd; |
|
| 255 | + return $k6.$dtd; |
|
| 256 | 256 | } // cas du synonyme complet |
| 257 | 257 | $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
| 258 | 258 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
| 353 | 353 | foreach ($r2 as $m2) { |
| 354 | 354 | $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
| 355 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 355 | + : ('/^'.preg_replace('/\s+/', '', $m2[2]).'$/'); |
|
| 356 | 356 | $m21 = expanserEntite($m2[1], $dtc->macros); |
| 357 | 357 | $m25 = expanserEntite($m2[5], $dtc->macros); |
| 358 | 358 | $dtc->attributs[$nom][$m21] = [$v, $m25]; |
@@ -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 | // TODO: get/set_caracteres ? |
@@ -43,88 +43,88 @@ discard block |
||
| 43 | 43 | * @return array|bool |
| 44 | 44 | */ |
| 45 | 45 | function req_sqlite_dist($addr, $port, $login, #[\SensitiveParameter] $pass, $db = '', $prefixe = '', $sqlite_version = '') { |
| 46 | - static $last_connect = []; |
|
| 47 | - |
|
| 48 | - // si provient de selectdb |
|
| 49 | - // un code pour etre sur que l'on vient de select_db() |
|
| 50 | - if (str_contains($db, $code = '@selectdb@')) { |
|
| 51 | - foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 52 | - ${$a} = $last_connect[$a]; |
|
| 53 | - } |
|
| 54 | - $db = str_replace($code, '', $db); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /* |
|
| 46 | + static $last_connect = []; |
|
| 47 | + |
|
| 48 | + // si provient de selectdb |
|
| 49 | + // un code pour etre sur que l'on vient de select_db() |
|
| 50 | + if (str_contains($db, $code = '@selectdb@')) { |
|
| 51 | + foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 52 | + ${$a} = $last_connect[$a]; |
|
| 53 | + } |
|
| 54 | + $db = str_replace($code, '', $db); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /* |
|
| 58 | 58 | * En sqlite, seule l'adresse du fichier est importante. |
| 59 | 59 | * Ce sera $db le nom, |
| 60 | 60 | * le path est $addr |
| 61 | 61 | * (_DIR_DB si $addr est vide) |
| 62 | 62 | */ |
| 63 | - _sqlite_init(); |
|
| 64 | - |
|
| 65 | - // determiner le dossier de la base : $addr ou _DIR_DB |
|
| 66 | - $f = _DIR_DB; |
|
| 67 | - if ($addr && str_contains($addr, '/')) { |
|
| 68 | - $f = rtrim($addr, '/') . '/'; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // un nom de base demande et impossible d'obtenir la base, on s'en va : |
|
| 72 | - // il faut que la base existe ou que le repertoire parent soit writable |
|
| 73 | - if ($db && !is_file($f .= $db . '.sqlite') && !is_writable(dirname($f))) { |
|
| 74 | - spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.' . _LOG_HS); |
|
| 75 | - |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // charger les modules sqlite au besoin |
|
| 80 | - if (!_sqlite_charger_version($sqlite_version)) { |
|
| 81 | - spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.' . _LOG_HS); |
|
| 82 | - |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // chargement des constantes |
|
| 87 | - // il ne faut pas definir les constantes avant d'avoir charge les modules sqlite |
|
| 88 | - $define = 'spip_sqlite' . $sqlite_version . '_constantes'; |
|
| 89 | - $define(); |
|
| 90 | - |
|
| 91 | - if (!$db) { |
|
| 92 | - // si pas de db -> |
|
| 93 | - // base temporaire tant qu'on ne connait pas son vrai nom |
|
| 94 | - // pour tester la connexion |
|
| 95 | - $db = '_sqlite' . $sqlite_version . '_install'; |
|
| 96 | - $tmp = _DIR_DB . $db . '.sqlite'; |
|
| 97 | - $link = spip_sqlite_open($tmp); |
|
| 98 | - } else { |
|
| 99 | - // Ouvrir (eventuellement creer la base) |
|
| 100 | - $link = spip_sqlite_open($f); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - if (!$link) { |
|
| 104 | - spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f", 'sqlite.' . _LOG_HS); |
|
| 105 | - |
|
| 106 | - return false; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $last_connect = [ |
|
| 110 | - 'addr' => $addr, |
|
| 111 | - 'port' => $port, |
|
| 112 | - 'login' => $login, |
|
| 113 | - 'pass' => $pass, |
|
| 114 | - 'db' => $db, |
|
| 115 | - 'prefixe' => $prefixe, |
|
| 116 | - ]; |
|
| 117 | - |
|
| 118 | - // etre sur qu'on definit bien les fonctions a chaque nouvelle connexion |
|
| 119 | - include_spip('req/sqlite_fonctions'); |
|
| 120 | - _sqlite_init_functions($link); |
|
| 121 | - |
|
| 122 | - return [ |
|
| 123 | - 'db' => $db, |
|
| 124 | - 'prefixe' => $prefixe ?: $db, |
|
| 125 | - 'link' => $link, |
|
| 126 | - 'total_requetes' => 0, |
|
| 127 | - ]; |
|
| 63 | + _sqlite_init(); |
|
| 64 | + |
|
| 65 | + // determiner le dossier de la base : $addr ou _DIR_DB |
|
| 66 | + $f = _DIR_DB; |
|
| 67 | + if ($addr && str_contains($addr, '/')) { |
|
| 68 | + $f = rtrim($addr, '/') . '/'; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // un nom de base demande et impossible d'obtenir la base, on s'en va : |
|
| 72 | + // il faut que la base existe ou que le repertoire parent soit writable |
|
| 73 | + if ($db && !is_file($f .= $db . '.sqlite') && !is_writable(dirname($f))) { |
|
| 74 | + spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.' . _LOG_HS); |
|
| 75 | + |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // charger les modules sqlite au besoin |
|
| 80 | + if (!_sqlite_charger_version($sqlite_version)) { |
|
| 81 | + spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.' . _LOG_HS); |
|
| 82 | + |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // chargement des constantes |
|
| 87 | + // il ne faut pas definir les constantes avant d'avoir charge les modules sqlite |
|
| 88 | + $define = 'spip_sqlite' . $sqlite_version . '_constantes'; |
|
| 89 | + $define(); |
|
| 90 | + |
|
| 91 | + if (!$db) { |
|
| 92 | + // si pas de db -> |
|
| 93 | + // base temporaire tant qu'on ne connait pas son vrai nom |
|
| 94 | + // pour tester la connexion |
|
| 95 | + $db = '_sqlite' . $sqlite_version . '_install'; |
|
| 96 | + $tmp = _DIR_DB . $db . '.sqlite'; |
|
| 97 | + $link = spip_sqlite_open($tmp); |
|
| 98 | + } else { |
|
| 99 | + // Ouvrir (eventuellement creer la base) |
|
| 100 | + $link = spip_sqlite_open($f); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + if (!$link) { |
|
| 104 | + spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f", 'sqlite.' . _LOG_HS); |
|
| 105 | + |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $last_connect = [ |
|
| 110 | + 'addr' => $addr, |
|
| 111 | + 'port' => $port, |
|
| 112 | + 'login' => $login, |
|
| 113 | + 'pass' => $pass, |
|
| 114 | + 'db' => $db, |
|
| 115 | + 'prefixe' => $prefixe, |
|
| 116 | + ]; |
|
| 117 | + |
|
| 118 | + // etre sur qu'on definit bien les fonctions a chaque nouvelle connexion |
|
| 119 | + include_spip('req/sqlite_fonctions'); |
|
| 120 | + _sqlite_init_functions($link); |
|
| 121 | + |
|
| 122 | + return [ |
|
| 123 | + 'db' => $db, |
|
| 124 | + 'prefixe' => $prefixe ?: $db, |
|
| 125 | + 'link' => $link, |
|
| 126 | + 'total_requetes' => 0, |
|
| 127 | + ]; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | * @return PDO |
| 135 | 135 | */ |
| 136 | 136 | function spip_sqlite_open(string $file): \PDO { |
| 137 | - $PDO = new \PDO("sqlite:$file"); |
|
| 138 | - $PDO->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, [&$PDO]]); |
|
| 139 | - return $PDO; |
|
| 137 | + $PDO = new \PDO("sqlite:$file"); |
|
| 138 | + $PDO->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, [&$PDO]]); |
|
| 139 | + return $PDO; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
@@ -155,14 +155,14 @@ discard block |
||
| 155 | 155 | * Resultat de la requete |
| 156 | 156 | */ |
| 157 | 157 | function spip_sqlite_query($query, $serveur = '', $requeter = true) { |
| 158 | - #spip_log("spip_sqlite_query() > $query",'sqlite.'._LOG_DEBUG); |
|
| 159 | - #_sqlite_init(); // fait la premiere fois dans spip_sqlite |
|
| 160 | - $query = Sqlite::traduire_requete($query, $serveur); |
|
| 161 | - if (!$requeter) { |
|
| 162 | - return $query; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return Sqlite::executer_requete($query, $serveur); |
|
| 158 | + #spip_log("spip_sqlite_query() > $query",'sqlite.'._LOG_DEBUG); |
|
| 159 | + #_sqlite_init(); // fait la premiere fois dans spip_sqlite |
|
| 160 | + $query = Sqlite::traduire_requete($query, $serveur); |
|
| 161 | + if (!$requeter) { |
|
| 162 | + return $query; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return Sqlite::executer_requete($query, $serveur); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | function spip_sqlite_alter($query, $serveur = '', $requeter = true) { |
| 181 | 181 | |
| 182 | - $query = spip_sqlite_query("ALTER $query", $serveur, false); |
|
| 183 | - // traduire la requete pour recuperer les bons noms de table |
|
| 184 | - $query = Sqlite::traduire_requete($query, $serveur); |
|
| 182 | + $query = spip_sqlite_query("ALTER $query", $serveur, false); |
|
| 183 | + // traduire la requete pour recuperer les bons noms de table |
|
| 184 | + $query = Sqlite::traduire_requete($query, $serveur); |
|
| 185 | 185 | |
| 186 | - /* |
|
| 186 | + /* |
|
| 187 | 187 | * la il faut faire les transformations |
| 188 | 188 | * si ALTER TABLE x (DROP|CHANGE) y |
| 189 | 189 | * |
@@ -192,251 +192,251 @@ discard block |
||
| 192 | 192 | * 3) faire chaque requete independemment |
| 193 | 193 | */ |
| 194 | 194 | |
| 195 | - // 1 |
|
| 196 | - if (preg_match('/\s*(ALTER(\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 197 | - $debut = $regs[1]; |
|
| 198 | - $table = $regs[3]; |
|
| 199 | - $suite = $regs[4]; |
|
| 200 | - } else { |
|
| 201 | - spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.' . _LOG_ERREUR); |
|
| 202 | - |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // 2 |
|
| 207 | - // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 208 | - // tout en cassant "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... en deux |
|
| 209 | - // ou revoir l'api de sql_alter en creant un |
|
| 210 | - // sql_alter_table($table,array($actions)); |
|
| 211 | - $todo = explode(',', $suite); |
|
| 212 | - |
|
| 213 | - // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 214 | - $todo2 = []; |
|
| 215 | - $i = 0; |
|
| 216 | - $ouverte = false; |
|
| 217 | - while ($do = array_shift($todo)) { |
|
| 218 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 219 | - $o = (str_contains($do, '(')); |
|
| 220 | - $f = (str_contains($do, ')')); |
|
| 221 | - if ($o && !$f) { |
|
| 222 | - $ouverte = true; |
|
| 223 | - } elseif ($f) { |
|
| 224 | - $ouverte = false; |
|
| 225 | - } |
|
| 226 | - if (!$ouverte) { |
|
| 227 | - $i++; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // 3 |
|
| 232 | - $resultats = []; |
|
| 233 | - foreach ($todo2 as $do) { |
|
| 234 | - $do = trim($do); |
|
| 235 | - if ( |
|
| 236 | - !preg_match('/(DROP PRIMARY KEY|DROP KEY|DROP INDEX|DROP COLUMN|DROP' |
|
| 237 | - . '|CHANGE COLUMN|CHANGE|MODIFY|RENAME TO|RENAME' |
|
| 238 | - . '|ADD PRIMARY KEY|ADD KEY|ADD INDEX|ADD UNIQUE KEY|ADD UNIQUE' |
|
| 239 | - . '|ADD COLUMN|ADD' |
|
| 240 | - . ')\s*([^\s]*)\s*(.*)?/i', $do, $matches) |
|
| 241 | - ) { |
|
| 242 | - spip_log( |
|
| 243 | - "SQLite : Probleme de ALTER TABLE, utilisation non reconnue dans : $do \n(requete d'origine : $query)", |
|
| 244 | - 'sqlite.' . _LOG_ERREUR |
|
| 245 | - ); |
|
| 246 | - |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $cle = strtoupper($matches[1]); |
|
| 251 | - $colonne_origine = $matches[2]; |
|
| 252 | - $colonne_destination = ''; |
|
| 253 | - |
|
| 254 | - $def = $matches[3]; |
|
| 255 | - |
|
| 256 | - // eluder une eventuelle clause before|after|first inutilisable |
|
| 257 | - $defr = rtrim(preg_replace('/(BEFORE|AFTER|FIRST)(.*)$/is', '', $def)); |
|
| 258 | - $defo = $defr; // garder la def d'origine pour certains cas |
|
| 259 | - // remplacer les definitions venant de mysql |
|
| 260 | - $defr = _sqlite_remplacements_definitions_table($defr); |
|
| 261 | - |
|
| 262 | - // reinjecter dans le do |
|
| 263 | - $do = str_replace($def, $defr, $do); |
|
| 264 | - $def = $defr; |
|
| 265 | - |
|
| 266 | - switch ($cle) { |
|
| 267 | - // suppression d'un index |
|
| 268 | - case 'DROP KEY': |
|
| 269 | - case 'DROP INDEX': |
|
| 270 | - $nom_index = $colonne_origine; |
|
| 271 | - spip_sqlite_drop_index($nom_index, $table, $serveur); |
|
| 272 | - break; |
|
| 273 | - |
|
| 274 | - // suppression d'une pk |
|
| 275 | - case 'DROP PRIMARY KEY': |
|
| 276 | - if ( |
|
| 277 | - !_sqlite_modifier_table( |
|
| 278 | - $table, |
|
| 279 | - $colonne_origine, |
|
| 280 | - ['key' => ['PRIMARY KEY' => '']], |
|
| 281 | - $serveur |
|
| 282 | - ) |
|
| 283 | - ) { |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - break; |
|
| 287 | - // suppression d'une colonne |
|
| 288 | - case 'DROP COLUMN': |
|
| 289 | - case 'DROP': |
|
| 290 | - if ( |
|
| 291 | - !_sqlite_modifier_table( |
|
| 292 | - $table, |
|
| 293 | - [$colonne_origine => ''], |
|
| 294 | - [], |
|
| 295 | - $serveur |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - return false; |
|
| 299 | - } |
|
| 300 | - break; |
|
| 301 | - |
|
| 302 | - case 'CHANGE COLUMN': |
|
| 303 | - case 'CHANGE': |
|
| 304 | - // recuperer le nom de la future colonne |
|
| 305 | - // on reprend la def d'origine car _sqlite_modifier_table va refaire la translation |
|
| 306 | - // en tenant compte de la cle primaire (ce qui est mieux) |
|
| 307 | - $def = trim($defo); |
|
| 308 | - $colonne_destination = substr($def, 0, strpos($def, ' ')); |
|
| 309 | - $def = substr($def, strlen($colonne_destination) + 1); |
|
| 310 | - |
|
| 311 | - if ( |
|
| 312 | - !_sqlite_modifier_table( |
|
| 313 | - $table, |
|
| 314 | - [$colonne_origine => $colonne_destination], |
|
| 315 | - ['field' => [$colonne_destination => $def]], |
|
| 316 | - $serveur |
|
| 317 | - ) |
|
| 318 | - ) { |
|
| 319 | - return false; |
|
| 320 | - } |
|
| 321 | - break; |
|
| 322 | - |
|
| 323 | - case 'MODIFY': |
|
| 324 | - // on reprend la def d'origine car _sqlite_modifier_table va refaire la translation |
|
| 325 | - // en tenant compte de la cle primaire (ce qui est mieux) |
|
| 326 | - if ( |
|
| 327 | - !_sqlite_modifier_table( |
|
| 328 | - $table, |
|
| 329 | - $colonne_origine, |
|
| 330 | - ['field' => [$colonne_origine => $defo]], |
|
| 331 | - $serveur |
|
| 332 | - ) |
|
| 333 | - ) { |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - break; |
|
| 337 | - |
|
| 338 | - // pas geres en sqlite2 |
|
| 339 | - case 'RENAME': |
|
| 340 | - $do = 'RENAME TO' . substr($do, 6); |
|
| 341 | - case 'RENAME TO': |
|
| 342 | - if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
|
| 343 | - spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 344 | - |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - break; |
|
| 348 | - |
|
| 349 | - // ajout d'une pk |
|
| 350 | - case 'ADD PRIMARY KEY': |
|
| 351 | - $pk = trim(substr($do, 16)); |
|
| 352 | - $pk = ($pk[0] == '(') ? substr($pk, 1, -1) : $pk; |
|
| 353 | - if ( |
|
| 354 | - !_sqlite_modifier_table( |
|
| 355 | - $table, |
|
| 356 | - $colonne_origine, |
|
| 357 | - ['key' => ['PRIMARY KEY' => $pk]], |
|
| 358 | - $serveur |
|
| 359 | - ) |
|
| 360 | - ) { |
|
| 361 | - return false; |
|
| 362 | - } |
|
| 363 | - break; |
|
| 364 | - // ajout d'un index |
|
| 365 | - case 'ADD UNIQUE KEY': |
|
| 366 | - case 'ADD UNIQUE': |
|
| 367 | - $unique = true; |
|
| 368 | - case 'ADD INDEX': |
|
| 369 | - case 'ADD KEY': |
|
| 370 | - if (!isset($unique)) { |
|
| 371 | - $unique = false; |
|
| 372 | - } |
|
| 373 | - // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 374 | - // bug potentiel si qqn met "(colonne, colonne)" |
|
| 375 | - // |
|
| 376 | - // nom_index (colonnes) |
|
| 377 | - if ($def) { |
|
| 378 | - $colonnes = substr($def, 1, -1); |
|
| 379 | - $nom_index = $colonne_origine; |
|
| 380 | - } else { |
|
| 381 | - // (colonne) |
|
| 382 | - if ($colonne_origine[0] == '(') { |
|
| 383 | - $colonnes = substr($colonne_origine, 1, -1); |
|
| 384 | - if (str_contains(',', $colonnes)) { |
|
| 385 | - spip_log('SQLite : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 386 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.' . _LOG_ERREUR); |
|
| 387 | - break; |
|
| 388 | - } else { |
|
| 389 | - $nom_index = $colonnes; |
|
| 390 | - } |
|
| 391 | - } // nom_index |
|
| 392 | - else { |
|
| 393 | - $nom_index = $colonnes = $colonne_origine; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - spip_sqlite_create_index($nom_index, $table, $colonnes, $unique, $serveur); |
|
| 397 | - break; |
|
| 398 | - |
|
| 399 | - // pas geres en sqlite2 |
|
| 400 | - case 'ADD COLUMN': |
|
| 401 | - $do = 'ADD' . substr($do, 10); |
|
| 402 | - case 'ADD': |
|
| 403 | - default: |
|
| 404 | - if (!preg_match(',primary\s+key,i', $do)) { |
|
| 405 | - if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
|
| 406 | - spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 407 | - |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - break; |
|
| 411 | - } |
|
| 412 | - // ou si la colonne est aussi primary key |
|
| 413 | - // cas du add id_truc int primary key |
|
| 414 | - // ajout d'une colonne qui passe en primary key directe |
|
| 415 | - else { |
|
| 416 | - $def = trim(substr($do, 3)); |
|
| 417 | - $colonne_ajoutee = substr($def, 0, strpos($def, ' ')); |
|
| 418 | - $def = substr($def, strlen($colonne_ajoutee) + 1); |
|
| 419 | - $opts = []; |
|
| 420 | - if (preg_match(',primary\s+key,i', $def)) { |
|
| 421 | - $opts['key'] = ['PRIMARY KEY' => $colonne_ajoutee]; |
|
| 422 | - $def = preg_replace(',primary\s+key,i', '', $def); |
|
| 423 | - } |
|
| 424 | - $opts['field'] = [$colonne_ajoutee => $def]; |
|
| 425 | - if (!_sqlite_modifier_table($table, [$colonne_ajoutee], $opts, $serveur)) { |
|
| 426 | - spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 427 | - |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - break; |
|
| 432 | - } |
|
| 433 | - // tout est bon, ouf ! |
|
| 434 | - spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.' . _LOG_INFO); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.' . _LOG_INFO); |
|
| 438 | - |
|
| 439 | - return true; |
|
| 195 | + // 1 |
|
| 196 | + if (preg_match('/\s*(ALTER(\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 197 | + $debut = $regs[1]; |
|
| 198 | + $table = $regs[3]; |
|
| 199 | + $suite = $regs[4]; |
|
| 200 | + } else { |
|
| 201 | + spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.' . _LOG_ERREUR); |
|
| 202 | + |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // 2 |
|
| 207 | + // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 208 | + // tout en cassant "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... en deux |
|
| 209 | + // ou revoir l'api de sql_alter en creant un |
|
| 210 | + // sql_alter_table($table,array($actions)); |
|
| 211 | + $todo = explode(',', $suite); |
|
| 212 | + |
|
| 213 | + // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 214 | + $todo2 = []; |
|
| 215 | + $i = 0; |
|
| 216 | + $ouverte = false; |
|
| 217 | + while ($do = array_shift($todo)) { |
|
| 218 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 219 | + $o = (str_contains($do, '(')); |
|
| 220 | + $f = (str_contains($do, ')')); |
|
| 221 | + if ($o && !$f) { |
|
| 222 | + $ouverte = true; |
|
| 223 | + } elseif ($f) { |
|
| 224 | + $ouverte = false; |
|
| 225 | + } |
|
| 226 | + if (!$ouverte) { |
|
| 227 | + $i++; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // 3 |
|
| 232 | + $resultats = []; |
|
| 233 | + foreach ($todo2 as $do) { |
|
| 234 | + $do = trim($do); |
|
| 235 | + if ( |
|
| 236 | + !preg_match('/(DROP PRIMARY KEY|DROP KEY|DROP INDEX|DROP COLUMN|DROP' |
|
| 237 | + . '|CHANGE COLUMN|CHANGE|MODIFY|RENAME TO|RENAME' |
|
| 238 | + . '|ADD PRIMARY KEY|ADD KEY|ADD INDEX|ADD UNIQUE KEY|ADD UNIQUE' |
|
| 239 | + . '|ADD COLUMN|ADD' |
|
| 240 | + . ')\s*([^\s]*)\s*(.*)?/i', $do, $matches) |
|
| 241 | + ) { |
|
| 242 | + spip_log( |
|
| 243 | + "SQLite : Probleme de ALTER TABLE, utilisation non reconnue dans : $do \n(requete d'origine : $query)", |
|
| 244 | + 'sqlite.' . _LOG_ERREUR |
|
| 245 | + ); |
|
| 246 | + |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $cle = strtoupper($matches[1]); |
|
| 251 | + $colonne_origine = $matches[2]; |
|
| 252 | + $colonne_destination = ''; |
|
| 253 | + |
|
| 254 | + $def = $matches[3]; |
|
| 255 | + |
|
| 256 | + // eluder une eventuelle clause before|after|first inutilisable |
|
| 257 | + $defr = rtrim(preg_replace('/(BEFORE|AFTER|FIRST)(.*)$/is', '', $def)); |
|
| 258 | + $defo = $defr; // garder la def d'origine pour certains cas |
|
| 259 | + // remplacer les definitions venant de mysql |
|
| 260 | + $defr = _sqlite_remplacements_definitions_table($defr); |
|
| 261 | + |
|
| 262 | + // reinjecter dans le do |
|
| 263 | + $do = str_replace($def, $defr, $do); |
|
| 264 | + $def = $defr; |
|
| 265 | + |
|
| 266 | + switch ($cle) { |
|
| 267 | + // suppression d'un index |
|
| 268 | + case 'DROP KEY': |
|
| 269 | + case 'DROP INDEX': |
|
| 270 | + $nom_index = $colonne_origine; |
|
| 271 | + spip_sqlite_drop_index($nom_index, $table, $serveur); |
|
| 272 | + break; |
|
| 273 | + |
|
| 274 | + // suppression d'une pk |
|
| 275 | + case 'DROP PRIMARY KEY': |
|
| 276 | + if ( |
|
| 277 | + !_sqlite_modifier_table( |
|
| 278 | + $table, |
|
| 279 | + $colonne_origine, |
|
| 280 | + ['key' => ['PRIMARY KEY' => '']], |
|
| 281 | + $serveur |
|
| 282 | + ) |
|
| 283 | + ) { |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + break; |
|
| 287 | + // suppression d'une colonne |
|
| 288 | + case 'DROP COLUMN': |
|
| 289 | + case 'DROP': |
|
| 290 | + if ( |
|
| 291 | + !_sqlite_modifier_table( |
|
| 292 | + $table, |
|
| 293 | + [$colonne_origine => ''], |
|
| 294 | + [], |
|
| 295 | + $serveur |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | + break; |
|
| 301 | + |
|
| 302 | + case 'CHANGE COLUMN': |
|
| 303 | + case 'CHANGE': |
|
| 304 | + // recuperer le nom de la future colonne |
|
| 305 | + // on reprend la def d'origine car _sqlite_modifier_table va refaire la translation |
|
| 306 | + // en tenant compte de la cle primaire (ce qui est mieux) |
|
| 307 | + $def = trim($defo); |
|
| 308 | + $colonne_destination = substr($def, 0, strpos($def, ' ')); |
|
| 309 | + $def = substr($def, strlen($colonne_destination) + 1); |
|
| 310 | + |
|
| 311 | + if ( |
|
| 312 | + !_sqlite_modifier_table( |
|
| 313 | + $table, |
|
| 314 | + [$colonne_origine => $colonne_destination], |
|
| 315 | + ['field' => [$colonne_destination => $def]], |
|
| 316 | + $serveur |
|
| 317 | + ) |
|
| 318 | + ) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 321 | + break; |
|
| 322 | + |
|
| 323 | + case 'MODIFY': |
|
| 324 | + // on reprend la def d'origine car _sqlite_modifier_table va refaire la translation |
|
| 325 | + // en tenant compte de la cle primaire (ce qui est mieux) |
|
| 326 | + if ( |
|
| 327 | + !_sqlite_modifier_table( |
|
| 328 | + $table, |
|
| 329 | + $colonne_origine, |
|
| 330 | + ['field' => [$colonne_origine => $defo]], |
|
| 331 | + $serveur |
|
| 332 | + ) |
|
| 333 | + ) { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + break; |
|
| 337 | + |
|
| 338 | + // pas geres en sqlite2 |
|
| 339 | + case 'RENAME': |
|
| 340 | + $do = 'RENAME TO' . substr($do, 6); |
|
| 341 | + case 'RENAME TO': |
|
| 342 | + if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
|
| 343 | + spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 344 | + |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + break; |
|
| 348 | + |
|
| 349 | + // ajout d'une pk |
|
| 350 | + case 'ADD PRIMARY KEY': |
|
| 351 | + $pk = trim(substr($do, 16)); |
|
| 352 | + $pk = ($pk[0] == '(') ? substr($pk, 1, -1) : $pk; |
|
| 353 | + if ( |
|
| 354 | + !_sqlite_modifier_table( |
|
| 355 | + $table, |
|
| 356 | + $colonne_origine, |
|
| 357 | + ['key' => ['PRIMARY KEY' => $pk]], |
|
| 358 | + $serveur |
|
| 359 | + ) |
|
| 360 | + ) { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 363 | + break; |
|
| 364 | + // ajout d'un index |
|
| 365 | + case 'ADD UNIQUE KEY': |
|
| 366 | + case 'ADD UNIQUE': |
|
| 367 | + $unique = true; |
|
| 368 | + case 'ADD INDEX': |
|
| 369 | + case 'ADD KEY': |
|
| 370 | + if (!isset($unique)) { |
|
| 371 | + $unique = false; |
|
| 372 | + } |
|
| 373 | + // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 374 | + // bug potentiel si qqn met "(colonne, colonne)" |
|
| 375 | + // |
|
| 376 | + // nom_index (colonnes) |
|
| 377 | + if ($def) { |
|
| 378 | + $colonnes = substr($def, 1, -1); |
|
| 379 | + $nom_index = $colonne_origine; |
|
| 380 | + } else { |
|
| 381 | + // (colonne) |
|
| 382 | + if ($colonne_origine[0] == '(') { |
|
| 383 | + $colonnes = substr($colonne_origine, 1, -1); |
|
| 384 | + if (str_contains(',', $colonnes)) { |
|
| 385 | + spip_log('SQLite : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 386 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.' . _LOG_ERREUR); |
|
| 387 | + break; |
|
| 388 | + } else { |
|
| 389 | + $nom_index = $colonnes; |
|
| 390 | + } |
|
| 391 | + } // nom_index |
|
| 392 | + else { |
|
| 393 | + $nom_index = $colonnes = $colonne_origine; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + spip_sqlite_create_index($nom_index, $table, $colonnes, $unique, $serveur); |
|
| 397 | + break; |
|
| 398 | + |
|
| 399 | + // pas geres en sqlite2 |
|
| 400 | + case 'ADD COLUMN': |
|
| 401 | + $do = 'ADD' . substr($do, 10); |
|
| 402 | + case 'ADD': |
|
| 403 | + default: |
|
| 404 | + if (!preg_match(',primary\s+key,i', $do)) { |
|
| 405 | + if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
|
| 406 | + spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 407 | + |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + break; |
|
| 411 | + } |
|
| 412 | + // ou si la colonne est aussi primary key |
|
| 413 | + // cas du add id_truc int primary key |
|
| 414 | + // ajout d'une colonne qui passe en primary key directe |
|
| 415 | + else { |
|
| 416 | + $def = trim(substr($do, 3)); |
|
| 417 | + $colonne_ajoutee = substr($def, 0, strpos($def, ' ')); |
|
| 418 | + $def = substr($def, strlen($colonne_ajoutee) + 1); |
|
| 419 | + $opts = []; |
|
| 420 | + if (preg_match(',primary\s+key,i', $def)) { |
|
| 421 | + $opts['key'] = ['PRIMARY KEY' => $colonne_ajoutee]; |
|
| 422 | + $def = preg_replace(',primary\s+key,i', '', $def); |
|
| 423 | + } |
|
| 424 | + $opts['field'] = [$colonne_ajoutee => $def]; |
|
| 425 | + if (!_sqlite_modifier_table($table, [$colonne_ajoutee], $opts, $serveur)) { |
|
| 426 | + spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 427 | + |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + break; |
|
| 432 | + } |
|
| 433 | + // tout est bon, ouf ! |
|
| 434 | + spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.' . _LOG_INFO); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.' . _LOG_INFO); |
|
| 438 | + |
|
| 439 | + return true; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -458,38 +458,38 @@ discard block |
||
| 458 | 458 | * - true si la requête réussie, false sinon. |
| 459 | 459 | */ |
| 460 | 460 | function spip_sqlite_create( |
| 461 | - $nom, |
|
| 462 | - $champs, |
|
| 463 | - $cles, |
|
| 464 | - $autoinc = false, |
|
| 465 | - $temporary = false, |
|
| 466 | - $serveur = '', |
|
| 467 | - $requeter = true |
|
| 461 | + $nom, |
|
| 462 | + $champs, |
|
| 463 | + $cles, |
|
| 464 | + $autoinc = false, |
|
| 465 | + $temporary = false, |
|
| 466 | + $serveur = '', |
|
| 467 | + $requeter = true |
|
| 468 | 468 | ) { |
| 469 | - $query = _sqlite_requete_create($nom, $champs, $cles, $autoinc, $temporary, $ifnotexists = true, $serveur, $requeter); |
|
| 470 | - if (!$query) { |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 473 | - $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 474 | - |
|
| 475 | - // SQLite ne cree pas les KEY sur les requetes CREATE TABLE |
|
| 476 | - // il faut donc les faire creer ensuite |
|
| 477 | - if (!$requeter) { |
|
| 478 | - return $res; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - $ok = (bool) $res; |
|
| 482 | - if ($ok) { |
|
| 483 | - foreach ($cles as $k => $v) { |
|
| 484 | - if (preg_match(',^(UNIQUE KEY|KEY|UNIQUE)\s,i', $k, $m)) { |
|
| 485 | - $index = trim(substr($k, strlen($m[1]))); |
|
| 486 | - $unique = (strlen($m[1]) > 3); |
|
| 487 | - $ok &= spip_sqlite_create_index($index, $nom, $v, $unique, $serveur); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - return (bool) $ok; |
|
| 469 | + $query = _sqlite_requete_create($nom, $champs, $cles, $autoinc, $temporary, $ifnotexists = true, $serveur, $requeter); |
|
| 470 | + if (!$query) { |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 474 | + |
|
| 475 | + // SQLite ne cree pas les KEY sur les requetes CREATE TABLE |
|
| 476 | + // il faut donc les faire creer ensuite |
|
| 477 | + if (!$requeter) { |
|
| 478 | + return $res; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + $ok = (bool) $res; |
|
| 482 | + if ($ok) { |
|
| 483 | + foreach ($cles as $k => $v) { |
|
| 484 | + if (preg_match(',^(UNIQUE KEY|KEY|UNIQUE)\s,i', $k, $m)) { |
|
| 485 | + $index = trim(substr($k, strlen($m[1]))); |
|
| 486 | + $unique = (strlen($m[1]) > 3); |
|
| 487 | + $ok &= spip_sqlite_create_index($index, $nom, $v, $unique, $serveur); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + return (bool) $ok; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -502,21 +502,21 @@ discard block |
||
| 502 | 502 | * @return bool true si la base est créee. |
| 503 | 503 | **/ |
| 504 | 504 | function spip_sqlite_create_base($nom, $serveur = '', $option = true) { |
| 505 | - $f = $nom . '.sqlite'; |
|
| 506 | - if (!str_contains($nom, '/')) { |
|
| 507 | - $f = _DIR_DB . $f; |
|
| 508 | - } |
|
| 505 | + $f = $nom . '.sqlite'; |
|
| 506 | + if (!str_contains($nom, '/')) { |
|
| 507 | + $f = _DIR_DB . $f; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - $ok = new \PDO("sqlite:$f"); |
|
| 510 | + $ok = new \PDO("sqlite:$f"); |
|
| 511 | 511 | |
| 512 | - if ($ok) { |
|
| 513 | - unset($ok); |
|
| 512 | + if ($ok) { |
|
| 513 | + unset($ok); |
|
| 514 | 514 | |
| 515 | - return true; |
|
| 516 | - } |
|
| 517 | - unset($ok); |
|
| 515 | + return true; |
|
| 516 | + } |
|
| 517 | + unset($ok); |
|
| 518 | 518 | |
| 519 | - return false; |
|
| 519 | + return false; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | |
@@ -537,22 +537,22 @@ discard block |
||
| 537 | 537 | * - string texte de la requête si $requeter vaut false |
| 538 | 538 | */ |
| 539 | 539 | function spip_sqlite_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 540 | - if (!$query_select) { |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - // vue deja presente |
|
| 544 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 545 | - spip_log( |
|
| 546 | - "Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", |
|
| 547 | - 'sqlite.' . _LOG_ERREUR |
|
| 548 | - ); |
|
| 549 | - |
|
| 550 | - return false; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 554 | - |
|
| 555 | - return spip_sqlite_query($query, $serveur, $requeter); |
|
| 540 | + if (!$query_select) { |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + // vue deja presente |
|
| 544 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 545 | + spip_log( |
|
| 546 | + "Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", |
|
| 547 | + 'sqlite.' . _LOG_ERREUR |
|
| 548 | + ); |
|
| 549 | + |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 554 | + |
|
| 555 | + return spip_sqlite_query($query, $serveur, $requeter); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -574,54 +574,54 @@ discard block |
||
| 574 | 574 | * string : requête, false si erreur, true sinon. |
| 575 | 575 | */ |
| 576 | 576 | function spip_sqlite_create_index($nom, $table, $champs, $unique = '', $serveur = '', $requeter = true) { |
| 577 | - if (!($nom || $table || $champs)) { |
|
| 578 | - spip_log( |
|
| 579 | - "Champ manquant pour creer un index sqlite ($nom, $table, (" . implode(',', $champs) . '))', |
|
| 580 | - 'sqlite.' . _LOG_ERREUR |
|
| 581 | - ); |
|
| 582 | - |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // SQLite ne differentie pas noms des index en fonction des tables |
|
| 587 | - // il faut donc creer des noms uniques d'index pour une base sqlite |
|
| 588 | - $nom = $table . '_' . $nom; |
|
| 589 | - // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 590 | - if (!is_array($champs)) { |
|
| 591 | - if ($champs[0] == '(') { |
|
| 592 | - $champs = substr($champs, 1, -1); |
|
| 593 | - } |
|
| 594 | - $champs = [$champs]; |
|
| 595 | - // supprimer l'info de longueur d'index mysql en fin de champ |
|
| 596 | - $champs = preg_replace(',\(\d+\)$,', '', $champs); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $ifnotexists = ''; |
|
| 600 | - $version = spip_sqlite_fetch(spip_sqlite_query('select sqlite_version() AS sqlite_version', $serveur), '', $serveur); |
|
| 601 | - if (!function_exists('spip_version_compare')) { |
|
| 602 | - include_spip('plugins/installer'); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - if ($version && spip_version_compare($version['sqlite_version'], '3.3.0', '>=')) { |
|
| 606 | - $ifnotexists = ' IF NOT EXISTS'; |
|
| 607 | - } else { |
|
| 608 | - /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
|
| 609 | - $a = spip_sqlite_showtable($table, $serveur); |
|
| 610 | - if (isset($a['key']['KEY ' . $nom])) { |
|
| 611 | - return true; |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - $query = 'CREATE ' . ($unique ? 'UNIQUE ' : '') . "INDEX$ifnotexists $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 616 | - $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 617 | - if (!$requeter) { |
|
| 618 | - return $res; |
|
| 619 | - } |
|
| 620 | - if ($res) { |
|
| 621 | - return true; |
|
| 622 | - } else { |
|
| 623 | - return false; |
|
| 624 | - } |
|
| 577 | + if (!($nom || $table || $champs)) { |
|
| 578 | + spip_log( |
|
| 579 | + "Champ manquant pour creer un index sqlite ($nom, $table, (" . implode(',', $champs) . '))', |
|
| 580 | + 'sqlite.' . _LOG_ERREUR |
|
| 581 | + ); |
|
| 582 | + |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // SQLite ne differentie pas noms des index en fonction des tables |
|
| 587 | + // il faut donc creer des noms uniques d'index pour une base sqlite |
|
| 588 | + $nom = $table . '_' . $nom; |
|
| 589 | + // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 590 | + if (!is_array($champs)) { |
|
| 591 | + if ($champs[0] == '(') { |
|
| 592 | + $champs = substr($champs, 1, -1); |
|
| 593 | + } |
|
| 594 | + $champs = [$champs]; |
|
| 595 | + // supprimer l'info de longueur d'index mysql en fin de champ |
|
| 596 | + $champs = preg_replace(',\(\d+\)$,', '', $champs); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $ifnotexists = ''; |
|
| 600 | + $version = spip_sqlite_fetch(spip_sqlite_query('select sqlite_version() AS sqlite_version', $serveur), '', $serveur); |
|
| 601 | + if (!function_exists('spip_version_compare')) { |
|
| 602 | + include_spip('plugins/installer'); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + if ($version && spip_version_compare($version['sqlite_version'], '3.3.0', '>=')) { |
|
| 606 | + $ifnotexists = ' IF NOT EXISTS'; |
|
| 607 | + } else { |
|
| 608 | + /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
|
| 609 | + $a = spip_sqlite_showtable($table, $serveur); |
|
| 610 | + if (isset($a['key']['KEY ' . $nom])) { |
|
| 611 | + return true; |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + $query = 'CREATE ' . ($unique ? 'UNIQUE ' : '') . "INDEX$ifnotexists $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 616 | + $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 617 | + if (!$requeter) { |
|
| 618 | + return $res; |
|
| 619 | + } |
|
| 620 | + if ($res) { |
|
| 621 | + return true; |
|
| 622 | + } else { |
|
| 623 | + return false; |
|
| 624 | + } |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | /** |
@@ -637,24 +637,24 @@ discard block |
||
| 637 | 637 | * @return int Nombre de lignes |
| 638 | 638 | */ |
| 639 | 639 | function spip_sqlite_count($r, $serveur = '', $requeter = true) { |
| 640 | - if (!$r) { |
|
| 641 | - return 0; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - // select ou autre (insert, update,...) ? |
|
| 645 | - // (link,requete) a compter |
|
| 646 | - if (strtoupper(substr(ltrim($r->queryString), 0, 6)) === 'SELECT') { |
|
| 647 | - $link = $r->getPDO(); |
|
| 648 | - $query = "SELECT count(*) as zzzzsqlitecount FROM ({$r->queryString})"; |
|
| 649 | - $l = $link->query($query); |
|
| 650 | - $i = 0; |
|
| 651 | - if ($l && ($z = $l->fetch())) { |
|
| 652 | - $i = (int) $z['zzzzsqlitecount']; |
|
| 653 | - } |
|
| 654 | - return $i; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return $r->rowCount(); |
|
| 640 | + if (!$r) { |
|
| 641 | + return 0; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + // select ou autre (insert, update,...) ? |
|
| 645 | + // (link,requete) a compter |
|
| 646 | + if (strtoupper(substr(ltrim($r->queryString), 0, 6)) === 'SELECT') { |
|
| 647 | + $link = $r->getPDO(); |
|
| 648 | + $query = "SELECT count(*) as zzzzsqlitecount FROM ({$r->queryString})"; |
|
| 649 | + $l = $link->query($query); |
|
| 650 | + $i = 0; |
|
| 651 | + if ($l && ($z = $l->fetch())) { |
|
| 652 | + $i = (int) $z['zzzzsqlitecount']; |
|
| 653 | + } |
|
| 654 | + return $i; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return $r->rowCount(); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | |
@@ -673,31 +673,31 @@ discard block |
||
| 673 | 673 | * - false si la requête a échouée |
| 674 | 674 | **/ |
| 675 | 675 | function spip_sqlite_countsel( |
| 676 | - $from = [], |
|
| 677 | - $where = [], |
|
| 678 | - $groupby = '', |
|
| 679 | - $having = [], |
|
| 680 | - $serveur = '', |
|
| 681 | - $requeter = true |
|
| 676 | + $from = [], |
|
| 677 | + $where = [], |
|
| 678 | + $groupby = '', |
|
| 679 | + $having = [], |
|
| 680 | + $serveur = '', |
|
| 681 | + $requeter = true |
|
| 682 | 682 | ) { |
| 683 | - $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 684 | - $r = spip_sqlite_select( |
|
| 685 | - "COUNT($c)", |
|
| 686 | - $from, |
|
| 687 | - $where, |
|
| 688 | - '', |
|
| 689 | - '', |
|
| 690 | - '', |
|
| 691 | - $having, |
|
| 692 | - $serveur, |
|
| 693 | - $requeter |
|
| 694 | - ); |
|
| 695 | - if ((is_resource($r) || is_object($r)) && $requeter) { // ressource : sqlite2, object : sqlite3 |
|
| 696 | - [$r] = spip_sqlite_fetch($r, SPIP_SQLITE3_NUM, $serveur); |
|
| 697 | - $r = (int) $r; |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - return $r; |
|
| 683 | + $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 684 | + $r = spip_sqlite_select( |
|
| 685 | + "COUNT($c)", |
|
| 686 | + $from, |
|
| 687 | + $where, |
|
| 688 | + '', |
|
| 689 | + '', |
|
| 690 | + '', |
|
| 691 | + $having, |
|
| 692 | + $serveur, |
|
| 693 | + $requeter |
|
| 694 | + ); |
|
| 695 | + if ((is_resource($r) || is_object($r)) && $requeter) { // ressource : sqlite2, object : sqlite3 |
|
| 696 | + [$r] = spip_sqlite_fetch($r, SPIP_SQLITE3_NUM, $serveur); |
|
| 697 | + $r = (int) $r; |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + return $r; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | |
@@ -714,24 +714,24 @@ discard block |
||
| 714 | 714 | * - false en cas d'erreur. |
| 715 | 715 | **/ |
| 716 | 716 | function spip_sqlite_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 717 | - $res = spip_sqlite_query( |
|
| 718 | - _sqlite_calculer_expression('DELETE FROM', $table, ',') |
|
| 719 | - . _sqlite_calculer_expression('WHERE', $where), |
|
| 720 | - $serveur, |
|
| 721 | - $requeter |
|
| 722 | - ); |
|
| 723 | - |
|
| 724 | - // renvoyer la requete inerte si demandee |
|
| 725 | - if (!$requeter) { |
|
| 726 | - return $res; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - if ($res) { |
|
| 730 | - $link = _sqlite_link($serveur); |
|
| 731 | - return $res->rowCount(); |
|
| 732 | - } else { |
|
| 733 | - return false; |
|
| 734 | - } |
|
| 717 | + $res = spip_sqlite_query( |
|
| 718 | + _sqlite_calculer_expression('DELETE FROM', $table, ',') |
|
| 719 | + . _sqlite_calculer_expression('WHERE', $where), |
|
| 720 | + $serveur, |
|
| 721 | + $requeter |
|
| 722 | + ); |
|
| 723 | + |
|
| 724 | + // renvoyer la requete inerte si demandee |
|
| 725 | + if (!$requeter) { |
|
| 726 | + return $res; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + if ($res) { |
|
| 730 | + $link = _sqlite_link($serveur); |
|
| 731 | + return $res->rowCount(); |
|
| 732 | + } else { |
|
| 733 | + return false; |
|
| 734 | + } |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | |
@@ -747,15 +747,15 @@ discard block |
||
| 747 | 747 | * - true si la requête a réussie, false sinon |
| 748 | 748 | */ |
| 749 | 749 | function spip_sqlite_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 750 | - if ($exist) { |
|
| 751 | - $exist = ' IF EXISTS'; |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - if (spip_sqlite_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 755 | - return true; |
|
| 756 | - } else { |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 750 | + if ($exist) { |
|
| 751 | + $exist = ' IF EXISTS'; |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + if (spip_sqlite_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 755 | + return true; |
|
| 756 | + } else { |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
@@ -771,11 +771,11 @@ discard block |
||
| 771 | 771 | * - true si la requête a réussie, false sinon |
| 772 | 772 | */ |
| 773 | 773 | function spip_sqlite_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 774 | - if ($exist) { |
|
| 775 | - $exist = ' IF EXISTS'; |
|
| 776 | - } |
|
| 774 | + if ($exist) { |
|
| 775 | + $exist = ' IF EXISTS'; |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - return spip_sqlite_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 778 | + return spip_sqlite_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -789,20 +789,20 @@ discard block |
||
| 789 | 789 | * @return bool ou requete |
| 790 | 790 | */ |
| 791 | 791 | function spip_sqlite_drop_index($nom, $table, $serveur = '', $requeter = true) { |
| 792 | - if (!$nom && !$table) { |
|
| 793 | - spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.' . _LOG_ERREUR); |
|
| 792 | + if (!$nom && !$table) { |
|
| 793 | + spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.' . _LOG_ERREUR); |
|
| 794 | 794 | |
| 795 | - return false; |
|
| 796 | - } |
|
| 795 | + return false; |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | - // SQLite ne differentie pas noms des index en fonction des tables |
|
| 799 | - // il faut donc creer des noms uniques d'index pour une base sqlite |
|
| 800 | - $index = $table . '_' . $nom; |
|
| 801 | - $exist = ' IF EXISTS'; |
|
| 798 | + // SQLite ne differentie pas noms des index en fonction des tables |
|
| 799 | + // il faut donc creer des noms uniques d'index pour une base sqlite |
|
| 800 | + $index = $table . '_' . $nom; |
|
| 801 | + $exist = ' IF EXISTS'; |
|
| 802 | 802 | |
| 803 | - $query = "DROP INDEX$exist $index"; |
|
| 803 | + $query = "DROP INDEX$exist $index"; |
|
| 804 | 804 | |
| 805 | - return spip_sqlite_query($query, $serveur, $requeter); |
|
| 805 | + return spip_sqlite_query($query, $serveur, $requeter); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | /** |
@@ -818,28 +818,28 @@ discard block |
||
| 818 | 818 | * Erreur eventuelle |
| 819 | 819 | **/ |
| 820 | 820 | function spip_sqlite_error($query = '', $serveur = '') { |
| 821 | - $link = _sqlite_link($serveur); |
|
| 822 | - |
|
| 823 | - if ($link) { |
|
| 824 | - $errs = $link->errorInfo(); |
|
| 825 | - $s = _sqlite_last_error_from_link($link); |
|
| 826 | - } else { |
|
| 827 | - $s = ': aucune ressource sqlite (link)'; |
|
| 828 | - } |
|
| 829 | - if ($s) { |
|
| 830 | - $trace = debug_backtrace(); |
|
| 831 | - if ($trace[0]['function'] != 'spip_sqlite_error') { |
|
| 832 | - spip_log("$s - $query - " . sql_error_backtrace(), 'sqlite.' . _LOG_ERREUR); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - return $s; |
|
| 821 | + $link = _sqlite_link($serveur); |
|
| 822 | + |
|
| 823 | + if ($link) { |
|
| 824 | + $errs = $link->errorInfo(); |
|
| 825 | + $s = _sqlite_last_error_from_link($link); |
|
| 826 | + } else { |
|
| 827 | + $s = ': aucune ressource sqlite (link)'; |
|
| 828 | + } |
|
| 829 | + if ($s) { |
|
| 830 | + $trace = debug_backtrace(); |
|
| 831 | + if ($trace[0]['function'] != 'spip_sqlite_error') { |
|
| 832 | + spip_log("$s - $query - " . sql_error_backtrace(), 'sqlite.' . _LOG_ERREUR); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + return $s; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | function _sqlite_last_error_from_link($link) { |
| 840 | - if ($link) { |
|
| 841 | - $errs = $link->errorInfo(); |
|
| 842 | - /* |
|
| 840 | + if ($link) { |
|
| 841 | + $errs = $link->errorInfo(); |
|
| 842 | + /* |
|
| 843 | 843 | $errs[0] |
| 844 | 844 | numero SQLState ('HY000' souvent lors d'une erreur) |
| 845 | 845 | http://www.easysoft.com/developer/interfaces/odbc/sqlstate_status_return_codes.html |
@@ -849,11 +849,11 @@ discard block |
||
| 849 | 849 | $errs[2] |
| 850 | 850 | Le texte du message d'erreur |
| 851 | 851 | */ |
| 852 | - if (ltrim($errs[0], '0')) { // 00000 si pas d'erreur |
|
| 853 | - return "$errs[2]"; |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - return ''; |
|
| 852 | + if (ltrim($errs[0], '0')) { // 00000 si pas d'erreur |
|
| 853 | + return "$errs[2]"; |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + return ''; |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -870,23 +870,23 @@ discard block |
||
| 870 | 870 | * 'HY000/1' : numéro de l'erreur SQLState / numéro d'erreur interne SQLite (en sqlite 3) |
| 871 | 871 | **/ |
| 872 | 872 | function spip_sqlite_errno($serveur = '') { |
| 873 | - $link = _sqlite_link($serveur); |
|
| 874 | - |
|
| 875 | - if ($link) { |
|
| 876 | - $t = $link->errorInfo(); |
|
| 877 | - $s = ltrim($t[0], '0'); // 00000 si pas d'erreur |
|
| 878 | - if ($s) { |
|
| 879 | - $s .= ' / ' . $t[1]; |
|
| 880 | - } // ajoute l'erreur du moteur SQLite |
|
| 881 | - } else { |
|
| 882 | - $s = ': aucune ressource sqlite (link)'; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - if ($s) { |
|
| 886 | - spip_log("Erreur sqlite $s", 'sqlite.' . _LOG_ERREUR); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - return $s ?: 0; |
|
| 873 | + $link = _sqlite_link($serveur); |
|
| 874 | + |
|
| 875 | + if ($link) { |
|
| 876 | + $t = $link->errorInfo(); |
|
| 877 | + $s = ltrim($t[0], '0'); // 00000 si pas d'erreur |
|
| 878 | + if ($s) { |
|
| 879 | + $s .= ' / ' . $t[1]; |
|
| 880 | + } // ajoute l'erreur du moteur SQLite |
|
| 881 | + } else { |
|
| 882 | + $s = ': aucune ressource sqlite (link)'; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + if ($s) { |
|
| 886 | + spip_log("Erreur sqlite $s", 'sqlite.' . _LOG_ERREUR); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + return $s ?: 0; |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | |
@@ -902,19 +902,19 @@ discard block |
||
| 902 | 902 | * - false si on a pas pu avoir d'explication |
| 903 | 903 | */ |
| 904 | 904 | function spip_sqlite_explain($query, $serveur = '', $requeter = true) { |
| 905 | - if (!str_starts_with(ltrim($query), 'SELECT')) { |
|
| 906 | - return []; |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - $query = Sqlite::traduire_requete($query, $serveur); |
|
| 910 | - $query = 'EXPLAIN ' . $query; |
|
| 911 | - if (!$requeter) { |
|
| 912 | - return $query; |
|
| 913 | - } |
|
| 914 | - // on ne trace pas ces requetes, sinon on obtient un tracage sans fin... |
|
| 915 | - $r = Sqlite::executer_requete($query, $serveur, false); |
|
| 916 | - |
|
| 917 | - return $r ? spip_sqlite_fetch($r, null, $serveur) : false; // hum ? etrange ca... a verifier |
|
| 905 | + if (!str_starts_with(ltrim($query), 'SELECT')) { |
|
| 906 | + return []; |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + $query = Sqlite::traduire_requete($query, $serveur); |
|
| 910 | + $query = 'EXPLAIN ' . $query; |
|
| 911 | + if (!$requeter) { |
|
| 912 | + return $query; |
|
| 913 | + } |
|
| 914 | + // on ne trace pas ces requetes, sinon on obtient un tracage sans fin... |
|
| 915 | + $r = Sqlite::executer_requete($query, $serveur, false); |
|
| 916 | + |
|
| 917 | + return $r ? spip_sqlite_fetch($r, null, $serveur) : false; // hum ? etrange ca... a verifier |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | |
@@ -934,35 +934,35 @@ discard block |
||
| 934 | 934 | */ |
| 935 | 935 | function spip_sqlite_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 936 | 936 | |
| 937 | - $link = _sqlite_link($serveur); |
|
| 938 | - $t = $t ?: SPIP_SQLITE3_ASSOC; |
|
| 939 | - |
|
| 940 | - if (!$r) { |
|
| 941 | - return false; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $retour = $r->fetch($t); |
|
| 945 | - |
|
| 946 | - if (!$retour) { |
|
| 947 | - if ($r->errorCode() === '00000') { |
|
| 948 | - return null; |
|
| 949 | - } |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - // Renvoie des 'table.titre' au lieu de 'titre' tout court ! pff ! |
|
| 954 | - // suppression de 'table.' pour toutes les cles (c'est un peu violent !) |
|
| 955 | - // c'est couteux : on ne verifie que la premiere ligne pour voir si on le fait ou non |
|
| 956 | - if (str_contains(implode('', array_keys($retour)), '.')) { |
|
| 957 | - foreach ($retour as $cle => $val) { |
|
| 958 | - if (($pos = strpos($cle, '.')) !== false) { |
|
| 959 | - $retour[substr($cle, $pos + 1)] = &$retour[$cle]; |
|
| 960 | - unset($retour[$cle]); |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - return $retour; |
|
| 937 | + $link = _sqlite_link($serveur); |
|
| 938 | + $t = $t ?: SPIP_SQLITE3_ASSOC; |
|
| 939 | + |
|
| 940 | + if (!$r) { |
|
| 941 | + return false; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $retour = $r->fetch($t); |
|
| 945 | + |
|
| 946 | + if (!$retour) { |
|
| 947 | + if ($r->errorCode() === '00000') { |
|
| 948 | + return null; |
|
| 949 | + } |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + // Renvoie des 'table.titre' au lieu de 'titre' tout court ! pff ! |
|
| 954 | + // suppression de 'table.' pour toutes les cles (c'est un peu violent !) |
|
| 955 | + // c'est couteux : on ne verifie que la premiere ligne pour voir si on le fait ou non |
|
| 956 | + if (str_contains(implode('', array_keys($retour)), '.')) { |
|
| 957 | + foreach ($retour as $cle => $val) { |
|
| 958 | + if (($pos = strpos($cle, '.')) !== false) { |
|
| 959 | + $retour[substr($cle, $pos + 1)] = &$retour[$cle]; |
|
| 960 | + unset($retour[$cle]); |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + return $retour; |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | /** |
@@ -975,8 +975,8 @@ discard block |
||
| 975 | 975 | * @return bool True si déplacement réussi, false sinon. |
| 976 | 976 | **/ |
| 977 | 977 | function spip_sqlite_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 978 | - // encore un truc de bien fichu : PDO ne PEUT PAS faire de seek ou de rewind... |
|
| 979 | - return false; |
|
| 978 | + // encore un truc de bien fichu : PDO ne PEUT PAS faire de seek ou de rewind... |
|
| 979 | + return false; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
@@ -992,10 +992,10 @@ discard block |
||
| 992 | 992 | * @return bool True si réussi |
| 993 | 993 | */ |
| 994 | 994 | function spip_sqlite_free(&$r, $serveur = '', $requeter = true) { |
| 995 | - unset($r); |
|
| 995 | + unset($r); |
|
| 996 | 996 | |
| 997 | - return true; |
|
| 998 | - //return sqlite_free_result($r); |
|
| 997 | + return true; |
|
| 998 | + //return sqlite_free_result($r); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | |
@@ -1010,8 +1010,8 @@ discard block |
||
| 1010 | 1010 | * @return void |
| 1011 | 1011 | */ |
| 1012 | 1012 | function spip_sqlite_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 1013 | - //$c = !$charset ? '' : (" LIKE "._q($charset['charset'])); |
|
| 1014 | - //return spip_sqlite_fetch(sqlite_query(_sqlite_link($serveur), "SHOW CHARACTER SET$c"), NULL, $serveur); |
|
| 1013 | + //$c = !$charset ? '' : (" LIKE "._q($charset['charset'])); |
|
| 1014 | + //return spip_sqlite_fetch(sqlite_query(_sqlite_link($serveur), "SHOW CHARACTER SET$c"), NULL, $serveur); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | * Valeur hexadécimale pour SQLite |
| 1027 | 1027 | **/ |
| 1028 | 1028 | function spip_sqlite_hex($v) { |
| 1029 | - return hexdec($v); |
|
| 1029 | + return hexdec($v); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | * Expression de requête SQL |
| 1049 | 1049 | **/ |
| 1050 | 1050 | function spip_sqlite_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1051 | - return "($val $not IN ($valeurs))"; |
|
| 1051 | + return "($val $not IN ($valeurs))"; |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | |
@@ -1076,20 +1076,20 @@ discard block |
||
| 1076 | 1076 | **/ |
| 1077 | 1077 | function spip_sqlite_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1078 | 1078 | |
| 1079 | - $query = "INSERT INTO $table " . ($champs ? "$champs VALUES $valeurs" : 'DEFAULT VALUES'); |
|
| 1080 | - if ($r = spip_sqlite_query($query, $serveur, $requeter)) { |
|
| 1081 | - if (!$requeter) { |
|
| 1082 | - return $r; |
|
| 1083 | - } |
|
| 1084 | - $nb = Sqlite::last_insert_id($serveur); |
|
| 1085 | - } else { |
|
| 1086 | - $nb = false; |
|
| 1087 | - } |
|
| 1079 | + $query = "INSERT INTO $table " . ($champs ? "$champs VALUES $valeurs" : 'DEFAULT VALUES'); |
|
| 1080 | + if ($r = spip_sqlite_query($query, $serveur, $requeter)) { |
|
| 1081 | + if (!$requeter) { |
|
| 1082 | + return $r; |
|
| 1083 | + } |
|
| 1084 | + $nb = Sqlite::last_insert_id($serveur); |
|
| 1085 | + } else { |
|
| 1086 | + $nb = false; |
|
| 1087 | + } |
|
| 1088 | 1088 | |
| 1089 | - $err = spip_sqlite_error($query, $serveur); |
|
| 1089 | + $err = spip_sqlite_error($query, $serveur); |
|
| 1090 | 1090 | |
| 1091 | - // cas particulier : ne pas substituer la reponse spip_sqlite_query si on est en profilage |
|
| 1092 | - return isset($_GET['var_profile']) ? $r : $nb; |
|
| 1091 | + // cas particulier : ne pas substituer la reponse spip_sqlite_query si on est en profilage |
|
| 1092 | + return isset($_GET['var_profile']) ? $r : $nb; |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | |
@@ -1114,28 +1114,28 @@ discard block |
||
| 1114 | 1114 | * - Tableau de description de la requête et du temps d'exécution, si var_profile activé |
| 1115 | 1115 | **/ |
| 1116 | 1116 | function spip_sqlite_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1117 | - if (!$desc) { |
|
| 1118 | - $desc = description_table($table, $serveur); |
|
| 1119 | - } |
|
| 1120 | - if (!$desc) { |
|
| 1121 | - die("$table insertion sans description"); |
|
| 1122 | - } |
|
| 1123 | - $fields = $desc['field'] ?? []; |
|
| 1124 | - |
|
| 1125 | - foreach ($couples as $champ => $val) { |
|
| 1126 | - $couples[$champ] = _sqlite_calculer_cite($val, $fields[$champ]); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1130 | - $couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1131 | - |
|
| 1132 | - $cles = $valeurs = ''; |
|
| 1133 | - if (is_countable($couples) ? count($couples) : 0) { |
|
| 1134 | - $cles = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1135 | - $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - return spip_sqlite_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 1117 | + if (!$desc) { |
|
| 1118 | + $desc = description_table($table, $serveur); |
|
| 1119 | + } |
|
| 1120 | + if (!$desc) { |
|
| 1121 | + die("$table insertion sans description"); |
|
| 1122 | + } |
|
| 1123 | + $fields = $desc['field'] ?? []; |
|
| 1124 | + |
|
| 1125 | + foreach ($couples as $champ => $val) { |
|
| 1126 | + $couples[$champ] = _sqlite_calculer_cite($val, $fields[$champ]); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1130 | + $couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1131 | + |
|
| 1132 | + $cles = $valeurs = ''; |
|
| 1133 | + if (is_countable($couples) ? count($couples) : 0) { |
|
| 1134 | + $cles = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1135 | + $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + return spip_sqlite_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | |
@@ -1159,72 +1159,72 @@ discard block |
||
| 1159 | 1159 | * - false en cas d'erreur. |
| 1160 | 1160 | **/ |
| 1161 | 1161 | function spip_sqlite_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1162 | - $retour = null; |
|
| 1163 | - $nb = null; |
|
| 1164 | - if (!$desc) { |
|
| 1165 | - $desc = description_table($table, $serveur); |
|
| 1166 | - } |
|
| 1167 | - if (!$desc) { |
|
| 1168 | - die("$table insertion sans description"); |
|
| 1169 | - } |
|
| 1170 | - if (!isset($desc['field'])) { |
|
| 1171 | - $desc['field'] = []; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // recuperer les champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1175 | - $maj = _sqlite_ajouter_champs_timestamp($table, [], $desc, $serveur); |
|
| 1176 | - |
|
| 1177 | - // seul le nom de la table est a traduire ici : |
|
| 1178 | - // le faire une seule fois au debut |
|
| 1179 | - $query_start = "INSERT INTO $table "; |
|
| 1180 | - $query_start = Sqlite::traduire_requete($query_start, $serveur); |
|
| 1181 | - |
|
| 1182 | - // ouvrir une transaction |
|
| 1183 | - if ($requeter) { |
|
| 1184 | - Sqlite::demarrer_transaction($serveur); |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - while ($couples = array_shift($tab_couples)) { |
|
| 1188 | - foreach ($couples as $champ => $val) { |
|
| 1189 | - $couples[$champ] = _sqlite_calculer_cite($val, $desc['field'][$champ]); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - // inserer les champs timestamp par defaut |
|
| 1193 | - $couples = array_merge($maj, $couples); |
|
| 1194 | - |
|
| 1195 | - $champs = $valeurs = ''; |
|
| 1196 | - if ($couples !== []) { |
|
| 1197 | - $champs = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1198 | - $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1199 | - $query = $query_start . "$champs VALUES $valeurs"; |
|
| 1200 | - } else { |
|
| 1201 | - $query = $query_start . 'DEFAULT VALUES'; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - if ($requeter) { |
|
| 1205 | - $retour = Sqlite::executer_requete($query, $serveur); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - // sur le dernier couple uniquement |
|
| 1209 | - if ($tab_couples === []) { |
|
| 1210 | - $nb = 0; |
|
| 1211 | - if ($requeter) { |
|
| 1212 | - $nb = Sqlite::last_insert_id($serveur); |
|
| 1213 | - } else { |
|
| 1214 | - return $query; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $err = spip_sqlite_error($query, $serveur); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - if ($requeter) { |
|
| 1222 | - Sqlite::finir_transaction($serveur); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - // renvoie le dernier id d'autoincrement ajoute |
|
| 1226 | - // cas particulier : ne pas substituer la reponse spip_sqlite_query si on est en profilage |
|
| 1227 | - return isset($_GET['var_profile']) ? $retour : $nb; |
|
| 1162 | + $retour = null; |
|
| 1163 | + $nb = null; |
|
| 1164 | + if (!$desc) { |
|
| 1165 | + $desc = description_table($table, $serveur); |
|
| 1166 | + } |
|
| 1167 | + if (!$desc) { |
|
| 1168 | + die("$table insertion sans description"); |
|
| 1169 | + } |
|
| 1170 | + if (!isset($desc['field'])) { |
|
| 1171 | + $desc['field'] = []; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // recuperer les champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1175 | + $maj = _sqlite_ajouter_champs_timestamp($table, [], $desc, $serveur); |
|
| 1176 | + |
|
| 1177 | + // seul le nom de la table est a traduire ici : |
|
| 1178 | + // le faire une seule fois au debut |
|
| 1179 | + $query_start = "INSERT INTO $table "; |
|
| 1180 | + $query_start = Sqlite::traduire_requete($query_start, $serveur); |
|
| 1181 | + |
|
| 1182 | + // ouvrir une transaction |
|
| 1183 | + if ($requeter) { |
|
| 1184 | + Sqlite::demarrer_transaction($serveur); |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + while ($couples = array_shift($tab_couples)) { |
|
| 1188 | + foreach ($couples as $champ => $val) { |
|
| 1189 | + $couples[$champ] = _sqlite_calculer_cite($val, $desc['field'][$champ]); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + // inserer les champs timestamp par defaut |
|
| 1193 | + $couples = array_merge($maj, $couples); |
|
| 1194 | + |
|
| 1195 | + $champs = $valeurs = ''; |
|
| 1196 | + if ($couples !== []) { |
|
| 1197 | + $champs = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1198 | + $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1199 | + $query = $query_start . "$champs VALUES $valeurs"; |
|
| 1200 | + } else { |
|
| 1201 | + $query = $query_start . 'DEFAULT VALUES'; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + if ($requeter) { |
|
| 1205 | + $retour = Sqlite::executer_requete($query, $serveur); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + // sur le dernier couple uniquement |
|
| 1209 | + if ($tab_couples === []) { |
|
| 1210 | + $nb = 0; |
|
| 1211 | + if ($requeter) { |
|
| 1212 | + $nb = Sqlite::last_insert_id($serveur); |
|
| 1213 | + } else { |
|
| 1214 | + return $query; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $err = spip_sqlite_error($query, $serveur); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + if ($requeter) { |
|
| 1222 | + Sqlite::finir_transaction($serveur); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + // renvoie le dernier id d'autoincrement ajoute |
|
| 1226 | + // cas particulier : ne pas substituer la reponse spip_sqlite_query si on est en profilage |
|
| 1227 | + return isset($_GET['var_profile']) ? $retour : $nb; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | |
@@ -1239,7 +1239,7 @@ discard block |
||
| 1239 | 1239 | * Toujours true. |
| 1240 | 1240 | **/ |
| 1241 | 1241 | function spip_sqlite_preferer_transaction($serveur = '', $requeter = true) { |
| 1242 | - return true; |
|
| 1242 | + return true; |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | /** |
@@ -1256,12 +1256,12 @@ discard block |
||
| 1256 | 1256 | * string si texte de la requête demandé, true sinon |
| 1257 | 1257 | **/ |
| 1258 | 1258 | function spip_sqlite_demarrer_transaction($serveur = '', $requeter = true) { |
| 1259 | - if (!$requeter) { |
|
| 1260 | - return 'BEGIN TRANSACTION'; |
|
| 1261 | - } |
|
| 1262 | - Sqlite::demarrer_transaction($serveur); |
|
| 1259 | + if (!$requeter) { |
|
| 1260 | + return 'BEGIN TRANSACTION'; |
|
| 1261 | + } |
|
| 1262 | + Sqlite::demarrer_transaction($serveur); |
|
| 1263 | 1263 | |
| 1264 | - return true; |
|
| 1264 | + return true; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | /** |
@@ -1275,12 +1275,12 @@ discard block |
||
| 1275 | 1275 | * string si texte de la requête demandé, true sinon |
| 1276 | 1276 | **/ |
| 1277 | 1277 | function spip_sqlite_terminer_transaction($serveur = '', $requeter = true) { |
| 1278 | - if (!$requeter) { |
|
| 1279 | - return 'COMMIT'; |
|
| 1280 | - } |
|
| 1281 | - Sqlite::finir_transaction($serveur); |
|
| 1278 | + if (!$requeter) { |
|
| 1279 | + return 'COMMIT'; |
|
| 1280 | + } |
|
| 1281 | + Sqlite::finir_transaction($serveur); |
|
| 1282 | 1282 | |
| 1283 | - return true; |
|
| 1283 | + return true; |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | |
@@ -1295,27 +1295,27 @@ discard block |
||
| 1295 | 1295 | * Liste des noms de bases |
| 1296 | 1296 | **/ |
| 1297 | 1297 | function spip_sqlite_listdbs($serveur = '', $requeter = true) { |
| 1298 | - _sqlite_init(); |
|
| 1299 | - |
|
| 1300 | - if (!is_dir($d = substr(_DIR_DB, 0, -1))) { |
|
| 1301 | - return []; |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - include_spip('inc/flock'); |
|
| 1305 | - $bases = preg_files($d, $pattern = '(.*)\.sqlite$'); |
|
| 1306 | - $bds = []; |
|
| 1307 | - |
|
| 1308 | - foreach ($bases as $b) { |
|
| 1309 | - // pas de bases commencant pas sqlite |
|
| 1310 | - // (on s'en sert pour l'installation pour simuler la presence d'un serveur) |
|
| 1311 | - // les bases sont de la forme _sqliteX_tmp_spip_install.sqlite |
|
| 1312 | - if (strpos($b, '_sqlite')) { |
|
| 1313 | - continue; |
|
| 1314 | - } |
|
| 1315 | - $bds[] = preg_replace(";.*/$pattern;iS", '$1', $b); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - return $bds; |
|
| 1298 | + _sqlite_init(); |
|
| 1299 | + |
|
| 1300 | + if (!is_dir($d = substr(_DIR_DB, 0, -1))) { |
|
| 1301 | + return []; |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + include_spip('inc/flock'); |
|
| 1305 | + $bases = preg_files($d, $pattern = '(.*)\.sqlite$'); |
|
| 1306 | + $bds = []; |
|
| 1307 | + |
|
| 1308 | + foreach ($bases as $b) { |
|
| 1309 | + // pas de bases commencant pas sqlite |
|
| 1310 | + // (on s'en sert pour l'installation pour simuler la presence d'un serveur) |
|
| 1311 | + // les bases sont de la forme _sqliteX_tmp_spip_install.sqlite |
|
| 1312 | + if (strpos($b, '_sqlite')) { |
|
| 1313 | + continue; |
|
| 1314 | + } |
|
| 1315 | + $bds[] = preg_replace(";.*/$pattern;iS", '$1', $b); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + return $bds; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | * @return string texte de sélection pour la requête |
| 1331 | 1331 | */ |
| 1332 | 1332 | function spip_sqlite_multi($objet, $lang) { |
| 1333 | - return 'EXTRAIRE_MULTI(' . $objet . ", '" . $lang . "') AS multi"; |
|
| 1333 | + return 'EXTRAIRE_MULTI(' . $objet . ", '" . $lang . "') AS multi"; |
|
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | 1336 | |
@@ -1347,15 +1347,15 @@ discard block |
||
| 1347 | 1347 | * @return bool|string true / false / requete |
| 1348 | 1348 | **/ |
| 1349 | 1349 | function spip_sqlite_optimize($table, $serveur = '', $requeter = true) { |
| 1350 | - static $do = false; |
|
| 1351 | - if ($requeter && $do) { |
|
| 1352 | - return true; |
|
| 1353 | - } |
|
| 1354 | - if ($requeter) { |
|
| 1355 | - $do = true; |
|
| 1356 | - } |
|
| 1357 | - |
|
| 1358 | - return spip_sqlite_query('VACUUM', $serveur, $requeter); |
|
| 1350 | + static $do = false; |
|
| 1351 | + if ($requeter && $do) { |
|
| 1352 | + return true; |
|
| 1353 | + } |
|
| 1354 | + if ($requeter) { |
|
| 1355 | + $do = true; |
|
| 1356 | + } |
|
| 1357 | + |
|
| 1358 | + return spip_sqlite_query('VACUUM', $serveur, $requeter); |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | |
@@ -1372,15 +1372,15 @@ discard block |
||
| 1372 | 1372 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1373 | 1373 | */ |
| 1374 | 1374 | function spip_sqlite_quote($v, $type = '') { |
| 1375 | - if (!is_array($v)) { |
|
| 1376 | - return _sqlite_calculer_cite($v, $type); |
|
| 1377 | - } |
|
| 1378 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1379 | - foreach ($v as $k => $r) { |
|
| 1380 | - $v[$k] = spip_sqlite_quote($r, $type); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - return implode(',', $v); |
|
| 1375 | + if (!is_array($v)) { |
|
| 1376 | + return _sqlite_calculer_cite($v, $type); |
|
| 1377 | + } |
|
| 1378 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1379 | + foreach ($v as $k => $r) { |
|
| 1380 | + $v[$k] = spip_sqlite_quote($r, $type); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + return implode(',', $v); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | |
@@ -1397,9 +1397,9 @@ discard block |
||
| 1397 | 1397 | * Expression SQL |
| 1398 | 1398 | **/ |
| 1399 | 1399 | function spip_sqlite_date_proche($champ, $interval, $unite) { |
| 1400 | - $op = (($interval <= 0) ? '>' : '<'); |
|
| 1400 | + $op = (($interval <= 0) ? '>' : '<'); |
|
| 1401 | 1401 | |
| 1402 | - return "($champ $op datetime('" . date('Y-m-d H:i:s') . "', '$interval $unite'))"; |
|
| 1402 | + return "($champ $op datetime('" . date('Y-m-d H:i:s') . "', '$interval $unite'))"; |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | |
@@ -1417,48 +1417,48 @@ discard block |
||
| 1417 | 1417 | * l'état de la table après la réparation |
| 1418 | 1418 | */ |
| 1419 | 1419 | function spip_sqlite_repair($table, $serveur = '', $requeter = true) { |
| 1420 | - if ( |
|
| 1421 | - ($desc = spip_sqlite_showtable($table, $serveur)) |
|
| 1422 | - && isset($desc['field']) |
|
| 1423 | - && is_array($desc['field']) |
|
| 1424 | - ) { |
|
| 1425 | - foreach ($desc['field'] as $c => $d) { |
|
| 1426 | - if ( |
|
| 1427 | - preg_match(',^(tinytext|mediumtext|text|longtext|varchar|char),i', $d) |
|
| 1428 | - && stripos($d, 'NOT NULL') !== false |
|
| 1429 | - && stripos($d, 'DEFAULT') === false |
|
| 1430 | - /* pas touche aux cles primaires */ |
|
| 1431 | - && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1432 | - ) { |
|
| 1433 | - spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT ''", $serveur); |
|
| 1434 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1435 | - } |
|
| 1436 | - if ( |
|
| 1437 | - preg_match(',^(INTEGER),i', $d) |
|
| 1438 | - && stripos($d, 'NOT NULL') !== false |
|
| 1439 | - && stripos($d, 'DEFAULT') === false |
|
| 1440 | - /* pas touche aux cles primaires */ |
|
| 1441 | - && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1442 | - ) { |
|
| 1443 | - spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0'", $serveur); |
|
| 1444 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1445 | - } |
|
| 1446 | - if ( |
|
| 1447 | - preg_match(',^(datetime),i', $d) |
|
| 1448 | - && stripos($d, 'NOT NULL') !== false |
|
| 1449 | - && stripos($d, 'DEFAULT') === false |
|
| 1450 | - /* pas touche aux cles primaires */ |
|
| 1451 | - && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1452 | - ) { |
|
| 1453 | - spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0000-00-00 00:00:00'", $serveur); |
|
| 1454 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1455 | - } |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - return [' OK ']; |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - return [' ERROR ']; |
|
| 1420 | + if ( |
|
| 1421 | + ($desc = spip_sqlite_showtable($table, $serveur)) |
|
| 1422 | + && isset($desc['field']) |
|
| 1423 | + && is_array($desc['field']) |
|
| 1424 | + ) { |
|
| 1425 | + foreach ($desc['field'] as $c => $d) { |
|
| 1426 | + if ( |
|
| 1427 | + preg_match(',^(tinytext|mediumtext|text|longtext|varchar|char),i', $d) |
|
| 1428 | + && stripos($d, 'NOT NULL') !== false |
|
| 1429 | + && stripos($d, 'DEFAULT') === false |
|
| 1430 | + /* pas touche aux cles primaires */ |
|
| 1431 | + && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1432 | + ) { |
|
| 1433 | + spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT ''", $serveur); |
|
| 1434 | + spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1435 | + } |
|
| 1436 | + if ( |
|
| 1437 | + preg_match(',^(INTEGER),i', $d) |
|
| 1438 | + && stripos($d, 'NOT NULL') !== false |
|
| 1439 | + && stripos($d, 'DEFAULT') === false |
|
| 1440 | + /* pas touche aux cles primaires */ |
|
| 1441 | + && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1442 | + ) { |
|
| 1443 | + spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0'", $serveur); |
|
| 1444 | + spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1445 | + } |
|
| 1446 | + if ( |
|
| 1447 | + preg_match(',^(datetime),i', $d) |
|
| 1448 | + && stripos($d, 'NOT NULL') !== false |
|
| 1449 | + && stripos($d, 'DEFAULT') === false |
|
| 1450 | + /* pas touche aux cles primaires */ |
|
| 1451 | + && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
|
| 1452 | + ) { |
|
| 1453 | + spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0000-00-00 00:00:00'", $serveur); |
|
| 1454 | + spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1455 | + } |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + return [' OK ']; |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + return [' ERROR ']; |
|
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | 1464 | |
@@ -1487,25 +1487,25 @@ discard block |
||
| 1487 | 1487 | * - false en cas d'erreur. |
| 1488 | 1488 | **/ |
| 1489 | 1489 | function spip_sqlite_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1490 | - if (!$desc) { |
|
| 1491 | - $desc = description_table($table, $serveur); |
|
| 1492 | - } |
|
| 1493 | - if (!$desc) { |
|
| 1494 | - die("$table insertion sans description"); |
|
| 1495 | - } |
|
| 1496 | - $fields = $desc['field'] ?? []; |
|
| 1497 | - |
|
| 1498 | - foreach ($couples as $champ => $val) { |
|
| 1499 | - $couples[$champ] = _sqlite_calculer_cite($val, $fields[$champ]); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1503 | - $couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1504 | - |
|
| 1505 | - return spip_sqlite_query("REPLACE INTO $table (" . implode(',', array_keys($couples)) . ') VALUES (' . implode( |
|
| 1506 | - ',', |
|
| 1507 | - $couples |
|
| 1508 | - ) . ')', $serveur); |
|
| 1490 | + if (!$desc) { |
|
| 1491 | + $desc = description_table($table, $serveur); |
|
| 1492 | + } |
|
| 1493 | + if (!$desc) { |
|
| 1494 | + die("$table insertion sans description"); |
|
| 1495 | + } |
|
| 1496 | + $fields = $desc['field'] ?? []; |
|
| 1497 | + |
|
| 1498 | + foreach ($couples as $champ => $val) { |
|
| 1499 | + $couples[$champ] = _sqlite_calculer_cite($val, $fields[$champ]); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1503 | + $couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1504 | + |
|
| 1505 | + return spip_sqlite_query("REPLACE INTO $table (" . implode(',', array_keys($couples)) . ') VALUES (' . implode( |
|
| 1506 | + ',', |
|
| 1507 | + $couples |
|
| 1508 | + ) . ')', $serveur); |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | |
@@ -1535,14 +1535,14 @@ discard block |
||
| 1535 | 1535 | **/ |
| 1536 | 1536 | function spip_sqlite_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1537 | 1537 | |
| 1538 | - $retour = null; |
|
| 1539 | - // boucler pour traiter chaque requete independemment |
|
| 1540 | - foreach ($tab_couples as $couples) { |
|
| 1541 | - $retour = spip_sqlite_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1542 | - } |
|
| 1538 | + $retour = null; |
|
| 1539 | + // boucler pour traiter chaque requete independemment |
|
| 1540 | + foreach ($tab_couples as $couples) { |
|
| 1541 | + $retour = spip_sqlite_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1542 | + } |
|
| 1543 | 1543 | |
| 1544 | - // renvoie le dernier id |
|
| 1545 | - return $retour; |
|
| 1544 | + // renvoie le dernier id |
|
| 1545 | + return $retour; |
|
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | 1548 | |
@@ -1569,44 +1569,44 @@ discard block |
||
| 1569 | 1569 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1570 | 1570 | */ |
| 1571 | 1571 | function spip_sqlite_select( |
| 1572 | - $select, |
|
| 1573 | - $from, |
|
| 1574 | - $where = '', |
|
| 1575 | - $groupby = '', |
|
| 1576 | - $orderby = '', |
|
| 1577 | - $limit = '', |
|
| 1578 | - $having = '', |
|
| 1579 | - $serveur = '', |
|
| 1580 | - $requeter = true |
|
| 1572 | + $select, |
|
| 1573 | + $from, |
|
| 1574 | + $where = '', |
|
| 1575 | + $groupby = '', |
|
| 1576 | + $orderby = '', |
|
| 1577 | + $limit = '', |
|
| 1578 | + $having = '', |
|
| 1579 | + $serveur = '', |
|
| 1580 | + $requeter = true |
|
| 1581 | 1581 | ) { |
| 1582 | 1582 | |
| 1583 | - // version() n'est pas connu de sqlite |
|
| 1584 | - $select = str_replace('version()', 'sqlite_version()', $select); |
|
| 1585 | - |
|
| 1586 | - // recomposer from |
|
| 1587 | - $from = (is_array($from) ? _sqlite_calculer_select_as($from) : $from); |
|
| 1588 | - |
|
| 1589 | - $query = |
|
| 1590 | - _sqlite_calculer_expression('SELECT', $select, ', ') |
|
| 1591 | - . _sqlite_calculer_expression('FROM', $from, ', ') |
|
| 1592 | - . _sqlite_calculer_expression('WHERE', $where) |
|
| 1593 | - . _sqlite_calculer_expression('GROUP BY', $groupby, ',') |
|
| 1594 | - . _sqlite_calculer_expression('HAVING', $having) |
|
| 1595 | - . ($orderby ? ("\nORDER BY " . _sqlite_calculer_order($orderby)) : '') |
|
| 1596 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 1597 | - |
|
| 1598 | - // dans un select, on doit renvoyer la requête en cas d'erreur |
|
| 1599 | - $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1600 | - // texte de la requete demande ? |
|
| 1601 | - if (!$requeter) { |
|
| 1602 | - return $res; |
|
| 1603 | - } |
|
| 1604 | - // erreur survenue ? |
|
| 1605 | - if ($res === false) { |
|
| 1606 | - return Sqlite::traduire_requete($query, $serveur); |
|
| 1607 | - } |
|
| 1608 | - |
|
| 1609 | - return $res; |
|
| 1583 | + // version() n'est pas connu de sqlite |
|
| 1584 | + $select = str_replace('version()', 'sqlite_version()', $select); |
|
| 1585 | + |
|
| 1586 | + // recomposer from |
|
| 1587 | + $from = (is_array($from) ? _sqlite_calculer_select_as($from) : $from); |
|
| 1588 | + |
|
| 1589 | + $query = |
|
| 1590 | + _sqlite_calculer_expression('SELECT', $select, ', ') |
|
| 1591 | + . _sqlite_calculer_expression('FROM', $from, ', ') |
|
| 1592 | + . _sqlite_calculer_expression('WHERE', $where) |
|
| 1593 | + . _sqlite_calculer_expression('GROUP BY', $groupby, ',') |
|
| 1594 | + . _sqlite_calculer_expression('HAVING', $having) |
|
| 1595 | + . ($orderby ? ("\nORDER BY " . _sqlite_calculer_order($orderby)) : '') |
|
| 1596 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 1597 | + |
|
| 1598 | + // dans un select, on doit renvoyer la requête en cas d'erreur |
|
| 1599 | + $res = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1600 | + // texte de la requete demande ? |
|
| 1601 | + if (!$requeter) { |
|
| 1602 | + return $res; |
|
| 1603 | + } |
|
| 1604 | + // erreur survenue ? |
|
| 1605 | + if ($res === false) { |
|
| 1606 | + return Sqlite::traduire_requete($query, $serveur); |
|
| 1607 | + } |
|
| 1608 | + |
|
| 1609 | + return $res; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | |
| 1612 | 1612 | |
@@ -1625,32 +1625,32 @@ discard block |
||
| 1625 | 1625 | * - False en cas d'erreur. |
| 1626 | 1626 | **/ |
| 1627 | 1627 | function spip_sqlite_selectdb($db, $serveur = '', $requeter = true) { |
| 1628 | - _sqlite_init(); |
|
| 1629 | - |
|
| 1630 | - // interdire la creation d'une nouvelle base, |
|
| 1631 | - // sauf si on est dans l'installation |
|
| 1632 | - if ( |
|
| 1633 | - !is_file($f = _DIR_DB . $db . '.sqlite') |
|
| 1634 | - && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL) |
|
| 1635 | - ) { |
|
| 1636 | - spip_log("Il est interdit de creer la base $db", 'sqlite.' . _LOG_HS); |
|
| 1637 | - |
|
| 1638 | - return false; |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - // se connecter a la base indiquee |
|
| 1642 | - // avec les identifiants connus |
|
| 1643 | - $index = $serveur ?: 0; |
|
| 1644 | - |
|
| 1645 | - if ($link = spip_connect_db('', '', '', '', '@selectdb@' . $db, $serveur, '', '')) { |
|
| 1646 | - if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 1647 | - return $db; |
|
| 1648 | - } |
|
| 1649 | - } else { |
|
| 1650 | - spip_log("Impossible de selectionner la base $db", 'sqlite.' . _LOG_HS); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - return false; |
|
| 1628 | + _sqlite_init(); |
|
| 1629 | + |
|
| 1630 | + // interdire la creation d'une nouvelle base, |
|
| 1631 | + // sauf si on est dans l'installation |
|
| 1632 | + if ( |
|
| 1633 | + !is_file($f = _DIR_DB . $db . '.sqlite') |
|
| 1634 | + && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL) |
|
| 1635 | + ) { |
|
| 1636 | + spip_log("Il est interdit de creer la base $db", 'sqlite.' . _LOG_HS); |
|
| 1637 | + |
|
| 1638 | + return false; |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + // se connecter a la base indiquee |
|
| 1642 | + // avec les identifiants connus |
|
| 1643 | + $index = $serveur ?: 0; |
|
| 1644 | + |
|
| 1645 | + if ($link = spip_connect_db('', '', '', '', '@selectdb@' . $db, $serveur, '', '')) { |
|
| 1646 | + if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 1647 | + return $db; |
|
| 1648 | + } |
|
| 1649 | + } else { |
|
| 1650 | + spip_log("Impossible de selectionner la base $db", 'sqlite.' . _LOG_HS); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + return false; |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | |
@@ -1665,8 +1665,8 @@ discard block |
||
| 1665 | 1665 | * @return void |
| 1666 | 1666 | */ |
| 1667 | 1667 | function spip_sqlite_set_charset($charset, $serveur = '', $requeter = true) { |
| 1668 | - # spip_log("Gestion charset sql a ecrire : "."SET NAMES "._q($charset), 'sqlite.'._LOG_ERREUR); |
|
| 1669 | - # return spip_sqlite_query("SET NAMES ". spip_sqlite_quote($charset), $serveur); //<-- Passe pas ! |
|
| 1668 | + # spip_log("Gestion charset sql a ecrire : "."SET NAMES "._q($charset), 'sqlite.'._LOG_ERREUR); |
|
| 1669 | + # return spip_sqlite_query("SET NAMES ". spip_sqlite_quote($charset), $serveur); //<-- Passe pas ! |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | |
@@ -1684,24 +1684,24 @@ discard block |
||
| 1684 | 1684 | * Ressource à utiliser avec sql_fetch() |
| 1685 | 1685 | **/ |
| 1686 | 1686 | function spip_sqlite_showbase($match, $serveur = '', $requeter = true) { |
| 1687 | - // type est le type d'entrée : table / index / view |
|
| 1688 | - // on ne retourne que les tables (?) et non les vues... |
|
| 1689 | - # ESCAPE non supporte par les versions sqlite <3 |
|
| 1690 | - # return spip_sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND tbl_name LIKE "._q($match)." ESCAPE '\'", $serveur, $requeter); |
|
| 1691 | - $match = preg_quote($match); |
|
| 1692 | - $match = str_replace('\\\_', '[[TIRETBAS]]', $match); |
|
| 1693 | - $match = str_replace('\\\%', '[[POURCENT]]', $match); |
|
| 1694 | - $match = str_replace('_', '.', $match); |
|
| 1695 | - $match = str_replace('%', '.*', $match); |
|
| 1696 | - $match = str_replace('[[TIRETBAS]]', '_', $match); |
|
| 1697 | - $match = str_replace('[[POURCENT]]', '%', $match); |
|
| 1698 | - $match = "^$match$"; |
|
| 1699 | - |
|
| 1700 | - return spip_sqlite_query( |
|
| 1701 | - "SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP " . _q($match), |
|
| 1702 | - $serveur, |
|
| 1703 | - $requeter |
|
| 1704 | - ); |
|
| 1687 | + // type est le type d'entrée : table / index / view |
|
| 1688 | + // on ne retourne que les tables (?) et non les vues... |
|
| 1689 | + # ESCAPE non supporte par les versions sqlite <3 |
|
| 1690 | + # return spip_sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND tbl_name LIKE "._q($match)." ESCAPE '\'", $serveur, $requeter); |
|
| 1691 | + $match = preg_quote($match); |
|
| 1692 | + $match = str_replace('\\\_', '[[TIRETBAS]]', $match); |
|
| 1693 | + $match = str_replace('\\\%', '[[POURCENT]]', $match); |
|
| 1694 | + $match = str_replace('_', '.', $match); |
|
| 1695 | + $match = str_replace('%', '.*', $match); |
|
| 1696 | + $match = str_replace('[[TIRETBAS]]', '_', $match); |
|
| 1697 | + $match = str_replace('[[POURCENT]]', '%', $match); |
|
| 1698 | + $match = "^$match$"; |
|
| 1699 | + |
|
| 1700 | + return spip_sqlite_query( |
|
| 1701 | + "SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP " . _q($match), |
|
| 1702 | + $serveur, |
|
| 1703 | + $requeter |
|
| 1704 | + ); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | /** |
@@ -1719,19 +1719,19 @@ discard block |
||
| 1719 | 1719 | * - string : requete sql, si $requeter = true |
| 1720 | 1720 | **/ |
| 1721 | 1721 | function spip_sqlite_table_exists(string $table, $serveur = '', $requeter = true) { |
| 1722 | - $r = spip_sqlite_query( |
|
| 1723 | - 'SELECT name FROM sqlite_master WHERE' |
|
| 1724 | - . ' type=\'table\'' |
|
| 1725 | - . ' AND name=' . spip_sqlite_quote($table, 'string') |
|
| 1726 | - . ' AND name NOT LIKE \'sqlite_%\'', |
|
| 1727 | - $serveur, |
|
| 1728 | - $requeter |
|
| 1729 | - ); |
|
| 1730 | - if (!$requeter) { |
|
| 1731 | - return $r; |
|
| 1732 | - } |
|
| 1733 | - $res = spip_sqlite_fetch($r, '', $serveur); |
|
| 1734 | - return (bool) $res; |
|
| 1722 | + $r = spip_sqlite_query( |
|
| 1723 | + 'SELECT name FROM sqlite_master WHERE' |
|
| 1724 | + . ' type=\'table\'' |
|
| 1725 | + . ' AND name=' . spip_sqlite_quote($table, 'string') |
|
| 1726 | + . ' AND name NOT LIKE \'sqlite_%\'', |
|
| 1727 | + $serveur, |
|
| 1728 | + $requeter |
|
| 1729 | + ); |
|
| 1730 | + if (!$requeter) { |
|
| 1731 | + return $r; |
|
| 1732 | + } |
|
| 1733 | + $res = spip_sqlite_fetch($r, '', $serveur); |
|
| 1734 | + return (bool) $res; |
|
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | 1737 | define('_SQLITE_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -1754,129 +1754,129 @@ discard block |
||
| 1754 | 1754 | * - array description de la table sinon |
| 1755 | 1755 | */ |
| 1756 | 1756 | function spip_sqlite_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1757 | - $query = |
|
| 1758 | - 'SELECT sql, type FROM' |
|
| 1759 | - . ' (SELECT * FROM sqlite_master UNION ALL' |
|
| 1760 | - . ' SELECT * FROM sqlite_temp_master)' |
|
| 1761 | - . " WHERE tbl_name LIKE '$nom_table'" |
|
| 1762 | - . " AND type!='meta' AND sql NOT NULL AND name NOT LIKE 'sqlite_%'" |
|
| 1763 | - . ' ORDER BY substr(type,2,1), name'; |
|
| 1764 | - |
|
| 1765 | - $a = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1766 | - if (!$a) { |
|
| 1767 | - return ''; |
|
| 1768 | - } |
|
| 1769 | - if (!$requeter) { |
|
| 1770 | - return $a; |
|
| 1771 | - } |
|
| 1772 | - if (!($a = spip_sqlite_fetch($a, null, $serveur))) { |
|
| 1773 | - return ''; |
|
| 1774 | - } |
|
| 1775 | - $vue = ($a['type'] == 'view'); // table | vue |
|
| 1776 | - |
|
| 1777 | - // c'est une table |
|
| 1778 | - // il faut parser le create |
|
| 1779 | - if (!$vue) { |
|
| 1780 | - if (!preg_match(_SQLITE_RE_SHOW_TABLE, array_shift($a), $r)) { |
|
| 1781 | - return ''; |
|
| 1782 | - } else { |
|
| 1783 | - $desc = $r[1]; |
|
| 1784 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 1785 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 1786 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 1787 | - $namedkeys = $r[2]; |
|
| 1788 | - $desc = $r[1]; |
|
| 1789 | - } else { |
|
| 1790 | - $namedkeys = ''; |
|
| 1791 | - } |
|
| 1792 | - |
|
| 1793 | - $fields = []; |
|
| 1794 | - $keys = []; |
|
| 1795 | - |
|
| 1796 | - // enlever les contenus des valeurs DEFAULT 'xxx' qui pourraient perturber |
|
| 1797 | - // par exemple s'il contiennent une virgule. |
|
| 1798 | - // /!\ cela peut aussi echapper le nom des champs si la table a eu des operations avec SQLite Manager ! |
|
| 1799 | - [$desc, $echaps] = query_echappe_textes($desc); |
|
| 1800 | - |
|
| 1801 | - // separer toutes les descriptions de champs, separes par des virgules |
|
| 1802 | - # /!\ explode peut exploser aussi DECIMAL(10,2) ! |
|
| 1803 | - $k_precedent = null; |
|
| 1804 | - foreach (explode(',', $desc) as $v) { |
|
| 1805 | - preg_match('/^\s*([^\s]+)\s+(.*)/', $v, $r); |
|
| 1806 | - // Les cles de champs peuvent etre entourees |
|
| 1807 | - // de guillements doubles " , simples ', graves ` ou de crochets [ ], ou rien. |
|
| 1808 | - // http://www.sqlite.org/lang_keywords.html |
|
| 1809 | - $k = strtolower(query_reinjecte_textes($r[1], $echaps)); // champ, "champ", [champ]... |
|
| 1810 | - if ($char = strpbrk($k[0], '\'"[`')) { |
|
| 1811 | - $k = trim($k, $char); |
|
| 1812 | - if ($char == '[') { |
|
| 1813 | - $k = rtrim($k, ']'); |
|
| 1814 | - } |
|
| 1815 | - } |
|
| 1816 | - $def = query_reinjecte_textes($r[2], $echaps); // valeur du champ |
|
| 1817 | - |
|
| 1818 | - // rustine pour DECIMAL(10,2) |
|
| 1819 | - // s'il y a une parenthèse fermante dans la clé |
|
| 1820 | - // ou dans la définition sans qu'il n'y ait une ouverture avant |
|
| 1821 | - if (str_contains($k, ')') || preg_match('/^[^\(]*\)/', $def)) { |
|
| 1822 | - $fields[$k_precedent] .= ',' . $k . ' ' . $def; |
|
| 1823 | - continue; |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - // la primary key peut etre dans une des descriptions de champs |
|
| 1827 | - // et non en fin de table, cas encore decouvert avec Sqlite Manager |
|
| 1828 | - if (stripos($r[2], 'PRIMARY KEY') !== false) { |
|
| 1829 | - $keys['PRIMARY KEY'] = $k; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - $fields[$k] = $def; |
|
| 1833 | - $k_precedent = $k; |
|
| 1834 | - } |
|
| 1835 | - // key inclues dans la requete |
|
| 1836 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 1837 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 1838 | - $k = str_replace('`', '', trim($r[1])); |
|
| 1839 | - $t = trim(strtolower(str_replace('`', '', $r[2])), '"'); |
|
| 1840 | - if ($k && !isset($keys[$k])) { |
|
| 1841 | - $keys[$k] = $t; |
|
| 1842 | - } else { |
|
| 1843 | - $keys[] = $t; |
|
| 1844 | - } |
|
| 1845 | - } |
|
| 1846 | - } |
|
| 1847 | - // sinon ajouter les key index |
|
| 1848 | - $query = |
|
| 1849 | - 'SELECT name,sql FROM' |
|
| 1850 | - . ' (SELECT * FROM sqlite_master UNION ALL' |
|
| 1851 | - . ' SELECT * FROM sqlite_temp_master)' |
|
| 1852 | - . " WHERE tbl_name LIKE '$nom_table'" |
|
| 1853 | - . " AND type='index' AND name NOT LIKE 'sqlite_%'" |
|
| 1854 | - . 'ORDER BY substr(type,2,1), name'; |
|
| 1855 | - $a = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1856 | - while ($r = spip_sqlite_fetch($a, null, $serveur)) { |
|
| 1857 | - $key = str_replace($nom_table . '_', '', $r['name']); // enlever le nom de la table ajoute a l'index |
|
| 1858 | - $keytype = 'KEY'; |
|
| 1859 | - if (str_contains($r['sql'], 'UNIQUE INDEX')) { |
|
| 1860 | - $keytype = 'UNIQUE KEY'; |
|
| 1861 | - } |
|
| 1862 | - $colonnes = preg_replace(',.*\((.*)\).*,', '$1', $r['sql']); |
|
| 1863 | - $keys[$keytype . ' ' . $key] = $colonnes; |
|
| 1864 | - } |
|
| 1865 | - } |
|
| 1866 | - } // c'est une vue, on liste les champs disponibles simplement |
|
| 1867 | - else { |
|
| 1868 | - if ($res = sql_fetsel('*', $nom_table, '', '', '', '1', '', $serveur)) { // limit 1 |
|
| 1869 | - $fields = []; |
|
| 1870 | - foreach ($res as $c => $v) { |
|
| 1871 | - $fields[$c] = ''; |
|
| 1872 | - } |
|
| 1873 | - $keys = []; |
|
| 1874 | - } else { |
|
| 1875 | - return ''; |
|
| 1876 | - } |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - return ['field' => $fields, 'key' => $keys]; |
|
| 1757 | + $query = |
|
| 1758 | + 'SELECT sql, type FROM' |
|
| 1759 | + . ' (SELECT * FROM sqlite_master UNION ALL' |
|
| 1760 | + . ' SELECT * FROM sqlite_temp_master)' |
|
| 1761 | + . " WHERE tbl_name LIKE '$nom_table'" |
|
| 1762 | + . " AND type!='meta' AND sql NOT NULL AND name NOT LIKE 'sqlite_%'" |
|
| 1763 | + . ' ORDER BY substr(type,2,1), name'; |
|
| 1764 | + |
|
| 1765 | + $a = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1766 | + if (!$a) { |
|
| 1767 | + return ''; |
|
| 1768 | + } |
|
| 1769 | + if (!$requeter) { |
|
| 1770 | + return $a; |
|
| 1771 | + } |
|
| 1772 | + if (!($a = spip_sqlite_fetch($a, null, $serveur))) { |
|
| 1773 | + return ''; |
|
| 1774 | + } |
|
| 1775 | + $vue = ($a['type'] == 'view'); // table | vue |
|
| 1776 | + |
|
| 1777 | + // c'est une table |
|
| 1778 | + // il faut parser le create |
|
| 1779 | + if (!$vue) { |
|
| 1780 | + if (!preg_match(_SQLITE_RE_SHOW_TABLE, array_shift($a), $r)) { |
|
| 1781 | + return ''; |
|
| 1782 | + } else { |
|
| 1783 | + $desc = $r[1]; |
|
| 1784 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 1785 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 1786 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 1787 | + $namedkeys = $r[2]; |
|
| 1788 | + $desc = $r[1]; |
|
| 1789 | + } else { |
|
| 1790 | + $namedkeys = ''; |
|
| 1791 | + } |
|
| 1792 | + |
|
| 1793 | + $fields = []; |
|
| 1794 | + $keys = []; |
|
| 1795 | + |
|
| 1796 | + // enlever les contenus des valeurs DEFAULT 'xxx' qui pourraient perturber |
|
| 1797 | + // par exemple s'il contiennent une virgule. |
|
| 1798 | + // /!\ cela peut aussi echapper le nom des champs si la table a eu des operations avec SQLite Manager ! |
|
| 1799 | + [$desc, $echaps] = query_echappe_textes($desc); |
|
| 1800 | + |
|
| 1801 | + // separer toutes les descriptions de champs, separes par des virgules |
|
| 1802 | + # /!\ explode peut exploser aussi DECIMAL(10,2) ! |
|
| 1803 | + $k_precedent = null; |
|
| 1804 | + foreach (explode(',', $desc) as $v) { |
|
| 1805 | + preg_match('/^\s*([^\s]+)\s+(.*)/', $v, $r); |
|
| 1806 | + // Les cles de champs peuvent etre entourees |
|
| 1807 | + // de guillements doubles " , simples ', graves ` ou de crochets [ ], ou rien. |
|
| 1808 | + // http://www.sqlite.org/lang_keywords.html |
|
| 1809 | + $k = strtolower(query_reinjecte_textes($r[1], $echaps)); // champ, "champ", [champ]... |
|
| 1810 | + if ($char = strpbrk($k[0], '\'"[`')) { |
|
| 1811 | + $k = trim($k, $char); |
|
| 1812 | + if ($char == '[') { |
|
| 1813 | + $k = rtrim($k, ']'); |
|
| 1814 | + } |
|
| 1815 | + } |
|
| 1816 | + $def = query_reinjecte_textes($r[2], $echaps); // valeur du champ |
|
| 1817 | + |
|
| 1818 | + // rustine pour DECIMAL(10,2) |
|
| 1819 | + // s'il y a une parenthèse fermante dans la clé |
|
| 1820 | + // ou dans la définition sans qu'il n'y ait une ouverture avant |
|
| 1821 | + if (str_contains($k, ')') || preg_match('/^[^\(]*\)/', $def)) { |
|
| 1822 | + $fields[$k_precedent] .= ',' . $k . ' ' . $def; |
|
| 1823 | + continue; |
|
| 1824 | + } |
|
| 1825 | + |
|
| 1826 | + // la primary key peut etre dans une des descriptions de champs |
|
| 1827 | + // et non en fin de table, cas encore decouvert avec Sqlite Manager |
|
| 1828 | + if (stripos($r[2], 'PRIMARY KEY') !== false) { |
|
| 1829 | + $keys['PRIMARY KEY'] = $k; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + $fields[$k] = $def; |
|
| 1833 | + $k_precedent = $k; |
|
| 1834 | + } |
|
| 1835 | + // key inclues dans la requete |
|
| 1836 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 1837 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 1838 | + $k = str_replace('`', '', trim($r[1])); |
|
| 1839 | + $t = trim(strtolower(str_replace('`', '', $r[2])), '"'); |
|
| 1840 | + if ($k && !isset($keys[$k])) { |
|
| 1841 | + $keys[$k] = $t; |
|
| 1842 | + } else { |
|
| 1843 | + $keys[] = $t; |
|
| 1844 | + } |
|
| 1845 | + } |
|
| 1846 | + } |
|
| 1847 | + // sinon ajouter les key index |
|
| 1848 | + $query = |
|
| 1849 | + 'SELECT name,sql FROM' |
|
| 1850 | + . ' (SELECT * FROM sqlite_master UNION ALL' |
|
| 1851 | + . ' SELECT * FROM sqlite_temp_master)' |
|
| 1852 | + . " WHERE tbl_name LIKE '$nom_table'" |
|
| 1853 | + . " AND type='index' AND name NOT LIKE 'sqlite_%'" |
|
| 1854 | + . 'ORDER BY substr(type,2,1), name'; |
|
| 1855 | + $a = spip_sqlite_query($query, $serveur, $requeter); |
|
| 1856 | + while ($r = spip_sqlite_fetch($a, null, $serveur)) { |
|
| 1857 | + $key = str_replace($nom_table . '_', '', $r['name']); // enlever le nom de la table ajoute a l'index |
|
| 1858 | + $keytype = 'KEY'; |
|
| 1859 | + if (str_contains($r['sql'], 'UNIQUE INDEX')) { |
|
| 1860 | + $keytype = 'UNIQUE KEY'; |
|
| 1861 | + } |
|
| 1862 | + $colonnes = preg_replace(',.*\((.*)\).*,', '$1', $r['sql']); |
|
| 1863 | + $keys[$keytype . ' ' . $key] = $colonnes; |
|
| 1864 | + } |
|
| 1865 | + } |
|
| 1866 | + } // c'est une vue, on liste les champs disponibles simplement |
|
| 1867 | + else { |
|
| 1868 | + if ($res = sql_fetsel('*', $nom_table, '', '', '', '1', '', $serveur)) { // limit 1 |
|
| 1869 | + $fields = []; |
|
| 1870 | + foreach ($res as $c => $v) { |
|
| 1871 | + $fields[$c] = ''; |
|
| 1872 | + } |
|
| 1873 | + $keys = []; |
|
| 1874 | + } else { |
|
| 1875 | + return ''; |
|
| 1876 | + } |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + return ['field' => $fields, 'key' => $keys]; |
|
| 1880 | 1880 | } |
| 1881 | 1881 | |
| 1882 | 1882 | |
@@ -1902,24 +1902,24 @@ discard block |
||
| 1902 | 1902 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1903 | 1903 | */ |
| 1904 | 1904 | function spip_sqlite_update($table, $champs, $where = '', $desc = '', $serveur = '', $requeter = true) { |
| 1905 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1906 | - $champs = _sqlite_ajouter_champs_timestamp($table, $champs, $desc, $serveur); |
|
| 1907 | - |
|
| 1908 | - $set = []; |
|
| 1909 | - foreach ($champs as $champ => $val) { |
|
| 1910 | - $set[] = $champ . "=$val"; |
|
| 1911 | - } |
|
| 1912 | - if ($set !== []) { |
|
| 1913 | - return spip_sqlite_query( |
|
| 1914 | - _sqlite_calculer_expression('UPDATE', $table, ',') |
|
| 1915 | - . _sqlite_calculer_expression('SET', $set, ',') |
|
| 1916 | - . _sqlite_calculer_expression('WHERE', $where), |
|
| 1917 | - $serveur, |
|
| 1918 | - $requeter |
|
| 1919 | - ); |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - return false; |
|
| 1905 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1906 | + $champs = _sqlite_ajouter_champs_timestamp($table, $champs, $desc, $serveur); |
|
| 1907 | + |
|
| 1908 | + $set = []; |
|
| 1909 | + foreach ($champs as $champ => $val) { |
|
| 1910 | + $set[] = $champ . "=$val"; |
|
| 1911 | + } |
|
| 1912 | + if ($set !== []) { |
|
| 1913 | + return spip_sqlite_query( |
|
| 1914 | + _sqlite_calculer_expression('UPDATE', $table, ',') |
|
| 1915 | + . _sqlite_calculer_expression('SET', $set, ',') |
|
| 1916 | + . _sqlite_calculer_expression('WHERE', $where), |
|
| 1917 | + $serveur, |
|
| 1918 | + $requeter |
|
| 1919 | + ); |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + return false; |
|
| 1923 | 1923 | } |
| 1924 | 1924 | |
| 1925 | 1925 | |
@@ -1949,38 +1949,38 @@ discard block |
||
| 1949 | 1949 | */ |
| 1950 | 1950 | function spip_sqlite_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1951 | 1951 | |
| 1952 | - if (!$champs) { |
|
| 1953 | - return; |
|
| 1954 | - } |
|
| 1955 | - if (!$desc) { |
|
| 1956 | - $desc = description_table($table, $serveur); |
|
| 1957 | - } |
|
| 1958 | - if (!$desc) { |
|
| 1959 | - die("$table insertion sans description"); |
|
| 1960 | - } |
|
| 1961 | - $fields = $desc['field']; |
|
| 1962 | - |
|
| 1963 | - $set = []; |
|
| 1964 | - foreach ($champs as $champ => $val) { |
|
| 1965 | - $set[$champ] = $champ . '=' . _sqlite_calculer_cite($val, $fields[$champ] ?? ''); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1969 | - // attention ils sont deja quotes |
|
| 1970 | - $maj = _sqlite_ajouter_champs_timestamp($table, [], $desc, $serveur); |
|
| 1971 | - foreach ($maj as $champ => $val) { |
|
| 1972 | - if (!isset($set[$champ])) { |
|
| 1973 | - $set[$champ] = $champ . '=' . $val; |
|
| 1974 | - } |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - return spip_sqlite_query( |
|
| 1978 | - _sqlite_calculer_expression('UPDATE', $table, ',') |
|
| 1979 | - . _sqlite_calculer_expression('SET', $set, ',') |
|
| 1980 | - . _sqlite_calculer_expression('WHERE', $where), |
|
| 1981 | - $serveur, |
|
| 1982 | - $requeter |
|
| 1983 | - ); |
|
| 1952 | + if (!$champs) { |
|
| 1953 | + return; |
|
| 1954 | + } |
|
| 1955 | + if (!$desc) { |
|
| 1956 | + $desc = description_table($table, $serveur); |
|
| 1957 | + } |
|
| 1958 | + if (!$desc) { |
|
| 1959 | + die("$table insertion sans description"); |
|
| 1960 | + } |
|
| 1961 | + $fields = $desc['field']; |
|
| 1962 | + |
|
| 1963 | + $set = []; |
|
| 1964 | + foreach ($champs as $champ => $val) { |
|
| 1965 | + $set[$champ] = $champ . '=' . _sqlite_calculer_cite($val, $fields[$champ] ?? ''); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1969 | + // attention ils sont deja quotes |
|
| 1970 | + $maj = _sqlite_ajouter_champs_timestamp($table, [], $desc, $serveur); |
|
| 1971 | + foreach ($maj as $champ => $val) { |
|
| 1972 | + if (!isset($set[$champ])) { |
|
| 1973 | + $set[$champ] = $champ . '=' . $val; |
|
| 1974 | + } |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + return spip_sqlite_query( |
|
| 1978 | + _sqlite_calculer_expression('UPDATE', $table, ',') |
|
| 1979 | + . _sqlite_calculer_expression('SET', $set, ',') |
|
| 1980 | + . _sqlite_calculer_expression('WHERE', $where), |
|
| 1981 | + $serveur, |
|
| 1982 | + $requeter |
|
| 1983 | + ); |
|
| 1984 | 1984 | } |
| 1985 | 1985 | |
| 1986 | 1986 | |
@@ -1998,17 +1998,17 @@ discard block |
||
| 1998 | 1998 | * @return void |
| 1999 | 1999 | */ |
| 2000 | 2000 | function _sqlite_init() { |
| 2001 | - if (!defined('_DIR_DB')) { |
|
| 2002 | - define('_DIR_DB', _DIR_ETC . 'bases/'); |
|
| 2003 | - } |
|
| 2004 | - if (!defined('_SQLITE_CHMOD')) { |
|
| 2005 | - define('_SQLITE_CHMOD', _SPIP_CHMOD); |
|
| 2006 | - } |
|
| 2007 | - |
|
| 2008 | - if (!is_dir($d = _DIR_DB)) { |
|
| 2009 | - include_spip('inc/flock'); |
|
| 2010 | - sous_repertoire($d); |
|
| 2011 | - } |
|
| 2001 | + if (!defined('_DIR_DB')) { |
|
| 2002 | + define('_DIR_DB', _DIR_ETC . 'bases/'); |
|
| 2003 | + } |
|
| 2004 | + if (!defined('_SQLITE_CHMOD')) { |
|
| 2005 | + define('_SQLITE_CHMOD', _SPIP_CHMOD); |
|
| 2006 | + } |
|
| 2007 | + |
|
| 2008 | + if (!is_dir($d = _DIR_DB)) { |
|
| 2009 | + include_spip('inc/flock'); |
|
| 2010 | + sous_repertoire($d); |
|
| 2011 | + } |
|
| 2012 | 2012 | } |
| 2013 | 2013 | |
| 2014 | 2014 | |
@@ -2022,20 +2022,20 @@ discard block |
||
| 2022 | 2022 | * @return bool|int |
| 2023 | 2023 | */ |
| 2024 | 2024 | function _sqlite_is_version($version = '', $link = '', $serveur = '', $requeter = true) { |
| 2025 | - if ($link === '') { |
|
| 2026 | - $link = _sqlite_link($serveur); |
|
| 2027 | - } |
|
| 2028 | - if (!$link) { |
|
| 2029 | - return false; |
|
| 2030 | - } |
|
| 2025 | + if ($link === '') { |
|
| 2026 | + $link = _sqlite_link($serveur); |
|
| 2027 | + } |
|
| 2028 | + if (!$link) { |
|
| 2029 | + return false; |
|
| 2030 | + } |
|
| 2031 | 2031 | |
| 2032 | - $v = 3; |
|
| 2032 | + $v = 3; |
|
| 2033 | 2033 | |
| 2034 | - if (!$version) { |
|
| 2035 | - return $v; |
|
| 2036 | - } |
|
| 2034 | + if (!$version) { |
|
| 2035 | + return $v; |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | - return ($version == $v); |
|
| 2038 | + return ($version == $v); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | 2041 | |
@@ -2046,9 +2046,9 @@ discard block |
||
| 2046 | 2046 | * @return \PDO|null Information de connexion pour SQLite |
| 2047 | 2047 | */ |
| 2048 | 2048 | function _sqlite_link($serveur = ''): ?\PDO { |
| 2049 | - $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 2049 | + $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 2050 | 2050 | |
| 2051 | - return $link; |
|
| 2051 | + return $link; |
|
| 2052 | 2052 | } |
| 2053 | 2053 | |
| 2054 | 2054 | |
@@ -2063,51 +2063,51 @@ discard block |
||
| 2063 | 2063 | * @return string|number texte ou nombre échappé |
| 2064 | 2064 | */ |
| 2065 | 2065 | function _sqlite_calculer_cite($v, $type) { |
| 2066 | - if ($type) { |
|
| 2067 | - if (is_null($v) && stripos($type, 'NOT NULL') === false) { |
|
| 2068 | - // null php se traduit en NULL SQL |
|
| 2069 | - return 'NULL'; |
|
| 2070 | - } |
|
| 2071 | - |
|
| 2072 | - if (sql_test_date($type) && preg_match('/^\w+\(/', $v)) { |
|
| 2073 | - return $v; |
|
| 2074 | - } |
|
| 2075 | - if (sql_test_int($type)) { |
|
| 2076 | - if (is_numeric($v)) { |
|
| 2077 | - return $v; |
|
| 2078 | - } elseif ($v === null) { |
|
| 2079 | - return 0; |
|
| 2080 | - } elseif (ctype_xdigit(substr($v, 2)) && str_starts_with($v, '0x')) { |
|
| 2081 | - return hexdec(substr($v, 2)); |
|
| 2082 | - } else { |
|
| 2083 | - return (int) $v; |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2086 | - } else { |
|
| 2087 | - // si on ne connait pas le type on le deduit de $v autant que possible |
|
| 2088 | - if (is_bool($v)) { |
|
| 2089 | - return (string) (int) $v; |
|
| 2090 | - } elseif (is_numeric($v)) { |
|
| 2091 | - return (string) $v; |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - |
|
| 2095 | - // trouver un link sqlite pour faire l'echappement |
|
| 2096 | - foreach ($GLOBALS['connexions'] as $s) { |
|
| 2097 | - if ( |
|
| 2098 | - ($l = $s['link']) |
|
| 2099 | - && is_object($l) |
|
| 2100 | - && $l instanceof \PDO |
|
| 2101 | - && $l->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'sqlite' |
|
| 2102 | - ) { |
|
| 2103 | - return $l->quote($v ?? ''); |
|
| 2104 | - } |
|
| 2105 | - } |
|
| 2106 | - |
|
| 2107 | - // echapper les ' en '' |
|
| 2108 | - spip_log('Pas de methode ->quote pour echapper', 'sqlite.' . _LOG_INFO_IMPORTANTE); |
|
| 2109 | - |
|
| 2110 | - return ("'" . str_replace("'", "''", $v) . "'"); |
|
| 2066 | + if ($type) { |
|
| 2067 | + if (is_null($v) && stripos($type, 'NOT NULL') === false) { |
|
| 2068 | + // null php se traduit en NULL SQL |
|
| 2069 | + return 'NULL'; |
|
| 2070 | + } |
|
| 2071 | + |
|
| 2072 | + if (sql_test_date($type) && preg_match('/^\w+\(/', $v)) { |
|
| 2073 | + return $v; |
|
| 2074 | + } |
|
| 2075 | + if (sql_test_int($type)) { |
|
| 2076 | + if (is_numeric($v)) { |
|
| 2077 | + return $v; |
|
| 2078 | + } elseif ($v === null) { |
|
| 2079 | + return 0; |
|
| 2080 | + } elseif (ctype_xdigit(substr($v, 2)) && str_starts_with($v, '0x')) { |
|
| 2081 | + return hexdec(substr($v, 2)); |
|
| 2082 | + } else { |
|
| 2083 | + return (int) $v; |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | + } else { |
|
| 2087 | + // si on ne connait pas le type on le deduit de $v autant que possible |
|
| 2088 | + if (is_bool($v)) { |
|
| 2089 | + return (string) (int) $v; |
|
| 2090 | + } elseif (is_numeric($v)) { |
|
| 2091 | + return (string) $v; |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + |
|
| 2095 | + // trouver un link sqlite pour faire l'echappement |
|
| 2096 | + foreach ($GLOBALS['connexions'] as $s) { |
|
| 2097 | + if ( |
|
| 2098 | + ($l = $s['link']) |
|
| 2099 | + && is_object($l) |
|
| 2100 | + && $l instanceof \PDO |
|
| 2101 | + && $l->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'sqlite' |
|
| 2102 | + ) { |
|
| 2103 | + return $l->quote($v ?? ''); |
|
| 2104 | + } |
|
| 2105 | + } |
|
| 2106 | + |
|
| 2107 | + // echapper les ' en '' |
|
| 2108 | + spip_log('Pas de methode ->quote pour echapper', 'sqlite.' . _LOG_INFO_IMPORTANTE); |
|
| 2109 | + |
|
| 2110 | + return ("'" . str_replace("'", "''", $v) . "'"); |
|
| 2111 | 2111 | } |
| 2112 | 2112 | |
| 2113 | 2113 | |
@@ -2123,21 +2123,21 @@ discard block |
||
| 2123 | 2123 | * @return string texte de l'expression, une partie donc, du texte la requête. |
| 2124 | 2124 | */ |
| 2125 | 2125 | function _sqlite_calculer_expression($expression, $v, $join = 'AND') { |
| 2126 | - if (empty($v)) { |
|
| 2127 | - return ''; |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - $exp = "\n$expression "; |
|
| 2131 | - |
|
| 2132 | - if (!is_array($v)) { |
|
| 2133 | - return $exp . $v; |
|
| 2134 | - } else { |
|
| 2135 | - if (strtoupper($join) === 'AND') { |
|
| 2136 | - return $exp . implode("\n\t$join ", array_map('_sqlite_calculer_where', $v)); |
|
| 2137 | - } else { |
|
| 2138 | - return $exp . implode($join, $v); |
|
| 2139 | - } |
|
| 2140 | - } |
|
| 2126 | + if (empty($v)) { |
|
| 2127 | + return ''; |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + $exp = "\n$expression "; |
|
| 2131 | + |
|
| 2132 | + if (!is_array($v)) { |
|
| 2133 | + return $exp . $v; |
|
| 2134 | + } else { |
|
| 2135 | + if (strtoupper($join) === 'AND') { |
|
| 2136 | + return $exp . implode("\n\t$join ", array_map('_sqlite_calculer_where', $v)); |
|
| 2137 | + } else { |
|
| 2138 | + return $exp . implode($join, $v); |
|
| 2139 | + } |
|
| 2140 | + } |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | |
@@ -2153,7 +2153,7 @@ discard block |
||
| 2153 | 2153 | * @return string texte du orderby préparé |
| 2154 | 2154 | */ |
| 2155 | 2155 | function _sqlite_calculer_order($orderby) { |
| 2156 | - return (is_array($orderby)) ? implode(', ', $orderby) : $orderby; |
|
| 2156 | + return (is_array($orderby)) ? implode(', ', $orderby) : $orderby; |
|
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | 2159 | |
@@ -2164,26 +2164,26 @@ discard block |
||
| 2164 | 2164 | * @return string Sélection de colonnes pour une clause SELECT |
| 2165 | 2165 | */ |
| 2166 | 2166 | function _sqlite_calculer_select_as($args) { |
| 2167 | - $res = ''; |
|
| 2168 | - foreach ($args as $k => $v) { |
|
| 2169 | - if (str_ends_with($k, '@')) { |
|
| 2170 | - // c'est une jointure qui se refere au from precedent |
|
| 2171 | - // pas de virgule |
|
| 2172 | - $res .= ' ' . $v; |
|
| 2173 | - } else { |
|
| 2174 | - if (!is_numeric($k)) { |
|
| 2175 | - $p = strpos($v, ' '); |
|
| 2176 | - if ($p) { |
|
| 2177 | - $v = substr($v, 0, $p) . " AS '$k'" . substr($v, $p); |
|
| 2178 | - } else { |
|
| 2179 | - $v .= " AS '$k'"; |
|
| 2180 | - } |
|
| 2181 | - } |
|
| 2182 | - $res .= ', ' . $v; |
|
| 2183 | - } |
|
| 2184 | - } |
|
| 2185 | - |
|
| 2186 | - return substr($res, 2); |
|
| 2167 | + $res = ''; |
|
| 2168 | + foreach ($args as $k => $v) { |
|
| 2169 | + if (str_ends_with($k, '@')) { |
|
| 2170 | + // c'est une jointure qui se refere au from precedent |
|
| 2171 | + // pas de virgule |
|
| 2172 | + $res .= ' ' . $v; |
|
| 2173 | + } else { |
|
| 2174 | + if (!is_numeric($k)) { |
|
| 2175 | + $p = strpos($v, ' '); |
|
| 2176 | + if ($p) { |
|
| 2177 | + $v = substr($v, 0, $p) . " AS '$k'" . substr($v, $p); |
|
| 2178 | + } else { |
|
| 2179 | + $v .= " AS '$k'"; |
|
| 2180 | + } |
|
| 2181 | + } |
|
| 2182 | + $res .= ', ' . $v; |
|
| 2183 | + } |
|
| 2184 | + } |
|
| 2185 | + |
|
| 2186 | + return substr($res, 2); |
|
| 2187 | 2187 | } |
| 2188 | 2188 | |
| 2189 | 2189 | |
@@ -2206,26 +2206,26 @@ discard block |
||
| 2206 | 2206 | * Contrainte pour clause WHERE |
| 2207 | 2207 | */ |
| 2208 | 2208 | function _sqlite_calculer_where($v) { |
| 2209 | - if (!is_array($v)) { |
|
| 2210 | - return $v; |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - $op = array_shift($v); |
|
| 2214 | - if (!($n = count($v))) { |
|
| 2215 | - return $op; |
|
| 2216 | - } else { |
|
| 2217 | - $arg = _sqlite_calculer_where(array_shift($v)); |
|
| 2218 | - if ($n == 1) { |
|
| 2219 | - return "$op($arg)"; |
|
| 2220 | - } else { |
|
| 2221 | - $arg2 = _sqlite_calculer_where(array_shift($v)); |
|
| 2222 | - if ($n == 2) { |
|
| 2223 | - return "($arg $op $arg2)"; |
|
| 2224 | - } else { |
|
| 2225 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 2226 | - } |
|
| 2227 | - } |
|
| 2228 | - } |
|
| 2209 | + if (!is_array($v)) { |
|
| 2210 | + return $v; |
|
| 2211 | + } |
|
| 2212 | + |
|
| 2213 | + $op = array_shift($v); |
|
| 2214 | + if (!($n = count($v))) { |
|
| 2215 | + return $op; |
|
| 2216 | + } else { |
|
| 2217 | + $arg = _sqlite_calculer_where(array_shift($v)); |
|
| 2218 | + if ($n == 1) { |
|
| 2219 | + return "$op($arg)"; |
|
| 2220 | + } else { |
|
| 2221 | + $arg2 = _sqlite_calculer_where(array_shift($v)); |
|
| 2222 | + if ($n == 2) { |
|
| 2223 | + return "($arg $op $arg2)"; |
|
| 2224 | + } else { |
|
| 2225 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 2226 | + } |
|
| 2227 | + } |
|
| 2228 | + } |
|
| 2229 | 2229 | } |
| 2230 | 2230 | |
| 2231 | 2231 | |
@@ -2240,17 +2240,17 @@ discard block |
||
| 2240 | 2240 | * @return array|bool |
| 2241 | 2241 | */ |
| 2242 | 2242 | function _sqlite_charger_version($version = '') { |
| 2243 | - $versions = []; |
|
| 2243 | + $versions = []; |
|
| 2244 | 2244 | |
| 2245 | - // version 3 |
|
| 2246 | - if ((!$version || $version == 3) && (extension_loaded('pdo') && extension_loaded('pdo_sqlite'))) { |
|
| 2247 | - $versions[] = 3; |
|
| 2248 | - } |
|
| 2249 | - if ($version) { |
|
| 2250 | - return in_array($version, $versions); |
|
| 2251 | - } |
|
| 2245 | + // version 3 |
|
| 2246 | + if ((!$version || $version == 3) && (extension_loaded('pdo') && extension_loaded('pdo_sqlite'))) { |
|
| 2247 | + $versions[] = 3; |
|
| 2248 | + } |
|
| 2249 | + if ($version) { |
|
| 2250 | + return in_array($version, $versions); |
|
| 2251 | + } |
|
| 2252 | 2252 | |
| 2253 | - return $versions; |
|
| 2253 | + return $versions; |
|
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | 2256 | |
@@ -2288,147 +2288,147 @@ discard block |
||
| 2288 | 2288 | */ |
| 2289 | 2289 | function _sqlite_modifier_table($table, $colonne, $opt = [], $serveur = '') { |
| 2290 | 2290 | |
| 2291 | - if (is_array($table)) { |
|
| 2292 | - $table_destination = reset($table); |
|
| 2293 | - $table_origine = key($table); |
|
| 2294 | - } else { |
|
| 2295 | - $table_origine = $table_destination = $table; |
|
| 2296 | - } |
|
| 2297 | - // ne prend actuellement qu'un changement |
|
| 2298 | - // mais pourra etre adapte pour changer plus qu'une colonne a la fois |
|
| 2299 | - if (is_array($colonne)) { |
|
| 2300 | - $colonne_destination = reset($colonne); |
|
| 2301 | - $colonne_origine = key($colonne); |
|
| 2302 | - } else { |
|
| 2303 | - $colonne_origine = $colonne_destination = $colonne; |
|
| 2304 | - } |
|
| 2305 | - if (!isset($opt['field'])) { |
|
| 2306 | - $opt['field'] = []; |
|
| 2307 | - } |
|
| 2308 | - if (!isset($opt['key'])) { |
|
| 2309 | - $opt['key'] = []; |
|
| 2310 | - } |
|
| 2311 | - |
|
| 2312 | - // si les noms de tables sont differents, pas besoin de table temporaire |
|
| 2313 | - // on prendra directement le nom de la future table |
|
| 2314 | - $meme_table = ($table_origine == $table_destination); |
|
| 2315 | - |
|
| 2316 | - $def_origine = sql_showtable($table_origine, false, $serveur); |
|
| 2317 | - if (!$def_origine || !isset($def_origine['field'])) { |
|
| 2318 | - spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite' . _LOG_ERREUR); |
|
| 2319 | - |
|
| 2320 | - return false; |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - |
|
| 2324 | - $table_tmp = $table_origine . '_tmp'; |
|
| 2325 | - |
|
| 2326 | - // 1) creer une table temporaire avec les modifications |
|
| 2327 | - // - DROP : suppression de la colonne |
|
| 2328 | - // - CHANGE : modification de la colonne |
|
| 2329 | - // (foreach pour conserver l'ordre des champs) |
|
| 2330 | - |
|
| 2331 | - // field |
|
| 2332 | - $fields = []; |
|
| 2333 | - // pour le INSERT INTO plus loin |
|
| 2334 | - // stocker la correspondance nouvelles->anciennes colonnes |
|
| 2335 | - $fields_correspondances = []; |
|
| 2336 | - foreach ($def_origine['field'] as $c => $d) { |
|
| 2337 | - if ($colonne_origine && ($c == $colonne_origine)) { |
|
| 2338 | - // si pas DROP |
|
| 2339 | - if ($colonne_destination) { |
|
| 2340 | - $fields[$colonne_destination] = $opt['field'][$colonne_destination]; |
|
| 2341 | - $fields_correspondances[$colonne_destination] = $c; |
|
| 2342 | - } |
|
| 2343 | - } else { |
|
| 2344 | - $fields[$c] = $d; |
|
| 2345 | - $fields_correspondances[$c] = $c; |
|
| 2346 | - } |
|
| 2347 | - } |
|
| 2348 | - // cas de ADD sqlite2 (ajout du champ en fin de table): |
|
| 2349 | - if (!$colonne_origine && $colonne_destination) { |
|
| 2350 | - $fields[$colonne_destination] = $opt['field'][$colonne_destination]; |
|
| 2351 | - } |
|
| 2352 | - |
|
| 2353 | - // key... |
|
| 2354 | - $keys = []; |
|
| 2355 | - foreach ($def_origine['key'] as $c => $d) { |
|
| 2356 | - $c = str_replace($colonne_origine, $colonne_destination, $c); |
|
| 2357 | - $d = str_replace($colonne_origine, $colonne_destination, $d); |
|
| 2358 | - // seulement si on ne supprime pas la colonne ! |
|
| 2359 | - if ($d) { |
|
| 2360 | - $keys[$c] = $d; |
|
| 2361 | - } |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - // autres keys, on merge |
|
| 2365 | - $keys = array_merge($keys, $opt['key']); |
|
| 2366 | - $queries = []; |
|
| 2367 | - |
|
| 2368 | - // copier dans destination (si differente de origine), sinon tmp |
|
| 2369 | - $table_copie = ($meme_table) ? $table_tmp : $table_destination; |
|
| 2370 | - $autoinc = (isset($keys['PRIMARY KEY']) |
|
| 2371 | - && $keys['PRIMARY KEY'] |
|
| 2372 | - && stripos($keys['PRIMARY KEY'], ',') === false |
|
| 2373 | - && stripos($fields[$keys['PRIMARY KEY']], 'default') === false); |
|
| 2374 | - |
|
| 2375 | - if ( |
|
| 2376 | - $q = _sqlite_requete_create( |
|
| 2377 | - $table_copie, |
|
| 2378 | - $fields, |
|
| 2379 | - $keys, |
|
| 2380 | - $autoinc, |
|
| 2381 | - $temporary = false, |
|
| 2382 | - $ifnotexists = true, |
|
| 2383 | - $serveur |
|
| 2384 | - ) |
|
| 2385 | - ) { |
|
| 2386 | - $queries[] = $q; |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - |
|
| 2390 | - // 2) y copier les champs qui vont bien |
|
| 2391 | - $champs_dest = implode(', ', array_keys($fields_correspondances)); |
|
| 2392 | - $champs_ori = implode(', ', $fields_correspondances); |
|
| 2393 | - $queries[] = "INSERT INTO $table_copie ($champs_dest) SELECT $champs_ori FROM $table_origine"; |
|
| 2394 | - |
|
| 2395 | - // 3) supprimer la table d'origine |
|
| 2396 | - $queries[] = "DROP TABLE $table_origine"; |
|
| 2397 | - |
|
| 2398 | - // 4) renommer la table temporaire |
|
| 2399 | - // avec le nom de la table destination |
|
| 2400 | - // si necessaire |
|
| 2401 | - if ($meme_table) { |
|
| 2402 | - $queries[] = "ALTER TABLE $table_copie RENAME TO $table_destination"; |
|
| 2403 | - } |
|
| 2404 | - |
|
| 2405 | - // 5) remettre les index ! |
|
| 2406 | - foreach ($keys as $k => $v) { |
|
| 2407 | - if ($k == 'PRIMARY KEY') { |
|
| 2408 | - } else { |
|
| 2409 | - // enlever KEY |
|
| 2410 | - $k = substr($k, 4); |
|
| 2411 | - $queries[] = "CREATE INDEX $table_destination" . "_$k ON $table_destination ($v)"; |
|
| 2412 | - } |
|
| 2413 | - } |
|
| 2414 | - |
|
| 2415 | - |
|
| 2416 | - if ($queries !== []) { |
|
| 2417 | - Sqlite::demarrer_transaction($serveur); |
|
| 2418 | - // il faut les faire une par une car $query = join('; ', $queries).";"; ne fonctionne pas |
|
| 2419 | - foreach ($queries as $q) { |
|
| 2420 | - if (!Sqlite::executer_requete($q, $serveur)) { |
|
| 2421 | - spip_log('SQLite : ALTER TABLE table :' |
|
| 2422 | - . " Erreur a l'execution de la requete : $q", 'sqlite.' . _LOG_ERREUR); |
|
| 2423 | - Sqlite::annuler_transaction($serveur); |
|
| 2424 | - |
|
| 2425 | - return false; |
|
| 2426 | - } |
|
| 2427 | - } |
|
| 2428 | - Sqlite::finir_transaction($serveur); |
|
| 2429 | - } |
|
| 2430 | - |
|
| 2431 | - return true; |
|
| 2291 | + if (is_array($table)) { |
|
| 2292 | + $table_destination = reset($table); |
|
| 2293 | + $table_origine = key($table); |
|
| 2294 | + } else { |
|
| 2295 | + $table_origine = $table_destination = $table; |
|
| 2296 | + } |
|
| 2297 | + // ne prend actuellement qu'un changement |
|
| 2298 | + // mais pourra etre adapte pour changer plus qu'une colonne a la fois |
|
| 2299 | + if (is_array($colonne)) { |
|
| 2300 | + $colonne_destination = reset($colonne); |
|
| 2301 | + $colonne_origine = key($colonne); |
|
| 2302 | + } else { |
|
| 2303 | + $colonne_origine = $colonne_destination = $colonne; |
|
| 2304 | + } |
|
| 2305 | + if (!isset($opt['field'])) { |
|
| 2306 | + $opt['field'] = []; |
|
| 2307 | + } |
|
| 2308 | + if (!isset($opt['key'])) { |
|
| 2309 | + $opt['key'] = []; |
|
| 2310 | + } |
|
| 2311 | + |
|
| 2312 | + // si les noms de tables sont differents, pas besoin de table temporaire |
|
| 2313 | + // on prendra directement le nom de la future table |
|
| 2314 | + $meme_table = ($table_origine == $table_destination); |
|
| 2315 | + |
|
| 2316 | + $def_origine = sql_showtable($table_origine, false, $serveur); |
|
| 2317 | + if (!$def_origine || !isset($def_origine['field'])) { |
|
| 2318 | + spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite' . _LOG_ERREUR); |
|
| 2319 | + |
|
| 2320 | + return false; |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + |
|
| 2324 | + $table_tmp = $table_origine . '_tmp'; |
|
| 2325 | + |
|
| 2326 | + // 1) creer une table temporaire avec les modifications |
|
| 2327 | + // - DROP : suppression de la colonne |
|
| 2328 | + // - CHANGE : modification de la colonne |
|
| 2329 | + // (foreach pour conserver l'ordre des champs) |
|
| 2330 | + |
|
| 2331 | + // field |
|
| 2332 | + $fields = []; |
|
| 2333 | + // pour le INSERT INTO plus loin |
|
| 2334 | + // stocker la correspondance nouvelles->anciennes colonnes |
|
| 2335 | + $fields_correspondances = []; |
|
| 2336 | + foreach ($def_origine['field'] as $c => $d) { |
|
| 2337 | + if ($colonne_origine && ($c == $colonne_origine)) { |
|
| 2338 | + // si pas DROP |
|
| 2339 | + if ($colonne_destination) { |
|
| 2340 | + $fields[$colonne_destination] = $opt['field'][$colonne_destination]; |
|
| 2341 | + $fields_correspondances[$colonne_destination] = $c; |
|
| 2342 | + } |
|
| 2343 | + } else { |
|
| 2344 | + $fields[$c] = $d; |
|
| 2345 | + $fields_correspondances[$c] = $c; |
|
| 2346 | + } |
|
| 2347 | + } |
|
| 2348 | + // cas de ADD sqlite2 (ajout du champ en fin de table): |
|
| 2349 | + if (!$colonne_origine && $colonne_destination) { |
|
| 2350 | + $fields[$colonne_destination] = $opt['field'][$colonne_destination]; |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + // key... |
|
| 2354 | + $keys = []; |
|
| 2355 | + foreach ($def_origine['key'] as $c => $d) { |
|
| 2356 | + $c = str_replace($colonne_origine, $colonne_destination, $c); |
|
| 2357 | + $d = str_replace($colonne_origine, $colonne_destination, $d); |
|
| 2358 | + // seulement si on ne supprime pas la colonne ! |
|
| 2359 | + if ($d) { |
|
| 2360 | + $keys[$c] = $d; |
|
| 2361 | + } |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + // autres keys, on merge |
|
| 2365 | + $keys = array_merge($keys, $opt['key']); |
|
| 2366 | + $queries = []; |
|
| 2367 | + |
|
| 2368 | + // copier dans destination (si differente de origine), sinon tmp |
|
| 2369 | + $table_copie = ($meme_table) ? $table_tmp : $table_destination; |
|
| 2370 | + $autoinc = (isset($keys['PRIMARY KEY']) |
|
| 2371 | + && $keys['PRIMARY KEY'] |
|
| 2372 | + && stripos($keys['PRIMARY KEY'], ',') === false |
|
| 2373 | + && stripos($fields[$keys['PRIMARY KEY']], 'default') === false); |
|
| 2374 | + |
|
| 2375 | + if ( |
|
| 2376 | + $q = _sqlite_requete_create( |
|
| 2377 | + $table_copie, |
|
| 2378 | + $fields, |
|
| 2379 | + $keys, |
|
| 2380 | + $autoinc, |
|
| 2381 | + $temporary = false, |
|
| 2382 | + $ifnotexists = true, |
|
| 2383 | + $serveur |
|
| 2384 | + ) |
|
| 2385 | + ) { |
|
| 2386 | + $queries[] = $q; |
|
| 2387 | + } |
|
| 2388 | + |
|
| 2389 | + |
|
| 2390 | + // 2) y copier les champs qui vont bien |
|
| 2391 | + $champs_dest = implode(', ', array_keys($fields_correspondances)); |
|
| 2392 | + $champs_ori = implode(', ', $fields_correspondances); |
|
| 2393 | + $queries[] = "INSERT INTO $table_copie ($champs_dest) SELECT $champs_ori FROM $table_origine"; |
|
| 2394 | + |
|
| 2395 | + // 3) supprimer la table d'origine |
|
| 2396 | + $queries[] = "DROP TABLE $table_origine"; |
|
| 2397 | + |
|
| 2398 | + // 4) renommer la table temporaire |
|
| 2399 | + // avec le nom de la table destination |
|
| 2400 | + // si necessaire |
|
| 2401 | + if ($meme_table) { |
|
| 2402 | + $queries[] = "ALTER TABLE $table_copie RENAME TO $table_destination"; |
|
| 2403 | + } |
|
| 2404 | + |
|
| 2405 | + // 5) remettre les index ! |
|
| 2406 | + foreach ($keys as $k => $v) { |
|
| 2407 | + if ($k == 'PRIMARY KEY') { |
|
| 2408 | + } else { |
|
| 2409 | + // enlever KEY |
|
| 2410 | + $k = substr($k, 4); |
|
| 2411 | + $queries[] = "CREATE INDEX $table_destination" . "_$k ON $table_destination ($v)"; |
|
| 2412 | + } |
|
| 2413 | + } |
|
| 2414 | + |
|
| 2415 | + |
|
| 2416 | + if ($queries !== []) { |
|
| 2417 | + Sqlite::demarrer_transaction($serveur); |
|
| 2418 | + // il faut les faire une par une car $query = join('; ', $queries).";"; ne fonctionne pas |
|
| 2419 | + foreach ($queries as $q) { |
|
| 2420 | + if (!Sqlite::executer_requete($q, $serveur)) { |
|
| 2421 | + spip_log('SQLite : ALTER TABLE table :' |
|
| 2422 | + . " Erreur a l'execution de la requete : $q", 'sqlite.' . _LOG_ERREUR); |
|
| 2423 | + Sqlite::annuler_transaction($serveur); |
|
| 2424 | + |
|
| 2425 | + return false; |
|
| 2426 | + } |
|
| 2427 | + } |
|
| 2428 | + Sqlite::finir_transaction($serveur); |
|
| 2429 | + } |
|
| 2430 | + |
|
| 2431 | + return true; |
|
| 2432 | 2432 | } |
| 2433 | 2433 | |
| 2434 | 2434 | |
@@ -2438,61 +2438,61 @@ discard block |
||
| 2438 | 2438 | * @return array |
| 2439 | 2439 | */ |
| 2440 | 2440 | function _sqlite_ref_fonctions() { |
| 2441 | - $fonctions = [ |
|
| 2442 | - 'alter' => 'spip_sqlite_alter', |
|
| 2443 | - 'count' => 'spip_sqlite_count', |
|
| 2444 | - 'countsel' => 'spip_sqlite_countsel', |
|
| 2445 | - 'create' => 'spip_sqlite_create', |
|
| 2446 | - 'create_base' => 'spip_sqlite_create_base', |
|
| 2447 | - 'create_view' => 'spip_sqlite_create_view', |
|
| 2448 | - 'date_proche' => 'spip_sqlite_date_proche', |
|
| 2449 | - 'delete' => 'spip_sqlite_delete', |
|
| 2450 | - 'drop_table' => 'spip_sqlite_drop_table', |
|
| 2451 | - 'drop_view' => 'spip_sqlite_drop_view', |
|
| 2452 | - 'errno' => 'spip_sqlite_errno', |
|
| 2453 | - 'error' => 'spip_sqlite_error', |
|
| 2454 | - 'explain' => 'spip_sqlite_explain', |
|
| 2455 | - 'fetch' => 'spip_sqlite_fetch', |
|
| 2456 | - 'seek' => 'spip_sqlite_seek', |
|
| 2457 | - 'free' => 'spip_sqlite_free', |
|
| 2458 | - 'hex' => 'spip_sqlite_hex', |
|
| 2459 | - 'in' => 'spip_sqlite_in', |
|
| 2460 | - 'insert' => 'spip_sqlite_insert', |
|
| 2461 | - 'insertq' => 'spip_sqlite_insertq', |
|
| 2462 | - 'insertq_multi' => 'spip_sqlite_insertq_multi', |
|
| 2463 | - 'listdbs' => 'spip_sqlite_listdbs', |
|
| 2464 | - 'multi' => 'spip_sqlite_multi', |
|
| 2465 | - 'optimize' => 'spip_sqlite_optimize', |
|
| 2466 | - 'query' => 'spip_sqlite_query', |
|
| 2467 | - 'quote' => 'spip_sqlite_quote', |
|
| 2468 | - 'repair' => 'spip_sqlite_repair', |
|
| 2469 | - 'replace' => 'spip_sqlite_replace', |
|
| 2470 | - 'replace_multi' => 'spip_sqlite_replace_multi', |
|
| 2471 | - 'select' => 'spip_sqlite_select', |
|
| 2472 | - 'selectdb' => 'spip_sqlite_selectdb', |
|
| 2473 | - 'set_charset' => 'spip_sqlite_set_charset', |
|
| 2474 | - 'get_charset' => 'spip_sqlite_get_charset', |
|
| 2475 | - 'showbase' => 'spip_sqlite_showbase', |
|
| 2476 | - 'showtable' => 'spip_sqlite_showtable', |
|
| 2477 | - 'table_exists' => 'spip_sqlite_table_exists', |
|
| 2478 | - 'update' => 'spip_sqlite_update', |
|
| 2479 | - 'updateq' => 'spip_sqlite_updateq', |
|
| 2480 | - 'preferer_transaction' => 'spip_sqlite_preferer_transaction', |
|
| 2481 | - 'demarrer_transaction' => 'spip_sqlite_demarrer_transaction', |
|
| 2482 | - 'terminer_transaction' => 'spip_sqlite_terminer_transaction', |
|
| 2483 | - ]; |
|
| 2484 | - |
|
| 2485 | - // association de chaque nom http d'un charset aux couples sqlite |
|
| 2486 | - // SQLite supporte utf-8 et utf-16 uniquement. |
|
| 2487 | - $charsets = [ |
|
| 2488 | - 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'], |
|
| 2489 | - //'utf-16be'=>array('charset'=>'utf16be','collation'=>'UTF-16BE'),// aucune idee de quoi il faut remplir dans es champs la |
|
| 2490 | - //'utf-16le'=>array('charset'=>'utf16le','collation'=>'UTF-16LE') |
|
| 2491 | - ]; |
|
| 2492 | - |
|
| 2493 | - $fonctions['charsets'] = $charsets; |
|
| 2494 | - |
|
| 2495 | - return $fonctions; |
|
| 2441 | + $fonctions = [ |
|
| 2442 | + 'alter' => 'spip_sqlite_alter', |
|
| 2443 | + 'count' => 'spip_sqlite_count', |
|
| 2444 | + 'countsel' => 'spip_sqlite_countsel', |
|
| 2445 | + 'create' => 'spip_sqlite_create', |
|
| 2446 | + 'create_base' => 'spip_sqlite_create_base', |
|
| 2447 | + 'create_view' => 'spip_sqlite_create_view', |
|
| 2448 | + 'date_proche' => 'spip_sqlite_date_proche', |
|
| 2449 | + 'delete' => 'spip_sqlite_delete', |
|
| 2450 | + 'drop_table' => 'spip_sqlite_drop_table', |
|
| 2451 | + 'drop_view' => 'spip_sqlite_drop_view', |
|
| 2452 | + 'errno' => 'spip_sqlite_errno', |
|
| 2453 | + 'error' => 'spip_sqlite_error', |
|
| 2454 | + 'explain' => 'spip_sqlite_explain', |
|
| 2455 | + 'fetch' => 'spip_sqlite_fetch', |
|
| 2456 | + 'seek' => 'spip_sqlite_seek', |
|
| 2457 | + 'free' => 'spip_sqlite_free', |
|
| 2458 | + 'hex' => 'spip_sqlite_hex', |
|
| 2459 | + 'in' => 'spip_sqlite_in', |
|
| 2460 | + 'insert' => 'spip_sqlite_insert', |
|
| 2461 | + 'insertq' => 'spip_sqlite_insertq', |
|
| 2462 | + 'insertq_multi' => 'spip_sqlite_insertq_multi', |
|
| 2463 | + 'listdbs' => 'spip_sqlite_listdbs', |
|
| 2464 | + 'multi' => 'spip_sqlite_multi', |
|
| 2465 | + 'optimize' => 'spip_sqlite_optimize', |
|
| 2466 | + 'query' => 'spip_sqlite_query', |
|
| 2467 | + 'quote' => 'spip_sqlite_quote', |
|
| 2468 | + 'repair' => 'spip_sqlite_repair', |
|
| 2469 | + 'replace' => 'spip_sqlite_replace', |
|
| 2470 | + 'replace_multi' => 'spip_sqlite_replace_multi', |
|
| 2471 | + 'select' => 'spip_sqlite_select', |
|
| 2472 | + 'selectdb' => 'spip_sqlite_selectdb', |
|
| 2473 | + 'set_charset' => 'spip_sqlite_set_charset', |
|
| 2474 | + 'get_charset' => 'spip_sqlite_get_charset', |
|
| 2475 | + 'showbase' => 'spip_sqlite_showbase', |
|
| 2476 | + 'showtable' => 'spip_sqlite_showtable', |
|
| 2477 | + 'table_exists' => 'spip_sqlite_table_exists', |
|
| 2478 | + 'update' => 'spip_sqlite_update', |
|
| 2479 | + 'updateq' => 'spip_sqlite_updateq', |
|
| 2480 | + 'preferer_transaction' => 'spip_sqlite_preferer_transaction', |
|
| 2481 | + 'demarrer_transaction' => 'spip_sqlite_demarrer_transaction', |
|
| 2482 | + 'terminer_transaction' => 'spip_sqlite_terminer_transaction', |
|
| 2483 | + ]; |
|
| 2484 | + |
|
| 2485 | + // association de chaque nom http d'un charset aux couples sqlite |
|
| 2486 | + // SQLite supporte utf-8 et utf-16 uniquement. |
|
| 2487 | + $charsets = [ |
|
| 2488 | + 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'], |
|
| 2489 | + //'utf-16be'=>array('charset'=>'utf16be','collation'=>'UTF-16BE'),// aucune idee de quoi il faut remplir dans es champs la |
|
| 2490 | + //'utf-16le'=>array('charset'=>'utf16le','collation'=>'UTF-16LE') |
|
| 2491 | + ]; |
|
| 2492 | + |
|
| 2493 | + $fonctions['charsets'] = $charsets; |
|
| 2494 | + |
|
| 2495 | + return $fonctions; |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | |
@@ -2504,56 +2504,56 @@ discard block |
||
| 2504 | 2504 | * @return mixed |
| 2505 | 2505 | */ |
| 2506 | 2506 | function _sqlite_remplacements_definitions_table($query, $autoinc = false) { |
| 2507 | - // quelques remplacements |
|
| 2508 | - $num = '(\s*\([0-9]*\))?'; |
|
| 2509 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 2510 | - |
|
| 2511 | - $remplace = [ |
|
| 2512 | - '/enum' . $enum . '/is' => 'VARCHAR(255)', |
|
| 2513 | - '/COLLATE \w+_bin/is' => 'COLLATE BINARY', |
|
| 2514 | - '/COLLATE \w+_ci/is' => 'COLLATE NOCASE', |
|
| 2515 | - '/auto_increment/is' => '', |
|
| 2516 | - '/current_timestamp\(\)/is' => 'CURRENT_TIMESTAMP', // Fix export depuis mariaDB #4374 |
|
| 2517 | - '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 2518 | - '/character set \w+/is' => '', |
|
| 2519 | - '/((big|small|medium|tiny)?int(eger)?)' . $num . '\s*unsigned/is' => '\\1 UNSIGNED', |
|
| 2520 | - '/(text\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2521 | - '/((char|varchar)' . $num . '\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2522 | - '/(datetime\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00 00:00:00'", |
|
| 2523 | - '/(date\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00'", |
|
| 2524 | - ]; |
|
| 2525 | - |
|
| 2526 | - // pour l'autoincrement, il faut des INTEGER NOT NULL PRIMARY KEY |
|
| 2527 | - $remplace_autocinc = [ |
|
| 2528 | - '/(big|small|medium|tiny)?int(eger)?' . $num . '/is' => 'INTEGER' |
|
| 2529 | - ]; |
|
| 2530 | - // pour les int non autoincrement, il faut un DEFAULT |
|
| 2531 | - $remplace_nonautocinc = [ |
|
| 2532 | - '/((big|small|medium|tiny)?int(eger)?' . $num . '\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0", |
|
| 2533 | - ]; |
|
| 2534 | - |
|
| 2535 | - if (is_string($query)) { |
|
| 2536 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 2537 | - if ($autoinc || preg_match(',AUTO_INCREMENT,is', $query)) { |
|
| 2538 | - $query = preg_replace(array_keys($remplace_autocinc), $remplace_autocinc, $query); |
|
| 2539 | - } else { |
|
| 2540 | - $query = preg_replace(array_keys($remplace_nonautocinc), $remplace_nonautocinc, $query); |
|
| 2541 | - $query = _sqlite_collate_ci($query); |
|
| 2542 | - } |
|
| 2543 | - } elseif (is_array($query)) { |
|
| 2544 | - foreach ($query as $k => $q) { |
|
| 2545 | - $ai = ($autoinc ? $k == $autoinc : preg_match(',AUTO_INCREMENT,is', $q)); |
|
| 2546 | - $query[$k] = preg_replace(array_keys($remplace), $remplace, $query[$k]); |
|
| 2547 | - if ($ai) { |
|
| 2548 | - $query[$k] = preg_replace(array_keys($remplace_autocinc), $remplace_autocinc, $query[$k]); |
|
| 2549 | - } else { |
|
| 2550 | - $query[$k] = preg_replace(array_keys($remplace_nonautocinc), $remplace_nonautocinc, $query[$k]); |
|
| 2551 | - $query[$k] = _sqlite_collate_ci($query[$k]); |
|
| 2552 | - } |
|
| 2553 | - } |
|
| 2554 | - } |
|
| 2555 | - |
|
| 2556 | - return $query; |
|
| 2507 | + // quelques remplacements |
|
| 2508 | + $num = '(\s*\([0-9]*\))?'; |
|
| 2509 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 2510 | + |
|
| 2511 | + $remplace = [ |
|
| 2512 | + '/enum' . $enum . '/is' => 'VARCHAR(255)', |
|
| 2513 | + '/COLLATE \w+_bin/is' => 'COLLATE BINARY', |
|
| 2514 | + '/COLLATE \w+_ci/is' => 'COLLATE NOCASE', |
|
| 2515 | + '/auto_increment/is' => '', |
|
| 2516 | + '/current_timestamp\(\)/is' => 'CURRENT_TIMESTAMP', // Fix export depuis mariaDB #4374 |
|
| 2517 | + '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 2518 | + '/character set \w+/is' => '', |
|
| 2519 | + '/((big|small|medium|tiny)?int(eger)?)' . $num . '\s*unsigned/is' => '\\1 UNSIGNED', |
|
| 2520 | + '/(text\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2521 | + '/((char|varchar)' . $num . '\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2522 | + '/(datetime\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00 00:00:00'", |
|
| 2523 | + '/(date\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00'", |
|
| 2524 | + ]; |
|
| 2525 | + |
|
| 2526 | + // pour l'autoincrement, il faut des INTEGER NOT NULL PRIMARY KEY |
|
| 2527 | + $remplace_autocinc = [ |
|
| 2528 | + '/(big|small|medium|tiny)?int(eger)?' . $num . '/is' => 'INTEGER' |
|
| 2529 | + ]; |
|
| 2530 | + // pour les int non autoincrement, il faut un DEFAULT |
|
| 2531 | + $remplace_nonautocinc = [ |
|
| 2532 | + '/((big|small|medium|tiny)?int(eger)?' . $num . '\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0", |
|
| 2533 | + ]; |
|
| 2534 | + |
|
| 2535 | + if (is_string($query)) { |
|
| 2536 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 2537 | + if ($autoinc || preg_match(',AUTO_INCREMENT,is', $query)) { |
|
| 2538 | + $query = preg_replace(array_keys($remplace_autocinc), $remplace_autocinc, $query); |
|
| 2539 | + } else { |
|
| 2540 | + $query = preg_replace(array_keys($remplace_nonautocinc), $remplace_nonautocinc, $query); |
|
| 2541 | + $query = _sqlite_collate_ci($query); |
|
| 2542 | + } |
|
| 2543 | + } elseif (is_array($query)) { |
|
| 2544 | + foreach ($query as $k => $q) { |
|
| 2545 | + $ai = ($autoinc ? $k == $autoinc : preg_match(',AUTO_INCREMENT,is', $q)); |
|
| 2546 | + $query[$k] = preg_replace(array_keys($remplace), $remplace, $query[$k]); |
|
| 2547 | + if ($ai) { |
|
| 2548 | + $query[$k] = preg_replace(array_keys($remplace_autocinc), $remplace_autocinc, $query[$k]); |
|
| 2549 | + } else { |
|
| 2550 | + $query[$k] = preg_replace(array_keys($remplace_nonautocinc), $remplace_nonautocinc, $query[$k]); |
|
| 2551 | + $query[$k] = _sqlite_collate_ci($query[$k]); |
|
| 2552 | + } |
|
| 2553 | + } |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + return $query; |
|
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | 2559 | /** |
@@ -2564,17 +2564,17 @@ discard block |
||
| 2564 | 2564 | * @return string |
| 2565 | 2565 | */ |
| 2566 | 2566 | function _sqlite_collate_ci($champ) { |
| 2567 | - if (stripos($champ, 'COLLATE') !== false) { |
|
| 2568 | - return $champ; |
|
| 2569 | - } |
|
| 2570 | - if (stripos($champ, 'BINARY') !== false) { |
|
| 2571 | - return str_ireplace('BINARY', 'COLLATE BINARY', $champ); |
|
| 2572 | - } |
|
| 2573 | - if (preg_match(',^(char|varchar|(long|small|medium|tiny)?text),i', $champ)) { |
|
| 2574 | - return $champ . ' COLLATE NOCASE'; |
|
| 2575 | - } |
|
| 2576 | - |
|
| 2577 | - return $champ; |
|
| 2567 | + if (stripos($champ, 'COLLATE') !== false) { |
|
| 2568 | + return $champ; |
|
| 2569 | + } |
|
| 2570 | + if (stripos($champ, 'BINARY') !== false) { |
|
| 2571 | + return str_ireplace('BINARY', 'COLLATE BINARY', $champ); |
|
| 2572 | + } |
|
| 2573 | + if (preg_match(',^(char|varchar|(long|small|medium|tiny)?text),i', $champ)) { |
|
| 2574 | + return $champ . ' COLLATE NOCASE'; |
|
| 2575 | + } |
|
| 2576 | + |
|
| 2577 | + return $champ; |
|
| 2578 | 2578 | } |
| 2579 | 2579 | |
| 2580 | 2580 | |
@@ -2593,83 +2593,83 @@ discard block |
||
| 2593 | 2593 | * @return bool|string |
| 2594 | 2594 | */ |
| 2595 | 2595 | function _sqlite_requete_create( |
| 2596 | - $nom, |
|
| 2597 | - $champs, |
|
| 2598 | - $cles, |
|
| 2599 | - $autoinc = false, |
|
| 2600 | - $temporary = false, |
|
| 2601 | - $_ifnotexists = true, |
|
| 2602 | - $serveur = '', |
|
| 2603 | - $requeter = true |
|
| 2596 | + $nom, |
|
| 2597 | + $champs, |
|
| 2598 | + $cles, |
|
| 2599 | + $autoinc = false, |
|
| 2600 | + $temporary = false, |
|
| 2601 | + $_ifnotexists = true, |
|
| 2602 | + $serveur = '', |
|
| 2603 | + $requeter = true |
|
| 2604 | 2604 | ) { |
| 2605 | - $query = $keys = $s = $p = ''; |
|
| 2606 | - |
|
| 2607 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 2608 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 2609 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 2610 | - return; |
|
| 2611 | - } |
|
| 2612 | - |
|
| 2613 | - // sqlite ne gere pas KEY tout court dans une requete CREATE TABLE |
|
| 2614 | - // il faut passer par des create index |
|
| 2615 | - // Il gere par contre primary key ! |
|
| 2616 | - // Soit la PK est definie dans les cles, soit dans un champs |
|
| 2617 | - // soit faussement dans les 2 (et dans ce cas, il faut l’enlever à un des 2 endroits !) |
|
| 2618 | - $pk = 'PRIMARY KEY'; |
|
| 2619 | - // le champ de cle primaire |
|
| 2620 | - $champ_pk = empty($cles[$pk]) ? '' : $cles[$pk]; |
|
| 2621 | - |
|
| 2622 | - foreach ($champs as $k => $v) { |
|
| 2623 | - if (false !== stripos($v, $pk)) { |
|
| 2624 | - $champ_pk = $k; |
|
| 2625 | - // on n'en a plus besoin dans field, vu que defini dans key |
|
| 2626 | - $champs[$k] = preg_replace("/$pk/is", '', $champs[$k]); |
|
| 2627 | - break; |
|
| 2628 | - } |
|
| 2629 | - } |
|
| 2630 | - |
|
| 2631 | - if ($champ_pk) { |
|
| 2632 | - $keys = "\n\t\t$pk ($champ_pk)"; |
|
| 2633 | - } |
|
| 2634 | - // Pas de DEFAULT 0 sur les cles primaires en auto-increment |
|
| 2635 | - if ( |
|
| 2636 | - isset($champs[$champ_pk]) |
|
| 2637 | - && stripos($champs[$champ_pk], 'default 0') !== false |
|
| 2638 | - ) { |
|
| 2639 | - $champs[$champ_pk] = trim(str_ireplace('default 0', '', $champs[$champ_pk])); |
|
| 2640 | - } |
|
| 2641 | - |
|
| 2642 | - $champs = _sqlite_remplacements_definitions_table($champs, $autoinc ? $champ_pk : false); |
|
| 2643 | - foreach ($champs as $k => $v) { |
|
| 2644 | - $query .= "$s\n\t\t$k $v"; |
|
| 2645 | - $s = ','; |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - $ifnotexists = ''; |
|
| 2649 | - if ($_ifnotexists) { |
|
| 2650 | - $version = spip_sqlite_fetch( |
|
| 2651 | - spip_sqlite_query('select sqlite_version() AS sqlite_version', $serveur), |
|
| 2652 | - '', |
|
| 2653 | - $serveur |
|
| 2654 | - ); |
|
| 2655 | - if (!function_exists('spip_version_compare')) { |
|
| 2656 | - include_spip('plugins/installer'); |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - if ($version && spip_version_compare($version['sqlite_version'], '3.3.0', '>=')) { |
|
| 2660 | - $ifnotexists = ' IF NOT EXISTS'; |
|
| 2661 | - } else { |
|
| 2662 | - /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
|
| 2663 | - $a = spip_sqlite_showtable($nom, $serveur); |
|
| 2664 | - if (isset($a['key']['KEY ' . $nom])) { |
|
| 2665 | - return true; |
|
| 2666 | - } |
|
| 2667 | - } |
|
| 2668 | - } |
|
| 2669 | - |
|
| 2670 | - $temporary = $temporary ? ' TEMPORARY' : ''; |
|
| 2671 | - |
|
| 2672 | - return "CREATE$temporary TABLE$ifnotexists $nom ($query" . ($keys ? ",$keys" : '') . ")\n"; |
|
| 2605 | + $query = $keys = $s = $p = ''; |
|
| 2606 | + |
|
| 2607 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 2608 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 2609 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 2610 | + return; |
|
| 2611 | + } |
|
| 2612 | + |
|
| 2613 | + // sqlite ne gere pas KEY tout court dans une requete CREATE TABLE |
|
| 2614 | + // il faut passer par des create index |
|
| 2615 | + // Il gere par contre primary key ! |
|
| 2616 | + // Soit la PK est definie dans les cles, soit dans un champs |
|
| 2617 | + // soit faussement dans les 2 (et dans ce cas, il faut l’enlever à un des 2 endroits !) |
|
| 2618 | + $pk = 'PRIMARY KEY'; |
|
| 2619 | + // le champ de cle primaire |
|
| 2620 | + $champ_pk = empty($cles[$pk]) ? '' : $cles[$pk]; |
|
| 2621 | + |
|
| 2622 | + foreach ($champs as $k => $v) { |
|
| 2623 | + if (false !== stripos($v, $pk)) { |
|
| 2624 | + $champ_pk = $k; |
|
| 2625 | + // on n'en a plus besoin dans field, vu que defini dans key |
|
| 2626 | + $champs[$k] = preg_replace("/$pk/is", '', $champs[$k]); |
|
| 2627 | + break; |
|
| 2628 | + } |
|
| 2629 | + } |
|
| 2630 | + |
|
| 2631 | + if ($champ_pk) { |
|
| 2632 | + $keys = "\n\t\t$pk ($champ_pk)"; |
|
| 2633 | + } |
|
| 2634 | + // Pas de DEFAULT 0 sur les cles primaires en auto-increment |
|
| 2635 | + if ( |
|
| 2636 | + isset($champs[$champ_pk]) |
|
| 2637 | + && stripos($champs[$champ_pk], 'default 0') !== false |
|
| 2638 | + ) { |
|
| 2639 | + $champs[$champ_pk] = trim(str_ireplace('default 0', '', $champs[$champ_pk])); |
|
| 2640 | + } |
|
| 2641 | + |
|
| 2642 | + $champs = _sqlite_remplacements_definitions_table($champs, $autoinc ? $champ_pk : false); |
|
| 2643 | + foreach ($champs as $k => $v) { |
|
| 2644 | + $query .= "$s\n\t\t$k $v"; |
|
| 2645 | + $s = ','; |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + $ifnotexists = ''; |
|
| 2649 | + if ($_ifnotexists) { |
|
| 2650 | + $version = spip_sqlite_fetch( |
|
| 2651 | + spip_sqlite_query('select sqlite_version() AS sqlite_version', $serveur), |
|
| 2652 | + '', |
|
| 2653 | + $serveur |
|
| 2654 | + ); |
|
| 2655 | + if (!function_exists('spip_version_compare')) { |
|
| 2656 | + include_spip('plugins/installer'); |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + if ($version && spip_version_compare($version['sqlite_version'], '3.3.0', '>=')) { |
|
| 2660 | + $ifnotexists = ' IF NOT EXISTS'; |
|
| 2661 | + } else { |
|
| 2662 | + /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
|
| 2663 | + $a = spip_sqlite_showtable($nom, $serveur); |
|
| 2664 | + if (isset($a['key']['KEY ' . $nom])) { |
|
| 2665 | + return true; |
|
| 2666 | + } |
|
| 2667 | + } |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + $temporary = $temporary ? ' TEMPORARY' : ''; |
|
| 2671 | + |
|
| 2672 | + return "CREATE$temporary TABLE$ifnotexists $nom ($query" . ($keys ? ",$keys" : '') . ")\n"; |
|
| 2673 | 2673 | } |
| 2674 | 2674 | |
| 2675 | 2675 | |
@@ -2688,40 +2688,40 @@ discard block |
||
| 2688 | 2688 | * @return |
| 2689 | 2689 | */ |
| 2690 | 2690 | function _sqlite_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') { |
| 2691 | - static $tables = []; |
|
| 2692 | - |
|
| 2693 | - if (!isset($tables[$table])) { |
|
| 2694 | - if (!$desc) { |
|
| 2695 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2696 | - $desc = $trouver_table($table, $serveur); |
|
| 2697 | - // si pas de description, on ne fait rien, ou on die() ? |
|
| 2698 | - if (!$desc) { |
|
| 2699 | - return $couples; |
|
| 2700 | - } |
|
| 2701 | - } |
|
| 2702 | - |
|
| 2703 | - // recherche des champs avec simplement 'TIMESTAMP' |
|
| 2704 | - // cependant, il faudra peut etre etendre |
|
| 2705 | - // avec la gestion de DEFAULT et ON UPDATE |
|
| 2706 | - // mais ceux-ci ne sont pas utilises dans le core |
|
| 2707 | - $tables[$table] = ['valeur' => [], 'cite' => [], 'desc' => []]; |
|
| 2708 | - |
|
| 2709 | - $now = _sqlite_func_now(true); |
|
| 2710 | - foreach ($desc['field'] as $k => $v) { |
|
| 2711 | - if (str_starts_with(strtolower(ltrim($v)), 'timestamp')) { |
|
| 2712 | - $tables[$table]['desc'][$k] = $v; |
|
| 2713 | - $tables[$table]['valeur'][$k] = _sqlite_calculer_cite($now, $tables[$table]['desc'][$k]); |
|
| 2714 | - } |
|
| 2715 | - } |
|
| 2716 | - } else { |
|
| 2717 | - $now = _sqlite_func_now(true); |
|
| 2718 | - foreach (array_keys($tables[$table]['desc']) as $k) { |
|
| 2719 | - $tables[$table]['valeur'][$k] = _sqlite_calculer_cite($now, $tables[$table]['desc'][$k]); |
|
| 2720 | - } |
|
| 2721 | - } |
|
| 2722 | - |
|
| 2723 | - // ajout des champs type 'timestamp' absents |
|
| 2724 | - return array_merge($tables[$table]['valeur'], $couples); |
|
| 2691 | + static $tables = []; |
|
| 2692 | + |
|
| 2693 | + if (!isset($tables[$table])) { |
|
| 2694 | + if (!$desc) { |
|
| 2695 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2696 | + $desc = $trouver_table($table, $serveur); |
|
| 2697 | + // si pas de description, on ne fait rien, ou on die() ? |
|
| 2698 | + if (!$desc) { |
|
| 2699 | + return $couples; |
|
| 2700 | + } |
|
| 2701 | + } |
|
| 2702 | + |
|
| 2703 | + // recherche des champs avec simplement 'TIMESTAMP' |
|
| 2704 | + // cependant, il faudra peut etre etendre |
|
| 2705 | + // avec la gestion de DEFAULT et ON UPDATE |
|
| 2706 | + // mais ceux-ci ne sont pas utilises dans le core |
|
| 2707 | + $tables[$table] = ['valeur' => [], 'cite' => [], 'desc' => []]; |
|
| 2708 | + |
|
| 2709 | + $now = _sqlite_func_now(true); |
|
| 2710 | + foreach ($desc['field'] as $k => $v) { |
|
| 2711 | + if (str_starts_with(strtolower(ltrim($v)), 'timestamp')) { |
|
| 2712 | + $tables[$table]['desc'][$k] = $v; |
|
| 2713 | + $tables[$table]['valeur'][$k] = _sqlite_calculer_cite($now, $tables[$table]['desc'][$k]); |
|
| 2714 | + } |
|
| 2715 | + } |
|
| 2716 | + } else { |
|
| 2717 | + $now = _sqlite_func_now(true); |
|
| 2718 | + foreach (array_keys($tables[$table]['desc']) as $k) { |
|
| 2719 | + $tables[$table]['valeur'][$k] = _sqlite_calculer_cite($now, $tables[$table]['desc'][$k]); |
|
| 2720 | + } |
|
| 2721 | + } |
|
| 2722 | + |
|
| 2723 | + // ajout des champs type 'timestamp' absents |
|
| 2724 | + return array_merge($tables[$table]['valeur'], $couples); |
|
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | 2727 | |
@@ -2732,5 +2732,5 @@ discard block |
||
| 2732 | 2732 | * @return array|bool |
| 2733 | 2733 | */ |
| 2734 | 2734 | function spip_versions_sqlite() { |
| 2735 | - return _sqlite_charger_version(); |
|
| 2735 | + return _sqlite_charger_version(); |
|
| 2736 | 2736 | } |
@@ -65,35 +65,35 @@ discard block |
||
| 65 | 65 | // determiner le dossier de la base : $addr ou _DIR_DB |
| 66 | 66 | $f = _DIR_DB; |
| 67 | 67 | if ($addr && str_contains($addr, '/')) { |
| 68 | - $f = rtrim($addr, '/') . '/'; |
|
| 68 | + $f = rtrim($addr, '/').'/'; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // un nom de base demande et impossible d'obtenir la base, on s'en va : |
| 72 | 72 | // il faut que la base existe ou que le repertoire parent soit writable |
| 73 | - if ($db && !is_file($f .= $db . '.sqlite') && !is_writable(dirname($f))) { |
|
| 74 | - spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.' . _LOG_HS); |
|
| 73 | + if ($db && !is_file($f .= $db.'.sqlite') && !is_writable(dirname($f))) { |
|
| 74 | + spip_log("base $f non trouvee ou droits en ecriture manquants", 'sqlite.'._LOG_HS); |
|
| 75 | 75 | |
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // charger les modules sqlite au besoin |
| 80 | 80 | if (!_sqlite_charger_version($sqlite_version)) { |
| 81 | - spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.' . _LOG_HS); |
|
| 81 | + spip_log("Impossible de trouver/charger le module SQLite ($sqlite_version)!", 'sqlite.'._LOG_HS); |
|
| 82 | 82 | |
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // chargement des constantes |
| 87 | 87 | // il ne faut pas definir les constantes avant d'avoir charge les modules sqlite |
| 88 | - $define = 'spip_sqlite' . $sqlite_version . '_constantes'; |
|
| 88 | + $define = 'spip_sqlite'.$sqlite_version.'_constantes'; |
|
| 89 | 89 | $define(); |
| 90 | 90 | |
| 91 | 91 | if (!$db) { |
| 92 | 92 | // si pas de db -> |
| 93 | 93 | // base temporaire tant qu'on ne connait pas son vrai nom |
| 94 | 94 | // pour tester la connexion |
| 95 | - $db = '_sqlite' . $sqlite_version . '_install'; |
|
| 96 | - $tmp = _DIR_DB . $db . '.sqlite'; |
|
| 95 | + $db = '_sqlite'.$sqlite_version.'_install'; |
|
| 96 | + $tmp = _DIR_DB.$db.'.sqlite'; |
|
| 97 | 97 | $link = spip_sqlite_open($tmp); |
| 98 | 98 | } else { |
| 99 | 99 | // Ouvrir (eventuellement creer la base) |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if (!$link) { |
| 104 | - spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f", 'sqlite.' . _LOG_HS); |
|
| 104 | + spip_log("Impossible d'ouvrir la base SQLite($sqlite_version) $f", 'sqlite.'._LOG_HS); |
|
| 105 | 105 | |
| 106 | 106 | return false; |
| 107 | 107 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $table = $regs[3]; |
| 199 | 199 | $suite = $regs[4]; |
| 200 | 200 | } else { |
| 201 | - spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.' . _LOG_ERREUR); |
|
| 201 | + spip_log("SQLite : Probleme de ALTER TABLE mal forme dans $query", 'sqlite.'._LOG_ERREUR); |
|
| 202 | 202 | |
| 203 | 203 | return false; |
| 204 | 204 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $i = 0; |
| 216 | 216 | $ouverte = false; |
| 217 | 217 | while ($do = array_shift($todo)) { |
| 218 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 218 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i].','.$do : $do; |
|
| 219 | 219 | $o = (str_contains($do, '(')); |
| 220 | 220 | $f = (str_contains($do, ')')); |
| 221 | 221 | if ($o && !$f) { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | ) { |
| 242 | 242 | spip_log( |
| 243 | 243 | "SQLite : Probleme de ALTER TABLE, utilisation non reconnue dans : $do \n(requete d'origine : $query)", |
| 244 | - 'sqlite.' . _LOG_ERREUR |
|
| 244 | + 'sqlite.'._LOG_ERREUR |
|
| 245 | 245 | ); |
| 246 | 246 | |
| 247 | 247 | return false; |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | |
| 338 | 338 | // pas geres en sqlite2 |
| 339 | 339 | case 'RENAME': |
| 340 | - $do = 'RENAME TO' . substr($do, 6); |
|
| 340 | + $do = 'RENAME TO'.substr($do, 6); |
|
| 341 | 341 | case 'RENAME TO': |
| 342 | 342 | if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
| 343 | - spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 343 | + spip_log("SQLite : Erreur ALTER TABLE / RENAME : $query", 'sqlite.'._LOG_ERREUR); |
|
| 344 | 344 | |
| 345 | 345 | return false; |
| 346 | 346 | } |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | $colonnes = substr($colonne_origine, 1, -1); |
| 384 | 384 | if (str_contains(',', $colonnes)) { |
| 385 | 385 | spip_log('SQLite : Erreur, impossible de creer un index sur plusieurs colonnes' |
| 386 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.' . _LOG_ERREUR); |
|
| 386 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'sqlite.'._LOG_ERREUR); |
|
| 387 | 387 | break; |
| 388 | 388 | } else { |
| 389 | 389 | $nom_index = $colonnes; |
@@ -398,12 +398,12 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | // pas geres en sqlite2 |
| 400 | 400 | case 'ADD COLUMN': |
| 401 | - $do = 'ADD' . substr($do, 10); |
|
| 401 | + $do = 'ADD'.substr($do, 10); |
|
| 402 | 402 | case 'ADD': |
| 403 | 403 | default: |
| 404 | 404 | if (!preg_match(',primary\s+key,i', $do)) { |
| 405 | 405 | if (!Sqlite::executer_requete("$debut $do", $serveur)) { |
| 406 | - spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 406 | + spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.'._LOG_ERREUR); |
|
| 407 | 407 | |
| 408 | 408 | return false; |
| 409 | 409 | } |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | $opts['field'] = [$colonne_ajoutee => $def]; |
| 425 | 425 | if (!_sqlite_modifier_table($table, [$colonne_ajoutee], $opts, $serveur)) { |
| 426 | - spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.' . _LOG_ERREUR); |
|
| 426 | + spip_log("SQLite : Erreur ALTER TABLE / ADD : $query", 'sqlite.'._LOG_ERREUR); |
|
| 427 | 427 | |
| 428 | 428 | return false; |
| 429 | 429 | } |
@@ -431,10 +431,10 @@ discard block |
||
| 431 | 431 | break; |
| 432 | 432 | } |
| 433 | 433 | // tout est bon, ouf ! |
| 434 | - spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.' . _LOG_INFO); |
|
| 434 | + spip_log("SQLite ($serveur) : Changements OK : $debut $do", 'sqlite.'._LOG_INFO); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.' . _LOG_INFO); |
|
| 437 | + spip_log("SQLite ($serveur) : fin ALTER TABLE OK !", 'sqlite.'._LOG_INFO); |
|
| 438 | 438 | |
| 439 | 439 | return true; |
| 440 | 440 | } |
@@ -502,9 +502,9 @@ discard block |
||
| 502 | 502 | * @return bool true si la base est créee. |
| 503 | 503 | **/ |
| 504 | 504 | function spip_sqlite_create_base($nom, $serveur = '', $option = true) { |
| 505 | - $f = $nom . '.sqlite'; |
|
| 505 | + $f = $nom.'.sqlite'; |
|
| 506 | 506 | if (!str_contains($nom, '/')) { |
| 507 | - $f = _DIR_DB . $f; |
|
| 507 | + $f = _DIR_DB.$f; |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | $ok = new \PDO("sqlite:$f"); |
@@ -544,13 +544,13 @@ discard block |
||
| 544 | 544 | if (sql_showtable($nom, false, $serveur)) { |
| 545 | 545 | spip_log( |
| 546 | 546 | "Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", |
| 547 | - 'sqlite.' . _LOG_ERREUR |
|
| 547 | + 'sqlite.'._LOG_ERREUR |
|
| 548 | 548 | ); |
| 549 | 549 | |
| 550 | 550 | return false; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 553 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 554 | 554 | |
| 555 | 555 | return spip_sqlite_query($query, $serveur, $requeter); |
| 556 | 556 | } |
@@ -576,8 +576,8 @@ discard block |
||
| 576 | 576 | function spip_sqlite_create_index($nom, $table, $champs, $unique = '', $serveur = '', $requeter = true) { |
| 577 | 577 | if (!($nom || $table || $champs)) { |
| 578 | 578 | spip_log( |
| 579 | - "Champ manquant pour creer un index sqlite ($nom, $table, (" . implode(',', $champs) . '))', |
|
| 580 | - 'sqlite.' . _LOG_ERREUR |
|
| 579 | + "Champ manquant pour creer un index sqlite ($nom, $table, (".implode(',', $champs).'))', |
|
| 580 | + 'sqlite.'._LOG_ERREUR |
|
| 581 | 581 | ); |
| 582 | 582 | |
| 583 | 583 | return false; |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | // SQLite ne differentie pas noms des index en fonction des tables |
| 587 | 587 | // il faut donc creer des noms uniques d'index pour une base sqlite |
| 588 | - $nom = $table . '_' . $nom; |
|
| 588 | + $nom = $table.'_'.$nom; |
|
| 589 | 589 | // enlever d'eventuelles parentheses deja presentes sur champs |
| 590 | 590 | if (!is_array($champs)) { |
| 591 | 591 | if ($champs[0] == '(') { |
@@ -607,12 +607,12 @@ discard block |
||
| 607 | 607 | } else { |
| 608 | 608 | /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
| 609 | 609 | $a = spip_sqlite_showtable($table, $serveur); |
| 610 | - if (isset($a['key']['KEY ' . $nom])) { |
|
| 610 | + if (isset($a['key']['KEY '.$nom])) { |
|
| 611 | 611 | return true; |
| 612 | 612 | } |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - $query = 'CREATE ' . ($unique ? 'UNIQUE ' : '') . "INDEX$ifnotexists $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 615 | + $query = 'CREATE '.($unique ? 'UNIQUE ' : '')."INDEX$ifnotexists $nom ON $table (".implode(',', $champs).')'; |
|
| 616 | 616 | $res = spip_sqlite_query($query, $serveur, $requeter); |
| 617 | 617 | if (!$requeter) { |
| 618 | 618 | return $res; |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | $serveur = '', |
| 681 | 681 | $requeter = true |
| 682 | 682 | ) { |
| 683 | - $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 683 | + $c = $groupby ? 'DISTINCT '.(is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 684 | 684 | $r = spip_sqlite_select( |
| 685 | 685 | "COUNT($c)", |
| 686 | 686 | $from, |
@@ -790,14 +790,14 @@ discard block |
||
| 790 | 790 | */ |
| 791 | 791 | function spip_sqlite_drop_index($nom, $table, $serveur = '', $requeter = true) { |
| 792 | 792 | if (!$nom && !$table) { |
| 793 | - spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.' . _LOG_ERREUR); |
|
| 793 | + spip_log("Champ manquant pour supprimer un index sqlite ($nom, $table)", 'sqlite.'._LOG_ERREUR); |
|
| 794 | 794 | |
| 795 | 795 | return false; |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | // SQLite ne differentie pas noms des index en fonction des tables |
| 799 | 799 | // il faut donc creer des noms uniques d'index pour une base sqlite |
| 800 | - $index = $table . '_' . $nom; |
|
| 800 | + $index = $table.'_'.$nom; |
|
| 801 | 801 | $exist = ' IF EXISTS'; |
| 802 | 802 | |
| 803 | 803 | $query = "DROP INDEX$exist $index"; |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | if ($s) { |
| 830 | 830 | $trace = debug_backtrace(); |
| 831 | 831 | if ($trace[0]['function'] != 'spip_sqlite_error') { |
| 832 | - spip_log("$s - $query - " . sql_error_backtrace(), 'sqlite.' . _LOG_ERREUR); |
|
| 832 | + spip_log("$s - $query - ".sql_error_backtrace(), 'sqlite.'._LOG_ERREUR); |
|
| 833 | 833 | } |
| 834 | 834 | } |
| 835 | 835 | |
@@ -876,14 +876,14 @@ discard block |
||
| 876 | 876 | $t = $link->errorInfo(); |
| 877 | 877 | $s = ltrim($t[0], '0'); // 00000 si pas d'erreur |
| 878 | 878 | if ($s) { |
| 879 | - $s .= ' / ' . $t[1]; |
|
| 879 | + $s .= ' / '.$t[1]; |
|
| 880 | 880 | } // ajoute l'erreur du moteur SQLite |
| 881 | 881 | } else { |
| 882 | 882 | $s = ': aucune ressource sqlite (link)'; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | if ($s) { |
| 886 | - spip_log("Erreur sqlite $s", 'sqlite.' . _LOG_ERREUR); |
|
| 886 | + spip_log("Erreur sqlite $s", 'sqlite.'._LOG_ERREUR); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | return $s ?: 0; |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | $query = Sqlite::traduire_requete($query, $serveur); |
| 910 | - $query = 'EXPLAIN ' . $query; |
|
| 910 | + $query = 'EXPLAIN '.$query; |
|
| 911 | 911 | if (!$requeter) { |
| 912 | 912 | return $query; |
| 913 | 913 | } |
@@ -1076,7 +1076,7 @@ discard block |
||
| 1076 | 1076 | **/ |
| 1077 | 1077 | function spip_sqlite_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1078 | 1078 | |
| 1079 | - $query = "INSERT INTO $table " . ($champs ? "$champs VALUES $valeurs" : 'DEFAULT VALUES'); |
|
| 1079 | + $query = "INSERT INTO $table ".($champs ? "$champs VALUES $valeurs" : 'DEFAULT VALUES'); |
|
| 1080 | 1080 | if ($r = spip_sqlite_query($query, $serveur, $requeter)) { |
| 1081 | 1081 | if (!$requeter) { |
| 1082 | 1082 | return $r; |
@@ -1131,8 +1131,8 @@ discard block |
||
| 1131 | 1131 | |
| 1132 | 1132 | $cles = $valeurs = ''; |
| 1133 | 1133 | if (is_countable($couples) ? count($couples) : 0) { |
| 1134 | - $cles = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1135 | - $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1134 | + $cles = '('.implode(',', array_keys($couples)).')'; |
|
| 1135 | + $valeurs = '('.implode(',', $couples).')'; |
|
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | return spip_sqlite_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
@@ -1194,11 +1194,11 @@ discard block |
||
| 1194 | 1194 | |
| 1195 | 1195 | $champs = $valeurs = ''; |
| 1196 | 1196 | if ($couples !== []) { |
| 1197 | - $champs = '(' . implode(',', array_keys($couples)) . ')'; |
|
| 1198 | - $valeurs = '(' . implode(',', $couples) . ')'; |
|
| 1199 | - $query = $query_start . "$champs VALUES $valeurs"; |
|
| 1197 | + $champs = '('.implode(',', array_keys($couples)).')'; |
|
| 1198 | + $valeurs = '('.implode(',', $couples).')'; |
|
| 1199 | + $query = $query_start."$champs VALUES $valeurs"; |
|
| 1200 | 1200 | } else { |
| 1201 | - $query = $query_start . 'DEFAULT VALUES'; |
|
| 1201 | + $query = $query_start.'DEFAULT VALUES'; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | if ($requeter) { |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | * @return string texte de sélection pour la requête |
| 1331 | 1331 | */ |
| 1332 | 1332 | function spip_sqlite_multi($objet, $lang) { |
| 1333 | - return 'EXTRAIRE_MULTI(' . $objet . ", '" . $lang . "') AS multi"; |
|
| 1333 | + return 'EXTRAIRE_MULTI('.$objet.", '".$lang."') AS multi"; |
|
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | 1336 | |
@@ -1399,7 +1399,7 @@ discard block |
||
| 1399 | 1399 | function spip_sqlite_date_proche($champ, $interval, $unite) { |
| 1400 | 1400 | $op = (($interval <= 0) ? '>' : '<'); |
| 1401 | 1401 | |
| 1402 | - return "($champ $op datetime('" . date('Y-m-d H:i:s') . "', '$interval $unite'))"; |
|
| 1402 | + return "($champ $op datetime('".date('Y-m-d H:i:s')."', '$interval $unite'))"; |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | |
@@ -1431,7 +1431,7 @@ discard block |
||
| 1431 | 1431 | && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
| 1432 | 1432 | ) { |
| 1433 | 1433 | spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT ''", $serveur); |
| 1434 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1434 | + spip_log("ALTER $q", 'repair'._LOG_INFO_IMPORTANTE); |
|
| 1435 | 1435 | } |
| 1436 | 1436 | if ( |
| 1437 | 1437 | preg_match(',^(INTEGER),i', $d) |
@@ -1441,7 +1441,7 @@ discard block |
||
| 1441 | 1441 | && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
| 1442 | 1442 | ) { |
| 1443 | 1443 | spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0'", $serveur); |
| 1444 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1444 | + spip_log("ALTER $q", 'repair'._LOG_INFO_IMPORTANTE); |
|
| 1445 | 1445 | } |
| 1446 | 1446 | if ( |
| 1447 | 1447 | preg_match(',^(datetime),i', $d) |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | && (!isset($desc['key']['PRIMARY KEY']) || $desc['key']['PRIMARY KEY'] !== $c) |
| 1452 | 1452 | ) { |
| 1453 | 1453 | spip_sqlite_alter($q = "TABLE $table CHANGE $c $c $d DEFAULT '0000-00-00 00:00:00'", $serveur); |
| 1454 | - spip_log("ALTER $q", 'repair' . _LOG_INFO_IMPORTANTE); |
|
| 1454 | + spip_log("ALTER $q", 'repair'._LOG_INFO_IMPORTANTE); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | } |
| 1457 | 1457 | |
@@ -1502,10 +1502,10 @@ discard block |
||
| 1502 | 1502 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 1503 | 1503 | $couples = _sqlite_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 1504 | 1504 | |
| 1505 | - return spip_sqlite_query("REPLACE INTO $table (" . implode(',', array_keys($couples)) . ') VALUES (' . implode( |
|
| 1505 | + return spip_sqlite_query("REPLACE INTO $table (".implode(',', array_keys($couples)).') VALUES ('.implode( |
|
| 1506 | 1506 | ',', |
| 1507 | 1507 | $couples |
| 1508 | - ) . ')', $serveur); |
|
| 1508 | + ).')', $serveur); |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | |
@@ -1592,7 +1592,7 @@ discard block |
||
| 1592 | 1592 | . _sqlite_calculer_expression('WHERE', $where) |
| 1593 | 1593 | . _sqlite_calculer_expression('GROUP BY', $groupby, ',') |
| 1594 | 1594 | . _sqlite_calculer_expression('HAVING', $having) |
| 1595 | - . ($orderby ? ("\nORDER BY " . _sqlite_calculer_order($orderby)) : '') |
|
| 1595 | + . ($orderby ? ("\nORDER BY "._sqlite_calculer_order($orderby)) : '') |
|
| 1596 | 1596 | . ($limit ? "\nLIMIT $limit" : ''); |
| 1597 | 1597 | |
| 1598 | 1598 | // dans un select, on doit renvoyer la requête en cas d'erreur |
@@ -1630,10 +1630,10 @@ discard block |
||
| 1630 | 1630 | // interdire la creation d'une nouvelle base, |
| 1631 | 1631 | // sauf si on est dans l'installation |
| 1632 | 1632 | if ( |
| 1633 | - !is_file($f = _DIR_DB . $db . '.sqlite') |
|
| 1633 | + !is_file($f = _DIR_DB.$db.'.sqlite') |
|
| 1634 | 1634 | && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL) |
| 1635 | 1635 | ) { |
| 1636 | - spip_log("Il est interdit de creer la base $db", 'sqlite.' . _LOG_HS); |
|
| 1636 | + spip_log("Il est interdit de creer la base $db", 'sqlite.'._LOG_HS); |
|
| 1637 | 1637 | |
| 1638 | 1638 | return false; |
| 1639 | 1639 | } |
@@ -1642,12 +1642,12 @@ discard block |
||
| 1642 | 1642 | // avec les identifiants connus |
| 1643 | 1643 | $index = $serveur ?: 0; |
| 1644 | 1644 | |
| 1645 | - if ($link = spip_connect_db('', '', '', '', '@selectdb@' . $db, $serveur, '', '')) { |
|
| 1645 | + if ($link = spip_connect_db('', '', '', '', '@selectdb@'.$db, $serveur, '', '')) { |
|
| 1646 | 1646 | if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
| 1647 | 1647 | return $db; |
| 1648 | 1648 | } |
| 1649 | 1649 | } else { |
| 1650 | - spip_log("Impossible de selectionner la base $db", 'sqlite.' . _LOG_HS); |
|
| 1650 | + spip_log("Impossible de selectionner la base $db", 'sqlite.'._LOG_HS); |
|
| 1651 | 1651 | } |
| 1652 | 1652 | |
| 1653 | 1653 | return false; |
@@ -1698,7 +1698,7 @@ discard block |
||
| 1698 | 1698 | $match = "^$match$"; |
| 1699 | 1699 | |
| 1700 | 1700 | return spip_sqlite_query( |
| 1701 | - "SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP " . _q($match), |
|
| 1701 | + "SELECT name FROM sqlite_master WHERE type='table' AND tbl_name REGEXP "._q($match), |
|
| 1702 | 1702 | $serveur, |
| 1703 | 1703 | $requeter |
| 1704 | 1704 | ); |
@@ -1722,7 +1722,7 @@ discard block |
||
| 1722 | 1722 | $r = spip_sqlite_query( |
| 1723 | 1723 | 'SELECT name FROM sqlite_master WHERE' |
| 1724 | 1724 | . ' type=\'table\'' |
| 1725 | - . ' AND name=' . spip_sqlite_quote($table, 'string') |
|
| 1725 | + . ' AND name='.spip_sqlite_quote($table, 'string') |
|
| 1726 | 1726 | . ' AND name NOT LIKE \'sqlite_%\'', |
| 1727 | 1727 | $serveur, |
| 1728 | 1728 | $requeter |
@@ -1819,7 +1819,7 @@ discard block |
||
| 1819 | 1819 | // s'il y a une parenthèse fermante dans la clé |
| 1820 | 1820 | // ou dans la définition sans qu'il n'y ait une ouverture avant |
| 1821 | 1821 | if (str_contains($k, ')') || preg_match('/^[^\(]*\)/', $def)) { |
| 1822 | - $fields[$k_precedent] .= ',' . $k . ' ' . $def; |
|
| 1822 | + $fields[$k_precedent] .= ','.$k.' '.$def; |
|
| 1823 | 1823 | continue; |
| 1824 | 1824 | } |
| 1825 | 1825 | |
@@ -1854,13 +1854,13 @@ discard block |
||
| 1854 | 1854 | . 'ORDER BY substr(type,2,1), name'; |
| 1855 | 1855 | $a = spip_sqlite_query($query, $serveur, $requeter); |
| 1856 | 1856 | while ($r = spip_sqlite_fetch($a, null, $serveur)) { |
| 1857 | - $key = str_replace($nom_table . '_', '', $r['name']); // enlever le nom de la table ajoute a l'index |
|
| 1857 | + $key = str_replace($nom_table.'_', '', $r['name']); // enlever le nom de la table ajoute a l'index |
|
| 1858 | 1858 | $keytype = 'KEY'; |
| 1859 | 1859 | if (str_contains($r['sql'], 'UNIQUE INDEX')) { |
| 1860 | 1860 | $keytype = 'UNIQUE KEY'; |
| 1861 | 1861 | } |
| 1862 | 1862 | $colonnes = preg_replace(',.*\((.*)\).*,', '$1', $r['sql']); |
| 1863 | - $keys[$keytype . ' ' . $key] = $colonnes; |
|
| 1863 | + $keys[$keytype.' '.$key] = $colonnes; |
|
| 1864 | 1864 | } |
| 1865 | 1865 | } |
| 1866 | 1866 | } // c'est une vue, on liste les champs disponibles simplement |
@@ -1907,7 +1907,7 @@ discard block |
||
| 1907 | 1907 | |
| 1908 | 1908 | $set = []; |
| 1909 | 1909 | foreach ($champs as $champ => $val) { |
| 1910 | - $set[] = $champ . "=$val"; |
|
| 1910 | + $set[] = $champ."=$val"; |
|
| 1911 | 1911 | } |
| 1912 | 1912 | if ($set !== []) { |
| 1913 | 1913 | return spip_sqlite_query( |
@@ -1962,7 +1962,7 @@ discard block |
||
| 1962 | 1962 | |
| 1963 | 1963 | $set = []; |
| 1964 | 1964 | foreach ($champs as $champ => $val) { |
| 1965 | - $set[$champ] = $champ . '=' . _sqlite_calculer_cite($val, $fields[$champ] ?? ''); |
|
| 1965 | + $set[$champ] = $champ.'='._sqlite_calculer_cite($val, $fields[$champ] ?? ''); |
|
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | 1968 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
@@ -1970,7 +1970,7 @@ discard block |
||
| 1970 | 1970 | $maj = _sqlite_ajouter_champs_timestamp($table, [], $desc, $serveur); |
| 1971 | 1971 | foreach ($maj as $champ => $val) { |
| 1972 | 1972 | if (!isset($set[$champ])) { |
| 1973 | - $set[$champ] = $champ . '=' . $val; |
|
| 1973 | + $set[$champ] = $champ.'='.$val; |
|
| 1974 | 1974 | } |
| 1975 | 1975 | } |
| 1976 | 1976 | |
@@ -1999,7 +1999,7 @@ discard block |
||
| 1999 | 1999 | */ |
| 2000 | 2000 | function _sqlite_init() { |
| 2001 | 2001 | if (!defined('_DIR_DB')) { |
| 2002 | - define('_DIR_DB', _DIR_ETC . 'bases/'); |
|
| 2002 | + define('_DIR_DB', _DIR_ETC.'bases/'); |
|
| 2003 | 2003 | } |
| 2004 | 2004 | if (!defined('_SQLITE_CHMOD')) { |
| 2005 | 2005 | define('_SQLITE_CHMOD', _SPIP_CHMOD); |
@@ -2105,9 +2105,9 @@ discard block |
||
| 2105 | 2105 | } |
| 2106 | 2106 | |
| 2107 | 2107 | // echapper les ' en '' |
| 2108 | - spip_log('Pas de methode ->quote pour echapper', 'sqlite.' . _LOG_INFO_IMPORTANTE); |
|
| 2108 | + spip_log('Pas de methode ->quote pour echapper', 'sqlite.'._LOG_INFO_IMPORTANTE); |
|
| 2109 | 2109 | |
| 2110 | - return ("'" . str_replace("'", "''", $v) . "'"); |
|
| 2110 | + return ("'".str_replace("'", "''", $v)."'"); |
|
| 2111 | 2111 | } |
| 2112 | 2112 | |
| 2113 | 2113 | |
@@ -2130,12 +2130,12 @@ discard block |
||
| 2130 | 2130 | $exp = "\n$expression "; |
| 2131 | 2131 | |
| 2132 | 2132 | if (!is_array($v)) { |
| 2133 | - return $exp . $v; |
|
| 2133 | + return $exp.$v; |
|
| 2134 | 2134 | } else { |
| 2135 | 2135 | if (strtoupper($join) === 'AND') { |
| 2136 | - return $exp . implode("\n\t$join ", array_map('_sqlite_calculer_where', $v)); |
|
| 2136 | + return $exp.implode("\n\t$join ", array_map('_sqlite_calculer_where', $v)); |
|
| 2137 | 2137 | } else { |
| 2138 | - return $exp . implode($join, $v); |
|
| 2138 | + return $exp.implode($join, $v); |
|
| 2139 | 2139 | } |
| 2140 | 2140 | } |
| 2141 | 2141 | } |
@@ -2169,17 +2169,17 @@ discard block |
||
| 2169 | 2169 | if (str_ends_with($k, '@')) { |
| 2170 | 2170 | // c'est une jointure qui se refere au from precedent |
| 2171 | 2171 | // pas de virgule |
| 2172 | - $res .= ' ' . $v; |
|
| 2172 | + $res .= ' '.$v; |
|
| 2173 | 2173 | } else { |
| 2174 | 2174 | if (!is_numeric($k)) { |
| 2175 | 2175 | $p = strpos($v, ' '); |
| 2176 | 2176 | if ($p) { |
| 2177 | - $v = substr($v, 0, $p) . " AS '$k'" . substr($v, $p); |
|
| 2177 | + $v = substr($v, 0, $p)." AS '$k'".substr($v, $p); |
|
| 2178 | 2178 | } else { |
| 2179 | 2179 | $v .= " AS '$k'"; |
| 2180 | 2180 | } |
| 2181 | 2181 | } |
| 2182 | - $res .= ', ' . $v; |
|
| 2182 | + $res .= ', '.$v; |
|
| 2183 | 2183 | } |
| 2184 | 2184 | } |
| 2185 | 2185 | |
@@ -2315,13 +2315,13 @@ discard block |
||
| 2315 | 2315 | |
| 2316 | 2316 | $def_origine = sql_showtable($table_origine, false, $serveur); |
| 2317 | 2317 | if (!$def_origine || !isset($def_origine['field'])) { |
| 2318 | - spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite' . _LOG_ERREUR); |
|
| 2318 | + spip_log("Alter table impossible sur $table_origine : table non trouvee", 'sqlite'._LOG_ERREUR); |
|
| 2319 | 2319 | |
| 2320 | 2320 | return false; |
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | |
| 2324 | - $table_tmp = $table_origine . '_tmp'; |
|
| 2324 | + $table_tmp = $table_origine.'_tmp'; |
|
| 2325 | 2325 | |
| 2326 | 2326 | // 1) creer une table temporaire avec les modifications |
| 2327 | 2327 | // - DROP : suppression de la colonne |
@@ -2408,7 +2408,7 @@ discard block |
||
| 2408 | 2408 | } else { |
| 2409 | 2409 | // enlever KEY |
| 2410 | 2410 | $k = substr($k, 4); |
| 2411 | - $queries[] = "CREATE INDEX $table_destination" . "_$k ON $table_destination ($v)"; |
|
| 2411 | + $queries[] = "CREATE INDEX $table_destination"."_$k ON $table_destination ($v)"; |
|
| 2412 | 2412 | } |
| 2413 | 2413 | } |
| 2414 | 2414 | |
@@ -2419,7 +2419,7 @@ discard block |
||
| 2419 | 2419 | foreach ($queries as $q) { |
| 2420 | 2420 | if (!Sqlite::executer_requete($q, $serveur)) { |
| 2421 | 2421 | spip_log('SQLite : ALTER TABLE table :' |
| 2422 | - . " Erreur a l'execution de la requete : $q", 'sqlite.' . _LOG_ERREUR); |
|
| 2422 | + . " Erreur a l'execution de la requete : $q", 'sqlite.'._LOG_ERREUR); |
|
| 2423 | 2423 | Sqlite::annuler_transaction($serveur); |
| 2424 | 2424 | |
| 2425 | 2425 | return false; |
@@ -2509,27 +2509,27 @@ discard block |
||
| 2509 | 2509 | $enum = '(\s*\([^\)]*\))?'; |
| 2510 | 2510 | |
| 2511 | 2511 | $remplace = [ |
| 2512 | - '/enum' . $enum . '/is' => 'VARCHAR(255)', |
|
| 2512 | + '/enum'.$enum.'/is' => 'VARCHAR(255)', |
|
| 2513 | 2513 | '/COLLATE \w+_bin/is' => 'COLLATE BINARY', |
| 2514 | 2514 | '/COLLATE \w+_ci/is' => 'COLLATE NOCASE', |
| 2515 | 2515 | '/auto_increment/is' => '', |
| 2516 | 2516 | '/current_timestamp\(\)/is' => 'CURRENT_TIMESTAMP', // Fix export depuis mariaDB #4374 |
| 2517 | 2517 | '/(timestamp .* )ON .*$/is' => '\\1', |
| 2518 | 2518 | '/character set \w+/is' => '', |
| 2519 | - '/((big|small|medium|tiny)?int(eger)?)' . $num . '\s*unsigned/is' => '\\1 UNSIGNED', |
|
| 2519 | + '/((big|small|medium|tiny)?int(eger)?)'.$num.'\s*unsigned/is' => '\\1 UNSIGNED', |
|
| 2520 | 2520 | '/(text\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
| 2521 | - '/((char|varchar)' . $num . '\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2521 | + '/((char|varchar)'.$num.'\s+not\s+null(\s+collate\s+\w+)?)\s*$/is' => "\\1 DEFAULT ''", |
|
| 2522 | 2522 | '/(datetime\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00 00:00:00'", |
| 2523 | 2523 | '/(date\s+not\s+null)\s*$/is' => "\\1 DEFAULT '0000-00-00'", |
| 2524 | 2524 | ]; |
| 2525 | 2525 | |
| 2526 | 2526 | // pour l'autoincrement, il faut des INTEGER NOT NULL PRIMARY KEY |
| 2527 | 2527 | $remplace_autocinc = [ |
| 2528 | - '/(big|small|medium|tiny)?int(eger)?' . $num . '/is' => 'INTEGER' |
|
| 2528 | + '/(big|small|medium|tiny)?int(eger)?'.$num.'/is' => 'INTEGER' |
|
| 2529 | 2529 | ]; |
| 2530 | 2530 | // pour les int non autoincrement, il faut un DEFAULT |
| 2531 | 2531 | $remplace_nonautocinc = [ |
| 2532 | - '/((big|small|medium|tiny)?int(eger)?' . $num . '\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0", |
|
| 2532 | + '/((big|small|medium|tiny)?int(eger)?'.$num.'\s+not\s+null)\s*$/is' => "\\1 DEFAULT 0", |
|
| 2533 | 2533 | ]; |
| 2534 | 2534 | |
| 2535 | 2535 | if (is_string($query)) { |
@@ -2571,7 +2571,7 @@ discard block |
||
| 2571 | 2571 | return str_ireplace('BINARY', 'COLLATE BINARY', $champ); |
| 2572 | 2572 | } |
| 2573 | 2573 | if (preg_match(',^(char|varchar|(long|small|medium|tiny)?text),i', $champ)) { |
| 2574 | - return $champ . ' COLLATE NOCASE'; |
|
| 2574 | + return $champ.' COLLATE NOCASE'; |
|
| 2575 | 2575 | } |
| 2576 | 2576 | |
| 2577 | 2577 | return $champ; |
@@ -2661,7 +2661,7 @@ discard block |
||
| 2661 | 2661 | } else { |
| 2662 | 2662 | /* simuler le IF EXISTS - version 2 et sqlite < 3.3a */ |
| 2663 | 2663 | $a = spip_sqlite_showtable($nom, $serveur); |
| 2664 | - if (isset($a['key']['KEY ' . $nom])) { |
|
| 2664 | + if (isset($a['key']['KEY '.$nom])) { |
|
| 2665 | 2665 | return true; |
| 2666 | 2666 | } |
| 2667 | 2667 | } |
@@ -2669,7 +2669,7 @@ discard block |
||
| 2669 | 2669 | |
| 2670 | 2670 | $temporary = $temporary ? ' TEMPORARY' : ''; |
| 2671 | 2671 | |
| 2672 | - return "CREATE$temporary TABLE$ifnotexists $nom ($query" . ($keys ? ",$keys" : '') . ")\n"; |
|
| 2672 | + return "CREATE$temporary TABLE$ifnotexists $nom ($query".($keys ? ",$keys" : '').")\n"; |
|
| 2673 | 2673 | } |
| 2674 | 2674 | |
| 2675 | 2675 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -42,90 +42,90 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | function _sqlite_init_functions(&$sqlite) { |
| 44 | 44 | |
| 45 | - if (!$sqlite) { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 45 | + if (!$sqlite) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - $fonctions = [ |
|
| 51 | - // A |
|
| 52 | - 'ACOS' => ['acos', 1], |
|
| 53 | - 'ASIN' => ['asin', 1], |
|
| 54 | - 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 55 | - 'ATAN2' => ['atan2', 2], |
|
| 50 | + $fonctions = [ |
|
| 51 | + // A |
|
| 52 | + 'ACOS' => ['acos', 1], |
|
| 53 | + 'ASIN' => ['asin', 1], |
|
| 54 | + 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 55 | + 'ATAN2' => ['atan2', 2], |
|
| 56 | 56 | |
| 57 | - // C |
|
| 58 | - 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 59 | - 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 60 | - 'COS' => ['cos', 1], |
|
| 57 | + // C |
|
| 58 | + 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 59 | + 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 60 | + 'COS' => ['cos', 1], |
|
| 61 | 61 | |
| 62 | - // D |
|
| 63 | - 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 64 | - 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 65 | - 'DEGREES' => ['rad2deg', 1], |
|
| 62 | + // D |
|
| 63 | + 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 64 | + 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 65 | + 'DEGREES' => ['rad2deg', 1], |
|
| 66 | 66 | |
| 67 | - // E |
|
| 68 | - 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 69 | - 'EXP' => ['exp', 1], |
|
| 67 | + // E |
|
| 68 | + 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 69 | + 'EXP' => ['exp', 1], |
|
| 70 | 70 | |
| 71 | - // F |
|
| 72 | - 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 73 | - 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 71 | + // F |
|
| 72 | + 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 73 | + 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 74 | 74 | |
| 75 | - // G |
|
| 76 | - 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 75 | + // G |
|
| 76 | + 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 77 | 77 | |
| 78 | - // I |
|
| 79 | - 'IF' => ['_sqlite_func_if', 3], |
|
| 80 | - 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 81 | - 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 78 | + // I |
|
| 79 | + 'IF' => ['_sqlite_func_if', 3], |
|
| 80 | + 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 81 | + 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 82 | 82 | |
| 83 | - // L |
|
| 84 | - 'LEAST' => ['_sqlite_func_least', -1], |
|
| 85 | - '_LEFT' => ['_sqlite_func_left', 2], |
|
| 83 | + // L |
|
| 84 | + 'LEAST' => ['_sqlite_func_least', -1], |
|
| 85 | + '_LEFT' => ['_sqlite_func_left', 2], |
|
| 86 | 86 | |
| 87 | - // N |
|
| 88 | - 'NOW' => ['_sqlite_func_now', 0], |
|
| 87 | + // N |
|
| 88 | + 'NOW' => ['_sqlite_func_now', 0], |
|
| 89 | 89 | |
| 90 | - // M |
|
| 91 | - 'MD5' => ['md5', 1], |
|
| 92 | - 'MONTH' => ['_sqlite_func_month', 1], |
|
| 90 | + // M |
|
| 91 | + 'MD5' => ['md5', 1], |
|
| 92 | + 'MONTH' => ['_sqlite_func_month', 1], |
|
| 93 | 93 | |
| 94 | - // P |
|
| 95 | - 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 94 | + // P |
|
| 95 | + 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 96 | 96 | |
| 97 | - // R |
|
| 98 | - 'RADIANS' => ['deg2rad', 1], |
|
| 99 | - 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 100 | - 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 101 | - 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 97 | + // R |
|
| 98 | + 'RADIANS' => ['deg2rad', 1], |
|
| 99 | + 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 100 | + 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 101 | + 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 102 | 102 | |
| 103 | - // S |
|
| 104 | - 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 105 | - 'SIN' => ['sin', 1], |
|
| 106 | - 'SQRT' => ['sqrt', 1], |
|
| 107 | - 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 103 | + // S |
|
| 104 | + 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 105 | + 'SIN' => ['sin', 1], |
|
| 106 | + 'SQRT' => ['sqrt', 1], |
|
| 107 | + 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 108 | 108 | |
| 109 | - // T |
|
| 110 | - 'TAN' => ['tan', 1], |
|
| 111 | - 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 112 | - 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 109 | + // T |
|
| 110 | + 'TAN' => ['tan', 1], |
|
| 111 | + 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 112 | + 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 113 | 113 | |
| 114 | - // U |
|
| 115 | - 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 114 | + // U |
|
| 115 | + 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 116 | 116 | |
| 117 | - // V |
|
| 118 | - 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 117 | + // V |
|
| 118 | + 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 119 | 119 | |
| 120 | - // Y |
|
| 121 | - 'YEAR' => ['_sqlite_func_year', 1] |
|
| 122 | - ]; |
|
| 120 | + // Y |
|
| 121 | + 'YEAR' => ['_sqlite_func_year', 1] |
|
| 122 | + ]; |
|
| 123 | 123 | |
| 124 | - foreach ($fonctions as $f => $r) { |
|
| 125 | - _sqlite_add_function($sqlite, $f, $r); |
|
| 126 | - } |
|
| 124 | + foreach ($fonctions as $f => $r) { |
|
| 125 | + _sqlite_add_function($sqlite, $f, $r); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 128 | + #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | **/ |
| 148 | 148 | function _sqlite_add_function(&$sqlite, &$f, &$r) { |
| 149 | - isset($r[1]) |
|
| 150 | - ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 151 | - : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 149 | + isset($r[1]) |
|
| 150 | + ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 151 | + : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return int |
| 159 | 159 | */ |
| 160 | 160 | function _sqlite_func_ceil($a) { |
| 161 | - return ceil($a); |
|
| 161 | + return ceil($a); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | function _sqlite_func_concat(...$args) { |
| 171 | - return implode('', $args); |
|
| 171 | + return implode('', $args); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @return string |
| 182 | 182 | */ |
| 183 | 183 | function _sqlite_func_dayofmonth($d) { |
| 184 | - return _sqlite_func_date('d', $d); |
|
| 184 | + return _sqlite_func_date('d', $d); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -193,15 +193,15 @@ discard block |
||
| 193 | 193 | * @return int |
| 194 | 194 | */ |
| 195 | 195 | function _sqlite_func_find_in_set($num, $set) { |
| 196 | - $rank = 0; |
|
| 197 | - foreach (explode(',', $set) as $v) { |
|
| 198 | - if ($v == $num) { |
|
| 199 | - return (++$rank); |
|
| 200 | - } |
|
| 201 | - $rank++; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return 0; |
|
| 196 | + $rank = 0; |
|
| 197 | + foreach (explode(',', $set) as $v) { |
|
| 198 | + if ($v == $num) { |
|
| 199 | + return (++$rank); |
|
| 200 | + } |
|
| 201 | + $rank++; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return 0; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @return int |
| 212 | 212 | */ |
| 213 | 213 | function _sqlite_func_floor($a) { |
| 214 | - return floor($a); |
|
| 214 | + return floor($a); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @return mixed |
| 225 | 225 | */ |
| 226 | 226 | function _sqlite_func_if($bool, $oui, $non) { |
| 227 | - return ($bool) ? $oui : $non; |
|
| 227 | + return ($bool) ? $oui : $non; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function _sqlite_func_insert($s, $index, $longueur, $chaine) { |
| 244 | - return |
|
| 245 | - substr($s, 0, $index) |
|
| 246 | - . $chaine |
|
| 247 | - . substr(substr($s, $index), $longueur); |
|
| 244 | + return |
|
| 245 | + substr($s, 0, $index) |
|
| 246 | + . $chaine |
|
| 247 | + . substr(substr($s, $index), $longueur); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return int |
| 257 | 257 | */ |
| 258 | 258 | function _sqlite_func_instr($s, $search) { |
| 259 | - return strpos($s, $search); |
|
| 259 | + return strpos($s, $search); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return int |
| 268 | 268 | */ |
| 269 | 269 | function _sqlite_func_least(...$args) { |
| 270 | - return min($args); |
|
| 270 | + return min($args); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @return int |
| 279 | 279 | */ |
| 280 | 280 | function _sqlite_func_greatest(...$args) { |
| 281 | - return max($args); |
|
| 281 | + return max($args); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @return string |
| 291 | 291 | */ |
| 292 | 292 | function _sqlite_func_left($s, $lenght) { |
| 293 | - return substr($s, $lenght); |
|
| 293 | + return substr($s, $lenght); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | * @return string |
| 301 | 301 | */ |
| 302 | 302 | function _sqlite_func_now($force_refresh = false) { |
| 303 | - static $now = null; |
|
| 304 | - if (is_null($now) || $force_refresh) { |
|
| 305 | - $now = date('Y-m-d H:i:s'); |
|
| 306 | - } |
|
| 303 | + static $now = null; |
|
| 304 | + if (is_null($now) || $force_refresh) { |
|
| 305 | + $now = date('Y-m-d H:i:s'); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 309 | - return $now; |
|
| 308 | + #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 309 | + return $now; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @return string |
| 320 | 320 | */ |
| 321 | 321 | function _sqlite_func_month($d) { |
| 322 | - return _sqlite_func_date('m', $d); |
|
| 322 | + return _sqlite_func_date('m', $d); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | 334 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 335 | - #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 336 | - return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 335 | + #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 336 | + return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | * @return string, l'extrait trouve. |
| 347 | 347 | **/ |
| 348 | 348 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 349 | - if (str_contains($quoi, '<')) { |
|
| 350 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 351 | - include_spip('src/Texte/Collecteur/Multis'); |
|
| 352 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 353 | - $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 354 | - } |
|
| 355 | - return $quoi; |
|
| 349 | + if (str_contains($quoi, '<')) { |
|
| 350 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 351 | + include_spip('src/Texte/Collecteur/Multis'); |
|
| 352 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 353 | + $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 354 | + } |
|
| 355 | + return $quoi; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @return float |
| 363 | 363 | */ |
| 364 | 364 | function _sqlite_func_rand() { |
| 365 | - return random_int(0, mt_getrandmax()); |
|
| 365 | + return random_int(0, mt_getrandmax()); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function _sqlite_func_right($s, $length) { |
| 377 | - return substr($s, 0 - $length); |
|
| 377 | + return substr($s, 0 - $length); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | |
@@ -386,16 +386,16 @@ discard block |
||
| 386 | 386 | * @return bool |
| 387 | 387 | */ |
| 388 | 388 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 389 | - // optimiser un cas tres courant avec les requetes en base |
|
| 390 | - if (!$quoi && !strlen($quoi)) { |
|
| 391 | - return false; |
|
| 392 | - } |
|
| 393 | - // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 394 | - $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 395 | - $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 396 | - |
|
| 397 | - #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 398 | - return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 389 | + // optimiser un cas tres courant avec les requetes en base |
|
| 390 | + if (!$quoi && !strlen($quoi)) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 394 | + $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 395 | + $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 396 | + |
|
| 397 | + #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 398 | + return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * @return string |
| 411 | 411 | */ |
| 412 | 412 | function _sqlite_func_date_format($date, $conv) { |
| 413 | - $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 414 | - return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 413 | + $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 414 | + return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -427,28 +427,28 @@ discard block |
||
| 427 | 427 | * @return void |
| 428 | 428 | */ |
| 429 | 429 | function _sqlite_func_strftime_format_converter(string $conv): string { |
| 430 | - // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 431 | - // on ne sait pas en gérer certains... |
|
| 432 | - static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 433 | - static $mysql_to_strftime = [ |
|
| 434 | - '%h' => '%I', |
|
| 435 | - '%i' => '%M', |
|
| 436 | - '%M' => '%B', |
|
| 437 | - '%s' => '%S', |
|
| 438 | - '%u' => '%U', |
|
| 439 | - '%v' => '%V', |
|
| 440 | - '%x' => '%G', |
|
| 441 | - ]; |
|
| 442 | - static $to_strftime = []; |
|
| 443 | - if (!isset($to_strftime[$conv])) { |
|
| 444 | - $count = 0; |
|
| 445 | - str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 446 | - if ($count > 0) { |
|
| 447 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 448 | - } |
|
| 449 | - $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 450 | - } |
|
| 451 | - return $to_strftime[$conv]; |
|
| 430 | + // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 431 | + // on ne sait pas en gérer certains... |
|
| 432 | + static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 433 | + static $mysql_to_strftime = [ |
|
| 434 | + '%h' => '%I', |
|
| 435 | + '%i' => '%M', |
|
| 436 | + '%M' => '%B', |
|
| 437 | + '%s' => '%S', |
|
| 438 | + '%u' => '%U', |
|
| 439 | + '%v' => '%V', |
|
| 440 | + '%x' => '%G', |
|
| 441 | + ]; |
|
| 442 | + static $to_strftime = []; |
|
| 443 | + if (!isset($to_strftime[$conv])) { |
|
| 444 | + $count = 0; |
|
| 445 | + str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 446 | + if ($count > 0) { |
|
| 447 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 448 | + } |
|
| 449 | + $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 450 | + } |
|
| 451 | + return $to_strftime[$conv]; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * @return int |
| 463 | 463 | */ |
| 464 | 464 | function _sqlite_func_to_days($d) { |
| 465 | - static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 466 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 465 | + static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 466 | + $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 467 | 467 | |
| 468 | - #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 469 | - return $result; |
|
| 468 | + #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 469 | + return $result; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -478,13 +478,13 @@ discard block |
||
| 478 | 478 | * @return string |
| 479 | 479 | */ |
| 480 | 480 | function _sqlite_func_substring($string, $start, $len = null) { |
| 481 | - // SQL compte a partir de 1, php a partir de 0 |
|
| 482 | - $start = ($start > 0) ? $start - 1 : $start; |
|
| 483 | - if (is_null($len)) { |
|
| 484 | - return substr($string, $start); |
|
| 485 | - } else { |
|
| 486 | - return substr($string, $start, $len); |
|
| 487 | - } |
|
| 481 | + // SQL compte a partir de 1, php a partir de 0 |
|
| 482 | + $start = ($start > 0) ? $start - 1 : $start; |
|
| 483 | + if (is_null($len)) { |
|
| 484 | + return substr($string, $start); |
|
| 485 | + } else { |
|
| 486 | + return substr($string, $start, $len); |
|
| 487 | + } |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -500,22 +500,22 @@ discard block |
||
| 500 | 500 | * @return int |
| 501 | 501 | */ |
| 502 | 502 | function _sqlite_timestampdiff($unit, $date1, $date2) { |
| 503 | - $d1 = date_create($date1); |
|
| 504 | - $d2 = date_create($date2); |
|
| 505 | - $diff = date_diff($d1, $d2); |
|
| 506 | - $inv = $diff->invert ? -1 : 1; |
|
| 507 | - return match ($unit) { |
|
| 508 | - 'YEAR' => $inv * $diff->y, |
|
| 509 | - 'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)), |
|
| 510 | - 'MONTH' => $inv * (12 * $diff->y + $diff->m), |
|
| 511 | - 'WEEK' => $inv * (int) floor($diff->days / 7), |
|
| 512 | - 'DAY' => $inv * $diff->days, |
|
| 513 | - 'HOUR' => $inv * (24 * $diff->days + $diff->h), |
|
| 514 | - 'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i), |
|
| 515 | - 'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s), |
|
| 516 | - 'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000, |
|
| 517 | - default => 0, |
|
| 518 | - }; |
|
| 503 | + $d1 = date_create($date1); |
|
| 504 | + $d2 = date_create($date2); |
|
| 505 | + $diff = date_diff($d1, $d2); |
|
| 506 | + $inv = $diff->invert ? -1 : 1; |
|
| 507 | + return match ($unit) { |
|
| 508 | + 'YEAR' => $inv * $diff->y, |
|
| 509 | + 'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)), |
|
| 510 | + 'MONTH' => $inv * (12 * $diff->y + $diff->m), |
|
| 511 | + 'WEEK' => $inv * (int) floor($diff->days / 7), |
|
| 512 | + 'DAY' => $inv * $diff->days, |
|
| 513 | + 'HOUR' => $inv * (24 * $diff->days + $diff->h), |
|
| 514 | + 'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i), |
|
| 515 | + 'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s), |
|
| 516 | + 'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000, |
|
| 517 | + default => 0, |
|
| 518 | + }; |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -525,24 +525,24 @@ discard block |
||
| 525 | 525 | * @return int |
| 526 | 526 | */ |
| 527 | 527 | function _sqlite_func_unix_timestamp($d) { |
| 528 | - static $mem = []; |
|
| 529 | - static $n = 0; |
|
| 530 | - if (isset($mem[$d])) { |
|
| 531 | - return $mem[$d]; |
|
| 532 | - } |
|
| 533 | - if ($n++ > 100) { |
|
| 534 | - $mem = []; |
|
| 535 | - $n = 0; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - //2005-12-02 20:53:53 |
|
| 539 | - #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 540 | - if (!$d) { |
|
| 541 | - return $mem[$d] = time(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // une pile plus grosse n'accelere pas le calcul |
|
| 545 | - return $mem[$d] = strtotime($d); |
|
| 528 | + static $mem = []; |
|
| 529 | + static $n = 0; |
|
| 530 | + if (isset($mem[$d])) { |
|
| 531 | + return $mem[$d]; |
|
| 532 | + } |
|
| 533 | + if ($n++ > 100) { |
|
| 534 | + $mem = []; |
|
| 535 | + $n = 0; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + //2005-12-02 20:53:53 |
|
| 539 | + #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 540 | + if (!$d) { |
|
| 541 | + return $mem[$d] = time(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // une pile plus grosse n'accelere pas le calcul |
|
| 545 | + return $mem[$d] = strtotime($d); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | * @return string |
| 556 | 556 | */ |
| 557 | 557 | function _sqlite_func_year($d) { |
| 558 | - return _sqlite_func_date('Y', $d); |
|
| 558 | + return _sqlite_func_date('Y', $d); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -568,20 +568,20 @@ discard block |
||
| 568 | 568 | * @return string |
| 569 | 569 | */ |
| 570 | 570 | function _sqlite_func_date($quoi, $d) { |
| 571 | - static $mem = []; |
|
| 572 | - static $n = 0; |
|
| 573 | - if (isset($mem[$d])) { |
|
| 574 | - return $mem[$d][$quoi]; |
|
| 575 | - } |
|
| 576 | - if ($n++ > 100) { |
|
| 577 | - $mem = []; |
|
| 578 | - $n = 0; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 582 | - $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 583 | - |
|
| 584 | - return $mem[$d][$quoi]; |
|
| 571 | + static $mem = []; |
|
| 572 | + static $n = 0; |
|
| 573 | + if (isset($mem[$d])) { |
|
| 574 | + return $mem[$d][$quoi]; |
|
| 575 | + } |
|
| 576 | + if ($n++ > 100) { |
|
| 577 | + $mem = []; |
|
| 578 | + $n = 0; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 582 | + $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 583 | + |
|
| 584 | + return $mem[$d][$quoi]; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,5 +590,5 @@ discard block |
||
| 590 | 590 | * @return void |
| 591 | 591 | */ |
| 592 | 592 | function _sqlite_func_vide() { |
| 593 | - return; |
|
| 593 | + return; |
|
| 594 | 594 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 335 | 335 | #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
| 336 | - return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 336 | + return preg_replace('%'.$cherche.'%', $remplace, $quoi); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
| 396 | 396 | |
| 397 | 397 | #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
| 398 | - return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 398 | + return preg_match('%'.$cherche.'%imsS'.$u, $quoi); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | $count = 0; |
| 445 | 445 | str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
| 446 | 446 | if ($count > 0) { |
| 447 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 447 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.'._LOG_ERREUR); |
|
| 448 | 448 | } |
| 449 | 449 | $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
| 450 | 450 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | function _sqlite_func_to_days($d) { |
| 465 | 465 | static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
| 466 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 466 | + $result = $offset + (int) ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 467 | 467 | |
| 468 | 468 | #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
| 469 | 469 | return $result; |
@@ -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 | define('_DEFAULT_DB', 'spip'); |
@@ -30,155 +30,155 @@ discard block |
||
| 30 | 30 | // si ca ne marche toujours pas, echec. |
| 31 | 31 | |
| 32 | 32 | function req_pg_dist($addr, $port, $login, #[\SensitiveParameter] $pass, $db = '', $prefixe = '') { |
| 33 | - static $last_connect = []; |
|
| 34 | - if (!extension_loaded('pgsql')) { |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // si provient de selectdb |
|
| 39 | - if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 40 | - foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 41 | - ${$a} = $last_connect[$a]; |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - [$host, $p] = array_pad(explode(';', $addr), 2, null); |
|
| 45 | - $port = $p > 0 ? " port=$p" : ''; |
|
| 46 | - $erreurs = []; |
|
| 47 | - if ($db) { |
|
| 48 | - @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 49 | - } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 50 | - $erreurs[] = pg_last_error(); |
|
| 51 | - if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 52 | - $db = $login; |
|
| 53 | - } else { |
|
| 54 | - $erreurs[] = pg_last_error(); |
|
| 55 | - $db = _DEFAULT_DB; |
|
| 56 | - $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if (!$link) { |
|
| 60 | - $erreurs[] = pg_last_error(); |
|
| 61 | - foreach ($erreurs as $e) { |
|
| 62 | - spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return false; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($link) { |
|
| 69 | - $last_connect = [ |
|
| 70 | - 'addr' => $addr, |
|
| 71 | - 'port' => $port, |
|
| 72 | - 'login' => $login, |
|
| 73 | - 'pass' => $pass, |
|
| 74 | - 'db' => $db, |
|
| 75 | - 'prefixe' => $prefixe, |
|
| 76 | - ]; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - spip_log( |
|
| 80 | - "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 81 | - 'pg.' . _LOG_DEBUG |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - return $link ? [ |
|
| 85 | - 'db' => $db, |
|
| 86 | - 'prefixe' => $prefixe ?: $db, |
|
| 87 | - 'link' => $link, |
|
| 88 | - ] : false; |
|
| 33 | + static $last_connect = []; |
|
| 34 | + if (!extension_loaded('pgsql')) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // si provient de selectdb |
|
| 39 | + if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 40 | + foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 41 | + ${$a} = $last_connect[$a]; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + [$host, $p] = array_pad(explode(';', $addr), 2, null); |
|
| 45 | + $port = $p > 0 ? " port=$p" : ''; |
|
| 46 | + $erreurs = []; |
|
| 47 | + if ($db) { |
|
| 48 | + @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 49 | + } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 50 | + $erreurs[] = pg_last_error(); |
|
| 51 | + if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 52 | + $db = $login; |
|
| 53 | + } else { |
|
| 54 | + $erreurs[] = pg_last_error(); |
|
| 55 | + $db = _DEFAULT_DB; |
|
| 56 | + $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if (!$link) { |
|
| 60 | + $erreurs[] = pg_last_error(); |
|
| 61 | + foreach ($erreurs as $e) { |
|
| 62 | + spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($link) { |
|
| 69 | + $last_connect = [ |
|
| 70 | + 'addr' => $addr, |
|
| 71 | + 'port' => $port, |
|
| 72 | + 'login' => $login, |
|
| 73 | + 'pass' => $pass, |
|
| 74 | + 'db' => $db, |
|
| 75 | + 'prefixe' => $prefixe, |
|
| 76 | + ]; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + spip_log( |
|
| 80 | + "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 81 | + 'pg.' . _LOG_DEBUG |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + return $link ? [ |
|
| 85 | + 'db' => $db, |
|
| 86 | + 'prefixe' => $prefixe ?: $db, |
|
| 87 | + 'link' => $link, |
|
| 88 | + ] : false; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $GLOBALS['spip_pg_functions_1'] = [ |
| 92 | - 'alter' => 'spip_pg_alter', |
|
| 93 | - 'count' => 'spip_pg_count', |
|
| 94 | - 'countsel' => 'spip_pg_countsel', |
|
| 95 | - 'create' => 'spip_pg_create', |
|
| 96 | - 'create_base' => 'spip_pg_create_base', |
|
| 97 | - 'create_view' => 'spip_pg_create_view', |
|
| 98 | - 'date_proche' => 'spip_pg_date_proche', |
|
| 99 | - 'delete' => 'spip_pg_delete', |
|
| 100 | - 'drop_table' => 'spip_pg_drop_table', |
|
| 101 | - 'drop_view' => 'spip_pg_drop_view', |
|
| 102 | - 'errno' => 'spip_pg_errno', |
|
| 103 | - 'error' => 'spip_pg_error', |
|
| 104 | - 'explain' => 'spip_pg_explain', |
|
| 105 | - 'fetch' => 'spip_pg_fetch', |
|
| 106 | - 'seek' => 'spip_pg_seek', |
|
| 107 | - 'free' => 'spip_pg_free', |
|
| 108 | - 'hex' => 'spip_pg_hex', |
|
| 109 | - 'in' => 'spip_pg_in', |
|
| 110 | - 'insert' => 'spip_pg_insert', |
|
| 111 | - 'insertq' => 'spip_pg_insertq', |
|
| 112 | - 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 113 | - 'listdbs' => 'spip_pg_listdbs', |
|
| 114 | - 'multi' => 'spip_pg_multi', |
|
| 115 | - 'optimize' => 'spip_pg_optimize', |
|
| 116 | - 'query' => 'spip_pg_query', |
|
| 117 | - 'quote' => 'spip_pg_quote', |
|
| 118 | - 'replace' => 'spip_pg_replace', |
|
| 119 | - 'replace_multi' => 'spip_pg_replace_multi', |
|
| 120 | - 'select' => 'spip_pg_select', |
|
| 121 | - 'selectdb' => 'spip_pg_selectdb', |
|
| 122 | - 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 123 | - 'showbase' => 'spip_pg_showbase', |
|
| 124 | - 'showtable' => 'spip_pg_showtable', |
|
| 125 | - 'update' => 'spip_pg_update', |
|
| 126 | - 'updateq' => 'spip_pg_updateq', |
|
| 92 | + 'alter' => 'spip_pg_alter', |
|
| 93 | + 'count' => 'spip_pg_count', |
|
| 94 | + 'countsel' => 'spip_pg_countsel', |
|
| 95 | + 'create' => 'spip_pg_create', |
|
| 96 | + 'create_base' => 'spip_pg_create_base', |
|
| 97 | + 'create_view' => 'spip_pg_create_view', |
|
| 98 | + 'date_proche' => 'spip_pg_date_proche', |
|
| 99 | + 'delete' => 'spip_pg_delete', |
|
| 100 | + 'drop_table' => 'spip_pg_drop_table', |
|
| 101 | + 'drop_view' => 'spip_pg_drop_view', |
|
| 102 | + 'errno' => 'spip_pg_errno', |
|
| 103 | + 'error' => 'spip_pg_error', |
|
| 104 | + 'explain' => 'spip_pg_explain', |
|
| 105 | + 'fetch' => 'spip_pg_fetch', |
|
| 106 | + 'seek' => 'spip_pg_seek', |
|
| 107 | + 'free' => 'spip_pg_free', |
|
| 108 | + 'hex' => 'spip_pg_hex', |
|
| 109 | + 'in' => 'spip_pg_in', |
|
| 110 | + 'insert' => 'spip_pg_insert', |
|
| 111 | + 'insertq' => 'spip_pg_insertq', |
|
| 112 | + 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 113 | + 'listdbs' => 'spip_pg_listdbs', |
|
| 114 | + 'multi' => 'spip_pg_multi', |
|
| 115 | + 'optimize' => 'spip_pg_optimize', |
|
| 116 | + 'query' => 'spip_pg_query', |
|
| 117 | + 'quote' => 'spip_pg_quote', |
|
| 118 | + 'replace' => 'spip_pg_replace', |
|
| 119 | + 'replace_multi' => 'spip_pg_replace_multi', |
|
| 120 | + 'select' => 'spip_pg_select', |
|
| 121 | + 'selectdb' => 'spip_pg_selectdb', |
|
| 122 | + 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 123 | + 'showbase' => 'spip_pg_showbase', |
|
| 124 | + 'showtable' => 'spip_pg_showtable', |
|
| 125 | + 'update' => 'spip_pg_update', |
|
| 126 | + 'updateq' => 'spip_pg_updateq', |
|
| 127 | 127 | ]; |
| 128 | 128 | |
| 129 | 129 | // Par ou ca passe une fois les traductions faites |
| 130 | 130 | function spip_pg_trace_query($query, $serveur = '') { |
| 131 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 132 | - $prefixe = $connexion['prefixe']; |
|
| 133 | - $link = $connexion['link']; |
|
| 134 | - $db = $connexion['db']; |
|
| 135 | - |
|
| 136 | - if (isset($_GET['var_profile'])) { |
|
| 137 | - include_spip('public/tracer'); |
|
| 138 | - $t = trace_query_start(); |
|
| 139 | - $e = ''; |
|
| 140 | - } else { |
|
| 141 | - $t = 0; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $connexion['last'] = $query; |
|
| 145 | - $r = spip_pg_query_simple($link, $query); |
|
| 146 | - |
|
| 147 | - // Log de l'erreur eventuelle |
|
| 148 | - if ($e = spip_pg_errno($serveur)) { |
|
| 149 | - $e .= spip_pg_error($query, $serveur); |
|
| 150 | - } // et du fautif |
|
| 151 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 131 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 132 | + $prefixe = $connexion['prefixe']; |
|
| 133 | + $link = $connexion['link']; |
|
| 134 | + $db = $connexion['db']; |
|
| 135 | + |
|
| 136 | + if (isset($_GET['var_profile'])) { |
|
| 137 | + include_spip('public/tracer'); |
|
| 138 | + $t = trace_query_start(); |
|
| 139 | + $e = ''; |
|
| 140 | + } else { |
|
| 141 | + $t = 0; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $connexion['last'] = $query; |
|
| 145 | + $r = spip_pg_query_simple($link, $query); |
|
| 146 | + |
|
| 147 | + // Log de l'erreur eventuelle |
|
| 148 | + if ($e = spip_pg_errno($serveur)) { |
|
| 149 | + $e .= spip_pg_error($query, $serveur); |
|
| 150 | + } // et du fautif |
|
| 151 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Fonction de requete generale quand on est sur que c'est SQL standard. |
| 155 | 155 | // Elle change juste le noms des tables ($table_prefix) dans le FROM etc |
| 156 | 156 | |
| 157 | 157 | function spip_pg_query($query, $serveur = '', $requeter = true) { |
| 158 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 159 | - $prefixe = $connexion['prefixe']; |
|
| 160 | - $link = $connexion['link']; |
|
| 161 | - $db = $connexion['db']; |
|
| 162 | - |
|
| 163 | - if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 164 | - $suite = strstr($query, (string) $regs[0]); |
|
| 165 | - $query = substr($query, 0, -strlen($suite)); |
|
| 166 | - } else { |
|
| 167 | - $suite = ''; |
|
| 168 | - } |
|
| 169 | - $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 170 | - |
|
| 171 | - // renvoyer la requete inerte si demandee |
|
| 172 | - if (!$requeter) { |
|
| 173 | - return $query; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return spip_pg_trace_query($query, $serveur); |
|
| 158 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 159 | + $prefixe = $connexion['prefixe']; |
|
| 160 | + $link = $connexion['link']; |
|
| 161 | + $db = $connexion['db']; |
|
| 162 | + |
|
| 163 | + if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 164 | + $suite = strstr($query, (string) $regs[0]); |
|
| 165 | + $query = substr($query, 0, -strlen($suite)); |
|
| 166 | + } else { |
|
| 167 | + $suite = ''; |
|
| 168 | + } |
|
| 169 | + $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 170 | + |
|
| 171 | + // renvoyer la requete inerte si demandee |
|
| 172 | + if (!$requeter) { |
|
| 173 | + return $query; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return spip_pg_trace_query($query, $serveur); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | function spip_pg_query_simple($link, $query) { |
| 180 | - #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 181 | - return pg_query($link, $query); |
|
| 180 | + #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 181 | + return pg_query($link, $query); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /* |
@@ -190,192 +190,192 @@ discard block |
||
| 190 | 190 | * de requetes showtable intempestives |
| 191 | 191 | */ |
| 192 | 192 | function spip_pg_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') { |
| 193 | - static $tables = []; |
|
| 194 | - |
|
| 195 | - if (!isset($tables[$table])) { |
|
| 196 | - if (!$desc) { |
|
| 197 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 198 | - $desc = $trouver_table($table, $serveur); |
|
| 199 | - // si pas de description, on ne fait rien, ou on die() ? |
|
| 200 | - if (!$desc) { |
|
| 201 | - return $couples; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // recherche des champs avec simplement 'TIMESTAMP' |
|
| 206 | - // cependant, il faudra peut etre etendre |
|
| 207 | - // avec la gestion de DEFAULT et ON UPDATE |
|
| 208 | - // mais ceux-ci ne sont pas utilises dans le core |
|
| 209 | - $tables[$table] = []; |
|
| 210 | - foreach ($desc['field'] as $k => $v) { |
|
| 211 | - $v = strtolower(ltrim($v)); |
|
| 212 | - // ne pas ajouter de timestamp now() si un default est specifie |
|
| 213 | - if (str_starts_with($v, 'timestamp') && !str_contains($v, 'default')) { |
|
| 214 | - $tables[$table][] = $k; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // ajout des champs type 'timestamp' absents |
|
| 220 | - foreach ($tables[$table] as $maj) { |
|
| 221 | - if (!array_key_exists($maj, $couples)) { |
|
| 222 | - $couples[$maj] = 'NOW()'; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - return $couples; |
|
| 193 | + static $tables = []; |
|
| 194 | + |
|
| 195 | + if (!isset($tables[$table])) { |
|
| 196 | + if (!$desc) { |
|
| 197 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 198 | + $desc = $trouver_table($table, $serveur); |
|
| 199 | + // si pas de description, on ne fait rien, ou on die() ? |
|
| 200 | + if (!$desc) { |
|
| 201 | + return $couples; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // recherche des champs avec simplement 'TIMESTAMP' |
|
| 206 | + // cependant, il faudra peut etre etendre |
|
| 207 | + // avec la gestion de DEFAULT et ON UPDATE |
|
| 208 | + // mais ceux-ci ne sont pas utilises dans le core |
|
| 209 | + $tables[$table] = []; |
|
| 210 | + foreach ($desc['field'] as $k => $v) { |
|
| 211 | + $v = strtolower(ltrim($v)); |
|
| 212 | + // ne pas ajouter de timestamp now() si un default est specifie |
|
| 213 | + if (str_starts_with($v, 'timestamp') && !str_contains($v, 'default')) { |
|
| 214 | + $tables[$table][] = $k; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // ajout des champs type 'timestamp' absents |
|
| 220 | + foreach ($tables[$table] as $maj) { |
|
| 221 | + if (!array_key_exists($maj, $couples)) { |
|
| 222 | + $couples[$maj] = 'NOW()'; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + return $couples; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | // Alter en PG ne traite pas les index |
| 231 | 231 | function spip_pg_alter($query, $serveur = '', $requeter = true) { |
| 232 | - // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 233 | - // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 234 | - // ou revoir l'api de sql_alter en creant un |
|
| 235 | - // sql_alter_table($table,array($actions)); |
|
| 236 | - if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 237 | - spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 238 | - |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - $debut = $regs[1]; |
|
| 242 | - $table = $regs[3]; |
|
| 243 | - $suite = $regs[4]; |
|
| 244 | - $todo = explode(',', $suite); |
|
| 245 | - // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 246 | - $todo2 = []; |
|
| 247 | - $i = 0; |
|
| 248 | - $ouverte = false; |
|
| 249 | - while ($do = array_shift($todo)) { |
|
| 250 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 251 | - $o = (str_contains($do, '(')); |
|
| 252 | - $f = (str_contains($do, ')')); |
|
| 253 | - if ($o && !$f) { |
|
| 254 | - $ouverte = true; |
|
| 255 | - } elseif ($f) { |
|
| 256 | - $ouverte = false; |
|
| 257 | - } |
|
| 258 | - if (!$ouverte) { |
|
| 259 | - $i++; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - $todo = $todo2; |
|
| 263 | - $query = $debut . ' ' . array_shift($todo); |
|
| 264 | - |
|
| 265 | - if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 266 | - spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 267 | - } else { |
|
| 268 | - if ($r[1]) { |
|
| 269 | - spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 270 | - } |
|
| 271 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 272 | - if (function_exists($f)) { |
|
| 273 | - $f($r[2], $r[4], $serveur, $requeter); |
|
| 274 | - } else { |
|
| 275 | - spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - // Alter a plusieurs args. Faudrait optimiser. |
|
| 279 | - if ($todo) { |
|
| 280 | - spip_pg_alter("TABLE $table " . implode(',', $todo)); |
|
| 281 | - } |
|
| 232 | + // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 233 | + // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 234 | + // ou revoir l'api de sql_alter en creant un |
|
| 235 | + // sql_alter_table($table,array($actions)); |
|
| 236 | + if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 237 | + spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 238 | + |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 241 | + $debut = $regs[1]; |
|
| 242 | + $table = $regs[3]; |
|
| 243 | + $suite = $regs[4]; |
|
| 244 | + $todo = explode(',', $suite); |
|
| 245 | + // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 246 | + $todo2 = []; |
|
| 247 | + $i = 0; |
|
| 248 | + $ouverte = false; |
|
| 249 | + while ($do = array_shift($todo)) { |
|
| 250 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 251 | + $o = (str_contains($do, '(')); |
|
| 252 | + $f = (str_contains($do, ')')); |
|
| 253 | + if ($o && !$f) { |
|
| 254 | + $ouverte = true; |
|
| 255 | + } elseif ($f) { |
|
| 256 | + $ouverte = false; |
|
| 257 | + } |
|
| 258 | + if (!$ouverte) { |
|
| 259 | + $i++; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + $todo = $todo2; |
|
| 263 | + $query = $debut . ' ' . array_shift($todo); |
|
| 264 | + |
|
| 265 | + if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 266 | + spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 267 | + } else { |
|
| 268 | + if ($r[1]) { |
|
| 269 | + spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 270 | + } |
|
| 271 | + $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 272 | + if (function_exists($f)) { |
|
| 273 | + $f($r[2], $r[4], $serveur, $requeter); |
|
| 274 | + } else { |
|
| 275 | + spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + // Alter a plusieurs args. Faudrait optimiser. |
|
| 279 | + if ($todo) { |
|
| 280 | + spip_pg_alter("TABLE $table " . implode(',', $todo)); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 285 | - if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 286 | - spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 287 | - } else { |
|
| 288 | - [, $old, $new, $type, $default, $null, $def2] = $r; |
|
| 289 | - $actions = ["ALTER $old TYPE " . mysql2pg_type($type)]; |
|
| 290 | - $actions[] = $null ? "ALTER $old SET NOT NULL" : "ALTER $old DROP NOT NULL"; |
|
| 291 | - |
|
| 292 | - if ($d = ($default ?: $def2)) { |
|
| 293 | - $actions[] = "ALTER $old SET $d"; |
|
| 294 | - } else { |
|
| 295 | - $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - spip_pg_query("ALTER TABLE $table " . implode(', ', $actions)); |
|
| 299 | - |
|
| 300 | - if ($old !== $new) { |
|
| 301 | - spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 302 | - } |
|
| 303 | - } |
|
| 285 | + if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 286 | + spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 287 | + } else { |
|
| 288 | + [, $old, $new, $type, $default, $null, $def2] = $r; |
|
| 289 | + $actions = ["ALTER $old TYPE " . mysql2pg_type($type)]; |
|
| 290 | + $actions[] = $null ? "ALTER $old SET NOT NULL" : "ALTER $old DROP NOT NULL"; |
|
| 291 | + |
|
| 292 | + if ($d = ($default ?: $def2)) { |
|
| 293 | + $actions[] = "ALTER $old SET $d"; |
|
| 294 | + } else { |
|
| 295 | + $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + spip_pg_query("ALTER TABLE $table " . implode(', ', $actions)); |
|
| 299 | + |
|
| 300 | + if ($old !== $new) { |
|
| 301 | + spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
| 307 | - $nom_index = null; |
|
| 308 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 309 | - spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 310 | - |
|
| 311 | - return null; |
|
| 312 | - } |
|
| 313 | - if (!$r[1] || $r[1] == 'COLUMN') { |
|
| 314 | - preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 315 | - if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 316 | - $m[2] = $n[1]; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 320 | - } elseif ($r[1][0] == 'P') { |
|
| 321 | - // la primary peut etre sur plusieurs champs |
|
| 322 | - $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 323 | - $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 324 | - |
|
| 325 | - return spip_pg_query( |
|
| 326 | - "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', |
|
| 327 | - $serveur, |
|
| 328 | - $requeter |
|
| 329 | - ); |
|
| 330 | - } else { |
|
| 331 | - preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 332 | - // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 333 | - // bug potentiel si qqn met "(colonne, colonne)" |
|
| 334 | - // |
|
| 335 | - // nom_index (colonnes) |
|
| 336 | - if ($m[2]) { |
|
| 337 | - $colonnes = substr($m[2], 1, -1); |
|
| 338 | - $nom_index = $m[1]; |
|
| 339 | - } else { |
|
| 340 | - // (colonne) |
|
| 341 | - if ($m[1][0] == '(') { |
|
| 342 | - $colonnes = substr($m[1], 1, -1); |
|
| 343 | - if (str_contains(',', $colonnes)) { |
|
| 344 | - spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 345 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 346 | - } else { |
|
| 347 | - $nom_index = $colonnes; |
|
| 348 | - } |
|
| 349 | - } // nom_index |
|
| 350 | - else { |
|
| 351 | - $nom_index = $colonnes = $m[1]; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 356 | - } |
|
| 307 | + $nom_index = null; |
|
| 308 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 309 | + spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 310 | + |
|
| 311 | + return null; |
|
| 312 | + } |
|
| 313 | + if (!$r[1] || $r[1] == 'COLUMN') { |
|
| 314 | + preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 315 | + if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 316 | + $m[2] = $n[1]; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 320 | + } elseif ($r[1][0] == 'P') { |
|
| 321 | + // la primary peut etre sur plusieurs champs |
|
| 322 | + $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 323 | + $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 324 | + |
|
| 325 | + return spip_pg_query( |
|
| 326 | + "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', |
|
| 327 | + $serveur, |
|
| 328 | + $requeter |
|
| 329 | + ); |
|
| 330 | + } else { |
|
| 331 | + preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 332 | + // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 333 | + // bug potentiel si qqn met "(colonne, colonne)" |
|
| 334 | + // |
|
| 335 | + // nom_index (colonnes) |
|
| 336 | + if ($m[2]) { |
|
| 337 | + $colonnes = substr($m[2], 1, -1); |
|
| 338 | + $nom_index = $m[1]; |
|
| 339 | + } else { |
|
| 340 | + // (colonne) |
|
| 341 | + if ($m[1][0] == '(') { |
|
| 342 | + $colonnes = substr($m[1], 1, -1); |
|
| 343 | + if (str_contains(',', $colonnes)) { |
|
| 344 | + spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 345 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 346 | + } else { |
|
| 347 | + $nom_index = $colonnes; |
|
| 348 | + } |
|
| 349 | + } // nom_index |
|
| 350 | + else { |
|
| 351 | + $nom_index = $colonnes = $m[1]; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
| 360 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 361 | - spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 362 | - } else { |
|
| 363 | - if (!$r[1] || $r[1] == 'COLUMN') { |
|
| 364 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 365 | - } elseif ($r[1][0] == 'P') { |
|
| 366 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 367 | - } else { |
|
| 368 | - return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur); |
|
| 369 | - } |
|
| 370 | - } |
|
| 360 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 361 | + spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 362 | + } else { |
|
| 363 | + if (!$r[1] || $r[1] == 'COLUMN') { |
|
| 364 | + return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 365 | + } elseif ($r[1][0] == 'P') { |
|
| 366 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 367 | + } else { |
|
| 368 | + return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
| 374 | - if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 375 | - spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 376 | - } else { |
|
| 377 | - return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 378 | - } |
|
| 374 | + if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 375 | + spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 376 | + } else { |
|
| 377 | + return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // attention (en pg) : |
@@ -383,17 +383,17 @@ discard block |
||
| 383 | 383 | // - alter table A rename X to Y = changer le nom de la colonne X en Y |
| 384 | 384 | // pour l'instant, traiter simplement RENAME TO X |
| 385 | 385 | function spip_pg_alter_rename($table, $arg, $serveur = '', $requeter = true) { |
| 386 | - $rename = ''; |
|
| 387 | - // si TO, mais pas au debut |
|
| 388 | - if (!stripos($arg, 'TO ')) { |
|
| 389 | - $rename = $arg; |
|
| 390 | - } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 391 | - $rename = $r[2]; |
|
| 392 | - } else { |
|
| 393 | - spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 386 | + $rename = ''; |
|
| 387 | + // si TO, mais pas au debut |
|
| 388 | + if (!stripos($arg, 'TO ')) { |
|
| 389 | + $rename = $arg; |
|
| 390 | + } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 391 | + $rename = $r[2]; |
|
| 392 | + } else { |
|
| 393 | + spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
@@ -409,58 +409,58 @@ discard block |
||
| 409 | 409 | * @return bool ou requete |
| 410 | 410 | */ |
| 411 | 411 | function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
| 412 | - if (!($nom || $table || $champs)) { |
|
| 413 | - spip_log( |
|
| 414 | - "Champ manquant pour creer un index pg ($nom, $table, (" . @implode(',', $champs) . '))', |
|
| 415 | - 'pg.' . _LOG_ERREUR |
|
| 416 | - ); |
|
| 417 | - |
|
| 418 | - return false; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $nom = str_replace('`', '', $nom); |
|
| 422 | - $champs = str_replace('`', '', $champs); |
|
| 423 | - |
|
| 424 | - // PG ne differentie pas noms des index en fonction des tables |
|
| 425 | - // il faut donc creer des noms uniques d'index pour une base pg |
|
| 426 | - $nom = $table . '_' . $nom; |
|
| 427 | - // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 428 | - if (!is_array($champs)) { |
|
| 429 | - if ($champs[0] == '(') { |
|
| 430 | - $champs = substr($champs, 1, -1); |
|
| 431 | - } |
|
| 432 | - $champs = [$champs]; |
|
| 433 | - } |
|
| 434 | - $query = "CREATE INDEX $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 435 | - if (!$requeter) { |
|
| 436 | - return $query; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return spip_pg_query($query, $serveur, $requeter); |
|
| 412 | + if (!($nom || $table || $champs)) { |
|
| 413 | + spip_log( |
|
| 414 | + "Champ manquant pour creer un index pg ($nom, $table, (" . @implode(',', $champs) . '))', |
|
| 415 | + 'pg.' . _LOG_ERREUR |
|
| 416 | + ); |
|
| 417 | + |
|
| 418 | + return false; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $nom = str_replace('`', '', $nom); |
|
| 422 | + $champs = str_replace('`', '', $champs); |
|
| 423 | + |
|
| 424 | + // PG ne differentie pas noms des index en fonction des tables |
|
| 425 | + // il faut donc creer des noms uniques d'index pour une base pg |
|
| 426 | + $nom = $table . '_' . $nom; |
|
| 427 | + // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 428 | + if (!is_array($champs)) { |
|
| 429 | + if ($champs[0] == '(') { |
|
| 430 | + $champs = substr($champs, 1, -1); |
|
| 431 | + } |
|
| 432 | + $champs = [$champs]; |
|
| 433 | + } |
|
| 434 | + $query = "CREATE INDEX $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 435 | + if (!$requeter) { |
|
| 436 | + return $query; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return spip_pg_query($query, $serveur, $requeter); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | |
| 443 | 443 | function spip_pg_explain($query, $serveur = '', $requeter = true) { |
| 444 | - if (!str_starts_with(ltrim($query), 'SELECT')) { |
|
| 445 | - return []; |
|
| 446 | - } |
|
| 447 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 448 | - $prefixe = $connexion['prefixe']; |
|
| 449 | - $link = $connexion['link']; |
|
| 450 | - if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 451 | - $suite = strstr($query, (string) $regs[0]); |
|
| 452 | - $query = substr($query, 0, -strlen($suite)); |
|
| 453 | - } else { |
|
| 454 | - $suite = ''; |
|
| 455 | - } |
|
| 456 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 457 | - |
|
| 458 | - if (!$requeter) { |
|
| 459 | - return $query; |
|
| 460 | - } |
|
| 461 | - $r = spip_pg_query_simple($link, $query); |
|
| 462 | - |
|
| 463 | - return spip_pg_fetch($r, null, $serveur); |
|
| 444 | + if (!str_starts_with(ltrim($query), 'SELECT')) { |
|
| 445 | + return []; |
|
| 446 | + } |
|
| 447 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 448 | + $prefixe = $connexion['prefixe']; |
|
| 449 | + $link = $connexion['link']; |
|
| 450 | + if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 451 | + $suite = strstr($query, (string) $regs[0]); |
|
| 452 | + $query = substr($query, 0, -strlen($suite)); |
|
| 453 | + } else { |
|
| 454 | + $suite = ''; |
|
| 455 | + } |
|
| 456 | + $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 457 | + |
|
| 458 | + if (!$requeter) { |
|
| 459 | + return $query; |
|
| 460 | + } |
|
| 461 | + $r = spip_pg_query_simple($link, $query); |
|
| 462 | + |
|
| 463 | + return spip_pg_fetch($r, null, $serveur); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -479,88 +479,88 @@ discard block |
||
| 479 | 479 | * - False en cas d'erreur. |
| 480 | 480 | **/ |
| 481 | 481 | function spip_pg_selectdb($db, $serveur = '', $requeter = true) { |
| 482 | - // se connecter a la base indiquee |
|
| 483 | - // avec les identifiants connus |
|
| 484 | - $index = $serveur ? strtolower($serveur) : 0; |
|
| 482 | + // se connecter a la base indiquee |
|
| 483 | + // avec les identifiants connus |
|
| 484 | + $index = $serveur ? strtolower($serveur) : 0; |
|
| 485 | 485 | |
| 486 | - if (($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) && (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link)) { |
|
| 487 | - return $db; |
|
| 488 | - } |
|
| 486 | + if (($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) && (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link)) { |
|
| 487 | + return $db; |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - return false; |
|
| 490 | + return false; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | // Qu'une seule base pour le moment |
| 494 | 494 | |
| 495 | 495 | function spip_pg_listdbs($serveur) { |
| 496 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 497 | - $link = $connexion['link']; |
|
| 498 | - $dbs = []; |
|
| 499 | - $res = spip_pg_query_simple($link, 'select * From pg_database'); |
|
| 500 | - while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 501 | - $dbs[] = reset($row); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - return $dbs; |
|
| 496 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 497 | + $link = $connexion['link']; |
|
| 498 | + $dbs = []; |
|
| 499 | + $res = spip_pg_query_simple($link, 'select * From pg_database'); |
|
| 500 | + while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 501 | + $dbs[] = reset($row); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + return $dbs; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | function spip_pg_select( |
| 508 | - $select, |
|
| 509 | - $from, |
|
| 510 | - $where = '', |
|
| 511 | - $groupby = [], |
|
| 512 | - $orderby = '', |
|
| 513 | - $limit = '', |
|
| 514 | - $having = '', |
|
| 515 | - $serveur = '', |
|
| 516 | - $requeter = true |
|
| 508 | + $select, |
|
| 509 | + $from, |
|
| 510 | + $where = '', |
|
| 511 | + $groupby = [], |
|
| 512 | + $orderby = '', |
|
| 513 | + $limit = '', |
|
| 514 | + $having = '', |
|
| 515 | + $serveur = '', |
|
| 516 | + $requeter = true |
|
| 517 | 517 | ) { |
| 518 | 518 | |
| 519 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 520 | - $prefixe = $connexion['prefixe']; |
|
| 521 | - $link = $connexion['link']; |
|
| 522 | - $db = $connexion['db']; |
|
| 523 | - |
|
| 524 | - $limit = preg_match('/^\s*((\d+),)?\s*(\d+)\s*$/', $limit, $limatch); |
|
| 525 | - if ($limit) { |
|
| 526 | - $offset = $limatch[2]; |
|
| 527 | - $count = $limatch[3]; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - $select = spip_pg_frommysql($select); |
|
| 531 | - |
|
| 532 | - // si pas de tri explicitement demande, le GROUP BY ne |
|
| 533 | - // contient que la clef primaire. |
|
| 534 | - // lui ajouter alors le champ de tri par defaut |
|
| 535 | - if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) { |
|
| 536 | - $groupby[] = $groupbyplus[1]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $orderby = spip_pg_orderby($orderby, $select); |
|
| 540 | - |
|
| 541 | - if ($having && is_array($having)) { |
|
| 542 | - $having = implode("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 543 | - } |
|
| 544 | - $from = spip_pg_from($from, $prefixe); |
|
| 545 | - $query = 'SELECT ' . $select |
|
| 546 | - . ($from ? "\nFROM $from" : '') |
|
| 547 | - . ($where ? "\nWHERE " . (is_array($where) ? implode( |
|
| 548 | - "\n\tAND ", |
|
| 549 | - array_map('calculer_pg_where', $where) |
|
| 550 | - ) : (calculer_pg_where($where))) : ('')) |
|
| 551 | - . spip_pg_groupby($groupby, $from, $select) |
|
| 552 | - . ($having ? "\nHAVING $having" : '') |
|
| 553 | - . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 554 | - . ($limit ? " LIMIT $count" . ($offset ? " OFFSET $offset" : '') : ('')); |
|
| 555 | - |
|
| 556 | - // renvoyer la requete inerte si demandee |
|
| 557 | - if ($requeter === false) { |
|
| 558 | - return $query; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - $r = spip_pg_trace_query($query, $serveur); |
|
| 562 | - |
|
| 563 | - return $r ?: $query; |
|
| 519 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 520 | + $prefixe = $connexion['prefixe']; |
|
| 521 | + $link = $connexion['link']; |
|
| 522 | + $db = $connexion['db']; |
|
| 523 | + |
|
| 524 | + $limit = preg_match('/^\s*((\d+),)?\s*(\d+)\s*$/', $limit, $limatch); |
|
| 525 | + if ($limit) { |
|
| 526 | + $offset = $limatch[2]; |
|
| 527 | + $count = $limatch[3]; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + $select = spip_pg_frommysql($select); |
|
| 531 | + |
|
| 532 | + // si pas de tri explicitement demande, le GROUP BY ne |
|
| 533 | + // contient que la clef primaire. |
|
| 534 | + // lui ajouter alors le champ de tri par defaut |
|
| 535 | + if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) { |
|
| 536 | + $groupby[] = $groupbyplus[1]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $orderby = spip_pg_orderby($orderby, $select); |
|
| 540 | + |
|
| 541 | + if ($having && is_array($having)) { |
|
| 542 | + $having = implode("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 543 | + } |
|
| 544 | + $from = spip_pg_from($from, $prefixe); |
|
| 545 | + $query = 'SELECT ' . $select |
|
| 546 | + . ($from ? "\nFROM $from" : '') |
|
| 547 | + . ($where ? "\nWHERE " . (is_array($where) ? implode( |
|
| 548 | + "\n\tAND ", |
|
| 549 | + array_map('calculer_pg_where', $where) |
|
| 550 | + ) : (calculer_pg_where($where))) : ('')) |
|
| 551 | + . spip_pg_groupby($groupby, $from, $select) |
|
| 552 | + . ($having ? "\nHAVING $having" : '') |
|
| 553 | + . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 554 | + . ($limit ? " LIMIT $count" . ($offset ? " OFFSET $offset" : '') : ('')); |
|
| 555 | + |
|
| 556 | + // renvoyer la requete inerte si demandee |
|
| 557 | + if ($requeter === false) { |
|
| 558 | + return $query; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + $r = spip_pg_trace_query($query, $serveur); |
|
| 562 | + |
|
| 563 | + return $r ?: $query; |
|
| 564 | 564 | ; |
| 565 | 565 | } |
| 566 | 566 | |
@@ -568,22 +568,22 @@ discard block |
||
| 568 | 568 | // car le reste de la requete utilise les alias (AS) systematiquement |
| 569 | 569 | |
| 570 | 570 | function spip_pg_from($from, $prefixe) { |
| 571 | - if (is_array($from)) { |
|
| 572 | - $from = spip_pg_select_as($from); |
|
| 573 | - } |
|
| 571 | + if (is_array($from)) { |
|
| 572 | + $from = spip_pg_select_as($from); |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | - return $prefixe ? preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from) : $from; |
|
| 575 | + return $prefixe ? preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from) : $from; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | function spip_pg_orderby($order, $select) { |
| 579 | - $res = []; |
|
| 580 | - $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 579 | + $res = []; |
|
| 580 | + $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 581 | 581 | |
| 582 | - foreach ($arg as $v) { |
|
| 583 | - $res[] = preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m) ? $m[1] : $v; |
|
| 584 | - } |
|
| 582 | + foreach ($arg as $v) { |
|
| 583 | + $res[] = preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m) ? $m[1] : $v; |
|
| 584 | + } |
|
| 585 | 585 | |
| 586 | - return spip_pg_frommysql(implode(',', $res)); |
|
| 586 | + return spip_pg_frommysql(implode(',', $res)); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | // Conversion a l'arrach' des jointures MySQL en jointures PG |
@@ -591,56 +591,56 @@ discard block |
||
| 591 | 591 | // et pour enlever les repetitions (sans incidence de perf, mais ca fait sale) |
| 592 | 592 | |
| 593 | 593 | function spip_pg_groupby($groupby, $from, $select) { |
| 594 | - $join = strpos($from, ','); |
|
| 595 | - // ismplifier avant de decouper |
|
| 596 | - if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 597 | - $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if ($join || $groupby) { |
|
| 601 | - $join = is_array($select) ? $select : explode(', ', $select); |
|
| 602 | - } |
|
| 603 | - if ($join) { |
|
| 604 | - // enlever les 0 as points, '', ... |
|
| 605 | - foreach ($join as $k => $v) { |
|
| 606 | - $v = str_replace('DISTINCT ', '', $v); |
|
| 607 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 608 | - $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 609 | - $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 610 | - // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 611 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 612 | - // idem sans AS (fetch numerique) |
|
| 613 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 614 | - // des AS simples : on garde le cote droit du AS |
|
| 615 | - $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 616 | - // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 617 | - if (preg_match(',^[\'"],', $v) || is_numeric($v)) { |
|
| 618 | - unset($join[$k]); |
|
| 619 | - } else { |
|
| 620 | - $join[$k] = trim($v); |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - $join = array_diff($join, ['']); |
|
| 624 | - $join = implode(',', $join); |
|
| 625 | - } |
|
| 626 | - if (is_array($groupby)) { |
|
| 627 | - $groupby = implode(',', $groupby); |
|
| 628 | - } |
|
| 629 | - if ($join) { |
|
| 630 | - $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 631 | - } |
|
| 632 | - if (!$groupby) { |
|
| 633 | - return ''; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $groupby = spip_pg_frommysql($groupby); |
|
| 637 | - // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 638 | - // issue de prepare_recherche |
|
| 639 | - $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 640 | - $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 641 | - $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 642 | - |
|
| 643 | - return "\nGROUP BY $groupby"; |
|
| 594 | + $join = strpos($from, ','); |
|
| 595 | + // ismplifier avant de decouper |
|
| 596 | + if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 597 | + $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + if ($join || $groupby) { |
|
| 601 | + $join = is_array($select) ? $select : explode(', ', $select); |
|
| 602 | + } |
|
| 603 | + if ($join) { |
|
| 604 | + // enlever les 0 as points, '', ... |
|
| 605 | + foreach ($join as $k => $v) { |
|
| 606 | + $v = str_replace('DISTINCT ', '', $v); |
|
| 607 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 608 | + $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 609 | + $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 610 | + // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 611 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 612 | + // idem sans AS (fetch numerique) |
|
| 613 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 614 | + // des AS simples : on garde le cote droit du AS |
|
| 615 | + $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 616 | + // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 617 | + if (preg_match(',^[\'"],', $v) || is_numeric($v)) { |
|
| 618 | + unset($join[$k]); |
|
| 619 | + } else { |
|
| 620 | + $join[$k] = trim($v); |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + $join = array_diff($join, ['']); |
|
| 624 | + $join = implode(',', $join); |
|
| 625 | + } |
|
| 626 | + if (is_array($groupby)) { |
|
| 627 | + $groupby = implode(',', $groupby); |
|
| 628 | + } |
|
| 629 | + if ($join) { |
|
| 630 | + $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 631 | + } |
|
| 632 | + if (!$groupby) { |
|
| 633 | + return ''; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $groupby = spip_pg_frommysql($groupby); |
|
| 637 | + // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 638 | + // issue de prepare_recherche |
|
| 639 | + $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 640 | + $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 641 | + $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 642 | + |
|
| 643 | + return "\nGROUP BY $groupby"; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | // Conversion des operateurs MySQL en PG |
@@ -651,492 +651,492 @@ discard block |
||
| 651 | 651 | // A ameliorer. |
| 652 | 652 | |
| 653 | 653 | function spip_pg_frommysql($arg) { |
| 654 | - if (is_array($arg)) { |
|
| 655 | - $arg = implode(', ', $arg); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - $res = spip_pg_fromfield($arg); |
|
| 659 | - |
|
| 660 | - $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 661 | - |
|
| 662 | - $res = preg_replace( |
|
| 663 | - '/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 664 | - 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 665 | - $res |
|
| 666 | - ); |
|
| 667 | - $res = preg_replace( |
|
| 668 | - '/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 669 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 670 | - $res |
|
| 671 | - ); |
|
| 672 | - $res = preg_replace( |
|
| 673 | - '/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 674 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 675 | - $res |
|
| 676 | - ); |
|
| 677 | - |
|
| 678 | - $res = preg_replace( |
|
| 679 | - '/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 680 | - ' EXTRACT(epoch FROM NOW())', |
|
| 681 | - $res |
|
| 682 | - ); |
|
| 683 | - |
|
| 684 | - // la fonction md5(integer) n'est pas connu en pg |
|
| 685 | - // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 686 | - $res = preg_replace( |
|
| 687 | - '/md5\s*[(]([^)]*)[)]/i', |
|
| 688 | - 'MD5(CAST(\1 AS text))', |
|
| 689 | - $res |
|
| 690 | - ); |
|
| 691 | - |
|
| 692 | - $res = preg_replace( |
|
| 693 | - '/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 694 | - ' EXTRACT(epoch FROM \1)', |
|
| 695 | - $res |
|
| 696 | - ); |
|
| 697 | - |
|
| 698 | - $res = preg_replace( |
|
| 699 | - '/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 700 | - ' EXTRACT(day FROM \1)', |
|
| 701 | - $res |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - $res = preg_replace( |
|
| 705 | - '/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 706 | - ' EXTRACT(month FROM \1)', |
|
| 707 | - $res |
|
| 708 | - ); |
|
| 709 | - |
|
| 710 | - $res = preg_replace( |
|
| 711 | - '/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 712 | - ' EXTRACT(year FROM \1)', |
|
| 713 | - $res |
|
| 714 | - ); |
|
| 715 | - |
|
| 716 | - $res = preg_replace( |
|
| 717 | - '/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 718 | - ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 719 | - $res |
|
| 720 | - ); |
|
| 721 | - |
|
| 722 | - $res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res); |
|
| 723 | - |
|
| 724 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 725 | - |
|
| 726 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 727 | - |
|
| 728 | - $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 729 | - $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 730 | - $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 731 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 732 | - $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 733 | - |
|
| 734 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 735 | - $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 736 | - |
|
| 737 | - $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 738 | - $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 654 | + if (is_array($arg)) { |
|
| 655 | + $arg = implode(', ', $arg); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + $res = spip_pg_fromfield($arg); |
|
| 659 | + |
|
| 660 | + $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 661 | + |
|
| 662 | + $res = preg_replace( |
|
| 663 | + '/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 664 | + 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 665 | + $res |
|
| 666 | + ); |
|
| 667 | + $res = preg_replace( |
|
| 668 | + '/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 669 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 670 | + $res |
|
| 671 | + ); |
|
| 672 | + $res = preg_replace( |
|
| 673 | + '/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 674 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 675 | + $res |
|
| 676 | + ); |
|
| 677 | + |
|
| 678 | + $res = preg_replace( |
|
| 679 | + '/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 680 | + ' EXTRACT(epoch FROM NOW())', |
|
| 681 | + $res |
|
| 682 | + ); |
|
| 683 | + |
|
| 684 | + // la fonction md5(integer) n'est pas connu en pg |
|
| 685 | + // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 686 | + $res = preg_replace( |
|
| 687 | + '/md5\s*[(]([^)]*)[)]/i', |
|
| 688 | + 'MD5(CAST(\1 AS text))', |
|
| 689 | + $res |
|
| 690 | + ); |
|
| 691 | + |
|
| 692 | + $res = preg_replace( |
|
| 693 | + '/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 694 | + ' EXTRACT(epoch FROM \1)', |
|
| 695 | + $res |
|
| 696 | + ); |
|
| 697 | + |
|
| 698 | + $res = preg_replace( |
|
| 699 | + '/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 700 | + ' EXTRACT(day FROM \1)', |
|
| 701 | + $res |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + $res = preg_replace( |
|
| 705 | + '/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 706 | + ' EXTRACT(month FROM \1)', |
|
| 707 | + $res |
|
| 708 | + ); |
|
| 709 | + |
|
| 710 | + $res = preg_replace( |
|
| 711 | + '/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 712 | + ' EXTRACT(year FROM \1)', |
|
| 713 | + $res |
|
| 714 | + ); |
|
| 715 | + |
|
| 716 | + $res = preg_replace( |
|
| 717 | + '/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 718 | + ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 719 | + $res |
|
| 720 | + ); |
|
| 721 | + |
|
| 722 | + $res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res); |
|
| 723 | + |
|
| 724 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 725 | + |
|
| 726 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 727 | + |
|
| 728 | + $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 729 | + $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 730 | + $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 731 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 732 | + $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 733 | + |
|
| 734 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 735 | + $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 736 | + |
|
| 737 | + $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 738 | + $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 739 | 739 | # correct en theorie mais produit des debordements arithmetiques |
| 740 | 740 | # $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res); |
| 741 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 742 | - $res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res); |
|
| 741 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 742 | + $res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res); |
|
| 743 | 743 | |
| 744 | - return str_replace('REGEXP', '~', $res); |
|
| 744 | + return str_replace('REGEXP', '~', $res); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | function spip_pg_fromfield($arg) { |
| 748 | - while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 749 | - preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 750 | - $res = ''; |
|
| 751 | - $n = 0; |
|
| 752 | - $index = $m[2]; |
|
| 753 | - foreach ($r[1] as $v) { |
|
| 754 | - $n++; |
|
| 755 | - $res .= "\nwhen $index=$v then $n"; |
|
| 756 | - } |
|
| 757 | - $arg = $m[1] . "case $res else 0 end " |
|
| 758 | - . substr($arg, strlen($m[0])); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - return $arg; |
|
| 748 | + while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 749 | + preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 750 | + $res = ''; |
|
| 751 | + $n = 0; |
|
| 752 | + $index = $m[2]; |
|
| 753 | + foreach ($r[1] as $v) { |
|
| 754 | + $n++; |
|
| 755 | + $res .= "\nwhen $index=$v then $n"; |
|
| 756 | + } |
|
| 757 | + $arg = $m[1] . "case $res else 0 end " |
|
| 758 | + . substr($arg, strlen($m[0])); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + return $arg; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | function calculer_pg_where($v) { |
| 765 | - if (!is_array($v)) { |
|
| 766 | - return spip_pg_frommysql($v); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 770 | - if (!($n = count($v))) { |
|
| 771 | - return $op; |
|
| 772 | - } else { |
|
| 773 | - $arg = calculer_pg_where(array_shift($v)); |
|
| 774 | - if ($n == 1) { |
|
| 775 | - return "$op($arg)"; |
|
| 776 | - } else { |
|
| 777 | - $arg2 = calculer_pg_where(array_shift($v)); |
|
| 778 | - if ($n == 2) { |
|
| 779 | - return "($arg $op $arg2)"; |
|
| 780 | - } else { |
|
| 781 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - } |
|
| 765 | + if (!is_array($v)) { |
|
| 766 | + return spip_pg_frommysql($v); |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 770 | + if (!($n = count($v))) { |
|
| 771 | + return $op; |
|
| 772 | + } else { |
|
| 773 | + $arg = calculer_pg_where(array_shift($v)); |
|
| 774 | + if ($n == 1) { |
|
| 775 | + return "$op($arg)"; |
|
| 776 | + } else { |
|
| 777 | + $arg2 = calculer_pg_where(array_shift($v)); |
|
| 778 | + if ($n == 2) { |
|
| 779 | + return "($arg $op $arg2)"; |
|
| 780 | + } else { |
|
| 781 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | |
| 788 | 788 | function calculer_pg_expression($expression, $v, $join = 'AND') { |
| 789 | - if (empty($v)) { |
|
| 790 | - return ''; |
|
| 791 | - } |
|
| 789 | + if (empty($v)) { |
|
| 790 | + return ''; |
|
| 791 | + } |
|
| 792 | 792 | |
| 793 | - $exp = "\n$expression "; |
|
| 793 | + $exp = "\n$expression "; |
|
| 794 | 794 | |
| 795 | - if (!is_array($v)) { |
|
| 796 | - $v = [$v]; |
|
| 797 | - } |
|
| 795 | + if (!is_array($v)) { |
|
| 796 | + $v = [$v]; |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - if (strtoupper($join) === 'AND') { |
|
| 800 | - return $exp . implode("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 801 | - } else { |
|
| 802 | - return $exp . implode($join, $v); |
|
| 803 | - } |
|
| 799 | + if (strtoupper($join) === 'AND') { |
|
| 800 | + return $exp . implode("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 801 | + } else { |
|
| 802 | + return $exp . implode($join, $v); |
|
| 803 | + } |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | function spip_pg_select_as($args) { |
| 807 | - $argsas = ''; |
|
| 808 | - foreach ($args as $k => $v) { |
|
| 809 | - if (str_ends_with($k, '@')) { |
|
| 810 | - // c'est une jointure qui se refere au from precedent |
|
| 811 | - // pas de virgule |
|
| 812 | - $argsas .= ' ' . $v; |
|
| 813 | - } else { |
|
| 814 | - $as = ''; |
|
| 815 | - // spip_log("$k : $v", _LOG_DEBUG); |
|
| 816 | - if (!is_numeric($k)) { |
|
| 817 | - if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 818 | - $v = $k; |
|
| 819 | - } elseif ($v != $k) { |
|
| 820 | - $p = strpos($v, ' '); |
|
| 821 | - if ($p) { |
|
| 822 | - $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 823 | - } else { |
|
| 824 | - $as = " AS $k"; |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 829 | - // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 830 | - $argsas .= ', ' . $v . $as; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - return substr($argsas, 2); |
|
| 807 | + $argsas = ''; |
|
| 808 | + foreach ($args as $k => $v) { |
|
| 809 | + if (str_ends_with($k, '@')) { |
|
| 810 | + // c'est une jointure qui se refere au from precedent |
|
| 811 | + // pas de virgule |
|
| 812 | + $argsas .= ' ' . $v; |
|
| 813 | + } else { |
|
| 814 | + $as = ''; |
|
| 815 | + // spip_log("$k : $v", _LOG_DEBUG); |
|
| 816 | + if (!is_numeric($k)) { |
|
| 817 | + if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 818 | + $v = $k; |
|
| 819 | + } elseif ($v != $k) { |
|
| 820 | + $p = strpos($v, ' '); |
|
| 821 | + if ($p) { |
|
| 822 | + $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 823 | + } else { |
|
| 824 | + $as = " AS $k"; |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 829 | + // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 830 | + $argsas .= ', ' . $v . $as; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + return substr($argsas, 2); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) { |
| 838 | 838 | |
| 839 | - if ($res) { |
|
| 840 | - $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 841 | - } |
|
| 839 | + if ($res) { |
|
| 840 | + $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 841 | + } |
|
| 842 | 842 | |
| 843 | - return $res; |
|
| 843 | + return $res; |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | function spip_pg_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 847 | - if ($r) { |
|
| 848 | - return pg_result_seek($r, $row_number); |
|
| 849 | - } |
|
| 847 | + if ($r) { |
|
| 848 | + return pg_result_seek($r, $row_number); |
|
| 849 | + } |
|
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | |
| 853 | 853 | function spip_pg_countsel( |
| 854 | - $from = [], |
|
| 855 | - $where = [], |
|
| 856 | - $groupby = [], |
|
| 857 | - $having = [], |
|
| 858 | - $serveur = '', |
|
| 859 | - $requeter = true |
|
| 854 | + $from = [], |
|
| 855 | + $where = [], |
|
| 856 | + $groupby = [], |
|
| 857 | + $having = [], |
|
| 858 | + $serveur = '', |
|
| 859 | + $requeter = true |
|
| 860 | 860 | ) { |
| 861 | - $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 862 | - $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 863 | - if (!$requeter) { |
|
| 864 | - return $r; |
|
| 865 | - } |
|
| 866 | - if (!is_resource($r)) { |
|
| 867 | - return 0; |
|
| 868 | - } |
|
| 869 | - [$c] = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 870 | - |
|
| 871 | - return $c; |
|
| 861 | + $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 862 | + $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 863 | + if (!$requeter) { |
|
| 864 | + return $r; |
|
| 865 | + } |
|
| 866 | + if (!is_resource($r)) { |
|
| 867 | + return 0; |
|
| 868 | + } |
|
| 869 | + [$c] = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 870 | + |
|
| 871 | + return $c; |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | function spip_pg_count($res, $serveur = '', $requeter = true) { |
| 875 | - return $res ? pg_num_rows($res) : 0; |
|
| 875 | + return $res ? pg_num_rows($res) : 0; |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | function spip_pg_free($res, $serveur = '', $requeter = true) { |
| 879 | - // rien a faire en postgres |
|
| 879 | + // rien a faire en postgres |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | function spip_pg_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 883 | 883 | |
| 884 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 885 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 884 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 885 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 886 | 886 | |
| 887 | - $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 888 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 887 | + $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 888 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 889 | 889 | |
| 890 | - // renvoyer la requete inerte si demandee |
|
| 891 | - if (!$requeter) { |
|
| 892 | - return $query; |
|
| 893 | - } |
|
| 890 | + // renvoyer la requete inerte si demandee |
|
| 891 | + if (!$requeter) { |
|
| 892 | + return $query; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - $res = spip_pg_trace_query($query, $serveur); |
|
| 896 | - if ($res) { |
|
| 897 | - return pg_affected_rows($res); |
|
| 898 | - } else { |
|
| 899 | - return false; |
|
| 900 | - } |
|
| 895 | + $res = spip_pg_trace_query($query, $serveur); |
|
| 896 | + if ($res) { |
|
| 897 | + return pg_affected_rows($res); |
|
| 898 | + } else { |
|
| 899 | + return false; |
|
| 900 | + } |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | function spip_pg_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 904 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 905 | - $prefixe = $connexion['prefixe']; |
|
| 906 | - $link = $connexion['link']; |
|
| 907 | - |
|
| 908 | - if (!$desc) { |
|
| 909 | - $desc = description_table($table, $serveur); |
|
| 910 | - } |
|
| 911 | - $seq = spip_pg_sequence($table, true); |
|
| 912 | - // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 913 | - if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 914 | - $seq = spip_pg_sequence($table); |
|
| 915 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 916 | - $seq = "currval('$seq')"; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 920 | - $ret = $seq ? " RETURNING $seq" : (''); |
|
| 921 | - $ins = (strlen($champs) < 3) |
|
| 922 | - ? ' DEFAULT VALUES' |
|
| 923 | - : "$champs VALUES $valeurs"; |
|
| 924 | - $q = "INSERT INTO $table $ins $ret"; |
|
| 925 | - if (!$requeter) { |
|
| 926 | - return $q; |
|
| 927 | - } |
|
| 928 | - $connexion['last'] = $q; |
|
| 929 | - $r = spip_pg_query_simple($link, $q); |
|
| 904 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 905 | + $prefixe = $connexion['prefixe']; |
|
| 906 | + $link = $connexion['link']; |
|
| 907 | + |
|
| 908 | + if (!$desc) { |
|
| 909 | + $desc = description_table($table, $serveur); |
|
| 910 | + } |
|
| 911 | + $seq = spip_pg_sequence($table, true); |
|
| 912 | + // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 913 | + if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 914 | + $seq = spip_pg_sequence($table); |
|
| 915 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 916 | + $seq = "currval('$seq')"; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 920 | + $ret = $seq ? " RETURNING $seq" : (''); |
|
| 921 | + $ins = (strlen($champs) < 3) |
|
| 922 | + ? ' DEFAULT VALUES' |
|
| 923 | + : "$champs VALUES $valeurs"; |
|
| 924 | + $q = "INSERT INTO $table $ins $ret"; |
|
| 925 | + if (!$requeter) { |
|
| 926 | + return $q; |
|
| 927 | + } |
|
| 928 | + $connexion['last'] = $q; |
|
| 929 | + $r = spip_pg_query_simple($link, $q); |
|
| 930 | 930 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 931 | - if ($r) { |
|
| 932 | - if (!$ret) { |
|
| 933 | - return 0; |
|
| 934 | - } |
|
| 935 | - if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 936 | - return $r2[0]; |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - return false; |
|
| 931 | + if ($r) { |
|
| 932 | + if (!$ret) { |
|
| 933 | + return 0; |
|
| 934 | + } |
|
| 935 | + if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 936 | + return $r2[0]; |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + return false; |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | function spip_pg_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 944 | 944 | |
| 945 | - if (!$desc) { |
|
| 946 | - $desc = description_table($table, $serveur); |
|
| 947 | - } |
|
| 948 | - if (!$desc) { |
|
| 949 | - die("$table insertion sans description"); |
|
| 950 | - } |
|
| 951 | - $fields = $desc['field']; |
|
| 952 | - |
|
| 953 | - foreach ($couples as $champ => $val) { |
|
| 954 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 958 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 959 | - |
|
| 960 | - return spip_pg_insert( |
|
| 961 | - $table, |
|
| 962 | - '(' . implode(',', array_keys($couples)) . ')', |
|
| 963 | - '(' . implode(',', $couples) . ')', |
|
| 964 | - $desc, |
|
| 965 | - $serveur, |
|
| 966 | - $requeter |
|
| 967 | - ); |
|
| 945 | + if (!$desc) { |
|
| 946 | + $desc = description_table($table, $serveur); |
|
| 947 | + } |
|
| 948 | + if (!$desc) { |
|
| 949 | + die("$table insertion sans description"); |
|
| 950 | + } |
|
| 951 | + $fields = $desc['field']; |
|
| 952 | + |
|
| 953 | + foreach ($couples as $champ => $val) { |
|
| 954 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 958 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 959 | + |
|
| 960 | + return spip_pg_insert( |
|
| 961 | + $table, |
|
| 962 | + '(' . implode(',', array_keys($couples)) . ')', |
|
| 963 | + '(' . implode(',', $couples) . ')', |
|
| 964 | + $desc, |
|
| 965 | + $serveur, |
|
| 966 | + $requeter |
|
| 967 | + ); |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | |
| 971 | 971 | function spip_pg_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 972 | 972 | |
| 973 | - if (!$desc) { |
|
| 974 | - $desc = description_table($table, $serveur); |
|
| 975 | - } |
|
| 976 | - if (!$desc) { |
|
| 977 | - die("$table insertion sans description"); |
|
| 978 | - } |
|
| 979 | - $fields = $desc['field'] ?? []; |
|
| 980 | - |
|
| 981 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 982 | - // une premiere fois pour ajouter maj dans les cles |
|
| 983 | - $c = $tab_couples[0] ?? []; |
|
| 984 | - $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 985 | - |
|
| 986 | - $cles = '(' . implode(',', array_keys($les_cles)) . ')'; |
|
| 987 | - $valeurs = []; |
|
| 988 | - foreach ($tab_couples as $couples) { |
|
| 989 | - foreach ($couples as $champ => $val) { |
|
| 990 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 991 | - } |
|
| 992 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 993 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 994 | - |
|
| 995 | - $valeurs[] = '(' . implode(',', $couples) . ')'; |
|
| 996 | - } |
|
| 997 | - $valeurs = implode(', ', $valeurs); |
|
| 998 | - |
|
| 999 | - return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 973 | + if (!$desc) { |
|
| 974 | + $desc = description_table($table, $serveur); |
|
| 975 | + } |
|
| 976 | + if (!$desc) { |
|
| 977 | + die("$table insertion sans description"); |
|
| 978 | + } |
|
| 979 | + $fields = $desc['field'] ?? []; |
|
| 980 | + |
|
| 981 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 982 | + // une premiere fois pour ajouter maj dans les cles |
|
| 983 | + $c = $tab_couples[0] ?? []; |
|
| 984 | + $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 985 | + |
|
| 986 | + $cles = '(' . implode(',', array_keys($les_cles)) . ')'; |
|
| 987 | + $valeurs = []; |
|
| 988 | + foreach ($tab_couples as $couples) { |
|
| 989 | + foreach ($couples as $champ => $val) { |
|
| 990 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 991 | + } |
|
| 992 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 993 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 994 | + |
|
| 995 | + $valeurs[] = '(' . implode(',', $couples) . ')'; |
|
| 996 | + } |
|
| 997 | + $valeurs = implode(', ', $valeurs); |
|
| 998 | + |
|
| 999 | + return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | |
| 1003 | 1003 | function spip_pg_update($table, $couples, $where = '', $desc = '', $serveur = '', $requeter = true) { |
| 1004 | 1004 | |
| 1005 | - if (!$couples) { |
|
| 1006 | - return; |
|
| 1007 | - } |
|
| 1008 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1009 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1005 | + if (!$couples) { |
|
| 1006 | + return; |
|
| 1007 | + } |
|
| 1008 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1009 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1010 | 1010 | |
| 1011 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1012 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1011 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1012 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1013 | 1013 | |
| 1014 | - $set = []; |
|
| 1015 | - foreach ($couples as $champ => $val) { |
|
| 1016 | - $set[] = $champ . '=' . $val; |
|
| 1017 | - } |
|
| 1014 | + $set = []; |
|
| 1015 | + foreach ($couples as $champ => $val) { |
|
| 1016 | + $set[] = $champ . '=' . $val; |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | - $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1020 | - . calculer_pg_expression('SET', $set, ',') |
|
| 1021 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1019 | + $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1020 | + . calculer_pg_expression('SET', $set, ',') |
|
| 1021 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1022 | 1022 | |
| 1023 | - // renvoyer la requete inerte si demandee |
|
| 1024 | - if (!$requeter) { |
|
| 1025 | - return $query; |
|
| 1026 | - } |
|
| 1023 | + // renvoyer la requete inerte si demandee |
|
| 1024 | + if (!$requeter) { |
|
| 1025 | + return $query; |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | - return spip_pg_trace_query($query, $serveur); |
|
| 1028 | + return spip_pg_trace_query($query, $serveur); |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 1032 | 1032 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 1033 | 1033 | function spip_pg_updateq($table, $couples, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1034 | - if (!$couples) { |
|
| 1035 | - return; |
|
| 1036 | - } |
|
| 1037 | - if (!$desc) { |
|
| 1038 | - $desc = description_table($table, $serveur); |
|
| 1039 | - } |
|
| 1040 | - $fields = $desc['field']; |
|
| 1041 | - foreach ($couples as $k => $val) { |
|
| 1042 | - $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1034 | + if (!$couples) { |
|
| 1035 | + return; |
|
| 1036 | + } |
|
| 1037 | + if (!$desc) { |
|
| 1038 | + $desc = description_table($table, $serveur); |
|
| 1039 | + } |
|
| 1040 | + $fields = $desc['field']; |
|
| 1041 | + foreach ($couples as $k => $val) { |
|
| 1042 | + $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | |
| 1049 | 1049 | function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
| 1050 | - if (!$values) { |
|
| 1051 | - spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1052 | - |
|
| 1053 | - return 0; |
|
| 1054 | - } |
|
| 1055 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1056 | - $prefixe = $connexion['prefixe']; |
|
| 1057 | - $link = $connexion['link']; |
|
| 1058 | - |
|
| 1059 | - if (!$desc) { |
|
| 1060 | - $desc = description_table($table, $serveur); |
|
| 1061 | - } |
|
| 1062 | - if (!$desc) { |
|
| 1063 | - die("$table insertion sans description"); |
|
| 1064 | - } |
|
| 1065 | - $prim = $desc['key']['PRIMARY KEY']; |
|
| 1066 | - $ids = preg_split('/,\s*/', $prim); |
|
| 1067 | - $noprims = $prims = []; |
|
| 1068 | - foreach ($values as $k => $v) { |
|
| 1069 | - $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1070 | - |
|
| 1071 | - if (!in_array($k, $ids)) { |
|
| 1072 | - $noprims[$k] = "$k=$v"; |
|
| 1073 | - } else { |
|
| 1074 | - $prims[$k] = "$k=$v"; |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1079 | - $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1080 | - |
|
| 1081 | - $where = implode(' AND ', $prims); |
|
| 1082 | - if (!$where) { |
|
| 1083 | - return spip_pg_insert( |
|
| 1084 | - $table, |
|
| 1085 | - '(' . implode(',', array_keys($values)) . ')', |
|
| 1086 | - '(' . implode(',', $values) . ')', |
|
| 1087 | - $desc, |
|
| 1088 | - $serveur |
|
| 1089 | - ); |
|
| 1090 | - } |
|
| 1091 | - $couples = implode(',', $noprims); |
|
| 1092 | - |
|
| 1093 | - $seq = spip_pg_sequence($table); |
|
| 1094 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 1095 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1096 | - |
|
| 1097 | - $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1098 | - if ($couples) { |
|
| 1099 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1050 | + if (!$values) { |
|
| 1051 | + spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1052 | + |
|
| 1053 | + return 0; |
|
| 1054 | + } |
|
| 1055 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1056 | + $prefixe = $connexion['prefixe']; |
|
| 1057 | + $link = $connexion['link']; |
|
| 1058 | + |
|
| 1059 | + if (!$desc) { |
|
| 1060 | + $desc = description_table($table, $serveur); |
|
| 1061 | + } |
|
| 1062 | + if (!$desc) { |
|
| 1063 | + die("$table insertion sans description"); |
|
| 1064 | + } |
|
| 1065 | + $prim = $desc['key']['PRIMARY KEY']; |
|
| 1066 | + $ids = preg_split('/,\s*/', $prim); |
|
| 1067 | + $noprims = $prims = []; |
|
| 1068 | + foreach ($values as $k => $v) { |
|
| 1069 | + $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1070 | + |
|
| 1071 | + if (!in_array($k, $ids)) { |
|
| 1072 | + $noprims[$k] = "$k=$v"; |
|
| 1073 | + } else { |
|
| 1074 | + $prims[$k] = "$k=$v"; |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1079 | + $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1080 | + |
|
| 1081 | + $where = implode(' AND ', $prims); |
|
| 1082 | + if (!$where) { |
|
| 1083 | + return spip_pg_insert( |
|
| 1084 | + $table, |
|
| 1085 | + '(' . implode(',', array_keys($values)) . ')', |
|
| 1086 | + '(' . implode(',', $values) . ')', |
|
| 1087 | + $desc, |
|
| 1088 | + $serveur |
|
| 1089 | + ); |
|
| 1090 | + } |
|
| 1091 | + $couples = implode(',', $noprims); |
|
| 1092 | + |
|
| 1093 | + $seq = spip_pg_sequence($table); |
|
| 1094 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 1095 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1096 | + |
|
| 1097 | + $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1098 | + if ($couples) { |
|
| 1099 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1100 | 1100 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 1101 | - if (!$couples) { |
|
| 1102 | - return false; |
|
| 1103 | - } |
|
| 1104 | - $couples = pg_affected_rows($couples); |
|
| 1105 | - } |
|
| 1106 | - if (!$couples) { |
|
| 1107 | - $ret = $seq ? " RETURNING nextval('$seq') < $prim" : |
|
| 1108 | - (''); |
|
| 1109 | - $connexion['last'] = $q = "INSERT INTO $table (" . implode(',', array_keys($values)) . ') VALUES (' . implode( |
|
| 1110 | - ',', |
|
| 1111 | - $values |
|
| 1112 | - ) . ")$ret"; |
|
| 1113 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1114 | - if (!$couples) { |
|
| 1115 | - return false; |
|
| 1116 | - } elseif ($ret) { |
|
| 1117 | - $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1118 | - if ($r[0]) { |
|
| 1119 | - $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1120 | - // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1121 | - // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1122 | - $r = @pg_query($link, $q); |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - return $couples; |
|
| 1101 | + if (!$couples) { |
|
| 1102 | + return false; |
|
| 1103 | + } |
|
| 1104 | + $couples = pg_affected_rows($couples); |
|
| 1105 | + } |
|
| 1106 | + if (!$couples) { |
|
| 1107 | + $ret = $seq ? " RETURNING nextval('$seq') < $prim" : |
|
| 1108 | + (''); |
|
| 1109 | + $connexion['last'] = $q = "INSERT INTO $table (" . implode(',', array_keys($values)) . ') VALUES (' . implode( |
|
| 1110 | + ',', |
|
| 1111 | + $values |
|
| 1112 | + ) . ")$ret"; |
|
| 1113 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1114 | + if (!$couples) { |
|
| 1115 | + return false; |
|
| 1116 | + } elseif ($ret) { |
|
| 1117 | + $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1118 | + if ($r[0]) { |
|
| 1119 | + $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1120 | + // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1121 | + // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1122 | + $r = @pg_query($link, $q); |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + return $couples; |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
| 1131 | 1131 | function spip_pg_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1132 | - $retour = null; |
|
| 1133 | - // boucler pour traiter chaque requete independemment |
|
| 1134 | - foreach ($tab_couples as $couples) { |
|
| 1135 | - $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - // renvoie le dernier id |
|
| 1139 | - return $retour; |
|
| 1132 | + $retour = null; |
|
| 1133 | + // boucler pour traiter chaque requete independemment |
|
| 1134 | + foreach ($tab_couples as $couples) { |
|
| 1135 | + $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + // renvoie le dernier id |
|
| 1139 | + return $retour; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
@@ -1145,148 +1145,148 @@ discard block |
||
| 1145 | 1145 | |
| 1146 | 1146 | function spip_pg_sequence($table, $raw = false) { |
| 1147 | 1147 | |
| 1148 | - include_spip('base/serial'); |
|
| 1149 | - if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1150 | - return false; |
|
| 1151 | - } |
|
| 1152 | - $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1153 | - $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1154 | - if ( |
|
| 1155 | - !preg_match('/^\w+$/', $prim) || !str_contains($desc['field'][$prim], 'int') |
|
| 1156 | - ) { |
|
| 1157 | - return ''; |
|
| 1158 | - } else { |
|
| 1159 | - return $raw ? $prim : $table . '_' . $prim . '_seq'; |
|
| 1160 | - } |
|
| 1148 | + include_spip('base/serial'); |
|
| 1149 | + if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1150 | + return false; |
|
| 1151 | + } |
|
| 1152 | + $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1153 | + $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1154 | + if ( |
|
| 1155 | + !preg_match('/^\w+$/', $prim) || !str_contains($desc['field'][$prim], 'int') |
|
| 1156 | + ) { |
|
| 1157 | + return ''; |
|
| 1158 | + } else { |
|
| 1159 | + return $raw ? $prim : $table . '_' . $prim . '_seq'; |
|
| 1160 | + } |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
| 1164 | 1164 | // Dans le cas d'un champ date, pas d'apostrophe, c'est une syntaxe ad hoc |
| 1165 | 1165 | |
| 1166 | 1166 | function spip_pg_cite($v, $t) { |
| 1167 | - if (is_null($v)) { |
|
| 1168 | - return 'NULL'; |
|
| 1169 | - } // null php se traduit en NULL SQL |
|
| 1170 | - |
|
| 1171 | - if (sql_test_date($t)) { |
|
| 1172 | - if ($v && !str_contains('0123456789', (string) $v[0])) { |
|
| 1173 | - return spip_pg_frommysql($v); |
|
| 1174 | - } else { |
|
| 1175 | - if (str_starts_with($v, '0000')) { |
|
| 1176 | - $v = '0001' . substr($v, 4); |
|
| 1177 | - } |
|
| 1178 | - if (strpos($v, '-00-00') === 4) { |
|
| 1179 | - $v = substr($v, 0, 4) . '-01-01' . substr($v, 10); |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return "timestamp '$v'"; |
|
| 1183 | - } |
|
| 1184 | - } elseif (!sql_test_int($t)) { |
|
| 1185 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1186 | - } elseif (is_numeric($v) || str_starts_with($v, 'CAST(')) { |
|
| 1187 | - return $v; |
|
| 1188 | - } elseif ($v[0] == '0' && $v[1] !== 'x' && ctype_xdigit(substr($v, 1))) { |
|
| 1189 | - return substr($v, 1); |
|
| 1190 | - } else { |
|
| 1191 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1192 | - |
|
| 1193 | - return (int) $v; |
|
| 1194 | - } |
|
| 1167 | + if (is_null($v)) { |
|
| 1168 | + return 'NULL'; |
|
| 1169 | + } // null php se traduit en NULL SQL |
|
| 1170 | + |
|
| 1171 | + if (sql_test_date($t)) { |
|
| 1172 | + if ($v && !str_contains('0123456789', (string) $v[0])) { |
|
| 1173 | + return spip_pg_frommysql($v); |
|
| 1174 | + } else { |
|
| 1175 | + if (str_starts_with($v, '0000')) { |
|
| 1176 | + $v = '0001' . substr($v, 4); |
|
| 1177 | + } |
|
| 1178 | + if (strpos($v, '-00-00') === 4) { |
|
| 1179 | + $v = substr($v, 0, 4) . '-01-01' . substr($v, 10); |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return "timestamp '$v'"; |
|
| 1183 | + } |
|
| 1184 | + } elseif (!sql_test_int($t)) { |
|
| 1185 | + return ("'" . pg_escape_string($v) . "'"); |
|
| 1186 | + } elseif (is_numeric($v) || str_starts_with($v, 'CAST(')) { |
|
| 1187 | + return $v; |
|
| 1188 | + } elseif ($v[0] == '0' && $v[1] !== 'x' && ctype_xdigit(substr($v, 1))) { |
|
| 1189 | + return substr($v, 1); |
|
| 1190 | + } else { |
|
| 1191 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1192 | + |
|
| 1193 | + return (int) $v; |
|
| 1194 | + } |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | function spip_pg_hex($v) { |
| 1198 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1198 | + return "CAST(x'" . $v . "' as bigint)"; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | function spip_pg_quote($v, $type = '') { |
| 1202 | - if (!is_array($v)) { |
|
| 1203 | - return spip_pg_cite($v, $type); |
|
| 1204 | - } |
|
| 1205 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1206 | - foreach ($v as $k => $r) { |
|
| 1207 | - $v[$k] = spip_pg_quote($r, $type); |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - return implode(',', $v); |
|
| 1202 | + if (!is_array($v)) { |
|
| 1203 | + return spip_pg_cite($v, $type); |
|
| 1204 | + } |
|
| 1205 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1206 | + foreach ($v as $k => $r) { |
|
| 1207 | + $v[$k] = spip_pg_quote($r, $type); |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + return implode(',', $v); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | function spip_pg_date_proche($champ, $interval, $unite) { |
| 1214 | - return '(' |
|
| 1215 | - . $champ |
|
| 1216 | - . (($interval <= 0) ? '>' : '<') |
|
| 1217 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1218 | - . '(' |
|
| 1219 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1220 | - . ', INTERVAL ' |
|
| 1221 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1222 | - . ' ' |
|
| 1223 | - . $unite |
|
| 1224 | - . '))'; |
|
| 1214 | + return '(' |
|
| 1215 | + . $champ |
|
| 1216 | + . (($interval <= 0) ? '>' : '<') |
|
| 1217 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1218 | + . '(' |
|
| 1219 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1220 | + . ', INTERVAL ' |
|
| 1221 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1222 | + . ' ' |
|
| 1223 | + . $unite |
|
| 1224 | + . '))'; |
|
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | 1227 | function spip_pg_in($val, $valeurs, $not = '', $serveur = '') { |
| 1228 | 1228 | // |
| 1229 | 1229 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1230 | 1230 | // |
| 1231 | - // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1232 | - if (!$valeurs) { |
|
| 1233 | - return $not ? '0=0' : '0=1'; |
|
| 1234 | - } |
|
| 1235 | - if (str_contains($valeurs, "CAST(x'")) { |
|
| 1236 | - return "($val=" . implode("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1237 | - } |
|
| 1238 | - $n = $i = 0; |
|
| 1239 | - $in_sql = ''; |
|
| 1240 | - while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1241 | - if ((++$i) >= 255) { |
|
| 1242 | - $in_sql .= "($val $not IN (" . |
|
| 1243 | - substr($valeurs, 0, $n) . |
|
| 1244 | - "))\n" . |
|
| 1245 | - ($not ? "AND\t" : "OR\t"); |
|
| 1246 | - $valeurs = substr($valeurs, $n + 1); |
|
| 1247 | - $i = $n = 0; |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1251 | - |
|
| 1252 | - return "($in_sql)"; |
|
| 1231 | + // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1232 | + if (!$valeurs) { |
|
| 1233 | + return $not ? '0=0' : '0=1'; |
|
| 1234 | + } |
|
| 1235 | + if (str_contains($valeurs, "CAST(x'")) { |
|
| 1236 | + return "($val=" . implode("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1237 | + } |
|
| 1238 | + $n = $i = 0; |
|
| 1239 | + $in_sql = ''; |
|
| 1240 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1241 | + if ((++$i) >= 255) { |
|
| 1242 | + $in_sql .= "($val $not IN (" . |
|
| 1243 | + substr($valeurs, 0, $n) . |
|
| 1244 | + "))\n" . |
|
| 1245 | + ($not ? "AND\t" : "OR\t"); |
|
| 1246 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1247 | + $i = $n = 0; |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1251 | + |
|
| 1252 | + return "($in_sql)"; |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | function spip_pg_error($query = '', $serveur = '', $requeter = true) { |
| 1256 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1257 | - $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1258 | - if ($s) { |
|
| 1259 | - $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1260 | - spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - return $s; |
|
| 1256 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1257 | + $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1258 | + if ($s) { |
|
| 1259 | + $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1260 | + spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + return $s; |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | function spip_pg_errno($serveur = '') { |
| 1267 | - // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1268 | - // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1269 | - return 0; |
|
| 1267 | + // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1268 | + // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1269 | + return 0; |
|
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | function spip_pg_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 1273 | - if ($exist) { |
|
| 1274 | - $exist = ' IF EXISTS'; |
|
| 1275 | - } |
|
| 1276 | - if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1277 | - return true; |
|
| 1278 | - } else { |
|
| 1279 | - return false; |
|
| 1280 | - } |
|
| 1273 | + if ($exist) { |
|
| 1274 | + $exist = ' IF EXISTS'; |
|
| 1275 | + } |
|
| 1276 | + if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1277 | + return true; |
|
| 1278 | + } else { |
|
| 1279 | + return false; |
|
| 1280 | + } |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | // supprime une vue |
| 1284 | 1284 | function spip_pg_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 1285 | - if ($exist) { |
|
| 1286 | - $exist = ' IF EXISTS'; |
|
| 1287 | - } |
|
| 1285 | + if ($exist) { |
|
| 1286 | + $exist = ' IF EXISTS'; |
|
| 1287 | + } |
|
| 1288 | 1288 | |
| 1289 | - return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1289 | + return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | /** |
@@ -1303,40 +1303,40 @@ discard block |
||
| 1303 | 1303 | * Ressource à utiliser avec sql_fetch() |
| 1304 | 1304 | **/ |
| 1305 | 1305 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
| 1306 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1307 | - $link = $connexion['link']; |
|
| 1308 | - $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match); |
|
| 1306 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1307 | + $link = $connexion['link']; |
|
| 1308 | + $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match); |
|
| 1309 | 1309 | |
| 1310 | - return spip_pg_query_simple($link, $q); |
|
| 1310 | + return spip_pg_query_simple($link, $q); |
|
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | 1313 | function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1314 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1315 | - $link = $connexion['link']; |
|
| 1316 | - $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table); |
|
| 1317 | - |
|
| 1318 | - $res = spip_pg_query_simple($link, $q); |
|
| 1319 | - if (!$res) { |
|
| 1320 | - return false; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1324 | - // il faut en tenir compte dans le return |
|
| 1325 | - $fields = []; |
|
| 1326 | - while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1327 | - $fields[$field[0]] = $field[2] . ($field[1] ? ' DEFAULT ' . $field[1] : ('')); |
|
| 1328 | - } |
|
| 1329 | - $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table); |
|
| 1330 | - $res = spip_pg_query_simple($link, $q); |
|
| 1331 | - $keys = []; |
|
| 1332 | - while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1333 | - if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1334 | - $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1335 | - $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3]; |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - return count($fields) ? ['field' => $fields, 'key' => $keys] : false; |
|
| 1314 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1315 | + $link = $connexion['link']; |
|
| 1316 | + $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table); |
|
| 1317 | + |
|
| 1318 | + $res = spip_pg_query_simple($link, $q); |
|
| 1319 | + if (!$res) { |
|
| 1320 | + return false; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1324 | + // il faut en tenir compte dans le return |
|
| 1325 | + $fields = []; |
|
| 1326 | + while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1327 | + $fields[$field[0]] = $field[2] . ($field[1] ? ' DEFAULT ' . $field[1] : ('')); |
|
| 1328 | + } |
|
| 1329 | + $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table); |
|
| 1330 | + $res = spip_pg_query_simple($link, $q); |
|
| 1331 | + $keys = []; |
|
| 1332 | + while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1333 | + if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1334 | + $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1335 | + $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3]; |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + return count($fields) ? ['field' => $fields, 'key' => $keys] : false; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | // Fonction de creation d'une table SQL nommee $nom |
@@ -1347,114 +1347,114 @@ discard block |
||
| 1347 | 1347 | // Le nom des index est prefixe par celui de la table pour eviter les conflits |
| 1348 | 1348 | function spip_pg_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) { |
| 1349 | 1349 | |
| 1350 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1351 | - $link = $connexion['link']; |
|
| 1352 | - $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1353 | - |
|
| 1354 | - $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1355 | - $keys = []; |
|
| 1356 | - |
|
| 1357 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1358 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1359 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 1360 | - return; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - foreach ($cles as $k => $v) { |
|
| 1364 | - if (str_starts_with($k, 'KEY ')) { |
|
| 1365 | - $n = str_replace('`', '', $k); |
|
| 1366 | - $v = str_replace('`', '"', $v); |
|
| 1367 | - $i = $nom . preg_replace('/KEY +/', '_', $n); |
|
| 1368 | - if ($k != $n) { |
|
| 1369 | - $i = "\"$i\""; |
|
| 1370 | - } |
|
| 1371 | - $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1372 | - } elseif (str_starts_with($k, 'UNIQUE ')) { |
|
| 1373 | - $k = preg_replace('/^UNIQUE +/', '', $k); |
|
| 1374 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1375 | - } else { |
|
| 1376 | - $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1377 | - } |
|
| 1378 | - if ($k == 'PRIMARY KEY') { |
|
| 1379 | - $prim_name = $v; |
|
| 1380 | - } |
|
| 1381 | - $s = ','; |
|
| 1382 | - } |
|
| 1383 | - $s = ''; |
|
| 1384 | - |
|
| 1385 | - $character_set = ''; |
|
| 1386 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1387 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 1388 | - } |
|
| 1389 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1390 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - foreach ($champs as $k => $v) { |
|
| 1394 | - $k = str_replace('`', '"', $k); |
|
| 1395 | - if (preg_match(',([a-z]*\s*(\(\s*\d*\s*\))?(\s*binary)?),i', $v, $defs) && (preg_match(',(char|text),i', $defs[1]) && !preg_match(',binary,i', $defs[1]))) { |
|
| 1396 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - $query .= "$s\n\t\t$k " |
|
| 1400 | - . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1401 | - ? ' bigserial' |
|
| 1402 | - : mysql2pg_type($v) |
|
| 1403 | - ); |
|
| 1404 | - $s = ','; |
|
| 1405 | - } |
|
| 1406 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1407 | - |
|
| 1408 | - // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1409 | - |
|
| 1410 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' . |
|
| 1411 | - ($character_set ? " DEFAULT $character_set" : '') |
|
| 1412 | - . "\n"; |
|
| 1413 | - |
|
| 1414 | - if (!$requeter) { |
|
| 1415 | - return $q; |
|
| 1416 | - } |
|
| 1417 | - $connexion['last'] = $q; |
|
| 1418 | - $r = @pg_query($link, $q); |
|
| 1419 | - |
|
| 1420 | - if (!$r) { |
|
| 1421 | - spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1422 | - } else { |
|
| 1423 | - foreach ($keys as $index) { |
|
| 1424 | - pg_query($link, $index); |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - return $r; |
|
| 1350 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1351 | + $link = $connexion['link']; |
|
| 1352 | + $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1353 | + |
|
| 1354 | + $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1355 | + $keys = []; |
|
| 1356 | + |
|
| 1357 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1358 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1359 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 1360 | + return; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + foreach ($cles as $k => $v) { |
|
| 1364 | + if (str_starts_with($k, 'KEY ')) { |
|
| 1365 | + $n = str_replace('`', '', $k); |
|
| 1366 | + $v = str_replace('`', '"', $v); |
|
| 1367 | + $i = $nom . preg_replace('/KEY +/', '_', $n); |
|
| 1368 | + if ($k != $n) { |
|
| 1369 | + $i = "\"$i\""; |
|
| 1370 | + } |
|
| 1371 | + $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1372 | + } elseif (str_starts_with($k, 'UNIQUE ')) { |
|
| 1373 | + $k = preg_replace('/^UNIQUE +/', '', $k); |
|
| 1374 | + $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1375 | + } else { |
|
| 1376 | + $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1377 | + } |
|
| 1378 | + if ($k == 'PRIMARY KEY') { |
|
| 1379 | + $prim_name = $v; |
|
| 1380 | + } |
|
| 1381 | + $s = ','; |
|
| 1382 | + } |
|
| 1383 | + $s = ''; |
|
| 1384 | + |
|
| 1385 | + $character_set = ''; |
|
| 1386 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1387 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 1388 | + } |
|
| 1389 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1390 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + foreach ($champs as $k => $v) { |
|
| 1394 | + $k = str_replace('`', '"', $k); |
|
| 1395 | + if (preg_match(',([a-z]*\s*(\(\s*\d*\s*\))?(\s*binary)?),i', $v, $defs) && (preg_match(',(char|text),i', $defs[1]) && !preg_match(',binary,i', $defs[1]))) { |
|
| 1396 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + $query .= "$s\n\t\t$k " |
|
| 1400 | + . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1401 | + ? ' bigserial' |
|
| 1402 | + : mysql2pg_type($v) |
|
| 1403 | + ); |
|
| 1404 | + $s = ','; |
|
| 1405 | + } |
|
| 1406 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1407 | + |
|
| 1408 | + // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1409 | + |
|
| 1410 | + $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' . |
|
| 1411 | + ($character_set ? " DEFAULT $character_set" : '') |
|
| 1412 | + . "\n"; |
|
| 1413 | + |
|
| 1414 | + if (!$requeter) { |
|
| 1415 | + return $q; |
|
| 1416 | + } |
|
| 1417 | + $connexion['last'] = $q; |
|
| 1418 | + $r = @pg_query($link, $q); |
|
| 1419 | + |
|
| 1420 | + if (!$r) { |
|
| 1421 | + spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1422 | + } else { |
|
| 1423 | + foreach ($keys as $index) { |
|
| 1424 | + pg_query($link, $index); |
|
| 1425 | + } |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + return $r; |
|
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | |
| 1432 | 1432 | function spip_pg_create_base($nom, $serveur = '', $requeter = true) { |
| 1433 | - return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1433 | + return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | 1436 | // Fonction de creation d'une vue SQL nommee $nom |
| 1437 | 1437 | function spip_pg_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 1438 | - if (!$query_select) { |
|
| 1439 | - return false; |
|
| 1440 | - } |
|
| 1441 | - // vue deja presente |
|
| 1442 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 1443 | - if ($requeter) { |
|
| 1444 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1445 | - } |
|
| 1438 | + if (!$query_select) { |
|
| 1439 | + return false; |
|
| 1440 | + } |
|
| 1441 | + // vue deja presente |
|
| 1442 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 1443 | + if ($requeter) { |
|
| 1444 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1445 | + } |
|
| 1446 | 1446 | |
| 1447 | - return false; |
|
| 1448 | - } |
|
| 1447 | + return false; |
|
| 1448 | + } |
|
| 1449 | 1449 | |
| 1450 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1450 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1451 | 1451 | |
| 1452 | - return spip_pg_query($query, $serveur, $requeter); |
|
| 1452 | + return spip_pg_query($query, $serveur, $requeter); |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | |
| 1456 | 1456 | function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
| 1457 | - spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR); |
|
| 1457 | + spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR); |
|
| 1458 | 1458 | } |
| 1459 | 1459 | |
| 1460 | 1460 | |
@@ -1467,48 +1467,48 @@ discard block |
||
| 1467 | 1467 | * @return bool|string true / false / requete |
| 1468 | 1468 | **/ |
| 1469 | 1469 | function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
| 1470 | - return spip_pg_query('VACUUM ' . $table, $serveur, $requeter); |
|
| 1470 | + return spip_pg_query('VACUUM ' . $table, $serveur, $requeter); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | // Selectionner la sous-chaine dans $objet |
| 1474 | 1474 | // correspondant a $lang. Cf balise Multi de Spip |
| 1475 | 1475 | |
| 1476 | 1476 | function spip_pg_multi($objet, $lang) { |
| 1477 | - return 'regexp_replace(' |
|
| 1478 | - . $objet |
|
| 1479 | - . ",'<multi>.*[[]" |
|
| 1480 | - . $lang |
|
| 1481 | - . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1477 | + return 'regexp_replace(' |
|
| 1478 | + . $objet |
|
| 1479 | + . ",'<multi>.*[[]" |
|
| 1480 | + . $lang |
|
| 1481 | + . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | // Palanquee d'idiosyncrasies MySQL dans les creations de table |
| 1485 | 1485 | // A completer par les autres, mais essayer de reduire en amont. |
| 1486 | 1486 | |
| 1487 | 1487 | function mysql2pg_type($v) { |
| 1488 | - $remplace = [ |
|
| 1489 | - '/auto_increment/i' => '', // non reconnu |
|
| 1490 | - '/bigint/i' => 'bigint', |
|
| 1491 | - '/mediumint/i' => 'mediumint', |
|
| 1492 | - '/smallint/i' => 'smallint', |
|
| 1493 | - '/tinyint/i' => 'int', |
|
| 1494 | - '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1495 | - '/longtext/i' => 'text', |
|
| 1496 | - '/mediumtext/i' => 'text', |
|
| 1497 | - '/tinytext/i' => 'text', |
|
| 1498 | - '/longblob/i' => 'text', |
|
| 1499 | - '/0000-00-00/' => '0001-01-01', |
|
| 1500 | - '/datetime/i' => 'timestamp', |
|
| 1501 | - '/unsigned/i' => '', |
|
| 1502 | - '/double/i' => 'double precision', |
|
| 1503 | - '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1504 | - '/ENUM *[(][^)]*[)]/i' => 'varchar(255)', |
|
| 1505 | - '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1506 | - ]; |
|
| 1507 | - |
|
| 1508 | - return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1488 | + $remplace = [ |
|
| 1489 | + '/auto_increment/i' => '', // non reconnu |
|
| 1490 | + '/bigint/i' => 'bigint', |
|
| 1491 | + '/mediumint/i' => 'mediumint', |
|
| 1492 | + '/smallint/i' => 'smallint', |
|
| 1493 | + '/tinyint/i' => 'int', |
|
| 1494 | + '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1495 | + '/longtext/i' => 'text', |
|
| 1496 | + '/mediumtext/i' => 'text', |
|
| 1497 | + '/tinytext/i' => 'text', |
|
| 1498 | + '/longblob/i' => 'text', |
|
| 1499 | + '/0000-00-00/' => '0001-01-01', |
|
| 1500 | + '/datetime/i' => 'timestamp', |
|
| 1501 | + '/unsigned/i' => '', |
|
| 1502 | + '/double/i' => 'double precision', |
|
| 1503 | + '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1504 | + '/ENUM *[(][^)]*[)]/i' => 'varchar(255)', |
|
| 1505 | + '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1506 | + ]; |
|
| 1507 | + |
|
| 1508 | + return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | // Renvoie false si on n'a pas les fonctions pg (pour l'install) |
| 1512 | 1512 | function spip_versions_pg() { |
| 1513 | - return function_exists('pg_connect'); |
|
| 1513 | + return function_exists('pg_connect'); |
|
| 1514 | 1514 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | if (!$link) { |
| 60 | 60 | $erreurs[] = pg_last_error(); |
| 61 | 61 | foreach ($erreurs as $e) { |
| 62 | - spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 62 | + spip_log('Echec pg_connect. Erreur : '.$e, 'pg.'._LOG_HS); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return false; |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | spip_log( |
| 80 | - "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 81 | - 'pg.' . _LOG_DEBUG |
|
| 80 | + "Connexion vers $host, base $db, prefixe $prefixe ".($link ? 'operationnelle' : 'impossible'), |
|
| 81 | + 'pg.'._LOG_DEBUG |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | return $link ? [ |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | } else { |
| 167 | 167 | $suite = ''; |
| 168 | 168 | } |
| 169 | - $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 169 | + $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 170 | 170 | |
| 171 | 171 | // renvoyer la requete inerte si demandee |
| 172 | 172 | if (!$requeter) { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // ou revoir l'api de sql_alter en creant un |
| 235 | 235 | // sql_alter_table($table,array($actions)); |
| 236 | 236 | if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
| 237 | - spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 237 | + spip_log("$query mal comprise", 'pg.'._LOG_ERREUR); |
|
| 238 | 238 | |
| 239 | 239 | return false; |
| 240 | 240 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $i = 0; |
| 248 | 248 | $ouverte = false; |
| 249 | 249 | while ($do = array_shift($todo)) { |
| 250 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 250 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i].','.$do : $do; |
|
| 251 | 251 | $o = (str_contains($do, '(')); |
| 252 | 252 | $f = (str_contains($do, ')')); |
| 253 | 253 | if ($o && !$f) { |
@@ -260,33 +260,33 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | $todo = $todo2; |
| 263 | - $query = $debut . ' ' . array_shift($todo); |
|
| 263 | + $query = $debut.' '.array_shift($todo); |
|
| 264 | 264 | |
| 265 | 265 | if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
| 266 | - spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 266 | + spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
|
| 267 | 267 | } else { |
| 268 | 268 | if ($r[1]) { |
| 269 | - spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 269 | + spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 270 | 270 | } |
| 271 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 271 | + $f = 'spip_pg_alter_'.strtolower($r[3]); |
|
| 272 | 272 | if (function_exists($f)) { |
| 273 | 273 | $f($r[2], $r[4], $serveur, $requeter); |
| 274 | 274 | } else { |
| 275 | - spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 275 | + spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | // Alter a plusieurs args. Faudrait optimiser. |
| 279 | 279 | if ($todo) { |
| 280 | - spip_pg_alter("TABLE $table " . implode(',', $todo)); |
|
| 280 | + spip_pg_alter("TABLE $table ".implode(',', $todo)); |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 285 | 285 | if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
| 286 | - spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 286 | + spip_log("alter change: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 287 | 287 | } else { |
| 288 | 288 | [, $old, $new, $type, $default, $null, $def2] = $r; |
| 289 | - $actions = ["ALTER $old TYPE " . mysql2pg_type($type)]; |
|
| 289 | + $actions = ["ALTER $old TYPE ".mysql2pg_type($type)]; |
|
| 290 | 290 | $actions[] = $null ? "ALTER $old SET NOT NULL" : "ALTER $old DROP NOT NULL"; |
| 291 | 291 | |
| 292 | 292 | if ($d = ($default ?: $def2)) { |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $actions[] = "ALTER $old DROP DEFAULT"; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - spip_pg_query("ALTER TABLE $table " . implode(', ', $actions)); |
|
| 298 | + spip_pg_query("ALTER TABLE $table ".implode(', ', $actions)); |
|
| 299 | 299 | |
| 300 | 300 | if ($old !== $new) { |
| 301 | 301 | spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
| 307 | 307 | $nom_index = null; |
| 308 | 308 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
| 309 | - spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 309 | + spip_log("alter add $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 310 | 310 | |
| 311 | 311 | return null; |
| 312 | 312 | } |
@@ -316,14 +316,14 @@ discard block |
||
| 316 | 316 | $m[2] = $n[1]; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 319 | + return spip_pg_query("ALTER TABLE $table ADD ".$m[1].' '.mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 320 | 320 | } elseif ($r[1][0] == 'P') { |
| 321 | 321 | // la primary peut etre sur plusieurs champs |
| 322 | 322 | $r[2] = trim(str_replace('`', '', $r[2])); |
| 323 | 323 | $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
| 324 | 324 | |
| 325 | 325 | return spip_pg_query( |
| 326 | - "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', |
|
| 326 | + "ALTER TABLE $table ADD CONSTRAINT $table".'_pkey PRIMARY KEY ('.$m.')', |
|
| 327 | 327 | $serveur, |
| 328 | 328 | $requeter |
| 329 | 329 | ); |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $colonnes = substr($m[1], 1, -1); |
| 343 | 343 | if (str_contains(',', $colonnes)) { |
| 344 | 344 | spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes' |
| 345 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 345 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.'._LOG_ERREUR); |
|
| 346 | 346 | } else { |
| 347 | 347 | $nom_index = $colonnes; |
| 348 | 348 | } |
@@ -358,23 +358,23 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
| 360 | 360 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
| 361 | - spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 361 | + spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 362 | 362 | } else { |
| 363 | 363 | if (!$r[1] || $r[1] == 'COLUMN') { |
| 364 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 364 | + return spip_pg_query("ALTER TABLE $table DROP ".$r[2], $serveur); |
|
| 365 | 365 | } elseif ($r[1][0] == 'P') { |
| 366 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 366 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table".'_pkey', $serveur); |
|
| 367 | 367 | } else { |
| 368 | - return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur); |
|
| 368 | + return spip_pg_query('DROP INDEX '.$table.'_'.$r[2], $serveur); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
| 374 | 374 | if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
| 375 | - spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 375 | + spip_log("alter modify: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 376 | 376 | } else { |
| 377 | - return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 377 | + return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur = '', $requeter = true); |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
| 391 | 391 | $rename = $r[2]; |
| 392 | 392 | } else { |
| 393 | - spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 393 | + spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
| 412 | 412 | if (!($nom || $table || $champs)) { |
| 413 | 413 | spip_log( |
| 414 | - "Champ manquant pour creer un index pg ($nom, $table, (" . @implode(',', $champs) . '))', |
|
| 415 | - 'pg.' . _LOG_ERREUR |
|
| 414 | + "Champ manquant pour creer un index pg ($nom, $table, (".@implode(',', $champs).'))', |
|
| 415 | + 'pg.'._LOG_ERREUR |
|
| 416 | 416 | ); |
| 417 | 417 | |
| 418 | 418 | return false; |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | // PG ne differentie pas noms des index en fonction des tables |
| 425 | 425 | // il faut donc creer des noms uniques d'index pour une base pg |
| 426 | - $nom = $table . '_' . $nom; |
|
| 426 | + $nom = $table.'_'.$nom; |
|
| 427 | 427 | // enlever d'eventuelles parentheses deja presentes sur champs |
| 428 | 428 | if (!is_array($champs)) { |
| 429 | 429 | if ($champs[0] == '(') { |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | $champs = [$champs]; |
| 433 | 433 | } |
| 434 | - $query = "CREATE INDEX $nom ON $table (" . implode(',', $champs) . ')'; |
|
| 434 | + $query = "CREATE INDEX $nom ON $table (".implode(',', $champs).')'; |
|
| 435 | 435 | if (!$requeter) { |
| 436 | 436 | return $query; |
| 437 | 437 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | } else { |
| 454 | 454 | $suite = ''; |
| 455 | 455 | } |
| 456 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 456 | + $query = 'EXPLAIN '.preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 457 | 457 | |
| 458 | 458 | if (!$requeter) { |
| 459 | 459 | return $query; |
@@ -542,16 +542,16 @@ discard block |
||
| 542 | 542 | $having = implode("\n\tAND ", array_map('calculer_pg_where', $having)); |
| 543 | 543 | } |
| 544 | 544 | $from = spip_pg_from($from, $prefixe); |
| 545 | - $query = 'SELECT ' . $select |
|
| 545 | + $query = 'SELECT '.$select |
|
| 546 | 546 | . ($from ? "\nFROM $from" : '') |
| 547 | - . ($where ? "\nWHERE " . (is_array($where) ? implode( |
|
| 547 | + . ($where ? "\nWHERE ".(is_array($where) ? implode( |
|
| 548 | 548 | "\n\tAND ", |
| 549 | 549 | array_map('calculer_pg_where', $where) |
| 550 | 550 | ) : (calculer_pg_where($where))) : ('')) |
| 551 | 551 | . spip_pg_groupby($groupby, $from, $select) |
| 552 | 552 | . ($having ? "\nHAVING $having" : '') |
| 553 | 553 | . ($orderby ? ("\nORDER BY $orderby") : '') |
| 554 | - . ($limit ? " LIMIT $count" . ($offset ? " OFFSET $offset" : '') : ('')); |
|
| 554 | + . ($limit ? " LIMIT $count".($offset ? " OFFSET $offset" : '') : ('')); |
|
| 555 | 555 | |
| 556 | 556 | // renvoyer la requete inerte si demandee |
| 557 | 557 | if ($requeter === false) { |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | $from = spip_pg_select_as($from); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - return $prefixe ? preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from) : $from; |
|
| 575 | + return $prefixe ? preg_replace('/(\b)spip_/', '\1'.$prefixe.'_', $from) : $from; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | function spip_pg_orderby($order, $select) { |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
| 581 | 581 | |
| 582 | 582 | foreach ($arg as $v) { |
| 583 | - $res[] = preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m) ? $m[1] : $v; |
|
| 583 | + $res[] = preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+'.$v.'/', $select, $m) ? $m[1] : $v; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | return spip_pg_frommysql(implode(',', $res)); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | $n++; |
| 755 | 755 | $res .= "\nwhen $index=$v then $n"; |
| 756 | 756 | } |
| 757 | - $arg = $m[1] . "case $res else 0 end " |
|
| 757 | + $arg = $m[1]."case $res else 0 end " |
|
| 758 | 758 | . substr($arg, strlen($m[0])); |
| 759 | 759 | } |
| 760 | 760 | |
@@ -797,9 +797,9 @@ discard block |
||
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | if (strtoupper($join) === 'AND') { |
| 800 | - return $exp . implode("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 800 | + return $exp.implode("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 801 | 801 | } else { |
| 802 | - return $exp . implode($join, $v); |
|
| 802 | + return $exp.implode($join, $v); |
|
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | if (str_ends_with($k, '@')) { |
| 810 | 810 | // c'est une jointure qui se refere au from precedent |
| 811 | 811 | // pas de virgule |
| 812 | - $argsas .= ' ' . $v; |
|
| 812 | + $argsas .= ' '.$v; |
|
| 813 | 813 | } else { |
| 814 | 814 | $as = ''; |
| 815 | 815 | // spip_log("$k : $v", _LOG_DEBUG); |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | } elseif ($v != $k) { |
| 820 | 820 | $p = strpos($v, ' '); |
| 821 | 821 | if ($p) { |
| 822 | - $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 822 | + $v = substr($v, 0, $p)." AS $k".substr($v, $p); |
|
| 823 | 823 | } else { |
| 824 | 824 | $as = " AS $k"; |
| 825 | 825 | } |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | } |
| 828 | 828 | // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
| 829 | 829 | // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
| 830 | - $argsas .= ', ' . $v . $as; |
|
| 830 | + $argsas .= ', '.$v.$as; |
|
| 831 | 831 | } |
| 832 | 832 | } |
| 833 | 833 | |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | $serveur = '', |
| 859 | 859 | $requeter = true |
| 860 | 860 | ) { |
| 861 | - $c = $groupby ? 'DISTINCT ' . (is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 861 | + $c = $groupby ? 'DISTINCT '.(is_string($groupby) ? $groupby : implode(',', $groupby)) : ('*'); |
|
| 862 | 862 | $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 863 | 863 | if (!$requeter) { |
| 864 | 864 | return $r; |
@@ -959,8 +959,8 @@ discard block |
||
| 959 | 959 | |
| 960 | 960 | return spip_pg_insert( |
| 961 | 961 | $table, |
| 962 | - '(' . implode(',', array_keys($couples)) . ')', |
|
| 963 | - '(' . implode(',', $couples) . ')', |
|
| 962 | + '('.implode(',', array_keys($couples)).')', |
|
| 963 | + '('.implode(',', $couples).')', |
|
| 964 | 964 | $desc, |
| 965 | 965 | $serveur, |
| 966 | 966 | $requeter |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | $c = $tab_couples[0] ?? []; |
| 984 | 984 | $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
| 985 | 985 | |
| 986 | - $cles = '(' . implode(',', array_keys($les_cles)) . ')'; |
|
| 986 | + $cles = '('.implode(',', array_keys($les_cles)).')'; |
|
| 987 | 987 | $valeurs = []; |
| 988 | 988 | foreach ($tab_couples as $couples) { |
| 989 | 989 | foreach ($couples as $champ => $val) { |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 993 | 993 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 994 | 994 | |
| 995 | - $valeurs[] = '(' . implode(',', $couples) . ')'; |
|
| 995 | + $valeurs[] = '('.implode(',', $couples).')'; |
|
| 996 | 996 | } |
| 997 | 997 | $valeurs = implode(', ', $valeurs); |
| 998 | 998 | |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | |
| 1014 | 1014 | $set = []; |
| 1015 | 1015 | foreach ($couples as $champ => $val) { |
| 1016 | - $set[] = $champ . '=' . $val; |
|
| 1016 | + $set[] = $champ.'='.$val; |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | $query = calculer_pg_expression('UPDATE', $table, ',') |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | |
| 1049 | 1049 | function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
| 1050 | 1050 | if (!$values) { |
| 1051 | - spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1051 | + spip_log("replace vide $table", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1052 | 1052 | |
| 1053 | 1053 | return 0; |
| 1054 | 1054 | } |
@@ -1082,8 +1082,8 @@ discard block |
||
| 1082 | 1082 | if (!$where) { |
| 1083 | 1083 | return spip_pg_insert( |
| 1084 | 1084 | $table, |
| 1085 | - '(' . implode(',', array_keys($values)) . ')', |
|
| 1086 | - '(' . implode(',', $values) . ')', |
|
| 1085 | + '('.implode(',', array_keys($values)).')', |
|
| 1086 | + '('.implode(',', $values).')', |
|
| 1087 | 1087 | $desc, |
| 1088 | 1088 | $serveur |
| 1089 | 1089 | ); |
@@ -1104,12 +1104,11 @@ discard block |
||
| 1104 | 1104 | $couples = pg_affected_rows($couples); |
| 1105 | 1105 | } |
| 1106 | 1106 | if (!$couples) { |
| 1107 | - $ret = $seq ? " RETURNING nextval('$seq') < $prim" : |
|
| 1108 | - (''); |
|
| 1109 | - $connexion['last'] = $q = "INSERT INTO $table (" . implode(',', array_keys($values)) . ') VALUES (' . implode( |
|
| 1107 | + $ret = $seq ? " RETURNING nextval('$seq') < $prim" : (''); |
|
| 1108 | + $connexion['last'] = $q = "INSERT INTO $table (".implode(',', array_keys($values)).') VALUES ('.implode( |
|
| 1110 | 1109 | ',', |
| 1111 | 1110 | $values |
| 1112 | - ) . ")$ret"; |
|
| 1111 | + ).")$ret"; |
|
| 1113 | 1112 | $couples = spip_pg_query_simple($link, $q); |
| 1114 | 1113 | if (!$couples) { |
| 1115 | 1114 | return false; |
@@ -1156,7 +1155,7 @@ discard block |
||
| 1156 | 1155 | ) { |
| 1157 | 1156 | return ''; |
| 1158 | 1157 | } else { |
| 1159 | - return $raw ? $prim : $table . '_' . $prim . '_seq'; |
|
| 1158 | + return $raw ? $prim : $table.'_'.$prim.'_seq'; |
|
| 1160 | 1159 | } |
| 1161 | 1160 | } |
| 1162 | 1161 | |
@@ -1173,29 +1172,29 @@ discard block |
||
| 1173 | 1172 | return spip_pg_frommysql($v); |
| 1174 | 1173 | } else { |
| 1175 | 1174 | if (str_starts_with($v, '0000')) { |
| 1176 | - $v = '0001' . substr($v, 4); |
|
| 1175 | + $v = '0001'.substr($v, 4); |
|
| 1177 | 1176 | } |
| 1178 | 1177 | if (strpos($v, '-00-00') === 4) { |
| 1179 | - $v = substr($v, 0, 4) . '-01-01' . substr($v, 10); |
|
| 1178 | + $v = substr($v, 0, 4).'-01-01'.substr($v, 10); |
|
| 1180 | 1179 | } |
| 1181 | 1180 | |
| 1182 | 1181 | return "timestamp '$v'"; |
| 1183 | 1182 | } |
| 1184 | 1183 | } elseif (!sql_test_int($t)) { |
| 1185 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1184 | + return ("'".pg_escape_string($v)."'"); |
|
| 1186 | 1185 | } elseif (is_numeric($v) || str_starts_with($v, 'CAST(')) { |
| 1187 | 1186 | return $v; |
| 1188 | 1187 | } elseif ($v[0] == '0' && $v[1] !== 'x' && ctype_xdigit(substr($v, 1))) { |
| 1189 | 1188 | return substr($v, 1); |
| 1190 | 1189 | } else { |
| 1191 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1190 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1192 | 1191 | |
| 1193 | 1192 | return (int) $v; |
| 1194 | 1193 | } |
| 1195 | 1194 | } |
| 1196 | 1195 | |
| 1197 | 1196 | function spip_pg_hex($v) { |
| 1198 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1197 | + return "CAST(x'".$v."' as bigint)"; |
|
| 1199 | 1198 | } |
| 1200 | 1199 | |
| 1201 | 1200 | function spip_pg_quote($v, $type = '') { |
@@ -1233,15 +1232,15 @@ discard block |
||
| 1233 | 1232 | return $not ? '0=0' : '0=1'; |
| 1234 | 1233 | } |
| 1235 | 1234 | if (str_contains($valeurs, "CAST(x'")) { |
| 1236 | - return "($val=" . implode("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1235 | + return "($val=".implode("OR $val=", explode(',', $valeurs)).')'; |
|
| 1237 | 1236 | } |
| 1238 | 1237 | $n = $i = 0; |
| 1239 | 1238 | $in_sql = ''; |
| 1240 | 1239 | while ($n = strpos($valeurs, ',', $n + 1)) { |
| 1241 | 1240 | if ((++$i) >= 255) { |
| 1242 | - $in_sql .= "($val $not IN (" . |
|
| 1243 | - substr($valeurs, 0, $n) . |
|
| 1244 | - "))\n" . |
|
| 1241 | + $in_sql .= "($val $not IN (". |
|
| 1242 | + substr($valeurs, 0, $n). |
|
| 1243 | + "))\n". |
|
| 1245 | 1244 | ($not ? "AND\t" : "OR\t"); |
| 1246 | 1245 | $valeurs = substr($valeurs, $n + 1); |
| 1247 | 1246 | $i = $n = 0; |
@@ -1257,7 +1256,7 @@ discard block |
||
| 1257 | 1256 | $s = $link ? pg_last_error($link) : pg_last_error(); |
| 1258 | 1257 | if ($s) { |
| 1259 | 1258 | $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
| 1260 | - spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1259 | + spip_log("$s - $query", 'pg.'._LOG_ERREUR); |
|
| 1261 | 1260 | } |
| 1262 | 1261 | |
| 1263 | 1262 | return $s; |
@@ -1305,7 +1304,7 @@ discard block |
||
| 1305 | 1304 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
| 1306 | 1305 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1307 | 1306 | $link = $connexion['link']; |
| 1308 | - $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match); |
|
| 1307 | + $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE '._q($match); |
|
| 1309 | 1308 | |
| 1310 | 1309 | return spip_pg_query_simple($link, $q); |
| 1311 | 1310 | } |
@@ -1313,7 +1312,7 @@ discard block |
||
| 1313 | 1312 | function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1314 | 1313 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1315 | 1314 | $link = $connexion['link']; |
| 1316 | - $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table); |
|
| 1315 | + $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE '._q($nom_table); |
|
| 1317 | 1316 | |
| 1318 | 1317 | $res = spip_pg_query_simple($link, $q); |
| 1319 | 1318 | if (!$res) { |
@@ -1324,15 +1323,15 @@ discard block |
||
| 1324 | 1323 | // il faut en tenir compte dans le return |
| 1325 | 1324 | $fields = []; |
| 1326 | 1325 | while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
| 1327 | - $fields[$field[0]] = $field[2] . ($field[1] ? ' DEFAULT ' . $field[1] : ('')); |
|
| 1326 | + $fields[$field[0]] = $field[2].($field[1] ? ' DEFAULT '.$field[1] : ('')); |
|
| 1328 | 1327 | } |
| 1329 | - $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table); |
|
| 1328 | + $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE '._q($nom_table); |
|
| 1330 | 1329 | $res = spip_pg_query_simple($link, $q); |
| 1331 | 1330 | $keys = []; |
| 1332 | 1331 | while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
| 1333 | 1332 | if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
| 1334 | - $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1335 | - $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3]; |
|
| 1333 | + $nom = str_replace($nom_table.'_', '', $r[2]); |
|
| 1334 | + $keys[($r[1] ? 'PRIMARY KEY' : ('KEY '.$nom))] = $r[3]; |
|
| 1336 | 1335 | } |
| 1337 | 1336 | } |
| 1338 | 1337 | |
@@ -1364,16 +1363,16 @@ discard block |
||
| 1364 | 1363 | if (str_starts_with($k, 'KEY ')) { |
| 1365 | 1364 | $n = str_replace('`', '', $k); |
| 1366 | 1365 | $v = str_replace('`', '"', $v); |
| 1367 | - $i = $nom . preg_replace('/KEY +/', '_', $n); |
|
| 1366 | + $i = $nom.preg_replace('/KEY +/', '_', $n); |
|
| 1368 | 1367 | if ($k != $n) { |
| 1369 | 1368 | $i = "\"$i\""; |
| 1370 | 1369 | } |
| 1371 | 1370 | $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
| 1372 | 1371 | } elseif (str_starts_with($k, 'UNIQUE ')) { |
| 1373 | 1372 | $k = preg_replace('/^UNIQUE +/', '', $k); |
| 1374 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1373 | + $prim .= "$s\n\t\tCONSTRAINT ".str_replace('`', '"', $k)." UNIQUE ($v)"; |
|
| 1375 | 1374 | } else { |
| 1376 | - $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1375 | + $prim .= "$s\n\t\t".str_replace('`', '"', $k)." ($v)"; |
|
| 1377 | 1376 | } |
| 1378 | 1377 | if ($k == 'PRIMARY KEY') { |
| 1379 | 1378 | $prim_name = $v; |
@@ -1384,16 +1383,16 @@ discard block |
||
| 1384 | 1383 | |
| 1385 | 1384 | $character_set = ''; |
| 1386 | 1385 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 1387 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 1386 | + $character_set .= ' CHARACTER SET '.$GLOBALS['meta']['charset_sql_base']; |
|
| 1388 | 1387 | } |
| 1389 | 1388 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 1390 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1389 | + $character_set .= ' COLLATE '.$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1391 | 1390 | } |
| 1392 | 1391 | |
| 1393 | 1392 | foreach ($champs as $k => $v) { |
| 1394 | 1393 | $k = str_replace('`', '"', $k); |
| 1395 | 1394 | if (preg_match(',([a-z]*\s*(\(\s*\d*\s*\))?(\s*binary)?),i', $v, $defs) && (preg_match(',(char|text),i', $defs[1]) && !preg_match(',binary,i', $defs[1]))) { |
| 1396 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1395 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 1397 | 1396 | } |
| 1398 | 1397 | |
| 1399 | 1398 | $query .= "$s\n\t\t$k " |
@@ -1407,7 +1406,7 @@ discard block |
||
| 1407 | 1406 | |
| 1408 | 1407 | // En l'absence de "if not exists" en PG, on neutralise les erreurs |
| 1409 | 1408 | |
| 1410 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' . |
|
| 1409 | + $q = "CREATE $temporary TABLE $nom ($query".($prim ? ",$prim" : '').')'. |
|
| 1411 | 1410 | ($character_set ? " DEFAULT $character_set" : '') |
| 1412 | 1411 | . "\n"; |
| 1413 | 1412 | |
@@ -1418,7 +1417,7 @@ discard block |
||
| 1418 | 1417 | $r = @pg_query($link, $q); |
| 1419 | 1418 | |
| 1420 | 1419 | if (!$r) { |
| 1421 | - spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1420 | + spip_log("Impossible de creer cette table: $q", 'pg.'._LOG_ERREUR); |
|
| 1422 | 1421 | } else { |
| 1423 | 1422 | foreach ($keys as $index) { |
| 1424 | 1423 | pg_query($link, $index); |
@@ -1441,20 +1440,20 @@ discard block |
||
| 1441 | 1440 | // vue deja presente |
| 1442 | 1441 | if (sql_showtable($nom, false, $serveur)) { |
| 1443 | 1442 | if ($requeter) { |
| 1444 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1443 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.'._LOG_ERREUR); |
|
| 1445 | 1444 | } |
| 1446 | 1445 | |
| 1447 | 1446 | return false; |
| 1448 | 1447 | } |
| 1449 | 1448 | |
| 1450 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1449 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 1451 | 1450 | |
| 1452 | 1451 | return spip_pg_query($query, $serveur, $requeter); |
| 1453 | 1452 | } |
| 1454 | 1453 | |
| 1455 | 1454 | |
| 1456 | 1455 | function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
| 1457 | - spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR); |
|
| 1456 | + spip_log('changement de charset sql a ecrire en PG', 'pg.'._LOG_ERREUR); |
|
| 1458 | 1457 | } |
| 1459 | 1458 | |
| 1460 | 1459 | |
@@ -1467,7 +1466,7 @@ discard block |
||
| 1467 | 1466 | * @return bool|string true / false / requete |
| 1468 | 1467 | **/ |
| 1469 | 1468 | function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
| 1470 | - return spip_pg_query('VACUUM ' . $table, $serveur, $requeter); |
|
| 1469 | + return spip_pg_query('VACUUM '.$table, $serveur, $requeter); |
|
| 1471 | 1470 | } |
| 1472 | 1471 | |
| 1473 | 1472 | // Selectionner la sous-chaine dans $objet |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 25 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | * Description de la boucle complétée des champs |
| 44 | 44 | */ |
| 45 | 45 | function iterateur_DATA_dist($b) { |
| 46 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | - $b->show = [ |
|
| 48 | - 'field' => [ |
|
| 49 | - 'cle' => 'STRING', |
|
| 50 | - 'valeur' => 'STRING', |
|
| 51 | - '*' => 'ALL' // Champ joker * |
|
| 52 | - ] |
|
| 53 | - ]; |
|
| 54 | - $b->select[] = '.valeur'; |
|
| 55 | - |
|
| 56 | - return $b; |
|
| 46 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | + $b->show = [ |
|
| 48 | + 'field' => [ |
|
| 49 | + 'cle' => 'STRING', |
|
| 50 | + 'valeur' => 'STRING', |
|
| 51 | + '*' => 'ALL' // Champ joker * |
|
| 52 | + ] |
|
| 53 | + ]; |
|
| 54 | + $b->select[] = '.valeur'; |
|
| 55 | + |
|
| 56 | + return $b; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | 70 | function inc_file_to_array_dist($data) { |
| 71 | - return preg_split('/\r?\n/', $data); |
|
| 71 | + return preg_split('/\r?\n/', $data); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function inc_plugins_to_array_dist() { |
| 80 | - include_spip('inc/plugin'); |
|
| 80 | + include_spip('inc/plugin'); |
|
| 81 | 81 | |
| 82 | - return liste_chemin_plugin_actifs(); |
|
| 82 | + return liste_chemin_plugin_actifs(); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | 91 | function inc_xml_to_array_dist($data) { |
| 92 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 92 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | 103 | function inc_object_to_array($object) { |
| 104 | - if (!is_object($object) && !is_array($object)) { |
|
| 105 | - return $object; |
|
| 106 | - } |
|
| 107 | - if (is_object($object)) { |
|
| 108 | - $object = get_object_vars($object); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return array_map('inc_object_to_array', $object); |
|
| 104 | + if (!is_object($object) && !is_array($object)) { |
|
| 105 | + return $object; |
|
| 106 | + } |
|
| 107 | + if (is_object($object)) { |
|
| 108 | + $object = get_object_vars($object); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return array_map('inc_object_to_array', $object); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,20 +118,20 @@ discard block |
||
| 118 | 118 | * @return array|bool |
| 119 | 119 | */ |
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | - # sortir le connecteur de $data |
|
| 122 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | - $serveur = (string)$v[1]; |
|
| 124 | - $req = trim($v[2]); |
|
| 125 | - if ($s = sql_query($req, $serveur)) { |
|
| 126 | - $r = []; |
|
| 127 | - while ($t = sql_fetch($s)) { |
|
| 128 | - $r[] = $t; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $r; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return false; |
|
| 121 | + # sortir le connecteur de $data |
|
| 122 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | + $serveur = (string)$v[1]; |
|
| 124 | + $req = trim($v[2]); |
|
| 125 | + if ($s = sql_query($req, $serveur)) { |
|
| 126 | + $r = []; |
|
| 127 | + while ($t = sql_fetch($s)) { |
|
| 128 | + $r[] = $t; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $r; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @return array|bool |
| 142 | 142 | */ |
| 143 | 143 | function inc_json_to_array_dist($data) { |
| 144 | - try { |
|
| 145 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | - } catch (JsonException $e) { |
|
| 147 | - $json = null; |
|
| 148 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | - } |
|
| 150 | - return is_array($json) ? (array) $json : []; |
|
| 144 | + try { |
|
| 145 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | + } catch (JsonException $e) { |
|
| 147 | + $json = null; |
|
| 148 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | + } |
|
| 150 | + return is_array($json) ? (array) $json : []; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,30 +157,30 @@ discard block |
||
| 157 | 157 | * @return array|bool |
| 158 | 158 | */ |
| 159 | 159 | function inc_csv_to_array_dist($data) { |
| 160 | - include_spip('inc/csv'); |
|
| 161 | - [$entete, $csv] = analyse_csv($data); |
|
| 162 | - array_unshift($csv, $entete); |
|
| 163 | - |
|
| 164 | - include_spip('inc/charsets'); |
|
| 165 | - $i = 1; |
|
| 166 | - foreach ($entete as $k => $v) { |
|
| 167 | - if (trim($v) == '') { |
|
| 168 | - $v = 'col' . $i; |
|
| 169 | - } // reperer des eventuelles cases vides |
|
| 170 | - if (is_numeric($v) && $v < 0) { |
|
| 171 | - $v = '__' . $v; |
|
| 172 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | - if (is_numeric($v)) { |
|
| 174 | - $v = '_' . $v; |
|
| 175 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 177 | - foreach ($csv as &$item) { |
|
| 178 | - $item[$v] = &$item[$k]; |
|
| 179 | - } |
|
| 180 | - $i++; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $csv; |
|
| 160 | + include_spip('inc/csv'); |
|
| 161 | + [$entete, $csv] = analyse_csv($data); |
|
| 162 | + array_unshift($csv, $entete); |
|
| 163 | + |
|
| 164 | + include_spip('inc/charsets'); |
|
| 165 | + $i = 1; |
|
| 166 | + foreach ($entete as $k => $v) { |
|
| 167 | + if (trim($v) == '') { |
|
| 168 | + $v = 'col' . $i; |
|
| 169 | + } // reperer des eventuelles cases vides |
|
| 170 | + if (is_numeric($v) && $v < 0) { |
|
| 171 | + $v = '__' . $v; |
|
| 172 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | + if (is_numeric($v)) { |
|
| 174 | + $v = '_' . $v; |
|
| 175 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 177 | + foreach ($csv as &$item) { |
|
| 178 | + $item[$v] = &$item[$k]; |
|
| 179 | + } |
|
| 180 | + $i++; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $csv; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @return array|bool |
| 191 | 191 | */ |
| 192 | 192 | function inc_rss_to_array_dist($data) { |
| 193 | - $tableau = null; |
|
| 194 | - include_spip('inc/syndic'); |
|
| 195 | - if (is_array($rss = analyser_backend($data))) { |
|
| 196 | - $tableau = $rss; |
|
| 197 | - } |
|
| 193 | + $tableau = null; |
|
| 194 | + include_spip('inc/syndic'); |
|
| 195 | + if (is_array($rss = analyser_backend($data))) { |
|
| 196 | + $tableau = $rss; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $tableau; |
|
| 199 | + return $tableau; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @return array|bool |
| 207 | 207 | */ |
| 208 | 208 | function inc_atom_to_array_dist($data) { |
| 209 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 209 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | 210 | |
| 211 | - return $rss_to_array($data); |
|
| 211 | + return $rss_to_array($data); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @return array|bool |
| 220 | 220 | */ |
| 221 | 221 | function inc_glob_to_array_dist($data) { |
| 222 | - $a = glob( |
|
| 223 | - $data, |
|
| 224 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | - ); |
|
| 222 | + $a = glob( |
|
| 223 | + $data, |
|
| 224 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - return $a ?: []; |
|
| 227 | + return $a ?: []; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | * @throws Exception |
| 236 | 236 | */ |
| 237 | 237 | function inc_yaml_to_array_dist($data) { |
| 238 | - include_spip('inc/yaml-mini'); |
|
| 239 | - if (!function_exists('yaml_decode')) { |
|
| 240 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 238 | + include_spip('inc/yaml-mini'); |
|
| 239 | + if (!function_exists('yaml_decode')) { |
|
| 240 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 241 | 241 | |
| 242 | - return false; |
|
| 243 | - } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return yaml_decode($data); |
|
| 245 | + return yaml_decode($data); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -269,23 +269,23 @@ discard block |
||
| 269 | 269 | * @return array|bool |
| 270 | 270 | */ |
| 271 | 271 | function inc_ls_to_array_dist($data) { |
| 272 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | - $a = $glob_to_array($data); |
|
| 274 | - foreach ($a as &$v) { |
|
| 275 | - $b = (array)@stat($v); |
|
| 276 | - foreach (array_keys($b) as $k) { |
|
| 277 | - if (is_numeric($k)) { |
|
| 278 | - unset($b[$k]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 282 | - $v = array_merge( |
|
| 283 | - pathinfo($v), |
|
| 284 | - $b |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $a; |
|
| 272 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | + $a = $glob_to_array($data); |
|
| 274 | + foreach ($a as &$v) { |
|
| 275 | + $b = (array)@stat($v); |
|
| 276 | + foreach (array_keys($b) as $k) { |
|
| 277 | + if (is_numeric($k)) { |
|
| 278 | + unset($b[$k]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 282 | + $v = array_merge( |
|
| 283 | + pathinfo($v), |
|
| 284 | + $b |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $a; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | * @return array|bool |
| 296 | 296 | */ |
| 297 | 297 | function XMLObjectToArray($object) { |
| 298 | - $xml_array = []; |
|
| 299 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | - $key .= '-' . uniqid(); |
|
| 302 | - } |
|
| 303 | - $vars = get_object_vars($object->current()); |
|
| 304 | - if (isset($vars['@attributes'])) { |
|
| 305 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | - $xml_array[$key][$k] = $v; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - $xml_array[$key][] = $object->hasChildren() |
|
| 310 | - ? XMLObjectToArray($object->current()) |
|
| 311 | - : (string) $object->current(); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $xml_array; |
|
| 298 | + $xml_array = []; |
|
| 299 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | + $key .= '-' . uniqid(); |
|
| 302 | + } |
|
| 303 | + $vars = get_object_vars($object->current()); |
|
| 304 | + if (isset($vars['@attributes'])) { |
|
| 305 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | + $xml_array[$key][$k] = $v; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + $xml_array[$key][] = $object->hasChildren() |
|
| 310 | + ? XMLObjectToArray($object->current()) |
|
| 311 | + : (string) $object->current(); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $xml_array; |
|
| 315 | 315 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | 121 | # sortir le connecteur de $data |
| 122 | 122 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 123 | - $serveur = (string)$v[1]; |
|
| 123 | + $serveur = (string) $v[1]; |
|
| 124 | 124 | $req = trim($v[2]); |
| 125 | 125 | if ($s = sql_query($req, $serveur)) { |
| 126 | 126 | $r = []; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 146 | 146 | } catch (JsonException $e) { |
| 147 | 147 | $json = null; |
| 148 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 148 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 149 | 149 | } |
| 150 | 150 | return is_array($json) ? (array) $json : []; |
| 151 | 151 | } |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | $i = 1; |
| 166 | 166 | foreach ($entete as $k => $v) { |
| 167 | 167 | if (trim($v) == '') { |
| 168 | - $v = 'col' . $i; |
|
| 168 | + $v = 'col'.$i; |
|
| 169 | 169 | } // reperer des eventuelles cases vides |
| 170 | 170 | if (is_numeric($v) && $v < 0) { |
| 171 | - $v = '__' . $v; |
|
| 171 | + $v = '__'.$v; |
|
| 172 | 172 | } // ne pas risquer d'ecraser une cle numerique |
| 173 | 173 | if (is_numeric($v)) { |
| 174 | - $v = '_' . $v; |
|
| 174 | + $v = '_'.$v; |
|
| 175 | 175 | } // ne pas risquer d'ecraser une cle numerique |
| 176 | 176 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 177 | 177 | foreach ($csv as &$item) { |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 273 | 273 | $a = $glob_to_array($data); |
| 274 | 274 | foreach ($a as &$v) { |
| 275 | - $b = (array)@stat($v); |
|
| 275 | + $b = (array) @stat($v); |
|
| 276 | 276 | foreach (array_keys($b) as $k) { |
| 277 | 277 | if (is_numeric($k)) { |
| 278 | 278 | unset($b[$k]); |
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 282 | 282 | $v = array_merge( |
| 283 | 283 | pathinfo($v), |
| 284 | 284 | $b |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $xml_array = []; |
| 299 | 299 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 300 | 300 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 301 | - $key .= '-' . uniqid(); |
|
| 301 | + $key .= '-'.uniqid(); |
|
| 302 | 302 | } |
| 303 | 303 | $vars = get_object_vars($object->current()); |
| 304 | 304 | if (isset($vars['@attributes'])) { |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/charsets'); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * @return string Fonction PHP correspondante du filtre |
| 42 | 42 | */ |
| 43 | 43 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 44 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | - return chercher_filtre($fonc, $default); |
|
| 44 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | + return chercher_filtre($fonc, $default); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string texte |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_identite_dist($texte) { |
| 55 | - return $texte; |
|
| 55 | + return $texte; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -76,33 +76,33 @@ discard block |
||
| 76 | 76 | * Fonction PHP correspondante du filtre demandé |
| 77 | 77 | */ |
| 78 | 78 | function chercher_filtre($fonc, $default = null) { |
| 79 | - if (!$fonc) { |
|
| 80 | - return $default; |
|
| 81 | - } |
|
| 82 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | - // Foo::Bar |
|
| 84 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | - $f = chercher_filtre($nom); |
|
| 88 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | - if (!$f && $nom !== $fonc) { |
|
| 91 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $f; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - include_fichiers_fonctions(); |
|
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | - if (is_callable($f)) { |
|
| 101 | - return $f; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $default; |
|
| 79 | + if (!$fonc) { |
|
| 80 | + return $default; |
|
| 81 | + } |
|
| 82 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | + // Foo::Bar |
|
| 84 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | + $f = chercher_filtre($nom); |
|
| 88 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | + if (!$f && $nom !== $fonc) { |
|
| 91 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $f; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + include_fichiers_fonctions(); |
|
| 98 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | + if (is_callable($f)) { |
|
| 101 | + return $f; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $default; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * Chaîne vide sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function appliquer_filtre(mixed $arg, $filtre) { |
| 149 | - $args = func_get_args(); |
|
| 150 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 149 | + $args = func_get_args(); |
|
| 150 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * texte d'origine sinon |
| 173 | 173 | **/ |
| 174 | 174 | function appliquer_si_filtre(mixed $arg, $filtre) { |
| 175 | - $args = func_get_args(); |
|
| 176 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 175 | + $args = func_get_args(); |
|
| 176 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | * Version de SPIP |
| 190 | 190 | **/ |
| 191 | 191 | function spip_version() { |
| 192 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | - $version .= " $vcs_version"; |
|
| 195 | - } |
|
| 192 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | + $version .= " $vcs_version"; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $version; |
|
| 197 | + return $version; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | 208 | function header_silencieux($version): string { |
| 209 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | - $version = ''; |
|
| 211 | - } |
|
| 209 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | + $version = ''; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return (string) $version; |
|
| 213 | + return (string) $version; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | * - string|null si $raw = false |
| 224 | 224 | */ |
| 225 | 225 | function version_vcs_courante($dir, $raw = false) { |
| 226 | - $desc = decrire_version_git($dir); |
|
| 227 | - if ($desc === null || $raw) { |
|
| 228 | - return $desc; |
|
| 229 | - } |
|
| 230 | - // affichage "GIT [master: abcdef]" |
|
| 231 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | - if ($desc['branch']) { |
|
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | - } |
|
| 235 | - return "{$desc['vcs']} [$commit]"; |
|
| 226 | + $desc = decrire_version_git($dir); |
|
| 227 | + if ($desc === null || $raw) { |
|
| 228 | + return $desc; |
|
| 229 | + } |
|
| 230 | + // affichage "GIT [master: abcdef]" |
|
| 231 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | + if ($desc['branch']) { |
|
| 233 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | + } |
|
| 235 | + return "{$desc['vcs']} [$commit]"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,26 +244,26 @@ discard block |
||
| 244 | 244 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 245 | 245 | **/ |
| 246 | 246 | function decrire_version_git($dir) { |
| 247 | - $c = null; |
|
| 248 | - $hash = null; |
|
| 249 | - if (!$dir) { |
|
| 250 | - $dir = '.'; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // version installee par GIT |
|
| 254 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 255 | - $currentHead = trim(substr($c, 4)); |
|
| 256 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 257 | - return [ |
|
| 258 | - 'vcs' => 'GIT', |
|
| 259 | - 'branch' => basename($currentHead), |
|
| 260 | - 'commit' => trim($hash), |
|
| 261 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 262 | - ]; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return null; |
|
| 247 | + $c = null; |
|
| 248 | + $hash = null; |
|
| 249 | + if (!$dir) { |
|
| 250 | + $dir = '.'; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // version installee par GIT |
|
| 254 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 255 | + $currentHead = trim(substr($c, 4)); |
|
| 256 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 257 | + return [ |
|
| 258 | + 'vcs' => 'GIT', |
|
| 259 | + 'branch' => basename($currentHead), |
|
| 260 | + 'commit' => trim($hash), |
|
| 261 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 262 | + ]; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return null; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -310,18 +310,18 @@ discard block |
||
| 310 | 310 | * Code HTML retourné par le filtre |
| 311 | 311 | **/ |
| 312 | 312 | function filtrer($filtre) { |
| 313 | - $tous = func_get_args(); |
|
| 314 | - if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 315 | - return image_filtrer($tous); |
|
| 316 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 317 | - array_shift($tous); |
|
| 318 | - return $f(...$tous); |
|
| 319 | - } else { |
|
| 320 | - // le filtre n'existe pas, on provoque une erreur |
|
| 321 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 322 | - erreur_squelette($msg); |
|
| 323 | - return ''; |
|
| 324 | - } |
|
| 313 | + $tous = func_get_args(); |
|
| 314 | + if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 315 | + return image_filtrer($tous); |
|
| 316 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 317 | + array_shift($tous); |
|
| 318 | + return $f(...$tous); |
|
| 319 | + } else { |
|
| 320 | + // le filtre n'existe pas, on provoque une erreur |
|
| 321 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 322 | + erreur_squelette($msg); |
|
| 323 | + return ''; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -338,11 +338,11 @@ discard block |
||
| 338 | 338 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 339 | 339 | */ |
| 340 | 340 | function trouver_filtre_matrice($filtre) { |
| 341 | - if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 342 | - find_in_path($f, '', true); |
|
| 343 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 344 | - } |
|
| 345 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 341 | + if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 342 | + find_in_path($f, '', true); |
|
| 343 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 344 | + } |
|
| 345 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | * @return mixed |
| 371 | 371 | */ |
| 372 | 372 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 373 | - $Pile['vars'][$key] = $val; |
|
| 374 | - return $continue ? $val : ''; |
|
| 373 | + $Pile['vars'][$key] = $val; |
|
| 374 | + return $continue ? $val : ''; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -397,8 +397,8 @@ discard block |
||
| 397 | 397 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 398 | 398 | */ |
| 399 | 399 | function filtre_setenv(&$Pile, $val, mixed $key, $continue = null) { |
| 400 | - $Pile[0][$key] = $val; |
|
| 401 | - return $continue ? $val : ''; |
|
| 400 | + $Pile[0][$key] = $val; |
|
| 401 | + return $continue ? $val : ''; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * @return string |
| 408 | 408 | */ |
| 409 | 409 | function filtre_sanitize_env(&$Pile, $keys) { |
| 410 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 411 | - return ''; |
|
| 410 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 411 | + return ''; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -431,18 +431,18 @@ discard block |
||
| 431 | 431 | * @return mixed Retourne la valeur (sans la modifier). |
| 432 | 432 | */ |
| 433 | 433 | function filtre_debug($val, $key = null) { |
| 434 | - $debug = ( |
|
| 435 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | - ) . var_export($val, true); |
|
| 434 | + $debug = ( |
|
| 435 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | + ) . var_export($val, true); |
|
| 437 | 437 | |
| 438 | - include_spip('inc/autoriser'); |
|
| 439 | - if (autoriser('webmestre')) { |
|
| 440 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 441 | - } |
|
| 438 | + include_spip('inc/autoriser'); |
|
| 439 | + if (autoriser('webmestre')) { |
|
| 440 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - spip_log($debug, 'debug'); |
|
| 443 | + spip_log($debug, 'debug'); |
|
| 444 | 444 | |
| 445 | - return $val; |
|
| 445 | + return $val; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -472,81 +472,81 @@ discard block |
||
| 472 | 472 | * texte qui a reçu les filtres |
| 473 | 473 | **/ |
| 474 | 474 | function image_filtrer($args) { |
| 475 | - $filtre = array_shift($args); # enlever $filtre |
|
| 476 | - $texte = array_shift($args); |
|
| 477 | - if ($texte === null || !strlen($texte)) { |
|
| 478 | - return ''; |
|
| 479 | - } |
|
| 480 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 481 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 482 | - // Cas du nom de fichier local |
|
| 483 | - $is_file = trim($texte); |
|
| 484 | - if ( |
|
| 485 | - str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 486 | - || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 487 | - || str_starts_with($is_file, '/') |
|
| 488 | - ) { |
|
| 489 | - $is_file = false; |
|
| 490 | - } |
|
| 491 | - if ($is_file) { |
|
| 492 | - $is_local_file = function ($path) { |
|
| 493 | - if (str_contains($path, '?')) { |
|
| 494 | - $path = supprimer_timestamp($path); |
|
| 495 | - // remove ?24px added by find_in_theme on .svg files |
|
| 496 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 497 | - } |
|
| 498 | - return file_exists($path); |
|
| 499 | - }; |
|
| 500 | - if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 501 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 502 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 503 | - return $res; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 508 | - if ( |
|
| 509 | - preg_match_all( |
|
| 510 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 511 | - $texte, |
|
| 512 | - $tags, |
|
| 513 | - PREG_SET_ORDER |
|
| 514 | - ) |
|
| 515 | - ) { |
|
| 516 | - foreach ($tags as $tag) { |
|
| 517 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 518 | - if ( |
|
| 519 | - (!$class || !str_contains($class, 'filtre_inactif') |
|
| 520 | - && !str_contains($class, 'no_image_filtrer')) && ($reduit = $filtre($tag[3], ...$args)) |
|
| 521 | - ) { |
|
| 522 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 523 | - if ($tag[1]) { |
|
| 524 | - $w = extraire_attribut($reduit, 'width'); |
|
| 525 | - if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 526 | - $w = $regs[1]; |
|
| 527 | - } |
|
| 528 | - if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 529 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 530 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 531 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - // traiter aussi un eventuel mouseover |
|
| 535 | - if ( |
|
| 536 | - ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 537 | - && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 538 | - ) { |
|
| 539 | - $srcover = $match[1]; |
|
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 543 | - } |
|
| 544 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 549 | - return $texte; |
|
| 475 | + $filtre = array_shift($args); # enlever $filtre |
|
| 476 | + $texte = array_shift($args); |
|
| 477 | + if ($texte === null || !strlen($texte)) { |
|
| 478 | + return ''; |
|
| 479 | + } |
|
| 480 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 481 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 482 | + // Cas du nom de fichier local |
|
| 483 | + $is_file = trim($texte); |
|
| 484 | + if ( |
|
| 485 | + str_contains(substr($is_file, strlen(_DIR_RACINE)), '..') |
|
| 486 | + || strpbrk($is_file, "<>\n\r\t") !== false |
|
| 487 | + || str_starts_with($is_file, '/') |
|
| 488 | + ) { |
|
| 489 | + $is_file = false; |
|
| 490 | + } |
|
| 491 | + if ($is_file) { |
|
| 492 | + $is_local_file = function ($path) { |
|
| 493 | + if (str_contains($path, '?')) { |
|
| 494 | + $path = supprimer_timestamp($path); |
|
| 495 | + // remove ?24px added by find_in_theme on .svg files |
|
| 496 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 497 | + } |
|
| 498 | + return file_exists($path); |
|
| 499 | + }; |
|
| 500 | + if ($is_local_file($is_file) || tester_url_absolue($is_file)) { |
|
| 501 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 502 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 503 | + return $res; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 508 | + if ( |
|
| 509 | + preg_match_all( |
|
| 510 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 511 | + $texte, |
|
| 512 | + $tags, |
|
| 513 | + PREG_SET_ORDER |
|
| 514 | + ) |
|
| 515 | + ) { |
|
| 516 | + foreach ($tags as $tag) { |
|
| 517 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 518 | + if ( |
|
| 519 | + (!$class || !str_contains($class, 'filtre_inactif') |
|
| 520 | + && !str_contains($class, 'no_image_filtrer')) && ($reduit = $filtre($tag[3], ...$args)) |
|
| 521 | + ) { |
|
| 522 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 523 | + if ($tag[1]) { |
|
| 524 | + $w = extraire_attribut($reduit, 'width'); |
|
| 525 | + if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 526 | + $w = $regs[1]; |
|
| 527 | + } |
|
| 528 | + if ($w && ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 529 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 530 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 531 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + // traiter aussi un eventuel mouseover |
|
| 535 | + if ( |
|
| 536 | + ($mouseover = extraire_attribut($reduit, 'onmouseover')) |
|
| 537 | + && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
|
| 538 | + ) { |
|
| 539 | + $srcover = $match[1]; |
|
| 540 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 543 | + } |
|
| 544 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 549 | + return $texte; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -563,94 +563,94 @@ discard block |
||
| 563 | 563 | **/ |
| 564 | 564 | function infos_image($img, $force_refresh = false) { |
| 565 | 565 | |
| 566 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 567 | - $srcWidth = 0; |
|
| 568 | - $srcHeight = 0; |
|
| 569 | - $srcSize = null; |
|
| 570 | - $valeurs = null; |
|
| 571 | - |
|
| 572 | - $src = extraire_attribut($img, 'src'); |
|
| 573 | - |
|
| 574 | - if (!$src) { |
|
| 575 | - $src = $img; |
|
| 576 | - } else { |
|
| 577 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | - if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 580 | - $srcWidth = $srcHeight = 0; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | - if (tester_url_absolue($src)) { |
|
| 587 | - include_spip('inc/distant'); |
|
| 588 | - $fichier = copie_locale($src); |
|
| 589 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | - } |
|
| 591 | - if (($p = strpos($src, '?')) !== false) { |
|
| 592 | - $src = substr($src, 0, $p); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $imagesize = false; |
|
| 596 | - if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 597 | - $srcWidth = $largeur_img[$src]; |
|
| 598 | - } |
|
| 599 | - if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 600 | - $srcHeight = $hauteur_img[$src]; |
|
| 601 | - } |
|
| 602 | - if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 603 | - $srcSize = $poids_img[$src]; |
|
| 604 | - } |
|
| 605 | - if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 606 | - if ( |
|
| 607 | - file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 608 | - ) { |
|
| 609 | - if (!$srcWidth) { |
|
| 610 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 611 | - } |
|
| 612 | - if (!$srcHeight) { |
|
| 613 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 614 | - } |
|
| 615 | - if (!$srcSize) { |
|
| 616 | - $poids_img[$src] = filesize($src); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - elseif (str_contains($src, '<svg')) { |
|
| 620 | - include_spip('inc/svg'); |
|
| 621 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 622 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 623 | - if (!$srcWidth) { |
|
| 624 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 625 | - } |
|
| 626 | - if (!$srcHeight) { |
|
| 627 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 628 | - } |
|
| 629 | - if (!$srcSize) { |
|
| 630 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 635 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 636 | - elseif ( |
|
| 637 | - @file_exists($f = "$src.src") |
|
| 638 | - && lire_fichier($f, $valeurs) |
|
| 639 | - && ($valeurs = unserialize($valeurs)) |
|
| 640 | - ) { |
|
| 641 | - if (!$srcWidth) { |
|
| 642 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 643 | - } |
|
| 644 | - if (!$srcHeight) { |
|
| 645 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 646 | - } |
|
| 647 | - if (!$srcSize) { |
|
| 648 | - $poids_img[$src] = $srcSize = 0; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 566 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 567 | + $srcWidth = 0; |
|
| 568 | + $srcHeight = 0; |
|
| 569 | + $srcSize = null; |
|
| 570 | + $valeurs = null; |
|
| 571 | + |
|
| 572 | + $src = extraire_attribut($img, 'src'); |
|
| 573 | + |
|
| 574 | + if (!$src) { |
|
| 575 | + $src = $img; |
|
| 576 | + } else { |
|
| 577 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | + if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) { |
|
| 580 | + $srcWidth = $srcHeight = 0; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | + if (tester_url_absolue($src)) { |
|
| 587 | + include_spip('inc/distant'); |
|
| 588 | + $fichier = copie_locale($src); |
|
| 589 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | + } |
|
| 591 | + if (($p = strpos($src, '?')) !== false) { |
|
| 592 | + $src = substr($src, 0, $p); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $imagesize = false; |
|
| 596 | + if (isset($largeur_img[$src]) && !$force_refresh) { |
|
| 597 | + $srcWidth = $largeur_img[$src]; |
|
| 598 | + } |
|
| 599 | + if (isset($hauteur_img[$src]) && !$force_refresh) { |
|
| 600 | + $srcHeight = $hauteur_img[$src]; |
|
| 601 | + } |
|
| 602 | + if (isset($poids_img[$src]) && !$force_refresh) { |
|
| 603 | + $srcSize = $poids_img[$src]; |
|
| 604 | + } |
|
| 605 | + if (!$srcWidth || !$srcHeight || is_null($srcSize)) { |
|
| 606 | + if ( |
|
| 607 | + file_exists($src) && ($imagesize = spip_getimagesize($src)) |
|
| 608 | + ) { |
|
| 609 | + if (!$srcWidth) { |
|
| 610 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 611 | + } |
|
| 612 | + if (!$srcHeight) { |
|
| 613 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 614 | + } |
|
| 615 | + if (!$srcSize) { |
|
| 616 | + $poids_img[$src] = filesize($src); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + elseif (str_contains($src, '<svg')) { |
|
| 620 | + include_spip('inc/svg'); |
|
| 621 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 622 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 623 | + if (!$srcWidth) { |
|
| 624 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 625 | + } |
|
| 626 | + if (!$srcHeight) { |
|
| 627 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 628 | + } |
|
| 629 | + if (!$srcSize) { |
|
| 630 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 635 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 636 | + elseif ( |
|
| 637 | + @file_exists($f = "$src.src") |
|
| 638 | + && lire_fichier($f, $valeurs) |
|
| 639 | + && ($valeurs = unserialize($valeurs)) |
|
| 640 | + ) { |
|
| 641 | + if (!$srcWidth) { |
|
| 642 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 643 | + } |
|
| 644 | + if (!$srcHeight) { |
|
| 645 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 646 | + } |
|
| 647 | + if (!$srcSize) { |
|
| 648 | + $poids_img[$src] = $srcSize = 0; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -666,13 +666,13 @@ discard block |
||
| 666 | 666 | * poids |
| 667 | 667 | **/ |
| 668 | 668 | function poids_image($img, $force_refresh = false) { |
| 669 | - $infos = infos_image($img, $force_refresh); |
|
| 670 | - return $infos['poids']; |
|
| 669 | + $infos = infos_image($img, $force_refresh); |
|
| 670 | + return $infos['poids']; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | function taille_image($img, $force_refresh = false) { |
| 674 | - $infos = infos_image($img, $force_refresh); |
|
| 675 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 674 | + $infos = infos_image($img, $force_refresh); |
|
| 675 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -689,12 +689,12 @@ discard block |
||
| 689 | 689 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 690 | 690 | **/ |
| 691 | 691 | function largeur($img) { |
| 692 | - if (!$img) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - [$h, $l] = taille_image($img); |
|
| 692 | + if (!$img) { |
|
| 693 | + return; |
|
| 694 | + } |
|
| 695 | + [$h, $l] = taille_image($img); |
|
| 696 | 696 | |
| 697 | - return $l; |
|
| 697 | + return $l; |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 712 | 712 | **/ |
| 713 | 713 | function hauteur($img) { |
| 714 | - if (!$img) { |
|
| 715 | - return; |
|
| 716 | - } |
|
| 717 | - [$h, $l] = taille_image($img); |
|
| 714 | + if (!$img) { |
|
| 715 | + return; |
|
| 716 | + } |
|
| 717 | + [$h, $l] = taille_image($img); |
|
| 718 | 718 | |
| 719 | - return $h; |
|
| 719 | + return $h; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -736,11 +736,11 @@ discard block |
||
| 736 | 736 | * @return string |
| 737 | 737 | **/ |
| 738 | 738 | function corriger_entites_html($texte) { |
| 739 | - if (!str_contains($texte, '&')) { |
|
| 740 | - return $texte; |
|
| 741 | - } |
|
| 739 | + if (!str_contains($texte, '&')) { |
|
| 740 | + return $texte; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | - return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 743 | + return preg_replace(',&(#\d\d\d+;|amp;),iS', '&\1', $texte); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -755,11 +755,11 @@ discard block |
||
| 755 | 755 | * @return string |
| 756 | 756 | **/ |
| 757 | 757 | function corriger_toutes_entites_html($texte) { |
| 758 | - if (!str_contains($texte, '&')) { |
|
| 759 | - return $texte; |
|
| 760 | - } |
|
| 758 | + if (!str_contains($texte, '&')) { |
|
| 759 | + return $texte; |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 762 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | **/ |
| 771 | 771 | function proteger_amp($texte) { |
| 772 | - return str_replace('&', '&', $texte); |
|
| 772 | + return str_replace('&', '&', $texte); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -800,18 +800,18 @@ discard block |
||
| 800 | 800 | * @return mixed|string |
| 801 | 801 | */ |
| 802 | 802 | function entites_html($texte, $tout = false, $quote = true) { |
| 803 | - if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 804 | - return $texte; |
|
| 805 | - } |
|
| 806 | - include_spip('inc/texte'); |
|
| 807 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 808 | - $flags |= ENT_HTML401; |
|
| 809 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 810 | - if ($tout) { |
|
| 811 | - return corriger_toutes_entites_html($texte); |
|
| 812 | - } else { |
|
| 813 | - return corriger_entites_html($texte); |
|
| 814 | - } |
|
| 803 | + if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) { |
|
| 804 | + return $texte; |
|
| 805 | + } |
|
| 806 | + include_spip('inc/texte'); |
|
| 807 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 808 | + $flags |= ENT_HTML401; |
|
| 809 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 810 | + if ($tout) { |
|
| 811 | + return corriger_toutes_entites_html($texte); |
|
| 812 | + } else { |
|
| 813 | + return corriger_entites_html($texte); |
|
| 814 | + } |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | /** |
@@ -830,38 +830,38 @@ discard block |
||
| 830 | 830 | * texte converti |
| 831 | 831 | **/ |
| 832 | 832 | function filtrer_entites(?string $texte): string { |
| 833 | - $texte ??= ''; |
|
| 834 | - if (!str_contains($texte, '&')) { |
|
| 835 | - return $texte; |
|
| 836 | - } |
|
| 837 | - // filtrer |
|
| 838 | - $texte = html2unicode($texte); |
|
| 839 | - // remettre le tout dans le charset cible |
|
| 840 | - $texte = unicode2charset($texte); |
|
| 841 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 842 | - // (on le faisait deja avec un ") |
|
| 843 | - if (str_contains($texte, '&#')) { |
|
| 844 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 845 | - } |
|
| 833 | + $texte ??= ''; |
|
| 834 | + if (!str_contains($texte, '&')) { |
|
| 835 | + return $texte; |
|
| 836 | + } |
|
| 837 | + // filtrer |
|
| 838 | + $texte = html2unicode($texte); |
|
| 839 | + // remettre le tout dans le charset cible |
|
| 840 | + $texte = unicode2charset($texte); |
|
| 841 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 842 | + // (on le faisait deja avec un ") |
|
| 843 | + if (str_contains($texte, '&#')) { |
|
| 844 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return $texte; |
|
| 847 | + return $texte; |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
| 851 | 851 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 852 | - /** |
|
| 853 | - * Version sécurisée de filtrer_entites |
|
| 854 | - * |
|
| 855 | - * @uses interdire_scripts() |
|
| 856 | - * @uses filtrer_entites() |
|
| 857 | - * |
|
| 858 | - * @param string $t |
|
| 859 | - * @return string |
|
| 860 | - */ |
|
| 861 | - function filtre_filtrer_entites_dist($t) { |
|
| 862 | - include_spip('inc/texte'); |
|
| 863 | - return interdire_scripts(filtrer_entites($t)); |
|
| 864 | - } |
|
| 852 | + /** |
|
| 853 | + * Version sécurisée de filtrer_entites |
|
| 854 | + * |
|
| 855 | + * @uses interdire_scripts() |
|
| 856 | + * @uses filtrer_entites() |
|
| 857 | + * |
|
| 858 | + * @param string $t |
|
| 859 | + * @return string |
|
| 860 | + */ |
|
| 861 | + function filtre_filtrer_entites_dist($t) { |
|
| 862 | + include_spip('inc/texte'); |
|
| 863 | + return interdire_scripts(filtrer_entites($t)); |
|
| 864 | + } |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | |
@@ -876,18 +876,18 @@ discard block |
||
| 876 | 876 | * @return string|array |
| 877 | 877 | **/ |
| 878 | 878 | function supprimer_caracteres_illegaux($texte) { |
| 879 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 880 | - static $to = null; |
|
| 879 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 880 | + static $to = null; |
|
| 881 | 881 | |
| 882 | - if (is_array($texte)) { |
|
| 883 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 884 | - } |
|
| 882 | + if (is_array($texte)) { |
|
| 883 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - if (!$to) { |
|
| 887 | - $to = str_repeat('-', strlen($from)); |
|
| 888 | - } |
|
| 886 | + if (!$to) { |
|
| 887 | + $to = str_repeat('-', strlen($from)); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - return strtr($texte, $from, $to); |
|
| 890 | + return strtr($texte, $from, $to); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | /** |
@@ -899,9 +899,9 @@ discard block |
||
| 899 | 899 | * @return string|array |
| 900 | 900 | **/ |
| 901 | 901 | function corriger_caracteres($texte) { |
| 902 | - $texte = corriger_caracteres_windows($texte); |
|
| 902 | + $texte = corriger_caracteres_windows($texte); |
|
| 903 | 903 | |
| 904 | - return supprimer_caracteres_illegaux($texte); |
|
| 904 | + return supprimer_caracteres_illegaux($texte); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -918,44 +918,44 @@ discard block |
||
| 918 | 918 | * texte encodé pour XML |
| 919 | 919 | */ |
| 920 | 920 | function texte_backend(string $texte): string { |
| 921 | - if ($texte === '') { |
|
| 922 | - return ''; |
|
| 923 | - } |
|
| 921 | + if ($texte === '') { |
|
| 922 | + return ''; |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 925 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 926 | 926 | |
| 927 | - // si on a des liens ou des images, les passer en absolu |
|
| 928 | - $texte = liens_absolus($texte); |
|
| 927 | + // si on a des liens ou des images, les passer en absolu |
|
| 928 | + $texte = liens_absolus($texte); |
|
| 929 | 929 | |
| 930 | - // echapper les tags > < |
|
| 931 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 930 | + // echapper les tags > < |
|
| 931 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 932 | 932 | |
| 933 | - // importer les é |
|
| 934 | - $texte = filtrer_entites($texte); |
|
| 933 | + // importer les é |
|
| 934 | + $texte = filtrer_entites($texte); |
|
| 935 | 935 | |
| 936 | - // " -> " et tout ce genre de choses |
|
| 937 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 938 | - $texte = str_replace(' ', ' ', $texte); |
|
| 939 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 940 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 941 | - $texte = entites_html($texte, false, false); |
|
| 942 | - // mais bien echapper les double quotes ! |
|
| 943 | - $texte = str_replace('"', '"', $texte); |
|
| 936 | + // " -> " et tout ce genre de choses |
|
| 937 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 938 | + $texte = str_replace(' ', ' ', $texte); |
|
| 939 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 940 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 941 | + $texte = entites_html($texte, false, false); |
|
| 942 | + // mais bien echapper les double quotes ! |
|
| 943 | + $texte = str_replace('"', '"', $texte); |
|
| 944 | 944 | |
| 945 | - // verifier le charset |
|
| 946 | - $texte = charset2unicode($texte); |
|
| 945 | + // verifier le charset |
|
| 946 | + $texte = charset2unicode($texte); |
|
| 947 | 947 | |
| 948 | - // Caracteres problematiques en iso-latin 1 |
|
| 949 | - if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 950 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 951 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 952 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 953 | - } |
|
| 948 | + // Caracteres problematiques en iso-latin 1 |
|
| 949 | + if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 950 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 951 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 952 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 953 | + } |
|
| 954 | 954 | |
| 955 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 956 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 957 | - // ==> on les remplace par l'entite HTML |
|
| 958 | - return str_replace($apostrophe, "'", $texte); |
|
| 955 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 956 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 957 | + // ==> on les remplace par l'entite HTML |
|
| 958 | + return str_replace($apostrophe, "'", $texte); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | * texte encodé et quote pour XML |
| 973 | 973 | */ |
| 974 | 974 | function texte_backendq(string $texte): string { |
| 975 | - return addslashes(texte_backend($texte)); |
|
| 975 | + return addslashes(texte_backend($texte)); |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | |
@@ -994,14 +994,14 @@ discard block |
||
| 994 | 994 | * Texte sans son numéro éventuel |
| 995 | 995 | **/ |
| 996 | 996 | function supprimer_numero(?string $texte): string { |
| 997 | - if ($texte === null) { |
|
| 998 | - return ''; |
|
| 999 | - } |
|
| 1000 | - return preg_replace( |
|
| 1001 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1002 | - '', |
|
| 1003 | - $texte |
|
| 1004 | - ); |
|
| 997 | + if ($texte === null) { |
|
| 998 | + return ''; |
|
| 999 | + } |
|
| 1000 | + return preg_replace( |
|
| 1001 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1002 | + '', |
|
| 1003 | + $texte |
|
| 1004 | + ); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | /** |
@@ -1024,18 +1024,18 @@ discard block |
||
| 1024 | 1024 | * Numéro de titre, sinon chaîne vide |
| 1025 | 1025 | **/ |
| 1026 | 1026 | function recuperer_numero(?string $texte): string { |
| 1027 | - if ( |
|
| 1028 | - $texte |
|
| 1029 | - && preg_match( |
|
| 1030 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1031 | - $texte, |
|
| 1032 | - $regs |
|
| 1033 | - ) |
|
| 1034 | - ) { |
|
| 1035 | - return (string) $regs[1]; |
|
| 1036 | - } else { |
|
| 1037 | - return ''; |
|
| 1038 | - } |
|
| 1027 | + if ( |
|
| 1028 | + $texte |
|
| 1029 | + && preg_match( |
|
| 1030 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1031 | + $texte, |
|
| 1032 | + $regs |
|
| 1033 | + ) |
|
| 1034 | + ) { |
|
| 1035 | + return (string) $regs[1]; |
|
| 1036 | + } else { |
|
| 1037 | + return ''; |
|
| 1038 | + } |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1062,16 +1062,16 @@ discard block |
||
| 1062 | 1062 | * texte ou tableau de textes converti |
| 1063 | 1063 | **/ |
| 1064 | 1064 | function supprimer_tags($texte, $rempl = '') { |
| 1065 | - if ($texte === null) { |
|
| 1066 | - return ''; |
|
| 1067 | - } |
|
| 1068 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1069 | - // ne pas oublier un < final non ferme car coupe |
|
| 1070 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1071 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1072 | - $texte = str_replace('<', '<', $texte); |
|
| 1065 | + if ($texte === null) { |
|
| 1066 | + return ''; |
|
| 1067 | + } |
|
| 1068 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1069 | + // ne pas oublier un < final non ferme car coupe |
|
| 1070 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1071 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1072 | + $texte = str_replace('<', '<', $texte); |
|
| 1073 | 1073 | |
| 1074 | - return $texte; |
|
| 1074 | + return $texte; |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | * texte converti |
| 1095 | 1095 | **/ |
| 1096 | 1096 | function echapper_tags($texte, $rempl = '') { |
| 1097 | - return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1097 | + return preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
@@ -1115,18 +1115,18 @@ discard block |
||
| 1115 | 1115 | * texte converti |
| 1116 | 1116 | **/ |
| 1117 | 1117 | function textebrut($texte) { |
| 1118 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1119 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1120 | - $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1121 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1122 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1123 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1124 | - $texte = supprimer_tags($texte); |
|
| 1125 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1126 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1127 | - $texte = str_replace('’', "'", $texte); |
|
| 1118 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1119 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1120 | + $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
|
| 1121 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1122 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1123 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1124 | + $texte = supprimer_tags($texte); |
|
| 1125 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1126 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1127 | + $texte = str_replace('’', "'", $texte); |
|
| 1128 | 1128 | |
| 1129 | - return $texte; |
|
| 1129 | + return $texte; |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
@@ -1142,23 +1142,23 @@ discard block |
||
| 1142 | 1142 | * texte avec liens ouvrants |
| 1143 | 1143 | **/ |
| 1144 | 1144 | function liens_ouvrants($texte) { |
| 1145 | - if ( |
|
| 1146 | - preg_match_all( |
|
| 1147 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1148 | - $texte, |
|
| 1149 | - $liens, |
|
| 1150 | - PREG_PATTERN_ORDER |
|
| 1151 | - ) |
|
| 1152 | - ) { |
|
| 1153 | - foreach ($liens[0] as $a) { |
|
| 1154 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1155 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1156 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1157 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - return $texte; |
|
| 1145 | + if ( |
|
| 1146 | + preg_match_all( |
|
| 1147 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1148 | + $texte, |
|
| 1149 | + $liens, |
|
| 1150 | + PREG_PATTERN_ORDER |
|
| 1151 | + ) |
|
| 1152 | + ) { |
|
| 1153 | + foreach ($liens[0] as $a) { |
|
| 1154 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1155 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1156 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1157 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + return $texte; |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | /** |
@@ -1168,22 +1168,22 @@ discard block |
||
| 1168 | 1168 | * @return string |
| 1169 | 1169 | */ |
| 1170 | 1170 | function liens_nofollow($texte) { |
| 1171 | - if (stripos($texte, '<a') === false) { |
|
| 1172 | - return $texte; |
|
| 1173 | - } |
|
| 1171 | + if (stripos($texte, '<a') === false) { |
|
| 1172 | + return $texte; |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1176 | - foreach ($regs[0] as $a) { |
|
| 1177 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1178 | - if (!str_contains($rel, 'nofollow')) { |
|
| 1179 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1180 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1181 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1175 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1176 | + foreach ($regs[0] as $a) { |
|
| 1177 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1178 | + if (!str_contains($rel, 'nofollow')) { |
|
| 1179 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1180 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1181 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - return $texte; |
|
| 1186 | + return $texte; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1202,11 +1202,11 @@ discard block |
||
| 1202 | 1202 | * texte sans paraghaphes |
| 1203 | 1203 | **/ |
| 1204 | 1204 | function PtoBR($texte) { |
| 1205 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1206 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1207 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1205 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1206 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1207 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1208 | 1208 | |
| 1209 | - return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1209 | + return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | |
@@ -1231,19 +1231,19 @@ discard block |
||
| 1231 | 1231 | * @return string texte encadré du style CSS |
| 1232 | 1232 | */ |
| 1233 | 1233 | function lignes_longues($texte) { |
| 1234 | - trigger_error( |
|
| 1235 | - sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1236 | - \E_USER_DEPRECATED |
|
| 1237 | - ); |
|
| 1234 | + trigger_error( |
|
| 1235 | + sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1236 | + \E_USER_DEPRECATED |
|
| 1237 | + ); |
|
| 1238 | 1238 | |
| 1239 | - if (!strlen(trim($texte))) { |
|
| 1240 | - return $texte; |
|
| 1241 | - } |
|
| 1242 | - include_spip('inc/texte'); |
|
| 1243 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1244 | - 'div' : 'span'; |
|
| 1239 | + if (!strlen(trim($texte))) { |
|
| 1240 | + return $texte; |
|
| 1241 | + } |
|
| 1242 | + include_spip('inc/texte'); |
|
| 1243 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1244 | + 'div' : 'span'; |
|
| 1245 | 1245 | |
| 1246 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1246 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1262,30 +1262,30 @@ discard block |
||
| 1262 | 1262 | * @return string texte en majuscule |
| 1263 | 1263 | */ |
| 1264 | 1264 | function majuscules($texte) { |
| 1265 | - if (!strlen($texte)) { |
|
| 1266 | - return ''; |
|
| 1267 | - } |
|
| 1265 | + if (!strlen($texte)) { |
|
| 1266 | + return ''; |
|
| 1267 | + } |
|
| 1268 | 1268 | |
| 1269 | - // Cas du turc |
|
| 1270 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1271 | - # remplacer hors des tags et des entites |
|
| 1272 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1273 | - foreach ($regs as $n => $match) { |
|
| 1274 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1269 | + // Cas du turc |
|
| 1270 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1271 | + # remplacer hors des tags et des entites |
|
| 1272 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1273 | + foreach ($regs as $n => $match) { |
|
| 1274 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | 1277 | |
| 1278 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1278 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1279 | 1279 | |
| 1280 | - if ($regs) { |
|
| 1281 | - foreach ($regs as $n => $match) { |
|
| 1282 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1285 | - } |
|
| 1280 | + if ($regs) { |
|
| 1281 | + foreach ($regs as $n => $match) { |
|
| 1282 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | + } |
|
| 1286 | 1286 | |
| 1287 | - // Cas general |
|
| 1288 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1287 | + // Cas general |
|
| 1288 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1307,38 +1307,38 @@ discard block |
||
| 1307 | 1307 | */ |
| 1308 | 1308 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1309 | 1309 | |
| 1310 | - // Texte à afficher pour la taille |
|
| 1311 | - $affichage = ''; |
|
| 1310 | + // Texte à afficher pour la taille |
|
| 1311 | + $affichage = ''; |
|
| 1312 | 1312 | |
| 1313 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1314 | - static $precisions = [0, 1, 1, 2]; |
|
| 1313 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1314 | + static $precisions = [0, 1, 1, 2]; |
|
| 1315 | 1315 | |
| 1316 | - if ($octets >= 1) { |
|
| 1317 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1318 | - $systeme = strtolower($systeme); |
|
| 1319 | - if ($systeme === 'bi') { |
|
| 1320 | - $kilo = 1024; |
|
| 1321 | - $suffixe_item = "_$systeme"; |
|
| 1322 | - } elseif ($systeme === 'si') { |
|
| 1323 | - $kilo = 1000; |
|
| 1324 | - $suffixe_item = ''; |
|
| 1325 | - } else { |
|
| 1326 | - return $affichage; |
|
| 1327 | - } |
|
| 1316 | + if ($octets >= 1) { |
|
| 1317 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1318 | + $systeme = strtolower($systeme); |
|
| 1319 | + if ($systeme === 'bi') { |
|
| 1320 | + $kilo = 1024; |
|
| 1321 | + $suffixe_item = "_$systeme"; |
|
| 1322 | + } elseif ($systeme === 'si') { |
|
| 1323 | + $kilo = 1000; |
|
| 1324 | + $suffixe_item = ''; |
|
| 1325 | + } else { |
|
| 1326 | + return $affichage; |
|
| 1327 | + } |
|
| 1328 | 1328 | |
| 1329 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1330 | - $puissance = floor(log($octets, $kilo)); |
|
| 1329 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1330 | + $puissance = floor(log($octets, $kilo)); |
|
| 1331 | 1331 | |
| 1332 | - // Calcul de la taille et choix de l'unité |
|
| 1333 | - $affichage = _T( |
|
| 1334 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1335 | - [ |
|
| 1336 | - 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1337 | - ] |
|
| 1338 | - ); |
|
| 1339 | - } |
|
| 1332 | + // Calcul de la taille et choix de l'unité |
|
| 1333 | + $affichage = _T( |
|
| 1334 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1335 | + [ |
|
| 1336 | + 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
|
| 1337 | + ] |
|
| 1338 | + ); |
|
| 1339 | + } |
|
| 1340 | 1340 | |
| 1341 | - return $affichage; |
|
| 1341 | + return $affichage; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | |
@@ -1360,21 +1360,21 @@ discard block |
||
| 1360 | 1360 | * texte prêt pour être utilisé en attribut HTML |
| 1361 | 1361 | **/ |
| 1362 | 1362 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1363 | - if ($texte === null) { |
|
| 1364 | - return ''; |
|
| 1365 | - } |
|
| 1366 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1367 | - if ($textebrut) { |
|
| 1368 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1369 | - } |
|
| 1370 | - $texte = texte_backend($texte); |
|
| 1371 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1363 | + if ($texte === null) { |
|
| 1364 | + return ''; |
|
| 1365 | + } |
|
| 1366 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1367 | + if ($textebrut) { |
|
| 1368 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1369 | + } |
|
| 1370 | + $texte = texte_backend($texte); |
|
| 1371 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1372 | 1372 | |
| 1373 | - return preg_replace( |
|
| 1374 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1375 | - ['&', '&'], |
|
| 1376 | - $texte |
|
| 1377 | - ); |
|
| 1373 | + return preg_replace( |
|
| 1374 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1375 | + ['&', '&'], |
|
| 1376 | + $texte |
|
| 1377 | + ); |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | |
@@ -1394,15 +1394,15 @@ discard block |
||
| 1394 | 1394 | * URL ou chaîne vide |
| 1395 | 1395 | **/ |
| 1396 | 1396 | function vider_url(?string $url, $entites = true): string { |
| 1397 | - if ($url === null) { |
|
| 1398 | - return ''; |
|
| 1399 | - } |
|
| 1400 | - # un message pour abs_url |
|
| 1401 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1402 | - $url = trim($url); |
|
| 1403 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1397 | + if ($url === null) { |
|
| 1398 | + return ''; |
|
| 1399 | + } |
|
| 1400 | + # un message pour abs_url |
|
| 1401 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1402 | + $url = trim($url); |
|
| 1403 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1404 | 1404 | |
| 1405 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1405 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | |
@@ -1417,10 +1417,10 @@ discard block |
||
| 1417 | 1417 | * @return string Adresse email maquillée |
| 1418 | 1418 | **/ |
| 1419 | 1419 | function antispam($texte) { |
| 1420 | - include_spip('inc/acces'); |
|
| 1421 | - $masque = creer_pass_aleatoire(3); |
|
| 1420 | + include_spip('inc/acces'); |
|
| 1421 | + $masque = creer_pass_aleatoire(3); |
|
| 1422 | 1422 | |
| 1423 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1423 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | /** |
@@ -1452,8 +1452,8 @@ discard block |
||
| 1452 | 1452 | * True si on a le droit d'accès, false sinon. |
| 1453 | 1453 | **/ |
| 1454 | 1454 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1455 | - include_spip('inc/acces'); |
|
| 1456 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1455 | + include_spip('inc/acces'); |
|
| 1456 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | /** |
@@ -1477,13 +1477,13 @@ discard block |
||
| 1477 | 1477 | * Retourne $texte, sinon $sinon. |
| 1478 | 1478 | **/ |
| 1479 | 1479 | function sinon($texte, $sinon = '') { |
| 1480 | - if ($texte) { |
|
| 1481 | - return $texte; |
|
| 1482 | - } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1483 | - return $texte; |
|
| 1484 | - } else { |
|
| 1485 | - return $sinon; |
|
| 1486 | - } |
|
| 1480 | + if ($texte) { |
|
| 1481 | + return $texte; |
|
| 1482 | + } elseif (is_scalar($texte) && strlen($texte)) { |
|
| 1483 | + return $texte; |
|
| 1484 | + } else { |
|
| 1485 | + return $sinon; |
|
| 1486 | + } |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | /** |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | * @return mixed |
| 1508 | 1508 | **/ |
| 1509 | 1509 | function choixsivide($a, $vide, $pasvide) { |
| 1510 | - return $a ? $pasvide : $vide; |
|
| 1510 | + return $a ? $pasvide : $vide; |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | * @return mixed |
| 1532 | 1532 | **/ |
| 1533 | 1533 | function choixsiegal($a1, $a2, $v, $f) { |
| 1534 | - return ($a1 == $a2) ? $v : $f; |
|
| 1534 | + return ($a1 == $a2) ? $v : $f; |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | // |
@@ -1550,12 +1550,12 @@ discard block |
||
| 1550 | 1550 | * @return string |
| 1551 | 1551 | **/ |
| 1552 | 1552 | function filtrer_ical($texte) { |
| 1553 | - #include_spip('inc/charsets'); |
|
| 1554 | - $texte = html2unicode($texte); |
|
| 1555 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1556 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1553 | + #include_spip('inc/charsets'); |
|
| 1554 | + $texte = html2unicode($texte); |
|
| 1555 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1556 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1557 | 1557 | |
| 1558 | - return preg_replace('/,/', '\,', $texte); |
|
| 1558 | + return preg_replace('/,/', '\,', $texte); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | |
@@ -1580,58 +1580,58 @@ discard block |
||
| 1580 | 1580 | * @return string |
| 1581 | 1581 | **/ |
| 1582 | 1582 | function post_autobr($texte, $delim = "\n_ ") { |
| 1583 | - if (!function_exists('echappe_html')) { |
|
| 1584 | - include_spip('inc/texte_mini'); |
|
| 1585 | - } |
|
| 1586 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1587 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1588 | - |
|
| 1589 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1590 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1591 | - } else { |
|
| 1592 | - $fin = ''; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - $texte = echappe_html($texte, '', true); |
|
| 1596 | - |
|
| 1597 | - // echapper les modeles |
|
| 1598 | - $collecteurModeles = null; |
|
| 1599 | - if (str_contains($texte, '<')) { |
|
| 1600 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1601 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 1602 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1603 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - $debut = ''; |
|
| 1607 | - $suite = $texte; |
|
| 1608 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1609 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1610 | - $suite = substr($suite, $t); |
|
| 1611 | - $car = substr($suite, 0, 1); |
|
| 1612 | - if ( |
|
| 1613 | - $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1614 | - && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1615 | - && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1616 | - ) { |
|
| 1617 | - $debut .= $delim; |
|
| 1618 | - } else { |
|
| 1619 | - $debut .= "\n"; |
|
| 1620 | - } |
|
| 1621 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1622 | - $debut .= $regs[0]; |
|
| 1623 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1624 | - } |
|
| 1625 | - } |
|
| 1626 | - $texte = $debut . $suite; |
|
| 1627 | - |
|
| 1628 | - if ($collecteurModeles) { |
|
| 1629 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - $texte = echappe_retour($texte); |
|
| 1633 | - |
|
| 1634 | - return $texte . $fin; |
|
| 1583 | + if (!function_exists('echappe_html')) { |
|
| 1584 | + include_spip('inc/texte_mini'); |
|
| 1585 | + } |
|
| 1586 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1587 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1588 | + |
|
| 1589 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1590 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1591 | + } else { |
|
| 1592 | + $fin = ''; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + $texte = echappe_html($texte, '', true); |
|
| 1596 | + |
|
| 1597 | + // echapper les modeles |
|
| 1598 | + $collecteurModeles = null; |
|
| 1599 | + if (str_contains($texte, '<')) { |
|
| 1600 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1601 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 1602 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1603 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + $debut = ''; |
|
| 1607 | + $suite = $texte; |
|
| 1608 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1609 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1610 | + $suite = substr($suite, $t); |
|
| 1611 | + $car = substr($suite, 0, 1); |
|
| 1612 | + if ( |
|
| 1613 | + $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}' |
|
| 1614 | + && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1615 | + && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1616 | + ) { |
|
| 1617 | + $debut .= $delim; |
|
| 1618 | + } else { |
|
| 1619 | + $debut .= "\n"; |
|
| 1620 | + } |
|
| 1621 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1622 | + $debut .= $regs[0]; |
|
| 1623 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1624 | + } |
|
| 1625 | + } |
|
| 1626 | + $texte = $debut . $suite; |
|
| 1627 | + |
|
| 1628 | + if ($collecteurModeles) { |
|
| 1629 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + $texte = echappe_retour($texte); |
|
| 1633 | + |
|
| 1634 | + return $texte . $fin; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | |
@@ -1666,26 +1666,26 @@ discard block |
||
| 1666 | 1666 | **/ |
| 1667 | 1667 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1668 | 1668 | |
| 1669 | - if ($letexte && str_contains($letexte, '<:')) { |
|
| 1670 | - if (!$lang) { |
|
| 1671 | - $lang = $GLOBALS['spip_lang']; |
|
| 1672 | - } |
|
| 1673 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1674 | - if (is_bool($options)) { |
|
| 1675 | - $options = ['echappe_span' => $options]; |
|
| 1676 | - } |
|
| 1677 | - if (!isset($options['echappe_span'])) { |
|
| 1678 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1679 | - } |
|
| 1680 | - $options['lang'] = $lang; |
|
| 1669 | + if ($letexte && str_contains($letexte, '<:')) { |
|
| 1670 | + if (!$lang) { |
|
| 1671 | + $lang = $GLOBALS['spip_lang']; |
|
| 1672 | + } |
|
| 1673 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1674 | + if (is_bool($options)) { |
|
| 1675 | + $options = ['echappe_span' => $options]; |
|
| 1676 | + } |
|
| 1677 | + if (!isset($options['echappe_span'])) { |
|
| 1678 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1679 | + } |
|
| 1680 | + $options['lang'] = $lang; |
|
| 1681 | 1681 | |
| 1682 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1683 | - include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 1684 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1682 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1683 | + include_spip('src/Texte/Collecteur/Idiomes'); |
|
| 1684 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1685 | 1685 | |
| 1686 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1687 | - } |
|
| 1688 | - return $letexte; |
|
| 1686 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1687 | + } |
|
| 1688 | + return $letexte; |
|
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | /** |
@@ -1723,31 +1723,31 @@ discard block |
||
| 1723 | 1723 | **/ |
| 1724 | 1724 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1725 | 1725 | |
| 1726 | - if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1727 | - if (!$lang) { |
|
| 1728 | - $lang = $GLOBALS['spip_lang']; |
|
| 1729 | - } |
|
| 1726 | + if ($letexte && stripos($letexte, '<multi') !== false) { |
|
| 1727 | + if (!$lang) { |
|
| 1728 | + $lang = $GLOBALS['spip_lang']; |
|
| 1729 | + } |
|
| 1730 | 1730 | |
| 1731 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1732 | - if (is_bool($options)) { |
|
| 1733 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1734 | - } |
|
| 1735 | - if (!isset($options['echappe_span'])) { |
|
| 1736 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1737 | - } |
|
| 1738 | - if (!isset($options['lang_defaut'])) { |
|
| 1739 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1740 | - } |
|
| 1741 | - $options['lang'] = $lang; |
|
| 1731 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1732 | + if (is_bool($options)) { |
|
| 1733 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1734 | + } |
|
| 1735 | + if (!isset($options['echappe_span'])) { |
|
| 1736 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1737 | + } |
|
| 1738 | + if (!isset($options['lang_defaut'])) { |
|
| 1739 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1740 | + } |
|
| 1741 | + $options['lang'] = $lang; |
|
| 1742 | 1742 | |
| 1743 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1744 | - include_spip('src/Texte/Collecteur/Multis'); |
|
| 1745 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1743 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 1744 | + include_spip('src/Texte/Collecteur/Multis'); |
|
| 1745 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1746 | 1746 | |
| 1747 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1748 | - } |
|
| 1747 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1748 | + } |
|
| 1749 | 1749 | |
| 1750 | - return $letexte; |
|
| 1750 | + return $letexte; |
|
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | 1753 | /** |
@@ -1757,7 +1757,7 @@ discard block |
||
| 1757 | 1757 | * @return string L'initiale en majuscule |
| 1758 | 1758 | */ |
| 1759 | 1759 | function filtre_initiale($nom) { |
| 1760 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1760 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1761 | 1761 | } |
| 1762 | 1762 | |
| 1763 | 1763 | |
@@ -1802,33 +1802,33 @@ discard block |
||
| 1802 | 1802 | * - null (interne) : si on empile |
| 1803 | 1803 | **/ |
| 1804 | 1804 | function unique($donnee, $famille = '', $cpt = false) { |
| 1805 | - static $mem = []; |
|
| 1806 | - // permettre de vider la pile et de la restaurer |
|
| 1807 | - // pour le calcul de introduction... |
|
| 1808 | - if ($famille == '_spip_raz_') { |
|
| 1809 | - $tmp = $mem; |
|
| 1810 | - $mem = []; |
|
| 1811 | - |
|
| 1812 | - return $tmp; |
|
| 1813 | - } elseif ($famille == '_spip_set_') { |
|
| 1814 | - $mem = $donnee; |
|
| 1815 | - |
|
| 1816 | - return; |
|
| 1817 | - } |
|
| 1818 | - // eviter une notice |
|
| 1819 | - if (!isset($mem[$famille])) { |
|
| 1820 | - $mem[$famille] = []; |
|
| 1821 | - } |
|
| 1822 | - if ($cpt) { |
|
| 1823 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1824 | - } |
|
| 1825 | - // eviter une notice |
|
| 1826 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1827 | - $mem[$famille][$donnee] = 0; |
|
| 1828 | - } |
|
| 1829 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1830 | - return $donnee; |
|
| 1831 | - } |
|
| 1805 | + static $mem = []; |
|
| 1806 | + // permettre de vider la pile et de la restaurer |
|
| 1807 | + // pour le calcul de introduction... |
|
| 1808 | + if ($famille == '_spip_raz_') { |
|
| 1809 | + $tmp = $mem; |
|
| 1810 | + $mem = []; |
|
| 1811 | + |
|
| 1812 | + return $tmp; |
|
| 1813 | + } elseif ($famille == '_spip_set_') { |
|
| 1814 | + $mem = $donnee; |
|
| 1815 | + |
|
| 1816 | + return; |
|
| 1817 | + } |
|
| 1818 | + // eviter une notice |
|
| 1819 | + if (!isset($mem[$famille])) { |
|
| 1820 | + $mem[$famille] = []; |
|
| 1821 | + } |
|
| 1822 | + if ($cpt) { |
|
| 1823 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1824 | + } |
|
| 1825 | + // eviter une notice |
|
| 1826 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1827 | + $mem[$famille][$donnee] = 0; |
|
| 1828 | + } |
|
| 1829 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1830 | + return $donnee; |
|
| 1831 | + } |
|
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | |
@@ -1858,20 +1858,20 @@ discard block |
||
| 1858 | 1858 | * Une des valeurs en fonction du compteur. |
| 1859 | 1859 | **/ |
| 1860 | 1860 | function alterner($i, ...$args) { |
| 1861 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1862 | - $num = count($args); |
|
| 1861 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1862 | + $num = count($args); |
|
| 1863 | 1863 | |
| 1864 | - if ($num === 1 && is_array($args[0])) { |
|
| 1865 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1866 | - $args = array_values($args[0]); |
|
| 1867 | - $num = count($args); |
|
| 1868 | - } |
|
| 1864 | + if ($num === 1 && is_array($args[0])) { |
|
| 1865 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1866 | + $args = array_values($args[0]); |
|
| 1867 | + $num = count($args); |
|
| 1868 | + } |
|
| 1869 | 1869 | |
| 1870 | - // un index compris entre 0 et num exclus |
|
| 1871 | - $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1872 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1873 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | - return $args[$i]; |
|
| 1870 | + // un index compris entre 0 et num exclus |
|
| 1871 | + $i = (((int) $i - 1) % $num); // dans ]-$num;$num[ |
|
| 1872 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1873 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | + return $args[$i]; |
|
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | 1877 | |
@@ -1897,52 +1897,52 @@ discard block |
||
| 1897 | 1897 | * - null lorsque l’attribut n’existe pas. |
| 1898 | 1898 | **/ |
| 1899 | 1899 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1900 | - if (is_array($balise)) { |
|
| 1901 | - array_walk( |
|
| 1902 | - $balise, |
|
| 1903 | - function (&$a, $key, $t) { |
|
| 1904 | - $a = extraire_attribut($a, $t); |
|
| 1905 | - }, |
|
| 1906 | - $attribut |
|
| 1907 | - ); |
|
| 1908 | - |
|
| 1909 | - return $balise; |
|
| 1910 | - } |
|
| 1911 | - if ( |
|
| 1912 | - $balise |
|
| 1913 | - && stripos($balise, $attribut) !== false |
|
| 1914 | - && preg_match( |
|
| 1915 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1916 | - . $attribut |
|
| 1917 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1918 | - $balise, |
|
| 1919 | - $r |
|
| 1920 | - ) |
|
| 1921 | - ) { |
|
| 1922 | - if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1923 | - $r[4] = substr($r[3], 1, -1); |
|
| 1924 | - $r[3] = $r[3][0]; |
|
| 1925 | - } elseif ($r[3] !== '') { |
|
| 1926 | - $r[4] = $r[3]; |
|
| 1927 | - $r[3] = ''; |
|
| 1928 | - } else { |
|
| 1929 | - $r[4] = trim($r[2]); |
|
| 1930 | - } |
|
| 1931 | - $att = $r[4]; |
|
| 1932 | - if (str_contains($att, '&#')) { |
|
| 1933 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1934 | - } |
|
| 1935 | - $att = filtrer_entites($att); |
|
| 1936 | - } else { |
|
| 1937 | - $att = null; |
|
| 1938 | - $r = []; |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - if ($complet) { |
|
| 1942 | - return [$att, $r]; |
|
| 1943 | - } else { |
|
| 1944 | - return $att; |
|
| 1945 | - } |
|
| 1900 | + if (is_array($balise)) { |
|
| 1901 | + array_walk( |
|
| 1902 | + $balise, |
|
| 1903 | + function (&$a, $key, $t) { |
|
| 1904 | + $a = extraire_attribut($a, $t); |
|
| 1905 | + }, |
|
| 1906 | + $attribut |
|
| 1907 | + ); |
|
| 1908 | + |
|
| 1909 | + return $balise; |
|
| 1910 | + } |
|
| 1911 | + if ( |
|
| 1912 | + $balise |
|
| 1913 | + && stripos($balise, $attribut) !== false |
|
| 1914 | + && preg_match( |
|
| 1915 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1916 | + . $attribut |
|
| 1917 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1918 | + $balise, |
|
| 1919 | + $r |
|
| 1920 | + ) |
|
| 1921 | + ) { |
|
| 1922 | + if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1923 | + $r[4] = substr($r[3], 1, -1); |
|
| 1924 | + $r[3] = $r[3][0]; |
|
| 1925 | + } elseif ($r[3] !== '') { |
|
| 1926 | + $r[4] = $r[3]; |
|
| 1927 | + $r[3] = ''; |
|
| 1928 | + } else { |
|
| 1929 | + $r[4] = trim($r[2]); |
|
| 1930 | + } |
|
| 1931 | + $att = $r[4]; |
|
| 1932 | + if (str_contains($att, '&#')) { |
|
| 1933 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1934 | + } |
|
| 1935 | + $att = filtrer_entites($att); |
|
| 1936 | + } else { |
|
| 1937 | + $att = null; |
|
| 1938 | + $r = []; |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + if ($complet) { |
|
| 1942 | + return [$att, $r]; |
|
| 1943 | + } else { |
|
| 1944 | + return $att; |
|
| 1945 | + } |
|
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | /** |
@@ -1975,37 +1975,37 @@ discard block |
||
| 1975 | 1975 | **/ |
| 1976 | 1976 | function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string { |
| 1977 | 1977 | |
| 1978 | - if ($balise === null || $balise === '') { |
|
| 1979 | - return ''; |
|
| 1980 | - } |
|
| 1978 | + if ($balise === null || $balise === '') { |
|
| 1979 | + return ''; |
|
| 1980 | + } |
|
| 1981 | 1981 | |
| 1982 | - // preparer l'attribut |
|
| 1983 | - // supprimer les etc mais pas les balises html |
|
| 1984 | - // qui ont un sens dans un attribut value d'un input |
|
| 1985 | - if ($proteger) { |
|
| 1986 | - $val = attribut_html($val, false); |
|
| 1987 | - } |
|
| 1982 | + // preparer l'attribut |
|
| 1983 | + // supprimer les etc mais pas les balises html |
|
| 1984 | + // qui ont un sens dans un attribut value d'un input |
|
| 1985 | + if ($proteger) { |
|
| 1986 | + $val = attribut_html($val, false); |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - // echapper les ' pour eviter tout bug |
|
| 1990 | - $val = str_replace("'", ''', $val ?? ''); |
|
| 1991 | - $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1989 | + // echapper les ' pour eviter tout bug |
|
| 1990 | + $val = str_replace("'", ''', $val ?? ''); |
|
| 1991 | + $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'"; |
|
| 1992 | 1992 | |
| 1993 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1993 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 1994 | 1994 | |
| 1995 | - if ($old !== null) { |
|
| 1996 | - // Remplacer l'ancien attribut du meme nom |
|
| 1997 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1998 | - } else { |
|
| 1999 | - // preferer une balise " />" (comme <img />) |
|
| 2000 | - if (preg_match(',/>,', $balise)) { |
|
| 2001 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2002 | - } // sinon une balise <a ...> ... </a> |
|
| 2003 | - else { |
|
| 2004 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2005 | - } |
|
| 2006 | - } |
|
| 1995 | + if ($old !== null) { |
|
| 1996 | + // Remplacer l'ancien attribut du meme nom |
|
| 1997 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1998 | + } else { |
|
| 1999 | + // preferer une balise " />" (comme <img />) |
|
| 2000 | + if (preg_match(',/>,', $balise)) { |
|
| 2001 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2002 | + } // sinon une balise <a ...> ... </a> |
|
| 2003 | + else { |
|
| 2004 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2005 | + } |
|
| 2006 | + } |
|
| 2007 | 2007 | |
| 2008 | - return $balise; |
|
| 2008 | + return $balise; |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | /** |
@@ -2023,7 +2023,7 @@ discard block |
||
| 2023 | 2023 | * @return string Code HTML sans l'attribut |
| 2024 | 2024 | **/ |
| 2025 | 2025 | function vider_attribut(?string $balise, string $attribut): string { |
| 2026 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2026 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2027 | 2027 | } |
| 2028 | 2028 | |
| 2029 | 2029 | /** |
@@ -2035,50 +2035,50 @@ discard block |
||
| 2035 | 2035 | * @return string |
| 2036 | 2036 | */ |
| 2037 | 2037 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2038 | - if (is_string($class)) { |
|
| 2039 | - $class = explode(' ', trim($class)); |
|
| 2040 | - } |
|
| 2041 | - $class = array_filter($class); |
|
| 2042 | - $class = array_unique($class); |
|
| 2043 | - if (!$class) { |
|
| 2044 | - return $balise; |
|
| 2045 | - } |
|
| 2046 | - |
|
| 2047 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2048 | - $class_new = $class_courante; |
|
| 2049 | - foreach ($class as $c) { |
|
| 2050 | - $is_class_presente = false; |
|
| 2051 | - if ( |
|
| 2052 | - $class_courante |
|
| 2053 | - && str_contains($class_courante, (string) $c) |
|
| 2054 | - && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2055 | - ) { |
|
| 2056 | - $is_class_presente = true; |
|
| 2057 | - } |
|
| 2058 | - if ( |
|
| 2059 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2060 | - && !$is_class_presente |
|
| 2061 | - ) { |
|
| 2062 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2063 | - } elseif ( |
|
| 2064 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2065 | - && $is_class_presente |
|
| 2066 | - ) { |
|
| 2067 | - $class_new = preg_split(',\s+,', $class_new); |
|
| 2068 | - $class_new = array_diff($class_new, [$c]); |
|
| 2069 | - $class_new = implode(' ', $class_new); |
|
| 2070 | - } |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - if ($class_new !== $class_courante) { |
|
| 2074 | - if (strlen($class_new)) { |
|
| 2075 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2076 | - } elseif ($class_courante) { |
|
| 2077 | - $balise = vider_attribut($balise, 'class'); |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - return $balise; |
|
| 2038 | + if (is_string($class)) { |
|
| 2039 | + $class = explode(' ', trim($class)); |
|
| 2040 | + } |
|
| 2041 | + $class = array_filter($class); |
|
| 2042 | + $class = array_unique($class); |
|
| 2043 | + if (!$class) { |
|
| 2044 | + return $balise; |
|
| 2045 | + } |
|
| 2046 | + |
|
| 2047 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2048 | + $class_new = $class_courante; |
|
| 2049 | + foreach ($class as $c) { |
|
| 2050 | + $is_class_presente = false; |
|
| 2051 | + if ( |
|
| 2052 | + $class_courante |
|
| 2053 | + && str_contains($class_courante, (string) $c) |
|
| 2054 | + && in_array($c, preg_split(',\s+,', $class_courante)) |
|
| 2055 | + ) { |
|
| 2056 | + $is_class_presente = true; |
|
| 2057 | + } |
|
| 2058 | + if ( |
|
| 2059 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2060 | + && !$is_class_presente |
|
| 2061 | + ) { |
|
| 2062 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2063 | + } elseif ( |
|
| 2064 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2065 | + && $is_class_presente |
|
| 2066 | + ) { |
|
| 2067 | + $class_new = preg_split(',\s+,', $class_new); |
|
| 2068 | + $class_new = array_diff($class_new, [$c]); |
|
| 2069 | + $class_new = implode(' ', $class_new); |
|
| 2070 | + } |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + if ($class_new !== $class_courante) { |
|
| 2074 | + if (strlen($class_new)) { |
|
| 2075 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2076 | + } elseif ($class_courante) { |
|
| 2077 | + $balise = vider_attribut($balise, 'class'); |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + return $balise; |
|
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | 2084 | /** |
@@ -2088,7 +2088,7 @@ discard block |
||
| 2088 | 2088 | * @return string |
| 2089 | 2089 | */ |
| 2090 | 2090 | function ajouter_class($balise, $class) { |
| 2091 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2091 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2092 | 2092 | } |
| 2093 | 2093 | |
| 2094 | 2094 | /** |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | * @return string |
| 2099 | 2099 | */ |
| 2100 | 2100 | function supprimer_class($balise, $class) { |
| 2101 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2101 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | /** |
@@ -2109,7 +2109,7 @@ discard block |
||
| 2109 | 2109 | * @return string |
| 2110 | 2110 | */ |
| 2111 | 2111 | function commuter_class($balise, $class) { |
| 2112 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2112 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
@@ -2120,19 +2120,19 @@ discard block |
||
| 2120 | 2120 | * @return string |
| 2121 | 2121 | */ |
| 2122 | 2122 | function tester_config($id, $mode = '') { |
| 2123 | - include_spip('action/inscrire_auteur'); |
|
| 2123 | + include_spip('action/inscrire_auteur'); |
|
| 2124 | 2124 | |
| 2125 | - return tester_statut_inscription($mode, $id); |
|
| 2125 | + return tester_statut_inscription($mode, $id); |
|
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 2128 | 2128 | // |
| 2129 | 2129 | // Quelques fonctions de calcul arithmetique |
| 2130 | 2130 | // |
| 2131 | 2131 | function floatstr($a) { |
| 2132 | - return str_replace(',', '.', (string)(float) $a); |
|
| 2132 | + return str_replace(',', '.', (string)(float) $a); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | function strize($f, $a, $b) { |
| 2135 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2135 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | /** |
@@ -2151,11 +2151,11 @@ discard block |
||
| 2151 | 2151 | * @return int $a+$b |
| 2152 | 2152 | **/ |
| 2153 | 2153 | function plus($a, $b) { |
| 2154 | - return $a + $b; |
|
| 2154 | + return $a + $b; |
|
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | 2157 | function strplus($a, $b) { |
| 2158 | - return strize('plus', $a, $b); |
|
| 2158 | + return strize('plus', $a, $b); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2174,11 +2174,11 @@ discard block |
||
| 2174 | 2174 | * @return int $a-$b |
| 2175 | 2175 | **/ |
| 2176 | 2176 | function moins($a, $b) { |
| 2177 | - return $a - $b; |
|
| 2177 | + return $a - $b; |
|
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | function strmoins($a, $b) { |
| 2181 | - return strize('moins', $a, $b); |
|
| 2181 | + return strize('moins', $a, $b); |
|
| 2182 | 2182 | } |
| 2183 | 2183 | |
| 2184 | 2184 | /** |
@@ -2198,11 +2198,11 @@ discard block |
||
| 2198 | 2198 | * @return int $a*$b |
| 2199 | 2199 | **/ |
| 2200 | 2200 | function mult($a, $b) { |
| 2201 | - return $a * $b; |
|
| 2201 | + return $a * $b; |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | function strmult($a, $b) { |
| 2205 | - return strize('mult', $a, $b); |
|
| 2205 | + return strize('mult', $a, $b); |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | /** |
@@ -2222,11 +2222,11 @@ discard block |
||
| 2222 | 2222 | * @return int $a/$b (ou 0 si $b est nul) |
| 2223 | 2223 | **/ |
| 2224 | 2224 | function div($a, $b) { |
| 2225 | - return $b ? $a / $b : 0; |
|
| 2225 | + return $b ? $a / $b : 0; |
|
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | function strdiv($a, $b) { |
| 2229 | - return strize('div', $a, $b); |
|
| 2229 | + return strize('div', $a, $b); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2247,7 +2247,7 @@ discard block |
||
| 2247 | 2247 | * @return int ($nb % $mod) + $add |
| 2248 | 2248 | **/ |
| 2249 | 2249 | function modulo($nb, $mod, $add = 0) { |
| 2250 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2250 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | |
@@ -2262,26 +2262,26 @@ discard block |
||
| 2262 | 2262 | * - true sinon |
| 2263 | 2263 | **/ |
| 2264 | 2264 | function nom_acceptable($nom) { |
| 2265 | - $remp2 = []; |
|
| 2266 | - $remp1 = []; |
|
| 2267 | - if (!is_string($nom)) { |
|
| 2268 | - return false; |
|
| 2269 | - } |
|
| 2270 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2271 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2272 | - } |
|
| 2273 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2274 | - foreach ($tags_acceptes as $tag) { |
|
| 2275 | - if (strlen($tag)) { |
|
| 2276 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2280 | - } |
|
| 2281 | - } |
|
| 2282 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2283 | - |
|
| 2284 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2265 | + $remp2 = []; |
|
| 2266 | + $remp1 = []; |
|
| 2267 | + if (!is_string($nom)) { |
|
| 2268 | + return false; |
|
| 2269 | + } |
|
| 2270 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2271 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2272 | + } |
|
| 2273 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2274 | + foreach ($tags_acceptes as $tag) { |
|
| 2275 | + if (strlen($tag)) { |
|
| 2276 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2280 | + } |
|
| 2281 | + } |
|
| 2282 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2283 | + |
|
| 2284 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | |
@@ -2297,13 +2297,13 @@ discard block |
||
| 2297 | 2297 | * - renvoie un tableau si l'entree est un tableau |
| 2298 | 2298 | **/ |
| 2299 | 2299 | function email_valide($adresses) { |
| 2300 | - if (is_array($adresses)) { |
|
| 2301 | - $adresses = array_map('email_valide', $adresses); |
|
| 2302 | - return array_filter($adresses); |
|
| 2303 | - } |
|
| 2300 | + if (is_array($adresses)) { |
|
| 2301 | + $adresses = array_map('email_valide', $adresses); |
|
| 2302 | + return array_filter($adresses); |
|
| 2303 | + } |
|
| 2304 | 2304 | |
| 2305 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2306 | - return $email_valide($adresses); |
|
| 2305 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2306 | + return $email_valide($adresses); |
|
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | /** |
@@ -2317,29 +2317,29 @@ discard block |
||
| 2317 | 2317 | * @return string texte |
| 2318 | 2318 | **/ |
| 2319 | 2319 | function afficher_enclosures($tags) { |
| 2320 | - $s = []; |
|
| 2321 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2322 | - if ( |
|
| 2323 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2324 | - && ($t = extraire_attribut($tag, 'href')) |
|
| 2325 | - ) { |
|
| 2326 | - $s[] = preg_replace( |
|
| 2327 | - ',>[^<]+</a>,S', |
|
| 2328 | - '>' |
|
| 2329 | - . http_img_pack( |
|
| 2330 | - 'attachment-16.png', |
|
| 2331 | - $t, |
|
| 2332 | - '', |
|
| 2333 | - $t, |
|
| 2334 | - ['utiliser_suffixe_size' => true] |
|
| 2335 | - ) |
|
| 2336 | - . '</a>', |
|
| 2337 | - $tag |
|
| 2338 | - ); |
|
| 2339 | - } |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - return implode(' ', $s); |
|
| 2320 | + $s = []; |
|
| 2321 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2322 | + if ( |
|
| 2323 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2324 | + && ($t = extraire_attribut($tag, 'href')) |
|
| 2325 | + ) { |
|
| 2326 | + $s[] = preg_replace( |
|
| 2327 | + ',>[^<]+</a>,S', |
|
| 2328 | + '>' |
|
| 2329 | + . http_img_pack( |
|
| 2330 | + 'attachment-16.png', |
|
| 2331 | + $t, |
|
| 2332 | + '', |
|
| 2333 | + $t, |
|
| 2334 | + ['utiliser_suffixe_size' => true] |
|
| 2335 | + ) |
|
| 2336 | + . '</a>', |
|
| 2337 | + $tag |
|
| 2338 | + ); |
|
| 2339 | + } |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + return implode(' ', $s); |
|
| 2343 | 2343 | } |
| 2344 | 2344 | |
| 2345 | 2345 | /** |
@@ -2354,15 +2354,15 @@ discard block |
||
| 2354 | 2354 | * @return string Liens trouvés |
| 2355 | 2355 | **/ |
| 2356 | 2356 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2357 | - $s = []; |
|
| 2358 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2359 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2360 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2361 | - $s[] = $tag; |
|
| 2362 | - } |
|
| 2363 | - } |
|
| 2357 | + $s = []; |
|
| 2358 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2359 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2360 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2361 | + $s[] = $tag; |
|
| 2362 | + } |
|
| 2363 | + } |
|
| 2364 | 2364 | |
| 2365 | - return implode(', ', $s); |
|
| 2365 | + return implode(', ', $s); |
|
| 2366 | 2366 | } |
| 2367 | 2367 | |
| 2368 | 2368 | |
@@ -2384,21 +2384,21 @@ discard block |
||
| 2384 | 2384 | * @return string Tag HTML `<a>` avec microformat. |
| 2385 | 2385 | **/ |
| 2386 | 2386 | function enclosure2microformat($e) { |
| 2387 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2388 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2389 | - } |
|
| 2390 | - $type = extraire_attribut($e, 'type'); |
|
| 2391 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2392 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2393 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2394 | - } |
|
| 2395 | - $fichier = basename($url); |
|
| 2387 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2388 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2389 | + } |
|
| 2390 | + $type = extraire_attribut($e, 'type'); |
|
| 2391 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2392 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2393 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2394 | + } |
|
| 2395 | + $fichier = basename($url); |
|
| 2396 | 2396 | |
| 2397 | - return '<a rel="enclosure"' |
|
| 2398 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | - . '>' . $fichier . '</a>'; |
|
| 2397 | + return '<a rel="enclosure"' |
|
| 2398 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | + . '>' . $fichier . '</a>'; |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2416,24 +2416,24 @@ discard block |
||
| 2416 | 2416 | * @return string Tags RSS `<enclosure>`. |
| 2417 | 2417 | **/ |
| 2418 | 2418 | function microformat2enclosure($tags) { |
| 2419 | - $enclosures = []; |
|
| 2420 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2421 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2422 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2423 | - $type = extraire_attribut($e, 'type'); |
|
| 2424 | - if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2425 | - $length = (int) extraire_attribut($e, 'length'); |
|
| 2426 | - } # vieux data |
|
| 2427 | - $fichier = basename($url); |
|
| 2428 | - $enclosures[] = '<enclosure' |
|
| 2429 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2432 | - . ' />'; |
|
| 2433 | - } |
|
| 2434 | - } |
|
| 2419 | + $enclosures = []; |
|
| 2420 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2421 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2422 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2423 | + $type = extraire_attribut($e, 'type'); |
|
| 2424 | + if (!$length = (int) extraire_attribut($e, 'title')) { |
|
| 2425 | + $length = (int) extraire_attribut($e, 'length'); |
|
| 2426 | + } # vieux data |
|
| 2427 | + $fichier = basename($url); |
|
| 2428 | + $enclosures[] = '<enclosure' |
|
| 2429 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2432 | + . ' />'; |
|
| 2433 | + } |
|
| 2434 | + } |
|
| 2435 | 2435 | |
| 2436 | - return implode("\n", $enclosures); |
|
| 2436 | + return implode("\n", $enclosures); |
|
| 2437 | 2437 | } |
| 2438 | 2438 | |
| 2439 | 2439 | |
@@ -2449,16 +2449,16 @@ discard block |
||
| 2449 | 2449 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2450 | 2450 | **/ |
| 2451 | 2451 | function tags2dcsubject($tags) { |
| 2452 | - $subjects = ''; |
|
| 2453 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2454 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2455 | - $subjects .= '<dc:subject>' |
|
| 2456 | - . texte_backend(textebrut($e)) |
|
| 2457 | - . '</dc:subject>' . "\n"; |
|
| 2458 | - } |
|
| 2459 | - } |
|
| 2452 | + $subjects = ''; |
|
| 2453 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2454 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2455 | + $subjects .= '<dc:subject>' |
|
| 2456 | + . texte_backend(textebrut($e)) |
|
| 2457 | + . '</dc:subject>' . "\n"; |
|
| 2458 | + } |
|
| 2459 | + } |
|
| 2460 | 2460 | |
| 2461 | - return $subjects; |
|
| 2461 | + return $subjects; |
|
| 2462 | 2462 | } |
| 2463 | 2463 | |
| 2464 | 2464 | /** |
@@ -2487,27 +2487,27 @@ discard block |
||
| 2487 | 2487 | * - Tableau de résultats, si tableau en entrée. |
| 2488 | 2488 | **/ |
| 2489 | 2489 | function extraire_balise($texte, $tag = 'a') { |
| 2490 | - if (is_array($texte)) { |
|
| 2491 | - array_walk( |
|
| 2492 | - $texte, |
|
| 2493 | - function (&$a, $key, $t) { |
|
| 2494 | - $a = extraire_balise($a, $t); |
|
| 2495 | - }, |
|
| 2496 | - $tag |
|
| 2497 | - ); |
|
| 2498 | - |
|
| 2499 | - return $texte; |
|
| 2500 | - } |
|
| 2501 | - |
|
| 2502 | - if ( |
|
| 2503 | - preg_match( |
|
| 2504 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2505 | - $texte, |
|
| 2506 | - $regs |
|
| 2507 | - ) |
|
| 2508 | - ) { |
|
| 2509 | - return $regs[0]; |
|
| 2510 | - } |
|
| 2490 | + if (is_array($texte)) { |
|
| 2491 | + array_walk( |
|
| 2492 | + $texte, |
|
| 2493 | + function (&$a, $key, $t) { |
|
| 2494 | + $a = extraire_balise($a, $t); |
|
| 2495 | + }, |
|
| 2496 | + $tag |
|
| 2497 | + ); |
|
| 2498 | + |
|
| 2499 | + return $texte; |
|
| 2500 | + } |
|
| 2501 | + |
|
| 2502 | + if ( |
|
| 2503 | + preg_match( |
|
| 2504 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2505 | + $texte, |
|
| 2506 | + $regs |
|
| 2507 | + ) |
|
| 2508 | + ) { |
|
| 2509 | + return $regs[0]; |
|
| 2510 | + } |
|
| 2511 | 2511 | } |
| 2512 | 2512 | |
| 2513 | 2513 | /** |
@@ -2535,30 +2535,30 @@ discard block |
||
| 2535 | 2535 | * - Tableau de résultats, si tableau en entrée. |
| 2536 | 2536 | **/ |
| 2537 | 2537 | function extraire_balises($texte, $tag = 'a') { |
| 2538 | - if (is_array($texte)) { |
|
| 2539 | - array_walk( |
|
| 2540 | - $texte, |
|
| 2541 | - function (&$a, $key, $t) { |
|
| 2542 | - $a = extraire_balises($a, $t); |
|
| 2543 | - }, |
|
| 2544 | - $tag |
|
| 2545 | - ); |
|
| 2546 | - |
|
| 2547 | - return $texte; |
|
| 2548 | - } |
|
| 2549 | - |
|
| 2550 | - if ( |
|
| 2551 | - preg_match_all( |
|
| 2552 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2553 | - $texte, |
|
| 2554 | - $regs, |
|
| 2555 | - PREG_PATTERN_ORDER |
|
| 2556 | - ) |
|
| 2557 | - ) { |
|
| 2558 | - return $regs[0]; |
|
| 2559 | - } else { |
|
| 2560 | - return []; |
|
| 2561 | - } |
|
| 2538 | + if (is_array($texte)) { |
|
| 2539 | + array_walk( |
|
| 2540 | + $texte, |
|
| 2541 | + function (&$a, $key, $t) { |
|
| 2542 | + $a = extraire_balises($a, $t); |
|
| 2543 | + }, |
|
| 2544 | + $tag |
|
| 2545 | + ); |
|
| 2546 | + |
|
| 2547 | + return $texte; |
|
| 2548 | + } |
|
| 2549 | + |
|
| 2550 | + if ( |
|
| 2551 | + preg_match_all( |
|
| 2552 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2553 | + $texte, |
|
| 2554 | + $regs, |
|
| 2555 | + PREG_PATTERN_ORDER |
|
| 2556 | + ) |
|
| 2557 | + ) { |
|
| 2558 | + return $regs[0]; |
|
| 2559 | + } else { |
|
| 2560 | + return []; |
|
| 2561 | + } |
|
| 2562 | 2562 | } |
| 2563 | 2563 | |
| 2564 | 2564 | /** |
@@ -2587,11 +2587,11 @@ discard block |
||
| 2587 | 2587 | * - `$def` si on n'a pas transmis de tableau |
| 2588 | 2588 | **/ |
| 2589 | 2589 | function in_any($val, $vals, $def = '') { |
| 2590 | - if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2591 | - $vals = $v; |
|
| 2592 | - } |
|
| 2590 | + if (!is_array($vals) && $vals && ($v = unserialize($vals))) { |
|
| 2591 | + $vals = $v; |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | - return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2594 | + return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def)); |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | |
@@ -2612,12 +2612,12 @@ discard block |
||
| 2612 | 2612 | * Résultat du calcul |
| 2613 | 2613 | **/ |
| 2614 | 2614 | function valeur_numerique($expr) { |
| 2615 | - $a = 0; |
|
| 2616 | - if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2617 | - eval("\$a = $expr;"); |
|
| 2618 | - } |
|
| 2615 | + $a = 0; |
|
| 2616 | + if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) { |
|
| 2617 | + eval("\$a = $expr;"); |
|
| 2618 | + } |
|
| 2619 | 2619 | |
| 2620 | - return (int) $a; |
|
| 2620 | + return (int) $a; |
|
| 2621 | 2621 | } |
| 2622 | 2622 | |
| 2623 | 2623 | /** |
@@ -2636,7 +2636,7 @@ discard block |
||
| 2636 | 2636 | * Retourne `$a*$b/$c` |
| 2637 | 2637 | **/ |
| 2638 | 2638 | function regledetrois($a, $b, $c) { |
| 2639 | - return round($a * $b / $c); |
|
| 2639 | + return round($a * $b / $c); |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | |
@@ -2659,79 +2659,79 @@ discard block |
||
| 2659 | 2659 | * @return string Suite de champs input hidden |
| 2660 | 2660 | **/ |
| 2661 | 2661 | function form_hidden(?string $action = ''): string { |
| 2662 | - $action ??= ''; |
|
| 2663 | - |
|
| 2664 | - $contexte = []; |
|
| 2665 | - include_spip('inc/urls'); |
|
| 2666 | - if ( |
|
| 2667 | - ($p = urls_decoder_url($action, '')) |
|
| 2668 | - && reset($p) |
|
| 2669 | - ) { |
|
| 2670 | - $fond = array_shift($p); |
|
| 2671 | - if ($fond != '404') { |
|
| 2672 | - $contexte = array_shift($p); |
|
| 2673 | - $contexte['page'] = $fond; |
|
| 2674 | - $action = preg_replace('/([?]' . preg_quote($fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | - } |
|
| 2676 | - } |
|
| 2677 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2678 | - if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2679 | - unset($contexte['type']); |
|
| 2680 | - } |
|
| 2681 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2682 | - unset($contexte['type-page']); |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2686 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2687 | - $values = []; |
|
| 2688 | - |
|
| 2689 | - // d'abord avec celles de l'url |
|
| 2690 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2691 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2692 | - $c = explode('=', $c, 2); |
|
| 2693 | - $var = array_shift($c); |
|
| 2694 | - $val = array_shift($c) ?? ''; |
|
| 2695 | - if ($var) { |
|
| 2696 | - $val = rawurldecode($val); |
|
| 2697 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2698 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2699 | - $values[] = [$var, $val]; |
|
| 2700 | - } else { |
|
| 2701 | - if (!isset($values[$var])) { |
|
| 2702 | - $values[$var] = [$var, $val]; |
|
| 2703 | - } |
|
| 2704 | - } |
|
| 2705 | - } |
|
| 2706 | - } |
|
| 2707 | - } |
|
| 2708 | - |
|
| 2709 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2710 | - foreach ($contexte as $var => $val) { |
|
| 2711 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2712 | - $values[] = [$var, $val]; |
|
| 2713 | - } else { |
|
| 2714 | - if (!isset($values[$var])) { |
|
| 2715 | - $values[$var] = [$var, $val]; |
|
| 2716 | - } |
|
| 2717 | - } |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - // puis on rassemble le tout |
|
| 2721 | - $hidden = []; |
|
| 2722 | - foreach ($values as $value) { |
|
| 2723 | - [$var, $val] = $value; |
|
| 2724 | - $hidden[] = '<input name="' |
|
| 2725 | - . entites_html($var) |
|
| 2726 | - . '"' |
|
| 2727 | - . (is_null($val) |
|
| 2728 | - ? '' |
|
| 2729 | - : ' value="' . entites_html($val) . '"' |
|
| 2730 | - ) |
|
| 2731 | - . ' type="hidden"' . "\n/>"; |
|
| 2732 | - } |
|
| 2733 | - |
|
| 2734 | - return implode('', $hidden); |
|
| 2662 | + $action ??= ''; |
|
| 2663 | + |
|
| 2664 | + $contexte = []; |
|
| 2665 | + include_spip('inc/urls'); |
|
| 2666 | + if ( |
|
| 2667 | + ($p = urls_decoder_url($action, '')) |
|
| 2668 | + && reset($p) |
|
| 2669 | + ) { |
|
| 2670 | + $fond = array_shift($p); |
|
| 2671 | + if ($fond != '404') { |
|
| 2672 | + $contexte = array_shift($p); |
|
| 2673 | + $contexte['page'] = $fond; |
|
| 2674 | + $action = preg_replace('/([?]' . preg_quote($fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | + } |
|
| 2676 | + } |
|
| 2677 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2678 | + if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) { |
|
| 2679 | + unset($contexte['type']); |
|
| 2680 | + } |
|
| 2681 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2682 | + unset($contexte['type-page']); |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2686 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2687 | + $values = []; |
|
| 2688 | + |
|
| 2689 | + // d'abord avec celles de l'url |
|
| 2690 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2691 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2692 | + $c = explode('=', $c, 2); |
|
| 2693 | + $var = array_shift($c); |
|
| 2694 | + $val = array_shift($c) ?? ''; |
|
| 2695 | + if ($var) { |
|
| 2696 | + $val = rawurldecode($val); |
|
| 2697 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2698 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2699 | + $values[] = [$var, $val]; |
|
| 2700 | + } else { |
|
| 2701 | + if (!isset($values[$var])) { |
|
| 2702 | + $values[$var] = [$var, $val]; |
|
| 2703 | + } |
|
| 2704 | + } |
|
| 2705 | + } |
|
| 2706 | + } |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2710 | + foreach ($contexte as $var => $val) { |
|
| 2711 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2712 | + $values[] = [$var, $val]; |
|
| 2713 | + } else { |
|
| 2714 | + if (!isset($values[$var])) { |
|
| 2715 | + $values[$var] = [$var, $val]; |
|
| 2716 | + } |
|
| 2717 | + } |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + // puis on rassemble le tout |
|
| 2721 | + $hidden = []; |
|
| 2722 | + foreach ($values as $value) { |
|
| 2723 | + [$var, $val] = $value; |
|
| 2724 | + $hidden[] = '<input name="' |
|
| 2725 | + . entites_html($var) |
|
| 2726 | + . '"' |
|
| 2727 | + . (is_null($val) |
|
| 2728 | + ? '' |
|
| 2729 | + : ' value="' . entites_html($val) . '"' |
|
| 2730 | + ) |
|
| 2731 | + . ' type="hidden"' . "\n/>"; |
|
| 2732 | + } |
|
| 2733 | + |
|
| 2734 | + return implode('', $hidden); |
|
| 2735 | 2735 | } |
| 2736 | 2736 | |
| 2737 | 2737 | |
@@ -2753,7 +2753,7 @@ discard block |
||
| 2753 | 2753 | * - la première valeur du tableau sinon. |
| 2754 | 2754 | **/ |
| 2755 | 2755 | function filtre_reset($array) { |
| 2756 | - return is_array($array) ? reset($array) : null; |
|
| 2756 | + return is_array($array) ? reset($array) : null; |
|
| 2757 | 2757 | } |
| 2758 | 2758 | |
| 2759 | 2759 | /** |
@@ -2774,7 +2774,7 @@ discard block |
||
| 2774 | 2774 | * - la dernière valeur du tableau sinon. |
| 2775 | 2775 | **/ |
| 2776 | 2776 | function filtre_end($array) { |
| 2777 | - return is_array($array) ? end($array) : null; |
|
| 2777 | + return is_array($array) ? end($array) : null; |
|
| 2778 | 2778 | } |
| 2779 | 2779 | |
| 2780 | 2780 | /** |
@@ -2794,11 +2794,11 @@ discard block |
||
| 2794 | 2794 | * |
| 2795 | 2795 | **/ |
| 2796 | 2796 | function filtre_push($array, mixed $val) { |
| 2797 | - if (!is_array($array) || !array_push($array, $val)) { |
|
| 2798 | - return ''; |
|
| 2799 | - } |
|
| 2797 | + if (!is_array($array) || !array_push($array, $val)) { |
|
| 2798 | + return ''; |
|
| 2799 | + } |
|
| 2800 | 2800 | |
| 2801 | - return $array; |
|
| 2801 | + return $array; |
|
| 2802 | 2802 | } |
| 2803 | 2803 | |
| 2804 | 2804 | /** |
@@ -2817,7 +2817,7 @@ discard block |
||
| 2817 | 2817 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2818 | 2818 | **/ |
| 2819 | 2819 | function filtre_find($array, mixed $val) { |
| 2820 | - return (is_array($array) && in_array($val, $array)); |
|
| 2820 | + return (is_array($array) && in_array($val, $array)); |
|
| 2821 | 2821 | } |
| 2822 | 2822 | |
| 2823 | 2823 | |
@@ -2834,13 +2834,13 @@ discard block |
||
| 2834 | 2834 | * Contenu avec urls en absolus |
| 2835 | 2835 | **/ |
| 2836 | 2836 | function urls_absolues_css($contenu, $source) { |
| 2837 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2837 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2838 | 2838 | |
| 2839 | - return preg_replace_callback( |
|
| 2840 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2841 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2842 | - $contenu |
|
| 2843 | - ); |
|
| 2839 | + return preg_replace_callback( |
|
| 2840 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2841 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2842 | + $contenu |
|
| 2843 | + ); |
|
| 2844 | 2844 | } |
| 2845 | 2845 | |
| 2846 | 2846 | |
@@ -2869,120 +2869,120 @@ discard block |
||
| 2869 | 2869 | * Chemin du fichier CSS inversé |
| 2870 | 2870 | **/ |
| 2871 | 2871 | function direction_css($css, $voulue = '') { |
| 2872 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2873 | - return $css; |
|
| 2874 | - } |
|
| 2875 | - include_spip('inc/lang'); |
|
| 2876 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2877 | - if ($voulue = strtolower($voulue)) { |
|
| 2878 | - if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2879 | - $voulue = lang_dir($voulue); |
|
| 2880 | - } |
|
| 2881 | - } else { |
|
| 2882 | - $voulue = lang_dir(); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - $r = count($r) > 1; |
|
| 2886 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2887 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2888 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2889 | - |
|
| 2890 | - if ($voulue == $dir) { |
|
| 2891 | - return $css; |
|
| 2892 | - } |
|
| 2893 | - |
|
| 2894 | - if ( |
|
| 2895 | - // url absolue |
|
| 2896 | - preg_match(',^https?:,i', $css) |
|
| 2897 | - // ou qui contient un ? |
|
| 2898 | - || ($p = strpos($css, '?')) !== false |
|
| 2899 | - ) { |
|
| 2900 | - $distant = true; |
|
| 2901 | - $cssf = parse_url($css); |
|
| 2902 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2903 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2904 | - } else { |
|
| 2905 | - $distant = false; |
|
| 2906 | - $cssf = $css; |
|
| 2907 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2908 | - //propose (rien a faire dans ce cas) |
|
| 2909 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2910 | - if (@file_exists($f)) { |
|
| 2911 | - return $f; |
|
| 2912 | - } |
|
| 2913 | - } |
|
| 2914 | - |
|
| 2915 | - // 2. |
|
| 2916 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2917 | - $f = $dir_var |
|
| 2918 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2919 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2920 | - |
|
| 2921 | - // la css peut etre distante (url absolue !) |
|
| 2922 | - $contenu = null; |
|
| 2923 | - if ($distant) { |
|
| 2924 | - include_spip('inc/distant'); |
|
| 2925 | - $res = recuperer_url($css); |
|
| 2926 | - if (!$res || !($contenu = $res['page'])) { |
|
| 2927 | - return $css; |
|
| 2928 | - } |
|
| 2929 | - } else { |
|
| 2930 | - if ( |
|
| 2931 | - @filemtime($f) > @filemtime($css) |
|
| 2932 | - && _VAR_MODE != 'recalcul' |
|
| 2933 | - ) { |
|
| 2934 | - return $f; |
|
| 2935 | - } |
|
| 2936 | - if (!lire_fichier($css, $contenu)) { |
|
| 2937 | - return $css; |
|
| 2938 | - } |
|
| 2939 | - } |
|
| 2940 | - |
|
| 2941 | - |
|
| 2942 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2943 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2944 | - $parser = new csstidy(); |
|
| 2945 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2946 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2947 | - $parser->parse($contenu); |
|
| 2948 | - |
|
| 2949 | - $contenu = $parser->print->plain(); |
|
| 2950 | - |
|
| 2951 | - |
|
| 2952 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2953 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2954 | - $src = []; |
|
| 2955 | - $src_direction_css = []; |
|
| 2956 | - $src_faux_abs = []; |
|
| 2957 | - $d = dirname($css); |
|
| 2958 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2959 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2960 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2961 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2962 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2963 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2964 | - elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2965 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2966 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2968 | - } |
|
| 2969 | - $src[] = $regs[0][$k]; |
|
| 2970 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2971 | - } |
|
| 2972 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2973 | - |
|
| 2974 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2975 | - |
|
| 2976 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2977 | - if ($src_faux_abs !== []) { |
|
| 2978 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2979 | - } |
|
| 2980 | - |
|
| 2981 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2982 | - return $css; |
|
| 2983 | - } |
|
| 2984 | - |
|
| 2985 | - return $f; |
|
| 2872 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2873 | + return $css; |
|
| 2874 | + } |
|
| 2875 | + include_spip('inc/lang'); |
|
| 2876 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2877 | + if ($voulue = strtolower($voulue)) { |
|
| 2878 | + if ($voulue != 'rtl' && $voulue != 'ltr') { |
|
| 2879 | + $voulue = lang_dir($voulue); |
|
| 2880 | + } |
|
| 2881 | + } else { |
|
| 2882 | + $voulue = lang_dir(); |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + $r = count($r) > 1; |
|
| 2886 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2887 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2888 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2889 | + |
|
| 2890 | + if ($voulue == $dir) { |
|
| 2891 | + return $css; |
|
| 2892 | + } |
|
| 2893 | + |
|
| 2894 | + if ( |
|
| 2895 | + // url absolue |
|
| 2896 | + preg_match(',^https?:,i', $css) |
|
| 2897 | + // ou qui contient un ? |
|
| 2898 | + || ($p = strpos($css, '?')) !== false |
|
| 2899 | + ) { |
|
| 2900 | + $distant = true; |
|
| 2901 | + $cssf = parse_url($css); |
|
| 2902 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2903 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2904 | + } else { |
|
| 2905 | + $distant = false; |
|
| 2906 | + $cssf = $css; |
|
| 2907 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2908 | + //propose (rien a faire dans ce cas) |
|
| 2909 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2910 | + if (@file_exists($f)) { |
|
| 2911 | + return $f; |
|
| 2912 | + } |
|
| 2913 | + } |
|
| 2914 | + |
|
| 2915 | + // 2. |
|
| 2916 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2917 | + $f = $dir_var |
|
| 2918 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2919 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2920 | + |
|
| 2921 | + // la css peut etre distante (url absolue !) |
|
| 2922 | + $contenu = null; |
|
| 2923 | + if ($distant) { |
|
| 2924 | + include_spip('inc/distant'); |
|
| 2925 | + $res = recuperer_url($css); |
|
| 2926 | + if (!$res || !($contenu = $res['page'])) { |
|
| 2927 | + return $css; |
|
| 2928 | + } |
|
| 2929 | + } else { |
|
| 2930 | + if ( |
|
| 2931 | + @filemtime($f) > @filemtime($css) |
|
| 2932 | + && _VAR_MODE != 'recalcul' |
|
| 2933 | + ) { |
|
| 2934 | + return $f; |
|
| 2935 | + } |
|
| 2936 | + if (!lire_fichier($css, $contenu)) { |
|
| 2937 | + return $css; |
|
| 2938 | + } |
|
| 2939 | + } |
|
| 2940 | + |
|
| 2941 | + |
|
| 2942 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2943 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2944 | + $parser = new csstidy(); |
|
| 2945 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2946 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2947 | + $parser->parse($contenu); |
|
| 2948 | + |
|
| 2949 | + $contenu = $parser->print->plain(); |
|
| 2950 | + |
|
| 2951 | + |
|
| 2952 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2953 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2954 | + $src = []; |
|
| 2955 | + $src_direction_css = []; |
|
| 2956 | + $src_faux_abs = []; |
|
| 2957 | + $d = dirname($css); |
|
| 2958 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2959 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2960 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2961 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2962 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2963 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2964 | + elseif (str_starts_with($css_direction, $dir_var)) { |
|
| 2965 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2966 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2968 | + } |
|
| 2969 | + $src[] = $regs[0][$k]; |
|
| 2970 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2971 | + } |
|
| 2972 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2973 | + |
|
| 2974 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2975 | + |
|
| 2976 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2977 | + if ($src_faux_abs !== []) { |
|
| 2978 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2979 | + } |
|
| 2980 | + |
|
| 2981 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2982 | + return $css; |
|
| 2983 | + } |
|
| 2984 | + |
|
| 2985 | + return $f; |
|
| 2986 | 2986 | } |
| 2987 | 2987 | |
| 2988 | 2988 | |
@@ -3005,47 +3005,47 @@ discard block |
||
| 3005 | 3005 | * - Chemin ou URL du fichier CSS source sinon. |
| 3006 | 3006 | **/ |
| 3007 | 3007 | function url_absolue_css($css) { |
| 3008 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3009 | - return $css; |
|
| 3010 | - } |
|
| 3008 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3009 | + return $css; |
|
| 3010 | + } |
|
| 3011 | 3011 | |
| 3012 | - $url_absolue_css = url_absolue($css); |
|
| 3012 | + $url_absolue_css = url_absolue($css); |
|
| 3013 | 3013 | |
| 3014 | - $f = basename($css, '.css'); |
|
| 3015 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3016 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3017 | - . '.css'; |
|
| 3014 | + $f = basename($css, '.css'); |
|
| 3015 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3016 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3017 | + . '.css'; |
|
| 3018 | 3018 | |
| 3019 | - if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 3020 | - return $f; |
|
| 3021 | - } |
|
| 3019 | + if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
|
| 3020 | + return $f; |
|
| 3021 | + } |
|
| 3022 | 3022 | |
| 3023 | - $contenu = null; |
|
| 3024 | - if ($url_absolue_css == $css) { |
|
| 3025 | - if ( |
|
| 3026 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3027 | - || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3028 | - ) { |
|
| 3029 | - include_spip('inc/distant'); |
|
| 3030 | - $contenu = recuperer_url($css); |
|
| 3031 | - $contenu = $contenu['page'] ?? ''; |
|
| 3032 | - if (!$contenu) { |
|
| 3033 | - return $css; |
|
| 3034 | - } |
|
| 3035 | - } |
|
| 3036 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3037 | - return $css; |
|
| 3038 | - } |
|
| 3023 | + $contenu = null; |
|
| 3024 | + if ($url_absolue_css == $css) { |
|
| 3025 | + if ( |
|
| 3026 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3027 | + || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3028 | + ) { |
|
| 3029 | + include_spip('inc/distant'); |
|
| 3030 | + $contenu = recuperer_url($css); |
|
| 3031 | + $contenu = $contenu['page'] ?? ''; |
|
| 3032 | + if (!$contenu) { |
|
| 3033 | + return $css; |
|
| 3034 | + } |
|
| 3035 | + } |
|
| 3036 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3037 | + return $css; |
|
| 3038 | + } |
|
| 3039 | 3039 | |
| 3040 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3041 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3040 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3041 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3042 | 3042 | |
| 3043 | - // ecrire la css |
|
| 3044 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3045 | - return $css; |
|
| 3046 | - } |
|
| 3043 | + // ecrire la css |
|
| 3044 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3045 | + return $css; |
|
| 3046 | + } |
|
| 3047 | 3047 | |
| 3048 | - return $f; |
|
| 3048 | + return $f; |
|
| 3049 | 3049 | } |
| 3050 | 3050 | |
| 3051 | 3051 | |
@@ -3079,24 +3079,24 @@ discard block |
||
| 3079 | 3079 | * Valeur trouvée ou valeur par défaut. |
| 3080 | 3080 | **/ |
| 3081 | 3081 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3082 | - foreach (explode('/', $cle) as $k) { |
|
| 3083 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3082 | + foreach (explode('/', $cle) as $k) { |
|
| 3083 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3084 | 3084 | |
| 3085 | - if (is_object($table)) { |
|
| 3086 | - $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3087 | - } elseif (is_array($table)) { |
|
| 3088 | - if ($conserver_null) { |
|
| 3089 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3090 | - } else { |
|
| 3091 | - $table = ($table[$k] ?? $defaut); |
|
| 3092 | - } |
|
| 3093 | - } else { |
|
| 3094 | - $table = $defaut; |
|
| 3095 | - break; |
|
| 3096 | - } |
|
| 3097 | - } |
|
| 3085 | + if (is_object($table)) { |
|
| 3086 | + $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut; |
|
| 3087 | + } elseif (is_array($table)) { |
|
| 3088 | + if ($conserver_null) { |
|
| 3089 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3090 | + } else { |
|
| 3091 | + $table = ($table[$k] ?? $defaut); |
|
| 3092 | + } |
|
| 3093 | + } else { |
|
| 3094 | + $table = $defaut; |
|
| 3095 | + break; |
|
| 3096 | + } |
|
| 3097 | + } |
|
| 3098 | 3098 | |
| 3099 | - return $table; |
|
| 3099 | + return $table; |
|
| 3100 | 3100 | } |
| 3101 | 3101 | |
| 3102 | 3102 | /** |
@@ -3129,22 +3129,22 @@ discard block |
||
| 3129 | 3129 | * - string : expression trouvée. |
| 3130 | 3130 | **/ |
| 3131 | 3131 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3132 | - if ((int) $modif && $capte == 0) { |
|
| 3133 | - $capte = $modif; |
|
| 3134 | - $modif = 'UuimsS'; |
|
| 3135 | - } |
|
| 3136 | - $expression = str_replace('\/', '/', $expression); |
|
| 3137 | - $expression = str_replace('/', '\/', $expression); |
|
| 3132 | + if ((int) $modif && $capte == 0) { |
|
| 3133 | + $capte = $modif; |
|
| 3134 | + $modif = 'UuimsS'; |
|
| 3135 | + } |
|
| 3136 | + $expression = str_replace('\/', '/', $expression); |
|
| 3137 | + $expression = str_replace('/', '\/', $expression); |
|
| 3138 | 3138 | |
| 3139 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3140 | - if (isset($r[$capte])) { |
|
| 3141 | - return $r[$capte]; |
|
| 3142 | - } else { |
|
| 3143 | - return true; |
|
| 3144 | - } |
|
| 3145 | - } |
|
| 3139 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3140 | + if (isset($r[$capte])) { |
|
| 3141 | + return $r[$capte]; |
|
| 3142 | + } else { |
|
| 3143 | + return true; |
|
| 3144 | + } |
|
| 3145 | + } |
|
| 3146 | 3146 | |
| 3147 | - return false; |
|
| 3147 | + return false; |
|
| 3148 | 3148 | } |
| 3149 | 3149 | |
| 3150 | 3150 | |
@@ -3171,14 +3171,14 @@ discard block |
||
| 3171 | 3171 | * Texte |
| 3172 | 3172 | **/ |
| 3173 | 3173 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3174 | - if (null === $texte) { |
|
| 3175 | - return ''; |
|
| 3176 | - } |
|
| 3174 | + if (null === $texte) { |
|
| 3175 | + return ''; |
|
| 3176 | + } |
|
| 3177 | 3177 | |
| 3178 | - $expression = str_replace('\/', '/', $expression); |
|
| 3179 | - $expression = str_replace('/', '\/', $expression); |
|
| 3178 | + $expression = str_replace('\/', '/', $expression); |
|
| 3179 | + $expression = str_replace('/', '\/', $expression); |
|
| 3180 | 3180 | |
| 3181 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3181 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3182 | 3182 | } |
| 3183 | 3183 | |
| 3184 | 3184 | |
@@ -3196,25 +3196,25 @@ discard block |
||
| 3196 | 3196 | **/ |
| 3197 | 3197 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3198 | 3198 | |
| 3199 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3200 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3199 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3200 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3201 | 3201 | |
| 3202 | - if ( |
|
| 3203 | - strstr($t, 'spip_document_') |
|
| 3204 | - && preg_match_all( |
|
| 3205 | - ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3206 | - $t, |
|
| 3207 | - $matches, |
|
| 3208 | - PREG_PATTERN_ORDER |
|
| 3209 | - ) |
|
| 3210 | - ) { |
|
| 3211 | - if (!isset($doublons['documents'])) { |
|
| 3212 | - $doublons['documents'] = ''; |
|
| 3213 | - } |
|
| 3214 | - $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3215 | - } |
|
| 3202 | + if ( |
|
| 3203 | + strstr($t, 'spip_document_') |
|
| 3204 | + && preg_match_all( |
|
| 3205 | + ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS', |
|
| 3206 | + $t, |
|
| 3207 | + $matches, |
|
| 3208 | + PREG_PATTERN_ORDER |
|
| 3209 | + ) |
|
| 3210 | + ) { |
|
| 3211 | + if (!isset($doublons['documents'])) { |
|
| 3212 | + $doublons['documents'] = ''; |
|
| 3213 | + } |
|
| 3214 | + $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3215 | + } |
|
| 3216 | 3216 | |
| 3217 | - return $letexte; |
|
| 3217 | + return $letexte; |
|
| 3218 | 3218 | } |
| 3219 | 3219 | |
| 3220 | 3220 | /** |
@@ -3228,7 +3228,7 @@ discard block |
||
| 3228 | 3228 | * @return string Chaîne vide |
| 3229 | 3229 | **/ |
| 3230 | 3230 | function vide(mixed $texte) { |
| 3231 | - return ''; |
|
| 3231 | + return ''; |
|
| 3232 | 3232 | } |
| 3233 | 3233 | |
| 3234 | 3234 | // |
@@ -3257,23 +3257,23 @@ discard block |
||
| 3257 | 3257 | * Code HTML résultant |
| 3258 | 3258 | **/ |
| 3259 | 3259 | function env_to_params($env, $ignore_params = []) { |
| 3260 | - $ignore_params = array_merge( |
|
| 3261 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3262 | - $ignore_params |
|
| 3263 | - ); |
|
| 3264 | - if (!is_array($env)) { |
|
| 3265 | - $env = unserialize($env); |
|
| 3266 | - } |
|
| 3267 | - $texte = ''; |
|
| 3268 | - if ($env) { |
|
| 3269 | - foreach ($env as $i => $j) { |
|
| 3270 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3271 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3272 | - } |
|
| 3273 | - } |
|
| 3274 | - } |
|
| 3275 | - |
|
| 3276 | - return $texte; |
|
| 3260 | + $ignore_params = array_merge( |
|
| 3261 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3262 | + $ignore_params |
|
| 3263 | + ); |
|
| 3264 | + if (!is_array($env)) { |
|
| 3265 | + $env = unserialize($env); |
|
| 3266 | + } |
|
| 3267 | + $texte = ''; |
|
| 3268 | + if ($env) { |
|
| 3269 | + foreach ($env as $i => $j) { |
|
| 3270 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3271 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3272 | + } |
|
| 3273 | + } |
|
| 3274 | + } |
|
| 3275 | + |
|
| 3276 | + return $texte; |
|
| 3277 | 3277 | } |
| 3278 | 3278 | |
| 3279 | 3279 | /** |
@@ -3296,23 +3296,23 @@ discard block |
||
| 3296 | 3296 | * Code HTML résultant |
| 3297 | 3297 | **/ |
| 3298 | 3298 | function env_to_attributs($env, $ignore_params = []) { |
| 3299 | - $ignore_params = array_merge( |
|
| 3300 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3301 | - $ignore_params |
|
| 3302 | - ); |
|
| 3303 | - if (!is_array($env)) { |
|
| 3304 | - $env = unserialize($env); |
|
| 3305 | - } |
|
| 3306 | - $texte = ''; |
|
| 3307 | - if ($env) { |
|
| 3308 | - foreach ($env as $i => $j) { |
|
| 3309 | - if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3310 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3311 | - } |
|
| 3312 | - } |
|
| 3313 | - } |
|
| 3299 | + $ignore_params = array_merge( |
|
| 3300 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3301 | + $ignore_params |
|
| 3302 | + ); |
|
| 3303 | + if (!is_array($env)) { |
|
| 3304 | + $env = unserialize($env); |
|
| 3305 | + } |
|
| 3306 | + $texte = ''; |
|
| 3307 | + if ($env) { |
|
| 3308 | + foreach ($env as $i => $j) { |
|
| 3309 | + if (is_string($j) && !in_array($i, $ignore_params)) { |
|
| 3310 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3311 | + } |
|
| 3312 | + } |
|
| 3313 | + } |
|
| 3314 | 3314 | |
| 3315 | - return $texte; |
|
| 3315 | + return $texte; |
|
| 3316 | 3316 | } |
| 3317 | 3317 | |
| 3318 | 3318 | |
@@ -3330,7 +3330,7 @@ discard block |
||
| 3330 | 3330 | * @return string Chaînes concaténés |
| 3331 | 3331 | **/ |
| 3332 | 3332 | function concat(...$args): string { |
| 3333 | - return implode('', $args); |
|
| 3333 | + return implode('', $args); |
|
| 3334 | 3334 | } |
| 3335 | 3335 | |
| 3336 | 3336 | |
@@ -3350,23 +3350,23 @@ discard block |
||
| 3350 | 3350 | * Contenu du ou des fichiers, concaténé |
| 3351 | 3351 | **/ |
| 3352 | 3352 | function charge_scripts($files, $script = true) { |
| 3353 | - $flux = ''; |
|
| 3354 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3355 | - if (!is_string($file)) { |
|
| 3356 | - continue; |
|
| 3357 | - } |
|
| 3358 | - if ($script) { |
|
| 3359 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3360 | - } |
|
| 3361 | - if ($file) { |
|
| 3362 | - $path = find_in_path($file); |
|
| 3363 | - if ($path) { |
|
| 3364 | - $flux .= spip_file_get_contents($path); |
|
| 3365 | - } |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3368 | - |
|
| 3369 | - return $flux; |
|
| 3353 | + $flux = ''; |
|
| 3354 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3355 | + if (!is_string($file)) { |
|
| 3356 | + continue; |
|
| 3357 | + } |
|
| 3358 | + if ($script) { |
|
| 3359 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3360 | + } |
|
| 3361 | + if ($file) { |
|
| 3362 | + $path = find_in_path($file); |
|
| 3363 | + if ($path) { |
|
| 3364 | + $flux .= spip_file_get_contents($path); |
|
| 3365 | + } |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | + |
|
| 3369 | + return $flux; |
|
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | /** |
@@ -3377,23 +3377,23 @@ discard block |
||
| 3377 | 3377 | * @return string |
| 3378 | 3378 | */ |
| 3379 | 3379 | function http_img_variante_svg_si_possible($img_file) { |
| 3380 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3381 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3382 | - if ( |
|
| 3383 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3384 | - && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3385 | - && file_exists($variante_svg_generique) |
|
| 3386 | - ) { |
|
| 3387 | - if ( |
|
| 3388 | - ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3389 | - && file_exists($variante_svg_size)) { |
|
| 3390 | - $img_file = $variante_svg_size; |
|
| 3391 | - } else { |
|
| 3392 | - $img_file = $variante_svg_generique; |
|
| 3393 | - } |
|
| 3394 | - } |
|
| 3395 | - |
|
| 3396 | - return $img_file; |
|
| 3380 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3381 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3382 | + if ( |
|
| 3383 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3384 | + && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3385 | + && file_exists($variante_svg_generique) |
|
| 3386 | + ) { |
|
| 3387 | + if ( |
|
| 3388 | + ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3389 | + && file_exists($variante_svg_size)) { |
|
| 3390 | + $img_file = $variante_svg_size; |
|
| 3391 | + } else { |
|
| 3392 | + $img_file = $variante_svg_generique; |
|
| 3393 | + } |
|
| 3394 | + } |
|
| 3395 | + |
|
| 3396 | + return $img_file; |
|
| 3397 | 3397 | } |
| 3398 | 3398 | |
| 3399 | 3399 | /** |
@@ -3414,51 +3414,51 @@ discard block |
||
| 3414 | 3414 | */ |
| 3415 | 3415 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3416 | 3416 | |
| 3417 | - $img_file = $img; |
|
| 3418 | - if ($p = strpos($img_file, '?')) { |
|
| 3419 | - $img_file = substr($img_file, 0, $p); |
|
| 3420 | - } |
|
| 3421 | - if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3422 | - $img_file = chemin_image($img); |
|
| 3423 | - } |
|
| 3424 | - else { |
|
| 3425 | - if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3426 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3427 | - } |
|
| 3428 | - } |
|
| 3429 | - if (stripos($atts, 'width') === false) { |
|
| 3430 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3431 | - if ( |
|
| 3432 | - (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3433 | - && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3434 | - ) { |
|
| 3435 | - $largeur = $hauteur = (int) $regs[1]; |
|
| 3436 | - } else { |
|
| 3437 | - $taille = taille_image($img_file); |
|
| 3438 | - [$hauteur, $largeur] = $taille; |
|
| 3439 | - if (!$hauteur || !$largeur) { |
|
| 3440 | - return ''; |
|
| 3441 | - } |
|
| 3442 | - } |
|
| 3443 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3444 | - } |
|
| 3445 | - |
|
| 3446 | - if (file_exists($img_file)) { |
|
| 3447 | - $img_file = timestamp($img_file); |
|
| 3448 | - } |
|
| 3449 | - if ($alt === false) { |
|
| 3450 | - $alt = ''; |
|
| 3451 | - } |
|
| 3452 | - elseif ($alt || $alt === '') { |
|
| 3453 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3454 | - } |
|
| 3455 | - else { |
|
| 3456 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3457 | - } |
|
| 3458 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3459 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3460 | - . ' ' . ltrim($atts) |
|
| 3461 | - . ' />'; |
|
| 3417 | + $img_file = $img; |
|
| 3418 | + if ($p = strpos($img_file, '?')) { |
|
| 3419 | + $img_file = substr($img_file, 0, $p); |
|
| 3420 | + } |
|
| 3421 | + if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
|
| 3422 | + $img_file = chemin_image($img); |
|
| 3423 | + } |
|
| 3424 | + else { |
|
| 3425 | + if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
|
| 3426 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3427 | + } |
|
| 3428 | + } |
|
| 3429 | + if (stripos($atts, 'width') === false) { |
|
| 3430 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3431 | + if ( |
|
| 3432 | + (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg')) |
|
| 3433 | + && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs)) |
|
| 3434 | + ) { |
|
| 3435 | + $largeur = $hauteur = (int) $regs[1]; |
|
| 3436 | + } else { |
|
| 3437 | + $taille = taille_image($img_file); |
|
| 3438 | + [$hauteur, $largeur] = $taille; |
|
| 3439 | + if (!$hauteur || !$largeur) { |
|
| 3440 | + return ''; |
|
| 3441 | + } |
|
| 3442 | + } |
|
| 3443 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3444 | + } |
|
| 3445 | + |
|
| 3446 | + if (file_exists($img_file)) { |
|
| 3447 | + $img_file = timestamp($img_file); |
|
| 3448 | + } |
|
| 3449 | + if ($alt === false) { |
|
| 3450 | + $alt = ''; |
|
| 3451 | + } |
|
| 3452 | + elseif ($alt || $alt === '') { |
|
| 3453 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3454 | + } |
|
| 3455 | + else { |
|
| 3456 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3457 | + } |
|
| 3458 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3459 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3460 | + . ' ' . ltrim($atts) |
|
| 3461 | + . ' />'; |
|
| 3462 | 3462 | } |
| 3463 | 3463 | |
| 3464 | 3464 | /** |
@@ -3470,70 +3470,70 @@ discard block |
||
| 3470 | 3470 | * @return string |
| 3471 | 3471 | */ |
| 3472 | 3472 | function http_style_background($img, $att = '', $size = null) { |
| 3473 | - if ($size && is_numeric($size)) { |
|
| 3474 | - $size = trim($size) . 'px'; |
|
| 3475 | - } |
|
| 3476 | - return " style='background" . |
|
| 3477 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3478 | - . ($size ? "background-size:{$size};" : '') |
|
| 3479 | - . "'"; |
|
| 3473 | + if ($size && is_numeric($size)) { |
|
| 3474 | + $size = trim($size) . 'px'; |
|
| 3475 | + } |
|
| 3476 | + return " style='background" . |
|
| 3477 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3478 | + . ($size ? "background-size:{$size};" : '') |
|
| 3479 | + . "'"; |
|
| 3480 | 3480 | } |
| 3481 | 3481 | |
| 3482 | 3482 | |
| 3483 | 3483 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3484 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3485 | - while (is_null(end($args)) && count($args)) { |
|
| 3486 | - array_pop($args); |
|
| 3487 | - } |
|
| 3488 | - if ($args === []) { |
|
| 3489 | - return [null, null, null]; |
|
| 3490 | - } |
|
| 3491 | - if (count($args) < 3) { |
|
| 3492 | - $maybe_size = array_pop($args); |
|
| 3493 | - // @2x |
|
| 3494 | - // @1.5x |
|
| 3495 | - // 512 |
|
| 3496 | - // 512x* |
|
| 3497 | - // 512x300 |
|
| 3498 | - if ( |
|
| 3499 | - !strlen($maybe_size) |
|
| 3500 | - || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3501 | - ) { |
|
| 3502 | - $args[] = $maybe_size; |
|
| 3503 | - $maybe_size = null; |
|
| 3504 | - } |
|
| 3505 | - while (count($args) < 2) { |
|
| 3506 | - $args[] = null; // default alt or class |
|
| 3507 | - } |
|
| 3508 | - $args[] = $maybe_size; |
|
| 3509 | - } |
|
| 3510 | - return $args; |
|
| 3484 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3485 | + while (is_null(end($args)) && count($args)) { |
|
| 3486 | + array_pop($args); |
|
| 3487 | + } |
|
| 3488 | + if ($args === []) { |
|
| 3489 | + return [null, null, null]; |
|
| 3490 | + } |
|
| 3491 | + if (count($args) < 3) { |
|
| 3492 | + $maybe_size = array_pop($args); |
|
| 3493 | + // @2x |
|
| 3494 | + // @1.5x |
|
| 3495 | + // 512 |
|
| 3496 | + // 512x* |
|
| 3497 | + // 512x300 |
|
| 3498 | + if ( |
|
| 3499 | + !strlen($maybe_size) |
|
| 3500 | + || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3501 | + ) { |
|
| 3502 | + $args[] = $maybe_size; |
|
| 3503 | + $maybe_size = null; |
|
| 3504 | + } |
|
| 3505 | + while (count($args) < 2) { |
|
| 3506 | + $args[] = null; // default alt or class |
|
| 3507 | + } |
|
| 3508 | + $args[] = $maybe_size; |
|
| 3509 | + } |
|
| 3510 | + return $args; |
|
| 3511 | 3511 | } |
| 3512 | 3512 | |
| 3513 | 3513 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3514 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3515 | - if (str_starts_with($size, '@') && str_ends_with($size, 'x')) { |
|
| 3516 | - $coef = (float) substr($size, 1, -1); |
|
| 3517 | - [$h, $w] = taille_image($img); |
|
| 3518 | - $height = (int) round($h / $coef); |
|
| 3519 | - $width = (int) round($w / $coef); |
|
| 3520 | - } |
|
| 3521 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3522 | - else { |
|
| 3523 | - $size = explode('x', $size, 2); |
|
| 3524 | - $size = array_map('trim', $size); |
|
| 3525 | - $height = $width = (int) array_shift($size); |
|
| 3526 | - |
|
| 3527 | - if (count($size) && reset($size)) { |
|
| 3528 | - $height = array_shift($size); |
|
| 3529 | - if ($height === '*') { |
|
| 3530 | - [$h, $w] = taille_image($img); |
|
| 3531 | - $height = (int) round($h * $width / $w); |
|
| 3532 | - } |
|
| 3533 | - } |
|
| 3534 | - } |
|
| 3535 | - |
|
| 3536 | - return [$width, $height]; |
|
| 3514 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3515 | + if (str_starts_with($size, '@') && str_ends_with($size, 'x')) { |
|
| 3516 | + $coef = (float) substr($size, 1, -1); |
|
| 3517 | + [$h, $w] = taille_image($img); |
|
| 3518 | + $height = (int) round($h / $coef); |
|
| 3519 | + $width = (int) round($w / $coef); |
|
| 3520 | + } |
|
| 3521 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3522 | + else { |
|
| 3523 | + $size = explode('x', $size, 2); |
|
| 3524 | + $size = array_map('trim', $size); |
|
| 3525 | + $height = $width = (int) array_shift($size); |
|
| 3526 | + |
|
| 3527 | + if (count($size) && reset($size)) { |
|
| 3528 | + $height = array_shift($size); |
|
| 3529 | + if ($height === '*') { |
|
| 3530 | + [$h, $w] = taille_image($img); |
|
| 3531 | + $height = (int) round($h * $width / $w); |
|
| 3532 | + } |
|
| 3533 | + } |
|
| 3534 | + } |
|
| 3535 | + |
|
| 3536 | + return [$width, $height]; |
|
| 3537 | 3537 | } |
| 3538 | 3538 | |
| 3539 | 3539 | /** |
@@ -3569,38 +3569,38 @@ discard block |
||
| 3569 | 3569 | */ |
| 3570 | 3570 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3571 | 3571 | |
| 3572 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3572 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3573 | 3573 | |
| 3574 | - $img = trim((string) $img); |
|
| 3575 | - if (str_starts_with($img, '<img')) { |
|
| 3576 | - if (!is_null($alt)) { |
|
| 3577 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3578 | - } |
|
| 3579 | - if (!is_null($class)) { |
|
| 3580 | - $img = strlen($class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3581 | - } |
|
| 3582 | - } |
|
| 3583 | - else { |
|
| 3584 | - $img = http_img_pack( |
|
| 3585 | - $img, |
|
| 3586 | - $alt, |
|
| 3587 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3588 | - '', |
|
| 3589 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3590 | - ); |
|
| 3591 | - if (is_null($alt)) { |
|
| 3592 | - $img = vider_attribut($img, 'alt'); |
|
| 3593 | - } |
|
| 3594 | - } |
|
| 3574 | + $img = trim((string) $img); |
|
| 3575 | + if (str_starts_with($img, '<img')) { |
|
| 3576 | + if (!is_null($alt)) { |
|
| 3577 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3578 | + } |
|
| 3579 | + if (!is_null($class)) { |
|
| 3580 | + $img = strlen($class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
|
| 3581 | + } |
|
| 3582 | + } |
|
| 3583 | + else { |
|
| 3584 | + $img = http_img_pack( |
|
| 3585 | + $img, |
|
| 3586 | + $alt, |
|
| 3587 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3588 | + '', |
|
| 3589 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3590 | + ); |
|
| 3591 | + if (is_null($alt)) { |
|
| 3592 | + $img = vider_attribut($img, 'alt'); |
|
| 3593 | + } |
|
| 3594 | + } |
|
| 3595 | 3595 | |
| 3596 | - if ($img && !is_null($size) && strlen($size = trim($size))) { |
|
| 3597 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3596 | + if ($img && !is_null($size) && strlen($size = trim($size))) { |
|
| 3597 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3598 | 3598 | |
| 3599 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3600 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3601 | - } |
|
| 3599 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3600 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3601 | + } |
|
| 3602 | 3602 | |
| 3603 | - return $img; |
|
| 3603 | + return $img; |
|
| 3604 | 3604 | } |
| 3605 | 3605 | |
| 3606 | 3606 | |
@@ -3634,77 +3634,77 @@ discard block |
||
| 3634 | 3634 | */ |
| 3635 | 3635 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3636 | 3636 | |
| 3637 | - $svg = null; |
|
| 3638 | - $img = trim($img); |
|
| 3639 | - $img_file = $img; |
|
| 3640 | - if (!str_contains($img, '<svg')) { |
|
| 3641 | - if ($p = strpos($img_file, '?')) { |
|
| 3642 | - $img_file = substr($img_file, 0, $p); |
|
| 3643 | - } |
|
| 3637 | + $svg = null; |
|
| 3638 | + $img = trim($img); |
|
| 3639 | + $img_file = $img; |
|
| 3640 | + if (!str_contains($img, '<svg')) { |
|
| 3641 | + if ($p = strpos($img_file, '?')) { |
|
| 3642 | + $img_file = substr($img_file, 0, $p); |
|
| 3643 | + } |
|
| 3644 | 3644 | |
| 3645 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3646 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3647 | - if (tester_url_absolue($img_file)) { |
|
| 3648 | - include_spip('inc/distant'); |
|
| 3649 | - $fichier = copie_locale($img_file); |
|
| 3650 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3651 | - } |
|
| 3645 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3646 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3647 | + if (tester_url_absolue($img_file)) { |
|
| 3648 | + include_spip('inc/distant'); |
|
| 3649 | + $fichier = copie_locale($img_file); |
|
| 3650 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3651 | + } |
|
| 3652 | 3652 | |
| 3653 | - if ( |
|
| 3654 | - !$img_file |
|
| 3655 | - || !file_exists($img_file) |
|
| 3656 | - || !$svg = file_get_contents($img_file) |
|
| 3657 | - ) { |
|
| 3658 | - return ''; |
|
| 3659 | - } |
|
| 3660 | - } |
|
| 3653 | + if ( |
|
| 3654 | + !$img_file |
|
| 3655 | + || !file_exists($img_file) |
|
| 3656 | + || !$svg = file_get_contents($img_file) |
|
| 3657 | + ) { |
|
| 3658 | + return ''; |
|
| 3659 | + } |
|
| 3660 | + } |
|
| 3661 | 3661 | |
| 3662 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3663 | - return ''; |
|
| 3664 | - } |
|
| 3662 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3663 | + return ''; |
|
| 3664 | + } |
|
| 3665 | 3665 | |
| 3666 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3666 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3667 | 3667 | |
| 3668 | - $balise_svg = $match[0]; |
|
| 3669 | - $balise_svg_source = $balise_svg; |
|
| 3668 | + $balise_svg = $match[0]; |
|
| 3669 | + $balise_svg_source = $balise_svg; |
|
| 3670 | 3670 | |
| 3671 | - // entete XML à supprimer |
|
| 3672 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3671 | + // entete XML à supprimer |
|
| 3672 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg); |
|
| 3673 | 3673 | |
| 3674 | - // IE est toujours mon ami |
|
| 3675 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3674 | + // IE est toujours mon ami |
|
| 3675 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3676 | 3676 | |
| 3677 | - // regler la classe |
|
| 3678 | - if (!is_null($class)) { |
|
| 3679 | - $balise_svg = strlen($class) |
|
| 3680 | - ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3681 | - : vider_attribut($balise_svg, 'class'); |
|
| 3682 | - } |
|
| 3677 | + // regler la classe |
|
| 3678 | + if (!is_null($class)) { |
|
| 3679 | + $balise_svg = strlen($class) |
|
| 3680 | + ? inserer_attribut($balise_svg, 'class', $class) |
|
| 3681 | + : vider_attribut($balise_svg, 'class'); |
|
| 3682 | + } |
|
| 3683 | 3683 | |
| 3684 | - // regler le alt |
|
| 3685 | - if ($alt) { |
|
| 3686 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3687 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3688 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3689 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3690 | - $balise_svg .= $title; |
|
| 3691 | - } |
|
| 3692 | - else { |
|
| 3693 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3694 | - } |
|
| 3684 | + // regler le alt |
|
| 3685 | + if ($alt) { |
|
| 3686 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3687 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3688 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3689 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3690 | + $balise_svg .= $title; |
|
| 3691 | + } |
|
| 3692 | + else { |
|
| 3693 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3694 | + } |
|
| 3695 | 3695 | |
| 3696 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3696 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3697 | 3697 | |
| 3698 | - if (!is_null($size) && strlen($size = trim($size))) { |
|
| 3699 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3698 | + if (!is_null($size) && strlen($size = trim($size))) { |
|
| 3699 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3700 | 3700 | |
| 3701 | - if (!function_exists('svg_redimensionner')) { |
|
| 3702 | - include_spip('inc/svg'); |
|
| 3703 | - } |
|
| 3704 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3705 | - } |
|
| 3701 | + if (!function_exists('svg_redimensionner')) { |
|
| 3702 | + include_spip('inc/svg'); |
|
| 3703 | + } |
|
| 3704 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3705 | + } |
|
| 3706 | 3706 | |
| 3707 | - return $svg; |
|
| 3707 | + return $svg; |
|
| 3708 | 3708 | } |
| 3709 | 3709 | |
| 3710 | 3710 | |
@@ -3730,18 +3730,18 @@ discard block |
||
| 3730 | 3730 | * Code HTML résultant |
| 3731 | 3731 | **/ |
| 3732 | 3732 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3733 | - $texte = ''; |
|
| 3734 | - if (is_array($tableau)) { |
|
| 3735 | - foreach ($tableau as $k => $v) { |
|
| 3736 | - $res = recuperer_fond( |
|
| 3737 | - 'modeles/' . $modele, |
|
| 3738 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3739 | - ); |
|
| 3740 | - $texte .= $res; |
|
| 3741 | - } |
|
| 3742 | - } |
|
| 3733 | + $texte = ''; |
|
| 3734 | + if (is_array($tableau)) { |
|
| 3735 | + foreach ($tableau as $k => $v) { |
|
| 3736 | + $res = recuperer_fond( |
|
| 3737 | + 'modeles/' . $modele, |
|
| 3738 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3739 | + ); |
|
| 3740 | + $texte .= $res; |
|
| 3741 | + } |
|
| 3742 | + } |
|
| 3743 | 3743 | |
| 3744 | - return $texte; |
|
| 3744 | + return $texte; |
|
| 3745 | 3745 | } |
| 3746 | 3746 | |
| 3747 | 3747 | |
@@ -3766,37 +3766,37 @@ discard block |
||
| 3766 | 3766 | * - tout : retourne toutes les informations du plugin actif |
| 3767 | 3767 | **/ |
| 3768 | 3768 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3769 | - include_spip('inc/plugin'); |
|
| 3770 | - $plugin = strtoupper($plugin); |
|
| 3771 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3772 | - |
|
| 3773 | - if (!$plugin) { |
|
| 3774 | - return serialize(array_keys($plugins_actifs)); |
|
| 3775 | - } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3776 | - return ''; |
|
| 3777 | - } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3778 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3779 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3780 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3781 | - } else { |
|
| 3782 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3783 | - // On prend en compte les extensions |
|
| 3784 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3785 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3786 | - } else { |
|
| 3787 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3788 | - } |
|
| 3789 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3790 | - return ''; |
|
| 3791 | - } |
|
| 3792 | - if ($type_info == 'tout') { |
|
| 3793 | - return $infos; |
|
| 3794 | - } elseif ($type_info == 'est_actif') { |
|
| 3795 | - return $infos ? 1 : 0; |
|
| 3796 | - } else { |
|
| 3797 | - return (string) $infos[$type_info]; |
|
| 3798 | - } |
|
| 3799 | - } |
|
| 3769 | + include_spip('inc/plugin'); |
|
| 3770 | + $plugin = strtoupper($plugin); |
|
| 3771 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3772 | + |
|
| 3773 | + if (!$plugin) { |
|
| 3774 | + return serialize(array_keys($plugins_actifs)); |
|
| 3775 | + } elseif (empty($plugins_actifs[$plugin]) && !$reload) { |
|
| 3776 | + return ''; |
|
| 3777 | + } elseif ($type_info == 'est_actif' && !$reload) { |
|
| 3778 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3779 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) { |
|
| 3780 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3781 | + } else { |
|
| 3782 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3783 | + // On prend en compte les extensions |
|
| 3784 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3785 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3786 | + } else { |
|
| 3787 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3788 | + } |
|
| 3789 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3790 | + return ''; |
|
| 3791 | + } |
|
| 3792 | + if ($type_info == 'tout') { |
|
| 3793 | + return $infos; |
|
| 3794 | + } elseif ($type_info == 'est_actif') { |
|
| 3795 | + return $infos ? 1 : 0; |
|
| 3796 | + } else { |
|
| 3797 | + return (string) $infos[$type_info]; |
|
| 3798 | + } |
|
| 3799 | + } |
|
| 3800 | 3800 | } |
| 3801 | 3801 | |
| 3802 | 3802 | |
@@ -3823,9 +3823,9 @@ discard block |
||
| 3823 | 3823 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3824 | 3824 | */ |
| 3825 | 3825 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3826 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3826 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3827 | 3827 | |
| 3828 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3828 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3829 | 3829 | } |
| 3830 | 3830 | |
| 3831 | 3831 | |
@@ -3855,19 +3855,19 @@ discard block |
||
| 3855 | 3855 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3856 | 3856 | */ |
| 3857 | 3857 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3858 | - static $puce_statut = null; |
|
| 3859 | - if (!$puce_statut) { |
|
| 3860 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3861 | - } |
|
| 3858 | + static $puce_statut = null; |
|
| 3859 | + if (!$puce_statut) { |
|
| 3860 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3861 | + } |
|
| 3862 | 3862 | |
| 3863 | - return $puce_statut( |
|
| 3864 | - $id_objet, |
|
| 3865 | - $statut, |
|
| 3866 | - $id_parent, |
|
| 3867 | - $objet, |
|
| 3868 | - false, |
|
| 3869 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3870 | - ); |
|
| 3863 | + return $puce_statut( |
|
| 3864 | + $id_objet, |
|
| 3865 | + $statut, |
|
| 3866 | + $id_parent, |
|
| 3867 | + $objet, |
|
| 3868 | + false, |
|
| 3869 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3870 | + ); |
|
| 3871 | 3871 | } |
| 3872 | 3872 | |
| 3873 | 3873 | |
@@ -3894,95 +3894,95 @@ discard block |
||
| 3894 | 3894 | * hash du contexte |
| 3895 | 3895 | */ |
| 3896 | 3896 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3897 | - $env = null; |
|
| 3898 | - if (is_string($c) && @unserialize($c) !== false) { |
|
| 3899 | - $c = unserialize($c); |
|
| 3900 | - } |
|
| 3901 | - |
|
| 3902 | - // supprimer les parametres debut_x |
|
| 3903 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3904 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3905 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3906 | - if (is_array($c)) { |
|
| 3907 | - foreach (array_keys($c) as $k) { |
|
| 3908 | - if (str_starts_with($k, 'debut_')) { |
|
| 3909 | - unset($c[$k]); |
|
| 3910 | - } |
|
| 3911 | - } |
|
| 3912 | - } |
|
| 3913 | - |
|
| 3914 | - if (!function_exists('calculer_cle_action')) { |
|
| 3915 | - include_spip('inc/securiser_action'); |
|
| 3916 | - } |
|
| 3917 | - |
|
| 3918 | - $c = serialize($c); |
|
| 3919 | - $cle = calculer_cle_action($form . $c); |
|
| 3920 | - $c = "$cle:$c"; |
|
| 3921 | - |
|
| 3922 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3923 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3924 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3925 | - // que ce qui est toléré. |
|
| 3926 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3927 | - if (!$cache_contextes_ajax) { |
|
| 3928 | - $env = $c; |
|
| 3929 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3930 | - $env = gzdeflate($env); |
|
| 3931 | - } |
|
| 3932 | - $env = _xor($env); |
|
| 3933 | - $env = base64_encode($env); |
|
| 3934 | - $len = strlen($env); |
|
| 3935 | - // Si l’url est trop longue pour le navigateur |
|
| 3936 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3937 | - if ($len > $max_len) { |
|
| 3938 | - $cache_contextes_ajax = true; |
|
| 3939 | - spip_log( |
|
| 3940 | - 'Contextes AJAX forces en fichiers !' |
|
| 3941 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3942 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3943 | - _LOG_AVERTISSEMENT |
|
| 3944 | - ); |
|
| 3945 | - } |
|
| 3946 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3947 | - elseif ( |
|
| 3948 | - ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3949 | - && $max_len < $len |
|
| 3950 | - ) { |
|
| 3951 | - $cache_contextes_ajax = true; |
|
| 3952 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3953 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3954 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3955 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3956 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3957 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3958 | - } |
|
| 3959 | - } |
|
| 3960 | - |
|
| 3961 | - if ($cache_contextes_ajax) { |
|
| 3962 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3963 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3964 | - $md5 = md5($c); |
|
| 3965 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3966 | - $env = $md5; |
|
| 3967 | - } |
|
| 3968 | - |
|
| 3969 | - if ($emboite === null) { |
|
| 3970 | - return $env; |
|
| 3971 | - } |
|
| 3972 | - if (!trim($emboite)) { |
|
| 3973 | - return ''; |
|
| 3974 | - } |
|
| 3975 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3976 | - $r = self(); |
|
| 3977 | - $r = ' data-origin="' . $r . '"'; |
|
| 3978 | - $class = 'ajaxbloc'; |
|
| 3979 | - if ($ajaxid && is_string($ajaxid)) { |
|
| 3980 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3981 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3982 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3983 | - } |
|
| 3984 | - |
|
| 3985 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3897 | + $env = null; |
|
| 3898 | + if (is_string($c) && @unserialize($c) !== false) { |
|
| 3899 | + $c = unserialize($c); |
|
| 3900 | + } |
|
| 3901 | + |
|
| 3902 | + // supprimer les parametres debut_x |
|
| 3903 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3904 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3905 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3906 | + if (is_array($c)) { |
|
| 3907 | + foreach (array_keys($c) as $k) { |
|
| 3908 | + if (str_starts_with($k, 'debut_')) { |
|
| 3909 | + unset($c[$k]); |
|
| 3910 | + } |
|
| 3911 | + } |
|
| 3912 | + } |
|
| 3913 | + |
|
| 3914 | + if (!function_exists('calculer_cle_action')) { |
|
| 3915 | + include_spip('inc/securiser_action'); |
|
| 3916 | + } |
|
| 3917 | + |
|
| 3918 | + $c = serialize($c); |
|
| 3919 | + $cle = calculer_cle_action($form . $c); |
|
| 3920 | + $c = "$cle:$c"; |
|
| 3921 | + |
|
| 3922 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3923 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3924 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3925 | + // que ce qui est toléré. |
|
| 3926 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX); |
|
| 3927 | + if (!$cache_contextes_ajax) { |
|
| 3928 | + $env = $c; |
|
| 3929 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3930 | + $env = gzdeflate($env); |
|
| 3931 | + } |
|
| 3932 | + $env = _xor($env); |
|
| 3933 | + $env = base64_encode($env); |
|
| 3934 | + $len = strlen($env); |
|
| 3935 | + // Si l’url est trop longue pour le navigateur |
|
| 3936 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3937 | + if ($len > $max_len) { |
|
| 3938 | + $cache_contextes_ajax = true; |
|
| 3939 | + spip_log( |
|
| 3940 | + 'Contextes AJAX forces en fichiers !' |
|
| 3941 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3942 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3943 | + _LOG_AVERTISSEMENT |
|
| 3944 | + ); |
|
| 3945 | + } |
|
| 3946 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3947 | + elseif ( |
|
| 3948 | + ($max_len = @ini_get('suhosin.get.max_value_length')) |
|
| 3949 | + && $max_len < $len |
|
| 3950 | + ) { |
|
| 3951 | + $cache_contextes_ajax = true; |
|
| 3952 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3953 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3954 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3955 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3956 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3957 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3958 | + } |
|
| 3959 | + } |
|
| 3960 | + |
|
| 3961 | + if ($cache_contextes_ajax) { |
|
| 3962 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3963 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3964 | + $md5 = md5($c); |
|
| 3965 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3966 | + $env = $md5; |
|
| 3967 | + } |
|
| 3968 | + |
|
| 3969 | + if ($emboite === null) { |
|
| 3970 | + return $env; |
|
| 3971 | + } |
|
| 3972 | + if (!trim($emboite)) { |
|
| 3973 | + return ''; |
|
| 3974 | + } |
|
| 3975 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3976 | + $r = self(); |
|
| 3977 | + $r = ' data-origin="' . $r . '"'; |
|
| 3978 | + $class = 'ajaxbloc'; |
|
| 3979 | + if ($ajaxid && is_string($ajaxid)) { |
|
| 3980 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3981 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3982 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3983 | + } |
|
| 3984 | + |
|
| 3985 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3986 | 3986 | } |
| 3987 | 3987 | |
| 3988 | 3988 | /** |
@@ -4002,37 +4002,37 @@ discard block |
||
| 4002 | 4002 | * - false : erreur de décodage |
| 4003 | 4003 | */ |
| 4004 | 4004 | function decoder_contexte_ajax($c, $form = '') { |
| 4005 | - $contexte = null; |
|
| 4006 | - if (!function_exists('calculer_cle_action')) { |
|
| 4007 | - include_spip('inc/securiser_action'); |
|
| 4008 | - } |
|
| 4009 | - if ( |
|
| 4010 | - (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 4011 | - && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 4012 | - && lire_fichier("$dir/c$c", $contexte) |
|
| 4013 | - ) { |
|
| 4014 | - $c = $contexte; |
|
| 4015 | - } else { |
|
| 4016 | - $c = @base64_decode($c); |
|
| 4017 | - $c = _xor($c); |
|
| 4018 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4019 | - $c = @gzinflate($c); |
|
| 4020 | - } |
|
| 4021 | - } |
|
| 4022 | - |
|
| 4023 | - // extraire la signature en debut de contexte |
|
| 4024 | - // et la verifier avant de deserializer |
|
| 4025 | - // format : signature:donneesserializees |
|
| 4026 | - if ($p = strpos($c, ':')) { |
|
| 4027 | - $cle = substr($c, 0, $p); |
|
| 4028 | - $c = substr($c, $p + 1); |
|
| 4029 | - |
|
| 4030 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4031 | - return @unserialize($c); |
|
| 4032 | - } |
|
| 4033 | - } |
|
| 4034 | - |
|
| 4035 | - return false; |
|
| 4005 | + $contexte = null; |
|
| 4006 | + if (!function_exists('calculer_cle_action')) { |
|
| 4007 | + include_spip('inc/securiser_action'); |
|
| 4008 | + } |
|
| 4009 | + if ( |
|
| 4010 | + (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32) |
|
| 4011 | + && ($dir = sous_repertoire(_DIR_CACHE, 'contextes')) |
|
| 4012 | + && lire_fichier("$dir/c$c", $contexte) |
|
| 4013 | + ) { |
|
| 4014 | + $c = $contexte; |
|
| 4015 | + } else { |
|
| 4016 | + $c = @base64_decode($c); |
|
| 4017 | + $c = _xor($c); |
|
| 4018 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4019 | + $c = @gzinflate($c); |
|
| 4020 | + } |
|
| 4021 | + } |
|
| 4022 | + |
|
| 4023 | + // extraire la signature en debut de contexte |
|
| 4024 | + // et la verifier avant de deserializer |
|
| 4025 | + // format : signature:donneesserializees |
|
| 4026 | + if ($p = strpos($c, ':')) { |
|
| 4027 | + $cle = substr($c, 0, $p); |
|
| 4028 | + $c = substr($c, $p + 1); |
|
| 4029 | + |
|
| 4030 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4031 | + return @unserialize($c); |
|
| 4032 | + } |
|
| 4033 | + } |
|
| 4034 | + |
|
| 4035 | + return false; |
|
| 4036 | 4036 | } |
| 4037 | 4037 | |
| 4038 | 4038 | |
@@ -4050,20 +4050,20 @@ discard block |
||
| 4050 | 4050 | * Message décrypté ou encrypté |
| 4051 | 4051 | **/ |
| 4052 | 4052 | function _xor($message, $key = null) { |
| 4053 | - if (is_null($key)) { |
|
| 4054 | - if (!function_exists('calculer_cle_action')) { |
|
| 4055 | - include_spip('inc/securiser_action'); |
|
| 4056 | - } |
|
| 4057 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4058 | - } |
|
| 4053 | + if (is_null($key)) { |
|
| 4054 | + if (!function_exists('calculer_cle_action')) { |
|
| 4055 | + include_spip('inc/securiser_action'); |
|
| 4056 | + } |
|
| 4057 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4058 | + } |
|
| 4059 | 4059 | |
| 4060 | - $keylen = strlen($key); |
|
| 4061 | - $messagelen = strlen($message); |
|
| 4062 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4063 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4064 | - } |
|
| 4060 | + $keylen = strlen($key); |
|
| 4061 | + $messagelen = strlen($message); |
|
| 4062 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4063 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4064 | + } |
|
| 4065 | 4065 | |
| 4066 | - return $message; |
|
| 4066 | + return $message; |
|
| 4067 | 4067 | } |
| 4068 | 4068 | |
| 4069 | 4069 | /** |
@@ -4077,7 +4077,7 @@ discard block |
||
| 4077 | 4077 | * @return string |
| 4078 | 4078 | */ |
| 4079 | 4079 | function url_reponse_forum($texte) { |
| 4080 | - return $texte; |
|
| 4080 | + return $texte; |
|
| 4081 | 4081 | } |
| 4082 | 4082 | |
| 4083 | 4083 | /** |
@@ -4091,7 +4091,7 @@ discard block |
||
| 4091 | 4091 | * @return string |
| 4092 | 4092 | */ |
| 4093 | 4093 | function url_rss_forum($texte) { |
| 4094 | - return $texte; |
|
| 4094 | + return $texte; |
|
| 4095 | 4095 | } |
| 4096 | 4096 | |
| 4097 | 4097 | |
@@ -4130,37 +4130,37 @@ discard block |
||
| 4130 | 4130 | * Code HTML |
| 4131 | 4131 | */ |
| 4132 | 4132 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4133 | - if ($on) { |
|
| 4134 | - $bal = 'strong'; |
|
| 4135 | - $class = ''; |
|
| 4136 | - $att = ''; |
|
| 4137 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4138 | - // a.active span.selected.active etc.... |
|
| 4139 | - if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4140 | - $on = explode('.', $on); |
|
| 4141 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4142 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4143 | - $bal = array_shift($on); |
|
| 4144 | - $class = implode(' ', $on); |
|
| 4145 | - if ($bal == 'a') { |
|
| 4146 | - $att = 'href="#" '; |
|
| 4147 | - } |
|
| 4148 | - } |
|
| 4149 | - } |
|
| 4150 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4151 | - } else { |
|
| 4152 | - $bal = 'a'; |
|
| 4153 | - $att = "href='$url'" |
|
| 4154 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4155 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4156 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4157 | - . $evt; |
|
| 4158 | - } |
|
| 4159 | - if ($libelle === null) { |
|
| 4160 | - $libelle = $url; |
|
| 4161 | - } |
|
| 4162 | - |
|
| 4163 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4133 | + if ($on) { |
|
| 4134 | + $bal = 'strong'; |
|
| 4135 | + $class = ''; |
|
| 4136 | + $att = ''; |
|
| 4137 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4138 | + // a.active span.selected.active etc.... |
|
| 4139 | + if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) { |
|
| 4140 | + $on = explode('.', $on); |
|
| 4141 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4142 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4143 | + $bal = array_shift($on); |
|
| 4144 | + $class = implode(' ', $on); |
|
| 4145 | + if ($bal == 'a') { |
|
| 4146 | + $att = 'href="#" '; |
|
| 4147 | + } |
|
| 4148 | + } |
|
| 4149 | + } |
|
| 4150 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4151 | + } else { |
|
| 4152 | + $bal = 'a'; |
|
| 4153 | + $att = "href='$url'" |
|
| 4154 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4155 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4156 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4157 | + . $evt; |
|
| 4158 | + } |
|
| 4159 | + if ($libelle === null) { |
|
| 4160 | + $libelle = $url; |
|
| 4161 | + } |
|
| 4162 | + |
|
| 4163 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4164 | 4164 | } |
| 4165 | 4165 | |
| 4166 | 4166 | |
@@ -4177,39 +4177,39 @@ discard block |
||
| 4177 | 4177 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4178 | 4178 | */ |
| 4179 | 4179 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4180 | - static $local_singulier_ou_pluriel = []; |
|
| 4181 | - |
|
| 4182 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4183 | - if (!is_numeric($nb) || $nb == 0) { |
|
| 4184 | - return ''; |
|
| 4185 | - } |
|
| 4186 | - if (!is_array($vars)) { |
|
| 4187 | - return ''; |
|
| 4188 | - } |
|
| 4189 | - |
|
| 4190 | - $langue = $GLOBALS['spip_lang']; |
|
| 4191 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4192 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4193 | - if ( |
|
| 4194 | - ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4195 | - || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4196 | - ) { |
|
| 4197 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4198 | - } |
|
| 4199 | - } |
|
| 4200 | - |
|
| 4201 | - // si on a une surcharge on l'utilise |
|
| 4202 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4203 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4204 | - } |
|
| 4205 | - |
|
| 4206 | - // sinon traitement par defaut |
|
| 4207 | - $vars[$var] = $nb; |
|
| 4208 | - if ($nb >= 2) { |
|
| 4209 | - return _T($chaine_plusieurs, $vars); |
|
| 4210 | - } else { |
|
| 4211 | - return _T($chaine_un, $vars); |
|
| 4212 | - } |
|
| 4180 | + static $local_singulier_ou_pluriel = []; |
|
| 4181 | + |
|
| 4182 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4183 | + if (!is_numeric($nb) || $nb == 0) { |
|
| 4184 | + return ''; |
|
| 4185 | + } |
|
| 4186 | + if (!is_array($vars)) { |
|
| 4187 | + return ''; |
|
| 4188 | + } |
|
| 4189 | + |
|
| 4190 | + $langue = $GLOBALS['spip_lang']; |
|
| 4191 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4192 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4193 | + if ( |
|
| 4194 | + ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)) |
|
| 4195 | + || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true)) |
|
| 4196 | + ) { |
|
| 4197 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4198 | + } |
|
| 4199 | + } |
|
| 4200 | + |
|
| 4201 | + // si on a une surcharge on l'utilise |
|
| 4202 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4203 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4204 | + } |
|
| 4205 | + |
|
| 4206 | + // sinon traitement par defaut |
|
| 4207 | + $vars[$var] = $nb; |
|
| 4208 | + if ($nb >= 2) { |
|
| 4209 | + return _T($chaine_plusieurs, $vars); |
|
| 4210 | + } else { |
|
| 4211 | + return _T($chaine_un, $vars); |
|
| 4212 | + } |
|
| 4213 | 4213 | } |
| 4214 | 4214 | |
| 4215 | 4215 | |
@@ -4237,71 +4237,71 @@ discard block |
||
| 4237 | 4237 | */ |
| 4238 | 4238 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4239 | 4239 | |
| 4240 | - $class_lien = $class_bouton = $class; |
|
| 4241 | - |
|
| 4242 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4243 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4244 | - $class_lien .= ' danger'; |
|
| 4245 | - $class_bouton .= ' btn_danger'; |
|
| 4246 | - } elseif ($fonction == 'rien.gif') { |
|
| 4247 | - $fonction = ''; |
|
| 4248 | - } elseif ($fonction == 'delsafe') { |
|
| 4249 | - $fonction = 'del'; |
|
| 4250 | - } |
|
| 4251 | - |
|
| 4252 | - $fond_origine = $fond; |
|
| 4253 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4254 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4255 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4256 | - } |
|
| 4257 | - |
|
| 4258 | - // Ajouter le type d'objet dans la classe |
|
| 4259 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4260 | - $class_lien .= " $objet_type"; |
|
| 4261 | - $class_bouton .= " $objet_type"; |
|
| 4262 | - |
|
| 4263 | - // texte |
|
| 4264 | - $alt = attribut_html($texte); |
|
| 4265 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4266 | - |
|
| 4267 | - // Liens : préparer les classes ajax |
|
| 4268 | - $ajax = ''; |
|
| 4269 | - if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4270 | - $ajax = 'ajax'; |
|
| 4271 | - if (str_contains($class_lien, 'preload')) { |
|
| 4272 | - $ajax .= ' preload'; |
|
| 4273 | - } |
|
| 4274 | - if (str_contains($class_lien, 'nocache')) { |
|
| 4275 | - $ajax .= ' nocache'; |
|
| 4276 | - } |
|
| 4277 | - $ajax = " class='$ajax'"; |
|
| 4278 | - } |
|
| 4279 | - |
|
| 4280 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4281 | - $size = 24; |
|
| 4282 | - if ( |
|
| 4283 | - preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4284 | - || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4285 | - ) { |
|
| 4286 | - $size = $match[1]; |
|
| 4287 | - } |
|
| 4288 | - $class_lien .= " s$size"; |
|
| 4289 | - $class_bouton .= " s$size"; |
|
| 4290 | - |
|
| 4291 | - // Icône |
|
| 4292 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4293 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4294 | - |
|
| 4295 | - // Markup final |
|
| 4296 | - if ($type == 'lien') { |
|
| 4297 | - return "<span class='icone $class_lien'>" |
|
| 4298 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4299 | - . $icone |
|
| 4300 | - . "<b>$texte</b>" |
|
| 4301 | - . "</a></span>\n"; |
|
| 4302 | - } else { |
|
| 4303 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4304 | - } |
|
| 4240 | + $class_lien = $class_bouton = $class; |
|
| 4241 | + |
|
| 4242 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4243 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4244 | + $class_lien .= ' danger'; |
|
| 4245 | + $class_bouton .= ' btn_danger'; |
|
| 4246 | + } elseif ($fonction == 'rien.gif') { |
|
| 4247 | + $fonction = ''; |
|
| 4248 | + } elseif ($fonction == 'delsafe') { |
|
| 4249 | + $fonction = 'del'; |
|
| 4250 | + } |
|
| 4251 | + |
|
| 4252 | + $fond_origine = $fond; |
|
| 4253 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4254 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4255 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4256 | + } |
|
| 4257 | + |
|
| 4258 | + // Ajouter le type d'objet dans la classe |
|
| 4259 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4260 | + $class_lien .= " $objet_type"; |
|
| 4261 | + $class_bouton .= " $objet_type"; |
|
| 4262 | + |
|
| 4263 | + // texte |
|
| 4264 | + $alt = attribut_html($texte); |
|
| 4265 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4266 | + |
|
| 4267 | + // Liens : préparer les classes ajax |
|
| 4268 | + $ajax = ''; |
|
| 4269 | + if ($type === 'lien' && str_contains($class_lien, 'ajax')) { |
|
| 4270 | + $ajax = 'ajax'; |
|
| 4271 | + if (str_contains($class_lien, 'preload')) { |
|
| 4272 | + $ajax .= ' preload'; |
|
| 4273 | + } |
|
| 4274 | + if (str_contains($class_lien, 'nocache')) { |
|
| 4275 | + $ajax .= ' nocache'; |
|
| 4276 | + } |
|
| 4277 | + $ajax = " class='$ajax'"; |
|
| 4278 | + } |
|
| 4279 | + |
|
| 4280 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4281 | + $size = 24; |
|
| 4282 | + if ( |
|
| 4283 | + preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4284 | + || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4285 | + ) { |
|
| 4286 | + $size = $match[1]; |
|
| 4287 | + } |
|
| 4288 | + $class_lien .= " s$size"; |
|
| 4289 | + $class_bouton .= " s$size"; |
|
| 4290 | + |
|
| 4291 | + // Icône |
|
| 4292 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4293 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4294 | + |
|
| 4295 | + // Markup final |
|
| 4296 | + if ($type == 'lien') { |
|
| 4297 | + return "<span class='icone $class_lien'>" |
|
| 4298 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4299 | + . $icone |
|
| 4300 | + . "<b>$texte</b>" |
|
| 4301 | + . "</a></span>\n"; |
|
| 4302 | + } else { |
|
| 4303 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4304 | + } |
|
| 4305 | 4305 | } |
| 4306 | 4306 | |
| 4307 | 4307 | /** |
@@ -4325,7 +4325,7 @@ discard block |
||
| 4325 | 4325 | * Code HTML du lien |
| 4326 | 4326 | **/ |
| 4327 | 4327 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4328 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4328 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4329 | 4329 | } |
| 4330 | 4330 | |
| 4331 | 4331 | /** |
@@ -4360,7 +4360,7 @@ discard block |
||
| 4360 | 4360 | * Code HTML du lien |
| 4361 | 4361 | **/ |
| 4362 | 4362 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4363 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4363 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4364 | 4364 | } |
| 4365 | 4365 | |
| 4366 | 4366 | /** |
@@ -4405,7 +4405,7 @@ discard block |
||
| 4405 | 4405 | * Code HTML du lien |
| 4406 | 4406 | **/ |
| 4407 | 4407 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4408 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4408 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4409 | 4409 | } |
| 4410 | 4410 | |
| 4411 | 4411 | /** |
@@ -4436,7 +4436,7 @@ discard block |
||
| 4436 | 4436 | * Code HTML du lien |
| 4437 | 4437 | **/ |
| 4438 | 4438 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4439 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4439 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4440 | 4440 | } |
| 4441 | 4441 | |
| 4442 | 4442 | /** |
@@ -4467,7 +4467,7 @@ discard block |
||
| 4467 | 4467 | * Code HTML du lien |
| 4468 | 4468 | */ |
| 4469 | 4469 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4470 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4470 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4471 | 4471 | } |
| 4472 | 4472 | |
| 4473 | 4473 | |
@@ -4489,7 +4489,7 @@ discard block |
||
| 4489 | 4489 | * @return array Liste des éléments |
| 4490 | 4490 | */ |
| 4491 | 4491 | function filtre_explode_dist($a, $b) { |
| 4492 | - return explode($b, (string) $a); |
|
| 4492 | + return explode($b, (string) $a); |
|
| 4493 | 4493 | } |
| 4494 | 4494 | |
| 4495 | 4495 | /** |
@@ -4510,7 +4510,7 @@ discard block |
||
| 4510 | 4510 | * @return string texte |
| 4511 | 4511 | */ |
| 4512 | 4512 | function filtre_implode_dist($a, $b) { |
| 4513 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4513 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4514 | 4514 | } |
| 4515 | 4515 | |
| 4516 | 4516 | /** |
@@ -4519,22 +4519,22 @@ discard block |
||
| 4519 | 4519 | * @return string Code CSS |
| 4520 | 4520 | */ |
| 4521 | 4521 | function bando_images_background() { |
| 4522 | - include_spip('inc/bandeau'); |
|
| 4523 | - // recuperer tous les boutons et leurs images |
|
| 4524 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4522 | + include_spip('inc/bandeau'); |
|
| 4523 | + // recuperer tous les boutons et leurs images |
|
| 4524 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4525 | 4525 | |
| 4526 | - $res = ''; |
|
| 4527 | - foreach ($boutons as $page => $detail) { |
|
| 4528 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4529 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4530 | - if ($sousdetail->icone && strlen(trim($sousdetail->icone))) { |
|
| 4531 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4532 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4533 | - } |
|
| 4534 | - } |
|
| 4535 | - } |
|
| 4526 | + $res = ''; |
|
| 4527 | + foreach ($boutons as $page => $detail) { |
|
| 4528 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4529 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4530 | + if ($sousdetail->icone && strlen(trim($sousdetail->icone))) { |
|
| 4531 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4532 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4533 | + } |
|
| 4534 | + } |
|
| 4535 | + } |
|
| 4536 | 4536 | |
| 4537 | - return $res; |
|
| 4537 | + return $res; |
|
| 4538 | 4538 | } |
| 4539 | 4539 | |
| 4540 | 4540 | /** |
@@ -4559,23 +4559,23 @@ discard block |
||
| 4559 | 4559 | */ |
| 4560 | 4560 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4561 | 4561 | |
| 4562 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4563 | - $class_form = ''; |
|
| 4564 | - if (str_contains($class, 'ajax')) { |
|
| 4565 | - $class_form = 'ajax'; |
|
| 4566 | - $class = str_replace('ajax', '', $class); |
|
| 4567 | - } |
|
| 4568 | - $class_btn = 'submit ' . trim($class); |
|
| 4562 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4563 | + $class_form = ''; |
|
| 4564 | + if (str_contains($class, 'ajax')) { |
|
| 4565 | + $class_form = 'ajax'; |
|
| 4566 | + $class = str_replace('ajax', '', $class); |
|
| 4567 | + } |
|
| 4568 | + $class_btn = 'submit ' . trim($class); |
|
| 4569 | 4569 | |
| 4570 | - if ($confirm) { |
|
| 4571 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4572 | - $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4573 | - } |
|
| 4574 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4575 | - $title = $title ? " title='$title'" : ''; |
|
| 4570 | + if ($confirm) { |
|
| 4571 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4572 | + $callback = $callback ? "$confirm?($callback):false" : $confirm; |
|
| 4573 | + } |
|
| 4574 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4575 | + $title = $title ? " title='$title'" : ''; |
|
| 4576 | 4576 | |
| 4577 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4578 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4577 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4578 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4579 | 4579 | } |
| 4580 | 4580 | |
| 4581 | 4581 | /** |
@@ -4598,98 +4598,98 @@ discard block |
||
| 4598 | 4598 | * @return string |
| 4599 | 4599 | */ |
| 4600 | 4600 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4601 | - static $trouver_table = null; |
|
| 4602 | - static $objets; |
|
| 4603 | - |
|
| 4604 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4605 | - $id_objet = (int) $id_objet; |
|
| 4606 | - if (!($id_objet && $type_objet && $info)) { |
|
| 4607 | - return ''; |
|
| 4608 | - } |
|
| 4609 | - |
|
| 4610 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4611 | - if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4612 | - return ''; |
|
| 4613 | - } |
|
| 4614 | - |
|
| 4615 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4616 | - if ($info == 'url') { |
|
| 4617 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4618 | - } |
|
| 4619 | - |
|
| 4620 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4621 | - $demande_titre = ($info === 'titre'); |
|
| 4622 | - $demande_introduction = ($info === 'introduction'); |
|
| 4623 | - |
|
| 4624 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4625 | - if ( |
|
| 4626 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4627 | - || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4628 | - ) { |
|
| 4629 | - if (!$trouver_table) { |
|
| 4630 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4631 | - } |
|
| 4632 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4633 | - if (!$desc) { |
|
| 4634 | - return $objets[$type_objet] = false; |
|
| 4635 | - } |
|
| 4636 | - |
|
| 4637 | - // Si on demande le titre, on le gere en interne |
|
| 4638 | - $champ_titre = ''; |
|
| 4639 | - if ($demande_titre) { |
|
| 4640 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4641 | - $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4642 | - } |
|
| 4643 | - include_spip('base/abstract_sql'); |
|
| 4644 | - include_spip('base/connect_sql'); |
|
| 4645 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4646 | - '*' . $champ_titre, |
|
| 4647 | - $desc['table_sql'], |
|
| 4648 | - id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4649 | - ); |
|
| 4650 | - |
|
| 4651 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4652 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4653 | - } |
|
| 4654 | - |
|
| 4655 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4656 | - // ajouter la longueur au début des params supplémentaires |
|
| 4657 | - if ($demande_introduction) { |
|
| 4658 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4659 | - array_unshift($params, $introduction_longueur); |
|
| 4660 | - } |
|
| 4661 | - |
|
| 4662 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4663 | - if ( |
|
| 4664 | - ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) |
|
| 4665 | - || ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) |
|
| 4666 | - ) { |
|
| 4667 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4668 | - } |
|
| 4669 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4670 | - elseif ( |
|
| 4671 | - ($generer = charger_fonction("generer_objet_{$info}", '', true)) |
|
| 4672 | - || ($generer = charger_fonction("generer_{$info}_entite", '', true)) |
|
| 4673 | - ) { |
|
| 4674 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4675 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4676 | - else { |
|
| 4677 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4678 | - } |
|
| 4679 | - |
|
| 4680 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4681 | - if (!$etoile) { |
|
| 4682 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4683 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4684 | - $info_generee = appliquer_traitement_champ( |
|
| 4685 | - $info_generee, |
|
| 4686 | - $info, |
|
| 4687 | - table_objet($type_objet), |
|
| 4688 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4689 | - ); |
|
| 4690 | - } |
|
| 4691 | - |
|
| 4692 | - return $info_generee; |
|
| 4601 | + static $trouver_table = null; |
|
| 4602 | + static $objets; |
|
| 4603 | + |
|
| 4604 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4605 | + $id_objet = (int) $id_objet; |
|
| 4606 | + if (!($id_objet && $type_objet && $info)) { |
|
| 4607 | + return ''; |
|
| 4608 | + } |
|
| 4609 | + |
|
| 4610 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4611 | + if (isset($objets[$type_objet]) && $objets[$type_objet] === false) { |
|
| 4612 | + return ''; |
|
| 4613 | + } |
|
| 4614 | + |
|
| 4615 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4616 | + if ($info == 'url') { |
|
| 4617 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4618 | + } |
|
| 4619 | + |
|
| 4620 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4621 | + $demande_titre = ($info === 'titre'); |
|
| 4622 | + $demande_introduction = ($info === 'introduction'); |
|
| 4623 | + |
|
| 4624 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4625 | + if ( |
|
| 4626 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4627 | + || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre']) |
|
| 4628 | + ) { |
|
| 4629 | + if (!$trouver_table) { |
|
| 4630 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4631 | + } |
|
| 4632 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4633 | + if (!$desc) { |
|
| 4634 | + return $objets[$type_objet] = false; |
|
| 4635 | + } |
|
| 4636 | + |
|
| 4637 | + // Si on demande le titre, on le gere en interne |
|
| 4638 | + $champ_titre = ''; |
|
| 4639 | + if ($demande_titre) { |
|
| 4640 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4641 | + $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4642 | + } |
|
| 4643 | + include_spip('base/abstract_sql'); |
|
| 4644 | + include_spip('base/connect_sql'); |
|
| 4645 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4646 | + '*' . $champ_titre, |
|
| 4647 | + $desc['table_sql'], |
|
| 4648 | + id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4649 | + ); |
|
| 4650 | + |
|
| 4651 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4652 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4653 | + } |
|
| 4654 | + |
|
| 4655 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4656 | + // ajouter la longueur au début des params supplémentaires |
|
| 4657 | + if ($demande_introduction) { |
|
| 4658 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4659 | + array_unshift($params, $introduction_longueur); |
|
| 4660 | + } |
|
| 4661 | + |
|
| 4662 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4663 | + if ( |
|
| 4664 | + ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) |
|
| 4665 | + || ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) |
|
| 4666 | + ) { |
|
| 4667 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4668 | + } |
|
| 4669 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4670 | + elseif ( |
|
| 4671 | + ($generer = charger_fonction("generer_objet_{$info}", '', true)) |
|
| 4672 | + || ($generer = charger_fonction("generer_{$info}_entite", '', true)) |
|
| 4673 | + ) { |
|
| 4674 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4675 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4676 | + else { |
|
| 4677 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4678 | + } |
|
| 4679 | + |
|
| 4680 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4681 | + if (!$etoile) { |
|
| 4682 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4683 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4684 | + $info_generee = appliquer_traitement_champ( |
|
| 4685 | + $info_generee, |
|
| 4686 | + $info, |
|
| 4687 | + table_objet($type_objet), |
|
| 4688 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4689 | + ); |
|
| 4690 | + } |
|
| 4691 | + |
|
| 4692 | + return $info_generee; |
|
| 4693 | 4693 | } |
| 4694 | 4694 | |
| 4695 | 4695 | /** |
@@ -4697,7 +4697,7 @@ discard block |
||
| 4697 | 4697 | * @see generer_objet_info |
| 4698 | 4698 | */ |
| 4699 | 4699 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4700 | - return generer_objet_info((int) $id_objet, $type_objet, $info, $etoile, $params); |
|
| 4700 | + return generer_objet_info((int) $id_objet, $type_objet, $info, $etoile, $params); |
|
| 4701 | 4701 | } |
| 4702 | 4702 | |
| 4703 | 4703 | /** |
@@ -4730,34 +4730,34 @@ discard block |
||
| 4730 | 4730 | */ |
| 4731 | 4731 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4732 | 4732 | |
| 4733 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4734 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4735 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4736 | - if (isset($ligne_sql['chapo'])) { |
|
| 4737 | - $chapo = $ligne_sql['chapo']; |
|
| 4738 | - $texte = strlen($descriptif) ? |
|
| 4739 | - '' : |
|
| 4740 | - "$chapo \n\n $texte"; |
|
| 4741 | - } |
|
| 4733 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4734 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4735 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4736 | + if (isset($ligne_sql['chapo'])) { |
|
| 4737 | + $chapo = $ligne_sql['chapo']; |
|
| 4738 | + $texte = strlen($descriptif) ? |
|
| 4739 | + '' : |
|
| 4740 | + "$chapo \n\n $texte"; |
|
| 4741 | + } |
|
| 4742 | 4742 | |
| 4743 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4744 | - if (!(int) $longueur_ou_suite) { |
|
| 4745 | - $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4746 | - } else { |
|
| 4747 | - $longueur = (int) $longueur_ou_suite; |
|
| 4748 | - } |
|
| 4743 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4744 | + if (!(int) $longueur_ou_suite) { |
|
| 4745 | + $longueur = (int) ($introduction_longueur ?: 600); |
|
| 4746 | + } else { |
|
| 4747 | + $longueur = (int) $longueur_ou_suite; |
|
| 4748 | + } |
|
| 4749 | 4749 | |
| 4750 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4751 | - // Ex : #INTRODUCTION{...} |
|
| 4752 | - if ( |
|
| 4753 | - is_null($suite) && !(int) $longueur_ou_suite |
|
| 4754 | - ) { |
|
| 4755 | - $suite = $longueur_ou_suite; |
|
| 4756 | - } |
|
| 4750 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4751 | + // Ex : #INTRODUCTION{...} |
|
| 4752 | + if ( |
|
| 4753 | + is_null($suite) && !(int) $longueur_ou_suite |
|
| 4754 | + ) { |
|
| 4755 | + $suite = $longueur_ou_suite; |
|
| 4756 | + } |
|
| 4757 | 4757 | |
| 4758 | - $f = chercher_filtre('introduction'); |
|
| 4758 | + $f = chercher_filtre('introduction'); |
|
| 4759 | 4759 | |
| 4760 | - return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4760 | + return $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4761 | 4761 | } |
| 4762 | 4762 | |
| 4763 | 4763 | /** |
@@ -4765,7 +4765,7 @@ discard block |
||
| 4765 | 4765 | * @see generer_objet_introduction |
| 4766 | 4766 | */ |
| 4767 | 4767 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4768 | - return generer_objet_introduction((int) $id_objet, $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4768 | + return generer_objet_introduction((int) $id_objet, $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4769 | 4769 | } |
| 4770 | 4770 | |
| 4771 | 4771 | /** |
@@ -4778,49 +4778,49 @@ discard block |
||
| 4778 | 4778 | * @return string |
| 4779 | 4779 | */ |
| 4780 | 4780 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4781 | - if (!$champ) { |
|
| 4782 | - return $texte; |
|
| 4783 | - } |
|
| 4781 | + if (!$champ) { |
|
| 4782 | + return $texte; |
|
| 4783 | + } |
|
| 4784 | 4784 | |
| 4785 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4786 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4787 | - include_fichiers_fonctions(); |
|
| 4785 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4786 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4787 | + include_fichiers_fonctions(); |
|
| 4788 | 4788 | |
| 4789 | - $champ = strtoupper($champ); |
|
| 4790 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4791 | - if (!$traitements || !is_array($traitements)) { |
|
| 4792 | - return $texte; |
|
| 4793 | - } |
|
| 4789 | + $champ = strtoupper($champ); |
|
| 4790 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4791 | + if (!$traitements || !is_array($traitements)) { |
|
| 4792 | + return $texte; |
|
| 4793 | + } |
|
| 4794 | 4794 | |
| 4795 | - $traitement = ''; |
|
| 4796 | - if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4797 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4798 | - $table_objet = table_objet($table_objet); |
|
| 4799 | - if (isset($traitements[$table_objet])) { |
|
| 4800 | - $traitement = $traitements[$table_objet]; |
|
| 4801 | - } |
|
| 4802 | - } |
|
| 4803 | - if (!$traitement && isset($traitements[0])) { |
|
| 4804 | - $traitement = $traitements[0]; |
|
| 4805 | - } |
|
| 4806 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4795 | + $traitement = ''; |
|
| 4796 | + if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) { |
|
| 4797 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4798 | + $table_objet = table_objet($table_objet); |
|
| 4799 | + if (isset($traitements[$table_objet])) { |
|
| 4800 | + $traitement = $traitements[$table_objet]; |
|
| 4801 | + } |
|
| 4802 | + } |
|
| 4803 | + if (!$traitement && isset($traitements[0])) { |
|
| 4804 | + $traitement = $traitements[0]; |
|
| 4805 | + } |
|
| 4806 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4807 | 4807 | |
| 4808 | - if (!$traitement) { |
|
| 4809 | - return $texte; |
|
| 4810 | - } |
|
| 4808 | + if (!$traitement) { |
|
| 4809 | + return $texte; |
|
| 4810 | + } |
|
| 4811 | 4811 | |
| 4812 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4812 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4813 | 4813 | |
| 4814 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4815 | - if (test_espace_prive()) { |
|
| 4816 | - $env['espace_prive'] = 1; |
|
| 4817 | - } |
|
| 4814 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4815 | + if (test_espace_prive()) { |
|
| 4816 | + $env['espace_prive'] = 1; |
|
| 4817 | + } |
|
| 4818 | 4818 | |
| 4819 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4820 | - $Pile = [0 => $env]; |
|
| 4821 | - eval("\$texte = $traitement;"); |
|
| 4819 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4820 | + $Pile = [0 => $env]; |
|
| 4821 | + eval("\$texte = $traitement;"); |
|
| 4822 | 4822 | |
| 4823 | - return $texte; |
|
| 4823 | + return $texte; |
|
| 4824 | 4824 | } |
| 4825 | 4825 | |
| 4826 | 4826 | |
@@ -4831,21 +4831,21 @@ discard block |
||
| 4831 | 4831 | * @return string |
| 4832 | 4832 | */ |
| 4833 | 4833 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4834 | - include_spip('inc/liens'); |
|
| 4835 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4836 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4837 | - // le raccourcis n'est plus valide |
|
| 4838 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4839 | - // on essaye avec generer_info_entite ? |
|
| 4840 | - if (!strlen($titre) && !$connect) { |
|
| 4841 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4842 | - } |
|
| 4843 | - if (!strlen($titre)) { |
|
| 4844 | - $titre = _T('info_sans_titre'); |
|
| 4845 | - } |
|
| 4846 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4834 | + include_spip('inc/liens'); |
|
| 4835 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4836 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4837 | + // le raccourcis n'est plus valide |
|
| 4838 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4839 | + // on essaye avec generer_info_entite ? |
|
| 4840 | + if (!strlen($titre) && !$connect) { |
|
| 4841 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4842 | + } |
|
| 4843 | + if (!strlen($titre)) { |
|
| 4844 | + $titre = _T('info_sans_titre'); |
|
| 4845 | + } |
|
| 4846 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4847 | 4847 | |
| 4848 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4848 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4849 | 4849 | } |
| 4850 | 4850 | |
| 4851 | 4851 | /** |
@@ -4853,7 +4853,7 @@ discard block |
||
| 4853 | 4853 | * @see generer_objet_lien |
| 4854 | 4854 | */ |
| 4855 | 4855 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4856 | - return generer_objet_lien((int) $id_objet, $objet, $longueur, $connect ?? ''); |
|
| 4856 | + return generer_objet_lien((int) $id_objet, $objet, $longueur, $connect ?? ''); |
|
| 4857 | 4857 | } |
| 4858 | 4858 | |
| 4859 | 4859 | /** |
@@ -4869,15 +4869,15 @@ discard block |
||
| 4869 | 4869 | * @return string |
| 4870 | 4870 | */ |
| 4871 | 4871 | function wrap($texte, $wrap) { |
| 4872 | - $balises = extraire_balises($wrap); |
|
| 4873 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4874 | - $texte = $wrap . $texte; |
|
| 4875 | - $regs = array_reverse($regs[1]); |
|
| 4876 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4877 | - $texte .= $wrap; |
|
| 4878 | - } |
|
| 4872 | + $balises = extraire_balises($wrap); |
|
| 4873 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4874 | + $texte = $wrap . $texte; |
|
| 4875 | + $regs = array_reverse($regs[1]); |
|
| 4876 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4877 | + $texte .= $wrap; |
|
| 4878 | + } |
|
| 4879 | 4879 | |
| 4880 | - return $texte; |
|
| 4880 | + return $texte; |
|
| 4881 | 4881 | } |
| 4882 | 4882 | |
| 4883 | 4883 | |
@@ -4897,42 +4897,42 @@ discard block |
||
| 4897 | 4897 | * @return array|mixed|string |
| 4898 | 4898 | */ |
| 4899 | 4899 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4900 | - if (is_string($u)) { |
|
| 4901 | - return typo($u); |
|
| 4902 | - } |
|
| 4903 | - |
|
| 4904 | - // caster $u en array si besoin |
|
| 4905 | - if (is_object($u)) { |
|
| 4906 | - $u = (array)$u; |
|
| 4907 | - } |
|
| 4908 | - |
|
| 4909 | - if (is_array($u)) { |
|
| 4910 | - $out = ''; |
|
| 4911 | - // toutes les cles sont numeriques ? |
|
| 4912 | - // et aucun enfant n'est un tableau |
|
| 4913 | - // liste simple separee par des virgules |
|
| 4914 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4915 | - $array_values = array_map('is_array', $u); |
|
| 4916 | - $object_values = array_map('is_object', $u); |
|
| 4917 | - if ( |
|
| 4918 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4919 | - && !array_sum($array_values) |
|
| 4920 | - && !array_sum($object_values) |
|
| 4921 | - ) { |
|
| 4922 | - return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4923 | - } |
|
| 4924 | - |
|
| 4925 | - // sinon on passe a la ligne et on indente |
|
| 4926 | - $i_str = str_pad('', $indent, ' '); |
|
| 4927 | - foreach ($u as $k => $v) { |
|
| 4928 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4929 | - } |
|
| 4930 | - |
|
| 4931 | - return $out; |
|
| 4932 | - } |
|
| 4933 | - |
|
| 4934 | - // on sait pas quoi faire... |
|
| 4935 | - return $u; |
|
| 4900 | + if (is_string($u)) { |
|
| 4901 | + return typo($u); |
|
| 4902 | + } |
|
| 4903 | + |
|
| 4904 | + // caster $u en array si besoin |
|
| 4905 | + if (is_object($u)) { |
|
| 4906 | + $u = (array)$u; |
|
| 4907 | + } |
|
| 4908 | + |
|
| 4909 | + if (is_array($u)) { |
|
| 4910 | + $out = ''; |
|
| 4911 | + // toutes les cles sont numeriques ? |
|
| 4912 | + // et aucun enfant n'est un tableau |
|
| 4913 | + // liste simple separee par des virgules |
|
| 4914 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4915 | + $array_values = array_map('is_array', $u); |
|
| 4916 | + $object_values = array_map('is_object', $u); |
|
| 4917 | + if ( |
|
| 4918 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4919 | + && !array_sum($array_values) |
|
| 4920 | + && !array_sum($object_values) |
|
| 4921 | + ) { |
|
| 4922 | + return implode(', ', array_map('filtre_print_dist', $u)); |
|
| 4923 | + } |
|
| 4924 | + |
|
| 4925 | + // sinon on passe a la ligne et on indente |
|
| 4926 | + $i_str = str_pad('', $indent, ' '); |
|
| 4927 | + foreach ($u as $k => $v) { |
|
| 4928 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4929 | + } |
|
| 4930 | + |
|
| 4931 | + return $out; |
|
| 4932 | + } |
|
| 4933 | + |
|
| 4934 | + // on sait pas quoi faire... |
|
| 4935 | + return $u; |
|
| 4936 | 4936 | } |
| 4937 | 4937 | |
| 4938 | 4938 | |
@@ -4945,10 +4945,10 @@ discard block |
||
| 4945 | 4945 | * @return string|array |
| 4946 | 4946 | */ |
| 4947 | 4947 | function objet_info($objet, $info) { |
| 4948 | - $table = table_objet_sql($objet); |
|
| 4949 | - $infos = lister_tables_objets_sql($table); |
|
| 4948 | + $table = table_objet_sql($objet); |
|
| 4949 | + $infos = lister_tables_objets_sql($table); |
|
| 4950 | 4950 | |
| 4951 | - return ($infos[$info] ?? ''); |
|
| 4951 | + return ($infos[$info] ?? ''); |
|
| 4952 | 4952 | } |
| 4953 | 4953 | |
| 4954 | 4954 | /** |
@@ -4963,11 +4963,11 @@ discard block |
||
| 4963 | 4963 | * texte traduit du comptage, tel que '3 articles' |
| 4964 | 4964 | */ |
| 4965 | 4965 | function objet_afficher_nb($nb, $objet) { |
| 4966 | - if (!$nb) { |
|
| 4967 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4968 | - } else { |
|
| 4969 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4970 | - } |
|
| 4966 | + if (!$nb) { |
|
| 4967 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4968 | + } else { |
|
| 4969 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 4970 | + } |
|
| 4971 | 4971 | } |
| 4972 | 4972 | |
| 4973 | 4973 | /** |
@@ -4979,11 +4979,11 @@ discard block |
||
| 4979 | 4979 | * @return string |
| 4980 | 4980 | */ |
| 4981 | 4981 | function objet_icone($objet, $taille = 24, $class = '') { |
| 4982 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4983 | - $icone = chemin_image($icone); |
|
| 4984 | - $balise_img = charger_filtre('balise_img'); |
|
| 4982 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4983 | + $icone = chemin_image($icone); |
|
| 4984 | + $balise_img = charger_filtre('balise_img'); |
|
| 4985 | 4985 | |
| 4986 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4986 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4987 | 4987 | } |
| 4988 | 4988 | |
| 4989 | 4989 | /** |
@@ -5004,12 +5004,12 @@ discard block |
||
| 5004 | 5004 | * @return string |
| 5005 | 5005 | */ |
| 5006 | 5006 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5007 | - $chaine = explode(':', $chaine); |
|
| 5008 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5009 | - return $t; |
|
| 5010 | - } |
|
| 5011 | - $chaine = implode(':', $chaine); |
|
| 5012 | - return _T($chaine, $args, $options); |
|
| 5007 | + $chaine = explode(':', $chaine); |
|
| 5008 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5009 | + return $t; |
|
| 5010 | + } |
|
| 5011 | + $chaine = implode(':', $chaine); |
|
| 5012 | + return _T($chaine, $args, $options); |
|
| 5013 | 5013 | } |
| 5014 | 5014 | |
| 5015 | 5015 | /** |
@@ -5023,18 +5023,18 @@ discard block |
||
| 5023 | 5023 | * @return string Code HTML |
| 5024 | 5024 | */ |
| 5025 | 5025 | function insert_head_css_conditionnel($flux) { |
| 5026 | - if ( |
|
| 5027 | - !str_contains($flux, '<!-- insert_head_css -->') |
|
| 5028 | - && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 5029 | - ) { |
|
| 5030 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5031 | - if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 5032 | - $p = $p1; |
|
| 5033 | - } |
|
| 5034 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5035 | - } |
|
| 5026 | + if ( |
|
| 5027 | + !str_contains($flux, '<!-- insert_head_css -->') |
|
| 5028 | + && ($p = strpos($flux, '<!-- insert_head -->')) |
|
| 5029 | + ) { |
|
| 5030 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5031 | + if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) { |
|
| 5032 | + $p = $p1; |
|
| 5033 | + } |
|
| 5034 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5035 | + } |
|
| 5036 | 5036 | |
| 5037 | - return $flux; |
|
| 5037 | + return $flux; |
|
| 5038 | 5038 | } |
| 5039 | 5039 | |
| 5040 | 5040 | /** |
@@ -5057,75 +5057,75 @@ discard block |
||
| 5057 | 5057 | * @return string |
| 5058 | 5058 | */ |
| 5059 | 5059 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5060 | - if (isset($contexte['format'])) { |
|
| 5061 | - $extension = $contexte['format']; |
|
| 5062 | - unset($contexte['format']); |
|
| 5063 | - } else { |
|
| 5064 | - $extension = 'html'; |
|
| 5065 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5066 | - $extension = $m[1]; |
|
| 5067 | - } |
|
| 5068 | - } |
|
| 5069 | - // recuperer le contenu produit par le squelette |
|
| 5070 | - $options['raw'] = true; |
|
| 5071 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5072 | - |
|
| 5073 | - // calculer le nom de la css |
|
| 5074 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5075 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5076 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5077 | - |
|
| 5078 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5079 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5080 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5081 | - if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 5082 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5083 | - } |
|
| 5084 | - else { |
|
| 5085 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5086 | - ksort($contexte); |
|
| 5087 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5088 | - } |
|
| 5089 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5090 | - |
|
| 5091 | - // mettre a jour le fichier si il n'existe pas |
|
| 5092 | - // ou trop ancien |
|
| 5093 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5094 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5095 | - if ( |
|
| 5096 | - !file_exists($filename) |
|
| 5097 | - || !file_exists($filename . '.last') |
|
| 5098 | - || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5099 | - || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5100 | - ) { |
|
| 5101 | - $contenu = $cache['texte']; |
|
| 5102 | - // passer les urls en absolu si c'est une css |
|
| 5103 | - if ($extension == 'css') { |
|
| 5104 | - $contenu = urls_absolues_css( |
|
| 5105 | - $contenu, |
|
| 5106 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5107 | - ); |
|
| 5108 | - } |
|
| 5109 | - |
|
| 5110 | - $comment = ''; |
|
| 5111 | - // ne pas insérer de commentaire sur certains formats |
|
| 5112 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5113 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5114 | - foreach ($contexte as $k => $v) { |
|
| 5115 | - if (is_array($v)) { |
|
| 5116 | - $v = var_export($v, true); |
|
| 5117 | - } |
|
| 5118 | - $comment .= ",$k=$v"; |
|
| 5119 | - } |
|
| 5120 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5121 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5122 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5123 | - } |
|
| 5124 | - // et ecrire le fichier si il change |
|
| 5125 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5126 | - } |
|
| 5127 | - |
|
| 5128 | - return timestamp($filename); |
|
| 5060 | + if (isset($contexte['format'])) { |
|
| 5061 | + $extension = $contexte['format']; |
|
| 5062 | + unset($contexte['format']); |
|
| 5063 | + } else { |
|
| 5064 | + $extension = 'html'; |
|
| 5065 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5066 | + $extension = $m[1]; |
|
| 5067 | + } |
|
| 5068 | + } |
|
| 5069 | + // recuperer le contenu produit par le squelette |
|
| 5070 | + $options['raw'] = true; |
|
| 5071 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5072 | + |
|
| 5073 | + // calculer le nom de la css |
|
| 5074 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5075 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5076 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5077 | + |
|
| 5078 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5079 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5080 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5081 | + if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
|
| 5082 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5083 | + } |
|
| 5084 | + else { |
|
| 5085 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5086 | + ksort($contexte); |
|
| 5087 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5088 | + } |
|
| 5089 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5090 | + |
|
| 5091 | + // mettre a jour le fichier si il n'existe pas |
|
| 5092 | + // ou trop ancien |
|
| 5093 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5094 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5095 | + if ( |
|
| 5096 | + !file_exists($filename) |
|
| 5097 | + || !file_exists($filename . '.last') |
|
| 5098 | + || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5099 | + || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
|
| 5100 | + ) { |
|
| 5101 | + $contenu = $cache['texte']; |
|
| 5102 | + // passer les urls en absolu si c'est une css |
|
| 5103 | + if ($extension == 'css') { |
|
| 5104 | + $contenu = urls_absolues_css( |
|
| 5105 | + $contenu, |
|
| 5106 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5107 | + ); |
|
| 5108 | + } |
|
| 5109 | + |
|
| 5110 | + $comment = ''; |
|
| 5111 | + // ne pas insérer de commentaire sur certains formats |
|
| 5112 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5113 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5114 | + foreach ($contexte as $k => $v) { |
|
| 5115 | + if (is_array($v)) { |
|
| 5116 | + $v = var_export($v, true); |
|
| 5117 | + } |
|
| 5118 | + $comment .= ",$k=$v"; |
|
| 5119 | + } |
|
| 5120 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5121 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5122 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5123 | + } |
|
| 5124 | + // et ecrire le fichier si il change |
|
| 5125 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5126 | + } |
|
| 5127 | + |
|
| 5128 | + return timestamp($filename); |
|
| 5129 | 5129 | } |
| 5130 | 5130 | |
| 5131 | 5131 | /** |
@@ -5138,11 +5138,11 @@ discard block |
||
| 5138 | 5138 | * $fichier auquel on a ajouté le timestamp |
| 5139 | 5139 | */ |
| 5140 | 5140 | function timestamp($fichier) { |
| 5141 | - if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5142 | - return $fichier; |
|
| 5143 | - } |
|
| 5141 | + if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) { |
|
| 5142 | + return $fichier; |
|
| 5143 | + } |
|
| 5144 | 5144 | |
| 5145 | - return "$fichier?$m"; |
|
| 5145 | + return "$fichier?$m"; |
|
| 5146 | 5146 | } |
| 5147 | 5147 | |
| 5148 | 5148 | /** |
@@ -5152,11 +5152,11 @@ discard block |
||
| 5152 | 5152 | * @return string |
| 5153 | 5153 | */ |
| 5154 | 5154 | function supprimer_timestamp($url) { |
| 5155 | - if (!str_contains($url, '?')) { |
|
| 5156 | - return $url; |
|
| 5157 | - } |
|
| 5155 | + if (!str_contains($url, '?')) { |
|
| 5156 | + return $url; |
|
| 5157 | + } |
|
| 5158 | 5158 | |
| 5159 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5159 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5160 | 5160 | } |
| 5161 | 5161 | |
| 5162 | 5162 | /** |
@@ -5171,15 +5171,15 @@ discard block |
||
| 5171 | 5171 | * @return string |
| 5172 | 5172 | */ |
| 5173 | 5173 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5174 | - include_spip('inc/envoyer_mail'); |
|
| 5174 | + include_spip('inc/envoyer_mail'); |
|
| 5175 | 5175 | |
| 5176 | - $titre = nettoyer_titre_email($titre); |
|
| 5177 | - // on est dans un squelette : securiser le retour |
|
| 5178 | - if (str_contains($titre, '<')) { |
|
| 5179 | - $titre = interdire_scripts($titre); |
|
| 5180 | - } |
|
| 5176 | + $titre = nettoyer_titre_email($titre); |
|
| 5177 | + // on est dans un squelette : securiser le retour |
|
| 5178 | + if (str_contains($titre, '<')) { |
|
| 5179 | + $titre = interdire_scripts($titre); |
|
| 5180 | + } |
|
| 5181 | 5181 | |
| 5182 | - return $titre; |
|
| 5182 | + return $titre; |
|
| 5183 | 5183 | } |
| 5184 | 5184 | |
| 5185 | 5185 | /** |
@@ -5201,27 +5201,27 @@ discard block |
||
| 5201 | 5201 | * @return string |
| 5202 | 5202 | */ |
| 5203 | 5203 | function filtre_chercher_rubrique_dist( |
| 5204 | - $titre, |
|
| 5205 | - $id_objet, |
|
| 5206 | - $id_parent, |
|
| 5207 | - $objet, |
|
| 5208 | - $id_secteur, |
|
| 5209 | - $restreint, |
|
| 5210 | - $actionable = false, |
|
| 5211 | - $retour_sans_cadre = false |
|
| 5204 | + $titre, |
|
| 5205 | + $id_objet, |
|
| 5206 | + $id_parent, |
|
| 5207 | + $objet, |
|
| 5208 | + $id_secteur, |
|
| 5209 | + $restreint, |
|
| 5210 | + $actionable = false, |
|
| 5211 | + $retour_sans_cadre = false |
|
| 5212 | 5212 | ) { |
| 5213 | - include_spip('inc/filtres_ecrire'); |
|
| 5213 | + include_spip('inc/filtres_ecrire'); |
|
| 5214 | 5214 | |
| 5215 | - return chercher_rubrique( |
|
| 5216 | - $titre, |
|
| 5217 | - $id_objet, |
|
| 5218 | - $id_parent, |
|
| 5219 | - $objet, |
|
| 5220 | - $id_secteur, |
|
| 5221 | - $restreint, |
|
| 5222 | - $actionable, |
|
| 5223 | - $retour_sans_cadre |
|
| 5224 | - ); |
|
| 5215 | + return chercher_rubrique( |
|
| 5216 | + $titre, |
|
| 5217 | + $id_objet, |
|
| 5218 | + $id_parent, |
|
| 5219 | + $objet, |
|
| 5220 | + $id_secteur, |
|
| 5221 | + $restreint, |
|
| 5222 | + $actionable, |
|
| 5223 | + $retour_sans_cadre |
|
| 5224 | + ); |
|
| 5225 | 5225 | } |
| 5226 | 5226 | |
| 5227 | 5227 | /** |
@@ -5250,56 +5250,56 @@ discard block |
||
| 5250 | 5250 | * Chaîne vide si l'accès est autorisé |
| 5251 | 5251 | */ |
| 5252 | 5252 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5253 | - if ($ok) { |
|
| 5254 | - return ''; |
|
| 5255 | - } |
|
| 5256 | - |
|
| 5257 | - // Vider tous les tampons |
|
| 5258 | - $level = @ob_get_level(); |
|
| 5259 | - while ($level--) { |
|
| 5260 | - @ob_end_clean(); |
|
| 5261 | - } |
|
| 5262 | - |
|
| 5263 | - include_spip('inc/headers'); |
|
| 5264 | - |
|
| 5265 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5266 | - if ($url) { |
|
| 5267 | - redirige_par_entete($url, '', $statut); |
|
| 5268 | - } |
|
| 5269 | - |
|
| 5270 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5271 | - if (!is_numeric($statut) && is_null($message)) { |
|
| 5272 | - $message = $statut; |
|
| 5273 | - $statut = 0; |
|
| 5274 | - } |
|
| 5275 | - if (!$message) { |
|
| 5276 | - $message = ''; |
|
| 5277 | - } |
|
| 5278 | - $statut = (int) $statut; |
|
| 5279 | - |
|
| 5280 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5281 | - if (test_espace_prive()) { |
|
| 5282 | - if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5283 | - $statut = 403; |
|
| 5284 | - } |
|
| 5285 | - http_response_code(403); |
|
| 5286 | - $echec = charger_fonction('403', 'exec'); |
|
| 5287 | - $echec($message); |
|
| 5288 | - } else { |
|
| 5289 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5290 | - if (!$statut) { |
|
| 5291 | - $statut = 404; |
|
| 5292 | - } |
|
| 5293 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5294 | - http_response_code($statut); |
|
| 5295 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5296 | - if ($statut >= 400) { |
|
| 5297 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5298 | - } |
|
| 5299 | - } |
|
| 5300 | - |
|
| 5301 | - |
|
| 5302 | - exit; |
|
| 5253 | + if ($ok) { |
|
| 5254 | + return ''; |
|
| 5255 | + } |
|
| 5256 | + |
|
| 5257 | + // Vider tous les tampons |
|
| 5258 | + $level = @ob_get_level(); |
|
| 5259 | + while ($level--) { |
|
| 5260 | + @ob_end_clean(); |
|
| 5261 | + } |
|
| 5262 | + |
|
| 5263 | + include_spip('inc/headers'); |
|
| 5264 | + |
|
| 5265 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5266 | + if ($url) { |
|
| 5267 | + redirige_par_entete($url, '', $statut); |
|
| 5268 | + } |
|
| 5269 | + |
|
| 5270 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5271 | + if (!is_numeric($statut) && is_null($message)) { |
|
| 5272 | + $message = $statut; |
|
| 5273 | + $statut = 0; |
|
| 5274 | + } |
|
| 5275 | + if (!$message) { |
|
| 5276 | + $message = ''; |
|
| 5277 | + } |
|
| 5278 | + $statut = (int) $statut; |
|
| 5279 | + |
|
| 5280 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5281 | + if (test_espace_prive()) { |
|
| 5282 | + if (!$statut || !in_array($statut, [404, 403])) { |
|
| 5283 | + $statut = 403; |
|
| 5284 | + } |
|
| 5285 | + http_response_code(403); |
|
| 5286 | + $echec = charger_fonction('403', 'exec'); |
|
| 5287 | + $echec($message); |
|
| 5288 | + } else { |
|
| 5289 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5290 | + if (!$statut) { |
|
| 5291 | + $statut = 404; |
|
| 5292 | + } |
|
| 5293 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5294 | + http_response_code($statut); |
|
| 5295 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5296 | + if ($statut >= 400) { |
|
| 5297 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5298 | + } |
|
| 5299 | + } |
|
| 5300 | + |
|
| 5301 | + |
|
| 5302 | + exit; |
|
| 5303 | 5303 | } |
| 5304 | 5304 | |
| 5305 | 5305 | /** |
@@ -5310,11 +5310,11 @@ discard block |
||
| 5310 | 5310 | * @return string |
| 5311 | 5311 | */ |
| 5312 | 5312 | function filtre_compacte_dist($source, $format = null) { |
| 5313 | - if (function_exists('minifier')) { |
|
| 5314 | - return minifier($source, $format); |
|
| 5315 | - } |
|
| 5313 | + if (function_exists('minifier')) { |
|
| 5314 | + return minifier($source, $format); |
|
| 5315 | + } |
|
| 5316 | 5316 | |
| 5317 | - return $source; |
|
| 5317 | + return $source; |
|
| 5318 | 5318 | } |
| 5319 | 5319 | |
| 5320 | 5320 | |
@@ -5324,32 +5324,32 @@ discard block |
||
| 5324 | 5324 | * @return string |
| 5325 | 5325 | */ |
| 5326 | 5326 | function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5327 | - $passe ??= ''; |
|
| 5328 | - $l = strlen($passe); |
|
| 5329 | - |
|
| 5330 | - if ($l <= 8 || !$afficher_partiellement) { |
|
| 5331 | - if (!$l) { |
|
| 5332 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5333 | - } |
|
| 5334 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5335 | - } |
|
| 5336 | - |
|
| 5337 | - if (is_null($portion_pourcent)) { |
|
| 5338 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5339 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5340 | - } |
|
| 5341 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5342 | - } |
|
| 5343 | - if ($portion_pourcent >= 100) { |
|
| 5344 | - return $passe; |
|
| 5345 | - } |
|
| 5346 | - $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5347 | - $e = max($e, 0); |
|
| 5348 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5349 | - if ($e > 0 && strlen($mid) > 8) { |
|
| 5350 | - $mid = '***...***'; |
|
| 5351 | - } |
|
| 5352 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5327 | + $passe ??= ''; |
|
| 5328 | + $l = strlen($passe); |
|
| 5329 | + |
|
| 5330 | + if ($l <= 8 || !$afficher_partiellement) { |
|
| 5331 | + if (!$l) { |
|
| 5332 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5333 | + } |
|
| 5334 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5335 | + } |
|
| 5336 | + |
|
| 5337 | + if (is_null($portion_pourcent)) { |
|
| 5338 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5339 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5340 | + } |
|
| 5341 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5342 | + } |
|
| 5343 | + if ($portion_pourcent >= 100) { |
|
| 5344 | + return $passe; |
|
| 5345 | + } |
|
| 5346 | + $e = (int) ceil($l * $portion_pourcent / 100 / 2); |
|
| 5347 | + $e = max($e, 0); |
|
| 5348 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5349 | + if ($e > 0 && strlen($mid) > 8) { |
|
| 5350 | + $mid = '***...***'; |
|
| 5351 | + } |
|
| 5352 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5353 | 5353 | } |
| 5354 | 5354 | |
| 5355 | 5355 | |
@@ -5370,64 +5370,64 @@ discard block |
||
| 5370 | 5370 | */ |
| 5371 | 5371 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5372 | 5372 | |
| 5373 | - $original = $texte; |
|
| 5374 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5375 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5376 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5373 | + $original = $texte; |
|
| 5374 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5375 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5376 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5377 | 5377 | |
| 5378 | - if (!function_exists('translitteration')) { |
|
| 5379 | - include_spip('inc/charsets'); |
|
| 5380 | - } |
|
| 5378 | + if (!function_exists('translitteration')) { |
|
| 5379 | + include_spip('inc/charsets'); |
|
| 5380 | + } |
|
| 5381 | 5381 | |
| 5382 | - // pas de balise html |
|
| 5383 | - if (str_contains($texte, '<')) { |
|
| 5384 | - $texte = strip_tags($texte); |
|
| 5385 | - } |
|
| 5386 | - if (str_contains($texte, '&')) { |
|
| 5387 | - $texte = unicode2charset($texte); |
|
| 5388 | - } |
|
| 5389 | - // On enlève les espaces indésirables |
|
| 5390 | - $texte = trim($texte); |
|
| 5382 | + // pas de balise html |
|
| 5383 | + if (str_contains($texte, '<')) { |
|
| 5384 | + $texte = strip_tags($texte); |
|
| 5385 | + } |
|
| 5386 | + if (str_contains($texte, '&')) { |
|
| 5387 | + $texte = unicode2charset($texte); |
|
| 5388 | + } |
|
| 5389 | + // On enlève les espaces indésirables |
|
| 5390 | + $texte = trim($texte); |
|
| 5391 | 5391 | |
| 5392 | - // On enlève les accents et cie |
|
| 5393 | - $texte = translitteration($texte); |
|
| 5392 | + // On enlève les accents et cie |
|
| 5393 | + $texte = translitteration($texte); |
|
| 5394 | 5394 | |
| 5395 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5396 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5395 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5396 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5397 | 5397 | |
| 5398 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5399 | - while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5400 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5401 | - } |
|
| 5398 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5399 | + while (str_contains($texte, (string) "$separateur$separateur")) { |
|
| 5400 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5401 | + } |
|
| 5402 | 5402 | |
| 5403 | - // pas de separateur au debut ni a la fin |
|
| 5404 | - $texte = trim($texte, $separateur); |
|
| 5403 | + // pas de separateur au debut ni a la fin |
|
| 5404 | + $texte = trim($texte, $separateur); |
|
| 5405 | 5405 | |
| 5406 | - // en minuscules |
|
| 5407 | - $texte = strtolower($texte); |
|
| 5406 | + // en minuscules |
|
| 5407 | + $texte = strtolower($texte); |
|
| 5408 | 5408 | |
| 5409 | - switch ($type) { |
|
| 5410 | - case 'class': |
|
| 5411 | - case 'id': |
|
| 5412 | - case 'anchor': |
|
| 5413 | - if (preg_match(',^\d,', $texte)) { |
|
| 5414 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5415 | - } |
|
| 5416 | - } |
|
| 5409 | + switch ($type) { |
|
| 5410 | + case 'class': |
|
| 5411 | + case 'id': |
|
| 5412 | + case 'anchor': |
|
| 5413 | + if (preg_match(',^\d,', $texte)) { |
|
| 5414 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5415 | + } |
|
| 5416 | + } |
|
| 5417 | 5417 | |
| 5418 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5419 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5420 | - } |
|
| 5418 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5419 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5420 | + } |
|
| 5421 | 5421 | |
| 5422 | - if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5423 | - if (preg_match(',^\d,', $texte)) { |
|
| 5424 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5425 | - } |
|
| 5426 | - $texte .= $separateur . md5($original); |
|
| 5427 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5428 | - } |
|
| 5422 | + if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
|
| 5423 | + if (preg_match(',^\d,', $texte)) { |
|
| 5424 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5425 | + } |
|
| 5426 | + $texte .= $separateur . md5($original); |
|
| 5427 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5428 | + } |
|
| 5429 | 5429 | |
| 5430 | - return $texte; |
|
| 5430 | + return $texte; |
|
| 5431 | 5431 | } |
| 5432 | 5432 | |
| 5433 | 5433 | |
@@ -5448,11 +5448,11 @@ discard block |
||
| 5448 | 5448 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5449 | 5449 | */ |
| 5450 | 5450 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5451 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5452 | - if ($ucfirst) { |
|
| 5453 | - $label = spip_ucfirst($label); |
|
| 5454 | - } |
|
| 5455 | - return $label; |
|
| 5451 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5452 | + if ($ucfirst) { |
|
| 5453 | + $label = spip_ucfirst($label); |
|
| 5454 | + } |
|
| 5455 | + return $label; |
|
| 5456 | 5456 | } |
| 5457 | 5457 | |
| 5458 | 5458 | /** |
@@ -5465,8 +5465,8 @@ discard block |
||
| 5465 | 5465 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5466 | 5466 | */ |
| 5467 | 5467 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5468 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5469 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5468 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5469 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5470 | 5470 | } |
| 5471 | 5471 | |
| 5472 | 5472 | |
@@ -5479,19 +5479,19 @@ discard block |
||
| 5479 | 5479 | * @return array |
| 5480 | 5480 | */ |
| 5481 | 5481 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5482 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5483 | - return []; |
|
| 5484 | - } |
|
| 5482 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5483 | + return []; |
|
| 5484 | + } |
|
| 5485 | 5485 | |
| 5486 | - // compatibilite signature inversee |
|
| 5487 | - if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5488 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5489 | - } |
|
| 5486 | + // compatibilite signature inversee |
|
| 5487 | + if (is_numeric($objet) && !is_numeric($id_objet)) { |
|
| 5488 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5489 | + } |
|
| 5490 | 5490 | |
| 5491 | - if (!function_exists($fonction)) { |
|
| 5492 | - include_spip('base/objets'); |
|
| 5493 | - } |
|
| 5494 | - return $fonction($objet, $id_objet); |
|
| 5491 | + if (!function_exists($fonction)) { |
|
| 5492 | + include_spip('base/objets'); |
|
| 5493 | + } |
|
| 5494 | + return $fonction($objet, $id_objet); |
|
| 5495 | 5495 | } |
| 5496 | 5496 | |
| 5497 | 5497 | |
@@ -5506,7 +5506,7 @@ discard block |
||
| 5506 | 5506 | * @return array |
| 5507 | 5507 | */ |
| 5508 | 5508 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5509 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5509 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5510 | 5510 | } |
| 5511 | 5511 | |
| 5512 | 5512 | /** |
@@ -5520,7 +5520,7 @@ discard block |
||
| 5520 | 5520 | * @return array |
| 5521 | 5521 | */ |
| 5522 | 5522 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5523 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5523 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5524 | 5524 | } |
| 5525 | 5525 | |
| 5526 | 5526 | /** |
@@ -5534,7 +5534,7 @@ discard block |
||
| 5534 | 5534 | * @return array |
| 5535 | 5535 | */ |
| 5536 | 5536 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5537 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5537 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5538 | 5538 | } |
| 5539 | 5539 | |
| 5540 | 5540 | /** |
@@ -5548,5 +5548,5 @@ discard block |
||
| 5548 | 5548 | * @return array |
| 5549 | 5549 | */ |
| 5550 | 5550 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5551 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5551 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5552 | 5552 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | include_fichiers_fonctions(); |
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 98 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 99 | 99 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 100 | 100 | if (is_callable($f)) { |
| 101 | 101 | return $f; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | // affichage "GIT [master: abcdef]" |
| 231 | 231 | $commit = $desc['commit_short'] ?? $desc['commit']; |
| 232 | 232 | if ($desc['branch']) { |
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 233 | + $commit = $desc['branch'].': '.$commit; |
|
| 234 | 234 | } |
| 235 | 235 | return "{$desc['vcs']} [$commit]"; |
| 236 | 236 | } |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // version installee par GIT |
| 254 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 254 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 255 | 255 | $currentHead = trim(substr($c, 4)); |
| 256 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 256 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 257 | 257 | return [ |
| 258 | 258 | 'vcs' => 'GIT', |
| 259 | 259 | 'branch' => basename($currentHead), |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 270 | 270 | // et laisser passer les fonctions personnelles baptisees image_... |
| 271 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 272 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 273 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 274 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 275 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 276 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 271 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 272 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 273 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 274 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 275 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 276 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 277 | 277 | |
| 278 | 278 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 279 | 279 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | function filtre_debug($val, $key = null) { |
| 434 | 434 | $debug = ( |
| 435 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 436 | - ) . var_export($val, true); |
|
| 435 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 436 | + ).var_export($val, true); |
|
| 437 | 437 | |
| 438 | 438 | include_spip('inc/autoriser'); |
| 439 | 439 | if (autoriser('webmestre')) { |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $is_file = false; |
| 490 | 490 | } |
| 491 | 491 | if ($is_file) { |
| 492 | - $is_local_file = function ($path) { |
|
| 492 | + $is_local_file = function($path) { |
|
| 493 | 493 | if (str_contains($path, '?')) { |
| 494 | 494 | $path = supprimer_timestamp($path); |
| 495 | 495 | // remove ?24px added by find_in_theme on .svg files |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match) |
| 538 | 538 | ) { |
| 539 | 539 | $srcover = $match[1]; |
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | + $srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args); |
|
| 541 | 541 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 542 | 542 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
| 543 | 543 | } |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | // " -> " et tout ce genre de choses |
| 937 | 937 | $u = $GLOBALS['meta']['pcre_u']; |
| 938 | 938 | $texte = str_replace(' ', ' ', $texte); |
| 939 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 939 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 940 | 940 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 941 | 941 | $texte = entites_html($texte, false, false); |
| 942 | 942 | // mais bien echapper les double quotes ! |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | return ''; |
| 999 | 999 | } |
| 1000 | 1000 | return preg_replace( |
| 1001 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1001 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1002 | 1002 | '', |
| 1003 | 1003 | $texte |
| 1004 | 1004 | ); |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | if ( |
| 1028 | 1028 | $texte |
| 1029 | 1029 | && preg_match( |
| 1030 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1030 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1031 | 1031 | $texte, |
| 1032 | 1032 | $regs |
| 1033 | 1033 | ) |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | **/ |
| 1117 | 1117 | function textebrut($texte) { |
| 1118 | 1118 | $u = $GLOBALS['meta']['pcre_u']; |
| 1119 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1119 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1120 | 1120 | $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte); |
| 1121 | 1121 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1122 | 1122 | $texte = preg_replace("/\n+$/", '', $texte); |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | ) |
| 1152 | 1152 | ) { |
| 1153 | 1153 | foreach ($liens[0] as $a) { |
| 1154 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1154 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1155 | 1155 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1156 | 1156 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1157 | 1157 | $texte = str_replace($a, $ablank, $texte); |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | foreach ($regs[0] as $a) { |
| 1177 | 1177 | $rel = extraire_attribut($a, 'rel') ?? ''; |
| 1178 | 1178 | if (!str_contains($rel, 'nofollow')) { |
| 1179 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1179 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1180 | 1180 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1181 | 1181 | $texte = str_replace($a, $anofollow, $texte); |
| 1182 | 1182 | } |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1207 | 1207 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1208 | 1208 | |
| 1209 | - return preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1209 | + return preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | |
@@ -1240,7 +1240,7 @@ discard block |
||
| 1240 | 1240 | return $texte; |
| 1241 | 1241 | } |
| 1242 | 1242 | include_spip('inc/texte'); |
| 1243 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1243 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1244 | 1244 | 'div' : 'span'; |
| 1245 | 1245 | |
| 1246 | 1246 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | |
| 1332 | 1332 | // Calcul de la taille et choix de l'unité |
| 1333 | 1333 | $affichage = _T( |
| 1334 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1334 | + 'spip:taille_'.$unites[$puissance].$suffixe_item, |
|
| 1335 | 1335 | [ |
| 1336 | 1336 | 'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance]) |
| 1337 | 1337 | ] |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | } |
| 1366 | 1366 | $u = $GLOBALS['meta']['pcre_u']; |
| 1367 | 1367 | if ($textebrut) { |
| 1368 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1368 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1369 | 1369 | } |
| 1370 | 1370 | $texte = texte_backend($texte); |
| 1371 | 1371 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | # un message pour abs_url |
| 1401 | 1401 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1402 | 1402 | $url = trim($url); |
| 1403 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1403 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1404 | 1404 | |
| 1405 | 1405 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1406 | 1406 | } |
@@ -1605,7 +1605,7 @@ discard block |
||
| 1605 | 1605 | |
| 1606 | 1606 | $debut = ''; |
| 1607 | 1607 | $suite = $texte; |
| 1608 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1608 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1609 | 1609 | $debut .= substr($suite, 0, $t - 1); |
| 1610 | 1610 | $suite = substr($suite, $t); |
| 1611 | 1611 | $car = substr($suite, 0, 1); |
@@ -1623,7 +1623,7 @@ discard block |
||
| 1623 | 1623 | $suite = substr($suite, strlen($regs[0])); |
| 1624 | 1624 | } |
| 1625 | 1625 | } |
| 1626 | - $texte = $debut . $suite; |
|
| 1626 | + $texte = $debut.$suite; |
|
| 1627 | 1627 | |
| 1628 | 1628 | if ($collecteurModeles) { |
| 1629 | 1629 | $texte = $collecteurModeles->retablir($texte); |
@@ -1631,7 +1631,7 @@ discard block |
||
| 1631 | 1631 | |
| 1632 | 1632 | $texte = echappe_retour($texte); |
| 1633 | 1633 | |
| 1634 | - return $texte . $fin; |
|
| 1634 | + return $texte.$fin; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | |
@@ -1900,7 +1900,7 @@ discard block |
||
| 1900 | 1900 | if (is_array($balise)) { |
| 1901 | 1901 | array_walk( |
| 1902 | 1902 | $balise, |
| 1903 | - function (&$a, $key, $t) { |
|
| 1903 | + function(&$a, $key, $t) { |
|
| 1904 | 1904 | $a = extraire_attribut($a, $t); |
| 1905 | 1905 | }, |
| 1906 | 1906 | $attribut |
@@ -1994,14 +1994,14 @@ discard block |
||
| 1994 | 1994 | |
| 1995 | 1995 | if ($old !== null) { |
| 1996 | 1996 | // Remplacer l'ancien attribut du meme nom |
| 1997 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1997 | + $balise = $r[1].$insert.$r[5]; |
|
| 1998 | 1998 | } else { |
| 1999 | 1999 | // preferer une balise " />" (comme <img />) |
| 2000 | 2000 | if (preg_match(',/>,', $balise)) { |
| 2001 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2001 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2002 | 2002 | } // sinon une balise <a ...> ... </a> |
| 2003 | 2003 | else { |
| 2004 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2004 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | } |
| 2007 | 2007 | |
@@ -2059,7 +2059,7 @@ discard block |
||
| 2059 | 2059 | in_array($operation, ['ajouter', 'commuter']) |
| 2060 | 2060 | && !$is_class_presente |
| 2061 | 2061 | ) { |
| 2062 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2062 | + $class_new = ltrim(rtrim($class_new ?? '').' '.$c); |
|
| 2063 | 2063 | } elseif ( |
| 2064 | 2064 | in_array($operation, ['supprimer', 'commuter']) |
| 2065 | 2065 | && $is_class_presente |
@@ -2129,7 +2129,7 @@ discard block |
||
| 2129 | 2129 | // Quelques fonctions de calcul arithmetique |
| 2130 | 2130 | // |
| 2131 | 2131 | function floatstr($a) { |
| 2132 | - return str_replace(',', '.', (string)(float) $a); |
|
| 2132 | + return str_replace(',', '.', (string) (float) $a); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | function strize($f, $a, $b) { |
| 2135 | 2135 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2270,13 +2270,13 @@ discard block |
||
| 2270 | 2270 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2271 | 2271 | define('_TAGS_NOM_AUTEUR', ''); |
| 2272 | 2272 | } |
| 2273 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2273 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2274 | 2274 | foreach ($tags_acceptes as $tag) { |
| 2275 | 2275 | if (strlen($tag)) { |
| 2276 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2277 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2278 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2279 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2276 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2277 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2278 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2279 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2280 | 2280 | } |
| 2281 | 2281 | } |
| 2282 | 2282 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2395,10 +2395,10 @@ discard block |
||
| 2395 | 2395 | $fichier = basename($url); |
| 2396 | 2396 | |
| 2397 | 2397 | return '<a rel="enclosure"' |
| 2398 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2399 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2400 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2401 | - . '>' . $fichier . '</a>'; |
|
| 2398 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2399 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2400 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2401 | + . '>'.$fichier.'</a>'; |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2426,9 +2426,9 @@ discard block |
||
| 2426 | 2426 | } # vieux data |
| 2427 | 2427 | $fichier = basename($url); |
| 2428 | 2428 | $enclosures[] = '<enclosure' |
| 2429 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2430 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2431 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2429 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2430 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2431 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2432 | 2432 | . ' />'; |
| 2433 | 2433 | } |
| 2434 | 2434 | } |
@@ -2454,7 +2454,7 @@ discard block |
||
| 2454 | 2454 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2455 | 2455 | $subjects .= '<dc:subject>' |
| 2456 | 2456 | . texte_backend(textebrut($e)) |
| 2457 | - . '</dc:subject>' . "\n"; |
|
| 2457 | + . '</dc:subject>'."\n"; |
|
| 2458 | 2458 | } |
| 2459 | 2459 | } |
| 2460 | 2460 | |
@@ -2490,7 +2490,7 @@ discard block |
||
| 2490 | 2490 | if (is_array($texte)) { |
| 2491 | 2491 | array_walk( |
| 2492 | 2492 | $texte, |
| 2493 | - function (&$a, $key, $t) { |
|
| 2493 | + function(&$a, $key, $t) { |
|
| 2494 | 2494 | $a = extraire_balise($a, $t); |
| 2495 | 2495 | }, |
| 2496 | 2496 | $tag |
@@ -2538,7 +2538,7 @@ discard block |
||
| 2538 | 2538 | if (is_array($texte)) { |
| 2539 | 2539 | array_walk( |
| 2540 | 2540 | $texte, |
| 2541 | - function (&$a, $key, $t) { |
|
| 2541 | + function(&$a, $key, $t) { |
|
| 2542 | 2542 | $a = extraire_balises($a, $t); |
| 2543 | 2543 | }, |
| 2544 | 2544 | $tag |
@@ -2671,7 +2671,7 @@ discard block |
||
| 2671 | 2671 | if ($fond != '404') { |
| 2672 | 2672 | $contexte = array_shift($p); |
| 2673 | 2673 | $contexte['page'] = $fond; |
| 2674 | - $action = preg_replace('/([?]' . preg_quote($fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2674 | + $action = preg_replace('/([?]'.preg_quote($fond, '/').'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2675 | 2675 | } |
| 2676 | 2676 | } |
| 2677 | 2677 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2726,9 +2726,9 @@ discard block |
||
| 2726 | 2726 | . '"' |
| 2727 | 2727 | . (is_null($val) |
| 2728 | 2728 | ? '' |
| 2729 | - : ' value="' . entites_html($val) . '"' |
|
| 2729 | + : ' value="'.entites_html($val).'"' |
|
| 2730 | 2730 | ) |
| 2731 | - . ' type="hidden"' . "\n/>"; |
|
| 2731 | + . ' type="hidden"'."\n/>"; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | return implode('', $hidden); |
@@ -2838,7 +2838,7 @@ discard block |
||
| 2838 | 2838 | |
| 2839 | 2839 | return preg_replace_callback( |
| 2840 | 2840 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2841 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2841 | + fn($x) => "url('".suivre_lien($path, $x[1])."')", |
|
| 2842 | 2842 | $contenu |
| 2843 | 2843 | ); |
| 2844 | 2844 | } |
@@ -2899,14 +2899,14 @@ discard block |
||
| 2899 | 2899 | ) { |
| 2900 | 2900 | $distant = true; |
| 2901 | 2901 | $cssf = parse_url($css); |
| 2902 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2902 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 2903 | 2903 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 2904 | 2904 | } else { |
| 2905 | 2905 | $distant = false; |
| 2906 | 2906 | $cssf = $css; |
| 2907 | 2907 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2908 | 2908 | //propose (rien a faire dans ce cas) |
| 2909 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2909 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2910 | 2910 | if (@file_exists($f)) { |
| 2911 | 2911 | return $f; |
| 2912 | 2912 | } |
@@ -2916,7 +2916,7 @@ discard block |
||
| 2916 | 2916 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2917 | 2917 | $f = $dir_var |
| 2918 | 2918 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2919 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2919 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2920 | 2920 | |
| 2921 | 2921 | // la css peut etre distante (url absolue !) |
| 2922 | 2922 | $contenu = null; |
@@ -2963,8 +2963,8 @@ discard block |
||
| 2963 | 2963 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 2964 | 2964 | elseif (str_starts_with($css_direction, $dir_var)) { |
| 2965 | 2965 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 2966 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2967 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2966 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 2967 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 2968 | 2968 | } |
| 2969 | 2969 | $src[] = $regs[0][$k]; |
| 2970 | 2970 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -3013,7 +3013,7 @@ discard block |
||
| 3013 | 3013 | |
| 3014 | 3014 | $f = basename($css, '.css'); |
| 3015 | 3015 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3016 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3016 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3017 | 3017 | . '.css'; |
| 3018 | 3018 | |
| 3019 | 3019 | if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') { |
@@ -3024,7 +3024,7 @@ discard block |
||
| 3024 | 3024 | if ($url_absolue_css == $css) { |
| 3025 | 3025 | if ( |
| 3026 | 3026 | strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 3027 | - || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3027 | + || !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3028 | 3028 | ) { |
| 3029 | 3029 | include_spip('inc/distant'); |
| 3030 | 3030 | $contenu = recuperer_url($css); |
@@ -3136,7 +3136,7 @@ discard block |
||
| 3136 | 3136 | $expression = str_replace('\/', '/', $expression); |
| 3137 | 3137 | $expression = str_replace('/', '\/', $expression); |
| 3138 | 3138 | |
| 3139 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3139 | + if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) { |
|
| 3140 | 3140 | if (isset($r[$capte])) { |
| 3141 | 3141 | return $r[$capte]; |
| 3142 | 3142 | } else { |
@@ -3178,7 +3178,7 @@ discard block |
||
| 3178 | 3178 | $expression = str_replace('\/', '/', $expression); |
| 3179 | 3179 | $expression = str_replace('/', '\/', $expression); |
| 3180 | 3180 | |
| 3181 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3181 | + return (string) preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3182 | 3182 | } |
| 3183 | 3183 | |
| 3184 | 3184 | |
@@ -3197,7 +3197,7 @@ discard block |
||
| 3197 | 3197 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3198 | 3198 | |
| 3199 | 3199 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3200 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3200 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3201 | 3201 | |
| 3202 | 3202 | if ( |
| 3203 | 3203 | strstr($t, 'spip_document_') |
@@ -3211,7 +3211,7 @@ discard block |
||
| 3211 | 3211 | if (!isset($doublons['documents'])) { |
| 3212 | 3212 | $doublons['documents'] = ''; |
| 3213 | 3213 | } |
| 3214 | - $doublons['documents'] .= ',' . implode(',', $matches[1]); |
|
| 3214 | + $doublons['documents'] .= ','.implode(',', $matches[1]); |
|
| 3215 | 3215 | } |
| 3216 | 3216 | |
| 3217 | 3217 | return $letexte; |
@@ -3268,7 +3268,7 @@ discard block |
||
| 3268 | 3268 | if ($env) { |
| 3269 | 3269 | foreach ($env as $i => $j) { |
| 3270 | 3270 | if (is_string($j) && !in_array($i, $ignore_params)) { |
| 3271 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3271 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3272 | 3272 | } |
| 3273 | 3273 | } |
| 3274 | 3274 | } |
@@ -3307,7 +3307,7 @@ discard block |
||
| 3307 | 3307 | if ($env) { |
| 3308 | 3308 | foreach ($env as $i => $j) { |
| 3309 | 3309 | if (is_string($j) && !in_array($i, $ignore_params)) { |
| 3310 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3310 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3311 | 3311 | } |
| 3312 | 3312 | } |
| 3313 | 3313 | } |
@@ -3381,11 +3381,11 @@ discard block |
||
| 3381 | 3381 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3382 | 3382 | if ( |
| 3383 | 3383 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3384 | - && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 3384 | + && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg') |
|
| 3385 | 3385 | && file_exists($variante_svg_generique) |
| 3386 | 3386 | ) { |
| 3387 | 3387 | if ( |
| 3388 | - ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg') |
|
| 3388 | + ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg') |
|
| 3389 | 3389 | && file_exists($variante_svg_size)) { |
| 3390 | 3390 | $img_file = $variante_svg_size; |
| 3391 | 3391 | } else { |
@@ -3440,7 +3440,7 @@ discard block |
||
| 3440 | 3440 | return ''; |
| 3441 | 3441 | } |
| 3442 | 3442 | } |
| 3443 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3443 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3444 | 3444 | } |
| 3445 | 3445 | |
| 3446 | 3446 | if (file_exists($img_file)) { |
@@ -3450,14 +3450,14 @@ discard block |
||
| 3450 | 3450 | $alt = ''; |
| 3451 | 3451 | } |
| 3452 | 3452 | elseif ($alt || $alt === '') { |
| 3453 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3453 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3454 | 3454 | } |
| 3455 | 3455 | else { |
| 3456 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3456 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3457 | 3457 | } |
| 3458 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3459 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3460 | - . ' ' . ltrim($atts) |
|
| 3458 | + return "<img src='".attribut_html($img_file)."'$alt" |
|
| 3459 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3460 | + . ' '.ltrim($atts) |
|
| 3461 | 3461 | . ' />'; |
| 3462 | 3462 | } |
| 3463 | 3463 | |
@@ -3471,10 +3471,10 @@ discard block |
||
| 3471 | 3471 | */ |
| 3472 | 3472 | function http_style_background($img, $att = '', $size = null) { |
| 3473 | 3473 | if ($size && is_numeric($size)) { |
| 3474 | - $size = trim($size) . 'px'; |
|
| 3474 | + $size = trim($size).'px'; |
|
| 3475 | 3475 | } |
| 3476 | - return " style='background" . |
|
| 3477 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3476 | + return " style='background". |
|
| 3477 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3478 | 3478 | . ($size ? "background-size:{$size};" : '') |
| 3479 | 3479 | . "'"; |
| 3480 | 3480 | } |
@@ -3584,7 +3584,7 @@ discard block |
||
| 3584 | 3584 | $img = http_img_pack( |
| 3585 | 3585 | $img, |
| 3586 | 3586 | $alt, |
| 3587 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3587 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3588 | 3588 | '', |
| 3589 | 3589 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3590 | 3590 | ); |
@@ -3684,9 +3684,9 @@ discard block |
||
| 3684 | 3684 | // regler le alt |
| 3685 | 3685 | if ($alt) { |
| 3686 | 3686 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3687 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3687 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3688 | 3688 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3689 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3689 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3690 | 3690 | $balise_svg .= $title; |
| 3691 | 3691 | } |
| 3692 | 3692 | else { |
@@ -3734,7 +3734,7 @@ discard block |
||
| 3734 | 3734 | if (is_array($tableau)) { |
| 3735 | 3735 | foreach ($tableau as $k => $v) { |
| 3736 | 3736 | $res = recuperer_fond( |
| 3737 | - 'modeles/' . $modele, |
|
| 3737 | + 'modeles/'.$modele, |
|
| 3738 | 3738 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3739 | 3739 | ); |
| 3740 | 3740 | $texte .= $res; |
@@ -3916,7 +3916,7 @@ discard block |
||
| 3916 | 3916 | } |
| 3917 | 3917 | |
| 3918 | 3918 | $c = serialize($c); |
| 3919 | - $cle = calculer_cle_action($form . $c); |
|
| 3919 | + $cle = calculer_cle_action($form.$c); |
|
| 3920 | 3920 | $c = "$cle:$c"; |
| 3921 | 3921 | |
| 3922 | 3922 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -3974,15 +3974,15 @@ discard block |
||
| 3974 | 3974 | } |
| 3975 | 3975 | // toujours encoder l'url source dans le bloc ajax |
| 3976 | 3976 | $r = self(); |
| 3977 | - $r = ' data-origin="' . $r . '"'; |
|
| 3977 | + $r = ' data-origin="'.$r.'"'; |
|
| 3978 | 3978 | $class = 'ajaxbloc'; |
| 3979 | 3979 | if ($ajaxid && is_string($ajaxid)) { |
| 3980 | 3980 | // ajaxid est normalement conforme a un nom de classe css |
| 3981 | 3981 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 3982 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3982 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 3983 | 3983 | } |
| 3984 | 3984 | |
| 3985 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3985 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3986 | 3986 | } |
| 3987 | 3987 | |
| 3988 | 3988 | /** |
@@ -4027,7 +4027,7 @@ discard block |
||
| 4027 | 4027 | $cle = substr($c, 0, $p); |
| 4028 | 4028 | $c = substr($c, $p + 1); |
| 4029 | 4029 | |
| 4030 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4030 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 4031 | 4031 | return @unserialize($c); |
| 4032 | 4032 | } |
| 4033 | 4033 | } |
@@ -4147,13 +4147,13 @@ discard block |
||
| 4147 | 4147 | } |
| 4148 | 4148 | } |
| 4149 | 4149 | } |
| 4150 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4150 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4151 | 4151 | } else { |
| 4152 | 4152 | $bal = 'a'; |
| 4153 | 4153 | $att = "href='$url'" |
| 4154 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4155 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4156 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4154 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4155 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4156 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4157 | 4157 | . $evt; |
| 4158 | 4158 | } |
| 4159 | 4159 | if ($libelle === null) { |
@@ -4290,7 +4290,7 @@ discard block |
||
| 4290 | 4290 | |
| 4291 | 4291 | // Icône |
| 4292 | 4292 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4293 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4293 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4294 | 4294 | |
| 4295 | 4295 | // Markup final |
| 4296 | 4296 | if ($type == 'lien') { |
@@ -4565,16 +4565,16 @@ discard block |
||
| 4565 | 4565 | $class_form = 'ajax'; |
| 4566 | 4566 | $class = str_replace('ajax', '', $class); |
| 4567 | 4567 | } |
| 4568 | - $class_btn = 'submit ' . trim($class); |
|
| 4568 | + $class_btn = 'submit '.trim($class); |
|
| 4569 | 4569 | |
| 4570 | 4570 | if ($confirm) { |
| 4571 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4571 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4572 | 4572 | $callback = $callback ? "$confirm?($callback):false" : $confirm; |
| 4573 | 4573 | } |
| 4574 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4574 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4575 | 4575 | $title = $title ? " title='$title'" : ''; |
| 4576 | 4576 | |
| 4577 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4577 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4578 | 4578 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4579 | 4579 | } |
| 4580 | 4580 | |
@@ -4638,14 +4638,14 @@ discard block |
||
| 4638 | 4638 | $champ_titre = ''; |
| 4639 | 4639 | if ($demande_titre) { |
| 4640 | 4640 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4641 | - $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre']; |
|
| 4641 | + $champ_titre = (empty($desc['titre'])) ? '' : ', '.$desc['titre']; |
|
| 4642 | 4642 | } |
| 4643 | 4643 | include_spip('base/abstract_sql'); |
| 4644 | 4644 | include_spip('base/connect_sql'); |
| 4645 | 4645 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4646 | - '*' . $champ_titre, |
|
| 4646 | + '*'.$champ_titre, |
|
| 4647 | 4647 | $desc['table_sql'], |
| 4648 | - id_table_objet($type_objet) . ' = ' . (int) $id_objet |
|
| 4648 | + id_table_objet($type_objet).' = '.(int) $id_objet |
|
| 4649 | 4649 | ); |
| 4650 | 4650 | |
| 4651 | 4651 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4736,8 +4736,7 @@ discard block |
||
| 4736 | 4736 | if (isset($ligne_sql['chapo'])) { |
| 4737 | 4737 | $chapo = $ligne_sql['chapo']; |
| 4738 | 4738 | $texte = strlen($descriptif) ? |
| 4739 | - '' : |
|
| 4740 | - "$chapo \n\n $texte"; |
|
| 4739 | + '' : "$chapo \n\n $texte"; |
|
| 4741 | 4740 | } |
| 4742 | 4741 | |
| 4743 | 4742 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4809,7 +4808,7 @@ discard block |
||
| 4809 | 4808 | return $texte; |
| 4810 | 4809 | } |
| 4811 | 4810 | |
| 4812 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4811 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4813 | 4812 | |
| 4814 | 4813 | // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
| 4815 | 4814 | if (test_espace_prive()) { |
@@ -4845,7 +4844,7 @@ discard block |
||
| 4845 | 4844 | } |
| 4846 | 4845 | $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
| 4847 | 4846 | |
| 4848 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4847 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 4849 | 4848 | } |
| 4850 | 4849 | |
| 4851 | 4850 | /** |
@@ -4871,9 +4870,9 @@ discard block |
||
| 4871 | 4870 | function wrap($texte, $wrap) { |
| 4872 | 4871 | $balises = extraire_balises($wrap); |
| 4873 | 4872 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4874 | - $texte = $wrap . $texte; |
|
| 4873 | + $texte = $wrap.$texte; |
|
| 4875 | 4874 | $regs = array_reverse($regs[1]); |
| 4876 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4875 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 4877 | 4876 | $texte .= $wrap; |
| 4878 | 4877 | } |
| 4879 | 4878 | |
@@ -4903,7 +4902,7 @@ discard block |
||
| 4903 | 4902 | |
| 4904 | 4903 | // caster $u en array si besoin |
| 4905 | 4904 | if (is_object($u)) { |
| 4906 | - $u = (array)$u; |
|
| 4905 | + $u = (array) $u; |
|
| 4907 | 4906 | } |
| 4908 | 4907 | |
| 4909 | 4908 | if (is_array($u)) { |
@@ -4925,7 +4924,7 @@ discard block |
||
| 4925 | 4924 | // sinon on passe a la ligne et on indente |
| 4926 | 4925 | $i_str = str_pad('', $indent, ' '); |
| 4927 | 4926 | foreach ($u as $k => $v) { |
| 4928 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4927 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4929 | 4928 | } |
| 4930 | 4929 | |
| 4931 | 4930 | return $out; |
@@ -4979,7 +4978,7 @@ discard block |
||
| 4979 | 4978 | * @return string |
| 4980 | 4979 | */ |
| 4981 | 4980 | function objet_icone($objet, $taille = 24, $class = '') { |
| 4982 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 4981 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 4983 | 4982 | $icone = chemin_image($icone); |
| 4984 | 4983 | $balise_img = charger_filtre('balise_img'); |
| 4985 | 4984 | |
@@ -5005,7 +5004,7 @@ discard block |
||
| 5005 | 5004 | */ |
| 5006 | 5005 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5007 | 5006 | $chaine = explode(':', $chaine); |
| 5008 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5007 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5009 | 5008 | return $t; |
| 5010 | 5009 | } |
| 5011 | 5010 | $chaine = implode(':', $chaine); |
@@ -5071,7 +5070,7 @@ discard block |
||
| 5071 | 5070 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5072 | 5071 | |
| 5073 | 5072 | // calculer le nom de la css |
| 5074 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5073 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5075 | 5074 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5076 | 5075 | $contexte_implicite = calculer_contexte_implicite(); |
| 5077 | 5076 | |
@@ -5079,14 +5078,14 @@ discard block |
||
| 5079 | 5078 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5080 | 5079 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5081 | 5080 | if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
| 5082 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5081 | + $hash = md5($contexte_implicite['host'].'::'.$cache); |
|
| 5083 | 5082 | } |
| 5084 | 5083 | else { |
| 5085 | 5084 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5086 | 5085 | ksort($contexte); |
| 5087 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5086 | + $hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect); |
|
| 5088 | 5087 | } |
| 5089 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5088 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5090 | 5089 | |
| 5091 | 5090 | // mettre a jour le fichier si il n'existe pas |
| 5092 | 5091 | // ou trop ancien |
@@ -5094,8 +5093,8 @@ discard block |
||
| 5094 | 5093 | // et recopie sur le fichier cible uniquement si il change |
| 5095 | 5094 | if ( |
| 5096 | 5095 | !file_exists($filename) |
| 5097 | - || !file_exists($filename . '.last') |
|
| 5098 | - || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified'] |
|
| 5096 | + || !file_exists($filename.'.last') |
|
| 5097 | + || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename.'.last') < $cache['lastmodified'] |
|
| 5099 | 5098 | || defined('_VAR_MODE') && _VAR_MODE == 'recalcul' |
| 5100 | 5099 | ) { |
| 5101 | 5100 | $contenu = $cache['texte']; |
@@ -5119,10 +5118,10 @@ discard block |
||
| 5119 | 5118 | } |
| 5120 | 5119 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5121 | 5120 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5122 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5121 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 5123 | 5122 | } |
| 5124 | 5123 | // et ecrire le fichier si il change |
| 5125 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5124 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5126 | 5125 | } |
| 5127 | 5126 | |
| 5128 | 5127 | return timestamp($filename); |
@@ -5349,7 +5348,7 @@ discard block |
||
| 5349 | 5348 | if ($e > 0 && strlen($mid) > 8) { |
| 5350 | 5349 | $mid = '***...***'; |
| 5351 | 5350 | } |
| 5352 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5351 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5353 | 5352 | } |
| 5354 | 5353 | |
| 5355 | 5354 | |
@@ -5411,7 +5410,7 @@ discard block |
||
| 5411 | 5410 | case 'id': |
| 5412 | 5411 | case 'anchor': |
| 5413 | 5412 | if (preg_match(',^\d,', $texte)) { |
| 5414 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5413 | + $texte = substr($type, 0, 1).$texte; |
|
| 5415 | 5414 | } |
| 5416 | 5415 | } |
| 5417 | 5416 | |
@@ -5421,9 +5420,9 @@ discard block |
||
| 5421 | 5420 | |
| 5422 | 5421 | if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) { |
| 5423 | 5422 | if (preg_match(',^\d,', $texte)) { |
| 5424 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5423 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5425 | 5424 | } |
| 5426 | - $texte .= $separateur . md5($original); |
|
| 5425 | + $texte .= $separateur.md5($original); |
|
| 5427 | 5426 | $texte = substr($texte, 0, $longueur_mini); |
| 5428 | 5427 | } |
| 5429 | 5428 | |
@@ -615,8 +615,7 @@ discard block |
||
| 615 | 615 | if (!$srcSize) { |
| 616 | 616 | $poids_img[$src] = filesize($src); |
| 617 | 617 | } |
| 618 | - } |
|
| 619 | - elseif (str_contains($src, '<svg')) { |
|
| 618 | + } elseif (str_contains($src, '<svg')) { |
|
| 620 | 619 | include_spip('inc/svg'); |
| 621 | 620 | if ($attrs = svg_lire_attributs($src)) { |
| 622 | 621 | [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
@@ -3420,8 +3419,7 @@ discard block |
||
| 3420 | 3419 | } |
| 3421 | 3420 | if (!isset($options['chemin_image']) || $options['chemin_image'] == true) { |
| 3422 | 3421 | $img_file = chemin_image($img); |
| 3423 | - } |
|
| 3424 | - else { |
|
| 3422 | + } else { |
|
| 3425 | 3423 | if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) { |
| 3426 | 3424 | $img_file = http_img_variante_svg_si_possible($img_file); |
| 3427 | 3425 | } |
@@ -3448,11 +3446,9 @@ discard block |
||
| 3448 | 3446 | } |
| 3449 | 3447 | if ($alt === false) { |
| 3450 | 3448 | $alt = ''; |
| 3451 | - } |
|
| 3452 | - elseif ($alt || $alt === '') { |
|
| 3449 | + } elseif ($alt || $alt === '') { |
|
| 3453 | 3450 | $alt = " alt='" . attribut_html($alt) . "'"; |
| 3454 | - } |
|
| 3455 | - else { |
|
| 3451 | + } else { |
|
| 3456 | 3452 | $alt = " alt='" . attribut_html($title) . "'"; |
| 3457 | 3453 | } |
| 3458 | 3454 | return "<img src='" . attribut_html($img_file) . "'$alt" |
@@ -3579,8 +3575,7 @@ discard block |
||
| 3579 | 3575 | if (!is_null($class)) { |
| 3580 | 3576 | $img = strlen($class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class'); |
| 3581 | 3577 | } |
| 3582 | - } |
|
| 3583 | - else { |
|
| 3578 | + } else { |
|
| 3584 | 3579 | $img = http_img_pack( |
| 3585 | 3580 | $img, |
| 3586 | 3581 | $alt, |
@@ -3688,8 +3683,7 @@ discard block |
||
| 3688 | 3683 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3689 | 3684 | $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
| 3690 | 3685 | $balise_svg .= $title; |
| 3691 | - } |
|
| 3692 | - else { |
|
| 3686 | + } else { |
|
| 3693 | 3687 | $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
| 3694 | 3688 | } |
| 3695 | 3689 | |
@@ -5080,8 +5074,7 @@ discard block |
||
| 5080 | 5074 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5081 | 5075 | if (isset($options['hash_on_content']) && $options['hash_on_content']) { |
| 5082 | 5076 | $hash = md5($contexte_implicite['host'] . '::' . $cache); |
| 5083 | - } |
|
| 5084 | - else { |
|
| 5077 | + } else { |
|
| 5085 | 5078 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5086 | 5079 | ksort($contexte); |
| 5087 | 5080 | $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $type = reset($objets); |
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | - $ref = $type . $ref; |
|
| 162 | + $ref = $type.$ref; |
|
| 163 | 163 | } |
| 164 | 164 | else { |
| 165 | 165 | // Si la référence ne correspond à rien, c'est fini |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | return json_export(false); |
| 168 | 168 | } |
| 169 | 169 | // Sinon on récupère les infos utiles |
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | + [$type,, $id,,,,] = array_pad($match, 7, null); |
|
| 171 | 171 | |
| 172 | 172 | // On regarde si le type trouvé fait partie des objets sélectionnables |
| 173 | 173 | if (!in_array(table_objet($type), $objets)) { |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | $types = (is_array($types) ? array_filter($types) : []); |
| 214 | 214 | |
| 215 | 215 | // recuperer tous les freres et soeurs de la rubrique visee |
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.(int) $id_parent); |
|
| 218 | 218 | $fratrie = array_column($fratrie, 'id_rubrique'); |
| 219 | 219 | $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
| 220 | 220 | $has = array_column($has, 'id_parent'); |
@@ -160,8 +160,7 @@ |
||
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | 162 | $ref = $type . $ref; |
| 163 | - } |
|
| 164 | - else { |
|
| 163 | + } else { |
|
| 165 | 164 | // Si la référence ne correspond à rien, c'est fini |
| 166 | 165 | if (!($match = typer_raccourci($ref))) { |
| 167 | 166 | return json_export(false); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return |
| 75 | 75 | **/ |
| 76 | 76 | function inc_genie_dist($taches = []) { |
| 77 | - include_spip('inc/queue'); |
|
| 78 | - |
|
| 79 | - if (_request('exec') == 'job_queue') { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $force_jobs = []; |
|
| 84 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | - // etait de la passer en parametre a ing_genie_dist |
|
| 86 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | - foreach ($taches as $function => $period) { |
|
| 88 | - $force_jobs[] = queue_add_job( |
|
| 89 | - $function, |
|
| 90 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | - [time() - abs($period)], |
|
| 92 | - 'genie/' |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // et on passe la main a la gestion de la queue ! |
|
| 97 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 77 | + include_spip('inc/queue'); |
|
| 78 | + |
|
| 79 | + if (_request('exec') == 'job_queue') { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $force_jobs = []; |
|
| 84 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | + // etait de la passer en parametre a ing_genie_dist |
|
| 86 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | + foreach ($taches as $function => $period) { |
|
| 88 | + $force_jobs[] = queue_add_job( |
|
| 89 | + $function, |
|
| 90 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | + [time() - abs($period)], |
|
| 92 | + 'genie/' |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // et on passe la main a la gestion de la queue ! |
|
| 97 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | // |
| 109 | 109 | function taches_generales($taches_generales = []) { |
| 110 | 110 | |
| 111 | - // verifier que toutes les taches cron sont planifiees |
|
| 112 | - // c'est une tache cron ! |
|
| 113 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 111 | + // verifier que toutes les taches cron sont planifiees |
|
| 112 | + // c'est une tache cron ! |
|
| 113 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 114 | 114 | |
| 115 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | - // est fait au coup par coup a present |
|
| 117 | - // $taches_generales['rubriques'] = 3600; |
|
| 115 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | + // est fait au coup par coup a present |
|
| 117 | + // $taches_generales['rubriques'] = 3600; |
|
| 118 | 118 | |
| 119 | - // Optimisation de la base |
|
| 120 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 119 | + // Optimisation de la base |
|
| 120 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 121 | 121 | |
| 122 | - // nouveautes |
|
| 123 | - if ( |
|
| 124 | - isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | - && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 122 | + // nouveautes |
|
| 123 | + if ( |
|
| 124 | + isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | + && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |