@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | 27 | function generer_nom_fichier_cache($contexte, $page) { |
| 28 | - $u = md5(var_export([$contexte, $page], true)); |
|
| 28 | + $u = md5(var_export([$contexte, $page], true)); |
|
| 29 | 29 | |
| 30 | - return $u . '.cache'; |
|
| 30 | + return $u . '.cache'; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -43,26 +43,26 @@ discard block |
||
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | 45 | function cache_chemin_fichier($nom_cache, $ecrire = false) { |
| 46 | - static $l1, $l2; |
|
| 47 | - if (is_null($l1)) { |
|
| 48 | - $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 49 | - $l1 = intval(floor($length / 2)); |
|
| 50 | - $l2 = $length - $l1; |
|
| 51 | - } |
|
| 52 | - $d = substr($nom_cache, 0, $l1); |
|
| 53 | - $u = substr($nom_cache, $l1, $l2); |
|
| 54 | - |
|
| 55 | - if ($ecrire) { |
|
| 56 | - $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 57 | - $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 58 | - $rep = sous_repertoire($rep, $d, false, true); |
|
| 59 | - } |
|
| 60 | - else { |
|
| 61 | - // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 62 | - $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $rep . $u . '.cache'; |
|
| 46 | + static $l1, $l2; |
|
| 47 | + if (is_null($l1)) { |
|
| 48 | + $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 49 | + $l1 = intval(floor($length / 2)); |
|
| 50 | + $l2 = $length - $l1; |
|
| 51 | + } |
|
| 52 | + $d = substr($nom_cache, 0, $l1); |
|
| 53 | + $u = substr($nom_cache, $l1, $l2); |
|
| 54 | + |
|
| 55 | + if ($ecrire) { |
|
| 56 | + $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 57 | + $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 58 | + $rep = sous_repertoire($rep, $d, false, true); |
|
| 59 | + } |
|
| 60 | + else { |
|
| 61 | + // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 62 | + $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $rep . $u . '.cache'; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | function ecrire_cache($nom_cache, $valeur) { |
| 76 | - return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 76 | + return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,38 +83,38 @@ discard block |
||
| 83 | 83 | * @return mixed |
| 84 | 84 | */ |
| 85 | 85 | function lire_cache($nom_cache) { |
| 86 | - $tmp = []; |
|
| 87 | - if ( |
|
| 88 | - file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 89 | - and lire_fichier($f, $tmp) |
|
| 90 | - and $tmp = unserialize($tmp) |
|
| 91 | - and $tmp['nom_cache'] == $nom_cache |
|
| 92 | - and isset($tmp['valeur']) |
|
| 93 | - ) { |
|
| 94 | - return $tmp['valeur']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return false; |
|
| 86 | + $tmp = []; |
|
| 87 | + if ( |
|
| 88 | + file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 89 | + and lire_fichier($f, $tmp) |
|
| 90 | + and $tmp = unserialize($tmp) |
|
| 91 | + and $tmp['nom_cache'] == $nom_cache |
|
| 92 | + and isset($tmp['valeur']) |
|
| 93 | + ) { |
|
| 94 | + return $tmp['valeur']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return false; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Parano : on signe le cache, afin d'interdire un hack d'injection |
| 101 | 101 | // dans notre memcache |
| 102 | 102 | function cache_signature(&$page) { |
| 103 | - if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 104 | - include_spip('inc/acces'); |
|
| 105 | - include_spip('auth/sha256.inc'); |
|
| 106 | - ecrire_meta( |
|
| 107 | - 'cache_signature', |
|
| 108 | - spip_sha256( |
|
| 109 | - $_SERVER['DOCUMENT_ROOT'] |
|
| 110 | - . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 111 | - . creer_uniqid() |
|
| 112 | - ), |
|
| 113 | - 'non' |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 103 | + if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 104 | + include_spip('inc/acces'); |
|
| 105 | + include_spip('auth/sha256.inc'); |
|
| 106 | + ecrire_meta( |
|
| 107 | + 'cache_signature', |
|
| 108 | + spip_sha256( |
|
| 109 | + $_SERVER['DOCUMENT_ROOT'] |
|
| 110 | + . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 111 | + . creer_uniqid() |
|
| 112 | + ), |
|
| 113 | + 'non' |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | 129 | function gzip_page($page) { |
| 130 | - if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 131 | - $page['gz'] = true; |
|
| 132 | - $page['texte'] = gzcompress($page['texte']); |
|
| 133 | - } else { |
|
| 134 | - $page['gz'] = false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $page; |
|
| 130 | + if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 131 | + $page['gz'] = true; |
|
| 132 | + $page['texte'] = gzcompress($page['texte']); |
|
| 133 | + } else { |
|
| 134 | + $page['gz'] = false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $page; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | 149 | function gunzip_page(&$page) { |
| 150 | - if ($page['gz']) { |
|
| 151 | - $page['texte'] = gzuncompress($page['texte']); |
|
| 152 | - $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 153 | - } |
|
| 150 | + if ($page['gz']) { |
|
| 151 | + $page['texte'] = gzuncompress($page['texte']); |
|
| 152 | + $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,72 +165,72 @@ discard block |
||
| 165 | 165 | * -1 si il faut calculer sans stocker en cache |
| 166 | 166 | */ |
| 167 | 167 | function cache_valide(&$page, $date) { |
| 168 | - $now = $_SERVER['REQUEST_TIME']; |
|
| 169 | - |
|
| 170 | - // Apparition d'un nouvel article post-date ? |
|
| 171 | - if ( |
|
| 172 | - isset($GLOBALS['meta']['post_dates']) |
|
| 173 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 174 | - and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 176 | - ) { |
|
| 177 | - spip_log('Un article post-date invalide le cache'); |
|
| 178 | - include_spip('inc/rubriques'); |
|
| 179 | - calculer_prochain_postdate(true); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 183 | - return -1; |
|
| 184 | - } |
|
| 185 | - if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 186 | - return -1; |
|
| 187 | - } |
|
| 188 | - if (defined('_NO_CACHE')) { |
|
| 189 | - return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 193 | - if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 194 | - return _IS_BOT ? -1 : 1; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // controle de la signature |
|
| 198 | - if ($page['sig'] !== cache_signature($page)) { |
|
| 199 | - return _IS_BOT ? -1 : 1; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 203 | - // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 204 | - if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 205 | - // Cache invalide par la meta 'derniere_modif' |
|
| 206 | - // sauf pour les bots, qui utilisent toujours le cache |
|
| 207 | - if ( |
|
| 208 | - !_IS_BOT |
|
| 209 | - and $GLOBALS['derniere_modif_invalide'] |
|
| 210 | - and isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | - and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | - ) { |
|
| 213 | - return 1; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | - $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 219 | - $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | - if ($duree == 0) { #CACHE{0} |
|
| 221 | - return -1; |
|
| 222 | - } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | - else { |
|
| 224 | - if ( |
|
| 225 | - (!_IS_BOT and $date + $duree < $now) |
|
| 226 | - # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 227 | - or $date < $cache_mark |
|
| 228 | - ) { |
|
| 229 | - return _IS_BOT ? -1 : 1; |
|
| 230 | - } else { |
|
| 231 | - return 0; |
|
| 232 | - } |
|
| 233 | - } |
|
| 168 | + $now = $_SERVER['REQUEST_TIME']; |
|
| 169 | + |
|
| 170 | + // Apparition d'un nouvel article post-date ? |
|
| 171 | + if ( |
|
| 172 | + isset($GLOBALS['meta']['post_dates']) |
|
| 173 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 174 | + and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 176 | + ) { |
|
| 177 | + spip_log('Un article post-date invalide le cache'); |
|
| 178 | + include_spip('inc/rubriques'); |
|
| 179 | + calculer_prochain_postdate(true); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 183 | + return -1; |
|
| 184 | + } |
|
| 185 | + if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 186 | + return -1; |
|
| 187 | + } |
|
| 188 | + if (defined('_NO_CACHE')) { |
|
| 189 | + return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 193 | + if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 194 | + return _IS_BOT ? -1 : 1; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // controle de la signature |
|
| 198 | + if ($page['sig'] !== cache_signature($page)) { |
|
| 199 | + return _IS_BOT ? -1 : 1; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 203 | + // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 204 | + if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 205 | + // Cache invalide par la meta 'derniere_modif' |
|
| 206 | + // sauf pour les bots, qui utilisent toujours le cache |
|
| 207 | + if ( |
|
| 208 | + !_IS_BOT |
|
| 209 | + and $GLOBALS['derniere_modif_invalide'] |
|
| 210 | + and isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | + and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | + ) { |
|
| 213 | + return 1; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | + $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 219 | + $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | + if ($duree == 0) { #CACHE{0} |
|
| 221 | + return -1; |
|
| 222 | + } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | + else { |
|
| 224 | + if ( |
|
| 225 | + (!_IS_BOT and $date + $duree < $now) |
|
| 226 | + # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 227 | + or $date < $cache_mark |
|
| 228 | + ) { |
|
| 229 | + return _IS_BOT ? -1 : 1; |
|
| 230 | + } else { |
|
| 231 | + return 0; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -243,59 +243,59 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | function creer_cache(&$page, &$chemin_cache) { |
| 245 | 245 | |
| 246 | - // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 247 | - // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 248 | - // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 249 | - // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 250 | - if ( |
|
| 251 | - (defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 252 | - or defined('spip_interdire_cache') |
|
| 253 | - ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 258 | - // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 259 | - if ( |
|
| 260 | - isset($page['invalideurs']) |
|
| 261 | - and isset($page['invalideurs']['session']) |
|
| 262 | - ) { |
|
| 263 | - // on verifie que le contenu du chemin cache indique seulement |
|
| 264 | - // "cache sessionne" ; sa date indique la date de validite |
|
| 265 | - // des caches sessionnes |
|
| 266 | - if (!$tmp = lire_cache($chemin_cache)) { |
|
| 267 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 268 | - $tmp = [ |
|
| 269 | - 'invalideurs' => ['session' => ''], |
|
| 270 | - 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 271 | - ]; |
|
| 272 | - ecrire_cache($chemin_cache, $tmp); |
|
| 273 | - } |
|
| 274 | - $chemin_cache = generer_nom_fichier_cache( |
|
| 275 | - ['chemin_cache' => $chemin_cache], |
|
| 276 | - ['session' => $page['invalideurs']['session']] |
|
| 277 | - ); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // ajouter la date de production dans le cache lui meme |
|
| 281 | - // (qui contient deja sa duree de validite) |
|
| 282 | - $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 283 | - |
|
| 284 | - // compresser le contenu si besoin |
|
| 285 | - $pagez = gzip_page($page); |
|
| 286 | - |
|
| 287 | - // signer le contenu |
|
| 288 | - $pagez['sig'] = cache_signature($pagez); |
|
| 289 | - |
|
| 290 | - // l'enregistrer, compresse ou non... |
|
| 291 | - $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 292 | - |
|
| 293 | - spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 294 | - . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 295 | - |
|
| 296 | - // Inserer ses invalideurs |
|
| 297 | - include_spip('inc/invalideur'); |
|
| 298 | - maj_invalideurs($chemin_cache, $page); |
|
| 246 | + // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 247 | + // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 248 | + // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 249 | + // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 250 | + if ( |
|
| 251 | + (defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 252 | + or defined('spip_interdire_cache') |
|
| 253 | + ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 258 | + // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 259 | + if ( |
|
| 260 | + isset($page['invalideurs']) |
|
| 261 | + and isset($page['invalideurs']['session']) |
|
| 262 | + ) { |
|
| 263 | + // on verifie que le contenu du chemin cache indique seulement |
|
| 264 | + // "cache sessionne" ; sa date indique la date de validite |
|
| 265 | + // des caches sessionnes |
|
| 266 | + if (!$tmp = lire_cache($chemin_cache)) { |
|
| 267 | + spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 268 | + $tmp = [ |
|
| 269 | + 'invalideurs' => ['session' => ''], |
|
| 270 | + 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 271 | + ]; |
|
| 272 | + ecrire_cache($chemin_cache, $tmp); |
|
| 273 | + } |
|
| 274 | + $chemin_cache = generer_nom_fichier_cache( |
|
| 275 | + ['chemin_cache' => $chemin_cache], |
|
| 276 | + ['session' => $page['invalideurs']['session']] |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + // ajouter la date de production dans le cache lui meme |
|
| 281 | + // (qui contient deja sa duree de validite) |
|
| 282 | + $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 283 | + |
|
| 284 | + // compresser le contenu si besoin |
|
| 285 | + $pagez = gzip_page($page); |
|
| 286 | + |
|
| 287 | + // signer le contenu |
|
| 288 | + $pagez['sig'] = cache_signature($pagez); |
|
| 289 | + |
|
| 290 | + // l'enregistrer, compresse ou non... |
|
| 291 | + $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 292 | + |
|
| 293 | + spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 294 | + . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 295 | + |
|
| 296 | + // Inserer ses invalideurs |
|
| 297 | + include_spip('inc/invalideur'); |
|
| 298 | + maj_invalideurs($chemin_cache, $page); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -308,15 +308,15 @@ discard block |
||
| 308 | 308 | * @return void |
| 309 | 309 | */ |
| 310 | 310 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 311 | - // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 312 | - $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 313 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 314 | - foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 315 | - if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 316 | - spip_unlink($f); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 311 | + // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 312 | + $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 313 | + if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 314 | + foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 315 | + if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 316 | + spip_unlink($f); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -344,134 +344,134 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) { |
| 346 | 346 | |
| 347 | - # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 348 | - # $use_cache = -1; return; |
|
| 349 | - |
|
| 350 | - // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 351 | - if (isset($chemin_cache)) { |
|
| 352 | - creer_cache($page, $chemin_cache); |
|
| 353 | - return; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // Toute la suite correspond au premier appel |
|
| 357 | - $contexte_implicite = $page['contexte_implicite']; |
|
| 358 | - |
|
| 359 | - // Cas ignorant le cache car completement dynamique |
|
| 360 | - if ( |
|
| 361 | - (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'POST') |
|
| 362 | - or _request('connect') |
|
| 363 | - ) { |
|
| 364 | - $use_cache = -1; |
|
| 365 | - $lastmodified = 0; |
|
| 366 | - $chemin_cache = ''; |
|
| 367 | - $page = []; |
|
| 368 | - |
|
| 369 | - return; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Controler l'existence d'un cache nous correspondant |
|
| 373 | - $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 374 | - $lastmodified = 0; |
|
| 375 | - |
|
| 376 | - // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 377 | - if (!$page = lire_cache($chemin_cache)) { |
|
| 378 | - $page = []; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - // s'il est sessionne, charger celui correspondant a notre session |
|
| 382 | - if ( |
|
| 383 | - isset($page['invalideurs']) |
|
| 384 | - and isset($page['invalideurs']['session']) |
|
| 385 | - ) { |
|
| 386 | - $chemin_cache_session = generer_nom_fichier_cache( |
|
| 387 | - ['chemin_cache' => $chemin_cache], |
|
| 388 | - ['session' => spip_session()] |
|
| 389 | - ); |
|
| 390 | - if ( |
|
| 391 | - $page_session = lire_cache($chemin_cache_session) |
|
| 392 | - and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 393 | - ) { |
|
| 394 | - $page = $page_session; |
|
| 395 | - } else { |
|
| 396 | - $page = []; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 402 | - if (isset($GLOBALS['meta']['invalider'])) { |
|
| 403 | - // ne le faire que si la base est disponible |
|
| 404 | - if (spip_connect()) { |
|
| 405 | - include_spip('inc/invalideur'); |
|
| 406 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 407 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 408 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 409 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 415 | - // on supprime le cache |
|
| 416 | - if ( |
|
| 417 | - defined('_VAR_MODE') && |
|
| 418 | - _VAR_MODE && |
|
| 419 | - (isset($_COOKIE['spip_session']) || |
|
| 420 | - isset($_COOKIE['spip_admin']) || |
|
| 421 | - @file_exists(_ACCESS_FILE_NAME)) |
|
| 422 | - ) { |
|
| 423 | - $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 424 | - include_spip('inc/invalideur'); |
|
| 425 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 426 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 427 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 428 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // $delais par defaut |
|
| 433 | - // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 434 | - // qui sont a cache nul par defaut |
|
| 435 | - if (!isset($GLOBALS['delais'])) { |
|
| 436 | - if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 437 | - define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 438 | - } |
|
| 439 | - $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - // determiner la validite de la page |
|
| 443 | - if ($page) { |
|
| 444 | - $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 445 | - // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 446 | - // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 447 | - $page['contexte_implicite'] = $contexte_implicite; |
|
| 448 | - if (!$use_cache) { |
|
| 449 | - // $page est un cache utilisable |
|
| 450 | - gunzip_page($page); |
|
| 451 | - |
|
| 452 | - return; |
|
| 453 | - } |
|
| 454 | - } else { |
|
| 455 | - $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 456 | - $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 460 | - if (!spip_connect()) { |
|
| 461 | - if (isset($page['texte'])) { |
|
| 462 | - gunzip_page($page); |
|
| 463 | - $use_cache = 0; |
|
| 464 | - } else { |
|
| 465 | - spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 466 | - include_spip('inc/minipres'); |
|
| 467 | - |
|
| 468 | - return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - if ($use_cache < 0) { |
|
| 473 | - $chemin_cache = ''; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - return; |
|
| 347 | + # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 348 | + # $use_cache = -1; return; |
|
| 349 | + |
|
| 350 | + // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 351 | + if (isset($chemin_cache)) { |
|
| 352 | + creer_cache($page, $chemin_cache); |
|
| 353 | + return; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // Toute la suite correspond au premier appel |
|
| 357 | + $contexte_implicite = $page['contexte_implicite']; |
|
| 358 | + |
|
| 359 | + // Cas ignorant le cache car completement dynamique |
|
| 360 | + if ( |
|
| 361 | + (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'POST') |
|
| 362 | + or _request('connect') |
|
| 363 | + ) { |
|
| 364 | + $use_cache = -1; |
|
| 365 | + $lastmodified = 0; |
|
| 366 | + $chemin_cache = ''; |
|
| 367 | + $page = []; |
|
| 368 | + |
|
| 369 | + return; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Controler l'existence d'un cache nous correspondant |
|
| 373 | + $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 374 | + $lastmodified = 0; |
|
| 375 | + |
|
| 376 | + // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 377 | + if (!$page = lire_cache($chemin_cache)) { |
|
| 378 | + $page = []; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + // s'il est sessionne, charger celui correspondant a notre session |
|
| 382 | + if ( |
|
| 383 | + isset($page['invalideurs']) |
|
| 384 | + and isset($page['invalideurs']['session']) |
|
| 385 | + ) { |
|
| 386 | + $chemin_cache_session = generer_nom_fichier_cache( |
|
| 387 | + ['chemin_cache' => $chemin_cache], |
|
| 388 | + ['session' => spip_session()] |
|
| 389 | + ); |
|
| 390 | + if ( |
|
| 391 | + $page_session = lire_cache($chemin_cache_session) |
|
| 392 | + and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 393 | + ) { |
|
| 394 | + $page = $page_session; |
|
| 395 | + } else { |
|
| 396 | + $page = []; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 402 | + if (isset($GLOBALS['meta']['invalider'])) { |
|
| 403 | + // ne le faire que si la base est disponible |
|
| 404 | + if (spip_connect()) { |
|
| 405 | + include_spip('inc/invalideur'); |
|
| 406 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 407 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 408 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 409 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 415 | + // on supprime le cache |
|
| 416 | + if ( |
|
| 417 | + defined('_VAR_MODE') && |
|
| 418 | + _VAR_MODE && |
|
| 419 | + (isset($_COOKIE['spip_session']) || |
|
| 420 | + isset($_COOKIE['spip_admin']) || |
|
| 421 | + @file_exists(_ACCESS_FILE_NAME)) |
|
| 422 | + ) { |
|
| 423 | + $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 424 | + include_spip('inc/invalideur'); |
|
| 425 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 426 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 427 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 428 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // $delais par defaut |
|
| 433 | + // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 434 | + // qui sont a cache nul par defaut |
|
| 435 | + if (!isset($GLOBALS['delais'])) { |
|
| 436 | + if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 437 | + define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 438 | + } |
|
| 439 | + $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + // determiner la validite de la page |
|
| 443 | + if ($page) { |
|
| 444 | + $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 445 | + // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 446 | + // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 447 | + $page['contexte_implicite'] = $contexte_implicite; |
|
| 448 | + if (!$use_cache) { |
|
| 449 | + // $page est un cache utilisable |
|
| 450 | + gunzip_page($page); |
|
| 451 | + |
|
| 452 | + return; |
|
| 453 | + } |
|
| 454 | + } else { |
|
| 455 | + $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 456 | + $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 460 | + if (!spip_connect()) { |
|
| 461 | + if (isset($page['texte'])) { |
|
| 462 | + gunzip_page($page); |
|
| 463 | + $use_cache = 0; |
|
| 464 | + } else { |
|
| 465 | + spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 466 | + include_spip('inc/minipres'); |
|
| 467 | + |
|
| 468 | + return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + if ($use_cache < 0) { |
|
| 473 | + $chemin_cache = ''; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + return; |
|
| 477 | 477 | } |
@@ -20,178 +20,178 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | function assembler($fond, string $connect = '') { |
| 32 | 32 | |
| 33 | - $chemin_cache = null; |
|
| 34 | - $lastmodified = null; |
|
| 35 | - $res = null; |
|
| 36 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | - |
|
| 40 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | - ',\.[a-zA-Z0-9]*$,', |
|
| 44 | - '', |
|
| 45 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | - ); |
|
| 47 | - // Cette fonction est utilisee deux fois |
|
| 48 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | - if ($cacher) { |
|
| 52 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | - } else { |
|
| 54 | - $GLOBALS['use_cache'] = -1; |
|
| 55 | - } |
|
| 56 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | - if ($res) { |
|
| 58 | - return ['texte' => $res]; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$chemin_cache || !$lastmodified) { |
|
| 62 | - $lastmodified = time(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | - $calculer_page = true; |
|
| 67 | - |
|
| 68 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | - // pages sont dynamiques) |
|
| 71 | - if ( |
|
| 72 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | - and $chemin_cache |
|
| 75 | - and isset($page['entetes']) |
|
| 76 | - and isset($page['entetes']['Cache-Control']) |
|
| 77 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | - ) { |
|
| 80 | - $since = preg_replace( |
|
| 81 | - '/;.*/', |
|
| 82 | - '', |
|
| 83 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | - ); |
|
| 85 | - $since = str_replace('GMT', '', $since); |
|
| 86 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | - $page['status'] = 304; |
|
| 88 | - $headers_only = true; |
|
| 89 | - $calculer_page = false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | - if (!$calculer_page) { |
|
| 96 | - $page['texte'] = ''; |
|
| 97 | - } else { |
|
| 98 | - // si la page est prise dans le cache |
|
| 99 | - if (!$GLOBALS['use_cache']) { |
|
| 100 | - // Informer les boutons d'admin du contexte |
|
| 101 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | - |
|
| 104 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | - // d'inversion url => objet |
|
| 106 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | - #unset($_ENV['url_propre']); |
|
| 109 | - } else { |
|
| 110 | - // Compat ascendante : |
|
| 111 | - // 1. $contexte est global |
|
| 112 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | - // et calculer la page |
|
| 114 | - if (!test_espace_prive()) { |
|
| 115 | - include_spip('inc/urls'); |
|
| 116 | - [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | - nettoyer_uri(), |
|
| 118 | - $fond, |
|
| 119 | - $GLOBALS['contexte'], |
|
| 120 | - true |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - // squelette par defaut |
|
| 124 | - if (!strlen($fond ?? '')) { |
|
| 125 | - $fond = 'sommaire'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // produire la page : peut mettre a jour $lastmodified |
|
| 129 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | - $page = $produire_page( |
|
| 131 | - $fond, |
|
| 132 | - $GLOBALS['contexte'], |
|
| 133 | - $GLOBALS['use_cache'], |
|
| 134 | - $chemin_cache, |
|
| 135 | - null, |
|
| 136 | - $page, |
|
| 137 | - $lastmodified, |
|
| 138 | - $connect |
|
| 139 | - ); |
|
| 140 | - if ($page === '') { |
|
| 141 | - $erreur = _T( |
|
| 142 | - 'info_erreur_squelette2', |
|
| 143 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | - ); |
|
| 145 | - erreur_squelette($erreur); |
|
| 146 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($page and $chemin_cache) { |
|
| 152 | - $page['cache'] = $chemin_cache; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - auto_content_type($page); |
|
| 156 | - |
|
| 157 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | - |
|
| 159 | - // Definir les entetes si ce n'est fait |
|
| 160 | - if (!$GLOBALS['flag_preserver']) { |
|
| 161 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | - if ( |
|
| 163 | - trim($page['texte']) === '' |
|
| 164 | - and _VAR_MODE !== 'debug' |
|
| 165 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | - ) { |
|
| 167 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | - } |
|
| 170 | - // pas de cache client en mode 'observation' |
|
| 171 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Entete Last-Modified: |
|
| 179 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | - if ( |
|
| 182 | - $lastmodified |
|
| 183 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | - and !isset($page['entetes']['Last-Modified']) |
|
| 185 | - ) { |
|
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // fermer la connexion apres les headers si requete HEAD |
|
| 190 | - if ($headers_only) { |
|
| 191 | - $page['entetes']['Connection'] = 'close'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 33 | + $chemin_cache = null; |
|
| 34 | + $lastmodified = null; |
|
| 35 | + $res = null; |
|
| 36 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | + |
|
| 40 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | + ',\.[a-zA-Z0-9]*$,', |
|
| 44 | + '', |
|
| 45 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | + ); |
|
| 47 | + // Cette fonction est utilisee deux fois |
|
| 48 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | + if ($cacher) { |
|
| 52 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | + } else { |
|
| 54 | + $GLOBALS['use_cache'] = -1; |
|
| 55 | + } |
|
| 56 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | + if ($res) { |
|
| 58 | + return ['texte' => $res]; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$chemin_cache || !$lastmodified) { |
|
| 62 | + $lastmodified = time(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | + $calculer_page = true; |
|
| 67 | + |
|
| 68 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | + // pages sont dynamiques) |
|
| 71 | + if ( |
|
| 72 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | + and $chemin_cache |
|
| 75 | + and isset($page['entetes']) |
|
| 76 | + and isset($page['entetes']['Cache-Control']) |
|
| 77 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | + ) { |
|
| 80 | + $since = preg_replace( |
|
| 81 | + '/;.*/', |
|
| 82 | + '', |
|
| 83 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | + ); |
|
| 85 | + $since = str_replace('GMT', '', $since); |
|
| 86 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | + $page['status'] = 304; |
|
| 88 | + $headers_only = true; |
|
| 89 | + $calculer_page = false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | + if (!$calculer_page) { |
|
| 96 | + $page['texte'] = ''; |
|
| 97 | + } else { |
|
| 98 | + // si la page est prise dans le cache |
|
| 99 | + if (!$GLOBALS['use_cache']) { |
|
| 100 | + // Informer les boutons d'admin du contexte |
|
| 101 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | + |
|
| 104 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | + // d'inversion url => objet |
|
| 106 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | + #unset($_ENV['url_propre']); |
|
| 109 | + } else { |
|
| 110 | + // Compat ascendante : |
|
| 111 | + // 1. $contexte est global |
|
| 112 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | + // et calculer la page |
|
| 114 | + if (!test_espace_prive()) { |
|
| 115 | + include_spip('inc/urls'); |
|
| 116 | + [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | + nettoyer_uri(), |
|
| 118 | + $fond, |
|
| 119 | + $GLOBALS['contexte'], |
|
| 120 | + true |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + // squelette par defaut |
|
| 124 | + if (!strlen($fond ?? '')) { |
|
| 125 | + $fond = 'sommaire'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // produire la page : peut mettre a jour $lastmodified |
|
| 129 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | + $page = $produire_page( |
|
| 131 | + $fond, |
|
| 132 | + $GLOBALS['contexte'], |
|
| 133 | + $GLOBALS['use_cache'], |
|
| 134 | + $chemin_cache, |
|
| 135 | + null, |
|
| 136 | + $page, |
|
| 137 | + $lastmodified, |
|
| 138 | + $connect |
|
| 139 | + ); |
|
| 140 | + if ($page === '') { |
|
| 141 | + $erreur = _T( |
|
| 142 | + 'info_erreur_squelette2', |
|
| 143 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | + ); |
|
| 145 | + erreur_squelette($erreur); |
|
| 146 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($page and $chemin_cache) { |
|
| 152 | + $page['cache'] = $chemin_cache; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + auto_content_type($page); |
|
| 156 | + |
|
| 157 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | + |
|
| 159 | + // Definir les entetes si ce n'est fait |
|
| 160 | + if (!$GLOBALS['flag_preserver']) { |
|
| 161 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | + if ( |
|
| 163 | + trim($page['texte']) === '' |
|
| 164 | + and _VAR_MODE !== 'debug' |
|
| 165 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | + ) { |
|
| 167 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | + } |
|
| 170 | + // pas de cache client en mode 'observation' |
|
| 171 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Entete Last-Modified: |
|
| 179 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | + if ( |
|
| 182 | + $lastmodified |
|
| 183 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | + and !isset($page['entetes']['Last-Modified']) |
|
| 185 | + ) { |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // fermer la connexion apres les headers si requete HEAD |
|
| 190 | + if ($headers_only) { |
|
| 191 | + $page['entetes']['Connection'] = 'close'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function calculer_contexte() { |
| 210 | 210 | |
| 211 | - $contexte = []; |
|
| 212 | - foreach ($_GET as $var => $val) { |
|
| 213 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | - $contexte[$var] = $val; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - foreach ($_POST as $var => $val) { |
|
| 218 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | - $contexte[$var] = $val; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $contexte; |
|
| 211 | + $contexte = []; |
|
| 212 | + foreach ($_GET as $var => $val) { |
|
| 213 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | + $contexte[$var] = $val; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + foreach ($_POST as $var => $val) { |
|
| 218 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | + $contexte[$var] = $val; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $contexte; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,25 +231,25 @@ discard block |
||
| 231 | 231 | * @return array |
| 232 | 232 | */ |
| 233 | 233 | function calculer_contexte_implicite() { |
| 234 | - static $notes = null; |
|
| 235 | - if (is_null($notes)) { |
|
| 236 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | - } |
|
| 238 | - $contexte_implicite = [ |
|
| 239 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | - 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | - 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | - 'espace' => test_espace_prive(), |
|
| 243 | - 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | - 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | - ]; |
|
| 248 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $contexte_implicite; |
|
| 234 | + static $notes = null; |
|
| 235 | + if (is_null($notes)) { |
|
| 236 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | + } |
|
| 238 | + $contexte_implicite = [ |
|
| 239 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | + 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | + 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | + 'espace' => test_espace_prive(), |
|
| 243 | + 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | + 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | + ]; |
|
| 248 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $contexte_implicite; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // |
@@ -258,55 +258,55 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | function auto_content_type($page) { |
| 260 | 260 | |
| 261 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | - $page['texte'] |
|
| 265 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | - } |
|
| 261 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | + $page['texte'] |
|
| 265 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | + } |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | function inclure_page($fond, $contexte, string $connect = '') { |
| 270 | - $use_cache = null; |
|
| 271 | - $chemin_cache = null; |
|
| 272 | - $lastinclude = null; |
|
| 273 | - $res = null; |
|
| 274 | - static $cacher, $produire_page; |
|
| 275 | - |
|
| 276 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | - // (cette precaution n'est probablement plus utile) |
|
| 279 | - unset($contexte['fond']); |
|
| 280 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | - if (is_null($cacher)) { |
|
| 283 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | - } |
|
| 285 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | - if ($cacher) { |
|
| 288 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | - } else { |
|
| 290 | - $use_cache = -1; |
|
| 291 | - } |
|
| 292 | - // $res = message d'erreur : on sort de la |
|
| 293 | - if ($res) { |
|
| 294 | - return ['texte' => $res]; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | - // produire la page : peut mettre a jour $lastinclude |
|
| 299 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | - if ($use_cache) { |
|
| 301 | - if (is_null($produire_page)) { |
|
| 302 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | - } |
|
| 304 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | - $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 270 | + $use_cache = null; |
|
| 271 | + $chemin_cache = null; |
|
| 272 | + $lastinclude = null; |
|
| 273 | + $res = null; |
|
| 274 | + static $cacher, $produire_page; |
|
| 275 | + |
|
| 276 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | + // (cette precaution n'est probablement plus utile) |
|
| 279 | + unset($contexte['fond']); |
|
| 280 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | + if (is_null($cacher)) { |
|
| 283 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | + } |
|
| 285 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | + if ($cacher) { |
|
| 288 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | + } else { |
|
| 290 | + $use_cache = -1; |
|
| 291 | + } |
|
| 292 | + // $res = message d'erreur : on sort de la |
|
| 293 | + if ($res) { |
|
| 294 | + return ['texte' => $res]; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | + // produire la page : peut mettre a jour $lastinclude |
|
| 299 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | + if ($use_cache) { |
|
| 301 | + if (is_null($produire_page)) { |
|
| 302 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | + } |
|
| 304 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | + $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 308 | + |
|
| 309 | + return $page; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -324,41 +324,41 @@ discard block |
||
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | 326 | function public_produire_page_dist( |
| 327 | - $fond, |
|
| 328 | - $contexte, |
|
| 329 | - $use_cache, |
|
| 330 | - $chemin_cache, |
|
| 331 | - $contexte_cache, |
|
| 332 | - &$page, |
|
| 333 | - &$lastinclude, |
|
| 334 | - $connect = '' |
|
| 327 | + $fond, |
|
| 328 | + $contexte, |
|
| 329 | + $use_cache, |
|
| 330 | + $chemin_cache, |
|
| 331 | + $contexte_cache, |
|
| 332 | + &$page, |
|
| 333 | + &$lastinclude, |
|
| 334 | + $connect = '' |
|
| 335 | 335 | ) { |
| 336 | - static $parametrer, $cacher; |
|
| 337 | - if (!$parametrer) { |
|
| 338 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | - } |
|
| 340 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | - // et on l'enregistre sur le disque |
|
| 342 | - if ( |
|
| 343 | - $chemin_cache |
|
| 344 | - and $use_cache > -1 |
|
| 345 | - and is_array($page) |
|
| 346 | - and count($page) |
|
| 347 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | - ) { |
|
| 350 | - if (is_null($cacher)) { |
|
| 351 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | - } |
|
| 353 | - $lastinclude = time(); |
|
| 354 | - if ($cacher) { |
|
| 355 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | - } else { |
|
| 357 | - $use_cache = -1; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $page; |
|
| 336 | + static $parametrer, $cacher; |
|
| 337 | + if (!$parametrer) { |
|
| 338 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | + } |
|
| 340 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | + // et on l'enregistre sur le disque |
|
| 342 | + if ( |
|
| 343 | + $chemin_cache |
|
| 344 | + and $use_cache > -1 |
|
| 345 | + and is_array($page) |
|
| 346 | + and count($page) |
|
| 347 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | + ) { |
|
| 350 | + if (is_null($cacher)) { |
|
| 351 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | + } |
|
| 353 | + $lastinclude = time(); |
|
| 354 | + if ($cacher) { |
|
| 355 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | + } else { |
|
| 357 | + $use_cache = -1; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $page; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Fonction inseree par le compilateur dans le code compile. |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | // 4: langue |
| 373 | 373 | |
| 374 | 374 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 375 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | - |
|
| 377 | - if (!is_array($contexte_exec)) { |
|
| 378 | - echo $contexte_exec; |
|
| 379 | - } // message d'erreur etc |
|
| 380 | - else { |
|
| 381 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | - } |
|
| 375 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | + |
|
| 377 | + if (!is_array($contexte_exec)) { |
|
| 378 | + echo $contexte_exec; |
|
| 379 | + } // message d'erreur etc |
|
| 380 | + else { |
|
| 381 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -392,101 +392,101 @@ discard block |
||
| 392 | 392 | * @return string|void |
| 393 | 393 | */ |
| 394 | 394 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 395 | - if (is_array($texte)) { |
|
| 396 | - [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | - |
|
| 398 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | - $d = $GLOBALS['delais'] ?? null; |
|
| 400 | - $GLOBALS['delais'] = $delainc; |
|
| 401 | - |
|
| 402 | - $page = recuperer_fond( |
|
| 403 | - $fond, |
|
| 404 | - $contexte_inclus, |
|
| 405 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - $texte = $page['texte']; |
|
| 409 | - |
|
| 410 | - $GLOBALS['delais'] = $d; |
|
| 411 | - // Faire remonter les entetes |
|
| 412 | - if ( |
|
| 413 | - isset($page['entetes']) |
|
| 414 | - and is_array($page['entetes']) |
|
| 415 | - ) { |
|
| 416 | - // mais pas toutes |
|
| 417 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | - unset($page['entetes']['Content-Type']); |
|
| 419 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | - $GLOBALS['page']['entetes'] = []; |
|
| 422 | - } |
|
| 423 | - $GLOBALS['page']['entetes'] = |
|
| 424 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | - if ( |
|
| 429 | - isset($page['contexte']['_pipelines']) |
|
| 430 | - and is_array($page['contexte']['_pipelines']) |
|
| 431 | - and count($page['contexte']['_pipelines']) |
|
| 432 | - ) { |
|
| 433 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | - $args['contexte'] = $page['contexte']; |
|
| 435 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | - $texte = pipeline( |
|
| 437 | - $pipe, |
|
| 438 | - [ |
|
| 439 | - 'data' => $texte, |
|
| 440 | - 'args' => $args |
|
| 441 | - ] |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | - $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 450 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | - } |
|
| 452 | - if ($echo) { |
|
| 453 | - echo $texte; |
|
| 454 | - } else { |
|
| 455 | - return $texte; |
|
| 456 | - } |
|
| 395 | + if (is_array($texte)) { |
|
| 396 | + [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | + |
|
| 398 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | + $d = $GLOBALS['delais'] ?? null; |
|
| 400 | + $GLOBALS['delais'] = $delainc; |
|
| 401 | + |
|
| 402 | + $page = recuperer_fond( |
|
| 403 | + $fond, |
|
| 404 | + $contexte_inclus, |
|
| 405 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + $texte = $page['texte']; |
|
| 409 | + |
|
| 410 | + $GLOBALS['delais'] = $d; |
|
| 411 | + // Faire remonter les entetes |
|
| 412 | + if ( |
|
| 413 | + isset($page['entetes']) |
|
| 414 | + and is_array($page['entetes']) |
|
| 415 | + ) { |
|
| 416 | + // mais pas toutes |
|
| 417 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | + unset($page['entetes']['Content-Type']); |
|
| 419 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | + $GLOBALS['page']['entetes'] = []; |
|
| 422 | + } |
|
| 423 | + $GLOBALS['page']['entetes'] = |
|
| 424 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | + if ( |
|
| 429 | + isset($page['contexte']['_pipelines']) |
|
| 430 | + and is_array($page['contexte']['_pipelines']) |
|
| 431 | + and count($page['contexte']['_pipelines']) |
|
| 432 | + ) { |
|
| 433 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | + $args['contexte'] = $page['contexte']; |
|
| 435 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | + $texte = pipeline( |
|
| 437 | + $pipe, |
|
| 438 | + [ |
|
| 439 | + 'data' => $texte, |
|
| 440 | + 'args' => $args |
|
| 441 | + ] |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | + $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 450 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | + } |
|
| 452 | + if ($echo) { |
|
| 453 | + echo $texte; |
|
| 454 | + } else { |
|
| 455 | + return $texte; |
|
| 456 | + } |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | function message_page_indisponible($page, $contexte) { |
| 460 | - static $deja = false; |
|
| 461 | - if ($deja) { |
|
| 462 | - return 'erreur'; |
|
| 463 | - } |
|
| 464 | - $codes = [ |
|
| 465 | - '404' => '404 Not Found', |
|
| 466 | - '503' => '503 Service Unavailable', |
|
| 467 | - ]; |
|
| 468 | - |
|
| 469 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | - if (!isset($contexte['lang'])) { |
|
| 473 | - include_spip('inc/lang'); |
|
| 474 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $deja = true; |
|
| 478 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | - // ex restriction d'acces => 401 |
|
| 480 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | - |
|
| 482 | - // produire la page d'erreur |
|
| 483 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | - if (!$page) { |
|
| 485 | - $page = inclure_page('404', $contexte); |
|
| 486 | - } |
|
| 487 | - $page['status'] = $contexte['status']; |
|
| 488 | - |
|
| 489 | - return $page; |
|
| 460 | + static $deja = false; |
|
| 461 | + if ($deja) { |
|
| 462 | + return 'erreur'; |
|
| 463 | + } |
|
| 464 | + $codes = [ |
|
| 465 | + '404' => '404 Not Found', |
|
| 466 | + '503' => '503 Service Unavailable', |
|
| 467 | + ]; |
|
| 468 | + |
|
| 469 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | + if (!isset($contexte['lang'])) { |
|
| 473 | + include_spip('inc/lang'); |
|
| 474 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $deja = true; |
|
| 478 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | + // ex restriction d'acces => 401 |
|
| 480 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | + |
|
| 482 | + // produire la page d'erreur |
|
| 483 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | + if (!$page) { |
|
| 485 | + $page = inclure_page('404', $contexte); |
|
| 486 | + } |
|
| 487 | + $page['status'] = $contexte['status']; |
|
| 488 | + |
|
| 489 | + return $page; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -498,44 +498,44 @@ discard block |
||
| 498 | 498 | * @return mixed |
| 499 | 499 | */ |
| 500 | 500 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 501 | - static $balise_dyn_appellee_par_modele = null; |
|
| 502 | - switch ($operation) { |
|
| 503 | - case 'read': |
|
| 504 | - return $balise_dyn_appellee_par_modele; |
|
| 505 | - case 'reset': |
|
| 506 | - $balise_dyn_appellee_par_modele = null; |
|
| 507 | - return null; |
|
| 508 | - case 'set': |
|
| 509 | - default: |
|
| 510 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | - return $arg; |
|
| 512 | - } |
|
| 501 | + static $balise_dyn_appellee_par_modele = null; |
|
| 502 | + switch ($operation) { |
|
| 503 | + case 'read': |
|
| 504 | + return $balise_dyn_appellee_par_modele; |
|
| 505 | + case 'reset': |
|
| 506 | + $balise_dyn_appellee_par_modele = null; |
|
| 507 | + return null; |
|
| 508 | + case 'set': |
|
| 509 | + default: |
|
| 510 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | + return $arg; |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // temporairement ici : a mettre dans le futur inc/modeles |
| 516 | 516 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 517 | 517 | function creer_contexte_de_modele($args) { |
| 518 | - $contexte = []; |
|
| 519 | - foreach ($args as $var => $val) { |
|
| 520 | - if (is_int($var)) { // argument pas formate |
|
| 521 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | - $var = 'align'; |
|
| 523 | - $contexte[$var] = $val; |
|
| 524 | - } else { |
|
| 525 | - $args = explode('=', $val); |
|
| 526 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | - } else // notation abregee |
|
| 529 | - { |
|
| 530 | - $contexte[trim($val)] = trim($val); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - } else { |
|
| 534 | - $contexte[$var] = $val; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $contexte; |
|
| 518 | + $contexte = []; |
|
| 519 | + foreach ($args as $var => $val) { |
|
| 520 | + if (is_int($var)) { // argument pas formate |
|
| 521 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | + $var = 'align'; |
|
| 523 | + $contexte[$var] = $val; |
|
| 524 | + } else { |
|
| 525 | + $args = explode('=', $val); |
|
| 526 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | + } else // notation abregee |
|
| 529 | + { |
|
| 530 | + $contexte[trim($val)] = trim($val); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + } else { |
|
| 534 | + $contexte[$var] = $val; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $contexte; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -550,43 +550,43 @@ discard block |
||
| 550 | 550 | * @return string |
| 551 | 551 | */ |
| 552 | 552 | function styliser_modele($modele, $id, $contexte = null) { |
| 553 | - static $styliseurs = null; |
|
| 554 | - if (is_null($styliseurs)) { |
|
| 555 | - $tables_objet = lister_tables_objets_sql(); |
|
| 556 | - foreach ($tables_objet as $table => $desc) { |
|
| 557 | - if ( |
|
| 558 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | - and function_exists($desc['modeles_styliser']) |
|
| 561 | - ) { |
|
| 562 | - $primary = id_table_objet($table); |
|
| 563 | - foreach ($desc['modeles'] as $m) { |
|
| 564 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (isset($styliseurs[$modele])) { |
|
| 571 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | - $primary = $styliseurs[$modele]['primary']; |
|
| 573 | - if (is_null($id) and $contexte) { |
|
| 574 | - if (isset($contexte['id'])) { |
|
| 575 | - $id = $contexte['id']; |
|
| 576 | - } elseif (isset($contexte[$primary])) { |
|
| 577 | - $id = $contexte[$primary]; |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - if (is_null($id)) { |
|
| 581 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | - erreur_squelette($msg); |
|
| 583 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | - $id = 0; |
|
| 585 | - } |
|
| 586 | - $modele = $styliseur($modele, $id); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $modele; |
|
| 553 | + static $styliseurs = null; |
|
| 554 | + if (is_null($styliseurs)) { |
|
| 555 | + $tables_objet = lister_tables_objets_sql(); |
|
| 556 | + foreach ($tables_objet as $table => $desc) { |
|
| 557 | + if ( |
|
| 558 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | + and function_exists($desc['modeles_styliser']) |
|
| 561 | + ) { |
|
| 562 | + $primary = id_table_objet($table); |
|
| 563 | + foreach ($desc['modeles'] as $m) { |
|
| 564 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (isset($styliseurs[$modele])) { |
|
| 571 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | + $primary = $styliseurs[$modele]['primary']; |
|
| 573 | + if (is_null($id) and $contexte) { |
|
| 574 | + if (isset($contexte['id'])) { |
|
| 575 | + $id = $contexte['id']; |
|
| 576 | + } elseif (isset($contexte[$primary])) { |
|
| 577 | + $id = $contexte[$primary]; |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + if (is_null($id)) { |
|
| 581 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + erreur_squelette($msg); |
|
| 583 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | + $id = 0; |
|
| 585 | + } |
|
| 586 | + $modele = $styliseur($modele, $id); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $modele; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -603,102 +603,102 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 605 | 605 | |
| 606 | - static $compteur; |
|
| 607 | - if (++$compteur > 10) { |
|
| 608 | - return ''; |
|
| 609 | - } # ne pas boucler indefiniment |
|
| 610 | - |
|
| 611 | - $type = strtolower($type); |
|
| 612 | - $type = styliser_modele($type, $id); |
|
| 613 | - |
|
| 614 | - $fond = $class = ''; |
|
| 615 | - |
|
| 616 | - $params = array_filter(explode('|', $params)); |
|
| 617 | - if ($params) { |
|
| 618 | - $soustype = current($params); |
|
| 619 | - $soustype = strtolower(trim($soustype)); |
|
| 620 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | - $soustype = next($params); |
|
| 622 | - $soustype = strtolower($soustype); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | - $fond = ''; |
|
| 628 | - $class = $soustype; |
|
| 629 | - } |
|
| 630 | - // enlever le sous type des params |
|
| 631 | - $params = array_diff($params, [$soustype]); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | - |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - $fond = 'modeles/' . $fond; |
|
| 642 | - // Creer le contexte |
|
| 643 | - $contexte = $env; |
|
| 644 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 645 | - |
|
| 646 | - // Le numero du modele est mis dans l'environnement |
|
| 647 | - // d'une part sous l'identifiant "id" |
|
| 648 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | - // par la fonction id_table_objet, |
|
| 650 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | - $_id = id_table_objet($type); |
|
| 652 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | - |
|
| 654 | - if (isset($class)) { |
|
| 655 | - $contexte['class'] = $class; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | - if ($lien) { |
|
| 660 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | - $contexte['lien_class'] = $lien['class']; |
|
| 663 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | - $contexte['lien_title'] = $lien['title']; |
|
| 665 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - // Traiter les parametres |
|
| 669 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | - $arg_list = creer_contexte_de_modele($params); |
|
| 671 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | - $contexte = array_merge($contexte, $arg_list); |
|
| 673 | - |
|
| 674 | - // Appliquer le modele avec le contexte |
|
| 675 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | - |
|
| 677 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | - if ( |
|
| 681 | - strstr( |
|
| 682 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | - 'spip_lien_ok' |
|
| 684 | - ) |
|
| 685 | - ) { |
|
| 686 | - $retour = inserer_attribut( |
|
| 687 | - $retour, |
|
| 688 | - 'class', |
|
| 689 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | - ); |
|
| 691 | - } else { |
|
| 692 | - if ($lien) { |
|
| 693 | - $retour = "<a href=\"" . $lien['href'] . "\" class=\"" . $lien['class'] . "\">" . $retour . '</a>'; |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $compteur--; |
|
| 698 | - |
|
| 699 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | - : $retour; |
|
| 606 | + static $compteur; |
|
| 607 | + if (++$compteur > 10) { |
|
| 608 | + return ''; |
|
| 609 | + } # ne pas boucler indefiniment |
|
| 610 | + |
|
| 611 | + $type = strtolower($type); |
|
| 612 | + $type = styliser_modele($type, $id); |
|
| 613 | + |
|
| 614 | + $fond = $class = ''; |
|
| 615 | + |
|
| 616 | + $params = array_filter(explode('|', $params)); |
|
| 617 | + if ($params) { |
|
| 618 | + $soustype = current($params); |
|
| 619 | + $soustype = strtolower(trim($soustype)); |
|
| 620 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | + $soustype = next($params); |
|
| 622 | + $soustype = strtolower($soustype); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | + $fond = ''; |
|
| 628 | + $class = $soustype; |
|
| 629 | + } |
|
| 630 | + // enlever le sous type des params |
|
| 631 | + $params = array_diff($params, [$soustype]); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | + |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + $fond = 'modeles/' . $fond; |
|
| 642 | + // Creer le contexte |
|
| 643 | + $contexte = $env; |
|
| 644 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 645 | + |
|
| 646 | + // Le numero du modele est mis dans l'environnement |
|
| 647 | + // d'une part sous l'identifiant "id" |
|
| 648 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | + // par la fonction id_table_objet, |
|
| 650 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | + $_id = id_table_objet($type); |
|
| 652 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | + |
|
| 654 | + if (isset($class)) { |
|
| 655 | + $contexte['class'] = $class; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | + if ($lien) { |
|
| 660 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | + $contexte['lien_class'] = $lien['class']; |
|
| 663 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | + $contexte['lien_title'] = $lien['title']; |
|
| 665 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + // Traiter les parametres |
|
| 669 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | + $arg_list = creer_contexte_de_modele($params); |
|
| 671 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | + $contexte = array_merge($contexte, $arg_list); |
|
| 673 | + |
|
| 674 | + // Appliquer le modele avec le contexte |
|
| 675 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | + |
|
| 677 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | + if ( |
|
| 681 | + strstr( |
|
| 682 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | + 'spip_lien_ok' |
|
| 684 | + ) |
|
| 685 | + ) { |
|
| 686 | + $retour = inserer_attribut( |
|
| 687 | + $retour, |
|
| 688 | + 'class', |
|
| 689 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | + ); |
|
| 691 | + } else { |
|
| 692 | + if ($lien) { |
|
| 693 | + $retour = "<a href=\"" . $lien['href'] . "\" class=\"" . $lien['class'] . "\">" . $retour . '</a>'; |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $compteur--; |
|
| 698 | + |
|
| 699 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | + : $retour; |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -707,105 +707,105 @@ discard block |
||
| 707 | 707 | // recuperer_fond($fond,$contexte,array('raw'=>true)) |
| 708 | 708 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 709 | 709 | |
| 710 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | - |
|
| 712 | - if (!$page) { |
|
| 713 | - return $page; |
|
| 714 | - } |
|
| 715 | - // eval $page et affecte $res |
|
| 716 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | - |
|
| 718 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | - // a destination de public/parametrer |
|
| 720 | - // pour remonter vers les inclusions appelantes |
|
| 721 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | - if ( |
|
| 724 | - isset($page['invalideurs']) |
|
| 725 | - and isset($page['invalideurs']['session']) |
|
| 726 | - ) { |
|
| 727 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $page; |
|
| 710 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | + |
|
| 712 | + if (!$page) { |
|
| 713 | + return $page; |
|
| 714 | + } |
|
| 715 | + // eval $page et affecte $res |
|
| 716 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | + |
|
| 718 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | + // a destination de public/parametrer |
|
| 720 | + // pour remonter vers les inclusions appelantes |
|
| 721 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | + if ( |
|
| 724 | + isset($page['invalideurs']) |
|
| 725 | + and isset($page['invalideurs']['session']) |
|
| 726 | + ) { |
|
| 727 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $page; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
| 734 | 734 | function page_base_href(&$texte) { |
| 735 | - static $set_html_base = null; |
|
| 736 | - if (is_null($set_html_base)) { |
|
| 737 | - if (!defined('_SET_HTML_BASE')) { |
|
| 738 | - // si la profondeur est superieure a 1 |
|
| 739 | - // est que ce n'est pas une url page ni une url action |
|
| 740 | - // activer par defaut |
|
| 741 | - $set_html_base = (( |
|
| 742 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | - and !_request('action')) ? true : false); |
|
| 745 | - } else { |
|
| 746 | - $set_html_base = _SET_HTML_BASE; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - if ( |
|
| 751 | - $set_html_base |
|
| 752 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | - ) { |
|
| 756 | - $head = substr($texte, 0, $poshead); |
|
| 757 | - $insert = false; |
|
| 758 | - $href_base = false; |
|
| 759 | - if (strpos($head, '<base') === false) { |
|
| 760 | - $insert = true; |
|
| 761 | - } else { |
|
| 762 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | - // sinon juste re-ecrire les ancres si besoin |
|
| 764 | - $insert = true; |
|
| 765 | - include_spip('inc/filtres'); |
|
| 766 | - $bases = extraire_balises($head, 'base'); |
|
| 767 | - foreach ($bases as $base) { |
|
| 768 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | - $insert = false; |
|
| 770 | - break; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if ($insert) { |
|
| 776 | - include_spip('inc/filtres_mini'); |
|
| 777 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | - $href_base = url_absolue('./'); |
|
| 779 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | - } |
|
| 785 | - $texte = $head . substr($texte, $poshead); |
|
| 786 | - } |
|
| 787 | - if ($href_base) { |
|
| 788 | - // gerer les ancres |
|
| 789 | - $base = $_SERVER['REQUEST_URI']; |
|
| 790 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | - } |
|
| 794 | - if (strpos($texte, "href='#") !== false) { |
|
| 795 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | - } |
|
| 797 | - if (strpos($texte, 'href="#') !== false) { |
|
| 798 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 735 | + static $set_html_base = null; |
|
| 736 | + if (is_null($set_html_base)) { |
|
| 737 | + if (!defined('_SET_HTML_BASE')) { |
|
| 738 | + // si la profondeur est superieure a 1 |
|
| 739 | + // est que ce n'est pas une url page ni une url action |
|
| 740 | + // activer par defaut |
|
| 741 | + $set_html_base = (( |
|
| 742 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | + and !_request('action')) ? true : false); |
|
| 745 | + } else { |
|
| 746 | + $set_html_base = _SET_HTML_BASE; |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + if ( |
|
| 751 | + $set_html_base |
|
| 752 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | + ) { |
|
| 756 | + $head = substr($texte, 0, $poshead); |
|
| 757 | + $insert = false; |
|
| 758 | + $href_base = false; |
|
| 759 | + if (strpos($head, '<base') === false) { |
|
| 760 | + $insert = true; |
|
| 761 | + } else { |
|
| 762 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | + // sinon juste re-ecrire les ancres si besoin |
|
| 764 | + $insert = true; |
|
| 765 | + include_spip('inc/filtres'); |
|
| 766 | + $bases = extraire_balises($head, 'base'); |
|
| 767 | + foreach ($bases as $base) { |
|
| 768 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | + $insert = false; |
|
| 770 | + break; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if ($insert) { |
|
| 776 | + include_spip('inc/filtres_mini'); |
|
| 777 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | + $href_base = url_absolue('./'); |
|
| 779 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | + } |
|
| 785 | + $texte = $head . substr($texte, $poshead); |
|
| 786 | + } |
|
| 787 | + if ($href_base) { |
|
| 788 | + // gerer les ancres |
|
| 789 | + $base = $_SERVER['REQUEST_URI']; |
|
| 790 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | + } |
|
| 794 | + if (strpos($texte, "href='#") !== false) { |
|
| 795 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | + } |
|
| 797 | + if (strpos($texte, 'href="#') !== false) { |
|
| 798 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | |
| 805 | 805 | // Envoyer les entetes, en retenant ceux qui sont a usage interne |
| 806 | 806 | // et demarrent par X-Spip-... |
| 807 | 807 | function envoyer_entetes($entetes) { |
| 808 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | - } |
|
| 808 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | + } |
|
| 811 | 811 | } |
@@ -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 | /** |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | **/ |
| 48 | 48 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 49 | 49 | |
| 50 | - $not = $crit->not; |
|
| 51 | - $boucle = &$boucles[$idb]; |
|
| 52 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 50 | + $not = $crit->not; |
|
| 51 | + $boucle = &$boucles[$idb]; |
|
| 52 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 53 | 53 | |
| 54 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 55 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 54 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 55 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | * @return void|array |
| 70 | 70 | **/ |
| 71 | 71 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 72 | - $not = $crit->not; |
|
| 73 | - $boucle = &$boucles[$idb]; |
|
| 74 | - $id = $boucle->primary; |
|
| 75 | - |
|
| 76 | - if ($not or !$id) { |
|
| 77 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 78 | - } |
|
| 79 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 80 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 72 | + $not = $crit->not; |
|
| 73 | + $boucle = &$boucles[$idb]; |
|
| 74 | + $id = $boucle->primary; |
|
| 75 | + |
|
| 76 | + if ($not or !$id) { |
|
| 77 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 78 | + } |
|
| 79 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 80 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -97,73 +97,73 @@ discard block |
||
| 97 | 97 | * @return void|array |
| 98 | 98 | **/ |
| 99 | 99 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 100 | - $boucle = &$boucles[$idb]; |
|
| 101 | - $primary = $boucle->primary; |
|
| 102 | - |
|
| 103 | - // la table nécessite une clé primaire, non composée |
|
| 104 | - if (!$primary or strpos($primary, ',')) { |
|
| 105 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 109 | - |
|
| 110 | - // le doublon s'applique sur un type de boucle (article) |
|
| 111 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 112 | - |
|
| 113 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 114 | - // on obtient $nom = "'article' . 'nom'" |
|
| 115 | - if (isset($crit->param[0])) { |
|
| 116 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 120 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 121 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 122 | - |
|
| 123 | - // on crée un sql_in avec la clé primaire de la table |
|
| 124 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 125 | - // $doublons et son index, ici $nom |
|
| 126 | - |
|
| 127 | - // debut du code "sql_in('articles.id_article', " |
|
| 128 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 129 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 130 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 131 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 132 | - |
|
| 133 | - // le debut complet du code des doublons |
|
| 134 | - $debut_doub = $debut_in . $debut_doub; |
|
| 135 | - |
|
| 136 | - // nom du doublon "('article' . 'nom')]" |
|
| 137 | - $fin_doub = "($nom)]"; |
|
| 138 | - |
|
| 139 | - // si on trouve un autre critère doublon, |
|
| 140 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 141 | - foreach ($boucle->where as $k => $w) { |
|
| 142 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 143 | - // fusionner le sql_in (du where) |
|
| 144 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 145 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 146 | - $x = strpos($boucle->hash, $init_comment); |
|
| 147 | - $len = strlen($init_comment); |
|
| 148 | - $boucle->hash = |
|
| 149 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 150 | - |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 156 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 157 | - |
|
| 158 | - // déclarer le doublon s'il n'existe pas encore |
|
| 159 | - $boucle->hash .= $init_comment . $init_code; |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 163 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 164 | - # {!doublons A}{doublons B} |
|
| 165 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 166 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 100 | + $boucle = &$boucles[$idb]; |
|
| 101 | + $primary = $boucle->primary; |
|
| 102 | + |
|
| 103 | + // la table nécessite une clé primaire, non composée |
|
| 104 | + if (!$primary or strpos($primary, ',')) { |
|
| 105 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 109 | + |
|
| 110 | + // le doublon s'applique sur un type de boucle (article) |
|
| 111 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 112 | + |
|
| 113 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 114 | + // on obtient $nom = "'article' . 'nom'" |
|
| 115 | + if (isset($crit->param[0])) { |
|
| 116 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 120 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 121 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 122 | + |
|
| 123 | + // on crée un sql_in avec la clé primaire de la table |
|
| 124 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 125 | + // $doublons et son index, ici $nom |
|
| 126 | + |
|
| 127 | + // debut du code "sql_in('articles.id_article', " |
|
| 128 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 129 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 130 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 131 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 132 | + |
|
| 133 | + // le debut complet du code des doublons |
|
| 134 | + $debut_doub = $debut_in . $debut_doub; |
|
| 135 | + |
|
| 136 | + // nom du doublon "('article' . 'nom')]" |
|
| 137 | + $fin_doub = "($nom)]"; |
|
| 138 | + |
|
| 139 | + // si on trouve un autre critère doublon, |
|
| 140 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 141 | + foreach ($boucle->where as $k => $w) { |
|
| 142 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 143 | + // fusionner le sql_in (du where) |
|
| 144 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 145 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 146 | + $x = strpos($boucle->hash, $init_comment); |
|
| 147 | + $len = strlen($init_comment); |
|
| 148 | + $boucle->hash = |
|
| 149 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 150 | + |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 156 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 157 | + |
|
| 158 | + // déclarer le doublon s'il n'existe pas encore |
|
| 159 | + $boucle->hash .= $init_comment . $init_code; |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 163 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 164 | + # {!doublons A}{doublons B} |
|
| 165 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 166 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | * @return void |
| 185 | 185 | **/ |
| 186 | 186 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 187 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 188 | - $param = 'oui'; |
|
| 189 | - } |
|
| 190 | - if ($crit->not) { |
|
| 191 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 192 | - } |
|
| 193 | - $boucle = &$boucles[$idb]; |
|
| 194 | - $boucle->lang_select = $param; |
|
| 187 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 188 | + $param = 'oui'; |
|
| 189 | + } |
|
| 190 | + if ($crit->not) { |
|
| 191 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 192 | + } |
|
| 193 | + $boucle = &$boucles[$idb]; |
|
| 194 | + $boucle->lang_select = $param; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | * @return void |
| 214 | 214 | **/ |
| 215 | 215 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 216 | - [$un, $deux] = $crit->param; |
|
| 217 | - $un = $un[0]->texte; |
|
| 218 | - $deux = $deux[0]->texte; |
|
| 219 | - if ($deux) { |
|
| 220 | - $boucles[$idb]->limit = |
|
| 221 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 222 | - } else { |
|
| 223 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 224 | - } |
|
| 216 | + [$un, $deux] = $crit->param; |
|
| 217 | + $un = $un[0]->texte; |
|
| 218 | + $deux = $deux[0]->texte; |
|
| 219 | + if ($deux) { |
|
| 220 | + $boucles[$idb]->limit = |
|
| 221 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 222 | + } else { |
|
| 223 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -255,58 +255,58 @@ discard block |
||
| 255 | 255 | **/ |
| 256 | 256 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 257 | 257 | |
| 258 | - $boucle = &$boucles[$idb]; |
|
| 259 | - // definition de la taille de la page |
|
| 260 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 261 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 262 | - |
|
| 263 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 264 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | - } else { |
|
| 266 | - $r = intval($r[2]); |
|
| 267 | - $pas = strval($r ?: 10); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Calcul du nommage de la pagination si il existe. |
|
| 271 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | - $type = "'$idb'"; |
|
| 274 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | - // Syntaxe {pagination 20, nom} |
|
| 276 | - if (isset($crit->param[0][1])) { |
|
| 277 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | - elseif (isset($crit->param[1][0])) { |
|
| 280 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 284 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | - $partie = |
|
| 286 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 289 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 290 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 291 | - . "\t}\n" |
|
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | - |
|
| 294 | - $boucle->hash .= ' |
|
| 258 | + $boucle = &$boucles[$idb]; |
|
| 259 | + // definition de la taille de la page |
|
| 260 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 261 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 262 | + |
|
| 263 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 264 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | + } else { |
|
| 266 | + $r = intval($r[2]); |
|
| 267 | + $pas = strval($r ?: 10); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Calcul du nommage de la pagination si il existe. |
|
| 271 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | + $type = "'$idb'"; |
|
| 274 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | + // Syntaxe {pagination 20, nom} |
|
| 276 | + if (isset($crit->param[0][1])) { |
|
| 277 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | + elseif (isset($crit->param[1][0])) { |
|
| 280 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 284 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | + $partie = |
|
| 286 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 289 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 290 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 291 | + . "\t}\n" |
|
| 292 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | + |
|
| 294 | + $boucle->hash .= ' |
|
| 295 | 295 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 296 | 296 | |
| 297 | - $boucle->total_parties = $pas; |
|
| 298 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | - // sauf si pas de primaire, ou si primaire composee |
|
| 301 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | - if ( |
|
| 304 | - $boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 297 | + $boucle->total_parties = $pas; |
|
| 298 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | + // sauf si pas de primaire, ou si primaire composee |
|
| 301 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | + if ( |
|
| 304 | + $boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - [ |
|
| 397 | - "'OR'", |
|
| 398 | - [ |
|
| 399 | - "'AND'", |
|
| 400 | - ["'='", "'$table.id_trad'", 0], |
|
| 401 | - ["'='", "'$table.$prim'", $dprim] |
|
| 402 | - ], |
|
| 403 | - [ |
|
| 404 | - "'AND'", |
|
| 405 | - ["'>'", "'$table.id_trad'", 0], |
|
| 406 | - ["'='", "'$table.id_trad'", $arg] |
|
| 407 | - ] |
|
| 408 | - ]; |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + [ |
|
| 397 | + "'OR'", |
|
| 398 | + [ |
|
| 399 | + "'AND'", |
|
| 400 | + ["'='", "'$table.id_trad'", 0], |
|
| 401 | + ["'='", "'$table.$prim'", $dprim] |
|
| 402 | + ], |
|
| 403 | + [ |
|
| 404 | + "'AND'", |
|
| 405 | + ["'>'", "'$table.id_trad'", 0], |
|
| 406 | + ["'='", "'$table.id_trad'", $arg] |
|
| 407 | + ] |
|
| 408 | + ]; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - [ |
|
| 432 | - "'OR'", |
|
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | - ]; |
|
| 436 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + [ |
|
| 432 | + "'OR'", |
|
| 433 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | + ]; |
|
| 436 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,17 +450,17 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | - |
|
| 458 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | - else { |
|
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | - } |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | + |
|
| 458 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | + else { |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -491,37 +491,37 @@ discard block |
||
| 491 | 491 | **/ |
| 492 | 492 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 493 | 493 | |
| 494 | - $not = $crit->not; |
|
| 495 | - $boucle = &$boucles[$idb]; |
|
| 496 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | - if (isset($crit->param[0])) { |
|
| 498 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | - // sinon on le prend chez une boucle parente |
|
| 500 | - } else { |
|
| 501 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - //Trouver une jointure |
|
| 505 | - $champ = 'id_rubrique'; |
|
| 506 | - $desc = $boucle->show; |
|
| 507 | - //Seulement si necessaire |
|
| 508 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | - $decompose = decompose_champ_id_objet($champ); |
|
| 514 | - $champ = array_shift($decompose); |
|
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - $cle = $boucle->id_table; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 494 | + $not = $crit->not; |
|
| 495 | + $boucle = &$boucles[$idb]; |
|
| 496 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | + if (isset($crit->param[0])) { |
|
| 498 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | + // sinon on le prend chez une boucle parente |
|
| 500 | + } else { |
|
| 501 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + //Trouver une jointure |
|
| 505 | + $champ = 'id_rubrique'; |
|
| 506 | + $desc = $boucle->show; |
|
| 507 | + //Seulement si necessaire |
|
| 508 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | + $decompose = decompose_champ_id_objet($champ); |
|
| 514 | + $champ = array_shift($decompose); |
|
| 515 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + $cle = $boucle->id_table; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -537,15 +537,15 @@ discard block |
||
| 537 | 537 | **/ |
| 538 | 538 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 539 | 539 | |
| 540 | - $boucle = &$boucles[$idb]; |
|
| 541 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | - $serveur = $boucle->sql_serveur; |
|
| 540 | + $boucle = &$boucles[$idb]; |
|
| 541 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | + $serveur = $boucle->sql_serveur; |
|
| 543 | 543 | |
| 544 | - $c = "sql_in('" . |
|
| 545 | - $boucle->id_table . '.' . $boucle->primary |
|
| 546 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('" . |
|
| 545 | + $boucle->id_table . '.' . $boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | 547 | |
| 548 | - $boucle->where[] = $c; |
|
| 548 | + $boucle->where[] = $c; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -567,31 +567,31 @@ discard block |
||
| 567 | 567 | * @return void|array |
| 568 | 568 | **/ |
| 569 | 569 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 570 | - if ($t = isset($crit->param[0])) { |
|
| 571 | - $t = $crit->param[0]; |
|
| 572 | - if ($t[0]->type == 'texte') { |
|
| 573 | - $t = $t[0]->texte; |
|
| 574 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | - $t = table_objet_sql($r[1]); |
|
| 576 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | - if ($t) { |
|
| 578 | - $t .= '.' . $r[2]; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } else { |
|
| 582 | - $t = '".' |
|
| 583 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | - . '."'; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - if ($t) { |
|
| 588 | - $boucles[$idb]->group[] = $t; |
|
| 589 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | - $boucles[$idb]->select[] = $t; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | - } |
|
| 570 | + if ($t = isset($crit->param[0])) { |
|
| 571 | + $t = $crit->param[0]; |
|
| 572 | + if ($t[0]->type == 'texte') { |
|
| 573 | + $t = $t[0]->texte; |
|
| 574 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | + $t = table_objet_sql($r[1]); |
|
| 576 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | + if ($t) { |
|
| 578 | + $t .= '.' . $r[2]; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } else { |
|
| 582 | + $t = '".' |
|
| 583 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | + . '."'; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + if ($t) { |
|
| 588 | + $boucles[$idb]->group[] = $t; |
|
| 589 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | + $boucles[$idb]->select[] = $t; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | + } |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return void |
| 612 | 612 | **/ |
| 613 | 613 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 614 | - $boucles[$idb]->group = []; |
|
| 614 | + $boucles[$idb]->group = []; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -648,44 +648,44 @@ discard block |
||
| 648 | 648 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 649 | 649 | */ |
| 650 | 650 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 651 | - if (isset($crit->param[0])) { |
|
| 652 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | - $boucle = $boucles[$idb]; |
|
| 654 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 656 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | - if ( |
|
| 660 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | - ) { |
|
| 663 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | - } else { |
|
| 665 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | - } |
|
| 651 | + if (isset($crit->param[0])) { |
|
| 652 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | + $boucle = $boucles[$idb]; |
|
| 654 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 656 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | + if ( |
|
| 660 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | + ) { |
|
| 663 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | + } else { |
|
| 665 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 674 | - $boucle = $boucles[$idb]; |
|
| 675 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 676 | - $var = '$champs_' . $idb; |
|
| 677 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 678 | - if (!$desc) { |
|
| 679 | - $desc = $boucle->show['field']; |
|
| 680 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 681 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | - } |
|
| 683 | - if ($desc) { |
|
| 684 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 685 | - } |
|
| 686 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 687 | - |
|
| 688 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 674 | + $boucle = $boucles[$idb]; |
|
| 675 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 676 | + $var = '$champs_' . $idb; |
|
| 677 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 678 | + if (!$desc) { |
|
| 679 | + $desc = $boucle->show['field']; |
|
| 680 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 681 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | + } |
|
| 683 | + if ($desc) { |
|
| 684 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 685 | + } |
|
| 686 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 687 | + |
|
| 688 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 725 | 725 | */ |
| 726 | 726 | function critere_par_dist($idb, &$boucles, $crit) { |
| 727 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 727 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -746,93 +746,93 @@ discard block |
||
| 746 | 746 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 747 | 747 | */ |
| 748 | 748 | function critere_parinverse($idb, &$boucles, $crit) { |
| 749 | - $boucle = &$boucles[$idb]; |
|
| 750 | - |
|
| 751 | - $sens = $collecte = ''; |
|
| 752 | - if ($crit->not) { |
|
| 753 | - $sens = " . ' DESC'"; |
|
| 754 | - } |
|
| 755 | - if (isset($boucle->modificateur['collate'])) { |
|
| 756 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - // Pour chaque paramètre du critère |
|
| 760 | - foreach ($crit->param as $tri) { |
|
| 761 | - $order = $fct = ''; |
|
| 762 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 763 | - if ($tri[0]->type != 'texte') { |
|
| 764 | - // calculer le order dynamique qui verifie les champs |
|
| 765 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 766 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 767 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 768 | - } |
|
| 769 | - // tris textuels {par titre} |
|
| 770 | - else { |
|
| 771 | - $par = array_shift($tri); |
|
| 772 | - $par = $par->texte; |
|
| 773 | - |
|
| 774 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 775 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 776 | - $expression = trim($m[1]); |
|
| 777 | - $champ = trim($m[2]); |
|
| 778 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 780 | - } else { |
|
| 781 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 785 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 786 | - // {par FONCTION(champ)} |
|
| 787 | - if (isset($match) and count($match) > 2) { |
|
| 788 | - $par = substr($match[2], 1, -1); |
|
| 789 | - $fct = $match[1]; |
|
| 790 | - } |
|
| 791 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 792 | - if ($par == 'hasard') { |
|
| 793 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 794 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 795 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | - } else { |
|
| 797 | - // cas général {par champ}, {par table.champ}, ... |
|
| 798 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - // on ne sait pas traiter… |
|
| 803 | - else { |
|
| 804 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 808 | - if (is_array($order)) { |
|
| 809 | - return $order; |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 814 | - $t = $m[1]; |
|
| 815 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 816 | - $boucle->select[] = $t; |
|
| 817 | - } |
|
| 818 | - } else { |
|
| 819 | - $sens = ''; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - if ($fct) { |
|
| 823 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 824 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 825 | - } else { |
|
| 826 | - $order = "'$fct(' . $order . ')'"; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - $t = $order . $collecte . $sens; |
|
| 830 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 831 | - $t = $r[1] . $r[2]; |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - $boucle->order[] = $t; |
|
| 835 | - } |
|
| 749 | + $boucle = &$boucles[$idb]; |
|
| 750 | + |
|
| 751 | + $sens = $collecte = ''; |
|
| 752 | + if ($crit->not) { |
|
| 753 | + $sens = " . ' DESC'"; |
|
| 754 | + } |
|
| 755 | + if (isset($boucle->modificateur['collate'])) { |
|
| 756 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + // Pour chaque paramètre du critère |
|
| 760 | + foreach ($crit->param as $tri) { |
|
| 761 | + $order = $fct = ''; |
|
| 762 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 763 | + if ($tri[0]->type != 'texte') { |
|
| 764 | + // calculer le order dynamique qui verifie les champs |
|
| 765 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 766 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 767 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 768 | + } |
|
| 769 | + // tris textuels {par titre} |
|
| 770 | + else { |
|
| 771 | + $par = array_shift($tri); |
|
| 772 | + $par = $par->texte; |
|
| 773 | + |
|
| 774 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 775 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 776 | + $expression = trim($m[1]); |
|
| 777 | + $champ = trim($m[2]); |
|
| 778 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 780 | + } else { |
|
| 781 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 785 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 786 | + // {par FONCTION(champ)} |
|
| 787 | + if (isset($match) and count($match) > 2) { |
|
| 788 | + $par = substr($match[2], 1, -1); |
|
| 789 | + $fct = $match[1]; |
|
| 790 | + } |
|
| 791 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 792 | + if ($par == 'hasard') { |
|
| 793 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 794 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 795 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | + } else { |
|
| 797 | + // cas général {par champ}, {par table.champ}, ... |
|
| 798 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + // on ne sait pas traiter… |
|
| 803 | + else { |
|
| 804 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 808 | + if (is_array($order)) { |
|
| 809 | + return $order; |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 814 | + $t = $m[1]; |
|
| 815 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 816 | + $boucle->select[] = $t; |
|
| 817 | + } |
|
| 818 | + } else { |
|
| 819 | + $sens = ''; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + if ($fct) { |
|
| 823 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 824 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 825 | + } else { |
|
| 826 | + $order = "'$fct(' . $order . ')'"; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + $t = $order . $collecte . $sens; |
|
| 830 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 831 | + $t = $r[1] . $r[2]; |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + $boucle->order[] = $t; |
|
| 835 | + } |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | /** |
@@ -846,13 +846,13 @@ discard block |
||
| 846 | 846 | * @return string Clause pour le Order by |
| 847 | 847 | */ |
| 848 | 848 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 849 | - $boucle = &$boucles[$idb]; |
|
| 850 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 851 | - $parha = 'rand() AS hasard'; |
|
| 852 | - if (!in_array($parha, $boucle->select)) { |
|
| 853 | - $boucle->select[] = $parha; |
|
| 854 | - } |
|
| 855 | - return "'hasard'"; |
|
| 849 | + $boucle = &$boucles[$idb]; |
|
| 850 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 851 | + $parha = 'rand() AS hasard'; |
|
| 852 | + if (!in_array($parha, $boucle->select)) { |
|
| 853 | + $boucle->select[] = $parha; |
|
| 854 | + } |
|
| 855 | + return "'hasard'"; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -876,24 +876,24 @@ discard block |
||
| 876 | 876 | * @return string|array Clause pour le Order by (array si erreur) |
| 877 | 877 | */ |
| 878 | 878 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 879 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 880 | - if (is_array($_champ)) { |
|
| 881 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 882 | - } |
|
| 883 | - $boucle = &$boucles[$idb]; |
|
| 884 | - $texte = '0+' . $_champ; |
|
| 885 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 886 | - if ($suite !== "''") { |
|
| 887 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 888 | - } |
|
| 889 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 890 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 891 | - |
|
| 892 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 893 | - $orderassinum = trim($orderassinum, "'"); |
|
| 894 | - |
|
| 895 | - $order = "'$orderassinum, $asnum'"; |
|
| 896 | - return $order; |
|
| 879 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 880 | + if (is_array($_champ)) { |
|
| 881 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 882 | + } |
|
| 883 | + $boucle = &$boucles[$idb]; |
|
| 884 | + $texte = '0+' . $_champ; |
|
| 885 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 886 | + if ($suite !== "''") { |
|
| 887 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 888 | + } |
|
| 889 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 890 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 891 | + |
|
| 892 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 893 | + $orderassinum = trim($orderassinum, "'"); |
|
| 894 | + |
|
| 895 | + $order = "'$orderassinum, $asnum'"; |
|
| 896 | + return $order; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -914,35 +914,35 @@ discard block |
||
| 914 | 914 | * @return string|array Clause pour le Order by (array si erreur) |
| 915 | 915 | */ |
| 916 | 916 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 917 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 918 | - if (is_array($_champ)) { |
|
| 919 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 920 | - } |
|
| 921 | - $boucle = &$boucles[$idb]; |
|
| 922 | - $texte = '0+' . $_champ; |
|
| 923 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 924 | - if ($suite !== "''") { |
|
| 925 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - $as = false; |
|
| 929 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 930 | - foreach ($boucle->select as $s) { |
|
| 931 | - if (strpos($s, $select) === 0) { |
|
| 932 | - $as = trim(substr($s, strlen($select))); |
|
| 933 | - if (!preg_match(',\W,', $as)) { |
|
| 934 | - break; |
|
| 935 | - } |
|
| 936 | - $as = false; |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - if (!$as) { |
|
| 941 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 942 | - $boucle->select[] = $select . $as; |
|
| 943 | - } |
|
| 944 | - $order = "'$as'"; |
|
| 945 | - return $order; |
|
| 917 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 918 | + if (is_array($_champ)) { |
|
| 919 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 920 | + } |
|
| 921 | + $boucle = &$boucles[$idb]; |
|
| 922 | + $texte = '0+' . $_champ; |
|
| 923 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 924 | + if ($suite !== "''") { |
|
| 925 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + $as = false; |
|
| 929 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 930 | + foreach ($boucle->select as $s) { |
|
| 931 | + if (strpos($s, $select) === 0) { |
|
| 932 | + $as = trim(substr($s, strlen($select))); |
|
| 933 | + if (!preg_match(',\W,', $as)) { |
|
| 934 | + break; |
|
| 935 | + } |
|
| 936 | + $as = false; |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + if (!$as) { |
|
| 941 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 942 | + $boucle->select[] = $select . $as; |
|
| 943 | + } |
|
| 944 | + $order = "'$as'"; |
|
| 945 | + return $order; |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | |
@@ -962,14 +962,14 @@ discard block |
||
| 962 | 962 | * @return string|array Clause pour le Order by (array si erreur) |
| 963 | 963 | */ |
| 964 | 964 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 965 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 966 | - if (is_array($_champ)) { |
|
| 967 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 968 | - } |
|
| 969 | - $boucle = &$boucles[$idb]; |
|
| 970 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 971 | - $order = "'multi'"; |
|
| 972 | - return $order; |
|
| 965 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 966 | + if (is_array($_champ)) { |
|
| 967 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 968 | + } |
|
| 969 | + $boucle = &$boucles[$idb]; |
|
| 970 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 971 | + $order = "'multi'"; |
|
| 972 | + return $order; |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
@@ -988,56 +988,56 @@ discard block |
||
| 988 | 988 | * @return array|string |
| 989 | 989 | */ |
| 990 | 990 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 991 | - $boucle = &$boucles[$idb]; |
|
| 992 | - $desc = $boucle->show; |
|
| 993 | - |
|
| 994 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 995 | - if (isset($desc['field'][$par])) { |
|
| 996 | - $par = $boucle->id_table . '.' . $par; |
|
| 997 | - } |
|
| 998 | - // le champ est peut être une jointure |
|
| 999 | - else { |
|
| 1000 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1001 | - $champ = $par; |
|
| 1002 | - |
|
| 1003 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1004 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1005 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1006 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1007 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1008 | - [, $table, $champ] = $r; |
|
| 1009 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1010 | - $table = table_objet_sql($table); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1014 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1015 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1016 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1017 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1018 | - } elseif ( |
|
| 1019 | - $boucle->jointures_explicites |
|
| 1020 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1021 | - ) { |
|
| 1022 | - $par = $alias . '.' . $champ; |
|
| 1023 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1024 | - $par = $alias . '.' . $champ; |
|
| 1025 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1026 | - } elseif ( |
|
| 1027 | - $table_alias |
|
| 1028 | - and isset($boucle->from[$table_alias]) |
|
| 1029 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1030 | - ) { |
|
| 1031 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1032 | - } elseif ($table) { |
|
| 1033 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1034 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1035 | - } else { |
|
| 1036 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - return $raw ? $par : "'$par'"; |
|
| 991 | + $boucle = &$boucles[$idb]; |
|
| 992 | + $desc = $boucle->show; |
|
| 993 | + |
|
| 994 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 995 | + if (isset($desc['field'][$par])) { |
|
| 996 | + $par = $boucle->id_table . '.' . $par; |
|
| 997 | + } |
|
| 998 | + // le champ est peut être une jointure |
|
| 999 | + else { |
|
| 1000 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1001 | + $champ = $par; |
|
| 1002 | + |
|
| 1003 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1004 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1005 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1006 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1007 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1008 | + [, $table, $champ] = $r; |
|
| 1009 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1010 | + $table = table_objet_sql($table); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1014 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1015 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1016 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1017 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1018 | + } elseif ( |
|
| 1019 | + $boucle->jointures_explicites |
|
| 1020 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1021 | + ) { |
|
| 1022 | + $par = $alias . '.' . $champ; |
|
| 1023 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1024 | + $par = $alias . '.' . $champ; |
|
| 1025 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1026 | + } elseif ( |
|
| 1027 | + $table_alias |
|
| 1028 | + and isset($boucle->from[$table_alias]) |
|
| 1029 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1030 | + ) { |
|
| 1031 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1032 | + } elseif ($table) { |
|
| 1033 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1034 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1035 | + } else { |
|
| 1036 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + return $raw ? $par : "'$par'"; |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | /** |
@@ -1051,11 +1051,11 @@ discard block |
||
| 1051 | 1051 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1052 | 1052 | */ |
| 1053 | 1053 | function critere_par_joint($table, $champ, &$boucle) { |
| 1054 | - $t = array_search($table, $boucle->from); |
|
| 1055 | - if (!$t) { |
|
| 1056 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1057 | - } |
|
| 1058 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1054 | + $t = array_search($table, $boucle->from); |
|
| 1055 | + if (!$t) { |
|
| 1056 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1057 | + } |
|
| 1058 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1080,33 +1080,33 @@ discard block |
||
| 1080 | 1080 | */ |
| 1081 | 1081 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1082 | 1082 | |
| 1083 | - $boucle = &$boucles[$idb]; |
|
| 1084 | - // Classement par ordre inverse |
|
| 1085 | - if ($crit->not) { |
|
| 1086 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1087 | - } else { |
|
| 1088 | - $order = "' DESC'"; |
|
| 1089 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1090 | - if (isset($crit->param[0])) { |
|
| 1091 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1092 | - $order = "(($critere)?' DESC':'')"; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1096 | - if (!$n) { |
|
| 1097 | - if (isset($boucle->default_order[0])) { |
|
| 1098 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1099 | - } else { |
|
| 1100 | - $boucle->default_order[] = ' DESC'; |
|
| 1101 | - } |
|
| 1102 | - } else { |
|
| 1103 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1104 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1105 | - $t = $r[1] . $r[2]; |
|
| 1106 | - } |
|
| 1107 | - $boucle->order[$n - 1] = $t; |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1083 | + $boucle = &$boucles[$idb]; |
|
| 1084 | + // Classement par ordre inverse |
|
| 1085 | + if ($crit->not) { |
|
| 1086 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1087 | + } else { |
|
| 1088 | + $order = "' DESC'"; |
|
| 1089 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1090 | + if (isset($crit->param[0])) { |
|
| 1091 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1092 | + $order = "(($critere)?' DESC':'')"; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1096 | + if (!$n) { |
|
| 1097 | + if (isset($boucle->default_order[0])) { |
|
| 1098 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1099 | + } else { |
|
| 1100 | + $boucle->default_order[] = ' DESC'; |
|
| 1101 | + } |
|
| 1102 | + } else { |
|
| 1103 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1104 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1105 | + $t = $r[1] . $r[2]; |
|
| 1106 | + } |
|
| 1107 | + $boucle->order[$n - 1] = $t; |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | /** |
@@ -1118,139 +1118,139 @@ discard block |
||
| 1118 | 1118 | * @return void|array |
| 1119 | 1119 | */ |
| 1120 | 1120 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1121 | - $boucle = &$boucles[$idb]; |
|
| 1121 | + $boucle = &$boucles[$idb]; |
|
| 1122 | 1122 | |
| 1123 | - $sens = $collecte = ''; |
|
| 1124 | - if ($crit->not) { |
|
| 1125 | - $sens = " . ' DESC'"; |
|
| 1126 | - } |
|
| 1123 | + $sens = $collecte = ''; |
|
| 1124 | + if ($crit->not) { |
|
| 1125 | + $sens = " . ' DESC'"; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - $crit2 = clone $crit; |
|
| 1129 | - $crit2->not = false; |
|
| 1130 | - $crit2->param = [reset($crit->param)]; |
|
| 1131 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1128 | + $crit2 = clone $crit; |
|
| 1129 | + $crit2->not = false; |
|
| 1130 | + $crit2->param = [reset($crit->param)]; |
|
| 1131 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1132 | 1132 | |
| 1133 | - // erreur ? |
|
| 1134 | - if (is_array($res)) { |
|
| 1135 | - return $res; |
|
| 1136 | - } |
|
| 1133 | + // erreur ? |
|
| 1134 | + if (is_array($res)) { |
|
| 1135 | + return $res; |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - $_order = array_pop($boucle->order); |
|
| 1138 | + $_order = array_pop($boucle->order); |
|
| 1139 | 1139 | |
| 1140 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1140 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1141 | 1141 | |
| 1142 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | - $boucle->order[] = $order; |
|
| 1142 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | + $boucle->order[] = $order; |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | |
| 1147 | 1147 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1148 | - $params = $crit->param; |
|
| 1149 | - |
|
| 1150 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1151 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - $boucle = &$boucles[$idb]; |
|
| 1155 | - $parent = $boucle->id_parent; |
|
| 1156 | - $fields = $boucle->show['field']; |
|
| 1157 | - |
|
| 1158 | - $date = array_shift($params); |
|
| 1159 | - $type = array_shift($params); |
|
| 1160 | - |
|
| 1161 | - // la valeur $type doit etre connue a la compilation |
|
| 1162 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1163 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1164 | - |
|
| 1165 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1166 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1167 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1168 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1169 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1170 | - $date = $date[0]->texte; |
|
| 1171 | - if (!isset($fields[$date])) { |
|
| 1172 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1173 | - } |
|
| 1174 | - } else { |
|
| 1175 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1176 | - $noms = array_keys($fields); |
|
| 1177 | - $defaut = $noms[0]; |
|
| 1178 | - $noms = join(' ', $noms); |
|
| 1179 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1180 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1181 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1182 | - } |
|
| 1183 | - $annee = $params ? array_shift($params) : ''; |
|
| 1184 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1185 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1186 | - ') ? $x : date("Y"))'; |
|
| 1187 | - |
|
| 1188 | - $mois = $params ? array_shift($params) : ''; |
|
| 1189 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1190 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1191 | - ') ? $x : date("m"))'; |
|
| 1192 | - |
|
| 1193 | - $jour = $params ? array_shift($params) : ''; |
|
| 1194 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1195 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1196 | - ') ? $x : date("d"))'; |
|
| 1197 | - |
|
| 1198 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1199 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1200 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1201 | - ') ? $x : date("Y"))'; |
|
| 1202 | - |
|
| 1203 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1204 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1205 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1206 | - ') ? $x : date("m"))'; |
|
| 1207 | - |
|
| 1208 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1209 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1210 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1211 | - ') ? $x : date("d"))'; |
|
| 1212 | - |
|
| 1213 | - $date = $boucle->id_table . ".$date"; |
|
| 1214 | - |
|
| 1215 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1216 | - if ($type == 'jour') { |
|
| 1217 | - $boucle->where[] = [ |
|
| 1218 | - "'='", |
|
| 1219 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1220 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1221 | - ]; |
|
| 1222 | - } elseif ($type == 'mois') { |
|
| 1223 | - $boucle->where[] = [ |
|
| 1224 | - "'='", |
|
| 1225 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1226 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1227 | - ]; |
|
| 1228 | - } elseif ($type == 'semaine') { |
|
| 1229 | - $boucle->where[] = [ |
|
| 1230 | - "'AND'", |
|
| 1231 | - [ |
|
| 1232 | - "'>='", |
|
| 1233 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1234 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1235 | - ], |
|
| 1236 | - [ |
|
| 1237 | - "'<='", |
|
| 1238 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1239 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1240 | - ] |
|
| 1241 | - ]; |
|
| 1242 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1243 | - $boucle->where[] = [ |
|
| 1244 | - "'AND'", |
|
| 1245 | - [ |
|
| 1246 | - "'>='", |
|
| 1247 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1248 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1249 | - ], |
|
| 1250 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1251 | - ]; |
|
| 1252 | - } |
|
| 1253 | - // sinon on prend tout |
|
| 1148 | + $params = $crit->param; |
|
| 1149 | + |
|
| 1150 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1151 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + $boucle = &$boucles[$idb]; |
|
| 1155 | + $parent = $boucle->id_parent; |
|
| 1156 | + $fields = $boucle->show['field']; |
|
| 1157 | + |
|
| 1158 | + $date = array_shift($params); |
|
| 1159 | + $type = array_shift($params); |
|
| 1160 | + |
|
| 1161 | + // la valeur $type doit etre connue a la compilation |
|
| 1162 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1163 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1164 | + |
|
| 1165 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1166 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1167 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1168 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1169 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1170 | + $date = $date[0]->texte; |
|
| 1171 | + if (!isset($fields[$date])) { |
|
| 1172 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1173 | + } |
|
| 1174 | + } else { |
|
| 1175 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1176 | + $noms = array_keys($fields); |
|
| 1177 | + $defaut = $noms[0]; |
|
| 1178 | + $noms = join(' ', $noms); |
|
| 1179 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1180 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1181 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1182 | + } |
|
| 1183 | + $annee = $params ? array_shift($params) : ''; |
|
| 1184 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1185 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1186 | + ') ? $x : date("Y"))'; |
|
| 1187 | + |
|
| 1188 | + $mois = $params ? array_shift($params) : ''; |
|
| 1189 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1190 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1191 | + ') ? $x : date("m"))'; |
|
| 1192 | + |
|
| 1193 | + $jour = $params ? array_shift($params) : ''; |
|
| 1194 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1195 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1196 | + ') ? $x : date("d"))'; |
|
| 1197 | + |
|
| 1198 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1199 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1200 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1201 | + ') ? $x : date("Y"))'; |
|
| 1202 | + |
|
| 1203 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1204 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1205 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1206 | + ') ? $x : date("m"))'; |
|
| 1207 | + |
|
| 1208 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1209 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1210 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1211 | + ') ? $x : date("d"))'; |
|
| 1212 | + |
|
| 1213 | + $date = $boucle->id_table . ".$date"; |
|
| 1214 | + |
|
| 1215 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1216 | + if ($type == 'jour') { |
|
| 1217 | + $boucle->where[] = [ |
|
| 1218 | + "'='", |
|
| 1219 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1220 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1221 | + ]; |
|
| 1222 | + } elseif ($type == 'mois') { |
|
| 1223 | + $boucle->where[] = [ |
|
| 1224 | + "'='", |
|
| 1225 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1226 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1227 | + ]; |
|
| 1228 | + } elseif ($type == 'semaine') { |
|
| 1229 | + $boucle->where[] = [ |
|
| 1230 | + "'AND'", |
|
| 1231 | + [ |
|
| 1232 | + "'>='", |
|
| 1233 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1234 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1235 | + ], |
|
| 1236 | + [ |
|
| 1237 | + "'<='", |
|
| 1238 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1239 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1240 | + ] |
|
| 1241 | + ]; |
|
| 1242 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1243 | + $boucle->where[] = [ |
|
| 1244 | + "'AND'", |
|
| 1245 | + [ |
|
| 1246 | + "'>='", |
|
| 1247 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1248 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1249 | + ], |
|
| 1250 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1251 | + ]; |
|
| 1252 | + } |
|
| 1253 | + // sinon on prend tout |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1275,33 +1275,33 @@ discard block |
||
| 1275 | 1275 | * @return void |
| 1276 | 1276 | **/ |
| 1277 | 1277 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1278 | - $boucle = &$boucles[$idb]; |
|
| 1279 | - $a1 = $crit->param[0]; |
|
| 1280 | - $a2 = $crit->param[1]; |
|
| 1281 | - $op = $crit->op; |
|
| 1282 | - |
|
| 1283 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1284 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1285 | - |
|
| 1286 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1287 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1288 | - } else { |
|
| 1289 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1290 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1291 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1292 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1293 | - $mode = (($op == '/') ? '/' : |
|
| 1294 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1295 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1296 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1297 | - $boucle->limit = |
|
| 1298 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1299 | - . ".','." |
|
| 1300 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1301 | - } else { |
|
| 1302 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1278 | + $boucle = &$boucles[$idb]; |
|
| 1279 | + $a1 = $crit->param[0]; |
|
| 1280 | + $a2 = $crit->param[1]; |
|
| 1281 | + $op = $crit->op; |
|
| 1282 | + |
|
| 1283 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1284 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1285 | + |
|
| 1286 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1287 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1288 | + } else { |
|
| 1289 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1290 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1291 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1292 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1293 | + $mode = (($op == '/') ? '/' : |
|
| 1294 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1295 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1296 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1297 | + $boucle->limit = |
|
| 1298 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1299 | + . ".','." |
|
| 1300 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1301 | + } else { |
|
| 1302 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | 1307 | /** |
@@ -1329,63 +1329,63 @@ discard block |
||
| 1329 | 1329 | * @return void |
| 1330 | 1330 | **/ |
| 1331 | 1331 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1332 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1333 | - |
|
| 1334 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1335 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1336 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1337 | - // {1/3} |
|
| 1338 | - if ($op1 == '/') { |
|
| 1339 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1340 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1341 | - "($total_parties ? $total_parties : 1)"; |
|
| 1342 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1343 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1344 | - } else { |
|
| 1345 | - // cas {n-1,x} |
|
| 1346 | - if ($op1 == '-') { |
|
| 1347 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - // cas {x,n-1} |
|
| 1351 | - if ($op2 == '-') { |
|
| 1352 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1353 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1354 | - ($total_parties . ' - 1')); |
|
| 1355 | - } else { |
|
| 1356 | - // {x,1} ou {pagination} |
|
| 1357 | - $fin = '$debut_boucle' |
|
| 1358 | - . (is_numeric($total_parties) ? |
|
| 1359 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1360 | - ('+' . $total_parties . ' - 1')); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1364 | - if ($op1 == 'p') { |
|
| 1365 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1366 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1367 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - // Notes : |
|
| 1372 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1373 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1374 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1375 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1376 | - |
|
| 1377 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1378 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1379 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1380 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1381 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1382 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1383 | - . "\n\tif (\$debut_boucle>0" |
|
| 1384 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1385 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1386 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1387 | - |
|
| 1388 | - $boucles[$id_boucle]->partie = " |
|
| 1332 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1333 | + |
|
| 1334 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1335 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1336 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1337 | + // {1/3} |
|
| 1338 | + if ($op1 == '/') { |
|
| 1339 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1340 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1341 | + "($total_parties ? $total_parties : 1)"; |
|
| 1342 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1343 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1344 | + } else { |
|
| 1345 | + // cas {n-1,x} |
|
| 1346 | + if ($op1 == '-') { |
|
| 1347 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + // cas {x,n-1} |
|
| 1351 | + if ($op2 == '-') { |
|
| 1352 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1353 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1354 | + ($total_parties . ' - 1')); |
|
| 1355 | + } else { |
|
| 1356 | + // {x,1} ou {pagination} |
|
| 1357 | + $fin = '$debut_boucle' |
|
| 1358 | + . (is_numeric($total_parties) ? |
|
| 1359 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1360 | + ('+' . $total_parties . ' - 1')); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1364 | + if ($op1 == 'p') { |
|
| 1365 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1366 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1367 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + // Notes : |
|
| 1372 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1373 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1374 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1375 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1376 | + |
|
| 1377 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1378 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1379 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1380 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1381 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1382 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1383 | + . "\n\tif (\$debut_boucle>0" |
|
| 1384 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1385 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1386 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1387 | + |
|
| 1388 | + $boucles[$id_boucle]->partie = " |
|
| 1389 | 1389 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1390 | 1390 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1391 | 1391 | } |
@@ -1402,26 +1402,26 @@ discard block |
||
| 1402 | 1402 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1403 | 1403 | **/ |
| 1404 | 1404 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1405 | - if ($param[0]->type != 'texte') { |
|
| 1406 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1407 | - if (isset($param[1]->texte)) { |
|
| 1408 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1409 | - |
|
| 1410 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1411 | - } else { |
|
| 1412 | - return ["intval($a1)", 0]; |
|
| 1413 | - } |
|
| 1414 | - } else { |
|
| 1415 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1416 | - $a1 = $m[1]; |
|
| 1417 | - if (empty($m[3])) { |
|
| 1418 | - return [$a1, 0]; |
|
| 1419 | - } elseif (!empty($m[4])) { |
|
| 1420 | - return [$a1, $m[4]]; |
|
| 1421 | - } else { |
|
| 1422 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1423 | - } |
|
| 1424 | - } |
|
| 1405 | + if ($param[0]->type != 'texte') { |
|
| 1406 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1407 | + if (isset($param[1]->texte)) { |
|
| 1408 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1409 | + |
|
| 1410 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1411 | + } else { |
|
| 1412 | + return ["intval($a1)", 0]; |
|
| 1413 | + } |
|
| 1414 | + } else { |
|
| 1415 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1416 | + $a1 = $m[1]; |
|
| 1417 | + if (empty($m[3])) { |
|
| 1418 | + return [$a1, 0]; |
|
| 1419 | + } elseif (!empty($m[4])) { |
|
| 1420 | + return [$a1, $m[4]]; |
|
| 1421 | + } else { |
|
| 1422 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1423 | + } |
|
| 1424 | + } |
|
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | 1427 | |
@@ -1448,47 +1448,47 @@ discard block |
||
| 1448 | 1448 | * array : Erreur sur un des critères |
| 1449 | 1449 | **/ |
| 1450 | 1450 | function calculer_criteres($idb, &$boucles) { |
| 1451 | - $msg = ''; |
|
| 1452 | - $boucle = $boucles[$idb]; |
|
| 1453 | - $table = strtoupper($boucle->type_requete); |
|
| 1454 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1455 | - |
|
| 1456 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1457 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1458 | - if (!is_array($boucle->criteres)) { |
|
| 1459 | - return []; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - foreach ($boucle->criteres as $crit) { |
|
| 1463 | - $critere = $crit->op; |
|
| 1464 | - // critere personnalise ? |
|
| 1465 | - if ( |
|
| 1466 | - (!$serveur or |
|
| 1467 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1468 | - and (!function_exists($f = $f . '_dist')) |
|
| 1469 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - ) |
|
| 1472 | - ) |
|
| 1473 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1474 | - and (!function_exists($f = $f . '_dist')) |
|
| 1475 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1476 | - and (!function_exists($f = $f . '_dist')) |
|
| 1477 | - ) { |
|
| 1478 | - // fonction critere standard |
|
| 1479 | - $f = $defaut; |
|
| 1480 | - } |
|
| 1481 | - // compile le critere |
|
| 1482 | - $res = $f($idb, $boucles, $crit); |
|
| 1483 | - |
|
| 1484 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1485 | - if (is_array($res)) { |
|
| 1486 | - $msg = $res; |
|
| 1487 | - erreur_squelette($msg, $boucle); |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - return $msg; |
|
| 1451 | + $msg = ''; |
|
| 1452 | + $boucle = $boucles[$idb]; |
|
| 1453 | + $table = strtoupper($boucle->type_requete); |
|
| 1454 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1455 | + |
|
| 1456 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1457 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1458 | + if (!is_array($boucle->criteres)) { |
|
| 1459 | + return []; |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + foreach ($boucle->criteres as $crit) { |
|
| 1463 | + $critere = $crit->op; |
|
| 1464 | + // critere personnalise ? |
|
| 1465 | + if ( |
|
| 1466 | + (!$serveur or |
|
| 1467 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1468 | + and (!function_exists($f = $f . '_dist')) |
|
| 1469 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1470 | + and (!function_exists($f = $f . '_dist')) |
|
| 1471 | + ) |
|
| 1472 | + ) |
|
| 1473 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1474 | + and (!function_exists($f = $f . '_dist')) |
|
| 1475 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1476 | + and (!function_exists($f = $f . '_dist')) |
|
| 1477 | + ) { |
|
| 1478 | + // fonction critere standard |
|
| 1479 | + $f = $defaut; |
|
| 1480 | + } |
|
| 1481 | + // compile le critere |
|
| 1482 | + $res = $f($idb, $boucles, $crit); |
|
| 1483 | + |
|
| 1484 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1485 | + if (is_array($res)) { |
|
| 1486 | + $msg = $res; |
|
| 1487 | + erreur_squelette($msg, $boucle); |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + return $msg; |
|
| 1492 | 1492 | } |
| 1493 | 1493 | |
| 1494 | 1494 | /** |
@@ -1503,11 +1503,11 @@ discard block |
||
| 1503 | 1503 | * @return string Code compilé rééchappé |
| 1504 | 1504 | */ |
| 1505 | 1505 | function kwote($lisp, $serveur = '', $type = '') { |
| 1506 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1507 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1508 | - } else { |
|
| 1509 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1510 | - } |
|
| 1506 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1507 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1508 | + } else { |
|
| 1509 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1510 | + } |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | |
@@ -1526,81 +1526,81 @@ discard block |
||
| 1526 | 1526 | * @return void|array |
| 1527 | 1527 | **/ |
| 1528 | 1528 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1529 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1530 | - if (!$r) { |
|
| 1531 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1532 | - } |
|
| 1533 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1534 | - |
|
| 1535 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1536 | - |
|
| 1537 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1538 | - $where = $in; |
|
| 1539 | - if ($crit->cond) { |
|
| 1540 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1541 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1542 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1543 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - if ($crit->exclus) { |
|
| 1547 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1548 | - $where = ["'NOT'", $where]; |
|
| 1549 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1550 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1551 | - { |
|
| 1552 | - $where = [ |
|
| 1553 | - "'NOT'", |
|
| 1554 | - [ |
|
| 1555 | - "'IN'", |
|
| 1556 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1557 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1558 | - ] |
|
| 1559 | - ]; |
|
| 1560 | - } |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - $boucles[$idb]->where[] = $where; |
|
| 1564 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1565 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1566 | - } |
|
| 1529 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1530 | + if (!$r) { |
|
| 1531 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1532 | + } |
|
| 1533 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1534 | + |
|
| 1535 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1536 | + |
|
| 1537 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1538 | + $where = $in; |
|
| 1539 | + if ($crit->cond) { |
|
| 1540 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1541 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1542 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1543 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + if ($crit->exclus) { |
|
| 1547 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1548 | + $where = ["'NOT'", $where]; |
|
| 1549 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1550 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1551 | + { |
|
| 1552 | + $where = [ |
|
| 1553 | + "'NOT'", |
|
| 1554 | + [ |
|
| 1555 | + "'IN'", |
|
| 1556 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1557 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1558 | + ] |
|
| 1559 | + ]; |
|
| 1560 | + } |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + $boucles[$idb]->where[] = $where; |
|
| 1564 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1565 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1566 | + } |
|
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1570 | - static $num = []; |
|
| 1571 | - $descr = $boucles[$idb]->descr; |
|
| 1572 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1573 | - |
|
| 1574 | - $var = '$in' . $cpt++; |
|
| 1575 | - $x = "\n\t$var = array();"; |
|
| 1576 | - foreach ($val as $k => $v) { |
|
| 1577 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1578 | - // optimiser le traitement des constantes |
|
| 1579 | - if (is_numeric($r[2])) { |
|
| 1580 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1581 | - } else { |
|
| 1582 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1583 | - } |
|
| 1584 | - } else { |
|
| 1585 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1586 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1587 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1588 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1589 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - $boucles[$idb]->in .= $x; |
|
| 1594 | - |
|
| 1595 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1596 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1597 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1598 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1599 | - if (!$crit2) { |
|
| 1600 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1570 | + static $num = []; |
|
| 1571 | + $descr = $boucles[$idb]->descr; |
|
| 1572 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1573 | + |
|
| 1574 | + $var = '$in' . $cpt++; |
|
| 1575 | + $x = "\n\t$var = array();"; |
|
| 1576 | + foreach ($val as $k => $v) { |
|
| 1577 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1578 | + // optimiser le traitement des constantes |
|
| 1579 | + if (is_numeric($r[2])) { |
|
| 1580 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1581 | + } else { |
|
| 1582 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1583 | + } |
|
| 1584 | + } else { |
|
| 1585 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1586 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1587 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1588 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1589 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + $boucles[$idb]->in .= $x; |
|
| 1594 | + |
|
| 1595 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1596 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1597 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1598 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1599 | + if (!$crit2) { |
|
| 1600 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1616,22 +1616,22 @@ discard block |
||
| 1616 | 1616 | * @return void |
| 1617 | 1617 | */ |
| 1618 | 1618 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1619 | - $boucle = &$boucles[$idb]; |
|
| 1620 | - if (isset($crit->param[0])) { |
|
| 1621 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1622 | - } else { |
|
| 1623 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - if ($crit->cond) { |
|
| 1627 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - if ($crit->not) { |
|
| 1631 | - $_where = "array('NOT',$_where)"; |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - $boucle->where[] = $_where; |
|
| 1619 | + $boucle = &$boucles[$idb]; |
|
| 1620 | + if (isset($crit->param[0])) { |
|
| 1621 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1622 | + } else { |
|
| 1623 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + if ($crit->cond) { |
|
| 1627 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + if ($crit->not) { |
|
| 1631 | + $_where = "array('NOT',$_where)"; |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + $boucle->where[] = $_where; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | /** |
@@ -1659,31 +1659,31 @@ discard block |
||
| 1659 | 1659 | * @return void |
| 1660 | 1660 | */ |
| 1661 | 1661 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1662 | - /** @var Boucle $boucle */ |
|
| 1663 | - $boucle = $boucles[$idb]; |
|
| 1664 | - |
|
| 1665 | - $champs = lister_champs_id_conditionnel( |
|
| 1666 | - $boucle->show['table'], |
|
| 1667 | - $boucle->show, |
|
| 1668 | - $boucle->sql_serveur |
|
| 1669 | - ); |
|
| 1670 | - |
|
| 1671 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1672 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1673 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1674 | - } |
|
| 1675 | - // nous aider en mode debug. |
|
| 1676 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1677 | - $boucle->modificateur['id_'] = $champs; |
|
| 1678 | - |
|
| 1679 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1680 | - foreach ($champs as $champ) { |
|
| 1681 | - $critere_id_table = new Critere(); |
|
| 1682 | - $critere_id_table->op = $champ; |
|
| 1683 | - $critere_id_table->cond = '?'; |
|
| 1684 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1685 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1686 | - } |
|
| 1662 | + /** @var Boucle $boucle */ |
|
| 1663 | + $boucle = $boucles[$idb]; |
|
| 1664 | + |
|
| 1665 | + $champs = lister_champs_id_conditionnel( |
|
| 1666 | + $boucle->show['table'], |
|
| 1667 | + $boucle->show, |
|
| 1668 | + $boucle->sql_serveur |
|
| 1669 | + ); |
|
| 1670 | + |
|
| 1671 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1672 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1673 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1674 | + } |
|
| 1675 | + // nous aider en mode debug. |
|
| 1676 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1677 | + $boucle->modificateur['id_'] = $champs; |
|
| 1678 | + |
|
| 1679 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1680 | + foreach ($champs as $champ) { |
|
| 1681 | + $critere_id_table = new Critere(); |
|
| 1682 | + $critere_id_table->op = $champ; |
|
| 1683 | + $critere_id_table->cond = '?'; |
|
| 1684 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1685 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1686 | + } |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | /** |
@@ -1703,75 +1703,75 @@ discard block |
||
| 1703 | 1703 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1704 | 1704 | */ |
| 1705 | 1705 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1706 | - // calculer la description de la table |
|
| 1707 | - if (!is_array($desc)) { |
|
| 1708 | - $desc = description_table($table, $serveur); |
|
| 1709 | - } |
|
| 1710 | - if (!$desc) { |
|
| 1711 | - return []; |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - // Les champs id_xx de la table demandée |
|
| 1715 | - $champs = array_filter( |
|
| 1716 | - array_keys($desc['field']), |
|
| 1717 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1718 | - ); |
|
| 1719 | - |
|
| 1720 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1721 | - if ( |
|
| 1722 | - in_array('id_rubrique', $champs) |
|
| 1723 | - and !in_array('id_secteur', $champs) |
|
| 1724 | - ) { |
|
| 1725 | - $champs[] = 'id_secteur'; |
|
| 1726 | - } |
|
| 1727 | - |
|
| 1728 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1729 | - if ($serveur) { |
|
| 1730 | - return $champs; |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - $primary = false; |
|
| 1734 | - $associable = false; |
|
| 1735 | - include_spip('action/editer_liens'); |
|
| 1736 | - |
|
| 1737 | - if (isset($desc['type'])) { |
|
| 1738 | - $primary = id_table_objet($desc['type']); |
|
| 1739 | - $associable = objet_associable($desc['type']); |
|
| 1740 | - } |
|
| 1741 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1742 | - $associable = true; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // liste de toutes les tables principales, sauf la notre |
|
| 1746 | - $tables = lister_tables_objets_sql(); |
|
| 1747 | - unset($tables[$table]); |
|
| 1748 | - |
|
| 1749 | - foreach ($tables as $_table => $_desc) { |
|
| 1750 | - if ( |
|
| 1751 | - $associable |
|
| 1752 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1753 | - or objet_associable($_desc['type']) |
|
| 1754 | - ) { |
|
| 1755 | - $champs[] = id_table_objet($_table); |
|
| 1756 | - } |
|
| 1757 | - } |
|
| 1758 | - $champs = array_values(array_unique($champs)); |
|
| 1759 | - |
|
| 1760 | - // Exclusions de certains id |
|
| 1761 | - $exclusions = pipeline( |
|
| 1762 | - 'exclure_id_conditionnel', |
|
| 1763 | - [ |
|
| 1764 | - 'args' => [ |
|
| 1765 | - 'table' => $table, |
|
| 1766 | - 'id_table_objet' => $primary, |
|
| 1767 | - 'associable' => $associable, |
|
| 1768 | - ], |
|
| 1769 | - 'data' => [], |
|
| 1770 | - ] |
|
| 1771 | - ); |
|
| 1772 | - $champs = array_diff($champs, $exclusions); |
|
| 1773 | - |
|
| 1774 | - return $champs; |
|
| 1706 | + // calculer la description de la table |
|
| 1707 | + if (!is_array($desc)) { |
|
| 1708 | + $desc = description_table($table, $serveur); |
|
| 1709 | + } |
|
| 1710 | + if (!$desc) { |
|
| 1711 | + return []; |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + // Les champs id_xx de la table demandée |
|
| 1715 | + $champs = array_filter( |
|
| 1716 | + array_keys($desc['field']), |
|
| 1717 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1718 | + ); |
|
| 1719 | + |
|
| 1720 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1721 | + if ( |
|
| 1722 | + in_array('id_rubrique', $champs) |
|
| 1723 | + and !in_array('id_secteur', $champs) |
|
| 1724 | + ) { |
|
| 1725 | + $champs[] = 'id_secteur'; |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1729 | + if ($serveur) { |
|
| 1730 | + return $champs; |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + $primary = false; |
|
| 1734 | + $associable = false; |
|
| 1735 | + include_spip('action/editer_liens'); |
|
| 1736 | + |
|
| 1737 | + if (isset($desc['type'])) { |
|
| 1738 | + $primary = id_table_objet($desc['type']); |
|
| 1739 | + $associable = objet_associable($desc['type']); |
|
| 1740 | + } |
|
| 1741 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1742 | + $associable = true; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // liste de toutes les tables principales, sauf la notre |
|
| 1746 | + $tables = lister_tables_objets_sql(); |
|
| 1747 | + unset($tables[$table]); |
|
| 1748 | + |
|
| 1749 | + foreach ($tables as $_table => $_desc) { |
|
| 1750 | + if ( |
|
| 1751 | + $associable |
|
| 1752 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1753 | + or objet_associable($_desc['type']) |
|
| 1754 | + ) { |
|
| 1755 | + $champs[] = id_table_objet($_table); |
|
| 1756 | + } |
|
| 1757 | + } |
|
| 1758 | + $champs = array_values(array_unique($champs)); |
|
| 1759 | + |
|
| 1760 | + // Exclusions de certains id |
|
| 1761 | + $exclusions = pipeline( |
|
| 1762 | + 'exclure_id_conditionnel', |
|
| 1763 | + [ |
|
| 1764 | + 'args' => [ |
|
| 1765 | + 'table' => $table, |
|
| 1766 | + 'id_table_objet' => $primary, |
|
| 1767 | + 'associable' => $associable, |
|
| 1768 | + ], |
|
| 1769 | + 'data' => [], |
|
| 1770 | + ] |
|
| 1771 | + ); |
|
| 1772 | + $champs = array_diff($champs, $exclusions); |
|
| 1773 | + |
|
| 1774 | + return $champs; |
|
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | 1777 | /** |
@@ -1826,28 +1826,28 @@ discard block |
||
| 1826 | 1826 | * @return void |
| 1827 | 1827 | */ |
| 1828 | 1828 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1829 | - $boucle = &$boucles[$idb]; |
|
| 1830 | - |
|
| 1831 | - // definition du champ par defaut |
|
| 1832 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1833 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1835 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1836 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1837 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1838 | - |
|
| 1839 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1840 | - |
|
| 1841 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1842 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1843 | - |
|
| 1844 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1845 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1846 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1847 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1848 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1849 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1850 | - $boucle->hash .= " |
|
| 1829 | + $boucle = &$boucles[$idb]; |
|
| 1830 | + |
|
| 1831 | + // definition du champ par defaut |
|
| 1832 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1833 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1835 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1836 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1837 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1838 | + |
|
| 1839 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1840 | + |
|
| 1841 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1842 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1843 | + |
|
| 1844 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1845 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1846 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1847 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1848 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1849 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1850 | + $boucle->hash .= " |
|
| 1851 | 1851 | \$senstri = ''; |
| 1852 | 1852 | \$tri = $_tri; |
| 1853 | 1853 | if (\$tri){ |
@@ -1855,8 +1855,8 @@ discard block |
||
| 1855 | 1855 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1856 | 1856 | }; |
| 1857 | 1857 | "; |
| 1858 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1859 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1858 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1859 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | # criteres de comparaison |
@@ -1873,21 +1873,21 @@ discard block |
||
| 1873 | 1873 | * @return void|array |
| 1874 | 1874 | **/ |
| 1875 | 1875 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1876 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1877 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1878 | - calculer_critere_parties($idb, $boucles, $crit); |
|
| 1879 | - return; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1883 | - if (!$r) { |
|
| 1884 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1885 | - # if (!$crit->cond) { |
|
| 1886 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1887 | - # } |
|
| 1888 | - } else { |
|
| 1889 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1890 | - } |
|
| 1876 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1877 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1878 | + calculer_critere_parties($idb, $boucles, $crit); |
|
| 1879 | + return; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1883 | + if (!$r) { |
|
| 1884 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1885 | + # if (!$crit->cond) { |
|
| 1886 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1887 | + # } |
|
| 1888 | + } else { |
|
| 1889 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1890 | + } |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | |
@@ -1907,62 +1907,62 @@ discard block |
||
| 1907 | 1907 | * @return void |
| 1908 | 1908 | **/ |
| 1909 | 1909 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1910 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1911 | - |
|
| 1912 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1913 | - |
|
| 1914 | - // inserer la negation (cf !...) |
|
| 1915 | - |
|
| 1916 | - if ($crit->not) { |
|
| 1917 | - $where = ["'NOT'", $where]; |
|
| 1918 | - } |
|
| 1919 | - if ($crit->exclus) { |
|
| 1920 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1921 | - $where = ["'NOT'", $where]; |
|
| 1922 | - } else { |
|
| 1923 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1924 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1925 | - $where = [ |
|
| 1926 | - "'NOT'", |
|
| 1927 | - [ |
|
| 1928 | - "'IN'", |
|
| 1929 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1930 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1931 | - ] |
|
| 1932 | - ]; |
|
| 1933 | - } |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - // inserer la condition (cf {lang?}) |
|
| 1937 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1938 | - if ($crit->cond) { |
|
| 1939 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1940 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1941 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1942 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1943 | - } |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - if ($op === '=' and !$crit->not) { |
|
| 1947 | - $where = [ |
|
| 1948 | - "'?'", |
|
| 1949 | - "(is_array($pred))", |
|
| 1950 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1951 | - $where |
|
| 1952 | - ]; |
|
| 1953 | - } |
|
| 1954 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1955 | - if ($where_complement) { |
|
| 1956 | - // condition annexe du type "AND (objet='article')" |
|
| 1957 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1958 | - } |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - $boucles[$idb]->where[] = $where; |
|
| 1962 | - if ($where_complement) { |
|
| 1963 | - // condition annexe du type "AND (objet='article')" |
|
| 1964 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1965 | - } |
|
| 1910 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1911 | + |
|
| 1912 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1913 | + |
|
| 1914 | + // inserer la negation (cf !...) |
|
| 1915 | + |
|
| 1916 | + if ($crit->not) { |
|
| 1917 | + $where = ["'NOT'", $where]; |
|
| 1918 | + } |
|
| 1919 | + if ($crit->exclus) { |
|
| 1920 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1921 | + $where = ["'NOT'", $where]; |
|
| 1922 | + } else { |
|
| 1923 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1924 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1925 | + $where = [ |
|
| 1926 | + "'NOT'", |
|
| 1927 | + [ |
|
| 1928 | + "'IN'", |
|
| 1929 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1930 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1931 | + ] |
|
| 1932 | + ]; |
|
| 1933 | + } |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + // inserer la condition (cf {lang?}) |
|
| 1937 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1938 | + if ($crit->cond) { |
|
| 1939 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1940 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1941 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1942 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1943 | + } |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + if ($op === '=' and !$crit->not) { |
|
| 1947 | + $where = [ |
|
| 1948 | + "'?'", |
|
| 1949 | + "(is_array($pred))", |
|
| 1950 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1951 | + $where |
|
| 1952 | + ]; |
|
| 1953 | + } |
|
| 1954 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1955 | + if ($where_complement) { |
|
| 1956 | + // condition annexe du type "AND (objet='article')" |
|
| 1957 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1958 | + } |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + $boucles[$idb]->where[] = $where; |
|
| 1962 | + if ($where_complement) { |
|
| 1963 | + // condition annexe du type "AND (objet='article')" |
|
| 1964 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1965 | + } |
|
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | 1968 | |
@@ -2003,165 +2003,165 @@ discard block |
||
| 2003 | 2003 | **/ |
| 2004 | 2004 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2005 | 2005 | |
| 2006 | - $boucle = &$boucles[$idb]; |
|
| 2007 | - $type = $boucle->type_requete; |
|
| 2008 | - $table = $boucle->id_table; |
|
| 2009 | - $desc = $boucle->show; |
|
| 2010 | - $col_vraie = null; |
|
| 2011 | - |
|
| 2012 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2013 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2014 | - |
|
| 2015 | - $col_alias = $col; |
|
| 2016 | - $where_complement = false; |
|
| 2017 | - |
|
| 2018 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2019 | - if ($col == 'id_enfant') { |
|
| 2020 | - $col = $boucle->primary; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2024 | - if ( |
|
| 2025 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2027 | - ) { |
|
| 2028 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2029 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2030 | - else { |
|
| 2031 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2032 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2033 | - } |
|
| 2034 | - |
|
| 2035 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2036 | - // sauf si exception declaree : sauter cette etape |
|
| 2037 | - else { |
|
| 2038 | - if ( |
|
| 2039 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2040 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2041 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2042 | - ) { |
|
| 2043 | - $e = decompose_champ_id_objet($col); |
|
| 2044 | - $col = array_shift($e); |
|
| 2045 | - $where_complement = primary_doublee($e, $table); |
|
| 2046 | - } // Cas particulier : expressions de date |
|
| 2047 | - else { |
|
| 2048 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2049 | - [$col, $col_vraie] = $c; |
|
| 2050 | - $table = ''; |
|
| 2051 | - } // table explicitée {mots.titre} |
|
| 2052 | - else { |
|
| 2053 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2054 | - [, $table, $col] = $r; |
|
| 2055 | - $col_alias = $col; |
|
| 2056 | - |
|
| 2057 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2058 | - if ( |
|
| 2059 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2060 | - and isset($desc['field'][$col]) |
|
| 2061 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2062 | - ) { |
|
| 2063 | - $table = $cle; |
|
| 2064 | - } else { |
|
| 2065 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2066 | - } |
|
| 2067 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2068 | - if (!$table) { |
|
| 2069 | - return ''; |
|
| 2070 | - } |
|
| 2071 | - } |
|
| 2072 | - // si le champ n'est pas trouvé dans la table, |
|
| 2073 | - // on cherche si une jointure peut l'obtenir |
|
| 2074 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2075 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2076 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2077 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2078 | - } |
|
| 2079 | - else { |
|
| 2080 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2081 | - if (!$r) { |
|
| 2082 | - return ''; |
|
| 2083 | - } |
|
| 2084 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2085 | - } |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2093 | - // Dans tous les cas, |
|
| 2094 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2095 | - // et passer dans sql_quote avec le type si connu |
|
| 2096 | - // et int sinon si la valeur est numerique |
|
| 2097 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2098 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2099 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2100 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2101 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2102 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2103 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2104 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2105 | - } |
|
| 2106 | - // sinon expliciter les |
|
| 2107 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2108 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2109 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2110 | - // sans toucher aux |
|
| 2111 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2112 | - // sql_quote(truc,'','varchar') |
|
| 2113 | - elseif ( |
|
| 2114 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2115 | - // si pas deja un type |
|
| 2116 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2117 | - ) { |
|
| 2118 | - $r = $r[1] |
|
| 2119 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2120 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2121 | - $val[0] = "sql_quote($r)"; |
|
| 2122 | - } |
|
| 2123 | - elseif ( |
|
| 2124 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | - ) { |
|
| 2127 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2128 | - } |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - if ( |
|
| 2132 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2133 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2134 | - ) { |
|
| 2135 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2139 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2140 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2141 | - if ($table === $boucle->id_table) { |
|
| 2142 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2143 | - if ($col_alias != $col_vraie) { |
|
| 2144 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2145 | - } |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2149 | - if ($table) { |
|
| 2150 | - if ($col[0] == '`') { |
|
| 2151 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2152 | - } else { |
|
| 2153 | - $arg = "$table.$col"; |
|
| 2154 | - } |
|
| 2155 | - } else { |
|
| 2156 | - $arg = $col; |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - // inserer la fonction SQL |
|
| 2160 | - if ($fct) { |
|
| 2161 | - $arg = "$fct($arg$args_sql)"; |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2006 | + $boucle = &$boucles[$idb]; |
|
| 2007 | + $type = $boucle->type_requete; |
|
| 2008 | + $table = $boucle->id_table; |
|
| 2009 | + $desc = $boucle->show; |
|
| 2010 | + $col_vraie = null; |
|
| 2011 | + |
|
| 2012 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2013 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2014 | + |
|
| 2015 | + $col_alias = $col; |
|
| 2016 | + $where_complement = false; |
|
| 2017 | + |
|
| 2018 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2019 | + if ($col == 'id_enfant') { |
|
| 2020 | + $col = $boucle->primary; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2024 | + if ( |
|
| 2025 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2027 | + ) { |
|
| 2028 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2029 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2030 | + else { |
|
| 2031 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2032 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2033 | + } |
|
| 2034 | + |
|
| 2035 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2036 | + // sauf si exception declaree : sauter cette etape |
|
| 2037 | + else { |
|
| 2038 | + if ( |
|
| 2039 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2040 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2041 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2042 | + ) { |
|
| 2043 | + $e = decompose_champ_id_objet($col); |
|
| 2044 | + $col = array_shift($e); |
|
| 2045 | + $where_complement = primary_doublee($e, $table); |
|
| 2046 | + } // Cas particulier : expressions de date |
|
| 2047 | + else { |
|
| 2048 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2049 | + [$col, $col_vraie] = $c; |
|
| 2050 | + $table = ''; |
|
| 2051 | + } // table explicitée {mots.titre} |
|
| 2052 | + else { |
|
| 2053 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2054 | + [, $table, $col] = $r; |
|
| 2055 | + $col_alias = $col; |
|
| 2056 | + |
|
| 2057 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2058 | + if ( |
|
| 2059 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2060 | + and isset($desc['field'][$col]) |
|
| 2061 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2062 | + ) { |
|
| 2063 | + $table = $cle; |
|
| 2064 | + } else { |
|
| 2065 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2066 | + } |
|
| 2067 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2068 | + if (!$table) { |
|
| 2069 | + return ''; |
|
| 2070 | + } |
|
| 2071 | + } |
|
| 2072 | + // si le champ n'est pas trouvé dans la table, |
|
| 2073 | + // on cherche si une jointure peut l'obtenir |
|
| 2074 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2075 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2076 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2077 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2078 | + } |
|
| 2079 | + else { |
|
| 2080 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2081 | + if (!$r) { |
|
| 2082 | + return ''; |
|
| 2083 | + } |
|
| 2084 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2085 | + } |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2093 | + // Dans tous les cas, |
|
| 2094 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2095 | + // et passer dans sql_quote avec le type si connu |
|
| 2096 | + // et int sinon si la valeur est numerique |
|
| 2097 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2098 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2099 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2100 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2101 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2102 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2103 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2104 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2105 | + } |
|
| 2106 | + // sinon expliciter les |
|
| 2107 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2108 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2109 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2110 | + // sans toucher aux |
|
| 2111 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2112 | + // sql_quote(truc,'','varchar') |
|
| 2113 | + elseif ( |
|
| 2114 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2115 | + // si pas deja un type |
|
| 2116 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2117 | + ) { |
|
| 2118 | + $r = $r[1] |
|
| 2119 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2120 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2121 | + $val[0] = "sql_quote($r)"; |
|
| 2122 | + } |
|
| 2123 | + elseif ( |
|
| 2124 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | + ) { |
|
| 2127 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2128 | + } |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + if ( |
|
| 2132 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2133 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2134 | + ) { |
|
| 2135 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2139 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2140 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2141 | + if ($table === $boucle->id_table) { |
|
| 2142 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2143 | + if ($col_alias != $col_vraie) { |
|
| 2144 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2149 | + if ($table) { |
|
| 2150 | + if ($col[0] == '`') { |
|
| 2151 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2152 | + } else { |
|
| 2153 | + $arg = "$table.$col"; |
|
| 2154 | + } |
|
| 2155 | + } else { |
|
| 2156 | + $arg = $col; |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + // inserer la fonction SQL |
|
| 2160 | + if ($fct) { |
|
| 2161 | + $arg = "$fct($arg$args_sql)"; |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2165 | 2165 | } |
| 2166 | 2166 | |
| 2167 | 2167 | |
@@ -2190,77 +2190,77 @@ discard block |
||
| 2190 | 2190 | **/ |
| 2191 | 2191 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2192 | 2192 | |
| 2193 | - $where = ''; |
|
| 2194 | - |
|
| 2195 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2196 | - // gestion par les plugins des jointures tordues |
|
| 2197 | - // pas automatiques mais necessaires |
|
| 2198 | - $table_sql = table_objet_sql($table); |
|
| 2199 | - if ( |
|
| 2200 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2202 | - and |
|
| 2203 | - ( |
|
| 2204 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2205 | - or |
|
| 2206 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2207 | - ) |
|
| 2208 | - ) { |
|
| 2209 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2210 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2211 | - |
|
| 2212 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2213 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2214 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2215 | - [$t, $col] = $t[$col]; |
|
| 2216 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2217 | - [$calculer_critere_externe] = $index; |
|
| 2218 | - $t = $table; |
|
| 2219 | - } else { |
|
| 2220 | - $t = ''; |
|
| 2221 | - } // jointure non declaree. La trouver. |
|
| 2222 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2223 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2224 | - } else { |
|
| 2225 | - $t = ''; |
|
| 2226 | - } // jointure non declaree. La trouver. |
|
| 2227 | - |
|
| 2228 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2229 | - |
|
| 2230 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2231 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2232 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2233 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2234 | - $table = ''; |
|
| 2235 | - if ($boucle->jointures_explicites) { |
|
| 2236 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2237 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2241 | - if (!$table) { |
|
| 2242 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - if (!$table) { |
|
| 2246 | - return ''; |
|
| 2247 | - } |
|
| 2248 | - |
|
| 2249 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2250 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2251 | - |
|
| 2252 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2253 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2254 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2255 | - $e = decompose_champ_id_objet($col); |
|
| 2256 | - $col = array_shift($e); |
|
| 2257 | - $where = primary_doublee($e, $table); |
|
| 2258 | - } else { |
|
| 2259 | - $col = reset($cle); |
|
| 2260 | - } |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2193 | + $where = ''; |
|
| 2194 | + |
|
| 2195 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2196 | + // gestion par les plugins des jointures tordues |
|
| 2197 | + // pas automatiques mais necessaires |
|
| 2198 | + $table_sql = table_objet_sql($table); |
|
| 2199 | + if ( |
|
| 2200 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2202 | + and |
|
| 2203 | + ( |
|
| 2204 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2205 | + or |
|
| 2206 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2207 | + ) |
|
| 2208 | + ) { |
|
| 2209 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2210 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2211 | + |
|
| 2212 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2213 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2214 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2215 | + [$t, $col] = $t[$col]; |
|
| 2216 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2217 | + [$calculer_critere_externe] = $index; |
|
| 2218 | + $t = $table; |
|
| 2219 | + } else { |
|
| 2220 | + $t = ''; |
|
| 2221 | + } // jointure non declaree. La trouver. |
|
| 2222 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2223 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2224 | + } else { |
|
| 2225 | + $t = ''; |
|
| 2226 | + } // jointure non declaree. La trouver. |
|
| 2227 | + |
|
| 2228 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2229 | + |
|
| 2230 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2231 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2232 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2233 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2234 | + $table = ''; |
|
| 2235 | + if ($boucle->jointures_explicites) { |
|
| 2236 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2237 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2241 | + if (!$table) { |
|
| 2242 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + if (!$table) { |
|
| 2246 | + return ''; |
|
| 2247 | + } |
|
| 2248 | + |
|
| 2249 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2250 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2251 | + |
|
| 2252 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2253 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2254 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2255 | + $e = decompose_champ_id_objet($col); |
|
| 2256 | + $col = array_shift($e); |
|
| 2257 | + $where = primary_doublee($e, $table); |
|
| 2258 | + } else { |
|
| 2259 | + $col = reset($cle); |
|
| 2260 | + } |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | |
@@ -2281,10 +2281,10 @@ discard block |
||
| 2281 | 2281 | * - valeur |
| 2282 | 2282 | **/ |
| 2283 | 2283 | function primary_doublee($decompose, $table) { |
| 2284 | - $e1 = reset($decompose); |
|
| 2285 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2284 | + $e1 = reset($decompose); |
|
| 2285 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2286 | 2286 | |
| 2287 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2287 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2288 | 2288 | } |
| 2289 | 2289 | |
| 2290 | 2290 | /** |
@@ -2315,57 +2315,57 @@ discard block |
||
| 2315 | 2315 | * Vide sinon. |
| 2316 | 2316 | */ |
| 2317 | 2317 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2318 | - // si on demande un truc du genre spip_mots |
|
| 2319 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2320 | - // et qu'on est la |
|
| 2321 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2322 | - if ( |
|
| 2323 | - $checkarrivee |
|
| 2324 | - and is_string($checkarrivee) |
|
| 2325 | - and $a = table_objet($checkarrivee) |
|
| 2326 | - and in_array($a . '_liens', $joints) |
|
| 2327 | - ) { |
|
| 2328 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2329 | - return $res; |
|
| 2330 | - } |
|
| 2331 | - } |
|
| 2332 | - foreach ($joints as $joint) { |
|
| 2333 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2334 | - // alias de table dans le from |
|
| 2335 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2336 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2337 | - $cols = $arrivee[2]; |
|
| 2338 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2339 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2340 | - array_pop($cols); |
|
| 2341 | - } |
|
| 2342 | - if ($t) { |
|
| 2343 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2344 | - $joindre = false; |
|
| 2345 | - foreach ($cols as $col) { |
|
| 2346 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2347 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2348 | - $joindre = true; |
|
| 2349 | - } else { |
|
| 2350 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2351 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2352 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2353 | - $joindre = true; |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - if (!$joindre) { |
|
| 2358 | - return $t; |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - array_pop($arrivee); |
|
| 2362 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2363 | - return $res; |
|
| 2364 | - } |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - return ''; |
|
| 2318 | + // si on demande un truc du genre spip_mots |
|
| 2319 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2320 | + // et qu'on est la |
|
| 2321 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2322 | + if ( |
|
| 2323 | + $checkarrivee |
|
| 2324 | + and is_string($checkarrivee) |
|
| 2325 | + and $a = table_objet($checkarrivee) |
|
| 2326 | + and in_array($a . '_liens', $joints) |
|
| 2327 | + ) { |
|
| 2328 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2329 | + return $res; |
|
| 2330 | + } |
|
| 2331 | + } |
|
| 2332 | + foreach ($joints as $joint) { |
|
| 2333 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2334 | + // alias de table dans le from |
|
| 2335 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2336 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2337 | + $cols = $arrivee[2]; |
|
| 2338 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2339 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2340 | + array_pop($cols); |
|
| 2341 | + } |
|
| 2342 | + if ($t) { |
|
| 2343 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2344 | + $joindre = false; |
|
| 2345 | + foreach ($cols as $col) { |
|
| 2346 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2347 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2348 | + $joindre = true; |
|
| 2349 | + } else { |
|
| 2350 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2351 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2352 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2353 | + $joindre = true; |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + if (!$joindre) { |
|
| 2358 | + return $t; |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + array_pop($arrivee); |
|
| 2362 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2363 | + return $res; |
|
| 2364 | + } |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + return ''; |
|
| 2369 | 2369 | } |
| 2370 | 2370 | |
| 2371 | 2371 | /** |
@@ -2391,35 +2391,35 @@ discard block |
||
| 2391 | 2391 | * Alias de la table de jointure (Lx) |
| 2392 | 2392 | */ |
| 2393 | 2393 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2394 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2395 | - |
|
| 2396 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2397 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2398 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2399 | - |
|
| 2400 | - if (!$intermediaire or !$arrivee) { |
|
| 2401 | - return ''; |
|
| 2402 | - } |
|
| 2403 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2404 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2405 | - |
|
| 2406 | - $res = fabrique_jointures( |
|
| 2407 | - $boucle, |
|
| 2408 | - [ |
|
| 2409 | - [ |
|
| 2410 | - $boucle->id_table, |
|
| 2411 | - $intermediaire, |
|
| 2412 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2413 | - ], |
|
| 2414 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2415 | - ], |
|
| 2416 | - $cond, |
|
| 2417 | - $desc, |
|
| 2418 | - $boucle->id_table, |
|
| 2419 | - [$col] |
|
| 2420 | - ); |
|
| 2421 | - |
|
| 2422 | - return $res; |
|
| 2394 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2395 | + |
|
| 2396 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2397 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2398 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2399 | + |
|
| 2400 | + if (!$intermediaire or !$arrivee) { |
|
| 2401 | + return ''; |
|
| 2402 | + } |
|
| 2403 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2404 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2405 | + |
|
| 2406 | + $res = fabrique_jointures( |
|
| 2407 | + $boucle, |
|
| 2408 | + [ |
|
| 2409 | + [ |
|
| 2410 | + $boucle->id_table, |
|
| 2411 | + $intermediaire, |
|
| 2412 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2413 | + ], |
|
| 2414 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2415 | + ], |
|
| 2416 | + $cond, |
|
| 2417 | + $desc, |
|
| 2418 | + $boucle->id_table, |
|
| 2419 | + [$col] |
|
| 2420 | + ); |
|
| 2421 | + |
|
| 2422 | + return $res; |
|
| 2423 | 2423 | } |
| 2424 | 2424 | |
| 2425 | 2425 | |
@@ -2436,17 +2436,17 @@ discard block |
||
| 2436 | 2436 | * false sinon. |
| 2437 | 2437 | **/ |
| 2438 | 2438 | function trouver_champ($champ, $where) { |
| 2439 | - if (!is_array($where)) { |
|
| 2440 | - return preg_match($champ, $where); |
|
| 2441 | - } else { |
|
| 2442 | - foreach ($where as $clause) { |
|
| 2443 | - if (trouver_champ($champ, $clause)) { |
|
| 2444 | - return true; |
|
| 2445 | - } |
|
| 2446 | - } |
|
| 2447 | - |
|
| 2448 | - return false; |
|
| 2449 | - } |
|
| 2439 | + if (!is_array($where)) { |
|
| 2440 | + return preg_match($champ, $where); |
|
| 2441 | + } else { |
|
| 2442 | + foreach ($where as $clause) { |
|
| 2443 | + if (trouver_champ($champ, $clause)) { |
|
| 2444 | + return true; |
|
| 2445 | + } |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + return false; |
|
| 2449 | + } |
|
| 2450 | 2450 | } |
| 2451 | 2451 | |
| 2452 | 2452 | |
@@ -2472,129 +2472,129 @@ discard block |
||
| 2472 | 2472 | * - string $args_sql Suite des arguments du critère. ? |
| 2473 | 2473 | **/ |
| 2474 | 2474 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2475 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2476 | - if (count($crit->param) == 0) { |
|
| 2477 | - $op = '='; |
|
| 2478 | - $col = $val = $crit->op; |
|
| 2479 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2480 | - $val = $r[2]; |
|
| 2481 | - } |
|
| 2482 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2483 | - if ($val == 'lang') { |
|
| 2484 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2485 | - } else { |
|
| 2486 | - $defaut = null; |
|
| 2487 | - if ($val == 'id_parent') { |
|
| 2488 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2489 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2490 | - // pour eviter l'erreur SQL |
|
| 2491 | - $val = $boucles[$idb]->primary; |
|
| 2492 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2493 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2494 | - } elseif ($val == 'id_enfant') { |
|
| 2495 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2496 | - // de la boucle superieure |
|
| 2497 | - $val = 'id_parent'; |
|
| 2498 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2499 | - // un critere conditionnel sur date est traite a part |
|
| 2500 | - // car la date est mise d'office par SPIP, |
|
| 2501 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2502 | - } |
|
| 2503 | - |
|
| 2504 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2505 | - $val = [kwote($val)]; |
|
| 2506 | - } |
|
| 2507 | - } else { |
|
| 2508 | - // comparaison explicite |
|
| 2509 | - // le phraseur impose que le premier param soit du texte |
|
| 2510 | - $params = $crit->param; |
|
| 2511 | - $op = $crit->op; |
|
| 2512 | - if ($op == '==') { |
|
| 2513 | - $op = 'REGEXP'; |
|
| 2514 | - } |
|
| 2515 | - $col = array_shift($params); |
|
| 2516 | - $col = $col[0]->texte; |
|
| 2517 | - |
|
| 2518 | - $val = []; |
|
| 2519 | - $parent = $boucles[$idb]->id_parent; |
|
| 2520 | - |
|
| 2521 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2522 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2523 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2524 | - if ( |
|
| 2525 | - count($params) == 1 |
|
| 2526 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2527 | - and $params[0][0]->type == 'texte' |
|
| 2528 | - and $params[0][2]->type == 'texte' |
|
| 2529 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2530 | - and (($p == "'") or ($p == '"')) |
|
| 2531 | - and $params[0][1]->type == 'champ' |
|
| 2532 | - ) { |
|
| 2533 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2534 | - } else { |
|
| 2535 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2536 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2537 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2538 | - $val[] = $a; |
|
| 2539 | - } else { |
|
| 2540 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2541 | - } // toujours quoter en char ici |
|
| 2542 | - } |
|
| 2543 | - } |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - $fct = $args_sql = ''; |
|
| 2547 | - // fonction SQL ? |
|
| 2548 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2549 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2550 | - $fct = $m[1]; |
|
| 2551 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2552 | - $col = $a[1]; |
|
| 2553 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2554 | - $col = $m[1]; |
|
| 2555 | - $args_sql = $m[2]; |
|
| 2556 | - } |
|
| 2557 | - $args_sql .= $a[2]; |
|
| 2558 | - } |
|
| 2559 | - |
|
| 2560 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2475 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2476 | + if (count($crit->param) == 0) { |
|
| 2477 | + $op = '='; |
|
| 2478 | + $col = $val = $crit->op; |
|
| 2479 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2480 | + $val = $r[2]; |
|
| 2481 | + } |
|
| 2482 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2483 | + if ($val == 'lang') { |
|
| 2484 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2485 | + } else { |
|
| 2486 | + $defaut = null; |
|
| 2487 | + if ($val == 'id_parent') { |
|
| 2488 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2489 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2490 | + // pour eviter l'erreur SQL |
|
| 2491 | + $val = $boucles[$idb]->primary; |
|
| 2492 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2493 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2494 | + } elseif ($val == 'id_enfant') { |
|
| 2495 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2496 | + // de la boucle superieure |
|
| 2497 | + $val = 'id_parent'; |
|
| 2498 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2499 | + // un critere conditionnel sur date est traite a part |
|
| 2500 | + // car la date est mise d'office par SPIP, |
|
| 2501 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2502 | + } |
|
| 2503 | + |
|
| 2504 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2505 | + $val = [kwote($val)]; |
|
| 2506 | + } |
|
| 2507 | + } else { |
|
| 2508 | + // comparaison explicite |
|
| 2509 | + // le phraseur impose que le premier param soit du texte |
|
| 2510 | + $params = $crit->param; |
|
| 2511 | + $op = $crit->op; |
|
| 2512 | + if ($op == '==') { |
|
| 2513 | + $op = 'REGEXP'; |
|
| 2514 | + } |
|
| 2515 | + $col = array_shift($params); |
|
| 2516 | + $col = $col[0]->texte; |
|
| 2517 | + |
|
| 2518 | + $val = []; |
|
| 2519 | + $parent = $boucles[$idb]->id_parent; |
|
| 2520 | + |
|
| 2521 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2522 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2523 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2524 | + if ( |
|
| 2525 | + count($params) == 1 |
|
| 2526 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2527 | + and $params[0][0]->type == 'texte' |
|
| 2528 | + and $params[0][2]->type == 'texte' |
|
| 2529 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2530 | + and (($p == "'") or ($p == '"')) |
|
| 2531 | + and $params[0][1]->type == 'champ' |
|
| 2532 | + ) { |
|
| 2533 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2534 | + } else { |
|
| 2535 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2536 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2537 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2538 | + $val[] = $a; |
|
| 2539 | + } else { |
|
| 2540 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2541 | + } // toujours quoter en char ici |
|
| 2542 | + } |
|
| 2543 | + } |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + $fct = $args_sql = ''; |
|
| 2547 | + // fonction SQL ? |
|
| 2548 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2549 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2550 | + $fct = $m[1]; |
|
| 2551 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2552 | + $col = $a[1]; |
|
| 2553 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2554 | + $col = $m[1]; |
|
| 2555 | + $args_sql = $m[2]; |
|
| 2556 | + } |
|
| 2557 | + $args_sql .= $a[2]; |
|
| 2558 | + } |
|
| 2559 | + |
|
| 2560 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2561 | 2561 | } |
| 2562 | 2562 | |
| 2563 | 2563 | // compatibilite ancienne version |
| 2564 | 2564 | |
| 2565 | 2565 | function calculer_vieux_in($params) { |
| 2566 | - $deb = $params[0][0]; |
|
| 2567 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2568 | - $last = $params[$k]; |
|
| 2569 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2570 | - $last = $last[$j]; |
|
| 2571 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2572 | - |
|
| 2573 | - if ( |
|
| 2574 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2575 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2576 | - ) { |
|
| 2577 | - return $params; |
|
| 2578 | - } |
|
| 2579 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2580 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2581 | - $last = $params[$k][$j]; |
|
| 2582 | - $n = strlen($last->texte); |
|
| 2583 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2584 | - $newp = []; |
|
| 2585 | - foreach ($params as $v) { |
|
| 2586 | - if ($v[0]->type != 'texte') { |
|
| 2587 | - $newp[] = $v; |
|
| 2588 | - } else { |
|
| 2589 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2590 | - $t = new Texte(); |
|
| 2591 | - $t->texte = $x; |
|
| 2592 | - $newp[] = [$t]; |
|
| 2593 | - } |
|
| 2594 | - } |
|
| 2595 | - } |
|
| 2596 | - |
|
| 2597 | - return $newp; |
|
| 2566 | + $deb = $params[0][0]; |
|
| 2567 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2568 | + $last = $params[$k]; |
|
| 2569 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2570 | + $last = $last[$j]; |
|
| 2571 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2572 | + |
|
| 2573 | + if ( |
|
| 2574 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2575 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2576 | + ) { |
|
| 2577 | + return $params; |
|
| 2578 | + } |
|
| 2579 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2580 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2581 | + $last = $params[$k][$j]; |
|
| 2582 | + $n = strlen($last->texte); |
|
| 2583 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2584 | + $newp = []; |
|
| 2585 | + foreach ($params as $v) { |
|
| 2586 | + if ($v[0]->type != 'texte') { |
|
| 2587 | + $newp[] = $v; |
|
| 2588 | + } else { |
|
| 2589 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2590 | + $t = new Texte(); |
|
| 2591 | + $t->texte = $x; |
|
| 2592 | + $newp[] = [$t]; |
|
| 2593 | + } |
|
| 2594 | + } |
|
| 2595 | + } |
|
| 2596 | + |
|
| 2597 | + return $newp; |
|
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | /** |
@@ -2613,95 +2613,95 @@ discard block |
||
| 2613 | 2613 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2614 | 2614 | **/ |
| 2615 | 2615 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2616 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2617 | - return ''; |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - $boucle = $boucles[$idb]; |
|
| 2621 | - $table = $boucle->show; |
|
| 2622 | - |
|
| 2623 | - // si c'est une colonne de la table, ne rien faire |
|
| 2624 | - if (isset($table['field'][$col])) { |
|
| 2625 | - return ''; |
|
| 2626 | - } |
|
| 2627 | - |
|
| 2628 | - // Le type de critère à prendre en compte |
|
| 2629 | - $col = $regs[1]; |
|
| 2630 | - |
|
| 2631 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2632 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2633 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2634 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2635 | - if (isset($table['field']["date$suite"])) { |
|
| 2636 | - $date_orig = 'date' . $suite; |
|
| 2637 | - } else { |
|
| 2638 | - $date_orig = substr($suite, 1); |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - $pred = $date_orig; |
|
| 2642 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2643 | - // Si aucune déclaration trouvée, on quitte |
|
| 2644 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2645 | - return ''; |
|
| 2646 | - } |
|
| 2647 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2648 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2649 | - |
|
| 2650 | - // Si c'est pour du relatif |
|
| 2651 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | - $pred = 'date'; |
|
| 2653 | - } |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | - ") . '\""; |
|
| 2659 | - |
|
| 2660 | - $col_vraie = $date_orig; |
|
| 2661 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | - |
|
| 2663 | - switch ($col) { |
|
| 2664 | - case 'date': |
|
| 2665 | - $col = $date_orig; |
|
| 2666 | - break; |
|
| 2667 | - case 'jour': |
|
| 2668 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | - break; |
|
| 2670 | - case 'mois': |
|
| 2671 | - $col = "MONTH($date_orig)"; |
|
| 2672 | - break; |
|
| 2673 | - case 'annee': |
|
| 2674 | - $col = "YEAR($date_orig)"; |
|
| 2675 | - break; |
|
| 2676 | - case 'heure': |
|
| 2677 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | - break; |
|
| 2679 | - case 'age': |
|
| 2680 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | - break; |
|
| 2683 | - case 'age_relatif': |
|
| 2684 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - case 'jour_relatif': |
|
| 2688 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | - break; |
|
| 2691 | - case 'mois_relatif': |
|
| 2692 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | - break; |
|
| 2697 | - case 'annee_relatif': |
|
| 2698 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | - $date_orig . ')'; |
|
| 2700 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | - break; |
|
| 2702 | - } |
|
| 2703 | - |
|
| 2704 | - return [$col, $col_vraie]; |
|
| 2616 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2617 | + return ''; |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + $boucle = $boucles[$idb]; |
|
| 2621 | + $table = $boucle->show; |
|
| 2622 | + |
|
| 2623 | + // si c'est une colonne de la table, ne rien faire |
|
| 2624 | + if (isset($table['field'][$col])) { |
|
| 2625 | + return ''; |
|
| 2626 | + } |
|
| 2627 | + |
|
| 2628 | + // Le type de critère à prendre en compte |
|
| 2629 | + $col = $regs[1]; |
|
| 2630 | + |
|
| 2631 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2632 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2633 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2634 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2635 | + if (isset($table['field']["date$suite"])) { |
|
| 2636 | + $date_orig = 'date' . $suite; |
|
| 2637 | + } else { |
|
| 2638 | + $date_orig = substr($suite, 1); |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + $pred = $date_orig; |
|
| 2642 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2643 | + // Si aucune déclaration trouvée, on quitte |
|
| 2644 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2645 | + return ''; |
|
| 2646 | + } |
|
| 2647 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2648 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2649 | + |
|
| 2650 | + // Si c'est pour du relatif |
|
| 2651 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | + $pred = 'date'; |
|
| 2653 | + } |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | + ") . '\""; |
|
| 2659 | + |
|
| 2660 | + $col_vraie = $date_orig; |
|
| 2661 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | + |
|
| 2663 | + switch ($col) { |
|
| 2664 | + case 'date': |
|
| 2665 | + $col = $date_orig; |
|
| 2666 | + break; |
|
| 2667 | + case 'jour': |
|
| 2668 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | + break; |
|
| 2670 | + case 'mois': |
|
| 2671 | + $col = "MONTH($date_orig)"; |
|
| 2672 | + break; |
|
| 2673 | + case 'annee': |
|
| 2674 | + $col = "YEAR($date_orig)"; |
|
| 2675 | + break; |
|
| 2676 | + case 'heure': |
|
| 2677 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | + break; |
|
| 2679 | + case 'age': |
|
| 2680 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + break; |
|
| 2683 | + case 'age_relatif': |
|
| 2684 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + case 'jour_relatif': |
|
| 2688 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | + break; |
|
| 2691 | + case 'mois_relatif': |
|
| 2692 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | + break; |
|
| 2697 | + case 'annee_relatif': |
|
| 2698 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | + $date_orig . ')'; |
|
| 2700 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | + break; |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + return [$col, $col_vraie]; |
|
| 2705 | 2705 | } |
| 2706 | 2706 | |
| 2707 | 2707 | /** |
@@ -2720,16 +2720,16 @@ discard block |
||
| 2720 | 2720 | * de colonne SQL et une date. |
| 2721 | 2721 | **/ |
| 2722 | 2722 | function calculer_param_date($date_compare, $date_orig) { |
| 2723 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | - $date_compare = '\'$x\''; |
|
| 2726 | - } else { |
|
| 2727 | - $init = $date_compare; |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - return |
|
| 2731 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2723 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | + $date_compare = '\'$x\''; |
|
| 2726 | + } else { |
|
| 2727 | + $init = $date_compare; |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + return |
|
| 2731 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2733 | 2733 | } |
| 2734 | 2734 | |
| 2735 | 2735 | /** |
@@ -2747,20 +2747,20 @@ discard block |
||
| 2747 | 2747 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2748 | 2748 | */ |
| 2749 | 2749 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2750 | - $boucle = &$boucles[$idb]; |
|
| 2751 | - |
|
| 2752 | - $args = []; |
|
| 2753 | - foreach ($crit->param as &$param) { |
|
| 2754 | - array_push( |
|
| 2755 | - $args, |
|
| 2756 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | - ); |
|
| 2758 | - } |
|
| 2750 | + $boucle = &$boucles[$idb]; |
|
| 2759 | 2751 | |
| 2760 | - $boucle->hash .= ' |
|
| 2752 | + $args = []; |
|
| 2753 | + foreach ($crit->param as &$param) { |
|
| 2754 | + array_push( |
|
| 2755 | + $args, |
|
| 2756 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | + ); |
|
| 2758 | + } |
|
| 2759 | + |
|
| 2760 | + $boucle->hash .= ' |
|
| 2761 | 2761 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2762 | 2762 | |
| 2763 | - $boucle->hash .= ' |
|
| 2763 | + $boucle->hash .= ' |
|
| 2764 | 2764 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2765 | 2765 | } |
| 2766 | 2766 | |
@@ -2778,8 +2778,8 @@ discard block |
||
| 2778 | 2778 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2779 | 2779 | */ |
| 2780 | 2780 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2781 | - $boucle = &$boucles[$idb]; |
|
| 2782 | - $boucle->hash .= ' |
|
| 2781 | + $boucle = &$boucles[$idb]; |
|
| 2782 | + $boucle->hash .= ' |
|
| 2783 | 2783 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2784 | 2784 | } |
| 2785 | 2785 | |
@@ -2795,12 +2795,12 @@ discard block |
||
| 2795 | 2795 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2796 | 2796 | */ |
| 2797 | 2797 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2798 | - $boucle = &$boucles[$idb]; |
|
| 2799 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | - foreach ($crit->param as $param) { |
|
| 2801 | - $boucle->hash .= ' |
|
| 2798 | + $boucle = &$boucles[$idb]; |
|
| 2799 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | + foreach ($crit->param as $param) { |
|
| 2801 | + $boucle->hash .= ' |
|
| 2802 | 2802 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2803 | - } |
|
| 2803 | + } |
|
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | 2806 | /** |
@@ -2817,16 +2817,16 @@ discard block |
||
| 2817 | 2817 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2818 | 2818 | */ |
| 2819 | 2819 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2820 | - $boucle = &$boucles[$idb]; |
|
| 2821 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | - foreach ($crit->param as $param) { |
|
| 2823 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | - $param, |
|
| 2825 | - $idb, |
|
| 2826 | - $boucles, |
|
| 2827 | - $boucles[$idb]->id_parent |
|
| 2828 | - ) . ";\n"; |
|
| 2829 | - } |
|
| 2820 | + $boucle = &$boucles[$idb]; |
|
| 2821 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | + foreach ($crit->param as $param) { |
|
| 2823 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | + $param, |
|
| 2825 | + $idb, |
|
| 2826 | + $boucles, |
|
| 2827 | + $boucles[$idb]->id_parent |
|
| 2828 | + ) . ";\n"; |
|
| 2829 | + } |
|
| 2830 | 2830 | } |
| 2831 | 2831 | |
| 2832 | 2832 | /** |
@@ -2851,16 +2851,16 @@ discard block |
||
| 2851 | 2851 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2852 | 2852 | */ |
| 2853 | 2853 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2854 | - $boucle = &$boucles[$idb]; |
|
| 2855 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | - foreach ($crit->param as $param) { |
|
| 2857 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | - $param, |
|
| 2859 | - $idb, |
|
| 2860 | - $boucles, |
|
| 2861 | - $boucles[$idb]->id_parent |
|
| 2862 | - ) . ";\n"; |
|
| 2863 | - } |
|
| 2854 | + $boucle = &$boucles[$idb]; |
|
| 2855 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | + foreach ($crit->param as $param) { |
|
| 2857 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | + $param, |
|
| 2859 | + $idb, |
|
| 2860 | + $boucles, |
|
| 2861 | + $boucles[$idb]->id_parent |
|
| 2862 | + ) . ";\n"; |
|
| 2863 | + } |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | /** |
@@ -2875,11 +2875,11 @@ discard block |
||
| 2875 | 2875 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2876 | 2876 | */ |
| 2877 | 2877 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2878 | - $boucle = &$boucles[$idb]; |
|
| 2879 | - foreach ($crit->param as $param) { |
|
| 2880 | - $boucle->hash .= ' |
|
| 2878 | + $boucle = &$boucles[$idb]; |
|
| 2879 | + foreach ($crit->param as $param) { |
|
| 2880 | + $boucle->hash .= ' |
|
| 2881 | 2881 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2882 | - } |
|
| 2882 | + } |
|
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | 2885 | |
@@ -2911,20 +2911,20 @@ discard block |
||
| 2911 | 2911 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2912 | 2912 | */ |
| 2913 | 2913 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2914 | - $boucle = &$boucles[$idb]; |
|
| 2915 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | - if ($crit->param) { |
|
| 2920 | - foreach ($crit->param as $param) { |
|
| 2921 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | - } |
|
| 2924 | - // interdire {si 0} aussi ! |
|
| 2925 | - } else { |
|
| 2926 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | - } |
|
| 2914 | + $boucle = &$boucles[$idb]; |
|
| 2915 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | + if ($crit->param) { |
|
| 2920 | + foreach ($crit->param as $param) { |
|
| 2921 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | + } |
|
| 2924 | + // interdire {si 0} aussi ! |
|
| 2925 | + } else { |
|
| 2926 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | + } |
|
| 2928 | 2928 | } |
| 2929 | 2929 | |
| 2930 | 2930 | /** |
@@ -2941,8 +2941,8 @@ discard block |
||
| 2941 | 2941 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2942 | 2942 | */ |
| 2943 | 2943 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2944 | - $boucle = &$boucles[$idb]; |
|
| 2945 | - $boucle->hash .= ' |
|
| 2944 | + $boucle = &$boucles[$idb]; |
|
| 2945 | + $boucle->hash .= ' |
|
| 2946 | 2946 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2947 | 2947 | $command[\'sourcemode\'] = \'table\';'; |
| 2948 | 2948 | } |
@@ -2963,27 +2963,27 @@ discard block |
||
| 2963 | 2963 | */ |
| 2964 | 2964 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2965 | 2965 | |
| 2966 | - $not = $crit->not; |
|
| 2967 | - $boucle = &$boucles[$idb]; |
|
| 2968 | - $primary = $boucle->primary; |
|
| 2966 | + $not = $crit->not; |
|
| 2967 | + $boucle = &$boucles[$idb]; |
|
| 2968 | + $primary = $boucle->primary; |
|
| 2969 | 2969 | |
| 2970 | - if (!$primary or strpos($primary, ',')) { |
|
| 2971 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2970 | + if (!$primary or strpos($primary, ',')) { |
|
| 2971 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2972 | 2972 | |
| 2973 | - return; |
|
| 2974 | - } |
|
| 2975 | - $table = $boucle->type_requete; |
|
| 2976 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2973 | + return; |
|
| 2974 | + } |
|
| 2975 | + $table = $boucle->type_requete; |
|
| 2976 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2977 | 2977 | |
| 2978 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2978 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2979 | 2979 | |
| 2980 | - $in = 'IN'; |
|
| 2981 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2982 | - if ($not) { |
|
| 2983 | - $where = ["'NOT'", $where]; |
|
| 2984 | - } |
|
| 2980 | + $in = 'IN'; |
|
| 2981 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2982 | + if ($not) { |
|
| 2983 | + $where = ["'NOT'", $where]; |
|
| 2984 | + } |
|
| 2985 | 2985 | |
| 2986 | - $boucle->where[] = $where; |
|
| 2986 | + $boucle->where[] = $where; |
|
| 2987 | 2987 | } |
| 2988 | 2988 | |
| 2989 | 2989 | /** |
@@ -2999,8 +2999,8 @@ discard block |
||
| 2999 | 2999 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3000 | 3000 | */ |
| 3001 | 3001 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3002 | - $not = $crit->not; |
|
| 3003 | - $crit->not = $not ? false : true; |
|
| 3004 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3005 | - $crit->not = $not; |
|
| 3002 | + $not = $crit->not; |
|
| 3003 | + $crit->not = $not ? false : true; |
|
| 3004 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3005 | + $crit->not = $not; |
|
| 3006 | 3006 | } |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('_MYSQL_NOPLANES')) { |
| 27 | - define('_MYSQL_NOPLANES', true); |
|
| 27 | + define('_MYSQL_NOPLANES', true); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -41,112 +41,112 @@ discard block |
||
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | */ |
| 43 | 43 | function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
| 44 | - if (!extension_loaded(\mysqli::class)) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | - try { |
|
| 50 | - if ( |
|
| 51 | - $port and !is_numeric($socket = $port) |
|
| 52 | - and (!$host or $host === 'localhost') |
|
| 53 | - ) { |
|
| 54 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 55 | - } elseif ($port) { |
|
| 56 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 57 | - } else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - } catch (\mysqli_sql_exception $e) { |
|
| 61 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 62 | - $link = false; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (!$link) { |
|
| 66 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 67 | - |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - $last = ''; |
|
| 71 | - if (!$db) { |
|
| 72 | - $ok = $link; |
|
| 73 | - $db = 'spip'; |
|
| 74 | - } else { |
|
| 75 | - $ok = mysqli_select_db($link, $db); |
|
| 76 | - if ( |
|
| 77 | - defined('_MYSQL_SET_SQL_MODE') |
|
| 78 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 79 | - ) { |
|
| 80 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - spip_log( |
|
| 85 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | - _LOG_DEBUG |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - return !$ok ? false : [ |
|
| 90 | - 'db' => $db, |
|
| 91 | - 'last' => $last, |
|
| 92 | - 'prefixe' => $prefixe ?: $db, |
|
| 93 | - 'link' => $link, |
|
| 94 | - 'total_requetes' => 0, |
|
| 95 | - ]; |
|
| 44 | + if (!extension_loaded(\mysqli::class)) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | + try { |
|
| 50 | + if ( |
|
| 51 | + $port and !is_numeric($socket = $port) |
|
| 52 | + and (!$host or $host === 'localhost') |
|
| 53 | + ) { |
|
| 54 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 55 | + } elseif ($port) { |
|
| 56 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 57 | + } else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + } catch (\mysqli_sql_exception $e) { |
|
| 61 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 62 | + $link = false; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (!$link) { |
|
| 66 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 67 | + |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + $last = ''; |
|
| 71 | + if (!$db) { |
|
| 72 | + $ok = $link; |
|
| 73 | + $db = 'spip'; |
|
| 74 | + } else { |
|
| 75 | + $ok = mysqli_select_db($link, $db); |
|
| 76 | + if ( |
|
| 77 | + defined('_MYSQL_SET_SQL_MODE') |
|
| 78 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 79 | + ) { |
|
| 80 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + spip_log( |
|
| 85 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | + _LOG_DEBUG |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + return !$ok ? false : [ |
|
| 90 | + 'db' => $db, |
|
| 91 | + 'last' => $last, |
|
| 92 | + 'prefixe' => $prefixe ?: $db, |
|
| 93 | + 'link' => $link, |
|
| 94 | + 'total_requetes' => 0, |
|
| 95 | + ]; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | $GLOBALS['spip_mysql_functions_1'] = [ |
| 100 | - 'alter' => 'spip_mysql_alter', |
|
| 101 | - 'count' => 'spip_mysql_count', |
|
| 102 | - 'countsel' => 'spip_mysql_countsel', |
|
| 103 | - 'create' => 'spip_mysql_create', |
|
| 104 | - 'create_base' => 'spip_mysql_create_base', |
|
| 105 | - 'create_view' => 'spip_mysql_create_view', |
|
| 106 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 107 | - 'delete' => 'spip_mysql_delete', |
|
| 108 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 109 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 110 | - 'errno' => 'spip_mysql_errno', |
|
| 111 | - 'error' => 'spip_mysql_error', |
|
| 112 | - 'explain' => 'spip_mysql_explain', |
|
| 113 | - 'fetch' => 'spip_mysql_fetch', |
|
| 114 | - 'seek' => 'spip_mysql_seek', |
|
| 115 | - 'free' => 'spip_mysql_free', |
|
| 116 | - 'hex' => 'spip_mysql_hex', |
|
| 117 | - 'in' => 'spip_mysql_in', |
|
| 118 | - 'insert' => 'spip_mysql_insert', |
|
| 119 | - 'insertq' => 'spip_mysql_insertq', |
|
| 120 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 121 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 122 | - 'multi' => 'spip_mysql_multi', |
|
| 123 | - 'optimize' => 'spip_mysql_optimize', |
|
| 124 | - 'query' => 'spip_mysql_query', |
|
| 125 | - 'quote' => 'spip_mysql_quote', |
|
| 126 | - 'replace' => 'spip_mysql_replace', |
|
| 127 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 128 | - 'repair' => 'spip_mysql_repair', |
|
| 129 | - 'select' => 'spip_mysql_select', |
|
| 130 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 131 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 132 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 133 | - 'showbase' => 'spip_mysql_showbase', |
|
| 134 | - 'showtable' => 'spip_mysql_showtable', |
|
| 135 | - 'table_exists' => 'spip_mysql_table_exists', |
|
| 136 | - 'update' => 'spip_mysql_update', |
|
| 137 | - 'updateq' => 'spip_mysql_updateq', |
|
| 138 | - |
|
| 139 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 140 | - 'charsets' => [ |
|
| 141 | - 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 142 | - 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 143 | - 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 144 | - 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 100 | + 'alter' => 'spip_mysql_alter', |
|
| 101 | + 'count' => 'spip_mysql_count', |
|
| 102 | + 'countsel' => 'spip_mysql_countsel', |
|
| 103 | + 'create' => 'spip_mysql_create', |
|
| 104 | + 'create_base' => 'spip_mysql_create_base', |
|
| 105 | + 'create_view' => 'spip_mysql_create_view', |
|
| 106 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 107 | + 'delete' => 'spip_mysql_delete', |
|
| 108 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 109 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 110 | + 'errno' => 'spip_mysql_errno', |
|
| 111 | + 'error' => 'spip_mysql_error', |
|
| 112 | + 'explain' => 'spip_mysql_explain', |
|
| 113 | + 'fetch' => 'spip_mysql_fetch', |
|
| 114 | + 'seek' => 'spip_mysql_seek', |
|
| 115 | + 'free' => 'spip_mysql_free', |
|
| 116 | + 'hex' => 'spip_mysql_hex', |
|
| 117 | + 'in' => 'spip_mysql_in', |
|
| 118 | + 'insert' => 'spip_mysql_insert', |
|
| 119 | + 'insertq' => 'spip_mysql_insertq', |
|
| 120 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 121 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 122 | + 'multi' => 'spip_mysql_multi', |
|
| 123 | + 'optimize' => 'spip_mysql_optimize', |
|
| 124 | + 'query' => 'spip_mysql_query', |
|
| 125 | + 'quote' => 'spip_mysql_quote', |
|
| 126 | + 'replace' => 'spip_mysql_replace', |
|
| 127 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 128 | + 'repair' => 'spip_mysql_repair', |
|
| 129 | + 'select' => 'spip_mysql_select', |
|
| 130 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 131 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 132 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 133 | + 'showbase' => 'spip_mysql_showbase', |
|
| 134 | + 'showtable' => 'spip_mysql_showtable', |
|
| 135 | + 'table_exists' => 'spip_mysql_table_exists', |
|
| 136 | + 'update' => 'spip_mysql_update', |
|
| 137 | + 'updateq' => 'spip_mysql_updateq', |
|
| 138 | + |
|
| 139 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 140 | + 'charsets' => [ |
|
| 141 | + 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 142 | + 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 143 | + 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 144 | + 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 145 | 145 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 146 | - 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 146 | + 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 147 | 147 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 148 | - 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 149 | - ] |
|
| 148 | + 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 149 | + ] |
|
| 150 | 150 | ]; |
| 151 | 151 | |
| 152 | 152 | |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @return Object Information de connexion pour mysqli |
| 158 | 158 | */ |
| 159 | 159 | function _mysql_link($serveur = '') { |
| 160 | - $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 160 | + $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 161 | 161 | |
| 162 | - return $link; |
|
| 162 | + return $link; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | * @return mysqli_result|bool Jeu de résultats pour fetch() |
| 173 | 173 | */ |
| 174 | 174 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 175 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 176 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 175 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 176 | + spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 177 | 177 | |
| 178 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | * @return array Description du charset (son nom est dans 'charset') |
| 189 | 189 | */ |
| 190 | 190 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 191 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 192 | - $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 193 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 191 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 192 | + $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 193 | + . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 194 | 194 | |
| 195 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 195 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -208,80 +208,80 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 210 | 210 | |
| 211 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 212 | - $prefixe = $connexion['prefixe']; |
|
| 213 | - $link = $connexion['link']; |
|
| 214 | - $db = $connexion['db']; |
|
| 215 | - |
|
| 216 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 217 | - |
|
| 218 | - // renvoyer la requete inerte si demandee |
|
| 219 | - if (!$requeter) { |
|
| 220 | - return $query; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 224 | - include_spip('public/tracer'); |
|
| 225 | - $t = trace_query_start(); |
|
| 226 | - } else { |
|
| 227 | - $t = 0; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $connexion['last'] = $query; |
|
| 231 | - $connexion['total_requetes']++; |
|
| 232 | - |
|
| 233 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 234 | - $debug = ''; |
|
| 235 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 236 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 237 | - [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | - $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 239 | - } |
|
| 240 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 241 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 242 | - } |
|
| 243 | - if (!empty($GLOBALS['ip'])) { |
|
| 244 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 245 | - } |
|
| 246 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 247 | - } |
|
| 248 | - try { |
|
| 249 | - $r = mysqli_query($link, $query . $debug); |
|
| 250 | - } catch (\mysqli_sql_exception $e) { |
|
| 251 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 252 | - $r = false; |
|
| 253 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 254 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 258 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 259 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 260 | - //Fermer la connexion defaillante |
|
| 261 | - mysqli_close($connexion['link']); |
|
| 262 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 263 | - //Relancer une connexion vierge |
|
| 264 | - spip_connect($serveur); |
|
| 265 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 266 | - $link = $connexion['link']; |
|
| 267 | - //On retente au cas où |
|
| 268 | - try { |
|
| 269 | - $r = mysqli_query($link, $query . $debug); |
|
| 270 | - } catch (\mysqli_sql_exception $e) { |
|
| 271 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 272 | - $r = false; |
|
| 273 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 274 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // Log de l'erreur eventuelle |
|
| 280 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 281 | - // et du fautif |
|
| 282 | - $e .= spip_mysql_error($query, $serveur); |
|
| 283 | - } |
|
| 284 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 211 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 212 | + $prefixe = $connexion['prefixe']; |
|
| 213 | + $link = $connexion['link']; |
|
| 214 | + $db = $connexion['db']; |
|
| 215 | + |
|
| 216 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 217 | + |
|
| 218 | + // renvoyer la requete inerte si demandee |
|
| 219 | + if (!$requeter) { |
|
| 220 | + return $query; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 224 | + include_spip('public/tracer'); |
|
| 225 | + $t = trace_query_start(); |
|
| 226 | + } else { |
|
| 227 | + $t = 0; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $connexion['last'] = $query; |
|
| 231 | + $connexion['total_requetes']++; |
|
| 232 | + |
|
| 233 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 234 | + $debug = ''; |
|
| 235 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 236 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 237 | + [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | + $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 239 | + } |
|
| 240 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 241 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 242 | + } |
|
| 243 | + if (!empty($GLOBALS['ip'])) { |
|
| 244 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 245 | + } |
|
| 246 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 247 | + } |
|
| 248 | + try { |
|
| 249 | + $r = mysqli_query($link, $query . $debug); |
|
| 250 | + } catch (\mysqli_sql_exception $e) { |
|
| 251 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 252 | + $r = false; |
|
| 253 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 254 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 258 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 259 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 260 | + //Fermer la connexion defaillante |
|
| 261 | + mysqli_close($connexion['link']); |
|
| 262 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 263 | + //Relancer une connexion vierge |
|
| 264 | + spip_connect($serveur); |
|
| 265 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 266 | + $link = $connexion['link']; |
|
| 267 | + //On retente au cas où |
|
| 268 | + try { |
|
| 269 | + $r = mysqli_query($link, $query . $debug); |
|
| 270 | + } catch (\mysqli_sql_exception $e) { |
|
| 271 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 272 | + $r = false; |
|
| 273 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 274 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // Log de l'erreur eventuelle |
|
| 280 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 281 | + // et du fautif |
|
| 282 | + $e .= spip_mysql_error($query, $serveur); |
|
| 283 | + } |
|
| 284 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 297 | 297 | */ |
| 298 | 298 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 299 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 300 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 301 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 302 | - $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 299 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 300 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 301 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 302 | + $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 303 | 303 | |
| 304 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 304 | + return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | * @return bool Toujours true |
| 315 | 315 | */ |
| 316 | 316 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 317 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 317 | + spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 318 | 318 | |
| 319 | - return true; |
|
| 319 | + return true; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -329,18 +329,18 @@ discard block |
||
| 329 | 329 | * @return array Tableau de l'explication |
| 330 | 330 | */ |
| 331 | 331 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 332 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 333 | - return []; |
|
| 334 | - } |
|
| 335 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 336 | - $prefixe = $connexion['prefixe']; |
|
| 337 | - $link = $connexion['link']; |
|
| 338 | - $db = $connexion['db']; |
|
| 339 | - |
|
| 340 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 341 | - $r = mysqli_query($link, $query); |
|
| 342 | - |
|
| 343 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 332 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 333 | + return []; |
|
| 334 | + } |
|
| 335 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 336 | + $prefixe = $connexion['prefixe']; |
|
| 337 | + $link = $connexion['link']; |
|
| 338 | + $db = $connexion['db']; |
|
| 339 | + |
|
| 340 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 341 | + $r = mysqli_query($link, $query); |
|
| 342 | + |
|
| 343 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -369,35 +369,35 @@ discard block |
||
| 369 | 369 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 370 | 370 | */ |
| 371 | 371 | function spip_mysql_select( |
| 372 | - $select, |
|
| 373 | - $from, |
|
| 374 | - $where = '', |
|
| 375 | - $groupby = '', |
|
| 376 | - $orderby = '', |
|
| 377 | - $limit = '', |
|
| 378 | - $having = '', |
|
| 379 | - $serveur = '', |
|
| 380 | - $requeter = true |
|
| 372 | + $select, |
|
| 373 | + $from, |
|
| 374 | + $where = '', |
|
| 375 | + $groupby = '', |
|
| 376 | + $orderby = '', |
|
| 377 | + $limit = '', |
|
| 378 | + $having = '', |
|
| 379 | + $serveur = '', |
|
| 380 | + $requeter = true |
|
| 381 | 381 | ) { |
| 382 | 382 | |
| 383 | 383 | |
| 384 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 385 | - $query = |
|
| 386 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 387 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 388 | - . calculer_mysql_expression('WHERE', $where) |
|
| 389 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 390 | - . calculer_mysql_expression('HAVING', $having) |
|
| 391 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 392 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 384 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 385 | + $query = |
|
| 386 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 387 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 388 | + . calculer_mysql_expression('WHERE', $where) |
|
| 389 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 390 | + . calculer_mysql_expression('HAVING', $having) |
|
| 391 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 392 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 393 | 393 | |
| 394 | - // renvoyer la requete inerte si demandee |
|
| 395 | - if ($requeter === false) { |
|
| 396 | - return $query; |
|
| 397 | - } |
|
| 398 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 394 | + // renvoyer la requete inerte si demandee |
|
| 395 | + if ($requeter === false) { |
|
| 396 | + return $query; |
|
| 397 | + } |
|
| 398 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 399 | 399 | |
| 400 | - return $r ?: $query; |
|
| 400 | + return $r ?: $query; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | * @return string texte du orderby préparé |
| 415 | 415 | */ |
| 416 | 416 | function spip_mysql_order($orderby) { |
| 417 | - return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 417 | + return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | |
@@ -437,26 +437,26 @@ discard block |
||
| 437 | 437 | * Contrainte pour clause WHERE |
| 438 | 438 | */ |
| 439 | 439 | function calculer_mysql_where($v) { |
| 440 | - if (!is_array($v)) { |
|
| 441 | - return $v; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - $op = array_shift($v); |
|
| 445 | - if (!($n = count($v))) { |
|
| 446 | - return $op; |
|
| 447 | - } else { |
|
| 448 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 449 | - if ($n == 1) { |
|
| 450 | - return "$op($arg)"; |
|
| 451 | - } else { |
|
| 452 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 453 | - if ($n == 2) { |
|
| 454 | - return "($arg $op $arg2)"; |
|
| 455 | - } else { |
|
| 456 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - } |
|
| 440 | + if (!is_array($v)) { |
|
| 441 | + return $v; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + $op = array_shift($v); |
|
| 445 | + if (!($n = count($v))) { |
|
| 446 | + return $op; |
|
| 447 | + } else { |
|
| 448 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 449 | + if ($n == 1) { |
|
| 450 | + return "$op($arg)"; |
|
| 451 | + } else { |
|
| 452 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 453 | + if ($n == 2) { |
|
| 454 | + return "($arg $op $arg2)"; |
|
| 455 | + } else { |
|
| 456 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -471,21 +471,21 @@ discard block |
||
| 471 | 471 | * @return string texte de l'expression, une partie donc, du texte la requête. |
| 472 | 472 | */ |
| 473 | 473 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 474 | - if (empty($v)) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $exp = "\n$expression "; |
|
| 479 | - |
|
| 480 | - if (!is_array($v)) { |
|
| 481 | - return $exp . $v; |
|
| 482 | - } else { |
|
| 483 | - if (strtoupper($join) === 'AND') { |
|
| 484 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 485 | - } else { |
|
| 486 | - return $exp . join($join, $v); |
|
| 487 | - } |
|
| 488 | - } |
|
| 474 | + if (empty($v)) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $exp = "\n$expression "; |
|
| 479 | + |
|
| 480 | + if (!is_array($v)) { |
|
| 481 | + return $exp . $v; |
|
| 482 | + } else { |
|
| 483 | + if (strtoupper($join) === 'AND') { |
|
| 484 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 485 | + } else { |
|
| 486 | + return $exp . join($join, $v); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -496,26 +496,26 @@ discard block |
||
| 496 | 496 | * @return string Sélection de colonnes pour une clause SELECT |
| 497 | 497 | */ |
| 498 | 498 | function spip_mysql_select_as($args) { |
| 499 | - $res = ''; |
|
| 500 | - foreach ($args as $k => $v) { |
|
| 501 | - if (substr($k, -1) == '@') { |
|
| 502 | - // c'est une jointure qui se refere au from precedent |
|
| 503 | - // pas de virgule |
|
| 504 | - $res .= ' ' . $v; |
|
| 505 | - } else { |
|
| 506 | - if (!is_numeric($k)) { |
|
| 507 | - $p = strpos($v, ' '); |
|
| 508 | - if ($p) { |
|
| 509 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 510 | - } else { |
|
| 511 | - $v .= " AS `$k`"; |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - $res .= ', ' . $v; |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - return substr($res, 2); |
|
| 499 | + $res = ''; |
|
| 500 | + foreach ($args as $k => $v) { |
|
| 501 | + if (substr($k, -1) == '@') { |
|
| 502 | + // c'est une jointure qui se refere au from precedent |
|
| 503 | + // pas de virgule |
|
| 504 | + $res .= ' ' . $v; |
|
| 505 | + } else { |
|
| 506 | + if (!is_numeric($k)) { |
|
| 507 | + $p = strpos($v, ' '); |
|
| 508 | + if ($p) { |
|
| 509 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 510 | + } else { |
|
| 511 | + $v .= " AS `$k`"; |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + $res .= ', ' . $v; |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + return substr($res, 2); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | |
@@ -540,58 +540,58 @@ discard block |
||
| 540 | 540 | */ |
| 541 | 541 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 542 | 542 | |
| 543 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 544 | - $pref = '`' . $db . '`.'; |
|
| 545 | - } else { |
|
| 546 | - $pref = ''; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - if ($prefixe) { |
|
| 550 | - $pref .= $prefixe . '_'; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 554 | - $suite = ''; |
|
| 555 | - } else { |
|
| 556 | - $suite = strstr($query, (string) $regs[0]); |
|
| 557 | - $query = substr($query, 0, -strlen($suite)); |
|
| 558 | - // propager le prefixe en cas de requete imbriquee |
|
| 559 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 560 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 561 | - if (stripos($suite, 'SELECT') !== false) { |
|
| 562 | - if ($echappe_textes) { |
|
| 563 | - [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 564 | - } |
|
| 565 | - else { |
|
| 566 | - $suite_echap = $suite; |
|
| 567 | - } |
|
| 568 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 569 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 570 | - if ($echappe_textes) { |
|
| 571 | - $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 572 | - } |
|
| 573 | - else { |
|
| 574 | - $suite = $suite_echap; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 580 | - |
|
| 581 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 583 | - if ( |
|
| 584 | - defined('_MYSQL_NOPLANES') |
|
| 585 | - and _MYSQL_NOPLANES |
|
| 586 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 587 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 588 | - ) { |
|
| 589 | - include_spip('inc/charsets'); |
|
| 590 | - $r = utf8_noplanes($r); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 594 | - return $r; |
|
| 543 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 544 | + $pref = '`' . $db . '`.'; |
|
| 545 | + } else { |
|
| 546 | + $pref = ''; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + if ($prefixe) { |
|
| 550 | + $pref .= $prefixe . '_'; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 554 | + $suite = ''; |
|
| 555 | + } else { |
|
| 556 | + $suite = strstr($query, (string) $regs[0]); |
|
| 557 | + $query = substr($query, 0, -strlen($suite)); |
|
| 558 | + // propager le prefixe en cas de requete imbriquee |
|
| 559 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 560 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 561 | + if (stripos($suite, 'SELECT') !== false) { |
|
| 562 | + if ($echappe_textes) { |
|
| 563 | + [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 564 | + } |
|
| 565 | + else { |
|
| 566 | + $suite_echap = $suite; |
|
| 567 | + } |
|
| 568 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 569 | + $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 570 | + if ($echappe_textes) { |
|
| 571 | + $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 572 | + } |
|
| 573 | + else { |
|
| 574 | + $suite = $suite_echap; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 580 | + |
|
| 581 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 583 | + if ( |
|
| 584 | + defined('_MYSQL_NOPLANES') |
|
| 585 | + and _MYSQL_NOPLANES |
|
| 586 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 587 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 588 | + ) { |
|
| 589 | + include_spip('inc/charsets'); |
|
| 590 | + $r = utf8_noplanes($r); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 594 | + return $r; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -609,17 +609,17 @@ discard block |
||
| 609 | 609 | * - False en cas d'erreur. |
| 610 | 610 | **/ |
| 611 | 611 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 612 | - $link = _mysql_link($serveur); |
|
| 613 | - try { |
|
| 614 | - $ok = mysqli_select_db($link, $db); |
|
| 615 | - } catch (\mysqli_sql_exception $e) { |
|
| 616 | - $ok = false; |
|
| 617 | - } |
|
| 618 | - if (!$ok) { |
|
| 619 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - return $ok; |
|
| 612 | + $link = _mysql_link($serveur); |
|
| 613 | + try { |
|
| 614 | + $ok = mysqli_select_db($link, $db); |
|
| 615 | + } catch (\mysqli_sql_exception $e) { |
|
| 616 | + $ok = false; |
|
| 617 | + } |
|
| 618 | + if (!$ok) { |
|
| 619 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + return $ok; |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | |
@@ -640,14 +640,14 @@ discard block |
||
| 640 | 640 | * Liste de noms de bases de données |
| 641 | 641 | **/ |
| 642 | 642 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 643 | - $dbs = []; |
|
| 644 | - if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 645 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 646 | - $dbs[] = $row['Database']; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $dbs; |
|
| 643 | + $dbs = []; |
|
| 644 | + if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 645 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 646 | + $dbs[] = $row['Database']; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $dbs; |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | |
@@ -670,73 +670,73 @@ discard block |
||
| 670 | 670 | * - true si la requête réussie, false sinon. |
| 671 | 671 | */ |
| 672 | 672 | function spip_mysql_create( |
| 673 | - $nom, |
|
| 674 | - $champs, |
|
| 675 | - $cles, |
|
| 676 | - $autoinc = false, |
|
| 677 | - $temporary = false, |
|
| 678 | - $serveur = '', |
|
| 679 | - $requeter = true |
|
| 673 | + $nom, |
|
| 674 | + $champs, |
|
| 675 | + $cles, |
|
| 676 | + $autoinc = false, |
|
| 677 | + $temporary = false, |
|
| 678 | + $serveur = '', |
|
| 679 | + $requeter = true |
|
| 680 | 680 | ) { |
| 681 | 681 | |
| 682 | - $query = ''; |
|
| 683 | - $keys = ''; |
|
| 684 | - $s = ''; |
|
| 685 | - $p = ''; |
|
| 686 | - |
|
| 687 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 688 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 689 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 690 | - return; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 694 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 695 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - foreach ($cles as $k => $v) { |
|
| 699 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 700 | - if ($k == 'PRIMARY KEY') { |
|
| 701 | - $p = $v; |
|
| 702 | - } |
|
| 703 | - $s = ','; |
|
| 704 | - } |
|
| 705 | - $s = ''; |
|
| 706 | - |
|
| 707 | - $character_set = ''; |
|
| 708 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 709 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 710 | - } |
|
| 711 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 712 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - foreach ($champs as $k => $v) { |
|
| 716 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 717 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 718 | - if ( |
|
| 719 | - preg_match(',(char|text),i', $defs[1]) |
|
| 720 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 721 | - ) { |
|
| 722 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - $query .= "$s\n\t\t$k $v" |
|
| 727 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 728 | - ? ' auto_increment' |
|
| 729 | - : '' |
|
| 730 | - ); |
|
| 731 | - $s = ','; |
|
| 732 | - } |
|
| 733 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 734 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 735 | - . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 736 | - . ($character_set ? " DEFAULT $character_set" : '') |
|
| 737 | - . "\n"; |
|
| 738 | - |
|
| 739 | - return spip_mysql_query($q, $serveur); |
|
| 682 | + $query = ''; |
|
| 683 | + $keys = ''; |
|
| 684 | + $s = ''; |
|
| 685 | + $p = ''; |
|
| 686 | + |
|
| 687 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 688 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 689 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 690 | + return; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 694 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 695 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + foreach ($cles as $k => $v) { |
|
| 699 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 700 | + if ($k == 'PRIMARY KEY') { |
|
| 701 | + $p = $v; |
|
| 702 | + } |
|
| 703 | + $s = ','; |
|
| 704 | + } |
|
| 705 | + $s = ''; |
|
| 706 | + |
|
| 707 | + $character_set = ''; |
|
| 708 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 709 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 710 | + } |
|
| 711 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 712 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + foreach ($champs as $k => $v) { |
|
| 716 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 717 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 718 | + if ( |
|
| 719 | + preg_match(',(char|text),i', $defs[1]) |
|
| 720 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 721 | + ) { |
|
| 722 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + $query .= "$s\n\t\t$k $v" |
|
| 727 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 728 | + ? ' auto_increment' |
|
| 729 | + : '' |
|
| 730 | + ); |
|
| 731 | + $s = ','; |
|
| 732 | + } |
|
| 733 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 734 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 735 | + . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 736 | + . ($character_set ? " DEFAULT $character_set" : '') |
|
| 737 | + . "\n"; |
|
| 738 | + |
|
| 739 | + return spip_mysql_query($q, $serveur); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | |
@@ -749,25 +749,25 @@ discard block |
||
| 749 | 749 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 750 | 750 | */ |
| 751 | 751 | function _mysql_remplacements_definitions_table($query) { |
| 752 | - // quelques remplacements |
|
| 753 | - $num = '(\s*\([0-9]*\))?'; |
|
| 754 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 755 | - |
|
| 756 | - $remplace = [ |
|
| 757 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 758 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 759 | - ]; |
|
| 760 | - |
|
| 761 | - if (is_string($query)) { |
|
| 762 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 763 | - } elseif (is_array($query)) { |
|
| 764 | - $keys = array_keys($remplace); |
|
| 765 | - foreach ($query as $k => $q) { |
|
| 766 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - return $query; |
|
| 752 | + // quelques remplacements |
|
| 753 | + $num = '(\s*\([0-9]*\))?'; |
|
| 754 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 755 | + |
|
| 756 | + $remplace = [ |
|
| 757 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 758 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 759 | + ]; |
|
| 760 | + |
|
| 761 | + if (is_string($query)) { |
|
| 762 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 763 | + } elseif (is_array($query)) { |
|
| 764 | + $keys = array_keys($remplace); |
|
| 765 | + foreach ($query as $k => $q) { |
|
| 766 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + return $query; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return bool true si la base est créee. |
| 781 | 781 | **/ |
| 782 | 782 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 783 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 783 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -801,19 +801,19 @@ discard block |
||
| 801 | 801 | * - string texte de la requête si $requeter vaut false |
| 802 | 802 | */ |
| 803 | 803 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 804 | - if (!$query_select) { |
|
| 805 | - return false; |
|
| 806 | - } |
|
| 807 | - // vue deja presente |
|
| 808 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 809 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 804 | + if (!$query_select) { |
|
| 805 | + return false; |
|
| 806 | + } |
|
| 807 | + // vue deja presente |
|
| 808 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 809 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 810 | 810 | |
| 811 | - return false; |
|
| 812 | - } |
|
| 811 | + return false; |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 814 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 815 | 815 | |
| 816 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 816 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | |
@@ -829,11 +829,11 @@ discard block |
||
| 829 | 829 | * - true si la requête a réussie, false sinon |
| 830 | 830 | */ |
| 831 | 831 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 832 | - if ($exist) { |
|
| 833 | - $exist = ' IF EXISTS'; |
|
| 834 | - } |
|
| 832 | + if ($exist) { |
|
| 833 | + $exist = ' IF EXISTS'; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 836 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -848,11 +848,11 @@ discard block |
||
| 848 | 848 | * - true si la requête a réussie, false sinon |
| 849 | 849 | */ |
| 850 | 850 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 851 | - if ($exist) { |
|
| 852 | - $exist = ' IF EXISTS'; |
|
| 853 | - } |
|
| 851 | + if ($exist) { |
|
| 852 | + $exist = ' IF EXISTS'; |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 855 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | * Ressource à utiliser avec sql_fetch() |
| 870 | 870 | **/ |
| 871 | 871 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 872 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 872 | + return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | /** |
@@ -885,18 +885,18 @@ discard block |
||
| 885 | 885 | * - true si la requête a réussie, false sinon |
| 886 | 886 | */ |
| 887 | 887 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 888 | - $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 889 | - $engine = $table_status['Engine']; |
|
| 890 | - if ($engine == 'InnoDB') { |
|
| 891 | - if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 892 | - return [' OK ']; |
|
| 893 | - } |
|
| 894 | - } elseif ($engine == 'MyISAM') { |
|
| 895 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 896 | - } else { |
|
| 897 | - spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 898 | - } |
|
| 899 | - return false; |
|
| 888 | + $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 889 | + $engine = $table_status['Engine']; |
|
| 890 | + if ($engine == 'InnoDB') { |
|
| 891 | + if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 892 | + return [' OK ']; |
|
| 893 | + } |
|
| 894 | + } elseif ($engine == 'MyISAM') { |
|
| 895 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 896 | + } else { |
|
| 897 | + spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 898 | + } |
|
| 899 | + return false; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -914,12 +914,12 @@ discard block |
||
| 914 | 914 | * - string : requete sql, si $requeter = true |
| 915 | 915 | **/ |
| 916 | 916 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 917 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 918 | - if (!$requeter) { |
|
| 919 | - return $r; |
|
| 920 | - } |
|
| 921 | - $res = spip_mysql_fetch($r); |
|
| 922 | - return (bool) $res; |
|
| 917 | + $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 918 | + if (!$requeter) { |
|
| 919 | + return $r; |
|
| 920 | + } |
|
| 921 | + $res = spip_mysql_fetch($r); |
|
| 922 | + return (bool) $res; |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -942,86 +942,86 @@ discard block |
||
| 942 | 942 | * - array description de la table sinon |
| 943 | 943 | */ |
| 944 | 944 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 945 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 946 | - if (!$s) { |
|
| 947 | - return ''; |
|
| 948 | - } |
|
| 949 | - if (!$requeter) { |
|
| 950 | - return $s; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 954 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 955 | - $desc = $r[1]; |
|
| 956 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 957 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 958 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 959 | - $namedkeys = $r[2]; |
|
| 960 | - $desc = $r[1]; |
|
| 961 | - } else { |
|
| 962 | - $namedkeys = ''; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - $fields = []; |
|
| 966 | - foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 967 | - preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 968 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 969 | - } |
|
| 970 | - $keys = []; |
|
| 971 | - |
|
| 972 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 973 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 974 | - $k = str_replace('`', '', trim($r[1])); |
|
| 975 | - $t = strtolower(str_replace('`', '', $r[2])); |
|
| 976 | - if ($k && !isset($keys[$k])) { |
|
| 977 | - $keys[$k] = $t; |
|
| 978 | - } else { |
|
| 979 | - $keys[] = $t; |
|
| 980 | - } |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - spip_mysql_free($s); |
|
| 984 | - |
|
| 985 | - return ['field' => $fields, 'key' => $keys]; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 989 | - if ($res) { |
|
| 990 | - $nfields = []; |
|
| 991 | - $nkeys = []; |
|
| 992 | - while ($val = spip_mysql_fetch($res)) { |
|
| 993 | - $nfields[$val['Field']] = $val['Type']; |
|
| 994 | - if ($val['Null'] == 'NO') { |
|
| 995 | - $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 996 | - } |
|
| 997 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 998 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 999 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 1000 | - } else { |
|
| 1001 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - if ($val['Extra']) { |
|
| 1005 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1006 | - } |
|
| 1007 | - if ($val['Key'] == 'PRI') { |
|
| 1008 | - $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1009 | - } else { |
|
| 1010 | - if ($val['Key'] == 'MUL') { |
|
| 1011 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1012 | - } else { |
|
| 1013 | - if ($val['Key'] == 'UNI') { |
|
| 1014 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - spip_mysql_free($res); |
|
| 1020 | - |
|
| 1021 | - return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - return ''; |
|
| 945 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 946 | + if (!$s) { |
|
| 947 | + return ''; |
|
| 948 | + } |
|
| 949 | + if (!$requeter) { |
|
| 950 | + return $s; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 954 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 955 | + $desc = $r[1]; |
|
| 956 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 957 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 958 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 959 | + $namedkeys = $r[2]; |
|
| 960 | + $desc = $r[1]; |
|
| 961 | + } else { |
|
| 962 | + $namedkeys = ''; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + $fields = []; |
|
| 966 | + foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 967 | + preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 968 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 969 | + } |
|
| 970 | + $keys = []; |
|
| 971 | + |
|
| 972 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 973 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 974 | + $k = str_replace('`', '', trim($r[1])); |
|
| 975 | + $t = strtolower(str_replace('`', '', $r[2])); |
|
| 976 | + if ($k && !isset($keys[$k])) { |
|
| 977 | + $keys[$k] = $t; |
|
| 978 | + } else { |
|
| 979 | + $keys[] = $t; |
|
| 980 | + } |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + spip_mysql_free($s); |
|
| 984 | + |
|
| 985 | + return ['field' => $fields, 'key' => $keys]; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 989 | + if ($res) { |
|
| 990 | + $nfields = []; |
|
| 991 | + $nkeys = []; |
|
| 992 | + while ($val = spip_mysql_fetch($res)) { |
|
| 993 | + $nfields[$val['Field']] = $val['Type']; |
|
| 994 | + if ($val['Null'] == 'NO') { |
|
| 995 | + $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 996 | + } |
|
| 997 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 998 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 999 | + $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 1000 | + } else { |
|
| 1001 | + $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + if ($val['Extra']) { |
|
| 1005 | + $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1006 | + } |
|
| 1007 | + if ($val['Key'] == 'PRI') { |
|
| 1008 | + $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1009 | + } else { |
|
| 1010 | + if ($val['Key'] == 'MUL') { |
|
| 1011 | + $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1012 | + } else { |
|
| 1013 | + if ($val['Key'] == 'UNI') { |
|
| 1014 | + $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + spip_mysql_free($res); |
|
| 1020 | + |
|
| 1021 | + return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + return ''; |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | |
@@ -1040,13 +1040,13 @@ discard block |
||
| 1040 | 1040 | * - false Erreur |
| 1041 | 1041 | */ |
| 1042 | 1042 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 1043 | - if (!$t) { |
|
| 1044 | - $t = \MYSQLI_ASSOC; |
|
| 1045 | - } |
|
| 1046 | - if ($r) { |
|
| 1047 | - return mysqli_fetch_array($r, $t); |
|
| 1048 | - } |
|
| 1049 | - return false; |
|
| 1043 | + if (!$t) { |
|
| 1044 | + $t = \MYSQLI_ASSOC; |
|
| 1045 | + } |
|
| 1046 | + if ($r) { |
|
| 1047 | + return mysqli_fetch_array($r, $t); |
|
| 1048 | + } |
|
| 1049 | + return false; |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | /** |
@@ -1059,10 +1059,10 @@ discard block |
||
| 1059 | 1059 | * @return bool True si déplacement réussi, false sinon. |
| 1060 | 1060 | **/ |
| 1061 | 1061 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1062 | - if ($r and mysqli_num_rows($r)) { |
|
| 1063 | - return mysqli_data_seek($r, $row_number); |
|
| 1064 | - } |
|
| 1065 | - return false; |
|
| 1062 | + if ($r and mysqli_num_rows($r)) { |
|
| 1063 | + return mysqli_data_seek($r, $row_number); |
|
| 1064 | + } |
|
| 1065 | + return false; |
|
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | |
@@ -1080,26 +1080,26 @@ discard block |
||
| 1080 | 1080 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1081 | 1081 | **/ |
| 1082 | 1082 | function spip_mysql_countsel( |
| 1083 | - $from = [], |
|
| 1084 | - $where = [], |
|
| 1085 | - $groupby = '', |
|
| 1086 | - $having = [], |
|
| 1087 | - $serveur = '', |
|
| 1088 | - $requeter = true |
|
| 1083 | + $from = [], |
|
| 1084 | + $where = [], |
|
| 1085 | + $groupby = '', |
|
| 1086 | + $having = [], |
|
| 1087 | + $serveur = '', |
|
| 1088 | + $requeter = true |
|
| 1089 | 1089 | ) { |
| 1090 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1091 | - |
|
| 1092 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1093 | - if (!$requeter) { |
|
| 1094 | - return $r; |
|
| 1095 | - } |
|
| 1096 | - if (!$r instanceof mysqli_result) { |
|
| 1097 | - return 0; |
|
| 1098 | - } |
|
| 1099 | - [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1100 | - mysqli_free_result($r); |
|
| 1101 | - |
|
| 1102 | - return intval($c); |
|
| 1090 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1091 | + |
|
| 1092 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1093 | + if (!$requeter) { |
|
| 1094 | + return $r; |
|
| 1095 | + } |
|
| 1096 | + if (!$r instanceof mysqli_result) { |
|
| 1097 | + return 0; |
|
| 1098 | + } |
|
| 1099 | + [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1100 | + mysqli_free_result($r); |
|
| 1101 | + |
|
| 1102 | + return intval($c); |
|
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | |
@@ -1122,16 +1122,16 @@ discard block |
||
| 1122 | 1122 | * Erreur eventuelle |
| 1123 | 1123 | **/ |
| 1124 | 1124 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1125 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1126 | - $s = mysqli_error($link); |
|
| 1127 | - if ($s) { |
|
| 1128 | - $trace = debug_backtrace(); |
|
| 1129 | - if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1130 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - return $s; |
|
| 1125 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1126 | + $s = mysqli_error($link); |
|
| 1127 | + if ($s) { |
|
| 1128 | + $trace = debug_backtrace(); |
|
| 1129 | + if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1130 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + return $s; |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | |
@@ -1146,18 +1146,18 @@ discard block |
||
| 1146 | 1146 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1147 | 1147 | **/ |
| 1148 | 1148 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1149 | - $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1150 | - $s = mysqli_errno($link); |
|
| 1151 | - // 2006 MySQL server has gone away |
|
| 1152 | - // 2013 Lost connection to MySQL server during query |
|
| 1153 | - if (in_array($s, [2006, 2013])) { |
|
| 1154 | - define('spip_interdire_cache', true); |
|
| 1155 | - } |
|
| 1156 | - if ($s) { |
|
| 1157 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - return $s; |
|
| 1149 | + $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1150 | + $s = mysqli_errno($link); |
|
| 1151 | + // 2006 MySQL server has gone away |
|
| 1152 | + // 2013 Lost connection to MySQL server during query |
|
| 1153 | + if (in_array($s, [2006, 2013])) { |
|
| 1154 | + define('spip_interdire_cache', true); |
|
| 1155 | + } |
|
| 1156 | + if ($s) { |
|
| 1157 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + return $s; |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | |
@@ -1171,9 +1171,9 @@ discard block |
||
| 1171 | 1171 | * @return int Nombre de lignes |
| 1172 | 1172 | */ |
| 1173 | 1173 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1174 | - if ($r) { |
|
| 1175 | - return mysqli_num_rows($r); |
|
| 1176 | - } |
|
| 1174 | + if ($r) { |
|
| 1175 | + return mysqli_num_rows($r); |
|
| 1176 | + } |
|
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | 1179 | |
@@ -1189,11 +1189,11 @@ discard block |
||
| 1189 | 1189 | * @return bool True si réussi |
| 1190 | 1190 | */ |
| 1191 | 1191 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1192 | - if ($r instanceof mysqli_result) { |
|
| 1193 | - mysqli_free_result($r); |
|
| 1194 | - return true; |
|
| 1195 | - } |
|
| 1196 | - return false; |
|
| 1192 | + if ($r instanceof mysqli_result) { |
|
| 1193 | + mysqli_free_result($r); |
|
| 1194 | + return true; |
|
| 1195 | + } |
|
| 1196 | + return false; |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | |
@@ -1221,59 +1221,59 @@ discard block |
||
| 1221 | 1221 | **/ |
| 1222 | 1222 | function spip_mysql_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1223 | 1223 | |
| 1224 | - $e = null; |
|
| 1225 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1226 | - $link = $connexion['link']; |
|
| 1227 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1228 | - |
|
| 1229 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1230 | - if ( |
|
| 1231 | - defined('_MYSQL_NOPLANES') |
|
| 1232 | - and _MYSQL_NOPLANES |
|
| 1233 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1234 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1235 | - ) { |
|
| 1236 | - include_spip('inc/charsets'); |
|
| 1237 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1241 | - if (!$requeter) { |
|
| 1242 | - return $query; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - if (isset($_GET['var_profile'])) { |
|
| 1246 | - include_spip('public/tracer'); |
|
| 1247 | - $t = trace_query_start(); |
|
| 1248 | - $e = ''; |
|
| 1249 | - } else { |
|
| 1250 | - $t = 0; |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - $connexion['last'] = $query; |
|
| 1254 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1255 | - $r = false; |
|
| 1256 | - $insert = false; |
|
| 1257 | - try { |
|
| 1258 | - $insert = mysqli_query($link, $query); |
|
| 1259 | - } catch (\mysqli_sql_exception $e) { |
|
| 1260 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1261 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1262 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1263 | - } |
|
| 1264 | - if ($insert) { |
|
| 1265 | - $r = mysqli_insert_id($link); |
|
| 1266 | - } else { |
|
| 1267 | - // Log de l'erreur eventuelle |
|
| 1268 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1269 | - // et du fautif |
|
| 1270 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1275 | - |
|
| 1276 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1224 | + $e = null; |
|
| 1225 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1226 | + $link = $connexion['link']; |
|
| 1227 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1228 | + |
|
| 1229 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1230 | + if ( |
|
| 1231 | + defined('_MYSQL_NOPLANES') |
|
| 1232 | + and _MYSQL_NOPLANES |
|
| 1233 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1234 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1235 | + ) { |
|
| 1236 | + include_spip('inc/charsets'); |
|
| 1237 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1241 | + if (!$requeter) { |
|
| 1242 | + return $query; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + if (isset($_GET['var_profile'])) { |
|
| 1246 | + include_spip('public/tracer'); |
|
| 1247 | + $t = trace_query_start(); |
|
| 1248 | + $e = ''; |
|
| 1249 | + } else { |
|
| 1250 | + $t = 0; |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + $connexion['last'] = $query; |
|
| 1254 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1255 | + $r = false; |
|
| 1256 | + $insert = false; |
|
| 1257 | + try { |
|
| 1258 | + $insert = mysqli_query($link, $query); |
|
| 1259 | + } catch (\mysqli_sql_exception $e) { |
|
| 1260 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1261 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1262 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1263 | + } |
|
| 1264 | + if ($insert) { |
|
| 1265 | + $r = mysqli_insert_id($link); |
|
| 1266 | + } else { |
|
| 1267 | + // Log de l'erreur eventuelle |
|
| 1268 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1269 | + // et du fautif |
|
| 1270 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1275 | + |
|
| 1276 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | /** |
@@ -1298,26 +1298,26 @@ discard block |
||
| 1298 | 1298 | **/ |
| 1299 | 1299 | function spip_mysql_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1300 | 1300 | |
| 1301 | - if (!$desc) { |
|
| 1302 | - $desc = description_table($table, $serveur); |
|
| 1303 | - } |
|
| 1304 | - if (!$desc) { |
|
| 1305 | - $couples = []; |
|
| 1306 | - } |
|
| 1307 | - $fields = $desc['field'] ?? []; |
|
| 1308 | - |
|
| 1309 | - foreach ($couples as $champ => $val) { |
|
| 1310 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - return spip_mysql_insert( |
|
| 1314 | - $table, |
|
| 1315 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1316 | - '(' . join(',', $couples) . ')', |
|
| 1317 | - $desc, |
|
| 1318 | - $serveur, |
|
| 1319 | - $requeter |
|
| 1320 | - ); |
|
| 1301 | + if (!$desc) { |
|
| 1302 | + $desc = description_table($table, $serveur); |
|
| 1303 | + } |
|
| 1304 | + if (!$desc) { |
|
| 1305 | + $couples = []; |
|
| 1306 | + } |
|
| 1307 | + $fields = $desc['field'] ?? []; |
|
| 1308 | + |
|
| 1309 | + foreach ($couples as $champ => $val) { |
|
| 1310 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + return spip_mysql_insert( |
|
| 1314 | + $table, |
|
| 1315 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 1316 | + '(' . join(',', $couples) . ')', |
|
| 1317 | + $desc, |
|
| 1318 | + $serveur, |
|
| 1319 | + $requeter |
|
| 1320 | + ); |
|
| 1321 | 1321 | } |
| 1322 | 1322 | |
| 1323 | 1323 | |
@@ -1342,34 +1342,34 @@ discard block |
||
| 1342 | 1342 | **/ |
| 1343 | 1343 | function spip_mysql_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1344 | 1344 | |
| 1345 | - if (!$desc) { |
|
| 1346 | - $desc = description_table($table, $serveur); |
|
| 1347 | - } |
|
| 1348 | - if (!$desc) { |
|
| 1349 | - $tab_couples = []; |
|
| 1350 | - } |
|
| 1351 | - $fields = $desc['field'] ?? []; |
|
| 1352 | - |
|
| 1353 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1354 | - $valeurs = []; |
|
| 1355 | - $r = false; |
|
| 1356 | - |
|
| 1357 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1358 | - foreach ($tab_couples as $couples) { |
|
| 1359 | - foreach ($couples as $champ => $val) { |
|
| 1360 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1361 | - } |
|
| 1362 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1363 | - if (count($valeurs) >= 100) { |
|
| 1364 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1365 | - $valeurs = []; |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - if (count($valeurs)) { |
|
| 1369 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1345 | + if (!$desc) { |
|
| 1346 | + $desc = description_table($table, $serveur); |
|
| 1347 | + } |
|
| 1348 | + if (!$desc) { |
|
| 1349 | + $tab_couples = []; |
|
| 1350 | + } |
|
| 1351 | + $fields = $desc['field'] ?? []; |
|
| 1352 | + |
|
| 1353 | + $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1354 | + $valeurs = []; |
|
| 1355 | + $r = false; |
|
| 1356 | + |
|
| 1357 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1358 | + foreach ($tab_couples as $couples) { |
|
| 1359 | + foreach ($couples as $champ => $val) { |
|
| 1360 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1361 | + } |
|
| 1362 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1363 | + if (count($valeurs) >= 100) { |
|
| 1364 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1365 | + $valeurs = []; |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + if (count($valeurs)) { |
|
| 1369 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | /** |
@@ -1394,20 +1394,20 @@ discard block |
||
| 1394 | 1394 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1395 | 1395 | */ |
| 1396 | 1396 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1397 | - $set = []; |
|
| 1398 | - foreach ($champs as $champ => $val) { |
|
| 1399 | - $set[] = $champ . "=$val"; |
|
| 1400 | - } |
|
| 1401 | - if (!empty($set)) { |
|
| 1402 | - return spip_mysql_query( |
|
| 1403 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1404 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1405 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1406 | - $serveur, |
|
| 1407 | - $requeter |
|
| 1408 | - ); |
|
| 1409 | - } |
|
| 1410 | - return false; |
|
| 1397 | + $set = []; |
|
| 1398 | + foreach ($champs as $champ => $val) { |
|
| 1399 | + $set[] = $champ . "=$val"; |
|
| 1400 | + } |
|
| 1401 | + if (!empty($set)) { |
|
| 1402 | + return spip_mysql_query( |
|
| 1403 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1404 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1405 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1406 | + $serveur, |
|
| 1407 | + $requeter |
|
| 1408 | + ); |
|
| 1409 | + } |
|
| 1410 | + return false; |
|
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | 1413 | /** |
@@ -1440,29 +1440,29 @@ discard block |
||
| 1440 | 1440 | */ |
| 1441 | 1441 | function spip_mysql_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1442 | 1442 | |
| 1443 | - if (!$champs) { |
|
| 1444 | - return; |
|
| 1445 | - } |
|
| 1446 | - if (!$desc) { |
|
| 1447 | - $desc = description_table($table, $serveur); |
|
| 1448 | - } |
|
| 1449 | - if (!$desc) { |
|
| 1450 | - $champs = []; |
|
| 1451 | - } else { |
|
| 1452 | - $fields = $desc['field']; |
|
| 1453 | - } |
|
| 1454 | - $set = []; |
|
| 1455 | - foreach ($champs as $champ => $val) { |
|
| 1456 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - return spip_mysql_query( |
|
| 1460 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1461 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1462 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1463 | - $serveur, |
|
| 1464 | - $requeter |
|
| 1465 | - ); |
|
| 1443 | + if (!$champs) { |
|
| 1444 | + return; |
|
| 1445 | + } |
|
| 1446 | + if (!$desc) { |
|
| 1447 | + $desc = description_table($table, $serveur); |
|
| 1448 | + } |
|
| 1449 | + if (!$desc) { |
|
| 1450 | + $champs = []; |
|
| 1451 | + } else { |
|
| 1452 | + $fields = $desc['field']; |
|
| 1453 | + } |
|
| 1454 | + $set = []; |
|
| 1455 | + foreach ($champs as $champ => $val) { |
|
| 1456 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + return spip_mysql_query( |
|
| 1460 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1461 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1462 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1463 | + $serveur, |
|
| 1464 | + $requeter |
|
| 1465 | + ); |
|
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | /** |
@@ -1478,22 +1478,22 @@ discard block |
||
| 1478 | 1478 | * - false en cas d'erreur. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1481 | - $res = spip_mysql_query( |
|
| 1482 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1483 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1484 | - $serveur, |
|
| 1485 | - $requeter |
|
| 1486 | - ); |
|
| 1487 | - if (!$requeter) { |
|
| 1488 | - return $res; |
|
| 1489 | - } |
|
| 1490 | - if ($res) { |
|
| 1491 | - $link = _mysql_link($serveur); |
|
| 1492 | - |
|
| 1493 | - return mysqli_affected_rows($link); |
|
| 1494 | - } else { |
|
| 1495 | - return false; |
|
| 1496 | - } |
|
| 1481 | + $res = spip_mysql_query( |
|
| 1482 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1483 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1484 | + $serveur, |
|
| 1485 | + $requeter |
|
| 1486 | + ); |
|
| 1487 | + if (!$requeter) { |
|
| 1488 | + return $res; |
|
| 1489 | + } |
|
| 1490 | + if ($res) { |
|
| 1491 | + $link = _mysql_link($serveur); |
|
| 1492 | + |
|
| 1493 | + return mysqli_affected_rows($link); |
|
| 1494 | + } else { |
|
| 1495 | + return false; |
|
| 1496 | + } |
|
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | 1499 | |
@@ -1522,10 +1522,10 @@ discard block |
||
| 1522 | 1522 | * - false en cas d'erreur. |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1525 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1526 | - ',', |
|
| 1527 | - array_map('_q', $couples) |
|
| 1528 | - ) . ')', $serveur, $requeter); |
|
| 1525 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1526 | + ',', |
|
| 1527 | + array_map('_q', $couples) |
|
| 1528 | + ) . ')', $serveur, $requeter); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | |
@@ -1554,14 +1554,14 @@ discard block |
||
| 1554 | 1554 | * - false en cas d'erreur. |
| 1555 | 1555 | **/ |
| 1556 | 1556 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1557 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1558 | - $valeurs = []; |
|
| 1559 | - foreach ($tab_couples as $couples) { |
|
| 1560 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1561 | - } |
|
| 1562 | - $valeurs = implode(', ', $valeurs); |
|
| 1563 | - |
|
| 1564 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1557 | + $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1558 | + $valeurs = []; |
|
| 1559 | + foreach ($tab_couples as $couples) { |
|
| 1560 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1561 | + } |
|
| 1562 | + $valeurs = implode(', ', $valeurs); |
|
| 1563 | + |
|
| 1564 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | |
@@ -1576,32 +1576,32 @@ discard block |
||
| 1576 | 1576 | * @return string texte de sélection pour la requête |
| 1577 | 1577 | */ |
| 1578 | 1578 | function spip_mysql_multi($objet, $lang) { |
| 1579 | - $lengthlang = strlen("[$lang]"); |
|
| 1580 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1581 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1582 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1583 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1584 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1586 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1587 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1589 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1590 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1591 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1592 | - ' TRIM(' . $objet . '), ' . |
|
| 1593 | - ' CONCAT( ' . |
|
| 1594 | - " $debutchaine, " . |
|
| 1595 | - ' IF( ' . |
|
| 1596 | - " $poslang = 0, " . |
|
| 1597 | - " $chainemulti, " . |
|
| 1598 | - " $chainelang" . |
|
| 1599 | - ' ), ' . |
|
| 1600 | - " $finchaine" . |
|
| 1601 | - ' ) ' . |
|
| 1602 | - '))) AS multi'; |
|
| 1603 | - |
|
| 1604 | - return $retour; |
|
| 1579 | + $lengthlang = strlen("[$lang]"); |
|
| 1580 | + $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1581 | + $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1582 | + $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1583 | + $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1584 | + $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1586 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1587 | + $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | + $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1589 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1590 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1591 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1592 | + ' TRIM(' . $objet . '), ' . |
|
| 1593 | + ' CONCAT( ' . |
|
| 1594 | + " $debutchaine, " . |
|
| 1595 | + ' IF( ' . |
|
| 1596 | + " $poslang = 0, " . |
|
| 1597 | + " $chainemulti, " . |
|
| 1598 | + " $chainelang" . |
|
| 1599 | + ' ), ' . |
|
| 1600 | + " $finchaine" . |
|
| 1601 | + ' ) ' . |
|
| 1602 | + '))) AS multi'; |
|
| 1603 | + |
|
| 1604 | + return $retour; |
|
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | 1607 | /** |
@@ -1615,7 +1615,7 @@ discard block |
||
| 1615 | 1615 | * Valeur hexadécimale pour MySQL |
| 1616 | 1616 | **/ |
| 1617 | 1617 | function spip_mysql_hex($v) { |
| 1618 | - return '0x' . $v; |
|
| 1618 | + return '0x' . $v; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | /** |
@@ -1631,15 +1631,15 @@ discard block |
||
| 1631 | 1631 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1632 | 1632 | */ |
| 1633 | 1633 | function spip_mysql_quote($v, $type = '') { |
| 1634 | - if (!is_array($v)) { |
|
| 1635 | - return spip_mysql_cite($v, $type); |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1639 | - foreach ($v as $k => $r) { |
|
| 1640 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1641 | - } |
|
| 1642 | - return implode(',', $v); |
|
| 1634 | + if (!is_array($v)) { |
|
| 1635 | + return spip_mysql_cite($v, $type); |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1639 | + foreach ($v as $k => $r) { |
|
| 1640 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1641 | + } |
|
| 1642 | + return implode(',', $v); |
|
| 1643 | 1643 | } |
| 1644 | 1644 | |
| 1645 | 1645 | /** |
@@ -1655,18 +1655,18 @@ discard block |
||
| 1655 | 1655 | * Expression SQL |
| 1656 | 1656 | **/ |
| 1657 | 1657 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1658 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1659 | - return '(' |
|
| 1660 | - . $champ |
|
| 1661 | - . (($interval <= 0) ? '>' : '<') |
|
| 1662 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1663 | - . '(' |
|
| 1664 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1665 | - . ', INTERVAL ' |
|
| 1666 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1667 | - . ' ' |
|
| 1668 | - . $unite |
|
| 1669 | - . '))'; |
|
| 1658 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1659 | + return '(' |
|
| 1660 | + . $champ |
|
| 1661 | + . (($interval <= 0) ? '>' : '<') |
|
| 1662 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1663 | + . '(' |
|
| 1664 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1665 | + . ', INTERVAL ' |
|
| 1666 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1667 | + . ' ' |
|
| 1668 | + . $unite |
|
| 1669 | + . '))'; |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | |
@@ -1690,7 +1690,7 @@ discard block |
||
| 1690 | 1690 | * Expression de requête SQL |
| 1691 | 1691 | **/ |
| 1692 | 1692 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1693 | - return "($val $not IN ($valeurs))"; |
|
| 1693 | + return "($val $not IN ($valeurs))"; |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | |
@@ -1702,39 +1702,39 @@ discard block |
||
| 1702 | 1702 | * @return string|number texte ou nombre échappé |
| 1703 | 1703 | */ |
| 1704 | 1704 | function spip_mysql_cite($v, $type) { |
| 1705 | - if (!$type) { |
|
| 1706 | - if (is_bool($v)) { |
|
| 1707 | - return strval(intval($v)); |
|
| 1708 | - } elseif (is_numeric($v)) { |
|
| 1709 | - return strval($v); |
|
| 1710 | - } elseif ($v === null) { |
|
| 1711 | - return "''"; |
|
| 1712 | - } |
|
| 1713 | - return "'" . addslashes($v) . "'"; |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - if ($v === null) { |
|
| 1717 | - if (stripos($type, 'NOT NULL') === false) { |
|
| 1718 | - // null php se traduit en NULL SQL |
|
| 1719 | - return 'NULL'; |
|
| 1720 | - } else { |
|
| 1721 | - return "''"; |
|
| 1722 | - } |
|
| 1723 | - } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1724 | - return $v; |
|
| 1725 | - } elseif (sql_test_int($type)) { |
|
| 1726 | - if ( |
|
| 1727 | - is_numeric($v) |
|
| 1728 | - or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1729 | - ) { |
|
| 1730 | - return $v; |
|
| 1731 | - } else { |
|
| 1732 | - // si pas numerique, forcer le intval |
|
| 1733 | - return intval($v); |
|
| 1734 | - } |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - return ("'" . addslashes($v) . "'"); |
|
| 1705 | + if (!$type) { |
|
| 1706 | + if (is_bool($v)) { |
|
| 1707 | + return strval(intval($v)); |
|
| 1708 | + } elseif (is_numeric($v)) { |
|
| 1709 | + return strval($v); |
|
| 1710 | + } elseif ($v === null) { |
|
| 1711 | + return "''"; |
|
| 1712 | + } |
|
| 1713 | + return "'" . addslashes($v) . "'"; |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + if ($v === null) { |
|
| 1717 | + if (stripos($type, 'NOT NULL') === false) { |
|
| 1718 | + // null php se traduit en NULL SQL |
|
| 1719 | + return 'NULL'; |
|
| 1720 | + } else { |
|
| 1721 | + return "''"; |
|
| 1722 | + } |
|
| 1723 | + } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1724 | + return $v; |
|
| 1725 | + } elseif (sql_test_int($type)) { |
|
| 1726 | + if ( |
|
| 1727 | + is_numeric($v) |
|
| 1728 | + or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1729 | + ) { |
|
| 1730 | + return $v; |
|
| 1731 | + } else { |
|
| 1732 | + // si pas numerique, forcer le intval |
|
| 1733 | + return intval($v); |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + return ("'" . addslashes($v) . "'"); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | /** |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | * True si on a les fonctions, false sinon |
| 1745 | 1745 | */ |
| 1746 | 1746 | function spip_versions_mysql() { |
| 1747 | - return function_exists('mysqli_query'); |
|
| 1747 | + return function_exists('mysqli_query'); |
|
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | |
@@ -1757,20 +1757,20 @@ discard block |
||
| 1757 | 1757 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1758 | 1758 | */ |
| 1759 | 1759 | function test_rappel_nom_base_mysql($server_db) { |
| 1760 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1761 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1762 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1760 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1761 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1762 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1763 | 1763 | |
| 1764 | - if ($ok) { |
|
| 1765 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1764 | + if ($ok) { |
|
| 1765 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1766 | 1766 | |
| 1767 | - return ''; |
|
| 1768 | - } else { |
|
| 1769 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1767 | + return ''; |
|
| 1768 | + } else { |
|
| 1769 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1770 | 1770 | |
| 1771 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1772 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1773 | - } |
|
| 1771 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1772 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1773 | + } |
|
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | 1776 | /** |
@@ -1784,13 +1784,13 @@ discard block |
||
| 1784 | 1784 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1785 | 1785 | */ |
| 1786 | 1786 | function test_sql_mode_mysql($server_db) { |
| 1787 | - $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1788 | - $row = sql_fetch($res, $server_db); |
|
| 1789 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1790 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1787 | + $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1788 | + $row = sql_fetch($res, $server_db); |
|
| 1789 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1790 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1791 | 1791 | |
| 1792 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1793 | - } |
|
| 1792 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1793 | + } |
|
| 1794 | 1794 | |
| 1795 | - return ''; |
|
| 1795 | + return ''; |
|
| 1796 | 1796 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | define('_DEFAULT_DB', 'spip'); |
@@ -31,159 +31,159 @@ discard block |
||
| 31 | 31 | // si ca ne marche toujours pas, echec. |
| 32 | 32 | |
| 33 | 33 | function req_pg_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') { |
| 34 | - static $last_connect = []; |
|
| 35 | - if (!extension_loaded('pgsql')) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // si provient de selectdb |
|
| 40 | - if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 41 | - foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 42 | - ${$a} = $last_connect[$a]; |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - [$host, $p] = array_pad(explode(';', $addr), 2, null); |
|
| 46 | - if ($p > 0) { |
|
| 47 | - $port = " port=$p"; |
|
| 48 | - } else { |
|
| 49 | - $port = ''; |
|
| 50 | - } |
|
| 51 | - $erreurs = []; |
|
| 52 | - if ($db) { |
|
| 53 | - @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 54 | - } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 55 | - $erreurs[] = pg_last_error(); |
|
| 56 | - if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 57 | - $db = $login; |
|
| 58 | - } else { |
|
| 59 | - $erreurs[] = pg_last_error(); |
|
| 60 | - $db = _DEFAULT_DB; |
|
| 61 | - $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (!$link) { |
|
| 65 | - $erreurs[] = pg_last_error(); |
|
| 66 | - foreach ($erreurs as $e) { |
|
| 67 | - spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - if ($link) { |
|
| 74 | - $last_connect = [ |
|
| 75 | - 'addr' => $addr, |
|
| 76 | - 'port' => $port, |
|
| 77 | - 'login' => $login, |
|
| 78 | - 'pass' => $pass, |
|
| 79 | - 'db' => $db, |
|
| 80 | - 'prefixe' => $prefixe, |
|
| 81 | - ]; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - spip_log( |
|
| 85 | - "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 86 | - 'pg.' . _LOG_DEBUG |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - return !$link ? false : [ |
|
| 90 | - 'db' => $db, |
|
| 91 | - 'prefixe' => $prefixe ?: $db, |
|
| 92 | - 'link' => $link, |
|
| 93 | - ]; |
|
| 34 | + static $last_connect = []; |
|
| 35 | + if (!extension_loaded('pgsql')) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // si provient de selectdb |
|
| 40 | + if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 41 | + foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) { |
|
| 42 | + ${$a} = $last_connect[$a]; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + [$host, $p] = array_pad(explode(';', $addr), 2, null); |
|
| 46 | + if ($p > 0) { |
|
| 47 | + $port = " port=$p"; |
|
| 48 | + } else { |
|
| 49 | + $port = ''; |
|
| 50 | + } |
|
| 51 | + $erreurs = []; |
|
| 52 | + if ($db) { |
|
| 53 | + @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 54 | + } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 55 | + $erreurs[] = pg_last_error(); |
|
| 56 | + if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 57 | + $db = $login; |
|
| 58 | + } else { |
|
| 59 | + $erreurs[] = pg_last_error(); |
|
| 60 | + $db = _DEFAULT_DB; |
|
| 61 | + $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (!$link) { |
|
| 65 | + $erreurs[] = pg_last_error(); |
|
| 66 | + foreach ($erreurs as $e) { |
|
| 67 | + spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + if ($link) { |
|
| 74 | + $last_connect = [ |
|
| 75 | + 'addr' => $addr, |
|
| 76 | + 'port' => $port, |
|
| 77 | + 'login' => $login, |
|
| 78 | + 'pass' => $pass, |
|
| 79 | + 'db' => $db, |
|
| 80 | + 'prefixe' => $prefixe, |
|
| 81 | + ]; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + spip_log( |
|
| 85 | + "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 86 | + 'pg.' . _LOG_DEBUG |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + return !$link ? false : [ |
|
| 90 | + 'db' => $db, |
|
| 91 | + 'prefixe' => $prefixe ?: $db, |
|
| 92 | + 'link' => $link, |
|
| 93 | + ]; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $GLOBALS['spip_pg_functions_1'] = [ |
| 97 | - 'alter' => 'spip_pg_alter', |
|
| 98 | - 'count' => 'spip_pg_count', |
|
| 99 | - 'countsel' => 'spip_pg_countsel', |
|
| 100 | - 'create' => 'spip_pg_create', |
|
| 101 | - 'create_base' => 'spip_pg_create_base', |
|
| 102 | - 'create_view' => 'spip_pg_create_view', |
|
| 103 | - 'date_proche' => 'spip_pg_date_proche', |
|
| 104 | - 'delete' => 'spip_pg_delete', |
|
| 105 | - 'drop_table' => 'spip_pg_drop_table', |
|
| 106 | - 'drop_view' => 'spip_pg_drop_view', |
|
| 107 | - 'errno' => 'spip_pg_errno', |
|
| 108 | - 'error' => 'spip_pg_error', |
|
| 109 | - 'explain' => 'spip_pg_explain', |
|
| 110 | - 'fetch' => 'spip_pg_fetch', |
|
| 111 | - 'seek' => 'spip_pg_seek', |
|
| 112 | - 'free' => 'spip_pg_free', |
|
| 113 | - 'hex' => 'spip_pg_hex', |
|
| 114 | - 'in' => 'spip_pg_in', |
|
| 115 | - 'insert' => 'spip_pg_insert', |
|
| 116 | - 'insertq' => 'spip_pg_insertq', |
|
| 117 | - 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 118 | - 'listdbs' => 'spip_pg_listdbs', |
|
| 119 | - 'multi' => 'spip_pg_multi', |
|
| 120 | - 'optimize' => 'spip_pg_optimize', |
|
| 121 | - 'query' => 'spip_pg_query', |
|
| 122 | - 'quote' => 'spip_pg_quote', |
|
| 123 | - 'replace' => 'spip_pg_replace', |
|
| 124 | - 'replace_multi' => 'spip_pg_replace_multi', |
|
| 125 | - 'select' => 'spip_pg_select', |
|
| 126 | - 'selectdb' => 'spip_pg_selectdb', |
|
| 127 | - 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 128 | - 'showbase' => 'spip_pg_showbase', |
|
| 129 | - 'showtable' => 'spip_pg_showtable', |
|
| 130 | - 'update' => 'spip_pg_update', |
|
| 131 | - 'updateq' => 'spip_pg_updateq', |
|
| 97 | + 'alter' => 'spip_pg_alter', |
|
| 98 | + 'count' => 'spip_pg_count', |
|
| 99 | + 'countsel' => 'spip_pg_countsel', |
|
| 100 | + 'create' => 'spip_pg_create', |
|
| 101 | + 'create_base' => 'spip_pg_create_base', |
|
| 102 | + 'create_view' => 'spip_pg_create_view', |
|
| 103 | + 'date_proche' => 'spip_pg_date_proche', |
|
| 104 | + 'delete' => 'spip_pg_delete', |
|
| 105 | + 'drop_table' => 'spip_pg_drop_table', |
|
| 106 | + 'drop_view' => 'spip_pg_drop_view', |
|
| 107 | + 'errno' => 'spip_pg_errno', |
|
| 108 | + 'error' => 'spip_pg_error', |
|
| 109 | + 'explain' => 'spip_pg_explain', |
|
| 110 | + 'fetch' => 'spip_pg_fetch', |
|
| 111 | + 'seek' => 'spip_pg_seek', |
|
| 112 | + 'free' => 'spip_pg_free', |
|
| 113 | + 'hex' => 'spip_pg_hex', |
|
| 114 | + 'in' => 'spip_pg_in', |
|
| 115 | + 'insert' => 'spip_pg_insert', |
|
| 116 | + 'insertq' => 'spip_pg_insertq', |
|
| 117 | + 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 118 | + 'listdbs' => 'spip_pg_listdbs', |
|
| 119 | + 'multi' => 'spip_pg_multi', |
|
| 120 | + 'optimize' => 'spip_pg_optimize', |
|
| 121 | + 'query' => 'spip_pg_query', |
|
| 122 | + 'quote' => 'spip_pg_quote', |
|
| 123 | + 'replace' => 'spip_pg_replace', |
|
| 124 | + 'replace_multi' => 'spip_pg_replace_multi', |
|
| 125 | + 'select' => 'spip_pg_select', |
|
| 126 | + 'selectdb' => 'spip_pg_selectdb', |
|
| 127 | + 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 128 | + 'showbase' => 'spip_pg_showbase', |
|
| 129 | + 'showtable' => 'spip_pg_showtable', |
|
| 130 | + 'update' => 'spip_pg_update', |
|
| 131 | + 'updateq' => 'spip_pg_updateq', |
|
| 132 | 132 | ]; |
| 133 | 133 | |
| 134 | 134 | // Par ou ca passe une fois les traductions faites |
| 135 | 135 | function spip_pg_trace_query($query, $serveur = '') { |
| 136 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 137 | - $prefixe = $connexion['prefixe']; |
|
| 138 | - $link = $connexion['link']; |
|
| 139 | - $db = $connexion['db']; |
|
| 140 | - |
|
| 141 | - if (isset($_GET['var_profile'])) { |
|
| 142 | - include_spip('public/tracer'); |
|
| 143 | - $t = trace_query_start(); |
|
| 144 | - $e = ''; |
|
| 145 | - } else { |
|
| 146 | - $t = 0; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $connexion['last'] = $query; |
|
| 150 | - $r = spip_pg_query_simple($link, $query); |
|
| 151 | - |
|
| 152 | - // Log de l'erreur eventuelle |
|
| 153 | - if ($e = spip_pg_errno($serveur)) { |
|
| 154 | - $e .= spip_pg_error($query, $serveur); |
|
| 155 | - } // et du fautif |
|
| 156 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 136 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 137 | + $prefixe = $connexion['prefixe']; |
|
| 138 | + $link = $connexion['link']; |
|
| 139 | + $db = $connexion['db']; |
|
| 140 | + |
|
| 141 | + if (isset($_GET['var_profile'])) { |
|
| 142 | + include_spip('public/tracer'); |
|
| 143 | + $t = trace_query_start(); |
|
| 144 | + $e = ''; |
|
| 145 | + } else { |
|
| 146 | + $t = 0; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $connexion['last'] = $query; |
|
| 150 | + $r = spip_pg_query_simple($link, $query); |
|
| 151 | + |
|
| 152 | + // Log de l'erreur eventuelle |
|
| 153 | + if ($e = spip_pg_errno($serveur)) { |
|
| 154 | + $e .= spip_pg_error($query, $serveur); |
|
| 155 | + } // et du fautif |
|
| 156 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Fonction de requete generale quand on est sur que c'est SQL standard. |
| 160 | 160 | // Elle change juste le noms des tables ($table_prefix) dans le FROM etc |
| 161 | 161 | |
| 162 | 162 | function spip_pg_query($query, $serveur = '', $requeter = true) { |
| 163 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 164 | - $prefixe = $connexion['prefixe']; |
|
| 165 | - $link = $connexion['link']; |
|
| 166 | - $db = $connexion['db']; |
|
| 167 | - |
|
| 168 | - if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 169 | - $suite = strstr($query, (string) $regs[0]); |
|
| 170 | - $query = substr($query, 0, -strlen($suite)); |
|
| 171 | - } else { |
|
| 172 | - $suite = ''; |
|
| 173 | - } |
|
| 174 | - $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 175 | - |
|
| 176 | - // renvoyer la requete inerte si demandee |
|
| 177 | - if (!$requeter) { |
|
| 178 | - return $query; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return spip_pg_trace_query($query, $serveur); |
|
| 163 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 164 | + $prefixe = $connexion['prefixe']; |
|
| 165 | + $link = $connexion['link']; |
|
| 166 | + $db = $connexion['db']; |
|
| 167 | + |
|
| 168 | + if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 169 | + $suite = strstr($query, (string) $regs[0]); |
|
| 170 | + $query = substr($query, 0, -strlen($suite)); |
|
| 171 | + } else { |
|
| 172 | + $suite = ''; |
|
| 173 | + } |
|
| 174 | + $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 175 | + |
|
| 176 | + // renvoyer la requete inerte si demandee |
|
| 177 | + if (!$requeter) { |
|
| 178 | + return $query; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return spip_pg_trace_query($query, $serveur); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function spip_pg_query_simple($link, $query) { |
| 185 | - #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 186 | - return pg_query($link, $query); |
|
| 185 | + #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 186 | + return pg_query($link, $query); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /* |
@@ -195,196 +195,196 @@ discard block |
||
| 195 | 195 | * de requetes showtable intempestives |
| 196 | 196 | */ |
| 197 | 197 | function spip_pg_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') { |
| 198 | - static $tables = []; |
|
| 199 | - |
|
| 200 | - if (!isset($tables[$table])) { |
|
| 201 | - if (!$desc) { |
|
| 202 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 203 | - $desc = $trouver_table($table, $serveur); |
|
| 204 | - // si pas de description, on ne fait rien, ou on die() ? |
|
| 205 | - if (!$desc) { |
|
| 206 | - return $couples; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // recherche des champs avec simplement 'TIMESTAMP' |
|
| 211 | - // cependant, il faudra peut etre etendre |
|
| 212 | - // avec la gestion de DEFAULT et ON UPDATE |
|
| 213 | - // mais ceux-ci ne sont pas utilises dans le core |
|
| 214 | - $tables[$table] = []; |
|
| 215 | - foreach ($desc['field'] as $k => $v) { |
|
| 216 | - $v = strtolower(ltrim($v)); |
|
| 217 | - // ne pas ajouter de timestamp now() si un default est specifie |
|
| 218 | - if (strpos($v, 'timestamp') === 0 and !str_contains($v, 'default')) { |
|
| 219 | - $tables[$table][] = $k; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // ajout des champs type 'timestamp' absents |
|
| 225 | - foreach ($tables[$table] as $maj) { |
|
| 226 | - if (!array_key_exists($maj, $couples)) { |
|
| 227 | - $couples[$maj] = 'NOW()'; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $couples; |
|
| 198 | + static $tables = []; |
|
| 199 | + |
|
| 200 | + if (!isset($tables[$table])) { |
|
| 201 | + if (!$desc) { |
|
| 202 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 203 | + $desc = $trouver_table($table, $serveur); |
|
| 204 | + // si pas de description, on ne fait rien, ou on die() ? |
|
| 205 | + if (!$desc) { |
|
| 206 | + return $couples; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // recherche des champs avec simplement 'TIMESTAMP' |
|
| 211 | + // cependant, il faudra peut etre etendre |
|
| 212 | + // avec la gestion de DEFAULT et ON UPDATE |
|
| 213 | + // mais ceux-ci ne sont pas utilises dans le core |
|
| 214 | + $tables[$table] = []; |
|
| 215 | + foreach ($desc['field'] as $k => $v) { |
|
| 216 | + $v = strtolower(ltrim($v)); |
|
| 217 | + // ne pas ajouter de timestamp now() si un default est specifie |
|
| 218 | + if (strpos($v, 'timestamp') === 0 and !str_contains($v, 'default')) { |
|
| 219 | + $tables[$table][] = $k; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // ajout des champs type 'timestamp' absents |
|
| 225 | + foreach ($tables[$table] as $maj) { |
|
| 226 | + if (!array_key_exists($maj, $couples)) { |
|
| 227 | + $couples[$maj] = 'NOW()'; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $couples; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
| 235 | 235 | // Alter en PG ne traite pas les index |
| 236 | 236 | function spip_pg_alter($query, $serveur = '', $requeter = true) { |
| 237 | - // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 238 | - // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 239 | - // ou revoir l'api de sql_alter en creant un |
|
| 240 | - // sql_alter_table($table,array($actions)); |
|
| 241 | - if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 242 | - spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 243 | - |
|
| 244 | - return false; |
|
| 245 | - } |
|
| 246 | - $debut = $regs[1]; |
|
| 247 | - $table = $regs[3]; |
|
| 248 | - $suite = $regs[4]; |
|
| 249 | - $todo = explode(',', $suite); |
|
| 250 | - // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 251 | - $todo2 = []; |
|
| 252 | - $i = 0; |
|
| 253 | - $ouverte = false; |
|
| 254 | - while ($do = array_shift($todo)) { |
|
| 255 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 256 | - $o = (str_contains($do, '(')); |
|
| 257 | - $f = (str_contains($do, ')')); |
|
| 258 | - if ($o and !$f) { |
|
| 259 | - $ouverte = true; |
|
| 260 | - } elseif ($f) { |
|
| 261 | - $ouverte = false; |
|
| 262 | - } |
|
| 263 | - if (!$ouverte) { |
|
| 264 | - $i++; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - $todo = $todo2; |
|
| 268 | - $query = $debut . ' ' . array_shift($todo); |
|
| 269 | - |
|
| 270 | - if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 271 | - spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 272 | - } else { |
|
| 273 | - if ($r[1]) { |
|
| 274 | - spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 275 | - } |
|
| 276 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 277 | - if (function_exists($f)) { |
|
| 278 | - $f($r[2], $r[4], $serveur, $requeter); |
|
| 279 | - } else { |
|
| 280 | - spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - // Alter a plusieurs args. Faudrait optimiser. |
|
| 284 | - if ($todo) { |
|
| 285 | - spip_pg_alter("TABLE $table " . join(',', $todo)); |
|
| 286 | - } |
|
| 237 | + // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 238 | + // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 239 | + // ou revoir l'api de sql_alter en creant un |
|
| 240 | + // sql_alter_table($table,array($actions)); |
|
| 241 | + if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) { |
|
| 242 | + spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 243 | + |
|
| 244 | + return false; |
|
| 245 | + } |
|
| 246 | + $debut = $regs[1]; |
|
| 247 | + $table = $regs[3]; |
|
| 248 | + $suite = $regs[4]; |
|
| 249 | + $todo = explode(',', $suite); |
|
| 250 | + // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 251 | + $todo2 = []; |
|
| 252 | + $i = 0; |
|
| 253 | + $ouverte = false; |
|
| 254 | + while ($do = array_shift($todo)) { |
|
| 255 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do; |
|
| 256 | + $o = (str_contains($do, '(')); |
|
| 257 | + $f = (str_contains($do, ')')); |
|
| 258 | + if ($o and !$f) { |
|
| 259 | + $ouverte = true; |
|
| 260 | + } elseif ($f) { |
|
| 261 | + $ouverte = false; |
|
| 262 | + } |
|
| 263 | + if (!$ouverte) { |
|
| 264 | + $i++; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + $todo = $todo2; |
|
| 268 | + $query = $debut . ' ' . array_shift($todo); |
|
| 269 | + |
|
| 270 | + if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 271 | + spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 272 | + } else { |
|
| 273 | + if ($r[1]) { |
|
| 274 | + spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 275 | + } |
|
| 276 | + $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 277 | + if (function_exists($f)) { |
|
| 278 | + $f($r[2], $r[4], $serveur, $requeter); |
|
| 279 | + } else { |
|
| 280 | + spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + // Alter a plusieurs args. Faudrait optimiser. |
|
| 284 | + if ($todo) { |
|
| 285 | + spip_pg_alter("TABLE $table " . join(',', $todo)); |
|
| 286 | + } |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 290 | - if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 291 | - spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 292 | - } else { |
|
| 293 | - [, $old, $new, $type, $default, $null, $def2] = $r; |
|
| 294 | - $actions = ["ALTER $old TYPE " . mysql2pg_type($type)]; |
|
| 295 | - if ($null) { |
|
| 296 | - $actions[] = "ALTER $old SET NOT NULL"; |
|
| 297 | - } else { |
|
| 298 | - $actions[] = "ALTER $old DROP NOT NULL"; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - if ($d = ($default ?: $def2)) { |
|
| 302 | - $actions[] = "ALTER $old SET $d"; |
|
| 303 | - } else { |
|
| 304 | - $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 308 | - |
|
| 309 | - if ($old != $new) { |
|
| 310 | - spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 311 | - } |
|
| 312 | - } |
|
| 290 | + if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 291 | + spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 292 | + } else { |
|
| 293 | + [, $old, $new, $type, $default, $null, $def2] = $r; |
|
| 294 | + $actions = ["ALTER $old TYPE " . mysql2pg_type($type)]; |
|
| 295 | + if ($null) { |
|
| 296 | + $actions[] = "ALTER $old SET NOT NULL"; |
|
| 297 | + } else { |
|
| 298 | + $actions[] = "ALTER $old DROP NOT NULL"; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + if ($d = ($default ?: $def2)) { |
|
| 302 | + $actions[] = "ALTER $old SET $d"; |
|
| 303 | + } else { |
|
| 304 | + $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 308 | + |
|
| 309 | + if ($old != $new) { |
|
| 310 | + spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
| 316 | - $nom_index = null; |
|
| 317 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 318 | - spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 319 | - |
|
| 320 | - return null; |
|
| 321 | - } |
|
| 322 | - if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 323 | - preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 324 | - if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 325 | - $m[2] = $n[1]; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 329 | - } elseif ($r[1][0] == 'P') { |
|
| 330 | - // la primary peut etre sur plusieurs champs |
|
| 331 | - $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 332 | - $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 333 | - |
|
| 334 | - return spip_pg_query( |
|
| 335 | - "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', |
|
| 336 | - $serveur, |
|
| 337 | - $requeter |
|
| 338 | - ); |
|
| 339 | - } else { |
|
| 340 | - preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 341 | - // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 342 | - // bug potentiel si qqn met "(colonne, colonne)" |
|
| 343 | - // |
|
| 344 | - // nom_index (colonnes) |
|
| 345 | - if ($m[2]) { |
|
| 346 | - $colonnes = substr($m[2], 1, -1); |
|
| 347 | - $nom_index = $m[1]; |
|
| 348 | - } else { |
|
| 349 | - // (colonne) |
|
| 350 | - if ($m[1][0] == '(') { |
|
| 351 | - $colonnes = substr($m[1], 1, -1); |
|
| 352 | - if (str_contains(',', $colonnes)) { |
|
| 353 | - spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 354 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 355 | - } else { |
|
| 356 | - $nom_index = $colonnes; |
|
| 357 | - } |
|
| 358 | - } // nom_index |
|
| 359 | - else { |
|
| 360 | - $nom_index = $colonnes = $m[1]; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 365 | - } |
|
| 316 | + $nom_index = null; |
|
| 317 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 318 | + spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 319 | + |
|
| 320 | + return null; |
|
| 321 | + } |
|
| 322 | + if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 323 | + preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 324 | + if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 325 | + $m[2] = $n[1]; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 329 | + } elseif ($r[1][0] == 'P') { |
|
| 330 | + // la primary peut etre sur plusieurs champs |
|
| 331 | + $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 332 | + $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 333 | + |
|
| 334 | + return spip_pg_query( |
|
| 335 | + "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', |
|
| 336 | + $serveur, |
|
| 337 | + $requeter |
|
| 338 | + ); |
|
| 339 | + } else { |
|
| 340 | + preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 341 | + // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 342 | + // bug potentiel si qqn met "(colonne, colonne)" |
|
| 343 | + // |
|
| 344 | + // nom_index (colonnes) |
|
| 345 | + if ($m[2]) { |
|
| 346 | + $colonnes = substr($m[2], 1, -1); |
|
| 347 | + $nom_index = $m[1]; |
|
| 348 | + } else { |
|
| 349 | + // (colonne) |
|
| 350 | + if ($m[1][0] == '(') { |
|
| 351 | + $colonnes = substr($m[1], 1, -1); |
|
| 352 | + if (str_contains(',', $colonnes)) { |
|
| 353 | + spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes' |
|
| 354 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 355 | + } else { |
|
| 356 | + $nom_index = $colonnes; |
|
| 357 | + } |
|
| 358 | + } // nom_index |
|
| 359 | + else { |
|
| 360 | + $nom_index = $colonnes = $m[1]; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 365 | + } |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
| 369 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 370 | - spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 371 | - } else { |
|
| 372 | - if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 373 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 374 | - } elseif ($r[1][0] == 'P') { |
|
| 375 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 376 | - } else { |
|
| 377 | - return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur); |
|
| 378 | - } |
|
| 379 | - } |
|
| 369 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 370 | + spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 371 | + } else { |
|
| 372 | + if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 373 | + return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 374 | + } elseif ($r[1][0] == 'P') { |
|
| 375 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 376 | + } else { |
|
| 377 | + return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
| 383 | - if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 384 | - spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 385 | - } else { |
|
| 386 | - return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 387 | - } |
|
| 383 | + if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 384 | + spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 385 | + } else { |
|
| 386 | + return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // attention (en pg) : |
@@ -392,17 +392,17 @@ discard block |
||
| 392 | 392 | // - alter table A rename X to Y = changer le nom de la colonne X en Y |
| 393 | 393 | // pour l'instant, traiter simplement RENAME TO X |
| 394 | 394 | function spip_pg_alter_rename($table, $arg, $serveur = '', $requeter = true) { |
| 395 | - $rename = ''; |
|
| 396 | - // si TO, mais pas au debut |
|
| 397 | - if (!stripos($arg, 'TO ')) { |
|
| 398 | - $rename = $arg; |
|
| 399 | - } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 400 | - $rename = $r[2]; |
|
| 401 | - } else { |
|
| 402 | - spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 395 | + $rename = ''; |
|
| 396 | + // si TO, mais pas au debut |
|
| 397 | + if (!stripos($arg, 'TO ')) { |
|
| 398 | + $rename = $arg; |
|
| 399 | + } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 400 | + $rename = $r[2]; |
|
| 401 | + } else { |
|
| 402 | + spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -418,59 +418,59 @@ discard block |
||
| 418 | 418 | * @return bool ou requete |
| 419 | 419 | */ |
| 420 | 420 | function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
| 421 | - if (!($nom or $table or $champs)) { |
|
| 422 | - spip_log( |
|
| 423 | - "Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . '))', |
|
| 424 | - 'pg.' . _LOG_ERREUR |
|
| 425 | - ); |
|
| 426 | - |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $nom = str_replace('`', '', $nom); |
|
| 431 | - $champs = str_replace('`', '', $champs); |
|
| 432 | - |
|
| 433 | - // PG ne differentie pas noms des index en fonction des tables |
|
| 434 | - // il faut donc creer des noms uniques d'index pour une base pg |
|
| 435 | - $nom = $table . '_' . $nom; |
|
| 436 | - // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 437 | - if (!is_array($champs)) { |
|
| 438 | - if ($champs[0] == '(') { |
|
| 439 | - $champs = substr($champs, 1, -1); |
|
| 440 | - } |
|
| 441 | - $champs = [$champs]; |
|
| 442 | - } |
|
| 443 | - $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ')'; |
|
| 444 | - if (!$requeter) { |
|
| 445 | - return $query; |
|
| 446 | - } |
|
| 447 | - $res = spip_pg_query($query, $serveur, $requeter); |
|
| 448 | - |
|
| 449 | - return $res; |
|
| 421 | + if (!($nom or $table or $champs)) { |
|
| 422 | + spip_log( |
|
| 423 | + "Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . '))', |
|
| 424 | + 'pg.' . _LOG_ERREUR |
|
| 425 | + ); |
|
| 426 | + |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $nom = str_replace('`', '', $nom); |
|
| 431 | + $champs = str_replace('`', '', $champs); |
|
| 432 | + |
|
| 433 | + // PG ne differentie pas noms des index en fonction des tables |
|
| 434 | + // il faut donc creer des noms uniques d'index pour une base pg |
|
| 435 | + $nom = $table . '_' . $nom; |
|
| 436 | + // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 437 | + if (!is_array($champs)) { |
|
| 438 | + if ($champs[0] == '(') { |
|
| 439 | + $champs = substr($champs, 1, -1); |
|
| 440 | + } |
|
| 441 | + $champs = [$champs]; |
|
| 442 | + } |
|
| 443 | + $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ')'; |
|
| 444 | + if (!$requeter) { |
|
| 445 | + return $query; |
|
| 446 | + } |
|
| 447 | + $res = spip_pg_query($query, $serveur, $requeter); |
|
| 448 | + |
|
| 449 | + return $res; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| 453 | 453 | function spip_pg_explain($query, $serveur = '', $requeter = true) { |
| 454 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 455 | - return []; |
|
| 456 | - } |
|
| 457 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 458 | - $prefixe = $connexion['prefixe']; |
|
| 459 | - $link = $connexion['link']; |
|
| 460 | - if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 461 | - $suite = strstr($query, (string) $regs[0]); |
|
| 462 | - $query = substr($query, 0, -strlen($suite)); |
|
| 463 | - } else { |
|
| 464 | - $suite = ''; |
|
| 465 | - } |
|
| 466 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 467 | - |
|
| 468 | - if (!$requeter) { |
|
| 469 | - return $query; |
|
| 470 | - } |
|
| 471 | - $r = spip_pg_query_simple($link, $query); |
|
| 472 | - |
|
| 473 | - return spip_pg_fetch($r, null, $serveur); |
|
| 454 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 455 | + return []; |
|
| 456 | + } |
|
| 457 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 458 | + $prefixe = $connexion['prefixe']; |
|
| 459 | + $link = $connexion['link']; |
|
| 460 | + if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 461 | + $suite = strstr($query, (string) $regs[0]); |
|
| 462 | + $query = substr($query, 0, -strlen($suite)); |
|
| 463 | + } else { |
|
| 464 | + $suite = ''; |
|
| 465 | + } |
|
| 466 | + $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 467 | + |
|
| 468 | + if (!$requeter) { |
|
| 469 | + return $query; |
|
| 470 | + } |
|
| 471 | + $r = spip_pg_query_simple($link, $query); |
|
| 472 | + |
|
| 473 | + return spip_pg_fetch($r, null, $serveur); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | |
@@ -489,92 +489,92 @@ discard block |
||
| 489 | 489 | * - False en cas d'erreur. |
| 490 | 490 | **/ |
| 491 | 491 | function spip_pg_selectdb($db, $serveur = '', $requeter = true) { |
| 492 | - // se connecter a la base indiquee |
|
| 493 | - // avec les identifiants connus |
|
| 494 | - $index = $serveur ? strtolower($serveur) : 0; |
|
| 492 | + // se connecter a la base indiquee |
|
| 493 | + // avec les identifiants connus |
|
| 494 | + $index = $serveur ? strtolower($serveur) : 0; |
|
| 495 | 495 | |
| 496 | - if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) { |
|
| 497 | - if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 498 | - return $db; |
|
| 499 | - } |
|
| 500 | - } |
|
| 496 | + if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) { |
|
| 497 | + if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 498 | + return $db; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - return false; |
|
| 502 | + return false; |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // Qu'une seule base pour le moment |
| 506 | 506 | |
| 507 | 507 | function spip_pg_listdbs($serveur) { |
| 508 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 509 | - $link = $connexion['link']; |
|
| 510 | - $dbs = []; |
|
| 511 | - $res = spip_pg_query_simple($link, 'select * From pg_database'); |
|
| 512 | - while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 513 | - $dbs[] = reset($row); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $dbs; |
|
| 508 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 509 | + $link = $connexion['link']; |
|
| 510 | + $dbs = []; |
|
| 511 | + $res = spip_pg_query_simple($link, 'select * From pg_database'); |
|
| 512 | + while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 513 | + $dbs[] = reset($row); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $dbs; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | function spip_pg_select( |
| 520 | - $select, |
|
| 521 | - $from, |
|
| 522 | - $where = '', |
|
| 523 | - $groupby = [], |
|
| 524 | - $orderby = '', |
|
| 525 | - $limit = '', |
|
| 526 | - $having = '', |
|
| 527 | - $serveur = '', |
|
| 528 | - $requeter = true |
|
| 520 | + $select, |
|
| 521 | + $from, |
|
| 522 | + $where = '', |
|
| 523 | + $groupby = [], |
|
| 524 | + $orderby = '', |
|
| 525 | + $limit = '', |
|
| 526 | + $having = '', |
|
| 527 | + $serveur = '', |
|
| 528 | + $requeter = true |
|
| 529 | 529 | ) { |
| 530 | 530 | |
| 531 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 532 | - $prefixe = $connexion['prefixe']; |
|
| 533 | - $link = $connexion['link']; |
|
| 534 | - $db = $connexion['db']; |
|
| 535 | - |
|
| 536 | - $limit = preg_match('/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/', $limit, $limatch); |
|
| 537 | - if ($limit) { |
|
| 538 | - $offset = $limatch[2]; |
|
| 539 | - $count = $limatch[3]; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - $select = spip_pg_frommysql($select); |
|
| 543 | - |
|
| 544 | - // si pas de tri explicitement demande, le GROUP BY ne |
|
| 545 | - // contient que la clef primaire. |
|
| 546 | - // lui ajouter alors le champ de tri par defaut |
|
| 547 | - if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) { |
|
| 548 | - $groupby[] = $groupbyplus[1]; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $orderby = spip_pg_orderby($orderby, $select); |
|
| 552 | - |
|
| 553 | - if ($having) { |
|
| 554 | - if (is_array($having)) { |
|
| 555 | - $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - $from = spip_pg_from($from, $prefixe); |
|
| 559 | - $query = 'SELECT ' . $select |
|
| 560 | - . (!$from ? '' : "\nFROM $from") |
|
| 561 | - . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join( |
|
| 562 | - "\n\tAND ", |
|
| 563 | - array_map('calculer_pg_where', $where) |
|
| 564 | - ))))) |
|
| 565 | - . spip_pg_groupby($groupby, $from, $select) |
|
| 566 | - . (!$having ? '' : "\nHAVING $having") |
|
| 567 | - . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 568 | - . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 569 | - |
|
| 570 | - // renvoyer la requete inerte si demandee |
|
| 571 | - if ($requeter === false) { |
|
| 572 | - return $query; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $r = spip_pg_trace_query($query, $serveur); |
|
| 576 | - |
|
| 577 | - return $r ?: $query; |
|
| 531 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 532 | + $prefixe = $connexion['prefixe']; |
|
| 533 | + $link = $connexion['link']; |
|
| 534 | + $db = $connexion['db']; |
|
| 535 | + |
|
| 536 | + $limit = preg_match('/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/', $limit, $limatch); |
|
| 537 | + if ($limit) { |
|
| 538 | + $offset = $limatch[2]; |
|
| 539 | + $count = $limatch[3]; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + $select = spip_pg_frommysql($select); |
|
| 543 | + |
|
| 544 | + // si pas de tri explicitement demande, le GROUP BY ne |
|
| 545 | + // contient que la clef primaire. |
|
| 546 | + // lui ajouter alors le champ de tri par defaut |
|
| 547 | + if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) { |
|
| 548 | + $groupby[] = $groupbyplus[1]; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $orderby = spip_pg_orderby($orderby, $select); |
|
| 552 | + |
|
| 553 | + if ($having) { |
|
| 554 | + if (is_array($having)) { |
|
| 555 | + $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + $from = spip_pg_from($from, $prefixe); |
|
| 559 | + $query = 'SELECT ' . $select |
|
| 560 | + . (!$from ? '' : "\nFROM $from") |
|
| 561 | + . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join( |
|
| 562 | + "\n\tAND ", |
|
| 563 | + array_map('calculer_pg_where', $where) |
|
| 564 | + ))))) |
|
| 565 | + . spip_pg_groupby($groupby, $from, $select) |
|
| 566 | + . (!$having ? '' : "\nHAVING $having") |
|
| 567 | + . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 568 | + . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 569 | + |
|
| 570 | + // renvoyer la requete inerte si demandee |
|
| 571 | + if ($requeter === false) { |
|
| 572 | + return $query; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $r = spip_pg_trace_query($query, $serveur); |
|
| 576 | + |
|
| 577 | + return $r ?: $query; |
|
| 578 | 578 | ; |
| 579 | 579 | } |
| 580 | 580 | |
@@ -582,26 +582,26 @@ discard block |
||
| 582 | 582 | // car le reste de la requete utilise les alias (AS) systematiquement |
| 583 | 583 | |
| 584 | 584 | function spip_pg_from($from, $prefixe) { |
| 585 | - if (is_array($from)) { |
|
| 586 | - $from = spip_pg_select_as($from); |
|
| 587 | - } |
|
| 585 | + if (is_array($from)) { |
|
| 586 | + $from = spip_pg_select_as($from); |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from); |
|
| 589 | + return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | function spip_pg_orderby($order, $select) { |
| 593 | - $res = []; |
|
| 594 | - $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 595 | - |
|
| 596 | - foreach ($arg as $v) { |
|
| 597 | - if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) { |
|
| 598 | - $res[] = $m[1]; |
|
| 599 | - } else { |
|
| 600 | - $res[] = $v; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return spip_pg_frommysql(join(',', $res)); |
|
| 593 | + $res = []; |
|
| 594 | + $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 595 | + |
|
| 596 | + foreach ($arg as $v) { |
|
| 597 | + if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) { |
|
| 598 | + $res[] = $m[1]; |
|
| 599 | + } else { |
|
| 600 | + $res[] = $v; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return spip_pg_frommysql(join(',', $res)); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | // Conversion a l'arrach' des jointures MySQL en jointures PG |
@@ -609,56 +609,56 @@ discard block |
||
| 609 | 609 | // et pour enlever les repetitions (sans incidence de perf, mais ca fait sale) |
| 610 | 610 | |
| 611 | 611 | function spip_pg_groupby($groupby, $from, $select) { |
| 612 | - $join = strpos($from, ','); |
|
| 613 | - // ismplifier avant de decouper |
|
| 614 | - if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 615 | - $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - if ($join or $groupby) { |
|
| 619 | - $join = is_array($select) ? $select : explode(', ', $select); |
|
| 620 | - } |
|
| 621 | - if ($join) { |
|
| 622 | - // enlever les 0 as points, '', ... |
|
| 623 | - foreach ($join as $k => $v) { |
|
| 624 | - $v = str_replace('DISTINCT ', '', $v); |
|
| 625 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 626 | - $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 627 | - $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 628 | - // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 629 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 630 | - // idem sans AS (fetch numerique) |
|
| 631 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 632 | - // des AS simples : on garde le cote droit du AS |
|
| 633 | - $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 634 | - // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 635 | - if (preg_match(',^[\'"],', $v) or is_numeric($v)) { |
|
| 636 | - unset($join[$k]); |
|
| 637 | - } else { |
|
| 638 | - $join[$k] = trim($v); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - $join = array_diff($join, ['']); |
|
| 642 | - $join = implode(',', $join); |
|
| 643 | - } |
|
| 644 | - if (is_array($groupby)) { |
|
| 645 | - $groupby = join(',', $groupby); |
|
| 646 | - } |
|
| 647 | - if ($join) { |
|
| 648 | - $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 649 | - } |
|
| 650 | - if (!$groupby) { |
|
| 651 | - return ''; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $groupby = spip_pg_frommysql($groupby); |
|
| 655 | - // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 656 | - // issue de prepare_recherche |
|
| 657 | - $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 658 | - $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 659 | - $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 660 | - |
|
| 661 | - return "\nGROUP BY $groupby"; |
|
| 612 | + $join = strpos($from, ','); |
|
| 613 | + // ismplifier avant de decouper |
|
| 614 | + if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 615 | + $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + if ($join or $groupby) { |
|
| 619 | + $join = is_array($select) ? $select : explode(', ', $select); |
|
| 620 | + } |
|
| 621 | + if ($join) { |
|
| 622 | + // enlever les 0 as points, '', ... |
|
| 623 | + foreach ($join as $k => $v) { |
|
| 624 | + $v = str_replace('DISTINCT ', '', $v); |
|
| 625 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 626 | + $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 627 | + $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 628 | + // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 629 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 630 | + // idem sans AS (fetch numerique) |
|
| 631 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 632 | + // des AS simples : on garde le cote droit du AS |
|
| 633 | + $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 634 | + // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 635 | + if (preg_match(',^[\'"],', $v) or is_numeric($v)) { |
|
| 636 | + unset($join[$k]); |
|
| 637 | + } else { |
|
| 638 | + $join[$k] = trim($v); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + $join = array_diff($join, ['']); |
|
| 642 | + $join = implode(',', $join); |
|
| 643 | + } |
|
| 644 | + if (is_array($groupby)) { |
|
| 645 | + $groupby = join(',', $groupby); |
|
| 646 | + } |
|
| 647 | + if ($join) { |
|
| 648 | + $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 649 | + } |
|
| 650 | + if (!$groupby) { |
|
| 651 | + return ''; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $groupby = spip_pg_frommysql($groupby); |
|
| 655 | + // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 656 | + // issue de prepare_recherche |
|
| 657 | + $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 658 | + $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 659 | + $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 660 | + |
|
| 661 | + return "\nGROUP BY $groupby"; |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | // Conversion des operateurs MySQL en PG |
@@ -669,492 +669,492 @@ discard block |
||
| 669 | 669 | // A ameliorer. |
| 670 | 670 | |
| 671 | 671 | function spip_pg_frommysql($arg) { |
| 672 | - if (is_array($arg)) { |
|
| 673 | - $arg = join(', ', $arg); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - $res = spip_pg_fromfield($arg); |
|
| 677 | - |
|
| 678 | - $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 679 | - |
|
| 680 | - $res = preg_replace( |
|
| 681 | - '/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 682 | - 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 683 | - $res |
|
| 684 | - ); |
|
| 685 | - $res = preg_replace( |
|
| 686 | - '/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 687 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 688 | - $res |
|
| 689 | - ); |
|
| 690 | - $res = preg_replace( |
|
| 691 | - '/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 692 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 693 | - $res |
|
| 694 | - ); |
|
| 695 | - |
|
| 696 | - $res = preg_replace( |
|
| 697 | - '/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 698 | - ' EXTRACT(epoch FROM NOW())', |
|
| 699 | - $res |
|
| 700 | - ); |
|
| 701 | - |
|
| 702 | - // la fonction md5(integer) n'est pas connu en pg |
|
| 703 | - // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 704 | - $res = preg_replace( |
|
| 705 | - '/md5\s*[(]([^)]*)[)]/i', |
|
| 706 | - 'MD5(CAST(\1 AS text))', |
|
| 707 | - $res |
|
| 708 | - ); |
|
| 709 | - |
|
| 710 | - $res = preg_replace( |
|
| 711 | - '/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 712 | - ' EXTRACT(epoch FROM \1)', |
|
| 713 | - $res |
|
| 714 | - ); |
|
| 715 | - |
|
| 716 | - $res = preg_replace( |
|
| 717 | - '/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 718 | - ' EXTRACT(day FROM \1)', |
|
| 719 | - $res |
|
| 720 | - ); |
|
| 721 | - |
|
| 722 | - $res = preg_replace( |
|
| 723 | - '/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 724 | - ' EXTRACT(month FROM \1)', |
|
| 725 | - $res |
|
| 726 | - ); |
|
| 727 | - |
|
| 728 | - $res = preg_replace( |
|
| 729 | - '/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 730 | - ' EXTRACT(year FROM \1)', |
|
| 731 | - $res |
|
| 732 | - ); |
|
| 733 | - |
|
| 734 | - $res = preg_replace( |
|
| 735 | - '/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 736 | - ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 737 | - $res |
|
| 738 | - ); |
|
| 739 | - |
|
| 740 | - $res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res); |
|
| 741 | - |
|
| 742 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 743 | - |
|
| 744 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 745 | - |
|
| 746 | - $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 747 | - $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 748 | - $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 749 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 750 | - $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 751 | - |
|
| 752 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 753 | - $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 754 | - |
|
| 755 | - $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 756 | - $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 672 | + if (is_array($arg)) { |
|
| 673 | + $arg = join(', ', $arg); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + $res = spip_pg_fromfield($arg); |
|
| 677 | + |
|
| 678 | + $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 679 | + |
|
| 680 | + $res = preg_replace( |
|
| 681 | + '/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 682 | + 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 683 | + $res |
|
| 684 | + ); |
|
| 685 | + $res = preg_replace( |
|
| 686 | + '/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 687 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 688 | + $res |
|
| 689 | + ); |
|
| 690 | + $res = preg_replace( |
|
| 691 | + '/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 692 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 693 | + $res |
|
| 694 | + ); |
|
| 695 | + |
|
| 696 | + $res = preg_replace( |
|
| 697 | + '/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 698 | + ' EXTRACT(epoch FROM NOW())', |
|
| 699 | + $res |
|
| 700 | + ); |
|
| 701 | + |
|
| 702 | + // la fonction md5(integer) n'est pas connu en pg |
|
| 703 | + // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 704 | + $res = preg_replace( |
|
| 705 | + '/md5\s*[(]([^)]*)[)]/i', |
|
| 706 | + 'MD5(CAST(\1 AS text))', |
|
| 707 | + $res |
|
| 708 | + ); |
|
| 709 | + |
|
| 710 | + $res = preg_replace( |
|
| 711 | + '/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 712 | + ' EXTRACT(epoch FROM \1)', |
|
| 713 | + $res |
|
| 714 | + ); |
|
| 715 | + |
|
| 716 | + $res = preg_replace( |
|
| 717 | + '/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 718 | + ' EXTRACT(day FROM \1)', |
|
| 719 | + $res |
|
| 720 | + ); |
|
| 721 | + |
|
| 722 | + $res = preg_replace( |
|
| 723 | + '/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 724 | + ' EXTRACT(month FROM \1)', |
|
| 725 | + $res |
|
| 726 | + ); |
|
| 727 | + |
|
| 728 | + $res = preg_replace( |
|
| 729 | + '/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 730 | + ' EXTRACT(year FROM \1)', |
|
| 731 | + $res |
|
| 732 | + ); |
|
| 733 | + |
|
| 734 | + $res = preg_replace( |
|
| 735 | + '/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 736 | + ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 737 | + $res |
|
| 738 | + ); |
|
| 739 | + |
|
| 740 | + $res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res); |
|
| 741 | + |
|
| 742 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 743 | + |
|
| 744 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 745 | + |
|
| 746 | + $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 747 | + $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 748 | + $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 749 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 750 | + $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 751 | + |
|
| 752 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 753 | + $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 754 | + |
|
| 755 | + $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 756 | + $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 757 | 757 | # correct en theorie mais produit des debordements arithmetiques |
| 758 | 758 | # $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res); |
| 759 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 760 | - $res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res); |
|
| 759 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 760 | + $res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res); |
|
| 761 | 761 | |
| 762 | - return str_replace('REGEXP', '~', $res); |
|
| 762 | + return str_replace('REGEXP', '~', $res); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | function spip_pg_fromfield($arg) { |
| 766 | - while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 767 | - preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 768 | - $res = ''; |
|
| 769 | - $n = 0; |
|
| 770 | - $index = $m[2]; |
|
| 771 | - foreach ($r[1] as $v) { |
|
| 772 | - $n++; |
|
| 773 | - $res .= "\nwhen $index=$v then $n"; |
|
| 774 | - } |
|
| 775 | - $arg = $m[1] . "case $res else 0 end " |
|
| 776 | - . substr($arg, strlen($m[0])); |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return $arg; |
|
| 766 | + while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 767 | + preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 768 | + $res = ''; |
|
| 769 | + $n = 0; |
|
| 770 | + $index = $m[2]; |
|
| 771 | + foreach ($r[1] as $v) { |
|
| 772 | + $n++; |
|
| 773 | + $res .= "\nwhen $index=$v then $n"; |
|
| 774 | + } |
|
| 775 | + $arg = $m[1] . "case $res else 0 end " |
|
| 776 | + . substr($arg, strlen($m[0])); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $arg; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | function calculer_pg_where($v) { |
| 783 | - if (!is_array($v)) { |
|
| 784 | - return spip_pg_frommysql($v); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 788 | - if (!($n = count($v))) { |
|
| 789 | - return $op; |
|
| 790 | - } else { |
|
| 791 | - $arg = calculer_pg_where(array_shift($v)); |
|
| 792 | - if ($n == 1) { |
|
| 793 | - return "$op($arg)"; |
|
| 794 | - } else { |
|
| 795 | - $arg2 = calculer_pg_where(array_shift($v)); |
|
| 796 | - if ($n == 2) { |
|
| 797 | - return "($arg $op $arg2)"; |
|
| 798 | - } else { |
|
| 799 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - } |
|
| 783 | + if (!is_array($v)) { |
|
| 784 | + return spip_pg_frommysql($v); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 788 | + if (!($n = count($v))) { |
|
| 789 | + return $op; |
|
| 790 | + } else { |
|
| 791 | + $arg = calculer_pg_where(array_shift($v)); |
|
| 792 | + if ($n == 1) { |
|
| 793 | + return "$op($arg)"; |
|
| 794 | + } else { |
|
| 795 | + $arg2 = calculer_pg_where(array_shift($v)); |
|
| 796 | + if ($n == 2) { |
|
| 797 | + return "($arg $op $arg2)"; |
|
| 798 | + } else { |
|
| 799 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | function calculer_pg_expression($expression, $v, $join = 'AND') { |
| 807 | - if (empty($v)) { |
|
| 808 | - return ''; |
|
| 809 | - } |
|
| 807 | + if (empty($v)) { |
|
| 808 | + return ''; |
|
| 809 | + } |
|
| 810 | 810 | |
| 811 | - $exp = "\n$expression "; |
|
| 811 | + $exp = "\n$expression "; |
|
| 812 | 812 | |
| 813 | - if (!is_array($v)) { |
|
| 814 | - $v = [$v]; |
|
| 815 | - } |
|
| 813 | + if (!is_array($v)) { |
|
| 814 | + $v = [$v]; |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | - if (strtoupper($join) === 'AND') { |
|
| 818 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 819 | - } else { |
|
| 820 | - return $exp . join($join, $v); |
|
| 821 | - } |
|
| 817 | + if (strtoupper($join) === 'AND') { |
|
| 818 | + return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 819 | + } else { |
|
| 820 | + return $exp . join($join, $v); |
|
| 821 | + } |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | function spip_pg_select_as($args) { |
| 825 | - $argsas = ''; |
|
| 826 | - foreach ($args as $k => $v) { |
|
| 827 | - if (substr($k, -1) == '@') { |
|
| 828 | - // c'est une jointure qui se refere au from precedent |
|
| 829 | - // pas de virgule |
|
| 830 | - $argsas .= ' ' . $v; |
|
| 831 | - } else { |
|
| 832 | - $as = ''; |
|
| 833 | - // spip_log("$k : $v", _LOG_DEBUG); |
|
| 834 | - if (!is_numeric($k)) { |
|
| 835 | - if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 836 | - $v = $k; |
|
| 837 | - } elseif ($v != $k) { |
|
| 838 | - $p = strpos($v, ' '); |
|
| 839 | - if ($p) { |
|
| 840 | - $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 841 | - } else { |
|
| 842 | - $as = " AS $k"; |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 847 | - // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 848 | - $argsas .= ', ' . $v . $as; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - return substr($argsas, 2); |
|
| 825 | + $argsas = ''; |
|
| 826 | + foreach ($args as $k => $v) { |
|
| 827 | + if (substr($k, -1) == '@') { |
|
| 828 | + // c'est une jointure qui se refere au from precedent |
|
| 829 | + // pas de virgule |
|
| 830 | + $argsas .= ' ' . $v; |
|
| 831 | + } else { |
|
| 832 | + $as = ''; |
|
| 833 | + // spip_log("$k : $v", _LOG_DEBUG); |
|
| 834 | + if (!is_numeric($k)) { |
|
| 835 | + if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 836 | + $v = $k; |
|
| 837 | + } elseif ($v != $k) { |
|
| 838 | + $p = strpos($v, ' '); |
|
| 839 | + if ($p) { |
|
| 840 | + $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 841 | + } else { |
|
| 842 | + $as = " AS $k"; |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 847 | + // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 848 | + $argsas .= ', ' . $v . $as; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + return substr($argsas, 2); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) { |
| 856 | 856 | |
| 857 | - if ($res) { |
|
| 858 | - $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 859 | - } |
|
| 857 | + if ($res) { |
|
| 858 | + $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | - return $res; |
|
| 861 | + return $res; |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | function spip_pg_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 865 | - if ($r) { |
|
| 866 | - return pg_result_seek($r, $row_number); |
|
| 867 | - } |
|
| 865 | + if ($r) { |
|
| 866 | + return pg_result_seek($r, $row_number); |
|
| 867 | + } |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | |
| 871 | 871 | function spip_pg_countsel( |
| 872 | - $from = [], |
|
| 873 | - $where = [], |
|
| 874 | - $groupby = [], |
|
| 875 | - $having = [], |
|
| 876 | - $serveur = '', |
|
| 877 | - $requeter = true |
|
| 872 | + $from = [], |
|
| 873 | + $where = [], |
|
| 874 | + $groupby = [], |
|
| 875 | + $having = [], |
|
| 876 | + $serveur = '', |
|
| 877 | + $requeter = true |
|
| 878 | 878 | ) { |
| 879 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 880 | - $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 881 | - if (!$requeter) { |
|
| 882 | - return $r; |
|
| 883 | - } |
|
| 884 | - if (!is_resource($r)) { |
|
| 885 | - return 0; |
|
| 886 | - } |
|
| 887 | - [$c] = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 888 | - |
|
| 889 | - return $c; |
|
| 879 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 880 | + $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 881 | + if (!$requeter) { |
|
| 882 | + return $r; |
|
| 883 | + } |
|
| 884 | + if (!is_resource($r)) { |
|
| 885 | + return 0; |
|
| 886 | + } |
|
| 887 | + [$c] = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 888 | + |
|
| 889 | + return $c; |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | function spip_pg_count($res, $serveur = '', $requeter = true) { |
| 893 | - return !$res ? 0 : pg_numrows($res); |
|
| 893 | + return !$res ? 0 : pg_numrows($res); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | function spip_pg_free($res, $serveur = '', $requeter = true) { |
| 897 | - // rien a faire en postgres |
|
| 897 | + // rien a faire en postgres |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | function spip_pg_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 901 | 901 | |
| 902 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 903 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 902 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 903 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 904 | 904 | |
| 905 | - $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 906 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 905 | + $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 906 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 907 | 907 | |
| 908 | - // renvoyer la requete inerte si demandee |
|
| 909 | - if (!$requeter) { |
|
| 910 | - return $query; |
|
| 911 | - } |
|
| 908 | + // renvoyer la requete inerte si demandee |
|
| 909 | + if (!$requeter) { |
|
| 910 | + return $query; |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | - $res = spip_pg_trace_query($query, $serveur); |
|
| 914 | - if ($res) { |
|
| 915 | - return pg_affected_rows($res); |
|
| 916 | - } else { |
|
| 917 | - return false; |
|
| 918 | - } |
|
| 913 | + $res = spip_pg_trace_query($query, $serveur); |
|
| 914 | + if ($res) { |
|
| 915 | + return pg_affected_rows($res); |
|
| 916 | + } else { |
|
| 917 | + return false; |
|
| 918 | + } |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | function spip_pg_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 922 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 923 | - $prefixe = $connexion['prefixe']; |
|
| 924 | - $link = $connexion['link']; |
|
| 925 | - |
|
| 926 | - if (!$desc) { |
|
| 927 | - $desc = description_table($table, $serveur); |
|
| 928 | - } |
|
| 929 | - $seq = spip_pg_sequence($table, true); |
|
| 930 | - // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 931 | - if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 932 | - $seq = spip_pg_sequence($table); |
|
| 933 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 934 | - $seq = "currval('$seq')"; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 938 | - $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 939 | - $ins = (strlen($champs) < 3) |
|
| 940 | - ? ' DEFAULT VALUES' |
|
| 941 | - : "$champs VALUES $valeurs"; |
|
| 942 | - $q = "INSERT INTO $table $ins $ret"; |
|
| 943 | - if (!$requeter) { |
|
| 944 | - return $q; |
|
| 945 | - } |
|
| 946 | - $connexion['last'] = $q; |
|
| 947 | - $r = spip_pg_query_simple($link, $q); |
|
| 922 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 923 | + $prefixe = $connexion['prefixe']; |
|
| 924 | + $link = $connexion['link']; |
|
| 925 | + |
|
| 926 | + if (!$desc) { |
|
| 927 | + $desc = description_table($table, $serveur); |
|
| 928 | + } |
|
| 929 | + $seq = spip_pg_sequence($table, true); |
|
| 930 | + // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 931 | + if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 932 | + $seq = spip_pg_sequence($table); |
|
| 933 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 934 | + $seq = "currval('$seq')"; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 938 | + $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 939 | + $ins = (strlen($champs) < 3) |
|
| 940 | + ? ' DEFAULT VALUES' |
|
| 941 | + : "$champs VALUES $valeurs"; |
|
| 942 | + $q = "INSERT INTO $table $ins $ret"; |
|
| 943 | + if (!$requeter) { |
|
| 944 | + return $q; |
|
| 945 | + } |
|
| 946 | + $connexion['last'] = $q; |
|
| 947 | + $r = spip_pg_query_simple($link, $q); |
|
| 948 | 948 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 949 | - if ($r) { |
|
| 950 | - if (!$ret) { |
|
| 951 | - return 0; |
|
| 952 | - } |
|
| 953 | - if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 954 | - return $r2[0]; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - return false; |
|
| 949 | + if ($r) { |
|
| 950 | + if (!$ret) { |
|
| 951 | + return 0; |
|
| 952 | + } |
|
| 953 | + if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 954 | + return $r2[0]; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + return false; |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | function spip_pg_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 962 | 962 | |
| 963 | - if (!$desc) { |
|
| 964 | - $desc = description_table($table, $serveur); |
|
| 965 | - } |
|
| 966 | - if (!$desc) { |
|
| 967 | - die("$table insertion sans description"); |
|
| 968 | - } |
|
| 969 | - $fields = $desc['field']; |
|
| 970 | - |
|
| 971 | - foreach ($couples as $champ => $val) { |
|
| 972 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 976 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 977 | - |
|
| 978 | - return spip_pg_insert( |
|
| 979 | - $table, |
|
| 980 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 981 | - '(' . join(',', $couples) . ')', |
|
| 982 | - $desc, |
|
| 983 | - $serveur, |
|
| 984 | - $requeter |
|
| 985 | - ); |
|
| 963 | + if (!$desc) { |
|
| 964 | + $desc = description_table($table, $serveur); |
|
| 965 | + } |
|
| 966 | + if (!$desc) { |
|
| 967 | + die("$table insertion sans description"); |
|
| 968 | + } |
|
| 969 | + $fields = $desc['field']; |
|
| 970 | + |
|
| 971 | + foreach ($couples as $champ => $val) { |
|
| 972 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 976 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 977 | + |
|
| 978 | + return spip_pg_insert( |
|
| 979 | + $table, |
|
| 980 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 981 | + '(' . join(',', $couples) . ')', |
|
| 982 | + $desc, |
|
| 983 | + $serveur, |
|
| 984 | + $requeter |
|
| 985 | + ); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | |
| 989 | 989 | function spip_pg_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 990 | 990 | |
| 991 | - if (!$desc) { |
|
| 992 | - $desc = description_table($table, $serveur); |
|
| 993 | - } |
|
| 994 | - if (!$desc) { |
|
| 995 | - die("$table insertion sans description"); |
|
| 996 | - } |
|
| 997 | - $fields = $desc['field'] ?? []; |
|
| 998 | - |
|
| 999 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1000 | - // une premiere fois pour ajouter maj dans les cles |
|
| 1001 | - $c = $tab_couples[0] ?? []; |
|
| 1002 | - $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 1003 | - |
|
| 1004 | - $cles = '(' . join(',', array_keys($les_cles)) . ')'; |
|
| 1005 | - $valeurs = []; |
|
| 1006 | - foreach ($tab_couples as $couples) { |
|
| 1007 | - foreach ($couples as $champ => $val) { |
|
| 1008 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 1009 | - } |
|
| 1010 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1011 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1012 | - |
|
| 1013 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1014 | - } |
|
| 1015 | - $valeurs = implode(', ', $valeurs); |
|
| 1016 | - |
|
| 1017 | - return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 991 | + if (!$desc) { |
|
| 992 | + $desc = description_table($table, $serveur); |
|
| 993 | + } |
|
| 994 | + if (!$desc) { |
|
| 995 | + die("$table insertion sans description"); |
|
| 996 | + } |
|
| 997 | + $fields = $desc['field'] ?? []; |
|
| 998 | + |
|
| 999 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1000 | + // une premiere fois pour ajouter maj dans les cles |
|
| 1001 | + $c = $tab_couples[0] ?? []; |
|
| 1002 | + $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 1003 | + |
|
| 1004 | + $cles = '(' . join(',', array_keys($les_cles)) . ')'; |
|
| 1005 | + $valeurs = []; |
|
| 1006 | + foreach ($tab_couples as $couples) { |
|
| 1007 | + foreach ($couples as $champ => $val) { |
|
| 1008 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 1009 | + } |
|
| 1010 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1011 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1012 | + |
|
| 1013 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1014 | + } |
|
| 1015 | + $valeurs = implode(', ', $valeurs); |
|
| 1016 | + |
|
| 1017 | + return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | |
| 1021 | 1021 | function spip_pg_update($table, $couples, $where = '', $desc = '', $serveur = '', $requeter = true) { |
| 1022 | 1022 | |
| 1023 | - if (!$couples) { |
|
| 1024 | - return; |
|
| 1025 | - } |
|
| 1026 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1027 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1023 | + if (!$couples) { |
|
| 1024 | + return; |
|
| 1025 | + } |
|
| 1026 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1027 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1028 | 1028 | |
| 1029 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1030 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1029 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1030 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1031 | 1031 | |
| 1032 | - $set = []; |
|
| 1033 | - foreach ($couples as $champ => $val) { |
|
| 1034 | - $set[] = $champ . '=' . $val; |
|
| 1035 | - } |
|
| 1032 | + $set = []; |
|
| 1033 | + foreach ($couples as $champ => $val) { |
|
| 1034 | + $set[] = $champ . '=' . $val; |
|
| 1035 | + } |
|
| 1036 | 1036 | |
| 1037 | - $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1038 | - . calculer_pg_expression('SET', $set, ',') |
|
| 1039 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1037 | + $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1038 | + . calculer_pg_expression('SET', $set, ',') |
|
| 1039 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1040 | 1040 | |
| 1041 | - // renvoyer la requete inerte si demandee |
|
| 1042 | - if (!$requeter) { |
|
| 1043 | - return $query; |
|
| 1044 | - } |
|
| 1041 | + // renvoyer la requete inerte si demandee |
|
| 1042 | + if (!$requeter) { |
|
| 1043 | + return $query; |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - return spip_pg_trace_query($query, $serveur); |
|
| 1046 | + return spip_pg_trace_query($query, $serveur); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 1050 | 1050 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 1051 | 1051 | function spip_pg_updateq($table, $couples, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1052 | - if (!$couples) { |
|
| 1053 | - return; |
|
| 1054 | - } |
|
| 1055 | - if (!$desc) { |
|
| 1056 | - $desc = description_table($table, $serveur); |
|
| 1057 | - } |
|
| 1058 | - $fields = $desc['field']; |
|
| 1059 | - foreach ($couples as $k => $val) { |
|
| 1060 | - $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1052 | + if (!$couples) { |
|
| 1053 | + return; |
|
| 1054 | + } |
|
| 1055 | + if (!$desc) { |
|
| 1056 | + $desc = description_table($table, $serveur); |
|
| 1057 | + } |
|
| 1058 | + $fields = $desc['field']; |
|
| 1059 | + foreach ($couples as $k => $val) { |
|
| 1060 | + $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | |
| 1067 | 1067 | function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
| 1068 | - if (!$values) { |
|
| 1069 | - spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1070 | - |
|
| 1071 | - return 0; |
|
| 1072 | - } |
|
| 1073 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1074 | - $prefixe = $connexion['prefixe']; |
|
| 1075 | - $link = $connexion['link']; |
|
| 1076 | - |
|
| 1077 | - if (!$desc) { |
|
| 1078 | - $desc = description_table($table, $serveur); |
|
| 1079 | - } |
|
| 1080 | - if (!$desc) { |
|
| 1081 | - die("$table insertion sans description"); |
|
| 1082 | - } |
|
| 1083 | - $prim = $desc['key']['PRIMARY KEY']; |
|
| 1084 | - $ids = preg_split('/,\s*/', $prim); |
|
| 1085 | - $noprims = $prims = []; |
|
| 1086 | - foreach ($values as $k => $v) { |
|
| 1087 | - $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1088 | - |
|
| 1089 | - if (!in_array($k, $ids)) { |
|
| 1090 | - $noprims[$k] = "$k=$v"; |
|
| 1091 | - } else { |
|
| 1092 | - $prims[$k] = "$k=$v"; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1097 | - $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1098 | - |
|
| 1099 | - $where = join(' AND ', $prims); |
|
| 1100 | - if (!$where) { |
|
| 1101 | - return spip_pg_insert( |
|
| 1102 | - $table, |
|
| 1103 | - '(' . join(',', array_keys($values)) . ')', |
|
| 1104 | - '(' . join(',', $values) . ')', |
|
| 1105 | - $desc, |
|
| 1106 | - $serveur |
|
| 1107 | - ); |
|
| 1108 | - } |
|
| 1109 | - $couples = join(',', $noprims); |
|
| 1110 | - |
|
| 1111 | - $seq = spip_pg_sequence($table); |
|
| 1112 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 1113 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1114 | - |
|
| 1115 | - $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1116 | - if ($couples) { |
|
| 1117 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1068 | + if (!$values) { |
|
| 1069 | + spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1070 | + |
|
| 1071 | + return 0; |
|
| 1072 | + } |
|
| 1073 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1074 | + $prefixe = $connexion['prefixe']; |
|
| 1075 | + $link = $connexion['link']; |
|
| 1076 | + |
|
| 1077 | + if (!$desc) { |
|
| 1078 | + $desc = description_table($table, $serveur); |
|
| 1079 | + } |
|
| 1080 | + if (!$desc) { |
|
| 1081 | + die("$table insertion sans description"); |
|
| 1082 | + } |
|
| 1083 | + $prim = $desc['key']['PRIMARY KEY']; |
|
| 1084 | + $ids = preg_split('/,\s*/', $prim); |
|
| 1085 | + $noprims = $prims = []; |
|
| 1086 | + foreach ($values as $k => $v) { |
|
| 1087 | + $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1088 | + |
|
| 1089 | + if (!in_array($k, $ids)) { |
|
| 1090 | + $noprims[$k] = "$k=$v"; |
|
| 1091 | + } else { |
|
| 1092 | + $prims[$k] = "$k=$v"; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1097 | + $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1098 | + |
|
| 1099 | + $where = join(' AND ', $prims); |
|
| 1100 | + if (!$where) { |
|
| 1101 | + return spip_pg_insert( |
|
| 1102 | + $table, |
|
| 1103 | + '(' . join(',', array_keys($values)) . ')', |
|
| 1104 | + '(' . join(',', $values) . ')', |
|
| 1105 | + $desc, |
|
| 1106 | + $serveur |
|
| 1107 | + ); |
|
| 1108 | + } |
|
| 1109 | + $couples = join(',', $noprims); |
|
| 1110 | + |
|
| 1111 | + $seq = spip_pg_sequence($table); |
|
| 1112 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 1113 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1114 | + |
|
| 1115 | + $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1116 | + if ($couples) { |
|
| 1117 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1118 | 1118 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 1119 | - if (!$couples) { |
|
| 1120 | - return false; |
|
| 1121 | - } |
|
| 1122 | - $couples = pg_affected_rows($couples); |
|
| 1123 | - } |
|
| 1124 | - if (!$couples) { |
|
| 1125 | - $ret = !$seq ? '' : |
|
| 1126 | - (" RETURNING nextval('$seq') < $prim"); |
|
| 1127 | - $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join( |
|
| 1128 | - ',', |
|
| 1129 | - $values |
|
| 1130 | - ) . ")$ret"; |
|
| 1131 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1132 | - if (!$couples) { |
|
| 1133 | - return false; |
|
| 1134 | - } elseif ($ret) { |
|
| 1135 | - $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1136 | - if ($r[0]) { |
|
| 1137 | - $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1138 | - // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1139 | - // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1140 | - $r = @pg_query($link, $q); |
|
| 1141 | - } |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - return $couples; |
|
| 1119 | + if (!$couples) { |
|
| 1120 | + return false; |
|
| 1121 | + } |
|
| 1122 | + $couples = pg_affected_rows($couples); |
|
| 1123 | + } |
|
| 1124 | + if (!$couples) { |
|
| 1125 | + $ret = !$seq ? '' : |
|
| 1126 | + (" RETURNING nextval('$seq') < $prim"); |
|
| 1127 | + $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join( |
|
| 1128 | + ',', |
|
| 1129 | + $values |
|
| 1130 | + ) . ")$ret"; |
|
| 1131 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1132 | + if (!$couples) { |
|
| 1133 | + return false; |
|
| 1134 | + } elseif ($ret) { |
|
| 1135 | + $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1136 | + if ($r[0]) { |
|
| 1137 | + $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1138 | + // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1139 | + // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1140 | + $r = @pg_query($link, $q); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + return $couples; |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | |
| 1149 | 1149 | function spip_pg_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1150 | - $retour = null; |
|
| 1151 | - // boucler pour traiter chaque requete independemment |
|
| 1152 | - foreach ($tab_couples as $couples) { |
|
| 1153 | - $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - // renvoie le dernier id |
|
| 1157 | - return $retour; |
|
| 1150 | + $retour = null; |
|
| 1151 | + // boucler pour traiter chaque requete independemment |
|
| 1152 | + foreach ($tab_couples as $couples) { |
|
| 1153 | + $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + // renvoie le dernier id |
|
| 1157 | + return $retour; |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | |
@@ -1163,149 +1163,149 @@ discard block |
||
| 1163 | 1163 | |
| 1164 | 1164 | function spip_pg_sequence($table, $raw = false) { |
| 1165 | 1165 | |
| 1166 | - include_spip('base/serial'); |
|
| 1167 | - if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1168 | - return false; |
|
| 1169 | - } |
|
| 1170 | - $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1171 | - $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1172 | - if ( |
|
| 1173 | - !preg_match('/^\w+$/', $prim) |
|
| 1174 | - or !str_contains($desc['field'][$prim], 'int') |
|
| 1175 | - ) { |
|
| 1176 | - return ''; |
|
| 1177 | - } else { |
|
| 1178 | - return $raw ? $prim : $table . '_' . $prim . '_seq'; |
|
| 1179 | - } |
|
| 1166 | + include_spip('base/serial'); |
|
| 1167 | + if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1168 | + return false; |
|
| 1169 | + } |
|
| 1170 | + $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1171 | + $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1172 | + if ( |
|
| 1173 | + !preg_match('/^\w+$/', $prim) |
|
| 1174 | + or !str_contains($desc['field'][$prim], 'int') |
|
| 1175 | + ) { |
|
| 1176 | + return ''; |
|
| 1177 | + } else { |
|
| 1178 | + return $raw ? $prim : $table . '_' . $prim . '_seq'; |
|
| 1179 | + } |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
| 1183 | 1183 | // Dans le cas d'un champ date, pas d'apostrophe, c'est une syntaxe ad hoc |
| 1184 | 1184 | |
| 1185 | 1185 | function spip_pg_cite($v, $t) { |
| 1186 | - if (is_null($v)) { |
|
| 1187 | - return 'NULL'; |
|
| 1188 | - } // null php se traduit en NULL SQL |
|
| 1189 | - |
|
| 1190 | - if (sql_test_date($t)) { |
|
| 1191 | - if ($v and (strpos('0123456789', (string) $v[0]) === false)) { |
|
| 1192 | - return spip_pg_frommysql($v); |
|
| 1193 | - } else { |
|
| 1194 | - if (strncmp($v, '0000', 4) == 0) { |
|
| 1195 | - $v = '0001' . substr($v, 4); |
|
| 1196 | - } |
|
| 1197 | - if (strpos($v, '-00-00') === 4) { |
|
| 1198 | - $v = substr($v, 0, 4) . '-01-01' . substr($v, 10); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - return "timestamp '$v'"; |
|
| 1202 | - } |
|
| 1203 | - } elseif (!sql_test_int($t)) { |
|
| 1204 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1205 | - } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) { |
|
| 1206 | - return $v; |
|
| 1207 | - } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { |
|
| 1208 | - return substr($v, 1); |
|
| 1209 | - } else { |
|
| 1210 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1211 | - |
|
| 1212 | - return intval($v); |
|
| 1213 | - } |
|
| 1186 | + if (is_null($v)) { |
|
| 1187 | + return 'NULL'; |
|
| 1188 | + } // null php se traduit en NULL SQL |
|
| 1189 | + |
|
| 1190 | + if (sql_test_date($t)) { |
|
| 1191 | + if ($v and (strpos('0123456789', (string) $v[0]) === false)) { |
|
| 1192 | + return spip_pg_frommysql($v); |
|
| 1193 | + } else { |
|
| 1194 | + if (strncmp($v, '0000', 4) == 0) { |
|
| 1195 | + $v = '0001' . substr($v, 4); |
|
| 1196 | + } |
|
| 1197 | + if (strpos($v, '-00-00') === 4) { |
|
| 1198 | + $v = substr($v, 0, 4) . '-01-01' . substr($v, 10); |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + return "timestamp '$v'"; |
|
| 1202 | + } |
|
| 1203 | + } elseif (!sql_test_int($t)) { |
|
| 1204 | + return ("'" . pg_escape_string($v) . "'"); |
|
| 1205 | + } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) { |
|
| 1206 | + return $v; |
|
| 1207 | + } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { |
|
| 1208 | + return substr($v, 1); |
|
| 1209 | + } else { |
|
| 1210 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1211 | + |
|
| 1212 | + return intval($v); |
|
| 1213 | + } |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | function spip_pg_hex($v) { |
| 1217 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1217 | + return "CAST(x'" . $v . "' as bigint)"; |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | function spip_pg_quote($v, $type = '') { |
| 1221 | - if (!is_array($v)) { |
|
| 1222 | - return spip_pg_cite($v, $type); |
|
| 1223 | - } |
|
| 1224 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1225 | - foreach ($v as $k => $r) { |
|
| 1226 | - $v[$k] = spip_pg_quote($r, $type); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - return join(',', $v); |
|
| 1221 | + if (!is_array($v)) { |
|
| 1222 | + return spip_pg_cite($v, $type); |
|
| 1223 | + } |
|
| 1224 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1225 | + foreach ($v as $k => $r) { |
|
| 1226 | + $v[$k] = spip_pg_quote($r, $type); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + return join(',', $v); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | function spip_pg_date_proche($champ, $interval, $unite) { |
| 1233 | - return '(' |
|
| 1234 | - . $champ |
|
| 1235 | - . (($interval <= 0) ? '>' : '<') |
|
| 1236 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1237 | - . '(' |
|
| 1238 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1239 | - . ', INTERVAL ' |
|
| 1240 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1241 | - . ' ' |
|
| 1242 | - . $unite |
|
| 1243 | - . '))'; |
|
| 1233 | + return '(' |
|
| 1234 | + . $champ |
|
| 1235 | + . (($interval <= 0) ? '>' : '<') |
|
| 1236 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1237 | + . '(' |
|
| 1238 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1239 | + . ', INTERVAL ' |
|
| 1240 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1241 | + . ' ' |
|
| 1242 | + . $unite |
|
| 1243 | + . '))'; |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | function spip_pg_in($val, $valeurs, $not = '', $serveur = '') { |
| 1247 | 1247 | // |
| 1248 | 1248 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1249 | 1249 | // |
| 1250 | - // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1251 | - if (!$valeurs) { |
|
| 1252 | - return $not ? '0=0' : '0=1'; |
|
| 1253 | - } |
|
| 1254 | - if (strpos($valeurs, "CAST(x'") !== false) { |
|
| 1255 | - return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1256 | - } |
|
| 1257 | - $n = $i = 0; |
|
| 1258 | - $in_sql = ''; |
|
| 1259 | - while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1260 | - if ((++$i) >= 255) { |
|
| 1261 | - $in_sql .= "($val $not IN (" . |
|
| 1262 | - substr($valeurs, 0, $n) . |
|
| 1263 | - "))\n" . |
|
| 1264 | - ($not ? "AND\t" : "OR\t"); |
|
| 1265 | - $valeurs = substr($valeurs, $n + 1); |
|
| 1266 | - $i = $n = 0; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1270 | - |
|
| 1271 | - return "($in_sql)"; |
|
| 1250 | + // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1251 | + if (!$valeurs) { |
|
| 1252 | + return $not ? '0=0' : '0=1'; |
|
| 1253 | + } |
|
| 1254 | + if (strpos($valeurs, "CAST(x'") !== false) { |
|
| 1255 | + return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1256 | + } |
|
| 1257 | + $n = $i = 0; |
|
| 1258 | + $in_sql = ''; |
|
| 1259 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1260 | + if ((++$i) >= 255) { |
|
| 1261 | + $in_sql .= "($val $not IN (" . |
|
| 1262 | + substr($valeurs, 0, $n) . |
|
| 1263 | + "))\n" . |
|
| 1264 | + ($not ? "AND\t" : "OR\t"); |
|
| 1265 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1266 | + $i = $n = 0; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1270 | + |
|
| 1271 | + return "($in_sql)"; |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | function spip_pg_error($query = '', $serveur = '', $requeter = true) { |
| 1275 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1276 | - $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1277 | - if ($s) { |
|
| 1278 | - $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1279 | - spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - return $s; |
|
| 1275 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1276 | + $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1277 | + if ($s) { |
|
| 1278 | + $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1279 | + spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + return $s; |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | function spip_pg_errno($serveur = '') { |
| 1286 | - // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1287 | - // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1288 | - return 0; |
|
| 1286 | + // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1287 | + // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1288 | + return 0; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | function spip_pg_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 1292 | - if ($exist) { |
|
| 1293 | - $exist = ' IF EXISTS'; |
|
| 1294 | - } |
|
| 1295 | - if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1296 | - return true; |
|
| 1297 | - } else { |
|
| 1298 | - return false; |
|
| 1299 | - } |
|
| 1292 | + if ($exist) { |
|
| 1293 | + $exist = ' IF EXISTS'; |
|
| 1294 | + } |
|
| 1295 | + if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1296 | + return true; |
|
| 1297 | + } else { |
|
| 1298 | + return false; |
|
| 1299 | + } |
|
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | 1302 | // supprime une vue |
| 1303 | 1303 | function spip_pg_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 1304 | - if ($exist) { |
|
| 1305 | - $exist = ' IF EXISTS'; |
|
| 1306 | - } |
|
| 1304 | + if ($exist) { |
|
| 1305 | + $exist = ' IF EXISTS'; |
|
| 1306 | + } |
|
| 1307 | 1307 | |
| 1308 | - return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1308 | + return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | /** |
@@ -1322,40 +1322,40 @@ discard block |
||
| 1322 | 1322 | * Ressource à utiliser avec sql_fetch() |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
| 1325 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1326 | - $link = $connexion['link']; |
|
| 1327 | - $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match); |
|
| 1325 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1326 | + $link = $connexion['link']; |
|
| 1327 | + $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match); |
|
| 1328 | 1328 | |
| 1329 | - return spip_pg_query_simple($link, $q); |
|
| 1329 | + return spip_pg_query_simple($link, $q); |
|
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1333 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1334 | - $link = $connexion['link']; |
|
| 1335 | - $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table); |
|
| 1336 | - |
|
| 1337 | - $res = spip_pg_query_simple($link, $q); |
|
| 1338 | - if (!$res) { |
|
| 1339 | - return false; |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1343 | - // il faut en tenir compte dans le return |
|
| 1344 | - $fields = []; |
|
| 1345 | - while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1346 | - $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (' DEFAULT ' . $field[1])); |
|
| 1347 | - } |
|
| 1348 | - $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table); |
|
| 1349 | - $res = spip_pg_query_simple($link, $q); |
|
| 1350 | - $keys = []; |
|
| 1351 | - while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1352 | - if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1353 | - $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1354 | - $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3]; |
|
| 1355 | - } |
|
| 1356 | - } |
|
| 1357 | - |
|
| 1358 | - return count($fields) ? ['field' => $fields, 'key' => $keys] : false; |
|
| 1333 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1334 | + $link = $connexion['link']; |
|
| 1335 | + $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table); |
|
| 1336 | + |
|
| 1337 | + $res = spip_pg_query_simple($link, $q); |
|
| 1338 | + if (!$res) { |
|
| 1339 | + return false; |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1343 | + // il faut en tenir compte dans le return |
|
| 1344 | + $fields = []; |
|
| 1345 | + while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1346 | + $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (' DEFAULT ' . $field[1])); |
|
| 1347 | + } |
|
| 1348 | + $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table); |
|
| 1349 | + $res = spip_pg_query_simple($link, $q); |
|
| 1350 | + $keys = []; |
|
| 1351 | + while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1352 | + if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1353 | + $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1354 | + $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3]; |
|
| 1355 | + } |
|
| 1356 | + } |
|
| 1357 | + |
|
| 1358 | + return count($fields) ? ['field' => $fields, 'key' => $keys] : false; |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | // Fonction de creation d'une table SQL nommee $nom |
@@ -1366,116 +1366,116 @@ discard block |
||
| 1366 | 1366 | // Le nom des index est prefixe par celui de la table pour eviter les conflits |
| 1367 | 1367 | function spip_pg_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) { |
| 1368 | 1368 | |
| 1369 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1370 | - $link = $connexion['link']; |
|
| 1371 | - $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1372 | - |
|
| 1373 | - $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1374 | - $keys = []; |
|
| 1375 | - |
|
| 1376 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1377 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1378 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 1379 | - return; |
|
| 1380 | - } |
|
| 1381 | - |
|
| 1382 | - foreach ($cles as $k => $v) { |
|
| 1383 | - if (strpos($k, 'KEY ') === 0) { |
|
| 1384 | - $n = str_replace('`', '', $k); |
|
| 1385 | - $v = str_replace('`', '"', $v); |
|
| 1386 | - $i = $nom . preg_replace('/KEY +/', '_', $n); |
|
| 1387 | - if ($k != $n) { |
|
| 1388 | - $i = "\"$i\""; |
|
| 1389 | - } |
|
| 1390 | - $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1391 | - } elseif (strpos($k, 'UNIQUE ') === 0) { |
|
| 1392 | - $k = preg_replace('/^UNIQUE +/', '', $k); |
|
| 1393 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1394 | - } else { |
|
| 1395 | - $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1396 | - } |
|
| 1397 | - if ($k == 'PRIMARY KEY') { |
|
| 1398 | - $prim_name = $v; |
|
| 1399 | - } |
|
| 1400 | - $s = ','; |
|
| 1401 | - } |
|
| 1402 | - $s = ''; |
|
| 1403 | - |
|
| 1404 | - $character_set = ''; |
|
| 1405 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1406 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 1407 | - } |
|
| 1408 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1409 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - foreach ($champs as $k => $v) { |
|
| 1413 | - $k = str_replace('`', '"', $k); |
|
| 1414 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 1415 | - if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) { |
|
| 1416 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - $query .= "$s\n\t\t$k " |
|
| 1421 | - . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1422 | - ? ' bigserial' |
|
| 1423 | - : mysql2pg_type($v) |
|
| 1424 | - ); |
|
| 1425 | - $s = ','; |
|
| 1426 | - } |
|
| 1427 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1428 | - |
|
| 1429 | - // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1430 | - |
|
| 1431 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' . |
|
| 1432 | - ($character_set ? " DEFAULT $character_set" : '') |
|
| 1433 | - . "\n"; |
|
| 1434 | - |
|
| 1435 | - if (!$requeter) { |
|
| 1436 | - return $q; |
|
| 1437 | - } |
|
| 1438 | - $connexion['last'] = $q; |
|
| 1439 | - $r = @pg_query($link, $q); |
|
| 1440 | - |
|
| 1441 | - if (!$r) { |
|
| 1442 | - spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1443 | - } else { |
|
| 1444 | - foreach ($keys as $index) { |
|
| 1445 | - pg_query($link, $index); |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - |
|
| 1449 | - return $r; |
|
| 1369 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1370 | + $link = $connexion['link']; |
|
| 1371 | + $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1372 | + |
|
| 1373 | + $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1374 | + $keys = []; |
|
| 1375 | + |
|
| 1376 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1377 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1378 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 1379 | + return; |
|
| 1380 | + } |
|
| 1381 | + |
|
| 1382 | + foreach ($cles as $k => $v) { |
|
| 1383 | + if (strpos($k, 'KEY ') === 0) { |
|
| 1384 | + $n = str_replace('`', '', $k); |
|
| 1385 | + $v = str_replace('`', '"', $v); |
|
| 1386 | + $i = $nom . preg_replace('/KEY +/', '_', $n); |
|
| 1387 | + if ($k != $n) { |
|
| 1388 | + $i = "\"$i\""; |
|
| 1389 | + } |
|
| 1390 | + $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1391 | + } elseif (strpos($k, 'UNIQUE ') === 0) { |
|
| 1392 | + $k = preg_replace('/^UNIQUE +/', '', $k); |
|
| 1393 | + $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1394 | + } else { |
|
| 1395 | + $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1396 | + } |
|
| 1397 | + if ($k == 'PRIMARY KEY') { |
|
| 1398 | + $prim_name = $v; |
|
| 1399 | + } |
|
| 1400 | + $s = ','; |
|
| 1401 | + } |
|
| 1402 | + $s = ''; |
|
| 1403 | + |
|
| 1404 | + $character_set = ''; |
|
| 1405 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1406 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 1407 | + } |
|
| 1408 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1409 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + foreach ($champs as $k => $v) { |
|
| 1413 | + $k = str_replace('`', '"', $k); |
|
| 1414 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 1415 | + if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) { |
|
| 1416 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + $query .= "$s\n\t\t$k " |
|
| 1421 | + . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1422 | + ? ' bigserial' |
|
| 1423 | + : mysql2pg_type($v) |
|
| 1424 | + ); |
|
| 1425 | + $s = ','; |
|
| 1426 | + } |
|
| 1427 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1428 | + |
|
| 1429 | + // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1430 | + |
|
| 1431 | + $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' . |
|
| 1432 | + ($character_set ? " DEFAULT $character_set" : '') |
|
| 1433 | + . "\n"; |
|
| 1434 | + |
|
| 1435 | + if (!$requeter) { |
|
| 1436 | + return $q; |
|
| 1437 | + } |
|
| 1438 | + $connexion['last'] = $q; |
|
| 1439 | + $r = @pg_query($link, $q); |
|
| 1440 | + |
|
| 1441 | + if (!$r) { |
|
| 1442 | + spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1443 | + } else { |
|
| 1444 | + foreach ($keys as $index) { |
|
| 1445 | + pg_query($link, $index); |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + |
|
| 1449 | + return $r; |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | |
| 1453 | 1453 | function spip_pg_create_base($nom, $serveur = '', $requeter = true) { |
| 1454 | - return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1454 | + return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | // Fonction de creation d'une vue SQL nommee $nom |
| 1458 | 1458 | function spip_pg_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 1459 | - if (!$query_select) { |
|
| 1460 | - return false; |
|
| 1461 | - } |
|
| 1462 | - // vue deja presente |
|
| 1463 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 1464 | - if ($requeter) { |
|
| 1465 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1466 | - } |
|
| 1459 | + if (!$query_select) { |
|
| 1460 | + return false; |
|
| 1461 | + } |
|
| 1462 | + // vue deja presente |
|
| 1463 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 1464 | + if ($requeter) { |
|
| 1465 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1466 | + } |
|
| 1467 | 1467 | |
| 1468 | - return false; |
|
| 1469 | - } |
|
| 1468 | + return false; |
|
| 1469 | + } |
|
| 1470 | 1470 | |
| 1471 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1471 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1472 | 1472 | |
| 1473 | - return spip_pg_query($query, $serveur, $requeter); |
|
| 1473 | + return spip_pg_query($query, $serveur, $requeter); |
|
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | |
| 1477 | 1477 | function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
| 1478 | - spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR); |
|
| 1478 | + spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | |
@@ -1488,50 +1488,50 @@ discard block |
||
| 1488 | 1488 | * @return bool|string true / false / requete |
| 1489 | 1489 | **/ |
| 1490 | 1490 | function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
| 1491 | - return spip_pg_query('VACUUM ' . $table, $serveur, $requeter); |
|
| 1491 | + return spip_pg_query('VACUUM ' . $table, $serveur, $requeter); |
|
| 1492 | 1492 | } |
| 1493 | 1493 | |
| 1494 | 1494 | // Selectionner la sous-chaine dans $objet |
| 1495 | 1495 | // correspondant a $lang. Cf balise Multi de Spip |
| 1496 | 1496 | |
| 1497 | 1497 | function spip_pg_multi($objet, $lang) { |
| 1498 | - $r = 'regexp_replace(' |
|
| 1499 | - . $objet |
|
| 1500 | - . ",'<multi>.*[[]" |
|
| 1501 | - . $lang |
|
| 1502 | - . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1498 | + $r = 'regexp_replace(' |
|
| 1499 | + . $objet |
|
| 1500 | + . ",'<multi>.*[[]" |
|
| 1501 | + . $lang |
|
| 1502 | + . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1503 | 1503 | |
| 1504 | - return $r; |
|
| 1504 | + return $r; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | 1507 | // Palanquee d'idiosyncrasies MySQL dans les creations de table |
| 1508 | 1508 | // A completer par les autres, mais essayer de reduire en amont. |
| 1509 | 1509 | |
| 1510 | 1510 | function mysql2pg_type($v) { |
| 1511 | - $remplace = [ |
|
| 1512 | - '/auto_increment/i' => '', // non reconnu |
|
| 1513 | - '/bigint/i' => 'bigint', |
|
| 1514 | - '/mediumint/i' => 'mediumint', |
|
| 1515 | - '/smallint/i' => 'smallint', |
|
| 1516 | - '/tinyint/i' => 'int', |
|
| 1517 | - '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1518 | - '/longtext/i' => 'text', |
|
| 1519 | - '/mediumtext/i' => 'text', |
|
| 1520 | - '/tinytext/i' => 'text', |
|
| 1521 | - '/longblob/i' => 'text', |
|
| 1522 | - '/0000-00-00/' => '0001-01-01', |
|
| 1523 | - '/datetime/i' => 'timestamp', |
|
| 1524 | - '/unsigned/i' => '', |
|
| 1525 | - '/double/i' => 'double precision', |
|
| 1526 | - '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1527 | - '/ENUM *[(][^)]*[)]/i' => 'varchar(255)', |
|
| 1528 | - '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1529 | - ]; |
|
| 1530 | - |
|
| 1531 | - return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1511 | + $remplace = [ |
|
| 1512 | + '/auto_increment/i' => '', // non reconnu |
|
| 1513 | + '/bigint/i' => 'bigint', |
|
| 1514 | + '/mediumint/i' => 'mediumint', |
|
| 1515 | + '/smallint/i' => 'smallint', |
|
| 1516 | + '/tinyint/i' => 'int', |
|
| 1517 | + '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1518 | + '/longtext/i' => 'text', |
|
| 1519 | + '/mediumtext/i' => 'text', |
|
| 1520 | + '/tinytext/i' => 'text', |
|
| 1521 | + '/longblob/i' => 'text', |
|
| 1522 | + '/0000-00-00/' => '0001-01-01', |
|
| 1523 | + '/datetime/i' => 'timestamp', |
|
| 1524 | + '/unsigned/i' => '', |
|
| 1525 | + '/double/i' => 'double precision', |
|
| 1526 | + '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1527 | + '/ENUM *[(][^)]*[)]/i' => 'varchar(255)', |
|
| 1528 | + '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1529 | + ]; |
|
| 1530 | + |
|
| 1531 | + return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | // Renvoie false si on n'a pas les fonctions pg (pour l'install) |
| 1535 | 1535 | function spip_versions_pg() { |
| 1536 | - return function_exists('pg_connect'); |
|
| 1536 | + return function_exists('pg_connect'); |
|
| 1537 | 1537 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -55,65 +55,65 @@ discard block |
||
| 55 | 55 | * @return void |
| 56 | 56 | **/ |
| 57 | 57 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 58 | - $statuts_publies = null; |
|
| 59 | - $neuf = false; |
|
| 60 | - |
|
| 61 | - // Compat avec l'ancienne signature |
|
| 62 | - if (is_string($infos)) { |
|
| 63 | - $infos = ['statut_ancien' => $infos]; |
|
| 64 | - } |
|
| 65 | - if (!isset($infos['statut_ancien'])) { |
|
| 66 | - $infos['statut_ancien'] = ''; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // On recherche quels statuts tester |
|
| 70 | - if ( |
|
| 71 | - isset($infos['objet']) |
|
| 72 | - and include_spip('inc/filtres') |
|
| 73 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 74 | - and is_array($declaration_statut) |
|
| 75 | - ) { |
|
| 76 | - foreach ($declaration_statut as $champ_statut) { |
|
| 77 | - if ($champ_statut['champ'] == 'statut') { |
|
| 78 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 79 | - break; // stop on a trouvé le bon champ |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } else { |
|
| 83 | - $statuts_publies = ['publie']; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 87 | - if ( |
|
| 88 | - isset($modifs['statut']) |
|
| 89 | - or isset($modifs['id_rubrique']) |
|
| 90 | - or ($postdate and strtotime($postdate) > time()) |
|
| 91 | - ) { |
|
| 92 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 93 | - } |
|
| 94 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 95 | - if ($postdate) { |
|
| 96 | - calculer_prochain_postdate(true); |
|
| 97 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 98 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 99 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 100 | - } |
|
| 101 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 102 | - if ($postdate) { |
|
| 103 | - calculer_prochain_postdate(true); |
|
| 104 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 105 | - } else { |
|
| 106 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($neuf) { |
|
| 111 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 112 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $langues = calculer_langues_utilisees(); |
|
| 116 | - ecrire_meta('langues_utilisees', $langues); |
|
| 58 | + $statuts_publies = null; |
|
| 59 | + $neuf = false; |
|
| 60 | + |
|
| 61 | + // Compat avec l'ancienne signature |
|
| 62 | + if (is_string($infos)) { |
|
| 63 | + $infos = ['statut_ancien' => $infos]; |
|
| 64 | + } |
|
| 65 | + if (!isset($infos['statut_ancien'])) { |
|
| 66 | + $infos['statut_ancien'] = ''; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // On recherche quels statuts tester |
|
| 70 | + if ( |
|
| 71 | + isset($infos['objet']) |
|
| 72 | + and include_spip('inc/filtres') |
|
| 73 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 74 | + and is_array($declaration_statut) |
|
| 75 | + ) { |
|
| 76 | + foreach ($declaration_statut as $champ_statut) { |
|
| 77 | + if ($champ_statut['champ'] == 'statut') { |
|
| 78 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 79 | + break; // stop on a trouvé le bon champ |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } else { |
|
| 83 | + $statuts_publies = ['publie']; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 87 | + if ( |
|
| 88 | + isset($modifs['statut']) |
|
| 89 | + or isset($modifs['id_rubrique']) |
|
| 90 | + or ($postdate and strtotime($postdate) > time()) |
|
| 91 | + ) { |
|
| 92 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 93 | + } |
|
| 94 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 95 | + if ($postdate) { |
|
| 96 | + calculer_prochain_postdate(true); |
|
| 97 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 98 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 99 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 100 | + } |
|
| 101 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 102 | + if ($postdate) { |
|
| 103 | + calculer_prochain_postdate(true); |
|
| 104 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 105 | + } else { |
|
| 106 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($neuf) { |
|
| 111 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 112 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $langues = calculer_langues_utilisees(); |
|
| 116 | + ecrire_meta('langues_utilisees', $langues); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -131,22 +131,22 @@ discard block |
||
| 131 | 131 | * true si le statut change effectivement |
| 132 | 132 | */ |
| 133 | 133 | function publier_branche_rubrique($id_rubrique) { |
| 134 | - $id_pred = $id_rubrique; |
|
| 135 | - while (true) { |
|
| 136 | - sql_updateq( |
|
| 137 | - 'spip_rubriques', |
|
| 138 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 139 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 140 | - ); |
|
| 141 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 142 | - if (!$id_parent) { |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - $id_rubrique = $id_parent; |
|
| 146 | - } |
|
| 134 | + $id_pred = $id_rubrique; |
|
| 135 | + while (true) { |
|
| 136 | + sql_updateq( |
|
| 137 | + 'spip_rubriques', |
|
| 138 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 139 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 140 | + ); |
|
| 141 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 142 | + if (!$id_parent) { |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + $id_rubrique = $id_parent; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 149 | - return $id_pred != $id_rubrique; |
|
| 149 | + return $id_pred != $id_rubrique; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | * true si le statut change effectivement |
| 165 | 165 | */ |
| 166 | 166 | function depublier_branche_rubrique_if($id_rubrique) { |
| 167 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 168 | - |
|
| 169 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 170 | - $id_pred = $id_rubrique; |
|
| 171 | - while ($id_pred) { |
|
| 172 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 173 | - return $id_pred != $id_rubrique; |
|
| 174 | - } |
|
| 175 | - // passer au parent si on a depublie |
|
| 176 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 177 | - $id_pred = $r['id_parent']; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $id_pred != $id_rubrique; |
|
| 167 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 168 | + |
|
| 169 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 170 | + $id_pred = $id_rubrique; |
|
| 171 | + while ($id_pred) { |
|
| 172 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 173 | + return $id_pred != $id_rubrique; |
|
| 174 | + } |
|
| 175 | + // passer au parent si on a depublie |
|
| 176 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 177 | + $id_pred = $r['id_parent']; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $id_pred != $id_rubrique; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -194,61 +194,61 @@ discard block |
||
| 194 | 194 | * true si la rubrique a été dépubliée |
| 195 | 195 | */ |
| 196 | 196 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 197 | - if (is_null($date)) { |
|
| 198 | - $date = date('Y-m-d H:i:s'); |
|
| 199 | - } |
|
| 200 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 201 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 202 | - |
|
| 203 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // verifier qu'elle existe et est bien publiee |
|
| 208 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 209 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 210 | - return false; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 214 | - // Le type de l'objet est au pluriel |
|
| 215 | - $compte = [ |
|
| 216 | - 'articles' => sql_countsel( |
|
| 217 | - 'spip_articles', |
|
| 218 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 219 | - ), |
|
| 220 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 221 | - 'documents' => sql_countsel( |
|
| 222 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 223 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 224 | - ) |
|
| 225 | - ]; |
|
| 226 | - |
|
| 227 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 228 | - $compte = pipeline( |
|
| 229 | - 'objet_compte_enfants', |
|
| 230 | - [ |
|
| 231 | - 'args' => [ |
|
| 232 | - 'objet' => 'rubrique', |
|
| 233 | - 'id_objet' => $id_rubrique, |
|
| 234 | - 'statut' => 'publie', |
|
| 235 | - 'date' => $date |
|
| 236 | - ], |
|
| 237 | - 'data' => $compte |
|
| 238 | - ] |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 242 | - foreach ($compte as $objet => $n) { |
|
| 243 | - if ($n) { |
|
| 244 | - return false; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 197 | + if (is_null($date)) { |
|
| 198 | + $date = date('Y-m-d H:i:s'); |
|
| 199 | + } |
|
| 200 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 201 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 202 | + |
|
| 203 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // verifier qu'elle existe et est bien publiee |
|
| 208 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 209 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 210 | + return false; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 214 | + // Le type de l'objet est au pluriel |
|
| 215 | + $compte = [ |
|
| 216 | + 'articles' => sql_countsel( |
|
| 217 | + 'spip_articles', |
|
| 218 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 219 | + ), |
|
| 220 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 221 | + 'documents' => sql_countsel( |
|
| 222 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 223 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 224 | + ) |
|
| 225 | + ]; |
|
| 226 | + |
|
| 227 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 228 | + $compte = pipeline( |
|
| 229 | + 'objet_compte_enfants', |
|
| 230 | + [ |
|
| 231 | + 'args' => [ |
|
| 232 | + 'objet' => 'rubrique', |
|
| 233 | + 'id_objet' => $id_rubrique, |
|
| 234 | + 'statut' => 'publie', |
|
| 235 | + 'date' => $date |
|
| 236 | + ], |
|
| 237 | + 'data' => $compte |
|
| 238 | + ] |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 242 | + foreach ($compte as $objet => $n) { |
|
| 243 | + if ($n) { |
|
| 244 | + return false; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 249 | 249 | |
| 250 | 250 | # spip_log("depublier_rubrique $id_pred"); |
| 251 | - return true; |
|
| 251 | + return true; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
@@ -271,18 +271,18 @@ discard block |
||
| 271 | 271 | **/ |
| 272 | 272 | function calculer_rubriques() { |
| 273 | 273 | |
| 274 | - calculer_rubriques_publiees(); |
|
| 274 | + calculer_rubriques_publiees(); |
|
| 275 | 275 | |
| 276 | - // Apres chaque (de)publication |
|
| 277 | - // recalculer les langues utilisees sur le site |
|
| 278 | - $langues = calculer_langues_utilisees(); |
|
| 279 | - ecrire_meta('langues_utilisees', $langues); |
|
| 276 | + // Apres chaque (de)publication |
|
| 277 | + // recalculer les langues utilisees sur le site |
|
| 278 | + $langues = calculer_langues_utilisees(); |
|
| 279 | + ecrire_meta('langues_utilisees', $langues); |
|
| 280 | 280 | |
| 281 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 282 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 281 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 282 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 283 | 283 | |
| 284 | - // on calcule la date du prochain article post-date |
|
| 285 | - calculer_prochain_postdate(); |
|
| 284 | + // on calcule la date du prochain article post-date |
|
| 285 | + calculer_prochain_postdate(); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | |
@@ -299,61 +299,61 @@ discard block |
||
| 299 | 299 | **/ |
| 300 | 300 | function calculer_rubriques_publiees() { |
| 301 | 301 | |
| 302 | - // Mettre les compteurs a zero |
|
| 303 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 304 | - |
|
| 305 | - // |
|
| 306 | - // Publier et dater les rubriques qui ont un article publie |
|
| 307 | - // |
|
| 308 | - |
|
| 309 | - // Afficher les articles post-dates ? |
|
| 310 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 311 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 312 | - |
|
| 313 | - $r = sql_select( |
|
| 314 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 315 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 316 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 317 | - 'R.id_rubrique' |
|
| 318 | - ); |
|
| 319 | - while ($row = sql_fetch($r)) { |
|
| 320 | - sql_updateq( |
|
| 321 | - 'spip_rubriques', |
|
| 322 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 323 | - 'id_rubrique=' . intval($row['id']) |
|
| 324 | - ); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 328 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 329 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 330 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 331 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 332 | - pipeline('calculer_rubriques', null); |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 336 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 337 | - do { |
|
| 338 | - $continuer = false; |
|
| 339 | - $r = sql_select( |
|
| 340 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 341 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 342 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 343 | - 'R.id_rubrique' |
|
| 344 | - ); |
|
| 345 | - while ($row = sql_fetch($r)) { |
|
| 346 | - sql_updateq( |
|
| 347 | - 'spip_rubriques', |
|
| 348 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 349 | - 'id_rubrique=' . intval($row['id']) |
|
| 350 | - ); |
|
| 351 | - $continuer = true; |
|
| 352 | - } |
|
| 353 | - } while ($continuer); |
|
| 354 | - |
|
| 355 | - // Enregistrement des modifs |
|
| 356 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 302 | + // Mettre les compteurs a zero |
|
| 303 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 304 | + |
|
| 305 | + // |
|
| 306 | + // Publier et dater les rubriques qui ont un article publie |
|
| 307 | + // |
|
| 308 | + |
|
| 309 | + // Afficher les articles post-dates ? |
|
| 310 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 311 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 312 | + |
|
| 313 | + $r = sql_select( |
|
| 314 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 315 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 316 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 317 | + 'R.id_rubrique' |
|
| 318 | + ); |
|
| 319 | + while ($row = sql_fetch($r)) { |
|
| 320 | + sql_updateq( |
|
| 321 | + 'spip_rubriques', |
|
| 322 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 323 | + 'id_rubrique=' . intval($row['id']) |
|
| 324 | + ); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 328 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 329 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 330 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 331 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 332 | + pipeline('calculer_rubriques', null); |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 336 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 337 | + do { |
|
| 338 | + $continuer = false; |
|
| 339 | + $r = sql_select( |
|
| 340 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 341 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 342 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 343 | + 'R.id_rubrique' |
|
| 344 | + ); |
|
| 345 | + while ($row = sql_fetch($r)) { |
|
| 346 | + sql_updateq( |
|
| 347 | + 'spip_rubriques', |
|
| 348 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 349 | + 'id_rubrique=' . intval($row['id']) |
|
| 350 | + ); |
|
| 351 | + $continuer = true; |
|
| 352 | + } |
|
| 353 | + } while ($continuer); |
|
| 354 | + |
|
| 355 | + // Enregistrement des modifs |
|
| 356 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -368,123 +368,123 @@ discard block |
||
| 368 | 368 | * @return void |
| 369 | 369 | **/ |
| 370 | 370 | function propager_les_secteurs() { |
| 371 | - // Profondeur 0 |
|
| 372 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 373 | - // et fixer les id_secteur des rubriques racines |
|
| 374 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 375 | - // Toute rubrique non racine est de profondeur >0 |
|
| 376 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 377 | - |
|
| 378 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 379 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 380 | - |
|
| 381 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 382 | - // on fait profondeur par profondeur |
|
| 383 | - |
|
| 384 | - $prof = 0; |
|
| 385 | - do { |
|
| 386 | - $continuer = false; |
|
| 387 | - |
|
| 388 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 389 | - // on fixe le profondeur $prof+1 |
|
| 390 | - |
|
| 391 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 392 | - // on teste A.profondeur > $prof+1 car : |
|
| 393 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 394 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 395 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 396 | - $maxiter2 = $maxiter; |
|
| 397 | - while ( |
|
| 398 | - $maxiter2-- |
|
| 399 | - and $rows = sql_allfetsel( |
|
| 400 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 401 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 402 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 403 | - '', |
|
| 404 | - 'R.id_secteur', |
|
| 405 | - '0,100' |
|
| 406 | - ) |
|
| 407 | - ) { |
|
| 408 | - $id_secteur = null; |
|
| 409 | - $ids = []; |
|
| 410 | - while ($row = array_shift($rows)) { |
|
| 411 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 412 | - if (count($ids)) { |
|
| 413 | - sql_updateq( |
|
| 414 | - 'spip_rubriques', |
|
| 415 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 416 | - sql_in('id_rubrique', $ids) |
|
| 417 | - ); |
|
| 418 | - } |
|
| 419 | - $id_secteur = $row['id_secteur']; |
|
| 420 | - $ids = []; |
|
| 421 | - } |
|
| 422 | - $ids[] = $row['id']; |
|
| 423 | - } |
|
| 424 | - if (count($ids)) { |
|
| 425 | - sql_updateq( |
|
| 426 | - 'spip_rubriques', |
|
| 427 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 428 | - sql_in('id_rubrique', $ids) |
|
| 429 | - ); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 435 | - $maxiter2 = $maxiter; |
|
| 436 | - while ( |
|
| 437 | - $maxiter2-- |
|
| 438 | - and $rows = sql_allfetsel( |
|
| 439 | - 'id_rubrique as id', |
|
| 440 | - 'spip_rubriques', |
|
| 441 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 442 | - 'zzz.id_rubrique', |
|
| 443 | - 'spip_rubriques AS zzz', |
|
| 444 | - 'zzz.profondeur=' . intval($prof) |
|
| 445 | - ) . ')', |
|
| 446 | - '', |
|
| 447 | - '', |
|
| 448 | - '0,100' |
|
| 449 | - ) |
|
| 450 | - ) { |
|
| 451 | - $rows = array_column($rows, 'id'); |
|
| 452 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 456 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 457 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 458 | - // on arrete les frais |
|
| 459 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 460 | - $prof++; |
|
| 461 | - $continuer = true; |
|
| 462 | - } |
|
| 463 | - } while ($continuer and $maxiter--); |
|
| 464 | - |
|
| 465 | - // loger si la table des rubriques semble foireuse |
|
| 466 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 467 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 468 | - spip_log( |
|
| 469 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 470 | - _LOG_CRITIQUE |
|
| 471 | - ); |
|
| 472 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // reparer les articles |
|
| 476 | - $r = sql_select( |
|
| 477 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 478 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 479 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 480 | - ); |
|
| 481 | - |
|
| 482 | - while ($row = sql_fetch($r)) { |
|
| 483 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 487 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 371 | + // Profondeur 0 |
|
| 372 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 373 | + // et fixer les id_secteur des rubriques racines |
|
| 374 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 375 | + // Toute rubrique non racine est de profondeur >0 |
|
| 376 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 377 | + |
|
| 378 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 379 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 380 | + |
|
| 381 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 382 | + // on fait profondeur par profondeur |
|
| 383 | + |
|
| 384 | + $prof = 0; |
|
| 385 | + do { |
|
| 386 | + $continuer = false; |
|
| 387 | + |
|
| 388 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 389 | + // on fixe le profondeur $prof+1 |
|
| 390 | + |
|
| 391 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 392 | + // on teste A.profondeur > $prof+1 car : |
|
| 393 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 394 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 395 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 396 | + $maxiter2 = $maxiter; |
|
| 397 | + while ( |
|
| 398 | + $maxiter2-- |
|
| 399 | + and $rows = sql_allfetsel( |
|
| 400 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 401 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 402 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 403 | + '', |
|
| 404 | + 'R.id_secteur', |
|
| 405 | + '0,100' |
|
| 406 | + ) |
|
| 407 | + ) { |
|
| 408 | + $id_secteur = null; |
|
| 409 | + $ids = []; |
|
| 410 | + while ($row = array_shift($rows)) { |
|
| 411 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 412 | + if (count($ids)) { |
|
| 413 | + sql_updateq( |
|
| 414 | + 'spip_rubriques', |
|
| 415 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 416 | + sql_in('id_rubrique', $ids) |
|
| 417 | + ); |
|
| 418 | + } |
|
| 419 | + $id_secteur = $row['id_secteur']; |
|
| 420 | + $ids = []; |
|
| 421 | + } |
|
| 422 | + $ids[] = $row['id']; |
|
| 423 | + } |
|
| 424 | + if (count($ids)) { |
|
| 425 | + sql_updateq( |
|
| 426 | + 'spip_rubriques', |
|
| 427 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 428 | + sql_in('id_rubrique', $ids) |
|
| 429 | + ); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 435 | + $maxiter2 = $maxiter; |
|
| 436 | + while ( |
|
| 437 | + $maxiter2-- |
|
| 438 | + and $rows = sql_allfetsel( |
|
| 439 | + 'id_rubrique as id', |
|
| 440 | + 'spip_rubriques', |
|
| 441 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 442 | + 'zzz.id_rubrique', |
|
| 443 | + 'spip_rubriques AS zzz', |
|
| 444 | + 'zzz.profondeur=' . intval($prof) |
|
| 445 | + ) . ')', |
|
| 446 | + '', |
|
| 447 | + '', |
|
| 448 | + '0,100' |
|
| 449 | + ) |
|
| 450 | + ) { |
|
| 451 | + $rows = array_column($rows, 'id'); |
|
| 452 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 456 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 457 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 458 | + // on arrete les frais |
|
| 459 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 460 | + $prof++; |
|
| 461 | + $continuer = true; |
|
| 462 | + } |
|
| 463 | + } while ($continuer and $maxiter--); |
|
| 464 | + |
|
| 465 | + // loger si la table des rubriques semble foireuse |
|
| 466 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 467 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 468 | + spip_log( |
|
| 469 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 470 | + _LOG_CRITIQUE |
|
| 471 | + ); |
|
| 472 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // reparer les articles |
|
| 476 | + $r = sql_select( |
|
| 477 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 478 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 479 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 480 | + ); |
|
| 481 | + |
|
| 482 | + while ($row = sql_fetch($r)) { |
|
| 483 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 487 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -499,23 +499,23 @@ discard block |
||
| 499 | 499 | * true si un changement a eu lieu |
| 500 | 500 | **/ |
| 501 | 501 | function calculer_langues_rubriques_etape() { |
| 502 | - $s = sql_select( |
|
| 503 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 504 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 505 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 506 | - ); |
|
| 507 | - |
|
| 508 | - $t = false; |
|
| 509 | - while ($row = sql_fetch($s)) { |
|
| 510 | - $id_rubrique = $row['id_rubrique']; |
|
| 511 | - $t = sql_updateq( |
|
| 512 | - 'spip_rubriques', |
|
| 513 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 514 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - return $t; |
|
| 502 | + $s = sql_select( |
|
| 503 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 504 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 505 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 506 | + ); |
|
| 507 | + |
|
| 508 | + $t = false; |
|
| 509 | + while ($row = sql_fetch($s)) { |
|
| 510 | + $id_rubrique = $row['id_rubrique']; |
|
| 511 | + $t = sql_updateq( |
|
| 512 | + 'spip_rubriques', |
|
| 513 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 514 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + return $t; |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -535,38 +535,38 @@ discard block |
||
| 535 | 535 | **/ |
| 536 | 536 | function calculer_langues_rubriques() { |
| 537 | 537 | |
| 538 | - // rubriques (recursivite) |
|
| 539 | - sql_updateq( |
|
| 540 | - 'spip_rubriques', |
|
| 541 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 542 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 543 | - ); |
|
| 544 | - while (calculer_langues_rubriques_etape()) { |
|
| 545 | - ; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // articles |
|
| 549 | - $s = sql_select( |
|
| 550 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 551 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 552 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 553 | - ); |
|
| 554 | - while ($row = sql_fetch($s)) { |
|
| 555 | - $id_article = $row['id_article']; |
|
| 556 | - sql_updateq( |
|
| 557 | - 'spip_articles', |
|
| 558 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 559 | - 'id_article=' . intval($id_article) |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 564 | - $langues = calculer_langues_utilisees(); |
|
| 565 | - ecrire_meta('langues_utilisees', $langues); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 569 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 538 | + // rubriques (recursivite) |
|
| 539 | + sql_updateq( |
|
| 540 | + 'spip_rubriques', |
|
| 541 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 542 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 543 | + ); |
|
| 544 | + while (calculer_langues_rubriques_etape()) { |
|
| 545 | + ; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // articles |
|
| 549 | + $s = sql_select( |
|
| 550 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 551 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 552 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 553 | + ); |
|
| 554 | + while ($row = sql_fetch($s)) { |
|
| 555 | + $id_article = $row['id_article']; |
|
| 556 | + sql_updateq( |
|
| 557 | + 'spip_articles', |
|
| 558 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 559 | + 'id_article=' . intval($id_article) |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 564 | + $langues = calculer_langues_utilisees(); |
|
| 565 | + ecrire_meta('langues_utilisees', $langues); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 569 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -583,80 +583,80 @@ discard block |
||
| 583 | 583 | * Liste des langues utilisées séparées par des virgules |
| 584 | 584 | **/ |
| 585 | 585 | function calculer_langues_utilisees($serveur = '') { |
| 586 | - include_spip('public/interfaces'); |
|
| 587 | - include_spip('public/compiler'); |
|
| 588 | - include_spip('public/composer'); |
|
| 589 | - include_spip('public/phraser_html'); |
|
| 590 | - $langues = []; |
|
| 591 | - |
|
| 592 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 593 | - |
|
| 594 | - include_spip('base/objets'); |
|
| 595 | - $tables = lister_tables_objets_sql(); |
|
| 596 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 597 | - |
|
| 598 | - foreach (array_keys($tables) as $t) { |
|
| 599 | - $desc = $trouver_table($t, $serveur); |
|
| 600 | - // c'est une table avec des langues |
|
| 601 | - if ( |
|
| 602 | - $desc['exist'] |
|
| 603 | - and isset($desc['field']['lang']) |
|
| 604 | - and isset($desc['field']['langue_choisie']) |
|
| 605 | - ) { |
|
| 606 | - $boucle = new Boucle(); |
|
| 607 | - $boucle->show = $desc; |
|
| 608 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 609 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 610 | - $boucle->id_table = $desc['table_objet']; |
|
| 611 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 612 | - $boucle->sql_serveur = $serveur; |
|
| 613 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 614 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 615 | - $boucle->separateur[] = ','; |
|
| 616 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 617 | - $boucle->iterateur = 'sql'; |
|
| 618 | - |
|
| 619 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 620 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 621 | - $boucle->descr['gram'] = 'html'; |
|
| 622 | - |
|
| 623 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 624 | - |
|
| 625 | - if ( |
|
| 626 | - isset($desc['statut']) |
|
| 627 | - and $desc['statut'] |
|
| 628 | - ) { |
|
| 629 | - $boucles = [ |
|
| 630 | - 'calculer_langues_utilisees' => $boucle, |
|
| 631 | - ]; |
|
| 632 | - // generer un nom de fonction "anonyme" unique |
|
| 633 | - do { |
|
| 634 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 635 | - } while (function_exists($functionname)); |
|
| 636 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 637 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 638 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 639 | - $res = ''; |
|
| 640 | - eval($code); |
|
| 641 | - $res = explode(',', $res); |
|
| 642 | - foreach ($res as $lang) { |
|
| 643 | - $langues[$lang] = 1; |
|
| 644 | - } |
|
| 645 | - } else { |
|
| 646 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 647 | - while ($row = sql_fetch($res)) { |
|
| 648 | - $langues[$row['lang']] = 1; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $langues = array_filter(array_keys($langues)); |
|
| 655 | - sort($langues); |
|
| 656 | - $langues = join(',', $langues); |
|
| 657 | - spip_log("langues utilisees: $langues"); |
|
| 658 | - |
|
| 659 | - return $langues; |
|
| 586 | + include_spip('public/interfaces'); |
|
| 587 | + include_spip('public/compiler'); |
|
| 588 | + include_spip('public/composer'); |
|
| 589 | + include_spip('public/phraser_html'); |
|
| 590 | + $langues = []; |
|
| 591 | + |
|
| 592 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 593 | + |
|
| 594 | + include_spip('base/objets'); |
|
| 595 | + $tables = lister_tables_objets_sql(); |
|
| 596 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 597 | + |
|
| 598 | + foreach (array_keys($tables) as $t) { |
|
| 599 | + $desc = $trouver_table($t, $serveur); |
|
| 600 | + // c'est une table avec des langues |
|
| 601 | + if ( |
|
| 602 | + $desc['exist'] |
|
| 603 | + and isset($desc['field']['lang']) |
|
| 604 | + and isset($desc['field']['langue_choisie']) |
|
| 605 | + ) { |
|
| 606 | + $boucle = new Boucle(); |
|
| 607 | + $boucle->show = $desc; |
|
| 608 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 609 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 610 | + $boucle->id_table = $desc['table_objet']; |
|
| 611 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 612 | + $boucle->sql_serveur = $serveur; |
|
| 613 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 614 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 615 | + $boucle->separateur[] = ','; |
|
| 616 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 617 | + $boucle->iterateur = 'sql'; |
|
| 618 | + |
|
| 619 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 620 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 621 | + $boucle->descr['gram'] = 'html'; |
|
| 622 | + |
|
| 623 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 624 | + |
|
| 625 | + if ( |
|
| 626 | + isset($desc['statut']) |
|
| 627 | + and $desc['statut'] |
|
| 628 | + ) { |
|
| 629 | + $boucles = [ |
|
| 630 | + 'calculer_langues_utilisees' => $boucle, |
|
| 631 | + ]; |
|
| 632 | + // generer un nom de fonction "anonyme" unique |
|
| 633 | + do { |
|
| 634 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 635 | + } while (function_exists($functionname)); |
|
| 636 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 637 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 638 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 639 | + $res = ''; |
|
| 640 | + eval($code); |
|
| 641 | + $res = explode(',', $res); |
|
| 642 | + foreach ($res as $lang) { |
|
| 643 | + $langues[$lang] = 1; |
|
| 644 | + } |
|
| 645 | + } else { |
|
| 646 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 647 | + while ($row = sql_fetch($res)) { |
|
| 648 | + $langues[$row['lang']] = 1; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $langues = array_filter(array_keys($langues)); |
|
| 655 | + sort($langues); |
|
| 656 | + $langues = join(',', $langues); |
|
| 657 | + spip_log("langues utilisees: $langues"); |
|
| 658 | + |
|
| 659 | + return $langues; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -673,9 +673,9 @@ discard block |
||
| 673 | 673 | * incluant les rubriques noeuds et toutes leurs descendances |
| 674 | 674 | */ |
| 675 | 675 | function calcul_branche_in($id) { |
| 676 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 676 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 677 | 677 | |
| 678 | - return $calcul_branche_in($id); |
|
| 678 | + return $calcul_branche_in($id); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -693,9 +693,9 @@ discard block |
||
| 693 | 693 | * incluant les rubriques transmises et toutes leurs parentées |
| 694 | 694 | */ |
| 695 | 695 | function calcul_hierarchie_in($id, $tout = true) { |
| 696 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 696 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 697 | 697 | |
| 698 | - return $calcul_hierarchie_in($id, $tout); |
|
| 698 | + return $calcul_hierarchie_in($id, $tout); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | |
@@ -716,40 +716,40 @@ discard block |
||
| 716 | 716 | * incluant les rubriques noeuds et toutes leurs descendances |
| 717 | 717 | */ |
| 718 | 718 | function inc_calcul_branche_in_dist($id) { |
| 719 | - static $b = []; |
|
| 720 | - |
|
| 721 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 722 | - if (!is_array($id)) { |
|
| 723 | - $id = explode(',', $id); |
|
| 724 | - } |
|
| 725 | - $id = join(',', array_map('intval', $id)); |
|
| 726 | - if (isset($b[$id])) { |
|
| 727 | - return $b[$id]; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - // Notre branche commence par la rubrique de depart |
|
| 731 | - $branche = $r = $id; |
|
| 732 | - |
|
| 733 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 734 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 735 | - $maxiter = 10000; |
|
| 736 | - while ( |
|
| 737 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 738 | - 'id_rubrique', |
|
| 739 | - 'spip_rubriques', |
|
| 740 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 741 | - ) |
|
| 742 | - ) { |
|
| 743 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 744 | - $branche .= ',' . $r; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 748 | - if (strlen($branche) < 10000) { |
|
| 749 | - $b[$id] = $branche; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - return $branche; |
|
| 719 | + static $b = []; |
|
| 720 | + |
|
| 721 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 722 | + if (!is_array($id)) { |
|
| 723 | + $id = explode(',', $id); |
|
| 724 | + } |
|
| 725 | + $id = join(',', array_map('intval', $id)); |
|
| 726 | + if (isset($b[$id])) { |
|
| 727 | + return $b[$id]; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + // Notre branche commence par la rubrique de depart |
|
| 731 | + $branche = $r = $id; |
|
| 732 | + |
|
| 733 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 734 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 735 | + $maxiter = 10000; |
|
| 736 | + while ( |
|
| 737 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 738 | + 'id_rubrique', |
|
| 739 | + 'spip_rubriques', |
|
| 740 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 741 | + ) |
|
| 742 | + ) { |
|
| 743 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 744 | + $branche .= ',' . $r; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 748 | + if (strlen($branche) < 10000) { |
|
| 749 | + $b[$id] = $branche; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + return $branche; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -771,45 +771,45 @@ discard block |
||
| 771 | 771 | * incluant les rubriques transmises et toutes leurs parentées |
| 772 | 772 | */ |
| 773 | 773 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 774 | - static $b = []; |
|
| 775 | - |
|
| 776 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 777 | - if (!is_array($id)) { |
|
| 778 | - $id = explode(',', $id); |
|
| 779 | - } |
|
| 780 | - $id = join(',', array_map('intval', $id)); |
|
| 781 | - |
|
| 782 | - if (isset($b[$id])) { |
|
| 783 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 784 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - $hier = ''; |
|
| 788 | - |
|
| 789 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 790 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 791 | - $ids_nouveaux_parents = $id; |
|
| 792 | - $maxiter = 10000; |
|
| 793 | - while ( |
|
| 794 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 795 | - 'id_parent', |
|
| 796 | - 'spip_rubriques', |
|
| 797 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 798 | - ) |
|
| 799 | - ) { |
|
| 800 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 801 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 805 | - if (strlen($hier) < 10000) { |
|
| 806 | - $b[$id] = $hier; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 810 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 811 | - |
|
| 812 | - return $hier; |
|
| 774 | + static $b = []; |
|
| 775 | + |
|
| 776 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 777 | + if (!is_array($id)) { |
|
| 778 | + $id = explode(',', $id); |
|
| 779 | + } |
|
| 780 | + $id = join(',', array_map('intval', $id)); |
|
| 781 | + |
|
| 782 | + if (isset($b[$id])) { |
|
| 783 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 784 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + $hier = ''; |
|
| 788 | + |
|
| 789 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 790 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 791 | + $ids_nouveaux_parents = $id; |
|
| 792 | + $maxiter = 10000; |
|
| 793 | + while ( |
|
| 794 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 795 | + 'id_parent', |
|
| 796 | + 'spip_rubriques', |
|
| 797 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 798 | + ) |
|
| 799 | + ) { |
|
| 800 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 801 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 805 | + if (strlen($hier) < 10000) { |
|
| 806 | + $b[$id] = $hier; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 810 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 811 | + |
|
| 812 | + return $hier; |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -827,47 +827,47 @@ discard block |
||
| 827 | 827 | * @return void |
| 828 | 828 | **/ |
| 829 | 829 | function calculer_prochain_postdate($check = false) { |
| 830 | - include_spip('base/abstract_sql'); |
|
| 831 | - if ($check) { |
|
| 832 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 833 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 834 | - |
|
| 835 | - $r = sql_select( |
|
| 836 | - 'DISTINCT A.id_rubrique AS id', |
|
| 837 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 838 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 839 | - ); |
|
| 840 | - while ($row = sql_fetch($r)) { |
|
| 841 | - publier_branche_rubrique($row['id']); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - $t = sql_fetsel( |
|
| 848 | - 'date', |
|
| 849 | - 'spip_articles', |
|
| 850 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 851 | - '', |
|
| 852 | - 'date', |
|
| 853 | - '1' |
|
| 854 | - ); |
|
| 855 | - |
|
| 856 | - if ($t) { |
|
| 857 | - $t = $t['date']; |
|
| 858 | - if ( |
|
| 859 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 860 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 861 | - ) { |
|
| 862 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 863 | - ecrire_meta('derniere_modif', time()); |
|
| 864 | - } |
|
| 865 | - } else { |
|
| 866 | - effacer_meta('date_prochain_postdate'); |
|
| 867 | - ecrire_meta('derniere_modif', time()); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - spip_log("prochain postdate: $t"); |
|
| 830 | + include_spip('base/abstract_sql'); |
|
| 831 | + if ($check) { |
|
| 832 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 833 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 834 | + |
|
| 835 | + $r = sql_select( |
|
| 836 | + 'DISTINCT A.id_rubrique AS id', |
|
| 837 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 838 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 839 | + ); |
|
| 840 | + while ($row = sql_fetch($r)) { |
|
| 841 | + publier_branche_rubrique($row['id']); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + $t = sql_fetsel( |
|
| 848 | + 'date', |
|
| 849 | + 'spip_articles', |
|
| 850 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 851 | + '', |
|
| 852 | + 'date', |
|
| 853 | + '1' |
|
| 854 | + ); |
|
| 855 | + |
|
| 856 | + if ($t) { |
|
| 857 | + $t = $t['date']; |
|
| 858 | + if ( |
|
| 859 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 860 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 861 | + ) { |
|
| 862 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 863 | + ecrire_meta('derniere_modif', time()); |
|
| 864 | + } |
|
| 865 | + } else { |
|
| 866 | + effacer_meta('date_prochain_postdate'); |
|
| 867 | + ecrire_meta('derniere_modif', time()); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + spip_log("prochain postdate: $t"); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
@@ -892,62 +892,62 @@ discard block |
||
| 892 | 892 | */ |
| 893 | 893 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 894 | 894 | |
| 895 | - // eclater l'arborescence demandee |
|
| 896 | - // echapper les </multi> et autres balises fermantes html |
|
| 897 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 898 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 899 | - include_spip('base/abstract_sql'); |
|
| 900 | - foreach ($arbo as $titre) { |
|
| 901 | - // retablir les </multi> et autres balises fermantes html |
|
| 902 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 903 | - $r = sql_getfetsel( |
|
| 904 | - 'id_rubrique', |
|
| 905 | - 'spip_rubriques', |
|
| 906 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 907 | - $groupby = [], |
|
| 908 | - $orderby = [], |
|
| 909 | - $limit = '', |
|
| 910 | - $having = [], |
|
| 911 | - $serveur |
|
| 912 | - ); |
|
| 913 | - if ($r !== null) { |
|
| 914 | - $id_parent = $r; |
|
| 915 | - } else { |
|
| 916 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 917 | - 'titre' => $titre, |
|
| 918 | - 'id_parent' => $id_parent, |
|
| 919 | - 'statut' => 'prepa' |
|
| 920 | - ], $desc = [], $serveur); |
|
| 921 | - if ($id_parent > 0) { |
|
| 922 | - $data = sql_fetsel( |
|
| 923 | - 'id_secteur,lang', |
|
| 924 | - 'spip_rubriques', |
|
| 925 | - "id_rubrique=$id_parent", |
|
| 926 | - $groupby = [], |
|
| 927 | - $orderby = [], |
|
| 928 | - $limit = '', |
|
| 929 | - $having = [], |
|
| 930 | - $serveur |
|
| 931 | - ); |
|
| 932 | - $id_secteur = $data['id_secteur']; |
|
| 933 | - $lang = $data['lang']; |
|
| 934 | - } else { |
|
| 935 | - $id_secteur = $id_rubrique; |
|
| 936 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - sql_updateq( |
|
| 940 | - 'spip_rubriques', |
|
| 941 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 942 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 943 | - [], |
|
| 944 | - $serveur |
|
| 945 | - ); |
|
| 946 | - |
|
| 947 | - // pour la recursion |
|
| 948 | - $id_parent = $id_rubrique; |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - return intval($id_parent); |
|
| 895 | + // eclater l'arborescence demandee |
|
| 896 | + // echapper les </multi> et autres balises fermantes html |
|
| 897 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 898 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 899 | + include_spip('base/abstract_sql'); |
|
| 900 | + foreach ($arbo as $titre) { |
|
| 901 | + // retablir les </multi> et autres balises fermantes html |
|
| 902 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 903 | + $r = sql_getfetsel( |
|
| 904 | + 'id_rubrique', |
|
| 905 | + 'spip_rubriques', |
|
| 906 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 907 | + $groupby = [], |
|
| 908 | + $orderby = [], |
|
| 909 | + $limit = '', |
|
| 910 | + $having = [], |
|
| 911 | + $serveur |
|
| 912 | + ); |
|
| 913 | + if ($r !== null) { |
|
| 914 | + $id_parent = $r; |
|
| 915 | + } else { |
|
| 916 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 917 | + 'titre' => $titre, |
|
| 918 | + 'id_parent' => $id_parent, |
|
| 919 | + 'statut' => 'prepa' |
|
| 920 | + ], $desc = [], $serveur); |
|
| 921 | + if ($id_parent > 0) { |
|
| 922 | + $data = sql_fetsel( |
|
| 923 | + 'id_secteur,lang', |
|
| 924 | + 'spip_rubriques', |
|
| 925 | + "id_rubrique=$id_parent", |
|
| 926 | + $groupby = [], |
|
| 927 | + $orderby = [], |
|
| 928 | + $limit = '', |
|
| 929 | + $having = [], |
|
| 930 | + $serveur |
|
| 931 | + ); |
|
| 932 | + $id_secteur = $data['id_secteur']; |
|
| 933 | + $lang = $data['lang']; |
|
| 934 | + } else { |
|
| 935 | + $id_secteur = $id_rubrique; |
|
| 936 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + sql_updateq( |
|
| 940 | + 'spip_rubriques', |
|
| 941 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 942 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 943 | + [], |
|
| 944 | + $serveur |
|
| 945 | + ); |
|
| 946 | + |
|
| 947 | + // pour la recursion |
|
| 948 | + $id_parent = $id_rubrique; |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + return intval($id_parent); |
|
| 953 | 953 | } |
@@ -18,32 +18,32 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\Distant |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 25 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 25 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 26 | 26 | } |
| 27 | 27 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 28 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 28 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 29 | 29 | } |
| 30 | 30 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 31 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 31 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 32 | 32 | } |
| 33 | 33 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 34 | - define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 34 | + define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 35 | 35 | } |
| 36 | 36 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 37 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 37 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 41 | - preg_replace( |
|
| 42 | - '@^https?:@', |
|
| 43 | - 'https?:', |
|
| 44 | - ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 45 | - ) |
|
| 46 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 41 | + preg_replace( |
|
| 42 | + '@^https?:@', |
|
| 43 | + 'https?:', |
|
| 44 | + ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 45 | + ) |
|
| 46 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 47 | 47 | |
| 48 | 48 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 49 | 49 | |
@@ -72,107 +72,107 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) { |
| 74 | 74 | |
| 75 | - // si c'est la protection de soi-meme, retourner le path |
|
| 76 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 77 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 78 | - |
|
| 79 | - return @file_exists($source) ? $source : false; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (is_null($local)) { |
|
| 83 | - $local = fichier_copie_locale($source); |
|
| 84 | - } else { |
|
| 85 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 86 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 91 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 92 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 93 | - if (!$local) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $localrac = _DIR_RACINE . $local; |
|
| 98 | - $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 99 | - |
|
| 100 | - // test d'existence du fichier |
|
| 101 | - if ($mode === 'test') { |
|
| 102 | - return $t ? $local : ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // sinon voir si on doit/peut le telecharger |
|
| 106 | - if ($local === $source or !tester_url_absolue($source)) { |
|
| 107 | - return $t ? $local : ''; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($mode === 'modif' or !$t) { |
|
| 111 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 112 | - // et des eventuelles recuperations concurantes |
|
| 113 | - include_spip('inc/acces'); |
|
| 114 | - if (!$taille_max) { |
|
| 115 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 116 | - } |
|
| 117 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 118 | - $res = recuperer_url( |
|
| 119 | - $source, |
|
| 120 | - ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 124 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 125 | - @unlink($localrac_tmp); |
|
| 126 | - } |
|
| 127 | - else { |
|
| 128 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 129 | - } |
|
| 130 | - if (!$res or !$res['length']) { |
|
| 131 | - // si $t c'est sans doute juste un not-modified-since |
|
| 132 | - return $t ? $local : false; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // si option valider url, verifions que l'URL finale est acceptable |
|
| 136 | - if ( |
|
| 137 | - $callback_valider_url |
|
| 138 | - and is_callable($callback_valider_url) |
|
| 139 | - and !$callback_valider_url($res['url']) |
|
| 140 | - ) { |
|
| 141 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 142 | - @unlink($localrac_tmp); |
|
| 143 | - return $t ? $local : false; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // on peut renommer le fichier tmp |
|
| 147 | - @rename($localrac_tmp, $localrac); |
|
| 148 | - |
|
| 149 | - // si on retrouve l'extension |
|
| 150 | - if ( |
|
| 151 | - !empty($res['headers']) |
|
| 152 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 153 | - ) { |
|
| 154 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 155 | - $sanitizer($localrac); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // pour une eventuelle indexation |
|
| 160 | - pipeline( |
|
| 161 | - 'post_edition', |
|
| 162 | - [ |
|
| 163 | - 'args' => [ |
|
| 164 | - 'operation' => 'copie_locale', |
|
| 165 | - 'source' => $source, |
|
| 166 | - 'fichier' => $local, |
|
| 167 | - 'http_res' => $res['length'], |
|
| 168 | - 'url' => $res['url'], |
|
| 169 | - ], |
|
| 170 | - 'data' => null |
|
| 171 | - ] |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $local; |
|
| 75 | + // si c'est la protection de soi-meme, retourner le path |
|
| 76 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 77 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 78 | + |
|
| 79 | + return @file_exists($source) ? $source : false; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (is_null($local)) { |
|
| 83 | + $local = fichier_copie_locale($source); |
|
| 84 | + } else { |
|
| 85 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 86 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 91 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 92 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 93 | + if (!$local) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $localrac = _DIR_RACINE . $local; |
|
| 98 | + $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 99 | + |
|
| 100 | + // test d'existence du fichier |
|
| 101 | + if ($mode === 'test') { |
|
| 102 | + return $t ? $local : ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // sinon voir si on doit/peut le telecharger |
|
| 106 | + if ($local === $source or !tester_url_absolue($source)) { |
|
| 107 | + return $t ? $local : ''; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($mode === 'modif' or !$t) { |
|
| 111 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 112 | + // et des eventuelles recuperations concurantes |
|
| 113 | + include_spip('inc/acces'); |
|
| 114 | + if (!$taille_max) { |
|
| 115 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 116 | + } |
|
| 117 | + $localrac_tmp = $localrac . '.tmp'; |
|
| 118 | + $res = recuperer_url( |
|
| 119 | + $source, |
|
| 120 | + ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 124 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 125 | + @unlink($localrac_tmp); |
|
| 126 | + } |
|
| 127 | + else { |
|
| 128 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 129 | + } |
|
| 130 | + if (!$res or !$res['length']) { |
|
| 131 | + // si $t c'est sans doute juste un not-modified-since |
|
| 132 | + return $t ? $local : false; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // si option valider url, verifions que l'URL finale est acceptable |
|
| 136 | + if ( |
|
| 137 | + $callback_valider_url |
|
| 138 | + and is_callable($callback_valider_url) |
|
| 139 | + and !$callback_valider_url($res['url']) |
|
| 140 | + ) { |
|
| 141 | + spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 142 | + @unlink($localrac_tmp); |
|
| 143 | + return $t ? $local : false; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // on peut renommer le fichier tmp |
|
| 147 | + @rename($localrac_tmp, $localrac); |
|
| 148 | + |
|
| 149 | + // si on retrouve l'extension |
|
| 150 | + if ( |
|
| 151 | + !empty($res['headers']) |
|
| 152 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 153 | + ) { |
|
| 154 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 155 | + $sanitizer($localrac); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // pour une eventuelle indexation |
|
| 160 | + pipeline( |
|
| 161 | + 'post_edition', |
|
| 162 | + [ |
|
| 163 | + 'args' => [ |
|
| 164 | + 'operation' => 'copie_locale', |
|
| 165 | + 'source' => $source, |
|
| 166 | + 'fichier' => $local, |
|
| 167 | + 'http_res' => $res['length'], |
|
| 168 | + 'url' => $res['url'], |
|
| 169 | + ], |
|
| 170 | + 'data' => null |
|
| 171 | + ] |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $local; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -187,99 +187,99 @@ discard block |
||
| 187 | 187 | * url ou false en cas d'echec |
| 188 | 188 | */ |
| 189 | 189 | function valider_url_distante($url, $known_hosts = []) { |
| 190 | - if (!function_exists('protocole_verifier')) { |
|
| 191 | - include_spip('inc/filtres_mini'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $parsed_url = parse_url($url); |
|
| 199 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!is_array($known_hosts)) { |
|
| 212 | - $known_hosts = [$known_hosts]; |
|
| 213 | - } |
|
| 214 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 215 | - $known_hosts[] = url_de_base(); |
|
| 216 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 217 | - |
|
| 218 | - $is_known_host = false; |
|
| 219 | - foreach ($known_hosts as $known_host) { |
|
| 220 | - $parse_known = parse_url($known_host); |
|
| 221 | - if ( |
|
| 222 | - $parse_known |
|
| 223 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 224 | - ) { |
|
| 225 | - $is_known_host = true; |
|
| 226 | - break; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if (!$is_known_host) { |
|
| 231 | - $host = trim($parsed_url['host'], '.'); |
|
| 232 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 233 | - $ip = gethostbyname($host); |
|
| 234 | - if ($ip === $host) { |
|
| 235 | - // Error condition for gethostbyname() |
|
| 236 | - $ip = false; |
|
| 237 | - } |
|
| 238 | - if ($records = dns_get_record($host)) { |
|
| 239 | - foreach ($records as $record) { |
|
| 240 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 241 | - // se fasse sur la meme IP |
|
| 242 | - if ($record['ttl'] < 10) { |
|
| 243 | - $ip = false; |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - else { |
|
| 249 | - $ip = false; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - if ($ip) { |
|
| 253 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (empty($parsed_url['port'])) { |
|
| 260 | - return $url; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - $port = $parsed_url['port']; |
|
| 264 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 265 | - return $url; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ($is_known_host) { |
|
| 269 | - foreach ($known_hosts as $known_host) { |
|
| 270 | - $parse_known = parse_url($known_host); |
|
| 271 | - if ( |
|
| 272 | - $parse_known |
|
| 273 | - and !empty($parse_known['port']) |
|
| 274 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 275 | - and $parse_known['port'] == $port |
|
| 276 | - ) { |
|
| 277 | - return $url; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return false; |
|
| 190 | + if (!function_exists('protocole_verifier')) { |
|
| 191 | + include_spip('inc/filtres_mini'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $parsed_url = parse_url($url); |
|
| 199 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!is_array($known_hosts)) { |
|
| 212 | + $known_hosts = [$known_hosts]; |
|
| 213 | + } |
|
| 214 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 215 | + $known_hosts[] = url_de_base(); |
|
| 216 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 217 | + |
|
| 218 | + $is_known_host = false; |
|
| 219 | + foreach ($known_hosts as $known_host) { |
|
| 220 | + $parse_known = parse_url($known_host); |
|
| 221 | + if ( |
|
| 222 | + $parse_known |
|
| 223 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 224 | + ) { |
|
| 225 | + $is_known_host = true; |
|
| 226 | + break; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if (!$is_known_host) { |
|
| 231 | + $host = trim($parsed_url['host'], '.'); |
|
| 232 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 233 | + $ip = gethostbyname($host); |
|
| 234 | + if ($ip === $host) { |
|
| 235 | + // Error condition for gethostbyname() |
|
| 236 | + $ip = false; |
|
| 237 | + } |
|
| 238 | + if ($records = dns_get_record($host)) { |
|
| 239 | + foreach ($records as $record) { |
|
| 240 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 241 | + // se fasse sur la meme IP |
|
| 242 | + if ($record['ttl'] < 10) { |
|
| 243 | + $ip = false; |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + else { |
|
| 249 | + $ip = false; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + if ($ip) { |
|
| 253 | + if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 254 | + return false; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (empty($parsed_url['port'])) { |
|
| 260 | + return $url; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + $port = $parsed_url['port']; |
|
| 264 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 265 | + return $url; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ($is_known_host) { |
|
| 269 | + foreach ($known_hosts as $known_host) { |
|
| 270 | + $parse_known = parse_url($known_host); |
|
| 271 | + if ( |
|
| 272 | + $parse_known |
|
| 273 | + and !empty($parse_known['port']) |
|
| 274 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 275 | + and $parse_known['port'] == $port |
|
| 276 | + ) { |
|
| 277 | + return $url; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return false; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -299,86 +299,86 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function prepare_donnees_post($donnees, $boundary = '') { |
| 301 | 301 | |
| 302 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 303 | - // pour un appel soap par exemple |
|
| 304 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 305 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 306 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 307 | - $entete = ''; |
|
| 308 | - // on repasse tous les \r\n et \r en simples \n |
|
| 309 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 310 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 311 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 312 | - $p = strpos($donnees, "\n\n"); |
|
| 313 | - if ($p !== false) { |
|
| 314 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 315 | - $donnees = substr($donnees, $p + 2); |
|
| 316 | - } |
|
| 317 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 318 | - } else { |
|
| 319 | - /* boundary automatique */ |
|
| 320 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 321 | - if ($boundary === '') { |
|
| 322 | - $taille = 0; |
|
| 323 | - foreach ($donnees as $cle => $valeur) { |
|
| 324 | - if (is_array($valeur)) { |
|
| 325 | - foreach ($valeur as $val2) { |
|
| 326 | - $taille += strlen($val2); |
|
| 327 | - } |
|
| 328 | - } else { |
|
| 329 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 330 | - $taille += strlen($valeur); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - if ($taille > 500) { |
|
| 334 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 339 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 340 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 341 | - $chaine = ''; |
|
| 342 | - if (is_array($donnees)) { |
|
| 343 | - foreach ($donnees as $cle => $valeur) { |
|
| 344 | - if (is_array($valeur)) { |
|
| 345 | - foreach ($valeur as $val2) { |
|
| 346 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 347 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 348 | - $chaine .= "\r\n"; |
|
| 349 | - $chaine .= $val2; |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 353 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 354 | - $chaine .= "\r\n"; |
|
| 355 | - $chaine .= $valeur; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 359 | - } |
|
| 360 | - } else { |
|
| 361 | - // fabrique une chaine HTTP simple pour un POST |
|
| 362 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 363 | - $chaine = []; |
|
| 364 | - if (is_array($donnees)) { |
|
| 365 | - foreach ($donnees as $cle => $valeur) { |
|
| 366 | - if (is_array($valeur)) { |
|
| 367 | - foreach ($valeur as $val2) { |
|
| 368 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 369 | - } |
|
| 370 | - } else { |
|
| 371 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - $chaine = implode('&', $chaine); |
|
| 375 | - } else { |
|
| 376 | - $chaine = $donnees; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - return [$entete, $chaine]; |
|
| 302 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 303 | + // pour un appel soap par exemple |
|
| 304 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 305 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 306 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 307 | + $entete = ''; |
|
| 308 | + // on repasse tous les \r\n et \r en simples \n |
|
| 309 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 310 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 311 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 312 | + $p = strpos($donnees, "\n\n"); |
|
| 313 | + if ($p !== false) { |
|
| 314 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 315 | + $donnees = substr($donnees, $p + 2); |
|
| 316 | + } |
|
| 317 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 318 | + } else { |
|
| 319 | + /* boundary automatique */ |
|
| 320 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 321 | + if ($boundary === '') { |
|
| 322 | + $taille = 0; |
|
| 323 | + foreach ($donnees as $cle => $valeur) { |
|
| 324 | + if (is_array($valeur)) { |
|
| 325 | + foreach ($valeur as $val2) { |
|
| 326 | + $taille += strlen($val2); |
|
| 327 | + } |
|
| 328 | + } else { |
|
| 329 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 330 | + $taille += strlen($valeur); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + if ($taille > 500) { |
|
| 334 | + $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 339 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 340 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 341 | + $chaine = ''; |
|
| 342 | + if (is_array($donnees)) { |
|
| 343 | + foreach ($donnees as $cle => $valeur) { |
|
| 344 | + if (is_array($valeur)) { |
|
| 345 | + foreach ($valeur as $val2) { |
|
| 346 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 347 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 348 | + $chaine .= "\r\n"; |
|
| 349 | + $chaine .= $val2; |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 353 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 354 | + $chaine .= "\r\n"; |
|
| 355 | + $chaine .= $valeur; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 359 | + } |
|
| 360 | + } else { |
|
| 361 | + // fabrique une chaine HTTP simple pour un POST |
|
| 362 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 363 | + $chaine = []; |
|
| 364 | + if (is_array($donnees)) { |
|
| 365 | + foreach ($donnees as $cle => $valeur) { |
|
| 366 | + if (is_array($valeur)) { |
|
| 367 | + foreach ($valeur as $val2) { |
|
| 368 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 369 | + } |
|
| 370 | + } else { |
|
| 371 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + $chaine = implode('&', $chaine); |
|
| 375 | + } else { |
|
| 376 | + $chaine = $donnees; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + return [$entete, $chaine]; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -389,19 +389,19 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | function url_to_ascii($url_idn) { |
| 391 | 391 | |
| 392 | - if ($parts = parse_url($url_idn)) { |
|
| 393 | - $host = $parts['host']; |
|
| 394 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 395 | - $converter = new ToIdn(); |
|
| 396 | - $host_ascii = $converter->convert($host); |
|
| 397 | - $url_idn = explode($host, $url_idn, 2); |
|
| 398 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 399 | - } |
|
| 400 | - // et on urlencode les char utf si besoin dans le path |
|
| 401 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $url_idn; |
|
| 392 | + if ($parts = parse_url($url_idn)) { |
|
| 393 | + $host = $parts['host']; |
|
| 394 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 395 | + $converter = new ToIdn(); |
|
| 396 | + $host_ascii = $converter->convert($host); |
|
| 397 | + $url_idn = explode($host, $url_idn, 2); |
|
| 398 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 399 | + } |
|
| 400 | + // et on urlencode les char utf si besoin dans le path |
|
| 401 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $url_idn; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -442,209 +442,209 @@ discard block |
||
| 442 | 442 | * string file : nom du fichier si enregistre dans un fichier |
| 443 | 443 | */ |
| 444 | 444 | function recuperer_url($url, $options = []) { |
| 445 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 446 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 447 | - $default = [ |
|
| 448 | - 'transcoder' => false, |
|
| 449 | - 'methode' => 'GET', |
|
| 450 | - 'taille_max' => null, |
|
| 451 | - 'headers' => [], |
|
| 452 | - 'datas' => '', |
|
| 453 | - 'boundary' => '', |
|
| 454 | - 'refuser_gz' => false, |
|
| 455 | - 'if_modified_since' => '', |
|
| 456 | - 'uri_referer' => '', |
|
| 457 | - 'file' => '', |
|
| 458 | - 'follow_location' => 10, |
|
| 459 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 460 | - ]; |
|
| 461 | - $options = array_merge($default, $options); |
|
| 462 | - // copier directement dans un fichier ? |
|
| 463 | - $copy = $options['file']; |
|
| 464 | - |
|
| 465 | - if ($options['methode'] == 'HEAD') { |
|
| 466 | - $options['taille_max'] = 0; |
|
| 467 | - } |
|
| 468 | - if (is_null($options['taille_max'])) { |
|
| 469 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 473 | - |
|
| 474 | - // Ajout des en-têtes spécifiques si besoin |
|
| 475 | - $formatted_data = ''; |
|
| 476 | - if (!empty($options['headers'])) { |
|
| 477 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 478 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if (!empty($options['datas'])) { |
|
| 483 | - [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 484 | - $head .= $formatted_data; |
|
| 485 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 486 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 487 | - } |
|
| 488 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 489 | - if ( |
|
| 490 | - strlen($postdata) |
|
| 491 | - and !$methode_demandee |
|
| 492 | - ) { |
|
| 493 | - $options['methode'] = 'POST'; |
|
| 494 | - } |
|
| 495 | - } elseif ($formatted_data) { |
|
| 496 | - $formatted_data .= "\r\n"; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 500 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 501 | - if (!tester_url_absolue($url)) { |
|
| 502 | - $url = 'http://' . $url; |
|
| 503 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 504 | - $url = 'http:' . $url; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $url = url_to_ascii($url); |
|
| 508 | - |
|
| 509 | - $result = [ |
|
| 510 | - 'status' => 0, |
|
| 511 | - 'headers' => '', |
|
| 512 | - 'page' => '', |
|
| 513 | - 'length' => 0, |
|
| 514 | - 'last_modified' => '', |
|
| 515 | - 'location' => '', |
|
| 516 | - 'url' => $url |
|
| 517 | - ]; |
|
| 518 | - |
|
| 519 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 520 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 521 | - |
|
| 522 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 523 | - [$handle, $fopen] = init_http( |
|
| 524 | - $options['methode'], |
|
| 525 | - $url, |
|
| 526 | - $refuser_gz, |
|
| 527 | - $options['uri_referer'], |
|
| 528 | - $formatted_data, |
|
| 529 | - $options['version_http'], |
|
| 530 | - $options['if_modified_since'] |
|
| 531 | - ); |
|
| 532 | - if (!$handle) { |
|
| 533 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 534 | - |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 539 | - // et recuperer les en-tetes de reponses |
|
| 540 | - if (!$fopen) { |
|
| 541 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 542 | - if (!$res) { |
|
| 543 | - fclose($handle); |
|
| 544 | - $t = @parse_url($url); |
|
| 545 | - $host = $t['host']; |
|
| 546 | - // Chinoisierie inexplicable pour contrer |
|
| 547 | - // les actions liberticides de l'empire du milieu |
|
| 548 | - if ( |
|
| 549 | - !need_proxy($host) |
|
| 550 | - and $res = @file_get_contents($url) |
|
| 551 | - ) { |
|
| 552 | - $result['length'] = strlen($res); |
|
| 553 | - if ($copy) { |
|
| 554 | - ecrire_fichier($copy, $res); |
|
| 555 | - $result['file'] = $copy; |
|
| 556 | - } else { |
|
| 557 | - $result['page'] = $res; |
|
| 558 | - } |
|
| 559 | - $res = [ |
|
| 560 | - 'status' => 200, |
|
| 561 | - ]; |
|
| 562 | - } else { |
|
| 563 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 564 | - return false; |
|
| 565 | - } |
|
| 566 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 567 | - $options['follow_location']--; |
|
| 568 | - fclose($handle); |
|
| 569 | - include_spip('inc/filtres'); |
|
| 570 | - $url = suivre_lien($url, $res['location']); |
|
| 571 | - |
|
| 572 | - // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 573 | - if ($options['methode'] !== 'GET') { |
|
| 574 | - if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 575 | - $options['methode'] = 'GET'; |
|
| 576 | - $options['datas'] = ''; |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 580 | - |
|
| 581 | - return recuperer_url($url, $options); |
|
| 582 | - } elseif ($res['status'] !== 200) { |
|
| 583 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 584 | - } |
|
| 585 | - $result['status'] = $res['status']; |
|
| 586 | - if (isset($res['headers'])) { |
|
| 587 | - $result['headers'] = $res['headers']; |
|
| 588 | - } |
|
| 589 | - if (isset($res['last_modified'])) { |
|
| 590 | - $result['last_modified'] = $res['last_modified']; |
|
| 591 | - } |
|
| 592 | - if (isset($res['location'])) { |
|
| 593 | - $result['location'] = $res['location']; |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - // on ne veut que les entetes |
|
| 598 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 599 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 600 | - return $result; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 605 | - // sinon la memoire explose pour les gros flux |
|
| 606 | - |
|
| 607 | - $gz = false; |
|
| 608 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 609 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 613 | - if (!$result['length']) { |
|
| 614 | - $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 615 | - fclose($handle); |
|
| 616 | - if ($copy) { |
|
| 617 | - $result['length'] = $res; |
|
| 618 | - $result['file'] = $copy; |
|
| 619 | - } elseif ($res) { |
|
| 620 | - $result['page'] = &$res; |
|
| 621 | - $result['length'] = strlen($result['page']); |
|
| 622 | - } |
|
| 623 | - if (!$result['status']) { |
|
| 624 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - if (!$result['page']) { |
|
| 628 | - return $result; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - // Decompresser au besoin |
|
| 632 | - if ($gz) { |
|
| 633 | - $result['page'] = implode('', gzfile($gz)); |
|
| 634 | - supprimer_fichier($gz); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - // Faut-il l'importer dans notre charset local ? |
|
| 638 | - if ($options['transcoder']) { |
|
| 639 | - include_spip('inc/charsets'); |
|
| 640 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - $trace = json_decode(json_encode($result), true); |
|
| 644 | - $trace['page'] = '...'; |
|
| 645 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 646 | - |
|
| 647 | - return $result; |
|
| 445 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 446 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 447 | + $default = [ |
|
| 448 | + 'transcoder' => false, |
|
| 449 | + 'methode' => 'GET', |
|
| 450 | + 'taille_max' => null, |
|
| 451 | + 'headers' => [], |
|
| 452 | + 'datas' => '', |
|
| 453 | + 'boundary' => '', |
|
| 454 | + 'refuser_gz' => false, |
|
| 455 | + 'if_modified_since' => '', |
|
| 456 | + 'uri_referer' => '', |
|
| 457 | + 'file' => '', |
|
| 458 | + 'follow_location' => 10, |
|
| 459 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 460 | + ]; |
|
| 461 | + $options = array_merge($default, $options); |
|
| 462 | + // copier directement dans un fichier ? |
|
| 463 | + $copy = $options['file']; |
|
| 464 | + |
|
| 465 | + if ($options['methode'] == 'HEAD') { |
|
| 466 | + $options['taille_max'] = 0; |
|
| 467 | + } |
|
| 468 | + if (is_null($options['taille_max'])) { |
|
| 469 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 473 | + |
|
| 474 | + // Ajout des en-têtes spécifiques si besoin |
|
| 475 | + $formatted_data = ''; |
|
| 476 | + if (!empty($options['headers'])) { |
|
| 477 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 478 | + $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if (!empty($options['datas'])) { |
|
| 483 | + [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 484 | + $head .= $formatted_data; |
|
| 485 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 486 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 487 | + } |
|
| 488 | + $formatted_data = $head . "\r\n" . $postdata; |
|
| 489 | + if ( |
|
| 490 | + strlen($postdata) |
|
| 491 | + and !$methode_demandee |
|
| 492 | + ) { |
|
| 493 | + $options['methode'] = 'POST'; |
|
| 494 | + } |
|
| 495 | + } elseif ($formatted_data) { |
|
| 496 | + $formatted_data .= "\r\n"; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 500 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 501 | + if (!tester_url_absolue($url)) { |
|
| 502 | + $url = 'http://' . $url; |
|
| 503 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 504 | + $url = 'http:' . $url; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $url = url_to_ascii($url); |
|
| 508 | + |
|
| 509 | + $result = [ |
|
| 510 | + 'status' => 0, |
|
| 511 | + 'headers' => '', |
|
| 512 | + 'page' => '', |
|
| 513 | + 'length' => 0, |
|
| 514 | + 'last_modified' => '', |
|
| 515 | + 'location' => '', |
|
| 516 | + 'url' => $url |
|
| 517 | + ]; |
|
| 518 | + |
|
| 519 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 520 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 521 | + |
|
| 522 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 523 | + [$handle, $fopen] = init_http( |
|
| 524 | + $options['methode'], |
|
| 525 | + $url, |
|
| 526 | + $refuser_gz, |
|
| 527 | + $options['uri_referer'], |
|
| 528 | + $formatted_data, |
|
| 529 | + $options['version_http'], |
|
| 530 | + $options['if_modified_since'] |
|
| 531 | + ); |
|
| 532 | + if (!$handle) { |
|
| 533 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 534 | + |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 539 | + // et recuperer les en-tetes de reponses |
|
| 540 | + if (!$fopen) { |
|
| 541 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 542 | + if (!$res) { |
|
| 543 | + fclose($handle); |
|
| 544 | + $t = @parse_url($url); |
|
| 545 | + $host = $t['host']; |
|
| 546 | + // Chinoisierie inexplicable pour contrer |
|
| 547 | + // les actions liberticides de l'empire du milieu |
|
| 548 | + if ( |
|
| 549 | + !need_proxy($host) |
|
| 550 | + and $res = @file_get_contents($url) |
|
| 551 | + ) { |
|
| 552 | + $result['length'] = strlen($res); |
|
| 553 | + if ($copy) { |
|
| 554 | + ecrire_fichier($copy, $res); |
|
| 555 | + $result['file'] = $copy; |
|
| 556 | + } else { |
|
| 557 | + $result['page'] = $res; |
|
| 558 | + } |
|
| 559 | + $res = [ |
|
| 560 | + 'status' => 200, |
|
| 561 | + ]; |
|
| 562 | + } else { |
|
| 563 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 564 | + return false; |
|
| 565 | + } |
|
| 566 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 567 | + $options['follow_location']--; |
|
| 568 | + fclose($handle); |
|
| 569 | + include_spip('inc/filtres'); |
|
| 570 | + $url = suivre_lien($url, $res['location']); |
|
| 571 | + |
|
| 572 | + // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 573 | + if ($options['methode'] !== 'GET') { |
|
| 574 | + if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 575 | + $options['methode'] = 'GET'; |
|
| 576 | + $options['datas'] = ''; |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 580 | + |
|
| 581 | + return recuperer_url($url, $options); |
|
| 582 | + } elseif ($res['status'] !== 200) { |
|
| 583 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 584 | + } |
|
| 585 | + $result['status'] = $res['status']; |
|
| 586 | + if (isset($res['headers'])) { |
|
| 587 | + $result['headers'] = $res['headers']; |
|
| 588 | + } |
|
| 589 | + if (isset($res['last_modified'])) { |
|
| 590 | + $result['last_modified'] = $res['last_modified']; |
|
| 591 | + } |
|
| 592 | + if (isset($res['location'])) { |
|
| 593 | + $result['location'] = $res['location']; |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + // on ne veut que les entetes |
|
| 598 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 599 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 600 | + return $result; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 605 | + // sinon la memoire explose pour les gros flux |
|
| 606 | + |
|
| 607 | + $gz = false; |
|
| 608 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 609 | + $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 613 | + if (!$result['length']) { |
|
| 614 | + $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 615 | + fclose($handle); |
|
| 616 | + if ($copy) { |
|
| 617 | + $result['length'] = $res; |
|
| 618 | + $result['file'] = $copy; |
|
| 619 | + } elseif ($res) { |
|
| 620 | + $result['page'] = &$res; |
|
| 621 | + $result['length'] = strlen($result['page']); |
|
| 622 | + } |
|
| 623 | + if (!$result['status']) { |
|
| 624 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (!$result['page']) { |
|
| 628 | + return $result; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + // Decompresser au besoin |
|
| 632 | + if ($gz) { |
|
| 633 | + $result['page'] = implode('', gzfile($gz)); |
|
| 634 | + supprimer_fichier($gz); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + // Faut-il l'importer dans notre charset local ? |
|
| 638 | + if ($options['transcoder']) { |
|
| 639 | + include_spip('inc/charsets'); |
|
| 640 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + $trace = json_decode(json_encode($result), true); |
|
| 644 | + $trace['page'] = '...'; |
|
| 645 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 646 | + |
|
| 647 | + return $result; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /** |
@@ -660,73 +660,73 @@ discard block |
||
| 660 | 660 | * @return array|bool|mixed |
| 661 | 661 | */ |
| 662 | 662 | function recuperer_url_cache($url, $options = []) { |
| 663 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 664 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 665 | - } |
|
| 666 | - $default = [ |
|
| 667 | - 'transcoder' => false, |
|
| 668 | - 'methode' => 'GET', |
|
| 669 | - 'taille_max' => null, |
|
| 670 | - 'datas' => '', |
|
| 671 | - 'boundary' => '', |
|
| 672 | - 'refuser_gz' => false, |
|
| 673 | - 'if_modified_since' => '', |
|
| 674 | - 'uri_referer' => '', |
|
| 675 | - 'file' => '', |
|
| 676 | - 'follow_location' => 10, |
|
| 677 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 678 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 679 | - ]; |
|
| 680 | - $options = array_merge($default, $options); |
|
| 681 | - |
|
| 682 | - // cas ou il n'est pas possible de cacher |
|
| 683 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 684 | - return recuperer_url($url, $options); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 688 | - static $errors = []; |
|
| 689 | - if (isset($errors[$url])) { |
|
| 690 | - return $errors[$url]; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $sig = $options; |
|
| 694 | - unset($sig['if_modified_since']); |
|
| 695 | - unset($sig['delai_cache']); |
|
| 696 | - $sig['url'] = $url; |
|
| 697 | - |
|
| 698 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 699 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 700 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 701 | - $cache = "$sub$cache"; |
|
| 702 | - |
|
| 703 | - $res = false; |
|
| 704 | - $is_cached = file_exists($cache); |
|
| 705 | - if ( |
|
| 706 | - $is_cached |
|
| 707 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 708 | - ) { |
|
| 709 | - lire_fichier($cache, $res); |
|
| 710 | - if ($res = unserialize($res)) { |
|
| 711 | - // mettre le last_modified et le status=304 ? |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - if (!$res) { |
|
| 715 | - $res = recuperer_url($url, $options); |
|
| 716 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 717 | - if (!$res) { |
|
| 718 | - if ($is_cached) { |
|
| 719 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 720 | - lire_fichier($cache, $res); |
|
| 721 | - $res = unserialize($res); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $errors[$url] = $res; |
|
| 725 | - } |
|
| 726 | - ecrire_fichier($cache, serialize($res)); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - return $res; |
|
| 663 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 664 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 665 | + } |
|
| 666 | + $default = [ |
|
| 667 | + 'transcoder' => false, |
|
| 668 | + 'methode' => 'GET', |
|
| 669 | + 'taille_max' => null, |
|
| 670 | + 'datas' => '', |
|
| 671 | + 'boundary' => '', |
|
| 672 | + 'refuser_gz' => false, |
|
| 673 | + 'if_modified_since' => '', |
|
| 674 | + 'uri_referer' => '', |
|
| 675 | + 'file' => '', |
|
| 676 | + 'follow_location' => 10, |
|
| 677 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 678 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 679 | + ]; |
|
| 680 | + $options = array_merge($default, $options); |
|
| 681 | + |
|
| 682 | + // cas ou il n'est pas possible de cacher |
|
| 683 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 684 | + return recuperer_url($url, $options); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 688 | + static $errors = []; |
|
| 689 | + if (isset($errors[$url])) { |
|
| 690 | + return $errors[$url]; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $sig = $options; |
|
| 694 | + unset($sig['if_modified_since']); |
|
| 695 | + unset($sig['delai_cache']); |
|
| 696 | + $sig['url'] = $url; |
|
| 697 | + |
|
| 698 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 699 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 700 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 701 | + $cache = "$sub$cache"; |
|
| 702 | + |
|
| 703 | + $res = false; |
|
| 704 | + $is_cached = file_exists($cache); |
|
| 705 | + if ( |
|
| 706 | + $is_cached |
|
| 707 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 708 | + ) { |
|
| 709 | + lire_fichier($cache, $res); |
|
| 710 | + if ($res = unserialize($res)) { |
|
| 711 | + // mettre le last_modified et le status=304 ? |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + if (!$res) { |
|
| 715 | + $res = recuperer_url($url, $options); |
|
| 716 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 717 | + if (!$res) { |
|
| 718 | + if ($is_cached) { |
|
| 719 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 720 | + lire_fichier($cache, $res); |
|
| 721 | + $res = unserialize($res); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $errors[$url] = $res; |
|
| 725 | + } |
|
| 726 | + ecrire_fichier($cache, serialize($res)); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + return $res; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -744,42 +744,42 @@ discard block |
||
| 744 | 744 | * string contenu de la resource |
| 745 | 745 | */ |
| 746 | 746 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 747 | - $tmpfile = null; |
|
| 748 | - $taille = 0; |
|
| 749 | - $result = ''; |
|
| 750 | - $fp = false; |
|
| 751 | - if ($fichier) { |
|
| 752 | - include_spip('inc/acces'); |
|
| 753 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 754 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 755 | - if (!$fp and file_exists($fichier)) { |
|
| 756 | - return filesize($fichier); |
|
| 757 | - } |
|
| 758 | - if (!$fp) { |
|
| 759 | - return false; |
|
| 760 | - } |
|
| 761 | - $result = 0; // on renvoie la taille du fichier |
|
| 762 | - } |
|
| 763 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 764 | - $res = fread($handle, 16384); |
|
| 765 | - $taille += strlen($res); |
|
| 766 | - if ($fp) { |
|
| 767 | - fwrite($fp, $res); |
|
| 768 | - $result = $taille; |
|
| 769 | - } else { |
|
| 770 | - $result .= $res; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - if ($fp) { |
|
| 774 | - spip_fclose_unlock($fp); |
|
| 775 | - spip_unlink($fichier); |
|
| 776 | - @rename($tmpfile, $fichier); |
|
| 777 | - if (!file_exists($fichier)) { |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - return $result; |
|
| 747 | + $tmpfile = null; |
|
| 748 | + $taille = 0; |
|
| 749 | + $result = ''; |
|
| 750 | + $fp = false; |
|
| 751 | + if ($fichier) { |
|
| 752 | + include_spip('inc/acces'); |
|
| 753 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 754 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 755 | + if (!$fp and file_exists($fichier)) { |
|
| 756 | + return filesize($fichier); |
|
| 757 | + } |
|
| 758 | + if (!$fp) { |
|
| 759 | + return false; |
|
| 760 | + } |
|
| 761 | + $result = 0; // on renvoie la taille du fichier |
|
| 762 | + } |
|
| 763 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 764 | + $res = fread($handle, 16384); |
|
| 765 | + $taille += strlen($res); |
|
| 766 | + if ($fp) { |
|
| 767 | + fwrite($fp, $res); |
|
| 768 | + $result = $taille; |
|
| 769 | + } else { |
|
| 770 | + $result .= $res; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + if ($fp) { |
|
| 774 | + spip_fclose_unlock($fp); |
|
| 775 | + spip_unlink($fichier); |
|
| 776 | + @rename($tmpfile, $fichier); |
|
| 777 | + if (!file_exists($fichier)) { |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + return $result; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
@@ -801,35 +801,35 @@ discard block |
||
| 801 | 801 | * string location |
| 802 | 802 | */ |
| 803 | 803 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 804 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 805 | - |
|
| 806 | - $s = @trim(fgets($handle, 16384)); |
|
| 807 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $result['status'] = intval($r[1]); |
|
| 811 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 812 | - $result['headers'][] = $s . "\n"; |
|
| 813 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 814 | - [, $d, $v] = $r; |
|
| 815 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 816 | - $result['location'] = $v; |
|
| 817 | - } elseif ($d == 'Last-Modified') { |
|
| 818 | - $result['last_modified'] = strtotime($v); |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - if ( |
|
| 822 | - $if_modified_since |
|
| 823 | - and $result['last_modified'] |
|
| 824 | - and $if_modified_since > $result['last_modified'] |
|
| 825 | - and $result['status'] == 200 |
|
| 826 | - ) { |
|
| 827 | - $result['status'] = 304; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $result['headers'] = implode('', $result['headers']); |
|
| 831 | - |
|
| 832 | - return $result; |
|
| 804 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 805 | + |
|
| 806 | + $s = @trim(fgets($handle, 16384)); |
|
| 807 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $result['status'] = intval($r[1]); |
|
| 811 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 812 | + $result['headers'][] = $s . "\n"; |
|
| 813 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 814 | + [, $d, $v] = $r; |
|
| 815 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 816 | + $result['location'] = $v; |
|
| 817 | + } elseif ($d == 'Last-Modified') { |
|
| 818 | + $result['last_modified'] = strtotime($v); |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + if ( |
|
| 822 | + $if_modified_since |
|
| 823 | + and $result['last_modified'] |
|
| 824 | + and $if_modified_since > $result['last_modified'] |
|
| 825 | + and $result['status'] == 200 |
|
| 826 | + ) { |
|
| 827 | + $result['status'] = 304; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $result['headers'] = implode('', $result['headers']); |
|
| 831 | + |
|
| 832 | + return $result; |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -851,22 +851,22 @@ discard block |
||
| 851 | 851 | * Nom du fichier pour copie locale |
| 852 | 852 | **/ |
| 853 | 853 | function nom_fichier_copie_locale($source, $extension) { |
| 854 | - include_spip('inc/documents'); |
|
| 854 | + include_spip('inc/documents'); |
|
| 855 | 855 | |
| 856 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 857 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 856 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 857 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 858 | 858 | |
| 859 | - // on se place tout le temps comme si on etait a la racine |
|
| 860 | - if (_DIR_RACINE) { |
|
| 861 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 862 | - } |
|
| 859 | + // on se place tout le temps comme si on etait a la racine |
|
| 860 | + if (_DIR_RACINE) { |
|
| 861 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 862 | + } |
|
| 863 | 863 | |
| 864 | - $m = md5($source); |
|
| 864 | + $m = md5($source); |
|
| 865 | 865 | |
| 866 | - return $d |
|
| 867 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 868 | - . substr($m, 0, 4) |
|
| 869 | - . ".$extension"; |
|
| 866 | + return $d |
|
| 867 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 868 | + . substr($m, 0, 4) |
|
| 869 | + . ".$extension"; |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -885,72 +885,72 @@ discard block |
||
| 885 | 885 | * - null: Copie locale impossible |
| 886 | 886 | **/ |
| 887 | 887 | function fichier_copie_locale($source) { |
| 888 | - // Si c'est deja local pas de souci |
|
| 889 | - if (!tester_url_absolue($source)) { |
|
| 890 | - if (_DIR_RACINE) { |
|
| 891 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - return $source; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 898 | - // a deja ete copie en local avec cette extension |
|
| 899 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 900 | - $path_parts = pathinfo($source); |
|
| 901 | - if (!isset($path_parts['extension'])) { |
|
| 902 | - $path_parts['extension'] = ''; |
|
| 903 | - } |
|
| 904 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 905 | - if ( |
|
| 906 | - $ext |
|
| 907 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 908 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 909 | - and file_exists(_DIR_RACINE . $f) |
|
| 910 | - ) { |
|
| 911 | - return $f; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - // Si c'est deja dans la table des documents, |
|
| 916 | - // ramener le nom de sa copie potentielle |
|
| 917 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 918 | - |
|
| 919 | - if ($ext) { |
|
| 920 | - return nom_fichier_copie_locale($source, $ext); |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 924 | - // et si il n'aurait pas deja ete rapatrie |
|
| 925 | - |
|
| 926 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 927 | - |
|
| 928 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 929 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 930 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 931 | - return $f; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // Ping pour voir si son extension est connue et autorisee |
|
| 936 | - // avec mise en cache du resultat du ping |
|
| 937 | - |
|
| 938 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 939 | - if ( |
|
| 940 | - !@file_exists($cache) |
|
| 941 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 942 | - or _request('var_mode') === 'recalcul' |
|
| 943 | - ) { |
|
| 944 | - $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 945 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 946 | - } |
|
| 947 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 948 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 949 | - return nom_fichier_copie_locale($source, $ext); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 953 | - return null; |
|
| 888 | + // Si c'est deja local pas de souci |
|
| 889 | + if (!tester_url_absolue($source)) { |
|
| 890 | + if (_DIR_RACINE) { |
|
| 891 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + return $source; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 898 | + // a deja ete copie en local avec cette extension |
|
| 899 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 900 | + $path_parts = pathinfo($source); |
|
| 901 | + if (!isset($path_parts['extension'])) { |
|
| 902 | + $path_parts['extension'] = ''; |
|
| 903 | + } |
|
| 904 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 905 | + if ( |
|
| 906 | + $ext |
|
| 907 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 908 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 909 | + and file_exists(_DIR_RACINE . $f) |
|
| 910 | + ) { |
|
| 911 | + return $f; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + // Si c'est deja dans la table des documents, |
|
| 916 | + // ramener le nom de sa copie potentielle |
|
| 917 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 918 | + |
|
| 919 | + if ($ext) { |
|
| 920 | + return nom_fichier_copie_locale($source, $ext); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 924 | + // et si il n'aurait pas deja ete rapatrie |
|
| 925 | + |
|
| 926 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 927 | + |
|
| 928 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 929 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 930 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 931 | + return $f; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // Ping pour voir si son extension est connue et autorisee |
|
| 936 | + // avec mise en cache du resultat du ping |
|
| 937 | + |
|
| 938 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 939 | + if ( |
|
| 940 | + !@file_exists($cache) |
|
| 941 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 942 | + or _request('var_mode') === 'recalcul' |
|
| 943 | + ) { |
|
| 944 | + $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 945 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 946 | + } |
|
| 947 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 948 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 949 | + return nom_fichier_copie_locale($source, $ext); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 953 | + return null; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | |
@@ -979,110 +979,110 @@ discard block |
||
| 979 | 979 | **/ |
| 980 | 980 | function recuperer_infos_distantes($source, $options = []) { |
| 981 | 981 | |
| 982 | - // pas la peine de perdre son temps |
|
| 983 | - if (!tester_url_absolue($source)) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $taille_max = $options['taille_max'] ?? 0; |
|
| 988 | - $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 989 | - $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 990 | - |
|
| 991 | - # charger les alias des types mime |
|
| 992 | - include_spip('base/typedoc'); |
|
| 993 | - |
|
| 994 | - $a = []; |
|
| 995 | - $mime_type = ''; |
|
| 996 | - // On va directement charger le debut des images et des fichiers html, |
|
| 997 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 998 | - // ca echoue l'utilisateur devra les entrer... |
|
| 999 | - $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 1000 | - if ( |
|
| 1001 | - $callback_valider_url |
|
| 1002 | - and is_callable($callback_valider_url) |
|
| 1003 | - and !$callback_valider_url($reponse['url']) |
|
| 1004 | - ) { |
|
| 1005 | - return false; |
|
| 1006 | - } |
|
| 1007 | - $headers = $reponse['headers'] ?? ''; |
|
| 1008 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 1009 | - if ($headers) { |
|
| 1010 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - $a['extension'] = $extension; |
|
| 1015 | - |
|
| 1016 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1017 | - $a['taille'] = intval($regs[1]); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // Echec avec HEAD, on tente avec GET |
|
| 1022 | - if (!$a and !$taille_max) { |
|
| 1023 | - spip_log("tenter GET $source", 'distant'); |
|
| 1024 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1025 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - // si on a rien trouve pas la peine d'insister |
|
| 1029 | - if (!$a) { |
|
| 1030 | - return false; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1034 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1035 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1036 | - if ( |
|
| 1037 | - strpos($mime_type, 'image/') === 0 |
|
| 1038 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1039 | - ) { |
|
| 1040 | - if ( |
|
| 1041 | - $taille_max == 0 |
|
| 1042 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1043 | - and in_array($extension, formats_image_acceptables()) |
|
| 1044 | - and $charger_si_petite_image |
|
| 1045 | - ) { |
|
| 1046 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1047 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1048 | - } else { |
|
| 1049 | - if ($a['body']) { |
|
| 1050 | - $a['extension'] = $extension; |
|
| 1051 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1052 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1053 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1054 | - $a['largeur'] = intval($size_image[0]); |
|
| 1055 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1056 | - $a['type_image'] = true; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1062 | - // ce sera mieux que 0x0 |
|
| 1063 | - // Flash is dead! |
|
| 1064 | - if ( |
|
| 1065 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1066 | - and empty($a['largeur']) |
|
| 1067 | - ) { |
|
| 1068 | - $a['largeur'] = 425; |
|
| 1069 | - $a['hauteur'] = 350; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - if ($mime_type == 'text/html') { |
|
| 1073 | - include_spip('inc/filtres'); |
|
| 1074 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1075 | - $page = $page['page'] ?? ''; |
|
| 1076 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1077 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1078 | - } |
|
| 1079 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1080 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - $a['mime_type'] = $mime_type; |
|
| 1084 | - |
|
| 1085 | - return $a; |
|
| 982 | + // pas la peine de perdre son temps |
|
| 983 | + if (!tester_url_absolue($source)) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $taille_max = $options['taille_max'] ?? 0; |
|
| 988 | + $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 989 | + $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 990 | + |
|
| 991 | + # charger les alias des types mime |
|
| 992 | + include_spip('base/typedoc'); |
|
| 993 | + |
|
| 994 | + $a = []; |
|
| 995 | + $mime_type = ''; |
|
| 996 | + // On va directement charger le debut des images et des fichiers html, |
|
| 997 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 998 | + // ca echoue l'utilisateur devra les entrer... |
|
| 999 | + $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 1000 | + if ( |
|
| 1001 | + $callback_valider_url |
|
| 1002 | + and is_callable($callback_valider_url) |
|
| 1003 | + and !$callback_valider_url($reponse['url']) |
|
| 1004 | + ) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 1007 | + $headers = $reponse['headers'] ?? ''; |
|
| 1008 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 1009 | + if ($headers) { |
|
| 1010 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + $a['extension'] = $extension; |
|
| 1015 | + |
|
| 1016 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1017 | + $a['taille'] = intval($regs[1]); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // Echec avec HEAD, on tente avec GET |
|
| 1022 | + if (!$a and !$taille_max) { |
|
| 1023 | + spip_log("tenter GET $source", 'distant'); |
|
| 1024 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1025 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + // si on a rien trouve pas la peine d'insister |
|
| 1029 | + if (!$a) { |
|
| 1030 | + return false; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1034 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1035 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1036 | + if ( |
|
| 1037 | + strpos($mime_type, 'image/') === 0 |
|
| 1038 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1039 | + ) { |
|
| 1040 | + if ( |
|
| 1041 | + $taille_max == 0 |
|
| 1042 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1043 | + and in_array($extension, formats_image_acceptables()) |
|
| 1044 | + and $charger_si_petite_image |
|
| 1045 | + ) { |
|
| 1046 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1047 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1048 | + } else { |
|
| 1049 | + if ($a['body']) { |
|
| 1050 | + $a['extension'] = $extension; |
|
| 1051 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1052 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1053 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1054 | + $a['largeur'] = intval($size_image[0]); |
|
| 1055 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1056 | + $a['type_image'] = true; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1062 | + // ce sera mieux que 0x0 |
|
| 1063 | + // Flash is dead! |
|
| 1064 | + if ( |
|
| 1065 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1066 | + and empty($a['largeur']) |
|
| 1067 | + ) { |
|
| 1068 | + $a['largeur'] = 425; |
|
| 1069 | + $a['hauteur'] = 350; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + if ($mime_type == 'text/html') { |
|
| 1073 | + include_spip('inc/filtres'); |
|
| 1074 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1075 | + $page = $page['page'] ?? ''; |
|
| 1076 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1077 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1078 | + } |
|
| 1079 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1080 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + $a['mime_type'] = $mime_type; |
|
| 1084 | + |
|
| 1085 | + return $a; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1091,70 +1091,70 @@ discard block |
||
| 1091 | 1091 | * @return false|mixed |
| 1092 | 1092 | */ |
| 1093 | 1093 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1094 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1095 | - $mime_type = (trim($regs[1])); |
|
| 1096 | - } else { |
|
| 1097 | - $mime_type = ''; |
|
| 1098 | - } // inconnu |
|
| 1099 | - |
|
| 1100 | - // Appliquer les alias |
|
| 1101 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1102 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - // pour corriger_extension() |
|
| 1106 | - include_spip('inc/documents'); |
|
| 1107 | - |
|
| 1108 | - // Si on a un mime-type insignifiant |
|
| 1109 | - // text/plain,application/octet-stream ou vide |
|
| 1110 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1111 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1112 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1113 | - $t = null; |
|
| 1114 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1115 | - if ( |
|
| 1116 | - !$t |
|
| 1117 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1118 | - ) { |
|
| 1119 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1120 | - } |
|
| 1121 | - if ( |
|
| 1122 | - !$t |
|
| 1123 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1124 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1125 | - ) { |
|
| 1126 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1127 | - } |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1131 | - if (!$t) { |
|
| 1132 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1136 | - // On essaie de nouveau avec l'extension |
|
| 1137 | - if ( |
|
| 1138 | - !$t |
|
| 1139 | - and $mime_type != 'text/plain' |
|
| 1140 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1141 | - ) { |
|
| 1142 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1143 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if ($t) { |
|
| 1147 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1148 | - return $t['extension']; |
|
| 1149 | - } else { |
|
| 1150 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1151 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1152 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1153 | - if (!$t) { |
|
| 1154 | - return false; |
|
| 1155 | - } |
|
| 1156 | - return $t['extension']; |
|
| 1157 | - } |
|
| 1094 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1095 | + $mime_type = (trim($regs[1])); |
|
| 1096 | + } else { |
|
| 1097 | + $mime_type = ''; |
|
| 1098 | + } // inconnu |
|
| 1099 | + |
|
| 1100 | + // Appliquer les alias |
|
| 1101 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1102 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + // pour corriger_extension() |
|
| 1106 | + include_spip('inc/documents'); |
|
| 1107 | + |
|
| 1108 | + // Si on a un mime-type insignifiant |
|
| 1109 | + // text/plain,application/octet-stream ou vide |
|
| 1110 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1111 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1112 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1113 | + $t = null; |
|
| 1114 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1115 | + if ( |
|
| 1116 | + !$t |
|
| 1117 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1118 | + ) { |
|
| 1119 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1120 | + } |
|
| 1121 | + if ( |
|
| 1122 | + !$t |
|
| 1123 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1124 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1125 | + ) { |
|
| 1126 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1127 | + } |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1131 | + if (!$t) { |
|
| 1132 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1136 | + // On essaie de nouveau avec l'extension |
|
| 1137 | + if ( |
|
| 1138 | + !$t |
|
| 1139 | + and $mime_type != 'text/plain' |
|
| 1140 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1141 | + ) { |
|
| 1142 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1143 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if ($t) { |
|
| 1147 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1148 | + return $t['extension']; |
|
| 1149 | + } else { |
|
| 1150 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1151 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1152 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1153 | + if (!$t) { |
|
| 1154 | + return false; |
|
| 1155 | + } |
|
| 1156 | + return $t['extension']; |
|
| 1157 | + } |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | /** |
@@ -1170,45 +1170,45 @@ discard block |
||
| 1170 | 1170 | */ |
| 1171 | 1171 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1172 | 1172 | |
| 1173 | - $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1174 | - |
|
| 1175 | - // rien a faire si pas de proxy :) |
|
| 1176 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1177 | - return ''; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - if (is_null($http_noproxy)) { |
|
| 1181 | - $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1182 | - } |
|
| 1183 | - // si pas d'exception, on retourne le proxy |
|
| 1184 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1185 | - return $http_proxy; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1189 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1190 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1191 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1192 | - $http_noproxy = " $http_noproxy "; |
|
| 1193 | - $domain = $host; |
|
| 1194 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1195 | - if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1196 | - return ''; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - while (strpos($domain, '.') !== false) { |
|
| 1200 | - $domain = explode('.', $domain); |
|
| 1201 | - array_shift($domain); |
|
| 1202 | - $domain = implode('.', $domain); |
|
| 1203 | - |
|
| 1204 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1205 | - if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1206 | - return ''; |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - // ok c'est pas une exception |
|
| 1211 | - return $http_proxy; |
|
| 1173 | + $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1174 | + |
|
| 1175 | + // rien a faire si pas de proxy :) |
|
| 1176 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1177 | + return ''; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + if (is_null($http_noproxy)) { |
|
| 1181 | + $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1182 | + } |
|
| 1183 | + // si pas d'exception, on retourne le proxy |
|
| 1184 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1185 | + return $http_proxy; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1189 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1190 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1191 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1192 | + $http_noproxy = " $http_noproxy "; |
|
| 1193 | + $domain = $host; |
|
| 1194 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1195 | + if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1196 | + return ''; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + while (strpos($domain, '.') !== false) { |
|
| 1200 | + $domain = explode('.', $domain); |
|
| 1201 | + array_shift($domain); |
|
| 1202 | + $domain = implode('.', $domain); |
|
| 1203 | + |
|
| 1204 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1205 | + if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1206 | + return ''; |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + // ok c'est pas une exception |
|
| 1211 | + return $http_proxy; |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | |
@@ -1231,59 +1231,59 @@ discard block |
||
| 1231 | 1231 | * @return array |
| 1232 | 1232 | */ |
| 1233 | 1233 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1234 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1235 | - $fopen = false; |
|
| 1236 | - |
|
| 1237 | - $t = @parse_url($url); |
|
| 1238 | - $host = $t['host']; |
|
| 1239 | - if ($t['scheme'] == 'http') { |
|
| 1240 | - $scheme = 'http'; |
|
| 1241 | - $noproxy = ''; |
|
| 1242 | - } elseif ($t['scheme'] == 'https') { |
|
| 1243 | - $scheme = 'ssl'; |
|
| 1244 | - $noproxy = 'ssl://'; |
|
| 1245 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1246 | - $t['port'] = 443; |
|
| 1247 | - } |
|
| 1248 | - } else { |
|
| 1249 | - $scheme = $t['scheme']; |
|
| 1250 | - $noproxy = $scheme . '://'; |
|
| 1251 | - } |
|
| 1252 | - if (isset($t['user'])) { |
|
| 1253 | - $user = [$t['user'], $t['pass']]; |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1257 | - $port = 80; |
|
| 1258 | - } |
|
| 1259 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1260 | - $path = '/'; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - if (!empty($t['query'])) { |
|
| 1264 | - $path .= '?' . $t['query']; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1268 | - if (!$f or !is_resource($f)) { |
|
| 1269 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1270 | - // ce qui correspond a $f===110 |
|
| 1271 | - if ( |
|
| 1272 | - $f !== 110 |
|
| 1273 | - and !need_proxy($host) |
|
| 1274 | - and !_request('tester_proxy') |
|
| 1275 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1276 | - ) { |
|
| 1277 | - $f = @fopen($url, 'rb'); |
|
| 1278 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1279 | - $fopen = true; |
|
| 1280 | - } else { |
|
| 1281 | - // echec total |
|
| 1282 | - $f = false; |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - return [$f, $fopen]; |
|
| 1234 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1235 | + $fopen = false; |
|
| 1236 | + |
|
| 1237 | + $t = @parse_url($url); |
|
| 1238 | + $host = $t['host']; |
|
| 1239 | + if ($t['scheme'] == 'http') { |
|
| 1240 | + $scheme = 'http'; |
|
| 1241 | + $noproxy = ''; |
|
| 1242 | + } elseif ($t['scheme'] == 'https') { |
|
| 1243 | + $scheme = 'ssl'; |
|
| 1244 | + $noproxy = 'ssl://'; |
|
| 1245 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1246 | + $t['port'] = 443; |
|
| 1247 | + } |
|
| 1248 | + } else { |
|
| 1249 | + $scheme = $t['scheme']; |
|
| 1250 | + $noproxy = $scheme . '://'; |
|
| 1251 | + } |
|
| 1252 | + if (isset($t['user'])) { |
|
| 1253 | + $user = [$t['user'], $t['pass']]; |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1257 | + $port = 80; |
|
| 1258 | + } |
|
| 1259 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1260 | + $path = '/'; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + if (!empty($t['query'])) { |
|
| 1264 | + $path .= '?' . $t['query']; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1268 | + if (!$f or !is_resource($f)) { |
|
| 1269 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1270 | + // ce qui correspond a $f===110 |
|
| 1271 | + if ( |
|
| 1272 | + $f !== 110 |
|
| 1273 | + and !need_proxy($host) |
|
| 1274 | + and !_request('tester_proxy') |
|
| 1275 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1276 | + ) { |
|
| 1277 | + $f = @fopen($url, 'rb'); |
|
| 1278 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1279 | + $fopen = true; |
|
| 1280 | + } else { |
|
| 1281 | + // echec total |
|
| 1282 | + $f = false; |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + return [$f, $fopen]; |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | /** |
@@ -1318,123 +1318,123 @@ discard block |
||
| 1318 | 1318 | * resource socket vers l'url demandee |
| 1319 | 1319 | */ |
| 1320 | 1320 | function lance_requete( |
| 1321 | - $method, |
|
| 1322 | - $scheme, |
|
| 1323 | - $user, |
|
| 1324 | - $host, |
|
| 1325 | - $path, |
|
| 1326 | - $port, |
|
| 1327 | - $noproxy, |
|
| 1328 | - $refuse_gz = false, |
|
| 1329 | - $referer = '', |
|
| 1330 | - $datas = '', |
|
| 1331 | - $vers = 'HTTP/1.0', |
|
| 1332 | - $date = '' |
|
| 1321 | + $method, |
|
| 1322 | + $scheme, |
|
| 1323 | + $user, |
|
| 1324 | + $host, |
|
| 1325 | + $path, |
|
| 1326 | + $port, |
|
| 1327 | + $noproxy, |
|
| 1328 | + $refuse_gz = false, |
|
| 1329 | + $referer = '', |
|
| 1330 | + $datas = '', |
|
| 1331 | + $vers = 'HTTP/1.0', |
|
| 1332 | + $date = '' |
|
| 1333 | 1333 | ) { |
| 1334 | 1334 | |
| 1335 | - $proxy_user = ''; |
|
| 1336 | - $http_proxy = need_proxy($host); |
|
| 1337 | - if ($user) { |
|
| 1338 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - $connect = ''; |
|
| 1342 | - if ($http_proxy) { |
|
| 1343 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1344 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1345 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1346 | - . "Host: $path_host\r\n" |
|
| 1347 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1348 | - } else { |
|
| 1349 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1350 | - . (!$user ? '' : "$user@") |
|
| 1351 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1352 | - } |
|
| 1353 | - $t2 = @parse_url($http_proxy); |
|
| 1354 | - $first_host = $t2['host']; |
|
| 1355 | - $port = ($t2['port'] ?? null) ?: 80; |
|
| 1356 | - if ($t2['user'] ?? null) { |
|
| 1357 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1358 | - } |
|
| 1359 | - } else { |
|
| 1360 | - $first_host = $noproxy . $host; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - if ($connect) { |
|
| 1364 | - $streamContext = stream_context_create([ |
|
| 1365 | - 'ssl' => [ |
|
| 1366 | - 'verify_peer' => false, |
|
| 1367 | - 'allow_self_signed' => true, |
|
| 1368 | - 'SNI_enabled' => true, |
|
| 1369 | - 'peer_name' => $host, |
|
| 1370 | - ] |
|
| 1371 | - ]); |
|
| 1372 | - $f = @stream_socket_client( |
|
| 1373 | - "tcp://$first_host:$port", |
|
| 1374 | - $errno, |
|
| 1375 | - $errstr, |
|
| 1376 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | - STREAM_CLIENT_CONNECT, |
|
| 1378 | - $streamContext |
|
| 1379 | - ); |
|
| 1380 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1381 | - if (!$f) { |
|
| 1382 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | - return $errno; |
|
| 1384 | - } |
|
| 1385 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | - |
|
| 1387 | - fputs($f, $connect); |
|
| 1388 | - fputs($f, "\r\n"); |
|
| 1389 | - $res = fread($f, 1024); |
|
| 1390 | - if ( |
|
| 1391 | - !$res |
|
| 1392 | - or !count($res = explode(' ', $res)) |
|
| 1393 | - or $res[1] !== '200' |
|
| 1394 | - ) { |
|
| 1395 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | - fclose($f); |
|
| 1397 | - |
|
| 1398 | - return false; |
|
| 1399 | - } |
|
| 1400 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | - stream_set_blocking($f, true); |
|
| 1402 | - // envoyer le handshake |
|
| 1403 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1405 | - } else { |
|
| 1406 | - $ntry = 3; |
|
| 1407 | - do { |
|
| 1408 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1411 | - if (!$f) { |
|
| 1412 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | - |
|
| 1414 | - return $errno; |
|
| 1415 | - } |
|
| 1416 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | - |
|
| 1421 | - $host_port = $host; |
|
| 1422 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | - $host_port .= ":$port"; |
|
| 1424 | - } |
|
| 1425 | - $req = "$method $path $vers\r\n" |
|
| 1426 | - . "Host: $host_port\r\n" |
|
| 1427 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1335 | + $proxy_user = ''; |
|
| 1336 | + $http_proxy = need_proxy($host); |
|
| 1337 | + if ($user) { |
|
| 1338 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + $connect = ''; |
|
| 1342 | + if ($http_proxy) { |
|
| 1343 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1344 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1345 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1346 | + . "Host: $path_host\r\n" |
|
| 1347 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1348 | + } else { |
|
| 1349 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1350 | + . (!$user ? '' : "$user@") |
|
| 1351 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1352 | + } |
|
| 1353 | + $t2 = @parse_url($http_proxy); |
|
| 1354 | + $first_host = $t2['host']; |
|
| 1355 | + $port = ($t2['port'] ?? null) ?: 80; |
|
| 1356 | + if ($t2['user'] ?? null) { |
|
| 1357 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1358 | + } |
|
| 1359 | + } else { |
|
| 1360 | + $first_host = $noproxy . $host; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + if ($connect) { |
|
| 1364 | + $streamContext = stream_context_create([ |
|
| 1365 | + 'ssl' => [ |
|
| 1366 | + 'verify_peer' => false, |
|
| 1367 | + 'allow_self_signed' => true, |
|
| 1368 | + 'SNI_enabled' => true, |
|
| 1369 | + 'peer_name' => $host, |
|
| 1370 | + ] |
|
| 1371 | + ]); |
|
| 1372 | + $f = @stream_socket_client( |
|
| 1373 | + "tcp://$first_host:$port", |
|
| 1374 | + $errno, |
|
| 1375 | + $errstr, |
|
| 1376 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | + STREAM_CLIENT_CONNECT, |
|
| 1378 | + $streamContext |
|
| 1379 | + ); |
|
| 1380 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1381 | + if (!$f) { |
|
| 1382 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | + return $errno; |
|
| 1384 | + } |
|
| 1385 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | + |
|
| 1387 | + fputs($f, $connect); |
|
| 1388 | + fputs($f, "\r\n"); |
|
| 1389 | + $res = fread($f, 1024); |
|
| 1390 | + if ( |
|
| 1391 | + !$res |
|
| 1392 | + or !count($res = explode(' ', $res)) |
|
| 1393 | + or $res[1] !== '200' |
|
| 1394 | + ) { |
|
| 1395 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | + fclose($f); |
|
| 1397 | + |
|
| 1398 | + return false; |
|
| 1399 | + } |
|
| 1400 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | + stream_set_blocking($f, true); |
|
| 1402 | + // envoyer le handshake |
|
| 1403 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1405 | + } else { |
|
| 1406 | + $ntry = 3; |
|
| 1407 | + do { |
|
| 1408 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1411 | + if (!$f) { |
|
| 1412 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | + |
|
| 1414 | + return $errno; |
|
| 1415 | + } |
|
| 1416 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | + |
|
| 1421 | + $host_port = $host; |
|
| 1422 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | + $host_port .= ":$port"; |
|
| 1424 | + } |
|
| 1425 | + $req = "$method $path $vers\r\n" |
|
| 1426 | + . "Host: $host_port\r\n" |
|
| 1427 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1434 | 1434 | |
| 1435 | 1435 | # spip_log("Requete\n$req", 'distant'); |
| 1436 | - fputs($f, $req); |
|
| 1437 | - fputs($f, $datas ?: "\r\n"); |
|
| 1436 | + fputs($f, $req); |
|
| 1437 | + fputs($f, $datas ?: "\r\n"); |
|
| 1438 | 1438 | |
| 1439 | - return $f; |
|
| 1439 | + return $f; |
|
| 1440 | 1440 | } |
@@ -4,879 +4,879 @@ |
||
| 4 | 4 | // ** ne pas modifier le fichier ** |
| 5 | 5 | |
| 6 | 6 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 7 | - return; |
|
| 7 | + return; |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $GLOBALS[$GLOBALS['idx_lang']] = array( |
| 11 | 11 | |
| 12 | - // A |
|
| 13 | - 'activer_plugin' => 'Ativar o plugin', |
|
| 14 | - 'affichage' => 'Exibição', |
|
| 15 | - 'aide_non_disponible' => 'Esta parte da ajuda online ainda não está disponível neste idioma.', |
|
| 16 | - 'annuler_recherche' => 'Cancelar a busca', |
|
| 17 | - 'auteur' => 'Autor:', |
|
| 18 | - 'avis_acces_interdit' => 'Acesso negado.', |
|
| 19 | - 'avis_acces_interdit_prive' => 'Você não está autorizado a acessar a página <b>@exec@</b>.', |
|
| 20 | - 'avis_article_modifie' => 'Atenção, @nom_auteur_modif@ editou esta matéria há @date_diff@ minutos', |
|
| 21 | - 'avis_aucun_resultat' => 'Nenhum resultado.', |
|
| 22 | - 'avis_base_inaccessible' => 'Não foi possível conectar com a base de dados @base@.', |
|
| 23 | - 'avis_chemin_invalide_1' => 'O caminho que você escolheu', |
|
| 24 | - 'avis_chemin_invalide_2' => 'não parece válido. Por favor, volte à página anterior e verifique as informações fornecidas.', |
|
| 25 | - 'avis_connexion_echec_1' => 'A conexão com a base de dados falhou.', |
|
| 26 | - 'avis_connexion_echec_2' => 'Volte à página anterior e verifique as informações que você forneceu.', |
|
| 27 | - 'avis_connexion_echec_3' => '<b>N.B.</b> Em diversos servidores, você precisa <b>solicitar</b> a ativação do seu acesso à base de dados antes de poder utilizá-la. Se você não consegue se conectar, verifique se você efetuou esse pedido.', |
|
| 28 | - 'avis_connexion_erreur_creer_base' => 'Não foi possível criar a base de dados.', |
|
| 29 | - 'avis_connexion_erreur_fichier_cle_manquant_1' => 'A instalação deve ser realizada por um webmaster com um backup das chaves e sua senha.', |
|
| 30 | - 'avis_connexion_erreur_fichier_cle_manquant_2' => 'A instalação deve ser feita por um webmaster com um backup das chaves', |
|
| 31 | - 'avis_connexion_erreur_nom_base' => 'O nome da base só pode conter letras, números e traços', |
|
| 32 | - 'avis_connexion_ldap_echec_1' => 'A conexão ao servidor LDAP falhou.', |
|
| 33 | - 'avis_connexion_ldap_echec_2' => 'Volte à página anterior e verifique as informações que você forneceu.', |
|
| 34 | - 'avis_connexion_ldap_echec_3' => 'Opcionalmente, não use o suporte LDAP para importar os usuários.', |
|
| 35 | - 'avis_deplacement_rubrique' => 'Atenção! Esta seção contém @contient_breves@ nota@scb@: se você a transferir, por favor, marque este quadrado.', |
|
| 36 | - 'avis_erreur_connexion_mysql' => 'Erro de conexão SQL', |
|
| 37 | - 'avis_erreur_creation_compte' => 'Erro durante a inicialização da conta', |
|
| 38 | - 'avis_espace_interdit' => '<b>Área interdita</b> <div>O SPIP já está instalado.</div>', |
|
| 39 | - 'avis_lecture_noms_bases_1' => 'O programa de instalação não pôde ler os nomes das bases de dados instaladas.', |
|
| 40 | - 'avis_lecture_noms_bases_2' => 'Ou nenhuma base de dados esta disponível, ou a função que permite listar as bases foi desativada por razões de segurança (o que é o caso de diversos provedores de hospedagem).', |
|
| 41 | - 'avis_lecture_noms_bases_3' => 'No segundo caso, é provável que uma base de dados com o nome do seu login possa ser utilizada:', |
|
| 42 | - 'avis_non_acces_page' => 'Você não tem acesso a esta página.', |
|
| 43 | - 'avis_operation_echec' => 'A operação falhou.', |
|
| 44 | - 'avis_operation_impossible' => 'Operação impossível', |
|
| 45 | - 'avis_suppression_base' => 'ATENÇÃO, a supressão dos dados é irreversível', |
|
| 12 | + // A |
|
| 13 | + 'activer_plugin' => 'Ativar o plugin', |
|
| 14 | + 'affichage' => 'Exibição', |
|
| 15 | + 'aide_non_disponible' => 'Esta parte da ajuda online ainda não está disponível neste idioma.', |
|
| 16 | + 'annuler_recherche' => 'Cancelar a busca', |
|
| 17 | + 'auteur' => 'Autor:', |
|
| 18 | + 'avis_acces_interdit' => 'Acesso negado.', |
|
| 19 | + 'avis_acces_interdit_prive' => 'Você não está autorizado a acessar a página <b>@exec@</b>.', |
|
| 20 | + 'avis_article_modifie' => 'Atenção, @nom_auteur_modif@ editou esta matéria há @date_diff@ minutos', |
|
| 21 | + 'avis_aucun_resultat' => 'Nenhum resultado.', |
|
| 22 | + 'avis_base_inaccessible' => 'Não foi possível conectar com a base de dados @base@.', |
|
| 23 | + 'avis_chemin_invalide_1' => 'O caminho que você escolheu', |
|
| 24 | + 'avis_chemin_invalide_2' => 'não parece válido. Por favor, volte à página anterior e verifique as informações fornecidas.', |
|
| 25 | + 'avis_connexion_echec_1' => 'A conexão com a base de dados falhou.', |
|
| 26 | + 'avis_connexion_echec_2' => 'Volte à página anterior e verifique as informações que você forneceu.', |
|
| 27 | + 'avis_connexion_echec_3' => '<b>N.B.</b> Em diversos servidores, você precisa <b>solicitar</b> a ativação do seu acesso à base de dados antes de poder utilizá-la. Se você não consegue se conectar, verifique se você efetuou esse pedido.', |
|
| 28 | + 'avis_connexion_erreur_creer_base' => 'Não foi possível criar a base de dados.', |
|
| 29 | + 'avis_connexion_erreur_fichier_cle_manquant_1' => 'A instalação deve ser realizada por um webmaster com um backup das chaves e sua senha.', |
|
| 30 | + 'avis_connexion_erreur_fichier_cle_manquant_2' => 'A instalação deve ser feita por um webmaster com um backup das chaves', |
|
| 31 | + 'avis_connexion_erreur_nom_base' => 'O nome da base só pode conter letras, números e traços', |
|
| 32 | + 'avis_connexion_ldap_echec_1' => 'A conexão ao servidor LDAP falhou.', |
|
| 33 | + 'avis_connexion_ldap_echec_2' => 'Volte à página anterior e verifique as informações que você forneceu.', |
|
| 34 | + 'avis_connexion_ldap_echec_3' => 'Opcionalmente, não use o suporte LDAP para importar os usuários.', |
|
| 35 | + 'avis_deplacement_rubrique' => 'Atenção! Esta seção contém @contient_breves@ nota@scb@: se você a transferir, por favor, marque este quadrado.', |
|
| 36 | + 'avis_erreur_connexion_mysql' => 'Erro de conexão SQL', |
|
| 37 | + 'avis_erreur_creation_compte' => 'Erro durante a inicialização da conta', |
|
| 38 | + 'avis_espace_interdit' => '<b>Área interdita</b> <div>O SPIP já está instalado.</div>', |
|
| 39 | + 'avis_lecture_noms_bases_1' => 'O programa de instalação não pôde ler os nomes das bases de dados instaladas.', |
|
| 40 | + 'avis_lecture_noms_bases_2' => 'Ou nenhuma base de dados esta disponível, ou a função que permite listar as bases foi desativada por razões de segurança (o que é o caso de diversos provedores de hospedagem).', |
|
| 41 | + 'avis_lecture_noms_bases_3' => 'No segundo caso, é provável que uma base de dados com o nome do seu login possa ser utilizada:', |
|
| 42 | + 'avis_non_acces_page' => 'Você não tem acesso a esta página.', |
|
| 43 | + 'avis_operation_echec' => 'A operação falhou.', |
|
| 44 | + 'avis_operation_impossible' => 'Operação impossível', |
|
| 45 | + 'avis_suppression_base' => 'ATENÇÃO, a supressão dos dados é irreversível', |
|
| 46 | 46 | |
| 47 | - // B |
|
| 48 | - 'bouton_acces_ldap' => 'Incluir o acesso ao LDAP', |
|
| 49 | - 'bouton_ajouter' => 'Incluir', |
|
| 50 | - 'bouton_annuler' => 'Anular', |
|
| 51 | - 'bouton_cache_activer' => 'Reativar o cache', |
|
| 52 | - 'bouton_cache_desactiver' => 'Desativar temporariamente o cache', |
|
| 53 | - 'bouton_demande_publication' => 'Solicitar a publicação desta matéria', |
|
| 54 | - 'bouton_desactive_tout' => 'Desativar tudo', |
|
| 55 | - 'bouton_desinstaller' => 'Desinstalar', |
|
| 56 | - 'bouton_effacer_tout' => 'Apagar TUDO', |
|
| 57 | - 'bouton_envoyer_message' => 'Mensagem definitiva: enviar', |
|
| 58 | - 'bouton_fermer' => 'Fechar', |
|
| 59 | - 'bouton_mettre_a_jour_base' => 'Atualizar a base de dados', |
|
| 60 | - 'bouton_modifier' => 'Alterar', |
|
| 61 | - 'bouton_radio_afficher' => 'Exibir', |
|
| 62 | - 'bouton_radio_apparaitre_liste_redacteurs_connectes' => 'Exibir nas listas de redatores conectados', |
|
| 63 | - 'bouton_radio_envoi_annonces_adresse' => 'Enviar os avisos para o endereço:', |
|
| 64 | - 'bouton_radio_envoi_liste_nouveautes' => 'Enviar a lista de novidades', |
|
| 65 | - 'bouton_radio_non_apparaitre_liste_redacteurs_connectes' => 'Não exibir na lista de redatores', |
|
| 66 | - 'bouton_radio_non_envoi_annonces_editoriales' => 'Não enviar os avisos editoriais', |
|
| 67 | - 'bouton_redirection' => 'REDIRECIONAMENTO', |
|
| 68 | - 'bouton_reinitialiser_aux_valeurs_par_defaut' => 'Reiniciar aos valores padrão', |
|
| 69 | - 'bouton_relancer_inscription' => 'Reiniciar o registro', |
|
| 70 | - 'bouton_relancer_inscriptions' => 'Reiniciar os registros', |
|
| 71 | - 'bouton_relancer_installation' => 'Reiniciar a instalação', |
|
| 72 | - 'bouton_reset_password' => 'Criar uma nova senha e enviá-la por e-mail', |
|
| 73 | - 'bouton_suivant' => 'Avançar', |
|
| 74 | - 'bouton_tenter_recuperation' => 'Tentar uma reparação', |
|
| 75 | - 'bouton_test_proxy' => 'Testar o proxy', |
|
| 76 | - 'bouton_vider_cache' => 'Limpar o cache', |
|
| 47 | + // B |
|
| 48 | + 'bouton_acces_ldap' => 'Incluir o acesso ao LDAP', |
|
| 49 | + 'bouton_ajouter' => 'Incluir', |
|
| 50 | + 'bouton_annuler' => 'Anular', |
|
| 51 | + 'bouton_cache_activer' => 'Reativar o cache', |
|
| 52 | + 'bouton_cache_desactiver' => 'Desativar temporariamente o cache', |
|
| 53 | + 'bouton_demande_publication' => 'Solicitar a publicação desta matéria', |
|
| 54 | + 'bouton_desactive_tout' => 'Desativar tudo', |
|
| 55 | + 'bouton_desinstaller' => 'Desinstalar', |
|
| 56 | + 'bouton_effacer_tout' => 'Apagar TUDO', |
|
| 57 | + 'bouton_envoyer_message' => 'Mensagem definitiva: enviar', |
|
| 58 | + 'bouton_fermer' => 'Fechar', |
|
| 59 | + 'bouton_mettre_a_jour_base' => 'Atualizar a base de dados', |
|
| 60 | + 'bouton_modifier' => 'Alterar', |
|
| 61 | + 'bouton_radio_afficher' => 'Exibir', |
|
| 62 | + 'bouton_radio_apparaitre_liste_redacteurs_connectes' => 'Exibir nas listas de redatores conectados', |
|
| 63 | + 'bouton_radio_envoi_annonces_adresse' => 'Enviar os avisos para o endereço:', |
|
| 64 | + 'bouton_radio_envoi_liste_nouveautes' => 'Enviar a lista de novidades', |
|
| 65 | + 'bouton_radio_non_apparaitre_liste_redacteurs_connectes' => 'Não exibir na lista de redatores', |
|
| 66 | + 'bouton_radio_non_envoi_annonces_editoriales' => 'Não enviar os avisos editoriais', |
|
| 67 | + 'bouton_redirection' => 'REDIRECIONAMENTO', |
|
| 68 | + 'bouton_reinitialiser_aux_valeurs_par_defaut' => 'Reiniciar aos valores padrão', |
|
| 69 | + 'bouton_relancer_inscription' => 'Reiniciar o registro', |
|
| 70 | + 'bouton_relancer_inscriptions' => 'Reiniciar os registros', |
|
| 71 | + 'bouton_relancer_installation' => 'Reiniciar a instalação', |
|
| 72 | + 'bouton_reset_password' => 'Criar uma nova senha e enviá-la por e-mail', |
|
| 73 | + 'bouton_suivant' => 'Avançar', |
|
| 74 | + 'bouton_tenter_recuperation' => 'Tentar uma reparação', |
|
| 75 | + 'bouton_test_proxy' => 'Testar o proxy', |
|
| 76 | + 'bouton_vider_cache' => 'Limpar o cache', |
|
| 77 | 77 | |
| 78 | - // C |
|
| 79 | - 'cache_modifiable_webmestre' => 'Este parâmetro é modificável pelo webmaster do site.', |
|
| 80 | - 'calendrier_synchro' => 'Se você usa um programa de agenda compatível com <b>iCal</b>, você pode sincronizá-lo com as informações deste site.', |
|
| 81 | - 'config_activer_champs' => 'Ativar os campos a seguir', |
|
| 82 | - 'config_choix_base_sup' => 'indicar uma base neste servidor', |
|
| 83 | - 'config_erreur_base_sup' => 'O SPIP não tem acesso à lista de bases acessíveis', |
|
| 84 | - 'config_info_base_sup' => 'Se você tiver outras bases de dados para serem consultadas via SPIP, em seu servidor SQL ou em outro, o formulário abaixo permite configurá-las. Se você deixar determinados campos em branco, os dados de conexão da base principal serão utilizados.', |
|
| 85 | - 'config_info_base_sup_disponibles' => 'Bases suplementares já consultáveis:', |
|
| 86 | - 'config_info_enregistree' => 'A nova configuração foi gravada', |
|
| 87 | - 'config_info_logos' => 'Cada elemento do site pode ter um ícone, bem como um ícone de «mouseOver»', |
|
| 88 | - 'config_info_logos_utiliser' => 'Usar os ícones', |
|
| 89 | - 'config_info_logos_utiliser_non' => 'Não usar o ícones', |
|
| 90 | - 'config_info_logos_utiliser_survol' => 'Usar os ícones de mouseOver', |
|
| 91 | - 'config_info_logos_utiliser_survol_non' => 'Não usar os ícones de mouseOver', |
|
| 92 | - 'config_info_redirection' => 'Ao ativar esta opção, você poderá criar matérias virtuais, meras referências a matérias publicadas em outros sites ou fora do SPIP.', |
|
| 93 | - 'config_redirection' => 'Matérias virtuais', |
|
| 94 | - 'config_titre_base_sup' => 'Configuração de uma base suplementar', |
|
| 95 | - 'config_titre_base_sup_choix' => 'Escolha uma base suplementar', |
|
| 96 | - 'connexion_ldap' => 'Conexão:', |
|
| 97 | - 'creer_et_associer_un_auteur' => 'Criar e vincular um autor', |
|
| 78 | + // C |
|
| 79 | + 'cache_modifiable_webmestre' => 'Este parâmetro é modificável pelo webmaster do site.', |
|
| 80 | + 'calendrier_synchro' => 'Se você usa um programa de agenda compatível com <b>iCal</b>, você pode sincronizá-lo com as informações deste site.', |
|
| 81 | + 'config_activer_champs' => 'Ativar os campos a seguir', |
|
| 82 | + 'config_choix_base_sup' => 'indicar uma base neste servidor', |
|
| 83 | + 'config_erreur_base_sup' => 'O SPIP não tem acesso à lista de bases acessíveis', |
|
| 84 | + 'config_info_base_sup' => 'Se você tiver outras bases de dados para serem consultadas via SPIP, em seu servidor SQL ou em outro, o formulário abaixo permite configurá-las. Se você deixar determinados campos em branco, os dados de conexão da base principal serão utilizados.', |
|
| 85 | + 'config_info_base_sup_disponibles' => 'Bases suplementares já consultáveis:', |
|
| 86 | + 'config_info_enregistree' => 'A nova configuração foi gravada', |
|
| 87 | + 'config_info_logos' => 'Cada elemento do site pode ter um ícone, bem como um ícone de «mouseOver»', |
|
| 88 | + 'config_info_logos_utiliser' => 'Usar os ícones', |
|
| 89 | + 'config_info_logos_utiliser_non' => 'Não usar o ícones', |
|
| 90 | + 'config_info_logos_utiliser_survol' => 'Usar os ícones de mouseOver', |
|
| 91 | + 'config_info_logos_utiliser_survol_non' => 'Não usar os ícones de mouseOver', |
|
| 92 | + 'config_info_redirection' => 'Ao ativar esta opção, você poderá criar matérias virtuais, meras referências a matérias publicadas em outros sites ou fora do SPIP.', |
|
| 93 | + 'config_redirection' => 'Matérias virtuais', |
|
| 94 | + 'config_titre_base_sup' => 'Configuração de uma base suplementar', |
|
| 95 | + 'config_titre_base_sup_choix' => 'Escolha uma base suplementar', |
|
| 96 | + 'connexion_ldap' => 'Conexão:', |
|
| 97 | + 'creer_et_associer_un_auteur' => 'Criar e vincular um autor', |
|
| 98 | 98 | |
| 99 | - // D |
|
| 100 | - 'date_mot_heures' => 'horas', |
|
| 99 | + // D |
|
| 100 | + 'date_mot_heures' => 'horas', |
|
| 101 | 101 | |
| 102 | - // E |
|
| 103 | - 'ecran_connexion_couleur_principale' => 'Cor principal', |
|
| 104 | - 'ecran_connexion_image_fond' => 'Imagem de fundo', |
|
| 105 | - 'ecran_connexion_image_fond_explication' => 'Usar uma imagem (formato JPEG, 1920x1080 pixels)', |
|
| 106 | - 'ecran_connexion_image_revenir_couleur_defaut' => 'Reverter para a cor padrão', |
|
| 107 | - 'ecran_connexion_titre' => 'Tela de conexão', |
|
| 108 | - 'ecran_securite' => ' + tela de segurança @version@', |
|
| 109 | - 'email' => 'e-mail', |
|
| 110 | - 'email_2' => 'e-mail:', |
|
| 111 | - 'en_savoir_plus' => 'Saiba mais', |
|
| 112 | - 'entree_adresse_annuaire' => 'Endereço do catálogo', |
|
| 113 | - 'entree_adresse_email' => 'Seu endereço de e-mail', |
|
| 114 | - 'entree_adresse_email_2' => 'Endereço de e-mail', |
|
| 115 | - 'entree_base_donnee_1' => 'Endereço da base de dados', |
|
| 116 | - 'entree_base_donnee_2' => '(Frequentemente este endereço corresponde ao do seu site, às vezes ele corresponde ao nome «localhost», algumas vezes ele pode ser deixado completamente em branco.)', |
|
| 117 | - 'entree_biographie' => 'Biografia curta em poucas palavras.', |
|
| 118 | - 'entree_chemin_acces' => '<b>Informe</b> o caminho de acesso:', |
|
| 119 | - 'entree_cle_pgp' => 'Sua chave PGP', |
|
| 120 | - 'entree_cle_pgp_2' => 'Chave PGP', |
|
| 121 | - 'entree_contenu_rubrique' => '(Conteúdo da seção em poucas palavras.)', |
|
| 122 | - 'entree_identifiants_connexion' => 'Seus dados de conexão...', |
|
| 123 | - 'entree_identifiants_connexion_2' => 'Dados de conexão', |
|
| 124 | - 'entree_informations_connexion_ldap' => 'Informe neste formulário os dados de conexão ao seu catálogo LDAP. |
|
| 102 | + // E |
|
| 103 | + 'ecran_connexion_couleur_principale' => 'Cor principal', |
|
| 104 | + 'ecran_connexion_image_fond' => 'Imagem de fundo', |
|
| 105 | + 'ecran_connexion_image_fond_explication' => 'Usar uma imagem (formato JPEG, 1920x1080 pixels)', |
|
| 106 | + 'ecran_connexion_image_revenir_couleur_defaut' => 'Reverter para a cor padrão', |
|
| 107 | + 'ecran_connexion_titre' => 'Tela de conexão', |
|
| 108 | + 'ecran_securite' => ' + tela de segurança @version@', |
|
| 109 | + 'email' => 'e-mail', |
|
| 110 | + 'email_2' => 'e-mail:', |
|
| 111 | + 'en_savoir_plus' => 'Saiba mais', |
|
| 112 | + 'entree_adresse_annuaire' => 'Endereço do catálogo', |
|
| 113 | + 'entree_adresse_email' => 'Seu endereço de e-mail', |
|
| 114 | + 'entree_adresse_email_2' => 'Endereço de e-mail', |
|
| 115 | + 'entree_base_donnee_1' => 'Endereço da base de dados', |
|
| 116 | + 'entree_base_donnee_2' => '(Frequentemente este endereço corresponde ao do seu site, às vezes ele corresponde ao nome «localhost», algumas vezes ele pode ser deixado completamente em branco.)', |
|
| 117 | + 'entree_biographie' => 'Biografia curta em poucas palavras.', |
|
| 118 | + 'entree_chemin_acces' => '<b>Informe</b> o caminho de acesso:', |
|
| 119 | + 'entree_cle_pgp' => 'Sua chave PGP', |
|
| 120 | + 'entree_cle_pgp_2' => 'Chave PGP', |
|
| 121 | + 'entree_contenu_rubrique' => '(Conteúdo da seção em poucas palavras.)', |
|
| 122 | + 'entree_identifiants_connexion' => 'Seus dados de conexão...', |
|
| 123 | + 'entree_identifiants_connexion_2' => 'Dados de conexão', |
|
| 124 | + 'entree_informations_connexion_ldap' => 'Informe neste formulário os dados de conexão ao seu catálogo LDAP. |
|
| 125 | 125 | Estas informações deverão ser fornecidas pelo administrador do sistema ou da rede.', |
| 126 | - 'entree_infos_perso' => 'Quem é você?', |
|
| 127 | - 'entree_infos_perso_2' => 'Quem é o autor?', |
|
| 128 | - 'entree_interieur_rubrique' => 'No interior da seção:', |
|
| 129 | - 'entree_liens_sites' => '<b>Link hipertexto</b> (referência, site a visitar...)', |
|
| 130 | - 'entree_login' => 'Seu login', |
|
| 131 | - 'entree_login_connexion_1' => 'O login de conexão', |
|
| 132 | - 'entree_login_connexion_2' => '(Frequentemente corresponde ao seu login para acesso por FTP; às vezes pode ser deixado em branco)', |
|
| 133 | - 'entree_mot_passe' => 'Sua senha', |
|
| 134 | - 'entree_mot_passe_1' => 'A senha de conexão', |
|
| 135 | - 'entree_mot_passe_2' => '(Frequentemente corresponde à sua senha para acesso por FTP; às vezes pode ser deixado em branco)', |
|
| 136 | - 'entree_nom_fichier' => 'Por favor, informe o nome do arquivo @texte_compresse@:', |
|
| 137 | - 'entree_nom_pseudo' => 'Seu nome ou apelido', |
|
| 138 | - 'entree_nom_pseudo_1' => '(Seu nome ou apelido)', |
|
| 139 | - 'entree_nom_pseudo_2' => 'Nome ou apelido', |
|
| 140 | - 'entree_nom_site' => 'O nome do seu site', |
|
| 141 | - 'entree_nom_site_2' => 'Nome do site do autor', |
|
| 142 | - 'entree_nouveau_passe' => 'Nova senha', |
|
| 143 | - 'entree_passe_ldap' => 'Senha', |
|
| 144 | - 'entree_port_annuaire' => 'O número da porta do catálogo', |
|
| 145 | - 'entree_signature' => 'Assinatura', |
|
| 146 | - 'entree_titre_obligatoire' => '<b>Título</b> [Obrigatório]<br />', |
|
| 147 | - 'entree_url' => 'O endereço (URL) do seu site', |
|
| 148 | - 'entree_url_2' => 'Endereço (URL) do site', |
|
| 149 | - 'erreur_connect_deja_existant' => 'Já existe um servidor com esse nome', |
|
| 150 | - 'erreur_contenu_suspect' => 'Texto escapado', |
|
| 151 | - 'erreur_email_deja_existant' => 'Esse endereço de email já está em uso.', |
|
| 152 | - 'erreur_nom_connect_incorrect' => 'Este nome de servidor não é autorizado', |
|
| 153 | - 'erreur_plugin_attribut_balise_manquant' => 'Atributo @attribut@ faltando no tag @balise@.', |
|
| 154 | - 'erreur_plugin_desinstalation_echouee' => 'A desinstalação do plugin falhou. No entanto, você pode desativá-lo.', |
|
| 155 | - 'erreur_plugin_fichier_absent' => 'Arquivo ausente', |
|
| 156 | - 'erreur_plugin_fichier_def_absent' => 'Arquivo de definição ausente', |
|
| 157 | - 'erreur_plugin_nom_fonction_interdit' => 'Nome de função não permitido', |
|
| 158 | - 'erreur_plugin_nom_manquant' => 'Nome do plugin ausente', |
|
| 159 | - 'erreur_plugin_prefix_manquant' => 'Área de nomeação do plugin não definida', |
|
| 160 | - 'erreur_plugin_tag_plugin_absent' => '<plugin> ausente no arquivo de definição', |
|
| 161 | - 'erreur_plugin_version_manquant' => 'Versão do plugin ausente', |
|
| 162 | - 'erreur_type_fichier' => 'Tipo de arquivo incorreto', |
|
| 126 | + 'entree_infos_perso' => 'Quem é você?', |
|
| 127 | + 'entree_infos_perso_2' => 'Quem é o autor?', |
|
| 128 | + 'entree_interieur_rubrique' => 'No interior da seção:', |
|
| 129 | + 'entree_liens_sites' => '<b>Link hipertexto</b> (referência, site a visitar...)', |
|
| 130 | + 'entree_login' => 'Seu login', |
|
| 131 | + 'entree_login_connexion_1' => 'O login de conexão', |
|
| 132 | + 'entree_login_connexion_2' => '(Frequentemente corresponde ao seu login para acesso por FTP; às vezes pode ser deixado em branco)', |
|
| 133 | + 'entree_mot_passe' => 'Sua senha', |
|
| 134 | + 'entree_mot_passe_1' => 'A senha de conexão', |
|
| 135 | + 'entree_mot_passe_2' => '(Frequentemente corresponde à sua senha para acesso por FTP; às vezes pode ser deixado em branco)', |
|
| 136 | + 'entree_nom_fichier' => 'Por favor, informe o nome do arquivo @texte_compresse@:', |
|
| 137 | + 'entree_nom_pseudo' => 'Seu nome ou apelido', |
|
| 138 | + 'entree_nom_pseudo_1' => '(Seu nome ou apelido)', |
|
| 139 | + 'entree_nom_pseudo_2' => 'Nome ou apelido', |
|
| 140 | + 'entree_nom_site' => 'O nome do seu site', |
|
| 141 | + 'entree_nom_site_2' => 'Nome do site do autor', |
|
| 142 | + 'entree_nouveau_passe' => 'Nova senha', |
|
| 143 | + 'entree_passe_ldap' => 'Senha', |
|
| 144 | + 'entree_port_annuaire' => 'O número da porta do catálogo', |
|
| 145 | + 'entree_signature' => 'Assinatura', |
|
| 146 | + 'entree_titre_obligatoire' => '<b>Título</b> [Obrigatório]<br />', |
|
| 147 | + 'entree_url' => 'O endereço (URL) do seu site', |
|
| 148 | + 'entree_url_2' => 'Endereço (URL) do site', |
|
| 149 | + 'erreur_connect_deja_existant' => 'Já existe um servidor com esse nome', |
|
| 150 | + 'erreur_contenu_suspect' => 'Texto escapado', |
|
| 151 | + 'erreur_email_deja_existant' => 'Esse endereço de email já está em uso.', |
|
| 152 | + 'erreur_nom_connect_incorrect' => 'Este nome de servidor não é autorizado', |
|
| 153 | + 'erreur_plugin_attribut_balise_manquant' => 'Atributo @attribut@ faltando no tag @balise@.', |
|
| 154 | + 'erreur_plugin_desinstalation_echouee' => 'A desinstalação do plugin falhou. No entanto, você pode desativá-lo.', |
|
| 155 | + 'erreur_plugin_fichier_absent' => 'Arquivo ausente', |
|
| 156 | + 'erreur_plugin_fichier_def_absent' => 'Arquivo de definição ausente', |
|
| 157 | + 'erreur_plugin_nom_fonction_interdit' => 'Nome de função não permitido', |
|
| 158 | + 'erreur_plugin_nom_manquant' => 'Nome do plugin ausente', |
|
| 159 | + 'erreur_plugin_prefix_manquant' => 'Área de nomeação do plugin não definida', |
|
| 160 | + 'erreur_plugin_tag_plugin_absent' => '<plugin> ausente no arquivo de definição', |
|
| 161 | + 'erreur_plugin_version_manquant' => 'Versão do plugin ausente', |
|
| 162 | + 'erreur_type_fichier' => 'Tipo de arquivo incorreto', |
|
| 163 | 163 | |
| 164 | - // H |
|
| 165 | - 'htaccess_a_simuler' => 'Aviso: a configuração do seu servidor HTTP não leva em conta os arquivos @htaccess@. Para poder garantir um bom nível de segurança, é preciso que você altere esta configuração, ou que as constantes @constantes@ (definíveis no arquivo mes_options.php) tenham como valor os diretórios abaixo de @document_root@.', |
|
| 166 | - 'htaccess_inoperant' => 'htaccess inoperante', |
|
| 164 | + // H |
|
| 165 | + 'htaccess_a_simuler' => 'Aviso: a configuração do seu servidor HTTP não leva em conta os arquivos @htaccess@. Para poder garantir um bom nível de segurança, é preciso que você altere esta configuração, ou que as constantes @constantes@ (definíveis no arquivo mes_options.php) tenham como valor os diretórios abaixo de @document_root@.', |
|
| 166 | + 'htaccess_inoperant' => 'htaccess inoperante', |
|
| 167 | 167 | |
| 168 | - // I |
|
| 169 | - 'ical_info1' => 'Esta página apresenta diversos métodos para se manter a par da atividade deste site.', |
|
| 170 | - 'ical_info2' => 'Para mais informações sobre todas estas técnicas, não deixe de consultar <a href="@spipnet@">a documentação do SPIP</a>.', |
|
| 171 | - 'ical_info_calendrier' => 'Dois calendários estão à sua disposição. O primeiro é um mapa do site anunciando todas as matérias publicadas. O segundo contém os avisos editoriais bem como suas últimas mensagens privadas: ele lhe é reservado graças a uma chave pessoal, que você pode alterar a qualquer momento ao renovar a sua senha.', |
|
| 172 | - 'ical_methode_http' => 'Transferência', |
|
| 173 | - 'ical_methode_webcal' => 'Sincronização (webcal://)', |
|
| 174 | - 'ical_texte_prive' => 'Este calendário, de uso estritamente pessoal, o informa sobre a atividade editorial privada deste site (tarefas e encontros pessoais, matérias e notas propostas...).', |
|
| 175 | - 'ical_texte_public' => 'Este calendário permite-lhe acompanhar a atividade pública deste site (matérias e notas publicadas).', |
|
| 176 | - 'ical_texte_rss' => 'Você pode sindicar as novidades deste site em qualquer leitor de arquivos em formato XML/RSS (Rich Site Summary). É também o formato que permite ao SPIP ler as novidades publicadas em outros sites que utilizem um formato de troca de informações compatível (sites sindicados).', |
|
| 177 | - 'ical_titre_js' => 'Javascript', |
|
| 178 | - 'ical_titre_mailing' => 'Mailing-list', |
|
| 179 | - 'ical_titre_rss' => 'Arquivos de sindicação', |
|
| 180 | - 'icone_accueil' => 'Página Inicial', |
|
| 181 | - 'icone_activer_cookie' => 'Ativar o coockie de correspondência', |
|
| 182 | - 'icone_activite' => 'Atividade', |
|
| 183 | - 'icone_admin_plugin' => 'Gerenciamento dos plugins', |
|
| 184 | - 'icone_administration' => 'Manutenção', |
|
| 185 | - 'icone_afficher_auteurs' => 'Exibir os autores', |
|
| 186 | - 'icone_afficher_visiteurs' => 'Exibir os visitantes', |
|
| 187 | - 'icone_arret_discussion' => 'Não participar mais desta discussão', |
|
| 188 | - 'icone_calendrier' => 'Calendário', |
|
| 189 | - 'icone_configuration' => 'Configuração', |
|
| 190 | - 'icone_creer_auteur' => 'Criar um novo autor e vinculá-lo a esta matéria', |
|
| 191 | - 'icone_creer_mot_cle' => 'Criar uma nova palavra-chave e vinculá-la a esta matéria', |
|
| 192 | - 'icone_creer_rubrique_2' => 'Criar uma nova seção', |
|
| 193 | - 'icone_developpement' => 'Desenvolvimento', |
|
| 194 | - 'icone_edition' => 'Edição', |
|
| 195 | - 'icone_ma_langue' => 'Meu idioma', |
|
| 196 | - 'icone_mes_infos' => 'Minhas informações', |
|
| 197 | - 'icone_mes_preferences' => 'Minhas preferências', |
|
| 198 | - 'icone_modifier_article' => 'Editar esta matéria', |
|
| 199 | - 'icone_modifier_rubrique' => 'Editar esta seção', |
|
| 200 | - 'icone_publication' => 'Publicação', |
|
| 201 | - 'icone_relancer_signataire' => 'Reconfirmar o assinante', |
|
| 202 | - 'icone_retour' => 'Voltar', |
|
| 203 | - 'icone_retour_article' => 'Voltar para a matéria', |
|
| 204 | - 'icone_squelette' => 'Templates', |
|
| 205 | - 'icone_suivi_publication' => 'Acompanhamento da publicação', |
|
| 206 | - 'icone_supprimer_cookie' => 'Excluir o cookie de correspondência', |
|
| 207 | - 'icone_supprimer_rubrique' => 'Excluir esta seção', |
|
| 208 | - 'icone_supprimer_signature' => 'Excluir esta assinatura', |
|
| 209 | - 'icone_valider_signature' => 'Validar esta assinatura', |
|
| 210 | - 'image_administrer_rubrique' => 'Você pode administrar esta seção', |
|
| 211 | - 'impossible_modifier_login_auteur' => 'Não foi possível alterar o login.', |
|
| 212 | - 'impossible_modifier_pass_auteur' => 'Não foi possível alterar a senha.', |
|
| 213 | - 'info_1_article' => '1 matéria', |
|
| 214 | - 'info_1_auteur' => '1 autor', |
|
| 215 | - 'info_1_message' => '1 mensagem', |
|
| 216 | - 'info_1_mot_cle' => '1 palavra-chave', |
|
| 217 | - 'info_1_rubrique' => '1 seção', |
|
| 218 | - 'info_1_visiteur' => '1 visitante', |
|
| 219 | - 'info_activer_cookie' => 'Você pode ativar um <b>cookie de correspondência</b>, que lhe permitirá passar facilmente do site público para o site privado.', |
|
| 220 | - 'info_activer_menu_developpement' => 'Exibir o menu Desenvolvimento', |
|
| 221 | - 'info_admin_etre_webmestre' => 'Me conceder direitos de webmaster', |
|
| 222 | - 'info_admin_je_suis_webmestre' => 'Eu sou <b>webmaster</b>', |
|
| 223 | - 'info_admin_statuer_webmestre' => 'Dar a este administrador os direitos de webmaster', |
|
| 224 | - 'info_admin_webmestre' => 'Este administrador é <b>webmaster</b>', |
|
| 225 | - 'info_administrateur' => 'Administrador', |
|
| 226 | - 'info_administrateur_1' => 'Administrador', |
|
| 227 | - 'info_administrateur_2' => 'do site (<i>use com cuidado</i>)', |
|
| 228 | - 'info_administrateur_site_01' => 'Se você é administrador do site, por favor,', |
|
| 229 | - 'info_administrateur_site_02' => 'clique neste link', |
|
| 230 | - 'info_administrateurs' => 'Administradores', |
|
| 231 | - 'info_administrer_rubrique' => 'Você pode administrar esta seção', |
|
| 232 | - 'info_adresse' => 'no endereço:', |
|
| 233 | - 'info_adresse_desinscription' => 'Endereço da desinscrição:', |
|
| 234 | - 'info_adresse_url' => 'Endereço (URL) do site público', |
|
| 235 | - 'info_afficher_par_nb' => 'Exibir por', |
|
| 236 | - 'info_aide_en_ligne' => 'Ajuda online SPIP', |
|
| 237 | - 'info_ajout_image' => 'Assim que você incluir imagens e documentos anexados a uma matéria, o SPIP pode criar para você, automaticamente, ícones (miniaturas) das imagens inseridas. Isto permite, por exemplo, criar automaticamente uma galeria ou um portfólio.', |
|
| 238 | - 'info_ajouter_rubrique' => 'Incluir outra seção para administrar:', |
|
| 239 | - 'info_annonce_nouveautes' => 'Aviso das novidades', |
|
| 240 | - 'info_article' => 'matéria', |
|
| 241 | - 'info_article_2' => 'matérias', |
|
| 242 | - 'info_article_a_paraitre' => 'As matérias pós-datadas para exibição', |
|
| 243 | - 'info_articles_02' => 'matérias', |
|
| 244 | - 'info_articles_2' => 'Matérias', |
|
| 245 | - 'info_articles_auteur' => 'As matérias deste autor', |
|
| 246 | - 'info_articles_miens' => 'Minhas matérias', |
|
| 247 | - 'info_articles_tous' => 'Todas as matérias', |
|
| 248 | - 'info_articles_trouves' => 'Matérias encontradas', |
|
| 249 | - 'info_attente_validation' => 'Suas matérias aguardando validação', |
|
| 250 | - 'info_aucun_article' => 'Nenhuma matéria', |
|
| 251 | - 'info_aucun_auteur' => 'Nenhum autor', |
|
| 252 | - 'info_aucun_message' => 'Nenhuma mensagem', |
|
| 253 | - 'info_aucun_rubrique' => 'Nenhuma seção', |
|
| 254 | - 'info_aujourdhui' => 'Hoje:', |
|
| 255 | - 'info_auteur_gere_rubriques' => 'Este autor gerencia as seções a seguir:', |
|
| 256 | - 'info_auteur_gere_toutes_rubriques' => 'Este autor gerencia <b>todas as seções</b>', |
|
| 257 | - 'info_auteur_gere_toutes_rubriques_2' => 'Eu gerencio <b>todas as seções</b>', |
|
| 258 | - 'info_auteurs' => 'Os autores', |
|
| 259 | - 'info_auteurs_par_tri' => 'Autores@partri@', |
|
| 260 | - 'info_auteurs_trouves' => 'Autores encontrados', |
|
| 261 | - 'info_authentification_externe' => 'Autenticação externa', |
|
| 262 | - 'info_avertissement' => 'Aviso', |
|
| 263 | - 'info_barre_outils' => 'com sua barra de ferramentas?', |
|
| 264 | - 'info_base_installee' => 'A estrutura da sua base de dados foi instalada.', |
|
| 265 | - 'info_bio' => 'Biografia', |
|
| 266 | - 'info_cache_desactive' => 'O cache está temporariamente desativado.', |
|
| 267 | - 'info_chapeau' => 'Introdução', |
|
| 268 | - 'info_chapeau_2' => 'Introdução:', |
|
| 269 | - 'info_chemin_acces_1' => 'Opções: <b>Caminho de acesso no diretório</b>', |
|
| 270 | - 'info_chemin_acces_2' => 'A partir daqui, você deverá configurar o caminho de acesso às informações do diretório. Esta informação é indispensávelpara ler os perfis dos usuários no diretório.', |
|
| 271 | - 'info_chemin_acces_annuaire' => 'Opções: <b>Caminho de acesso no diretório</b>', |
|
| 272 | - 'info_choix_base' => 'Terceiro passo:', |
|
| 273 | - 'info_classement_1' => '<sup><u>o</u></sup> em @liste@', |
|
| 274 | - 'info_classement_2' => '<sup><u>a</u></sup> em @liste@', |
|
| 275 | - 'info_code_acces' => 'Não se esqueça dos seus dados de conexão!', |
|
| 276 | - 'info_config_suivi' => 'Se este endereço corresponde a uma mailing-list, você pode informar abaixo o endereço onde os participantes do site podem se inscrever. Este endereço pode ser um URL (por exemplo a página de inscrição na lista pela Web), ou um endereço de e-mail dotado de um assunto específico (par exemple: <tt>@adresse_suivi@?subject=subscribe</tt>):', |
|
| 277 | - 'info_config_suivi_explication' => 'Voce pode assinar a mailing-list deste site. Você irá receber por e-mail, os avisos de matérias e notas propostos para publicação.', |
|
| 278 | - 'info_confirmer_passe' => 'Confirmar a nova senha:', |
|
| 279 | - 'info_conflit_edition_avis_non_sauvegarde' => 'Atenção os campos a seguir foram alterados por terceiros. As suas modificações nestes campos não foram, por isso, gravadas.', |
|
| 280 | - 'info_conflit_edition_differences' => 'Diferenças:', |
|
| 281 | - 'info_conflit_edition_version_enregistree' => 'A versão gravada:', |
|
| 282 | - 'info_conflit_edition_votre_version' => 'A sua versão:', |
|
| 283 | - 'info_connexion_base' => 'Teste de conexão com a base', |
|
| 284 | - 'info_connexion_base_donnee' => 'Conexão à sua base de dados', |
|
| 285 | - 'info_connexion_ldap_ok' => '<b>A conexão LDAP foi efetuada.</b><p>Você pode passar para o próximo passo.</p>', |
|
| 286 | - 'info_connexion_mysql' => 'Sua conexão SQL', |
|
| 287 | - 'info_connexion_ok' => 'A conexão foi obtida.', |
|
| 288 | - 'info_contact' => 'Contato', |
|
| 289 | - 'info_contenu_articles' => 'Conteúdo das matérias', |
|
| 290 | - 'info_contributions' => 'Contribuições', |
|
| 291 | - 'info_creation_paragraphe' => 'Para criar parágrafos, basta deixar linhas em branco.', |
|
| 292 | - 'info_creation_rubrique' => 'Antes de poder escrever matérias, você deve criar, pelo menos, uma seção.<br />', |
|
| 293 | - 'info_creation_tables' => 'Criação das tabelas da base', |
|
| 294 | - 'info_creer_base' => '<b>Criar</b> uma nova base de dados:', |
|
| 295 | - 'info_dans_rubrique' => 'Na seção:', |
|
| 296 | - 'info_date_publication_anterieure' => 'Data de redação anterior:', |
|
| 297 | - 'info_date_referencement' => 'DATA DE REFERENCIAMENTO DESTE SITE:', |
|
| 298 | - 'info_derniere_etape' => 'Terminou!', |
|
| 299 | - 'info_descriptif' => 'Descrição:', |
|
| 300 | - 'info_desinstaller_plugin' => 'exclui os dados e desativa o plugin', |
|
| 301 | - 'info_discussion_cours' => 'Discussões em andamento', |
|
| 302 | - 'info_ecrire_article' => 'Antes de poder escrever matérias, você precisa criar pelo menos uma seção.', |
|
| 303 | - 'info_email_envoi' => 'Endereço de e-mail de envio (opcional)', |
|
| 304 | - 'info_email_envoi_txt' => 'Informe aqui o endereço a ser utilizado para enviar os e-mails (por padrão, o endereço de destino será usado como endereço de envio):', |
|
| 305 | - 'info_email_webmestre' => 'Endereço de e-mail do webmaster', |
|
| 306 | - 'info_envoi_email_automatique' => 'Envio automático de e-mails', |
|
| 307 | - 'info_envoyer_maintenant' => 'Enviar agora', |
|
| 308 | - 'info_etape_suivante' => 'Avançar para a próxima etapa', |
|
| 309 | - 'info_etape_suivante_1' => 'Você pode passar para a próxima etapa.', |
|
| 310 | - 'info_etape_suivante_2' => 'Você pode passar para a próxima etapa.', |
|
| 311 | - 'info_exceptions_proxy' => 'Exceções para o proxy', |
|
| 312 | - 'info_exportation_base' => 'exportação da base para @archive@', |
|
| 313 | - 'info_facilite_suivi_activite' => 'Para facilitar o acompanhamento da atividade editorial do site, o SPIP pode avisar por e-mail, por exemplo para uma mailing-list de redatores, os avisos dos pedidos de publicação e das validações das matérias. Informe um ou mais endereços, separados por vírgula.', |
|
| 314 | - 'info_fichiers_authent' => 'Arquivos de autenticação «.htpasswd»', |
|
| 315 | - 'info_forums_abo_invites' => 'O seu site comporta fóruns por assinatura; os visitantes são convidados a se registrar no site público.', |
|
| 316 | - 'info_gauche_admin_tech' => '<b>Esta página é acessível apenas aos responsáveis pelo site.</b><p>Ela dá acesso às diferentes funções de manutenção técnica. Algumas dessas funções possuem um processo específico de autenticação que exige acesso FTP ao website.</p>', |
|
| 317 | - 'info_gauche_admin_vider' => '<b>Esta página é acessível apenas aos responsáveis pelo site.</b><p> Ela dá acesso às diferentes funções de manutenção técnica. Algumas dessas funções possuem um processo específico de autenticação que exige acesso FTP ao website.</p>', |
|
| 318 | - 'info_gauche_auteurs' => 'Aqui, você encontra todos os autores do site. |
|
| 168 | + // I |
|
| 169 | + 'ical_info1' => 'Esta página apresenta diversos métodos para se manter a par da atividade deste site.', |
|
| 170 | + 'ical_info2' => 'Para mais informações sobre todas estas técnicas, não deixe de consultar <a href="@spipnet@">a documentação do SPIP</a>.', |
|
| 171 | + 'ical_info_calendrier' => 'Dois calendários estão à sua disposição. O primeiro é um mapa do site anunciando todas as matérias publicadas. O segundo contém os avisos editoriais bem como suas últimas mensagens privadas: ele lhe é reservado graças a uma chave pessoal, que você pode alterar a qualquer momento ao renovar a sua senha.', |
|
| 172 | + 'ical_methode_http' => 'Transferência', |
|
| 173 | + 'ical_methode_webcal' => 'Sincronização (webcal://)', |
|
| 174 | + 'ical_texte_prive' => 'Este calendário, de uso estritamente pessoal, o informa sobre a atividade editorial privada deste site (tarefas e encontros pessoais, matérias e notas propostas...).', |
|
| 175 | + 'ical_texte_public' => 'Este calendário permite-lhe acompanhar a atividade pública deste site (matérias e notas publicadas).', |
|
| 176 | + 'ical_texte_rss' => 'Você pode sindicar as novidades deste site em qualquer leitor de arquivos em formato XML/RSS (Rich Site Summary). É também o formato que permite ao SPIP ler as novidades publicadas em outros sites que utilizem um formato de troca de informações compatível (sites sindicados).', |
|
| 177 | + 'ical_titre_js' => 'Javascript', |
|
| 178 | + 'ical_titre_mailing' => 'Mailing-list', |
|
| 179 | + 'ical_titre_rss' => 'Arquivos de sindicação', |
|
| 180 | + 'icone_accueil' => 'Página Inicial', |
|
| 181 | + 'icone_activer_cookie' => 'Ativar o coockie de correspondência', |
|
| 182 | + 'icone_activite' => 'Atividade', |
|
| 183 | + 'icone_admin_plugin' => 'Gerenciamento dos plugins', |
|
| 184 | + 'icone_administration' => 'Manutenção', |
|
| 185 | + 'icone_afficher_auteurs' => 'Exibir os autores', |
|
| 186 | + 'icone_afficher_visiteurs' => 'Exibir os visitantes', |
|
| 187 | + 'icone_arret_discussion' => 'Não participar mais desta discussão', |
|
| 188 | + 'icone_calendrier' => 'Calendário', |
|
| 189 | + 'icone_configuration' => 'Configuração', |
|
| 190 | + 'icone_creer_auteur' => 'Criar um novo autor e vinculá-lo a esta matéria', |
|
| 191 | + 'icone_creer_mot_cle' => 'Criar uma nova palavra-chave e vinculá-la a esta matéria', |
|
| 192 | + 'icone_creer_rubrique_2' => 'Criar uma nova seção', |
|
| 193 | + 'icone_developpement' => 'Desenvolvimento', |
|
| 194 | + 'icone_edition' => 'Edição', |
|
| 195 | + 'icone_ma_langue' => 'Meu idioma', |
|
| 196 | + 'icone_mes_infos' => 'Minhas informações', |
|
| 197 | + 'icone_mes_preferences' => 'Minhas preferências', |
|
| 198 | + 'icone_modifier_article' => 'Editar esta matéria', |
|
| 199 | + 'icone_modifier_rubrique' => 'Editar esta seção', |
|
| 200 | + 'icone_publication' => 'Publicação', |
|
| 201 | + 'icone_relancer_signataire' => 'Reconfirmar o assinante', |
|
| 202 | + 'icone_retour' => 'Voltar', |
|
| 203 | + 'icone_retour_article' => 'Voltar para a matéria', |
|
| 204 | + 'icone_squelette' => 'Templates', |
|
| 205 | + 'icone_suivi_publication' => 'Acompanhamento da publicação', |
|
| 206 | + 'icone_supprimer_cookie' => 'Excluir o cookie de correspondência', |
|
| 207 | + 'icone_supprimer_rubrique' => 'Excluir esta seção', |
|
| 208 | + 'icone_supprimer_signature' => 'Excluir esta assinatura', |
|
| 209 | + 'icone_valider_signature' => 'Validar esta assinatura', |
|
| 210 | + 'image_administrer_rubrique' => 'Você pode administrar esta seção', |
|
| 211 | + 'impossible_modifier_login_auteur' => 'Não foi possível alterar o login.', |
|
| 212 | + 'impossible_modifier_pass_auteur' => 'Não foi possível alterar a senha.', |
|
| 213 | + 'info_1_article' => '1 matéria', |
|
| 214 | + 'info_1_auteur' => '1 autor', |
|
| 215 | + 'info_1_message' => '1 mensagem', |
|
| 216 | + 'info_1_mot_cle' => '1 palavra-chave', |
|
| 217 | + 'info_1_rubrique' => '1 seção', |
|
| 218 | + 'info_1_visiteur' => '1 visitante', |
|
| 219 | + 'info_activer_cookie' => 'Você pode ativar um <b>cookie de correspondência</b>, que lhe permitirá passar facilmente do site público para o site privado.', |
|
| 220 | + 'info_activer_menu_developpement' => 'Exibir o menu Desenvolvimento', |
|
| 221 | + 'info_admin_etre_webmestre' => 'Me conceder direitos de webmaster', |
|
| 222 | + 'info_admin_je_suis_webmestre' => 'Eu sou <b>webmaster</b>', |
|
| 223 | + 'info_admin_statuer_webmestre' => 'Dar a este administrador os direitos de webmaster', |
|
| 224 | + 'info_admin_webmestre' => 'Este administrador é <b>webmaster</b>', |
|
| 225 | + 'info_administrateur' => 'Administrador', |
|
| 226 | + 'info_administrateur_1' => 'Administrador', |
|
| 227 | + 'info_administrateur_2' => 'do site (<i>use com cuidado</i>)', |
|
| 228 | + 'info_administrateur_site_01' => 'Se você é administrador do site, por favor,', |
|
| 229 | + 'info_administrateur_site_02' => 'clique neste link', |
|
| 230 | + 'info_administrateurs' => 'Administradores', |
|
| 231 | + 'info_administrer_rubrique' => 'Você pode administrar esta seção', |
|
| 232 | + 'info_adresse' => 'no endereço:', |
|
| 233 | + 'info_adresse_desinscription' => 'Endereço da desinscrição:', |
|
| 234 | + 'info_adresse_url' => 'Endereço (URL) do site público', |
|
| 235 | + 'info_afficher_par_nb' => 'Exibir por', |
|
| 236 | + 'info_aide_en_ligne' => 'Ajuda online SPIP', |
|
| 237 | + 'info_ajout_image' => 'Assim que você incluir imagens e documentos anexados a uma matéria, o SPIP pode criar para você, automaticamente, ícones (miniaturas) das imagens inseridas. Isto permite, por exemplo, criar automaticamente uma galeria ou um portfólio.', |
|
| 238 | + 'info_ajouter_rubrique' => 'Incluir outra seção para administrar:', |
|
| 239 | + 'info_annonce_nouveautes' => 'Aviso das novidades', |
|
| 240 | + 'info_article' => 'matéria', |
|
| 241 | + 'info_article_2' => 'matérias', |
|
| 242 | + 'info_article_a_paraitre' => 'As matérias pós-datadas para exibição', |
|
| 243 | + 'info_articles_02' => 'matérias', |
|
| 244 | + 'info_articles_2' => 'Matérias', |
|
| 245 | + 'info_articles_auteur' => 'As matérias deste autor', |
|
| 246 | + 'info_articles_miens' => 'Minhas matérias', |
|
| 247 | + 'info_articles_tous' => 'Todas as matérias', |
|
| 248 | + 'info_articles_trouves' => 'Matérias encontradas', |
|
| 249 | + 'info_attente_validation' => 'Suas matérias aguardando validação', |
|
| 250 | + 'info_aucun_article' => 'Nenhuma matéria', |
|
| 251 | + 'info_aucun_auteur' => 'Nenhum autor', |
|
| 252 | + 'info_aucun_message' => 'Nenhuma mensagem', |
|
| 253 | + 'info_aucun_rubrique' => 'Nenhuma seção', |
|
| 254 | + 'info_aujourdhui' => 'Hoje:', |
|
| 255 | + 'info_auteur_gere_rubriques' => 'Este autor gerencia as seções a seguir:', |
|
| 256 | + 'info_auteur_gere_toutes_rubriques' => 'Este autor gerencia <b>todas as seções</b>', |
|
| 257 | + 'info_auteur_gere_toutes_rubriques_2' => 'Eu gerencio <b>todas as seções</b>', |
|
| 258 | + 'info_auteurs' => 'Os autores', |
|
| 259 | + 'info_auteurs_par_tri' => 'Autores@partri@', |
|
| 260 | + 'info_auteurs_trouves' => 'Autores encontrados', |
|
| 261 | + 'info_authentification_externe' => 'Autenticação externa', |
|
| 262 | + 'info_avertissement' => 'Aviso', |
|
| 263 | + 'info_barre_outils' => 'com sua barra de ferramentas?', |
|
| 264 | + 'info_base_installee' => 'A estrutura da sua base de dados foi instalada.', |
|
| 265 | + 'info_bio' => 'Biografia', |
|
| 266 | + 'info_cache_desactive' => 'O cache está temporariamente desativado.', |
|
| 267 | + 'info_chapeau' => 'Introdução', |
|
| 268 | + 'info_chapeau_2' => 'Introdução:', |
|
| 269 | + 'info_chemin_acces_1' => 'Opções: <b>Caminho de acesso no diretório</b>', |
|
| 270 | + 'info_chemin_acces_2' => 'A partir daqui, você deverá configurar o caminho de acesso às informações do diretório. Esta informação é indispensávelpara ler os perfis dos usuários no diretório.', |
|
| 271 | + 'info_chemin_acces_annuaire' => 'Opções: <b>Caminho de acesso no diretório</b>', |
|
| 272 | + 'info_choix_base' => 'Terceiro passo:', |
|
| 273 | + 'info_classement_1' => '<sup><u>o</u></sup> em @liste@', |
|
| 274 | + 'info_classement_2' => '<sup><u>a</u></sup> em @liste@', |
|
| 275 | + 'info_code_acces' => 'Não se esqueça dos seus dados de conexão!', |
|
| 276 | + 'info_config_suivi' => 'Se este endereço corresponde a uma mailing-list, você pode informar abaixo o endereço onde os participantes do site podem se inscrever. Este endereço pode ser um URL (por exemplo a página de inscrição na lista pela Web), ou um endereço de e-mail dotado de um assunto específico (par exemple: <tt>@adresse_suivi@?subject=subscribe</tt>):', |
|
| 277 | + 'info_config_suivi_explication' => 'Voce pode assinar a mailing-list deste site. Você irá receber por e-mail, os avisos de matérias e notas propostos para publicação.', |
|
| 278 | + 'info_confirmer_passe' => 'Confirmar a nova senha:', |
|
| 279 | + 'info_conflit_edition_avis_non_sauvegarde' => 'Atenção os campos a seguir foram alterados por terceiros. As suas modificações nestes campos não foram, por isso, gravadas.', |
|
| 280 | + 'info_conflit_edition_differences' => 'Diferenças:', |
|
| 281 | + 'info_conflit_edition_version_enregistree' => 'A versão gravada:', |
|
| 282 | + 'info_conflit_edition_votre_version' => 'A sua versão:', |
|
| 283 | + 'info_connexion_base' => 'Teste de conexão com a base', |
|
| 284 | + 'info_connexion_base_donnee' => 'Conexão à sua base de dados', |
|
| 285 | + 'info_connexion_ldap_ok' => '<b>A conexão LDAP foi efetuada.</b><p>Você pode passar para o próximo passo.</p>', |
|
| 286 | + 'info_connexion_mysql' => 'Sua conexão SQL', |
|
| 287 | + 'info_connexion_ok' => 'A conexão foi obtida.', |
|
| 288 | + 'info_contact' => 'Contato', |
|
| 289 | + 'info_contenu_articles' => 'Conteúdo das matérias', |
|
| 290 | + 'info_contributions' => 'Contribuições', |
|
| 291 | + 'info_creation_paragraphe' => 'Para criar parágrafos, basta deixar linhas em branco.', |
|
| 292 | + 'info_creation_rubrique' => 'Antes de poder escrever matérias, você deve criar, pelo menos, uma seção.<br />', |
|
| 293 | + 'info_creation_tables' => 'Criação das tabelas da base', |
|
| 294 | + 'info_creer_base' => '<b>Criar</b> uma nova base de dados:', |
|
| 295 | + 'info_dans_rubrique' => 'Na seção:', |
|
| 296 | + 'info_date_publication_anterieure' => 'Data de redação anterior:', |
|
| 297 | + 'info_date_referencement' => 'DATA DE REFERENCIAMENTO DESTE SITE:', |
|
| 298 | + 'info_derniere_etape' => 'Terminou!', |
|
| 299 | + 'info_descriptif' => 'Descrição:', |
|
| 300 | + 'info_desinstaller_plugin' => 'exclui os dados e desativa o plugin', |
|
| 301 | + 'info_discussion_cours' => 'Discussões em andamento', |
|
| 302 | + 'info_ecrire_article' => 'Antes de poder escrever matérias, você precisa criar pelo menos uma seção.', |
|
| 303 | + 'info_email_envoi' => 'Endereço de e-mail de envio (opcional)', |
|
| 304 | + 'info_email_envoi_txt' => 'Informe aqui o endereço a ser utilizado para enviar os e-mails (por padrão, o endereço de destino será usado como endereço de envio):', |
|
| 305 | + 'info_email_webmestre' => 'Endereço de e-mail do webmaster', |
|
| 306 | + 'info_envoi_email_automatique' => 'Envio automático de e-mails', |
|
| 307 | + 'info_envoyer_maintenant' => 'Enviar agora', |
|
| 308 | + 'info_etape_suivante' => 'Avançar para a próxima etapa', |
|
| 309 | + 'info_etape_suivante_1' => 'Você pode passar para a próxima etapa.', |
|
| 310 | + 'info_etape_suivante_2' => 'Você pode passar para a próxima etapa.', |
|
| 311 | + 'info_exceptions_proxy' => 'Exceções para o proxy', |
|
| 312 | + 'info_exportation_base' => 'exportação da base para @archive@', |
|
| 313 | + 'info_facilite_suivi_activite' => 'Para facilitar o acompanhamento da atividade editorial do site, o SPIP pode avisar por e-mail, por exemplo para uma mailing-list de redatores, os avisos dos pedidos de publicação e das validações das matérias. Informe um ou mais endereços, separados por vírgula.', |
|
| 314 | + 'info_fichiers_authent' => 'Arquivos de autenticação «.htpasswd»', |
|
| 315 | + 'info_forums_abo_invites' => 'O seu site comporta fóruns por assinatura; os visitantes são convidados a se registrar no site público.', |
|
| 316 | + 'info_gauche_admin_tech' => '<b>Esta página é acessível apenas aos responsáveis pelo site.</b><p>Ela dá acesso às diferentes funções de manutenção técnica. Algumas dessas funções possuem um processo específico de autenticação que exige acesso FTP ao website.</p>', |
|
| 317 | + 'info_gauche_admin_vider' => '<b>Esta página é acessível apenas aos responsáveis pelo site.</b><p> Ela dá acesso às diferentes funções de manutenção técnica. Algumas dessas funções possuem um processo específico de autenticação que exige acesso FTP ao website.</p>', |
|
| 318 | + 'info_gauche_auteurs' => 'Aqui, você encontra todos os autores do site. |
|
| 319 | 319 | Os status dos autores é indicado pela côr dos ícones (administrador = verde; redator = amarelo).', |
| 320 | - 'info_gauche_auteurs_exterieurs' => 'Os autores externos, sem acesso ao site, são indicados por um ícone azul; |
|
| 320 | + 'info_gauche_auteurs_exterieurs' => 'Os autores externos, sem acesso ao site, são indicados por um ícone azul; |
|
| 321 | 321 | os autores excluídos por um ícone cinza.', |
| 322 | - 'info_gauche_messagerie' => 'O sistema interno de mensagens permite a troca de mensagens entre redatores, a criação de lembretes (para seu uso pessoal) ou exibir anúncios na página de entrada da área privada (se você for administrador).', |
|
| 323 | - 'info_gauche_statistiques_referers' => 'Esta página apresenta a lista dos <i>referers</i>, ou seja, dos sites que contêm links para o seu site, unicamente para ontem e hoje; esta lista é zerada a cada 24 horas.', |
|
| 324 | - 'info_gauche_visiteurs_enregistres' => 'Você encontrará aqui os visitantes registrados na área pública do site (fóruns por assinatura).', |
|
| 325 | - 'info_generation_miniatures_images' => 'Geração de miniaturas das imagens', |
|
| 326 | - 'info_gerer_trad_objets' => '@objets@ : gerenciar os links de tradução', |
|
| 327 | - 'info_hebergeur_desactiver_envoi_email' => 'Alguns serviços de hospedagem desativam o envio automático de e-mails a partir dos seus servidores. Neste caso, as funcionalidades a seguir não funcionarão.', |
|
| 328 | - 'info_hier' => 'ontem:', |
|
| 329 | - 'info_identification_publique' => 'Sua identificação pública...', |
|
| 330 | - 'info_image_process' => 'Por favor, selecione o melhor método de criação dos ícones, clicando na imagem correspondente.', |
|
| 331 | - 'info_image_process2' => 'Se nenhuma imagem está sendo exibida, o servidor que hospeda o seu site não foi configurado para utilizar essas ferramentas. Se você deseja usar essas funções, contate o responsável técnico e solicite as extensões «GD» ou «Imagick».', |
|
| 332 | - 'info_images_auto' => 'Imagens calculadas automaticamente', |
|
| 333 | - 'info_informations_personnelles' => 'Informações pessoais', |
|
| 334 | - 'info_inscription' => 'Inscrição online', |
|
| 335 | - 'info_inscription_automatique' => 'Inscrição automática de novos redatores', |
|
| 336 | - 'info_jeu_caractere' => 'Conjunto de caracteres do site', |
|
| 337 | - 'info_jours' => 'dias', |
|
| 338 | - 'info_laisser_champs_vides' => 'deixar estes campos vazios)', |
|
| 339 | - 'info_langues' => 'Idiomas do site', |
|
| 340 | - 'info_ldap_ok' => 'A autenticação LDAP está instalada.', |
|
| 341 | - 'info_lien_hypertexte' => 'Link hipertexto:', |
|
| 342 | - 'info_liste_nouveautes_envoyee' => 'A lista de novidades foi enviada', |
|
| 343 | - 'info_liste_redacteurs_connectes' => 'Lista de redatores conectados', |
|
| 344 | - 'info_login_existant' => 'Este login já está cadastrado.', |
|
| 345 | - 'info_login_trop_court' => 'Login muito curto.', |
|
| 346 | - 'info_login_trop_court_car_pluriel' => 'O login deve conter pelo menos @nb@ caracteres.', |
|
| 347 | - 'info_logos' => 'Os ícones', |
|
| 348 | - 'info_maximum' => 'máximo:', |
|
| 349 | - 'info_meme_rubrique' => 'Na mesma seção', |
|
| 350 | - 'info_message_en_redaction' => 'Suas mensagens em fase de redação', |
|
| 351 | - 'info_message_technique' => 'Mensagem técnica:', |
|
| 352 | - 'info_messagerie_interne' => 'Mensageria interna', |
|
| 353 | - 'info_mise_a_niveau_base' => 'atualização da sua base SQL', |
|
| 354 | - 'info_mise_a_niveau_base_2' => '{{Atenção!}} Você instalou uma versão de arquivos SPIP {anterior} à que estava instalada no site: a sua base de dados corre o risco de se corromper e o seu site não funcionar mais.<br />{{Reinstale os arquivos SPIP.}}', |
|
| 355 | - 'info_modification_enregistree' => 'Sua alteração foi gravada', |
|
| 356 | - 'info_modifier_auteur' => 'Editar o autor:', |
|
| 357 | - 'info_modifier_rubrique' => 'Editar a seção:', |
|
| 358 | - 'info_modifier_titre' => 'Editar: @titre@', |
|
| 359 | - 'info_mon_site_spip' => 'Meu site SPIP', |
|
| 360 | - 'info_moyenne' => 'média:', |
|
| 361 | - 'info_multi_cet_article' => 'Idioma desta matéria:', |
|
| 362 | - 'info_multi_langues_choisies' => 'Por favor, selecione a seguir os idiomas à disposição dos redatores do seu site. |
|
| 322 | + 'info_gauche_messagerie' => 'O sistema interno de mensagens permite a troca de mensagens entre redatores, a criação de lembretes (para seu uso pessoal) ou exibir anúncios na página de entrada da área privada (se você for administrador).', |
|
| 323 | + 'info_gauche_statistiques_referers' => 'Esta página apresenta a lista dos <i>referers</i>, ou seja, dos sites que contêm links para o seu site, unicamente para ontem e hoje; esta lista é zerada a cada 24 horas.', |
|
| 324 | + 'info_gauche_visiteurs_enregistres' => 'Você encontrará aqui os visitantes registrados na área pública do site (fóruns por assinatura).', |
|
| 325 | + 'info_generation_miniatures_images' => 'Geração de miniaturas das imagens', |
|
| 326 | + 'info_gerer_trad_objets' => '@objets@ : gerenciar os links de tradução', |
|
| 327 | + 'info_hebergeur_desactiver_envoi_email' => 'Alguns serviços de hospedagem desativam o envio automático de e-mails a partir dos seus servidores. Neste caso, as funcionalidades a seguir não funcionarão.', |
|
| 328 | + 'info_hier' => 'ontem:', |
|
| 329 | + 'info_identification_publique' => 'Sua identificação pública...', |
|
| 330 | + 'info_image_process' => 'Por favor, selecione o melhor método de criação dos ícones, clicando na imagem correspondente.', |
|
| 331 | + 'info_image_process2' => 'Se nenhuma imagem está sendo exibida, o servidor que hospeda o seu site não foi configurado para utilizar essas ferramentas. Se você deseja usar essas funções, contate o responsável técnico e solicite as extensões «GD» ou «Imagick».', |
|
| 332 | + 'info_images_auto' => 'Imagens calculadas automaticamente', |
|
| 333 | + 'info_informations_personnelles' => 'Informações pessoais', |
|
| 334 | + 'info_inscription' => 'Inscrição online', |
|
| 335 | + 'info_inscription_automatique' => 'Inscrição automática de novos redatores', |
|
| 336 | + 'info_jeu_caractere' => 'Conjunto de caracteres do site', |
|
| 337 | + 'info_jours' => 'dias', |
|
| 338 | + 'info_laisser_champs_vides' => 'deixar estes campos vazios)', |
|
| 339 | + 'info_langues' => 'Idiomas do site', |
|
| 340 | + 'info_ldap_ok' => 'A autenticação LDAP está instalada.', |
|
| 341 | + 'info_lien_hypertexte' => 'Link hipertexto:', |
|
| 342 | + 'info_liste_nouveautes_envoyee' => 'A lista de novidades foi enviada', |
|
| 343 | + 'info_liste_redacteurs_connectes' => 'Lista de redatores conectados', |
|
| 344 | + 'info_login_existant' => 'Este login já está cadastrado.', |
|
| 345 | + 'info_login_trop_court' => 'Login muito curto.', |
|
| 346 | + 'info_login_trop_court_car_pluriel' => 'O login deve conter pelo menos @nb@ caracteres.', |
|
| 347 | + 'info_logos' => 'Os ícones', |
|
| 348 | + 'info_maximum' => 'máximo:', |
|
| 349 | + 'info_meme_rubrique' => 'Na mesma seção', |
|
| 350 | + 'info_message_en_redaction' => 'Suas mensagens em fase de redação', |
|
| 351 | + 'info_message_technique' => 'Mensagem técnica:', |
|
| 352 | + 'info_messagerie_interne' => 'Mensageria interna', |
|
| 353 | + 'info_mise_a_niveau_base' => 'atualização da sua base SQL', |
|
| 354 | + 'info_mise_a_niveau_base_2' => '{{Atenção!}} Você instalou uma versão de arquivos SPIP {anterior} à que estava instalada no site: a sua base de dados corre o risco de se corromper e o seu site não funcionar mais.<br />{{Reinstale os arquivos SPIP.}}', |
|
| 355 | + 'info_modification_enregistree' => 'Sua alteração foi gravada', |
|
| 356 | + 'info_modifier_auteur' => 'Editar o autor:', |
|
| 357 | + 'info_modifier_rubrique' => 'Editar a seção:', |
|
| 358 | + 'info_modifier_titre' => 'Editar: @titre@', |
|
| 359 | + 'info_mon_site_spip' => 'Meu site SPIP', |
|
| 360 | + 'info_moyenne' => 'média:', |
|
| 361 | + 'info_multi_cet_article' => 'Idioma desta matéria:', |
|
| 362 | + 'info_multi_langues_choisies' => 'Por favor, selecione a seguir os idiomas à disposição dos redatores do seu site. |
|
| 363 | 363 | Os idiomas já utilizados no site (no topo da lista) não podem ser desativados.', |
| 364 | - 'info_multi_objets' => '@objets@ : ativar o menu de idioma', |
|
| 365 | - 'info_multi_secteurs' => '... apenas para as seções situadas na raiz?', |
|
| 366 | - 'info_nb_articles' => '@nb@ matérias', |
|
| 367 | - 'info_nb_auteurs' => '@nb@ autores', |
|
| 368 | - 'info_nb_messages' => '@nb@ mensagens', |
|
| 369 | - 'info_nb_mots_cles' => '@nb@ palavras-chave', |
|
| 370 | - 'info_nb_rubriques' => '@nb@ seções', |
|
| 371 | - 'info_nb_visiteurs' => '@nb@ visitantes', |
|
| 372 | - 'info_nom' => 'Nome', |
|
| 373 | - 'info_nom_destinataire' => 'Nome do destinatário', |
|
| 374 | - 'info_nom_pas_conforme' => 'tags HTML não são permitidas', |
|
| 375 | - 'info_nom_site' => 'Nome do seu site', |
|
| 376 | - 'info_nombre_articles' => '@nb_articles@ matérias,', |
|
| 377 | - 'info_nombre_rubriques' => '@nb_rubriques@ seções,', |
|
| 378 | - 'info_nombre_sites' => '@nb_sites@ sites,', |
|
| 379 | - 'info_non_deplacer' => 'Não mover...', |
|
| 380 | - 'info_non_envoi_annonce_dernieres_nouveautes' => 'O SPIP pode enviar regularmente o anúncio das últimas novidades do site (matérias e notas publicadas recentemente).', |
|
| 381 | - 'info_non_envoi_liste_nouveautes' => 'Não enviar a lista de novidades', |
|
| 382 | - 'info_non_modifiable' => 'não pode ser modificado', |
|
| 383 | - 'info_non_suppression_mot_cle' => 'Eu não quero excluir esta palavra-chave.', |
|
| 384 | - 'info_notes' => 'Observações', |
|
| 385 | - 'info_nouvel_article' => 'Nova matéria', |
|
| 386 | - 'info_nouvelle_traduction' => 'Nova tradução:', |
|
| 387 | - 'info_numero_article' => 'MATÉRIA NÚMERO:', |
|
| 388 | - 'info_obligatoire_02' => '(obrigatório)', |
|
| 389 | - 'info_option_accepter_visiteurs' => 'Aceitar a inscrição de visitantes do site público', |
|
| 390 | - 'info_option_ne_pas_accepter_visiteurs' => 'Recusar a inscrição dos visitantes', |
|
| 391 | - 'info_options_avancees' => 'OPÇÕES AVANÇADAS', |
|
| 392 | - 'info_ou' => 'ou...', |
|
| 393 | - 'info_page_interdite' => 'Página não autorizada', |
|
| 394 | - 'info_par_nom' => 'por nome', |
|
| 395 | - 'info_par_nombre_article' => 'por número de matérias', |
|
| 396 | - 'info_par_statut' => 'por status', |
|
| 397 | - 'info_par_tri' => '’(por @tri@)’', |
|
| 398 | - 'info_passe_trop_court' => 'Senha muito curta.', |
|
| 399 | - 'info_passe_trop_court_car_pluriel' => 'A senha deve conter pelo menos @nb@ caracteres.', |
|
| 400 | - 'info_passes_identiques' => 'As duas senhas não são idênticas.', |
|
| 401 | - 'info_plus_cinq_car' => 'mais de 5 caracteres', |
|
| 402 | - 'info_plus_cinq_car_2' => '(Mais de 5 caracteres)', |
|
| 403 | - 'info_plus_trois_car' => '(Mais de 3 caracteres)', |
|
| 404 | - 'info_popularite' => 'popularidade: @popularite@; visitas: @visites@', |
|
| 405 | - 'info_post_scriptum' => 'Rodapé', |
|
| 406 | - 'info_post_scriptum_2' => 'Rodapé:', |
|
| 407 | - 'info_pour' => 'para', |
|
| 408 | - 'info_preview_texte' => 'É possível visualizar os diferentes elementos editoriais do site que tenham pelo menos o status de «proposto», bem como os elementos em fase de redação de que se é autor. Esta funcionalidade deve estar disponível para os administradores, para os redatores, ou para ninguém?', |
|
| 409 | - 'info_procedez_par_etape' => 'proceder passo-a-passo', |
|
| 410 | - 'info_procedure_maj_version' => 'o procedimento de atualização deve ser rodado para adaptar a base de dados à nova versão do SPIP.', |
|
| 411 | - 'info_proxy_ok' => 'Teste do proxy bem sucedido', |
|
| 412 | - 'info_ps' => 'P.S.', |
|
| 413 | - 'info_publier' => 'publicar', |
|
| 414 | - 'info_publies' => 'Suas matérias publicadas online', |
|
| 415 | - 'info_question_accepter_visiteurs' => 'Se os templates do seu site prevêem o cadastramento de visitantes sem acesso à área privada, por favor, ative a opção abaixo:', |
|
| 416 | - 'info_question_inscription_nouveaux_redacteurs' => 'Você quer aceitar inscrições de novos redatores a partir do site público? Se você aceitar, os visitantes poderão se cadastrar através de um formulário automatizado, tendo acesso à área privada para propôr as suas próprias matérias. <div class="notice">Durante a fase de inscrição, os usuários recebem um e-mail automático, fornecendo-lhes os seus códigos de acesso à área privada. Alguns serviços de hospedagem desativam o envio de e-mails a partir dos seus servidores: nesse caso, a inscrição automática é impossível.</div>', |
|
| 417 | - 'info_qui_edite' => '@nom_auteur_modif@ trabalhou neste conteúdo há @date_diff@ minutos', |
|
| 418 | - 'info_racine_site' => 'Raiz do site', |
|
| 419 | - 'info_recharger_page' => 'Por favor, atualize esta página em alguns instantes.', |
|
| 420 | - 'info_recherche_auteur_zero' => 'Nenhum resultado para «@cherche_auteur@».', |
|
| 421 | - 'info_recommencer' => 'Por favor, recomece.', |
|
| 422 | - 'info_redacteur_1' => 'Redator', |
|
| 423 | - 'info_redacteur_2' => 'com acesso à área privada (<i>recomendado</i>)', |
|
| 424 | - 'info_redacteurs' => 'Redatores', |
|
| 425 | - 'info_redaction_en_cours' => 'EM FASE DE REDAÇÃO', |
|
| 426 | - 'info_redirection' => 'Redirecionamento', |
|
| 427 | - 'info_redirection_activee' => 'O redirecionamento foi ativado.', |
|
| 428 | - 'info_redirection_boucle' => 'Você tentou redirecionar a matéria para ela mesma.', |
|
| 429 | - 'info_redirection_desactivee' => 'O redirecionamento foi excluído.', |
|
| 430 | - 'info_refuses' => 'Suas matérias recusadas', |
|
| 431 | - 'info_reglage_ldap' => 'Opções: <b>Configuração da importação LDAP</b>', |
|
| 432 | - 'info_renvoi_article' => '<b>Redirecionamento.</b> Esta matéria redireciona para a página:', |
|
| 433 | - 'info_reserve_admin' => 'Apenas os administradores podem alterar este endereço.', |
|
| 434 | - 'info_restreindre_rubrique' => 'Restringir o gerenciamento à seção:', |
|
| 435 | - 'info_resultat_recherche' => 'Resultados da busca:', |
|
| 436 | - 'info_rubriques' => 'Seções', |
|
| 437 | - 'info_rubriques_02' => 'seções', |
|
| 438 | - 'info_rubriques_trouvees' => 'Seções encontradas', |
|
| 439 | - 'info_sans_titre' => 'Sem título', |
|
| 440 | - 'info_selection_chemin_acces' => '<b>Selecione</b> a seguir o caminho para acessar o diretório:', |
|
| 441 | - 'info_signatures' => 'assinaturas', |
|
| 442 | - 'info_site' => 'Site', |
|
| 443 | - 'info_site_2' => 'site:', |
|
| 444 | - 'info_site_min' => 'site', |
|
| 445 | - 'info_site_reference_2' => 'Site referenciado', |
|
| 446 | - 'info_site_web' => 'Website:', |
|
| 447 | - 'info_sites' => 'sites', |
|
| 448 | - 'info_sites_lies_mot' => 'Os sites referenciados vinculados a esta palavra-chave', |
|
| 449 | - 'info_sites_proxy' => 'Utilizar um proxy', |
|
| 450 | - 'info_sites_trouves' => 'Sites encontrados', |
|
| 451 | - 'info_sous_titre' => 'Subtítulo:', |
|
| 452 | - 'info_statut_administrateur' => 'Administrador', |
|
| 453 | - 'info_statut_auteur' => 'Status deste autor:', |
|
| 454 | - 'info_statut_auteur_2' => 'Eu sou', |
|
| 455 | - 'info_statut_auteur_a_confirmer' => 'Inscrição a confirmar', |
|
| 456 | - 'info_statut_auteur_autre' => 'Outro status:', |
|
| 457 | - 'info_statut_redacteur' => 'Redator', |
|
| 458 | - 'info_statut_utilisateurs_1' => 'Status padrão dos usuários importados', |
|
| 459 | - 'info_statut_utilisateurs_2' => 'Escolha o status atribuído às pessoas que constam do diretório LDAP, quando elas se conectarem pela primeira vêz. Você poderá, em seguida, alterar caso a caso este valor para cada autor.', |
|
| 460 | - 'info_suivi_activite' => 'Acompanhamento da atividade editorial', |
|
| 461 | - 'info_surtitre' => 'Sobretítulo:', |
|
| 462 | - 'info_syndication_integrale_1' => 'O seu site propõe arquivos de sindicação (ver «<a href="@url@">@titre@</a>»).', |
|
| 463 | - 'info_syndication_integrale_2' => 'Você deseja transmitir as matérias integralmente, ou difundir apenas um resumo de algumas centenas de caracteres?', |
|
| 464 | - 'info_table_prefix' => 'Você pode alterar o prefixo do nome das tabelas de dados (indispensável no caso de pretender instalar diversos sites na mesma base de dados). Este prefixo deve estar em minúsculas, não acentuadas, e sem espaços.', |
|
| 465 | - 'info_taille_maximale_images' => 'SPIP irá testar o tamanho máximo das imagens que o sistema pode tratar (em milhões de pixels).<br />As imagens muito grandes não serão reduzidas.', |
|
| 466 | - 'info_taille_maximale_vignette' => 'Tamanho máximo dos ícones gerados pelo sistema:', |
|
| 467 | - 'info_terminer_installation' => 'Você pode agora terminar o procedimento de instalação padrão.', |
|
| 468 | - 'info_texte' => 'Texto', |
|
| 469 | - 'info_texte_explicatif' => 'Texto explicativo', |
|
| 470 | - 'info_texte_long' => '(o texto é longo: ele aparecerá em diversas partes que serão recombinadas após validação.)', |
|
| 471 | - 'info_texte_message' => 'Texto da sua mensagem', |
|
| 472 | - 'info_texte_message_02' => 'Texto da mensagem', |
|
| 473 | - 'info_titre' => 'Título:', |
|
| 474 | - 'info_total' => 'total:', |
|
| 475 | - 'info_tous_articles_en_redaction' => 'Todas as matérias em fase de redação', |
|
| 476 | - 'info_tous_articles_presents' => 'Todas as matérias publicadas nesta seção', |
|
| 477 | - 'info_tous_articles_refuses' => 'Todas as matérias recusadas', |
|
| 478 | - 'info_tous_les' => 'todos os:', |
|
| 479 | - 'info_tout_site' => 'Todo o site', |
|
| 480 | - 'info_tout_site2' => 'A matéria não foi traduzida para este idioma.', |
|
| 481 | - 'info_tout_site3' => 'A matéria foi traduzida para este idioma, mas foram feitas alterações na matéria de referência. A tradução procisa ser atualizada.', |
|
| 482 | - 'info_tout_site4' => 'A matéria foi traduzida para este idioma e a tradução está em dia.', |
|
| 483 | - 'info_tout_site5' => 'Matéria original.', |
|
| 484 | - 'info_tout_site6' => '<b>Atenção:</b> apenas as matérias originais estão exibidas. |
|
| 364 | + 'info_multi_objets' => '@objets@ : ativar o menu de idioma', |
|
| 365 | + 'info_multi_secteurs' => '... apenas para as seções situadas na raiz?', |
|
| 366 | + 'info_nb_articles' => '@nb@ matérias', |
|
| 367 | + 'info_nb_auteurs' => '@nb@ autores', |
|
| 368 | + 'info_nb_messages' => '@nb@ mensagens', |
|
| 369 | + 'info_nb_mots_cles' => '@nb@ palavras-chave', |
|
| 370 | + 'info_nb_rubriques' => '@nb@ seções', |
|
| 371 | + 'info_nb_visiteurs' => '@nb@ visitantes', |
|
| 372 | + 'info_nom' => 'Nome', |
|
| 373 | + 'info_nom_destinataire' => 'Nome do destinatário', |
|
| 374 | + 'info_nom_pas_conforme' => 'tags HTML não são permitidas', |
|
| 375 | + 'info_nom_site' => 'Nome do seu site', |
|
| 376 | + 'info_nombre_articles' => '@nb_articles@ matérias,', |
|
| 377 | + 'info_nombre_rubriques' => '@nb_rubriques@ seções,', |
|
| 378 | + 'info_nombre_sites' => '@nb_sites@ sites,', |
|
| 379 | + 'info_non_deplacer' => 'Não mover...', |
|
| 380 | + 'info_non_envoi_annonce_dernieres_nouveautes' => 'O SPIP pode enviar regularmente o anúncio das últimas novidades do site (matérias e notas publicadas recentemente).', |
|
| 381 | + 'info_non_envoi_liste_nouveautes' => 'Não enviar a lista de novidades', |
|
| 382 | + 'info_non_modifiable' => 'não pode ser modificado', |
|
| 383 | + 'info_non_suppression_mot_cle' => 'Eu não quero excluir esta palavra-chave.', |
|
| 384 | + 'info_notes' => 'Observações', |
|
| 385 | + 'info_nouvel_article' => 'Nova matéria', |
|
| 386 | + 'info_nouvelle_traduction' => 'Nova tradução:', |
|
| 387 | + 'info_numero_article' => 'MATÉRIA NÚMERO:', |
|
| 388 | + 'info_obligatoire_02' => '(obrigatório)', |
|
| 389 | + 'info_option_accepter_visiteurs' => 'Aceitar a inscrição de visitantes do site público', |
|
| 390 | + 'info_option_ne_pas_accepter_visiteurs' => 'Recusar a inscrição dos visitantes', |
|
| 391 | + 'info_options_avancees' => 'OPÇÕES AVANÇADAS', |
|
| 392 | + 'info_ou' => 'ou...', |
|
| 393 | + 'info_page_interdite' => 'Página não autorizada', |
|
| 394 | + 'info_par_nom' => 'por nome', |
|
| 395 | + 'info_par_nombre_article' => 'por número de matérias', |
|
| 396 | + 'info_par_statut' => 'por status', |
|
| 397 | + 'info_par_tri' => '’(por @tri@)’', |
|
| 398 | + 'info_passe_trop_court' => 'Senha muito curta.', |
|
| 399 | + 'info_passe_trop_court_car_pluriel' => 'A senha deve conter pelo menos @nb@ caracteres.', |
|
| 400 | + 'info_passes_identiques' => 'As duas senhas não são idênticas.', |
|
| 401 | + 'info_plus_cinq_car' => 'mais de 5 caracteres', |
|
| 402 | + 'info_plus_cinq_car_2' => '(Mais de 5 caracteres)', |
|
| 403 | + 'info_plus_trois_car' => '(Mais de 3 caracteres)', |
|
| 404 | + 'info_popularite' => 'popularidade: @popularite@; visitas: @visites@', |
|
| 405 | + 'info_post_scriptum' => 'Rodapé', |
|
| 406 | + 'info_post_scriptum_2' => 'Rodapé:', |
|
| 407 | + 'info_pour' => 'para', |
|
| 408 | + 'info_preview_texte' => 'É possível visualizar os diferentes elementos editoriais do site que tenham pelo menos o status de «proposto», bem como os elementos em fase de redação de que se é autor. Esta funcionalidade deve estar disponível para os administradores, para os redatores, ou para ninguém?', |
|
| 409 | + 'info_procedez_par_etape' => 'proceder passo-a-passo', |
|
| 410 | + 'info_procedure_maj_version' => 'o procedimento de atualização deve ser rodado para adaptar a base de dados à nova versão do SPIP.', |
|
| 411 | + 'info_proxy_ok' => 'Teste do proxy bem sucedido', |
|
| 412 | + 'info_ps' => 'P.S.', |
|
| 413 | + 'info_publier' => 'publicar', |
|
| 414 | + 'info_publies' => 'Suas matérias publicadas online', |
|
| 415 | + 'info_question_accepter_visiteurs' => 'Se os templates do seu site prevêem o cadastramento de visitantes sem acesso à área privada, por favor, ative a opção abaixo:', |
|
| 416 | + 'info_question_inscription_nouveaux_redacteurs' => 'Você quer aceitar inscrições de novos redatores a partir do site público? Se você aceitar, os visitantes poderão se cadastrar através de um formulário automatizado, tendo acesso à área privada para propôr as suas próprias matérias. <div class="notice">Durante a fase de inscrição, os usuários recebem um e-mail automático, fornecendo-lhes os seus códigos de acesso à área privada. Alguns serviços de hospedagem desativam o envio de e-mails a partir dos seus servidores: nesse caso, a inscrição automática é impossível.</div>', |
|
| 417 | + 'info_qui_edite' => '@nom_auteur_modif@ trabalhou neste conteúdo há @date_diff@ minutos', |
|
| 418 | + 'info_racine_site' => 'Raiz do site', |
|
| 419 | + 'info_recharger_page' => 'Por favor, atualize esta página em alguns instantes.', |
|
| 420 | + 'info_recherche_auteur_zero' => 'Nenhum resultado para «@cherche_auteur@».', |
|
| 421 | + 'info_recommencer' => 'Por favor, recomece.', |
|
| 422 | + 'info_redacteur_1' => 'Redator', |
|
| 423 | + 'info_redacteur_2' => 'com acesso à área privada (<i>recomendado</i>)', |
|
| 424 | + 'info_redacteurs' => 'Redatores', |
|
| 425 | + 'info_redaction_en_cours' => 'EM FASE DE REDAÇÃO', |
|
| 426 | + 'info_redirection' => 'Redirecionamento', |
|
| 427 | + 'info_redirection_activee' => 'O redirecionamento foi ativado.', |
|
| 428 | + 'info_redirection_boucle' => 'Você tentou redirecionar a matéria para ela mesma.', |
|
| 429 | + 'info_redirection_desactivee' => 'O redirecionamento foi excluído.', |
|
| 430 | + 'info_refuses' => 'Suas matérias recusadas', |
|
| 431 | + 'info_reglage_ldap' => 'Opções: <b>Configuração da importação LDAP</b>', |
|
| 432 | + 'info_renvoi_article' => '<b>Redirecionamento.</b> Esta matéria redireciona para a página:', |
|
| 433 | + 'info_reserve_admin' => 'Apenas os administradores podem alterar este endereço.', |
|
| 434 | + 'info_restreindre_rubrique' => 'Restringir o gerenciamento à seção:', |
|
| 435 | + 'info_resultat_recherche' => 'Resultados da busca:', |
|
| 436 | + 'info_rubriques' => 'Seções', |
|
| 437 | + 'info_rubriques_02' => 'seções', |
|
| 438 | + 'info_rubriques_trouvees' => 'Seções encontradas', |
|
| 439 | + 'info_sans_titre' => 'Sem título', |
|
| 440 | + 'info_selection_chemin_acces' => '<b>Selecione</b> a seguir o caminho para acessar o diretório:', |
|
| 441 | + 'info_signatures' => 'assinaturas', |
|
| 442 | + 'info_site' => 'Site', |
|
| 443 | + 'info_site_2' => 'site:', |
|
| 444 | + 'info_site_min' => 'site', |
|
| 445 | + 'info_site_reference_2' => 'Site referenciado', |
|
| 446 | + 'info_site_web' => 'Website:', |
|
| 447 | + 'info_sites' => 'sites', |
|
| 448 | + 'info_sites_lies_mot' => 'Os sites referenciados vinculados a esta palavra-chave', |
|
| 449 | + 'info_sites_proxy' => 'Utilizar um proxy', |
|
| 450 | + 'info_sites_trouves' => 'Sites encontrados', |
|
| 451 | + 'info_sous_titre' => 'Subtítulo:', |
|
| 452 | + 'info_statut_administrateur' => 'Administrador', |
|
| 453 | + 'info_statut_auteur' => 'Status deste autor:', |
|
| 454 | + 'info_statut_auteur_2' => 'Eu sou', |
|
| 455 | + 'info_statut_auteur_a_confirmer' => 'Inscrição a confirmar', |
|
| 456 | + 'info_statut_auteur_autre' => 'Outro status:', |
|
| 457 | + 'info_statut_redacteur' => 'Redator', |
|
| 458 | + 'info_statut_utilisateurs_1' => 'Status padrão dos usuários importados', |
|
| 459 | + 'info_statut_utilisateurs_2' => 'Escolha o status atribuído às pessoas que constam do diretório LDAP, quando elas se conectarem pela primeira vêz. Você poderá, em seguida, alterar caso a caso este valor para cada autor.', |
|
| 460 | + 'info_suivi_activite' => 'Acompanhamento da atividade editorial', |
|
| 461 | + 'info_surtitre' => 'Sobretítulo:', |
|
| 462 | + 'info_syndication_integrale_1' => 'O seu site propõe arquivos de sindicação (ver «<a href="@url@">@titre@</a>»).', |
|
| 463 | + 'info_syndication_integrale_2' => 'Você deseja transmitir as matérias integralmente, ou difundir apenas um resumo de algumas centenas de caracteres?', |
|
| 464 | + 'info_table_prefix' => 'Você pode alterar o prefixo do nome das tabelas de dados (indispensável no caso de pretender instalar diversos sites na mesma base de dados). Este prefixo deve estar em minúsculas, não acentuadas, e sem espaços.', |
|
| 465 | + 'info_taille_maximale_images' => 'SPIP irá testar o tamanho máximo das imagens que o sistema pode tratar (em milhões de pixels).<br />As imagens muito grandes não serão reduzidas.', |
|
| 466 | + 'info_taille_maximale_vignette' => 'Tamanho máximo dos ícones gerados pelo sistema:', |
|
| 467 | + 'info_terminer_installation' => 'Você pode agora terminar o procedimento de instalação padrão.', |
|
| 468 | + 'info_texte' => 'Texto', |
|
| 469 | + 'info_texte_explicatif' => 'Texto explicativo', |
|
| 470 | + 'info_texte_long' => '(o texto é longo: ele aparecerá em diversas partes que serão recombinadas após validação.)', |
|
| 471 | + 'info_texte_message' => 'Texto da sua mensagem', |
|
| 472 | + 'info_texte_message_02' => 'Texto da mensagem', |
|
| 473 | + 'info_titre' => 'Título:', |
|
| 474 | + 'info_total' => 'total:', |
|
| 475 | + 'info_tous_articles_en_redaction' => 'Todas as matérias em fase de redação', |
|
| 476 | + 'info_tous_articles_presents' => 'Todas as matérias publicadas nesta seção', |
|
| 477 | + 'info_tous_articles_refuses' => 'Todas as matérias recusadas', |
|
| 478 | + 'info_tous_les' => 'todos os:', |
|
| 479 | + 'info_tout_site' => 'Todo o site', |
|
| 480 | + 'info_tout_site2' => 'A matéria não foi traduzida para este idioma.', |
|
| 481 | + 'info_tout_site3' => 'A matéria foi traduzida para este idioma, mas foram feitas alterações na matéria de referência. A tradução procisa ser atualizada.', |
|
| 482 | + 'info_tout_site4' => 'A matéria foi traduzida para este idioma e a tradução está em dia.', |
|
| 483 | + 'info_tout_site5' => 'Matéria original.', |
|
| 484 | + 'info_tout_site6' => '<b>Atenção:</b> apenas as matérias originais estão exibidas. |
|
| 485 | 485 | As traduções estão associadas ao original, numa côr que indica o seu status:', |
| 486 | - 'info_traductions' => 'Traduções', |
|
| 487 | - 'info_travail_colaboratif' => 'Trabalho colaborativo nas matérias', |
|
| 488 | - 'info_un_article' => 'uma matéria,', |
|
| 489 | - 'info_un_site' => 'um site,', |
|
| 490 | - 'info_une_rubrique' => 'uma seção,', |
|
| 491 | - 'info_une_rubrique_02' => '1 seção', |
|
| 492 | - 'info_url' => 'URL:', |
|
| 493 | - 'info_url_proxy' => 'URL do proxy', |
|
| 494 | - 'info_url_proxy_pas_conforme' => 'O URL do proxy não é válido.', |
|
| 495 | - 'info_url_site_pas_conforme' => 'O URL do site não é válido.', |
|
| 496 | - 'info_url_test_proxy' => 'URL de teste', |
|
| 497 | - 'info_urlref' => 'Link hipertexto:', |
|
| 498 | - 'info_utilisation_spip' => 'Você pode agora começar a utilizar o sistema de publicação assistida...', |
|
| 499 | - 'info_visites_par_mois' => 'Exibir por mês:', |
|
| 500 | - 'info_visiteur_1' => 'Visitante', |
|
| 501 | - 'info_visiteur_2' => 'do site público', |
|
| 502 | - 'info_visiteurs' => 'Visitantes', |
|
| 503 | - 'info_visiteurs_02' => 'Visitantes do site público', |
|
| 504 | - 'info_webmestre_forces' => 'Os webmasters são definidos em <tt>@file_options@</tt>.', |
|
| 505 | - 'install_adresse_base_hebergeur' => 'Endereço da base de dados atribuído pelo serviço de hospedagem:', |
|
| 506 | - 'install_connect_ok' => 'A nova base de dados foi corretamente declarada sob o nome de servidor @connect@.', |
|
| 507 | - 'install_echec_annonce' => 'A instalação irá, provavelmente, falhar, ou levar a um site que não funciona...', |
|
| 508 | - 'install_extension_mbstring' => 'O SPIP não funciona com:', |
|
| 509 | - 'install_extension_php_obligatoire' => 'O SPIP exige a extensão php:', |
|
| 510 | - 'install_login_base_hebergeur' => 'Login de conexão atribuído pelo serviço de hospedagem:', |
|
| 511 | - 'install_nom_base_hebergeur' => 'Nome da base atribuído pelo serviço de hospedagem:', |
|
| 512 | - 'install_pas_table' => 'Base atualmente sem tabelas', |
|
| 513 | - 'install_pass_base_hebergeur' => 'Senha de conexão atribuída pelo serviço de hospedagem', |
|
| 514 | - 'install_php_extension' => 'As extensões a seguir estão faltando: @extensions@', |
|
| 515 | - 'install_php_version' => 'PHP versão @version@ é insuficiente (mínimo = @minimum@)', |
|
| 516 | - 'install_php_version_max' => 'A versão @version@ do PHP é muito recente (máximo = @maximum@)', |
|
| 517 | - 'install_select_langue' => 'Escolha um idioma e clique no botão «avançar» para iniciar o procedimento de instalação.', |
|
| 518 | - 'install_select_type_db' => 'Indicar o tipo de base de dados:', |
|
| 519 | - 'install_select_type_mysql' => 'MySQL', |
|
| 520 | - 'install_select_type_pg' => 'PostgreSQL', |
|
| 521 | - 'install_select_type_sqlite2' => 'SQLite 2', |
|
| 522 | - 'install_select_type_sqlite3' => 'SQLite 3', |
|
| 523 | - 'install_serveur_hebergeur' => 'Servidor de base de dados atribuído pelo serviço de hospedagem', |
|
| 524 | - 'install_table_prefix_hebergeur' => 'Prefixo de tabela atribuído pelo serviço de hospedagem:', |
|
| 525 | - 'install_tables_base' => 'Tabelas da base', |
|
| 526 | - 'install_types_db_connus' => 'SPIP pode usar <b>MySQL</b> (a mais comum), e <b>SQLite</b>.', |
|
| 527 | - 'install_types_db_connus_avertissement' => 'O suporte ao <b>PostgreSQL</b> é também proposto a título experimental', |
|
| 528 | - 'instituer_erreur_statut_a_change' => 'O status já foi alterado', |
|
| 529 | - 'instituer_erreur_statut_non_autorise' => 'Você não pode escolher este status', |
|
| 530 | - 'intem_redacteur' => 'redator', |
|
| 531 | - 'intitule_licence' => 'Licença', |
|
| 532 | - 'item_accepter_inscriptions' => 'Aceitar as inscrições', |
|
| 533 | - 'item_activer_messages_avertissement' => 'Ativar as mensagens de aviso', |
|
| 534 | - 'item_administrateur_2' => 'administrador', |
|
| 535 | - 'item_afficher_calendrier' => 'Exibir no calendário', |
|
| 536 | - 'item_autoriser_syndication_integrale' => 'Difundir a íntegra das matérias nos arquivos de sindicação', |
|
| 537 | - 'item_choix_administrateurs' => 'os administradores', |
|
| 538 | - 'item_choix_generation_miniature' => 'Gerar automaticamente as miniaturas das imagens.', |
|
| 539 | - 'item_choix_non_generation_miniature' => 'Não gerar as miniaturas das imagens.', |
|
| 540 | - 'item_choix_redacteurs' => 'os redatores', |
|
| 541 | - 'item_choix_visiteurs' => 'os visitantes do site público', |
|
| 542 | - 'item_creer_fichiers_authent' => 'Criar os arquivos .htpasswd', |
|
| 543 | - 'item_login' => 'Login', |
|
| 544 | - 'item_messagerie_agenda' => 'Ativar as mesagens internas e a agenda', |
|
| 545 | - 'item_mots_cles_association_articles' => 'às matérias', |
|
| 546 | - 'item_mots_cles_association_rubriques' => 'às seções', |
|
| 547 | - 'item_mots_cles_association_sites' => 'aos sites referenciados ou sindicados.', |
|
| 548 | - 'item_non' => 'Não', |
|
| 549 | - 'item_non_accepter_inscriptions' => 'Não aceitar inscrições', |
|
| 550 | - 'item_non_activer_messages_avertissement' => 'Sem mensagens de aviso', |
|
| 551 | - 'item_non_afficher_calendrier' => 'Não exibir no calendário', |
|
| 552 | - 'item_non_autoriser_syndication_integrale' => 'Difundir apenas um resumo', |
|
| 553 | - 'item_non_creer_fichiers_authent' => 'Não criar os arquivos', |
|
| 554 | - 'item_non_messagerie_agenda' => 'Desativar as mensagens internas e a agenda', |
|
| 555 | - 'item_non_publier_articles' => 'Não publicar as matérias antes da data de publicação fixada.', |
|
| 556 | - 'item_nouvel_auteur' => 'Novo autor', |
|
| 557 | - 'item_nouvelle_rubrique' => 'Nova seção', |
|
| 558 | - 'item_oui' => 'Sim', |
|
| 559 | - 'item_publier_articles' => 'Publicar as matérias seja qual for a sua data de publicação.', |
|
| 560 | - 'item_reponse_article' => 'Resposta à matéria', |
|
| 561 | - 'item_visiteur' => 'Visitante', |
|
| 486 | + 'info_traductions' => 'Traduções', |
|
| 487 | + 'info_travail_colaboratif' => 'Trabalho colaborativo nas matérias', |
|
| 488 | + 'info_un_article' => 'uma matéria,', |
|
| 489 | + 'info_un_site' => 'um site,', |
|
| 490 | + 'info_une_rubrique' => 'uma seção,', |
|
| 491 | + 'info_une_rubrique_02' => '1 seção', |
|
| 492 | + 'info_url' => 'URL:', |
|
| 493 | + 'info_url_proxy' => 'URL do proxy', |
|
| 494 | + 'info_url_proxy_pas_conforme' => 'O URL do proxy não é válido.', |
|
| 495 | + 'info_url_site_pas_conforme' => 'O URL do site não é válido.', |
|
| 496 | + 'info_url_test_proxy' => 'URL de teste', |
|
| 497 | + 'info_urlref' => 'Link hipertexto:', |
|
| 498 | + 'info_utilisation_spip' => 'Você pode agora começar a utilizar o sistema de publicação assistida...', |
|
| 499 | + 'info_visites_par_mois' => 'Exibir por mês:', |
|
| 500 | + 'info_visiteur_1' => 'Visitante', |
|
| 501 | + 'info_visiteur_2' => 'do site público', |
|
| 502 | + 'info_visiteurs' => 'Visitantes', |
|
| 503 | + 'info_visiteurs_02' => 'Visitantes do site público', |
|
| 504 | + 'info_webmestre_forces' => 'Os webmasters são definidos em <tt>@file_options@</tt>.', |
|
| 505 | + 'install_adresse_base_hebergeur' => 'Endereço da base de dados atribuído pelo serviço de hospedagem:', |
|
| 506 | + 'install_connect_ok' => 'A nova base de dados foi corretamente declarada sob o nome de servidor @connect@.', |
|
| 507 | + 'install_echec_annonce' => 'A instalação irá, provavelmente, falhar, ou levar a um site que não funciona...', |
|
| 508 | + 'install_extension_mbstring' => 'O SPIP não funciona com:', |
|
| 509 | + 'install_extension_php_obligatoire' => 'O SPIP exige a extensão php:', |
|
| 510 | + 'install_login_base_hebergeur' => 'Login de conexão atribuído pelo serviço de hospedagem:', |
|
| 511 | + 'install_nom_base_hebergeur' => 'Nome da base atribuído pelo serviço de hospedagem:', |
|
| 512 | + 'install_pas_table' => 'Base atualmente sem tabelas', |
|
| 513 | + 'install_pass_base_hebergeur' => 'Senha de conexão atribuída pelo serviço de hospedagem', |
|
| 514 | + 'install_php_extension' => 'As extensões a seguir estão faltando: @extensions@', |
|
| 515 | + 'install_php_version' => 'PHP versão @version@ é insuficiente (mínimo = @minimum@)', |
|
| 516 | + 'install_php_version_max' => 'A versão @version@ do PHP é muito recente (máximo = @maximum@)', |
|
| 517 | + 'install_select_langue' => 'Escolha um idioma e clique no botão «avançar» para iniciar o procedimento de instalação.', |
|
| 518 | + 'install_select_type_db' => 'Indicar o tipo de base de dados:', |
|
| 519 | + 'install_select_type_mysql' => 'MySQL', |
|
| 520 | + 'install_select_type_pg' => 'PostgreSQL', |
|
| 521 | + 'install_select_type_sqlite2' => 'SQLite 2', |
|
| 522 | + 'install_select_type_sqlite3' => 'SQLite 3', |
|
| 523 | + 'install_serveur_hebergeur' => 'Servidor de base de dados atribuído pelo serviço de hospedagem', |
|
| 524 | + 'install_table_prefix_hebergeur' => 'Prefixo de tabela atribuído pelo serviço de hospedagem:', |
|
| 525 | + 'install_tables_base' => 'Tabelas da base', |
|
| 526 | + 'install_types_db_connus' => 'SPIP pode usar <b>MySQL</b> (a mais comum), e <b>SQLite</b>.', |
|
| 527 | + 'install_types_db_connus_avertissement' => 'O suporte ao <b>PostgreSQL</b> é também proposto a título experimental', |
|
| 528 | + 'instituer_erreur_statut_a_change' => 'O status já foi alterado', |
|
| 529 | + 'instituer_erreur_statut_non_autorise' => 'Você não pode escolher este status', |
|
| 530 | + 'intem_redacteur' => 'redator', |
|
| 531 | + 'intitule_licence' => 'Licença', |
|
| 532 | + 'item_accepter_inscriptions' => 'Aceitar as inscrições', |
|
| 533 | + 'item_activer_messages_avertissement' => 'Ativar as mensagens de aviso', |
|
| 534 | + 'item_administrateur_2' => 'administrador', |
|
| 535 | + 'item_afficher_calendrier' => 'Exibir no calendário', |
|
| 536 | + 'item_autoriser_syndication_integrale' => 'Difundir a íntegra das matérias nos arquivos de sindicação', |
|
| 537 | + 'item_choix_administrateurs' => 'os administradores', |
|
| 538 | + 'item_choix_generation_miniature' => 'Gerar automaticamente as miniaturas das imagens.', |
|
| 539 | + 'item_choix_non_generation_miniature' => 'Não gerar as miniaturas das imagens.', |
|
| 540 | + 'item_choix_redacteurs' => 'os redatores', |
|
| 541 | + 'item_choix_visiteurs' => 'os visitantes do site público', |
|
| 542 | + 'item_creer_fichiers_authent' => 'Criar os arquivos .htpasswd', |
|
| 543 | + 'item_login' => 'Login', |
|
| 544 | + 'item_messagerie_agenda' => 'Ativar as mesagens internas e a agenda', |
|
| 545 | + 'item_mots_cles_association_articles' => 'às matérias', |
|
| 546 | + 'item_mots_cles_association_rubriques' => 'às seções', |
|
| 547 | + 'item_mots_cles_association_sites' => 'aos sites referenciados ou sindicados.', |
|
| 548 | + 'item_non' => 'Não', |
|
| 549 | + 'item_non_accepter_inscriptions' => 'Não aceitar inscrições', |
|
| 550 | + 'item_non_activer_messages_avertissement' => 'Sem mensagens de aviso', |
|
| 551 | + 'item_non_afficher_calendrier' => 'Não exibir no calendário', |
|
| 552 | + 'item_non_autoriser_syndication_integrale' => 'Difundir apenas um resumo', |
|
| 553 | + 'item_non_creer_fichiers_authent' => 'Não criar os arquivos', |
|
| 554 | + 'item_non_messagerie_agenda' => 'Desativar as mensagens internas e a agenda', |
|
| 555 | + 'item_non_publier_articles' => 'Não publicar as matérias antes da data de publicação fixada.', |
|
| 556 | + 'item_nouvel_auteur' => 'Novo autor', |
|
| 557 | + 'item_nouvelle_rubrique' => 'Nova seção', |
|
| 558 | + 'item_oui' => 'Sim', |
|
| 559 | + 'item_publier_articles' => 'Publicar as matérias seja qual for a sua data de publicação.', |
|
| 560 | + 'item_reponse_article' => 'Resposta à matéria', |
|
| 561 | + 'item_visiteur' => 'Visitante', |
|
| 562 | 562 | |
| 563 | - // J |
|
| 564 | - 'jour_non_connu_nc' => 'n.c.', |
|
| 563 | + // J |
|
| 564 | + 'jour_non_connu_nc' => 'n.c.', |
|
| 565 | 565 | |
| 566 | - // L |
|
| 567 | - 'label_bando_outils' => 'Barra de ferramentas', |
|
| 568 | - 'label_bando_outils_afficher' => 'Exibir as ferramentas', |
|
| 569 | - 'label_bando_outils_masquer' => 'Esconder as ferramentas', |
|
| 570 | - 'label_choix_langue' => 'Escolha o seu idioma', |
|
| 571 | - 'label_langue' => 'Idioma', |
|
| 572 | - 'label_nom_fichier_connect' => 'Informe o nome usado por este servidor', |
|
| 573 | - 'label_slogan_site' => 'Slogan do site', |
|
| 574 | - 'label_taille_ecran' => 'Largura da tela', |
|
| 575 | - 'label_texte_et_icones_navigation' => 'Menu de navegação', |
|
| 576 | - 'label_texte_et_icones_page' => 'Exibição na página', |
|
| 577 | - 'ldap_correspondance' => 'herança do campo @champ@', |
|
| 578 | - 'ldap_correspondance_1' => 'Herança dos campos LDAP', |
|
| 579 | - 'ldap_correspondance_2' => 'Para cada um dos campos SPIP a seguir, indique o nome do campo LDAP correspondente. Deixe em branco para não preencher, separe por espaços ou vírgulas para tentar vários campos LDAP.', |
|
| 580 | - 'lien_ajouter_auteur' => 'Incluir este autor', |
|
| 581 | - 'lien_ajouter_une_rubrique' => 'Incluir esta seção', |
|
| 582 | - 'lien_email' => 'e-mail', |
|
| 583 | - 'lien_nom_site' => 'NOME DO SITE:', |
|
| 584 | - 'lien_rapide_contenu' => 'Ir para o conteúdo', |
|
| 585 | - 'lien_rapide_navigation' => 'Ir para a navegação', |
|
| 586 | - 'lien_rapide_recherche' => 'Ir para a busca', |
|
| 587 | - 'lien_retirer_auteur' => 'Retirar o autor', |
|
| 588 | - 'lien_retirer_rubrique' => 'Excluir a seção', |
|
| 589 | - 'lien_retirer_tous_auteurs' => 'Retirar todos os autores', |
|
| 590 | - 'lien_retirer_toutes_rubriques' => 'Retirar todas as seções', |
|
| 591 | - 'lien_site' => 'site', |
|
| 592 | - 'lien_tout_decocher' => 'Desmarcar tudo', |
|
| 593 | - 'lien_tout_deplier' => 'Expandir tudo', |
|
| 594 | - 'lien_tout_replier' => 'Retrair tudo', |
|
| 595 | - 'lien_tout_supprimer' => 'Excluir tudo', |
|
| 596 | - 'lien_trier_nom' => 'Ordenar pelo nome', |
|
| 597 | - 'lien_trier_nombre_articles' => 'Ordenar por número de matérias', |
|
| 598 | - 'lien_trier_statut' => 'Ordenar pelo status', |
|
| 599 | - 'lien_voir_en_ligne' => 'VER ONLINE:', |
|
| 600 | - 'logo_article' => 'Ícone da matéria', |
|
| 601 | - 'logo_auteur' => 'Ícone do autor', |
|
| 602 | - 'logo_rubrique' => 'Ícone da seção', |
|
| 603 | - 'logo_site' => 'Ícone deste site', |
|
| 604 | - 'logo_standard_rubrique' => 'Ícone padrão das seções', |
|
| 605 | - 'logo_survol' => 'Ícone para mouseOver', |
|
| 566 | + // L |
|
| 567 | + 'label_bando_outils' => 'Barra de ferramentas', |
|
| 568 | + 'label_bando_outils_afficher' => 'Exibir as ferramentas', |
|
| 569 | + 'label_bando_outils_masquer' => 'Esconder as ferramentas', |
|
| 570 | + 'label_choix_langue' => 'Escolha o seu idioma', |
|
| 571 | + 'label_langue' => 'Idioma', |
|
| 572 | + 'label_nom_fichier_connect' => 'Informe o nome usado por este servidor', |
|
| 573 | + 'label_slogan_site' => 'Slogan do site', |
|
| 574 | + 'label_taille_ecran' => 'Largura da tela', |
|
| 575 | + 'label_texte_et_icones_navigation' => 'Menu de navegação', |
|
| 576 | + 'label_texte_et_icones_page' => 'Exibição na página', |
|
| 577 | + 'ldap_correspondance' => 'herança do campo @champ@', |
|
| 578 | + 'ldap_correspondance_1' => 'Herança dos campos LDAP', |
|
| 579 | + 'ldap_correspondance_2' => 'Para cada um dos campos SPIP a seguir, indique o nome do campo LDAP correspondente. Deixe em branco para não preencher, separe por espaços ou vírgulas para tentar vários campos LDAP.', |
|
| 580 | + 'lien_ajouter_auteur' => 'Incluir este autor', |
|
| 581 | + 'lien_ajouter_une_rubrique' => 'Incluir esta seção', |
|
| 582 | + 'lien_email' => 'e-mail', |
|
| 583 | + 'lien_nom_site' => 'NOME DO SITE:', |
|
| 584 | + 'lien_rapide_contenu' => 'Ir para o conteúdo', |
|
| 585 | + 'lien_rapide_navigation' => 'Ir para a navegação', |
|
| 586 | + 'lien_rapide_recherche' => 'Ir para a busca', |
|
| 587 | + 'lien_retirer_auteur' => 'Retirar o autor', |
|
| 588 | + 'lien_retirer_rubrique' => 'Excluir a seção', |
|
| 589 | + 'lien_retirer_tous_auteurs' => 'Retirar todos os autores', |
|
| 590 | + 'lien_retirer_toutes_rubriques' => 'Retirar todas as seções', |
|
| 591 | + 'lien_site' => 'site', |
|
| 592 | + 'lien_tout_decocher' => 'Desmarcar tudo', |
|
| 593 | + 'lien_tout_deplier' => 'Expandir tudo', |
|
| 594 | + 'lien_tout_replier' => 'Retrair tudo', |
|
| 595 | + 'lien_tout_supprimer' => 'Excluir tudo', |
|
| 596 | + 'lien_trier_nom' => 'Ordenar pelo nome', |
|
| 597 | + 'lien_trier_nombre_articles' => 'Ordenar por número de matérias', |
|
| 598 | + 'lien_trier_statut' => 'Ordenar pelo status', |
|
| 599 | + 'lien_voir_en_ligne' => 'VER ONLINE:', |
|
| 600 | + 'logo_article' => 'Ícone da matéria', |
|
| 601 | + 'logo_auteur' => 'Ícone do autor', |
|
| 602 | + 'logo_rubrique' => 'Ícone da seção', |
|
| 603 | + 'logo_site' => 'Ícone deste site', |
|
| 604 | + 'logo_standard_rubrique' => 'Ícone padrão das seções', |
|
| 605 | + 'logo_survol' => 'Ícone para mouseOver', |
|
| 606 | 606 | |
| 607 | - // M |
|
| 608 | - 'menu_aide_installation_choix_base' => 'Seleção da sua base', |
|
| 609 | - 'module_fichier_langue' => 'Arquivo de idioma', |
|
| 610 | - 'module_raccourci' => 'Atalho', |
|
| 611 | - 'module_texte_affiche' => 'Texto exibido', |
|
| 612 | - 'module_texte_explicatif' => 'Você pode inserir os atalhos a seguir nos templates do seu site público. Eles serão traduzidos automaticamente para os idiomas para os quais exista um arquivo de idioma.', |
|
| 613 | - 'module_texte_traduction' => 'O arquivo de idioma «@module@» está disponível em:', |
|
| 614 | - 'mois_non_connu' => 'desconhecido', |
|
| 607 | + // M |
|
| 608 | + 'menu_aide_installation_choix_base' => 'Seleção da sua base', |
|
| 609 | + 'module_fichier_langue' => 'Arquivo de idioma', |
|
| 610 | + 'module_raccourci' => 'Atalho', |
|
| 611 | + 'module_texte_affiche' => 'Texto exibido', |
|
| 612 | + 'module_texte_explicatif' => 'Você pode inserir os atalhos a seguir nos templates do seu site público. Eles serão traduzidos automaticamente para os idiomas para os quais exista um arquivo de idioma.', |
|
| 613 | + 'module_texte_traduction' => 'O arquivo de idioma «@module@» está disponível em:', |
|
| 614 | + 'mois_non_connu' => 'desconhecido', |
|
| 615 | 615 | |
| 616 | - // N |
|
| 617 | - 'nouvelle_version_spip' => 'A versão @version@ do SPIP está disponível', |
|
| 618 | - 'nouvelle_version_spip_majeure' => 'Uma nova versão SPIP @version@ está disponível', |
|
| 616 | + // N |
|
| 617 | + 'nouvelle_version_spip' => 'A versão @version@ do SPIP está disponível', |
|
| 618 | + 'nouvelle_version_spip_majeure' => 'Uma nova versão SPIP @version@ está disponível', |
|
| 619 | 619 | |
| 620 | - // O |
|
| 621 | - 'onglet_contenu' => 'Conteúdo', |
|
| 622 | - 'onglet_declarer_une_autre_base' => 'Configurar outra base', |
|
| 623 | - 'onglet_discuter' => 'Discutir', |
|
| 624 | - 'onglet_interactivite' => 'Interatividade', |
|
| 625 | - 'onglet_proprietes' => 'Propriedades', |
|
| 626 | - 'onglet_repartition_actuelle' => 'atualmente', |
|
| 627 | - 'onglet_sous_rubriques' => 'Subseções', |
|
| 620 | + // O |
|
| 621 | + 'onglet_contenu' => 'Conteúdo', |
|
| 622 | + 'onglet_declarer_une_autre_base' => 'Configurar outra base', |
|
| 623 | + 'onglet_discuter' => 'Discutir', |
|
| 624 | + 'onglet_interactivite' => 'Interatividade', |
|
| 625 | + 'onglet_proprietes' => 'Propriedades', |
|
| 626 | + 'onglet_repartition_actuelle' => 'atualmente', |
|
| 627 | + 'onglet_sous_rubriques' => 'Subseções', |
|
| 628 | 628 | |
| 629 | - // P |
|
| 630 | - 'page_pas_proxy' => 'Esta página não deve passar pelo proxy', |
|
| 631 | - 'pas_de_proxy_pour' => 'Se necessário, indique as máquinas ou domínios para os quais este proxy não se aplica (por exemplo: @exemple@)', |
|
| 632 | - 'phpinfo' => 'Configuração PHP', |
|
| 633 | - 'plugin_charge_paquet' => 'Carregamento do pacote @name@', |
|
| 634 | - 'plugin_charger' => 'Transferir', |
|
| 635 | - 'plugin_erreur_charger' => 'erro: não foi possível carregar @zip@', |
|
| 636 | - 'plugin_erreur_droit1' => 'O diretório <code>@dest@</code> não está acessível para escrita.', |
|
| 637 | - 'plugin_erreur_droit2' => 'Por favor, verifique os direitos deste diretório (e criá-lo, caso não exista), ou instalar os arquivos por FTP.', |
|
| 638 | - 'plugin_erreur_zip' => 'falha pclzip: erro @status@', |
|
| 639 | - 'plugin_etat_developpement' => 'em desenvolvimento', |
|
| 640 | - 'plugin_etat_experimental' => 'experimental', |
|
| 641 | - 'plugin_etat_stable' => 'estável', |
|
| 642 | - 'plugin_etat_test' => 'em teste', |
|
| 643 | - 'plugin_impossible_activer' => 'Não foi possível ativar o plugin @plugin@', |
|
| 644 | - 'plugin_info_automatique1' => 'Se você deseja autorizar a instalaçào automática dos plugins, por favor:', |
|
| 645 | - 'plugin_info_automatique1_lib' => 'Se você deseja autorizar a instalação automática desta biblioteca, por favor:', |
|
| 646 | - 'plugin_info_automatique2' => 'crie um diretório <code>@rep@</code> ;', |
|
| 647 | - 'plugin_info_automatique3' => 'verifique se o servidor está autorizado a escrever neste diretório', |
|
| 648 | - 'plugin_info_automatique_creer' => 'a ser criado na raiz do site.', |
|
| 649 | - 'plugin_info_automatique_exemples' => 'exemplos:', |
|
| 650 | - 'plugin_info_automatique_ftp' => 'Você pode instalar os plugins, por FTP, no diretório <tt>@rep@</tt>', |
|
| 651 | - 'plugin_info_automatique_lib' => 'Alguns plugins precisam também poder transferir arquivos para o diretório <code>lib/</code>, a ser criado, caso não exista, na raiz do site.', |
|
| 652 | - 'plugin_info_automatique_liste' => 'Suas listas de plugins:', |
|
| 653 | - 'plugin_info_automatique_liste_officielle' => 'os plugins oficiais', |
|
| 654 | - 'plugin_info_automatique_liste_update' => 'Atualizar as listas', |
|
| 655 | - 'plugin_info_automatique_ou' => 'ou...', |
|
| 656 | - 'plugin_info_automatique_select' => 'Selecione abaixo um plugin: O SPIP o transferirá e o instalará no diretório <code>@rep@</code>; se o plugin já existir, será atualizado.', |
|
| 657 | - 'plugin_info_credit' => 'Créditos', |
|
| 658 | - 'plugin_info_erreur_xml' => 'A declaração deste plugin está incorreta', |
|
| 659 | - 'plugin_info_install_ok' => 'Instalação bem sucedida', |
|
| 660 | - 'plugin_info_necessite' => 'Requer:', |
|
| 661 | - 'plugin_info_non_compatible_spip' => 'Este plugin não é compatível com esta versão do SPIP', |
|
| 662 | - 'plugin_info_plugins_dist_1' => 'Os plugins abaixo são carregados e ativados no diretório @plugins_dist@.', |
|
| 663 | - 'plugin_info_plugins_dist_2' => 'Eles não são desativáveis.', |
|
| 664 | - 'plugin_info_telecharger' => 'transferir de @url@ e instalar em @rep@', |
|
| 665 | - 'plugin_info_upgrade_ok' => 'Atualização bem sucedida', |
|
| 666 | - 'plugin_librairies_installees' => 'Bibliotecas instaladas', |
|
| 667 | - 'plugin_necessite_extension_php' => 'Requer a extensão PHP @plugin@ na versão @version@.', |
|
| 668 | - 'plugin_necessite_extension_php_sans_version' => 'Requer a extensão PHP @plugin@', |
|
| 669 | - 'plugin_necessite_lib' => 'Este plugin precisa da biblioteca @lib@', |
|
| 670 | - 'plugin_necessite_php' => 'Requer @plugin@ na versão @version@.', |
|
| 671 | - 'plugin_necessite_plugin' => 'Precisa do plugin @plugin@, na versão @version@.', |
|
| 672 | - 'plugin_necessite_plugin_sans_version' => 'Precisa do plugin @plugin@', |
|
| 673 | - 'plugin_necessite_spip' => 'É necessário o SPIP na versão @version@, pelo menos.', |
|
| 674 | - 'plugin_source' => 'fonte: ', |
|
| 675 | - 'plugin_titre_automatique' => 'Instalação automática', |
|
| 676 | - 'plugin_titre_automatique_ajouter' => 'Incluir plugins', |
|
| 677 | - 'plugin_titre_installation' => 'Instalação do plugin @plugin@', |
|
| 678 | - 'plugin_titre_modifier' => 'Meus plugins', |
|
| 679 | - 'plugin_utilise_extension_php' => 'A extensão PHP @plugin@ deve estar na versão @version@.', |
|
| 680 | - 'plugin_utilise_php' => '@plugin@ deve estar na versão @version@.', |
|
| 681 | - 'plugin_utilise_plugin' => 'O plugin @plugin@ deve estar na versão @version@.', |
|
| 682 | - 'plugin_zip_active' => 'Continue para o ativar', |
|
| 683 | - 'plugin_zip_adresse' => 'Indique abaixo o endereço de um arquivo zip de plugin a ser transferido, ou ainda o endereço de uma lista de plugins.', |
|
| 684 | - 'plugin_zip_adresse_champ' => 'Endereço do plugin ou da lista', |
|
| 685 | - 'plugin_zip_content' => 'Ele contém os arquivos a seguir (@taille@),<br />prontos para serem instalados no diretório <code>@rep@</code>', |
|
| 686 | - 'plugin_zip_installe_finie' => 'O arquivo @zip@ foi descompactado e instalado.', |
|
| 687 | - 'plugin_zip_installe_rep_finie' => 'O arquivo @zip@ foi descompactado e instalado no diretório @rep@', |
|
| 688 | - 'plugin_zip_installer' => 'Você pode, agora, instalá-lo.', |
|
| 689 | - 'plugin_zip_telecharge' => 'O arquivo @zip@ foi transferido', |
|
| 690 | - 'plugins_actif_aucun' => 'Nenhum plugin ativado.', |
|
| 691 | - 'plugins_actif_un' => 'Um plugin ativado.', |
|
| 692 | - 'plugins_actifs' => '@count@ plugins ativados.', |
|
| 693 | - 'plugins_actifs_liste' => 'Ativos', |
|
| 694 | - 'plugins_compte' => '@count@ plugins', |
|
| 695 | - 'plugins_disponible_un' => 'Um plugin disponível.', |
|
| 696 | - 'plugins_disponibles' => '@count@ plugins disponiveis.', |
|
| 697 | - 'plugins_erreur' => 'Erro nos plugins: @plugins@', |
|
| 698 | - 'plugins_liste' => 'Lista dos plugins', |
|
| 699 | - 'plugins_liste_dist' => 'Plugins bloqueados', |
|
| 700 | - 'plugins_recents' => 'Plugins recentes.', |
|
| 701 | - 'plugins_tous_liste' => 'Todos', |
|
| 702 | - 'plugins_vue_hierarchie' => 'Hierarquia', |
|
| 703 | - 'plugins_vue_liste' => 'Lista', |
|
| 704 | - 'protocole_ldap' => 'Versão do protocolo:', |
|
| 629 | + // P |
|
| 630 | + 'page_pas_proxy' => 'Esta página não deve passar pelo proxy', |
|
| 631 | + 'pas_de_proxy_pour' => 'Se necessário, indique as máquinas ou domínios para os quais este proxy não se aplica (por exemplo: @exemple@)', |
|
| 632 | + 'phpinfo' => 'Configuração PHP', |
|
| 633 | + 'plugin_charge_paquet' => 'Carregamento do pacote @name@', |
|
| 634 | + 'plugin_charger' => 'Transferir', |
|
| 635 | + 'plugin_erreur_charger' => 'erro: não foi possível carregar @zip@', |
|
| 636 | + 'plugin_erreur_droit1' => 'O diretório <code>@dest@</code> não está acessível para escrita.', |
|
| 637 | + 'plugin_erreur_droit2' => 'Por favor, verifique os direitos deste diretório (e criá-lo, caso não exista), ou instalar os arquivos por FTP.', |
|
| 638 | + 'plugin_erreur_zip' => 'falha pclzip: erro @status@', |
|
| 639 | + 'plugin_etat_developpement' => 'em desenvolvimento', |
|
| 640 | + 'plugin_etat_experimental' => 'experimental', |
|
| 641 | + 'plugin_etat_stable' => 'estável', |
|
| 642 | + 'plugin_etat_test' => 'em teste', |
|
| 643 | + 'plugin_impossible_activer' => 'Não foi possível ativar o plugin @plugin@', |
|
| 644 | + 'plugin_info_automatique1' => 'Se você deseja autorizar a instalaçào automática dos plugins, por favor:', |
|
| 645 | + 'plugin_info_automatique1_lib' => 'Se você deseja autorizar a instalação automática desta biblioteca, por favor:', |
|
| 646 | + 'plugin_info_automatique2' => 'crie um diretório <code>@rep@</code> ;', |
|
| 647 | + 'plugin_info_automatique3' => 'verifique se o servidor está autorizado a escrever neste diretório', |
|
| 648 | + 'plugin_info_automatique_creer' => 'a ser criado na raiz do site.', |
|
| 649 | + 'plugin_info_automatique_exemples' => 'exemplos:', |
|
| 650 | + 'plugin_info_automatique_ftp' => 'Você pode instalar os plugins, por FTP, no diretório <tt>@rep@</tt>', |
|
| 651 | + 'plugin_info_automatique_lib' => 'Alguns plugins precisam também poder transferir arquivos para o diretório <code>lib/</code>, a ser criado, caso não exista, na raiz do site.', |
|
| 652 | + 'plugin_info_automatique_liste' => 'Suas listas de plugins:', |
|
| 653 | + 'plugin_info_automatique_liste_officielle' => 'os plugins oficiais', |
|
| 654 | + 'plugin_info_automatique_liste_update' => 'Atualizar as listas', |
|
| 655 | + 'plugin_info_automatique_ou' => 'ou...', |
|
| 656 | + 'plugin_info_automatique_select' => 'Selecione abaixo um plugin: O SPIP o transferirá e o instalará no diretório <code>@rep@</code>; se o plugin já existir, será atualizado.', |
|
| 657 | + 'plugin_info_credit' => 'Créditos', |
|
| 658 | + 'plugin_info_erreur_xml' => 'A declaração deste plugin está incorreta', |
|
| 659 | + 'plugin_info_install_ok' => 'Instalação bem sucedida', |
|
| 660 | + 'plugin_info_necessite' => 'Requer:', |
|
| 661 | + 'plugin_info_non_compatible_spip' => 'Este plugin não é compatível com esta versão do SPIP', |
|
| 662 | + 'plugin_info_plugins_dist_1' => 'Os plugins abaixo são carregados e ativados no diretório @plugins_dist@.', |
|
| 663 | + 'plugin_info_plugins_dist_2' => 'Eles não são desativáveis.', |
|
| 664 | + 'plugin_info_telecharger' => 'transferir de @url@ e instalar em @rep@', |
|
| 665 | + 'plugin_info_upgrade_ok' => 'Atualização bem sucedida', |
|
| 666 | + 'plugin_librairies_installees' => 'Bibliotecas instaladas', |
|
| 667 | + 'plugin_necessite_extension_php' => 'Requer a extensão PHP @plugin@ na versão @version@.', |
|
| 668 | + 'plugin_necessite_extension_php_sans_version' => 'Requer a extensão PHP @plugin@', |
|
| 669 | + 'plugin_necessite_lib' => 'Este plugin precisa da biblioteca @lib@', |
|
| 670 | + 'plugin_necessite_php' => 'Requer @plugin@ na versão @version@.', |
|
| 671 | + 'plugin_necessite_plugin' => 'Precisa do plugin @plugin@, na versão @version@.', |
|
| 672 | + 'plugin_necessite_plugin_sans_version' => 'Precisa do plugin @plugin@', |
|
| 673 | + 'plugin_necessite_spip' => 'É necessário o SPIP na versão @version@, pelo menos.', |
|
| 674 | + 'plugin_source' => 'fonte: ', |
|
| 675 | + 'plugin_titre_automatique' => 'Instalação automática', |
|
| 676 | + 'plugin_titre_automatique_ajouter' => 'Incluir plugins', |
|
| 677 | + 'plugin_titre_installation' => 'Instalação do plugin @plugin@', |
|
| 678 | + 'plugin_titre_modifier' => 'Meus plugins', |
|
| 679 | + 'plugin_utilise_extension_php' => 'A extensão PHP @plugin@ deve estar na versão @version@.', |
|
| 680 | + 'plugin_utilise_php' => '@plugin@ deve estar na versão @version@.', |
|
| 681 | + 'plugin_utilise_plugin' => 'O plugin @plugin@ deve estar na versão @version@.', |
|
| 682 | + 'plugin_zip_active' => 'Continue para o ativar', |
|
| 683 | + 'plugin_zip_adresse' => 'Indique abaixo o endereço de um arquivo zip de plugin a ser transferido, ou ainda o endereço de uma lista de plugins.', |
|
| 684 | + 'plugin_zip_adresse_champ' => 'Endereço do plugin ou da lista', |
|
| 685 | + 'plugin_zip_content' => 'Ele contém os arquivos a seguir (@taille@),<br />prontos para serem instalados no diretório <code>@rep@</code>', |
|
| 686 | + 'plugin_zip_installe_finie' => 'O arquivo @zip@ foi descompactado e instalado.', |
|
| 687 | + 'plugin_zip_installe_rep_finie' => 'O arquivo @zip@ foi descompactado e instalado no diretório @rep@', |
|
| 688 | + 'plugin_zip_installer' => 'Você pode, agora, instalá-lo.', |
|
| 689 | + 'plugin_zip_telecharge' => 'O arquivo @zip@ foi transferido', |
|
| 690 | + 'plugins_actif_aucun' => 'Nenhum plugin ativado.', |
|
| 691 | + 'plugins_actif_un' => 'Um plugin ativado.', |
|
| 692 | + 'plugins_actifs' => '@count@ plugins ativados.', |
|
| 693 | + 'plugins_actifs_liste' => 'Ativos', |
|
| 694 | + 'plugins_compte' => '@count@ plugins', |
|
| 695 | + 'plugins_disponible_un' => 'Um plugin disponível.', |
|
| 696 | + 'plugins_disponibles' => '@count@ plugins disponiveis.', |
|
| 697 | + 'plugins_erreur' => 'Erro nos plugins: @plugins@', |
|
| 698 | + 'plugins_liste' => 'Lista dos plugins', |
|
| 699 | + 'plugins_liste_dist' => 'Plugins bloqueados', |
|
| 700 | + 'plugins_recents' => 'Plugins recentes.', |
|
| 701 | + 'plugins_tous_liste' => 'Todos', |
|
| 702 | + 'plugins_vue_hierarchie' => 'Hierarquia', |
|
| 703 | + 'plugins_vue_liste' => 'Lista', |
|
| 704 | + 'protocole_ldap' => 'Versão do protocolo:', |
|
| 705 | 705 | |
| 706 | - // Q |
|
| 707 | - 'queue_executer_maintenant' => 'Executar agora', |
|
| 708 | - 'queue_info_purger' => 'Você pode excluir todas as tarefas de fundo em espera e reinicializar a lista com as tarefas periódicas', |
|
| 709 | - 'queue_nb_jobs_in_queue' => '@nb@ tarefas em espera', |
|
| 710 | - 'queue_next_job_in_nb_sec' => 'Próxima tarefa em @nb@ s', |
|
| 711 | - 'queue_no_job_in_queue' => 'Nenhum tarefa em espera', |
|
| 712 | - 'queue_one_job_in_queue' => '1 tarefa em espera', |
|
| 713 | - 'queue_priorite_tache' => 'prioridade', |
|
| 714 | - 'queue_purger_queue' => 'Reiniciar a lista de tarefas', |
|
| 715 | - 'queue_titre' => 'Tarefas de fundo', |
|
| 706 | + // Q |
|
| 707 | + 'queue_executer_maintenant' => 'Executar agora', |
|
| 708 | + 'queue_info_purger' => 'Você pode excluir todas as tarefas de fundo em espera e reinicializar a lista com as tarefas periódicas', |
|
| 709 | + 'queue_nb_jobs_in_queue' => '@nb@ tarefas em espera', |
|
| 710 | + 'queue_next_job_in_nb_sec' => 'Próxima tarefa em @nb@ s', |
|
| 711 | + 'queue_no_job_in_queue' => 'Nenhum tarefa em espera', |
|
| 712 | + 'queue_one_job_in_queue' => '1 tarefa em espera', |
|
| 713 | + 'queue_priorite_tache' => 'prioridade', |
|
| 714 | + 'queue_purger_queue' => 'Reiniciar a lista de tarefas', |
|
| 715 | + 'queue_titre' => 'Tarefas de fundo', |
|
| 716 | 716 | |
| 717 | - // R |
|
| 718 | - 'repertoire_plugins' => 'Diretório:', |
|
| 719 | - 'required' => '(obrigatório)', |
|
| 717 | + // R |
|
| 718 | + 'repertoire_plugins' => 'Diretório:', |
|
| 719 | + 'required' => '(obrigatório)', |
|
| 720 | 720 | |
| 721 | - // S |
|
| 722 | - 'sans_heure' => 'sem hora', |
|
| 723 | - 'statut_admin_restreint' => '(admin limitado)', |
|
| 724 | - 'statut_webmestre' => 'webmaster', |
|
| 721 | + // S |
|
| 722 | + 'sans_heure' => 'sem hora', |
|
| 723 | + 'statut_admin_restreint' => '(admin limitado)', |
|
| 724 | + 'statut_webmestre' => 'webmaster', |
|
| 725 | 725 | |
| 726 | - // T |
|
| 727 | - 'tache_cron_asap' => 'Tarefa CRON @function@ (ASAP)', |
|
| 728 | - 'tache_cron_secondes' => 'Tarefa CRON @function@ (a cada @nb@ s)', |
|
| 729 | - 'taille_cache_image' => 'As imagens calculadas automaticamente pelo SPIP (ícones de documentos, títulos apresentados sob a forma gráfica, funções matemáticas em formato TeX...) ocupam, no diretório @dir@, um total de @taille@.', |
|
| 730 | - 'taille_cache_moins_de' => 'O tamanho do cache é menor do que @octets@.', |
|
| 731 | - 'taille_cache_octets' => 'O tamanho atual do cache é de cerca de @octets@.', |
|
| 732 | - 'taille_cache_vide' => 'O cache está vazio.', |
|
| 733 | - 'taille_repertoire_cache' => 'Tamanho do diretório cache', |
|
| 734 | - 'text_article_propose_publication' => 'Matéria proposta para publicação.', |
|
| 735 | - 'texte_acces_ldap_anonyme_1' => 'Alguns servidores LDAP não aceitam nenhum acesso anônimo. Neste caso, é necessário especificar um identificador de acesso inicial de modo a poder, em seguida, pesquisar as informações no diretório. Na maior parte dos casos, entretanto, os campos a seguir poderão ser deixados em branco.', |
|
| 736 | - 'texte_admin_effacer_01' => 'Este comando apaga <i>todo</i> o conteúdo da base de dados,incluindo <i>todos</i> os acessos dos redatores e administradores. Após executá-lo, você deverá reinstalar o SPIP para recriar uma nova base de dados bem como um acesso inicial de administrador.', |
|
| 737 | - 'texte_adresse_annuaire_1' => '(Se o seu diretório está instalado na mesma máquina que este website, trata-se provavelmente de «localhost».)', |
|
| 738 | - 'texte_ajout_auteur' => 'O autor a seguir foi incluído na matéria:', |
|
| 739 | - 'texte_annuaire_ldap_1' => 'Se você tem acesso a um diretório LDAP, você poderá utilizá-lo para importar automaticamente os usuários para o SPIP.', |
|
| 740 | - 'texte_article_statut' => 'Esta matéria está:', |
|
| 741 | - 'texte_article_virtuel' => 'Matéria virtual', |
|
| 742 | - 'texte_article_virtuel_reference' => '<b>Matéria virtual:</b> matéria referenciada no seu site SPIP, mas redirecionada para um outro URL. Para cancelar o redirecionamento, apague o URL abaixo.', |
|
| 743 | - 'texte_aucun_resultat_auteur' => 'Nenhum resultado para "@cherche_auteur@"', |
|
| 744 | - 'texte_auteur_messagerie' => 'Este site pode monitorar permanentemente a lista de editores conectados, permitindo-lhe trocar mensagens em tempo real. Você pode decidir não aparecer nessa lista (ficando "invisível" para os outros usuários).', |
|
| 745 | - 'texte_auteurs' => 'OS AUTORES', |
|
| 746 | - 'texte_choix_base_1' => 'Escolha a sua base:', |
|
| 747 | - 'texte_choix_base_2' => 'O servidor SQL contém várias bases de dados.', |
|
| 748 | - 'texte_choix_base_3' => '<b>Escolha</b> abaixo a que lhe foi atribuída pelo seu serviço de hospedagem:', |
|
| 749 | - 'texte_choix_table_prefix' => 'Prefixo das tabelas:', |
|
| 750 | - 'texte_compte_element' => '@count@ elemento', |
|
| 751 | - 'texte_compte_elements' => '@count@ elementos', |
|
| 752 | - 'texte_conflit_edition_correction' => 'Por favor, controle abaixo as diferenças entre as duas versões do texto; você pode também copiar as suas modificações e depois recomeçar.', |
|
| 753 | - 'texte_connexion_mysql' => 'Consulte as informações fornecidas pelo seu serviço de hospedagem: nelas, você deverá encontrar o servidor de base de dados fornecido e os seus dados de conexão ao servidor SQL.', |
|
| 754 | - 'texte_contenu_article' => '(Conteúdo da matéria em poucas palavras.)', |
|
| 755 | - 'texte_contenu_articles' => 'De acordo com o layout adotado pelo seu site, você poderá decidir se certos elementos das matérias serão utilizados. Use a listagem abaixo para indicar quais elementos estão disponíveis.', |
|
| 756 | - 'texte_crash_base' => 'Se a sua base de dados se corrompeu, você poderá tentar uma reparação automática.', |
|
| 757 | - 'texte_creer_rubrique' => 'Antes de poder escrever matérias, você precisa criar uma seção.', |
|
| 758 | - 'texte_date_creation_article' => 'DATA DE CRIAÇÃO DA MATÉRIA:', |
|
| 759 | - 'texte_date_creation_objet' => 'Data de criação:', # on ajoute le ":" |
|
| 760 | - 'texte_date_publication_anterieure' => 'Data de redação anterior:', |
|
| 761 | - 'texte_date_publication_anterieure_nonaffichee' => 'Não exibir a data de redação anterior.', |
|
| 762 | - 'texte_date_publication_article' => 'DATA DE PUBLICAÇÃO ONLINE:', |
|
| 763 | - 'texte_date_publication_objet' => 'Data de publicação online:', |
|
| 764 | - 'texte_definir_comme_traduction_rubrique' => 'Esta seção é uma tradução da seção número:', |
|
| 765 | - 'texte_descriptif_rapide' => 'Descrição rápida', |
|
| 766 | - 'texte_effacer_base' => 'Apagar a base de dados do SPIP', |
|
| 767 | - 'texte_effacer_statistiques' => 'Apagar as estatísticas', |
|
| 768 | - 'texte_en_cours_validation' => 'Os conteúdos abaixo estão propostos para publicação.', |
|
| 769 | - 'texte_enrichir_mise_a_jour' => 'Você pode enriquecer a diagramação do seu texto usando «atalhos tipográficos».', |
|
| 770 | - 'texte_fichier_authent' => '<b>O SPIP pode criar os arquivos especiais <tt>.htpasswd</tt> e <tt>.htpasswd-admin</tt> no diretório @dossier@?</b><p> |
|
| 726 | + // T |
|
| 727 | + 'tache_cron_asap' => 'Tarefa CRON @function@ (ASAP)', |
|
| 728 | + 'tache_cron_secondes' => 'Tarefa CRON @function@ (a cada @nb@ s)', |
|
| 729 | + 'taille_cache_image' => 'As imagens calculadas automaticamente pelo SPIP (ícones de documentos, títulos apresentados sob a forma gráfica, funções matemáticas em formato TeX...) ocupam, no diretório @dir@, um total de @taille@.', |
|
| 730 | + 'taille_cache_moins_de' => 'O tamanho do cache é menor do que @octets@.', |
|
| 731 | + 'taille_cache_octets' => 'O tamanho atual do cache é de cerca de @octets@.', |
|
| 732 | + 'taille_cache_vide' => 'O cache está vazio.', |
|
| 733 | + 'taille_repertoire_cache' => 'Tamanho do diretório cache', |
|
| 734 | + 'text_article_propose_publication' => 'Matéria proposta para publicação.', |
|
| 735 | + 'texte_acces_ldap_anonyme_1' => 'Alguns servidores LDAP não aceitam nenhum acesso anônimo. Neste caso, é necessário especificar um identificador de acesso inicial de modo a poder, em seguida, pesquisar as informações no diretório. Na maior parte dos casos, entretanto, os campos a seguir poderão ser deixados em branco.', |
|
| 736 | + 'texte_admin_effacer_01' => 'Este comando apaga <i>todo</i> o conteúdo da base de dados,incluindo <i>todos</i> os acessos dos redatores e administradores. Após executá-lo, você deverá reinstalar o SPIP para recriar uma nova base de dados bem como um acesso inicial de administrador.', |
|
| 737 | + 'texte_adresse_annuaire_1' => '(Se o seu diretório está instalado na mesma máquina que este website, trata-se provavelmente de «localhost».)', |
|
| 738 | + 'texte_ajout_auteur' => 'O autor a seguir foi incluído na matéria:', |
|
| 739 | + 'texte_annuaire_ldap_1' => 'Se você tem acesso a um diretório LDAP, você poderá utilizá-lo para importar automaticamente os usuários para o SPIP.', |
|
| 740 | + 'texte_article_statut' => 'Esta matéria está:', |
|
| 741 | + 'texte_article_virtuel' => 'Matéria virtual', |
|
| 742 | + 'texte_article_virtuel_reference' => '<b>Matéria virtual:</b> matéria referenciada no seu site SPIP, mas redirecionada para um outro URL. Para cancelar o redirecionamento, apague o URL abaixo.', |
|
| 743 | + 'texte_aucun_resultat_auteur' => 'Nenhum resultado para "@cherche_auteur@"', |
|
| 744 | + 'texte_auteur_messagerie' => 'Este site pode monitorar permanentemente a lista de editores conectados, permitindo-lhe trocar mensagens em tempo real. Você pode decidir não aparecer nessa lista (ficando "invisível" para os outros usuários).', |
|
| 745 | + 'texte_auteurs' => 'OS AUTORES', |
|
| 746 | + 'texte_choix_base_1' => 'Escolha a sua base:', |
|
| 747 | + 'texte_choix_base_2' => 'O servidor SQL contém várias bases de dados.', |
|
| 748 | + 'texte_choix_base_3' => '<b>Escolha</b> abaixo a que lhe foi atribuída pelo seu serviço de hospedagem:', |
|
| 749 | + 'texte_choix_table_prefix' => 'Prefixo das tabelas:', |
|
| 750 | + 'texte_compte_element' => '@count@ elemento', |
|
| 751 | + 'texte_compte_elements' => '@count@ elementos', |
|
| 752 | + 'texte_conflit_edition_correction' => 'Por favor, controle abaixo as diferenças entre as duas versões do texto; você pode também copiar as suas modificações e depois recomeçar.', |
|
| 753 | + 'texte_connexion_mysql' => 'Consulte as informações fornecidas pelo seu serviço de hospedagem: nelas, você deverá encontrar o servidor de base de dados fornecido e os seus dados de conexão ao servidor SQL.', |
|
| 754 | + 'texte_contenu_article' => '(Conteúdo da matéria em poucas palavras.)', |
|
| 755 | + 'texte_contenu_articles' => 'De acordo com o layout adotado pelo seu site, você poderá decidir se certos elementos das matérias serão utilizados. Use a listagem abaixo para indicar quais elementos estão disponíveis.', |
|
| 756 | + 'texte_crash_base' => 'Se a sua base de dados se corrompeu, você poderá tentar uma reparação automática.', |
|
| 757 | + 'texte_creer_rubrique' => 'Antes de poder escrever matérias, você precisa criar uma seção.', |
|
| 758 | + 'texte_date_creation_article' => 'DATA DE CRIAÇÃO DA MATÉRIA:', |
|
| 759 | + 'texte_date_creation_objet' => 'Data de criação:', # on ajoute le ":" |
|
| 760 | + 'texte_date_publication_anterieure' => 'Data de redação anterior:', |
|
| 761 | + 'texte_date_publication_anterieure_nonaffichee' => 'Não exibir a data de redação anterior.', |
|
| 762 | + 'texte_date_publication_article' => 'DATA DE PUBLICAÇÃO ONLINE:', |
|
| 763 | + 'texte_date_publication_objet' => 'Data de publicação online:', |
|
| 764 | + 'texte_definir_comme_traduction_rubrique' => 'Esta seção é uma tradução da seção número:', |
|
| 765 | + 'texte_descriptif_rapide' => 'Descrição rápida', |
|
| 766 | + 'texte_effacer_base' => 'Apagar a base de dados do SPIP', |
|
| 767 | + 'texte_effacer_statistiques' => 'Apagar as estatísticas', |
|
| 768 | + 'texte_en_cours_validation' => 'Os conteúdos abaixo estão propostos para publicação.', |
|
| 769 | + 'texte_enrichir_mise_a_jour' => 'Você pode enriquecer a diagramação do seu texto usando «atalhos tipográficos».', |
|
| 770 | + 'texte_fichier_authent' => '<b>O SPIP pode criar os arquivos especiais <tt>.htpasswd</tt> e <tt>.htpasswd-admin</tt> no diretório @dossier@?</b><p> |
|
| 771 | 771 | Estes arquivos podem servir para restringir o acesso aos autores e administradores em outras áreas do seu site (programas externos de estatísticas, por exemplo).</p><p> |
| 772 | 772 | Se eles não forem úteis, você poderá deixar esta opção com o seu valor padrão (sem criar os arquivos).</p>', |
| 773 | - 'texte_informations_personnelles_1' => 'O sistema vai criar agora um acesso personalizado ao site.', |
|
| 774 | - 'texte_informations_personnelles_2' => '(Nota: trata-se de uma reinstalação, se o seu acesso funciona corretamente, você pode', |
|
| 775 | - 'texte_introductif_article' => '(Texto introdutório da matéria.)', |
|
| 776 | - 'texte_jeu_caractere' => 'É aconselhável usar no seu site o alfabeto universal (<tt>utf-8</tt>): ele permite a exibição de textos em todos os idiomas, e não tem problemas de compatibilidade com os navegadores modernos.', |
|
| 777 | - 'texte_jeu_caractere_3' => 'O seu site está configurado atualmente com o conjunto de caracteres:', |
|
| 778 | - 'texte_jeu_caractere_4' => 'Se isso não corresponde à realidade dos seus dados (por ex., em seguimento a um restauro da base de dados), ou se <em>você lançou este site</em> e deseja utilizar um outro conjunto de caracteres, por favor, indique-o aqui:', |
|
| 779 | - 'texte_login_ldap_1' => '(Deixe em branco para acesso anônimo, ou informe o caminho completo, por exemplo «<tt>uid=dupont, ou=users, dc=mon-domaine, dc=com</tt>».)', |
|
| 780 | - 'texte_login_precaution' => 'Atenção! Este é o login com o qual você está conectado agora. Use este formulário com cautela...', |
|
| 781 | - 'texte_messagerie_agenda' => 'As mensagens internas permitem que os redatores se comuniquem entre si, diretamente da área privada do site. Elas estão associadas a uma agenda.', |
|
| 782 | - 'texte_mise_a_niveau_base_1' => 'Você acabou de atualizar os arquivos do SPIP. |
|
| 773 | + 'texte_informations_personnelles_1' => 'O sistema vai criar agora um acesso personalizado ao site.', |
|
| 774 | + 'texte_informations_personnelles_2' => '(Nota: trata-se de uma reinstalação, se o seu acesso funciona corretamente, você pode', |
|
| 775 | + 'texte_introductif_article' => '(Texto introdutório da matéria.)', |
|
| 776 | + 'texte_jeu_caractere' => 'É aconselhável usar no seu site o alfabeto universal (<tt>utf-8</tt>): ele permite a exibição de textos em todos os idiomas, e não tem problemas de compatibilidade com os navegadores modernos.', |
|
| 777 | + 'texte_jeu_caractere_3' => 'O seu site está configurado atualmente com o conjunto de caracteres:', |
|
| 778 | + 'texte_jeu_caractere_4' => 'Se isso não corresponde à realidade dos seus dados (por ex., em seguimento a um restauro da base de dados), ou se <em>você lançou este site</em> e deseja utilizar um outro conjunto de caracteres, por favor, indique-o aqui:', |
|
| 779 | + 'texte_login_ldap_1' => '(Deixe em branco para acesso anônimo, ou informe o caminho completo, por exemplo «<tt>uid=dupont, ou=users, dc=mon-domaine, dc=com</tt>».)', |
|
| 780 | + 'texte_login_precaution' => 'Atenção! Este é o login com o qual você está conectado agora. Use este formulário com cautela...', |
|
| 781 | + 'texte_messagerie_agenda' => 'As mensagens internas permitem que os redatores se comuniquem entre si, diretamente da área privada do site. Elas estão associadas a uma agenda.', |
|
| 782 | + 'texte_mise_a_niveau_base_1' => 'Você acabou de atualizar os arquivos do SPIP. |
|
| 783 | 783 | Agora é necessário atualizar a base de dados do site.', |
| 784 | - 'texte_modifier_article' => 'Editar a matéria:', |
|
| 785 | - 'texte_multilinguisme' => 'Se você deseja gerar objetos em diversos idiomas, com uma navegação complexa, você pode incluir um menu de seleção de idioma nesses objetos, de acordo com a estrutura do seu site.', |
|
| 786 | - 'texte_multilinguisme_trad' => 'Você pode, igualmente, ativar um sistema de gerenciamento de links entre as diferentes traduções em certos objetos.', |
|
| 787 | - 'texte_non_compresse' => '<i>não compactado</i> (seu servidor não suporta esta funcionalidade)', |
|
| 788 | - 'texte_nouvelle_version_spip_1' => 'Você instalou uma nova versão do SPIP.', |
|
| 789 | - 'texte_nouvelle_version_spip_2' => 'Esta nova versão precisa de uma atualização mais completa do que o normal. Se você é o webmaster do site, por favor, apague o arquivo @connect@ e retome a instalação de forma a incluir os seus parâmetros de conexão à base de dados.<p> (NB.: se você não se lembra dos seus parâmetros de conexão, consulte o arquivo @connect@ antes de apagá-lo...)</p>', |
|
| 790 | - 'texte_operation_echec' => 'Volte à página anterior, escolha uma outra base de dados ou crie uma nova. Verifique as informações fornecidas pelo seu serviço de hospedagem.', |
|
| 791 | - 'texte_plus_trois_car' => 'mais de 3 caracteres', |
|
| 792 | - 'texte_plusieurs_articles' => 'Demasiados autores encontrados para "@cherche_auteur@":', |
|
| 793 | - 'texte_port_annuaire' => '(O valor padrão indicado é geralmente conveniente.)', |
|
| 794 | - 'texte_presente_plugin' => 'Esta página lista os plugins disponíveis para o site. Você pode ativar os plugins necessários marcando a opção correspondente.', |
|
| 795 | - 'texte_proposer_publication' => 'Assim que a sua matéria estiver pronta, você pode propor a sua publicação.', |
|
| 796 | - 'texte_proxy' => 'Em alguns casos (intranet, redes protegidas...), os sites remotos (documentação do SPIP, sites sindicados etc.) só estarão acessíveis através de um <i>proxy HTTP</i>. Nesse caso, informe abaixo o endereço, no formato @[email protected], você pode deixar este campo vazio.', |
|
| 797 | - 'texte_publication_articles_post_dates' => 'Que comportamento o SPIP deve adotar face às matérias em que a data de publicação está pré-datada?', |
|
| 798 | - 'texte_rappel_selection_champs' => '[Não se esqueça de selecionar corretamente este campo.]', |
|
| 799 | - 'texte_recalcul_page' => 'Se você quiser recalcular uma única página, passe para a área pública e clique no botão «atualizar».', |
|
| 800 | - 'texte_recuperer_base' => 'Reparar a base de dados', |
|
| 801 | - 'texte_reference_mais_redirige' => 'matéria referenciada no seu site em SPIP, mas redirecionada para outro URL.', |
|
| 802 | - 'texte_requetes_echouent' => '<b>Já que certas solicitações SQL falharam sistematicamente e sem razão aparente, é possível que a causa esteja na base de dados em si.</b><p> |
|
| 784 | + 'texte_modifier_article' => 'Editar a matéria:', |
|
| 785 | + 'texte_multilinguisme' => 'Se você deseja gerar objetos em diversos idiomas, com uma navegação complexa, você pode incluir um menu de seleção de idioma nesses objetos, de acordo com a estrutura do seu site.', |
|
| 786 | + 'texte_multilinguisme_trad' => 'Você pode, igualmente, ativar um sistema de gerenciamento de links entre as diferentes traduções em certos objetos.', |
|
| 787 | + 'texte_non_compresse' => '<i>não compactado</i> (seu servidor não suporta esta funcionalidade)', |
|
| 788 | + 'texte_nouvelle_version_spip_1' => 'Você instalou uma nova versão do SPIP.', |
|
| 789 | + 'texte_nouvelle_version_spip_2' => 'Esta nova versão precisa de uma atualização mais completa do que o normal. Se você é o webmaster do site, por favor, apague o arquivo @connect@ e retome a instalação de forma a incluir os seus parâmetros de conexão à base de dados.<p> (NB.: se você não se lembra dos seus parâmetros de conexão, consulte o arquivo @connect@ antes de apagá-lo...)</p>', |
|
| 790 | + 'texte_operation_echec' => 'Volte à página anterior, escolha uma outra base de dados ou crie uma nova. Verifique as informações fornecidas pelo seu serviço de hospedagem.', |
|
| 791 | + 'texte_plus_trois_car' => 'mais de 3 caracteres', |
|
| 792 | + 'texte_plusieurs_articles' => 'Demasiados autores encontrados para "@cherche_auteur@":', |
|
| 793 | + 'texte_port_annuaire' => '(O valor padrão indicado é geralmente conveniente.)', |
|
| 794 | + 'texte_presente_plugin' => 'Esta página lista os plugins disponíveis para o site. Você pode ativar os plugins necessários marcando a opção correspondente.', |
|
| 795 | + 'texte_proposer_publication' => 'Assim que a sua matéria estiver pronta, você pode propor a sua publicação.', |
|
| 796 | + 'texte_proxy' => 'Em alguns casos (intranet, redes protegidas...), os sites remotos (documentação do SPIP, sites sindicados etc.) só estarão acessíveis através de um <i>proxy HTTP</i>. Nesse caso, informe abaixo o endereço, no formato @[email protected], você pode deixar este campo vazio.', |
|
| 797 | + 'texte_publication_articles_post_dates' => 'Que comportamento o SPIP deve adotar face às matérias em que a data de publicação está pré-datada?', |
|
| 798 | + 'texte_rappel_selection_champs' => '[Não se esqueça de selecionar corretamente este campo.]', |
|
| 799 | + 'texte_recalcul_page' => 'Se você quiser recalcular uma única página, passe para a área pública e clique no botão «atualizar».', |
|
| 800 | + 'texte_recuperer_base' => 'Reparar a base de dados', |
|
| 801 | + 'texte_reference_mais_redirige' => 'matéria referenciada no seu site em SPIP, mas redirecionada para outro URL.', |
|
| 802 | + 'texte_requetes_echouent' => '<b>Já que certas solicitações SQL falharam sistematicamente e sem razão aparente, é possível que a causa esteja na base de dados em si.</b><p> |
|
| 803 | 803 | O seu servidor SQL dispõe de uma funcionalidade de reparação das suas tabelas quando elas são danificadas por acidente. Você poderá tentar esta reparação; em caso de falha, conserve uma cópia da mensagem de erro, que poderá conter indícios do que não está funcionando...</p><p> |
| 804 | 804 | Se o problema persistir, contate o seu serviço de hospedagem.</p>', |
| 805 | - 'texte_selection_langue_principale' => 'Você pode escolher abaixo o «idioma principal» do site. esta escolha não o obriga - felizmente! - a escrever as suas matérias no idioma selecionado, mas permite determinar: |
|
| 805 | + 'texte_selection_langue_principale' => 'Você pode escolher abaixo o «idioma principal» do site. esta escolha não o obriga - felizmente! - a escrever as suas matérias no idioma selecionado, mas permite determinar: |
|
| 806 | 806 | <ul><li>o formato padrão das datas no site público;</li> |
| 807 | 807 | <li>a natureza do motor tipográfico que o SPIP deverá usar para a composição dos textos;</li> |
| 808 | 808 | <li>o idioma usado nos formulários do site público;</li> |
| 809 | 809 | <li>o idioma padrão exibido na área privada.</li></ul>', |
| 810 | - 'texte_sous_titre' => 'Subtítulo', |
|
| 811 | - 'texte_statistiques_visites' => '(barras escuras: domingo / curva escura: evolução da média)', |
|
| 812 | - 'texte_statut_attente_validation' => 'aguardando validação', |
|
| 813 | - 'texte_statut_publies' => 'publicadas online', |
|
| 814 | - 'texte_statut_refuses' => 'recusadas', |
|
| 815 | - 'texte_suppression_fichiers' => 'Use este comando para excluir todos os arquivos que constam do cache do SPIP. Isto permite, por exemplo, forçar a reconstrução de todas as páginas, caso você tenha feito alterações importantes no layout ou na estrutura do site.', |
|
| 816 | - 'texte_sur_titre' => 'Sobretítulo', |
|
| 817 | - 'texte_table_ok' => ': esta tabela está OK.', |
|
| 818 | - 'texte_tentative_recuperation' => 'Tentativa de reparação', |
|
| 819 | - 'texte_tenter_reparation' => 'Tentar uma reparação da base de dados', |
|
| 820 | - 'texte_test_proxy' => 'Para testar este proxy, informe aqui o endereço de um website que você deseje testar.', |
|
| 821 | - 'texte_titre_02' => 'Título:', |
|
| 822 | - 'texte_titre_obligatoire' => '<b>Título</b> [obrigatório]', |
|
| 823 | - 'texte_travail_article' => '@nom_auteur_modif@ trabalhou nesta matéria há @date_diff@ minutos', |
|
| 824 | - 'texte_travail_collaboratif' => 'Se é frequente acontecer de mais de um redator trabalhar em uma mesma matéria, o sistema pode exibir as matérias recentemente "abertas", de modo a evitar modificações concorrentes. Esta opção está desativada por padrão, para evitar a exibição de mensagens de aviso desnecessárias.', |
|
| 825 | - 'texte_vide' => 'vazia', |
|
| 826 | - 'texte_vider_cache' => 'Esvaziar o cache', |
|
| 827 | - 'titre_admin_tech' => 'Manutenção técnica', |
|
| 828 | - 'titre_admin_vider' => 'Manutenção técnica', |
|
| 829 | - 'titre_ajouter_un_auteur' => 'Incluir um autor', |
|
| 830 | - 'titre_ajouter_un_mot' => 'Incluir uma palavra-chave', |
|
| 831 | - 'titre_cadre_afficher_article' => 'Exibir as matérias', |
|
| 832 | - 'titre_cadre_afficher_traductions' => 'Exibir o status das traduções para os idiomas a seguir:', |
|
| 833 | - 'titre_cadre_ajouter_auteur' => 'INCLUIR UM AUTOR:', |
|
| 834 | - 'titre_cadre_interieur_rubrique' => 'Na seção', |
|
| 835 | - 'titre_cadre_numero_auteur' => 'AUTOR NÚMERO', |
|
| 836 | - 'titre_cadre_numero_objet' => '@objet@ NÚMERO:', |
|
| 837 | - 'titre_cadre_signature_obligatoire' => '<b>Assinatura</b> [obrigatório]<br />', |
|
| 838 | - 'titre_config_contenu_notifications' => 'Notificações', |
|
| 839 | - 'titre_config_contenu_prive' => 'Na área privada', |
|
| 840 | - 'titre_config_contenu_public' => 'No site público', |
|
| 841 | - 'titre_config_fonctions' => 'Configuração do site', |
|
| 842 | - 'titre_config_langage' => 'Configurar o idioma', |
|
| 843 | - 'titre_configuration' => 'Configuração do site', |
|
| 844 | - 'titre_configurer_preferences' => 'Configurar as suas preferências', |
|
| 845 | - 'titre_configurer_preferences_menus' => 'Configurar as suas preferências de menus', |
|
| 846 | - 'titre_conflit_edition' => 'Conflito durante a edição', |
|
| 847 | - 'titre_connexion_ldap' => 'Opções: <b>Sua conexão LDAP</b>', |
|
| 848 | - 'titre_groupe_mots' => 'GRUPO DE PALAVRAS-CHAVE:', |
|
| 849 | - 'titre_identite_site' => 'Identidade do site', |
|
| 850 | - 'titre_langue_article' => 'Idioma da matéria', |
|
| 851 | - 'titre_langue_rubrique' => 'Idioma da seção', |
|
| 852 | - 'titre_langue_trad_article' => 'IDIOMA E TRADUÇÕES DA MATÉRIA', |
|
| 853 | - 'titre_les_articles' => 'AS MATÉRIAS', |
|
| 854 | - 'titre_messagerie_agenda' => 'Mensagens internas e agenda', |
|
| 855 | - 'titre_naviguer_dans_le_site' => 'Navegar no site...', |
|
| 856 | - 'titre_nouvelle_rubrique' => 'Nova seção', |
|
| 857 | - 'titre_numero_rubrique' => 'SEÇÃO NÚMERO:', |
|
| 858 | - 'titre_page_articles_edit' => 'Editar: @titre@', |
|
| 859 | - 'titre_page_articles_page' => 'As matérias', |
|
| 860 | - 'titre_page_articles_tous' => 'Todo o site', |
|
| 861 | - 'titre_page_calendrier' => 'Calendário @nom_mois@ @annee@', |
|
| 862 | - 'titre_page_config_contenu' => 'Configuração do site', |
|
| 863 | - 'titre_page_delete_all' => 'supressão total e irreversível', |
|
| 864 | - 'titre_page_recherche' => 'Resultados da busca por @recherche@', |
|
| 865 | - 'titre_page_statistiques_referers' => 'Estatísticas (links de entrada)', |
|
| 866 | - 'titre_page_upgrade' => 'Atualização do SPIP', |
|
| 867 | - 'titre_preference_menus_favoris' => 'Menus favoritos', |
|
| 868 | - 'titre_publication_articles_post_dates' => 'Publicação de matérias pós-datadas', |
|
| 869 | - 'titre_reparation' => 'Reparação', |
|
| 870 | - 'titre_suivi_petition' => 'Acompanhamento das petições', |
|
| 871 | - 'tls_ldap' => 'Transport Layer Security:', |
|
| 872 | - 'trad_article_traduction' => 'Todas as versões desta matéria:', |
|
| 873 | - 'trad_delier' => 'Desvincular destas traduções', |
|
| 874 | - 'trad_lier' => 'Esta matéria é uma tradução da matéria número:', |
|
| 875 | - 'trad_new' => 'Escrever uma nova tradução', |
|
| 810 | + 'texte_sous_titre' => 'Subtítulo', |
|
| 811 | + 'texte_statistiques_visites' => '(barras escuras: domingo / curva escura: evolução da média)', |
|
| 812 | + 'texte_statut_attente_validation' => 'aguardando validação', |
|
| 813 | + 'texte_statut_publies' => 'publicadas online', |
|
| 814 | + 'texte_statut_refuses' => 'recusadas', |
|
| 815 | + 'texte_suppression_fichiers' => 'Use este comando para excluir todos os arquivos que constam do cache do SPIP. Isto permite, por exemplo, forçar a reconstrução de todas as páginas, caso você tenha feito alterações importantes no layout ou na estrutura do site.', |
|
| 816 | + 'texte_sur_titre' => 'Sobretítulo', |
|
| 817 | + 'texte_table_ok' => ': esta tabela está OK.', |
|
| 818 | + 'texte_tentative_recuperation' => 'Tentativa de reparação', |
|
| 819 | + 'texte_tenter_reparation' => 'Tentar uma reparação da base de dados', |
|
| 820 | + 'texte_test_proxy' => 'Para testar este proxy, informe aqui o endereço de um website que você deseje testar.', |
|
| 821 | + 'texte_titre_02' => 'Título:', |
|
| 822 | + 'texte_titre_obligatoire' => '<b>Título</b> [obrigatório]', |
|
| 823 | + 'texte_travail_article' => '@nom_auteur_modif@ trabalhou nesta matéria há @date_diff@ minutos', |
|
| 824 | + 'texte_travail_collaboratif' => 'Se é frequente acontecer de mais de um redator trabalhar em uma mesma matéria, o sistema pode exibir as matérias recentemente "abertas", de modo a evitar modificações concorrentes. Esta opção está desativada por padrão, para evitar a exibição de mensagens de aviso desnecessárias.', |
|
| 825 | + 'texte_vide' => 'vazia', |
|
| 826 | + 'texte_vider_cache' => 'Esvaziar o cache', |
|
| 827 | + 'titre_admin_tech' => 'Manutenção técnica', |
|
| 828 | + 'titre_admin_vider' => 'Manutenção técnica', |
|
| 829 | + 'titre_ajouter_un_auteur' => 'Incluir um autor', |
|
| 830 | + 'titre_ajouter_un_mot' => 'Incluir uma palavra-chave', |
|
| 831 | + 'titre_cadre_afficher_article' => 'Exibir as matérias', |
|
| 832 | + 'titre_cadre_afficher_traductions' => 'Exibir o status das traduções para os idiomas a seguir:', |
|
| 833 | + 'titre_cadre_ajouter_auteur' => 'INCLUIR UM AUTOR:', |
|
| 834 | + 'titre_cadre_interieur_rubrique' => 'Na seção', |
|
| 835 | + 'titre_cadre_numero_auteur' => 'AUTOR NÚMERO', |
|
| 836 | + 'titre_cadre_numero_objet' => '@objet@ NÚMERO:', |
|
| 837 | + 'titre_cadre_signature_obligatoire' => '<b>Assinatura</b> [obrigatório]<br />', |
|
| 838 | + 'titre_config_contenu_notifications' => 'Notificações', |
|
| 839 | + 'titre_config_contenu_prive' => 'Na área privada', |
|
| 840 | + 'titre_config_contenu_public' => 'No site público', |
|
| 841 | + 'titre_config_fonctions' => 'Configuração do site', |
|
| 842 | + 'titre_config_langage' => 'Configurar o idioma', |
|
| 843 | + 'titre_configuration' => 'Configuração do site', |
|
| 844 | + 'titre_configurer_preferences' => 'Configurar as suas preferências', |
|
| 845 | + 'titre_configurer_preferences_menus' => 'Configurar as suas preferências de menus', |
|
| 846 | + 'titre_conflit_edition' => 'Conflito durante a edição', |
|
| 847 | + 'titre_connexion_ldap' => 'Opções: <b>Sua conexão LDAP</b>', |
|
| 848 | + 'titre_groupe_mots' => 'GRUPO DE PALAVRAS-CHAVE:', |
|
| 849 | + 'titre_identite_site' => 'Identidade do site', |
|
| 850 | + 'titre_langue_article' => 'Idioma da matéria', |
|
| 851 | + 'titre_langue_rubrique' => 'Idioma da seção', |
|
| 852 | + 'titre_langue_trad_article' => 'IDIOMA E TRADUÇÕES DA MATÉRIA', |
|
| 853 | + 'titre_les_articles' => 'AS MATÉRIAS', |
|
| 854 | + 'titre_messagerie_agenda' => 'Mensagens internas e agenda', |
|
| 855 | + 'titre_naviguer_dans_le_site' => 'Navegar no site...', |
|
| 856 | + 'titre_nouvelle_rubrique' => 'Nova seção', |
|
| 857 | + 'titre_numero_rubrique' => 'SEÇÃO NÚMERO:', |
|
| 858 | + 'titre_page_articles_edit' => 'Editar: @titre@', |
|
| 859 | + 'titre_page_articles_page' => 'As matérias', |
|
| 860 | + 'titre_page_articles_tous' => 'Todo o site', |
|
| 861 | + 'titre_page_calendrier' => 'Calendário @nom_mois@ @annee@', |
|
| 862 | + 'titre_page_config_contenu' => 'Configuração do site', |
|
| 863 | + 'titre_page_delete_all' => 'supressão total e irreversível', |
|
| 864 | + 'titre_page_recherche' => 'Resultados da busca por @recherche@', |
|
| 865 | + 'titre_page_statistiques_referers' => 'Estatísticas (links de entrada)', |
|
| 866 | + 'titre_page_upgrade' => 'Atualização do SPIP', |
|
| 867 | + 'titre_preference_menus_favoris' => 'Menus favoritos', |
|
| 868 | + 'titre_publication_articles_post_dates' => 'Publicação de matérias pós-datadas', |
|
| 869 | + 'titre_reparation' => 'Reparação', |
|
| 870 | + 'titre_suivi_petition' => 'Acompanhamento das petições', |
|
| 871 | + 'tls_ldap' => 'Transport Layer Security:', |
|
| 872 | + 'trad_article_traduction' => 'Todas as versões desta matéria:', |
|
| 873 | + 'trad_delier' => 'Desvincular destas traduções', |
|
| 874 | + 'trad_lier' => 'Esta matéria é uma tradução da matéria número:', |
|
| 875 | + 'trad_new' => 'Escrever uma nova tradução', |
|
| 876 | 876 | |
| 877 | - // U |
|
| 878 | - 'utf8_convert_erreur_orig' => 'Erro: o conjunto de caracteres @charset@ não é suportado.', |
|
| 877 | + // U |
|
| 878 | + 'utf8_convert_erreur_orig' => 'Erro: o conjunto de caracteres @charset@ não é suportado.', |
|
| 879 | 879 | |
| 880 | - // V |
|
| 881 | - 'version' => 'Versão:' |
|
| 880 | + // V |
|
| 881 | + 'version' => 'Versão:' |
|
| 882 | 882 | ); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 38 | 38 | **/ |
| 39 | 39 | function extraire_date($texte): string { |
| 40 | - // format = 2001-08 |
|
| 41 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | - } |
|
| 44 | - return ''; |
|
| 40 | + // format = 2001-08 |
|
| 41 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | + } |
|
| 44 | + return ''; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
@@ -63,29 +63,29 @@ discard block |
||
| 63 | 63 | * - une chaîne vide si la date est considérée nulle |
| 64 | 64 | **/ |
| 65 | 65 | function normaliser_date($date, $forcer_jour = false): string { |
| 66 | - $date = vider_date($date); |
|
| 67 | - if ($date) { |
|
| 68 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | - $date = date('Y-m-d H:i:s', $date); |
|
| 70 | - } |
|
| 71 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | - } else { |
|
| 75 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | - } else { |
|
| 79 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if ($forcer_jour) { |
|
| 84 | - $date = str_replace('-00', '-01', $date); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $date; |
|
| 66 | + $date = vider_date($date); |
|
| 67 | + if ($date) { |
|
| 68 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | + $date = date('Y-m-d H:i:s', $date); |
|
| 70 | + } |
|
| 71 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | + } else { |
|
| 75 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | + } else { |
|
| 79 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if ($forcer_jour) { |
|
| 84 | + $date = str_replace('-00', '-01', $date); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $date; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -98,23 +98,23 @@ discard block |
||
| 98 | 98 | * - Une chaine vide |
| 99 | 99 | **/ |
| 100 | 100 | function vider_date($letexte, $verif_format_date = false): string { |
| 101 | - $letexte ??= ''; |
|
| 102 | - if ( |
|
| 103 | - !$verif_format_date |
|
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | - ) { |
|
| 107 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } |
|
| 113 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | - return ''; |
|
| 115 | - } // eviter le bug GMT-1 |
|
| 116 | - } |
|
| 117 | - return $letexte; |
|
| 101 | + $letexte ??= ''; |
|
| 102 | + if ( |
|
| 103 | + !$verif_format_date |
|
| 104 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | + ) { |
|
| 107 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } |
|
| 113 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | + return ''; |
|
| 115 | + } // eviter le bug GMT-1 |
|
| 116 | + } |
|
| 117 | + return $letexte; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | **/ |
| 131 | 131 | function recup_heure($date): array { |
| 132 | 132 | |
| 133 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | - array_shift($elements); |
|
| 135 | - if (!isset($elements[2])) { |
|
| 136 | - $elements[2] = 0; |
|
| 137 | - } |
|
| 138 | - $heure = $elements; |
|
| 139 | - } else { |
|
| 140 | - $heure = [0, 0, 0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $heure; |
|
| 133 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | + array_shift($elements); |
|
| 135 | + if (!isset($elements[2])) { |
|
| 136 | + $elements[2] = 0; |
|
| 137 | + } |
|
| 138 | + $heure = $elements; |
|
| 139 | + } else { |
|
| 140 | + $heure = [0, 0, 0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $heure; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * @return string heures, sinon 0 |
| 155 | 155 | **/ |
| 156 | 156 | function heures($numdate): string { |
| 157 | - $heures = null; |
|
| 158 | - $date_array = recup_heure($numdate); |
|
| 159 | - if ($date_array) { |
|
| 160 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | - } |
|
| 157 | + $heures = null; |
|
| 158 | + $date_array = recup_heure($numdate); |
|
| 159 | + if ($date_array) { |
|
| 160 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $heures; |
|
| 163 | + return $heures; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string minutes, sinon 0 |
| 175 | 175 | **/ |
| 176 | 176 | function minutes($numdate): string { |
| 177 | - $minutes = null; |
|
| 178 | - $date_array = recup_heure($numdate); |
|
| 179 | - if ($date_array) { |
|
| 180 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | - } |
|
| 177 | + $minutes = null; |
|
| 178 | + $date_array = recup_heure($numdate); |
|
| 179 | + if ($date_array) { |
|
| 180 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $minutes; |
|
| 183 | + return $minutes; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | * @return string secondes, sinon 0 |
| 195 | 195 | **/ |
| 196 | 196 | function secondes($numdate): string { |
| 197 | - $secondes = null; |
|
| 198 | - $date_array = recup_heure($numdate); |
|
| 199 | - if ($date_array) { |
|
| 200 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | - } |
|
| 197 | + $secondes = null; |
|
| 198 | + $date_array = recup_heure($numdate); |
|
| 199 | + if ($date_array) { |
|
| 200 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $secondes; |
|
| 203 | + return $secondes; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * @return string L'heure formatée dans la langue en cours. |
| 220 | 220 | **/ |
| 221 | 221 | function heures_minutes($numdate, $forme = ''): string { |
| 222 | - if ($forme !== 'abbr') { |
|
| 223 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | - } else { |
|
| 225 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | - } |
|
| 222 | + if ($forme !== 'abbr') { |
|
| 223 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | + } else { |
|
| 225 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | + } |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -248,57 +248,57 @@ discard block |
||
| 248 | 248 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 249 | 249 | **/ |
| 250 | 250 | function recup_date($numdate, $forcer_jour = true): array { |
| 251 | - if (!$numdate) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 254 | - $heures = $minutes = $secondes = 0; |
|
| 255 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | - $jour = $regs[1]; |
|
| 257 | - $mois = $regs[2]; |
|
| 258 | - $annee = $regs[3]; |
|
| 259 | - if ($annee < 90) { |
|
| 260 | - $annee = 2000 + $annee; |
|
| 261 | - } elseif ($annee < 100) { |
|
| 262 | - $annee = 1900 + $annee; |
|
| 263 | - } |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = $regs[3]; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = ''; |
|
| 274 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | - $annee = $regs[1]; |
|
| 277 | - $mois = $regs[2]; |
|
| 278 | - $jour = $regs[3]; |
|
| 279 | - $heures = $regs[4]; |
|
| 280 | - $minutes = $regs[5]; |
|
| 281 | - $secondes = $regs[6]; |
|
| 282 | - } else { |
|
| 283 | - $annee = $mois = $jour = ''; |
|
| 284 | - } |
|
| 285 | - if ($annee > 4000) { |
|
| 286 | - $annee -= 9000; |
|
| 287 | - } |
|
| 288 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | - $jour = substr($jour, 1); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($forcer_jour and $jour == '0') { |
|
| 293 | - $jour = '1'; |
|
| 294 | - } |
|
| 295 | - if ($forcer_jour and $mois == '0') { |
|
| 296 | - $mois = '1'; |
|
| 297 | - } |
|
| 298 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | - } |
|
| 301 | - return []; |
|
| 251 | + if (!$numdate) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | + $heures = $minutes = $secondes = 0; |
|
| 255 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | + $jour = $regs[1]; |
|
| 257 | + $mois = $regs[2]; |
|
| 258 | + $annee = $regs[3]; |
|
| 259 | + if ($annee < 90) { |
|
| 260 | + $annee = 2000 + $annee; |
|
| 261 | + } elseif ($annee < 100) { |
|
| 262 | + $annee = 1900 + $annee; |
|
| 263 | + } |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = $regs[3]; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = ''; |
|
| 274 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | + $annee = $regs[1]; |
|
| 277 | + $mois = $regs[2]; |
|
| 278 | + $jour = $regs[3]; |
|
| 279 | + $heures = $regs[4]; |
|
| 280 | + $minutes = $regs[5]; |
|
| 281 | + $secondes = $regs[6]; |
|
| 282 | + } else { |
|
| 283 | + $annee = $mois = $jour = ''; |
|
| 284 | + } |
|
| 285 | + if ($annee > 4000) { |
|
| 286 | + $annee -= 9000; |
|
| 287 | + } |
|
| 288 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | + $jour = substr($jour, 1); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($forcer_jour and $jour == '0') { |
|
| 293 | + $jour = '1'; |
|
| 294 | + } |
|
| 295 | + if ($forcer_jour and $mois == '0') { |
|
| 296 | + $mois = '1'; |
|
| 297 | + } |
|
| 298 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | + } |
|
| 301 | + return []; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * La date relative ou complète |
| 326 | 326 | **/ |
| 327 | 327 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 328 | - return sinon( |
|
| 329 | - date_relative($date, $decalage_maxi), |
|
| 330 | - affdate_heure($date) |
|
| 331 | - ); |
|
| 328 | + return sinon( |
|
| 329 | + date_relative($date, $decalage_maxi), |
|
| 330 | + affdate_heure($date) |
|
| 331 | + ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -361,86 +361,86 @@ discard block |
||
| 361 | 361 | **/ |
| 362 | 362 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 363 | 363 | |
| 364 | - if (!$date) { |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - if (is_null($ref_date)) { |
|
| 369 | - $ref_time = time(); |
|
| 370 | - } else { |
|
| 371 | - $ref_time = strtotime($ref_date); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | - |
|
| 376 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | - return ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal < 0) { |
|
| 381 | - $il_y_a = 'date_dans'; |
|
| 382 | - $decal = -1 * $decal; |
|
| 383 | - } else { |
|
| 384 | - $il_y_a = 'date_il_y_a'; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | - return affdate_court($date); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($decal > 3600 * 24 * 30) { |
|
| 392 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | - if ($mois < 2) { |
|
| 394 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | - } else { |
|
| 396 | - $delai = "$mois " . _T('date_mois'); |
|
| 397 | - } |
|
| 398 | - } else { |
|
| 399 | - if ($decal > 3600 * 24 * 7) { |
|
| 400 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | - if ($semaines < 2) { |
|
| 402 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | - } else { |
|
| 404 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - if ($decal > 3600 * 24) { |
|
| 408 | - $jours = floor($decal / (3600 * 24)); |
|
| 409 | - if ($jours < 2) { |
|
| 410 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | - } else { |
|
| 412 | - $delai = "$jours " . _T('date_jours'); |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - if ($decal >= 3600) { |
|
| 416 | - $heures = floor($decal / 3600); |
|
| 417 | - if ($heures < 2) { |
|
| 418 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | - } else { |
|
| 420 | - $delai = "$heures " . _T('date_heures'); |
|
| 421 | - } |
|
| 422 | - } else { |
|
| 423 | - if ($decal >= 60) { |
|
| 424 | - $minutes = floor($decal / 60); |
|
| 425 | - if ($minutes < 2) { |
|
| 426 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | - } |
|
| 430 | - } else { |
|
| 431 | - $secondes = ceil($decal); |
|
| 432 | - if ($secondes < 2) { |
|
| 433 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | - } else { |
|
| 435 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 364 | + if (!$date) { |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + if (is_null($ref_date)) { |
|
| 369 | + $ref_time = time(); |
|
| 370 | + } else { |
|
| 371 | + $ref_time = strtotime($ref_date); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | + |
|
| 376 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | + return ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal < 0) { |
|
| 381 | + $il_y_a = 'date_dans'; |
|
| 382 | + $decal = -1 * $decal; |
|
| 383 | + } else { |
|
| 384 | + $il_y_a = 'date_il_y_a'; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | + return affdate_court($date); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($decal > 3600 * 24 * 30) { |
|
| 392 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | + if ($mois < 2) { |
|
| 394 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | + } else { |
|
| 396 | + $delai = "$mois " . _T('date_mois'); |
|
| 397 | + } |
|
| 398 | + } else { |
|
| 399 | + if ($decal > 3600 * 24 * 7) { |
|
| 400 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | + if ($semaines < 2) { |
|
| 402 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | + } else { |
|
| 404 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + if ($decal > 3600 * 24) { |
|
| 408 | + $jours = floor($decal / (3600 * 24)); |
|
| 409 | + if ($jours < 2) { |
|
| 410 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | + } else { |
|
| 412 | + $delai = "$jours " . _T('date_jours'); |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + if ($decal >= 3600) { |
|
| 416 | + $heures = floor($decal / 3600); |
|
| 417 | + if ($heures < 2) { |
|
| 418 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | + } else { |
|
| 420 | + $delai = "$heures " . _T('date_heures'); |
|
| 421 | + } |
|
| 422 | + } else { |
|
| 423 | + if ($decal >= 60) { |
|
| 424 | + $minutes = floor($decal / 60); |
|
| 425 | + if ($minutes < 2) { |
|
| 426 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | + } |
|
| 430 | + } else { |
|
| 431 | + $secondes = ceil($decal); |
|
| 432 | + if ($secondes < 2) { |
|
| 433 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | + } else { |
|
| 435 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -466,32 +466,32 @@ discard block |
||
| 466 | 466 | **/ |
| 467 | 467 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 468 | 468 | |
| 469 | - if (!$date) { |
|
| 470 | - return ''; |
|
| 471 | - } |
|
| 472 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | - |
|
| 474 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($decal < -24 * 3600) { |
|
| 479 | - $retour = date_relative($date, $decalage_maxi); |
|
| 480 | - } elseif ($decal < 0) { |
|
| 481 | - $retour = _T('date_demain'); |
|
| 482 | - } else { |
|
| 483 | - if ($decal < (3600 * 24)) { |
|
| 484 | - $retour = _T('date_aujourdhui'); |
|
| 485 | - } else { |
|
| 486 | - if ($decal < (3600 * 24 * 2)) { |
|
| 487 | - $retour = _T('date_hier'); |
|
| 488 | - } else { |
|
| 489 | - $retour = date_relative($date, $decalage_maxi); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $retour; |
|
| 469 | + if (!$date) { |
|
| 470 | + return ''; |
|
| 471 | + } |
|
| 472 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | + |
|
| 474 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($decal < -24 * 3600) { |
|
| 479 | + $retour = date_relative($date, $decalage_maxi); |
|
| 480 | + } elseif ($decal < 0) { |
|
| 481 | + $retour = _T('date_demain'); |
|
| 482 | + } else { |
|
| 483 | + if ($decal < (3600 * 24)) { |
|
| 484 | + $retour = _T('date_aujourdhui'); |
|
| 485 | + } else { |
|
| 486 | + if ($decal < (3600 * 24 * 2)) { |
|
| 487 | + $retour = _T('date_hier'); |
|
| 488 | + } else { |
|
| 489 | + $retour = date_relative($date, $decalage_maxi); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $retour; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -508,174 +508,174 @@ discard block |
||
| 508 | 508 | * @return string |
| 509 | 509 | */ |
| 510 | 510 | function affdate_base($numdate, $vue, $options = []): string { |
| 511 | - if (is_string($options)) { |
|
| 512 | - $options = ['param' => $options]; |
|
| 513 | - } |
|
| 514 | - $date_array = recup_date($numdate, false); |
|
| 515 | - if (!$date_array) { |
|
| 516 | - return ''; |
|
| 517 | - } |
|
| 518 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | - |
|
| 520 | - // 1er, 21st, etc. |
|
| 521 | - $journum = $jour; |
|
| 522 | - |
|
| 523 | - if ($jour == 0) { |
|
| 524 | - $jour = ''; |
|
| 525 | - $njour = 0; |
|
| 526 | - } else { |
|
| 527 | - $njour = intval($jour); |
|
| 528 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | - $jour = $jourth; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $mois = intval($mois); |
|
| 534 | - if ($mois > 0 and $mois < 13) { |
|
| 535 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | - if ($jour) { |
|
| 539 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | - } else { |
|
| 541 | - $jourmois = $nommois; |
|
| 542 | - } |
|
| 543 | - } else { |
|
| 544 | - $nommois = ''; |
|
| 545 | - $jourmois = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($annee < 0) { |
|
| 549 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | - $avjc = true; |
|
| 551 | - } else { |
|
| 552 | - $avjc = false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - switch ($vue) { |
|
| 556 | - case 'saison': |
|
| 557 | - case 'saison_annee': |
|
| 558 | - $saison = ''; |
|
| 559 | - if ($mois > 0) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | - } |
|
| 564 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | - } |
|
| 567 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | - } |
|
| 570 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - if ($vue == 'saison') { |
|
| 575 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | - } else { |
|
| 577 | - return $saison ? trim(_T( |
|
| 578 | - 'date_fmt_saison_annee', |
|
| 579 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | - )) : ''; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - case 'court': |
|
| 584 | - if ($avjc) { |
|
| 585 | - return $annee; |
|
| 586 | - } |
|
| 587 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | - return $annee; |
|
| 590 | - } |
|
| 591 | - if ($annee != $a) { |
|
| 592 | - return _T( |
|
| 593 | - 'date_fmt_mois_annee', |
|
| 594 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return _T( |
|
| 599 | - 'date_fmt_jour_mois', |
|
| 600 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | - ); |
|
| 602 | - |
|
| 603 | - case 'jourcourt': |
|
| 604 | - if ($avjc) { |
|
| 605 | - return $annee; |
|
| 606 | - } |
|
| 607 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | - return $annee; |
|
| 610 | - } |
|
| 611 | - if ($annee != $a) { |
|
| 612 | - return _T( |
|
| 613 | - 'date_fmt_jour_mois_annee', |
|
| 614 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return _T( |
|
| 619 | - 'date_fmt_jour_mois', |
|
| 620 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - case 'entier': |
|
| 624 | - if ($avjc) { |
|
| 625 | - return $annee; |
|
| 626 | - } |
|
| 627 | - if ($jour) { |
|
| 628 | - return _T( |
|
| 629 | - 'date_fmt_jour_mois_annee', |
|
| 630 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | - ); |
|
| 632 | - } elseif ($mois) { |
|
| 633 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | - } else { |
|
| 635 | - return $annee; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - case 'nom_mois': |
|
| 639 | - return $nommois; |
|
| 640 | - |
|
| 641 | - case 'mois': |
|
| 642 | - return sprintf('%02s', $mois); |
|
| 643 | - |
|
| 644 | - case 'jour': |
|
| 645 | - return $jour; |
|
| 646 | - |
|
| 647 | - case 'journum': |
|
| 648 | - return $journum; |
|
| 649 | - |
|
| 650 | - case 'nom_jour': |
|
| 651 | - if (!$mois or !$njour) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | - $nom = 1 + (int) date('w', $nom); |
|
| 656 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | - |
|
| 658 | - return _T('date_jour_' . $nom . $param); |
|
| 659 | - |
|
| 660 | - case 'mois_annee': |
|
| 661 | - if ($avjc) { |
|
| 662 | - return $annee; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | - |
|
| 667 | - case 'annee': |
|
| 668 | - return $annee; |
|
| 669 | - |
|
| 670 | - // Cas d'une vue non definie : retomber sur le format |
|
| 671 | - // de date propose par http://www.php.net/date |
|
| 672 | - default: |
|
| 673 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | - $time = strtotime($numdate); |
|
| 676 | - } |
|
| 677 | - return date($vue, $time); |
|
| 678 | - } |
|
| 511 | + if (is_string($options)) { |
|
| 512 | + $options = ['param' => $options]; |
|
| 513 | + } |
|
| 514 | + $date_array = recup_date($numdate, false); |
|
| 515 | + if (!$date_array) { |
|
| 516 | + return ''; |
|
| 517 | + } |
|
| 518 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | + |
|
| 520 | + // 1er, 21st, etc. |
|
| 521 | + $journum = $jour; |
|
| 522 | + |
|
| 523 | + if ($jour == 0) { |
|
| 524 | + $jour = ''; |
|
| 525 | + $njour = 0; |
|
| 526 | + } else { |
|
| 527 | + $njour = intval($jour); |
|
| 528 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | + $jour = $jourth; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $mois = intval($mois); |
|
| 534 | + if ($mois > 0 and $mois < 13) { |
|
| 535 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | + if ($jour) { |
|
| 539 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | + } else { |
|
| 541 | + $jourmois = $nommois; |
|
| 542 | + } |
|
| 543 | + } else { |
|
| 544 | + $nommois = ''; |
|
| 545 | + $jourmois = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($annee < 0) { |
|
| 549 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | + $avjc = true; |
|
| 551 | + } else { |
|
| 552 | + $avjc = false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + switch ($vue) { |
|
| 556 | + case 'saison': |
|
| 557 | + case 'saison_annee': |
|
| 558 | + $saison = ''; |
|
| 559 | + if ($mois > 0) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | + } |
|
| 564 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | + } |
|
| 567 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | + } |
|
| 570 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if ($vue == 'saison') { |
|
| 575 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | + } else { |
|
| 577 | + return $saison ? trim(_T( |
|
| 578 | + 'date_fmt_saison_annee', |
|
| 579 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | + )) : ''; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + case 'court': |
|
| 584 | + if ($avjc) { |
|
| 585 | + return $annee; |
|
| 586 | + } |
|
| 587 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | + return $annee; |
|
| 590 | + } |
|
| 591 | + if ($annee != $a) { |
|
| 592 | + return _T( |
|
| 593 | + 'date_fmt_mois_annee', |
|
| 594 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return _T( |
|
| 599 | + 'date_fmt_jour_mois', |
|
| 600 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + case 'jourcourt': |
|
| 604 | + if ($avjc) { |
|
| 605 | + return $annee; |
|
| 606 | + } |
|
| 607 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | + return $annee; |
|
| 610 | + } |
|
| 611 | + if ($annee != $a) { |
|
| 612 | + return _T( |
|
| 613 | + 'date_fmt_jour_mois_annee', |
|
| 614 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return _T( |
|
| 619 | + 'date_fmt_jour_mois', |
|
| 620 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + case 'entier': |
|
| 624 | + if ($avjc) { |
|
| 625 | + return $annee; |
|
| 626 | + } |
|
| 627 | + if ($jour) { |
|
| 628 | + return _T( |
|
| 629 | + 'date_fmt_jour_mois_annee', |
|
| 630 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | + ); |
|
| 632 | + } elseif ($mois) { |
|
| 633 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | + } else { |
|
| 635 | + return $annee; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + case 'nom_mois': |
|
| 639 | + return $nommois; |
|
| 640 | + |
|
| 641 | + case 'mois': |
|
| 642 | + return sprintf('%02s', $mois); |
|
| 643 | + |
|
| 644 | + case 'jour': |
|
| 645 | + return $jour; |
|
| 646 | + |
|
| 647 | + case 'journum': |
|
| 648 | + return $journum; |
|
| 649 | + |
|
| 650 | + case 'nom_jour': |
|
| 651 | + if (!$mois or !$njour) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | + $nom = 1 + (int) date('w', $nom); |
|
| 656 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | + |
|
| 658 | + return _T('date_jour_' . $nom . $param); |
|
| 659 | + |
|
| 660 | + case 'mois_annee': |
|
| 661 | + if ($avjc) { |
|
| 662 | + return $annee; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | + |
|
| 667 | + case 'annee': |
|
| 668 | + return $annee; |
|
| 669 | + |
|
| 670 | + // Cas d'une vue non definie : retomber sur le format |
|
| 671 | + // de date propose par http://www.php.net/date |
|
| 672 | + default: |
|
| 673 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | + $time = strtotime($numdate); |
|
| 676 | + } |
|
| 677 | + return date($vue, $time); |
|
| 678 | + } |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | * Nom du jour |
| 703 | 703 | **/ |
| 704 | 704 | function nom_jour($numdate, $forme = ''): string { |
| 705 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | - $forme = ''; |
|
| 707 | - } |
|
| 705 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | + $forme = ''; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * Numéro du jour |
| 729 | 729 | **/ |
| 730 | 730 | function jour($numdate): string { |
| 731 | - return affdate_base($numdate, 'jour'); |
|
| 731 | + return affdate_base($numdate, 'jour'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * Numéro du jour |
| 747 | 747 | **/ |
| 748 | 748 | function journum($numdate): string { |
| 749 | - return affdate_base($numdate, 'journum'); |
|
| 749 | + return affdate_base($numdate, 'journum'); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * Numéro du mois (sur 2 chiffres) |
| 765 | 765 | **/ |
| 766 | 766 | function mois($numdate): string { |
| 767 | - return affdate_base($numdate, 'mois'); |
|
| 767 | + return affdate_base($numdate, 'mois'); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * Nom du mois |
| 789 | 789 | **/ |
| 790 | 790 | function nom_mois($numdate, $forme = ''): string { |
| 791 | - if (!($forme === 'abbr')) { |
|
| 792 | - $forme = ''; |
|
| 793 | - } |
|
| 791 | + if (!($forme === 'abbr')) { |
|
| 792 | + $forme = ''; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * Année (sur 4 chiffres) |
| 811 | 811 | **/ |
| 812 | 812 | function annee($numdate): string { |
| 813 | - return affdate_base($numdate, 'annee'); |
|
| 813 | + return affdate_base($numdate, 'annee'); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -840,11 +840,11 @@ discard block |
||
| 840 | 840 | * La date formatée |
| 841 | 841 | **/ |
| 842 | 842 | function saison($numdate, $hemisphere = 'nord'): string { |
| 843 | - if ($hemisphere !== 'sud') { |
|
| 844 | - $hemisphere = 'nord'; |
|
| 845 | - } |
|
| 843 | + if ($hemisphere !== 'sud') { |
|
| 844 | + $hemisphere = 'nord'; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -873,11 +873,11 @@ discard block |
||
| 873 | 873 | * La date formatée |
| 874 | 874 | **/ |
| 875 | 875 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 876 | - if ($hemisphere !== 'sud') { |
|
| 877 | - $hemisphere = 'nord'; |
|
| 878 | - } |
|
| 876 | + if ($hemisphere !== 'sud') { |
|
| 877 | + $hemisphere = 'nord'; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | * La date formatée |
| 906 | 906 | **/ |
| 907 | 907 | function affdate($numdate, $format = 'entier'): string { |
| 908 | - return affdate_base($numdate, $format); |
|
| 908 | + return affdate_base($numdate, $format); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | * La date formatée |
| 933 | 933 | **/ |
| 934 | 934 | function affdate_court($numdate, $annee_courante = null): string { |
| 935 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * La date formatée |
| 960 | 960 | **/ |
| 961 | 961 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 962 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * La date formatée |
| 978 | 978 | **/ |
| 979 | 979 | function affdate_mois_annee($numdate): string { |
| 980 | - return affdate_base($numdate, 'mois_annee'); |
|
| 980 | + return affdate_base($numdate, 'mois_annee'); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -995,16 +995,16 @@ discard block |
||
| 995 | 995 | * La date formatée, sinon '' |
| 996 | 996 | **/ |
| 997 | 997 | function affdate_heure($numdate): string { |
| 998 | - $date_array = recup_date($numdate); |
|
| 999 | - if (!$date_array) { |
|
| 1000 | - return ''; |
|
| 1001 | - } |
|
| 1002 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | - |
|
| 1004 | - return _T('date_fmt_jour_heure', [ |
|
| 1005 | - 'jour' => affdate($numdate), |
|
| 1006 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | - ]); |
|
| 998 | + $date_array = recup_date($numdate); |
|
| 999 | + if (!$date_array) { |
|
| 1000 | + return ''; |
|
| 1001 | + } |
|
| 1002 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | + |
|
| 1004 | + return _T('date_fmt_jour_heure', [ |
|
| 1005 | + 'jour' => affdate($numdate), |
|
| 1006 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | + ]); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1036,117 +1036,117 @@ discard block |
||
| 1036 | 1036 | * texte de la date |
| 1037 | 1037 | */ |
| 1038 | 1038 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1039 | - $abbr = $jour = ''; |
|
| 1040 | - $affdate = 'affdate_jourcourt'; |
|
| 1041 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | - $abbr = 'abbr'; |
|
| 1043 | - } |
|
| 1044 | - if (strpos($forme, 'annee') !== false) { |
|
| 1045 | - $affdate = 'affdate'; |
|
| 1046 | - } |
|
| 1047 | - if (strpos($forme, 'jour') !== false) { |
|
| 1048 | - $jour = 'jour'; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | - $dtabbr = '</abbr>'; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $date_debut = strtotime($date_debut); |
|
| 1059 | - $date_fin = strtotime($date_fin); |
|
| 1060 | - $d = date('Y-m-d', $date_debut); |
|
| 1061 | - $f = date('Y-m-d', $date_fin); |
|
| 1062 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | - |
|
| 1066 | - if ($d == $f) { // meme jour |
|
| 1067 | - $nomjour = nom_jour($d, $abbr); |
|
| 1068 | - $s = $affdate($d); |
|
| 1069 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | - if ($h) { |
|
| 1071 | - if ($hd == $hf) { |
|
| 1072 | - // Lundi 20 fevrier a 18h25 |
|
| 1073 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | - $s = "$dtstart$s$dtabbr"; |
|
| 1075 | - } else { |
|
| 1076 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | - $s = _T( |
|
| 1079 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | - [ |
|
| 1081 | - 'jour' => spip_ucfirst($s), |
|
| 1082 | - 'heure_debut' => $hd, |
|
| 1083 | - 'heure_fin' => $hf, |
|
| 1084 | - 'dtstart' => $dtstart, |
|
| 1085 | - 'dtend' => $dtend, |
|
| 1086 | - 'dtabbr' => $dtabbr |
|
| 1087 | - ], |
|
| 1088 | - [ |
|
| 1089 | - 'sanitize' => false |
|
| 1090 | - ] |
|
| 1091 | - ); |
|
| 1092 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | - else { |
|
| 1094 | - $s = spip_ucfirst(_T( |
|
| 1095 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | - )); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - } else { |
|
| 1101 | - if ($dtabbr && $dtstart) { |
|
| 1102 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | - } else { |
|
| 1104 | - $s = spip_ucfirst($s); |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - } else { |
|
| 1108 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | - if (!$h) { |
|
| 1110 | - $date_debut = jour($d); |
|
| 1111 | - } else { |
|
| 1112 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | - } |
|
| 1114 | - $date_fin = $affdate($f); |
|
| 1115 | - if ($jour) { |
|
| 1116 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | - } |
|
| 1121 | - if ($h) { |
|
| 1122 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | - } |
|
| 1125 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | - |
|
| 1128 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | - } else { |
|
| 1130 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | - $date_fin = $affdate($f); |
|
| 1132 | - if ($jour) { |
|
| 1133 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | - } |
|
| 1138 | - if ($h) { |
|
| 1139 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return $s; |
|
| 1039 | + $abbr = $jour = ''; |
|
| 1040 | + $affdate = 'affdate_jourcourt'; |
|
| 1041 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | + $abbr = 'abbr'; |
|
| 1043 | + } |
|
| 1044 | + if (strpos($forme, 'annee') !== false) { |
|
| 1045 | + $affdate = 'affdate'; |
|
| 1046 | + } |
|
| 1047 | + if (strpos($forme, 'jour') !== false) { |
|
| 1048 | + $jour = 'jour'; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | + $dtabbr = '</abbr>'; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $date_debut = strtotime($date_debut); |
|
| 1059 | + $date_fin = strtotime($date_fin); |
|
| 1060 | + $d = date('Y-m-d', $date_debut); |
|
| 1061 | + $f = date('Y-m-d', $date_fin); |
|
| 1062 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | + |
|
| 1066 | + if ($d == $f) { // meme jour |
|
| 1067 | + $nomjour = nom_jour($d, $abbr); |
|
| 1068 | + $s = $affdate($d); |
|
| 1069 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | + if ($h) { |
|
| 1071 | + if ($hd == $hf) { |
|
| 1072 | + // Lundi 20 fevrier a 18h25 |
|
| 1073 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | + $s = "$dtstart$s$dtabbr"; |
|
| 1075 | + } else { |
|
| 1076 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | + $s = _T( |
|
| 1079 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | + [ |
|
| 1081 | + 'jour' => spip_ucfirst($s), |
|
| 1082 | + 'heure_debut' => $hd, |
|
| 1083 | + 'heure_fin' => $hf, |
|
| 1084 | + 'dtstart' => $dtstart, |
|
| 1085 | + 'dtend' => $dtend, |
|
| 1086 | + 'dtabbr' => $dtabbr |
|
| 1087 | + ], |
|
| 1088 | + [ |
|
| 1089 | + 'sanitize' => false |
|
| 1090 | + ] |
|
| 1091 | + ); |
|
| 1092 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | + else { |
|
| 1094 | + $s = spip_ucfirst(_T( |
|
| 1095 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | + )); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + } else { |
|
| 1101 | + if ($dtabbr && $dtstart) { |
|
| 1102 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | + } else { |
|
| 1104 | + $s = spip_ucfirst($s); |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + } else { |
|
| 1108 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | + if (!$h) { |
|
| 1110 | + $date_debut = jour($d); |
|
| 1111 | + } else { |
|
| 1112 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | + } |
|
| 1114 | + $date_fin = $affdate($f); |
|
| 1115 | + if ($jour) { |
|
| 1116 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | + } |
|
| 1121 | + if ($h) { |
|
| 1122 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | + } |
|
| 1125 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | + |
|
| 1128 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | + } else { |
|
| 1130 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | + $date_fin = $affdate($f); |
|
| 1132 | + if ($jour) { |
|
| 1133 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | + } |
|
| 1138 | + if ($h) { |
|
| 1139 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return $s; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | * Date au format ical |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function date_ical($date, $addminutes = 0): string { |
| 1170 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1170 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1172 | 1172 | |
| 1173 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -1194,11 +1194,11 @@ discard block |
||
| 1194 | 1194 | * La date formatée |
| 1195 | 1195 | **/ |
| 1196 | 1196 | function date_iso($date_heure): string { |
| 1197 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1197 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1200 | 1200 | |
| 1201 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1201 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
@@ -1221,11 +1221,11 @@ discard block |
||
| 1221 | 1221 | * La date formatée |
| 1222 | 1222 | **/ |
| 1223 | 1223 | function date_822($date_heure): string { |
| 1224 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1224 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1227 | 1227 | |
| 1228 | - return date('r', $time); |
|
| 1228 | + return date('r', $time); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * Date au format `Ymd` |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function date_anneemoisjour($d): string { |
| 1244 | - if (!$d) { |
|
| 1245 | - $d = date('Y-m-d'); |
|
| 1246 | - } |
|
| 1244 | + if (!$d) { |
|
| 1245 | + $d = date('Y-m-d'); |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1248 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -1261,11 +1261,11 @@ discard block |
||
| 1261 | 1261 | * Date au format `Ym` |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function date_anneemois($d): string { |
| 1264 | - if (!$d) { |
|
| 1265 | - $d = date('Y-m-d'); |
|
| 1266 | - } |
|
| 1264 | + if (!$d) { |
|
| 1265 | + $d = date('Y-m-d'); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1268 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | /** |
@@ -1281,13 +1281,13 @@ discard block |
||
| 1281 | 1281 | * Date au lundi de la même semaine au format `Ymd` |
| 1282 | 1282 | **/ |
| 1283 | 1283 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1284 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | - if ($w_day == 0) { |
|
| 1286 | - $w_day = 7; |
|
| 1287 | - } // Gaffe: le dimanche est zero |
|
| 1288 | - $debut = $jour - $w_day + 1; |
|
| 1284 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | + if ($w_day == 0) { |
|
| 1286 | + $w_day = 7; |
|
| 1287 | + } // Gaffe: le dimanche est zero |
|
| 1288 | + $debut = $jour - $w_day + 1; |
|
| 1289 | 1289 | |
| 1290 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1290 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1303,11 +1303,11 @@ discard block |
||
| 1303 | 1303 | * Date au dimanche de la même semaine au format `Ymd` |
| 1304 | 1304 | **/ |
| 1305 | 1305 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1306 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | - if ($w_day == 0) { |
|
| 1308 | - $w_day = 7; |
|
| 1309 | - } // Gaffe: le dimanche est zero |
|
| 1310 | - $debut = $jour - $w_day + 1; |
|
| 1306 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | + if ($w_day == 0) { |
|
| 1308 | + $w_day = 7; |
|
| 1309 | + } // Gaffe: le dimanche est zero |
|
| 1310 | + $debut = $jour - $w_day + 1; |
|
| 1311 | 1311 | |
| 1312 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1312 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1313 | 1313 | } |