@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 39 | 39 | */ |
| 40 | 40 | function find_langs_in_path($file, $dirname = 'lang') { |
| 41 | - static $dirs = []; |
|
| 42 | - $liste = []; |
|
| 43 | - foreach (creer_chemin() as $dir) { |
|
| 44 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | - } |
|
| 47 | - if ($dirs[$a]) { |
|
| 48 | - if (is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 41 | + static $dirs = []; |
|
| 42 | + $liste = []; |
|
| 43 | + foreach (creer_chemin() as $dir) { |
|
| 44 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | + } |
|
| 47 | + if ($dirs[$a]) { |
|
| 48 | + if (is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return array_reverse($liste); |
|
| 54 | + return array_reverse($liste); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -66,23 +66,23 @@ discard block |
||
| 66 | 66 | * Liste des fichiers touvés pour ce module et cette langue. |
| 67 | 67 | **/ |
| 68 | 68 | function chercher_module_lang($module, $lang = '') { |
| 69 | - if ($lang) { |
|
| 70 | - $lang = '_' . $lang; |
|
| 71 | - } |
|
| 69 | + if ($lang) { |
|
| 70 | + $lang = '_' . $lang; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | - if ( |
|
| 75 | - $f = ($module == 'local' |
|
| 76 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | - ) { |
|
| 79 | - return is_array($f) ? $f : [$f]; |
|
| 80 | - } |
|
| 73 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | + if ( |
|
| 75 | + $f = ($module == 'local' |
|
| 76 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | + ) { |
|
| 79 | + return is_array($f) ? $f : [$f]; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | - return (($module == 'local') or strpos($module, '/')) |
|
| 84 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | - : false; |
|
| 82 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | + return (($module == 'local') or strpos($module, '/')) |
|
| 84 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | + : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | * @return string Langue du module chargé, sinon chaîne vide. |
| 105 | 105 | **/ |
| 106 | 106 | function charger_langue($lang, $module = 'spip') { |
| 107 | - static $langs = []; |
|
| 108 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | - if (!isset($langs[$lang])) { |
|
| 110 | - $langs[$lang] = []; |
|
| 111 | - if ($lang) { |
|
| 112 | - $langs[$lang][] = $lang; |
|
| 113 | - if (strpos($lang, '_') !== false) { |
|
| 114 | - $l = explode('_', $lang); |
|
| 115 | - $langs[$lang][] = reset($l); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | - } |
|
| 121 | - foreach ($langs[$lang] as $l) { |
|
| 122 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | - include(array_shift($fichiers_lang)); |
|
| 125 | - surcharger_langue($fichiers_lang); |
|
| 126 | - if ($l !== $lang) { |
|
| 127 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | - } |
|
| 129 | - $GLOBALS['lang_' . $var] = $l; |
|
| 130 | - #spip_log("module de langue : ${module}_$l.php", 'traduire'); |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + static $langs = []; |
|
| 108 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | + if (!isset($langs[$lang])) { |
|
| 110 | + $langs[$lang] = []; |
|
| 111 | + if ($lang) { |
|
| 112 | + $langs[$lang][] = $lang; |
|
| 113 | + if (strpos($lang, '_') !== false) { |
|
| 114 | + $l = explode('_', $lang); |
|
| 115 | + $langs[$lang][] = reset($l); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | + } |
|
| 121 | + foreach ($langs[$lang] as $l) { |
|
| 122 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | + include(array_shift($fichiers_lang)); |
|
| 125 | + surcharger_langue($fichiers_lang); |
|
| 126 | + if ($l !== $lang) { |
|
| 127 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | + } |
|
| 129 | + $GLOBALS['lang_' . $var] = $l; |
|
| 130 | + #spip_log("module de langue : ${module}_$l.php", 'traduire'); |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -150,50 +150,50 @@ discard block |
||
| 150 | 150 | * Liste des chemins de fichiers de langue à surcharger. |
| 151 | 151 | **/ |
| 152 | 152 | function surcharger_langue($fichiers) { |
| 153 | - static $surcharges = []; |
|
| 154 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 155 | - return; |
|
| 156 | - } |
|
| 153 | + static $surcharges = []; |
|
| 154 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - if (!is_array($fichiers)) { |
|
| 159 | - $fichiers = [$fichiers]; |
|
| 160 | - } |
|
| 161 | - if (!count($fichiers)) { |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - foreach ($fichiers as $fichier) { |
|
| 165 | - if (!isset($surcharges[$fichier])) { |
|
| 166 | - $idx_lang_normal = $GLOBALS['idx_lang']; |
|
| 167 | - $GLOBALS['idx_lang'] = $GLOBALS['idx_lang'] . '@temporaire'; |
|
| 168 | - include($fichier); |
|
| 169 | - $surcharges[$fichier] = $GLOBALS[$GLOBALS['idx_lang']]; |
|
| 170 | - unset($GLOBALS[$GLOBALS['idx_lang']]); |
|
| 171 | - $GLOBALS['idx_lang'] = $idx_lang_normal; |
|
| 172 | - } |
|
| 173 | - if (is_array($surcharges[$fichier])) { |
|
| 174 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 175 | - (isset($GLOBALS[$GLOBALS['idx_lang']]) ? (array)$GLOBALS[$GLOBALS['idx_lang']] : []), |
|
| 176 | - $surcharges[$fichier] |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 158 | + if (!is_array($fichiers)) { |
|
| 159 | + $fichiers = [$fichiers]; |
|
| 160 | + } |
|
| 161 | + if (!count($fichiers)) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + foreach ($fichiers as $fichier) { |
|
| 165 | + if (!isset($surcharges[$fichier])) { |
|
| 166 | + $idx_lang_normal = $GLOBALS['idx_lang']; |
|
| 167 | + $GLOBALS['idx_lang'] = $GLOBALS['idx_lang'] . '@temporaire'; |
|
| 168 | + include($fichier); |
|
| 169 | + $surcharges[$fichier] = $GLOBALS[$GLOBALS['idx_lang']]; |
|
| 170 | + unset($GLOBALS[$GLOBALS['idx_lang']]); |
|
| 171 | + $GLOBALS['idx_lang'] = $idx_lang_normal; |
|
| 172 | + } |
|
| 173 | + if (is_array($surcharges[$fichier])) { |
|
| 174 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 175 | + (isset($GLOBALS[$GLOBALS['idx_lang']]) ? (array)$GLOBALS[$GLOBALS['idx_lang']] : []), |
|
| 176 | + $surcharges[$fichier] |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | class SPIP_Traductions_Description { |
| 185 | - /** @var string code de langue (hors module) */ |
|
| 186 | - public $code; |
|
| 187 | - /** @var string nom du module de langue */ |
|
| 188 | - public $module; |
|
| 189 | - /** @var string langue de la traduction */ |
|
| 190 | - public $langue; |
|
| 191 | - /** @var string traduction */ |
|
| 192 | - public $texte; |
|
| 193 | - /** @var string var mode particulier appliqué ? */ |
|
| 194 | - public $mode; |
|
| 195 | - /** @var bool Corrections des textes appliqué ? */ |
|
| 196 | - public $corrections = false; |
|
| 185 | + /** @var string code de langue (hors module) */ |
|
| 186 | + public $code; |
|
| 187 | + /** @var string nom du module de langue */ |
|
| 188 | + public $module; |
|
| 189 | + /** @var string langue de la traduction */ |
|
| 190 | + public $langue; |
|
| 191 | + /** @var string traduction */ |
|
| 192 | + public $texte; |
|
| 193 | + /** @var string var mode particulier appliqué ? */ |
|
| 194 | + public $mode; |
|
| 195 | + /** @var bool Corrections des textes appliqué ? */ |
|
| 196 | + public $corrections = false; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -235,99 +235,99 @@ discard block |
||
| 235 | 235 | * - SPIP_Traductions_Description : traduction et description (texte, module, langue) |
| 236 | 236 | **/ |
| 237 | 237 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 238 | - static $deja_vu = []; |
|
| 239 | - static $local = []; |
|
| 238 | + static $deja_vu = []; |
|
| 239 | + static $local = []; |
|
| 240 | 240 | |
| 241 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 242 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 243 | - } |
|
| 241 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 242 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 246 | - if (strpos($ori, ':')) { |
|
| 247 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 248 | - $modules = explode('|', $modules); |
|
| 249 | - $ori_complet = $ori; |
|
| 250 | - } else { |
|
| 251 | - $modules = ['spip', 'ecrire']; |
|
| 252 | - $code = $ori; |
|
| 253 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 254 | - } |
|
| 245 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 246 | + if (strpos($ori, ':')) { |
|
| 247 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 248 | + $modules = explode('|', $modules); |
|
| 249 | + $ori_complet = $ori; |
|
| 250 | + } else { |
|
| 251 | + $modules = ['spip', 'ecrire']; |
|
| 252 | + $code = $ori; |
|
| 253 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - $desc = new SPIP_Traductions_Description(); |
|
| 256 | + $desc = new SPIP_Traductions_Description(); |
|
| 257 | 257 | |
| 258 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 259 | - foreach ($modules as $module) { |
|
| 260 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 258 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 259 | + foreach ($modules as $module) { |
|
| 260 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 261 | 261 | |
| 262 | - if (empty($GLOBALS[$var])) { |
|
| 263 | - charger_langue($lang, $module); |
|
| 264 | - // surcharges persos -- on cherche |
|
| 265 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 266 | - if (!isset($local['local_' . $lang])) { |
|
| 267 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 268 | - $GLOBALS['idx_lang'] = $var; |
|
| 269 | - // ... (lang/)local_xx.php |
|
| 270 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 271 | - } |
|
| 272 | - if ($local['local_' . $lang]) { |
|
| 273 | - surcharger_langue($local['local_' . $lang]); |
|
| 274 | - } |
|
| 275 | - // ... puis (lang/)local.php |
|
| 276 | - if (!isset($local['local'])) { |
|
| 277 | - $local['local'] = chercher_module_lang('local'); |
|
| 278 | - } |
|
| 279 | - if ($local['local']) { |
|
| 280 | - surcharger_langue($local['local']); |
|
| 281 | - } |
|
| 282 | - } |
|
| 262 | + if (empty($GLOBALS[$var])) { |
|
| 263 | + charger_langue($lang, $module); |
|
| 264 | + // surcharges persos -- on cherche |
|
| 265 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 266 | + if (!isset($local['local_' . $lang])) { |
|
| 267 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 268 | + $GLOBALS['idx_lang'] = $var; |
|
| 269 | + // ... (lang/)local_xx.php |
|
| 270 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 271 | + } |
|
| 272 | + if ($local['local_' . $lang]) { |
|
| 273 | + surcharger_langue($local['local_' . $lang]); |
|
| 274 | + } |
|
| 275 | + // ... puis (lang/)local.php |
|
| 276 | + if (!isset($local['local'])) { |
|
| 277 | + $local['local'] = chercher_module_lang('local'); |
|
| 278 | + } |
|
| 279 | + if ($local['local']) { |
|
| 280 | + surcharger_langue($local['local']); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - if (isset($GLOBALS[$var][$code])) { |
|
| 285 | - $desc->code = $code; |
|
| 286 | - $desc->module = $module; |
|
| 287 | - $desc->langue = $GLOBALS['lang_' . $var]; |
|
| 288 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 289 | - break; |
|
| 290 | - } |
|
| 291 | - } |
|
| 284 | + if (isset($GLOBALS[$var][$code])) { |
|
| 285 | + $desc->code = $code; |
|
| 286 | + $desc->module = $module; |
|
| 287 | + $desc->langue = $GLOBALS['lang_' . $var]; |
|
| 288 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 289 | + break; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - if (!$desc->corrections) { |
|
| 294 | - $desc->corrections = true; |
|
| 295 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 296 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 297 | - if ( |
|
| 298 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 299 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 300 | - ) { |
|
| 301 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 302 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 303 | - } else { |
|
| 304 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 305 | - } |
|
| 306 | - } |
|
| 293 | + if (!$desc->corrections) { |
|
| 294 | + $desc->corrections = true; |
|
| 295 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 296 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 297 | + if ( |
|
| 298 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 299 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 300 | + ) { |
|
| 301 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 302 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 303 | + } else { |
|
| 304 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 309 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 310 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 311 | - } |
|
| 308 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 309 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 310 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 314 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 315 | - if ( |
|
| 316 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 317 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 318 | - ) { |
|
| 319 | - include_spip('inc/charsets'); |
|
| 320 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 321 | - } |
|
| 322 | - } |
|
| 313 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 314 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 315 | + if ( |
|
| 316 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 317 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 318 | + ) { |
|
| 319 | + include_spip('inc/charsets'); |
|
| 320 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - if (_request('var_mode') == 'traduction') { |
|
| 325 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 326 | - } else { |
|
| 327 | - $deja_vu[$lang][$ori] = $desc; |
|
| 328 | - } |
|
| 324 | + if (_request('var_mode') == 'traduction') { |
|
| 325 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 326 | + } else { |
|
| 327 | + $deja_vu[$lang][$ori] = $desc; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - return $raw ? $desc : $desc->texte; |
|
| 330 | + return $raw ? $desc : $desc->texte; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -339,23 +339,23 @@ discard block |
||
| 339 | 339 | * @return SPIP_Traductions_Description |
| 340 | 340 | */ |
| 341 | 341 | function definir_details_traduction($desc, $modules) { |
| 342 | - if (!$desc->mode and $desc->texte) { |
|
| 343 | - // ne pas modifier 2 fois l'affichage |
|
| 344 | - $desc->mode = 'traduction'; |
|
| 345 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 346 | - $desc->texte = '<span ' |
|
| 347 | - . 'lang=' . $desc->langue |
|
| 348 | - . ' class=' . $classe |
|
| 349 | - . ' data-module=' . $desc->module |
|
| 350 | - . ' data-code=' . $desc->code |
|
| 351 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 352 | - . $desc->texte |
|
| 353 | - . '</span>'; |
|
| 354 | - $desc->texte = str_replace( |
|
| 355 | - ["$desc->module:", "$desc->module|"], |
|
| 356 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 357 | - $desc->texte |
|
| 358 | - ); |
|
| 359 | - } |
|
| 360 | - return $desc; |
|
| 342 | + if (!$desc->mode and $desc->texte) { |
|
| 343 | + // ne pas modifier 2 fois l'affichage |
|
| 344 | + $desc->mode = 'traduction'; |
|
| 345 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 346 | + $desc->texte = '<span ' |
|
| 347 | + . 'lang=' . $desc->langue |
|
| 348 | + . ' class=' . $classe |
|
| 349 | + . ' data-module=' . $desc->module |
|
| 350 | + . ' data-code=' . $desc->code |
|
| 351 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 352 | + . $desc->texte |
|
| 353 | + . '</span>'; |
|
| 354 | + $desc->texte = str_replace( |
|
| 355 | + ["$desc->module:", "$desc->module|"], |
|
| 356 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 357 | + $desc->texte |
|
| 358 | + ); |
|
| 359 | + } |
|
| 360 | + return $desc; |
|
| 361 | 361 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -54,65 +54,65 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 57 | - $statuts_publies = null; |
|
| 58 | - $neuf = false; |
|
| 59 | - |
|
| 60 | - // Compat avec l'ancienne signature |
|
| 61 | - if (is_string($infos)) { |
|
| 62 | - $infos = ['statut_ancien' => $infos]; |
|
| 63 | - } |
|
| 64 | - if (!isset($infos['statut_ancien'])) { |
|
| 65 | - $infos['statut_ancien'] = ''; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // On recherche quels statuts tester |
|
| 69 | - if ( |
|
| 70 | - isset($infos['objet']) |
|
| 71 | - and include_spip('inc/filtres') |
|
| 72 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | - and is_array($declaration_statut) |
|
| 74 | - ) { |
|
| 75 | - foreach ($declaration_statut as $champ_statut) { |
|
| 76 | - if ($champ_statut['champ'] == 'statut') { |
|
| 77 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | - break; // stop on a trouvé le bon champ |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } else { |
|
| 82 | - $statuts_publies = ['publie']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if ( |
|
| 87 | - isset($modifs['statut']) |
|
| 88 | - or isset($modifs['id_rubrique']) |
|
| 89 | - or ($postdate and strtotime($postdate) > time()) |
|
| 90 | - ) { |
|
| 91 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | - } |
|
| 93 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | - if ($postdate) { |
|
| 95 | - calculer_prochain_postdate(true); |
|
| 96 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | - } |
|
| 100 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | - if ($postdate) { |
|
| 102 | - calculer_prochain_postdate(true); |
|
| 103 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | - } else { |
|
| 105 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($neuf) { |
|
| 110 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $langues = calculer_langues_utilisees(); |
|
| 115 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $statuts_publies = null; |
|
| 58 | + $neuf = false; |
|
| 59 | + |
|
| 60 | + // Compat avec l'ancienne signature |
|
| 61 | + if (is_string($infos)) { |
|
| 62 | + $infos = ['statut_ancien' => $infos]; |
|
| 63 | + } |
|
| 64 | + if (!isset($infos['statut_ancien'])) { |
|
| 65 | + $infos['statut_ancien'] = ''; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // On recherche quels statuts tester |
|
| 69 | + if ( |
|
| 70 | + isset($infos['objet']) |
|
| 71 | + and include_spip('inc/filtres') |
|
| 72 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | + and is_array($declaration_statut) |
|
| 74 | + ) { |
|
| 75 | + foreach ($declaration_statut as $champ_statut) { |
|
| 76 | + if ($champ_statut['champ'] == 'statut') { |
|
| 77 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | + break; // stop on a trouvé le bon champ |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + $statuts_publies = ['publie']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if ( |
|
| 87 | + isset($modifs['statut']) |
|
| 88 | + or isset($modifs['id_rubrique']) |
|
| 89 | + or ($postdate and strtotime($postdate) > time()) |
|
| 90 | + ) { |
|
| 91 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | + } |
|
| 93 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | + if ($postdate) { |
|
| 95 | + calculer_prochain_postdate(true); |
|
| 96 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | + } |
|
| 100 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | + if ($postdate) { |
|
| 102 | + calculer_prochain_postdate(true); |
|
| 103 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | + } else { |
|
| 105 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($neuf) { |
|
| 110 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $langues = calculer_langues_utilisees(); |
|
| 115 | + ecrire_meta('langues_utilisees', $langues); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | * true si le statut change effectivement |
| 131 | 131 | */ |
| 132 | 132 | function publier_branche_rubrique($id_rubrique) { |
| 133 | - $id_pred = $id_rubrique; |
|
| 134 | - while (true) { |
|
| 135 | - sql_updateq( |
|
| 136 | - 'spip_rubriques', |
|
| 137 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | - ); |
|
| 140 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | - if (!$id_parent) { |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - $id_rubrique = $id_parent; |
|
| 145 | - } |
|
| 133 | + $id_pred = $id_rubrique; |
|
| 134 | + while (true) { |
|
| 135 | + sql_updateq( |
|
| 136 | + 'spip_rubriques', |
|
| 137 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | + ); |
|
| 140 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | + if (!$id_parent) { |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + $id_rubrique = $id_parent; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 148 | - return $id_pred != $id_rubrique; |
|
| 148 | + return $id_pred != $id_rubrique; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * true si le statut change effectivement |
| 164 | 164 | */ |
| 165 | 165 | function depublier_branche_rubrique_if($id_rubrique) { |
| 166 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | - |
|
| 168 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | - $id_pred = $id_rubrique; |
|
| 170 | - while ($id_pred) { |
|
| 171 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | - return $id_pred != $id_rubrique; |
|
| 173 | - } |
|
| 174 | - // passer au parent si on a depublie |
|
| 175 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | - $id_pred = $r['id_parent']; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $id_pred != $id_rubrique; |
|
| 166 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | + |
|
| 168 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | + $id_pred = $id_rubrique; |
|
| 170 | + while ($id_pred) { |
|
| 171 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | + return $id_pred != $id_rubrique; |
|
| 173 | + } |
|
| 174 | + // passer au parent si on a depublie |
|
| 175 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | + $id_pred = $r['id_parent']; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $id_pred != $id_rubrique; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -193,61 +193,61 @@ discard block |
||
| 193 | 193 | * true si la rubrique a été dépubliée |
| 194 | 194 | */ |
| 195 | 195 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 196 | - if (is_null($date)) { |
|
| 197 | - $date = date('Y-m-d H:i:s'); |
|
| 198 | - } |
|
| 199 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | - |
|
| 202 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // verifier qu'elle existe et est bien publiee |
|
| 207 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | - // Le type de l'objet est au pluriel |
|
| 214 | - $compte = [ |
|
| 215 | - 'articles' => sql_countsel( |
|
| 216 | - 'spip_articles', |
|
| 217 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | - ), |
|
| 219 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | - 'documents' => sql_countsel( |
|
| 221 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | - ) |
|
| 224 | - ]; |
|
| 225 | - |
|
| 226 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | - $compte = pipeline( |
|
| 228 | - 'objet_compte_enfants', |
|
| 229 | - [ |
|
| 230 | - 'args' => [ |
|
| 231 | - 'objet' => 'rubrique', |
|
| 232 | - 'id_objet' => $id_rubrique, |
|
| 233 | - 'statut' => 'publie', |
|
| 234 | - 'date' => $date |
|
| 235 | - ], |
|
| 236 | - 'data' => $compte |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | - foreach ($compte as $objet => $n) { |
|
| 242 | - if ($n) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 196 | + if (is_null($date)) { |
|
| 197 | + $date = date('Y-m-d H:i:s'); |
|
| 198 | + } |
|
| 199 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | + |
|
| 202 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // verifier qu'elle existe et est bien publiee |
|
| 207 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | + // Le type de l'objet est au pluriel |
|
| 214 | + $compte = [ |
|
| 215 | + 'articles' => sql_countsel( |
|
| 216 | + 'spip_articles', |
|
| 217 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | + ), |
|
| 219 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | + 'documents' => sql_countsel( |
|
| 221 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | + ) |
|
| 224 | + ]; |
|
| 225 | + |
|
| 226 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | + $compte = pipeline( |
|
| 228 | + 'objet_compte_enfants', |
|
| 229 | + [ |
|
| 230 | + 'args' => [ |
|
| 231 | + 'objet' => 'rubrique', |
|
| 232 | + 'id_objet' => $id_rubrique, |
|
| 233 | + 'statut' => 'publie', |
|
| 234 | + 'date' => $date |
|
| 235 | + ], |
|
| 236 | + 'data' => $compte |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | + foreach ($compte as $objet => $n) { |
|
| 242 | + if ($n) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 248 | 248 | |
| 249 | 249 | # spip_log("depublier_rubrique $id_pred"); |
| 250 | - return true; |
|
| 250 | + return true; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | **/ |
| 271 | 271 | function calculer_rubriques() { |
| 272 | 272 | |
| 273 | - calculer_rubriques_publiees(); |
|
| 273 | + calculer_rubriques_publiees(); |
|
| 274 | 274 | |
| 275 | - // Apres chaque (de)publication |
|
| 276 | - // recalculer les langues utilisees sur le site |
|
| 277 | - $langues = calculer_langues_utilisees(); |
|
| 278 | - ecrire_meta('langues_utilisees', $langues); |
|
| 275 | + // Apres chaque (de)publication |
|
| 276 | + // recalculer les langues utilisees sur le site |
|
| 277 | + $langues = calculer_langues_utilisees(); |
|
| 278 | + ecrire_meta('langues_utilisees', $langues); |
|
| 279 | 279 | |
| 280 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 280 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 282 | 282 | |
| 283 | - // on calcule la date du prochain article post-date |
|
| 284 | - calculer_prochain_postdate(); |
|
| 283 | + // on calcule la date du prochain article post-date |
|
| 284 | + calculer_prochain_postdate(); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -298,61 +298,61 @@ discard block |
||
| 298 | 298 | **/ |
| 299 | 299 | function calculer_rubriques_publiees() { |
| 300 | 300 | |
| 301 | - // Mettre les compteurs a zero |
|
| 302 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | - |
|
| 304 | - // |
|
| 305 | - // Publier et dater les rubriques qui ont un article publie |
|
| 306 | - // |
|
| 307 | - |
|
| 308 | - // Afficher les articles post-dates ? |
|
| 309 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | - |
|
| 312 | - $r = sql_select( |
|
| 313 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | - 'R.id_rubrique' |
|
| 317 | - ); |
|
| 318 | - while ($row = sql_fetch($r)) { |
|
| 319 | - sql_updateq( |
|
| 320 | - 'spip_rubriques', |
|
| 321 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | - 'id_rubrique=' . intval($row['id']) |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | - pipeline('calculer_rubriques', null); |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | - do { |
|
| 337 | - $continuer = false; |
|
| 338 | - $r = sql_select( |
|
| 339 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | - 'R.id_rubrique' |
|
| 343 | - ); |
|
| 344 | - while ($row = sql_fetch($r)) { |
|
| 345 | - sql_updateq( |
|
| 346 | - 'spip_rubriques', |
|
| 347 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | - 'id_rubrique=' . intval($row['id']) |
|
| 349 | - ); |
|
| 350 | - $continuer = true; |
|
| 351 | - } |
|
| 352 | - } while ($continuer); |
|
| 353 | - |
|
| 354 | - // Enregistrement des modifs |
|
| 355 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 301 | + // Mettre les compteurs a zero |
|
| 302 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | + |
|
| 304 | + // |
|
| 305 | + // Publier et dater les rubriques qui ont un article publie |
|
| 306 | + // |
|
| 307 | + |
|
| 308 | + // Afficher les articles post-dates ? |
|
| 309 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | + |
|
| 312 | + $r = sql_select( |
|
| 313 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | + 'R.id_rubrique' |
|
| 317 | + ); |
|
| 318 | + while ($row = sql_fetch($r)) { |
|
| 319 | + sql_updateq( |
|
| 320 | + 'spip_rubriques', |
|
| 321 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | + 'id_rubrique=' . intval($row['id']) |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | + pipeline('calculer_rubriques', null); |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | + do { |
|
| 337 | + $continuer = false; |
|
| 338 | + $r = sql_select( |
|
| 339 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | + 'R.id_rubrique' |
|
| 343 | + ); |
|
| 344 | + while ($row = sql_fetch($r)) { |
|
| 345 | + sql_updateq( |
|
| 346 | + 'spip_rubriques', |
|
| 347 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | + 'id_rubrique=' . intval($row['id']) |
|
| 349 | + ); |
|
| 350 | + $continuer = true; |
|
| 351 | + } |
|
| 352 | + } while ($continuer); |
|
| 353 | + |
|
| 354 | + // Enregistrement des modifs |
|
| 355 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -367,123 +367,123 @@ discard block |
||
| 367 | 367 | * @return void |
| 368 | 368 | **/ |
| 369 | 369 | function propager_les_secteurs() { |
| 370 | - // Profondeur 0 |
|
| 371 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | - // et fixer les id_secteur des rubriques racines |
|
| 373 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | - // Toute rubrique non racine est de profondeur >0 |
|
| 375 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | - |
|
| 377 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | - |
|
| 380 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | - // on fait profondeur par profondeur |
|
| 382 | - |
|
| 383 | - $prof = 0; |
|
| 384 | - do { |
|
| 385 | - $continuer = false; |
|
| 386 | - |
|
| 387 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | - // on fixe le profondeur $prof+1 |
|
| 389 | - |
|
| 390 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | - // on teste A.profondeur > $prof+1 car : |
|
| 392 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | - $maxiter2 = $maxiter; |
|
| 396 | - while ( |
|
| 397 | - $maxiter2-- |
|
| 398 | - and $rows = sql_allfetsel( |
|
| 399 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | - '', |
|
| 403 | - 'R.id_secteur', |
|
| 404 | - '0,100' |
|
| 405 | - ) |
|
| 406 | - ) { |
|
| 407 | - $id_secteur = null; |
|
| 408 | - $ids = []; |
|
| 409 | - while ($row = array_shift($rows)) { |
|
| 410 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | - if (count($ids)) { |
|
| 412 | - sql_updateq( |
|
| 413 | - 'spip_rubriques', |
|
| 414 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | - sql_in('id_rubrique', $ids) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - $id_secteur = $row['id_secteur']; |
|
| 419 | - $ids = []; |
|
| 420 | - } |
|
| 421 | - $ids[] = $row['id']; |
|
| 422 | - } |
|
| 423 | - if (count($ids)) { |
|
| 424 | - sql_updateq( |
|
| 425 | - 'spip_rubriques', |
|
| 426 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | - sql_in('id_rubrique', $ids) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | - $maxiter2 = $maxiter; |
|
| 435 | - while ( |
|
| 436 | - $maxiter2-- |
|
| 437 | - and $rows = sql_allfetsel( |
|
| 438 | - 'id_rubrique as id', |
|
| 439 | - 'spip_rubriques', |
|
| 440 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | - 'zzz.id_rubrique', |
|
| 442 | - 'spip_rubriques AS zzz', |
|
| 443 | - 'zzz.profondeur=' . intval($prof) |
|
| 444 | - ) . ')', |
|
| 445 | - '', |
|
| 446 | - '', |
|
| 447 | - '0,100' |
|
| 448 | - ) |
|
| 449 | - ) { |
|
| 450 | - $rows = array_column($rows, 'id'); |
|
| 451 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | - // on arrete les frais |
|
| 458 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | - $prof++; |
|
| 460 | - $continuer = true; |
|
| 461 | - } |
|
| 462 | - } while ($continuer and $maxiter--); |
|
| 463 | - |
|
| 464 | - // loger si la table des rubriques semble foireuse |
|
| 465 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | - spip_log( |
|
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | - _LOG_CRITIQUE |
|
| 470 | - ); |
|
| 471 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // reparer les articles |
|
| 475 | - $r = sql_select( |
|
| 476 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | - ); |
|
| 480 | - |
|
| 481 | - while ($row = sql_fetch($r)) { |
|
| 482 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 370 | + // Profondeur 0 |
|
| 371 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | + // et fixer les id_secteur des rubriques racines |
|
| 373 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | + // Toute rubrique non racine est de profondeur >0 |
|
| 375 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | + |
|
| 377 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | + |
|
| 380 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | + // on fait profondeur par profondeur |
|
| 382 | + |
|
| 383 | + $prof = 0; |
|
| 384 | + do { |
|
| 385 | + $continuer = false; |
|
| 386 | + |
|
| 387 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | + // on fixe le profondeur $prof+1 |
|
| 389 | + |
|
| 390 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | + // on teste A.profondeur > $prof+1 car : |
|
| 392 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | + $maxiter2 = $maxiter; |
|
| 396 | + while ( |
|
| 397 | + $maxiter2-- |
|
| 398 | + and $rows = sql_allfetsel( |
|
| 399 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | + '', |
|
| 403 | + 'R.id_secteur', |
|
| 404 | + '0,100' |
|
| 405 | + ) |
|
| 406 | + ) { |
|
| 407 | + $id_secteur = null; |
|
| 408 | + $ids = []; |
|
| 409 | + while ($row = array_shift($rows)) { |
|
| 410 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | + if (count($ids)) { |
|
| 412 | + sql_updateq( |
|
| 413 | + 'spip_rubriques', |
|
| 414 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | + sql_in('id_rubrique', $ids) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + $id_secteur = $row['id_secteur']; |
|
| 419 | + $ids = []; |
|
| 420 | + } |
|
| 421 | + $ids[] = $row['id']; |
|
| 422 | + } |
|
| 423 | + if (count($ids)) { |
|
| 424 | + sql_updateq( |
|
| 425 | + 'spip_rubriques', |
|
| 426 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | + sql_in('id_rubrique', $ids) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | + $maxiter2 = $maxiter; |
|
| 435 | + while ( |
|
| 436 | + $maxiter2-- |
|
| 437 | + and $rows = sql_allfetsel( |
|
| 438 | + 'id_rubrique as id', |
|
| 439 | + 'spip_rubriques', |
|
| 440 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | + 'zzz.id_rubrique', |
|
| 442 | + 'spip_rubriques AS zzz', |
|
| 443 | + 'zzz.profondeur=' . intval($prof) |
|
| 444 | + ) . ')', |
|
| 445 | + '', |
|
| 446 | + '', |
|
| 447 | + '0,100' |
|
| 448 | + ) |
|
| 449 | + ) { |
|
| 450 | + $rows = array_column($rows, 'id'); |
|
| 451 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | + // on arrete les frais |
|
| 458 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | + $prof++; |
|
| 460 | + $continuer = true; |
|
| 461 | + } |
|
| 462 | + } while ($continuer and $maxiter--); |
|
| 463 | + |
|
| 464 | + // loger si la table des rubriques semble foireuse |
|
| 465 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | + spip_log( |
|
| 468 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | + _LOG_CRITIQUE |
|
| 470 | + ); |
|
| 471 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // reparer les articles |
|
| 475 | + $r = sql_select( |
|
| 476 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | + ); |
|
| 480 | + |
|
| 481 | + while ($row = sql_fetch($r)) { |
|
| 482 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -498,23 +498,23 @@ discard block |
||
| 498 | 498 | * true si un changement a eu lieu |
| 499 | 499 | **/ |
| 500 | 500 | function calculer_langues_rubriques_etape() { |
| 501 | - $s = sql_select( |
|
| 502 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | - ); |
|
| 506 | - |
|
| 507 | - $t = false; |
|
| 508 | - while ($row = sql_fetch($s)) { |
|
| 509 | - $id_rubrique = $row['id_rubrique']; |
|
| 510 | - $t = sql_updateq( |
|
| 511 | - 'spip_rubriques', |
|
| 512 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return $t; |
|
| 501 | + $s = sql_select( |
|
| 502 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | + ); |
|
| 506 | + |
|
| 507 | + $t = false; |
|
| 508 | + while ($row = sql_fetch($s)) { |
|
| 509 | + $id_rubrique = $row['id_rubrique']; |
|
| 510 | + $t = sql_updateq( |
|
| 511 | + 'spip_rubriques', |
|
| 512 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return $t; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -534,38 +534,38 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_langues_rubriques() { |
| 536 | 536 | |
| 537 | - // rubriques (recursivite) |
|
| 538 | - sql_updateq( |
|
| 539 | - 'spip_rubriques', |
|
| 540 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | - ); |
|
| 543 | - while (calculer_langues_rubriques_etape()) { |
|
| 544 | - ; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // articles |
|
| 548 | - $s = sql_select( |
|
| 549 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | - "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" |
|
| 552 | - ); |
|
| 553 | - while ($row = sql_fetch($s)) { |
|
| 554 | - $id_article = $row['id_article']; |
|
| 555 | - sql_updateq( |
|
| 556 | - 'spip_articles', |
|
| 557 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | - 'id_article=' . intval($id_article) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | - $langues = calculer_langues_utilisees(); |
|
| 564 | - ecrire_meta('langues_utilisees', $langues); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 537 | + // rubriques (recursivite) |
|
| 538 | + sql_updateq( |
|
| 539 | + 'spip_rubriques', |
|
| 540 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | + ); |
|
| 543 | + while (calculer_langues_rubriques_etape()) { |
|
| 544 | + ; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // articles |
|
| 548 | + $s = sql_select( |
|
| 549 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | + "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" |
|
| 552 | + ); |
|
| 553 | + while ($row = sql_fetch($s)) { |
|
| 554 | + $id_article = $row['id_article']; |
|
| 555 | + sql_updateq( |
|
| 556 | + 'spip_articles', |
|
| 557 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | + 'id_article=' . intval($id_article) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | + $langues = calculer_langues_utilisees(); |
|
| 564 | + ecrire_meta('langues_utilisees', $langues); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -582,80 +582,80 @@ discard block |
||
| 582 | 582 | * Liste des langues utilisées séparées par des virgules |
| 583 | 583 | **/ |
| 584 | 584 | function calculer_langues_utilisees($serveur = '') { |
| 585 | - include_spip('public/interfaces'); |
|
| 586 | - include_spip('public/compiler'); |
|
| 587 | - include_spip('public/composer'); |
|
| 588 | - include_spip('public/phraser_html'); |
|
| 589 | - $langues = []; |
|
| 590 | - |
|
| 591 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | - |
|
| 593 | - include_spip('base/objets'); |
|
| 594 | - $tables = lister_tables_objets_sql(); |
|
| 595 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | - |
|
| 597 | - foreach (array_keys($tables) as $t) { |
|
| 598 | - $desc = $trouver_table($t, $serveur); |
|
| 599 | - // c'est une table avec des langues |
|
| 600 | - if ( |
|
| 601 | - $desc['exist'] |
|
| 602 | - and isset($desc['field']['lang']) |
|
| 603 | - and isset($desc['field']['langue_choisie']) |
|
| 604 | - ) { |
|
| 605 | - $boucle = new Boucle(); |
|
| 606 | - $boucle->show = $desc; |
|
| 607 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | - $boucle->id_table = $desc['table_objet']; |
|
| 610 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | - $boucle->sql_serveur = $serveur; |
|
| 612 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | - $boucle->separateur[] = ','; |
|
| 615 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | - $boucle->iterateur = 'sql'; |
|
| 617 | - |
|
| 618 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | - $boucle->descr['gram'] = 'html'; |
|
| 621 | - |
|
| 622 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - isset($desc['statut']) |
|
| 626 | - and $desc['statut'] |
|
| 627 | - ) { |
|
| 628 | - $boucles = [ |
|
| 629 | - 'calculer_langues_utilisees' => $boucle, |
|
| 630 | - ]; |
|
| 631 | - // generer un nom de fonction "anonyme" unique |
|
| 632 | - do { |
|
| 633 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | - } while (function_exists($functionname)); |
|
| 635 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | - $res = ''; |
|
| 639 | - eval($code); |
|
| 640 | - $res = explode(',', $res); |
|
| 641 | - foreach ($res as $lang) { |
|
| 642 | - $langues[$lang] = 1; |
|
| 643 | - } |
|
| 644 | - } else { |
|
| 645 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | - while ($row = sql_fetch($res)) { |
|
| 647 | - $langues[$row['lang']] = 1; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - $langues = array_filter(array_keys($langues)); |
|
| 654 | - sort($langues); |
|
| 655 | - $langues = join(',', $langues); |
|
| 656 | - spip_log("langues utilisees: $langues"); |
|
| 657 | - |
|
| 658 | - return $langues; |
|
| 585 | + include_spip('public/interfaces'); |
|
| 586 | + include_spip('public/compiler'); |
|
| 587 | + include_spip('public/composer'); |
|
| 588 | + include_spip('public/phraser_html'); |
|
| 589 | + $langues = []; |
|
| 590 | + |
|
| 591 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | + |
|
| 593 | + include_spip('base/objets'); |
|
| 594 | + $tables = lister_tables_objets_sql(); |
|
| 595 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | + |
|
| 597 | + foreach (array_keys($tables) as $t) { |
|
| 598 | + $desc = $trouver_table($t, $serveur); |
|
| 599 | + // c'est une table avec des langues |
|
| 600 | + if ( |
|
| 601 | + $desc['exist'] |
|
| 602 | + and isset($desc['field']['lang']) |
|
| 603 | + and isset($desc['field']['langue_choisie']) |
|
| 604 | + ) { |
|
| 605 | + $boucle = new Boucle(); |
|
| 606 | + $boucle->show = $desc; |
|
| 607 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | + $boucle->id_table = $desc['table_objet']; |
|
| 610 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | + $boucle->sql_serveur = $serveur; |
|
| 612 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | + $boucle->separateur[] = ','; |
|
| 615 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | + $boucle->iterateur = 'sql'; |
|
| 617 | + |
|
| 618 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | + $boucle->descr['gram'] = 'html'; |
|
| 621 | + |
|
| 622 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + isset($desc['statut']) |
|
| 626 | + and $desc['statut'] |
|
| 627 | + ) { |
|
| 628 | + $boucles = [ |
|
| 629 | + 'calculer_langues_utilisees' => $boucle, |
|
| 630 | + ]; |
|
| 631 | + // generer un nom de fonction "anonyme" unique |
|
| 632 | + do { |
|
| 633 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | + } while (function_exists($functionname)); |
|
| 635 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | + $res = ''; |
|
| 639 | + eval($code); |
|
| 640 | + $res = explode(',', $res); |
|
| 641 | + foreach ($res as $lang) { |
|
| 642 | + $langues[$lang] = 1; |
|
| 643 | + } |
|
| 644 | + } else { |
|
| 645 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | + while ($row = sql_fetch($res)) { |
|
| 647 | + $langues[$row['lang']] = 1; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + $langues = array_filter(array_keys($langues)); |
|
| 654 | + sort($langues); |
|
| 655 | + $langues = join(',', $langues); |
|
| 656 | + spip_log("langues utilisees: $langues"); |
|
| 657 | + |
|
| 658 | + return $langues; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -672,9 +672,9 @@ discard block |
||
| 672 | 672 | * incluant les rubriques noeuds et toutes leurs descendances |
| 673 | 673 | */ |
| 674 | 674 | function calcul_branche_in($id) { |
| 675 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 676 | 676 | |
| 677 | - return $calcul_branche_in($id); |
|
| 677 | + return $calcul_branche_in($id); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * incluant les rubriques transmises et toutes leurs parentées |
| 693 | 693 | */ |
| 694 | 694 | function calcul_hierarchie_in($id, $tout = true) { |
| 695 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 696 | 696 | |
| 697 | - return $calcul_hierarchie_in($id, $tout); |
|
| 697 | + return $calcul_hierarchie_in($id, $tout); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -715,40 +715,40 @@ discard block |
||
| 715 | 715 | * incluant les rubriques noeuds et toutes leurs descendances |
| 716 | 716 | */ |
| 717 | 717 | function inc_calcul_branche_in_dist($id) { |
| 718 | - static $b = []; |
|
| 719 | - |
|
| 720 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | - if (!is_array($id)) { |
|
| 722 | - $id = explode(',', $id); |
|
| 723 | - } |
|
| 724 | - $id = join(',', array_map('intval', $id)); |
|
| 725 | - if (isset($b[$id])) { |
|
| 726 | - return $b[$id]; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // Notre branche commence par la rubrique de depart |
|
| 730 | - $branche = $r = $id; |
|
| 731 | - |
|
| 732 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | - $maxiter = 10000; |
|
| 735 | - while ( |
|
| 736 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | - 'id_rubrique', |
|
| 738 | - 'spip_rubriques', |
|
| 739 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | - ) |
|
| 741 | - ) { |
|
| 742 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | - $branche .= ',' . $r; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | - if (strlen($branche) < 10000) { |
|
| 748 | - $b[$id] = $branche; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $branche; |
|
| 718 | + static $b = []; |
|
| 719 | + |
|
| 720 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | + if (!is_array($id)) { |
|
| 722 | + $id = explode(',', $id); |
|
| 723 | + } |
|
| 724 | + $id = join(',', array_map('intval', $id)); |
|
| 725 | + if (isset($b[$id])) { |
|
| 726 | + return $b[$id]; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // Notre branche commence par la rubrique de depart |
|
| 730 | + $branche = $r = $id; |
|
| 731 | + |
|
| 732 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | + $maxiter = 10000; |
|
| 735 | + while ( |
|
| 736 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | + 'id_rubrique', |
|
| 738 | + 'spip_rubriques', |
|
| 739 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | + ) |
|
| 741 | + ) { |
|
| 742 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | + $branche .= ',' . $r; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | + if (strlen($branche) < 10000) { |
|
| 748 | + $b[$id] = $branche; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $branche; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -770,45 +770,45 @@ discard block |
||
| 770 | 770 | * incluant les rubriques transmises et toutes leurs parentées |
| 771 | 771 | */ |
| 772 | 772 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 773 | - static $b = []; |
|
| 774 | - |
|
| 775 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | - if (!is_array($id)) { |
|
| 777 | - $id = explode(',', $id); |
|
| 778 | - } |
|
| 779 | - $id = join(',', array_map('intval', $id)); |
|
| 780 | - |
|
| 781 | - if (isset($b[$id])) { |
|
| 782 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - $hier = ''; |
|
| 787 | - |
|
| 788 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | - $ids_nouveaux_parents = $id; |
|
| 791 | - $maxiter = 10000; |
|
| 792 | - while ( |
|
| 793 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | - 'id_parent', |
|
| 795 | - 'spip_rubriques', |
|
| 796 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | - ) |
|
| 798 | - ) { |
|
| 799 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | - if (strlen($hier) < 10000) { |
|
| 805 | - $b[$id] = $hier; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | - |
|
| 811 | - return $hier; |
|
| 773 | + static $b = []; |
|
| 774 | + |
|
| 775 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | + if (!is_array($id)) { |
|
| 777 | + $id = explode(',', $id); |
|
| 778 | + } |
|
| 779 | + $id = join(',', array_map('intval', $id)); |
|
| 780 | + |
|
| 781 | + if (isset($b[$id])) { |
|
| 782 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + $hier = ''; |
|
| 787 | + |
|
| 788 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | + $ids_nouveaux_parents = $id; |
|
| 791 | + $maxiter = 10000; |
|
| 792 | + while ( |
|
| 793 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | + 'id_parent', |
|
| 795 | + 'spip_rubriques', |
|
| 796 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | + ) |
|
| 798 | + ) { |
|
| 799 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | + if (strlen($hier) < 10000) { |
|
| 805 | + $b[$id] = $hier; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | + |
|
| 811 | + return $hier; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | |
@@ -826,47 +826,47 @@ discard block |
||
| 826 | 826 | * @return void |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_prochain_postdate($check = false) { |
| 829 | - include_spip('base/abstract_sql'); |
|
| 830 | - if ($check) { |
|
| 831 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | - |
|
| 834 | - $r = sql_select( |
|
| 835 | - 'DISTINCT A.id_rubrique AS id', |
|
| 836 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | - ); |
|
| 839 | - while ($row = sql_fetch($r)) { |
|
| 840 | - publier_branche_rubrique($row['id']); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $t = sql_fetsel( |
|
| 847 | - 'date', |
|
| 848 | - 'spip_articles', |
|
| 849 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | - '', |
|
| 851 | - 'date', |
|
| 852 | - '1' |
|
| 853 | - ); |
|
| 854 | - |
|
| 855 | - if ($t) { |
|
| 856 | - $t = $t['date']; |
|
| 857 | - if ( |
|
| 858 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | - ) { |
|
| 861 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | - ecrire_meta('derniere_modif', time()); |
|
| 863 | - } |
|
| 864 | - } else { |
|
| 865 | - effacer_meta('date_prochain_postdate'); |
|
| 866 | - ecrire_meta('derniere_modif', time()); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - spip_log("prochain postdate: $t"); |
|
| 829 | + include_spip('base/abstract_sql'); |
|
| 830 | + if ($check) { |
|
| 831 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | + |
|
| 834 | + $r = sql_select( |
|
| 835 | + 'DISTINCT A.id_rubrique AS id', |
|
| 836 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | + ); |
|
| 839 | + while ($row = sql_fetch($r)) { |
|
| 840 | + publier_branche_rubrique($row['id']); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $t = sql_fetsel( |
|
| 847 | + 'date', |
|
| 848 | + 'spip_articles', |
|
| 849 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | + '', |
|
| 851 | + 'date', |
|
| 852 | + '1' |
|
| 853 | + ); |
|
| 854 | + |
|
| 855 | + if ($t) { |
|
| 856 | + $t = $t['date']; |
|
| 857 | + if ( |
|
| 858 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | + ) { |
|
| 861 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | + ecrire_meta('derniere_modif', time()); |
|
| 863 | + } |
|
| 864 | + } else { |
|
| 865 | + effacer_meta('date_prochain_postdate'); |
|
| 866 | + ecrire_meta('derniere_modif', time()); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + spip_log("prochain postdate: $t"); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -891,62 +891,62 @@ discard block |
||
| 891 | 891 | */ |
| 892 | 892 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 893 | 893 | |
| 894 | - // eclater l'arborescence demandee |
|
| 895 | - // echapper les </multi> et autres balises fermantes html |
|
| 896 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | - include_spip('base/abstract_sql'); |
|
| 899 | - foreach ($arbo as $titre) { |
|
| 900 | - // retablir les </multi> et autres balises fermantes html |
|
| 901 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | - $r = sql_getfetsel( |
|
| 903 | - 'id_rubrique', |
|
| 904 | - 'spip_rubriques', |
|
| 905 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | - $groupby = [], |
|
| 907 | - $orderby = [], |
|
| 908 | - $limit = '', |
|
| 909 | - $having = [], |
|
| 910 | - $serveur |
|
| 911 | - ); |
|
| 912 | - if ($r !== null) { |
|
| 913 | - $id_parent = $r; |
|
| 914 | - } else { |
|
| 915 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | - 'titre' => $titre, |
|
| 917 | - 'id_parent' => $id_parent, |
|
| 918 | - 'statut' => 'prepa' |
|
| 919 | - ], $desc = [], $serveur); |
|
| 920 | - if ($id_parent > 0) { |
|
| 921 | - $data = sql_fetsel( |
|
| 922 | - 'id_secteur,lang', |
|
| 923 | - 'spip_rubriques', |
|
| 924 | - "id_rubrique=$id_parent", |
|
| 925 | - $groupby = [], |
|
| 926 | - $orderby = [], |
|
| 927 | - $limit = '', |
|
| 928 | - $having = [], |
|
| 929 | - $serveur |
|
| 930 | - ); |
|
| 931 | - $id_secteur = $data['id_secteur']; |
|
| 932 | - $lang = $data['lang']; |
|
| 933 | - } else { |
|
| 934 | - $id_secteur = $id_rubrique; |
|
| 935 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - sql_updateq( |
|
| 939 | - 'spip_rubriques', |
|
| 940 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | - $desc = '', |
|
| 943 | - $serveur |
|
| 944 | - ); |
|
| 945 | - |
|
| 946 | - // pour la recursion |
|
| 947 | - $id_parent = $id_rubrique; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return intval($id_parent); |
|
| 894 | + // eclater l'arborescence demandee |
|
| 895 | + // echapper les </multi> et autres balises fermantes html |
|
| 896 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | + include_spip('base/abstract_sql'); |
|
| 899 | + foreach ($arbo as $titre) { |
|
| 900 | + // retablir les </multi> et autres balises fermantes html |
|
| 901 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | + $r = sql_getfetsel( |
|
| 903 | + 'id_rubrique', |
|
| 904 | + 'spip_rubriques', |
|
| 905 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | + $groupby = [], |
|
| 907 | + $orderby = [], |
|
| 908 | + $limit = '', |
|
| 909 | + $having = [], |
|
| 910 | + $serveur |
|
| 911 | + ); |
|
| 912 | + if ($r !== null) { |
|
| 913 | + $id_parent = $r; |
|
| 914 | + } else { |
|
| 915 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | + 'titre' => $titre, |
|
| 917 | + 'id_parent' => $id_parent, |
|
| 918 | + 'statut' => 'prepa' |
|
| 919 | + ], $desc = [], $serveur); |
|
| 920 | + if ($id_parent > 0) { |
|
| 921 | + $data = sql_fetsel( |
|
| 922 | + 'id_secteur,lang', |
|
| 923 | + 'spip_rubriques', |
|
| 924 | + "id_rubrique=$id_parent", |
|
| 925 | + $groupby = [], |
|
| 926 | + $orderby = [], |
|
| 927 | + $limit = '', |
|
| 928 | + $having = [], |
|
| 929 | + $serveur |
|
| 930 | + ); |
|
| 931 | + $id_secteur = $data['id_secteur']; |
|
| 932 | + $lang = $data['lang']; |
|
| 933 | + } else { |
|
| 934 | + $id_secteur = $id_rubrique; |
|
| 935 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + sql_updateq( |
|
| 939 | + 'spip_rubriques', |
|
| 940 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | + $desc = '', |
|
| 943 | + $serveur |
|
| 944 | + ); |
|
| 945 | + |
|
| 946 | + // pour la recursion |
|
| 947 | + $id_parent = $id_rubrique; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return intval($id_parent); |
|
| 952 | 952 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc(?string $fichier): string { |
| 33 | - if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - // ex: fichier distant |
|
| 37 | - return $fichier ?? ''; |
|
| 38 | - } |
|
| 33 | + if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + // ex: fichier distant |
|
| 37 | + return $fichier ?? ''; |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * @return bool|string |
| 48 | 48 | */ |
| 49 | 49 | function get_spip_doc(?string $fichier) { |
| 50 | - if ($fichier === null) { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // fichier distant |
|
| 55 | - if (tester_url_absolue($fichier)) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // gestion d'erreurs, fichier='' |
|
| 60 | - if (!strlen($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | - $fichier = _DIR_IMG . $fichier; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // fichier normal |
|
| 69 | - return $fichier; |
|
| 50 | + if ($fichier === null) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // fichier distant |
|
| 55 | + if (tester_url_absolue($fichier)) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // gestion d'erreurs, fichier='' |
|
| 60 | + if (!strlen($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | + $fichier = _DIR_IMG . $fichier; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // fichier normal |
|
| 69 | + return $fichier; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function creer_repertoire_documents($ext) { |
| 83 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | - |
|
| 85 | - if (!$ext or !$rep) { |
|
| 86 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | - exit; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | - // par exemple acces_restreint |
|
| 92 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | - if ( |
|
| 94 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | - and $ext !== 'logo' |
|
| 97 | - ) { |
|
| 98 | - include_spip('inc/acces'); |
|
| 99 | - verifier_htaccess($rep); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return $rep; |
|
| 83 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | + |
|
| 85 | + if (!$ext or !$rep) { |
|
| 86 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | + exit; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | + // par exemple acces_restreint |
|
| 92 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | + if ( |
|
| 94 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | + and $ext !== 'logo' |
|
| 97 | + ) { |
|
| 98 | + include_spip('inc/acces'); |
|
| 99 | + verifier_htaccess($rep); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return $rep; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,22 +108,22 @@ discard block |
||
| 108 | 108 | * @param string $nom |
| 109 | 109 | */ |
| 110 | 110 | function effacer_repertoire_temporaire($nom) { |
| 111 | - if ($d = opendir($nom)) { |
|
| 112 | - while (($f = readdir($d)) !== false) { |
|
| 113 | - if (is_file("$nom/$f")) { |
|
| 114 | - spip_unlink("$nom/$f"); |
|
| 115 | - } else { |
|
| 116 | - if ( |
|
| 117 | - $f <> '.' and $f <> '..' |
|
| 118 | - and is_dir("$nom/$f") |
|
| 119 | - ) { |
|
| 120 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - closedir($d); |
|
| 126 | - @rmdir($nom); |
|
| 111 | + if ($d = opendir($nom)) { |
|
| 112 | + while (($f = readdir($d)) !== false) { |
|
| 113 | + if (is_file("$nom/$f")) { |
|
| 114 | + spip_unlink("$nom/$f"); |
|
| 115 | + } else { |
|
| 116 | + if ( |
|
| 117 | + $f <> '.' and $f <> '..' |
|
| 118 | + and is_dir("$nom/$f") |
|
| 119 | + ) { |
|
| 120 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + closedir($d); |
|
| 126 | + @rmdir($nom); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // |
@@ -140,45 +140,45 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 142 | 142 | |
| 143 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | - $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | - |
|
| 146 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | - $dest = translitteration($dest); |
|
| 149 | - $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | - |
|
| 151 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | - // pour les images transformees par rotation (action/documenter) |
|
| 153 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | - |
|
| 155 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | - if ( |
|
| 157 | - !function_exists('verifier_upload_autorise') |
|
| 158 | - or !$r = verifier_upload_autorise($dest) |
|
| 159 | - or $r['autozip'] |
|
| 160 | - ) { |
|
| 161 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | - break; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | - $ext = $m[1] . '.' . $ext; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | - return $source; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | - $n = 0; |
|
| 177 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | - ; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return deplacer_fichier_upload($source, $newFile); |
|
| 143 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | + $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | + |
|
| 146 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | + $dest = translitteration($dest); |
|
| 149 | + $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | + |
|
| 151 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | + // pour les images transformees par rotation (action/documenter) |
|
| 153 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | + |
|
| 155 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | + if ( |
|
| 157 | + !function_exists('verifier_upload_autorise') |
|
| 158 | + or !$r = verifier_upload_autorise($dest) |
|
| 159 | + or $r['autozip'] |
|
| 160 | + ) { |
|
| 161 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | + break; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | + $ext = $m[1] . '.' . $ext; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | + return $source; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | + $n = 0; |
|
| 177 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | + ; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return deplacer_fichier_upload($source, $newFile); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -193,28 +193,28 @@ discard block |
||
| 193 | 193 | * @return bool|string |
| 194 | 194 | */ |
| 195 | 195 | function determine_upload($type = '') { |
| 196 | - if (!function_exists('autoriser')) { |
|
| 197 | - include_spip('inc/autoriser'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ( |
|
| 201 | - !autoriser('chargerftp') |
|
| 202 | - or $type == 'logos' |
|
| 203 | - ) { # on ne le permet pas pour les logos |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $repertoire = _DIR_TRANSFERT; |
|
| 208 | - if (!@is_dir($repertoire)) { |
|
| 209 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | - return $repertoire; |
|
| 215 | - } else { |
|
| 216 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | - } |
|
| 196 | + if (!function_exists('autoriser')) { |
|
| 197 | + include_spip('inc/autoriser'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ( |
|
| 201 | + !autoriser('chargerftp') |
|
| 202 | + or $type == 'logos' |
|
| 203 | + ) { # on ne le permet pas pour les logos |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $repertoire = _DIR_TRANSFERT; |
|
| 208 | + if (!@is_dir($repertoire)) { |
|
| 209 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | + return $repertoire; |
|
| 215 | + } else { |
|
| 216 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -233,35 +233,35 @@ discard block |
||
| 233 | 233 | * @return bool|mixed|string |
| 234 | 234 | */ |
| 235 | 235 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 236 | - // Securite |
|
| 237 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | - } else { |
|
| 240 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ($move) { |
|
| 244 | - $ok = @rename($source, $dest); |
|
| 245 | - } else { |
|
| 246 | - $ok = @copy($source, $dest); |
|
| 247 | - } |
|
| 248 | - if (!$ok) { |
|
| 249 | - $ok = @move_uploaded_file($source, $dest); |
|
| 250 | - } |
|
| 251 | - if ($ok) { |
|
| 252 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | - } else { |
|
| 254 | - $f = @fopen($dest, 'w'); |
|
| 255 | - if ($f) { |
|
| 256 | - fclose($f); |
|
| 257 | - } else { |
|
| 258 | - include_spip('inc/flock'); |
|
| 259 | - raler_fichier($dest); |
|
| 260 | - } |
|
| 261 | - spip_unlink($dest); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $ok ? $dest : false; |
|
| 236 | + // Securite |
|
| 237 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | + } else { |
|
| 240 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ($move) { |
|
| 244 | + $ok = @rename($source, $dest); |
|
| 245 | + } else { |
|
| 246 | + $ok = @copy($source, $dest); |
|
| 247 | + } |
|
| 248 | + if (!$ok) { |
|
| 249 | + $ok = @move_uploaded_file($source, $dest); |
|
| 250 | + } |
|
| 251 | + if ($ok) { |
|
| 252 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | + } else { |
|
| 254 | + $f = @fopen($dest, 'w'); |
|
| 255 | + if ($f) { |
|
| 256 | + fclose($f); |
|
| 257 | + } else { |
|
| 258 | + include_spip('inc/flock'); |
|
| 259 | + raler_fichier($dest); |
|
| 260 | + } |
|
| 261 | + spip_unlink($dest); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $ok ? $dest : false; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -285,60 +285,60 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | function check_upload_error($error, $msg = '', $return = false) { |
| 287 | 287 | |
| 288 | - if (!$error) { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | - |
|
| 294 | - switch ($error) { |
|
| 295 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | - return true; |
|
| 297 | - |
|
| 298 | - # on peut affiner les differents messages d'erreur |
|
| 299 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | - $msg = _T( |
|
| 301 | - 'upload_limit', |
|
| 302 | - ['max' => ini_get('upload_max_filesize')] |
|
| 303 | - ); |
|
| 304 | - break; |
|
| 305 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | - $msg = _T( |
|
| 307 | - 'upload_limit', |
|
| 308 | - ['max' => ini_get('upload_max_filesize')] |
|
| 309 | - ); |
|
| 310 | - break; |
|
| 311 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | - $msg = _T( |
|
| 313 | - 'upload_limit', |
|
| 314 | - ['max' => ini_get('upload_max_filesize')] |
|
| 315 | - ); |
|
| 316 | - break; |
|
| 317 | - |
|
| 318 | - default: /* autre */ |
|
| 319 | - if (!$msg) { |
|
| 320 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | - } |
|
| 323 | - break; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - spip_log("erreur upload $error"); |
|
| 327 | - if ($return) { |
|
| 328 | - return $msg; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if (_request('iframe') == 'iframe') { |
|
| 332 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | - exit; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - include_spip('inc/minipres'); |
|
| 337 | - echo minipres( |
|
| 338 | - $msg, |
|
| 339 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | - ); |
|
| 341 | - exit; |
|
| 288 | + if (!$error) { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | + |
|
| 294 | + switch ($error) { |
|
| 295 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | + return true; |
|
| 297 | + |
|
| 298 | + # on peut affiner les differents messages d'erreur |
|
| 299 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | + $msg = _T( |
|
| 301 | + 'upload_limit', |
|
| 302 | + ['max' => ini_get('upload_max_filesize')] |
|
| 303 | + ); |
|
| 304 | + break; |
|
| 305 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | + $msg = _T( |
|
| 307 | + 'upload_limit', |
|
| 308 | + ['max' => ini_get('upload_max_filesize')] |
|
| 309 | + ); |
|
| 310 | + break; |
|
| 311 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | + $msg = _T( |
|
| 313 | + 'upload_limit', |
|
| 314 | + ['max' => ini_get('upload_max_filesize')] |
|
| 315 | + ); |
|
| 316 | + break; |
|
| 317 | + |
|
| 318 | + default: /* autre */ |
|
| 319 | + if (!$msg) { |
|
| 320 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | + } |
|
| 323 | + break; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + spip_log("erreur upload $error"); |
|
| 327 | + if ($return) { |
|
| 328 | + return $msg; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if (_request('iframe') == 'iframe') { |
|
| 332 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | + exit; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + include_spip('inc/minipres'); |
|
| 337 | + echo minipres( |
|
| 338 | + $msg, |
|
| 339 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | + ); |
|
| 341 | + exit; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -355,24 +355,24 @@ discard block |
||
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | 357 | function corriger_extension($ext) { |
| 358 | - $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | - switch ($ext) { |
|
| 360 | - case 'htm': |
|
| 361 | - $ext = 'html'; |
|
| 362 | - break; |
|
| 363 | - case 'jpeg': |
|
| 364 | - $ext = 'jpg'; |
|
| 365 | - break; |
|
| 366 | - case 'tiff': |
|
| 367 | - $ext = 'tif'; |
|
| 368 | - break; |
|
| 369 | - case 'aif': |
|
| 370 | - $ext = 'aiff'; |
|
| 371 | - break; |
|
| 372 | - case 'mpeg': |
|
| 373 | - $ext = 'mpg'; |
|
| 374 | - break; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return $ext; |
|
| 358 | + $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | + switch ($ext) { |
|
| 360 | + case 'htm': |
|
| 361 | + $ext = 'html'; |
|
| 362 | + break; |
|
| 363 | + case 'jpeg': |
|
| 364 | + $ext = 'jpg'; |
|
| 365 | + break; |
|
| 366 | + case 'tiff': |
|
| 367 | + $ext = 'tif'; |
|
| 368 | + break; |
|
| 369 | + case 'aif': |
|
| 370 | + $ext = 'aiff'; |
|
| 371 | + break; |
|
| 372 | + case 'mpeg': |
|
| 373 | + $ext = 'mpg'; |
|
| 374 | + break; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return $ext; |
|
| 378 | 378 | } |
@@ -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 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | 214 | function header_silencieux($version) { |
| 215 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | - $version = ''; |
|
| 217 | - } |
|
| 215 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | + $version = ''; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $version; |
|
| 219 | + return $version; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | * - string|null si $raw = false |
| 230 | 230 | */ |
| 231 | 231 | function version_vcs_courante($dir, $raw = false) { |
| 232 | - $desc = decrire_version_git($dir); |
|
| 233 | - if ($desc === null) { |
|
| 234 | - $desc = decrire_version_svn($dir); |
|
| 235 | - } |
|
| 236 | - if ($desc === null or $raw) { |
|
| 237 | - return $desc; |
|
| 238 | - } |
|
| 239 | - // affichage "GIT [master: abcdef]" |
|
| 240 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | - if ($desc['branch']) { |
|
| 242 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | - } |
|
| 244 | - return "{$desc['vcs']} [$commit]"; |
|
| 232 | + $desc = decrire_version_git($dir); |
|
| 233 | + if ($desc === null) { |
|
| 234 | + $desc = decrire_version_svn($dir); |
|
| 235 | + } |
|
| 236 | + if ($desc === null or $raw) { |
|
| 237 | + return $desc; |
|
| 238 | + } |
|
| 239 | + // affichage "GIT [master: abcdef]" |
|
| 240 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | + if ($desc['branch']) { |
|
| 242 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | + } |
|
| 244 | + return "{$desc['vcs']} [$commit]"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -253,24 +253,24 @@ discard block |
||
| 253 | 253 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 254 | 254 | **/ |
| 255 | 255 | function decrire_version_git($dir) { |
| 256 | - if (!$dir) { |
|
| 257 | - $dir = '.'; |
|
| 258 | - } |
|
| 256 | + if (!$dir) { |
|
| 257 | + $dir = '.'; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // version installee par GIT |
|
| 261 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | - $currentHead = trim(substr($c, 4)); |
|
| 263 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | - return [ |
|
| 265 | - 'vcs' => 'GIT', |
|
| 266 | - 'branch' => basename($currentHead), |
|
| 267 | - 'commit' => trim($hash), |
|
| 268 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | - ]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 260 | + // version installee par GIT |
|
| 261 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | + $currentHead = trim(substr($c, 4)); |
|
| 263 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | + return [ |
|
| 265 | + 'vcs' => 'GIT', |
|
| 266 | + 'branch' => basename($currentHead), |
|
| 267 | + 'commit' => trim($hash), |
|
| 268 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | + ]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - return null; |
|
| 273 | + return null; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -283,25 +283,25 @@ discard block |
||
| 283 | 283 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function decrire_version_svn($dir) { |
| 286 | - if (!$dir) { |
|
| 287 | - $dir = '.'; |
|
| 288 | - } |
|
| 289 | - // version installee par SVN |
|
| 290 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | - if ($result) { |
|
| 294 | - $row = $result->fetchArray(); |
|
| 295 | - if ($row['changed_revision'] != '') { |
|
| 296 | - return [ |
|
| 297 | - 'vcs' => 'SVN', |
|
| 298 | - 'branch' => '', |
|
| 299 | - 'commit' => $row['changed_revision'], |
|
| 300 | - ]; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return null; |
|
| 286 | + if (!$dir) { |
|
| 287 | + $dir = '.'; |
|
| 288 | + } |
|
| 289 | + // version installee par SVN |
|
| 290 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | + if ($result) { |
|
| 294 | + $row = $result->fetchArray(); |
|
| 295 | + if ($row['changed_revision'] != '') { |
|
| 296 | + return [ |
|
| 297 | + 'vcs' => 'SVN', |
|
| 298 | + 'branch' => '', |
|
| 299 | + 'commit' => $row['changed_revision'], |
|
| 300 | + ]; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return null; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | * Code HTML retourné par le filtre |
| 349 | 349 | **/ |
| 350 | 350 | function filtrer($filtre) { |
| 351 | - $tous = func_get_args(); |
|
| 352 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | - return image_filtrer($tous); |
|
| 354 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | - array_shift($tous); |
|
| 356 | - return $f(...$tous); |
|
| 357 | - } else { |
|
| 358 | - // le filtre n'existe pas, on provoque une erreur |
|
| 359 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | - erreur_squelette($msg); |
|
| 361 | - return ''; |
|
| 362 | - } |
|
| 351 | + $tous = func_get_args(); |
|
| 352 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | + return image_filtrer($tous); |
|
| 354 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | + array_shift($tous); |
|
| 356 | + return $f(...$tous); |
|
| 357 | + } else { |
|
| 358 | + // le filtre n'existe pas, on provoque une erreur |
|
| 359 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | + erreur_squelette($msg); |
|
| 361 | + return ''; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 377 | 377 | */ |
| 378 | 378 | function trouver_filtre_matrice($filtre) { |
| 379 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | - find_in_path($f, '', true); |
|
| 381 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | - } |
|
| 383 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | + find_in_path($f, '', true); |
|
| 381 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | + } |
|
| 383 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @return mixed |
| 409 | 409 | */ |
| 410 | 410 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 411 | - $Pile['vars'][$key] = $val; |
|
| 412 | - return $continue ? $val : ''; |
|
| 411 | + $Pile['vars'][$key] = $val; |
|
| 412 | + return $continue ? $val : ''; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 436 | 436 | */ |
| 437 | 437 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 438 | - $Pile[0][$key] = $val; |
|
| 439 | - return $continue ? $val : ''; |
|
| 438 | + $Pile[0][$key] = $val; |
|
| 439 | + return $continue ? $val : ''; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | 447 | function filtre_sanitize_env(&$Pile, $keys) { |
| 448 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | - return ''; |
|
| 448 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | * @return mixed Retourne la valeur (sans la modifier). |
| 470 | 470 | */ |
| 471 | 471 | function filtre_debug($val, $key = null) { |
| 472 | - $debug = ( |
|
| 473 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | - ) . var_export($val, true); |
|
| 472 | + $debug = ( |
|
| 473 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | + ) . var_export($val, true); |
|
| 475 | 475 | |
| 476 | - include_spip('inc/autoriser'); |
|
| 477 | - if (autoriser('webmestre')) { |
|
| 478 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | - } |
|
| 476 | + include_spip('inc/autoriser'); |
|
| 477 | + if (autoriser('webmestre')) { |
|
| 478 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - spip_log($debug, 'debug'); |
|
| 481 | + spip_log($debug, 'debug'); |
|
| 482 | 482 | |
| 483 | - return $val; |
|
| 483 | + return $val; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -508,89 +508,89 @@ discard block |
||
| 508 | 508 | * Texte qui a reçu les filtres |
| 509 | 509 | **/ |
| 510 | 510 | function image_filtrer($args) { |
| 511 | - $filtre = array_shift($args); # enlever $filtre |
|
| 512 | - $texte = array_shift($args); |
|
| 513 | - if ($texte === null || !strlen($texte)) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | - // Cas du nom de fichier local |
|
| 519 | - $is_file = trim($texte); |
|
| 520 | - if ( |
|
| 521 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | - or strpos($is_file, '/') === 0 |
|
| 524 | - ) { |
|
| 525 | - $is_file = false; |
|
| 526 | - } |
|
| 527 | - if ($is_file) { |
|
| 528 | - $is_local_file = function ($path) { |
|
| 529 | - if (strpos($path, '?') !== false) { |
|
| 530 | - $path = supprimer_timestamp($path); |
|
| 531 | - // remove ?24px added by find_in_theme on .svg files |
|
| 532 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | - } |
|
| 534 | - return file_exists($path); |
|
| 535 | - }; |
|
| 536 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | - $res = $filtre(...$args); |
|
| 539 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | - return $res; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | - if ( |
|
| 546 | - preg_match_all( |
|
| 547 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | - $texte, |
|
| 549 | - $tags, |
|
| 550 | - PREG_SET_ORDER |
|
| 551 | - ) |
|
| 552 | - ) { |
|
| 553 | - foreach ($tags as $tag) { |
|
| 554 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | - if ( |
|
| 556 | - !$class or |
|
| 557 | - (strpos($class, 'filtre_inactif') === false |
|
| 558 | - // compat historique a virer en 3.2 |
|
| 559 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | - ) { |
|
| 561 | - array_unshift($args, $tag[3]); |
|
| 562 | - if ($reduit = $filtre(...$args)) { |
|
| 563 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | - if ($tag[1]) { |
|
| 565 | - $w = extraire_attribut($reduit, 'width'); |
|
| 566 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | - $w = $regs[1]; |
|
| 568 | - } |
|
| 569 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - // traiter aussi un eventuel mouseover |
|
| 576 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | - $srcover = $match[1]; |
|
| 579 | - array_shift($args); |
|
| 580 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | - $srcover_filter = $filtre(...$args); |
|
| 582 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | - } |
|
| 588 | - array_shift($args); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | - return $texte; |
|
| 511 | + $filtre = array_shift($args); # enlever $filtre |
|
| 512 | + $texte = array_shift($args); |
|
| 513 | + if ($texte === null || !strlen($texte)) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | + // Cas du nom de fichier local |
|
| 519 | + $is_file = trim($texte); |
|
| 520 | + if ( |
|
| 521 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | + or strpos($is_file, '/') === 0 |
|
| 524 | + ) { |
|
| 525 | + $is_file = false; |
|
| 526 | + } |
|
| 527 | + if ($is_file) { |
|
| 528 | + $is_local_file = function ($path) { |
|
| 529 | + if (strpos($path, '?') !== false) { |
|
| 530 | + $path = supprimer_timestamp($path); |
|
| 531 | + // remove ?24px added by find_in_theme on .svg files |
|
| 532 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | + } |
|
| 534 | + return file_exists($path); |
|
| 535 | + }; |
|
| 536 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | + $res = $filtre(...$args); |
|
| 539 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | + return $res; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | + if ( |
|
| 546 | + preg_match_all( |
|
| 547 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | + $texte, |
|
| 549 | + $tags, |
|
| 550 | + PREG_SET_ORDER |
|
| 551 | + ) |
|
| 552 | + ) { |
|
| 553 | + foreach ($tags as $tag) { |
|
| 554 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | + if ( |
|
| 556 | + !$class or |
|
| 557 | + (strpos($class, 'filtre_inactif') === false |
|
| 558 | + // compat historique a virer en 3.2 |
|
| 559 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | + ) { |
|
| 561 | + array_unshift($args, $tag[3]); |
|
| 562 | + if ($reduit = $filtre(...$args)) { |
|
| 563 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | + if ($tag[1]) { |
|
| 565 | + $w = extraire_attribut($reduit, 'width'); |
|
| 566 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | + $w = $regs[1]; |
|
| 568 | + } |
|
| 569 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + // traiter aussi un eventuel mouseover |
|
| 576 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | + $srcover = $match[1]; |
|
| 579 | + array_shift($args); |
|
| 580 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | + $srcover_filter = $filtre(...$args); |
|
| 582 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | + } |
|
| 588 | + array_shift($args); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | + return $texte; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -607,91 +607,91 @@ discard block |
||
| 607 | 607 | **/ |
| 608 | 608 | function infos_image($img, $force_refresh = false) { |
| 609 | 609 | |
| 610 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | - $srcWidth = 0; |
|
| 612 | - $srcHeight = 0; |
|
| 613 | - $srcSize = null; |
|
| 614 | - |
|
| 615 | - $src = extraire_attribut($img, 'src'); |
|
| 616 | - |
|
| 617 | - if (!$src) { |
|
| 618 | - $src = $img; |
|
| 619 | - } else { |
|
| 620 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | - if (tester_url_absolue($src)) { |
|
| 627 | - include_spip('inc/distant'); |
|
| 628 | - $fichier = copie_locale($src); |
|
| 629 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | - } |
|
| 631 | - if (($p = strpos($src, '?')) !== false) { |
|
| 632 | - $src = substr($src, 0, $p); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $imagesize = false; |
|
| 636 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | - $srcWidth = $largeur_img[$src]; |
|
| 638 | - } |
|
| 639 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | - $srcHeight = $hauteur_img[$src]; |
|
| 641 | - } |
|
| 642 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | - $srcSize = $poids_img[$src]; |
|
| 644 | - } |
|
| 645 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | - if ( |
|
| 647 | - file_exists($src) |
|
| 648 | - and $imagesize = spip_getimagesize($src) |
|
| 649 | - ) { |
|
| 650 | - if (!$srcWidth) { |
|
| 651 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | - } |
|
| 653 | - if (!$srcHeight) { |
|
| 654 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | - } |
|
| 656 | - if (!$srcSize) { |
|
| 657 | - $poids_img[$src] = filesize($src); |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - elseif (strpos($src, '<svg') !== false) { |
|
| 661 | - include_spip('inc/svg'); |
|
| 662 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | - if (!$srcWidth) { |
|
| 665 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | - } |
|
| 667 | - if (!$srcHeight) { |
|
| 668 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | - } |
|
| 670 | - if (!$srcSize) { |
|
| 671 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | - elseif ( |
|
| 678 | - @file_exists($f = "$src.src") |
|
| 679 | - and lire_fichier($f, $valeurs) |
|
| 680 | - and $valeurs = unserialize($valeurs) |
|
| 681 | - ) { |
|
| 682 | - if (!$srcWidth) { |
|
| 683 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | - } |
|
| 685 | - if (!$srcHeight) { |
|
| 686 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | - } |
|
| 688 | - if (!$srcSize) { |
|
| 689 | - $poids_img[$src] = $srcSize = 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 610 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | + $srcWidth = 0; |
|
| 612 | + $srcHeight = 0; |
|
| 613 | + $srcSize = null; |
|
| 614 | + |
|
| 615 | + $src = extraire_attribut($img, 'src'); |
|
| 616 | + |
|
| 617 | + if (!$src) { |
|
| 618 | + $src = $img; |
|
| 619 | + } else { |
|
| 620 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | + if (tester_url_absolue($src)) { |
|
| 627 | + include_spip('inc/distant'); |
|
| 628 | + $fichier = copie_locale($src); |
|
| 629 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | + } |
|
| 631 | + if (($p = strpos($src, '?')) !== false) { |
|
| 632 | + $src = substr($src, 0, $p); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $imagesize = false; |
|
| 636 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | + $srcWidth = $largeur_img[$src]; |
|
| 638 | + } |
|
| 639 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | + $srcHeight = $hauteur_img[$src]; |
|
| 641 | + } |
|
| 642 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | + $srcSize = $poids_img[$src]; |
|
| 644 | + } |
|
| 645 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | + if ( |
|
| 647 | + file_exists($src) |
|
| 648 | + and $imagesize = spip_getimagesize($src) |
|
| 649 | + ) { |
|
| 650 | + if (!$srcWidth) { |
|
| 651 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | + } |
|
| 653 | + if (!$srcHeight) { |
|
| 654 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | + } |
|
| 656 | + if (!$srcSize) { |
|
| 657 | + $poids_img[$src] = filesize($src); |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + elseif (strpos($src, '<svg') !== false) { |
|
| 661 | + include_spip('inc/svg'); |
|
| 662 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | + if (!$srcWidth) { |
|
| 665 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | + } |
|
| 667 | + if (!$srcHeight) { |
|
| 668 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | + } |
|
| 670 | + if (!$srcSize) { |
|
| 671 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | + elseif ( |
|
| 678 | + @file_exists($f = "$src.src") |
|
| 679 | + and lire_fichier($f, $valeurs) |
|
| 680 | + and $valeurs = unserialize($valeurs) |
|
| 681 | + ) { |
|
| 682 | + if (!$srcWidth) { |
|
| 683 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | + } |
|
| 685 | + if (!$srcHeight) { |
|
| 686 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | + } |
|
| 688 | + if (!$srcSize) { |
|
| 689 | + $poids_img[$src] = $srcSize = 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | * poids |
| 708 | 708 | **/ |
| 709 | 709 | function poids_image($img, $force_refresh = false) { |
| 710 | - $infos = infos_image($img, $force_refresh); |
|
| 711 | - return $infos['poids']; |
|
| 710 | + $infos = infos_image($img, $force_refresh); |
|
| 711 | + return $infos['poids']; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function taille_image($img, $force_refresh = false) { |
| 715 | - $infos = infos_image($img, $force_refresh); |
|
| 716 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 715 | + $infos = infos_image($img, $force_refresh); |
|
| 716 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 731 | 731 | **/ |
| 732 | 732 | function largeur($img) { |
| 733 | - if (!$img) { |
|
| 734 | - return; |
|
| 735 | - } |
|
| 736 | - [$h, $l] = taille_image($img); |
|
| 733 | + if (!$img) { |
|
| 734 | + return; |
|
| 735 | + } |
|
| 736 | + [$h, $l] = taille_image($img); |
|
| 737 | 737 | |
| 738 | - return $l; |
|
| 738 | + return $l; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 753 | 753 | **/ |
| 754 | 754 | function hauteur($img) { |
| 755 | - if (!$img) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - [$h, $l] = taille_image($img); |
|
| 755 | + if (!$img) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + [$h, $l] = taille_image($img); |
|
| 759 | 759 | |
| 760 | - return $h; |
|
| 760 | + return $h; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | * @return string |
| 778 | 778 | **/ |
| 779 | 779 | function corriger_entites_html($texte) { |
| 780 | - if (strpos($texte, '&') === false) { |
|
| 781 | - return $texte; |
|
| 782 | - } |
|
| 780 | + if (strpos($texte, '&') === false) { |
|
| 781 | + return $texte; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 784 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | * @return string |
| 797 | 797 | **/ |
| 798 | 798 | function corriger_toutes_entites_html($texte) { |
| 799 | - if (strpos($texte, '&') === false) { |
|
| 800 | - return $texte; |
|
| 801 | - } |
|
| 799 | + if (strpos($texte, '&') === false) { |
|
| 800 | + return $texte; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 803 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * @return string |
| 811 | 811 | **/ |
| 812 | 812 | function proteger_amp($texte) { |
| 813 | - return str_replace('&', '&', $texte); |
|
| 813 | + return str_replace('&', '&', $texte); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -841,21 +841,21 @@ discard block |
||
| 841 | 841 | * @return mixed|string |
| 842 | 842 | */ |
| 843 | 843 | function entites_html($texte, $tout = false, $quote = true) { |
| 844 | - if ( |
|
| 845 | - !is_string($texte) or !$texte |
|
| 846 | - or strpbrk($texte, "&\"'<>") == false |
|
| 847 | - ) { |
|
| 848 | - return $texte; |
|
| 849 | - } |
|
| 850 | - include_spip('inc/texte'); |
|
| 851 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | - $flags |= ENT_HTML401; |
|
| 853 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | - if ($tout) { |
|
| 855 | - return corriger_toutes_entites_html($texte); |
|
| 856 | - } else { |
|
| 857 | - return corriger_entites_html($texte); |
|
| 858 | - } |
|
| 844 | + if ( |
|
| 845 | + !is_string($texte) or !$texte |
|
| 846 | + or strpbrk($texte, "&\"'<>") == false |
|
| 847 | + ) { |
|
| 848 | + return $texte; |
|
| 849 | + } |
|
| 850 | + include_spip('inc/texte'); |
|
| 851 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | + $flags |= ENT_HTML401; |
|
| 853 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | + if ($tout) { |
|
| 855 | + return corriger_toutes_entites_html($texte); |
|
| 856 | + } else { |
|
| 857 | + return corriger_entites_html($texte); |
|
| 858 | + } |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -874,37 +874,37 @@ discard block |
||
| 874 | 874 | * Texte converti |
| 875 | 875 | **/ |
| 876 | 876 | function filtrer_entites($texte) { |
| 877 | - if (strpos($texte, '&') === false) { |
|
| 878 | - return $texte; |
|
| 879 | - } |
|
| 880 | - // filtrer |
|
| 881 | - $texte = html2unicode($texte); |
|
| 882 | - // remettre le tout dans le charset cible |
|
| 883 | - $texte = unicode2charset($texte); |
|
| 884 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | - // (on le faisait deja avec un ") |
|
| 886 | - if (strpos($texte, '&#') !== false) { |
|
| 887 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | - } |
|
| 877 | + if (strpos($texte, '&') === false) { |
|
| 878 | + return $texte; |
|
| 879 | + } |
|
| 880 | + // filtrer |
|
| 881 | + $texte = html2unicode($texte); |
|
| 882 | + // remettre le tout dans le charset cible |
|
| 883 | + $texte = unicode2charset($texte); |
|
| 884 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | + // (on le faisait deja avec un ") |
|
| 886 | + if (strpos($texte, '&#') !== false) { |
|
| 887 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - return $texte; |
|
| 890 | + return $texte; |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
| 894 | 894 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 895 | - /** |
|
| 896 | - * Version sécurisée de filtrer_entites |
|
| 897 | - * |
|
| 898 | - * @uses interdire_scripts() |
|
| 899 | - * @uses filtrer_entites() |
|
| 900 | - * |
|
| 901 | - * @param string $t |
|
| 902 | - * @return string |
|
| 903 | - */ |
|
| 904 | - function filtre_filtrer_entites_dist($t) { |
|
| 905 | - include_spip('inc/texte'); |
|
| 906 | - return interdire_scripts(filtrer_entites($t)); |
|
| 907 | - } |
|
| 895 | + /** |
|
| 896 | + * Version sécurisée de filtrer_entites |
|
| 897 | + * |
|
| 898 | + * @uses interdire_scripts() |
|
| 899 | + * @uses filtrer_entites() |
|
| 900 | + * |
|
| 901 | + * @param string $t |
|
| 902 | + * @return string |
|
| 903 | + */ |
|
| 904 | + function filtre_filtrer_entites_dist($t) { |
|
| 905 | + include_spip('inc/texte'); |
|
| 906 | + return interdire_scripts(filtrer_entites($t)); |
|
| 907 | + } |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -919,18 +919,18 @@ discard block |
||
| 919 | 919 | * @return string|array |
| 920 | 920 | **/ |
| 921 | 921 | function supprimer_caracteres_illegaux($texte) { |
| 922 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 923 | - static $to = null; |
|
| 922 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 923 | + static $to = null; |
|
| 924 | 924 | |
| 925 | - if (is_array($texte)) { |
|
| 926 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | - } |
|
| 925 | + if (is_array($texte)) { |
|
| 926 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - if (!$to) { |
|
| 930 | - $to = str_repeat('-', strlen($from)); |
|
| 931 | - } |
|
| 929 | + if (!$to) { |
|
| 930 | + $to = str_repeat('-', strlen($from)); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return strtr($texte, $from, $to); |
|
| 933 | + return strtr($texte, $from, $to); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | * @return string|array |
| 943 | 943 | **/ |
| 944 | 944 | function corriger_caracteres($texte) { |
| 945 | - $texte = corriger_caracteres_windows($texte); |
|
| 946 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 945 | + $texte = corriger_caracteres_windows($texte); |
|
| 946 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 947 | 947 | |
| 948 | - return $texte; |
|
| 948 | + return $texte; |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -962,44 +962,44 @@ discard block |
||
| 962 | 962 | * Texte encodé pour XML |
| 963 | 963 | */ |
| 964 | 964 | function texte_backend(string $texte): string { |
| 965 | - if ($texte === '') { |
|
| 966 | - return ''; |
|
| 967 | - } |
|
| 965 | + if ($texte === '') { |
|
| 966 | + return ''; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 969 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 970 | 970 | |
| 971 | - // si on a des liens ou des images, les passer en absolu |
|
| 972 | - $texte = liens_absolus($texte); |
|
| 971 | + // si on a des liens ou des images, les passer en absolu |
|
| 972 | + $texte = liens_absolus($texte); |
|
| 973 | 973 | |
| 974 | - // echapper les tags > < |
|
| 975 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 974 | + // echapper les tags > < |
|
| 975 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 976 | 976 | |
| 977 | - // importer les é |
|
| 978 | - $texte = filtrer_entites($texte); |
|
| 977 | + // importer les é |
|
| 978 | + $texte = filtrer_entites($texte); |
|
| 979 | 979 | |
| 980 | - // " -> " et tout ce genre de choses |
|
| 981 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | - $texte = str_replace(' ', ' ', $texte); |
|
| 983 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | - $texte = entites_html($texte, false, false); |
|
| 986 | - // mais bien echapper les double quotes ! |
|
| 987 | - $texte = str_replace('"', '"', $texte); |
|
| 980 | + // " -> " et tout ce genre de choses |
|
| 981 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | + $texte = str_replace(' ', ' ', $texte); |
|
| 983 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | + $texte = entites_html($texte, false, false); |
|
| 986 | + // mais bien echapper les double quotes ! |
|
| 987 | + $texte = str_replace('"', '"', $texte); |
|
| 988 | 988 | |
| 989 | - // verifier le charset |
|
| 990 | - $texte = charset2unicode($texte); |
|
| 989 | + // verifier le charset |
|
| 990 | + $texte = charset2unicode($texte); |
|
| 991 | 991 | |
| 992 | - // Caracteres problematiques en iso-latin 1 |
|
| 993 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | - } |
|
| 992 | + // Caracteres problematiques en iso-latin 1 |
|
| 993 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | + } |
|
| 998 | 998 | |
| 999 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | - // ==> on les remplace par l'entite HTML |
|
| 1002 | - return str_replace($apostrophe, "'", $texte); |
|
| 999 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | + // ==> on les remplace par l'entite HTML |
|
| 1002 | + return str_replace($apostrophe, "'", $texte); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | * Texte encodé et quote pour XML |
| 1017 | 1017 | */ |
| 1018 | 1018 | function texte_backendq(string $texte): string { |
| 1019 | - return addslashes(texte_backend($texte)); |
|
| 1019 | + return addslashes(texte_backend($texte)); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | |
@@ -1039,11 +1039,11 @@ discard block |
||
| 1039 | 1039 | * Numéro de titre, sinon chaîne vide |
| 1040 | 1040 | **/ |
| 1041 | 1041 | function supprimer_numero($texte) { |
| 1042 | - return preg_replace( |
|
| 1043 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | - '', |
|
| 1045 | - $texte |
|
| 1046 | - ); |
|
| 1042 | + return preg_replace( |
|
| 1043 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | + '', |
|
| 1045 | + $texte |
|
| 1046 | + ); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1066,17 +1066,17 @@ discard block |
||
| 1066 | 1066 | * Numéro de titre, sinon chaîne vide |
| 1067 | 1067 | **/ |
| 1068 | 1068 | function recuperer_numero($texte) { |
| 1069 | - if ( |
|
| 1070 | - preg_match( |
|
| 1071 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | - $texte, |
|
| 1073 | - $regs |
|
| 1074 | - ) |
|
| 1075 | - ) { |
|
| 1076 | - return strval($regs[1]); |
|
| 1077 | - } else { |
|
| 1078 | - return ''; |
|
| 1079 | - } |
|
| 1069 | + if ( |
|
| 1070 | + preg_match( |
|
| 1071 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | + $texte, |
|
| 1073 | + $regs |
|
| 1074 | + ) |
|
| 1075 | + ) { |
|
| 1076 | + return strval($regs[1]); |
|
| 1077 | + } else { |
|
| 1078 | + return ''; |
|
| 1079 | + } |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * Texte converti |
| 1104 | 1104 | **/ |
| 1105 | 1105 | function supprimer_tags(?string $texte, $rempl = ''): string { |
| 1106 | - if ($texte === null || !strlen($texte)) { |
|
| 1107 | - return ''; |
|
| 1108 | - } |
|
| 1109 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | - // ne pas oublier un < final non ferme car coupe |
|
| 1111 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | - $texte = str_replace('<', '<', $texte); |
|
| 1106 | + if ($texte === null || !strlen($texte)) { |
|
| 1107 | + return ''; |
|
| 1108 | + } |
|
| 1109 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | + // ne pas oublier un < final non ferme car coupe |
|
| 1111 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | + $texte = str_replace('<', '<', $texte); |
|
| 1114 | 1114 | |
| 1115 | - return $texte; |
|
| 1115 | + return $texte; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1135,9 +1135,9 @@ discard block |
||
| 1135 | 1135 | * Texte converti |
| 1136 | 1136 | **/ |
| 1137 | 1137 | function echapper_tags($texte, $rempl = '') { |
| 1138 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1138 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1139 | 1139 | |
| 1140 | - return $texte; |
|
| 1140 | + return $texte; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1158,18 +1158,18 @@ discard block |
||
| 1158 | 1158 | * Texte converti |
| 1159 | 1159 | **/ |
| 1160 | 1160 | function textebrut($texte) { |
| 1161 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | - $texte = supprimer_tags($texte); |
|
| 1168 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | - $texte = str_replace('’', "'", $texte); |
|
| 1161 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | + $texte = supprimer_tags($texte); |
|
| 1168 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | + $texte = str_replace('’', "'", $texte); |
|
| 1171 | 1171 | |
| 1172 | - return $texte; |
|
| 1172 | + return $texte; |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1185,23 +1185,23 @@ discard block |
||
| 1185 | 1185 | * Texte avec liens ouvrants |
| 1186 | 1186 | **/ |
| 1187 | 1187 | function liens_ouvrants($texte) { |
| 1188 | - if ( |
|
| 1189 | - preg_match_all( |
|
| 1190 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | - $texte, |
|
| 1192 | - $liens, |
|
| 1193 | - PREG_PATTERN_ORDER |
|
| 1194 | - ) |
|
| 1195 | - ) { |
|
| 1196 | - foreach ($liens[0] as $a) { |
|
| 1197 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - return $texte; |
|
| 1188 | + if ( |
|
| 1189 | + preg_match_all( |
|
| 1190 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | + $texte, |
|
| 1192 | + $liens, |
|
| 1193 | + PREG_PATTERN_ORDER |
|
| 1194 | + ) |
|
| 1195 | + ) { |
|
| 1196 | + foreach ($liens[0] as $a) { |
|
| 1197 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return $texte; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | /** |
@@ -1211,22 +1211,22 @@ discard block |
||
| 1211 | 1211 | * @return string |
| 1212 | 1212 | */ |
| 1213 | 1213 | function liens_nofollow($texte) { |
| 1214 | - if (stripos($texte, '<a') === false) { |
|
| 1215 | - return $texte; |
|
| 1216 | - } |
|
| 1214 | + if (stripos($texte, '<a') === false) { |
|
| 1215 | + return $texte; |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | - foreach ($regs[0] as $a) { |
|
| 1220 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1221 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | - } |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1218 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | + foreach ($regs[0] as $a) { |
|
| 1220 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1221 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | + } |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | 1228 | |
| 1229 | - return $texte; |
|
| 1229 | + return $texte; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1245,12 +1245,12 @@ discard block |
||
| 1245 | 1245 | * Texte sans paraghaphes |
| 1246 | 1246 | **/ |
| 1247 | 1247 | function PtoBR($texte) { |
| 1248 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1248 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1252 | 1252 | |
| 1253 | - return $texte; |
|
| 1253 | + return $texte; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1275,14 +1275,14 @@ discard block |
||
| 1275 | 1275 | * @return string Texte encadré du style CSS |
| 1276 | 1276 | */ |
| 1277 | 1277 | function lignes_longues($texte) { |
| 1278 | - if (!strlen(trim($texte))) { |
|
| 1279 | - return $texte; |
|
| 1280 | - } |
|
| 1281 | - include_spip('inc/texte'); |
|
| 1282 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | - 'div' : 'span'; |
|
| 1278 | + if (!strlen(trim($texte))) { |
|
| 1279 | + return $texte; |
|
| 1280 | + } |
|
| 1281 | + include_spip('inc/texte'); |
|
| 1282 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | + 'div' : 'span'; |
|
| 1284 | 1284 | |
| 1285 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1285 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1301,30 +1301,30 @@ discard block |
||
| 1301 | 1301 | * @return string Texte en majuscule |
| 1302 | 1302 | */ |
| 1303 | 1303 | function majuscules($texte) { |
| 1304 | - if (!strlen($texte)) { |
|
| 1305 | - return ''; |
|
| 1306 | - } |
|
| 1304 | + if (!strlen($texte)) { |
|
| 1305 | + return ''; |
|
| 1306 | + } |
|
| 1307 | 1307 | |
| 1308 | - // Cas du turc |
|
| 1309 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | - # remplacer hors des tags et des entites |
|
| 1311 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | - foreach ($regs as $n => $match) { |
|
| 1313 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1308 | + // Cas du turc |
|
| 1309 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | + # remplacer hors des tags et des entites |
|
| 1311 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | + foreach ($regs as $n => $match) { |
|
| 1313 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | 1316 | |
| 1317 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1317 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1318 | 1318 | |
| 1319 | - if ($regs) { |
|
| 1320 | - foreach ($regs as $n => $match) { |
|
| 1321 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1319 | + if ($regs) { |
|
| 1320 | + foreach ($regs as $n => $match) { |
|
| 1321 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - // Cas general |
|
| 1327 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1326 | + // Cas general |
|
| 1327 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
@@ -1342,29 +1342,29 @@ discard block |
||
| 1342 | 1342 | * @return string |
| 1343 | 1343 | **/ |
| 1344 | 1344 | function taille_en_octets($taille) { |
| 1345 | - if (!defined('_KILOBYTE')) { |
|
| 1346 | - /** |
|
| 1347 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | - * |
|
| 1349 | - * @var int |
|
| 1350 | - **/ |
|
| 1351 | - define('_KILOBYTE', 1024); |
|
| 1352 | - } |
|
| 1345 | + if (!defined('_KILOBYTE')) { |
|
| 1346 | + /** |
|
| 1347 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | + * |
|
| 1349 | + * @var int |
|
| 1350 | + **/ |
|
| 1351 | + define('_KILOBYTE', 1024); |
|
| 1352 | + } |
|
| 1353 | 1353 | |
| 1354 | - if ($taille < 1) { |
|
| 1355 | - return ''; |
|
| 1356 | - } |
|
| 1357 | - if ($taille < _KILOBYTE) { |
|
| 1358 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | - } else { |
|
| 1364 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | - } |
|
| 1354 | + if ($taille < 1) { |
|
| 1355 | + return ''; |
|
| 1356 | + } |
|
| 1357 | + if ($taille < _KILOBYTE) { |
|
| 1358 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | + } else { |
|
| 1364 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | - return $taille; |
|
| 1367 | + return $taille; |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1386,21 +1386,21 @@ discard block |
||
| 1386 | 1386 | * Texte prêt pour être utilisé en attribut HTML |
| 1387 | 1387 | **/ |
| 1388 | 1388 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1389 | - if ($texte === null) { |
|
| 1390 | - return ''; |
|
| 1391 | - } |
|
| 1392 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | - if ($textebrut) { |
|
| 1394 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | - } |
|
| 1396 | - $texte = texte_backend($texte); |
|
| 1397 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1389 | + if ($texte === null) { |
|
| 1390 | + return ''; |
|
| 1391 | + } |
|
| 1392 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | + if ($textebrut) { |
|
| 1394 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | + } |
|
| 1396 | + $texte = texte_backend($texte); |
|
| 1397 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1398 | 1398 | |
| 1399 | - return preg_replace( |
|
| 1400 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | - ['&', '&'], |
|
| 1402 | - $texte |
|
| 1403 | - ); |
|
| 1399 | + return preg_replace( |
|
| 1400 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | + ['&', '&'], |
|
| 1402 | + $texte |
|
| 1403 | + ); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | |
@@ -1420,15 +1420,15 @@ discard block |
||
| 1420 | 1420 | * URL ou chaîne vide |
| 1421 | 1421 | **/ |
| 1422 | 1422 | function vider_url(?string $url, $entites = true): string { |
| 1423 | - if ($url === null) { |
|
| 1424 | - return ''; |
|
| 1425 | - } |
|
| 1426 | - # un message pour abs_url |
|
| 1427 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | - $url = trim($url); |
|
| 1429 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1423 | + if ($url === null) { |
|
| 1424 | + return ''; |
|
| 1425 | + } |
|
| 1426 | + # un message pour abs_url |
|
| 1427 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | + $url = trim($url); |
|
| 1429 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1430 | 1430 | |
| 1431 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1431 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | |
@@ -1443,10 +1443,10 @@ discard block |
||
| 1443 | 1443 | * @return string Adresse email maquillée |
| 1444 | 1444 | **/ |
| 1445 | 1445 | function antispam($texte) { |
| 1446 | - include_spip('inc/acces'); |
|
| 1447 | - $masque = creer_pass_aleatoire(3); |
|
| 1446 | + include_spip('inc/acces'); |
|
| 1447 | + $masque = creer_pass_aleatoire(3); |
|
| 1448 | 1448 | |
| 1449 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1449 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1478,8 +1478,8 @@ discard block |
||
| 1478 | 1478 | * True si on a le droit d'accès, false sinon. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1481 | - include_spip('inc/acces'); |
|
| 1482 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1481 | + include_spip('inc/acces'); |
|
| 1482 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1504,13 +1504,13 @@ discard block |
||
| 1504 | 1504 | * Retourne $texte, sinon $sinon. |
| 1505 | 1505 | **/ |
| 1506 | 1506 | function sinon($texte, $sinon = '') { |
| 1507 | - if ($texte) { |
|
| 1508 | - return $texte; |
|
| 1509 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | - return $texte; |
|
| 1511 | - } else { |
|
| 1512 | - return $sinon; |
|
| 1513 | - } |
|
| 1507 | + if ($texte) { |
|
| 1508 | + return $texte; |
|
| 1509 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | + return $texte; |
|
| 1511 | + } else { |
|
| 1512 | + return $sinon; |
|
| 1513 | + } |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | /** |
@@ -1534,7 +1534,7 @@ discard block |
||
| 1534 | 1534 | * @return mixed |
| 1535 | 1535 | **/ |
| 1536 | 1536 | function choixsivide($a, $vide, $pasvide) { |
| 1537 | - return $a ? $pasvide : $vide; |
|
| 1537 | + return $a ? $pasvide : $vide; |
|
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | /** |
@@ -1558,7 +1558,7 @@ discard block |
||
| 1558 | 1558 | * @return mixed |
| 1559 | 1559 | **/ |
| 1560 | 1560 | function choixsiegal($a1, $a2, $v, $f) { |
| 1561 | - return ($a1 == $a2) ? $v : $f; |
|
| 1561 | + return ($a1 == $a2) ? $v : $f; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | // |
@@ -1577,13 +1577,13 @@ discard block |
||
| 1577 | 1577 | * @return string |
| 1578 | 1578 | **/ |
| 1579 | 1579 | function filtrer_ical($texte) { |
| 1580 | - #include_spip('inc/charsets'); |
|
| 1581 | - $texte = html2unicode($texte); |
|
| 1582 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1580 | + #include_spip('inc/charsets'); |
|
| 1581 | + $texte = html2unicode($texte); |
|
| 1582 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1585 | 1585 | |
| 1586 | - return $texte; |
|
| 1586 | + return $texte; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | |
@@ -1608,54 +1608,54 @@ discard block |
||
| 1608 | 1608 | * @return string |
| 1609 | 1609 | **/ |
| 1610 | 1610 | function post_autobr($texte, $delim = "\n_ ") { |
| 1611 | - if (!function_exists('echappe_html')) { |
|
| 1612 | - include_spip('inc/texte_mini'); |
|
| 1613 | - } |
|
| 1614 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | - |
|
| 1617 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | - } else { |
|
| 1620 | - $fin = ''; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - $texte = echappe_html($texte, '', true); |
|
| 1624 | - |
|
| 1625 | - // echapper les modeles |
|
| 1626 | - if (strpos($texte, '<') !== false) { |
|
| 1627 | - include_spip('inc/lien'); |
|
| 1628 | - if (defined('_PREG_MODELE')) { |
|
| 1629 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | - } |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - $debut = ''; |
|
| 1635 | - $suite = $texte; |
|
| 1636 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | - $suite = substr($suite, $t); |
|
| 1639 | - $car = substr($suite, 0, 1); |
|
| 1640 | - if ( |
|
| 1641 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | - ) { |
|
| 1645 | - $debut .= $delim; |
|
| 1646 | - } else { |
|
| 1647 | - $debut .= "\n"; |
|
| 1648 | - } |
|
| 1649 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | - $debut .= $regs[0]; |
|
| 1651 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - $texte = $debut . $suite; |
|
| 1655 | - |
|
| 1656 | - $texte = echappe_retour($texte); |
|
| 1657 | - |
|
| 1658 | - return $texte . $fin; |
|
| 1611 | + if (!function_exists('echappe_html')) { |
|
| 1612 | + include_spip('inc/texte_mini'); |
|
| 1613 | + } |
|
| 1614 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | + |
|
| 1617 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | + } else { |
|
| 1620 | + $fin = ''; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + $texte = echappe_html($texte, '', true); |
|
| 1624 | + |
|
| 1625 | + // echapper les modeles |
|
| 1626 | + if (strpos($texte, '<') !== false) { |
|
| 1627 | + include_spip('inc/lien'); |
|
| 1628 | + if (defined('_PREG_MODELE')) { |
|
| 1629 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | + } |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + $debut = ''; |
|
| 1635 | + $suite = $texte; |
|
| 1636 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | + $suite = substr($suite, $t); |
|
| 1639 | + $car = substr($suite, 0, 1); |
|
| 1640 | + if ( |
|
| 1641 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | + ) { |
|
| 1645 | + $debut .= $delim; |
|
| 1646 | + } else { |
|
| 1647 | + $debut .= "\n"; |
|
| 1648 | + } |
|
| 1649 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | + $debut .= $regs[0]; |
|
| 1651 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + $texte = $debut . $suite; |
|
| 1655 | + |
|
| 1656 | + $texte = echappe_retour($texte); |
|
| 1657 | + |
|
| 1658 | + return $texte . $fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1696,47 +1696,47 @@ discard block |
||
| 1696 | 1696 | * @return string |
| 1697 | 1697 | **/ |
| 1698 | 1698 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1699 | - static $traduire = false; |
|
| 1700 | - if ( |
|
| 1701 | - $letexte |
|
| 1702 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | - ) { |
|
| 1704 | - if (!$traduire) { |
|
| 1705 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | - include_spip('inc/lang'); |
|
| 1707 | - } |
|
| 1708 | - if (!$lang) { |
|
| 1709 | - $lang = $GLOBALS['spip_lang']; |
|
| 1710 | - } |
|
| 1711 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | - if (is_bool($options)) { |
|
| 1713 | - $options = ['echappe_span' => $options]; |
|
| 1714 | - } |
|
| 1715 | - if (!isset($options['echappe_span'])) { |
|
| 1716 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - foreach ($regs as $reg) { |
|
| 1720 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | - $desc = $traduire($cle, $lang, true); |
|
| 1722 | - $l = $desc->langue; |
|
| 1723 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | - if (strlen($desc->texte ?? '')) { |
|
| 1725 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | - if ($l !== $lang) { |
|
| 1727 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | - } |
|
| 1729 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | - } |
|
| 1732 | - if (!$options['echappe_span']) { |
|
| 1733 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | - } |
|
| 1735 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - return $letexte; |
|
| 1699 | + static $traduire = false; |
|
| 1700 | + if ( |
|
| 1701 | + $letexte |
|
| 1702 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | + ) { |
|
| 1704 | + if (!$traduire) { |
|
| 1705 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | + include_spip('inc/lang'); |
|
| 1707 | + } |
|
| 1708 | + if (!$lang) { |
|
| 1709 | + $lang = $GLOBALS['spip_lang']; |
|
| 1710 | + } |
|
| 1711 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | + if (is_bool($options)) { |
|
| 1713 | + $options = ['echappe_span' => $options]; |
|
| 1714 | + } |
|
| 1715 | + if (!isset($options['echappe_span'])) { |
|
| 1716 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + foreach ($regs as $reg) { |
|
| 1720 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | + $desc = $traduire($cle, $lang, true); |
|
| 1722 | + $l = $desc->langue; |
|
| 1723 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | + if (strlen($desc->texte ?? '')) { |
|
| 1725 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | + if ($l !== $lang) { |
|
| 1727 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | + } |
|
| 1729 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | + } |
|
| 1732 | + if (!$options['echappe_span']) { |
|
| 1733 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | + } |
|
| 1735 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + return $letexte; |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | /** |
@@ -1788,68 +1788,68 @@ discard block |
||
| 1788 | 1788 | **/ |
| 1789 | 1789 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1790 | 1790 | |
| 1791 | - if ( |
|
| 1792 | - $letexte |
|
| 1793 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | - ) { |
|
| 1795 | - if (!$lang) { |
|
| 1796 | - $lang = $GLOBALS['spip_lang']; |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | - if (is_bool($options)) { |
|
| 1801 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | - } |
|
| 1803 | - if (!isset($options['echappe_span'])) { |
|
| 1804 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | - } |
|
| 1806 | - if (!isset($options['lang_defaut'])) { |
|
| 1807 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - include_spip('inc/lang'); |
|
| 1811 | - foreach ($regs as $reg) { |
|
| 1812 | - // chercher la version de la langue courante |
|
| 1813 | - $trads = extraire_trads($reg[1]); |
|
| 1814 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | - $trad = $trads[$l]; |
|
| 1816 | - } else { |
|
| 1817 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | - $trad = ''; |
|
| 1819 | - } else { |
|
| 1820 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | - // ou la premiere dispo |
|
| 1822 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | - $l = key($trads); |
|
| 1826 | - } |
|
| 1827 | - $trad = $trads[$l]; |
|
| 1828 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | - $trad = $typographie($trad); |
|
| 1830 | - // Tester si on echappe en span ou en div |
|
| 1831 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | - include_spip('inc/texte'); |
|
| 1833 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | - if ($mode === 'div') { |
|
| 1836 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | - } |
|
| 1838 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | - } |
|
| 1843 | - if (!$options['echappe_span']) { |
|
| 1844 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | - } |
|
| 1846 | - } |
|
| 1847 | - } |
|
| 1848 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | - } |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - return $letexte; |
|
| 1791 | + if ( |
|
| 1792 | + $letexte |
|
| 1793 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | + ) { |
|
| 1795 | + if (!$lang) { |
|
| 1796 | + $lang = $GLOBALS['spip_lang']; |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | + if (is_bool($options)) { |
|
| 1801 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | + } |
|
| 1803 | + if (!isset($options['echappe_span'])) { |
|
| 1804 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | + } |
|
| 1806 | + if (!isset($options['lang_defaut'])) { |
|
| 1807 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + include_spip('inc/lang'); |
|
| 1811 | + foreach ($regs as $reg) { |
|
| 1812 | + // chercher la version de la langue courante |
|
| 1813 | + $trads = extraire_trads($reg[1]); |
|
| 1814 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | + $trad = $trads[$l]; |
|
| 1816 | + } else { |
|
| 1817 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | + $trad = ''; |
|
| 1819 | + } else { |
|
| 1820 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | + // ou la premiere dispo |
|
| 1822 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | + $l = key($trads); |
|
| 1826 | + } |
|
| 1827 | + $trad = $trads[$l]; |
|
| 1828 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | + $trad = $typographie($trad); |
|
| 1830 | + // Tester si on echappe en span ou en div |
|
| 1831 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | + include_spip('inc/texte'); |
|
| 1833 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | + if ($mode === 'div') { |
|
| 1836 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | + } |
|
| 1838 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | + } |
|
| 1843 | + if (!$options['echappe_span']) { |
|
| 1844 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | + } |
|
| 1846 | + } |
|
| 1847 | + } |
|
| 1848 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | + } |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + return $letexte; |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | /** |
@@ -1865,21 +1865,21 @@ discard block |
||
| 1865 | 1865 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function extraire_trads($bloc) { |
| 1868 | - $trads = []; |
|
| 1869 | - $lang = ''; |
|
| 1868 | + $trads = []; |
|
| 1869 | + $lang = ''; |
|
| 1870 | 1870 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1871 | 1871 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1872 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | - $texte = trim($regs[1]); |
|
| 1874 | - if ($texte or $lang) { |
|
| 1875 | - $trads[$lang] = $texte; |
|
| 1876 | - } |
|
| 1877 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | - $lang = $regs[2]; |
|
| 1879 | - } |
|
| 1880 | - $trads[$lang] = $bloc; |
|
| 1872 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | + $texte = trim($regs[1]); |
|
| 1874 | + if ($texte or $lang) { |
|
| 1875 | + $trads[$lang] = $texte; |
|
| 1876 | + } |
|
| 1877 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | + $lang = $regs[2]; |
|
| 1879 | + } |
|
| 1880 | + $trads[$lang] = $bloc; |
|
| 1881 | 1881 | |
| 1882 | - return $trads; |
|
| 1882 | + return $trads; |
|
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | * @return string L'initiale en majuscule |
| 1891 | 1891 | */ |
| 1892 | 1892 | function filtre_initiale($nom) { |
| 1893 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1893 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | |
@@ -1935,33 +1935,33 @@ discard block |
||
| 1935 | 1935 | * - null (interne) : si on empile |
| 1936 | 1936 | **/ |
| 1937 | 1937 | function unique($donnee, $famille = '', $cpt = false) { |
| 1938 | - static $mem = []; |
|
| 1939 | - // permettre de vider la pile et de la restaurer |
|
| 1940 | - // pour le calcul de introduction... |
|
| 1941 | - if ($famille == '_spip_raz_') { |
|
| 1942 | - $tmp = $mem; |
|
| 1943 | - $mem = []; |
|
| 1944 | - |
|
| 1945 | - return $tmp; |
|
| 1946 | - } elseif ($famille == '_spip_set_') { |
|
| 1947 | - $mem = $donnee; |
|
| 1948 | - |
|
| 1949 | - return; |
|
| 1950 | - } |
|
| 1951 | - // eviter une notice |
|
| 1952 | - if (!isset($mem[$famille])) { |
|
| 1953 | - $mem[$famille] = []; |
|
| 1954 | - } |
|
| 1955 | - if ($cpt) { |
|
| 1956 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | - } |
|
| 1958 | - // eviter une notice |
|
| 1959 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | - $mem[$famille][$donnee] = 0; |
|
| 1961 | - } |
|
| 1962 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | - return $donnee; |
|
| 1964 | - } |
|
| 1938 | + static $mem = []; |
|
| 1939 | + // permettre de vider la pile et de la restaurer |
|
| 1940 | + // pour le calcul de introduction... |
|
| 1941 | + if ($famille == '_spip_raz_') { |
|
| 1942 | + $tmp = $mem; |
|
| 1943 | + $mem = []; |
|
| 1944 | + |
|
| 1945 | + return $tmp; |
|
| 1946 | + } elseif ($famille == '_spip_set_') { |
|
| 1947 | + $mem = $donnee; |
|
| 1948 | + |
|
| 1949 | + return; |
|
| 1950 | + } |
|
| 1951 | + // eviter une notice |
|
| 1952 | + if (!isset($mem[$famille])) { |
|
| 1953 | + $mem[$famille] = []; |
|
| 1954 | + } |
|
| 1955 | + if ($cpt) { |
|
| 1956 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | + } |
|
| 1958 | + // eviter une notice |
|
| 1959 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | + $mem[$famille][$donnee] = 0; |
|
| 1961 | + } |
|
| 1962 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | + return $donnee; |
|
| 1964 | + } |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | |
@@ -1991,20 +1991,20 @@ discard block |
||
| 1991 | 1991 | * Une des valeurs en fonction du compteur. |
| 1992 | 1992 | **/ |
| 1993 | 1993 | function alterner($i, ...$args) { |
| 1994 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | - $num = count($args); |
|
| 1994 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | + $num = count($args); |
|
| 1996 | 1996 | |
| 1997 | - if ($num === 1 && is_array($args[0])) { |
|
| 1998 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1999 | - $args = array_values($args[0]); |
|
| 2000 | - $num = count($args); |
|
| 2001 | - } |
|
| 1997 | + if ($num === 1 && is_array($args[0])) { |
|
| 1998 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1999 | + $args = array_values($args[0]); |
|
| 2000 | + $num = count($args); |
|
| 2001 | + } |
|
| 2002 | 2002 | |
| 2003 | - // un index compris entre 0 et num exclus |
|
| 2004 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 2005 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2006 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2007 | - return $args[$i]; |
|
| 2003 | + // un index compris entre 0 et num exclus |
|
| 2004 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 2005 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2006 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2007 | + return $args[$i]; |
|
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | 2010 | |
@@ -2030,51 +2030,51 @@ discard block |
||
| 2030 | 2030 | * - null lorsque l’attribut n’existe pas. |
| 2031 | 2031 | **/ |
| 2032 | 2032 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 2033 | - if (is_array($balise)) { |
|
| 2034 | - array_walk( |
|
| 2035 | - $balise, |
|
| 2036 | - function (&$a, $key, $t) { |
|
| 2037 | - $a = extraire_attribut($a, $t); |
|
| 2038 | - }, |
|
| 2039 | - $attribut |
|
| 2040 | - ); |
|
| 2041 | - |
|
| 2042 | - return $balise; |
|
| 2043 | - } |
|
| 2044 | - if ( |
|
| 2045 | - $balise |
|
| 2046 | - && preg_match( |
|
| 2047 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2048 | - . $attribut |
|
| 2049 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2050 | - $balise, |
|
| 2051 | - $r |
|
| 2052 | - ) |
|
| 2053 | - ) { |
|
| 2054 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2055 | - $r[4] = substr($r[3], 1, -1); |
|
| 2056 | - $r[3] = $r[3][0]; |
|
| 2057 | - } elseif ($r[3] !== '') { |
|
| 2058 | - $r[4] = $r[3]; |
|
| 2059 | - $r[3] = ''; |
|
| 2060 | - } else { |
|
| 2061 | - $r[4] = trim($r[2]); |
|
| 2062 | - } |
|
| 2063 | - $att = $r[4]; |
|
| 2064 | - if (strpos($att, '&#') !== false) { |
|
| 2065 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2066 | - } |
|
| 2067 | - $att = filtrer_entites($att); |
|
| 2068 | - } else { |
|
| 2069 | - $att = null; |
|
| 2070 | - $r = []; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - if ($complet) { |
|
| 2074 | - return [$att, $r]; |
|
| 2075 | - } else { |
|
| 2076 | - return $att; |
|
| 2077 | - } |
|
| 2033 | + if (is_array($balise)) { |
|
| 2034 | + array_walk( |
|
| 2035 | + $balise, |
|
| 2036 | + function (&$a, $key, $t) { |
|
| 2037 | + $a = extraire_attribut($a, $t); |
|
| 2038 | + }, |
|
| 2039 | + $attribut |
|
| 2040 | + ); |
|
| 2041 | + |
|
| 2042 | + return $balise; |
|
| 2043 | + } |
|
| 2044 | + if ( |
|
| 2045 | + $balise |
|
| 2046 | + && preg_match( |
|
| 2047 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2048 | + . $attribut |
|
| 2049 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2050 | + $balise, |
|
| 2051 | + $r |
|
| 2052 | + ) |
|
| 2053 | + ) { |
|
| 2054 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2055 | + $r[4] = substr($r[3], 1, -1); |
|
| 2056 | + $r[3] = $r[3][0]; |
|
| 2057 | + } elseif ($r[3] !== '') { |
|
| 2058 | + $r[4] = $r[3]; |
|
| 2059 | + $r[3] = ''; |
|
| 2060 | + } else { |
|
| 2061 | + $r[4] = trim($r[2]); |
|
| 2062 | + } |
|
| 2063 | + $att = $r[4]; |
|
| 2064 | + if (strpos($att, '&#') !== false) { |
|
| 2065 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2066 | + } |
|
| 2067 | + $att = filtrer_entites($att); |
|
| 2068 | + } else { |
|
| 2069 | + $att = null; |
|
| 2070 | + $r = []; |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + if ($complet) { |
|
| 2074 | + return [$att, $r]; |
|
| 2075 | + } else { |
|
| 2076 | + return $att; |
|
| 2077 | + } |
|
| 2078 | 2078 | } |
| 2079 | 2079 | |
| 2080 | 2080 | /** |
@@ -2107,41 +2107,41 @@ discard block |
||
| 2107 | 2107 | **/ |
| 2108 | 2108 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2109 | 2109 | |
| 2110 | - if ($balise === null or $balise === '') { |
|
| 2111 | - return ''; |
|
| 2112 | - } |
|
| 2110 | + if ($balise === null or $balise === '') { |
|
| 2111 | + return ''; |
|
| 2112 | + } |
|
| 2113 | 2113 | |
| 2114 | - // preparer l'attribut |
|
| 2115 | - // supprimer les etc mais pas les balises html |
|
| 2116 | - // qui ont un sens dans un attribut value d'un input |
|
| 2117 | - if ($proteger) { |
|
| 2118 | - $val = attribut_html($val, false); |
|
| 2119 | - } |
|
| 2114 | + // preparer l'attribut |
|
| 2115 | + // supprimer les etc mais pas les balises html |
|
| 2116 | + // qui ont un sens dans un attribut value d'un input |
|
| 2117 | + if ($proteger) { |
|
| 2118 | + $val = attribut_html($val, false); |
|
| 2119 | + } |
|
| 2120 | 2120 | |
| 2121 | - // echapper les ' pour eviter tout bug |
|
| 2122 | - $val = str_replace("'", ''', $val); |
|
| 2123 | - if ($vider and strlen($val) === 0) { |
|
| 2124 | - $insert = ''; |
|
| 2125 | - } else { |
|
| 2126 | - $insert = " $attribut='$val'"; |
|
| 2127 | - } |
|
| 2121 | + // echapper les ' pour eviter tout bug |
|
| 2122 | + $val = str_replace("'", ''', $val); |
|
| 2123 | + if ($vider and strlen($val) === 0) { |
|
| 2124 | + $insert = ''; |
|
| 2125 | + } else { |
|
| 2126 | + $insert = " $attribut='$val'"; |
|
| 2127 | + } |
|
| 2128 | 2128 | |
| 2129 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2129 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2130 | 2130 | |
| 2131 | - if ($old !== null) { |
|
| 2132 | - // Remplacer l'ancien attribut du meme nom |
|
| 2133 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2134 | - } else { |
|
| 2135 | - // preferer une balise " />" (comme <img />) |
|
| 2136 | - if (preg_match(',/>,', $balise)) { |
|
| 2137 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2138 | - } // sinon une balise <a ...> ... </a> |
|
| 2139 | - else { |
|
| 2140 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2141 | - } |
|
| 2142 | - } |
|
| 2131 | + if ($old !== null) { |
|
| 2132 | + // Remplacer l'ancien attribut du meme nom |
|
| 2133 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2134 | + } else { |
|
| 2135 | + // preferer une balise " />" (comme <img />) |
|
| 2136 | + if (preg_match(',/>,', $balise)) { |
|
| 2137 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2138 | + } // sinon une balise <a ...> ... </a> |
|
| 2139 | + else { |
|
| 2140 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2141 | + } |
|
| 2142 | + } |
|
| 2143 | 2143 | |
| 2144 | - return $balise; |
|
| 2144 | + return $balise; |
|
| 2145 | 2145 | } |
| 2146 | 2146 | |
| 2147 | 2147 | /** |
@@ -2159,7 +2159,7 @@ discard block |
||
| 2159 | 2159 | * @return string Code HTML sans l'attribut |
| 2160 | 2160 | **/ |
| 2161 | 2161 | function vider_attribut(?string $balise, string $attribut): string { |
| 2162 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2162 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | 2165 | /** |
@@ -2171,53 +2171,53 @@ discard block |
||
| 2171 | 2171 | * @return string |
| 2172 | 2172 | */ |
| 2173 | 2173 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2174 | - if (is_string($class)) { |
|
| 2175 | - $class = explode(' ', trim($class)); |
|
| 2176 | - } |
|
| 2177 | - $class = array_filter($class); |
|
| 2178 | - $class = array_unique($class); |
|
| 2179 | - if (!$class) { |
|
| 2180 | - return $balise; |
|
| 2181 | - } |
|
| 2182 | - |
|
| 2183 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2184 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2185 | - return $balise; |
|
| 2186 | - } |
|
| 2187 | - |
|
| 2188 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2189 | - $class_new = $class_courante; |
|
| 2190 | - foreach ($class as $c) { |
|
| 2191 | - $is_class_presente = false; |
|
| 2192 | - if ( |
|
| 2193 | - $class_courante |
|
| 2194 | - and strpos($class_courante, (string) $c) !== false |
|
| 2195 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2196 | - ) { |
|
| 2197 | - $is_class_presente = true; |
|
| 2198 | - } |
|
| 2199 | - if ( |
|
| 2200 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2201 | - and !$is_class_presente |
|
| 2202 | - ) { |
|
| 2203 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2204 | - } elseif ( |
|
| 2205 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2206 | - and $is_class_presente |
|
| 2207 | - ) { |
|
| 2208 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2209 | - } |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - if ($class_new !== $class_courante) { |
|
| 2213 | - if (strlen($class_new)) { |
|
| 2214 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2215 | - } elseif ($class_courante) { |
|
| 2216 | - $balise = vider_attribut($balise, 'class'); |
|
| 2217 | - } |
|
| 2218 | - } |
|
| 2219 | - |
|
| 2220 | - return $balise; |
|
| 2174 | + if (is_string($class)) { |
|
| 2175 | + $class = explode(' ', trim($class)); |
|
| 2176 | + } |
|
| 2177 | + $class = array_filter($class); |
|
| 2178 | + $class = array_unique($class); |
|
| 2179 | + if (!$class) { |
|
| 2180 | + return $balise; |
|
| 2181 | + } |
|
| 2182 | + |
|
| 2183 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2184 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2185 | + return $balise; |
|
| 2186 | + } |
|
| 2187 | + |
|
| 2188 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2189 | + $class_new = $class_courante; |
|
| 2190 | + foreach ($class as $c) { |
|
| 2191 | + $is_class_presente = false; |
|
| 2192 | + if ( |
|
| 2193 | + $class_courante |
|
| 2194 | + and strpos($class_courante, (string) $c) !== false |
|
| 2195 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2196 | + ) { |
|
| 2197 | + $is_class_presente = true; |
|
| 2198 | + } |
|
| 2199 | + if ( |
|
| 2200 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2201 | + and !$is_class_presente |
|
| 2202 | + ) { |
|
| 2203 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2204 | + } elseif ( |
|
| 2205 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2206 | + and $is_class_presente |
|
| 2207 | + ) { |
|
| 2208 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2209 | + } |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + if ($class_new !== $class_courante) { |
|
| 2213 | + if (strlen($class_new)) { |
|
| 2214 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2215 | + } elseif ($class_courante) { |
|
| 2216 | + $balise = vider_attribut($balise, 'class'); |
|
| 2217 | + } |
|
| 2218 | + } |
|
| 2219 | + |
|
| 2220 | + return $balise; |
|
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | 2223 | /** |
@@ -2227,7 +2227,7 @@ discard block |
||
| 2227 | 2227 | * @return string |
| 2228 | 2228 | */ |
| 2229 | 2229 | function ajouter_class($balise, $class) { |
| 2230 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2230 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | /** |
@@ -2237,7 +2237,7 @@ discard block |
||
| 2237 | 2237 | * @return string |
| 2238 | 2238 | */ |
| 2239 | 2239 | function supprimer_class($balise, $class) { |
| 2240 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2240 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2241 | 2241 | } |
| 2242 | 2242 | |
| 2243 | 2243 | /** |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | * @return string |
| 2249 | 2249 | */ |
| 2250 | 2250 | function commuter_class($balise, $class) { |
| 2251 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2251 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | 2254 | /** |
@@ -2259,19 +2259,19 @@ discard block |
||
| 2259 | 2259 | * @return string |
| 2260 | 2260 | */ |
| 2261 | 2261 | function tester_config($id, $mode = '') { |
| 2262 | - include_spip('action/inscrire_auteur'); |
|
| 2262 | + include_spip('action/inscrire_auteur'); |
|
| 2263 | 2263 | |
| 2264 | - return tester_statut_inscription($mode, $id); |
|
| 2264 | + return tester_statut_inscription($mode, $id); |
|
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | // |
| 2268 | 2268 | // Quelques fonctions de calcul arithmetique |
| 2269 | 2269 | // |
| 2270 | 2270 | function floatstr($a) { |
| 2271 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2271 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2272 | 2272 | } |
| 2273 | 2273 | function strize($f, $a, $b) { |
| 2274 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2274 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | 2277 | /** |
@@ -2290,7 +2290,7 @@ discard block |
||
| 2290 | 2290 | * @return int $a+$b |
| 2291 | 2291 | **/ |
| 2292 | 2292 | function plus($a, $b) { |
| 2293 | - return $a + $b; |
|
| 2293 | + return $a + $b; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | function strplus($a, $b) { |
| 2296 | 2296 | return strize('plus', $a, $b); |
@@ -2311,7 +2311,7 @@ discard block |
||
| 2311 | 2311 | * @return int $a-$b |
| 2312 | 2312 | **/ |
| 2313 | 2313 | function moins($a, $b) { |
| 2314 | - return $a - $b; |
|
| 2314 | + return $a - $b; |
|
| 2315 | 2315 | } |
| 2316 | 2316 | function strmoins($a, $b) { |
| 2317 | 2317 | return strize('moins', $a, $b); |
@@ -2334,7 +2334,7 @@ discard block |
||
| 2334 | 2334 | * @return int $a*$b |
| 2335 | 2335 | **/ |
| 2336 | 2336 | function mult($a, $b) { |
| 2337 | - return $a * $b; |
|
| 2337 | + return $a * $b; |
|
| 2338 | 2338 | } |
| 2339 | 2339 | function strmult($a, $b) { |
| 2340 | 2340 | return strize('mult', $a, $b); |
@@ -2357,7 +2357,7 @@ discard block |
||
| 2357 | 2357 | * @return int $a/$b (ou 0 si $b est nul) |
| 2358 | 2358 | **/ |
| 2359 | 2359 | function div($a, $b) { |
| 2360 | - return $b ? $a / $b : 0; |
|
| 2360 | + return $b ? $a / $b : 0; |
|
| 2361 | 2361 | } |
| 2362 | 2362 | function strdiv($a, $b) { |
| 2363 | 2363 | return strize('div', $a, $b); |
@@ -2381,7 +2381,7 @@ discard block |
||
| 2381 | 2381 | * @return int ($nb % $mod) + $add |
| 2382 | 2382 | **/ |
| 2383 | 2383 | function modulo($nb, $mod, $add = 0) { |
| 2384 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2384 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2385 | 2385 | } |
| 2386 | 2386 | |
| 2387 | 2387 | |
@@ -2396,26 +2396,26 @@ discard block |
||
| 2396 | 2396 | * - true sinon |
| 2397 | 2397 | **/ |
| 2398 | 2398 | function nom_acceptable($nom) { |
| 2399 | - $remp2 = []; |
|
| 2400 | - $remp1 = []; |
|
| 2401 | - if (!is_string($nom)) { |
|
| 2402 | - return false; |
|
| 2403 | - } |
|
| 2404 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2405 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2406 | - } |
|
| 2407 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2408 | - foreach ($tags_acceptes as $tag) { |
|
| 2409 | - if (strlen($tag)) { |
|
| 2410 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2411 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2412 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2413 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2414 | - } |
|
| 2415 | - } |
|
| 2416 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2417 | - |
|
| 2418 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2399 | + $remp2 = []; |
|
| 2400 | + $remp1 = []; |
|
| 2401 | + if (!is_string($nom)) { |
|
| 2402 | + return false; |
|
| 2403 | + } |
|
| 2404 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2405 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2406 | + } |
|
| 2407 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2408 | + foreach ($tags_acceptes as $tag) { |
|
| 2409 | + if (strlen($tag)) { |
|
| 2410 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2411 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2412 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2413 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2414 | + } |
|
| 2415 | + } |
|
| 2416 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2417 | + |
|
| 2418 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | |
@@ -2431,14 +2431,14 @@ discard block |
||
| 2431 | 2431 | * - renvoie un tableau si l'entree est un tableau |
| 2432 | 2432 | **/ |
| 2433 | 2433 | function email_valide($adresses) { |
| 2434 | - if (is_array($adresses)) { |
|
| 2435 | - $adresses = array_map('email_valide', $adresses); |
|
| 2436 | - $adresses = array_filter($adresses); |
|
| 2437 | - return $adresses; |
|
| 2438 | - } |
|
| 2434 | + if (is_array($adresses)) { |
|
| 2435 | + $adresses = array_map('email_valide', $adresses); |
|
| 2436 | + $adresses = array_filter($adresses); |
|
| 2437 | + return $adresses; |
|
| 2438 | + } |
|
| 2439 | 2439 | |
| 2440 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2441 | - return $email_valide($adresses); |
|
| 2440 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2441 | + return $email_valide($adresses); |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | /** |
@@ -2452,27 +2452,27 @@ discard block |
||
| 2452 | 2452 | * @return string Texte |
| 2453 | 2453 | **/ |
| 2454 | 2454 | function afficher_enclosures($tags) { |
| 2455 | - $s = []; |
|
| 2456 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2457 | - if ( |
|
| 2458 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2459 | - and $t = extraire_attribut($tag, 'href') |
|
| 2460 | - ) { |
|
| 2461 | - $s[] = preg_replace( |
|
| 2462 | - ',>[^<]+</a>,S', |
|
| 2463 | - '>' |
|
| 2464 | - . http_img_pack( |
|
| 2465 | - 'attachment-16.png', |
|
| 2466 | - $t, |
|
| 2467 | - 'title="' . attribut_html($t) . '"' |
|
| 2468 | - ) |
|
| 2469 | - . '</a>', |
|
| 2470 | - $tag |
|
| 2471 | - ); |
|
| 2472 | - } |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - return join(' ', $s); |
|
| 2455 | + $s = []; |
|
| 2456 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2457 | + if ( |
|
| 2458 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2459 | + and $t = extraire_attribut($tag, 'href') |
|
| 2460 | + ) { |
|
| 2461 | + $s[] = preg_replace( |
|
| 2462 | + ',>[^<]+</a>,S', |
|
| 2463 | + '>' |
|
| 2464 | + . http_img_pack( |
|
| 2465 | + 'attachment-16.png', |
|
| 2466 | + $t, |
|
| 2467 | + 'title="' . attribut_html($t) . '"' |
|
| 2468 | + ) |
|
| 2469 | + . '</a>', |
|
| 2470 | + $tag |
|
| 2471 | + ); |
|
| 2472 | + } |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + return join(' ', $s); |
|
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | 2478 | /** |
@@ -2487,15 +2487,15 @@ discard block |
||
| 2487 | 2487 | * @return string Liens trouvés |
| 2488 | 2488 | **/ |
| 2489 | 2489 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2490 | - $s = []; |
|
| 2491 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2492 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2493 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2494 | - $s[] = $tag; |
|
| 2495 | - } |
|
| 2496 | - } |
|
| 2490 | + $s = []; |
|
| 2491 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2492 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2493 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2494 | + $s[] = $tag; |
|
| 2495 | + } |
|
| 2496 | + } |
|
| 2497 | 2497 | |
| 2498 | - return join(', ', $s); |
|
| 2498 | + return join(', ', $s); |
|
| 2499 | 2499 | } |
| 2500 | 2500 | |
| 2501 | 2501 | |
@@ -2517,21 +2517,21 @@ discard block |
||
| 2517 | 2517 | * @return string Tag HTML `<a>` avec microformat. |
| 2518 | 2518 | **/ |
| 2519 | 2519 | function enclosure2microformat($e) { |
| 2520 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2521 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2522 | - } |
|
| 2523 | - $type = extraire_attribut($e, 'type'); |
|
| 2524 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2525 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2526 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2527 | - } |
|
| 2528 | - $fichier = basename($url); |
|
| 2520 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2521 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2522 | + } |
|
| 2523 | + $type = extraire_attribut($e, 'type'); |
|
| 2524 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2525 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2526 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2527 | + } |
|
| 2528 | + $fichier = basename($url); |
|
| 2529 | 2529 | |
| 2530 | - return '<a rel="enclosure"' |
|
| 2531 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2532 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2533 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2534 | - . '>' . $fichier . '</a>'; |
|
| 2530 | + return '<a rel="enclosure"' |
|
| 2531 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2532 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2533 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2534 | + . '>' . $fichier . '</a>'; |
|
| 2535 | 2535 | } |
| 2536 | 2536 | |
| 2537 | 2537 | /** |
@@ -2549,24 +2549,24 @@ discard block |
||
| 2549 | 2549 | * @return string Tags RSS `<enclosure>`. |
| 2550 | 2550 | **/ |
| 2551 | 2551 | function microformat2enclosure($tags) { |
| 2552 | - $enclosures = []; |
|
| 2553 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2554 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2555 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2556 | - $type = extraire_attribut($e, 'type'); |
|
| 2557 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2558 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2559 | - } # vieux data |
|
| 2560 | - $fichier = basename($url); |
|
| 2561 | - $enclosures[] = '<enclosure' |
|
| 2562 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2563 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2564 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2565 | - . ' />'; |
|
| 2566 | - } |
|
| 2567 | - } |
|
| 2552 | + $enclosures = []; |
|
| 2553 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2554 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2555 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2556 | + $type = extraire_attribut($e, 'type'); |
|
| 2557 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2558 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2559 | + } # vieux data |
|
| 2560 | + $fichier = basename($url); |
|
| 2561 | + $enclosures[] = '<enclosure' |
|
| 2562 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2563 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2564 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2565 | + . ' />'; |
|
| 2566 | + } |
|
| 2567 | + } |
|
| 2568 | 2568 | |
| 2569 | - return join("\n", $enclosures); |
|
| 2569 | + return join("\n", $enclosures); |
|
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | |
@@ -2582,16 +2582,16 @@ discard block |
||
| 2582 | 2582 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2583 | 2583 | **/ |
| 2584 | 2584 | function tags2dcsubject($tags) { |
| 2585 | - $subjects = ''; |
|
| 2586 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2587 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2588 | - $subjects .= '<dc:subject>' |
|
| 2589 | - . texte_backend(textebrut($e)) |
|
| 2590 | - . '</dc:subject>' . "\n"; |
|
| 2591 | - } |
|
| 2592 | - } |
|
| 2585 | + $subjects = ''; |
|
| 2586 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2587 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2588 | + $subjects .= '<dc:subject>' |
|
| 2589 | + . texte_backend(textebrut($e)) |
|
| 2590 | + . '</dc:subject>' . "\n"; |
|
| 2591 | + } |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | - return $subjects; |
|
| 2594 | + return $subjects; |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | /** |
@@ -2620,27 +2620,27 @@ discard block |
||
| 2620 | 2620 | * - Tableau de résultats, si tableau en entrée. |
| 2621 | 2621 | **/ |
| 2622 | 2622 | function extraire_balise($texte, $tag = 'a') { |
| 2623 | - if (is_array($texte)) { |
|
| 2624 | - array_walk( |
|
| 2625 | - $texte, |
|
| 2626 | - function (&$a, $key, $t) { |
|
| 2627 | - $a = extraire_balise($a, $t); |
|
| 2628 | - }, |
|
| 2629 | - $tag |
|
| 2630 | - ); |
|
| 2631 | - |
|
| 2632 | - return $texte; |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - if ( |
|
| 2636 | - preg_match( |
|
| 2637 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2638 | - $texte, |
|
| 2639 | - $regs |
|
| 2640 | - ) |
|
| 2641 | - ) { |
|
| 2642 | - return $regs[0]; |
|
| 2643 | - } |
|
| 2623 | + if (is_array($texte)) { |
|
| 2624 | + array_walk( |
|
| 2625 | + $texte, |
|
| 2626 | + function (&$a, $key, $t) { |
|
| 2627 | + $a = extraire_balise($a, $t); |
|
| 2628 | + }, |
|
| 2629 | + $tag |
|
| 2630 | + ); |
|
| 2631 | + |
|
| 2632 | + return $texte; |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + if ( |
|
| 2636 | + preg_match( |
|
| 2637 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2638 | + $texte, |
|
| 2639 | + $regs |
|
| 2640 | + ) |
|
| 2641 | + ) { |
|
| 2642 | + return $regs[0]; |
|
| 2643 | + } |
|
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | /** |
@@ -2668,30 +2668,30 @@ discard block |
||
| 2668 | 2668 | * - Tableau de résultats, si tableau en entrée. |
| 2669 | 2669 | **/ |
| 2670 | 2670 | function extraire_balises($texte, $tag = 'a') { |
| 2671 | - if (is_array($texte)) { |
|
| 2672 | - array_walk( |
|
| 2673 | - $texte, |
|
| 2674 | - function (&$a, $key, $t) { |
|
| 2675 | - $a = extraire_balises($a, $t); |
|
| 2676 | - }, |
|
| 2677 | - $tag |
|
| 2678 | - ); |
|
| 2679 | - |
|
| 2680 | - return $texte; |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - if ( |
|
| 2684 | - preg_match_all( |
|
| 2685 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2686 | - $texte, |
|
| 2687 | - $regs, |
|
| 2688 | - PREG_PATTERN_ORDER |
|
| 2689 | - ) |
|
| 2690 | - ) { |
|
| 2691 | - return $regs[0]; |
|
| 2692 | - } else { |
|
| 2693 | - return []; |
|
| 2694 | - } |
|
| 2671 | + if (is_array($texte)) { |
|
| 2672 | + array_walk( |
|
| 2673 | + $texte, |
|
| 2674 | + function (&$a, $key, $t) { |
|
| 2675 | + $a = extraire_balises($a, $t); |
|
| 2676 | + }, |
|
| 2677 | + $tag |
|
| 2678 | + ); |
|
| 2679 | + |
|
| 2680 | + return $texte; |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + if ( |
|
| 2684 | + preg_match_all( |
|
| 2685 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2686 | + $texte, |
|
| 2687 | + $regs, |
|
| 2688 | + PREG_PATTERN_ORDER |
|
| 2689 | + ) |
|
| 2690 | + ) { |
|
| 2691 | + return $regs[0]; |
|
| 2692 | + } else { |
|
| 2693 | + return []; |
|
| 2694 | + } |
|
| 2695 | 2695 | } |
| 2696 | 2696 | |
| 2697 | 2697 | /** |
@@ -2720,11 +2720,11 @@ discard block |
||
| 2720 | 2720 | * - `$def` si on n'a pas transmis de tableau |
| 2721 | 2721 | **/ |
| 2722 | 2722 | function in_any($val, $vals, $def = '') { |
| 2723 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2724 | - $vals = $v; |
|
| 2725 | - } |
|
| 2723 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2724 | + $vals = $v; |
|
| 2725 | + } |
|
| 2726 | 2726 | |
| 2727 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2727 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | 2730 | |
@@ -2745,12 +2745,12 @@ discard block |
||
| 2745 | 2745 | * Résultat du calcul |
| 2746 | 2746 | **/ |
| 2747 | 2747 | function valeur_numerique($expr) { |
| 2748 | - $a = 0; |
|
| 2749 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2750 | - eval("\$a = $expr;"); |
|
| 2751 | - } |
|
| 2748 | + $a = 0; |
|
| 2749 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2750 | + eval("\$a = $expr;"); |
|
| 2751 | + } |
|
| 2752 | 2752 | |
| 2753 | - return intval($a); |
|
| 2753 | + return intval($a); |
|
| 2754 | 2754 | } |
| 2755 | 2755 | |
| 2756 | 2756 | /** |
@@ -2769,7 +2769,7 @@ discard block |
||
| 2769 | 2769 | * Retourne `$a*$b/$c` |
| 2770 | 2770 | **/ |
| 2771 | 2771 | function regledetrois($a, $b, $c) { |
| 2772 | - return round($a * $b / $c); |
|
| 2772 | + return round($a * $b / $c); |
|
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | 2775 | |
@@ -2792,79 +2792,79 @@ discard block |
||
| 2792 | 2792 | * @return string Suite de champs input hidden |
| 2793 | 2793 | **/ |
| 2794 | 2794 | function form_hidden(?string $action = ''): string { |
| 2795 | - $action ??= ''; |
|
| 2796 | - |
|
| 2797 | - $contexte = []; |
|
| 2798 | - include_spip('inc/urls'); |
|
| 2799 | - if ( |
|
| 2800 | - $p = urls_decoder_url($action, '') |
|
| 2801 | - and reset($p) |
|
| 2802 | - ) { |
|
| 2803 | - $fond = array_shift($p); |
|
| 2804 | - if ($fond != '404') { |
|
| 2805 | - $contexte = array_shift($p); |
|
| 2806 | - $contexte['page'] = $fond; |
|
| 2807 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2808 | - } |
|
| 2809 | - } |
|
| 2810 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2811 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2812 | - unset($contexte['type']); |
|
| 2813 | - } |
|
| 2814 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2815 | - unset($contexte['type-page']); |
|
| 2816 | - } |
|
| 2817 | - |
|
| 2818 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2819 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2820 | - $values = []; |
|
| 2821 | - |
|
| 2822 | - // d'abord avec celles de l'url |
|
| 2823 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2824 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2825 | - $c = explode('=', $c, 2); |
|
| 2826 | - $var = array_shift($c); |
|
| 2827 | - $val = array_shift($c) ?? ''; |
|
| 2828 | - if ($var) { |
|
| 2829 | - $val = rawurldecode($val); |
|
| 2830 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2831 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2832 | - $values[] = [$var, $val]; |
|
| 2833 | - } else { |
|
| 2834 | - if (!isset($values[$var])) { |
|
| 2835 | - $values[$var] = [$var, $val]; |
|
| 2836 | - } |
|
| 2837 | - } |
|
| 2838 | - } |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - |
|
| 2842 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2843 | - foreach ($contexte as $var => $val) { |
|
| 2844 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2845 | - $values[] = [$var, $val]; |
|
| 2846 | - } else { |
|
| 2847 | - if (!isset($values[$var])) { |
|
| 2848 | - $values[$var] = [$var, $val]; |
|
| 2849 | - } |
|
| 2850 | - } |
|
| 2851 | - } |
|
| 2852 | - |
|
| 2853 | - // puis on rassemble le tout |
|
| 2854 | - $hidden = []; |
|
| 2855 | - foreach ($values as $value) { |
|
| 2856 | - [$var, $val] = $value; |
|
| 2857 | - $hidden[] = '<input name="' |
|
| 2858 | - . entites_html($var) |
|
| 2859 | - . '"' |
|
| 2860 | - . (is_null($val) |
|
| 2861 | - ? '' |
|
| 2862 | - : ' value="' . entites_html($val) . '"' |
|
| 2863 | - ) |
|
| 2864 | - . ' type="hidden"' . "\n/>"; |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - return join('', $hidden); |
|
| 2795 | + $action ??= ''; |
|
| 2796 | + |
|
| 2797 | + $contexte = []; |
|
| 2798 | + include_spip('inc/urls'); |
|
| 2799 | + if ( |
|
| 2800 | + $p = urls_decoder_url($action, '') |
|
| 2801 | + and reset($p) |
|
| 2802 | + ) { |
|
| 2803 | + $fond = array_shift($p); |
|
| 2804 | + if ($fond != '404') { |
|
| 2805 | + $contexte = array_shift($p); |
|
| 2806 | + $contexte['page'] = $fond; |
|
| 2807 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2808 | + } |
|
| 2809 | + } |
|
| 2810 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2811 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2812 | + unset($contexte['type']); |
|
| 2813 | + } |
|
| 2814 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2815 | + unset($contexte['type-page']); |
|
| 2816 | + } |
|
| 2817 | + |
|
| 2818 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2819 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2820 | + $values = []; |
|
| 2821 | + |
|
| 2822 | + // d'abord avec celles de l'url |
|
| 2823 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2824 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2825 | + $c = explode('=', $c, 2); |
|
| 2826 | + $var = array_shift($c); |
|
| 2827 | + $val = array_shift($c) ?? ''; |
|
| 2828 | + if ($var) { |
|
| 2829 | + $val = rawurldecode($val); |
|
| 2830 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2831 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2832 | + $values[] = [$var, $val]; |
|
| 2833 | + } else { |
|
| 2834 | + if (!isset($values[$var])) { |
|
| 2835 | + $values[$var] = [$var, $val]; |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + |
|
| 2842 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2843 | + foreach ($contexte as $var => $val) { |
|
| 2844 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2845 | + $values[] = [$var, $val]; |
|
| 2846 | + } else { |
|
| 2847 | + if (!isset($values[$var])) { |
|
| 2848 | + $values[$var] = [$var, $val]; |
|
| 2849 | + } |
|
| 2850 | + } |
|
| 2851 | + } |
|
| 2852 | + |
|
| 2853 | + // puis on rassemble le tout |
|
| 2854 | + $hidden = []; |
|
| 2855 | + foreach ($values as $value) { |
|
| 2856 | + [$var, $val] = $value; |
|
| 2857 | + $hidden[] = '<input name="' |
|
| 2858 | + . entites_html($var) |
|
| 2859 | + . '"' |
|
| 2860 | + . (is_null($val) |
|
| 2861 | + ? '' |
|
| 2862 | + : ' value="' . entites_html($val) . '"' |
|
| 2863 | + ) |
|
| 2864 | + . ' type="hidden"' . "\n/>"; |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + return join('', $hidden); |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | |
@@ -2886,7 +2886,7 @@ discard block |
||
| 2886 | 2886 | * - la première valeur du tableau sinon. |
| 2887 | 2887 | **/ |
| 2888 | 2888 | function filtre_reset($array) { |
| 2889 | - return !is_array($array) ? null : reset($array); |
|
| 2889 | + return !is_array($array) ? null : reset($array); |
|
| 2890 | 2890 | } |
| 2891 | 2891 | |
| 2892 | 2892 | /** |
@@ -2907,7 +2907,7 @@ discard block |
||
| 2907 | 2907 | * - la dernière valeur du tableau sinon. |
| 2908 | 2908 | **/ |
| 2909 | 2909 | function filtre_end($array) { |
| 2910 | - return !is_array($array) ? null : end($array); |
|
| 2910 | + return !is_array($array) ? null : end($array); |
|
| 2911 | 2911 | } |
| 2912 | 2912 | |
| 2913 | 2913 | /** |
@@ -2927,11 +2927,11 @@ discard block |
||
| 2927 | 2927 | * |
| 2928 | 2928 | **/ |
| 2929 | 2929 | function filtre_push($array, $val) { |
| 2930 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2931 | - return ''; |
|
| 2932 | - } |
|
| 2930 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2931 | + return ''; |
|
| 2932 | + } |
|
| 2933 | 2933 | |
| 2934 | - return $array; |
|
| 2934 | + return $array; |
|
| 2935 | 2935 | } |
| 2936 | 2936 | |
| 2937 | 2937 | /** |
@@ -2950,7 +2950,7 @@ discard block |
||
| 2950 | 2950 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2951 | 2951 | **/ |
| 2952 | 2952 | function filtre_find($array, $val) { |
| 2953 | - return (is_array($array) and in_array($val, $array)); |
|
| 2953 | + return (is_array($array) and in_array($val, $array)); |
|
| 2954 | 2954 | } |
| 2955 | 2955 | |
| 2956 | 2956 | |
@@ -2967,13 +2967,13 @@ discard block |
||
| 2967 | 2967 | * Contenu avec urls en absolus |
| 2968 | 2968 | **/ |
| 2969 | 2969 | function urls_absolues_css($contenu, $source) { |
| 2970 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2970 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2971 | 2971 | |
| 2972 | - return preg_replace_callback( |
|
| 2973 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2974 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2975 | - $contenu |
|
| 2976 | - ); |
|
| 2972 | + return preg_replace_callback( |
|
| 2973 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2974 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2975 | + $contenu |
|
| 2976 | + ); |
|
| 2977 | 2977 | } |
| 2978 | 2978 | |
| 2979 | 2979 | |
@@ -3002,119 +3002,119 @@ discard block |
||
| 3002 | 3002 | * Chemin du fichier CSS inversé |
| 3003 | 3003 | **/ |
| 3004 | 3004 | function direction_css($css, $voulue = '') { |
| 3005 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3006 | - return $css; |
|
| 3007 | - } |
|
| 3008 | - include_spip('inc/lang'); |
|
| 3009 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3010 | - if ($voulue = strtolower($voulue)) { |
|
| 3011 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3012 | - $voulue = lang_dir($voulue); |
|
| 3013 | - } |
|
| 3014 | - } else { |
|
| 3015 | - $voulue = lang_dir(); |
|
| 3016 | - } |
|
| 3017 | - |
|
| 3018 | - $r = count($r) > 1; |
|
| 3019 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3020 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 3021 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3022 | - |
|
| 3023 | - if ($voulue == $dir) { |
|
| 3024 | - return $css; |
|
| 3025 | - } |
|
| 3026 | - |
|
| 3027 | - if ( |
|
| 3028 | - // url absolue |
|
| 3029 | - preg_match(',^https?:,i', $css) |
|
| 3030 | - // ou qui contient un ? |
|
| 3031 | - or (($p = strpos($css, '?')) !== false) |
|
| 3032 | - ) { |
|
| 3033 | - $distant = true; |
|
| 3034 | - $cssf = parse_url($css); |
|
| 3035 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3036 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3037 | - } else { |
|
| 3038 | - $distant = false; |
|
| 3039 | - $cssf = $css; |
|
| 3040 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3041 | - //propose (rien a faire dans ce cas) |
|
| 3042 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3043 | - if (@file_exists($f)) { |
|
| 3044 | - return $f; |
|
| 3045 | - } |
|
| 3046 | - } |
|
| 3047 | - |
|
| 3048 | - // 2. |
|
| 3049 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3050 | - $f = $dir_var |
|
| 3051 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3052 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3053 | - |
|
| 3054 | - // la css peut etre distante (url absolue !) |
|
| 3055 | - if ($distant) { |
|
| 3056 | - include_spip('inc/distant'); |
|
| 3057 | - $res = recuperer_url($css); |
|
| 3058 | - if (!$res or !$contenu = $res['page']) { |
|
| 3059 | - return $css; |
|
| 3060 | - } |
|
| 3061 | - } else { |
|
| 3062 | - if ( |
|
| 3063 | - (@filemtime($f) > @filemtime($css)) |
|
| 3064 | - and (_VAR_MODE != 'recalcul') |
|
| 3065 | - ) { |
|
| 3066 | - return $f; |
|
| 3067 | - } |
|
| 3068 | - if (!lire_fichier($css, $contenu)) { |
|
| 3069 | - return $css; |
|
| 3070 | - } |
|
| 3071 | - } |
|
| 3072 | - |
|
| 3073 | - |
|
| 3074 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3075 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3076 | - $parser = new csstidy(); |
|
| 3077 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3078 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3079 | - $parser->parse($contenu); |
|
| 3080 | - |
|
| 3081 | - $contenu = $parser->print->plain(); |
|
| 3082 | - |
|
| 3083 | - |
|
| 3084 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3085 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3086 | - $src = []; |
|
| 3087 | - $src_direction_css = []; |
|
| 3088 | - $src_faux_abs = []; |
|
| 3089 | - $d = dirname($css); |
|
| 3090 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3091 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3092 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3093 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3094 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3095 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3096 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3097 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3098 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3099 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3100 | - } |
|
| 3101 | - $src[] = $regs[0][$k]; |
|
| 3102 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3103 | - } |
|
| 3104 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3105 | - |
|
| 3106 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3107 | - |
|
| 3108 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3109 | - if (count($src_faux_abs)) { |
|
| 3110 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3111 | - } |
|
| 3112 | - |
|
| 3113 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3114 | - return $css; |
|
| 3115 | - } |
|
| 3116 | - |
|
| 3117 | - return $f; |
|
| 3005 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3006 | + return $css; |
|
| 3007 | + } |
|
| 3008 | + include_spip('inc/lang'); |
|
| 3009 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3010 | + if ($voulue = strtolower($voulue)) { |
|
| 3011 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3012 | + $voulue = lang_dir($voulue); |
|
| 3013 | + } |
|
| 3014 | + } else { |
|
| 3015 | + $voulue = lang_dir(); |
|
| 3016 | + } |
|
| 3017 | + |
|
| 3018 | + $r = count($r) > 1; |
|
| 3019 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3020 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 3021 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3022 | + |
|
| 3023 | + if ($voulue == $dir) { |
|
| 3024 | + return $css; |
|
| 3025 | + } |
|
| 3026 | + |
|
| 3027 | + if ( |
|
| 3028 | + // url absolue |
|
| 3029 | + preg_match(',^https?:,i', $css) |
|
| 3030 | + // ou qui contient un ? |
|
| 3031 | + or (($p = strpos($css, '?')) !== false) |
|
| 3032 | + ) { |
|
| 3033 | + $distant = true; |
|
| 3034 | + $cssf = parse_url($css); |
|
| 3035 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3036 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3037 | + } else { |
|
| 3038 | + $distant = false; |
|
| 3039 | + $cssf = $css; |
|
| 3040 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3041 | + //propose (rien a faire dans ce cas) |
|
| 3042 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3043 | + if (@file_exists($f)) { |
|
| 3044 | + return $f; |
|
| 3045 | + } |
|
| 3046 | + } |
|
| 3047 | + |
|
| 3048 | + // 2. |
|
| 3049 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3050 | + $f = $dir_var |
|
| 3051 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3052 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3053 | + |
|
| 3054 | + // la css peut etre distante (url absolue !) |
|
| 3055 | + if ($distant) { |
|
| 3056 | + include_spip('inc/distant'); |
|
| 3057 | + $res = recuperer_url($css); |
|
| 3058 | + if (!$res or !$contenu = $res['page']) { |
|
| 3059 | + return $css; |
|
| 3060 | + } |
|
| 3061 | + } else { |
|
| 3062 | + if ( |
|
| 3063 | + (@filemtime($f) > @filemtime($css)) |
|
| 3064 | + and (_VAR_MODE != 'recalcul') |
|
| 3065 | + ) { |
|
| 3066 | + return $f; |
|
| 3067 | + } |
|
| 3068 | + if (!lire_fichier($css, $contenu)) { |
|
| 3069 | + return $css; |
|
| 3070 | + } |
|
| 3071 | + } |
|
| 3072 | + |
|
| 3073 | + |
|
| 3074 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3075 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3076 | + $parser = new csstidy(); |
|
| 3077 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3078 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3079 | + $parser->parse($contenu); |
|
| 3080 | + |
|
| 3081 | + $contenu = $parser->print->plain(); |
|
| 3082 | + |
|
| 3083 | + |
|
| 3084 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3085 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3086 | + $src = []; |
|
| 3087 | + $src_direction_css = []; |
|
| 3088 | + $src_faux_abs = []; |
|
| 3089 | + $d = dirname($css); |
|
| 3090 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3091 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3092 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3093 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3094 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3095 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3096 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3097 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3098 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3099 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3100 | + } |
|
| 3101 | + $src[] = $regs[0][$k]; |
|
| 3102 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3103 | + } |
|
| 3104 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3105 | + |
|
| 3106 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3107 | + |
|
| 3108 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3109 | + if (count($src_faux_abs)) { |
|
| 3110 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3111 | + } |
|
| 3112 | + |
|
| 3113 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3114 | + return $css; |
|
| 3115 | + } |
|
| 3116 | + |
|
| 3117 | + return $f; |
|
| 3118 | 3118 | } |
| 3119 | 3119 | |
| 3120 | 3120 | |
@@ -3137,46 +3137,46 @@ discard block |
||
| 3137 | 3137 | * - Chemin ou URL du fichier CSS source sinon. |
| 3138 | 3138 | **/ |
| 3139 | 3139 | function url_absolue_css($css) { |
| 3140 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3141 | - return $css; |
|
| 3142 | - } |
|
| 3140 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3141 | + return $css; |
|
| 3142 | + } |
|
| 3143 | 3143 | |
| 3144 | - $url_absolue_css = url_absolue($css); |
|
| 3144 | + $url_absolue_css = url_absolue($css); |
|
| 3145 | 3145 | |
| 3146 | - $f = basename($css, '.css'); |
|
| 3147 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3148 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3149 | - . '.css'; |
|
| 3146 | + $f = basename($css, '.css'); |
|
| 3147 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3148 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3149 | + . '.css'; |
|
| 3150 | 3150 | |
| 3151 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3152 | - return $f; |
|
| 3153 | - } |
|
| 3151 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3152 | + return $f; |
|
| 3153 | + } |
|
| 3154 | 3154 | |
| 3155 | - if ($url_absolue_css == $css) { |
|
| 3156 | - if ( |
|
| 3157 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3158 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3159 | - ) { |
|
| 3160 | - include_spip('inc/distant'); |
|
| 3161 | - $contenu = recuperer_url($css); |
|
| 3162 | - $contenu = $contenu['page'] ?? ''; |
|
| 3163 | - if (!$contenu) { |
|
| 3164 | - return $css; |
|
| 3165 | - } |
|
| 3166 | - } |
|
| 3167 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3168 | - return $css; |
|
| 3169 | - } |
|
| 3155 | + if ($url_absolue_css == $css) { |
|
| 3156 | + if ( |
|
| 3157 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3158 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3159 | + ) { |
|
| 3160 | + include_spip('inc/distant'); |
|
| 3161 | + $contenu = recuperer_url($css); |
|
| 3162 | + $contenu = $contenu['page'] ?? ''; |
|
| 3163 | + if (!$contenu) { |
|
| 3164 | + return $css; |
|
| 3165 | + } |
|
| 3166 | + } |
|
| 3167 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3168 | + return $css; |
|
| 3169 | + } |
|
| 3170 | 3170 | |
| 3171 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3172 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3171 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3172 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3173 | 3173 | |
| 3174 | - // ecrire la css |
|
| 3175 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3176 | - return $css; |
|
| 3177 | - } |
|
| 3174 | + // ecrire la css |
|
| 3175 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3176 | + return $css; |
|
| 3177 | + } |
|
| 3178 | 3178 | |
| 3179 | - return $f; |
|
| 3179 | + return $f; |
|
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | 3182 | |
@@ -3210,24 +3210,24 @@ discard block |
||
| 3210 | 3210 | * Valeur trouvée ou valeur par défaut. |
| 3211 | 3211 | **/ |
| 3212 | 3212 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3213 | - foreach (explode('/', $cle) as $k) { |
|
| 3214 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3213 | + foreach (explode('/', $cle) as $k) { |
|
| 3214 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3215 | 3215 | |
| 3216 | - if (is_object($table)) { |
|
| 3217 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3218 | - } elseif (is_array($table)) { |
|
| 3219 | - if ($conserver_null) { |
|
| 3220 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3221 | - } else { |
|
| 3222 | - $table = ($table[$k] ?? $defaut); |
|
| 3223 | - } |
|
| 3224 | - } else { |
|
| 3225 | - $table = $defaut; |
|
| 3226 | - break; |
|
| 3227 | - } |
|
| 3228 | - } |
|
| 3216 | + if (is_object($table)) { |
|
| 3217 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3218 | + } elseif (is_array($table)) { |
|
| 3219 | + if ($conserver_null) { |
|
| 3220 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3221 | + } else { |
|
| 3222 | + $table = ($table[$k] ?? $defaut); |
|
| 3223 | + } |
|
| 3224 | + } else { |
|
| 3225 | + $table = $defaut; |
|
| 3226 | + break; |
|
| 3227 | + } |
|
| 3228 | + } |
|
| 3229 | 3229 | |
| 3230 | - return $table; |
|
| 3230 | + return $table; |
|
| 3231 | 3231 | } |
| 3232 | 3232 | |
| 3233 | 3233 | /** |
@@ -3260,22 +3260,22 @@ discard block |
||
| 3260 | 3260 | * - string : expression trouvée. |
| 3261 | 3261 | **/ |
| 3262 | 3262 | function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3263 | - if (intval($modif) and $capte == 0) { |
|
| 3264 | - $capte = $modif; |
|
| 3265 | - $modif = 'UimsS'; |
|
| 3266 | - } |
|
| 3267 | - $expression = str_replace('\/', '/', $expression); |
|
| 3268 | - $expression = str_replace('/', '\/', $expression); |
|
| 3263 | + if (intval($modif) and $capte == 0) { |
|
| 3264 | + $capte = $modif; |
|
| 3265 | + $modif = 'UimsS'; |
|
| 3266 | + } |
|
| 3267 | + $expression = str_replace('\/', '/', $expression); |
|
| 3268 | + $expression = str_replace('/', '\/', $expression); |
|
| 3269 | 3269 | |
| 3270 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3271 | - if (isset($r[$capte])) { |
|
| 3272 | - return $r[$capte]; |
|
| 3273 | - } else { |
|
| 3274 | - return true; |
|
| 3275 | - } |
|
| 3276 | - } |
|
| 3270 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3271 | + if (isset($r[$capte])) { |
|
| 3272 | + return $r[$capte]; |
|
| 3273 | + } else { |
|
| 3274 | + return true; |
|
| 3275 | + } |
|
| 3276 | + } |
|
| 3277 | 3277 | |
| 3278 | - return false; |
|
| 3278 | + return false; |
|
| 3279 | 3279 | } |
| 3280 | 3280 | |
| 3281 | 3281 | |
@@ -3302,10 +3302,10 @@ discard block |
||
| 3302 | 3302 | * Texte |
| 3303 | 3303 | **/ |
| 3304 | 3304 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3305 | - $expression = str_replace('\/', '/', $expression); |
|
| 3306 | - $expression = str_replace('/', '\/', $expression); |
|
| 3305 | + $expression = str_replace('\/', '/', $expression); |
|
| 3306 | + $expression = str_replace('/', '\/', $expression); |
|
| 3307 | 3307 | |
| 3308 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3308 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3309 | 3309 | } |
| 3310 | 3310 | |
| 3311 | 3311 | |
@@ -3323,25 +3323,25 @@ discard block |
||
| 3323 | 3323 | **/ |
| 3324 | 3324 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3325 | 3325 | |
| 3326 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3327 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3326 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3327 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3328 | 3328 | |
| 3329 | - if ( |
|
| 3330 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3331 | - and preg_match_all( |
|
| 3332 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3333 | - $t, |
|
| 3334 | - $matches, |
|
| 3335 | - PREG_PATTERN_ORDER |
|
| 3336 | - ) |
|
| 3337 | - ) { |
|
| 3338 | - if (!isset($doublons['documents'])) { |
|
| 3339 | - $doublons['documents'] = ''; |
|
| 3340 | - } |
|
| 3341 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3342 | - } |
|
| 3329 | + if ( |
|
| 3330 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3331 | + and preg_match_all( |
|
| 3332 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3333 | + $t, |
|
| 3334 | + $matches, |
|
| 3335 | + PREG_PATTERN_ORDER |
|
| 3336 | + ) |
|
| 3337 | + ) { |
|
| 3338 | + if (!isset($doublons['documents'])) { |
|
| 3339 | + $doublons['documents'] = ''; |
|
| 3340 | + } |
|
| 3341 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3342 | + } |
|
| 3343 | 3343 | |
| 3344 | - return $letexte; |
|
| 3344 | + return $letexte; |
|
| 3345 | 3345 | } |
| 3346 | 3346 | |
| 3347 | 3347 | /** |
@@ -3355,7 +3355,7 @@ discard block |
||
| 3355 | 3355 | * @return string Chaîne vide |
| 3356 | 3356 | **/ |
| 3357 | 3357 | function vide($texte) { |
| 3358 | - return ''; |
|
| 3358 | + return ''; |
|
| 3359 | 3359 | } |
| 3360 | 3360 | |
| 3361 | 3361 | // |
@@ -3384,23 +3384,23 @@ discard block |
||
| 3384 | 3384 | * Code HTML résultant |
| 3385 | 3385 | **/ |
| 3386 | 3386 | function env_to_params($env, $ignore_params = []) { |
| 3387 | - $ignore_params = array_merge( |
|
| 3388 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3389 | - $ignore_params |
|
| 3390 | - ); |
|
| 3391 | - if (!is_array($env)) { |
|
| 3392 | - $env = unserialize($env); |
|
| 3393 | - } |
|
| 3394 | - $texte = ''; |
|
| 3395 | - if ($env) { |
|
| 3396 | - foreach ($env as $i => $j) { |
|
| 3397 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3398 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3399 | - } |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3402 | - |
|
| 3403 | - return $texte; |
|
| 3387 | + $ignore_params = array_merge( |
|
| 3388 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3389 | + $ignore_params |
|
| 3390 | + ); |
|
| 3391 | + if (!is_array($env)) { |
|
| 3392 | + $env = unserialize($env); |
|
| 3393 | + } |
|
| 3394 | + $texte = ''; |
|
| 3395 | + if ($env) { |
|
| 3396 | + foreach ($env as $i => $j) { |
|
| 3397 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3398 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3399 | + } |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3402 | + |
|
| 3403 | + return $texte; |
|
| 3404 | 3404 | } |
| 3405 | 3405 | |
| 3406 | 3406 | /** |
@@ -3423,23 +3423,23 @@ discard block |
||
| 3423 | 3423 | * Code HTML résultant |
| 3424 | 3424 | **/ |
| 3425 | 3425 | function env_to_attributs($env, $ignore_params = []) { |
| 3426 | - $ignore_params = array_merge( |
|
| 3427 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3428 | - $ignore_params |
|
| 3429 | - ); |
|
| 3430 | - if (!is_array($env)) { |
|
| 3431 | - $env = unserialize($env); |
|
| 3432 | - } |
|
| 3433 | - $texte = ''; |
|
| 3434 | - if ($env) { |
|
| 3435 | - foreach ($env as $i => $j) { |
|
| 3436 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3437 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3438 | - } |
|
| 3439 | - } |
|
| 3440 | - } |
|
| 3426 | + $ignore_params = array_merge( |
|
| 3427 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3428 | + $ignore_params |
|
| 3429 | + ); |
|
| 3430 | + if (!is_array($env)) { |
|
| 3431 | + $env = unserialize($env); |
|
| 3432 | + } |
|
| 3433 | + $texte = ''; |
|
| 3434 | + if ($env) { |
|
| 3435 | + foreach ($env as $i => $j) { |
|
| 3436 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3437 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3438 | + } |
|
| 3439 | + } |
|
| 3440 | + } |
|
| 3441 | 3441 | |
| 3442 | - return $texte; |
|
| 3442 | + return $texte; |
|
| 3443 | 3443 | } |
| 3444 | 3444 | |
| 3445 | 3445 | |
@@ -3457,7 +3457,7 @@ discard block |
||
| 3457 | 3457 | * @return string Chaînes concaténés |
| 3458 | 3458 | **/ |
| 3459 | 3459 | function concat(...$args): string { |
| 3460 | - return join('', $args); |
|
| 3460 | + return join('', $args); |
|
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | |
@@ -3477,23 +3477,23 @@ discard block |
||
| 3477 | 3477 | * Contenu du ou des fichiers, concaténé |
| 3478 | 3478 | **/ |
| 3479 | 3479 | function charge_scripts($files, $script = true) { |
| 3480 | - $flux = ''; |
|
| 3481 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3482 | - if (!is_string($file)) { |
|
| 3483 | - continue; |
|
| 3484 | - } |
|
| 3485 | - if ($script) { |
|
| 3486 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3487 | - } |
|
| 3488 | - if ($file) { |
|
| 3489 | - $path = find_in_path($file); |
|
| 3490 | - if ($path) { |
|
| 3491 | - $flux .= spip_file_get_contents($path); |
|
| 3492 | - } |
|
| 3493 | - } |
|
| 3494 | - } |
|
| 3495 | - |
|
| 3496 | - return $flux; |
|
| 3480 | + $flux = ''; |
|
| 3481 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3482 | + if (!is_string($file)) { |
|
| 3483 | + continue; |
|
| 3484 | + } |
|
| 3485 | + if ($script) { |
|
| 3486 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3487 | + } |
|
| 3488 | + if ($file) { |
|
| 3489 | + $path = find_in_path($file); |
|
| 3490 | + if ($path) { |
|
| 3491 | + $flux .= spip_file_get_contents($path); |
|
| 3492 | + } |
|
| 3493 | + } |
|
| 3494 | + } |
|
| 3495 | + |
|
| 3496 | + return $flux; |
|
| 3497 | 3497 | } |
| 3498 | 3498 | |
| 3499 | 3499 | /** |
@@ -3504,22 +3504,22 @@ discard block |
||
| 3504 | 3504 | * @return string |
| 3505 | 3505 | */ |
| 3506 | 3506 | function http_img_variante_svg_si_possible($img_file) { |
| 3507 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3508 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3509 | - if ( |
|
| 3510 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3511 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3512 | - and file_exists($variante_svg_generique) |
|
| 3513 | - ) { |
|
| 3514 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3515 | - $img_file = $variante_svg_size; |
|
| 3516 | - } |
|
| 3517 | - else { |
|
| 3518 | - $img_file = $variante_svg_generique; |
|
| 3519 | - } |
|
| 3520 | - } |
|
| 3507 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3508 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3509 | + if ( |
|
| 3510 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3511 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3512 | + and file_exists($variante_svg_generique) |
|
| 3513 | + ) { |
|
| 3514 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3515 | + $img_file = $variante_svg_size; |
|
| 3516 | + } |
|
| 3517 | + else { |
|
| 3518 | + $img_file = $variante_svg_generique; |
|
| 3519 | + } |
|
| 3520 | + } |
|
| 3521 | 3521 | |
| 3522 | - return $img_file; |
|
| 3522 | + return $img_file; |
|
| 3523 | 3523 | } |
| 3524 | 3524 | |
| 3525 | 3525 | /** |
@@ -3540,54 +3540,54 @@ discard block |
||
| 3540 | 3540 | */ |
| 3541 | 3541 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3542 | 3542 | |
| 3543 | - $img_file = $img; |
|
| 3544 | - if ($p = strpos($img_file, '?')) { |
|
| 3545 | - $img_file = substr($img_file, 0, $p); |
|
| 3546 | - } |
|
| 3547 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3548 | - $img_file = chemin_image($img); |
|
| 3549 | - } |
|
| 3550 | - else { |
|
| 3551 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3552 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3553 | - } |
|
| 3554 | - } |
|
| 3555 | - if (stripos($atts, 'width') === false) { |
|
| 3556 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3557 | - if ( |
|
| 3558 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3559 | - or $options['utiliser_suffixe_size'] == true |
|
| 3560 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3561 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3562 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3563 | - ) { |
|
| 3564 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3565 | - } else { |
|
| 3566 | - $taille = taille_image($img_file); |
|
| 3567 | - [$hauteur, $largeur] = $taille; |
|
| 3568 | - if (!$hauteur or !$largeur) { |
|
| 3569 | - return ''; |
|
| 3570 | - } |
|
| 3571 | - } |
|
| 3572 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3573 | - } |
|
| 3574 | - |
|
| 3575 | - if (file_exists($img_file)) { |
|
| 3576 | - $img_file = timestamp($img_file); |
|
| 3577 | - } |
|
| 3578 | - if ($alt === false) { |
|
| 3579 | - $alt = ''; |
|
| 3580 | - } |
|
| 3581 | - elseif ($alt or $alt === '') { |
|
| 3582 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3583 | - } |
|
| 3584 | - else { |
|
| 3585 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3586 | - } |
|
| 3587 | - return "<img src='$img_file'$alt" |
|
| 3588 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3589 | - . ' ' . ltrim($atts) |
|
| 3590 | - . ' />'; |
|
| 3543 | + $img_file = $img; |
|
| 3544 | + if ($p = strpos($img_file, '?')) { |
|
| 3545 | + $img_file = substr($img_file, 0, $p); |
|
| 3546 | + } |
|
| 3547 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3548 | + $img_file = chemin_image($img); |
|
| 3549 | + } |
|
| 3550 | + else { |
|
| 3551 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3552 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3553 | + } |
|
| 3554 | + } |
|
| 3555 | + if (stripos($atts, 'width') === false) { |
|
| 3556 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3557 | + if ( |
|
| 3558 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3559 | + or $options['utiliser_suffixe_size'] == true |
|
| 3560 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3561 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3562 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3563 | + ) { |
|
| 3564 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3565 | + } else { |
|
| 3566 | + $taille = taille_image($img_file); |
|
| 3567 | + [$hauteur, $largeur] = $taille; |
|
| 3568 | + if (!$hauteur or !$largeur) { |
|
| 3569 | + return ''; |
|
| 3570 | + } |
|
| 3571 | + } |
|
| 3572 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3573 | + } |
|
| 3574 | + |
|
| 3575 | + if (file_exists($img_file)) { |
|
| 3576 | + $img_file = timestamp($img_file); |
|
| 3577 | + } |
|
| 3578 | + if ($alt === false) { |
|
| 3579 | + $alt = ''; |
|
| 3580 | + } |
|
| 3581 | + elseif ($alt or $alt === '') { |
|
| 3582 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3583 | + } |
|
| 3584 | + else { |
|
| 3585 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3586 | + } |
|
| 3587 | + return "<img src='$img_file'$alt" |
|
| 3588 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3589 | + . ' ' . ltrim($atts) |
|
| 3590 | + . ' />'; |
|
| 3591 | 3591 | } |
| 3592 | 3592 | |
| 3593 | 3593 | /** |
@@ -3599,70 +3599,70 @@ discard block |
||
| 3599 | 3599 | * @return string |
| 3600 | 3600 | */ |
| 3601 | 3601 | function http_style_background($img, $att = '', $size = null) { |
| 3602 | - if ($size and is_numeric($size)) { |
|
| 3603 | - $size = trim($size) . 'px'; |
|
| 3604 | - } |
|
| 3605 | - return " style='background" . |
|
| 3606 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3607 | - . ($size ? "background-size:{$size};" : '') |
|
| 3608 | - . "'"; |
|
| 3602 | + if ($size and is_numeric($size)) { |
|
| 3603 | + $size = trim($size) . 'px'; |
|
| 3604 | + } |
|
| 3605 | + return " style='background" . |
|
| 3606 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3607 | + . ($size ? "background-size:{$size};" : '') |
|
| 3608 | + . "'"; |
|
| 3609 | 3609 | } |
| 3610 | 3610 | |
| 3611 | 3611 | |
| 3612 | 3612 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3613 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3614 | - while (is_null(end($args)) and count($args)) { |
|
| 3615 | - array_pop($args); |
|
| 3616 | - } |
|
| 3617 | - if (!count($args)) { |
|
| 3618 | - return [null, null, null]; |
|
| 3619 | - } |
|
| 3620 | - if (count($args) < 3) { |
|
| 3621 | - $maybe_size = array_pop($args); |
|
| 3622 | - // @2x |
|
| 3623 | - // @1.5x |
|
| 3624 | - // 512 |
|
| 3625 | - // 512x* |
|
| 3626 | - // 512x300 |
|
| 3627 | - if ( |
|
| 3628 | - !strlen($maybe_size) |
|
| 3629 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3630 | - ) { |
|
| 3631 | - $args[] = $maybe_size; |
|
| 3632 | - $maybe_size = null; |
|
| 3633 | - } |
|
| 3634 | - while (count($args) < 2) { |
|
| 3635 | - $args[] = null; // default alt or class |
|
| 3636 | - } |
|
| 3637 | - $args[] = $maybe_size; |
|
| 3638 | - } |
|
| 3639 | - return $args; |
|
| 3613 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3614 | + while (is_null(end($args)) and count($args)) { |
|
| 3615 | + array_pop($args); |
|
| 3616 | + } |
|
| 3617 | + if (!count($args)) { |
|
| 3618 | + return [null, null, null]; |
|
| 3619 | + } |
|
| 3620 | + if (count($args) < 3) { |
|
| 3621 | + $maybe_size = array_pop($args); |
|
| 3622 | + // @2x |
|
| 3623 | + // @1.5x |
|
| 3624 | + // 512 |
|
| 3625 | + // 512x* |
|
| 3626 | + // 512x300 |
|
| 3627 | + if ( |
|
| 3628 | + !strlen($maybe_size) |
|
| 3629 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3630 | + ) { |
|
| 3631 | + $args[] = $maybe_size; |
|
| 3632 | + $maybe_size = null; |
|
| 3633 | + } |
|
| 3634 | + while (count($args) < 2) { |
|
| 3635 | + $args[] = null; // default alt or class |
|
| 3636 | + } |
|
| 3637 | + $args[] = $maybe_size; |
|
| 3638 | + } |
|
| 3639 | + return $args; |
|
| 3640 | 3640 | } |
| 3641 | 3641 | |
| 3642 | 3642 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3643 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3644 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3645 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3646 | - [$h, $w] = taille_image($img); |
|
| 3647 | - $height = intval(round($h / $coef)); |
|
| 3648 | - $width = intval(round($w / $coef)); |
|
| 3649 | - } |
|
| 3650 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3651 | - else { |
|
| 3652 | - $size = explode('x', $size, 2); |
|
| 3653 | - $size = array_map('trim', $size); |
|
| 3654 | - $height = $width = intval(array_shift($size)); |
|
| 3655 | - |
|
| 3656 | - if (count($size) and reset($size)) { |
|
| 3657 | - $height = array_shift($size); |
|
| 3658 | - if ($height === '*') { |
|
| 3659 | - [$h, $w] = taille_image($img); |
|
| 3660 | - $height = intval(round($h * $width / $w)); |
|
| 3661 | - } |
|
| 3662 | - } |
|
| 3663 | - } |
|
| 3664 | - |
|
| 3665 | - return [$width, $height]; |
|
| 3643 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3644 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3645 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3646 | + [$h, $w] = taille_image($img); |
|
| 3647 | + $height = intval(round($h / $coef)); |
|
| 3648 | + $width = intval(round($w / $coef)); |
|
| 3649 | + } |
|
| 3650 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3651 | + else { |
|
| 3652 | + $size = explode('x', $size, 2); |
|
| 3653 | + $size = array_map('trim', $size); |
|
| 3654 | + $height = $width = intval(array_shift($size)); |
|
| 3655 | + |
|
| 3656 | + if (count($size) and reset($size)) { |
|
| 3657 | + $height = array_shift($size); |
|
| 3658 | + if ($height === '*') { |
|
| 3659 | + [$h, $w] = taille_image($img); |
|
| 3660 | + $height = intval(round($h * $width / $w)); |
|
| 3661 | + } |
|
| 3662 | + } |
|
| 3663 | + } |
|
| 3664 | + |
|
| 3665 | + return [$width, $height]; |
|
| 3666 | 3666 | } |
| 3667 | 3667 | |
| 3668 | 3668 | /** |
@@ -3698,43 +3698,43 @@ discard block |
||
| 3698 | 3698 | */ |
| 3699 | 3699 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3700 | 3700 | |
| 3701 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | - |
|
| 3703 | - $img = trim((string) $img); |
|
| 3704 | - if (strpos($img, '<img') === 0) { |
|
| 3705 | - if (!is_null($alt)) { |
|
| 3706 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3707 | - } |
|
| 3708 | - if (!is_null($class)) { |
|
| 3709 | - if (strlen($class)) { |
|
| 3710 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3711 | - } |
|
| 3712 | - else { |
|
| 3713 | - $img = vider_attribut($img, 'class'); |
|
| 3714 | - } |
|
| 3715 | - } |
|
| 3716 | - } |
|
| 3717 | - else { |
|
| 3718 | - $img = http_img_pack( |
|
| 3719 | - $img, |
|
| 3720 | - $alt, |
|
| 3721 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3722 | - '', |
|
| 3723 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3724 | - ); |
|
| 3725 | - if (is_null($alt)) { |
|
| 3726 | - $img = vider_attribut($img, 'alt'); |
|
| 3727 | - } |
|
| 3728 | - } |
|
| 3729 | - |
|
| 3730 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3731 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3732 | - |
|
| 3733 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3734 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - return $img; |
|
| 3701 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | + |
|
| 3703 | + $img = trim((string) $img); |
|
| 3704 | + if (strpos($img, '<img') === 0) { |
|
| 3705 | + if (!is_null($alt)) { |
|
| 3706 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3707 | + } |
|
| 3708 | + if (!is_null($class)) { |
|
| 3709 | + if (strlen($class)) { |
|
| 3710 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3711 | + } |
|
| 3712 | + else { |
|
| 3713 | + $img = vider_attribut($img, 'class'); |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + } |
|
| 3717 | + else { |
|
| 3718 | + $img = http_img_pack( |
|
| 3719 | + $img, |
|
| 3720 | + $alt, |
|
| 3721 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3722 | + '', |
|
| 3723 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3724 | + ); |
|
| 3725 | + if (is_null($alt)) { |
|
| 3726 | + $img = vider_attribut($img, 'alt'); |
|
| 3727 | + } |
|
| 3728 | + } |
|
| 3729 | + |
|
| 3730 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3731 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3732 | + |
|
| 3733 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3734 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + return $img; |
|
| 3738 | 3738 | } |
| 3739 | 3739 | |
| 3740 | 3740 | |
@@ -3768,80 +3768,80 @@ discard block |
||
| 3768 | 3768 | */ |
| 3769 | 3769 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3770 | 3770 | |
| 3771 | - $svg = null; |
|
| 3772 | - $img = trim($img); |
|
| 3773 | - $img_file = $img; |
|
| 3774 | - if (strpos($img, '<svg') === false) { |
|
| 3775 | - if ($p = strpos($img_file, '?')) { |
|
| 3776 | - $img_file = substr($img_file, 0, $p); |
|
| 3777 | - } |
|
| 3778 | - |
|
| 3779 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3780 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3781 | - if (tester_url_absolue($img_file)) { |
|
| 3782 | - include_spip('inc/distant'); |
|
| 3783 | - $fichier = copie_locale($img_file); |
|
| 3784 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3785 | - } |
|
| 3786 | - |
|
| 3787 | - if ( |
|
| 3788 | - !$img_file |
|
| 3789 | - or !file_exists($img_file) |
|
| 3790 | - or !$svg = file_get_contents($img_file) |
|
| 3791 | - ) { |
|
| 3792 | - return ''; |
|
| 3793 | - } |
|
| 3794 | - } |
|
| 3795 | - |
|
| 3796 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3797 | - return ''; |
|
| 3798 | - } |
|
| 3799 | - |
|
| 3800 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3801 | - |
|
| 3802 | - $balise_svg = $match[0]; |
|
| 3803 | - $balise_svg_source = $balise_svg; |
|
| 3804 | - |
|
| 3805 | - // entete XML à supprimer |
|
| 3806 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3807 | - |
|
| 3808 | - // IE est toujours mon ami |
|
| 3809 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3810 | - |
|
| 3811 | - // regler la classe |
|
| 3812 | - if (!is_null($class)) { |
|
| 3813 | - if (strlen($class)) { |
|
| 3814 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3815 | - } |
|
| 3816 | - else { |
|
| 3817 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3818 | - } |
|
| 3819 | - } |
|
| 3820 | - |
|
| 3821 | - // regler le alt |
|
| 3822 | - if ($alt) { |
|
| 3823 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3824 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3825 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3826 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3827 | - $balise_svg .= $title; |
|
| 3828 | - } |
|
| 3829 | - else { |
|
| 3830 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3831 | - } |
|
| 3832 | - |
|
| 3833 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3834 | - |
|
| 3835 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3836 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3837 | - |
|
| 3838 | - if (!function_exists('svg_redimensionner')) { |
|
| 3839 | - include_spip('inc/svg'); |
|
| 3840 | - } |
|
| 3841 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3842 | - } |
|
| 3843 | - |
|
| 3844 | - return $svg; |
|
| 3771 | + $svg = null; |
|
| 3772 | + $img = trim($img); |
|
| 3773 | + $img_file = $img; |
|
| 3774 | + if (strpos($img, '<svg') === false) { |
|
| 3775 | + if ($p = strpos($img_file, '?')) { |
|
| 3776 | + $img_file = substr($img_file, 0, $p); |
|
| 3777 | + } |
|
| 3778 | + |
|
| 3779 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3780 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3781 | + if (tester_url_absolue($img_file)) { |
|
| 3782 | + include_spip('inc/distant'); |
|
| 3783 | + $fichier = copie_locale($img_file); |
|
| 3784 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3785 | + } |
|
| 3786 | + |
|
| 3787 | + if ( |
|
| 3788 | + !$img_file |
|
| 3789 | + or !file_exists($img_file) |
|
| 3790 | + or !$svg = file_get_contents($img_file) |
|
| 3791 | + ) { |
|
| 3792 | + return ''; |
|
| 3793 | + } |
|
| 3794 | + } |
|
| 3795 | + |
|
| 3796 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3797 | + return ''; |
|
| 3798 | + } |
|
| 3799 | + |
|
| 3800 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3801 | + |
|
| 3802 | + $balise_svg = $match[0]; |
|
| 3803 | + $balise_svg_source = $balise_svg; |
|
| 3804 | + |
|
| 3805 | + // entete XML à supprimer |
|
| 3806 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3807 | + |
|
| 3808 | + // IE est toujours mon ami |
|
| 3809 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3810 | + |
|
| 3811 | + // regler la classe |
|
| 3812 | + if (!is_null($class)) { |
|
| 3813 | + if (strlen($class)) { |
|
| 3814 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3815 | + } |
|
| 3816 | + else { |
|
| 3817 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3818 | + } |
|
| 3819 | + } |
|
| 3820 | + |
|
| 3821 | + // regler le alt |
|
| 3822 | + if ($alt) { |
|
| 3823 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3824 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3825 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3826 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3827 | + $balise_svg .= $title; |
|
| 3828 | + } |
|
| 3829 | + else { |
|
| 3830 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3831 | + } |
|
| 3832 | + |
|
| 3833 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3834 | + |
|
| 3835 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3836 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3837 | + |
|
| 3838 | + if (!function_exists('svg_redimensionner')) { |
|
| 3839 | + include_spip('inc/svg'); |
|
| 3840 | + } |
|
| 3841 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3842 | + } |
|
| 3843 | + |
|
| 3844 | + return $svg; |
|
| 3845 | 3845 | } |
| 3846 | 3846 | |
| 3847 | 3847 | |
@@ -3867,18 +3867,18 @@ discard block |
||
| 3867 | 3867 | * Code HTML résultant |
| 3868 | 3868 | **/ |
| 3869 | 3869 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3870 | - $texte = ''; |
|
| 3871 | - if (is_array($tableau)) { |
|
| 3872 | - foreach ($tableau as $k => $v) { |
|
| 3873 | - $res = recuperer_fond( |
|
| 3874 | - 'modeles/' . $modele, |
|
| 3875 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3876 | - ); |
|
| 3877 | - $texte .= $res; |
|
| 3878 | - } |
|
| 3879 | - } |
|
| 3870 | + $texte = ''; |
|
| 3871 | + if (is_array($tableau)) { |
|
| 3872 | + foreach ($tableau as $k => $v) { |
|
| 3873 | + $res = recuperer_fond( |
|
| 3874 | + 'modeles/' . $modele, |
|
| 3875 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3876 | + ); |
|
| 3877 | + $texte .= $res; |
|
| 3878 | + } |
|
| 3879 | + } |
|
| 3880 | 3880 | |
| 3881 | - return $texte; |
|
| 3881 | + return $texte; |
|
| 3882 | 3882 | } |
| 3883 | 3883 | |
| 3884 | 3884 | |
@@ -3903,37 +3903,37 @@ discard block |
||
| 3903 | 3903 | * - tout : retourne toutes les informations du plugin actif |
| 3904 | 3904 | **/ |
| 3905 | 3905 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3906 | - include_spip('inc/plugin'); |
|
| 3907 | - $plugin = strtoupper($plugin); |
|
| 3908 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3909 | - |
|
| 3910 | - if (!$plugin) { |
|
| 3911 | - return serialize(array_keys($plugins_actifs)); |
|
| 3912 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3913 | - return ''; |
|
| 3914 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3915 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3916 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3917 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3918 | - } else { |
|
| 3919 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3920 | - // On prend en compte les extensions |
|
| 3921 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3922 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3923 | - } else { |
|
| 3924 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3925 | - } |
|
| 3926 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3927 | - return ''; |
|
| 3928 | - } |
|
| 3929 | - if ($type_info == 'tout') { |
|
| 3930 | - return $infos; |
|
| 3931 | - } elseif ($type_info == 'est_actif') { |
|
| 3932 | - return $infos ? 1 : 0; |
|
| 3933 | - } else { |
|
| 3934 | - return strval($infos[$type_info]); |
|
| 3935 | - } |
|
| 3936 | - } |
|
| 3906 | + include_spip('inc/plugin'); |
|
| 3907 | + $plugin = strtoupper($plugin); |
|
| 3908 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3909 | + |
|
| 3910 | + if (!$plugin) { |
|
| 3911 | + return serialize(array_keys($plugins_actifs)); |
|
| 3912 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3913 | + return ''; |
|
| 3914 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3915 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3916 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3917 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3918 | + } else { |
|
| 3919 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3920 | + // On prend en compte les extensions |
|
| 3921 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3922 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3923 | + } else { |
|
| 3924 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3925 | + } |
|
| 3926 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3927 | + return ''; |
|
| 3928 | + } |
|
| 3929 | + if ($type_info == 'tout') { |
|
| 3930 | + return $infos; |
|
| 3931 | + } elseif ($type_info == 'est_actif') { |
|
| 3932 | + return $infos ? 1 : 0; |
|
| 3933 | + } else { |
|
| 3934 | + return strval($infos[$type_info]); |
|
| 3935 | + } |
|
| 3936 | + } |
|
| 3937 | 3937 | } |
| 3938 | 3938 | |
| 3939 | 3939 | |
@@ -3960,9 +3960,9 @@ discard block |
||
| 3960 | 3960 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3961 | 3961 | */ |
| 3962 | 3962 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3963 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3963 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3964 | 3964 | |
| 3965 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3965 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3966 | 3966 | } |
| 3967 | 3967 | |
| 3968 | 3968 | |
@@ -3992,19 +3992,19 @@ discard block |
||
| 3992 | 3992 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3993 | 3993 | */ |
| 3994 | 3994 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3995 | - static $puce_statut = null; |
|
| 3996 | - if (!$puce_statut) { |
|
| 3997 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3998 | - } |
|
| 3995 | + static $puce_statut = null; |
|
| 3996 | + if (!$puce_statut) { |
|
| 3997 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3998 | + } |
|
| 3999 | 3999 | |
| 4000 | - return $puce_statut( |
|
| 4001 | - $id_objet, |
|
| 4002 | - $statut, |
|
| 4003 | - $id_parent, |
|
| 4004 | - $objet, |
|
| 4005 | - false, |
|
| 4006 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4007 | - ); |
|
| 4000 | + return $puce_statut( |
|
| 4001 | + $id_objet, |
|
| 4002 | + $statut, |
|
| 4003 | + $id_parent, |
|
| 4004 | + $objet, |
|
| 4005 | + false, |
|
| 4006 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4007 | + ); |
|
| 4008 | 4008 | } |
| 4009 | 4009 | |
| 4010 | 4010 | |
@@ -4031,98 +4031,98 @@ discard block |
||
| 4031 | 4031 | * hash du contexte |
| 4032 | 4032 | */ |
| 4033 | 4033 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 4034 | - $env = null; |
|
| 4035 | - if ( |
|
| 4036 | - is_string($c) |
|
| 4037 | - and @unserialize($c) !== false |
|
| 4038 | - ) { |
|
| 4039 | - $c = unserialize($c); |
|
| 4040 | - } |
|
| 4041 | - |
|
| 4042 | - // supprimer les parametres debut_x |
|
| 4043 | - // pour que la pagination ajax ne soit pas plantee |
|
| 4044 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4045 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4046 | - if (is_array($c)) { |
|
| 4047 | - foreach ($c as $k => $v) { |
|
| 4048 | - if (strpos($k, 'debut_') === 0) { |
|
| 4049 | - unset($c[$k]); |
|
| 4050 | - } |
|
| 4051 | - } |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - if (!function_exists('calculer_cle_action')) { |
|
| 4055 | - include_spip('inc/securiser_action'); |
|
| 4056 | - } |
|
| 4057 | - |
|
| 4058 | - $c = serialize($c); |
|
| 4059 | - $cle = calculer_cle_action($form . $c); |
|
| 4060 | - $c = "$cle:$c"; |
|
| 4061 | - |
|
| 4062 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4063 | - // par defaut, sauf si cette configuration a été forcée |
|
| 4064 | - // OU que la longueur de l’argument géneré est plus long |
|
| 4065 | - // que ce qui est toléré. |
|
| 4066 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4067 | - if (!$cache_contextes_ajax) { |
|
| 4068 | - $env = $c; |
|
| 4069 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4070 | - $env = gzdeflate($env); |
|
| 4071 | - } |
|
| 4072 | - $env = _xor($env); |
|
| 4073 | - $env = base64_encode($env); |
|
| 4074 | - $len = strlen($env); |
|
| 4075 | - // Si l’url est trop longue pour le navigateur |
|
| 4076 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4077 | - if ($len > $max_len) { |
|
| 4078 | - $cache_contextes_ajax = true; |
|
| 4079 | - spip_log( |
|
| 4080 | - 'Contextes AJAX forces en fichiers !' |
|
| 4081 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4082 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4083 | - _LOG_AVERTISSEMENT |
|
| 4084 | - ); |
|
| 4085 | - } |
|
| 4086 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4087 | - elseif ( |
|
| 4088 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4089 | - and $max_len < $len |
|
| 4090 | - ) { |
|
| 4091 | - $cache_contextes_ajax = true; |
|
| 4092 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4093 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4094 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4095 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4096 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4097 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4098 | - } |
|
| 4099 | - } |
|
| 4100 | - |
|
| 4101 | - if ($cache_contextes_ajax) { |
|
| 4102 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4103 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4104 | - $md5 = md5($c); |
|
| 4105 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4106 | - $env = $md5; |
|
| 4107 | - } |
|
| 4108 | - |
|
| 4109 | - if ($emboite === null) { |
|
| 4110 | - return $env; |
|
| 4111 | - } |
|
| 4112 | - if (!trim($emboite)) { |
|
| 4113 | - return ''; |
|
| 4114 | - } |
|
| 4115 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4116 | - $r = self(); |
|
| 4117 | - $r = ' data-origin="' . $r . '"'; |
|
| 4118 | - $class = 'ajaxbloc'; |
|
| 4119 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4120 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4121 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4122 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4123 | - } |
|
| 4124 | - |
|
| 4125 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4034 | + $env = null; |
|
| 4035 | + if ( |
|
| 4036 | + is_string($c) |
|
| 4037 | + and @unserialize($c) !== false |
|
| 4038 | + ) { |
|
| 4039 | + $c = unserialize($c); |
|
| 4040 | + } |
|
| 4041 | + |
|
| 4042 | + // supprimer les parametres debut_x |
|
| 4043 | + // pour que la pagination ajax ne soit pas plantee |
|
| 4044 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4045 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4046 | + if (is_array($c)) { |
|
| 4047 | + foreach ($c as $k => $v) { |
|
| 4048 | + if (strpos($k, 'debut_') === 0) { |
|
| 4049 | + unset($c[$k]); |
|
| 4050 | + } |
|
| 4051 | + } |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + if (!function_exists('calculer_cle_action')) { |
|
| 4055 | + include_spip('inc/securiser_action'); |
|
| 4056 | + } |
|
| 4057 | + |
|
| 4058 | + $c = serialize($c); |
|
| 4059 | + $cle = calculer_cle_action($form . $c); |
|
| 4060 | + $c = "$cle:$c"; |
|
| 4061 | + |
|
| 4062 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4063 | + // par defaut, sauf si cette configuration a été forcée |
|
| 4064 | + // OU que la longueur de l’argument géneré est plus long |
|
| 4065 | + // que ce qui est toléré. |
|
| 4066 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4067 | + if (!$cache_contextes_ajax) { |
|
| 4068 | + $env = $c; |
|
| 4069 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4070 | + $env = gzdeflate($env); |
|
| 4071 | + } |
|
| 4072 | + $env = _xor($env); |
|
| 4073 | + $env = base64_encode($env); |
|
| 4074 | + $len = strlen($env); |
|
| 4075 | + // Si l’url est trop longue pour le navigateur |
|
| 4076 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4077 | + if ($len > $max_len) { |
|
| 4078 | + $cache_contextes_ajax = true; |
|
| 4079 | + spip_log( |
|
| 4080 | + 'Contextes AJAX forces en fichiers !' |
|
| 4081 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4082 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4083 | + _LOG_AVERTISSEMENT |
|
| 4084 | + ); |
|
| 4085 | + } |
|
| 4086 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4087 | + elseif ( |
|
| 4088 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4089 | + and $max_len < $len |
|
| 4090 | + ) { |
|
| 4091 | + $cache_contextes_ajax = true; |
|
| 4092 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4093 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4094 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4095 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4096 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4097 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4098 | + } |
|
| 4099 | + } |
|
| 4100 | + |
|
| 4101 | + if ($cache_contextes_ajax) { |
|
| 4102 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4103 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4104 | + $md5 = md5($c); |
|
| 4105 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4106 | + $env = $md5; |
|
| 4107 | + } |
|
| 4108 | + |
|
| 4109 | + if ($emboite === null) { |
|
| 4110 | + return $env; |
|
| 4111 | + } |
|
| 4112 | + if (!trim($emboite)) { |
|
| 4113 | + return ''; |
|
| 4114 | + } |
|
| 4115 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4116 | + $r = self(); |
|
| 4117 | + $r = ' data-origin="' . $r . '"'; |
|
| 4118 | + $class = 'ajaxbloc'; |
|
| 4119 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4120 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4121 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4122 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4123 | + } |
|
| 4124 | + |
|
| 4125 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4126 | 4126 | } |
| 4127 | 4127 | |
| 4128 | 4128 | /** |
@@ -4142,37 +4142,37 @@ discard block |
||
| 4142 | 4142 | * - false : erreur de décodage |
| 4143 | 4143 | */ |
| 4144 | 4144 | function decoder_contexte_ajax($c, $form = '') { |
| 4145 | - if (!function_exists('calculer_cle_action')) { |
|
| 4146 | - include_spip('inc/securiser_action'); |
|
| 4147 | - } |
|
| 4148 | - if ( |
|
| 4149 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4150 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4151 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4152 | - ) { |
|
| 4153 | - $c = $contexte; |
|
| 4154 | - } else { |
|
| 4155 | - $c = @base64_decode($c); |
|
| 4156 | - $c = _xor($c); |
|
| 4157 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4158 | - $c = @gzinflate($c); |
|
| 4159 | - } |
|
| 4160 | - } |
|
| 4161 | - |
|
| 4162 | - // extraire la signature en debut de contexte |
|
| 4163 | - // et la verifier avant de deserializer |
|
| 4164 | - // format : signature:donneesserializees |
|
| 4165 | - if ($p = strpos($c, ':')) { |
|
| 4166 | - $cle = substr($c, 0, $p); |
|
| 4167 | - $c = substr($c, $p + 1); |
|
| 4168 | - |
|
| 4169 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4170 | - $env = @unserialize($c); |
|
| 4171 | - return $env; |
|
| 4172 | - } |
|
| 4173 | - } |
|
| 4174 | - |
|
| 4175 | - return false; |
|
| 4145 | + if (!function_exists('calculer_cle_action')) { |
|
| 4146 | + include_spip('inc/securiser_action'); |
|
| 4147 | + } |
|
| 4148 | + if ( |
|
| 4149 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4150 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4151 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4152 | + ) { |
|
| 4153 | + $c = $contexte; |
|
| 4154 | + } else { |
|
| 4155 | + $c = @base64_decode($c); |
|
| 4156 | + $c = _xor($c); |
|
| 4157 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4158 | + $c = @gzinflate($c); |
|
| 4159 | + } |
|
| 4160 | + } |
|
| 4161 | + |
|
| 4162 | + // extraire la signature en debut de contexte |
|
| 4163 | + // et la verifier avant de deserializer |
|
| 4164 | + // format : signature:donneesserializees |
|
| 4165 | + if ($p = strpos($c, ':')) { |
|
| 4166 | + $cle = substr($c, 0, $p); |
|
| 4167 | + $c = substr($c, $p + 1); |
|
| 4168 | + |
|
| 4169 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4170 | + $env = @unserialize($c); |
|
| 4171 | + return $env; |
|
| 4172 | + } |
|
| 4173 | + } |
|
| 4174 | + |
|
| 4175 | + return false; |
|
| 4176 | 4176 | } |
| 4177 | 4177 | |
| 4178 | 4178 | |
@@ -4190,20 +4190,20 @@ discard block |
||
| 4190 | 4190 | * Message décrypté ou encrypté |
| 4191 | 4191 | **/ |
| 4192 | 4192 | function _xor($message, $key = null) { |
| 4193 | - if (is_null($key)) { |
|
| 4194 | - if (!function_exists('calculer_cle_action')) { |
|
| 4195 | - include_spip('inc/securiser_action'); |
|
| 4196 | - } |
|
| 4197 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4198 | - } |
|
| 4193 | + if (is_null($key)) { |
|
| 4194 | + if (!function_exists('calculer_cle_action')) { |
|
| 4195 | + include_spip('inc/securiser_action'); |
|
| 4196 | + } |
|
| 4197 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4198 | + } |
|
| 4199 | 4199 | |
| 4200 | - $keylen = strlen($key); |
|
| 4201 | - $messagelen = strlen($message); |
|
| 4202 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4203 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4204 | - } |
|
| 4200 | + $keylen = strlen($key); |
|
| 4201 | + $messagelen = strlen($message); |
|
| 4202 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4203 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4204 | + } |
|
| 4205 | 4205 | |
| 4206 | - return $message; |
|
| 4206 | + return $message; |
|
| 4207 | 4207 | } |
| 4208 | 4208 | |
| 4209 | 4209 | /** |
@@ -4217,7 +4217,7 @@ discard block |
||
| 4217 | 4217 | * @return string |
| 4218 | 4218 | */ |
| 4219 | 4219 | function url_reponse_forum($texte) { |
| 4220 | - return $texte; |
|
| 4220 | + return $texte; |
|
| 4221 | 4221 | } |
| 4222 | 4222 | |
| 4223 | 4223 | /** |
@@ -4231,7 +4231,7 @@ discard block |
||
| 4231 | 4231 | * @return string |
| 4232 | 4232 | */ |
| 4233 | 4233 | function url_rss_forum($texte) { |
| 4234 | - return $texte; |
|
| 4234 | + return $texte; |
|
| 4235 | 4235 | } |
| 4236 | 4236 | |
| 4237 | 4237 | |
@@ -4270,37 +4270,37 @@ discard block |
||
| 4270 | 4270 | * Code HTML |
| 4271 | 4271 | */ |
| 4272 | 4272 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4273 | - if ($on) { |
|
| 4274 | - $bal = 'strong'; |
|
| 4275 | - $class = ''; |
|
| 4276 | - $att = ''; |
|
| 4277 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4278 | - // a.active span.selected.active etc.... |
|
| 4279 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4280 | - $on = explode('.', $on); |
|
| 4281 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4282 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4283 | - $bal = array_shift($on); |
|
| 4284 | - $class = implode(' ', $on); |
|
| 4285 | - if ($bal == 'a') { |
|
| 4286 | - $att = 'href="#" '; |
|
| 4287 | - } |
|
| 4288 | - } |
|
| 4289 | - } |
|
| 4290 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4291 | - } else { |
|
| 4292 | - $bal = 'a'; |
|
| 4293 | - $att = "href='$url'" |
|
| 4294 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4295 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4296 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4297 | - . $evt; |
|
| 4298 | - } |
|
| 4299 | - if ($libelle === null) { |
|
| 4300 | - $libelle = $url; |
|
| 4301 | - } |
|
| 4302 | - |
|
| 4303 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4273 | + if ($on) { |
|
| 4274 | + $bal = 'strong'; |
|
| 4275 | + $class = ''; |
|
| 4276 | + $att = ''; |
|
| 4277 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4278 | + // a.active span.selected.active etc.... |
|
| 4279 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4280 | + $on = explode('.', $on); |
|
| 4281 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4282 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4283 | + $bal = array_shift($on); |
|
| 4284 | + $class = implode(' ', $on); |
|
| 4285 | + if ($bal == 'a') { |
|
| 4286 | + $att = 'href="#" '; |
|
| 4287 | + } |
|
| 4288 | + } |
|
| 4289 | + } |
|
| 4290 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4291 | + } else { |
|
| 4292 | + $bal = 'a'; |
|
| 4293 | + $att = "href='$url'" |
|
| 4294 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4295 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4296 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4297 | + . $evt; |
|
| 4298 | + } |
|
| 4299 | + if ($libelle === null) { |
|
| 4300 | + $libelle = $url; |
|
| 4301 | + } |
|
| 4302 | + |
|
| 4303 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4304 | 4304 | } |
| 4305 | 4305 | |
| 4306 | 4306 | |
@@ -4317,39 +4317,39 @@ discard block |
||
| 4317 | 4317 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4318 | 4318 | */ |
| 4319 | 4319 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4320 | - static $local_singulier_ou_pluriel = []; |
|
| 4321 | - |
|
| 4322 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4323 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4324 | - return ''; |
|
| 4325 | - } |
|
| 4326 | - if (!is_array($vars)) { |
|
| 4327 | - return ''; |
|
| 4328 | - } |
|
| 4329 | - |
|
| 4330 | - $langue = $GLOBALS['spip_lang']; |
|
| 4331 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4332 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4333 | - if ( |
|
| 4334 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4335 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4336 | - ) { |
|
| 4337 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4338 | - } |
|
| 4339 | - } |
|
| 4340 | - |
|
| 4341 | - // si on a une surcharge on l'utilise |
|
| 4342 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4343 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4344 | - } |
|
| 4345 | - |
|
| 4346 | - // sinon traitement par defaut |
|
| 4347 | - $vars[$var] = $nb; |
|
| 4348 | - if ($nb >= 2) { |
|
| 4349 | - return _T($chaine_plusieurs, $vars); |
|
| 4350 | - } else { |
|
| 4351 | - return _T($chaine_un, $vars); |
|
| 4352 | - } |
|
| 4320 | + static $local_singulier_ou_pluriel = []; |
|
| 4321 | + |
|
| 4322 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4323 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4324 | + return ''; |
|
| 4325 | + } |
|
| 4326 | + if (!is_array($vars)) { |
|
| 4327 | + return ''; |
|
| 4328 | + } |
|
| 4329 | + |
|
| 4330 | + $langue = $GLOBALS['spip_lang']; |
|
| 4331 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4332 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4333 | + if ( |
|
| 4334 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4335 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4336 | + ) { |
|
| 4337 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4338 | + } |
|
| 4339 | + } |
|
| 4340 | + |
|
| 4341 | + // si on a une surcharge on l'utilise |
|
| 4342 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4343 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4344 | + } |
|
| 4345 | + |
|
| 4346 | + // sinon traitement par defaut |
|
| 4347 | + $vars[$var] = $nb; |
|
| 4348 | + if ($nb >= 2) { |
|
| 4349 | + return _T($chaine_plusieurs, $vars); |
|
| 4350 | + } else { |
|
| 4351 | + return _T($chaine_un, $vars); |
|
| 4352 | + } |
|
| 4353 | 4353 | } |
| 4354 | 4354 | |
| 4355 | 4355 | |
@@ -4377,73 +4377,73 @@ discard block |
||
| 4377 | 4377 | */ |
| 4378 | 4378 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4379 | 4379 | |
| 4380 | - $class_lien = $class_bouton = $class; |
|
| 4381 | - |
|
| 4382 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4383 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4384 | - $class_lien .= ' danger'; |
|
| 4385 | - $class_bouton .= ' btn_danger'; |
|
| 4386 | - } elseif ($fonction == 'rien.gif') { |
|
| 4387 | - $fonction = ''; |
|
| 4388 | - } elseif ($fonction == 'delsafe') { |
|
| 4389 | - $fonction = 'del'; |
|
| 4390 | - } |
|
| 4391 | - |
|
| 4392 | - $fond_origine = $fond; |
|
| 4393 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4394 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4395 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4396 | - } |
|
| 4397 | - |
|
| 4398 | - // Ajouter le type d'objet dans la classe |
|
| 4399 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4400 | - $class_lien .= " $objet_type"; |
|
| 4401 | - $class_bouton .= " $objet_type"; |
|
| 4402 | - |
|
| 4403 | - // Texte |
|
| 4404 | - $alt = attribut_html($texte); |
|
| 4405 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4406 | - |
|
| 4407 | - // Liens : préparer les classes ajax |
|
| 4408 | - $ajax = ''; |
|
| 4409 | - if ($type === 'lien') { |
|
| 4410 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4411 | - $ajax = 'ajax'; |
|
| 4412 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4413 | - $ajax .= ' preload'; |
|
| 4414 | - } |
|
| 4415 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4416 | - $ajax .= ' nocache'; |
|
| 4417 | - } |
|
| 4418 | - $ajax = " class='$ajax'"; |
|
| 4419 | - } |
|
| 4420 | - } |
|
| 4421 | - |
|
| 4422 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4423 | - $size = 24; |
|
| 4424 | - if ( |
|
| 4425 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4426 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4427 | - ) { |
|
| 4428 | - $size = $match[1]; |
|
| 4429 | - } |
|
| 4430 | - $class_lien .= " s$size"; |
|
| 4431 | - $class_bouton .= " s$size"; |
|
| 4432 | - |
|
| 4433 | - // Icône |
|
| 4434 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4435 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4436 | - |
|
| 4437 | - // Markup final |
|
| 4438 | - if ($type == 'lien') { |
|
| 4439 | - return "<span class='icone $class_lien'>" |
|
| 4440 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4441 | - . $icone |
|
| 4442 | - . "<b>$texte</b>" |
|
| 4443 | - . "</a></span>\n"; |
|
| 4444 | - } else { |
|
| 4445 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4446 | - } |
|
| 4380 | + $class_lien = $class_bouton = $class; |
|
| 4381 | + |
|
| 4382 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4383 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4384 | + $class_lien .= ' danger'; |
|
| 4385 | + $class_bouton .= ' btn_danger'; |
|
| 4386 | + } elseif ($fonction == 'rien.gif') { |
|
| 4387 | + $fonction = ''; |
|
| 4388 | + } elseif ($fonction == 'delsafe') { |
|
| 4389 | + $fonction = 'del'; |
|
| 4390 | + } |
|
| 4391 | + |
|
| 4392 | + $fond_origine = $fond; |
|
| 4393 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4394 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4395 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4396 | + } |
|
| 4397 | + |
|
| 4398 | + // Ajouter le type d'objet dans la classe |
|
| 4399 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4400 | + $class_lien .= " $objet_type"; |
|
| 4401 | + $class_bouton .= " $objet_type"; |
|
| 4402 | + |
|
| 4403 | + // Texte |
|
| 4404 | + $alt = attribut_html($texte); |
|
| 4405 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4406 | + |
|
| 4407 | + // Liens : préparer les classes ajax |
|
| 4408 | + $ajax = ''; |
|
| 4409 | + if ($type === 'lien') { |
|
| 4410 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4411 | + $ajax = 'ajax'; |
|
| 4412 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4413 | + $ajax .= ' preload'; |
|
| 4414 | + } |
|
| 4415 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4416 | + $ajax .= ' nocache'; |
|
| 4417 | + } |
|
| 4418 | + $ajax = " class='$ajax'"; |
|
| 4419 | + } |
|
| 4420 | + } |
|
| 4421 | + |
|
| 4422 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4423 | + $size = 24; |
|
| 4424 | + if ( |
|
| 4425 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4426 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4427 | + ) { |
|
| 4428 | + $size = $match[1]; |
|
| 4429 | + } |
|
| 4430 | + $class_lien .= " s$size"; |
|
| 4431 | + $class_bouton .= " s$size"; |
|
| 4432 | + |
|
| 4433 | + // Icône |
|
| 4434 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4435 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4436 | + |
|
| 4437 | + // Markup final |
|
| 4438 | + if ($type == 'lien') { |
|
| 4439 | + return "<span class='icone $class_lien'>" |
|
| 4440 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4441 | + . $icone |
|
| 4442 | + . "<b>$texte</b>" |
|
| 4443 | + . "</a></span>\n"; |
|
| 4444 | + } else { |
|
| 4445 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4446 | + } |
|
| 4447 | 4447 | } |
| 4448 | 4448 | |
| 4449 | 4449 | /** |
@@ -4467,7 +4467,7 @@ discard block |
||
| 4467 | 4467 | * Code HTML du lien |
| 4468 | 4468 | **/ |
| 4469 | 4469 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4470 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4470 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4471 | 4471 | } |
| 4472 | 4472 | |
| 4473 | 4473 | /** |
@@ -4502,7 +4502,7 @@ discard block |
||
| 4502 | 4502 | * Code HTML du lien |
| 4503 | 4503 | **/ |
| 4504 | 4504 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4505 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4505 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4506 | 4506 | } |
| 4507 | 4507 | |
| 4508 | 4508 | /** |
@@ -4547,7 +4547,7 @@ discard block |
||
| 4547 | 4547 | * Code HTML du lien |
| 4548 | 4548 | **/ |
| 4549 | 4549 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4550 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4550 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4551 | 4551 | } |
| 4552 | 4552 | |
| 4553 | 4553 | /** |
@@ -4578,7 +4578,7 @@ discard block |
||
| 4578 | 4578 | * Code HTML du lien |
| 4579 | 4579 | **/ |
| 4580 | 4580 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4581 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4581 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4582 | 4582 | } |
| 4583 | 4583 | |
| 4584 | 4584 | /** |
@@ -4609,7 +4609,7 @@ discard block |
||
| 4609 | 4609 | * Code HTML du lien |
| 4610 | 4610 | */ |
| 4611 | 4611 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4612 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4612 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4613 | 4613 | } |
| 4614 | 4614 | |
| 4615 | 4615 | |
@@ -4631,7 +4631,7 @@ discard block |
||
| 4631 | 4631 | * @return array Liste des éléments |
| 4632 | 4632 | */ |
| 4633 | 4633 | function filtre_explode_dist($a, $b) { |
| 4634 | - return explode($b, (string) $a); |
|
| 4634 | + return explode($b, (string) $a); |
|
| 4635 | 4635 | } |
| 4636 | 4636 | |
| 4637 | 4637 | /** |
@@ -4652,7 +4652,7 @@ discard block |
||
| 4652 | 4652 | * @return string Texte |
| 4653 | 4653 | */ |
| 4654 | 4654 | function filtre_implode_dist($a, $b) { |
| 4655 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4655 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4656 | 4656 | } |
| 4657 | 4657 | |
| 4658 | 4658 | /** |
@@ -4661,24 +4661,24 @@ discard block |
||
| 4661 | 4661 | * @return string Code CSS |
| 4662 | 4662 | */ |
| 4663 | 4663 | function bando_images_background() { |
| 4664 | - include_spip('inc/bandeau'); |
|
| 4665 | - // recuperer tous les boutons et leurs images |
|
| 4666 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4664 | + include_spip('inc/bandeau'); |
|
| 4665 | + // recuperer tous les boutons et leurs images |
|
| 4666 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4667 | 4667 | |
| 4668 | - $res = ''; |
|
| 4669 | - foreach ($boutons as $page => $detail) { |
|
| 4670 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4671 | - if (is_array($detail->sousmenu)) { |
|
| 4672 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4673 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4674 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4675 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4676 | - } |
|
| 4677 | - } |
|
| 4678 | - } |
|
| 4679 | - } |
|
| 4668 | + $res = ''; |
|
| 4669 | + foreach ($boutons as $page => $detail) { |
|
| 4670 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4671 | + if (is_array($detail->sousmenu)) { |
|
| 4672 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4673 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4674 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4675 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4676 | + } |
|
| 4677 | + } |
|
| 4678 | + } |
|
| 4679 | + } |
|
| 4680 | 4680 | |
| 4681 | - return $res; |
|
| 4681 | + return $res; |
|
| 4682 | 4682 | } |
| 4683 | 4683 | |
| 4684 | 4684 | /** |
@@ -4703,27 +4703,27 @@ discard block |
||
| 4703 | 4703 | */ |
| 4704 | 4704 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4705 | 4705 | |
| 4706 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4707 | - $class_form = ''; |
|
| 4708 | - if (strpos($class, 'ajax') !== false) { |
|
| 4709 | - $class_form = 'ajax'; |
|
| 4710 | - $class = str_replace('ajax', '', $class); |
|
| 4711 | - } |
|
| 4712 | - $class_btn = 'submit ' . trim($class); |
|
| 4706 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4707 | + $class_form = ''; |
|
| 4708 | + if (strpos($class, 'ajax') !== false) { |
|
| 4709 | + $class_form = 'ajax'; |
|
| 4710 | + $class = str_replace('ajax', '', $class); |
|
| 4711 | + } |
|
| 4712 | + $class_btn = 'submit ' . trim($class); |
|
| 4713 | 4713 | |
| 4714 | - if ($confirm) { |
|
| 4715 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4716 | - if ($callback) { |
|
| 4717 | - $callback = "$confirm?($callback):false"; |
|
| 4718 | - } else { |
|
| 4719 | - $callback = $confirm; |
|
| 4720 | - } |
|
| 4721 | - } |
|
| 4722 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4723 | - $title = $title ? " title='$title'" : ''; |
|
| 4714 | + if ($confirm) { |
|
| 4715 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4716 | + if ($callback) { |
|
| 4717 | + $callback = "$confirm?($callback):false"; |
|
| 4718 | + } else { |
|
| 4719 | + $callback = $confirm; |
|
| 4720 | + } |
|
| 4721 | + } |
|
| 4722 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4723 | + $title = $title ? " title='$title'" : ''; |
|
| 4724 | 4724 | |
| 4725 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4726 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4725 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4726 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4727 | 4727 | } |
| 4728 | 4728 | |
| 4729 | 4729 | /** |
@@ -4746,101 +4746,101 @@ discard block |
||
| 4746 | 4746 | * @return string |
| 4747 | 4747 | */ |
| 4748 | 4748 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4749 | - static $trouver_table = null; |
|
| 4750 | - static $objets; |
|
| 4751 | - |
|
| 4752 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4753 | - $id_objet = intval($id_objet); |
|
| 4754 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4755 | - return ''; |
|
| 4756 | - } |
|
| 4757 | - |
|
| 4758 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4759 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4760 | - return ''; |
|
| 4761 | - } |
|
| 4762 | - |
|
| 4763 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4764 | - if ($info == 'url') { |
|
| 4765 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4766 | - } |
|
| 4767 | - |
|
| 4768 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4769 | - $demande_titre = ($info === 'titre'); |
|
| 4770 | - $demande_introduction = ($info === 'introduction'); |
|
| 4771 | - |
|
| 4772 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4773 | - if ( |
|
| 4774 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4775 | - or |
|
| 4776 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4777 | - ) { |
|
| 4778 | - if (!$trouver_table) { |
|
| 4779 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4780 | - } |
|
| 4781 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4782 | - if (!$desc) { |
|
| 4783 | - return $objets[$type_objet] = false; |
|
| 4784 | - } |
|
| 4785 | - |
|
| 4786 | - // Si on demande le titre, on le gere en interne |
|
| 4787 | - $champ_titre = ''; |
|
| 4788 | - if ($demande_titre) { |
|
| 4789 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4790 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4791 | - } |
|
| 4792 | - include_spip('base/abstract_sql'); |
|
| 4793 | - include_spip('base/connect_sql'); |
|
| 4794 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4795 | - '*' . $champ_titre, |
|
| 4796 | - $desc['table_sql'], |
|
| 4797 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4798 | - ); |
|
| 4799 | - |
|
| 4800 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4801 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4802 | - } |
|
| 4803 | - |
|
| 4804 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4805 | - // ajouter la longueur au début des params supplémentaires |
|
| 4806 | - if ($demande_introduction) { |
|
| 4807 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4808 | - array_unshift($params, $introduction_longueur); |
|
| 4809 | - } |
|
| 4810 | - |
|
| 4811 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | - if ( |
|
| 4813 | - $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4814 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4815 | - or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4816 | - ) { |
|
| 4817 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | - } |
|
| 4819 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4820 | - elseif ( |
|
| 4821 | - $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4822 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4823 | - or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4824 | - ) { |
|
| 4825 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4826 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4827 | - else { |
|
| 4828 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4829 | - } |
|
| 4830 | - |
|
| 4831 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4832 | - if (!$etoile) { |
|
| 4833 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4834 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4835 | - $info_generee = appliquer_traitement_champ( |
|
| 4836 | - $info_generee, |
|
| 4837 | - $info, |
|
| 4838 | - table_objet($type_objet), |
|
| 4839 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4840 | - ); |
|
| 4841 | - } |
|
| 4842 | - |
|
| 4843 | - return $info_generee; |
|
| 4749 | + static $trouver_table = null; |
|
| 4750 | + static $objets; |
|
| 4751 | + |
|
| 4752 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4753 | + $id_objet = intval($id_objet); |
|
| 4754 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4755 | + return ''; |
|
| 4756 | + } |
|
| 4757 | + |
|
| 4758 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4759 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4760 | + return ''; |
|
| 4761 | + } |
|
| 4762 | + |
|
| 4763 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4764 | + if ($info == 'url') { |
|
| 4765 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4766 | + } |
|
| 4767 | + |
|
| 4768 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4769 | + $demande_titre = ($info === 'titre'); |
|
| 4770 | + $demande_introduction = ($info === 'introduction'); |
|
| 4771 | + |
|
| 4772 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4773 | + if ( |
|
| 4774 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4775 | + or |
|
| 4776 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4777 | + ) { |
|
| 4778 | + if (!$trouver_table) { |
|
| 4779 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4780 | + } |
|
| 4781 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4782 | + if (!$desc) { |
|
| 4783 | + return $objets[$type_objet] = false; |
|
| 4784 | + } |
|
| 4785 | + |
|
| 4786 | + // Si on demande le titre, on le gere en interne |
|
| 4787 | + $champ_titre = ''; |
|
| 4788 | + if ($demande_titre) { |
|
| 4789 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4790 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4791 | + } |
|
| 4792 | + include_spip('base/abstract_sql'); |
|
| 4793 | + include_spip('base/connect_sql'); |
|
| 4794 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4795 | + '*' . $champ_titre, |
|
| 4796 | + $desc['table_sql'], |
|
| 4797 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4798 | + ); |
|
| 4799 | + |
|
| 4800 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4801 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4802 | + } |
|
| 4803 | + |
|
| 4804 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4805 | + // ajouter la longueur au début des params supplémentaires |
|
| 4806 | + if ($demande_introduction) { |
|
| 4807 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4808 | + array_unshift($params, $introduction_longueur); |
|
| 4809 | + } |
|
| 4810 | + |
|
| 4811 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | + if ( |
|
| 4813 | + $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4814 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4815 | + or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4816 | + ) { |
|
| 4817 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | + } |
|
| 4819 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4820 | + elseif ( |
|
| 4821 | + $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4822 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4823 | + or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4824 | + ) { |
|
| 4825 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4826 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4827 | + else { |
|
| 4828 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4829 | + } |
|
| 4830 | + |
|
| 4831 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4832 | + if (!$etoile) { |
|
| 4833 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4834 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4835 | + $info_generee = appliquer_traitement_champ( |
|
| 4836 | + $info_generee, |
|
| 4837 | + $info, |
|
| 4838 | + table_objet($type_objet), |
|
| 4839 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4840 | + ); |
|
| 4841 | + } |
|
| 4842 | + |
|
| 4843 | + return $info_generee; |
|
| 4844 | 4844 | } |
| 4845 | 4845 | |
| 4846 | 4846 | /** |
@@ -4848,7 +4848,7 @@ discard block |
||
| 4848 | 4848 | * @see generer_objet_info |
| 4849 | 4849 | */ |
| 4850 | 4850 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4851 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4851 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4852 | 4852 | } |
| 4853 | 4853 | |
| 4854 | 4854 | /** |
@@ -4881,36 +4881,36 @@ discard block |
||
| 4881 | 4881 | */ |
| 4882 | 4882 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4883 | 4883 | |
| 4884 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4885 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4886 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4887 | - if (isset($ligne_sql['chapo'])) { |
|
| 4888 | - $chapo = $ligne_sql['chapo']; |
|
| 4889 | - $texte = strlen($descriptif) ? |
|
| 4890 | - '' : |
|
| 4891 | - "$chapo \n\n $texte"; |
|
| 4892 | - } |
|
| 4884 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4885 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4886 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4887 | + if (isset($ligne_sql['chapo'])) { |
|
| 4888 | + $chapo = $ligne_sql['chapo']; |
|
| 4889 | + $texte = strlen($descriptif) ? |
|
| 4890 | + '' : |
|
| 4891 | + "$chapo \n\n $texte"; |
|
| 4892 | + } |
|
| 4893 | 4893 | |
| 4894 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4895 | - if (!intval($longueur_ou_suite)) { |
|
| 4896 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4897 | - } else { |
|
| 4898 | - $longueur = intval($longueur_ou_suite); |
|
| 4899 | - } |
|
| 4894 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4895 | + if (!intval($longueur_ou_suite)) { |
|
| 4896 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4897 | + } else { |
|
| 4898 | + $longueur = intval($longueur_ou_suite); |
|
| 4899 | + } |
|
| 4900 | 4900 | |
| 4901 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4902 | - // Ex : #INTRODUCTION{...} |
|
| 4903 | - if ( |
|
| 4904 | - is_null($suite) |
|
| 4905 | - and !intval($longueur_ou_suite) |
|
| 4906 | - ) { |
|
| 4907 | - $suite = $longueur_ou_suite; |
|
| 4908 | - } |
|
| 4901 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4902 | + // Ex : #INTRODUCTION{...} |
|
| 4903 | + if ( |
|
| 4904 | + is_null($suite) |
|
| 4905 | + and !intval($longueur_ou_suite) |
|
| 4906 | + ) { |
|
| 4907 | + $suite = $longueur_ou_suite; |
|
| 4908 | + } |
|
| 4909 | 4909 | |
| 4910 | - $f = chercher_filtre('introduction'); |
|
| 4911 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4910 | + $f = chercher_filtre('introduction'); |
|
| 4911 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4912 | 4912 | |
| 4913 | - return $introduction; |
|
| 4913 | + return $introduction; |
|
| 4914 | 4914 | } |
| 4915 | 4915 | |
| 4916 | 4916 | /** |
@@ -4918,7 +4918,7 @@ discard block |
||
| 4918 | 4918 | * @see generer_objet_introduction |
| 4919 | 4919 | */ |
| 4920 | 4920 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4921 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4921 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4922 | 4922 | } |
| 4923 | 4923 | |
| 4924 | 4924 | /** |
@@ -4932,44 +4932,44 @@ discard block |
||
| 4932 | 4932 | * @return string |
| 4933 | 4933 | */ |
| 4934 | 4934 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4935 | - if (!$champ) { |
|
| 4936 | - return $texte; |
|
| 4937 | - } |
|
| 4935 | + if (!$champ) { |
|
| 4936 | + return $texte; |
|
| 4937 | + } |
|
| 4938 | 4938 | |
| 4939 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4940 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4941 | - include_fichiers_fonctions(); |
|
| 4939 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4940 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4941 | + include_fichiers_fonctions(); |
|
| 4942 | 4942 | |
| 4943 | - $champ = strtoupper($champ); |
|
| 4944 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4945 | - if (!$traitements or !is_array($traitements)) { |
|
| 4946 | - return $texte; |
|
| 4947 | - } |
|
| 4943 | + $champ = strtoupper($champ); |
|
| 4944 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4945 | + if (!$traitements or !is_array($traitements)) { |
|
| 4946 | + return $texte; |
|
| 4947 | + } |
|
| 4948 | 4948 | |
| 4949 | - $traitement = ''; |
|
| 4950 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4951 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4952 | - $table_objet = table_objet($table_objet); |
|
| 4953 | - if (isset($traitements[$table_objet])) { |
|
| 4954 | - $traitement = $traitements[$table_objet]; |
|
| 4955 | - } |
|
| 4956 | - } |
|
| 4957 | - if (!$traitement and isset($traitements[0])) { |
|
| 4958 | - $traitement = $traitements[0]; |
|
| 4959 | - } |
|
| 4960 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4949 | + $traitement = ''; |
|
| 4950 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4951 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4952 | + $table_objet = table_objet($table_objet); |
|
| 4953 | + if (isset($traitements[$table_objet])) { |
|
| 4954 | + $traitement = $traitements[$table_objet]; |
|
| 4955 | + } |
|
| 4956 | + } |
|
| 4957 | + if (!$traitement and isset($traitements[0])) { |
|
| 4958 | + $traitement = $traitements[0]; |
|
| 4959 | + } |
|
| 4960 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4961 | 4961 | |
| 4962 | - if (!$traitement) { |
|
| 4963 | - return $texte; |
|
| 4964 | - } |
|
| 4962 | + if (!$traitement) { |
|
| 4963 | + return $texte; |
|
| 4964 | + } |
|
| 4965 | 4965 | |
| 4966 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4966 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4967 | 4967 | |
| 4968 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4969 | - $Pile = [0 => $env]; |
|
| 4970 | - eval("\$texte = $traitement;"); |
|
| 4968 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4969 | + $Pile = [0 => $env]; |
|
| 4970 | + eval("\$texte = $traitement;"); |
|
| 4971 | 4971 | |
| 4972 | - return $texte; |
|
| 4972 | + return $texte; |
|
| 4973 | 4973 | } |
| 4974 | 4974 | |
| 4975 | 4975 | |
@@ -4983,21 +4983,21 @@ discard block |
||
| 4983 | 4983 | * @return string |
| 4984 | 4984 | */ |
| 4985 | 4985 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4986 | - include_spip('inc/liens'); |
|
| 4987 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4988 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4989 | - // le raccourcis n'est plus valide |
|
| 4990 | - $titre = typo($titre['titre']) ?? ''; |
|
| 4991 | - // on essaye avec generer_info_entite ? |
|
| 4992 | - if (!strlen($titre) and !$connect) { |
|
| 4993 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4994 | - } |
|
| 4995 | - if (!strlen($titre)) { |
|
| 4996 | - $titre = _T('info_sans_titre'); |
|
| 4997 | - } |
|
| 4998 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4986 | + include_spip('inc/liens'); |
|
| 4987 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4988 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4989 | + // le raccourcis n'est plus valide |
|
| 4990 | + $titre = typo($titre['titre']) ?? ''; |
|
| 4991 | + // on essaye avec generer_info_entite ? |
|
| 4992 | + if (!strlen($titre) and !$connect) { |
|
| 4993 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4994 | + } |
|
| 4995 | + if (!strlen($titre)) { |
|
| 4996 | + $titre = _T('info_sans_titre'); |
|
| 4997 | + } |
|
| 4998 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4999 | 4999 | |
| 5000 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 5000 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5005,7 +5005,7 @@ discard block |
||
| 5005 | 5005 | * @see generer_objet_lien |
| 5006 | 5006 | */ |
| 5007 | 5007 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 5008 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5008 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5009 | 5009 | } |
| 5010 | 5010 | |
| 5011 | 5011 | /** |
@@ -5021,15 +5021,15 @@ discard block |
||
| 5021 | 5021 | * @return string |
| 5022 | 5022 | */ |
| 5023 | 5023 | function wrap($texte, $wrap) { |
| 5024 | - $balises = extraire_balises($wrap); |
|
| 5025 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5026 | - $texte = $wrap . $texte; |
|
| 5027 | - $regs = array_reverse($regs[1]); |
|
| 5028 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5029 | - $texte = $texte . $wrap; |
|
| 5030 | - } |
|
| 5024 | + $balises = extraire_balises($wrap); |
|
| 5025 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5026 | + $texte = $wrap . $texte; |
|
| 5027 | + $regs = array_reverse($regs[1]); |
|
| 5028 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5029 | + $texte = $texte . $wrap; |
|
| 5030 | + } |
|
| 5031 | 5031 | |
| 5032 | - return $texte; |
|
| 5032 | + return $texte; |
|
| 5033 | 5033 | } |
| 5034 | 5034 | |
| 5035 | 5035 | |
@@ -5049,44 +5049,44 @@ discard block |
||
| 5049 | 5049 | * @return array|mixed|string |
| 5050 | 5050 | */ |
| 5051 | 5051 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 5052 | - if (is_string($u)) { |
|
| 5053 | - $u = typo($u); |
|
| 5052 | + if (is_string($u)) { |
|
| 5053 | + $u = typo($u); |
|
| 5054 | 5054 | |
| 5055 | - return $u; |
|
| 5056 | - } |
|
| 5055 | + return $u; |
|
| 5056 | + } |
|
| 5057 | 5057 | |
| 5058 | - // caster $u en array si besoin |
|
| 5059 | - if (is_object($u)) { |
|
| 5060 | - $u = (array)$u; |
|
| 5061 | - } |
|
| 5058 | + // caster $u en array si besoin |
|
| 5059 | + if (is_object($u)) { |
|
| 5060 | + $u = (array)$u; |
|
| 5061 | + } |
|
| 5062 | 5062 | |
| 5063 | - if (is_array($u)) { |
|
| 5064 | - $out = ''; |
|
| 5065 | - // toutes les cles sont numeriques ? |
|
| 5066 | - // et aucun enfant n'est un tableau |
|
| 5067 | - // liste simple separee par des virgules |
|
| 5068 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5069 | - $array_values = array_map('is_array', $u); |
|
| 5070 | - $object_values = array_map('is_object', $u); |
|
| 5071 | - if ( |
|
| 5072 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 5073 | - and !array_sum($array_values) |
|
| 5074 | - and !array_sum($object_values) |
|
| 5075 | - ) { |
|
| 5076 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5077 | - } |
|
| 5063 | + if (is_array($u)) { |
|
| 5064 | + $out = ''; |
|
| 5065 | + // toutes les cles sont numeriques ? |
|
| 5066 | + // et aucun enfant n'est un tableau |
|
| 5067 | + // liste simple separee par des virgules |
|
| 5068 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5069 | + $array_values = array_map('is_array', $u); |
|
| 5070 | + $object_values = array_map('is_object', $u); |
|
| 5071 | + if ( |
|
| 5072 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 5073 | + and !array_sum($array_values) |
|
| 5074 | + and !array_sum($object_values) |
|
| 5075 | + ) { |
|
| 5076 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5077 | + } |
|
| 5078 | 5078 | |
| 5079 | - // sinon on passe a la ligne et on indente |
|
| 5080 | - $i_str = str_pad('', $indent, ' '); |
|
| 5081 | - foreach ($u as $k => $v) { |
|
| 5082 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5083 | - } |
|
| 5079 | + // sinon on passe a la ligne et on indente |
|
| 5080 | + $i_str = str_pad('', $indent, ' '); |
|
| 5081 | + foreach ($u as $k => $v) { |
|
| 5082 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5083 | + } |
|
| 5084 | 5084 | |
| 5085 | - return $out; |
|
| 5086 | - } |
|
| 5085 | + return $out; |
|
| 5086 | + } |
|
| 5087 | 5087 | |
| 5088 | - // on sait pas quoi faire... |
|
| 5089 | - return $u; |
|
| 5088 | + // on sait pas quoi faire... |
|
| 5089 | + return $u; |
|
| 5090 | 5090 | } |
| 5091 | 5091 | |
| 5092 | 5092 | |
@@ -5099,10 +5099,10 @@ discard block |
||
| 5099 | 5099 | * @return string|array |
| 5100 | 5100 | */ |
| 5101 | 5101 | function objet_info($objet, $info) { |
| 5102 | - $table = table_objet_sql($objet); |
|
| 5103 | - $infos = lister_tables_objets_sql($table); |
|
| 5102 | + $table = table_objet_sql($objet); |
|
| 5103 | + $infos = lister_tables_objets_sql($table); |
|
| 5104 | 5104 | |
| 5105 | - return ($infos[$info] ?? ''); |
|
| 5105 | + return ($infos[$info] ?? ''); |
|
| 5106 | 5106 | } |
| 5107 | 5107 | |
| 5108 | 5108 | /** |
@@ -5117,11 +5117,11 @@ discard block |
||
| 5117 | 5117 | * Texte traduit du comptage, tel que '3 articles' |
| 5118 | 5118 | */ |
| 5119 | 5119 | function objet_afficher_nb($nb, $objet) { |
| 5120 | - if (!$nb) { |
|
| 5121 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5122 | - } else { |
|
| 5123 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5124 | - } |
|
| 5120 | + if (!$nb) { |
|
| 5121 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5122 | + } else { |
|
| 5123 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5124 | + } |
|
| 5125 | 5125 | } |
| 5126 | 5126 | |
| 5127 | 5127 | /** |
@@ -5133,11 +5133,11 @@ discard block |
||
| 5133 | 5133 | * @return string |
| 5134 | 5134 | */ |
| 5135 | 5135 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5136 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5137 | - $icone = chemin_image($icone); |
|
| 5138 | - $balise_img = charger_filtre('balise_img'); |
|
| 5136 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5137 | + $icone = chemin_image($icone); |
|
| 5138 | + $balise_img = charger_filtre('balise_img'); |
|
| 5139 | 5139 | |
| 5140 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5140 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5141 | 5141 | } |
| 5142 | 5142 | |
| 5143 | 5143 | /** |
@@ -5158,12 +5158,12 @@ discard block |
||
| 5158 | 5158 | * @return string |
| 5159 | 5159 | */ |
| 5160 | 5160 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5161 | - $chaine = explode(':', $chaine); |
|
| 5162 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5163 | - return $t; |
|
| 5164 | - } |
|
| 5165 | - $chaine = implode(':', $chaine); |
|
| 5166 | - return _T($chaine, $args, $options); |
|
| 5161 | + $chaine = explode(':', $chaine); |
|
| 5162 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5163 | + return $t; |
|
| 5164 | + } |
|
| 5165 | + $chaine = implode(':', $chaine); |
|
| 5166 | + return _T($chaine, $args, $options); |
|
| 5167 | 5167 | } |
| 5168 | 5168 | |
| 5169 | 5169 | /** |
@@ -5177,18 +5177,18 @@ discard block |
||
| 5177 | 5177 | * @return string Code HTML |
| 5178 | 5178 | */ |
| 5179 | 5179 | function insert_head_css_conditionnel($flux) { |
| 5180 | - if ( |
|
| 5181 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5182 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5183 | - ) { |
|
| 5184 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5185 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5186 | - $p = $p1; |
|
| 5187 | - } |
|
| 5188 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5189 | - } |
|
| 5180 | + if ( |
|
| 5181 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5182 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5183 | + ) { |
|
| 5184 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5185 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5186 | + $p = $p1; |
|
| 5187 | + } |
|
| 5188 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5189 | + } |
|
| 5190 | 5190 | |
| 5191 | - return $flux; |
|
| 5191 | + return $flux; |
|
| 5192 | 5192 | } |
| 5193 | 5193 | |
| 5194 | 5194 | /** |
@@ -5211,72 +5211,72 @@ discard block |
||
| 5211 | 5211 | * @return string |
| 5212 | 5212 | */ |
| 5213 | 5213 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5214 | - if (isset($contexte['format'])) { |
|
| 5215 | - $extension = $contexte['format']; |
|
| 5216 | - unset($contexte['format']); |
|
| 5217 | - } else { |
|
| 5218 | - $extension = 'html'; |
|
| 5219 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5220 | - $extension = $m[1]; |
|
| 5221 | - } |
|
| 5222 | - } |
|
| 5223 | - // recuperer le contenu produit par le squelette |
|
| 5224 | - $options['raw'] = true; |
|
| 5225 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5226 | - |
|
| 5227 | - // calculer le nom de la css |
|
| 5228 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5229 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5230 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5231 | - |
|
| 5232 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5233 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5234 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5235 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5236 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5237 | - } |
|
| 5238 | - else { |
|
| 5239 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5240 | - ksort($contexte); |
|
| 5241 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5242 | - } |
|
| 5243 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5244 | - |
|
| 5245 | - // mettre a jour le fichier si il n'existe pas |
|
| 5246 | - // ou trop ancien |
|
| 5247 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5248 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5249 | - if ( |
|
| 5250 | - !file_exists($filename) |
|
| 5251 | - or !file_exists($filename . '.last') |
|
| 5252 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5253 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5254 | - ) { |
|
| 5255 | - $contenu = $cache['texte']; |
|
| 5256 | - // passer les urls en absolu si c'est une css |
|
| 5257 | - if ($extension == 'css') { |
|
| 5258 | - $contenu = urls_absolues_css( |
|
| 5259 | - $contenu, |
|
| 5260 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5261 | - ); |
|
| 5262 | - } |
|
| 5263 | - |
|
| 5264 | - $comment = ''; |
|
| 5265 | - // ne pas insérer de commentaire sur certains formats |
|
| 5266 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5267 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5268 | - foreach ($contexte as $k => $v) { |
|
| 5269 | - $comment .= ",$k=$v"; |
|
| 5270 | - } |
|
| 5271 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | - } |
|
| 5275 | - // et ecrire le fichier si il change |
|
| 5276 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | - } |
|
| 5278 | - |
|
| 5279 | - return timestamp($filename); |
|
| 5214 | + if (isset($contexte['format'])) { |
|
| 5215 | + $extension = $contexte['format']; |
|
| 5216 | + unset($contexte['format']); |
|
| 5217 | + } else { |
|
| 5218 | + $extension = 'html'; |
|
| 5219 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5220 | + $extension = $m[1]; |
|
| 5221 | + } |
|
| 5222 | + } |
|
| 5223 | + // recuperer le contenu produit par le squelette |
|
| 5224 | + $options['raw'] = true; |
|
| 5225 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5226 | + |
|
| 5227 | + // calculer le nom de la css |
|
| 5228 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5229 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5230 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5231 | + |
|
| 5232 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5233 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5234 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5235 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5236 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5237 | + } |
|
| 5238 | + else { |
|
| 5239 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5240 | + ksort($contexte); |
|
| 5241 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5242 | + } |
|
| 5243 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5244 | + |
|
| 5245 | + // mettre a jour le fichier si il n'existe pas |
|
| 5246 | + // ou trop ancien |
|
| 5247 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5248 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5249 | + if ( |
|
| 5250 | + !file_exists($filename) |
|
| 5251 | + or !file_exists($filename . '.last') |
|
| 5252 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5253 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5254 | + ) { |
|
| 5255 | + $contenu = $cache['texte']; |
|
| 5256 | + // passer les urls en absolu si c'est une css |
|
| 5257 | + if ($extension == 'css') { |
|
| 5258 | + $contenu = urls_absolues_css( |
|
| 5259 | + $contenu, |
|
| 5260 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5261 | + ); |
|
| 5262 | + } |
|
| 5263 | + |
|
| 5264 | + $comment = ''; |
|
| 5265 | + // ne pas insérer de commentaire sur certains formats |
|
| 5266 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5267 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5268 | + foreach ($contexte as $k => $v) { |
|
| 5269 | + $comment .= ",$k=$v"; |
|
| 5270 | + } |
|
| 5271 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | + } |
|
| 5275 | + // et ecrire le fichier si il change |
|
| 5276 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | + } |
|
| 5278 | + |
|
| 5279 | + return timestamp($filename); |
|
| 5280 | 5280 | } |
| 5281 | 5281 | |
| 5282 | 5282 | /** |
@@ -5289,15 +5289,15 @@ discard block |
||
| 5289 | 5289 | * $fichier auquel on a ajouté le timestamp |
| 5290 | 5290 | */ |
| 5291 | 5291 | function timestamp($fichier) { |
| 5292 | - if ( |
|
| 5293 | - !$fichier |
|
| 5294 | - or !file_exists($fichier) |
|
| 5295 | - or !$m = filemtime($fichier) |
|
| 5296 | - ) { |
|
| 5297 | - return $fichier; |
|
| 5298 | - } |
|
| 5292 | + if ( |
|
| 5293 | + !$fichier |
|
| 5294 | + or !file_exists($fichier) |
|
| 5295 | + or !$m = filemtime($fichier) |
|
| 5296 | + ) { |
|
| 5297 | + return $fichier; |
|
| 5298 | + } |
|
| 5299 | 5299 | |
| 5300 | - return "$fichier?$m"; |
|
| 5300 | + return "$fichier?$m"; |
|
| 5301 | 5301 | } |
| 5302 | 5302 | |
| 5303 | 5303 | /** |
@@ -5307,11 +5307,11 @@ discard block |
||
| 5307 | 5307 | * @return string |
| 5308 | 5308 | */ |
| 5309 | 5309 | function supprimer_timestamp($url) { |
| 5310 | - if (strpos($url, '?') === false) { |
|
| 5311 | - return $url; |
|
| 5312 | - } |
|
| 5310 | + if (strpos($url, '?') === false) { |
|
| 5311 | + return $url; |
|
| 5312 | + } |
|
| 5313 | 5313 | |
| 5314 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5314 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5315 | 5315 | } |
| 5316 | 5316 | |
| 5317 | 5317 | /** |
@@ -5326,9 +5326,9 @@ discard block |
||
| 5326 | 5326 | * @return string |
| 5327 | 5327 | */ |
| 5328 | 5328 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5329 | - include_spip('inc/envoyer_mail'); |
|
| 5329 | + include_spip('inc/envoyer_mail'); |
|
| 5330 | 5330 | |
| 5331 | - return nettoyer_titre_email($titre); |
|
| 5331 | + return nettoyer_titre_email($titre); |
|
| 5332 | 5332 | } |
| 5333 | 5333 | |
| 5334 | 5334 | /** |
@@ -5350,27 +5350,27 @@ discard block |
||
| 5350 | 5350 | * @return string |
| 5351 | 5351 | */ |
| 5352 | 5352 | function filtre_chercher_rubrique_dist( |
| 5353 | - $titre, |
|
| 5354 | - $id_objet, |
|
| 5355 | - $id_parent, |
|
| 5356 | - $objet, |
|
| 5357 | - $id_secteur, |
|
| 5358 | - $restreint, |
|
| 5359 | - $actionable = false, |
|
| 5360 | - $retour_sans_cadre = false |
|
| 5353 | + $titre, |
|
| 5354 | + $id_objet, |
|
| 5355 | + $id_parent, |
|
| 5356 | + $objet, |
|
| 5357 | + $id_secteur, |
|
| 5358 | + $restreint, |
|
| 5359 | + $actionable = false, |
|
| 5360 | + $retour_sans_cadre = false |
|
| 5361 | 5361 | ) { |
| 5362 | - include_spip('inc/filtres_ecrire'); |
|
| 5362 | + include_spip('inc/filtres_ecrire'); |
|
| 5363 | 5363 | |
| 5364 | - return chercher_rubrique( |
|
| 5365 | - $titre, |
|
| 5366 | - $id_objet, |
|
| 5367 | - $id_parent, |
|
| 5368 | - $objet, |
|
| 5369 | - $id_secteur, |
|
| 5370 | - $restreint, |
|
| 5371 | - $actionable, |
|
| 5372 | - $retour_sans_cadre |
|
| 5373 | - ); |
|
| 5364 | + return chercher_rubrique( |
|
| 5365 | + $titre, |
|
| 5366 | + $id_objet, |
|
| 5367 | + $id_parent, |
|
| 5368 | + $objet, |
|
| 5369 | + $id_secteur, |
|
| 5370 | + $restreint, |
|
| 5371 | + $actionable, |
|
| 5372 | + $retour_sans_cadre |
|
| 5373 | + ); |
|
| 5374 | 5374 | } |
| 5375 | 5375 | |
| 5376 | 5376 | /** |
@@ -5399,56 +5399,56 @@ discard block |
||
| 5399 | 5399 | * Chaîne vide si l'accès est autorisé |
| 5400 | 5400 | */ |
| 5401 | 5401 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5402 | - if ($ok) { |
|
| 5403 | - return ''; |
|
| 5404 | - } |
|
| 5405 | - |
|
| 5406 | - // Vider tous les tampons |
|
| 5407 | - $level = @ob_get_level(); |
|
| 5408 | - while ($level--) { |
|
| 5409 | - @ob_end_clean(); |
|
| 5410 | - } |
|
| 5411 | - |
|
| 5412 | - include_spip('inc/headers'); |
|
| 5413 | - |
|
| 5414 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5415 | - if ($url) { |
|
| 5416 | - redirige_par_entete($url, '', $statut); |
|
| 5417 | - } |
|
| 5418 | - |
|
| 5419 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5420 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5421 | - $message = $statut; |
|
| 5422 | - $statut = 0; |
|
| 5423 | - } |
|
| 5424 | - if (!$message) { |
|
| 5425 | - $message = ''; |
|
| 5426 | - } |
|
| 5427 | - $statut = intval($statut); |
|
| 5428 | - |
|
| 5429 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5430 | - if (test_espace_prive()) { |
|
| 5431 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5432 | - $statut = 403; |
|
| 5433 | - } |
|
| 5434 | - http_response_code(403); |
|
| 5435 | - $echec = charger_fonction('403', 'exec'); |
|
| 5436 | - $echec($message); |
|
| 5437 | - } else { |
|
| 5438 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5439 | - if (!$statut) { |
|
| 5440 | - $statut = 404; |
|
| 5441 | - } |
|
| 5442 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5443 | - http_response_code($statut); |
|
| 5444 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5445 | - if ($statut >= 400) { |
|
| 5446 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5447 | - } |
|
| 5448 | - } |
|
| 5449 | - |
|
| 5450 | - |
|
| 5451 | - exit; |
|
| 5402 | + if ($ok) { |
|
| 5403 | + return ''; |
|
| 5404 | + } |
|
| 5405 | + |
|
| 5406 | + // Vider tous les tampons |
|
| 5407 | + $level = @ob_get_level(); |
|
| 5408 | + while ($level--) { |
|
| 5409 | + @ob_end_clean(); |
|
| 5410 | + } |
|
| 5411 | + |
|
| 5412 | + include_spip('inc/headers'); |
|
| 5413 | + |
|
| 5414 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5415 | + if ($url) { |
|
| 5416 | + redirige_par_entete($url, '', $statut); |
|
| 5417 | + } |
|
| 5418 | + |
|
| 5419 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5420 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5421 | + $message = $statut; |
|
| 5422 | + $statut = 0; |
|
| 5423 | + } |
|
| 5424 | + if (!$message) { |
|
| 5425 | + $message = ''; |
|
| 5426 | + } |
|
| 5427 | + $statut = intval($statut); |
|
| 5428 | + |
|
| 5429 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5430 | + if (test_espace_prive()) { |
|
| 5431 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5432 | + $statut = 403; |
|
| 5433 | + } |
|
| 5434 | + http_response_code(403); |
|
| 5435 | + $echec = charger_fonction('403', 'exec'); |
|
| 5436 | + $echec($message); |
|
| 5437 | + } else { |
|
| 5438 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5439 | + if (!$statut) { |
|
| 5440 | + $statut = 404; |
|
| 5441 | + } |
|
| 5442 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5443 | + http_response_code($statut); |
|
| 5444 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5445 | + if ($statut >= 400) { |
|
| 5446 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5447 | + } |
|
| 5448 | + } |
|
| 5449 | + |
|
| 5450 | + |
|
| 5451 | + exit; |
|
| 5452 | 5452 | } |
| 5453 | 5453 | |
| 5454 | 5454 | /** |
@@ -5459,11 +5459,11 @@ discard block |
||
| 5459 | 5459 | * @return string |
| 5460 | 5460 | */ |
| 5461 | 5461 | function filtre_compacte_dist($source, $format = null) { |
| 5462 | - if (function_exists('minifier')) { |
|
| 5463 | - return minifier($source, $format); |
|
| 5464 | - } |
|
| 5462 | + if (function_exists('minifier')) { |
|
| 5463 | + return minifier($source, $format); |
|
| 5464 | + } |
|
| 5465 | 5465 | |
| 5466 | - return $source; |
|
| 5466 | + return $source; |
|
| 5467 | 5467 | } |
| 5468 | 5468 | |
| 5469 | 5469 | |
@@ -5475,31 +5475,31 @@ discard block |
||
| 5475 | 5475 | * @return string |
| 5476 | 5476 | */ |
| 5477 | 5477 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5478 | - $l = strlen($passe); |
|
| 5479 | - |
|
| 5480 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5481 | - if (!$l) { |
|
| 5482 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5483 | - } |
|
| 5484 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5485 | - } |
|
| 5486 | - |
|
| 5487 | - if (is_null($portion_pourcent)) { |
|
| 5488 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5489 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5490 | - } |
|
| 5491 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5492 | - } |
|
| 5493 | - if ($portion_pourcent >= 100) { |
|
| 5494 | - return $passe; |
|
| 5495 | - } |
|
| 5496 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5497 | - $e = max($e, 0); |
|
| 5498 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5499 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5500 | - $mid = '***...***'; |
|
| 5501 | - } |
|
| 5502 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5478 | + $l = strlen($passe); |
|
| 5479 | + |
|
| 5480 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5481 | + if (!$l) { |
|
| 5482 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5483 | + } |
|
| 5484 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5485 | + } |
|
| 5486 | + |
|
| 5487 | + if (is_null($portion_pourcent)) { |
|
| 5488 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5489 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5490 | + } |
|
| 5491 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5492 | + } |
|
| 5493 | + if ($portion_pourcent >= 100) { |
|
| 5494 | + return $passe; |
|
| 5495 | + } |
|
| 5496 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5497 | + $e = max($e, 0); |
|
| 5498 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5499 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5500 | + $mid = '***...***'; |
|
| 5501 | + } |
|
| 5502 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5503 | 5503 | } |
| 5504 | 5504 | |
| 5505 | 5505 | |
@@ -5520,64 +5520,64 @@ discard block |
||
| 5520 | 5520 | */ |
| 5521 | 5521 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5522 | 5522 | |
| 5523 | - $original = $texte; |
|
| 5524 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5525 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5526 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5523 | + $original = $texte; |
|
| 5524 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5525 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5526 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5527 | 5527 | |
| 5528 | - if (!function_exists('translitteration')) { |
|
| 5529 | - include_spip('inc/charsets'); |
|
| 5530 | - } |
|
| 5528 | + if (!function_exists('translitteration')) { |
|
| 5529 | + include_spip('inc/charsets'); |
|
| 5530 | + } |
|
| 5531 | 5531 | |
| 5532 | - // pas de balise html |
|
| 5533 | - if (strpos($texte, '<') !== false) { |
|
| 5534 | - $texte = strip_tags($texte); |
|
| 5535 | - } |
|
| 5536 | - if (strpos($texte, '&') !== false) { |
|
| 5537 | - $texte = unicode2charset($texte); |
|
| 5538 | - } |
|
| 5539 | - // On enlève les espaces indésirables |
|
| 5540 | - $texte = trim($texte); |
|
| 5532 | + // pas de balise html |
|
| 5533 | + if (strpos($texte, '<') !== false) { |
|
| 5534 | + $texte = strip_tags($texte); |
|
| 5535 | + } |
|
| 5536 | + if (strpos($texte, '&') !== false) { |
|
| 5537 | + $texte = unicode2charset($texte); |
|
| 5538 | + } |
|
| 5539 | + // On enlève les espaces indésirables |
|
| 5540 | + $texte = trim($texte); |
|
| 5541 | 5541 | |
| 5542 | - // On enlève les accents et cie |
|
| 5543 | - $texte = translitteration($texte); |
|
| 5542 | + // On enlève les accents et cie |
|
| 5543 | + $texte = translitteration($texte); |
|
| 5544 | 5544 | |
| 5545 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5546 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5545 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5546 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5547 | 5547 | |
| 5548 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5549 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5550 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5551 | - } |
|
| 5548 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5549 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5550 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5551 | + } |
|
| 5552 | 5552 | |
| 5553 | - // pas de separateur au debut ni a la fin |
|
| 5554 | - $texte = trim($texte, $separateur); |
|
| 5553 | + // pas de separateur au debut ni a la fin |
|
| 5554 | + $texte = trim($texte, $separateur); |
|
| 5555 | 5555 | |
| 5556 | - // en minuscules |
|
| 5557 | - $texte = strtolower($texte); |
|
| 5556 | + // en minuscules |
|
| 5557 | + $texte = strtolower($texte); |
|
| 5558 | 5558 | |
| 5559 | - switch ($type) { |
|
| 5560 | - case 'class': |
|
| 5561 | - case 'id': |
|
| 5562 | - case 'anchor': |
|
| 5563 | - if (preg_match(',^\d,', $texte)) { |
|
| 5564 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5565 | - } |
|
| 5566 | - } |
|
| 5559 | + switch ($type) { |
|
| 5560 | + case 'class': |
|
| 5561 | + case 'id': |
|
| 5562 | + case 'anchor': |
|
| 5563 | + if (preg_match(',^\d,', $texte)) { |
|
| 5564 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5565 | + } |
|
| 5566 | + } |
|
| 5567 | 5567 | |
| 5568 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5569 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5570 | - } |
|
| 5568 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5569 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5570 | + } |
|
| 5571 | 5571 | |
| 5572 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5573 | - if (preg_match(',^\d,', $texte)) { |
|
| 5574 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5575 | - } |
|
| 5576 | - $texte .= $separateur . md5($original); |
|
| 5577 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5578 | - } |
|
| 5572 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5573 | + if (preg_match(',^\d,', $texte)) { |
|
| 5574 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5575 | + } |
|
| 5576 | + $texte .= $separateur . md5($original); |
|
| 5577 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5578 | + } |
|
| 5579 | 5579 | |
| 5580 | - return $texte; |
|
| 5580 | + return $texte; |
|
| 5581 | 5581 | } |
| 5582 | 5582 | |
| 5583 | 5583 | |
@@ -5598,11 +5598,11 @@ discard block |
||
| 5598 | 5598 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5599 | 5599 | */ |
| 5600 | 5600 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5601 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5602 | - if ($ucfirst) { |
|
| 5603 | - $label = spip_ucfirst($label); |
|
| 5604 | - } |
|
| 5605 | - return $label; |
|
| 5601 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5602 | + if ($ucfirst) { |
|
| 5603 | + $label = spip_ucfirst($label); |
|
| 5604 | + } |
|
| 5605 | + return $label; |
|
| 5606 | 5606 | } |
| 5607 | 5607 | |
| 5608 | 5608 | /** |
@@ -5615,8 +5615,8 @@ discard block |
||
| 5615 | 5615 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5616 | 5616 | */ |
| 5617 | 5617 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5618 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5619 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5618 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5619 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5620 | 5620 | } |
| 5621 | 5621 | |
| 5622 | 5622 | |
@@ -5629,19 +5629,19 @@ discard block |
||
| 5629 | 5629 | * @return array |
| 5630 | 5630 | */ |
| 5631 | 5631 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5632 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5633 | - return []; |
|
| 5634 | - } |
|
| 5632 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5633 | + return []; |
|
| 5634 | + } |
|
| 5635 | 5635 | |
| 5636 | - // compatibilite signature inversee |
|
| 5637 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5638 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5639 | - } |
|
| 5636 | + // compatibilite signature inversee |
|
| 5637 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5638 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5639 | + } |
|
| 5640 | 5640 | |
| 5641 | - if (!function_exists($fonction)) { |
|
| 5642 | - include_spip('base/objets'); |
|
| 5643 | - } |
|
| 5644 | - return $fonction($objet, $id_objet); |
|
| 5641 | + if (!function_exists($fonction)) { |
|
| 5642 | + include_spip('base/objets'); |
|
| 5643 | + } |
|
| 5644 | + return $fonction($objet, $id_objet); |
|
| 5645 | 5645 | } |
| 5646 | 5646 | |
| 5647 | 5647 | |
@@ -5656,7 +5656,7 @@ discard block |
||
| 5656 | 5656 | * @return array |
| 5657 | 5657 | */ |
| 5658 | 5658 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5659 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5659 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5660 | 5660 | } |
| 5661 | 5661 | |
| 5662 | 5662 | /** |
@@ -5670,7 +5670,7 @@ discard block |
||
| 5670 | 5670 | * @return array |
| 5671 | 5671 | */ |
| 5672 | 5672 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5673 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5673 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5674 | 5674 | } |
| 5675 | 5675 | |
| 5676 | 5676 | /** |
@@ -5684,7 +5684,7 @@ discard block |
||
| 5684 | 5684 | * @return array |
| 5685 | 5685 | */ |
| 5686 | 5686 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5687 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5687 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5688 | 5688 | } |
| 5689 | 5689 | |
| 5690 | 5690 | /** |
@@ -5698,5 +5698,5 @@ discard block |
||
| 5698 | 5698 | * @return array |
| 5699 | 5699 | */ |
| 5700 | 5700 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5701 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5701 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5702 | 5702 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | * @return void|bool |
| 326 | 326 | */ |
| 327 | 327 | function initialiser_sel() { |
| 328 | - if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | - if (CRYPT_MD5) { |
|
| 330 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 331 | - } else { |
|
| 332 | - $GLOBALS['htsalt'] = ''; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - return $GLOBALS['htsalt']; |
|
| 328 | + if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | + if (CRYPT_MD5) { |
|
| 330 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 331 | + } else { |
|
| 332 | + $GLOBALS['htsalt'] = ''; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + return $GLOBALS['htsalt']; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -349,32 +349,32 @@ discard block |
||
| 349 | 349 | * - void sinon. |
| 350 | 350 | **/ |
| 351 | 351 | function ecrire_acces() { |
| 352 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 353 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 354 | - |
|
| 355 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 356 | - // par exemple acces_restreint ; |
|
| 357 | - // si .htaccess existe, outrepasser spip_meta |
|
| 358 | - if ( |
|
| 359 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 360 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 361 | - and !@file_exists($htaccess) |
|
| 362 | - ) { |
|
| 363 | - spip_unlink($htpasswd); |
|
| 364 | - spip_unlink($htpasswd . '-admin'); |
|
| 365 | - return; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 369 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 370 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 371 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 372 | - |
|
| 373 | - if (spip_connect_ldap()) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 352 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 353 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 354 | + |
|
| 355 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 356 | + // par exemple acces_restreint ; |
|
| 357 | + // si .htaccess existe, outrepasser spip_meta |
|
| 358 | + if ( |
|
| 359 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 360 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 361 | + and !@file_exists($htaccess) |
|
| 362 | + ) { |
|
| 363 | + spip_unlink($htpasswd); |
|
| 364 | + spip_unlink($htpasswd . '-admin'); |
|
| 365 | + return; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 369 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 370 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 371 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 372 | + |
|
| 373 | + if (spip_connect_ldap()) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -383,29 +383,29 @@ discard block |
||
| 383 | 383 | * @param $htpasswd_admin |
| 384 | 384 | */ |
| 385 | 385 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 386 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 387 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - $pwd_all = ''; // login:htpass pour tous |
|
| 391 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 392 | - |
|
| 393 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 394 | - while ($row = sql_fetch($res)) { |
|
| 395 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 396 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 397 | - $pwd_all .= $ligne; |
|
| 398 | - if ($row['statut'] == '0minirezo') { |
|
| 399 | - $pwd_admin .= $ligne; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($pwd_all) { |
|
| 405 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 406 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 407 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 408 | - } |
|
| 386 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 387 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + $pwd_all = ''; // login:htpass pour tous |
|
| 391 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 392 | + |
|
| 393 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 394 | + while ($row = sql_fetch($res)) { |
|
| 395 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 396 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 397 | + $pwd_all .= $ligne; |
|
| 398 | + if ($row['statut'] == '0minirezo') { |
|
| 399 | + $pwd_admin .= $ligne; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($pwd_all) { |
|
| 405 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 406 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 407 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -419,13 +419,13 @@ discard block |
||
| 419 | 419 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 420 | 420 | */ |
| 421 | 421 | function generer_htpass($pass) { |
| 422 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 423 | - return $generer_htpass($pass); |
|
| 424 | - } |
|
| 425 | - elseif (function_exists('crypt')) { |
|
| 426 | - return crypt($pass, initialiser_sel()); |
|
| 427 | - } |
|
| 428 | - return ''; |
|
| 422 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 423 | + return $generer_htpass($pass); |
|
| 424 | + } |
|
| 425 | + elseif (function_exists('crypt')) { |
|
| 426 | + return crypt($pass, initialiser_sel()); |
|
| 427 | + } |
|
| 428 | + return ''; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | * @return boolean |
| 439 | 439 | */ |
| 440 | 440 | function verifier_htaccess($rep, $force = false) { |
| 441 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 442 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 443 | - return true; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // directive deny compatible Apache 2.0+ |
|
| 447 | - $deny = |
|
| 448 | - '# Deny all requests from Apache 2.4+. |
|
| 441 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 442 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 443 | + return true; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // directive deny compatible Apache 2.0+ |
|
| 447 | + $deny = |
|
| 448 | + '# Deny all requests from Apache 2.4+. |
|
| 449 | 449 | <IfModule mod_authz_core.c> |
| 450 | 450 | Require all denied |
| 451 | 451 | </IfModule> |
@@ -454,32 +454,32 @@ discard block |
||
| 454 | 454 | Deny from all |
| 455 | 455 | </IfModule> |
| 456 | 456 | '; |
| 457 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 458 | - if ( |
|
| 459 | - function_exists('apache_get_version') |
|
| 460 | - and $v = apache_get_version() |
|
| 461 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 462 | - ) { |
|
| 463 | - $deny = "deny from all\n"; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 467 | - fputs($ht, $deny); |
|
| 468 | - fclose($ht); |
|
| 469 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 470 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 471 | - if ($ht = @fopen($t, 'w')) { |
|
| 472 | - @fclose($ht); |
|
| 473 | - include_spip('inc/distant'); |
|
| 474 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 475 | - $t = url_de_base() . $t; |
|
| 476 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 477 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 481 | - |
|
| 482 | - return $ht; |
|
| 457 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 458 | + if ( |
|
| 459 | + function_exists('apache_get_version') |
|
| 460 | + and $v = apache_get_version() |
|
| 461 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 462 | + ) { |
|
| 463 | + $deny = "deny from all\n"; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 467 | + fputs($ht, $deny); |
|
| 468 | + fclose($ht); |
|
| 469 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 470 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 471 | + if ($ht = @fopen($t, 'w')) { |
|
| 472 | + @fclose($ht); |
|
| 473 | + include_spip('inc/distant'); |
|
| 474 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 475 | + $t = url_de_base() . $t; |
|
| 476 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 477 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 481 | + |
|
| 482 | + return $ht; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -497,20 +497,20 @@ discard block |
||
| 497 | 497 | * Valeur de la configuration `creer_htaccess` |
| 498 | 498 | */ |
| 499 | 499 | function gerer_htaccess() { |
| 500 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 501 | - // par exemple acces_restreint |
|
| 502 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 503 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 504 | - $dirs[] = ['extension' => 'distant']; |
|
| 505 | - foreach ($dirs as $e) { |
|
| 506 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 507 | - if ($f) { |
|
| 508 | - verifier_htaccess($dir); |
|
| 509 | - } else { |
|
| 510 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 500 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 501 | + // par exemple acces_restreint |
|
| 502 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 503 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 504 | + $dirs[] = ['extension' => 'distant']; |
|
| 505 | + foreach ($dirs as $e) { |
|
| 506 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 507 | + if ($f) { |
|
| 508 | + verifier_htaccess($dir); |
|
| 509 | + } else { |
|
| 510 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 516 | 516 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * @return void |
| 33 | 33 | **/ |
| 34 | 34 | function array_set_merge(&$table, $index, $valeur) { |
| 35 | - if (!isset($table[$index])) { |
|
| 36 | - $table[$index] = $valeur; |
|
| 37 | - } else { |
|
| 38 | - $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | - } |
|
| 35 | + if (!isset($table[$index])) { |
|
| 36 | + $table[$index] = $valeur; |
|
| 37 | + } else { |
|
| 38 | + $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -55,440 +55,440 @@ discard block |
||
| 55 | 55 | * - string (interne) si table '::md5' retourne un hash |
| 56 | 56 | */ |
| 57 | 57 | function lister_tables_objets_sql(?string $table_sql = null, $desc = []) { |
| 58 | - static $deja_la = false; |
|
| 59 | - static $infos_tables = null; |
|
| 60 | - static $md5 = null; |
|
| 61 | - static $plugin_hash = null; |
|
| 62 | - |
|
| 63 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 64 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 65 | - |
|
| 66 | - // prealablement recuperer les tables_principales |
|
| 67 | - if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 68 | - // pas de reentrance (cas base/serial) |
|
| 69 | - if ($deja_la) { |
|
| 70 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 71 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 72 | - |
|
| 73 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 74 | - } |
|
| 75 | - $deja_la = true; |
|
| 76 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 77 | - |
|
| 78 | - // recuperer les declarations explicites ancienne mode |
|
| 79 | - // qui servent a completer declarer_tables_objets_sql |
|
| 80 | - base_serial($GLOBALS['tables_principales']); |
|
| 81 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 82 | - $infos_tables = [ |
|
| 83 | - 'spip_articles' => [ |
|
| 84 | - 'page' => 'article', |
|
| 85 | - 'texte_retour' => 'icone_retour_article', |
|
| 86 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 87 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 88 | - 'texte_objets' => 'public:articles', |
|
| 89 | - 'texte_objet' => 'public:article', |
|
| 90 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 91 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 92 | - 'info_1_objet' => 'info_1_article', |
|
| 93 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 94 | - 'texte_logo_objet' => 'logo_article', |
|
| 95 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 96 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 97 | - 'titre' => 'titre, lang', |
|
| 98 | - 'date' => 'date', |
|
| 99 | - 'principale' => 'oui', |
|
| 100 | - 'introduction_longueur' => '500', |
|
| 101 | - 'champs_editables' => [ |
|
| 102 | - 'surtitre', |
|
| 103 | - 'titre', |
|
| 104 | - 'soustitre', |
|
| 105 | - 'descriptif', |
|
| 106 | - 'nom_site', |
|
| 107 | - 'url_site', |
|
| 108 | - 'chapo', |
|
| 109 | - 'texte', |
|
| 110 | - 'ps', |
|
| 111 | - 'virtuel' |
|
| 112 | - ], |
|
| 113 | - 'champs_versionnes' => [ |
|
| 114 | - 'id_rubrique', |
|
| 115 | - 'surtitre', |
|
| 116 | - 'titre', |
|
| 117 | - 'soustitre', |
|
| 118 | - 'jointure_auteurs', |
|
| 119 | - 'descriptif', |
|
| 120 | - 'nom_site', |
|
| 121 | - 'url_site', |
|
| 122 | - 'chapo', |
|
| 123 | - 'texte', |
|
| 124 | - 'ps' |
|
| 125 | - ], |
|
| 126 | - 'field' => [ |
|
| 127 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 128 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 130 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 131 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 132 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 133 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 135 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 136 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 137 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 138 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 139 | - 'maj' => 'TIMESTAMP', |
|
| 140 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 141 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 142 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 143 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 144 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 145 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 146 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 147 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 148 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 149 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 150 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 151 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 152 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 153 | - ], |
|
| 154 | - 'key' => [ |
|
| 155 | - 'PRIMARY KEY' => 'id_article', |
|
| 156 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 157 | - 'KEY id_secteur' => 'id_secteur', |
|
| 158 | - 'KEY id_trad' => 'id_trad', |
|
| 159 | - 'KEY lang' => 'lang', |
|
| 160 | - 'KEY statut' => 'statut, date', |
|
| 161 | - ], |
|
| 162 | - 'join' => [ |
|
| 163 | - 'id_article' => 'id_article', |
|
| 164 | - 'id_rubrique' => 'id_rubrique' |
|
| 165 | - ], |
|
| 166 | - 'parent' => [ |
|
| 167 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 168 | - ], |
|
| 169 | - 'rechercher_champs' => [ |
|
| 170 | - 'surtitre' => 5, |
|
| 171 | - 'titre' => 8, |
|
| 172 | - 'soustitre' => 5, |
|
| 173 | - 'chapo' => 3, |
|
| 174 | - 'texte' => 1, |
|
| 175 | - 'ps' => 1, |
|
| 176 | - 'nom_site' => 1, |
|
| 177 | - 'url_site' => 1, |
|
| 178 | - 'descriptif' => 4 |
|
| 179 | - ], |
|
| 180 | - 'rechercher_jointures' => [ |
|
| 181 | - 'auteur' => ['nom' => 10], |
|
| 182 | - ], |
|
| 183 | - 'statut' => [ |
|
| 184 | - [ |
|
| 185 | - 'champ' => 'statut', |
|
| 186 | - 'publie' => 'publie', |
|
| 187 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 188 | - 'post_date' => 'date', |
|
| 189 | - 'exception' => ['statut', 'tout'] |
|
| 190 | - ] |
|
| 191 | - ], |
|
| 192 | - 'statut_titres' => [ |
|
| 193 | - 'prepa' => 'info_article_redaction', |
|
| 194 | - 'prop' => 'info_article_propose', |
|
| 195 | - 'publie' => 'info_article_publie', |
|
| 196 | - 'refuse' => 'info_article_refuse', |
|
| 197 | - 'poubelle' => 'info_article_supprime' |
|
| 198 | - ], |
|
| 199 | - 'statut_textes_instituer' => [ |
|
| 200 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 201 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 202 | - 'publie' => 'texte_statut_publie', |
|
| 203 | - 'refuse' => 'texte_statut_refuse', |
|
| 204 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 205 | - ], |
|
| 206 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 207 | - 'aide_changer_statut' => 'artstatut', |
|
| 208 | - 'tables_jointures' => [ |
|
| 209 | - 'profondeur' => 'rubriques', |
|
| 210 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 211 | - ], |
|
| 212 | - ], |
|
| 213 | - 'spip_auteurs' => [ |
|
| 214 | - 'page' => 'auteur', |
|
| 215 | - 'texte_retour' => 'icone_retour', |
|
| 216 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 217 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 218 | - 'texte_objets' => 'icone_auteurs', |
|
| 219 | - 'texte_objet' => 'public:auteur', |
|
| 220 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 221 | - 'info_1_objet' => 'info_1_auteur', |
|
| 222 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 223 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 224 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 225 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 226 | - 'date' => 'date', |
|
| 227 | - 'principale' => 'oui', |
|
| 228 | - 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 229 | - 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 230 | - 'field' => [ |
|
| 231 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 232 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 233 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 234 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 235 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 237 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 238 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 239 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 240 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 241 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 242 | - 'maj' => 'TIMESTAMP', |
|
| 243 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 244 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 245 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 246 | - 'alea_actuel' => 'tinytext', |
|
| 247 | - 'alea_futur' => 'tinytext', |
|
| 248 | - 'prefs' => 'text', |
|
| 249 | - 'cookie_oubli' => 'tinytext', |
|
| 250 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 251 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 252 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 253 | - ], |
|
| 254 | - 'key' => [ |
|
| 255 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 256 | - 'KEY login' => 'login', |
|
| 257 | - 'KEY statut' => 'statut', |
|
| 258 | - 'KEY en_ligne' => 'en_ligne', |
|
| 259 | - ], |
|
| 260 | - 'join' => [ |
|
| 261 | - 'id_auteur' => 'id_auteur', |
|
| 262 | - 'login' => 'login' |
|
| 263 | - ], |
|
| 264 | - 'rechercher_champs' => [ |
|
| 265 | - 'nom' => 5, |
|
| 266 | - 'bio' => 1, |
|
| 267 | - 'email' => 1, |
|
| 268 | - 'nom_site' => 1, |
|
| 269 | - 'url_site' => 1, |
|
| 270 | - 'login' => 1 |
|
| 271 | - ], |
|
| 272 | - // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 273 | - // et avoir des articles publies |
|
| 274 | - 'statut' => [ |
|
| 275 | - [ |
|
| 276 | - 'champ' => 'statut', |
|
| 277 | - 'publie' => '!5poubelle', |
|
| 278 | - 'previsu' => '!5poubelle', |
|
| 279 | - 'exception' => 'statut' |
|
| 280 | - ], |
|
| 281 | - [ |
|
| 282 | - 'champ' => [ |
|
| 283 | - ['spip_auteurs_liens', 'id_auteur'], |
|
| 284 | - [ |
|
| 285 | - 'spip_articles', |
|
| 286 | - ['id_objet', 'id_article', 'objet', 'article'] |
|
| 287 | - ], |
|
| 288 | - 'statut' |
|
| 289 | - ], |
|
| 290 | - 'publie' => 'publie', |
|
| 291 | - 'previsu' => '!', |
|
| 292 | - 'post_date' => 'date', |
|
| 293 | - 'exception' => ['statut', 'lien', 'tout'] |
|
| 294 | - ], |
|
| 295 | - ], |
|
| 296 | - 'statut_images' => [ |
|
| 297 | - 'auteur-6forum-16.png', |
|
| 298 | - '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 299 | - '1comite' => 'auteur-1comite-16.png', |
|
| 300 | - '6forum' => 'auteur-6forum-16.png', |
|
| 301 | - '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 302 | - 'nouveau' => '' |
|
| 303 | - ], |
|
| 304 | - 'statut_titres' => [ |
|
| 305 | - 'titre_image_visiteur', |
|
| 306 | - '0minirezo' => 'titre_image_administrateur', |
|
| 307 | - '1comite' => 'titre_image_redacteur_02', |
|
| 308 | - '6forum' => 'titre_image_visiteur', |
|
| 309 | - '5poubelle' => 'titre_image_auteur_supprime', |
|
| 310 | - ], |
|
| 311 | - 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 312 | - ], |
|
| 313 | - ], |
|
| 314 | - 'spip_rubriques' => [ |
|
| 315 | - 'page' => 'rubrique', |
|
| 316 | - 'url_voir' => 'rubrique', |
|
| 317 | - 'url_edit' => 'rubrique_edit', |
|
| 318 | - 'texte_retour' => 'icone_retour', |
|
| 319 | - 'texte_objets' => 'public:rubriques', |
|
| 320 | - 'texte_objet' => 'public:rubrique', |
|
| 321 | - 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 322 | - 'texte_creer' => 'icone_creer_rubrique', |
|
| 323 | - 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 324 | - 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 325 | - 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 326 | - 'info_1_objet' => 'info_1_rubrique', |
|
| 327 | - 'info_nb_objets' => 'info_nb_rubriques', |
|
| 328 | - 'texte_logo_objet' => 'logo_rubrique', |
|
| 329 | - 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 330 | - 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 331 | - 'titre' => 'titre, lang', |
|
| 332 | - 'date' => 'date', |
|
| 333 | - 'principale' => 'oui', |
|
| 334 | - 'introduction_longueur' => '600', |
|
| 335 | - 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 336 | - 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 337 | - 'field' => [ |
|
| 338 | - 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 339 | - 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 340 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 341 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 342 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 343 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 344 | - 'maj' => 'TIMESTAMP', |
|
| 345 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 346 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 347 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 348 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 349 | - 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 350 | - 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 351 | - 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 352 | - ], |
|
| 353 | - 'key' => [ |
|
| 354 | - 'PRIMARY KEY' => 'id_rubrique', |
|
| 355 | - 'KEY lang' => 'lang', |
|
| 356 | - 'KEY id_parent' => 'id_parent', |
|
| 357 | - ], |
|
| 358 | - 'parent' => [ |
|
| 359 | - ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 360 | - ], |
|
| 361 | - 'rechercher_champs' => [ |
|
| 362 | - 'titre' => 8, |
|
| 363 | - 'descriptif' => 5, |
|
| 364 | - 'texte' => 1 |
|
| 365 | - ], |
|
| 366 | - 'statut' => [ |
|
| 367 | - [ |
|
| 368 | - 'champ' => 'statut', |
|
| 369 | - 'publie' => 'publie', |
|
| 370 | - 'previsu' => '!', |
|
| 371 | - 'exception' => ['statut', 'tout'] |
|
| 372 | - ], |
|
| 373 | - ], |
|
| 374 | - 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 375 | - ], |
|
| 376 | - ], |
|
| 377 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 378 | - ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 379 | - ]; |
|
| 380 | - |
|
| 381 | - // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 382 | - // initialiser la signature |
|
| 383 | - $md5 = md5(serialize($infos_tables)); |
|
| 384 | - |
|
| 385 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 386 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 387 | - $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 388 | - |
|
| 389 | - // completer les informations manquantes ou implicites |
|
| 390 | - $all = []; |
|
| 391 | - foreach (array_keys($infos_tables) as $t) { |
|
| 392 | - // les cles numeriques servent a declarer |
|
| 393 | - // les proprietes applicables a tous les objets |
|
| 394 | - // on les mets de cote |
|
| 395 | - if (is_numeric($t)) { |
|
| 396 | - $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 397 | - unset($infos_tables[$t]); |
|
| 398 | - } else { |
|
| 399 | - $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - // repercuter les proprietes generales communes a tous les objets |
|
| 404 | - foreach (array_keys($infos_tables) as $t) { |
|
| 405 | - foreach ($all as $i => $v) { |
|
| 406 | - if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 407 | - $add = $all[$i]; |
|
| 408 | - // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 409 | - // pour les declarations generiques avec cles numeriques |
|
| 410 | - if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0) { |
|
| 411 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 412 | - foreach ($doublons as $d) { |
|
| 413 | - if ( |
|
| 414 | - is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 415 | - and is_numeric($k = array_search($d, $add)) |
|
| 416 | - ) { |
|
| 417 | - unset($add[$k]); |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 422 | - } else { |
|
| 423 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 424 | - $infos_tables[$t][$i] ?? [], |
|
| 425 | - $all[$i] |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // completer les tables principales et auxiliaires |
|
| 432 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 433 | - // pour assurer la compat en transition |
|
| 434 | - foreach ($infos_tables as $table => $infos) { |
|
| 435 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 436 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 437 | - // qui a ete appelle avant |
|
| 438 | - $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 439 | - // l'ajouter au tableau |
|
| 440 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 441 | - if (isset($infos['field']) and isset($infos['key'])) { |
|
| 442 | - foreach (['field', 'key', 'join'] as $k) { |
|
| 443 | - if (isset($infos_tables[$table][$k])) { |
|
| 444 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } else { |
|
| 448 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 449 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 450 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 451 | - } |
|
| 452 | - if (is_countable($mem) ? count($mem) : 0) { |
|
| 453 | - foreach (array_keys($mem) as $k) { |
|
| 454 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 455 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 456 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 457 | - $mem[$k] |
|
| 458 | - ); |
|
| 459 | - } else { |
|
| 460 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // recuperer les interfaces (table_titre, table_date) |
|
| 467 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 468 | - // dans le pipeline de declarer_tables_interfaces |
|
| 469 | - include_spip('public/interfaces'); |
|
| 470 | - foreach (array_keys($infos_tables) as $t) { |
|
| 471 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $deja_la = false; |
|
| 475 | - // signature |
|
| 476 | - $md5 = md5(serialize($infos_tables)); |
|
| 477 | - } |
|
| 478 | - if ($table_sql === '::md5') { |
|
| 479 | - return $md5; |
|
| 480 | - } |
|
| 481 | - if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 482 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 483 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 484 | - |
|
| 485 | - return $desc; |
|
| 486 | - } |
|
| 487 | - if ($table_sql) { |
|
| 488 | - return $infos_tables[$table_sql] ?? []; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return $infos_tables; |
|
| 58 | + static $deja_la = false; |
|
| 59 | + static $infos_tables = null; |
|
| 60 | + static $md5 = null; |
|
| 61 | + static $plugin_hash = null; |
|
| 62 | + |
|
| 63 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 64 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 65 | + |
|
| 66 | + // prealablement recuperer les tables_principales |
|
| 67 | + if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 68 | + // pas de reentrance (cas base/serial) |
|
| 69 | + if ($deja_la) { |
|
| 70 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 71 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 72 | + |
|
| 73 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 74 | + } |
|
| 75 | + $deja_la = true; |
|
| 76 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 77 | + |
|
| 78 | + // recuperer les declarations explicites ancienne mode |
|
| 79 | + // qui servent a completer declarer_tables_objets_sql |
|
| 80 | + base_serial($GLOBALS['tables_principales']); |
|
| 81 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 82 | + $infos_tables = [ |
|
| 83 | + 'spip_articles' => [ |
|
| 84 | + 'page' => 'article', |
|
| 85 | + 'texte_retour' => 'icone_retour_article', |
|
| 86 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 87 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 88 | + 'texte_objets' => 'public:articles', |
|
| 89 | + 'texte_objet' => 'public:article', |
|
| 90 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 91 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 92 | + 'info_1_objet' => 'info_1_article', |
|
| 93 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 94 | + 'texte_logo_objet' => 'logo_article', |
|
| 95 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 96 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 97 | + 'titre' => 'titre, lang', |
|
| 98 | + 'date' => 'date', |
|
| 99 | + 'principale' => 'oui', |
|
| 100 | + 'introduction_longueur' => '500', |
|
| 101 | + 'champs_editables' => [ |
|
| 102 | + 'surtitre', |
|
| 103 | + 'titre', |
|
| 104 | + 'soustitre', |
|
| 105 | + 'descriptif', |
|
| 106 | + 'nom_site', |
|
| 107 | + 'url_site', |
|
| 108 | + 'chapo', |
|
| 109 | + 'texte', |
|
| 110 | + 'ps', |
|
| 111 | + 'virtuel' |
|
| 112 | + ], |
|
| 113 | + 'champs_versionnes' => [ |
|
| 114 | + 'id_rubrique', |
|
| 115 | + 'surtitre', |
|
| 116 | + 'titre', |
|
| 117 | + 'soustitre', |
|
| 118 | + 'jointure_auteurs', |
|
| 119 | + 'descriptif', |
|
| 120 | + 'nom_site', |
|
| 121 | + 'url_site', |
|
| 122 | + 'chapo', |
|
| 123 | + 'texte', |
|
| 124 | + 'ps' |
|
| 125 | + ], |
|
| 126 | + 'field' => [ |
|
| 127 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 128 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 130 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 131 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 132 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 133 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 135 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 136 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 137 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 138 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 139 | + 'maj' => 'TIMESTAMP', |
|
| 140 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 141 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 142 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 143 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 144 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 145 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 146 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 147 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 148 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 149 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 150 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 151 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 152 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 153 | + ], |
|
| 154 | + 'key' => [ |
|
| 155 | + 'PRIMARY KEY' => 'id_article', |
|
| 156 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 157 | + 'KEY id_secteur' => 'id_secteur', |
|
| 158 | + 'KEY id_trad' => 'id_trad', |
|
| 159 | + 'KEY lang' => 'lang', |
|
| 160 | + 'KEY statut' => 'statut, date', |
|
| 161 | + ], |
|
| 162 | + 'join' => [ |
|
| 163 | + 'id_article' => 'id_article', |
|
| 164 | + 'id_rubrique' => 'id_rubrique' |
|
| 165 | + ], |
|
| 166 | + 'parent' => [ |
|
| 167 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 168 | + ], |
|
| 169 | + 'rechercher_champs' => [ |
|
| 170 | + 'surtitre' => 5, |
|
| 171 | + 'titre' => 8, |
|
| 172 | + 'soustitre' => 5, |
|
| 173 | + 'chapo' => 3, |
|
| 174 | + 'texte' => 1, |
|
| 175 | + 'ps' => 1, |
|
| 176 | + 'nom_site' => 1, |
|
| 177 | + 'url_site' => 1, |
|
| 178 | + 'descriptif' => 4 |
|
| 179 | + ], |
|
| 180 | + 'rechercher_jointures' => [ |
|
| 181 | + 'auteur' => ['nom' => 10], |
|
| 182 | + ], |
|
| 183 | + 'statut' => [ |
|
| 184 | + [ |
|
| 185 | + 'champ' => 'statut', |
|
| 186 | + 'publie' => 'publie', |
|
| 187 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 188 | + 'post_date' => 'date', |
|
| 189 | + 'exception' => ['statut', 'tout'] |
|
| 190 | + ] |
|
| 191 | + ], |
|
| 192 | + 'statut_titres' => [ |
|
| 193 | + 'prepa' => 'info_article_redaction', |
|
| 194 | + 'prop' => 'info_article_propose', |
|
| 195 | + 'publie' => 'info_article_publie', |
|
| 196 | + 'refuse' => 'info_article_refuse', |
|
| 197 | + 'poubelle' => 'info_article_supprime' |
|
| 198 | + ], |
|
| 199 | + 'statut_textes_instituer' => [ |
|
| 200 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 201 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 202 | + 'publie' => 'texte_statut_publie', |
|
| 203 | + 'refuse' => 'texte_statut_refuse', |
|
| 204 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 205 | + ], |
|
| 206 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 207 | + 'aide_changer_statut' => 'artstatut', |
|
| 208 | + 'tables_jointures' => [ |
|
| 209 | + 'profondeur' => 'rubriques', |
|
| 210 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 211 | + ], |
|
| 212 | + ], |
|
| 213 | + 'spip_auteurs' => [ |
|
| 214 | + 'page' => 'auteur', |
|
| 215 | + 'texte_retour' => 'icone_retour', |
|
| 216 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 217 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 218 | + 'texte_objets' => 'icone_auteurs', |
|
| 219 | + 'texte_objet' => 'public:auteur', |
|
| 220 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 221 | + 'info_1_objet' => 'info_1_auteur', |
|
| 222 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 223 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 224 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 225 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 226 | + 'date' => 'date', |
|
| 227 | + 'principale' => 'oui', |
|
| 228 | + 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 229 | + 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 230 | + 'field' => [ |
|
| 231 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 232 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 233 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 234 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 235 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 237 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 238 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 239 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 240 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 241 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 242 | + 'maj' => 'TIMESTAMP', |
|
| 243 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 244 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 245 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 246 | + 'alea_actuel' => 'tinytext', |
|
| 247 | + 'alea_futur' => 'tinytext', |
|
| 248 | + 'prefs' => 'text', |
|
| 249 | + 'cookie_oubli' => 'tinytext', |
|
| 250 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 251 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 252 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 253 | + ], |
|
| 254 | + 'key' => [ |
|
| 255 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 256 | + 'KEY login' => 'login', |
|
| 257 | + 'KEY statut' => 'statut', |
|
| 258 | + 'KEY en_ligne' => 'en_ligne', |
|
| 259 | + ], |
|
| 260 | + 'join' => [ |
|
| 261 | + 'id_auteur' => 'id_auteur', |
|
| 262 | + 'login' => 'login' |
|
| 263 | + ], |
|
| 264 | + 'rechercher_champs' => [ |
|
| 265 | + 'nom' => 5, |
|
| 266 | + 'bio' => 1, |
|
| 267 | + 'email' => 1, |
|
| 268 | + 'nom_site' => 1, |
|
| 269 | + 'url_site' => 1, |
|
| 270 | + 'login' => 1 |
|
| 271 | + ], |
|
| 272 | + // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 273 | + // et avoir des articles publies |
|
| 274 | + 'statut' => [ |
|
| 275 | + [ |
|
| 276 | + 'champ' => 'statut', |
|
| 277 | + 'publie' => '!5poubelle', |
|
| 278 | + 'previsu' => '!5poubelle', |
|
| 279 | + 'exception' => 'statut' |
|
| 280 | + ], |
|
| 281 | + [ |
|
| 282 | + 'champ' => [ |
|
| 283 | + ['spip_auteurs_liens', 'id_auteur'], |
|
| 284 | + [ |
|
| 285 | + 'spip_articles', |
|
| 286 | + ['id_objet', 'id_article', 'objet', 'article'] |
|
| 287 | + ], |
|
| 288 | + 'statut' |
|
| 289 | + ], |
|
| 290 | + 'publie' => 'publie', |
|
| 291 | + 'previsu' => '!', |
|
| 292 | + 'post_date' => 'date', |
|
| 293 | + 'exception' => ['statut', 'lien', 'tout'] |
|
| 294 | + ], |
|
| 295 | + ], |
|
| 296 | + 'statut_images' => [ |
|
| 297 | + 'auteur-6forum-16.png', |
|
| 298 | + '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 299 | + '1comite' => 'auteur-1comite-16.png', |
|
| 300 | + '6forum' => 'auteur-6forum-16.png', |
|
| 301 | + '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 302 | + 'nouveau' => '' |
|
| 303 | + ], |
|
| 304 | + 'statut_titres' => [ |
|
| 305 | + 'titre_image_visiteur', |
|
| 306 | + '0minirezo' => 'titre_image_administrateur', |
|
| 307 | + '1comite' => 'titre_image_redacteur_02', |
|
| 308 | + '6forum' => 'titre_image_visiteur', |
|
| 309 | + '5poubelle' => 'titre_image_auteur_supprime', |
|
| 310 | + ], |
|
| 311 | + 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 312 | + ], |
|
| 313 | + ], |
|
| 314 | + 'spip_rubriques' => [ |
|
| 315 | + 'page' => 'rubrique', |
|
| 316 | + 'url_voir' => 'rubrique', |
|
| 317 | + 'url_edit' => 'rubrique_edit', |
|
| 318 | + 'texte_retour' => 'icone_retour', |
|
| 319 | + 'texte_objets' => 'public:rubriques', |
|
| 320 | + 'texte_objet' => 'public:rubrique', |
|
| 321 | + 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 322 | + 'texte_creer' => 'icone_creer_rubrique', |
|
| 323 | + 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 324 | + 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 325 | + 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 326 | + 'info_1_objet' => 'info_1_rubrique', |
|
| 327 | + 'info_nb_objets' => 'info_nb_rubriques', |
|
| 328 | + 'texte_logo_objet' => 'logo_rubrique', |
|
| 329 | + 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 330 | + 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 331 | + 'titre' => 'titre, lang', |
|
| 332 | + 'date' => 'date', |
|
| 333 | + 'principale' => 'oui', |
|
| 334 | + 'introduction_longueur' => '600', |
|
| 335 | + 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 336 | + 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 337 | + 'field' => [ |
|
| 338 | + 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 339 | + 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 340 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 341 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 342 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 343 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 344 | + 'maj' => 'TIMESTAMP', |
|
| 345 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 346 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 347 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 348 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 349 | + 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 350 | + 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 351 | + 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 352 | + ], |
|
| 353 | + 'key' => [ |
|
| 354 | + 'PRIMARY KEY' => 'id_rubrique', |
|
| 355 | + 'KEY lang' => 'lang', |
|
| 356 | + 'KEY id_parent' => 'id_parent', |
|
| 357 | + ], |
|
| 358 | + 'parent' => [ |
|
| 359 | + ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 360 | + ], |
|
| 361 | + 'rechercher_champs' => [ |
|
| 362 | + 'titre' => 8, |
|
| 363 | + 'descriptif' => 5, |
|
| 364 | + 'texte' => 1 |
|
| 365 | + ], |
|
| 366 | + 'statut' => [ |
|
| 367 | + [ |
|
| 368 | + 'champ' => 'statut', |
|
| 369 | + 'publie' => 'publie', |
|
| 370 | + 'previsu' => '!', |
|
| 371 | + 'exception' => ['statut', 'tout'] |
|
| 372 | + ], |
|
| 373 | + ], |
|
| 374 | + 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 375 | + ], |
|
| 376 | + ], |
|
| 377 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 378 | + ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 379 | + ]; |
|
| 380 | + |
|
| 381 | + // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 382 | + // initialiser la signature |
|
| 383 | + $md5 = md5(serialize($infos_tables)); |
|
| 384 | + |
|
| 385 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 386 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 387 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 388 | + |
|
| 389 | + // completer les informations manquantes ou implicites |
|
| 390 | + $all = []; |
|
| 391 | + foreach (array_keys($infos_tables) as $t) { |
|
| 392 | + // les cles numeriques servent a declarer |
|
| 393 | + // les proprietes applicables a tous les objets |
|
| 394 | + // on les mets de cote |
|
| 395 | + if (is_numeric($t)) { |
|
| 396 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 397 | + unset($infos_tables[$t]); |
|
| 398 | + } else { |
|
| 399 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + // repercuter les proprietes generales communes a tous les objets |
|
| 404 | + foreach (array_keys($infos_tables) as $t) { |
|
| 405 | + foreach ($all as $i => $v) { |
|
| 406 | + if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 407 | + $add = $all[$i]; |
|
| 408 | + // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 409 | + // pour les declarations generiques avec cles numeriques |
|
| 410 | + if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0) { |
|
| 411 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 412 | + foreach ($doublons as $d) { |
|
| 413 | + if ( |
|
| 414 | + is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 415 | + and is_numeric($k = array_search($d, $add)) |
|
| 416 | + ) { |
|
| 417 | + unset($add[$k]); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 422 | + } else { |
|
| 423 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 424 | + $infos_tables[$t][$i] ?? [], |
|
| 425 | + $all[$i] |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // completer les tables principales et auxiliaires |
|
| 432 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 433 | + // pour assurer la compat en transition |
|
| 434 | + foreach ($infos_tables as $table => $infos) { |
|
| 435 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 436 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 437 | + // qui a ete appelle avant |
|
| 438 | + $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 439 | + // l'ajouter au tableau |
|
| 440 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 441 | + if (isset($infos['field']) and isset($infos['key'])) { |
|
| 442 | + foreach (['field', 'key', 'join'] as $k) { |
|
| 443 | + if (isset($infos_tables[$table][$k])) { |
|
| 444 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } else { |
|
| 448 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 449 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 450 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 451 | + } |
|
| 452 | + if (is_countable($mem) ? count($mem) : 0) { |
|
| 453 | + foreach (array_keys($mem) as $k) { |
|
| 454 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 455 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 456 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 457 | + $mem[$k] |
|
| 458 | + ); |
|
| 459 | + } else { |
|
| 460 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // recuperer les interfaces (table_titre, table_date) |
|
| 467 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 468 | + // dans le pipeline de declarer_tables_interfaces |
|
| 469 | + include_spip('public/interfaces'); |
|
| 470 | + foreach (array_keys($infos_tables) as $t) { |
|
| 471 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $deja_la = false; |
|
| 475 | + // signature |
|
| 476 | + $md5 = md5(serialize($infos_tables)); |
|
| 477 | + } |
|
| 478 | + if ($table_sql === '::md5') { |
|
| 479 | + return $md5; |
|
| 480 | + } |
|
| 481 | + if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 482 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 483 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 484 | + |
|
| 485 | + return $desc; |
|
| 486 | + } |
|
| 487 | + if ($table_sql) { |
|
| 488 | + return $infos_tables[$table_sql] ?? []; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return $infos_tables; |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -503,27 +503,27 @@ discard block |
||
| 503 | 503 | **/ |
| 504 | 504 | function base_serial(&$tables_principales) { |
| 505 | 505 | |
| 506 | - $spip_jobs = [ |
|
| 507 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 508 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 509 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 510 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 511 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 512 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 513 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 514 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 515 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 516 | - ]; |
|
| 517 | - |
|
| 518 | - $spip_jobs_key = [ |
|
| 519 | - 'PRIMARY KEY' => 'id_job', |
|
| 520 | - 'KEY date' => 'date', |
|
| 521 | - 'KEY status' => 'status', |
|
| 522 | - ]; |
|
| 523 | - |
|
| 524 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 525 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 526 | - $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 506 | + $spip_jobs = [ |
|
| 507 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 508 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 509 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 510 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 511 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 512 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 513 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 514 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 515 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 516 | + ]; |
|
| 517 | + |
|
| 518 | + $spip_jobs_key = [ |
|
| 519 | + 'PRIMARY KEY' => 'id_job', |
|
| 520 | + 'KEY date' => 'date', |
|
| 521 | + 'KEY status' => 'status', |
|
| 522 | + ]; |
|
| 523 | + |
|
| 524 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 525 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 526 | + $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | |
@@ -535,71 +535,71 @@ discard block |
||
| 535 | 535 | * @return void |
| 536 | 536 | **/ |
| 537 | 537 | function base_auxiliaires(&$tables_auxiliaires) { |
| 538 | - $spip_resultats = [ |
|
| 539 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 540 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 541 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 542 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 543 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 544 | - 'maj' => 'TIMESTAMP' |
|
| 545 | - ]; |
|
| 546 | - |
|
| 547 | - $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 548 | - ]; |
|
| 549 | - |
|
| 550 | - $spip_auteurs_liens = [ |
|
| 551 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 552 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 553 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 554 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 555 | - ]; |
|
| 556 | - |
|
| 557 | - $spip_auteurs_liens_key = [ |
|
| 558 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 559 | - 'KEY id_auteur' => 'id_auteur', |
|
| 560 | - 'KEY id_objet' => 'id_objet', |
|
| 561 | - 'KEY objet' => 'objet', |
|
| 562 | - ]; |
|
| 563 | - |
|
| 564 | - $spip_meta = [ |
|
| 565 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 566 | - 'valeur' => "text DEFAULT ''", |
|
| 567 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 568 | - 'maj' => 'TIMESTAMP' |
|
| 569 | - ]; |
|
| 570 | - |
|
| 571 | - $spip_meta_key = [ |
|
| 572 | - 'PRIMARY KEY' => 'nom' |
|
| 573 | - ]; |
|
| 574 | - |
|
| 575 | - $spip_jobs_liens = [ |
|
| 576 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 577 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 578 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 579 | - ]; |
|
| 580 | - |
|
| 581 | - $spip_jobs_liens_key = [ |
|
| 582 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 583 | - 'KEY id_job' => 'id_job' |
|
| 584 | - ]; |
|
| 585 | - |
|
| 586 | - $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 587 | - 'field' => &$spip_auteurs_liens, |
|
| 588 | - 'key' => &$spip_auteurs_liens_key |
|
| 589 | - ]; |
|
| 590 | - |
|
| 591 | - $tables_auxiliaires['spip_meta'] = [ |
|
| 592 | - 'field' => &$spip_meta, |
|
| 593 | - 'key' => &$spip_meta_key |
|
| 594 | - ]; |
|
| 595 | - $tables_auxiliaires['spip_resultats'] = [ |
|
| 596 | - 'field' => &$spip_resultats, |
|
| 597 | - 'key' => &$spip_resultats_key |
|
| 598 | - ]; |
|
| 599 | - $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 600 | - 'field' => &$spip_jobs_liens, |
|
| 601 | - 'key' => &$spip_jobs_liens_key |
|
| 602 | - ]; |
|
| 538 | + $spip_resultats = [ |
|
| 539 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 540 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 541 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 542 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 543 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 544 | + 'maj' => 'TIMESTAMP' |
|
| 545 | + ]; |
|
| 546 | + |
|
| 547 | + $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 548 | + ]; |
|
| 549 | + |
|
| 550 | + $spip_auteurs_liens = [ |
|
| 551 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 552 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 553 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 554 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 555 | + ]; |
|
| 556 | + |
|
| 557 | + $spip_auteurs_liens_key = [ |
|
| 558 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 559 | + 'KEY id_auteur' => 'id_auteur', |
|
| 560 | + 'KEY id_objet' => 'id_objet', |
|
| 561 | + 'KEY objet' => 'objet', |
|
| 562 | + ]; |
|
| 563 | + |
|
| 564 | + $spip_meta = [ |
|
| 565 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 566 | + 'valeur' => "text DEFAULT ''", |
|
| 567 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 568 | + 'maj' => 'TIMESTAMP' |
|
| 569 | + ]; |
|
| 570 | + |
|
| 571 | + $spip_meta_key = [ |
|
| 572 | + 'PRIMARY KEY' => 'nom' |
|
| 573 | + ]; |
|
| 574 | + |
|
| 575 | + $spip_jobs_liens = [ |
|
| 576 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 577 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 578 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 579 | + ]; |
|
| 580 | + |
|
| 581 | + $spip_jobs_liens_key = [ |
|
| 582 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 583 | + 'KEY id_job' => 'id_job' |
|
| 584 | + ]; |
|
| 585 | + |
|
| 586 | + $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 587 | + 'field' => &$spip_auteurs_liens, |
|
| 588 | + 'key' => &$spip_auteurs_liens_key |
|
| 589 | + ]; |
|
| 590 | + |
|
| 591 | + $tables_auxiliaires['spip_meta'] = [ |
|
| 592 | + 'field' => &$spip_meta, |
|
| 593 | + 'key' => &$spip_meta_key |
|
| 594 | + ]; |
|
| 595 | + $tables_auxiliaires['spip_resultats'] = [ |
|
| 596 | + 'field' => &$spip_resultats, |
|
| 597 | + 'key' => &$spip_resultats_key |
|
| 598 | + ]; |
|
| 599 | + $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 600 | + 'field' => &$spip_jobs_liens, |
|
| 601 | + 'key' => &$spip_jobs_liens_key |
|
| 602 | + ]; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | |
@@ -656,129 +656,129 @@ discard block |
||
| 656 | 656 | * @return array |
| 657 | 657 | */ |
| 658 | 658 | function renseigner_table_objet_sql($table_sql, &$infos) { |
| 659 | - if (!isset($infos['type'])) { |
|
| 660 | - // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 661 | - // s'en servir pour extrapoler le type |
|
| 662 | - if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 663 | - $primary = $infos['key']['PRIMARY KEY']; |
|
| 664 | - $primary = explode(',', $primary); |
|
| 665 | - $primary = reset($primary); |
|
| 666 | - $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 667 | - } else { |
|
| 668 | - $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - if (!isset($infos['type_surnoms'])) { |
|
| 672 | - $infos['type_surnoms'] = []; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - if (!isset($infos['table_objet'])) { |
|
| 676 | - $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 677 | - } |
|
| 678 | - if (!isset($infos['table_objet_surnoms'])) { |
|
| 679 | - $infos['table_objet_surnoms'] = []; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if (!isset($infos['principale'])) { |
|
| 683 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 687 | - // et dans une boucle {principale=oui} |
|
| 688 | - $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false); |
|
| 689 | - |
|
| 690 | - // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 691 | - // et dans une boucle {editable=oui} |
|
| 692 | - if (!isset($infos['editable'])) { |
|
| 693 | - $infos['editable'] = 'oui'; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false); |
|
| 697 | - |
|
| 698 | - // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 699 | - // seules les exceptions sont donc a declarer |
|
| 700 | - if (!isset($infos['page'])) { |
|
| 701 | - $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - if (!isset($infos['url_voir'])) { |
|
| 705 | - $infos['url_voir'] = $infos['type']; |
|
| 706 | - } |
|
| 707 | - if (!isset($infos['url_edit'])) { |
|
| 708 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 709 | - } |
|
| 710 | - if (!isset($infos['icone_objet'])) { |
|
| 711 | - $infos['icone_objet'] = $infos['type']; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // chaines de langue |
|
| 715 | - // par defaut : objet:icone_xxx_objet |
|
| 716 | - if (!isset($infos['texte_retour'])) { |
|
| 717 | - $infos['texte_retour'] = 'icone_retour'; |
|
| 718 | - } |
|
| 719 | - if (!isset($infos['texte_modifier'])) { |
|
| 720 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 721 | - } |
|
| 722 | - if (!isset($infos['texte_creer'])) { |
|
| 723 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 724 | - } |
|
| 725 | - if (!isset($infos['texte_creer_associer'])) { |
|
| 726 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 727 | - } |
|
| 728 | - if (!isset($infos['texte_ajouter'])) { |
|
| 729 | - // Ajouter un X |
|
| 730 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 731 | - } |
|
| 732 | - if (!isset($infos['texte_objets'])) { |
|
| 733 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 734 | - } |
|
| 735 | - if (!isset($infos['texte_objet'])) { |
|
| 736 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 737 | - } |
|
| 738 | - if (!isset($infos['texte_logo_objet'])) { |
|
| 739 | - // objet:titre_logo_objet "Logo de ce X" |
|
| 740 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 741 | - } |
|
| 742 | - if (!isset($infos['texte_langue_objet'])) { |
|
| 743 | - // objet:texte_langue_objet "Langue de ce X" |
|
| 744 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 745 | - } |
|
| 746 | - if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 747 | - // "Ce X est une traduction du X numéro :" |
|
| 748 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - // objet:info_aucun_objet |
|
| 752 | - if (!isset($infos['info_aucun_objet'])) { |
|
| 753 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 754 | - } |
|
| 755 | - // objet:info_1_objet |
|
| 756 | - if (!isset($infos['info_1_objet'])) { |
|
| 757 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 758 | - } |
|
| 759 | - // objet:info_nb_objets |
|
| 760 | - if (!isset($infos['info_nb_objets'])) { |
|
| 761 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - if (!isset($infos['champs_editables'])) { |
|
| 765 | - $infos['champs_editables'] = []; |
|
| 766 | - } |
|
| 767 | - if (!isset($infos['champs_versionnes'])) { |
|
| 768 | - $infos['champs_versionnes'] = []; |
|
| 769 | - } |
|
| 770 | - if (!isset($infos['rechercher_champs'])) { |
|
| 771 | - $infos['rechercher_champs'] = []; |
|
| 772 | - } |
|
| 773 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 774 | - $infos['rechercher_jointures'] = []; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - if (!isset($infos['modeles'])) { |
|
| 778 | - $infos['modeles'] = [$infos['type']]; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - return $infos; |
|
| 659 | + if (!isset($infos['type'])) { |
|
| 660 | + // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 661 | + // s'en servir pour extrapoler le type |
|
| 662 | + if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 663 | + $primary = $infos['key']['PRIMARY KEY']; |
|
| 664 | + $primary = explode(',', $primary); |
|
| 665 | + $primary = reset($primary); |
|
| 666 | + $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 667 | + } else { |
|
| 668 | + $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + if (!isset($infos['type_surnoms'])) { |
|
| 672 | + $infos['type_surnoms'] = []; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + if (!isset($infos['table_objet'])) { |
|
| 676 | + $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 677 | + } |
|
| 678 | + if (!isset($infos['table_objet_surnoms'])) { |
|
| 679 | + $infos['table_objet_surnoms'] = []; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if (!isset($infos['principale'])) { |
|
| 683 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 687 | + // et dans une boucle {principale=oui} |
|
| 688 | + $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false); |
|
| 689 | + |
|
| 690 | + // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 691 | + // et dans une boucle {editable=oui} |
|
| 692 | + if (!isset($infos['editable'])) { |
|
| 693 | + $infos['editable'] = 'oui'; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false); |
|
| 697 | + |
|
| 698 | + // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 699 | + // seules les exceptions sont donc a declarer |
|
| 700 | + if (!isset($infos['page'])) { |
|
| 701 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + if (!isset($infos['url_voir'])) { |
|
| 705 | + $infos['url_voir'] = $infos['type']; |
|
| 706 | + } |
|
| 707 | + if (!isset($infos['url_edit'])) { |
|
| 708 | + $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 709 | + } |
|
| 710 | + if (!isset($infos['icone_objet'])) { |
|
| 711 | + $infos['icone_objet'] = $infos['type']; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // chaines de langue |
|
| 715 | + // par defaut : objet:icone_xxx_objet |
|
| 716 | + if (!isset($infos['texte_retour'])) { |
|
| 717 | + $infos['texte_retour'] = 'icone_retour'; |
|
| 718 | + } |
|
| 719 | + if (!isset($infos['texte_modifier'])) { |
|
| 720 | + $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 721 | + } |
|
| 722 | + if (!isset($infos['texte_creer'])) { |
|
| 723 | + $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 724 | + } |
|
| 725 | + if (!isset($infos['texte_creer_associer'])) { |
|
| 726 | + $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 727 | + } |
|
| 728 | + if (!isset($infos['texte_ajouter'])) { |
|
| 729 | + // Ajouter un X |
|
| 730 | + $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 731 | + } |
|
| 732 | + if (!isset($infos['texte_objets'])) { |
|
| 733 | + $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 734 | + } |
|
| 735 | + if (!isset($infos['texte_objet'])) { |
|
| 736 | + $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 737 | + } |
|
| 738 | + if (!isset($infos['texte_logo_objet'])) { |
|
| 739 | + // objet:titre_logo_objet "Logo de ce X" |
|
| 740 | + $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 741 | + } |
|
| 742 | + if (!isset($infos['texte_langue_objet'])) { |
|
| 743 | + // objet:texte_langue_objet "Langue de ce X" |
|
| 744 | + $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 745 | + } |
|
| 746 | + if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 747 | + // "Ce X est une traduction du X numéro :" |
|
| 748 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + // objet:info_aucun_objet |
|
| 752 | + if (!isset($infos['info_aucun_objet'])) { |
|
| 753 | + $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 754 | + } |
|
| 755 | + // objet:info_1_objet |
|
| 756 | + if (!isset($infos['info_1_objet'])) { |
|
| 757 | + $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 758 | + } |
|
| 759 | + // objet:info_nb_objets |
|
| 760 | + if (!isset($infos['info_nb_objets'])) { |
|
| 761 | + $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + if (!isset($infos['champs_editables'])) { |
|
| 765 | + $infos['champs_editables'] = []; |
|
| 766 | + } |
|
| 767 | + if (!isset($infos['champs_versionnes'])) { |
|
| 768 | + $infos['champs_versionnes'] = []; |
|
| 769 | + } |
|
| 770 | + if (!isset($infos['rechercher_champs'])) { |
|
| 771 | + $infos['rechercher_champs'] = []; |
|
| 772 | + } |
|
| 773 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 774 | + $infos['rechercher_jointures'] = []; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + if (!isset($infos['modeles'])) { |
|
| 778 | + $infos['modeles'] = [$infos['type']]; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + return $infos; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
@@ -795,30 +795,30 @@ discard block |
||
| 795 | 795 | * @return array |
| 796 | 796 | */ |
| 797 | 797 | function renseigner_table_objet_interfaces($table_sql, &$infos) { |
| 798 | - if (!isset($infos['titre'])) { |
|
| 799 | - if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 800 | - $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 801 | - } else { |
|
| 802 | - $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 803 | - $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - if (!isset($infos['date'])) { |
|
| 807 | - if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 808 | - $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 809 | - } else { |
|
| 810 | - $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 815 | - $infos['tables_jointures'] ??= []; |
|
| 816 | - |
|
| 817 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - return $infos; |
|
| 798 | + if (!isset($infos['titre'])) { |
|
| 799 | + if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 800 | + $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 801 | + } else { |
|
| 802 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 803 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + if (!isset($infos['date'])) { |
|
| 807 | + if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 808 | + $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 809 | + } else { |
|
| 810 | + $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 815 | + $infos['tables_jointures'] ??= []; |
|
| 816 | + |
|
| 817 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + return $infos; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -829,13 +829,13 @@ discard block |
||
| 829 | 829 | * Liste et descriptions des tables principales |
| 830 | 830 | **/ |
| 831 | 831 | function lister_tables_principales() { |
| 832 | - static $done = false; |
|
| 833 | - if (!$done or !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 834 | - lister_tables_objets_sql(); |
|
| 835 | - $done = true; |
|
| 836 | - } |
|
| 832 | + static $done = false; |
|
| 833 | + if (!$done or !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 834 | + lister_tables_objets_sql(); |
|
| 835 | + $done = true; |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - return $GLOBALS['tables_principales']; |
|
| 838 | + return $GLOBALS['tables_principales']; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -846,13 +846,13 @@ discard block |
||
| 846 | 846 | * Liste et descriptions des tables auxiliaires |
| 847 | 847 | **/ |
| 848 | 848 | function lister_tables_auxiliaires() { |
| 849 | - static $done = false; |
|
| 850 | - if (!$done or !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 851 | - lister_tables_objets_sql(); |
|
| 852 | - $done = true; |
|
| 853 | - } |
|
| 849 | + static $done = false; |
|
| 850 | + if (!$done or !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 851 | + lister_tables_objets_sql(); |
|
| 852 | + $done = true; |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | - return $GLOBALS['tables_auxiliaires']; |
|
| 855 | + return $GLOBALS['tables_auxiliaires']; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -861,45 +861,45 @@ discard block |
||
| 861 | 861 | * @return array |
| 862 | 862 | */ |
| 863 | 863 | function lister_tables_objets_surnoms() { |
| 864 | - static $surnoms = null; |
|
| 865 | - static $md5 = null; |
|
| 866 | - if ( |
|
| 867 | - !$surnoms |
|
| 868 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 869 | - ) { |
|
| 870 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 871 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 872 | - // declarer_table_objets_sql |
|
| 873 | - $surnoms = pipeline( |
|
| 874 | - 'declarer_tables_objets_surnoms', |
|
| 875 | - [ |
|
| 876 | - # pour les modeles |
|
| 877 | - # a enlever ? |
|
| 878 | - 'doc' => 'documents', |
|
| 879 | - 'img' => 'documents', |
|
| 880 | - 'emb' => 'documents', |
|
| 881 | - ] |
|
| 882 | - ); |
|
| 883 | - $infos_tables = lister_tables_objets_sql(); |
|
| 884 | - foreach ($infos_tables as $t => $infos) { |
|
| 885 | - // cas de base type=>table |
|
| 886 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 887 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 888 | - // optimisations pour table_objet |
|
| 889 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 890 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 891 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 892 | - if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 893 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 894 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - return $surnoms; |
|
| 864 | + static $surnoms = null; |
|
| 865 | + static $md5 = null; |
|
| 866 | + if ( |
|
| 867 | + !$surnoms |
|
| 868 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 869 | + ) { |
|
| 870 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 871 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 872 | + // declarer_table_objets_sql |
|
| 873 | + $surnoms = pipeline( |
|
| 874 | + 'declarer_tables_objets_surnoms', |
|
| 875 | + [ |
|
| 876 | + # pour les modeles |
|
| 877 | + # a enlever ? |
|
| 878 | + 'doc' => 'documents', |
|
| 879 | + 'img' => 'documents', |
|
| 880 | + 'emb' => 'documents', |
|
| 881 | + ] |
|
| 882 | + ); |
|
| 883 | + $infos_tables = lister_tables_objets_sql(); |
|
| 884 | + foreach ($infos_tables as $t => $infos) { |
|
| 885 | + // cas de base type=>table |
|
| 886 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 887 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 888 | + // optimisations pour table_objet |
|
| 889 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 890 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 891 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 892 | + if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 893 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 894 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + return $surnoms; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -908,35 +908,35 @@ discard block |
||
| 908 | 908 | * @return array |
| 909 | 909 | */ |
| 910 | 910 | function lister_types_surnoms() { |
| 911 | - static $surnoms = null; |
|
| 912 | - static $md5 = null; |
|
| 913 | - if ( |
|
| 914 | - !$surnoms |
|
| 915 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 916 | - ) { |
|
| 917 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 918 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 919 | - // declarer_table_objets_sql |
|
| 920 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 921 | - $infos_tables = lister_tables_objets_sql(); |
|
| 922 | - foreach ($infos_tables as $t => $infos) { |
|
| 923 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 924 | - // optimisations pour objet_type |
|
| 925 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 926 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 927 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 928 | - // surnoms declares |
|
| 929 | - if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 930 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 931 | - $surnoms[$surnom] = $infos['type']; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - return $surnoms; |
|
| 911 | + static $surnoms = null; |
|
| 912 | + static $md5 = null; |
|
| 913 | + if ( |
|
| 914 | + !$surnoms |
|
| 915 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 916 | + ) { |
|
| 917 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 918 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 919 | + // declarer_table_objets_sql |
|
| 920 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 921 | + $infos_tables = lister_tables_objets_sql(); |
|
| 922 | + foreach ($infos_tables as $t => $infos) { |
|
| 923 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 924 | + // optimisations pour objet_type |
|
| 925 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 926 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 927 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 928 | + // surnoms declares |
|
| 929 | + if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 930 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 931 | + $surnoms[$surnom] = $infos['type']; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + return $surnoms; |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | /** |
@@ -950,22 +950,22 @@ discard block |
||
| 950 | 950 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 951 | 951 | **/ |
| 952 | 952 | function lister_tables_spip($serveur = '') { |
| 953 | - static $tables = []; |
|
| 954 | - if (!isset($tables[$serveur])) { |
|
| 955 | - $tables[$serveur] = []; |
|
| 956 | - if (!function_exists('sql_alltable')) { |
|
| 957 | - include_spip('base/abstract_sql'); |
|
| 958 | - } |
|
| 959 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 960 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 961 | - $spip = $connexion['prefixe'] . '_'; |
|
| 962 | - foreach ($ts as $t) { |
|
| 963 | - $t = substr($t, strlen($spip)); |
|
| 964 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return $tables[$serveur]; |
|
| 953 | + static $tables = []; |
|
| 954 | + if (!isset($tables[$serveur])) { |
|
| 955 | + $tables[$serveur] = []; |
|
| 956 | + if (!function_exists('sql_alltable')) { |
|
| 957 | + include_spip('base/abstract_sql'); |
|
| 958 | + } |
|
| 959 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 960 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 961 | + $spip = $connexion['prefixe'] . '_'; |
|
| 962 | + foreach ($ts as $t) { |
|
| 963 | + $t = substr($t, strlen($spip)); |
|
| 964 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return $tables[$serveur]; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | |
@@ -980,18 +980,18 @@ discard block |
||
| 980 | 980 | * Couples (nom de la table SQL => même nom) |
| 981 | 981 | **/ |
| 982 | 982 | function lister_toutes_tables($serveur) { |
| 983 | - static $tables = []; |
|
| 984 | - if (!isset($tables[$serveur])) { |
|
| 985 | - $tables[$serveur] = []; |
|
| 986 | - if (!function_exists('sql_alltable')) { |
|
| 987 | - include_spip('base/abstract_sql'); |
|
| 988 | - } |
|
| 989 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 990 | - foreach ($ts as $t) { |
|
| 991 | - $tables[$serveur][$t] = $t; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - return $tables[$serveur]; |
|
| 983 | + static $tables = []; |
|
| 984 | + if (!isset($tables[$serveur])) { |
|
| 985 | + $tables[$serveur] = []; |
|
| 986 | + if (!function_exists('sql_alltable')) { |
|
| 987 | + include_spip('base/abstract_sql'); |
|
| 988 | + } |
|
| 989 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 990 | + foreach ($ts as $t) { |
|
| 991 | + $tables[$serveur][$t] = $t; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + return $tables[$serveur]; |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
@@ -1012,39 +1012,39 @@ discard block |
||
| 1012 | 1012 | **/ |
| 1013 | 1013 | function table_objet(string $type, string $serveur = ''): string { |
| 1014 | 1014 | |
| 1015 | - if ($type) { |
|
| 1016 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1017 | - } |
|
| 1018 | - if (!strlen($type)) { |
|
| 1019 | - return ''; |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1023 | - if (isset($surnoms[$type])) { |
|
| 1024 | - return $surnoms[$type]; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - if ($serveur !== false) { |
|
| 1028 | - $t = lister_tables_spip($serveur); |
|
| 1029 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1030 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1031 | - if ( |
|
| 1032 | - (isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1033 | - and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1034 | - ) { |
|
| 1035 | - return $desc['id_table']; |
|
| 1036 | - } elseif ( |
|
| 1037 | - (isset($t[$type]) or in_array($type, $t)) |
|
| 1038 | - and ($desc = $trouver_table($type, $serveur)) |
|
| 1039 | - ) { |
|
| 1040 | - return $desc['id_table']; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1044 | - #spip_log(debug_backtrace(),'db'); |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1015 | + if ($type) { |
|
| 1016 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1017 | + } |
|
| 1018 | + if (!strlen($type)) { |
|
| 1019 | + return ''; |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1023 | + if (isset($surnoms[$type])) { |
|
| 1024 | + return $surnoms[$type]; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + if ($serveur !== false) { |
|
| 1028 | + $t = lister_tables_spip($serveur); |
|
| 1029 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1030 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1031 | + if ( |
|
| 1032 | + (isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1033 | + and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1034 | + ) { |
|
| 1035 | + return $desc['id_table']; |
|
| 1036 | + } elseif ( |
|
| 1037 | + (isset($t[$type]) or in_array($type, $t)) |
|
| 1038 | + and ($desc = $trouver_table($type, $serveur)) |
|
| 1039 | + ) { |
|
| 1040 | + return $desc['id_table']; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1044 | + #spip_log(debug_backtrace(),'db'); |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | /** |
@@ -1065,33 +1065,33 @@ discard block |
||
| 1065 | 1065 | **/ |
| 1066 | 1066 | function table_objet_sql(string $type, string $serveur = ''): string { |
| 1067 | 1067 | |
| 1068 | - $nom = table_objet($type, $serveur); |
|
| 1069 | - if (!strlen($nom)) { |
|
| 1070 | - return ''; |
|
| 1071 | - } |
|
| 1072 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1073 | - // eviter de multiples inclusions |
|
| 1074 | - include_spip('public/interfaces'); |
|
| 1075 | - } |
|
| 1076 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1077 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1078 | - $nom = "spip_$nom"; |
|
| 1079 | - } else { |
|
| 1080 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1081 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1082 | - $nom = "spip_$nom"; |
|
| 1083 | - } elseif ($serveur !== false) { |
|
| 1084 | - $t = lister_tables_spip($serveur); |
|
| 1085 | - if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1086 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1087 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1088 | - return $desc['table_sql']; |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - return $nom; |
|
| 1068 | + $nom = table_objet($type, $serveur); |
|
| 1069 | + if (!strlen($nom)) { |
|
| 1070 | + return ''; |
|
| 1071 | + } |
|
| 1072 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1073 | + // eviter de multiples inclusions |
|
| 1074 | + include_spip('public/interfaces'); |
|
| 1075 | + } |
|
| 1076 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1077 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1078 | + $nom = "spip_$nom"; |
|
| 1079 | + } else { |
|
| 1080 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1081 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1082 | + $nom = "spip_$nom"; |
|
| 1083 | + } elseif ($serveur !== false) { |
|
| 1084 | + $t = lister_tables_spip($serveur); |
|
| 1085 | + if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1086 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1087 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1088 | + return $desc['table_sql']; |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + return $nom; |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | /** |
@@ -1110,35 +1110,35 @@ discard block |
||
| 1110 | 1110 | * Nom de la clé primaire |
| 1111 | 1111 | **/ |
| 1112 | 1112 | function id_table_objet($type, $serveur = '') { |
| 1113 | - static $trouver_table = null; |
|
| 1114 | - $type = objet_type($type, $serveur); |
|
| 1115 | - if (!$type) { |
|
| 1116 | - return null; |
|
| 1117 | - } |
|
| 1118 | - $t = table_objet($type); |
|
| 1119 | - if (!$trouver_table) { |
|
| 1120 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - $ts = lister_tables_spip($serveur); |
|
| 1124 | - if ( |
|
| 1125 | - in_array($t, $ts) |
|
| 1126 | - or in_array($t, lister_toutes_tables($serveur)) |
|
| 1127 | - ) { |
|
| 1128 | - $desc = $trouver_table($t, $serveur); |
|
| 1129 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1130 | - return $desc['key']['PRIMARY KEY']; |
|
| 1131 | - } |
|
| 1132 | - if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1133 | - return "id_$type"; |
|
| 1134 | - } |
|
| 1135 | - // sinon renvoyer le premier champ de la table... |
|
| 1136 | - $keys = array_keys($desc['field']); |
|
| 1137 | - |
|
| 1138 | - return array_shift($keys); |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - return "id_$type"; |
|
| 1113 | + static $trouver_table = null; |
|
| 1114 | + $type = objet_type($type, $serveur); |
|
| 1115 | + if (!$type) { |
|
| 1116 | + return null; |
|
| 1117 | + } |
|
| 1118 | + $t = table_objet($type); |
|
| 1119 | + if (!$trouver_table) { |
|
| 1120 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + $ts = lister_tables_spip($serveur); |
|
| 1124 | + if ( |
|
| 1125 | + in_array($t, $ts) |
|
| 1126 | + or in_array($t, lister_toutes_tables($serveur)) |
|
| 1127 | + ) { |
|
| 1128 | + $desc = $trouver_table($t, $serveur); |
|
| 1129 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1130 | + return $desc['key']['PRIMARY KEY']; |
|
| 1131 | + } |
|
| 1132 | + if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1133 | + return "id_$type"; |
|
| 1134 | + } |
|
| 1135 | + // sinon renvoyer le premier champ de la table... |
|
| 1136 | + $keys = array_keys($desc['field']); |
|
| 1137 | + |
|
| 1138 | + return array_shift($keys); |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + return "id_$type"; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | /** |
@@ -1157,60 +1157,60 @@ discard block |
||
| 1157 | 1157 | * Type de l'objet |
| 1158 | 1158 | **/ |
| 1159 | 1159 | function objet_type(string $table_objet, string $serveur = ''): ?string { |
| 1160 | - if (!$table_objet) { |
|
| 1161 | - return null; |
|
| 1162 | - } |
|
| 1163 | - $surnoms = lister_types_surnoms(); |
|
| 1164 | - |
|
| 1165 | - // scenario de base |
|
| 1166 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1167 | - // et la marque du pluriel |
|
| 1168 | - // on accepte id_xx en entree aussi |
|
| 1169 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1170 | - if (isset($surnoms[$type])) { |
|
| 1171 | - return $surnoms[$type]; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // securite : eliminer les caracteres non \w |
|
| 1175 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1176 | - |
|
| 1177 | - // si le type redonne bien la table c'est bon |
|
| 1178 | - // oui si table_objet ressemblait deja a un type |
|
| 1179 | - if ( |
|
| 1180 | - $type == $table_objet |
|
| 1181 | - or (table_objet($type, $serveur) == $table_objet) |
|
| 1182 | - or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1183 | - ) { |
|
| 1184 | - return $type; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // si on ne veut pas chercher en base |
|
| 1188 | - if ($serveur === false) { |
|
| 1189 | - return $type; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1193 | - // car le s a la fin est incertain |
|
| 1194 | - // notamment en cas de pluriel derogatoire |
|
| 1195 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1196 | - // une declaration jeu => jeux, journal => journaux |
|
| 1197 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1198 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1199 | - $ts = lister_tables_spip($serveur); |
|
| 1200 | - $desc = false; |
|
| 1201 | - if (in_array($table_objet, $ts)) { |
|
| 1202 | - $desc = $trouver_table($table_objet); |
|
| 1203 | - } |
|
| 1204 | - if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1205 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1206 | - } |
|
| 1207 | - // si le type est declare : bingo ! |
|
| 1208 | - if ($desc and isset($desc['type'])) { |
|
| 1209 | - return $desc['type']; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - // on a fait ce qu'on a pu |
|
| 1213 | - return $type; |
|
| 1160 | + if (!$table_objet) { |
|
| 1161 | + return null; |
|
| 1162 | + } |
|
| 1163 | + $surnoms = lister_types_surnoms(); |
|
| 1164 | + |
|
| 1165 | + // scenario de base |
|
| 1166 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1167 | + // et la marque du pluriel |
|
| 1168 | + // on accepte id_xx en entree aussi |
|
| 1169 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1170 | + if (isset($surnoms[$type])) { |
|
| 1171 | + return $surnoms[$type]; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // securite : eliminer les caracteres non \w |
|
| 1175 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1176 | + |
|
| 1177 | + // si le type redonne bien la table c'est bon |
|
| 1178 | + // oui si table_objet ressemblait deja a un type |
|
| 1179 | + if ( |
|
| 1180 | + $type == $table_objet |
|
| 1181 | + or (table_objet($type, $serveur) == $table_objet) |
|
| 1182 | + or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1183 | + ) { |
|
| 1184 | + return $type; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // si on ne veut pas chercher en base |
|
| 1188 | + if ($serveur === false) { |
|
| 1189 | + return $type; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1193 | + // car le s a la fin est incertain |
|
| 1194 | + // notamment en cas de pluriel derogatoire |
|
| 1195 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1196 | + // une declaration jeu => jeux, journal => journaux |
|
| 1197 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1198 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1199 | + $ts = lister_tables_spip($serveur); |
|
| 1200 | + $desc = false; |
|
| 1201 | + if (in_array($table_objet, $ts)) { |
|
| 1202 | + $desc = $trouver_table($table_objet); |
|
| 1203 | + } |
|
| 1204 | + if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1205 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1206 | + } |
|
| 1207 | + // si le type est declare : bingo ! |
|
| 1208 | + if ($desc and isset($desc['type'])) { |
|
| 1209 | + return $desc['type']; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + // on a fait ce qu'on a pu |
|
| 1213 | + return $type; |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | /** |
@@ -1226,62 +1226,62 @@ discard block |
||
| 1226 | 1226 | * @return bool |
| 1227 | 1227 | */ |
| 1228 | 1228 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1229 | - // voir si une fonction est definie pour faire le boulot |
|
| 1230 | - // elle a la priorite dans ce cas |
|
| 1231 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1232 | - return $f($objet, $id_objet, $serveur); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1236 | - $id_table = $table_objet = table_objet($objet); |
|
| 1237 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1238 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1239 | - if ( |
|
| 1240 | - $desc = $trouver_table($table_objet, $serveur) |
|
| 1241 | - and isset($desc['statut']) |
|
| 1242 | - and $desc['statut'] |
|
| 1243 | - ) { |
|
| 1244 | - $boucle = new Boucle(); |
|
| 1245 | - $boucle->show = $desc; |
|
| 1246 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1247 | - $boucle->id_boucle = $id_table; |
|
| 1248 | - $boucle->id_table = $id_table; |
|
| 1249 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1250 | - $boucle->sql_serveur = $serveur; |
|
| 1251 | - $boucle->select[] = $id_table_objet; |
|
| 1252 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1253 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1254 | - |
|
| 1255 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1256 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1257 | - $boucle->descr['gram'] = 'html'; |
|
| 1258 | - |
|
| 1259 | - include_spip('public/compiler'); |
|
| 1260 | - include_spip('public/composer'); |
|
| 1261 | - instituer_boucle($boucle, false, true); |
|
| 1262 | - $res = calculer_select( |
|
| 1263 | - $boucle->select, |
|
| 1264 | - $boucle->from, |
|
| 1265 | - $boucle->from_type, |
|
| 1266 | - $boucle->where, |
|
| 1267 | - $boucle->join, |
|
| 1268 | - $boucle->group, |
|
| 1269 | - $boucle->order, |
|
| 1270 | - $boucle->limit, |
|
| 1271 | - $boucle->having, |
|
| 1272 | - $table_objet, |
|
| 1273 | - $id_table, |
|
| 1274 | - $serveur |
|
| 1275 | - ); |
|
| 1276 | - if (sql_fetch($res)) { |
|
| 1277 | - return true; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - return false; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1284 | - return true; |
|
| 1229 | + // voir si une fonction est definie pour faire le boulot |
|
| 1230 | + // elle a la priorite dans ce cas |
|
| 1231 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1232 | + return $f($objet, $id_objet, $serveur); |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1236 | + $id_table = $table_objet = table_objet($objet); |
|
| 1237 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1238 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1239 | + if ( |
|
| 1240 | + $desc = $trouver_table($table_objet, $serveur) |
|
| 1241 | + and isset($desc['statut']) |
|
| 1242 | + and $desc['statut'] |
|
| 1243 | + ) { |
|
| 1244 | + $boucle = new Boucle(); |
|
| 1245 | + $boucle->show = $desc; |
|
| 1246 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1247 | + $boucle->id_boucle = $id_table; |
|
| 1248 | + $boucle->id_table = $id_table; |
|
| 1249 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1250 | + $boucle->sql_serveur = $serveur; |
|
| 1251 | + $boucle->select[] = $id_table_objet; |
|
| 1252 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1253 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1254 | + |
|
| 1255 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1256 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1257 | + $boucle->descr['gram'] = 'html'; |
|
| 1258 | + |
|
| 1259 | + include_spip('public/compiler'); |
|
| 1260 | + include_spip('public/composer'); |
|
| 1261 | + instituer_boucle($boucle, false, true); |
|
| 1262 | + $res = calculer_select( |
|
| 1263 | + $boucle->select, |
|
| 1264 | + $boucle->from, |
|
| 1265 | + $boucle->from_type, |
|
| 1266 | + $boucle->where, |
|
| 1267 | + $boucle->join, |
|
| 1268 | + $boucle->group, |
|
| 1269 | + $boucle->order, |
|
| 1270 | + $boucle->limit, |
|
| 1271 | + $boucle->having, |
|
| 1272 | + $table_objet, |
|
| 1273 | + $id_table, |
|
| 1274 | + $serveur |
|
| 1275 | + ); |
|
| 1276 | + if (sql_fetch($res)) { |
|
| 1277 | + return true; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return false; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1284 | + return true; |
|
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | 1287 | |
@@ -1316,124 +1316,124 @@ discard block |
||
| 1316 | 1316 | * Retourne un tableau décrivant les parents trouvés |
| 1317 | 1317 | */ |
| 1318 | 1318 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1319 | - $parents = []; |
|
| 1320 | - |
|
| 1321 | - // Si on trouve une ou des méthodes de parent |
|
| 1322 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1323 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1324 | - include_spip('base/abstract_sql'); |
|
| 1325 | - $table_objet = table_objet_sql($objet); |
|
| 1326 | - $cle_objet = id_table_objet($objet); |
|
| 1327 | - $id_objet = intval($id_objet); |
|
| 1328 | - |
|
| 1329 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1330 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1331 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1332 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1333 | - // de celle de l'objet source |
|
| 1334 | - $select = []; |
|
| 1335 | - if (isset($parent_methode['champ'])) { |
|
| 1336 | - $select[] = $parent_methode['champ']; |
|
| 1337 | - } |
|
| 1338 | - if (isset($parent_methode['champ_type'])) { |
|
| 1339 | - $select[] = $parent_methode['champ_type']; |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1343 | - $condition_objet_invalide = false; |
|
| 1344 | - $where = []; |
|
| 1345 | - if (!isset($parent_methode['table'])) { |
|
| 1346 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1347 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1348 | - $table = $table_objet; |
|
| 1349 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1350 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1351 | - if (isset($parent_methode['condition'])) { |
|
| 1352 | - $where[] = $parent_methode['condition']; |
|
| 1353 | - } |
|
| 1354 | - } elseif (!$parent_direct_seulement) { |
|
| 1355 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1356 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1357 | - // Si non, on peut arrêter le traitement. |
|
| 1358 | - if (isset($parent_methode['condition'])) { |
|
| 1359 | - $where = [ |
|
| 1360 | - "$cle_objet = $id_objet", |
|
| 1361 | - $parent_methode['condition'] |
|
| 1362 | - ]; |
|
| 1363 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1364 | - $condition_objet_invalide = true; |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1369 | - // la requête sur la table qui accueille le parent. |
|
| 1370 | - if (!$condition_objet_invalide) { |
|
| 1371 | - $table = $parent_methode['table']; |
|
| 1372 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1373 | - $where = []; |
|
| 1374 | - // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1375 | - // le même que celui de l'objet source. |
|
| 1376 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1377 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1378 | - : "${cle_objet} = $id_objet"; |
|
| 1379 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1380 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1381 | - } |
|
| 1382 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1383 | - if (isset($parent_methode['table_condition'])) { |
|
| 1384 | - $where[] = $parent_methode['table_condition']; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - // On lance la requête de récupération du parent |
|
| 1390 | - $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1391 | - if ( |
|
| 1392 | - !$condition_objet_invalide |
|
| 1393 | - and $where |
|
| 1394 | - and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1395 | - ) { |
|
| 1396 | - foreach ($lignes as $ligne) { |
|
| 1397 | - // Si le type est fixe |
|
| 1398 | - if (isset($parent_methode['type'])) { |
|
| 1399 | - $parent = [ |
|
| 1400 | - 'objet' => $parent_methode['type'], |
|
| 1401 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1402 | - 'champ' => $parent_methode['champ'], |
|
| 1403 | - 'table' => $table, |
|
| 1404 | - ]; |
|
| 1405 | - } |
|
| 1406 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1407 | - $parent = [ |
|
| 1408 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1409 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1410 | - 'champ' => $parent_methode['champ'], |
|
| 1411 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1412 | - 'table' => $table, |
|
| 1413 | - ]; |
|
| 1414 | - } |
|
| 1415 | - if ($is_table_lien) { |
|
| 1416 | - $parent['lien'] = $ligne; |
|
| 1417 | - } |
|
| 1418 | - $parents[] = $parent; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - // On passe par un pipeline avant de retourner |
|
| 1425 | - $parents = pipeline( |
|
| 1426 | - 'objet_lister_parents', |
|
| 1427 | - [ |
|
| 1428 | - 'args' => [ |
|
| 1429 | - 'objet' => $objet, |
|
| 1430 | - 'id_objet' => $id_objet, |
|
| 1431 | - ], |
|
| 1432 | - 'data' => $parents, |
|
| 1433 | - ] |
|
| 1434 | - ); |
|
| 1435 | - |
|
| 1436 | - return $parents; |
|
| 1319 | + $parents = []; |
|
| 1320 | + |
|
| 1321 | + // Si on trouve une ou des méthodes de parent |
|
| 1322 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1323 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1324 | + include_spip('base/abstract_sql'); |
|
| 1325 | + $table_objet = table_objet_sql($objet); |
|
| 1326 | + $cle_objet = id_table_objet($objet); |
|
| 1327 | + $id_objet = intval($id_objet); |
|
| 1328 | + |
|
| 1329 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1330 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1331 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1332 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1333 | + // de celle de l'objet source |
|
| 1334 | + $select = []; |
|
| 1335 | + if (isset($parent_methode['champ'])) { |
|
| 1336 | + $select[] = $parent_methode['champ']; |
|
| 1337 | + } |
|
| 1338 | + if (isset($parent_methode['champ_type'])) { |
|
| 1339 | + $select[] = $parent_methode['champ_type']; |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1343 | + $condition_objet_invalide = false; |
|
| 1344 | + $where = []; |
|
| 1345 | + if (!isset($parent_methode['table'])) { |
|
| 1346 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1347 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1348 | + $table = $table_objet; |
|
| 1349 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1350 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1351 | + if (isset($parent_methode['condition'])) { |
|
| 1352 | + $where[] = $parent_methode['condition']; |
|
| 1353 | + } |
|
| 1354 | + } elseif (!$parent_direct_seulement) { |
|
| 1355 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1356 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1357 | + // Si non, on peut arrêter le traitement. |
|
| 1358 | + if (isset($parent_methode['condition'])) { |
|
| 1359 | + $where = [ |
|
| 1360 | + "$cle_objet = $id_objet", |
|
| 1361 | + $parent_methode['condition'] |
|
| 1362 | + ]; |
|
| 1363 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1364 | + $condition_objet_invalide = true; |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1369 | + // la requête sur la table qui accueille le parent. |
|
| 1370 | + if (!$condition_objet_invalide) { |
|
| 1371 | + $table = $parent_methode['table']; |
|
| 1372 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1373 | + $where = []; |
|
| 1374 | + // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1375 | + // le même que celui de l'objet source. |
|
| 1376 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1377 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1378 | + : "${cle_objet} = $id_objet"; |
|
| 1379 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1380 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1381 | + } |
|
| 1382 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1383 | + if (isset($parent_methode['table_condition'])) { |
|
| 1384 | + $where[] = $parent_methode['table_condition']; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + // On lance la requête de récupération du parent |
|
| 1390 | + $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1391 | + if ( |
|
| 1392 | + !$condition_objet_invalide |
|
| 1393 | + and $where |
|
| 1394 | + and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1395 | + ) { |
|
| 1396 | + foreach ($lignes as $ligne) { |
|
| 1397 | + // Si le type est fixe |
|
| 1398 | + if (isset($parent_methode['type'])) { |
|
| 1399 | + $parent = [ |
|
| 1400 | + 'objet' => $parent_methode['type'], |
|
| 1401 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1402 | + 'champ' => $parent_methode['champ'], |
|
| 1403 | + 'table' => $table, |
|
| 1404 | + ]; |
|
| 1405 | + } |
|
| 1406 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1407 | + $parent = [ |
|
| 1408 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1409 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1410 | + 'champ' => $parent_methode['champ'], |
|
| 1411 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1412 | + 'table' => $table, |
|
| 1413 | + ]; |
|
| 1414 | + } |
|
| 1415 | + if ($is_table_lien) { |
|
| 1416 | + $parent['lien'] = $ligne; |
|
| 1417 | + } |
|
| 1418 | + $parents[] = $parent; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + // On passe par un pipeline avant de retourner |
|
| 1425 | + $parents = pipeline( |
|
| 1426 | + 'objet_lister_parents', |
|
| 1427 | + [ |
|
| 1428 | + 'args' => [ |
|
| 1429 | + 'objet' => $objet, |
|
| 1430 | + 'id_objet' => $id_objet, |
|
| 1431 | + ], |
|
| 1432 | + 'data' => $parents, |
|
| 1433 | + ] |
|
| 1434 | + ); |
|
| 1435 | + |
|
| 1436 | + return $parents; |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | /** |
@@ -1445,17 +1445,17 @@ discard block |
||
| 1445 | 1445 | * @return array |
| 1446 | 1446 | */ |
| 1447 | 1447 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1448 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1448 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1449 | 1449 | |
| 1450 | - $parents_par_type = []; |
|
| 1451 | - foreach ($parents as $parent) { |
|
| 1452 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1453 | - $parents_par_type[$parent['objet']] = []; |
|
| 1454 | - } |
|
| 1455 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1456 | - } |
|
| 1450 | + $parents_par_type = []; |
|
| 1451 | + foreach ($parents as $parent) { |
|
| 1452 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1453 | + $parents_par_type[$parent['objet']] = []; |
|
| 1454 | + } |
|
| 1455 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1456 | + } |
|
| 1457 | 1457 | |
| 1458 | - return $parents_par_type; |
|
| 1458 | + return $parents_par_type; |
|
| 1459 | 1459 | } |
| 1460 | 1460 | |
| 1461 | 1461 | |
@@ -1488,85 +1488,85 @@ discard block |
||
| 1488 | 1488 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1489 | 1489 | */ |
| 1490 | 1490 | function objet_lister_enfants($objet, $id_objet) { |
| 1491 | - $enfants = []; |
|
| 1492 | - |
|
| 1493 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1494 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1495 | - include_spip('base/abstract_sql'); |
|
| 1496 | - $id_objet = intval($id_objet); |
|
| 1497 | - |
|
| 1498 | - // On parcourt tous les types d'enfants trouvés |
|
| 1499 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1500 | - // On construit les conditions d'identification du parent |
|
| 1501 | - $where = []; |
|
| 1502 | - // -- L'identifiant du parent |
|
| 1503 | - if (isset($_methode_parent['champ'])) { |
|
| 1504 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1505 | - } |
|
| 1506 | - // -- Si le parent est variable |
|
| 1507 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1508 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1512 | - if (!isset($_methode_parent['table'])) { |
|
| 1513 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1514 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1515 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1516 | - |
|
| 1517 | - // S'il y a une condition supplémentaire |
|
| 1518 | - if (isset($_methode_parent['condition'])) { |
|
| 1519 | - $where[] = $_methode_parent['condition']; |
|
| 1520 | - } |
|
| 1521 | - } else { |
|
| 1522 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1523 | - $table_enfant = $_methode_parent['table']; |
|
| 1524 | - $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1525 | - |
|
| 1526 | - // S'il y a une condition supplémentaire |
|
| 1527 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1528 | - $where[] = $_methode_parent['table_condition']; |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - // On lance la requête |
|
| 1533 | - $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1534 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1535 | - $enfant = [ |
|
| 1536 | - 'objet' => $objet_enfant, |
|
| 1537 | - 'id_objet' => 0, |
|
| 1538 | - 'table' => $table_enfant |
|
| 1539 | - ]; |
|
| 1540 | - if (isset($_methode_parent['champ'])) { |
|
| 1541 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1542 | - } |
|
| 1543 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1544 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1545 | - } |
|
| 1546 | - foreach ($rows as $row) { |
|
| 1547 | - $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1548 | - if ($is_table_lien) { |
|
| 1549 | - $enfant['lien'] = $row; |
|
| 1550 | - } |
|
| 1551 | - $enfants[] = $enfant; |
|
| 1552 | - } |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - // On passe par un pipeline avant de retourner |
|
| 1558 | - $enfants = pipeline( |
|
| 1559 | - 'objet_lister_enfants', |
|
| 1560 | - [ |
|
| 1561 | - 'args' => [ |
|
| 1562 | - 'objet' => $objet, |
|
| 1563 | - 'id_objet' => $id_objet, |
|
| 1564 | - ], |
|
| 1565 | - 'data' => $enfants, |
|
| 1566 | - ] |
|
| 1567 | - ); |
|
| 1568 | - |
|
| 1569 | - return $enfants; |
|
| 1491 | + $enfants = []; |
|
| 1492 | + |
|
| 1493 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1494 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1495 | + include_spip('base/abstract_sql'); |
|
| 1496 | + $id_objet = intval($id_objet); |
|
| 1497 | + |
|
| 1498 | + // On parcourt tous les types d'enfants trouvés |
|
| 1499 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1500 | + // On construit les conditions d'identification du parent |
|
| 1501 | + $where = []; |
|
| 1502 | + // -- L'identifiant du parent |
|
| 1503 | + if (isset($_methode_parent['champ'])) { |
|
| 1504 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1505 | + } |
|
| 1506 | + // -- Si le parent est variable |
|
| 1507 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1508 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1512 | + if (!isset($_methode_parent['table'])) { |
|
| 1513 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1514 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1515 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1516 | + |
|
| 1517 | + // S'il y a une condition supplémentaire |
|
| 1518 | + if (isset($_methode_parent['condition'])) { |
|
| 1519 | + $where[] = $_methode_parent['condition']; |
|
| 1520 | + } |
|
| 1521 | + } else { |
|
| 1522 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1523 | + $table_enfant = $_methode_parent['table']; |
|
| 1524 | + $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1525 | + |
|
| 1526 | + // S'il y a une condition supplémentaire |
|
| 1527 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1528 | + $where[] = $_methode_parent['table_condition']; |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + // On lance la requête |
|
| 1533 | + $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1534 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1535 | + $enfant = [ |
|
| 1536 | + 'objet' => $objet_enfant, |
|
| 1537 | + 'id_objet' => 0, |
|
| 1538 | + 'table' => $table_enfant |
|
| 1539 | + ]; |
|
| 1540 | + if (isset($_methode_parent['champ'])) { |
|
| 1541 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1542 | + } |
|
| 1543 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1544 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1545 | + } |
|
| 1546 | + foreach ($rows as $row) { |
|
| 1547 | + $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1548 | + if ($is_table_lien) { |
|
| 1549 | + $enfant['lien'] = $row; |
|
| 1550 | + } |
|
| 1551 | + $enfants[] = $enfant; |
|
| 1552 | + } |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + // On passe par un pipeline avant de retourner |
|
| 1558 | + $enfants = pipeline( |
|
| 1559 | + 'objet_lister_enfants', |
|
| 1560 | + [ |
|
| 1561 | + 'args' => [ |
|
| 1562 | + 'objet' => $objet, |
|
| 1563 | + 'id_objet' => $id_objet, |
|
| 1564 | + ], |
|
| 1565 | + 'data' => $enfants, |
|
| 1566 | + ] |
|
| 1567 | + ); |
|
| 1568 | + |
|
| 1569 | + return $enfants; |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
@@ -1578,17 +1578,17 @@ discard block |
||
| 1578 | 1578 | * @return array |
| 1579 | 1579 | */ |
| 1580 | 1580 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1581 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1581 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1582 | 1582 | |
| 1583 | - $enfants_par_type = []; |
|
| 1584 | - foreach ($enfants as $enfant) { |
|
| 1585 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1586 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1587 | - } |
|
| 1588 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1589 | - } |
|
| 1583 | + $enfants_par_type = []; |
|
| 1584 | + foreach ($enfants as $enfant) { |
|
| 1585 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1586 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1587 | + } |
|
| 1588 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1589 | + } |
|
| 1590 | 1590 | |
| 1591 | - return $enfants_par_type; |
|
| 1591 | + return $enfants_par_type; |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | /** |
@@ -1600,35 +1600,35 @@ discard block |
||
| 1600 | 1600 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1601 | 1601 | */ |
| 1602 | 1602 | function objet_type_decrire_infos_parents($objet) { |
| 1603 | - static $parents = []; |
|
| 1604 | - |
|
| 1605 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1606 | - if (!isset($parents[$objet])) { |
|
| 1607 | - $parents[$objet] = false; |
|
| 1608 | - $table = table_objet_sql($objet); |
|
| 1609 | - |
|
| 1610 | - // Si on trouve bien la description de cet objet |
|
| 1611 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1612 | - if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1613 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1614 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1615 | - // de description |
|
| 1616 | - if (!isset($infos['parent'][0])) { |
|
| 1617 | - $parents[$objet] = [$infos['parent']]; |
|
| 1618 | - } else { |
|
| 1619 | - $parents[$objet] = $infos['parent']; |
|
| 1620 | - } |
|
| 1621 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1622 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1623 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1624 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1625 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1626 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1627 | - } |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - return $parents[$objet]; |
|
| 1603 | + static $parents = []; |
|
| 1604 | + |
|
| 1605 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1606 | + if (!isset($parents[$objet])) { |
|
| 1607 | + $parents[$objet] = false; |
|
| 1608 | + $table = table_objet_sql($objet); |
|
| 1609 | + |
|
| 1610 | + // Si on trouve bien la description de cet objet |
|
| 1611 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1612 | + if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1613 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1614 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1615 | + // de description |
|
| 1616 | + if (!isset($infos['parent'][0])) { |
|
| 1617 | + $parents[$objet] = [$infos['parent']]; |
|
| 1618 | + } else { |
|
| 1619 | + $parents[$objet] = $infos['parent']; |
|
| 1620 | + } |
|
| 1621 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1622 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1623 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1624 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1625 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1626 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + return $parents[$objet]; |
|
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | /** |
@@ -1640,36 +1640,36 @@ discard block |
||
| 1640 | 1640 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1641 | 1641 | */ |
| 1642 | 1642 | function objet_type_decrire_infos_enfants($objet) { |
| 1643 | - static $enfants = []; |
|
| 1644 | - |
|
| 1645 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1646 | - if (!isset($enfants[$objet])) { |
|
| 1647 | - $enfants[$objet] = []; |
|
| 1648 | - $tables = lister_tables_objets_sql(); |
|
| 1649 | - |
|
| 1650 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1651 | - foreach ($tables as $table => $infos) { |
|
| 1652 | - $objet_enfant = objet_type($table); |
|
| 1653 | - |
|
| 1654 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1655 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1656 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1657 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1658 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1659 | - if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1660 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1661 | - if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1662 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1663 | - } |
|
| 1664 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1665 | - elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1666 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1667 | - } |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - return $enfants[$objet]; |
|
| 1643 | + static $enfants = []; |
|
| 1644 | + |
|
| 1645 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1646 | + if (!isset($enfants[$objet])) { |
|
| 1647 | + $enfants[$objet] = []; |
|
| 1648 | + $tables = lister_tables_objets_sql(); |
|
| 1649 | + |
|
| 1650 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1651 | + foreach ($tables as $table => $infos) { |
|
| 1652 | + $objet_enfant = objet_type($table); |
|
| 1653 | + |
|
| 1654 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1655 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1656 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1657 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1658 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1659 | + if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1660 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1661 | + if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1662 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1663 | + } |
|
| 1664 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1665 | + elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1666 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + return $enfants[$objet]; |
|
| 1675 | 1675 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,118 +42,118 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ?: 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | - : ''))); // installation pas faite |
|
| 65 | - |
|
| 66 | - unset($GLOBALS['db_ok']); |
|
| 67 | - unset($GLOBALS['spip_connect_version']); |
|
| 68 | - if ($f) { |
|
| 69 | - if (is_readable($f)) { |
|
| 70 | - include($f); |
|
| 71 | - } elseif ($serveur and !$install) { |
|
| 72 | - // chercher une declaration de serveur dans le path |
|
| 73 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | - // fera mieux la prochaine fois |
|
| 80 | - if ($install) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - if ($f and is_readable($f)) { |
|
| 84 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | - } else { |
|
| 86 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | - } |
|
| 88 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | - |
|
| 90 | - // ne plus reessayer si ce n'est pas l'install |
|
| 91 | - return $GLOBALS['connexions'][$index] = false; |
|
| 92 | - } |
|
| 93 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | - } |
|
| 95 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // la connexion a reussi ou etait deja faite. |
|
| 101 | - // chargement de la version du jeu de fonctions |
|
| 102 | - // si pas dans le fichier par defaut |
|
| 103 | - $type = $GLOBALS['db_ok']['type']; |
|
| 104 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | - if (!isset($GLOBALS[$jeu])) { |
|
| 106 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | - |
|
| 109 | - // ne plus reessayer |
|
| 110 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | - if ($old) { |
|
| 115 | - return $GLOBALS['connexions'][$index]; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | - |
|
| 120 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | - // si l'installation l'a determine. |
|
| 122 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | - // s'ils le connaissent |
|
| 124 | - |
|
| 125 | - if (!$serveur) { |
|
| 126 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | - if (!$charset) { |
|
| 128 | - unset($GLOBALS['connexions'][$index]); |
|
| 129 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | - |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | - } |
|
| 137 | - // spip_meta n'existe pas toujours dans la base |
|
| 138 | - // C'est le cas d'un dump sqlite par exemple |
|
| 139 | - elseif ( |
|
| 140 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | - ) { |
|
| 144 | - $charset = $r; |
|
| 145 | - } else { |
|
| 146 | - $charset = -1; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($charset != -1) { |
|
| 150 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | - if (function_exists($f)) { |
|
| 152 | - $f($charset, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ?: 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | + : ''))); // installation pas faite |
|
| 65 | + |
|
| 66 | + unset($GLOBALS['db_ok']); |
|
| 67 | + unset($GLOBALS['spip_connect_version']); |
|
| 68 | + if ($f) { |
|
| 69 | + if (is_readable($f)) { |
|
| 70 | + include($f); |
|
| 71 | + } elseif ($serveur and !$install) { |
|
| 72 | + // chercher une declaration de serveur dans le path |
|
| 73 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | + // fera mieux la prochaine fois |
|
| 80 | + if ($install) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + if ($f and is_readable($f)) { |
|
| 84 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | + } else { |
|
| 86 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | + } |
|
| 88 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | + |
|
| 90 | + // ne plus reessayer si ce n'est pas l'install |
|
| 91 | + return $GLOBALS['connexions'][$index] = false; |
|
| 92 | + } |
|
| 93 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | + } |
|
| 95 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // la connexion a reussi ou etait deja faite. |
|
| 101 | + // chargement de la version du jeu de fonctions |
|
| 102 | + // si pas dans le fichier par defaut |
|
| 103 | + $type = $GLOBALS['db_ok']['type']; |
|
| 104 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | + if (!isset($GLOBALS[$jeu])) { |
|
| 106 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | + |
|
| 109 | + // ne plus reessayer |
|
| 110 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | + if ($old) { |
|
| 115 | + return $GLOBALS['connexions'][$index]; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | + |
|
| 120 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | + // si l'installation l'a determine. |
|
| 122 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | + // s'ils le connaissent |
|
| 124 | + |
|
| 125 | + if (!$serveur) { |
|
| 126 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | + if (!$charset) { |
|
| 128 | + unset($GLOBALS['connexions'][$index]); |
|
| 129 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | + |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | + } |
|
| 137 | + // spip_meta n'existe pas toujours dans la base |
|
| 138 | + // C'est le cas d'un dump sqlite par exemple |
|
| 139 | + elseif ( |
|
| 140 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | + ) { |
|
| 144 | + $charset = $r; |
|
| 145 | + } else { |
|
| 146 | + $charset = -1; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($charset != -1) { |
|
| 150 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | + if (function_exists($f)) { |
|
| 152 | + $f($charset, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $GLOBALS['connexions'][$index]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 163 | 163 | **/ |
| 164 | 164 | function spip_sql_erreur($serveur = '') { |
| 165 | - $connexion = spip_connect($serveur); |
|
| 166 | - $e = sql_errno($serveur); |
|
| 167 | - $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 165 | + $connexion = spip_connect($serveur); |
|
| 166 | + $e = sql_errno($serveur); |
|
| 167 | + $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | + $f = $t . $serveur; |
|
| 170 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -189,23 +189,23 @@ discard block |
||
| 189 | 189 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 190 | 190 | **/ |
| 191 | 191 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 192 | - $desc = spip_connect($serveur, $version); |
|
| 193 | - if ( |
|
| 194 | - $desc |
|
| 195 | - and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | - and function_exists($f) |
|
| 197 | - ) { |
|
| 198 | - return $f; |
|
| 199 | - } |
|
| 200 | - if ($continue) { |
|
| 201 | - return $desc; |
|
| 202 | - } |
|
| 203 | - if ($ins) { |
|
| 204 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | - } |
|
| 206 | - include_spip('inc/minipres'); |
|
| 207 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | - exit; |
|
| 192 | + $desc = spip_connect($serveur, $version); |
|
| 193 | + if ( |
|
| 194 | + $desc |
|
| 195 | + and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | + and function_exists($f) |
|
| 197 | + ) { |
|
| 198 | + return $f; |
|
| 199 | + } |
|
| 200 | + if ($continue) { |
|
| 201 | + return $desc; |
|
| 202 | + } |
|
| 203 | + if ($ins) { |
|
| 204 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | + } |
|
| 206 | + include_spip('inc/minipres'); |
|
| 207 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | + exit; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -231,70 +231,70 @@ discard block |
||
| 231 | 231 | * @return array|null Description de la connexion |
| 232 | 232 | */ |
| 233 | 233 | function spip_connect_db( |
| 234 | - $host, |
|
| 235 | - $port, |
|
| 236 | - $login, |
|
| 237 | - $pass, |
|
| 238 | - $db = '', |
|
| 239 | - $type = 'mysql', |
|
| 240 | - $prefixe = '', |
|
| 241 | - $auth = '', |
|
| 242 | - $charset = '' |
|
| 234 | + $host, |
|
| 235 | + $port, |
|
| 236 | + $login, |
|
| 237 | + $pass, |
|
| 238 | + $db = '', |
|
| 239 | + $type = 'mysql', |
|
| 240 | + $prefixe = '', |
|
| 241 | + $auth = '', |
|
| 242 | + $charset = '' |
|
| 243 | 243 | ) { |
| 244 | - // temps avant nouvelle tentative de connexion |
|
| 245 | - // suite a une connection echouee |
|
| 246 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $f = ''; |
|
| 251 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | - // car c'est un test de connexion |
|
| 255 | - if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | - } elseif ($db == '@test@') { |
|
| 258 | - $db = ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - $f |
|
| 263 | - and @file_exists($f) |
|
| 264 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | - ) { |
|
| 266 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | - |
|
| 268 | - return null; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if (!$prefixe) { |
|
| 272 | - $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | - } |
|
| 274 | - $h = charger_fonction($type, 'req', true); |
|
| 275 | - if (!$h) { |
|
| 276 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | - |
|
| 278 | - return null; |
|
| 279 | - } |
|
| 280 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | - if (!is_array($auth)) { |
|
| 282 | - // compatibilite version 0.7 initiale |
|
| 283 | - $g['ldap'] = $auth; |
|
| 284 | - $auth = ['ldap' => $auth]; |
|
| 285 | - } |
|
| 286 | - $g['authentification'] = $auth; |
|
| 287 | - $g['type'] = $type; |
|
| 288 | - $g['charset'] = $charset; |
|
| 289 | - |
|
| 290 | - return $GLOBALS['db_ok'] = $g; |
|
| 291 | - } |
|
| 292 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | - if ($f) { |
|
| 294 | - @touch($f); |
|
| 295 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | - } |
|
| 297 | - return null; |
|
| 244 | + // temps avant nouvelle tentative de connexion |
|
| 245 | + // suite a une connection echouee |
|
| 246 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $f = ''; |
|
| 251 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | + // car c'est un test de connexion |
|
| 255 | + if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | + } elseif ($db == '@test@') { |
|
| 258 | + $db = ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + $f |
|
| 263 | + and @file_exists($f) |
|
| 264 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | + ) { |
|
| 266 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | + |
|
| 268 | + return null; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if (!$prefixe) { |
|
| 272 | + $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | + } |
|
| 274 | + $h = charger_fonction($type, 'req', true); |
|
| 275 | + if (!$h) { |
|
| 276 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | + |
|
| 278 | + return null; |
|
| 279 | + } |
|
| 280 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | + if (!is_array($auth)) { |
|
| 282 | + // compatibilite version 0.7 initiale |
|
| 283 | + $g['ldap'] = $auth; |
|
| 284 | + $auth = ['ldap' => $auth]; |
|
| 285 | + } |
|
| 286 | + $g['authentification'] = $auth; |
|
| 287 | + $g['type'] = $type; |
|
| 288 | + $g['charset'] = $charset; |
|
| 289 | + |
|
| 290 | + return $GLOBALS['db_ok'] = $g; |
|
| 291 | + } |
|
| 292 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | + if ($f) { |
|
| 294 | + @touch($f); |
|
| 295 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | + } |
|
| 297 | + return null; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -326,32 +326,32 @@ discard block |
||
| 326 | 326 | * - nom du charset sinon |
| 327 | 327 | **/ |
| 328 | 328 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 329 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 330 | - include_spip('inc/headers'); |
|
| 331 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if (!($f = $connexion['select'])) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - // si le charset est fourni, l'utiliser |
|
| 338 | - if ($charset_sql_connexion) { |
|
| 339 | - return $charset_sql_connexion; |
|
| 340 | - } |
|
| 341 | - // sinon on regarde la table spip_meta |
|
| 342 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 343 | - if ( |
|
| 344 | - !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 345 | - or is_string($r) |
|
| 346 | - ) { |
|
| 347 | - return false; |
|
| 348 | - } |
|
| 349 | - if (!($f = $connexion['fetch'])) { |
|
| 350 | - return false; |
|
| 351 | - } |
|
| 352 | - $r = $f($r); |
|
| 353 | - |
|
| 354 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 329 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 330 | + include_spip('inc/headers'); |
|
| 331 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if (!($f = $connexion['select'])) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + // si le charset est fourni, l'utiliser |
|
| 338 | + if ($charset_sql_connexion) { |
|
| 339 | + return $charset_sql_connexion; |
|
| 340 | + } |
|
| 341 | + // sinon on regarde la table spip_meta |
|
| 342 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 343 | + if ( |
|
| 344 | + !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 345 | + or is_string($r) |
|
| 346 | + ) { |
|
| 347 | + return false; |
|
| 348 | + } |
|
| 349 | + if (!($f = $connexion['fetch'])) { |
|
| 350 | + return false; |
|
| 351 | + } |
|
| 352 | + $r = $f($r); |
|
| 353 | + |
|
| 354 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | * @return array |
| 368 | 368 | */ |
| 369 | 369 | function spip_connect_ldap($serveur = '') { |
| 370 | - include_spip('auth/ldap'); |
|
| 370 | + include_spip('auth/ldap'); |
|
| 371 | 371 | |
| 372 | - return auth_ldap_connect($serveur); |
|
| 372 | + return auth_ldap_connect($serveur); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,16 +385,16 @@ discard block |
||
| 385 | 385 | * @return string Valeur échappée. |
| 386 | 386 | **/ |
| 387 | 387 | function _q($a): string { |
| 388 | - if (is_numeric($a)) { |
|
| 389 | - return strval($a); |
|
| 390 | - } elseif (is_array($a)) { |
|
| 391 | - return join(',', array_map('_q', $a)); |
|
| 392 | - } elseif (is_scalar($a)) { |
|
| 393 | - return ("'" . addslashes($a) . "'"); |
|
| 394 | - } elseif ($a === null) { |
|
| 395 | - return "''"; |
|
| 396 | - } |
|
| 397 | - throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 388 | + if (is_numeric($a)) { |
|
| 389 | + return strval($a); |
|
| 390 | + } elseif (is_array($a)) { |
|
| 391 | + return join(',', array_map('_q', $a)); |
|
| 392 | + } elseif (is_scalar($a)) { |
|
| 393 | + return ("'" . addslashes($a) . "'"); |
|
| 394 | + } elseif ($a === null) { |
|
| 395 | + return "''"; |
|
| 396 | + } |
|
| 397 | + throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
@@ -410,75 +410,75 @@ discard block |
||
| 410 | 410 | * @return array |
| 411 | 411 | */ |
| 412 | 412 | function query_echappe_textes($query, $uniqid = null) { |
| 413 | - static $codeEchappements = null; |
|
| 414 | - if (is_null($codeEchappements) or $uniqid) { |
|
| 415 | - if (is_null($uniqid)) { |
|
| 416 | - $uniqid = uniqid(); |
|
| 417 | - } |
|
| 418 | - $uniqid = substr(md5($uniqid), 0, 4); |
|
| 419 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 420 | - } |
|
| 421 | - if ($query === null) { |
|
| 422 | - return $codeEchappements; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 426 | - // ce n'est pas un cas legitime |
|
| 427 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 428 | - if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 429 | - return [$query, []]; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 434 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 435 | - $textes = reset($textes); |
|
| 436 | - |
|
| 437 | - $parts = []; |
|
| 438 | - $currentpos = 0; |
|
| 439 | - $k = 0; |
|
| 440 | - while (count($textes)) { |
|
| 441 | - $part = array_shift($textes); |
|
| 442 | - $nextpos = strpos($query_echappees, $part, $currentpos); |
|
| 443 | - // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 444 | - while (count($textes) and substr($part, -1) === "'") { |
|
| 445 | - $next = reset($textes); |
|
| 446 | - if ( |
|
| 447 | - strpos($next, "'") === 0 |
|
| 448 | - and strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 449 | - ) { |
|
| 450 | - $part .= array_shift($textes); |
|
| 451 | - } |
|
| 452 | - else { |
|
| 453 | - break; |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - $k++; |
|
| 457 | - $parts[$k] = [ |
|
| 458 | - 'texte' => $part, |
|
| 459 | - 'position' => $nextpos, |
|
| 460 | - 'placeholder' => '%' . $k . '$s', |
|
| 461 | - ]; |
|
| 462 | - $currentpos = $nextpos + strlen($part); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // et on replace les parts une par une en commencant par la fin |
|
| 466 | - while ($k > 0) { |
|
| 467 | - $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte'])); |
|
| 468 | - $k--; |
|
| 469 | - } |
|
| 470 | - $textes = array_column($parts, 'texte'); |
|
| 471 | - } else { |
|
| 472 | - $textes = []; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 476 | - // dans le doute on ne touche a rien |
|
| 477 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 478 | - return [$query, []]; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return [$query_echappees, $textes]; |
|
| 413 | + static $codeEchappements = null; |
|
| 414 | + if (is_null($codeEchappements) or $uniqid) { |
|
| 415 | + if (is_null($uniqid)) { |
|
| 416 | + $uniqid = uniqid(); |
|
| 417 | + } |
|
| 418 | + $uniqid = substr(md5($uniqid), 0, 4); |
|
| 419 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 420 | + } |
|
| 421 | + if ($query === null) { |
|
| 422 | + return $codeEchappements; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 426 | + // ce n'est pas un cas legitime |
|
| 427 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 428 | + if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 429 | + return [$query, []]; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 434 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 435 | + $textes = reset($textes); |
|
| 436 | + |
|
| 437 | + $parts = []; |
|
| 438 | + $currentpos = 0; |
|
| 439 | + $k = 0; |
|
| 440 | + while (count($textes)) { |
|
| 441 | + $part = array_shift($textes); |
|
| 442 | + $nextpos = strpos($query_echappees, $part, $currentpos); |
|
| 443 | + // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 444 | + while (count($textes) and substr($part, -1) === "'") { |
|
| 445 | + $next = reset($textes); |
|
| 446 | + if ( |
|
| 447 | + strpos($next, "'") === 0 |
|
| 448 | + and strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 449 | + ) { |
|
| 450 | + $part .= array_shift($textes); |
|
| 451 | + } |
|
| 452 | + else { |
|
| 453 | + break; |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + $k++; |
|
| 457 | + $parts[$k] = [ |
|
| 458 | + 'texte' => $part, |
|
| 459 | + 'position' => $nextpos, |
|
| 460 | + 'placeholder' => '%' . $k . '$s', |
|
| 461 | + ]; |
|
| 462 | + $currentpos = $nextpos + strlen($part); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // et on replace les parts une par une en commencant par la fin |
|
| 466 | + while ($k > 0) { |
|
| 467 | + $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte'])); |
|
| 468 | + $k--; |
|
| 469 | + } |
|
| 470 | + $textes = array_column($parts, 'texte'); |
|
| 471 | + } else { |
|
| 472 | + $textes = []; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 476 | + // dans le doute on ne touche a rien |
|
| 477 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 478 | + return [$query, []]; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return [$query_echappees, $textes]; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -492,16 +492,16 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | 494 | function query_reinjecte_textes($query, $textes) { |
| 495 | - // recuperer les codes echappements |
|
| 496 | - $codeEchappements = query_echappe_textes(null); |
|
| 495 | + // recuperer les codes echappements |
|
| 496 | + $codeEchappements = query_echappe_textes(null); |
|
| 497 | 497 | |
| 498 | - if (!empty($textes)) { |
|
| 499 | - $query = sprintf($query, ...$textes); |
|
| 500 | - } |
|
| 498 | + if (!empty($textes)) { |
|
| 499 | + $query = sprintf($query, ...$textes); |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 502 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 503 | 503 | |
| 504 | - return $query; |
|
| 504 | + return $query; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | **/ |
| 521 | 521 | function spip_query($query, $serveur = '') { |
| 522 | 522 | |
| 523 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 523 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 524 | 524 | |
| 525 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 525 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 526 | 526 | } |
@@ -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,13 +609,13 @@ 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 | - $ok = mysqli_select_db($link, $db); |
|
| 614 | - if (!$ok) { |
|
| 615 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 616 | - } |
|
| 612 | + $link = _mysql_link($serveur); |
|
| 613 | + $ok = mysqli_select_db($link, $db); |
|
| 614 | + if (!$ok) { |
|
| 615 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 616 | + } |
|
| 617 | 617 | |
| 618 | - return $ok; |
|
| 618 | + return $ok; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -636,14 +636,14 @@ discard block |
||
| 636 | 636 | * Liste de noms de bases de données |
| 637 | 637 | **/ |
| 638 | 638 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 639 | - $dbs = []; |
|
| 640 | - if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 641 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 642 | - $dbs[] = $row['Database']; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - return $dbs; |
|
| 639 | + $dbs = []; |
|
| 640 | + if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 641 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 642 | + $dbs[] = $row['Database']; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + return $dbs; |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | |
@@ -666,73 +666,73 @@ discard block |
||
| 666 | 666 | * - true si la requête réussie, false sinon. |
| 667 | 667 | */ |
| 668 | 668 | function spip_mysql_create( |
| 669 | - $nom, |
|
| 670 | - $champs, |
|
| 671 | - $cles, |
|
| 672 | - $autoinc = false, |
|
| 673 | - $temporary = false, |
|
| 674 | - $serveur = '', |
|
| 675 | - $requeter = true |
|
| 669 | + $nom, |
|
| 670 | + $champs, |
|
| 671 | + $cles, |
|
| 672 | + $autoinc = false, |
|
| 673 | + $temporary = false, |
|
| 674 | + $serveur = '', |
|
| 675 | + $requeter = true |
|
| 676 | 676 | ) { |
| 677 | 677 | |
| 678 | - $query = ''; |
|
| 679 | - $keys = ''; |
|
| 680 | - $s = ''; |
|
| 681 | - $p = ''; |
|
| 682 | - |
|
| 683 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 684 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 685 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 686 | - return; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 690 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 691 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - foreach ($cles as $k => $v) { |
|
| 695 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 696 | - if ($k == 'PRIMARY KEY') { |
|
| 697 | - $p = $v; |
|
| 698 | - } |
|
| 699 | - $s = ','; |
|
| 700 | - } |
|
| 701 | - $s = ''; |
|
| 702 | - |
|
| 703 | - $character_set = ''; |
|
| 704 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 705 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 706 | - } |
|
| 707 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 708 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - foreach ($champs as $k => $v) { |
|
| 712 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 713 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 714 | - if ( |
|
| 715 | - preg_match(',(char|text),i', $defs[1]) |
|
| 716 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 717 | - ) { |
|
| 718 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - $query .= "$s\n\t\t$k $v" |
|
| 723 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 724 | - ? ' auto_increment' |
|
| 725 | - : '' |
|
| 726 | - ); |
|
| 727 | - $s = ','; |
|
| 728 | - } |
|
| 729 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 730 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 731 | - . ' ENGINE=MyISAM' |
|
| 732 | - . ($character_set ? " DEFAULT $character_set" : '') |
|
| 733 | - . "\n"; |
|
| 734 | - |
|
| 735 | - return spip_mysql_query($q, $serveur); |
|
| 678 | + $query = ''; |
|
| 679 | + $keys = ''; |
|
| 680 | + $s = ''; |
|
| 681 | + $p = ''; |
|
| 682 | + |
|
| 683 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 684 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 685 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 686 | + return; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 690 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 691 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + foreach ($cles as $k => $v) { |
|
| 695 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 696 | + if ($k == 'PRIMARY KEY') { |
|
| 697 | + $p = $v; |
|
| 698 | + } |
|
| 699 | + $s = ','; |
|
| 700 | + } |
|
| 701 | + $s = ''; |
|
| 702 | + |
|
| 703 | + $character_set = ''; |
|
| 704 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 705 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 706 | + } |
|
| 707 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 708 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + foreach ($champs as $k => $v) { |
|
| 712 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 713 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 714 | + if ( |
|
| 715 | + preg_match(',(char|text),i', $defs[1]) |
|
| 716 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 717 | + ) { |
|
| 718 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + $query .= "$s\n\t\t$k $v" |
|
| 723 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 724 | + ? ' auto_increment' |
|
| 725 | + : '' |
|
| 726 | + ); |
|
| 727 | + $s = ','; |
|
| 728 | + } |
|
| 729 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 730 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 731 | + . ' ENGINE=MyISAM' |
|
| 732 | + . ($character_set ? " DEFAULT $character_set" : '') |
|
| 733 | + . "\n"; |
|
| 734 | + |
|
| 735 | + return spip_mysql_query($q, $serveur); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -745,25 +745,25 @@ discard block |
||
| 745 | 745 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 746 | 746 | */ |
| 747 | 747 | function _mysql_remplacements_definitions_table($query) { |
| 748 | - // quelques remplacements |
|
| 749 | - $num = '(\s*\([0-9]*\))?'; |
|
| 750 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 751 | - |
|
| 752 | - $remplace = [ |
|
| 753 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 754 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 755 | - ]; |
|
| 756 | - |
|
| 757 | - if (is_string($query)) { |
|
| 758 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 759 | - } elseif (is_array($query)) { |
|
| 760 | - $keys = array_keys($remplace); |
|
| 761 | - foreach ($query as $k => $q) { |
|
| 762 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - return $query; |
|
| 748 | + // quelques remplacements |
|
| 749 | + $num = '(\s*\([0-9]*\))?'; |
|
| 750 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 751 | + |
|
| 752 | + $remplace = [ |
|
| 753 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 754 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 755 | + ]; |
|
| 756 | + |
|
| 757 | + if (is_string($query)) { |
|
| 758 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 759 | + } elseif (is_array($query)) { |
|
| 760 | + $keys = array_keys($remplace); |
|
| 761 | + foreach ($query as $k => $q) { |
|
| 762 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + return $query; |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * @return bool true si la base est créee. |
| 777 | 777 | **/ |
| 778 | 778 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 779 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 779 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | |
@@ -797,19 +797,19 @@ discard block |
||
| 797 | 797 | * - string texte de la requête si $requeter vaut false |
| 798 | 798 | */ |
| 799 | 799 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 800 | - if (!$query_select) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - // vue deja presente |
|
| 804 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 805 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 800 | + if (!$query_select) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + // vue deja presente |
|
| 804 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 805 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 806 | 806 | |
| 807 | - return false; |
|
| 808 | - } |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | 809 | |
| 810 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 810 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 811 | 811 | |
| 812 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 812 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -825,11 +825,11 @@ discard block |
||
| 825 | 825 | * - true si la requête a réussie, false sinon |
| 826 | 826 | */ |
| 827 | 827 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 828 | - if ($exist) { |
|
| 829 | - $exist = ' IF EXISTS'; |
|
| 830 | - } |
|
| 828 | + if ($exist) { |
|
| 829 | + $exist = ' IF EXISTS'; |
|
| 830 | + } |
|
| 831 | 831 | |
| 832 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 832 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -844,11 +844,11 @@ discard block |
||
| 844 | 844 | * - true si la requête a réussie, false sinon |
| 845 | 845 | */ |
| 846 | 846 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 847 | - if ($exist) { |
|
| 848 | - $exist = ' IF EXISTS'; |
|
| 849 | - } |
|
| 847 | + if ($exist) { |
|
| 848 | + $exist = ' IF EXISTS'; |
|
| 849 | + } |
|
| 850 | 850 | |
| 851 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 851 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | * Ressource à utiliser avec sql_fetch() |
| 866 | 866 | **/ |
| 867 | 867 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 868 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 868 | + return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | * - true si la requête a réussie, false sinon |
| 882 | 882 | */ |
| 883 | 883 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 884 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 884 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
@@ -899,12 +899,12 @@ discard block |
||
| 899 | 899 | * - string : requete sql, si $requeter = true |
| 900 | 900 | **/ |
| 901 | 901 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 902 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 903 | - if (!$requeter) { |
|
| 904 | - return $r; |
|
| 905 | - } |
|
| 906 | - $res = spip_mysql_fetch($r); |
|
| 907 | - return (bool) $res; |
|
| 902 | + $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 903 | + if (!$requeter) { |
|
| 904 | + return $r; |
|
| 905 | + } |
|
| 906 | + $res = spip_mysql_fetch($r); |
|
| 907 | + return (bool) $res; |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -927,86 +927,86 @@ discard block |
||
| 927 | 927 | * - array description de la table sinon |
| 928 | 928 | */ |
| 929 | 929 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 930 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 931 | - if (!$s) { |
|
| 932 | - return ''; |
|
| 933 | - } |
|
| 934 | - if (!$requeter) { |
|
| 935 | - return $s; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 939 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 940 | - $desc = $r[1]; |
|
| 941 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 942 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 943 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 944 | - $namedkeys = $r[2]; |
|
| 945 | - $desc = $r[1]; |
|
| 946 | - } else { |
|
| 947 | - $namedkeys = ''; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - $fields = []; |
|
| 951 | - foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 952 | - preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 953 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 954 | - } |
|
| 955 | - $keys = []; |
|
| 956 | - |
|
| 957 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 958 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 959 | - $k = str_replace('`', '', trim($r[1])); |
|
| 960 | - $t = strtolower(str_replace('`', '', $r[2])); |
|
| 961 | - if ($k && !isset($keys[$k])) { |
|
| 962 | - $keys[$k] = $t; |
|
| 963 | - } else { |
|
| 964 | - $keys[] = $t; |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - spip_mysql_free($s); |
|
| 969 | - |
|
| 970 | - return ['field' => $fields, 'key' => $keys]; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 974 | - if ($res) { |
|
| 975 | - $nfields = []; |
|
| 976 | - $nkeys = []; |
|
| 977 | - while ($val = spip_mysql_fetch($res)) { |
|
| 978 | - $nfields[$val['Field']] = $val['Type']; |
|
| 979 | - if ($val['Null'] == 'NO') { |
|
| 980 | - $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 981 | - } |
|
| 982 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 983 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 984 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 985 | - } else { |
|
| 986 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - if ($val['Extra']) { |
|
| 990 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 991 | - } |
|
| 992 | - if ($val['Key'] == 'PRI') { |
|
| 993 | - $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 994 | - } else { |
|
| 995 | - if ($val['Key'] == 'MUL') { |
|
| 996 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 997 | - } else { |
|
| 998 | - if ($val['Key'] == 'UNI') { |
|
| 999 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1000 | - } |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - spip_mysql_free($res); |
|
| 1005 | - |
|
| 1006 | - return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - return ''; |
|
| 930 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 931 | + if (!$s) { |
|
| 932 | + return ''; |
|
| 933 | + } |
|
| 934 | + if (!$requeter) { |
|
| 935 | + return $s; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 939 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 940 | + $desc = $r[1]; |
|
| 941 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 942 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 943 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 944 | + $namedkeys = $r[2]; |
|
| 945 | + $desc = $r[1]; |
|
| 946 | + } else { |
|
| 947 | + $namedkeys = ''; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + $fields = []; |
|
| 951 | + foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 952 | + preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 953 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 954 | + } |
|
| 955 | + $keys = []; |
|
| 956 | + |
|
| 957 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 958 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 959 | + $k = str_replace('`', '', trim($r[1])); |
|
| 960 | + $t = strtolower(str_replace('`', '', $r[2])); |
|
| 961 | + if ($k && !isset($keys[$k])) { |
|
| 962 | + $keys[$k] = $t; |
|
| 963 | + } else { |
|
| 964 | + $keys[] = $t; |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + spip_mysql_free($s); |
|
| 969 | + |
|
| 970 | + return ['field' => $fields, 'key' => $keys]; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 974 | + if ($res) { |
|
| 975 | + $nfields = []; |
|
| 976 | + $nkeys = []; |
|
| 977 | + while ($val = spip_mysql_fetch($res)) { |
|
| 978 | + $nfields[$val['Field']] = $val['Type']; |
|
| 979 | + if ($val['Null'] == 'NO') { |
|
| 980 | + $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 981 | + } |
|
| 982 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 983 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 984 | + $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 985 | + } else { |
|
| 986 | + $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + if ($val['Extra']) { |
|
| 990 | + $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 991 | + } |
|
| 992 | + if ($val['Key'] == 'PRI') { |
|
| 993 | + $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 994 | + } else { |
|
| 995 | + if ($val['Key'] == 'MUL') { |
|
| 996 | + $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 997 | + } else { |
|
| 998 | + if ($val['Key'] == 'UNI') { |
|
| 999 | + $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1000 | + } |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + spip_mysql_free($res); |
|
| 1005 | + |
|
| 1006 | + return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + return ''; |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | |
@@ -1022,12 +1022,12 @@ discard block |
||
| 1022 | 1022 | * @return array Ligne de résultat |
| 1023 | 1023 | */ |
| 1024 | 1024 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 1025 | - if (!$t) { |
|
| 1026 | - $t = \MYSQLI_ASSOC; |
|
| 1027 | - } |
|
| 1028 | - if ($r) { |
|
| 1029 | - return mysqli_fetch_array($r, $t); |
|
| 1030 | - } |
|
| 1025 | + if (!$t) { |
|
| 1026 | + $t = \MYSQLI_ASSOC; |
|
| 1027 | + } |
|
| 1028 | + if ($r) { |
|
| 1029 | + return mysqli_fetch_array($r, $t); |
|
| 1030 | + } |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /** |
@@ -1040,9 +1040,9 @@ discard block |
||
| 1040 | 1040 | * @return bool True si déplacement réussi, false sinon. |
| 1041 | 1041 | **/ |
| 1042 | 1042 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1043 | - if ($r and mysqli_num_rows($r)) { |
|
| 1044 | - return mysqli_data_seek($r, $row_number); |
|
| 1045 | - } |
|
| 1043 | + if ($r and mysqli_num_rows($r)) { |
|
| 1044 | + return mysqli_data_seek($r, $row_number); |
|
| 1045 | + } |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | |
@@ -1060,26 +1060,26 @@ discard block |
||
| 1060 | 1060 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1061 | 1061 | **/ |
| 1062 | 1062 | function spip_mysql_countsel( |
| 1063 | - $from = [], |
|
| 1064 | - $where = [], |
|
| 1065 | - $groupby = '', |
|
| 1066 | - $having = [], |
|
| 1067 | - $serveur = '', |
|
| 1068 | - $requeter = true |
|
| 1063 | + $from = [], |
|
| 1064 | + $where = [], |
|
| 1065 | + $groupby = '', |
|
| 1066 | + $having = [], |
|
| 1067 | + $serveur = '', |
|
| 1068 | + $requeter = true |
|
| 1069 | 1069 | ) { |
| 1070 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1071 | - |
|
| 1072 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1073 | - if (!$requeter) { |
|
| 1074 | - return $r; |
|
| 1075 | - } |
|
| 1076 | - if (!$r instanceof mysqli_result) { |
|
| 1077 | - return 0; |
|
| 1078 | - } |
|
| 1079 | - [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1080 | - mysqli_free_result($r); |
|
| 1081 | - |
|
| 1082 | - return $c; |
|
| 1070 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1071 | + |
|
| 1072 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1073 | + if (!$requeter) { |
|
| 1074 | + return $r; |
|
| 1075 | + } |
|
| 1076 | + if (!$r instanceof mysqli_result) { |
|
| 1077 | + return 0; |
|
| 1078 | + } |
|
| 1079 | + [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1080 | + mysqli_free_result($r); |
|
| 1081 | + |
|
| 1082 | + return $c; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | |
@@ -1102,16 +1102,16 @@ discard block |
||
| 1102 | 1102 | * Erreur eventuelle |
| 1103 | 1103 | **/ |
| 1104 | 1104 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1105 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1106 | - $s = mysqli_error($link); |
|
| 1107 | - if ($s) { |
|
| 1108 | - $trace = debug_backtrace(); |
|
| 1109 | - if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1110 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - return $s; |
|
| 1105 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1106 | + $s = mysqli_error($link); |
|
| 1107 | + if ($s) { |
|
| 1108 | + $trace = debug_backtrace(); |
|
| 1109 | + if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1110 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + return $s; |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1126,18 +1126,18 @@ discard block |
||
| 1126 | 1126 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1127 | 1127 | **/ |
| 1128 | 1128 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1129 | - $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1130 | - $s = mysqli_errno($link); |
|
| 1131 | - // 2006 MySQL server has gone away |
|
| 1132 | - // 2013 Lost connection to MySQL server during query |
|
| 1133 | - if (in_array($s, [2006, 2013])) { |
|
| 1134 | - define('spip_interdire_cache', true); |
|
| 1135 | - } |
|
| 1136 | - if ($s) { |
|
| 1137 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - return $s; |
|
| 1129 | + $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1130 | + $s = mysqli_errno($link); |
|
| 1131 | + // 2006 MySQL server has gone away |
|
| 1132 | + // 2013 Lost connection to MySQL server during query |
|
| 1133 | + if (in_array($s, [2006, 2013])) { |
|
| 1134 | + define('spip_interdire_cache', true); |
|
| 1135 | + } |
|
| 1136 | + if ($s) { |
|
| 1137 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + return $s; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | |
@@ -1151,9 +1151,9 @@ discard block |
||
| 1151 | 1151 | * @return int Nombre de lignes |
| 1152 | 1152 | */ |
| 1153 | 1153 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1154 | - if ($r) { |
|
| 1155 | - return mysqli_num_rows($r); |
|
| 1156 | - } |
|
| 1154 | + if ($r) { |
|
| 1155 | + return mysqli_num_rows($r); |
|
| 1156 | + } |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | * @return bool True si réussi |
| 1170 | 1170 | */ |
| 1171 | 1171 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1172 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1172 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1197,59 +1197,59 @@ discard block |
||
| 1197 | 1197 | **/ |
| 1198 | 1198 | function spip_mysql_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1199 | 1199 | |
| 1200 | - $e = null; |
|
| 1201 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1202 | - $link = $connexion['link']; |
|
| 1203 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1204 | - |
|
| 1205 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1206 | - if ( |
|
| 1207 | - defined('_MYSQL_NOPLANES') |
|
| 1208 | - and _MYSQL_NOPLANES |
|
| 1209 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1210 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1211 | - ) { |
|
| 1212 | - include_spip('inc/charsets'); |
|
| 1213 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1217 | - if (!$requeter) { |
|
| 1218 | - return $query; |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - if (isset($_GET['var_profile'])) { |
|
| 1222 | - include_spip('public/tracer'); |
|
| 1223 | - $t = trace_query_start(); |
|
| 1224 | - $e = ''; |
|
| 1225 | - } else { |
|
| 1226 | - $t = 0; |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - $connexion['last'] = $query; |
|
| 1230 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1231 | - $r = false; |
|
| 1232 | - $insert = false; |
|
| 1233 | - try { |
|
| 1234 | - $insert = mysqli_query($link, $query); |
|
| 1235 | - } catch (\mysqli_sql_exception $e) { |
|
| 1236 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1237 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1238 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1239 | - } |
|
| 1240 | - if ($insert) { |
|
| 1241 | - $r = mysqli_insert_id($link); |
|
| 1242 | - } else { |
|
| 1243 | - // Log de l'erreur eventuelle |
|
| 1244 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1245 | - // et du fautif |
|
| 1246 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1251 | - |
|
| 1252 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1200 | + $e = null; |
|
| 1201 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1202 | + $link = $connexion['link']; |
|
| 1203 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1204 | + |
|
| 1205 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1206 | + if ( |
|
| 1207 | + defined('_MYSQL_NOPLANES') |
|
| 1208 | + and _MYSQL_NOPLANES |
|
| 1209 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1210 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1211 | + ) { |
|
| 1212 | + include_spip('inc/charsets'); |
|
| 1213 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1217 | + if (!$requeter) { |
|
| 1218 | + return $query; |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + if (isset($_GET['var_profile'])) { |
|
| 1222 | + include_spip('public/tracer'); |
|
| 1223 | + $t = trace_query_start(); |
|
| 1224 | + $e = ''; |
|
| 1225 | + } else { |
|
| 1226 | + $t = 0; |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + $connexion['last'] = $query; |
|
| 1230 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1231 | + $r = false; |
|
| 1232 | + $insert = false; |
|
| 1233 | + try { |
|
| 1234 | + $insert = mysqli_query($link, $query); |
|
| 1235 | + } catch (\mysqli_sql_exception $e) { |
|
| 1236 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1237 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1238 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1239 | + } |
|
| 1240 | + if ($insert) { |
|
| 1241 | + $r = mysqli_insert_id($link); |
|
| 1242 | + } else { |
|
| 1243 | + // Log de l'erreur eventuelle |
|
| 1244 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1245 | + // et du fautif |
|
| 1246 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1251 | + |
|
| 1252 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | /** |
@@ -1274,26 +1274,26 @@ discard block |
||
| 1274 | 1274 | **/ |
| 1275 | 1275 | function spip_mysql_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1276 | 1276 | |
| 1277 | - if (!$desc) { |
|
| 1278 | - $desc = description_table($table, $serveur); |
|
| 1279 | - } |
|
| 1280 | - if (!$desc) { |
|
| 1281 | - $couples = []; |
|
| 1282 | - } |
|
| 1283 | - $fields = $desc['field'] ?? []; |
|
| 1284 | - |
|
| 1285 | - foreach ($couples as $champ => $val) { |
|
| 1286 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - return spip_mysql_insert( |
|
| 1290 | - $table, |
|
| 1291 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1292 | - '(' . join(',', $couples) . ')', |
|
| 1293 | - $desc, |
|
| 1294 | - $serveur, |
|
| 1295 | - $requeter |
|
| 1296 | - ); |
|
| 1277 | + if (!$desc) { |
|
| 1278 | + $desc = description_table($table, $serveur); |
|
| 1279 | + } |
|
| 1280 | + if (!$desc) { |
|
| 1281 | + $couples = []; |
|
| 1282 | + } |
|
| 1283 | + $fields = $desc['field'] ?? []; |
|
| 1284 | + |
|
| 1285 | + foreach ($couples as $champ => $val) { |
|
| 1286 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + return spip_mysql_insert( |
|
| 1290 | + $table, |
|
| 1291 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 1292 | + '(' . join(',', $couples) . ')', |
|
| 1293 | + $desc, |
|
| 1294 | + $serveur, |
|
| 1295 | + $requeter |
|
| 1296 | + ); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | |
@@ -1318,34 +1318,34 @@ discard block |
||
| 1318 | 1318 | **/ |
| 1319 | 1319 | function spip_mysql_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1320 | 1320 | |
| 1321 | - if (!$desc) { |
|
| 1322 | - $desc = description_table($table, $serveur); |
|
| 1323 | - } |
|
| 1324 | - if (!$desc) { |
|
| 1325 | - $tab_couples = []; |
|
| 1326 | - } |
|
| 1327 | - $fields = $desc['field'] ?? []; |
|
| 1328 | - |
|
| 1329 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1330 | - $valeurs = []; |
|
| 1331 | - $r = false; |
|
| 1332 | - |
|
| 1333 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1334 | - foreach ($tab_couples as $couples) { |
|
| 1335 | - foreach ($couples as $champ => $val) { |
|
| 1336 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1337 | - } |
|
| 1338 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1339 | - if (count($valeurs) >= 100) { |
|
| 1340 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1341 | - $valeurs = []; |
|
| 1342 | - } |
|
| 1343 | - } |
|
| 1344 | - if (count($valeurs)) { |
|
| 1345 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1321 | + if (!$desc) { |
|
| 1322 | + $desc = description_table($table, $serveur); |
|
| 1323 | + } |
|
| 1324 | + if (!$desc) { |
|
| 1325 | + $tab_couples = []; |
|
| 1326 | + } |
|
| 1327 | + $fields = $desc['field'] ?? []; |
|
| 1328 | + |
|
| 1329 | + $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1330 | + $valeurs = []; |
|
| 1331 | + $r = false; |
|
| 1332 | + |
|
| 1333 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1334 | + foreach ($tab_couples as $couples) { |
|
| 1335 | + foreach ($couples as $champ => $val) { |
|
| 1336 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1337 | + } |
|
| 1338 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1339 | + if (count($valeurs) >= 100) { |
|
| 1340 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1341 | + $valeurs = []; |
|
| 1342 | + } |
|
| 1343 | + } |
|
| 1344 | + if (count($valeurs)) { |
|
| 1345 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | /** |
@@ -1370,19 +1370,19 @@ discard block |
||
| 1370 | 1370 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1371 | 1371 | */ |
| 1372 | 1372 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1373 | - $set = []; |
|
| 1374 | - foreach ($champs as $champ => $val) { |
|
| 1375 | - $set[] = $champ . "=$val"; |
|
| 1376 | - } |
|
| 1377 | - if (!empty($set)) { |
|
| 1378 | - return spip_mysql_query( |
|
| 1379 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1380 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1381 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1382 | - $serveur, |
|
| 1383 | - $requeter |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1373 | + $set = []; |
|
| 1374 | + foreach ($champs as $champ => $val) { |
|
| 1375 | + $set[] = $champ . "=$val"; |
|
| 1376 | + } |
|
| 1377 | + if (!empty($set)) { |
|
| 1378 | + return spip_mysql_query( |
|
| 1379 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1380 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1381 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1382 | + $serveur, |
|
| 1383 | + $requeter |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | /** |
@@ -1415,29 +1415,29 @@ discard block |
||
| 1415 | 1415 | */ |
| 1416 | 1416 | function spip_mysql_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1417 | 1417 | |
| 1418 | - if (!$champs) { |
|
| 1419 | - return; |
|
| 1420 | - } |
|
| 1421 | - if (!$desc) { |
|
| 1422 | - $desc = description_table($table, $serveur); |
|
| 1423 | - } |
|
| 1424 | - if (!$desc) { |
|
| 1425 | - $champs = []; |
|
| 1426 | - } else { |
|
| 1427 | - $fields = $desc['field']; |
|
| 1428 | - } |
|
| 1429 | - $set = []; |
|
| 1430 | - foreach ($champs as $champ => $val) { |
|
| 1431 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - return spip_mysql_query( |
|
| 1435 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1436 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1437 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1438 | - $serveur, |
|
| 1439 | - $requeter |
|
| 1440 | - ); |
|
| 1418 | + if (!$champs) { |
|
| 1419 | + return; |
|
| 1420 | + } |
|
| 1421 | + if (!$desc) { |
|
| 1422 | + $desc = description_table($table, $serveur); |
|
| 1423 | + } |
|
| 1424 | + if (!$desc) { |
|
| 1425 | + $champs = []; |
|
| 1426 | + } else { |
|
| 1427 | + $fields = $desc['field']; |
|
| 1428 | + } |
|
| 1429 | + $set = []; |
|
| 1430 | + foreach ($champs as $champ => $val) { |
|
| 1431 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + return spip_mysql_query( |
|
| 1435 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1436 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1437 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1438 | + $serveur, |
|
| 1439 | + $requeter |
|
| 1440 | + ); |
|
| 1441 | 1441 | } |
| 1442 | 1442 | |
| 1443 | 1443 | /** |
@@ -1453,22 +1453,22 @@ discard block |
||
| 1453 | 1453 | * - False en cas d'erreur. |
| 1454 | 1454 | **/ |
| 1455 | 1455 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1456 | - $res = spip_mysql_query( |
|
| 1457 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1458 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1459 | - $serveur, |
|
| 1460 | - $requeter |
|
| 1461 | - ); |
|
| 1462 | - if (!$requeter) { |
|
| 1463 | - return $res; |
|
| 1464 | - } |
|
| 1465 | - if ($res) { |
|
| 1466 | - $link = _mysql_link($serveur); |
|
| 1467 | - |
|
| 1468 | - return mysqli_affected_rows($link); |
|
| 1469 | - } else { |
|
| 1470 | - return false; |
|
| 1471 | - } |
|
| 1456 | + $res = spip_mysql_query( |
|
| 1457 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1458 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1459 | + $serveur, |
|
| 1460 | + $requeter |
|
| 1461 | + ); |
|
| 1462 | + if (!$requeter) { |
|
| 1463 | + return $res; |
|
| 1464 | + } |
|
| 1465 | + if ($res) { |
|
| 1466 | + $link = _mysql_link($serveur); |
|
| 1467 | + |
|
| 1468 | + return mysqli_affected_rows($link); |
|
| 1469 | + } else { |
|
| 1470 | + return false; |
|
| 1471 | + } |
|
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
@@ -1497,10 +1497,10 @@ discard block |
||
| 1497 | 1497 | * - False en cas d'erreur. |
| 1498 | 1498 | **/ |
| 1499 | 1499 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1500 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1501 | - ',', |
|
| 1502 | - array_map('_q', $couples) |
|
| 1503 | - ) . ')', $serveur, $requeter); |
|
| 1500 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1501 | + ',', |
|
| 1502 | + array_map('_q', $couples) |
|
| 1503 | + ) . ')', $serveur, $requeter); |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | |
@@ -1529,14 +1529,14 @@ discard block |
||
| 1529 | 1529 | * - False en cas d'erreur. |
| 1530 | 1530 | **/ |
| 1531 | 1531 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1532 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1533 | - $valeurs = []; |
|
| 1534 | - foreach ($tab_couples as $couples) { |
|
| 1535 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1536 | - } |
|
| 1537 | - $valeurs = implode(', ', $valeurs); |
|
| 1538 | - |
|
| 1539 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1532 | + $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1533 | + $valeurs = []; |
|
| 1534 | + foreach ($tab_couples as $couples) { |
|
| 1535 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1536 | + } |
|
| 1537 | + $valeurs = implode(', ', $valeurs); |
|
| 1538 | + |
|
| 1539 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | |
@@ -1551,32 +1551,32 @@ discard block |
||
| 1551 | 1551 | * @return string Texte de sélection pour la requête |
| 1552 | 1552 | */ |
| 1553 | 1553 | function spip_mysql_multi($objet, $lang) { |
| 1554 | - $lengthlang = strlen("[$lang]"); |
|
| 1555 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1556 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1557 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1558 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1559 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1560 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1561 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1562 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1563 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1564 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1565 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1566 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1567 | - ' TRIM(' . $objet . '), ' . |
|
| 1568 | - ' CONCAT( ' . |
|
| 1569 | - " $debutchaine, " . |
|
| 1570 | - ' IF( ' . |
|
| 1571 | - " $poslang = 0, " . |
|
| 1572 | - " $chainemulti, " . |
|
| 1573 | - " $chainelang" . |
|
| 1574 | - ' ), ' . |
|
| 1575 | - " $finchaine" . |
|
| 1576 | - ' ) ' . |
|
| 1577 | - '))) AS multi'; |
|
| 1578 | - |
|
| 1579 | - return $retour; |
|
| 1554 | + $lengthlang = strlen("[$lang]"); |
|
| 1555 | + $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1556 | + $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1557 | + $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1558 | + $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1559 | + $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1560 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1561 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1562 | + $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1563 | + $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1564 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1565 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1566 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1567 | + ' TRIM(' . $objet . '), ' . |
|
| 1568 | + ' CONCAT( ' . |
|
| 1569 | + " $debutchaine, " . |
|
| 1570 | + ' IF( ' . |
|
| 1571 | + " $poslang = 0, " . |
|
| 1572 | + " $chainemulti, " . |
|
| 1573 | + " $chainelang" . |
|
| 1574 | + ' ), ' . |
|
| 1575 | + " $finchaine" . |
|
| 1576 | + ' ) ' . |
|
| 1577 | + '))) AS multi'; |
|
| 1578 | + |
|
| 1579 | + return $retour; |
|
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | /** |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | * Valeur hexadécimale pour MySQL |
| 1591 | 1591 | **/ |
| 1592 | 1592 | function spip_mysql_hex($v) { |
| 1593 | - return '0x' . $v; |
|
| 1593 | + return '0x' . $v; |
|
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | 1596 | /** |
@@ -1606,15 +1606,15 @@ discard block |
||
| 1606 | 1606 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1607 | 1607 | */ |
| 1608 | 1608 | function spip_mysql_quote($v, $type = '') { |
| 1609 | - if (!is_array($v)) { |
|
| 1610 | - return spip_mysql_cite($v, $type); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1614 | - foreach ($v as $k => $r) { |
|
| 1615 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1616 | - } |
|
| 1617 | - return implode(',', $v); |
|
| 1609 | + if (!is_array($v)) { |
|
| 1610 | + return spip_mysql_cite($v, $type); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1614 | + foreach ($v as $k => $r) { |
|
| 1615 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1616 | + } |
|
| 1617 | + return implode(',', $v); |
|
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | 1620 | /** |
@@ -1630,18 +1630,18 @@ discard block |
||
| 1630 | 1630 | * Expression SQL |
| 1631 | 1631 | **/ |
| 1632 | 1632 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1633 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1634 | - return '(' |
|
| 1635 | - . $champ |
|
| 1636 | - . (($interval <= 0) ? '>' : '<') |
|
| 1637 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1638 | - . '(' |
|
| 1639 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1640 | - . ', INTERVAL ' |
|
| 1641 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1642 | - . ' ' |
|
| 1643 | - . $unite |
|
| 1644 | - . '))'; |
|
| 1633 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1634 | + return '(' |
|
| 1635 | + . $champ |
|
| 1636 | + . (($interval <= 0) ? '>' : '<') |
|
| 1637 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1638 | + . '(' |
|
| 1639 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1640 | + . ', INTERVAL ' |
|
| 1641 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1642 | + . ' ' |
|
| 1643 | + . $unite |
|
| 1644 | + . '))'; |
|
| 1645 | 1645 | } |
| 1646 | 1646 | |
| 1647 | 1647 | |
@@ -1665,7 +1665,7 @@ discard block |
||
| 1665 | 1665 | * Expression de requête SQL |
| 1666 | 1666 | **/ |
| 1667 | 1667 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1668 | - return "($val $not IN ($valeurs))"; |
|
| 1668 | + return "($val $not IN ($valeurs))"; |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | |
@@ -1677,39 +1677,39 @@ discard block |
||
| 1677 | 1677 | * @return string|number Texte ou nombre échappé |
| 1678 | 1678 | */ |
| 1679 | 1679 | function spip_mysql_cite($v, $type) { |
| 1680 | - if (!$type) { |
|
| 1681 | - if (is_bool($v)) { |
|
| 1682 | - return strval(intval($v)); |
|
| 1683 | - } elseif (is_numeric($v)) { |
|
| 1684 | - return strval($v); |
|
| 1685 | - } elseif ($v === null) { |
|
| 1686 | - return "''"; |
|
| 1687 | - } |
|
| 1688 | - return "'" . addslashes($v) . "'"; |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - if ($v === null) { |
|
| 1692 | - if (stripos($type, 'NOT NULL') === false) { |
|
| 1693 | - // null php se traduit en NULL SQL |
|
| 1694 | - return 'NULL'; |
|
| 1695 | - } else { |
|
| 1696 | - return "''"; |
|
| 1697 | - } |
|
| 1698 | - } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1699 | - return $v; |
|
| 1700 | - } elseif (sql_test_int($type)) { |
|
| 1701 | - if ( |
|
| 1702 | - is_numeric($v) |
|
| 1703 | - or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1704 | - ) { |
|
| 1705 | - return $v; |
|
| 1706 | - } else { |
|
| 1707 | - // si pas numerique, forcer le intval |
|
| 1708 | - return intval($v); |
|
| 1709 | - } |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - return ("'" . addslashes($v) . "'"); |
|
| 1680 | + if (!$type) { |
|
| 1681 | + if (is_bool($v)) { |
|
| 1682 | + return strval(intval($v)); |
|
| 1683 | + } elseif (is_numeric($v)) { |
|
| 1684 | + return strval($v); |
|
| 1685 | + } elseif ($v === null) { |
|
| 1686 | + return "''"; |
|
| 1687 | + } |
|
| 1688 | + return "'" . addslashes($v) . "'"; |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + if ($v === null) { |
|
| 1692 | + if (stripos($type, 'NOT NULL') === false) { |
|
| 1693 | + // null php se traduit en NULL SQL |
|
| 1694 | + return 'NULL'; |
|
| 1695 | + } else { |
|
| 1696 | + return "''"; |
|
| 1697 | + } |
|
| 1698 | + } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1699 | + return $v; |
|
| 1700 | + } elseif (sql_test_int($type)) { |
|
| 1701 | + if ( |
|
| 1702 | + is_numeric($v) |
|
| 1703 | + or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1704 | + ) { |
|
| 1705 | + return $v; |
|
| 1706 | + } else { |
|
| 1707 | + // si pas numerique, forcer le intval |
|
| 1708 | + return intval($v); |
|
| 1709 | + } |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + return ("'" . addslashes($v) . "'"); |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | /** |
@@ -1719,7 +1719,7 @@ discard block |
||
| 1719 | 1719 | * True si on a les fonctions, false sinon |
| 1720 | 1720 | */ |
| 1721 | 1721 | function spip_versions_mysql() { |
| 1722 | - return function_exists('mysqli_query'); |
|
| 1722 | + return function_exists('mysqli_query'); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | |
@@ -1732,20 +1732,20 @@ discard block |
||
| 1732 | 1732 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1733 | 1733 | */ |
| 1734 | 1734 | function test_rappel_nom_base_mysql($server_db) { |
| 1735 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1736 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1737 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1735 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1736 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1737 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1738 | 1738 | |
| 1739 | - if ($ok) { |
|
| 1740 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1739 | + if ($ok) { |
|
| 1740 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1741 | 1741 | |
| 1742 | - return ''; |
|
| 1743 | - } else { |
|
| 1744 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1742 | + return ''; |
|
| 1743 | + } else { |
|
| 1744 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1745 | 1745 | |
| 1746 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1747 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1748 | - } |
|
| 1746 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1747 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1748 | + } |
|
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | 1751 | /** |
@@ -1759,13 +1759,13 @@ discard block |
||
| 1759 | 1759 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1760 | 1760 | */ |
| 1761 | 1761 | function test_sql_mode_mysql($server_db) { |
| 1762 | - $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1763 | - $row = sql_fetch($res, $server_db); |
|
| 1764 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1765 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1762 | + $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1763 | + $row = sql_fetch($res, $server_db); |
|
| 1764 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1765 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1766 | 1766 | |
| 1767 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1768 | - } |
|
| 1767 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1768 | + } |
|
| 1769 | 1769 | |
| 1770 | - return ''; |
|
| 1770 | + return ''; |
|
| 1771 | 1771 | } |
@@ -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 | /** |
@@ -22,320 +22,320 @@ discard block |
||
| 22 | 22 | * on a les memes methodes et variables que l'indenteur |
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | - if ($p = strpos($name, ':')) { |
|
| 28 | - $name = substr($name, $p + 1); |
|
| 29 | - $p = isset($this->dtc->elements[$name]); |
|
| 30 | - } |
|
| 31 | - if (!$p) { |
|
| 32 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | - . _T('zxml_inconnu_balise')); |
|
| 25 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | + if ($p = strpos($name, ':')) { |
|
| 28 | + $name = substr($name, $p + 1); |
|
| 29 | + $p = isset($this->dtc->elements[$name]); |
|
| 30 | + } |
|
| 31 | + if (!$p) { |
|
| 32 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | + . _T('zxml_inconnu_balise')); |
|
| 34 | 34 | |
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - // controler les filles illegitimes, ca suffit |
|
| 39 | - $depth = $this->depth; |
|
| 40 | - $ouvrant = $this->ouvrant; |
|
| 41 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | - if (isset($ouvrant[$depth])) { |
|
| 43 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 44 | - $pere = $r[1]; |
|
| 45 | - #spip_log("pere $pere"); |
|
| 46 | - if (isset($this->dtc->elements[$pere])) { |
|
| 47 | - $fils = $this->dtc->elements[$pere]; |
|
| 48 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 49 | - if (!($p = @in_array($name, $fils))) { |
|
| 50 | - if ($p = strpos($name, ':')) { |
|
| 51 | - $p = substr($name, $p + 1); |
|
| 52 | - $p = @in_array($p, $fils); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - if (!$p) { |
|
| 56 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 57 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 58 | - . _T('zxml_non_fils') |
|
| 59 | - . ' <b>' |
|
| 60 | - . $pere |
|
| 61 | - . '</b>' |
|
| 62 | - . (!$bons_peres ? '' |
|
| 63 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 64 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 65 | - $frat = substr($depth, 2); |
|
| 66 | - if (!isset($this->fratrie[$frat])) { |
|
| 67 | - $this->fratrie[$frat] = ''; |
|
| 68 | - } |
|
| 69 | - $this->fratrie[$frat] .= "$name "; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 75 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 76 | - $this->fratrie[$depth] = ''; |
|
| 77 | - } |
|
| 78 | - if (isset($this->dtc->attributs[$name])) { |
|
| 79 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 80 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 81 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 82 | - . ' : ' |
|
| 83 | - . _T('zxml_obligatoire_attribut') |
|
| 84 | - . " <b>$name</b>"); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + // controler les filles illegitimes, ca suffit |
|
| 39 | + $depth = $this->depth; |
|
| 40 | + $ouvrant = $this->ouvrant; |
|
| 41 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | + if (isset($ouvrant[$depth])) { |
|
| 43 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 44 | + $pere = $r[1]; |
|
| 45 | + #spip_log("pere $pere"); |
|
| 46 | + if (isset($this->dtc->elements[$pere])) { |
|
| 47 | + $fils = $this->dtc->elements[$pere]; |
|
| 48 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 49 | + if (!($p = @in_array($name, $fils))) { |
|
| 50 | + if ($p = strpos($name, ':')) { |
|
| 51 | + $p = substr($name, $p + 1); |
|
| 52 | + $p = @in_array($p, $fils); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + if (!$p) { |
|
| 56 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 57 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 58 | + . _T('zxml_non_fils') |
|
| 59 | + . ' <b>' |
|
| 60 | + . $pere |
|
| 61 | + . '</b>' |
|
| 62 | + . (!$bons_peres ? '' |
|
| 63 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 64 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 65 | + $frat = substr($depth, 2); |
|
| 66 | + if (!isset($this->fratrie[$frat])) { |
|
| 67 | + $this->fratrie[$frat] = ''; |
|
| 68 | + } |
|
| 69 | + $this->fratrie[$frat] .= "$name "; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 75 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 76 | + $this->fratrie[$depth] = ''; |
|
| 77 | + } |
|
| 78 | + if (isset($this->dtc->attributs[$name])) { |
|
| 79 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 80 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 81 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 82 | + . ' : ' |
|
| 83 | + . _T('zxml_obligatoire_attribut') |
|
| 84 | + . " <b>$name</b>"); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 91 | - // Si la balise est inconnue, eviter d'insister |
|
| 92 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 90 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 91 | + // Si la balise est inconnue, eviter d'insister |
|
| 92 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - $a = $this->dtc->attributs[$bal]; |
|
| 97 | - if (!isset($a[$name])) { |
|
| 98 | - $bons = join(', ', array_keys($a)); |
|
| 99 | - if ($bons) { |
|
| 100 | - $bons = " title=' " . |
|
| 101 | - _T('zxml_connus_attributs') . |
|
| 102 | - ' : ' . |
|
| 103 | - $bons . |
|
| 104 | - "'"; |
|
| 105 | - } |
|
| 106 | - $bons .= " style='font-weight: bold'"; |
|
| 107 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 108 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 109 | - . " <a$bons>$bal</a> (" |
|
| 110 | - . _T('zxml_survoler') |
|
| 111 | - . ')'); |
|
| 112 | - } else { |
|
| 113 | - $type = $a[$name][0]; |
|
| 114 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 115 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 116 | - } else { |
|
| 117 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 118 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 122 | - } |
|
| 123 | - } |
|
| 96 | + $a = $this->dtc->attributs[$bal]; |
|
| 97 | + if (!isset($a[$name])) { |
|
| 98 | + $bons = join(', ', array_keys($a)); |
|
| 99 | + if ($bons) { |
|
| 100 | + $bons = " title=' " . |
|
| 101 | + _T('zxml_connus_attributs') . |
|
| 102 | + ' : ' . |
|
| 103 | + $bons . |
|
| 104 | + "'"; |
|
| 105 | + } |
|
| 106 | + $bons .= " style='font-weight: bold'"; |
|
| 107 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 108 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 109 | + . " <a$bons>$bal</a> (" |
|
| 110 | + . _T('zxml_survoler') |
|
| 111 | + . ')'); |
|
| 112 | + } else { |
|
| 113 | + $type = $a[$name][0]; |
|
| 114 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 115 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 116 | + } else { |
|
| 117 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 118 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 126 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 127 | - } |
|
| 125 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 126 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 130 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 131 | - } |
|
| 129 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 130 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 134 | - if (isset($this->ids[$val])) { |
|
| 135 | - [$l, $c] = $this->ids[$val]; |
|
| 136 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 137 | - . _T('zxml_valeur_attribut') |
|
| 138 | - . " <b>$name</b> " |
|
| 139 | - . _T('zxml_de') |
|
| 140 | - . " <b>$bal</b> " |
|
| 141 | - . _T('zxml_vu') |
|
| 142 | - . " (L$l,C$c)"); |
|
| 143 | - } else { |
|
| 144 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 145 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | - } |
|
| 147 | - } |
|
| 133 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 134 | + if (isset($this->ids[$val])) { |
|
| 135 | + [$l, $c] = $this->ids[$val]; |
|
| 136 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 137 | + . _T('zxml_valeur_attribut') |
|
| 138 | + . " <b>$name</b> " |
|
| 139 | + . _T('zxml_de') |
|
| 140 | + . " <b>$bal</b> " |
|
| 141 | + . _T('zxml_vu') |
|
| 142 | + . " (L$l,C$c)"); |
|
| 143 | + } else { |
|
| 144 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 145 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 150 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 151 | - } |
|
| 149 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 150 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 154 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 155 | - } |
|
| 153 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 154 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 158 | - if (!preg_match($motif, $val)) { |
|
| 159 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 160 | - . _T('zxml_valeur_attribut') |
|
| 161 | - . " <b>$name</b> " |
|
| 162 | - . _T('zxml_de') |
|
| 163 | - . " <b>$bal</b> " |
|
| 164 | - . _T('zxml_non_conforme') |
|
| 165 | - . '</p><p>' |
|
| 166 | - . '<b>' . $motif . '</b>'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 157 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 158 | + if (!preg_match($motif, $val)) { |
|
| 159 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 160 | + . _T('zxml_valeur_attribut') |
|
| 161 | + . " <b>$name</b> " |
|
| 162 | + . _T('zxml_de') |
|
| 163 | + . " <b>$bal</b> " |
|
| 164 | + . _T('zxml_non_conforme') |
|
| 165 | + . '</p><p>' |
|
| 166 | + . '<b>' . $motif . '</b>'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - public function valider_idref($nom, $ligne, $col) { |
|
| 171 | - if (!isset($this->ids[$nom])) { |
|
| 172 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 173 | - } |
|
| 174 | - } |
|
| 170 | + public function valider_idref($nom, $ligne, $col) { |
|
| 171 | + if (!isset($this->ids[$nom])) { |
|
| 172 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - public function valider_passe2() { |
|
| 177 | - if (!$this->err) { |
|
| 178 | - foreach ($this->idrefs as $idref) { |
|
| 179 | - [$nom, $ligne, $col] = $idref; |
|
| 180 | - $this->valider_idref($nom, $ligne, $col); |
|
| 181 | - } |
|
| 182 | - foreach ($this->idrefss as $idref) { |
|
| 183 | - [$noms, $ligne, $col] = $idref; |
|
| 184 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 185 | - $this->valider_idref($nom, $ligne, $col); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 176 | + public function valider_passe2() { |
|
| 177 | + if (!$this->err) { |
|
| 178 | + foreach ($this->idrefs as $idref) { |
|
| 179 | + [$nom, $ligne, $col] = $idref; |
|
| 180 | + $this->valider_idref($nom, $ligne, $col); |
|
| 181 | + } |
|
| 182 | + foreach ($this->idrefss as $idref) { |
|
| 183 | + [$noms, $ligne, $col] = $idref; |
|
| 184 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 185 | + $this->valider_idref($nom, $ligne, $col); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 192 | - if ($this->dtc->elements) { |
|
| 193 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 194 | - } |
|
| 191 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 192 | + if ($this->dtc->elements) { |
|
| 193 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - if ($f = $this->process['debut']) { |
|
| 197 | - $f($this, $name, $attrs); |
|
| 198 | - } |
|
| 199 | - $depth = $this->depth; |
|
| 200 | - $this->debuts[$depth] = strlen($this->res); |
|
| 201 | - foreach ($attrs as $k => $v) { |
|
| 202 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 203 | - } |
|
| 204 | - } |
|
| 196 | + if ($f = $this->process['debut']) { |
|
| 197 | + $f($this, $name, $attrs); |
|
| 198 | + } |
|
| 199 | + $depth = $this->depth; |
|
| 200 | + $this->debuts[$depth] = strlen($this->res); |
|
| 201 | + foreach ($attrs as $k => $v) { |
|
| 202 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - public function finElement($phraseur, $name) { |
|
| 207 | - $depth = $this->depth; |
|
| 208 | - $contenu = $this->contenu; |
|
| 206 | + public function finElement($phraseur, $name) { |
|
| 207 | + $depth = $this->depth; |
|
| 208 | + $contenu = $this->contenu; |
|
| 209 | 209 | |
| 210 | - $n = strlen($this->res); |
|
| 211 | - $c = strlen(trim($contenu[$depth])); |
|
| 212 | - $k = $this->debuts[$depth]; |
|
| 210 | + $n = strlen($this->res); |
|
| 211 | + $c = strlen(trim($contenu[$depth])); |
|
| 212 | + $k = $this->debuts[$depth]; |
|
| 213 | 213 | |
| 214 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 215 | - $vide = ($regle == 'EMPTY'); |
|
| 216 | - // controler que les balises devant etre vides le sont |
|
| 217 | - if ($vide) { |
|
| 218 | - if ($n <> ($k + $c)) { |
|
| 219 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 220 | - } |
|
| 221 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 222 | - } elseif ($regle and ($regle != '*')) { |
|
| 223 | - if ($regle == '+') { |
|
| 224 | - // iteration de disjonction non vide: 1 balise au - |
|
| 225 | - if ($n == $k) { |
|
| 226 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 227 | - . _T('zxml_vide_balise')); |
|
| 228 | - } |
|
| 229 | - } else { |
|
| 230 | - $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 231 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 232 | - coordonnees_erreur( |
|
| 233 | - $this, |
|
| 234 | - " <p>\n<b>$name</b> " |
|
| 235 | - . _T('zxml_succession_fils_incorrecte') |
|
| 236 | - . ' : <b>' |
|
| 237 | - . $f |
|
| 238 | - . '</b>' |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - if ($f = $this->process['fin']) { |
|
| 244 | - $f($this, $name, $vide); |
|
| 245 | - } |
|
| 246 | - } |
|
| 214 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 215 | + $vide = ($regle == 'EMPTY'); |
|
| 216 | + // controler que les balises devant etre vides le sont |
|
| 217 | + if ($vide) { |
|
| 218 | + if ($n <> ($k + $c)) { |
|
| 219 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 220 | + } |
|
| 221 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 222 | + } elseif ($regle and ($regle != '*')) { |
|
| 223 | + if ($regle == '+') { |
|
| 224 | + // iteration de disjonction non vide: 1 balise au - |
|
| 225 | + if ($n == $k) { |
|
| 226 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 227 | + . _T('zxml_vide_balise')); |
|
| 228 | + } |
|
| 229 | + } else { |
|
| 230 | + $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 231 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 232 | + coordonnees_erreur( |
|
| 233 | + $this, |
|
| 234 | + " <p>\n<b>$name</b> " |
|
| 235 | + . _T('zxml_succession_fils_incorrecte') |
|
| 236 | + . ' : <b>' |
|
| 237 | + . $f |
|
| 238 | + . '</b>' |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + if ($f = $this->process['fin']) { |
|
| 244 | + $f($this, $name, $vide); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - public function textElement($phraseur, $data) { |
|
| 249 | - if (trim($data)) { |
|
| 250 | - $d = $this->depth; |
|
| 251 | - $d = $this->ouvrant[$d]; |
|
| 252 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 253 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 254 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 255 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - if ($f = $this->process['text']) { |
|
| 259 | - $f($this, $data); |
|
| 260 | - } |
|
| 261 | - } |
|
| 248 | + public function textElement($phraseur, $data) { |
|
| 249 | + if (trim($data)) { |
|
| 250 | + $d = $this->depth; |
|
| 251 | + $d = $this->ouvrant[$d]; |
|
| 252 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 253 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 254 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 255 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + if ($f = $this->process['text']) { |
|
| 259 | + $f($this, $data); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - public function piElement($phraseur, $target, $data) { |
|
| 264 | - if ($f = $this->process['pi']) { |
|
| 265 | - $f($this, $target, $data); |
|
| 266 | - } |
|
| 267 | - } |
|
| 263 | + public function piElement($phraseur, $target, $data) { |
|
| 264 | + if ($f = $this->process['pi']) { |
|
| 265 | + $f($this, $target, $data); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - // Denonciation des entitees XML inconnues |
|
| 270 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 271 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 272 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 273 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 274 | - // le source de la page laisse legitimement supposer. |
|
| 269 | + // Denonciation des entitees XML inconnues |
|
| 270 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 271 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 272 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 273 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 274 | + // le source de la page laisse legitimement supposer. |
|
| 275 | 275 | |
| 276 | - public function defaultElement($phraseur, $data) { |
|
| 277 | - if ( |
|
| 278 | - !preg_match('/^<!--/', $data) |
|
| 279 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 280 | - ) { |
|
| 281 | - foreach ($r as $m) { |
|
| 282 | - [$t, $e] = $m; |
|
| 283 | - if (!isset($this->dtc->entites[$e])) { |
|
| 284 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 285 | - . _T('zxml_inconnu_entite') |
|
| 286 | - . ' '); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 291 | - $f($this, $data); |
|
| 292 | - } |
|
| 293 | - } |
|
| 276 | + public function defaultElement($phraseur, $data) { |
|
| 277 | + if ( |
|
| 278 | + !preg_match('/^<!--/', $data) |
|
| 279 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 280 | + ) { |
|
| 281 | + foreach ($r as $m) { |
|
| 282 | + [$t, $e] = $m; |
|
| 283 | + if (!isset($this->dtc->entites[$e])) { |
|
| 284 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 285 | + . _T('zxml_inconnu_entite') |
|
| 286 | + . ' '); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 291 | + $f($this, $data); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - public function phraserTout($phraseur, $data) { |
|
| 296 | - xml_parsestring($this, $data); |
|
| 295 | + public function phraserTout($phraseur, $data) { |
|
| 296 | + xml_parsestring($this, $data); |
|
| 297 | 297 | |
| 298 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 299 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 300 | - } else { |
|
| 301 | - $this->valider_passe2(); |
|
| 302 | - } |
|
| 303 | - } |
|
| 298 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 299 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 300 | + } else { |
|
| 301 | + $this->valider_passe2(); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Constructeur |
|
| 307 | - * |
|
| 308 | - * @param array $process ? |
|
| 309 | - **/ |
|
| 310 | - public function __construct($process = []) { |
|
| 311 | - if (is_array($process)) { |
|
| 312 | - $this->process = $process; |
|
| 313 | - } |
|
| 314 | - } |
|
| 305 | + /** |
|
| 306 | + * Constructeur |
|
| 307 | + * |
|
| 308 | + * @param array $process ? |
|
| 309 | + **/ |
|
| 310 | + public function __construct($process = []) { |
|
| 311 | + if (is_array($process)) { |
|
| 312 | + $this->process = $process; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - public $ids = []; |
|
| 317 | - public $idrefs = []; |
|
| 318 | - public $idrefss = []; |
|
| 319 | - public $debuts = []; |
|
| 320 | - public $fratrie = []; |
|
| 316 | + public $ids = []; |
|
| 317 | + public $idrefs = []; |
|
| 318 | + public $idrefss = []; |
|
| 319 | + public $debuts = []; |
|
| 320 | + public $fratrie = []; |
|
| 321 | 321 | |
| 322 | - public $dtc = null; |
|
| 323 | - public $sax = null; |
|
| 324 | - public $depth = ''; |
|
| 325 | - public $entete = ''; |
|
| 326 | - public $page = ''; |
|
| 327 | - public $res = ''; |
|
| 328 | - public $err = []; |
|
| 329 | - public $contenu = []; |
|
| 330 | - public $ouvrant = []; |
|
| 331 | - public $reperes = []; |
|
| 332 | - public $process = [ |
|
| 333 | - 'debut' => 'xml_debutElement', |
|
| 334 | - 'fin' => 'xml_finElement', |
|
| 335 | - 'text' => 'xml_textElement', |
|
| 336 | - 'pi' => 'xml_piElement', |
|
| 337 | - 'default' => 'xml_defaultElement' |
|
| 338 | - ]; |
|
| 322 | + public $dtc = null; |
|
| 323 | + public $sax = null; |
|
| 324 | + public $depth = ''; |
|
| 325 | + public $entete = ''; |
|
| 326 | + public $page = ''; |
|
| 327 | + public $res = ''; |
|
| 328 | + public $err = []; |
|
| 329 | + public $contenu = []; |
|
| 330 | + public $ouvrant = []; |
|
| 331 | + public $reperes = []; |
|
| 332 | + public $process = [ |
|
| 333 | + 'debut' => 'xml_debutElement', |
|
| 334 | + 'fin' => 'xml_finElement', |
|
| 335 | + 'text' => 'xml_textElement', |
|
| 336 | + 'pi' => 'xml_piElement', |
|
| 337 | + 'default' => 'xml_defaultElement' |
|
| 338 | + ]; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * |
| 346 | 346 | **/ |
| 347 | 347 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 348 | - $f = new ValidateurXML($process); |
|
| 349 | - $sax = charger_fonction('sax', 'xml'); |
|
| 348 | + $f = new ValidateurXML($process); |
|
| 349 | + $sax = charger_fonction('sax', 'xml'); |
|
| 350 | 350 | |
| 351 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 351 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 352 | 352 | } |