@@ -623,11 +623,11 @@ |
||
| 623 | 623 | * |
| 624 | 624 | * @param $liste |
| 625 | 625 | * Liste de description des plugins |
| 626 | - * @param $nom |
|
| 626 | + * @param string $nom |
|
| 627 | 627 | * Le plugin donc on cherche la presence |
| 628 | 628 | * @param $intervalle |
| 629 | 629 | * L'éventuelle intervalle de compatibilité de la dépendance. ex: [1.1.0;] |
| 630 | - * @param $balise |
|
| 630 | + * @param string $balise |
|
| 631 | 631 | * Permet de définir si on teste un utilise ou un nécessite |
| 632 | 632 | * @return string. |
| 633 | 633 | * Vide si ok, |
@@ -555,11 +555,9 @@ discard block |
||
| 555 | 555 | if (!isset($msg[$p])) { |
| 556 | 556 | if (isset($resume['erreur']) and $resume['erreur']) { |
| 557 | 557 | $msg[$p] = array($resume['erreur']); |
| 558 | - } |
|
| 559 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 558 | + } elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 560 | 559 | $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')); |
| 561 | - } |
|
| 562 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 560 | + } elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 563 | 561 | $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
| 564 | 562 | } |
| 565 | 563 | } else { |
@@ -942,8 +940,7 @@ discard block |
||
| 942 | 940 | if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
| 943 | 941 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 944 | 942 | } |
| 945 | - } |
|
| 946 | - else{ |
|
| 943 | + } else{ |
|
| 947 | 944 | foreach ($info['chemin'] as $chemin) { |
| 948 | 945 | if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
| 949 | 946 | $GLOBALS['spip_version_branche'], 'spip') |
@@ -1166,10 +1163,12 @@ discard block |
||
| 1166 | 1163 | } |
| 1167 | 1164 | $nom = $nomlower; |
| 1168 | 1165 | // une action vide est une declaration qui ne doit pas etre compilee ! |
| 1169 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1166 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { |
|
| 1167 | + // creer le pipeline eventuel |
|
| 1170 | 1168 | { |
| 1171 | 1169 | $GLOBALS['spip_pipeline'][$nom] = ""; |
| 1172 | 1170 | } |
| 1171 | + } |
|
| 1173 | 1172 | if ($action) { |
| 1174 | 1173 | if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
| 1175 | 1174 | $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
@@ -1430,8 +1429,7 @@ discard block |
||
| 1430 | 1429 | if (file_exists($nom)) { |
| 1431 | 1430 | if (substr($nom, -4) == '.php') { |
| 1432 | 1431 | $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
| 1433 | - } |
|
| 1434 | - else { |
|
| 1432 | + } else { |
|
| 1435 | 1433 | $fichier_tmp = $nom . '.tmp'; |
| 1436 | 1434 | } |
| 1437 | 1435 | file_put_contents($fichier_tmp, $contenu); |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | **/ |
| 49 | 49 | function liste_plugin_files($dir_plugins = null) { |
| 50 | - static $plugin_files = array(); |
|
| 51 | - if (is_null($dir_plugins)) { |
|
| 52 | - $dir_plugins = _DIR_PLUGINS; |
|
| 53 | - } |
|
| 54 | - if (!isset($plugin_files[$dir_plugins]) |
|
| 55 | - or count($plugin_files[$dir_plugins]) == 0 |
|
| 56 | - ) { |
|
| 57 | - $plugin_files[$dir_plugins] = array(); |
|
| 58 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - sort($plugin_files[$dir_plugins]); |
|
| 63 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $plugin_files[$dir_plugins]; |
|
| 50 | + static $plugin_files = array(); |
|
| 51 | + if (is_null($dir_plugins)) { |
|
| 52 | + $dir_plugins = _DIR_PLUGINS; |
|
| 53 | + } |
|
| 54 | + if (!isset($plugin_files[$dir_plugins]) |
|
| 55 | + or count($plugin_files[$dir_plugins]) == 0 |
|
| 56 | + ) { |
|
| 57 | + $plugin_files[$dir_plugins] = array(); |
|
| 58 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + sort($plugin_files[$dir_plugins]); |
|
| 63 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $plugin_files[$dir_plugins]; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -82,44 +82,44 @@ discard block |
||
| 82 | 82 | * Liste complète des répeertoires |
| 83 | 83 | **/ |
| 84 | 84 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 85 | - $fichiers = array(); |
|
| 86 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | - if ($dir == '') { |
|
| 90 | - $dir = '.'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!is_dir($dir)) { |
|
| 94 | - return $fichiers; |
|
| 95 | - } |
|
| 96 | - if (is_plugin_dir($dir, '')) { |
|
| 97 | - $fichiers[] = $dir; |
|
| 98 | - |
|
| 99 | - return $fichiers; |
|
| 100 | - } |
|
| 101 | - if ($max_prof <= 0) { |
|
| 102 | - return $fichiers; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $subdirs = array(); |
|
| 106 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 107 | - while (($f = readdir($d)) !== false) { |
|
| 108 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 109 | - and $f != 'CVS' |
|
| 110 | - and is_dir($f = "$dir/$f") |
|
| 111 | - ) { |
|
| 112 | - $subdirs[] = $f; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - closedir($d); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - foreach ($subdirs as $d) { |
|
| 119 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $fichiers; |
|
| 85 | + $fichiers = array(); |
|
| 86 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | + if ($dir == '') { |
|
| 90 | + $dir = '.'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!is_dir($dir)) { |
|
| 94 | + return $fichiers; |
|
| 95 | + } |
|
| 96 | + if (is_plugin_dir($dir, '')) { |
|
| 97 | + $fichiers[] = $dir; |
|
| 98 | + |
|
| 99 | + return $fichiers; |
|
| 100 | + } |
|
| 101 | + if ($max_prof <= 0) { |
|
| 102 | + return $fichiers; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $subdirs = array(); |
|
| 106 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 107 | + while (($f = readdir($d)) !== false) { |
|
| 108 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 109 | + and $f != 'CVS' |
|
| 110 | + and is_dir($f = "$dir/$f") |
|
| 111 | + ) { |
|
| 112 | + $subdirs[] = $f; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + closedir($d); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + foreach ($subdirs as $d) { |
|
| 119 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $fichiers; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,27 +140,27 @@ discard block |
||
| 140 | 140 | **/ |
| 141 | 141 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 142 | 142 | |
| 143 | - if (is_array($dir)) { |
|
| 144 | - foreach ($dir as $k => $d) { |
|
| 145 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | - unset($dir[$k]); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $dir; |
|
| 151 | - } |
|
| 152 | - if (is_null($dir_plugins)) { |
|
| 153 | - $dir_plugins = _DIR_PLUGINS; |
|
| 154 | - } |
|
| 155 | - $search = array("$dir_plugins$dir/paquet.xml"); |
|
| 156 | - |
|
| 157 | - foreach ($search as $s) { |
|
| 158 | - if (file_exists($s)) { |
|
| 159 | - return $dir; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return ''; |
|
| 143 | + if (is_array($dir)) { |
|
| 144 | + foreach ($dir as $k => $d) { |
|
| 145 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | + unset($dir[$k]); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $dir; |
|
| 151 | + } |
|
| 152 | + if (is_null($dir_plugins)) { |
|
| 153 | + $dir_plugins = _DIR_PLUGINS; |
|
| 154 | + } |
|
| 155 | + $search = array("$dir_plugins$dir/paquet.xml"); |
|
| 156 | + |
|
| 157 | + foreach ($search as $s) { |
|
| 158 | + if (file_exists($s)) { |
|
| 159 | + return $dir; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return ''; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -187,51 +187,51 @@ discard block |
||
| 187 | 187 | **/ |
| 188 | 188 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 189 | 189 | |
| 190 | - if (!strlen($intervalle)) { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 193 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | - $minimum = $regs[1]; |
|
| 199 | - $maximum = $regs[2]; |
|
| 200 | - |
|
| 201 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | - // entre plugins) |
|
| 206 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $minimum_inc = $intervalle[0] == "["; |
|
| 215 | - $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 216 | - |
|
| 217 | - if (strlen($minimum)) { |
|
| 218 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - if (strlen($maximum)) { |
|
| 226 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return true; |
|
| 190 | + if (!strlen($intervalle)) { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | + $minimum = $regs[1]; |
|
| 199 | + $maximum = $regs[2]; |
|
| 200 | + |
|
| 201 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | + // entre plugins) |
|
| 206 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $minimum_inc = $intervalle[0] == "["; |
|
| 215 | + $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 216 | + |
|
| 217 | + if (strlen($minimum)) { |
|
| 218 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + if (strlen($maximum)) { |
|
| 226 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return true; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -248,62 +248,62 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function liste_plugin_valides($liste_plug, $force = false) { |
| 251 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | - $infos = array( |
|
| 254 | - // lister les extensions qui sont automatiquement actives |
|
| 255 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | - ); |
|
| 258 | - |
|
| 259 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 264 | - $liste_non_classee = array( |
|
| 265 | - 'SPIP' => array( |
|
| 266 | - 'nom' => 'SPIP', |
|
| 267 | - 'etat' => 'stable', |
|
| 268 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | - 'dir' => '', |
|
| 271 | - ) |
|
| 272 | - ); |
|
| 273 | - |
|
| 274 | - $invalides = array(); |
|
| 275 | - foreach ($liste_ext as $plug) { |
|
| 276 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - foreach ($liste_plug as $plug) { |
|
| 281 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | - if (is_array($r)) { |
|
| 284 | - $invalides = array_merge($invalides, $r); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 290 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | - foreach ($liste_plug as $plug) { |
|
| 292 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | - if (is_array($r)) { |
|
| 295 | - $invalides = array_merge($invalides, $r); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | - |
|
| 303 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | - |
|
| 306 | - return array($infos, $liste_non_classee, $invalides); |
|
| 251 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | + $infos = array( |
|
| 254 | + // lister les extensions qui sont automatiquement actives |
|
| 255 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | + ); |
|
| 258 | + |
|
| 259 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 264 | + $liste_non_classee = array( |
|
| 265 | + 'SPIP' => array( |
|
| 266 | + 'nom' => 'SPIP', |
|
| 267 | + 'etat' => 'stable', |
|
| 268 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | + 'dir' => '', |
|
| 271 | + ) |
|
| 272 | + ); |
|
| 273 | + |
|
| 274 | + $invalides = array(); |
|
| 275 | + foreach ($liste_ext as $plug) { |
|
| 276 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + foreach ($liste_plug as $plug) { |
|
| 281 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | + if (is_array($r)) { |
|
| 284 | + $invalides = array_merge($invalides, $r); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 290 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | + foreach ($liste_plug as $plug) { |
|
| 292 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | + if (is_array($r)) { |
|
| 295 | + $invalides = array_merge($invalides, $r); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | + |
|
| 303 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | + |
|
| 306 | + return array($infos, $liste_non_classee, $invalides); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -323,29 +323,29 @@ discard block |
||
| 323 | 323 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 324 | 324 | */ |
| 325 | 325 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 326 | - $i = $infos[$dir_type][$plug]; |
|
| 327 | - $p = strtoupper($i['prefix']); |
|
| 328 | - $short_desc = array( |
|
| 329 | - 'nom' => $i['nom'], |
|
| 330 | - 'etat' => $i['etat'], |
|
| 331 | - 'version' => $i['version'], |
|
| 332 | - 'dir' => $plug, |
|
| 333 | - 'dir_type' => $dir_type |
|
| 334 | - ); |
|
| 335 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 336 | - $short_desc['erreur'] = $i['erreur']; |
|
| 337 | - return array($p=>$short_desc); |
|
| 338 | - } |
|
| 339 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 340 | - return array($p=>$short_desc); |
|
| 341 | - } |
|
| 342 | - if (!isset($liste[$p]) |
|
| 343 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 344 | - ) { |
|
| 345 | - $liste[$p] = $short_desc; |
|
| 346 | - } |
|
| 347 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 348 | - return $p; |
|
| 326 | + $i = $infos[$dir_type][$plug]; |
|
| 327 | + $p = strtoupper($i['prefix']); |
|
| 328 | + $short_desc = array( |
|
| 329 | + 'nom' => $i['nom'], |
|
| 330 | + 'etat' => $i['etat'], |
|
| 331 | + 'version' => $i['version'], |
|
| 332 | + 'dir' => $plug, |
|
| 333 | + 'dir_type' => $dir_type |
|
| 334 | + ); |
|
| 335 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 336 | + $short_desc['erreur'] = $i['erreur']; |
|
| 337 | + return array($p=>$short_desc); |
|
| 338 | + } |
|
| 339 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 340 | + return array($p=>$short_desc); |
|
| 341 | + } |
|
| 342 | + if (!isset($liste[$p]) |
|
| 343 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 344 | + ) { |
|
| 345 | + $liste[$p] = $short_desc; |
|
| 346 | + } |
|
| 347 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 348 | + return $p; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -361,46 +361,46 @@ discard block |
||
| 361 | 361 | * @param array $infos |
| 362 | 362 | */ |
| 363 | 363 | function plugin_fixer_procure(&$liste, &$infos) { |
| 364 | - foreach ($liste as $p => $resume) { |
|
| 365 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 366 | - if (isset($i['procure']) and $i['procure']) { |
|
| 367 | - foreach ($i['procure'] as $procure) { |
|
| 368 | - $p = strtoupper($procure['nom']); |
|
| 369 | - $dir = $resume['dir']; |
|
| 370 | - if ($dir) { |
|
| 371 | - $dir .= "/"; |
|
| 372 | - } |
|
| 373 | - $dir .= "procure:" . $procure['nom']; |
|
| 374 | - |
|
| 375 | - $procure['etat'] = '?'; |
|
| 376 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 377 | - $procure['dir'] = $dir; |
|
| 378 | - |
|
| 379 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 380 | - // on ajoute cette version a la liste |
|
| 381 | - if (!isset($liste[$p]) |
|
| 382 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 383 | - ) { |
|
| 384 | - $liste[$p] = $procure; |
|
| 385 | - |
|
| 386 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 387 | - $infos[$resume['dir_type']][$dir] = array( |
|
| 388 | - 'prefix' => $procure['nom'], |
|
| 389 | - 'nom' => $procure['nom'], |
|
| 390 | - 'etat' => $procure['etat'], |
|
| 391 | - 'version' => $procure['version'], |
|
| 392 | - 'chemin' => array(), |
|
| 393 | - 'necessite' => array(), |
|
| 394 | - 'utilise' => array(), |
|
| 395 | - 'lib' => array(), |
|
| 396 | - 'menu' => array(), |
|
| 397 | - 'onglet' => array(), |
|
| 398 | - 'procure' => array(), |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 364 | + foreach ($liste as $p => $resume) { |
|
| 365 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 366 | + if (isset($i['procure']) and $i['procure']) { |
|
| 367 | + foreach ($i['procure'] as $procure) { |
|
| 368 | + $p = strtoupper($procure['nom']); |
|
| 369 | + $dir = $resume['dir']; |
|
| 370 | + if ($dir) { |
|
| 371 | + $dir .= "/"; |
|
| 372 | + } |
|
| 373 | + $dir .= "procure:" . $procure['nom']; |
|
| 374 | + |
|
| 375 | + $procure['etat'] = '?'; |
|
| 376 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 377 | + $procure['dir'] = $dir; |
|
| 378 | + |
|
| 379 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 380 | + // on ajoute cette version a la liste |
|
| 381 | + if (!isset($liste[$p]) |
|
| 382 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 383 | + ) { |
|
| 384 | + $liste[$p] = $procure; |
|
| 385 | + |
|
| 386 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 387 | + $infos[$resume['dir_type']][$dir] = array( |
|
| 388 | + 'prefix' => $procure['nom'], |
|
| 389 | + 'nom' => $procure['nom'], |
|
| 390 | + 'etat' => $procure['etat'], |
|
| 391 | + 'version' => $procure['version'], |
|
| 392 | + 'chemin' => array(), |
|
| 393 | + 'necessite' => array(), |
|
| 394 | + 'utilise' => array(), |
|
| 395 | + 'lib' => array(), |
|
| 396 | + 'menu' => array(), |
|
| 397 | + 'onglet' => array(), |
|
| 398 | + 'procure' => array(), |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -414,19 +414,19 @@ discard block |
||
| 414 | 414 | * @return array |
| 415 | 415 | */ |
| 416 | 416 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 417 | - foreach ($liste as $prefix => $infos) { |
|
| 418 | - if (!$dir_plugins |
|
| 419 | - or ( |
|
| 420 | - defined($infos['dir_type']) |
|
| 421 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 422 | - ) { |
|
| 423 | - $liste[$prefix] = $infos['dir']; |
|
| 424 | - } else { |
|
| 425 | - unset($liste[$prefix]); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return $liste; |
|
| 417 | + foreach ($liste as $prefix => $infos) { |
|
| 418 | + if (!$dir_plugins |
|
| 419 | + or ( |
|
| 420 | + defined($infos['dir_type']) |
|
| 421 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 422 | + ) { |
|
| 423 | + $liste[$prefix] = $infos['dir']; |
|
| 424 | + } else { |
|
| 425 | + unset($liste[$prefix]); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return $liste; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -441,9 +441,9 @@ discard block |
||
| 441 | 441 | * @return array |
| 442 | 442 | */ |
| 443 | 443 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 444 | - include_spip('plugins/installer'); |
|
| 444 | + include_spip('plugins/installer'); |
|
| 445 | 445 | |
| 446 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 446 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -474,53 +474,53 @@ discard block |
||
| 474 | 474 | * qui n'ont pas satisfait leurs dépendances |
| 475 | 475 | **/ |
| 476 | 476 | function plugin_trier($infos, $liste_non_classee) { |
| 477 | - $toute_la_liste = $liste_non_classee; |
|
| 478 | - $liste = $ordre = array(); |
|
| 479 | - $count = 0; |
|
| 480 | - |
|
| 481 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 482 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 483 | - $count = $c; |
|
| 484 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 485 | - $plug = $resume['dir']; |
|
| 486 | - $dir_type = $resume['dir_type']; |
|
| 487 | - $info1 = $infos[$dir_type][$plug]; |
|
| 488 | - // si des plugins sont necessaires, |
|
| 489 | - // on ne peut inserer qu'apres eux |
|
| 490 | - foreach ($info1['necessite'] as $need) { |
|
| 491 | - $nom = strtoupper($need['nom']); |
|
| 492 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 493 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 494 | - $info1 = false; |
|
| 495 | - break; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - if (!$info1) { |
|
| 499 | - continue; |
|
| 500 | - } |
|
| 501 | - // idem si des plugins sont utiles, |
|
| 502 | - // sauf si ils sont de toute facon absents de la liste |
|
| 503 | - foreach ($info1['utilise'] as $need) { |
|
| 504 | - $nom = strtoupper($need['nom']); |
|
| 505 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 506 | - if (isset($toute_la_liste[$nom])) { |
|
| 507 | - if (!isset($liste[$nom]) or |
|
| 508 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 509 | - ) { |
|
| 510 | - $info1 = false; |
|
| 511 | - break; |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - if ($info1) { |
|
| 516 | - $ordre[$p] = $info1; |
|
| 517 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 518 | - unset($liste_non_classee[$p]); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - return array($liste, $ordre, $liste_non_classee); |
|
| 477 | + $toute_la_liste = $liste_non_classee; |
|
| 478 | + $liste = $ordre = array(); |
|
| 479 | + $count = 0; |
|
| 480 | + |
|
| 481 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 482 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 483 | + $count = $c; |
|
| 484 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 485 | + $plug = $resume['dir']; |
|
| 486 | + $dir_type = $resume['dir_type']; |
|
| 487 | + $info1 = $infos[$dir_type][$plug]; |
|
| 488 | + // si des plugins sont necessaires, |
|
| 489 | + // on ne peut inserer qu'apres eux |
|
| 490 | + foreach ($info1['necessite'] as $need) { |
|
| 491 | + $nom = strtoupper($need['nom']); |
|
| 492 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 493 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 494 | + $info1 = false; |
|
| 495 | + break; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + if (!$info1) { |
|
| 499 | + continue; |
|
| 500 | + } |
|
| 501 | + // idem si des plugins sont utiles, |
|
| 502 | + // sauf si ils sont de toute facon absents de la liste |
|
| 503 | + foreach ($info1['utilise'] as $need) { |
|
| 504 | + $nom = strtoupper($need['nom']); |
|
| 505 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 506 | + if (isset($toute_la_liste[$nom])) { |
|
| 507 | + if (!isset($liste[$nom]) or |
|
| 508 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 509 | + ) { |
|
| 510 | + $info1 = false; |
|
| 511 | + break; |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + if ($info1) { |
|
| 516 | + $ordre[$p] = $info1; |
|
| 517 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 518 | + unset($liste_non_classee[$p]); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + return array($liste, $ordre, $liste_non_classee); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -537,40 +537,40 @@ discard block |
||
| 537 | 537 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 538 | 538 | **/ |
| 539 | 539 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array()) { |
| 540 | - static $erreurs = array(); |
|
| 541 | - |
|
| 542 | - if (!is_array($liste)) { |
|
| 543 | - $liste = array(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 547 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 548 | - |
|
| 549 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 550 | - $dir_type = $resume['dir_type']; |
|
| 551 | - $plug = $resume['dir']; |
|
| 552 | - $k = $infos[$dir_type][$plug]; |
|
| 553 | - |
|
| 554 | - $plug = constant($dir_type) . $plug; |
|
| 555 | - if (!isset($msg[$p])) { |
|
| 556 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 557 | - $msg[$p] = array($resume['erreur']); |
|
| 558 | - } |
|
| 559 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 560 | - $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')); |
|
| 561 | - } |
|
| 562 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 563 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 564 | - } |
|
| 565 | - } else { |
|
| 566 | - foreach ($msg[$p] as $c => $l) { |
|
| 567 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - $erreurs[$plug] = $msg[$p]; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 540 | + static $erreurs = array(); |
|
| 541 | + |
|
| 542 | + if (!is_array($liste)) { |
|
| 543 | + $liste = array(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 547 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 548 | + |
|
| 549 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 550 | + $dir_type = $resume['dir_type']; |
|
| 551 | + $plug = $resume['dir']; |
|
| 552 | + $k = $infos[$dir_type][$plug]; |
|
| 553 | + |
|
| 554 | + $plug = constant($dir_type) . $plug; |
|
| 555 | + if (!isset($msg[$p])) { |
|
| 556 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 557 | + $msg[$p] = array($resume['erreur']); |
|
| 558 | + } |
|
| 559 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 560 | + $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')); |
|
| 561 | + } |
|
| 562 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 563 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 564 | + } |
|
| 565 | + } else { |
|
| 566 | + foreach ($msg[$p] as $c => $l) { |
|
| 567 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + $erreurs[$plug] = $msg[$p]; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -585,25 +585,25 @@ discard block |
||
| 585 | 585 | * - Liste des erreurs ou code HTML des erreurs |
| 586 | 586 | **/ |
| 587 | 587 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 588 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 589 | - return $raw ? array() : ''; |
|
| 590 | - } |
|
| 591 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 592 | - // Compat ancienne version |
|
| 593 | - if (!$list) { |
|
| 594 | - $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 595 | - } elseif (!$raw) { |
|
| 596 | - foreach ($list as $plug => $msg) { |
|
| 597 | - $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | - . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 599 | - } |
|
| 600 | - $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 601 | - } |
|
| 602 | - if ($raz) { |
|
| 603 | - effacer_meta('plugin_erreur_activation'); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return $list; |
|
| 588 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 589 | + return $raw ? array() : ''; |
|
| 590 | + } |
|
| 591 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 592 | + // Compat ancienne version |
|
| 593 | + if (!$list) { |
|
| 594 | + $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 595 | + } elseif (!$raw) { |
|
| 596 | + foreach ($list as $plug => $msg) { |
|
| 597 | + $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | + . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 599 | + } |
|
| 600 | + $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 601 | + } |
|
| 602 | + if ($raz) { |
|
| 603 | + effacer_meta('plugin_erreur_activation'); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return $list; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -623,21 +623,21 @@ discard block |
||
| 623 | 623 | * |
| 624 | 624 | **/ |
| 625 | 625 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 626 | - $msg = array(); |
|
| 627 | - foreach ($n as $need) { |
|
| 628 | - $id = strtoupper($need['nom']); |
|
| 629 | - $r = plugin_controler_necessite( |
|
| 630 | - $liste, |
|
| 631 | - $id, |
|
| 632 | - isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 633 | - $balise |
|
| 634 | - ); |
|
| 635 | - if ($r) { |
|
| 636 | - $msg[] = $r; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $msg; |
|
| 626 | + $msg = array(); |
|
| 627 | + foreach ($n as $need) { |
|
| 628 | + $id = strtoupper($need['nom']); |
|
| 629 | + $r = plugin_controler_necessite( |
|
| 630 | + $liste, |
|
| 631 | + $id, |
|
| 632 | + isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 633 | + $balise |
|
| 634 | + ); |
|
| 635 | + if ($r) { |
|
| 636 | + $msg[] = $r; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $msg; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -659,19 +659,19 @@ discard block |
||
| 659 | 659 | * Message d'erreur lorsque la dépendance est absente. |
| 660 | 660 | **/ |
| 661 | 661 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 662 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 663 | - return ''; |
|
| 664 | - } |
|
| 665 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 666 | - if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 667 | - return ''; |
|
| 668 | - } |
|
| 669 | - return plugin_message_incompatibilite( |
|
| 670 | - $intervalle, |
|
| 671 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 672 | - $nom, |
|
| 673 | - $balise |
|
| 674 | - ); |
|
| 662 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 663 | + return ''; |
|
| 664 | + } |
|
| 665 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 666 | + if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 667 | + return ''; |
|
| 668 | + } |
|
| 669 | + return plugin_message_incompatibilite( |
|
| 670 | + $intervalle, |
|
| 671 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 672 | + $nom, |
|
| 673 | + $balise |
|
| 674 | + ); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -688,70 +688,70 @@ discard block |
||
| 688 | 688 | */ |
| 689 | 689 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 690 | 690 | |
| 691 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 692 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 693 | - $type = 'plugin'; |
|
| 694 | - if ($nom === 'SPIP') { |
|
| 695 | - $type = 'spip'; |
|
| 696 | - } elseif ($nom === 'PHP') { |
|
| 697 | - $type = 'php'; |
|
| 698 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 699 | - $type = 'extension_php'; |
|
| 700 | - list(,$nom) = explode(':', $nom, 2); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 704 | - $minimum = $regs[1]; |
|
| 705 | - $maximum = $regs[2]; |
|
| 706 | - |
|
| 707 | - $minimum_inclus = $intervalle[0] == "["; |
|
| 708 | - $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 709 | - |
|
| 710 | - if (strlen($minimum)) { |
|
| 711 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 712 | - return _T("plugin_${balise}_${type}", array( |
|
| 713 | - 'plugin' => $nom, |
|
| 714 | - 'version' => ' ≥ ' . $minimum |
|
| 715 | - )); |
|
| 716 | - } |
|
| 717 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 718 | - return _T("plugin_${balise}_${type}", array( |
|
| 719 | - 'plugin' => $nom, |
|
| 720 | - 'version' => ' > ' . $minimum |
|
| 721 | - )); |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - if (strlen($maximum)) { |
|
| 726 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 727 | - return _T("plugin_${balise}_${type}", array( |
|
| 728 | - 'plugin' => $nom, |
|
| 729 | - 'version' => ' ≤ ' . $maximum |
|
| 730 | - )); |
|
| 731 | - } |
|
| 732 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 733 | - return _T("plugin_${balise}_plugin", array( |
|
| 734 | - 'plugin' => $nom, |
|
| 735 | - 'version' => ' < ' . $maximum |
|
| 736 | - )); |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 742 | - // - un 'utilise' sans version. |
|
| 743 | - // - un 'php' sans version. |
|
| 744 | - return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 691 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 692 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 693 | + $type = 'plugin'; |
|
| 694 | + if ($nom === 'SPIP') { |
|
| 695 | + $type = 'spip'; |
|
| 696 | + } elseif ($nom === 'PHP') { |
|
| 697 | + $type = 'php'; |
|
| 698 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 699 | + $type = 'extension_php'; |
|
| 700 | + list(,$nom) = explode(':', $nom, 2); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 704 | + $minimum = $regs[1]; |
|
| 705 | + $maximum = $regs[2]; |
|
| 706 | + |
|
| 707 | + $minimum_inclus = $intervalle[0] == "["; |
|
| 708 | + $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 709 | + |
|
| 710 | + if (strlen($minimum)) { |
|
| 711 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 712 | + return _T("plugin_${balise}_${type}", array( |
|
| 713 | + 'plugin' => $nom, |
|
| 714 | + 'version' => ' ≥ ' . $minimum |
|
| 715 | + )); |
|
| 716 | + } |
|
| 717 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 718 | + return _T("plugin_${balise}_${type}", array( |
|
| 719 | + 'plugin' => $nom, |
|
| 720 | + 'version' => ' > ' . $minimum |
|
| 721 | + )); |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + if (strlen($maximum)) { |
|
| 726 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 727 | + return _T("plugin_${balise}_${type}", array( |
|
| 728 | + 'plugin' => $nom, |
|
| 729 | + 'version' => ' ≤ ' . $maximum |
|
| 730 | + )); |
|
| 731 | + } |
|
| 732 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 733 | + return _T("plugin_${balise}_plugin", array( |
|
| 734 | + 'plugin' => $nom, |
|
| 735 | + 'version' => ' < ' . $maximum |
|
| 736 | + )); |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 742 | + // - un 'utilise' sans version. |
|
| 743 | + // - un 'php' sans version. |
|
| 744 | + return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | |
| 748 | 748 | function plugin_controler_lib($lib, $url) { |
| 749 | - /* Feature sortie du core, voir STP |
|
| 749 | + /* Feature sortie du core, voir STP |
|
| 750 | 750 | * if ($url) { |
| 751 | 751 | include_spip('inc/charger_plugin'); |
| 752 | 752 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 753 | 753 | }*/ |
| 754 | - return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 754 | + return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 767 | 767 | **/ |
| 768 | 768 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 769 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 769 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -793,113 +793,113 @@ discard block |
||
| 793 | 793 | **/ |
| 794 | 794 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 795 | 795 | |
| 796 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 797 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 798 | - |
|
| 799 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 800 | - if (!$cache and !spip_connect()) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - if ($operation != 'raz') { |
|
| 805 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 806 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 807 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 808 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 809 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 810 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 811 | - } |
|
| 812 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 813 | - // on les reinjecte ici |
|
| 814 | - if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 815 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 816 | - ) { |
|
| 817 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - if ($operation == 'ajoute') { |
|
| 821 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 822 | - } elseif ($operation == 'enleve') { |
|
| 823 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 824 | - } else { |
|
| 825 | - $plugin = $plugin_valides; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 829 | - |
|
| 830 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 831 | - if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 832 | - $plugin = $ajouter_dependances($plugin); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - // recharger le xml des plugins a activer |
|
| 836 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 837 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 838 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 839 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 840 | - list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true); |
|
| 841 | - // trouver l'ordre d'activation |
|
| 842 | - list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 843 | - if ($invalides or $reste) { |
|
| 844 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - // Ignorer les plugins necessitant une lib absente |
|
| 848 | - // et preparer la meta d'entete Http |
|
| 849 | - $err = $msg = $header = array(); |
|
| 850 | - foreach ($plugin_valides as $p => $resume) { |
|
| 851 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 852 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 853 | - $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 854 | - } |
|
| 855 | - if ($resume['dir']) { |
|
| 856 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 857 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 858 | - $err[$p] = $resume; |
|
| 859 | - $msg[$p][] = $l; |
|
| 860 | - unset($plugin_valides[$p]); |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - if ($err) { |
|
| 866 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 870 | - effacer_meta('message_crash_plugins'); |
|
| 871 | - } |
|
| 872 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 873 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 874 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 875 | - $header = strtolower(implode(",", $header)); |
|
| 876 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 877 | - ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 878 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 879 | - } else { |
|
| 880 | - @unlink(_DIR_VAR . "config.txt"); |
|
| 881 | - } |
|
| 882 | - // generer charger_plugins_chemin.php |
|
| 883 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 884 | - // generer les fichiers |
|
| 885 | - // - charger_plugins_options.php |
|
| 886 | - // - charger_plugins_fonctions.php |
|
| 887 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 888 | - // charger les chemins des plugins et les fichiers d'options |
|
| 889 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 890 | - plugins_amorcer_plugins_actifs(); |
|
| 891 | - // mise a jour de la matrice des pipelines |
|
| 892 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 893 | - // generer le fichier _CACHE_PIPELINE |
|
| 894 | - pipeline_precompile($prepend_code); |
|
| 895 | - |
|
| 896 | - if (spip_connect()) { |
|
| 897 | - // lancer et initialiser les nouveaux crons ! |
|
| 898 | - include_spip('inc/genie'); |
|
| 899 | - genie_queue_watch_dist(); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 796 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 797 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 798 | + |
|
| 799 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 800 | + if (!$cache and !spip_connect()) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + if ($operation != 'raz') { |
|
| 805 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 806 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 807 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 808 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 809 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 810 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 811 | + } |
|
| 812 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 813 | + // on les reinjecte ici |
|
| 814 | + if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 815 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 816 | + ) { |
|
| 817 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + if ($operation == 'ajoute') { |
|
| 821 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 822 | + } elseif ($operation == 'enleve') { |
|
| 823 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 824 | + } else { |
|
| 825 | + $plugin = $plugin_valides; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 829 | + |
|
| 830 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 831 | + if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 832 | + $plugin = $ajouter_dependances($plugin); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + // recharger le xml des plugins a activer |
|
| 836 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 837 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 838 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 839 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 840 | + list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true); |
|
| 841 | + // trouver l'ordre d'activation |
|
| 842 | + list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 843 | + if ($invalides or $reste) { |
|
| 844 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + // Ignorer les plugins necessitant une lib absente |
|
| 848 | + // et preparer la meta d'entete Http |
|
| 849 | + $err = $msg = $header = array(); |
|
| 850 | + foreach ($plugin_valides as $p => $resume) { |
|
| 851 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 852 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 853 | + $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 854 | + } |
|
| 855 | + if ($resume['dir']) { |
|
| 856 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 857 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 858 | + $err[$p] = $resume; |
|
| 859 | + $msg[$p][] = $l; |
|
| 860 | + unset($plugin_valides[$p]); |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + if ($err) { |
|
| 866 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 870 | + effacer_meta('message_crash_plugins'); |
|
| 871 | + } |
|
| 872 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 873 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 874 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 875 | + $header = strtolower(implode(",", $header)); |
|
| 876 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 877 | + ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 878 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 879 | + } else { |
|
| 880 | + @unlink(_DIR_VAR . "config.txt"); |
|
| 881 | + } |
|
| 882 | + // generer charger_plugins_chemin.php |
|
| 883 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 884 | + // generer les fichiers |
|
| 885 | + // - charger_plugins_options.php |
|
| 886 | + // - charger_plugins_fonctions.php |
|
| 887 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 888 | + // charger les chemins des plugins et les fichiers d'options |
|
| 889 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 890 | + plugins_amorcer_plugins_actifs(); |
|
| 891 | + // mise a jour de la matrice des pipelines |
|
| 892 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 893 | + // generer le fichier _CACHE_PIPELINE |
|
| 894 | + pipeline_precompile($prepend_code); |
|
| 895 | + |
|
| 896 | + if (spip_connect()) { |
|
| 897 | + // lancer et initialiser les nouveaux crons ! |
|
| 898 | + include_spip('inc/genie'); |
|
| 899 | + genie_queue_watch_dist(); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -918,68 +918,68 @@ discard block |
||
| 918 | 918 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 919 | 919 | **/ |
| 920 | 920 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 921 | - $chemins = [ |
|
| 922 | - 'public' => [], |
|
| 923 | - 'prive' => [] |
|
| 924 | - ]; |
|
| 925 | - $contenu = ""; |
|
| 926 | - foreach ($ordre as $p => $info) { |
|
| 927 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 928 | - if (isset($plugin_valides[$p])) { |
|
| 929 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 930 | - $plug = $plugin_valides[$p]['dir']; |
|
| 931 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 932 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 933 | - |
|
| 934 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 935 | - |
|
| 936 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 937 | - if ( |
|
| 938 | - $prefix !== "SPIP" |
|
| 939 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 940 | - ) { |
|
| 941 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 942 | - if (!$info['chemin']) { |
|
| 943 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 944 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 945 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 946 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - else{ |
|
| 950 | - foreach ($info['chemin'] as $chemin) { |
|
| 951 | - if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 952 | - $GLOBALS['spip_version_branche'], 'spip') |
|
| 953 | - ) { |
|
| 954 | - $dir = $chemin['path']; |
|
| 955 | - if (strlen($dir) and $dir[0] == "/") { |
|
| 956 | - $dir = substr($dir, 1); |
|
| 957 | - } |
|
| 958 | - if (strlen($dir) and $dir == "./") { |
|
| 959 | - $dir = ''; |
|
| 960 | - } |
|
| 961 | - if (strlen($dir)) { |
|
| 962 | - $dir = rtrim($dir, '/') . '/'; |
|
| 963 | - } |
|
| 964 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 965 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 966 | - } |
|
| 967 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 968 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 977 | - $contenu .= "if (_DIR_RESTREINT) _chemin([" . implode(',', |
|
| 978 | - array_reverse($chemins['public'])) . "]);\n" |
|
| 979 | - . "else _chemin([" . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 921 | + $chemins = [ |
|
| 922 | + 'public' => [], |
|
| 923 | + 'prive' => [] |
|
| 924 | + ]; |
|
| 925 | + $contenu = ""; |
|
| 926 | + foreach ($ordre as $p => $info) { |
|
| 927 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 928 | + if (isset($plugin_valides[$p])) { |
|
| 929 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 930 | + $plug = $plugin_valides[$p]['dir']; |
|
| 931 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 932 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 933 | + |
|
| 934 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 935 | + |
|
| 936 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 937 | + if ( |
|
| 938 | + $prefix !== "SPIP" |
|
| 939 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 940 | + ) { |
|
| 941 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 942 | + if (!$info['chemin']) { |
|
| 943 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 944 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 945 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 946 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + else{ |
|
| 950 | + foreach ($info['chemin'] as $chemin) { |
|
| 951 | + if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 952 | + $GLOBALS['spip_version_branche'], 'spip') |
|
| 953 | + ) { |
|
| 954 | + $dir = $chemin['path']; |
|
| 955 | + if (strlen($dir) and $dir[0] == "/") { |
|
| 956 | + $dir = substr($dir, 1); |
|
| 957 | + } |
|
| 958 | + if (strlen($dir) and $dir == "./") { |
|
| 959 | + $dir = ''; |
|
| 960 | + } |
|
| 961 | + if (strlen($dir)) { |
|
| 962 | + $dir = rtrim($dir, '/') . '/'; |
|
| 963 | + } |
|
| 964 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 965 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 966 | + } |
|
| 967 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 968 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 977 | + $contenu .= "if (_DIR_RESTREINT) _chemin([" . implode(',', |
|
| 978 | + array_reverse($chemins['public'])) . "]);\n" |
|
| 979 | + . "else _chemin([" . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | /** |
@@ -997,65 +997,65 @@ discard block |
||
| 997 | 997 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 998 | 998 | **/ |
| 999 | 999 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1000 | - $contenu = array('options' => '', 'fonctions' => ''); |
|
| 1001 | - $boutons = array(); |
|
| 1002 | - $onglets = array(); |
|
| 1003 | - $sign = ""; |
|
| 1004 | - |
|
| 1005 | - foreach ($ordre as $p => $info) { |
|
| 1006 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1007 | - if (isset($plugin_valides[$p])) { |
|
| 1008 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1009 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1010 | - $dir = constant($dir_type); |
|
| 1011 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1012 | - if ($info['menu']) { |
|
| 1013 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1014 | - } |
|
| 1015 | - if ($info['onglet']) { |
|
| 1016 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1017 | - } |
|
| 1018 | - foreach ($contenu as $charge => $v) { |
|
| 1019 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1020 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1021 | - // donc ni sa relecture, ni sa detection |
|
| 1022 | - if (!isset($info[$charge]) |
|
| 1023 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1024 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 1025 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1026 | - ) { |
|
| 1027 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 1028 | - $info[$charge] = array($file); |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - if (isset($info[$charge])) { |
|
| 1032 | - $files = $info[$charge]; |
|
| 1033 | - foreach ($files as $k => $file) { |
|
| 1034 | - // on genere un if file_exists devant chaque include |
|
| 1035 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1036 | - $file = trim($file); |
|
| 1037 | - if (!is_readable("$dir$plug/$file") |
|
| 1038 | - // uniquement pour les paquet.xml |
|
| 1039 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1040 | - ) { |
|
| 1041 | - unset($info[$charge][$k]); |
|
| 1042 | - } else { |
|
| 1043 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1044 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - $sign .= md5(serialize($info)); |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1054 | - $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1055 | - . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1056 | - |
|
| 1057 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1058 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1000 | + $contenu = array('options' => '', 'fonctions' => ''); |
|
| 1001 | + $boutons = array(); |
|
| 1002 | + $onglets = array(); |
|
| 1003 | + $sign = ""; |
|
| 1004 | + |
|
| 1005 | + foreach ($ordre as $p => $info) { |
|
| 1006 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1007 | + if (isset($plugin_valides[$p])) { |
|
| 1008 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1009 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1010 | + $dir = constant($dir_type); |
|
| 1011 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1012 | + if ($info['menu']) { |
|
| 1013 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1014 | + } |
|
| 1015 | + if ($info['onglet']) { |
|
| 1016 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1017 | + } |
|
| 1018 | + foreach ($contenu as $charge => $v) { |
|
| 1019 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1020 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1021 | + // donc ni sa relecture, ni sa detection |
|
| 1022 | + if (!isset($info[$charge]) |
|
| 1023 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1024 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 1025 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1026 | + ) { |
|
| 1027 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 1028 | + $info[$charge] = array($file); |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + if (isset($info[$charge])) { |
|
| 1032 | + $files = $info[$charge]; |
|
| 1033 | + foreach ($files as $k => $file) { |
|
| 1034 | + // on genere un if file_exists devant chaque include |
|
| 1035 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1036 | + $file = trim($file); |
|
| 1037 | + if (!is_readable("$dir$plug/$file") |
|
| 1038 | + // uniquement pour les paquet.xml |
|
| 1039 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1040 | + ) { |
|
| 1041 | + unset($info[$charge][$k]); |
|
| 1042 | + } else { |
|
| 1043 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1044 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + $sign .= md5(serialize($info)); |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1054 | + $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1055 | + . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1056 | + |
|
| 1057 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1058 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1074,24 +1074,24 @@ discard block |
||
| 1074 | 1074 | * @return string Code php |
| 1075 | 1075 | */ |
| 1076 | 1076 | function plugin_ongletbouton($nom, $val) { |
| 1077 | - if (!$val) { |
|
| 1078 | - $val = array(); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $val = serialize($val); |
|
| 1082 | - $md5 = md5($val); |
|
| 1083 | - |
|
| 1084 | - if (!defined("_UPDATED_$nom")) { |
|
| 1085 | - define("_UPDATED_$nom", $val); |
|
| 1086 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1087 | - } |
|
| 1088 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1089 | - |
|
| 1090 | - return |
|
| 1091 | - "if (!function_exists('$nom')) {\n" |
|
| 1092 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1093 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1094 | - . "}\n"; |
|
| 1077 | + if (!$val) { |
|
| 1078 | + $val = array(); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $val = serialize($val); |
|
| 1082 | + $md5 = md5($val); |
|
| 1083 | + |
|
| 1084 | + if (!defined("_UPDATED_$nom")) { |
|
| 1085 | + define("_UPDATED_$nom", $val); |
|
| 1086 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1087 | + } |
|
| 1088 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1089 | + |
|
| 1090 | + return |
|
| 1091 | + "if (!function_exists('$nom')) {\n" |
|
| 1092 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1093 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1094 | + . "}\n"; |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | /** |
@@ -1106,15 +1106,15 @@ discard block |
||
| 1106 | 1106 | **/ |
| 1107 | 1107 | function plugins_amorcer_plugins_actifs() { |
| 1108 | 1108 | |
| 1109 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1110 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1111 | - } |
|
| 1109 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1110 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1114 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1115 | - } else { |
|
| 1116 | - spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1117 | - } |
|
| 1113 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1114 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1115 | + } else { |
|
| 1116 | + spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1117 | + } |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | /** |
@@ -1137,136 +1137,136 @@ discard block |
||
| 1137 | 1137 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1138 | 1138 | **/ |
| 1139 | 1139 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1140 | - static $liste_pipe_manquants = array(); |
|
| 1141 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1142 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - $prepend_code = array(); |
|
| 1146 | - |
|
| 1147 | - foreach ($ordre as $p => $info) { |
|
| 1148 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1149 | - if (isset($plugin_valides[$p])) { |
|
| 1150 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1151 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1152 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1153 | - $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1154 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1155 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1156 | - $nom = $pipe['nom']; |
|
| 1157 | - if (isset($pipe['action'])) { |
|
| 1158 | - $action = $pipe['action']; |
|
| 1159 | - } else { |
|
| 1160 | - $action = $nom; |
|
| 1161 | - } |
|
| 1162 | - $nomlower = strtolower($nom); |
|
| 1163 | - if ($nomlower != $nom |
|
| 1164 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1165 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1166 | - ) { |
|
| 1167 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1168 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1169 | - } |
|
| 1170 | - $nom = $nomlower; |
|
| 1171 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1172 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1173 | - { |
|
| 1174 | - $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1175 | - } |
|
| 1176 | - if ($action) { |
|
| 1177 | - if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1178 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1179 | - $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1180 | - } |
|
| 1181 | - if (isset($pipe['inclure'])) { |
|
| 1182 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1183 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1184 | - } |
|
| 1185 | - } |
|
| 1186 | - } |
|
| 1187 | - } |
|
| 1188 | - if (isset($info['genie']) and count($info['genie'])) { |
|
| 1189 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1190 | - $prepend_code['taches_generales_cron'] = ""; |
|
| 1191 | - } |
|
| 1192 | - foreach ($info['genie'] as $genie) { |
|
| 1193 | - $nom = $prefix . $genie['nom']; |
|
| 1194 | - $periode = max(60, intval($genie['periode'])); |
|
| 1195 | - if (charger_fonction($nom, "genie", true)) { |
|
| 1196 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1197 | - } else { |
|
| 1198 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - } |
|
| 1202 | - if (isset($info['style']) and count($info['style'])) { |
|
| 1203 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1204 | - $prepend_code['insert_head_css'] = ""; |
|
| 1205 | - } |
|
| 1206 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1207 | - $prepend_code['header_prive_css'] = ""; |
|
| 1208 | - } |
|
| 1209 | - foreach ($info['style'] as $style) { |
|
| 1210 | - if (isset($style['path']) and $style['path']) { |
|
| 1211 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1212 | - } else { |
|
| 1213 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1214 | - } |
|
| 1215 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1216 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1217 | - $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1218 | - } |
|
| 1219 | - $code .= "/>';\n"; |
|
| 1220 | - if ($style['type'] != 'prive') { |
|
| 1221 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1222 | - } |
|
| 1223 | - if ($style['type'] != 'public') { |
|
| 1224 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1225 | - } |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1229 | - $prepend_code['insert_head'] = ""; |
|
| 1230 | - } |
|
| 1231 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1232 | - $prepend_code['header_prive'] = ""; |
|
| 1233 | - } |
|
| 1234 | - if (isset($info['script']) and count($info['script'])) { |
|
| 1235 | - foreach ($info['script'] as $script) { |
|
| 1236 | - if (isset($script['path']) and $script['path']) { |
|
| 1237 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1238 | - } else { |
|
| 1239 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1240 | - } |
|
| 1241 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1242 | - if ($script['type'] != 'prive') { |
|
| 1243 | - $prepend_code['insert_head'] .= $code; |
|
| 1244 | - } |
|
| 1245 | - if ($script['type'] != 'public') { |
|
| 1246 | - $prepend_code['header_prive'] .= $code; |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - $prepend_code['insert_head'] = |
|
| 1254 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1255 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1256 | - . $prepend_code['insert_head']; |
|
| 1257 | - $prepend_code['header_prive'] = |
|
| 1258 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1259 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1260 | - . $prepend_code['header_prive']; |
|
| 1261 | - |
|
| 1262 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1263 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1264 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1265 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - return $prepend_code; |
|
| 1140 | + static $liste_pipe_manquants = array(); |
|
| 1141 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1142 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + $prepend_code = array(); |
|
| 1146 | + |
|
| 1147 | + foreach ($ordre as $p => $info) { |
|
| 1148 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1149 | + if (isset($plugin_valides[$p])) { |
|
| 1150 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1151 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1152 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1153 | + $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1154 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1155 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1156 | + $nom = $pipe['nom']; |
|
| 1157 | + if (isset($pipe['action'])) { |
|
| 1158 | + $action = $pipe['action']; |
|
| 1159 | + } else { |
|
| 1160 | + $action = $nom; |
|
| 1161 | + } |
|
| 1162 | + $nomlower = strtolower($nom); |
|
| 1163 | + if ($nomlower != $nom |
|
| 1164 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1165 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1166 | + ) { |
|
| 1167 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1168 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1169 | + } |
|
| 1170 | + $nom = $nomlower; |
|
| 1171 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1172 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1173 | + { |
|
| 1174 | + $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1175 | + } |
|
| 1176 | + if ($action) { |
|
| 1177 | + if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1178 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1179 | + $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1180 | + } |
|
| 1181 | + if (isset($pipe['inclure'])) { |
|
| 1182 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1183 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1184 | + } |
|
| 1185 | + } |
|
| 1186 | + } |
|
| 1187 | + } |
|
| 1188 | + if (isset($info['genie']) and count($info['genie'])) { |
|
| 1189 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1190 | + $prepend_code['taches_generales_cron'] = ""; |
|
| 1191 | + } |
|
| 1192 | + foreach ($info['genie'] as $genie) { |
|
| 1193 | + $nom = $prefix . $genie['nom']; |
|
| 1194 | + $periode = max(60, intval($genie['periode'])); |
|
| 1195 | + if (charger_fonction($nom, "genie", true)) { |
|
| 1196 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1197 | + } else { |
|
| 1198 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + } |
|
| 1202 | + if (isset($info['style']) and count($info['style'])) { |
|
| 1203 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1204 | + $prepend_code['insert_head_css'] = ""; |
|
| 1205 | + } |
|
| 1206 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1207 | + $prepend_code['header_prive_css'] = ""; |
|
| 1208 | + } |
|
| 1209 | + foreach ($info['style'] as $style) { |
|
| 1210 | + if (isset($style['path']) and $style['path']) { |
|
| 1211 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1212 | + } else { |
|
| 1213 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1214 | + } |
|
| 1215 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1216 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1217 | + $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1218 | + } |
|
| 1219 | + $code .= "/>';\n"; |
|
| 1220 | + if ($style['type'] != 'prive') { |
|
| 1221 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1222 | + } |
|
| 1223 | + if ($style['type'] != 'public') { |
|
| 1224 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1225 | + } |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1229 | + $prepend_code['insert_head'] = ""; |
|
| 1230 | + } |
|
| 1231 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1232 | + $prepend_code['header_prive'] = ""; |
|
| 1233 | + } |
|
| 1234 | + if (isset($info['script']) and count($info['script'])) { |
|
| 1235 | + foreach ($info['script'] as $script) { |
|
| 1236 | + if (isset($script['path']) and $script['path']) { |
|
| 1237 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1238 | + } else { |
|
| 1239 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1240 | + } |
|
| 1241 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1242 | + if ($script['type'] != 'prive') { |
|
| 1243 | + $prepend_code['insert_head'] .= $code; |
|
| 1244 | + } |
|
| 1245 | + if ($script['type'] != 'public') { |
|
| 1246 | + $prepend_code['header_prive'] .= $code; |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + $prepend_code['insert_head'] = |
|
| 1254 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1255 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1256 | + . $prepend_code['insert_head']; |
|
| 1257 | + $prepend_code['header_prive'] = |
|
| 1258 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1259 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1260 | + . $prepend_code['header_prive']; |
|
| 1261 | + |
|
| 1262 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1263 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1264 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1265 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + return $prepend_code; |
|
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | /** |
@@ -1293,62 +1293,62 @@ discard block |
||
| 1293 | 1293 | **/ |
| 1294 | 1294 | function pipeline_precompile($prepend_code = array()) { |
| 1295 | 1295 | |
| 1296 | - $all_pipes = $all_pipes_end = ''; |
|
| 1297 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1298 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1299 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1300 | - $all_pipes = trim(array_shift($a)); |
|
| 1301 | - if ($all_pipes) { |
|
| 1302 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1303 | - } |
|
| 1304 | - if (count($a)) { |
|
| 1305 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1308 | - $content = ""; |
|
| 1309 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1310 | - $s_inc = ""; |
|
| 1311 | - $s_call = ""; |
|
| 1312 | - if ($all_pipes) { |
|
| 1313 | - $pipeline = preg_replace(",(\|\||$),", "$all_pipes\\1", $pipeline, 1); |
|
| 1314 | - } |
|
| 1315 | - if ($all_pipes_end) { |
|
| 1316 | - $pipeline .= $all_pipes_end; |
|
| 1317 | - } |
|
| 1318 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1319 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1320 | - foreach ($pipe as $fonc) { |
|
| 1321 | - $fonc = trim($fonc); |
|
| 1322 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1323 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1324 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1325 | - $file = "'$file'"; |
|
| 1326 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1327 | - if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1328 | - $dir = $regs[1]; |
|
| 1329 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1330 | - if (defined($root_dir)) { |
|
| 1331 | - $dir = $root_dir; |
|
| 1332 | - } |
|
| 1333 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1334 | - $file = str_replace("''.", "", $file); |
|
| 1335 | - $file = str_replace(constant($dir), '', $file); |
|
| 1336 | - } |
|
| 1337 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - if (strlen($s_inc)) { |
|
| 1341 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1342 | - } |
|
| 1343 | - $content .= "// Pipeline $action \n" |
|
| 1344 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1345 | - . $s_inc |
|
| 1346 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1347 | - . $s_call |
|
| 1348 | - . "return \$val;\n}\n"; |
|
| 1349 | - } |
|
| 1350 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1351 | - clear_path_cache(); |
|
| 1296 | + $all_pipes = $all_pipes_end = ''; |
|
| 1297 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1298 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1299 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1300 | + $all_pipes = trim(array_shift($a)); |
|
| 1301 | + if ($all_pipes) { |
|
| 1302 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1303 | + } |
|
| 1304 | + if (count($a)) { |
|
| 1305 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | + $content = ""; |
|
| 1309 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1310 | + $s_inc = ""; |
|
| 1311 | + $s_call = ""; |
|
| 1312 | + if ($all_pipes) { |
|
| 1313 | + $pipeline = preg_replace(",(\|\||$),", "$all_pipes\\1", $pipeline, 1); |
|
| 1314 | + } |
|
| 1315 | + if ($all_pipes_end) { |
|
| 1316 | + $pipeline .= $all_pipes_end; |
|
| 1317 | + } |
|
| 1318 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1319 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1320 | + foreach ($pipe as $fonc) { |
|
| 1321 | + $fonc = trim($fonc); |
|
| 1322 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1323 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1324 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1325 | + $file = "'$file'"; |
|
| 1326 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1327 | + if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1328 | + $dir = $regs[1]; |
|
| 1329 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1330 | + if (defined($root_dir)) { |
|
| 1331 | + $dir = $root_dir; |
|
| 1332 | + } |
|
| 1333 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1334 | + $file = str_replace("''.", "", $file); |
|
| 1335 | + $file = str_replace(constant($dir), '', $file); |
|
| 1336 | + } |
|
| 1337 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + if (strlen($s_inc)) { |
|
| 1341 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1342 | + } |
|
| 1343 | + $content .= "// Pipeline $action \n" |
|
| 1344 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1345 | + . $s_inc |
|
| 1346 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1347 | + . $s_call |
|
| 1348 | + . "return \$val;\n}\n"; |
|
| 1349 | + } |
|
| 1350 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1351 | + clear_path_cache(); |
|
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | 1354 | |
@@ -1361,12 +1361,12 @@ discard block |
||
| 1361 | 1361 | * true si le plugin est actif, false sinon |
| 1362 | 1362 | **/ |
| 1363 | 1363 | function plugin_est_installe($plug_path) { |
| 1364 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1365 | - if (!$plugin_installes) { |
|
| 1366 | - return false; |
|
| 1367 | - } |
|
| 1364 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1365 | + if (!$plugin_installes) { |
|
| 1366 | + return false; |
|
| 1367 | + } |
|
| 1368 | 1368 | |
| 1369 | - return in_array($plug_path, $plugin_installes); |
|
| 1369 | + return in_array($plug_path, $plugin_installes); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | |
@@ -1379,37 +1379,37 @@ discard block |
||
| 1379 | 1379 | * @uses plugins_installer_dist() |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function plugin_installes_meta() { |
| 1382 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1383 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1384 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1388 | - $meta_plug_installes = array(); |
|
| 1389 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1390 | - if ($plug = $resume['dir']) { |
|
| 1391 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1392 | - if ($infos) { |
|
| 1393 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1394 | - $meta_plug_installes[] = $plug; |
|
| 1395 | - } |
|
| 1396 | - if (is_array($infos)) { |
|
| 1397 | - list($ok, $trace) = $infos['install_test']; |
|
| 1398 | - include_spip('inc/filtres_boites'); |
|
| 1399 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1400 | - . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1401 | - ($ok ? 'success' : 'error')) |
|
| 1402 | - . $trace |
|
| 1403 | - . "<div class='result'>" |
|
| 1404 | - . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1405 | - . "</div>" |
|
| 1406 | - . boite_fermer() |
|
| 1407 | - . "</div>"; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1382 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1383 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1384 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1388 | + $meta_plug_installes = array(); |
|
| 1389 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1390 | + if ($plug = $resume['dir']) { |
|
| 1391 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1392 | + if ($infos) { |
|
| 1393 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1394 | + $meta_plug_installes[] = $plug; |
|
| 1395 | + } |
|
| 1396 | + if (is_array($infos)) { |
|
| 1397 | + list($ok, $trace) = $infos['install_test']; |
|
| 1398 | + include_spip('inc/filtres_boites'); |
|
| 1399 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1400 | + . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1401 | + ($ok ? 'success' : 'error')) |
|
| 1402 | + . $trace |
|
| 1403 | + . "<div class='result'>" |
|
| 1404 | + . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1405 | + . "</div>" |
|
| 1406 | + . boite_fermer() |
|
| 1407 | + . "</div>"; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | /** |
@@ -1423,29 +1423,29 @@ discard block |
||
| 1423 | 1423 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1424 | 1424 | **/ |
| 1425 | 1425 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1426 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1427 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1431 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1432 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1433 | - if (file_exists($nom)) { |
|
| 1434 | - if (substr($nom, -4) == '.php') { |
|
| 1435 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1436 | - } |
|
| 1437 | - else { |
|
| 1438 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1439 | - } |
|
| 1440 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1441 | - if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1442 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1443 | - @unlink($fichier_tmp); |
|
| 1444 | - return; |
|
| 1445 | - } |
|
| 1446 | - @unlink($fichier_tmp); |
|
| 1447 | - } |
|
| 1448 | - ecrire_fichier($nom, $contenu); |
|
| 1449 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1450 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1426 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1427 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1431 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1432 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1433 | + if (file_exists($nom)) { |
|
| 1434 | + if (substr($nom, -4) == '.php') { |
|
| 1435 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1436 | + } |
|
| 1437 | + else { |
|
| 1438 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1439 | + } |
|
| 1440 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1441 | + if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1442 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1443 | + @unlink($fichier_tmp); |
|
| 1444 | + return; |
|
| 1445 | + } |
|
| 1446 | + @unlink($fichier_tmp); |
|
| 1447 | + } |
|
| 1448 | + ecrire_fichier($nom, $contenu); |
|
| 1449 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1450 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1451 | 1451 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | if ($dir) { |
| 371 | 371 | $dir .= "/"; |
| 372 | 372 | } |
| 373 | - $dir .= "procure:" . $procure['nom']; |
|
| 373 | + $dir .= "procure:".$procure['nom']; |
|
| 374 | 374 | |
| 375 | 375 | $procure['etat'] = '?'; |
| 376 | 376 | $procure['dir_type'] = $resume['dir_type']; |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $plug = $resume['dir']; |
| 552 | 552 | $k = $infos[$dir_type][$plug]; |
| 553 | 553 | |
| 554 | - $plug = constant($dir_type) . $plug; |
|
| 554 | + $plug = constant($dir_type).$plug; |
|
| 555 | 555 | if (!isset($msg[$p])) { |
| 556 | 556 | if (isset($resume['erreur']) and $resume['erreur']) { |
| 557 | 557 | $msg[$p] = array($resume['erreur']); |
@@ -594,10 +594,10 @@ discard block |
||
| 594 | 594 | $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
| 595 | 595 | } elseif (!$raw) { |
| 596 | 596 | foreach ($list as $plug => $msg) { |
| 597 | - $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | - . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 597 | + $list[$plug] = "<li>"._T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | + . "<ul><li>".implode("</li><li>", $msg)."</li></ul></li>"; |
|
| 599 | 599 | } |
| 600 | - $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 600 | + $list = "<ul>".join("\n", $list)."</ul>"; |
|
| 601 | 601 | } |
| 602 | 602 | if ($raz) { |
| 603 | 603 | effacer_meta('plugin_erreur_activation'); |
@@ -711,13 +711,13 @@ discard block |
||
| 711 | 711 | if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
| 712 | 712 | return _T("plugin_${balise}_${type}", array( |
| 713 | 713 | 'plugin' => $nom, |
| 714 | - 'version' => ' ≥ ' . $minimum |
|
| 714 | + 'version' => ' ≥ '.$minimum |
|
| 715 | 715 | )); |
| 716 | 716 | } |
| 717 | 717 | if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
| 718 | 718 | return _T("plugin_${balise}_${type}", array( |
| 719 | 719 | 'plugin' => $nom, |
| 720 | - 'version' => ' > ' . $minimum |
|
| 720 | + 'version' => ' > '.$minimum |
|
| 721 | 721 | )); |
| 722 | 722 | } |
| 723 | 723 | } |
@@ -726,13 +726,13 @@ discard block |
||
| 726 | 726 | if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
| 727 | 727 | return _T("plugin_${balise}_${type}", array( |
| 728 | 728 | 'plugin' => $nom, |
| 729 | - 'version' => ' ≤ ' . $maximum |
|
| 729 | + 'version' => ' ≤ '.$maximum |
|
| 730 | 730 | )); |
| 731 | 731 | } |
| 732 | 732 | if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
| 733 | 733 | return _T("plugin_${balise}_plugin", array( |
| 734 | 734 | 'plugin' => $nom, |
| 735 | - 'version' => ' < ' . $maximum |
|
| 735 | + 'version' => ' < '.$maximum |
|
| 736 | 736 | )); |
| 737 | 737 | } |
| 738 | 738 | } |
@@ -751,7 +751,7 @@ discard block |
||
| 751 | 751 | include_spip('inc/charger_plugin'); |
| 752 | 752 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 753 | 753 | }*/ |
| 754 | - return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 754 | + return _T('plugin_necessite_lib', array('lib' => $lib))." <a href='$url'>$url</a>"; |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | foreach ($plugin_valides as $p => $resume) { |
| 851 | 851 | // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
| 852 | 852 | if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
| 853 | - $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 853 | + $header[] = $p.($resume['version'] ? "(".$resume['version'].")" : ""); |
|
| 854 | 854 | } |
| 855 | 855 | if ($resume['dir']) { |
| 856 | 856 | foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
@@ -874,10 +874,10 @@ discard block |
||
| 874 | 874 | ecrire_meta('plugin_attente', serialize($liste)); |
| 875 | 875 | $header = strtolower(implode(",", $header)); |
| 876 | 876 | if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
| 877 | - ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 878 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 877 | + ecrire_fichier(_DIR_VAR."config.txt", |
|
| 878 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP").' '.$GLOBALS['spip_version_affichee']." @ www.spip.net + ".$header); |
|
| 879 | 879 | } else { |
| 880 | - @unlink(_DIR_VAR . "config.txt"); |
|
| 880 | + @unlink(_DIR_VAR."config.txt"); |
|
| 881 | 881 | } |
| 882 | 882 | // generer charger_plugins_chemin.php |
| 883 | 883 | plugins_precompile_chemin($plugin_valides, $ordre); |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | // definir le plugin, donc le path avant l'include du fichier options |
| 932 | 932 | // permet de faire des include_spip pour attraper un inc_ du plugin |
| 933 | 933 | |
| 934 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 934 | + $dir = $dir_type.".'".$plug."/'"; |
|
| 935 | 935 | |
| 936 | 936 | $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
| 937 | 937 | if ( |
@@ -942,11 +942,11 @@ discard block |
||
| 942 | 942 | if (!$info['chemin']) { |
| 943 | 943 | $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
| 944 | 944 | $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
| 945 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 945 | + if (is_dir(constant($dir_type).$plug.'/squelettes/')) { |
|
| 946 | 946 | $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
| 947 | 947 | } |
| 948 | 948 | } |
| 949 | - else{ |
|
| 949 | + else { |
|
| 950 | 950 | foreach ($info['chemin'] as $chemin) { |
| 951 | 951 | if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
| 952 | 952 | $GLOBALS['spip_version_branche'], 'spip') |
@@ -959,13 +959,13 @@ discard block |
||
| 959 | 959 | $dir = ''; |
| 960 | 960 | } |
| 961 | 961 | if (strlen($dir)) { |
| 962 | - $dir = rtrim($dir, '/') . '/'; |
|
| 962 | + $dir = rtrim($dir, '/').'/'; |
|
| 963 | 963 | } |
| 964 | 964 | if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
| 965 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 965 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ""); |
|
| 966 | 966 | } |
| 967 | 967 | if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
| 968 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 968 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ""); |
|
| 969 | 969 | } |
| 970 | 970 | } |
| 971 | 971 | } |
@@ -974,9 +974,9 @@ discard block |
||
| 974 | 974 | } |
| 975 | 975 | } |
| 976 | 976 | if (count($chemins['public']) or count($chemins['prive'])) { |
| 977 | - $contenu .= "if (_DIR_RESTREINT) _chemin([" . implode(',', |
|
| 978 | - array_reverse($chemins['public'])) . "]);\n" |
|
| 979 | - . "else _chemin([" . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 977 | + $contenu .= "if (_DIR_RESTREINT) _chemin([".implode(',', |
|
| 978 | + array_reverse($chemins['public']))."]);\n" |
|
| 979 | + . "else _chemin([".implode(',', array_reverse($chemins['prive']))."]);\n"; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | and strpos($dir, ":") === false // exclure le cas des procure: |
| 1025 | 1025 | and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
| 1026 | 1026 | ) { |
| 1027 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 1027 | + if (is_readable("$dir$plug/".($file = $info['prefix']."_".$charge.".php"))) { |
|
| 1028 | 1028 | $info[$charge] = array($file); |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | ) { |
| 1041 | 1041 | unset($info[$charge][$k]); |
| 1042 | 1042 | } else { |
| 1043 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1043 | + $_file = $root_dir_type.".'$plug/$file'"; |
|
| 1044 | 1044 | $contenu[$charge] .= "include_once_check($_file);\n"; |
| 1045 | 1045 | } |
| 1046 | 1046 | } |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1053 | + $contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options']; |
|
| 1054 | 1054 | $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
| 1055 | 1055 | . plugin_ongletbouton("onglets_plugins", $onglets); |
| 1056 | 1056 | |
@@ -1085,12 +1085,12 @@ discard block |
||
| 1085 | 1085 | define("_UPDATED_$nom", $val); |
| 1086 | 1086 | define("_UPDATED_md5_$nom", $md5); |
| 1087 | 1087 | } |
| 1088 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1088 | + $val = "unserialize('".str_replace("'", "\'", $val)."')"; |
|
| 1089 | 1089 | |
| 1090 | 1090 | return |
| 1091 | 1091 | "if (!function_exists('$nom')) {\n" |
| 1092 | 1092 | . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
| 1093 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1093 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n" |
|
| 1094 | 1094 | . "}\n"; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | if (@is_readable(_CACHE_PLUGINS_OPT)) { |
| 1114 | 1114 | include_once(_CACHE_PLUGINS_OPT); |
| 1115 | 1115 | } else { |
| 1116 | - spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1116 | + spip_log("pipelines desactives: impossible de produire "._CACHE_PLUGINS_OPT); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | } |
| 1119 | 1119 | |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | $dir_type = $plugin_valides[$p]['dir_type']; |
| 1151 | 1151 | $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
| 1152 | 1152 | $plug = $plugin_valides[$p]['dir']; |
| 1153 | - $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1153 | + $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix']."_"); |
|
| 1154 | 1154 | if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
| 1155 | 1155 | foreach ($info['pipeline'] as $pipe) { |
| 1156 | 1156 | $nom = $pipe['nom']; |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | } |
| 1181 | 1181 | if (isset($pipe['inclure'])) { |
| 1182 | 1182 | $GLOBALS['spip_matrice']["$prefix$action"] = |
| 1183 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1183 | + "$root_dir_type:$plug/".$pipe['inclure']; |
|
| 1184 | 1184 | } |
| 1185 | 1185 | } |
| 1186 | 1186 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | $prepend_code['taches_generales_cron'] = ""; |
| 1191 | 1191 | } |
| 1192 | 1192 | foreach ($info['genie'] as $genie) { |
| 1193 | - $nom = $prefix . $genie['nom']; |
|
| 1193 | + $nom = $prefix.$genie['nom']; |
|
| 1194 | 1194 | $periode = max(60, intval($genie['periode'])); |
| 1195 | 1195 | if (charger_fonction($nom, "genie", true)) { |
| 1196 | 1196 | $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
@@ -1208,13 +1208,13 @@ discard block |
||
| 1208 | 1208 | } |
| 1209 | 1209 | foreach ($info['style'] as $style) { |
| 1210 | 1210 | if (isset($style['path']) and $style['path']) { |
| 1211 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1211 | + $code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) "; |
|
| 1212 | 1212 | } else { |
| 1213 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1213 | + $code = "if (\$f='".addslashes($style['url'])."') "; |
|
| 1214 | 1214 | } |
| 1215 | 1215 | $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
| 1216 | 1216 | if (isset($style['media']) and strlen($style['media'])) { |
| 1217 | - $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1217 | + $code .= " media=\"".addslashes($style['media'])."\""; |
|
| 1218 | 1218 | } |
| 1219 | 1219 | $code .= "/>';\n"; |
| 1220 | 1220 | if ($style['type'] != 'prive') { |
@@ -1234,9 +1234,9 @@ discard block |
||
| 1234 | 1234 | if (isset($info['script']) and count($info['script'])) { |
| 1235 | 1235 | foreach ($info['script'] as $script) { |
| 1236 | 1236 | if (isset($script['path']) and $script['path']) { |
| 1237 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1237 | + $code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) "; |
|
| 1238 | 1238 | } else { |
| 1239 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1239 | + $code = "if (\$f='".addslashes($script['url'])."') "; |
|
| 1240 | 1240 | } |
| 1241 | 1241 | $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
| 1242 | 1242 | if ($script['type'] != 'prive') { |
@@ -1299,10 +1299,10 @@ discard block |
||
| 1299 | 1299 | unset($GLOBALS['spip_pipeline']['all']); |
| 1300 | 1300 | $all_pipes = trim(array_shift($a)); |
| 1301 | 1301 | if ($all_pipes) { |
| 1302 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1302 | + $all_pipes = '|'.ltrim($all_pipes, '|'); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | if (count($a)) { |
| 1305 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1305 | + $all_pipes_end = '||'.array_shift($a); |
|
| 1306 | 1306 | } |
| 1307 | 1307 | } |
| 1308 | 1308 | $content = ""; |
@@ -1319,7 +1319,7 @@ discard block |
||
| 1319 | 1319 | // Eclater le pipeline en filtres et appliquer chaque filtre |
| 1320 | 1320 | foreach ($pipe as $fonc) { |
| 1321 | 1321 | $fonc = trim($fonc); |
| 1322 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1322 | + $s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n"; |
|
| 1323 | 1323 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 1324 | 1324 | $file = $GLOBALS['spip_matrice'][$fonc]; |
| 1325 | 1325 | $file = "'$file'"; |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | if (defined($root_dir)) { |
| 1331 | 1331 | $dir = $root_dir; |
| 1332 | 1332 | } |
| 1333 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1333 | + $file = str_replace($regs[0], "'.".$dir.".'", $file); |
|
| 1334 | 1334 | $file = str_replace("''.", "", $file); |
| 1335 | 1335 | $file = str_replace(constant($dir), '', $file); |
| 1336 | 1336 | } |
@@ -1343,7 +1343,7 @@ discard block |
||
| 1343 | 1343 | $content .= "// Pipeline $action \n" |
| 1344 | 1344 | . "function execute_pipeline_$action(&\$val){\n" |
| 1345 | 1345 | . $s_inc |
| 1346 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1346 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '') |
|
| 1347 | 1347 | . $s_call |
| 1348 | 1348 | . "return \$val;\n}\n"; |
| 1349 | 1349 | } |
@@ -1427,18 +1427,18 @@ discard block |
||
| 1427 | 1427 | $GLOBALS['fichier_php_compile_recent'] = 0; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1430 | + $contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>'; |
|
| 1431 | 1431 | // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
| 1432 | 1432 | // si pas de modif on ne touche pas au fichier initial |
| 1433 | 1433 | if (file_exists($nom)) { |
| 1434 | 1434 | if (substr($nom, -4) == '.php') { |
| 1435 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1435 | + $fichier_tmp = substr($nom, 0, -4).'.tmp.php'; |
|
| 1436 | 1436 | } |
| 1437 | 1437 | else { |
| 1438 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1438 | + $fichier_tmp = $nom.'.tmp'; |
|
| 1439 | 1439 | } |
| 1440 | 1440 | file_put_contents($fichier_tmp, $contenu); |
| 1441 | - if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1441 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1442 | 1442 | $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
| 1443 | 1443 | @unlink($fichier_tmp); |
| 1444 | 1444 | return; |
@@ -165,7 +165,7 @@ |
||
| 165 | 165 | * @param string $primary |
| 166 | 166 | * @param array $rows |
| 167 | 167 | * @param string $serveur |
| 168 | - * @return array |
|
| 168 | + * @return string[] |
|
| 169 | 169 | */ |
| 170 | 170 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 171 | 171 | # calculer le {id_article IN()} et le {... as points} |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/rechercher'); |
| 24 | 24 | if (!defined('_DELAI_CACHE_resultats')) { |
| 25 | - define('_DELAI_CACHE_resultats', 600); |
|
| 25 | + define('_DELAI_CACHE_resultats', 600); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -49,111 +49,111 @@ discard block |
||
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | 51 | function inc_prepare_recherche_dist( |
| 52 | - $recherche, |
|
| 53 | - $table = 'articles', |
|
| 54 | - $cond = false, |
|
| 55 | - $serveur = '', |
|
| 56 | - $modificateurs = array(), |
|
| 57 | - $primary = '' |
|
| 52 | + $recherche, |
|
| 53 | + $table = 'articles', |
|
| 54 | + $cond = false, |
|
| 55 | + $serveur = '', |
|
| 56 | + $modificateurs = array(), |
|
| 57 | + $primary = '' |
|
| 58 | 58 | ) { |
| 59 | - static $cache = array(); |
|
| 60 | - $delai_fraicheur = min(_DELAI_CACHE_resultats, |
|
| 61 | - time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)); |
|
| 62 | - |
|
| 63 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 64 | - // ca permet de faire des inclure simple. |
|
| 65 | - if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 66 | - $recherche = $GLOBALS['recherche']; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // traiter le cas {recherche?} |
|
| 70 | - if ($cond and !strlen($recherche)) { |
|
| 71 | - return array( |
|
| 72 | - "0 as points" /* as points */, /* where */ |
|
| 73 | - '' |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - $rechercher = false; |
|
| 79 | - |
|
| 80 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
|
| 81 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 82 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 83 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | - $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
|
| 86 | - $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | - if (!$row |
|
| 88 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 89 | - ) { |
|
| 90 | - $rechercher = true; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 95 | - if ($rechercher) { |
|
| 96 | - //$tables = liste_des_champs(); |
|
| 97 | - $x = objet_type($table); |
|
| 98 | - $points = recherche_en_base($recherche, |
|
| 99 | - $x, |
|
| 100 | - array( |
|
| 101 | - 'score' => true, |
|
| 102 | - 'toutvoir' => true, |
|
| 103 | - 'jointures' => true |
|
| 104 | - ), |
|
| 105 | - $serveur); |
|
| 106 | - // pas de résultat, pas de point |
|
| 107 | - $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 108 | - |
|
| 109 | - // permettre aux plugins de modifier le resultat |
|
| 110 | - $points = pipeline('prepare_recherche', array( |
|
| 111 | - 'args' => array( |
|
| 112 | - 'type' => $x, |
|
| 113 | - 'recherche' => $recherche, |
|
| 114 | - 'serveur' => $serveur, |
|
| 115 | - 'modificateurs' => $modificateurs |
|
| 116 | - ), |
|
| 117 | - 'data' => $points |
|
| 118 | - )); |
|
| 119 | - |
|
| 120 | - // supprimer les anciens resultats de cette recherche |
|
| 121 | - // et les resultats trop vieux avec une marge |
|
| 122 | - // pas de AS resultats dans un delete (mysql) |
|
| 123 | - $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"), |
|
| 124 | - array("recherche", "table_objet", "serveur"), $where); |
|
| 125 | - |
|
| 126 | - sql_delete('spip_resultats', |
|
| 127 | - "NOT($where_resultat_recent) OR ($whered)"); |
|
| 128 | - |
|
| 129 | - // inserer les resultats dans la table de cache des resultats |
|
| 130 | - if (count($points)) { |
|
| 131 | - $tab_couples = array(); |
|
| 132 | - foreach ($points as $id => $p) { |
|
| 133 | - $tab_couples[] = array( |
|
| 134 | - 'recherche' => $hash, |
|
| 135 | - 'id' => $id, |
|
| 136 | - 'points' => $p['score'], |
|
| 137 | - 'table_objet' => $table, |
|
| 138 | - 'serveur' => $hash_serv, |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - sql_insertq_multi('spip_resultats', $tab_couples, array()); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 146 | - if (!$serveur) { |
|
| 147 | - $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where); |
|
| 148 | - } else { |
|
| 149 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 150 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 151 | - } |
|
| 152 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $cache[$serveur][$table][$recherche]; |
|
| 59 | + static $cache = array(); |
|
| 60 | + $delai_fraicheur = min(_DELAI_CACHE_resultats, |
|
| 61 | + time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)); |
|
| 62 | + |
|
| 63 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 64 | + // ca permet de faire des inclure simple. |
|
| 65 | + if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 66 | + $recherche = $GLOBALS['recherche']; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // traiter le cas {recherche?} |
|
| 70 | + if ($cond and !strlen($recherche)) { |
|
| 71 | + return array( |
|
| 72 | + "0 as points" /* as points */, /* where */ |
|
| 73 | + '' |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + $rechercher = false; |
|
| 79 | + |
|
| 80 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
|
| 81 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 82 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 83 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | + $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
|
| 86 | + $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | + if (!$row |
|
| 88 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 89 | + ) { |
|
| 90 | + $rechercher = true; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 95 | + if ($rechercher) { |
|
| 96 | + //$tables = liste_des_champs(); |
|
| 97 | + $x = objet_type($table); |
|
| 98 | + $points = recherche_en_base($recherche, |
|
| 99 | + $x, |
|
| 100 | + array( |
|
| 101 | + 'score' => true, |
|
| 102 | + 'toutvoir' => true, |
|
| 103 | + 'jointures' => true |
|
| 104 | + ), |
|
| 105 | + $serveur); |
|
| 106 | + // pas de résultat, pas de point |
|
| 107 | + $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 108 | + |
|
| 109 | + // permettre aux plugins de modifier le resultat |
|
| 110 | + $points = pipeline('prepare_recherche', array( |
|
| 111 | + 'args' => array( |
|
| 112 | + 'type' => $x, |
|
| 113 | + 'recherche' => $recherche, |
|
| 114 | + 'serveur' => $serveur, |
|
| 115 | + 'modificateurs' => $modificateurs |
|
| 116 | + ), |
|
| 117 | + 'data' => $points |
|
| 118 | + )); |
|
| 119 | + |
|
| 120 | + // supprimer les anciens resultats de cette recherche |
|
| 121 | + // et les resultats trop vieux avec une marge |
|
| 122 | + // pas de AS resultats dans un delete (mysql) |
|
| 123 | + $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"), |
|
| 124 | + array("recherche", "table_objet", "serveur"), $where); |
|
| 125 | + |
|
| 126 | + sql_delete('spip_resultats', |
|
| 127 | + "NOT($where_resultat_recent) OR ($whered)"); |
|
| 128 | + |
|
| 129 | + // inserer les resultats dans la table de cache des resultats |
|
| 130 | + if (count($points)) { |
|
| 131 | + $tab_couples = array(); |
|
| 132 | + foreach ($points as $id => $p) { |
|
| 133 | + $tab_couples[] = array( |
|
| 134 | + 'recherche' => $hash, |
|
| 135 | + 'id' => $id, |
|
| 136 | + 'points' => $p['score'], |
|
| 137 | + 'table_objet' => $table, |
|
| 138 | + 'serveur' => $hash_serv, |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + sql_insertq_multi('spip_resultats', $tab_couples, array()); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 146 | + if (!$serveur) { |
|
| 147 | + $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where); |
|
| 148 | + } else { |
|
| 149 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 150 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 151 | + } |
|
| 152 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $cache[$serveur][$table][$recherche]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -169,22 +169,22 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 172 | - # calculer le {id_article IN()} et le {... as points} |
|
| 173 | - if (!count($rows)) { |
|
| 174 | - return array("''", "0=1"); |
|
| 175 | - } else { |
|
| 176 | - $listes_ids = array(); |
|
| 177 | - $select = '0'; |
|
| 178 | - foreach ($rows as $r) { |
|
| 179 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - foreach ($listes_ids as $p => $ids) { |
|
| 183 | - $select .= "+$p*(" . |
|
| 184 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 185 | - . ") "; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)); |
|
| 189 | - } |
|
| 172 | + # calculer le {id_article IN()} et le {... as points} |
|
| 173 | + if (!count($rows)) { |
|
| 174 | + return array("''", "0=1"); |
|
| 175 | + } else { |
|
| 176 | + $listes_ids = array(); |
|
| 177 | + $select = '0'; |
|
| 178 | + foreach ($rows as $r) { |
|
| 179 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + foreach ($listes_ids as $p => $ids) { |
|
| 183 | + $select .= "+$p*(" . |
|
| 184 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 185 | + . ") "; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)); |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
| 81 | 81 | if (!isset($cache[$serveur][$table][$recherche])) { |
| 82 | 82 | $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
| 83 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 83 | + $hash = substr(md5($recherche.$table), 0, 16); |
|
| 84 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 85 | 85 | $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
| 86 | - $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 86 | + $where." AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | 87 | if (!$row |
| 88 | 88 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 89 | 89 | ) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | foreach ($listes_ids as $p => $ids) { |
| 183 | - $select .= "+$p*(" . |
|
| 183 | + $select .= "+$p*(". |
|
| 184 | 184 | sql_in("$table.$primary", $ids, '', $serveur) |
| 185 | 185 | . ") "; |
| 186 | 186 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * Raccourcis dépendant du sens de la langue |
| 33 | 33 | * |
| 34 | - * @return array Tablea ('','') |
|
| 34 | + * @return string[] Tablea ('','') |
|
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | 37 | return array('', ''); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * Ne fait rien ici. Voir plugin Textwheel |
| 355 | 355 | * |
| 356 | 356 | * @param string $letexte |
| 357 | - * @param null $forcer |
|
| 357 | + * @param boolean|null $forcer |
|
| 358 | 358 | * @return string |
| 359 | 359 | */ |
| 360 | 360 | function paragrapher($letexte, $forcer = true) { |
@@ -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 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return array('', ''); |
|
| 37 | + return array('', ''); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (array('script', 'iframe') as $tag) { |
|
| 106 | - if (stripos($t, "<$tag") !== false |
|
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | - ) { |
|
| 109 | - foreach ($r as $regs) { |
|
| 110 | - $t = str_replace($regs[0], |
|
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | - $t); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $t; |
|
| 105 | + foreach (array('script', 'iframe') as $tag) { |
|
| 106 | + if (stripos($t, "<$tag") !== false |
|
| 107 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + ) { |
|
| 109 | + foreach ($r as $regs) { |
|
| 110 | + $t = str_replace($regs[0], |
|
| 111 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | + $t); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $t; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -143,55 +143,55 @@ discard block |
||
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | 145 | function interdire_scripts($arg, $mode_filtre=null) { |
| 146 | - // on memorise le resultat sur les arguments non triviaux |
|
| 147 | - static $dejavu = array(); |
|
| 148 | - |
|
| 149 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | - return $arg; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | - return $dejavu[$mode_filtre][$arg]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // echapper les tags asp/php |
|
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | - |
|
| 165 | - // echapper le php |
|
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | - |
|
| 168 | - // echapper le < script language=php > |
|
| 169 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | - |
|
| 171 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | - switch ($mode_filtre) { |
|
| 173 | - case 0: |
|
| 174 | - if (!_DIR_RESTREINT) { |
|
| 175 | - $t = echappe_js($t); |
|
| 176 | - } |
|
| 177 | - break; |
|
| 178 | - case -1: |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - break; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // pas de <base href /> svp ! |
|
| 184 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | - |
|
| 186 | - // Reinserer les echappements des modeles |
|
| 187 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | - } |
|
| 190 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 146 | + // on memorise le resultat sur les arguments non triviaux |
|
| 147 | + static $dejavu = array(); |
|
| 148 | + |
|
| 149 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | + return $arg; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | + return $dejavu[$mode_filtre][$arg]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // echapper les tags asp/php |
|
| 163 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | + |
|
| 165 | + // echapper le php |
|
| 166 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | + |
|
| 168 | + // echapper le < script language=php > |
|
| 169 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | + |
|
| 171 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | + switch ($mode_filtre) { |
|
| 173 | + case 0: |
|
| 174 | + if (!_DIR_RESTREINT) { |
|
| 175 | + $t = echappe_js($t); |
|
| 176 | + } |
|
| 177 | + break; |
|
| 178 | + case -1: |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + break; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // pas de <base href /> svp ! |
|
| 184 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | + |
|
| 186 | + // Reinserer les echappements des modeles |
|
| 187 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | + $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | + } |
|
| 190 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -220,64 +220,64 @@ discard block |
||
| 220 | 220 | * Texte transformé |
| 221 | 221 | **/ |
| 222 | 222 | function typo($letexte, $echapper = true, $connect = null, $env = array()) { |
| 223 | - // Plus vite ! |
|
| 224 | - if (!$letexte) { |
|
| 225 | - return $letexte; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | - // prive etant historiquement ecrit sans argment $connect |
|
| 230 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | - // ou il faut passer interdire_script explicitement |
|
| 232 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | - // ne seront pas perturbes |
|
| 234 | - $interdire_script = false; |
|
| 235 | - if (is_null($connect)) { |
|
| 236 | - $connect = ''; |
|
| 237 | - $interdire_script = true; |
|
| 238 | - $env['espace_prive'] = test_espace_prive(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Echapper les codes <html> etc |
|
| 242 | - if ($echapper) { |
|
| 243 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // |
|
| 247 | - // Installer les modeles, notamment images et documents ; |
|
| 248 | - // |
|
| 249 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | - // cf. inc/lien |
|
| 251 | - |
|
| 252 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | - if ($letexte != $mem) { |
|
| 254 | - $echapper = true; |
|
| 255 | - } |
|
| 256 | - unset($mem); |
|
| 257 | - |
|
| 258 | - $letexte = corriger_typo($letexte); |
|
| 259 | - $letexte = echapper_faux_tags($letexte); |
|
| 260 | - |
|
| 261 | - // reintegrer les echappements |
|
| 262 | - if ($echapper) { |
|
| 263 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | - if ($interdire_script) { |
|
| 268 | - $letexte = interdire_scripts($letexte); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | - // https://core.spip.net/issues/3371 |
|
| 273 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | - // https://core.spip.net/issues/4166 |
|
| 275 | - if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | - $letexte = echapper_html_suspect($letexte); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $letexte; |
|
| 223 | + // Plus vite ! |
|
| 224 | + if (!$letexte) { |
|
| 225 | + return $letexte; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | + // prive etant historiquement ecrit sans argment $connect |
|
| 230 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | + // ou il faut passer interdire_script explicitement |
|
| 232 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | + // ne seront pas perturbes |
|
| 234 | + $interdire_script = false; |
|
| 235 | + if (is_null($connect)) { |
|
| 236 | + $connect = ''; |
|
| 237 | + $interdire_script = true; |
|
| 238 | + $env['espace_prive'] = test_espace_prive(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Echapper les codes <html> etc |
|
| 242 | + if ($echapper) { |
|
| 243 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // |
|
| 247 | + // Installer les modeles, notamment images et documents ; |
|
| 248 | + // |
|
| 249 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | + // cf. inc/lien |
|
| 251 | + |
|
| 252 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | + if ($letexte != $mem) { |
|
| 254 | + $echapper = true; |
|
| 255 | + } |
|
| 256 | + unset($mem); |
|
| 257 | + |
|
| 258 | + $letexte = corriger_typo($letexte); |
|
| 259 | + $letexte = echapper_faux_tags($letexte); |
|
| 260 | + |
|
| 261 | + // reintegrer les echappements |
|
| 262 | + if ($echapper) { |
|
| 263 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | + if ($interdire_script) { |
|
| 268 | + $letexte = interdire_scripts($letexte); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | + // https://core.spip.net/issues/3371 |
|
| 273 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | + // https://core.spip.net/issues/4166 |
|
| 275 | + if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | + $letexte = echapper_html_suspect($letexte); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $letexte; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Correcteur typographique |
@@ -302,57 +302,57 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function corriger_typo($letexte, $lang = '') { |
| 304 | 304 | |
| 305 | - // Plus vite ! |
|
| 306 | - if (!$letexte) { |
|
| 307 | - return $letexte; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | - |
|
| 312 | - // Caracteres de controle "illegaux" |
|
| 313 | - $letexte = corriger_caracteres($letexte); |
|
| 314 | - |
|
| 315 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | - foreach ($regs as $reg) { |
|
| 318 | - $insert = $reg[0]; |
|
| 319 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // trouver les blocs idiomes et les traiter à part |
|
| 327 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | - $ei = ($ei !== $letexte); |
|
| 329 | - |
|
| 330 | - // trouver les blocs multi et les traiter a part |
|
| 331 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | - $em = ($em !== $letexte); |
|
| 333 | - |
|
| 334 | - // Charger & appliquer les fonctions de typographie |
|
| 335 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | - $letexte = $typographie($letexte); |
|
| 337 | - |
|
| 338 | - // Les citations en une autre langue, s'il y a lieu |
|
| 339 | - if ($em) { |
|
| 340 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | - } |
|
| 342 | - if ($ei) { |
|
| 343 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Retablir les caracteres proteges |
|
| 347 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | - |
|
| 349 | - // pipeline |
|
| 350 | - $letexte = pipeline('post_typo', $letexte); |
|
| 351 | - |
|
| 352 | - # un message pour abs_url - on est passe en mode texte |
|
| 353 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | - |
|
| 355 | - return $letexte; |
|
| 305 | + // Plus vite ! |
|
| 306 | + if (!$letexte) { |
|
| 307 | + return $letexte; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | + |
|
| 312 | + // Caracteres de controle "illegaux" |
|
| 313 | + $letexte = corriger_caracteres($letexte); |
|
| 314 | + |
|
| 315 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | + foreach ($regs as $reg) { |
|
| 318 | + $insert = $reg[0]; |
|
| 319 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // trouver les blocs idiomes et les traiter à part |
|
| 327 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | + $ei = ($ei !== $letexte); |
|
| 329 | + |
|
| 330 | + // trouver les blocs multi et les traiter a part |
|
| 331 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | + $em = ($em !== $letexte); |
|
| 333 | + |
|
| 334 | + // Charger & appliquer les fonctions de typographie |
|
| 335 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | + $letexte = $typographie($letexte); |
|
| 337 | + |
|
| 338 | + // Les citations en une autre langue, s'il y a lieu |
|
| 339 | + if ($em) { |
|
| 340 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | + } |
|
| 342 | + if ($ei) { |
|
| 343 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Retablir les caracteres proteges |
|
| 347 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | + |
|
| 349 | + // pipeline |
|
| 350 | + $letexte = pipeline('post_typo', $letexte); |
|
| 351 | + |
|
| 352 | + # un message pour abs_url - on est passe en mode texte |
|
| 353 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | + |
|
| 355 | + return $letexte; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function paragrapher($letexte, $forcer = true) { |
| 371 | - return $letexte; |
|
| 371 | + return $letexte; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @return string Texte |
| 381 | 381 | **/ |
| 382 | 382 | function traiter_retours_chariots($letexte) { |
| 383 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | - $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | - $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 383 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | + $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | + $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 386 | 386 | |
| 387 | - return $letexte; |
|
| 387 | + return $letexte; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -410,37 +410,37 @@ discard block |
||
| 410 | 410 | * Texte transformé |
| 411 | 411 | **/ |
| 412 | 412 | function propre($t, $connect = null, $env = array()) { |
| 413 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | - // prive etant historiquement ecrits sans argment $connect |
|
| 415 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | - // ou il faut passer interdire_script explicitement |
|
| 417 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | - // ne seront pas perturbes |
|
| 419 | - $interdire_script = false; |
|
| 420 | - if (is_null($connect)) { |
|
| 421 | - $connect = ''; |
|
| 422 | - $interdire_script = true; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (!$t) { |
|
| 426 | - return strval($t); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | - // avant echappement des balises <html> |
|
| 431 | - // https://core.spip.net/issues/3371 |
|
| 432 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | - // https://core.spip.net/issues/4166 |
|
| 434 | - if ($interdire_script |
|
| 435 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | - $t = echapper_html_suspect($t, false); |
|
| 439 | - } |
|
| 440 | - $t = echappe_html($t); |
|
| 441 | - $t = expanser_liens($t, $connect, $env); |
|
| 442 | - $t = traiter_raccourcis($t); |
|
| 443 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | - |
|
| 445 | - return $t; |
|
| 413 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | + // prive etant historiquement ecrits sans argment $connect |
|
| 415 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | + // ou il faut passer interdire_script explicitement |
|
| 417 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | + // ne seront pas perturbes |
|
| 419 | + $interdire_script = false; |
|
| 420 | + if (is_null($connect)) { |
|
| 421 | + $connect = ''; |
|
| 422 | + $interdire_script = true; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (!$t) { |
|
| 426 | + return strval($t); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | + // avant echappement des balises <html> |
|
| 431 | + // https://core.spip.net/issues/3371 |
|
| 432 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | + // https://core.spip.net/issues/4166 |
|
| 434 | + if ($interdire_script |
|
| 435 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | + $t = echapper_html_suspect($t, false); |
|
| 439 | + } |
|
| 440 | + $t = echappe_html($t); |
|
| 441 | + $t = expanser_liens($t, $connect, $env); |
|
| 442 | + $t = traiter_raccourcis($t); |
|
| 443 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | + |
|
| 445 | + return $t; |
|
| 446 | 446 | } |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | 105 | foreach (array('script', 'iframe') as $tag) { |
| 106 | 106 | if (stripos($t, "<$tag") !== false |
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 107 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | 108 | ) { |
| 109 | 109 | foreach ($r as $regs) { |
| 110 | 110 | $t = str_replace($regs[0], |
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 111 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 112 | 112 | $t); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return string |
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | -function interdire_scripts($arg, $mode_filtre=null) { |
|
| 145 | +function interdire_scripts($arg, $mode_filtre = null) { |
|
| 146 | 146 | // on memorise le resultat sur les arguments non triviaux |
| 147 | 147 | static $dejavu = array(); |
| 148 | 148 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // echapper les tags asp/php |
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 163 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 164 | 164 | |
| 165 | 165 | // echapper le php |
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 166 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le < script language=php > |
| 169 | 169 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // Reinserer les echappements des modeles |
| 187 | 187 | if (defined('_PROTEGE_JS_MODELES')) { |
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 188 | + $t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES); |
|
| 189 | 189 | } |
| 190 | 190 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 191 | + $t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
| 274 | 274 | // https://core.spip.net/issues/4166 |
| 275 | 275 | if ($GLOBALS['filtrer_javascript'] == -1 |
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 277 | 277 | $letexte = echapper_html_suspect($letexte); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 285 | 285 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 286 | 286 | |
| 287 | -define('_TYPO_BALISE', ",</?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS"); |
|
| 287 | +define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS"); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Corrige la typographie |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | // https://core.spip.net/issues/4166 |
| 434 | 434 | if ($interdire_script |
| 435 | 435 | or $GLOBALS['filtrer_javascript'] == -1 |
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 438 | 438 | $t = echapper_html_suspect($t, false); |
| 439 | 439 | } |
| 440 | 440 | $t = echappe_html($t); |
@@ -245,7 +245,7 @@ |
||
| 245 | 245 | * @param array $matches |
| 246 | 246 | * Branches de l'arbre validant la rexgep |
| 247 | 247 | * @param bool $init ? |
| 248 | - * @return bool |
|
| 248 | + * @return integer |
|
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | while ( |
| 136 | 136 | $p !== false |
| 137 | 137 | and ($morceau = substr($txt, $d, $p - $d)) |
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 138 | + and (($nopen += preg_match_all("{<".preg_quote($closing_tag)."(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | 139 | $matches, PREG_SET_ORDER)) > $nclose) |
| 140 | 140 | ) { |
| 141 | 141 | $nclose++; |
@@ -154,9 +154,11 @@ |
||
| 154 | 154 | } |
| 155 | 155 | $content = substr($txt, 0, $p); |
| 156 | 156 | $txt = substr($txt, $p + $ncclos); |
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) { |
|
| 158 | + // eviter une recursion si pas utile |
|
| 158 | 159 | { |
| 159 | 160 | $out[$tag][] = importer_charset($content, $charset); |
| 161 | + } |
|
| 160 | 162 | }//$content; |
| 161 | 163 | else { |
| 162 | 164 | $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
@@ -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 | |
@@ -47,23 +47,23 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ""; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = array(); |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 50 | + $contenu = ""; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = array(); |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,150 +82,150 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = array(); |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean === true) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = array(); |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean === true) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while (count($chars) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while (count($chars) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ""; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | - if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | - $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | - ) { |
|
| 141 | - $nclose++; |
|
| 142 | - $d = $p + $ncclos; |
|
| 143 | - $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - if ($p === false) { |
|
| 147 | - if ($strict) { |
|
| 148 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ""; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | + if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | + $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | + ) { |
|
| 141 | + $nclose++; |
|
| 142 | + $d = $p + $ncclos; |
|
| 143 | + $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + if ($p === false) { |
|
| 147 | + if ($strict) { |
|
| 148 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 149 | 149 | |
| 150 | - return $out; |
|
| 151 | - } else { |
|
| 152 | - return importer_charset($texte, $charset); |
|
| 153 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | - } |
|
| 155 | - $content = substr($txt, 0, $p); |
|
| 156 | - $txt = substr($txt, $p + $ncclos); |
|
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | - { |
|
| 159 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | - }//$content; |
|
| 161 | - else { |
|
| 162 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | - } |
|
| 167 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | - return $out; |
|
| 169 | - } else { |
|
| 170 | - return importer_charset($texte, $charset); |
|
| 171 | - }//$texte; |
|
| 150 | + return $out; |
|
| 151 | + } else { |
|
| 152 | + return importer_charset($texte, $charset); |
|
| 153 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | + } |
|
| 155 | + $content = substr($txt, 0, $p); |
|
| 156 | + $txt = substr($txt, $p + $ncclos); |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | + { |
|
| 159 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | + }//$content; |
|
| 161 | + else { |
|
| 162 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | + } |
|
| 167 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | + return $out; |
|
| 169 | + } else { |
|
| 170 | + return importer_charset($texte, $charset); |
|
| 171 | + }//$texte; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // https://code.spip.net/@spip_xml_aplatit |
| 175 | 175 | function spip_xml_aplatit($arbre, $separateur = " ") { |
| 176 | - $s = ""; |
|
| 177 | - if (is_array($arbre)) { |
|
| 178 | - foreach ($arbre as $tag => $feuille) { |
|
| 179 | - if (is_array($feuille)) { |
|
| 180 | - if ($tag !== intval($tag)) { |
|
| 181 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | - if (strlen($f)) { |
|
| 183 | - $tagf = explode(" ", $tag); |
|
| 184 | - $tagf = $tagf[0]; |
|
| 185 | - $s .= "<$tag>$f</$tagf>"; |
|
| 186 | - } else { |
|
| 187 | - $s .= "<$tag />"; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - $s .= spip_xml_aplatit($feuille); |
|
| 191 | - } |
|
| 192 | - $s .= $separateur; |
|
| 193 | - } else { |
|
| 194 | - $s .= "$feuille$separateur"; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 176 | + $s = ""; |
|
| 177 | + if (is_array($arbre)) { |
|
| 178 | + foreach ($arbre as $tag => $feuille) { |
|
| 179 | + if (is_array($feuille)) { |
|
| 180 | + if ($tag !== intval($tag)) { |
|
| 181 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | + if (strlen($f)) { |
|
| 183 | + $tagf = explode(" ", $tag); |
|
| 184 | + $tagf = $tagf[0]; |
|
| 185 | + $s .= "<$tag>$f</$tagf>"; |
|
| 186 | + } else { |
|
| 187 | + $s .= "<$tag />"; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + $s .= spip_xml_aplatit($feuille); |
|
| 191 | + } |
|
| 192 | + $s .= $separateur; |
|
| 193 | + } else { |
|
| 194 | + $s .= "$feuille$separateur"; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 199 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // https://code.spip.net/@spip_xml_tagname |
| 203 | 203 | function spip_xml_tagname($tag) { |
| 204 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | - return $reg[1]; |
|
| 206 | - } |
|
| 204 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | + return $reg[1]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return ""; |
|
| 208 | + return ""; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // https://code.spip.net/@spip_xml_decompose_tag |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = array(); |
|
| 215 | - $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 216 | - $p = strpos($tag, '='); |
|
| 217 | - while ($p !== false) { |
|
| 218 | - $attr = trim(substr($tag, 0, $p)); |
|
| 219 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | - $quote = $tag[0]; |
|
| 221 | - $p = strpos($tag, $quote, 1); |
|
| 222 | - $cont = substr($tag, 1, $p - 1); |
|
| 223 | - $liste[$attr] = $cont; |
|
| 224 | - $tag = substr($tag, $p + 1); |
|
| 225 | - $p = strpos($tag, '='); |
|
| 226 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = array(); |
|
| 215 | + $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 216 | + $p = strpos($tag, '='); |
|
| 217 | + while ($p !== false) { |
|
| 218 | + $attr = trim(substr($tag, 0, $p)); |
|
| 219 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | + $quote = $tag[0]; |
|
| 221 | + $p = strpos($tag, $quote, 1); |
|
| 222 | + $cont = substr($tag, 1, $p - 1); |
|
| 223 | + $liste[$attr] = $cont; |
|
| 224 | + $tag = substr($tag, $p + 1); |
|
| 225 | + $p = strpos($tag, '='); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return array($tagname, $liste); |
|
| 228 | + return array($tagname, $liste); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -248,21 +248,21 @@ discard block |
||
| 248 | 248 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 251 | - if ($init) { |
|
| 252 | - $matches = array(); |
|
| 253 | - } |
|
| 254 | - if (is_array($arbre) && count($arbre)) { |
|
| 255 | - foreach (array_keys($arbre) as $tag) { |
|
| 256 | - if (preg_match($regexp, $tag)) { |
|
| 257 | - $matches[$tag] = &$arbre[$tag]; |
|
| 258 | - } |
|
| 259 | - if (is_array($arbre[$tag])) { |
|
| 260 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 251 | + if ($init) { |
|
| 252 | + $matches = array(); |
|
| 253 | + } |
|
| 254 | + if (is_array($arbre) && count($arbre)) { |
|
| 255 | + foreach (array_keys($arbre) as $tag) { |
|
| 256 | + if (preg_match($regexp, $tag)) { |
|
| 257 | + $matches[$tag] = &$arbre[$tag]; |
|
| 258 | + } |
|
| 259 | + if (is_array($arbre[$tag])) { |
|
| 260 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - return (count($matches)); |
|
| 267 | + return (count($matches)); |
|
| 268 | 268 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * Déclarer les critères exceptions |
| 135 | 135 | * |
| 136 | - * @return array |
|
| 136 | + * @return string[] |
|
| 137 | 137 | */ |
| 138 | 138 | public function exception_des_criteres() { |
| 139 | 139 | return array('tableau'); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * pour la syntaxe cf la fonction spip preg_files |
| 788 | 788 | * |
| 789 | 789 | * @param string $dir |
| 790 | - * @param string $regexp |
|
| 790 | + * @param integer $regexp |
|
| 791 | 791 | * @param int $limit |
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | /** |
| 827 | 827 | * Object -> tableau |
| 828 | 828 | * |
| 829 | - * @param Object $object |
|
| 829 | + * @param SimpleXMLIterator $object |
|
| 830 | 830 | * @return array|bool |
| 831 | 831 | */ |
| 832 | 832 | function XMLObjectToArray($object) { |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = array( |
|
| 47 | - 'field' => array( |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = array( |
|
| 47 | + 'field' => array( |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,505 +62,505 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = array()) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return array('tableau'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set($cle, |
|
| 183 | - array( |
|
| 184 | - 'data' => $valeur, |
|
| 185 | - 'time' => time(), |
|
| 186 | - 'ttl' => $ttl |
|
| 187 | - ), |
|
| 188 | - 3600 + $ttl); |
|
| 189 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Aller chercher les données de la boucle DATA |
|
| 195 | - * |
|
| 196 | - * @throws Exception |
|
| 197 | - * @param array $command |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - protected function select($command) { |
|
| 201 | - |
|
| 202 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | - // le type se retrouve dans la commande 'from' |
|
| 204 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | - if (isset($this->command['from'][0])) { |
|
| 206 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | - } |
|
| 209 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | - // les commandes connues pour l'iterateur DATA |
|
| 214 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | - |
|
| 216 | - // {source format, [URL], [arg2]...} |
|
| 217 | - if (isset($this->command['source']) |
|
| 218 | - and isset($this->command['sourcemode']) |
|
| 219 | - ) { |
|
| 220 | - $this->select_source(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Critere {liste X1, X2, X3} |
|
| 224 | - if (isset($this->command['liste'])) { |
|
| 225 | - $this->select_liste(); |
|
| 226 | - } |
|
| 227 | - if (isset($this->command['enum'])) { |
|
| 228 | - $this->select_enum(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | - if (!is_array($this->tableau)) { |
|
| 233 | - $this->err = true; |
|
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // {datapath query.results} |
|
| 238 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | - if (!$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if (isset($this->command['sourcemode']) |
|
| 272 | - and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | - ) { |
|
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - # le premier argument peut etre un array, une URL etc. |
|
| 278 | - $src = $this->command['source'][0]; |
|
| 279 | - |
|
| 280 | - # avons-nous un cache dispo ? |
|
| 281 | - $cle = null; |
|
| 282 | - if (is_string($src)) { |
|
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $cache = $this->cache_get($cle); |
|
| 287 | - if (isset($this->command['datacache'])) { |
|
| 288 | - $ttl = intval($this->command['datacache']); |
|
| 289 | - } |
|
| 290 | - if ($cache |
|
| 291 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | - > time()) |
|
| 293 | - and !(_request('var_mode') === 'recalcul' |
|
| 294 | - and include_spip('inc/autoriser') |
|
| 295 | - and autoriser('recalcul') |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - $this->tableau = $cache['data']; |
|
| 299 | - } else { |
|
| 300 | - try { |
|
| 301 | - if (isset($this->command['sourcemode']) |
|
| 302 | - and in_array($this->command['sourcemode'], |
|
| 303 | - array('table', 'array', 'tableau')) |
|
| 304 | - ) { |
|
| 305 | - if (is_array($a = $src) |
|
| 306 | - or (is_string($a) |
|
| 307 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | - and is_array($a = @unserialize($a))) |
|
| 309 | - ) { |
|
| 310 | - $this->tableau = $a; |
|
| 311 | - } |
|
| 312 | - } else { |
|
| 313 | - $data = $src; |
|
| 314 | - if (is_string($src)) { |
|
| 315 | - if (tester_url_absolue($src)) { |
|
| 316 | - include_spip('inc/distant'); |
|
| 317 | - $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | - if (!$data) { |
|
| 319 | - throw new Exception("404"); |
|
| 320 | - } |
|
| 321 | - if (!isset($ttl)) { |
|
| 322 | - $ttl = 24 * 3600; |
|
| 323 | - } |
|
| 324 | - } elseif (@is_dir($src)) { |
|
| 325 | - $data = $src; |
|
| 326 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | - $data = spip_file_get_contents($src); |
|
| 328 | - } |
|
| 329 | - if (!isset($ttl)) { |
|
| 330 | - $ttl = 10; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if (!$this->err |
|
| 335 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | - ) { |
|
| 337 | - $args = $this->command['source']; |
|
| 338 | - $args[0] = $data; |
|
| 339 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | - $this->tableau = $a; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if (!is_array($this->tableau)) { |
|
| 346 | - $this->err = true; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | - $this->cache_set($cle, $ttl); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - } catch (Exception $e) { |
|
| 354 | - $e = $e->getMessage(); |
|
| 355 | - $err = sprintf("[%s, %s] $e", |
|
| 356 | - $src, |
|
| 357 | - $this->command['sourcemode']); |
|
| 358 | - erreur_squelette(array($err, array())); |
|
| 359 | - $this->err = true; |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | - if ($this->err |
|
| 365 | - and $cache |
|
| 366 | - ) { |
|
| 367 | - $this->tableau = $cache['data']; |
|
| 368 | - $this->err = false; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Retourne un tableau donne depuis un critère liste |
|
| 375 | - * |
|
| 376 | - * Critère `{liste X1, X2, X3}` |
|
| 377 | - * |
|
| 378 | - * @see critere_DATA_liste_dist() |
|
| 379 | - * |
|
| 380 | - **/ |
|
| 381 | - protected function select_liste() { |
|
| 382 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | - if (!isset($this->command['liste'][1])) { |
|
| 384 | - if (!is_array($this->command['liste'][0])) { |
|
| 385 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | - } else { |
|
| 387 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - $this->tableau = $this->command['liste']; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Retourne un tableau donne depuis un critere liste |
|
| 395 | - * Critere {enum Xmin, Xmax} |
|
| 396 | - * |
|
| 397 | - **/ |
|
| 398 | - protected function select_enum() { |
|
| 399 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | - if (!isset($this->command['enum'][1])) { |
|
| 401 | - if (!is_array($this->command['enum'][0])) { |
|
| 402 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | - } else { |
|
| 404 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - if (count($this->command['enum']) >= 3) { |
|
| 408 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | - array_shift($this->command['enum'])); |
|
| 410 | - } else { |
|
| 411 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | - } |
|
| 413 | - $this->tableau = $enum; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | - * {datapath query.results} |
|
| 420 | - * |
|
| 421 | - **/ |
|
| 422 | - protected function select_datapath() { |
|
| 423 | - $base = reset($this->command['datapath']); |
|
| 424 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | - if (!is_array($this->tableau)) { |
|
| 427 | - $this->tableau = array(); |
|
| 428 | - $this->err = true; |
|
| 429 | - spip_log("datapath '$base' absent"); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Ordonner les resultats |
|
| 436 | - * {par x} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_orderby() { |
|
| 440 | - $sortfunc = ''; |
|
| 441 | - $aleas = 0; |
|
| 442 | - foreach ($this->command['orderby'] as $tri) { |
|
| 443 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | - $r = array_pad($r, 3, null); |
|
| 446 | - |
|
| 447 | - // tri par cle |
|
| 448 | - if ($r[1] == 'cle') { |
|
| 449 | - if (isset($r[2]) and $r[2]) { |
|
| 450 | - krsort($this->tableau); |
|
| 451 | - } else { |
|
| 452 | - ksort($this->tableau); |
|
| 453 | - } |
|
| 454 | - } # {par hasard} |
|
| 455 | - else { |
|
| 456 | - if ($r[1] == 'hasard') { |
|
| 457 | - $k = array_keys($this->tableau); |
|
| 458 | - shuffle($k); |
|
| 459 | - $v = array(); |
|
| 460 | - foreach ($k as $cle) { |
|
| 461 | - $v[$cle] = $this->tableau[$cle]; |
|
| 462 | - } |
|
| 463 | - $this->tableau = $v; |
|
| 464 | - } else { |
|
| 465 | - # {par valeur} |
|
| 466 | - if ($r[1] == 'valeur') { |
|
| 467 | - $tv = '%s'; |
|
| 468 | - } # {par valeur/xx/yy} ?? |
|
| 469 | - else { |
|
| 470 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | - } |
|
| 472 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = array()) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return array('tableau'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set($cle, |
|
| 183 | + array( |
|
| 184 | + 'data' => $valeur, |
|
| 185 | + 'time' => time(), |
|
| 186 | + 'ttl' => $ttl |
|
| 187 | + ), |
|
| 188 | + 3600 + $ttl); |
|
| 189 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Aller chercher les données de la boucle DATA |
|
| 195 | + * |
|
| 196 | + * @throws Exception |
|
| 197 | + * @param array $command |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + protected function select($command) { |
|
| 201 | + |
|
| 202 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | + // le type se retrouve dans la commande 'from' |
|
| 204 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | + if (isset($this->command['from'][0])) { |
|
| 206 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | + } |
|
| 209 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | + // les commandes connues pour l'iterateur DATA |
|
| 214 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | + |
|
| 216 | + // {source format, [URL], [arg2]...} |
|
| 217 | + if (isset($this->command['source']) |
|
| 218 | + and isset($this->command['sourcemode']) |
|
| 219 | + ) { |
|
| 220 | + $this->select_source(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Critere {liste X1, X2, X3} |
|
| 224 | + if (isset($this->command['liste'])) { |
|
| 225 | + $this->select_liste(); |
|
| 226 | + } |
|
| 227 | + if (isset($this->command['enum'])) { |
|
| 228 | + $this->select_enum(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | + if (!is_array($this->tableau)) { |
|
| 233 | + $this->err = true; |
|
| 234 | + spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // {datapath query.results} |
|
| 238 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | + if (!$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if (isset($this->command['sourcemode']) |
|
| 272 | + and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | + ) { |
|
| 274 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + # le premier argument peut etre un array, une URL etc. |
|
| 278 | + $src = $this->command['source'][0]; |
|
| 279 | + |
|
| 280 | + # avons-nous un cache dispo ? |
|
| 281 | + $cle = null; |
|
| 282 | + if (is_string($src)) { |
|
| 283 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $cache = $this->cache_get($cle); |
|
| 287 | + if (isset($this->command['datacache'])) { |
|
| 288 | + $ttl = intval($this->command['datacache']); |
|
| 289 | + } |
|
| 290 | + if ($cache |
|
| 291 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | + > time()) |
|
| 293 | + and !(_request('var_mode') === 'recalcul' |
|
| 294 | + and include_spip('inc/autoriser') |
|
| 295 | + and autoriser('recalcul') |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + $this->tableau = $cache['data']; |
|
| 299 | + } else { |
|
| 300 | + try { |
|
| 301 | + if (isset($this->command['sourcemode']) |
|
| 302 | + and in_array($this->command['sourcemode'], |
|
| 303 | + array('table', 'array', 'tableau')) |
|
| 304 | + ) { |
|
| 305 | + if (is_array($a = $src) |
|
| 306 | + or (is_string($a) |
|
| 307 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | + and is_array($a = @unserialize($a))) |
|
| 309 | + ) { |
|
| 310 | + $this->tableau = $a; |
|
| 311 | + } |
|
| 312 | + } else { |
|
| 313 | + $data = $src; |
|
| 314 | + if (is_string($src)) { |
|
| 315 | + if (tester_url_absolue($src)) { |
|
| 316 | + include_spip('inc/distant'); |
|
| 317 | + $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | + if (!$data) { |
|
| 319 | + throw new Exception("404"); |
|
| 320 | + } |
|
| 321 | + if (!isset($ttl)) { |
|
| 322 | + $ttl = 24 * 3600; |
|
| 323 | + } |
|
| 324 | + } elseif (@is_dir($src)) { |
|
| 325 | + $data = $src; |
|
| 326 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | + $data = spip_file_get_contents($src); |
|
| 328 | + } |
|
| 329 | + if (!isset($ttl)) { |
|
| 330 | + $ttl = 10; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if (!$this->err |
|
| 335 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | + ) { |
|
| 337 | + $args = $this->command['source']; |
|
| 338 | + $args[0] = $data; |
|
| 339 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | + $this->tableau = $a; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if (!is_array($this->tableau)) { |
|
| 346 | + $this->err = true; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | + $this->cache_set($cle, $ttl); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + } catch (Exception $e) { |
|
| 354 | + $e = $e->getMessage(); |
|
| 355 | + $err = sprintf("[%s, %s] $e", |
|
| 356 | + $src, |
|
| 357 | + $this->command['sourcemode']); |
|
| 358 | + erreur_squelette(array($err, array())); |
|
| 359 | + $this->err = true; |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | + if ($this->err |
|
| 365 | + and $cache |
|
| 366 | + ) { |
|
| 367 | + $this->tableau = $cache['data']; |
|
| 368 | + $this->err = false; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Retourne un tableau donne depuis un critère liste |
|
| 375 | + * |
|
| 376 | + * Critère `{liste X1, X2, X3}` |
|
| 377 | + * |
|
| 378 | + * @see critere_DATA_liste_dist() |
|
| 379 | + * |
|
| 380 | + **/ |
|
| 381 | + protected function select_liste() { |
|
| 382 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | + if (!isset($this->command['liste'][1])) { |
|
| 384 | + if (!is_array($this->command['liste'][0])) { |
|
| 385 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | + } else { |
|
| 387 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + $this->tableau = $this->command['liste']; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Retourne un tableau donne depuis un critere liste |
|
| 395 | + * Critere {enum Xmin, Xmax} |
|
| 396 | + * |
|
| 397 | + **/ |
|
| 398 | + protected function select_enum() { |
|
| 399 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | + if (!isset($this->command['enum'][1])) { |
|
| 401 | + if (!is_array($this->command['enum'][0])) { |
|
| 402 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | + } else { |
|
| 404 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + if (count($this->command['enum']) >= 3) { |
|
| 408 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | + array_shift($this->command['enum'])); |
|
| 410 | + } else { |
|
| 411 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | + } |
|
| 413 | + $this->tableau = $enum; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | + * {datapath query.results} |
|
| 420 | + * |
|
| 421 | + **/ |
|
| 422 | + protected function select_datapath() { |
|
| 423 | + $base = reset($this->command['datapath']); |
|
| 424 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | + if (!is_array($this->tableau)) { |
|
| 427 | + $this->tableau = array(); |
|
| 428 | + $this->err = true; |
|
| 429 | + spip_log("datapath '$base' absent"); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Ordonner les resultats |
|
| 436 | + * {par x} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_orderby() { |
|
| 440 | + $sortfunc = ''; |
|
| 441 | + $aleas = 0; |
|
| 442 | + foreach ($this->command['orderby'] as $tri) { |
|
| 443 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | + $r = array_pad($r, 3, null); |
|
| 446 | + |
|
| 447 | + // tri par cle |
|
| 448 | + if ($r[1] == 'cle') { |
|
| 449 | + if (isset($r[2]) and $r[2]) { |
|
| 450 | + krsort($this->tableau); |
|
| 451 | + } else { |
|
| 452 | + ksort($this->tableau); |
|
| 453 | + } |
|
| 454 | + } # {par hasard} |
|
| 455 | + else { |
|
| 456 | + if ($r[1] == 'hasard') { |
|
| 457 | + $k = array_keys($this->tableau); |
|
| 458 | + shuffle($k); |
|
| 459 | + $v = array(); |
|
| 460 | + foreach ($k as $cle) { |
|
| 461 | + $v[$cle] = $this->tableau[$cle]; |
|
| 462 | + } |
|
| 463 | + $this->tableau = $v; |
|
| 464 | + } else { |
|
| 465 | + # {par valeur} |
|
| 466 | + if ($r[1] == 'valeur') { |
|
| 467 | + $tv = '%s'; |
|
| 468 | + } # {par valeur/xx/yy} ?? |
|
| 469 | + else { |
|
| 470 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | + } |
|
| 472 | + $sortfunc .= ' |
|
| 473 | 473 | $a = ' . sprintf($tv, '$aa') . '; |
| 474 | 474 | $b = ' . sprintf($tv, '$bb') . '; |
| 475 | 475 | if ($a <> $b) |
| 476 | 476 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($sortfunc) { |
|
| 483 | - $sortfunc .= "\n return 0;"; |
|
| 484 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | - return eval($sortfunc); |
|
| 486 | - }); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Grouper les resultats |
|
| 493 | - * {fusion /x/y/z} |
|
| 494 | - * |
|
| 495 | - **/ |
|
| 496 | - protected function select_groupby() { |
|
| 497 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | - $vu = array(); |
|
| 500 | - foreach ($this->tableau as $k => $v) { |
|
| 501 | - $val = table_valeur($v, $fusion); |
|
| 502 | - if (isset($vu[$val])) { |
|
| 503 | - unset($this->tableau[$k]); |
|
| 504 | - } else { |
|
| 505 | - $vu[$val] = true; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * L'iterateur est-il encore valide ? |
|
| 514 | - * |
|
| 515 | - * @return bool |
|
| 516 | - */ |
|
| 517 | - public function valid() { |
|
| 518 | - return !is_null($this->cle); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Retourner la valeur |
|
| 523 | - * |
|
| 524 | - * @return null |
|
| 525 | - */ |
|
| 526 | - public function current() { |
|
| 527 | - return $this->valeur; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Retourner la cle |
|
| 532 | - * |
|
| 533 | - * @return null |
|
| 534 | - */ |
|
| 535 | - public function key() { |
|
| 536 | - return $this->cle; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Passer a la valeur suivante |
|
| 541 | - * |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public function next() { |
|
| 545 | - if ($this->valid()) { |
|
| 546 | - $this->cle = key($this->tableau); |
|
| 547 | - $this->valeur = current($this->tableau); |
|
| 548 | - next($this->tableau); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Compter le nombre total de resultats |
|
| 554 | - * |
|
| 555 | - * @return int |
|
| 556 | - */ |
|
| 557 | - public function count() { |
|
| 558 | - if (is_null($this->total)) { |
|
| 559 | - $this->total = count($this->tableau); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $this->total; |
|
| 563 | - } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($sortfunc) { |
|
| 483 | + $sortfunc .= "\n return 0;"; |
|
| 484 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | + return eval($sortfunc); |
|
| 486 | + }); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Grouper les resultats |
|
| 493 | + * {fusion /x/y/z} |
|
| 494 | + * |
|
| 495 | + **/ |
|
| 496 | + protected function select_groupby() { |
|
| 497 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | + $vu = array(); |
|
| 500 | + foreach ($this->tableau as $k => $v) { |
|
| 501 | + $val = table_valeur($v, $fusion); |
|
| 502 | + if (isset($vu[$val])) { |
|
| 503 | + unset($this->tableau[$k]); |
|
| 504 | + } else { |
|
| 505 | + $vu[$val] = true; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * L'iterateur est-il encore valide ? |
|
| 514 | + * |
|
| 515 | + * @return bool |
|
| 516 | + */ |
|
| 517 | + public function valid() { |
|
| 518 | + return !is_null($this->cle); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Retourner la valeur |
|
| 523 | + * |
|
| 524 | + * @return null |
|
| 525 | + */ |
|
| 526 | + public function current() { |
|
| 527 | + return $this->valeur; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Retourner la cle |
|
| 532 | + * |
|
| 533 | + * @return null |
|
| 534 | + */ |
|
| 535 | + public function key() { |
|
| 536 | + return $this->cle; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Passer a la valeur suivante |
|
| 541 | + * |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public function next() { |
|
| 545 | + if ($this->valid()) { |
|
| 546 | + $this->cle = key($this->tableau); |
|
| 547 | + $this->valeur = current($this->tableau); |
|
| 548 | + next($this->tableau); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Compter le nombre total de resultats |
|
| 554 | + * |
|
| 555 | + * @return int |
|
| 556 | + */ |
|
| 557 | + public function count() { |
|
| 558 | + if (is_null($this->total)) { |
|
| 559 | + $this->total = count($this->tableau); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $this->total; |
|
| 563 | + } |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /* |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @return array |
| 575 | 575 | */ |
| 576 | 576 | function inc_file_to_array_dist($data) { |
| 577 | - return preg_split('/\r?\n/', $data); |
|
| 577 | + return preg_split('/\r?\n/', $data); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -583,9 +583,9 @@ discard block |
||
| 583 | 583 | * @return array |
| 584 | 584 | */ |
| 585 | 585 | function inc_plugins_to_array_dist() { |
| 586 | - include_spip('inc/plugin'); |
|
| 586 | + include_spip('inc/plugin'); |
|
| 587 | 587 | |
| 588 | - return liste_chemin_plugin_actifs(); |
|
| 588 | + return liste_chemin_plugin_actifs(); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @return array |
| 596 | 596 | */ |
| 597 | 597 | function inc_xml_to_array_dist($data) { |
| 598 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 598 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -607,14 +607,14 @@ discard block |
||
| 607 | 607 | * |
| 608 | 608 | */ |
| 609 | 609 | function inc_object_to_array($object) { |
| 610 | - if (!is_object($object) && !is_array($object)) { |
|
| 611 | - return $object; |
|
| 612 | - } |
|
| 613 | - if (is_object($object)) { |
|
| 614 | - $object = get_object_vars($object); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return array_map('inc_object_to_array', $object); |
|
| 610 | + if (!is_object($object) && !is_array($object)) { |
|
| 611 | + return $object; |
|
| 612 | + } |
|
| 613 | + if (is_object($object)) { |
|
| 614 | + $object = get_object_vars($object); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return array_map('inc_object_to_array', $object); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -624,20 +624,20 @@ discard block |
||
| 624 | 624 | * @return array|bool |
| 625 | 625 | */ |
| 626 | 626 | function inc_sql_to_array_dist($data) { |
| 627 | - # sortir le connecteur de $data |
|
| 628 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | - $serveur = (string)$v[1]; |
|
| 630 | - $req = trim($v[2]); |
|
| 631 | - if ($s = sql_query($req, $serveur)) { |
|
| 632 | - $r = array(); |
|
| 633 | - while ($t = sql_fetch($s)) { |
|
| 634 | - $r[] = $t; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - return $r; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return false; |
|
| 627 | + # sortir le connecteur de $data |
|
| 628 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | + $serveur = (string)$v[1]; |
|
| 630 | + $req = trim($v[2]); |
|
| 631 | + if ($s = sql_query($req, $serveur)) { |
|
| 632 | + $r = array(); |
|
| 633 | + while ($t = sql_fetch($s)) { |
|
| 634 | + $r[] = $t; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + return $r; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return false; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -647,9 +647,9 @@ discard block |
||
| 647 | 647 | * @return array|bool |
| 648 | 648 | */ |
| 649 | 649 | function inc_json_to_array_dist($data) { |
| 650 | - if (is_array($json = json_decode($data, true))) { |
|
| 651 | - return (array)$json; |
|
| 652 | - } |
|
| 650 | + if (is_array($json = json_decode($data, true))) { |
|
| 651 | + return (array)$json; |
|
| 652 | + } |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,30 +659,30 @@ discard block |
||
| 659 | 659 | * @return array|bool |
| 660 | 660 | */ |
| 661 | 661 | function inc_csv_to_array_dist($data) { |
| 662 | - include_spip('inc/csv'); |
|
| 663 | - list($entete, $csv) = analyse_csv($data); |
|
| 664 | - array_unshift($csv, $entete); |
|
| 665 | - |
|
| 666 | - include_spip('inc/charsets'); |
|
| 667 | - $i = 1; |
|
| 668 | - foreach ($entete as $k => $v) { |
|
| 669 | - if (trim($v) == "") { |
|
| 670 | - $v = "col" . $i; |
|
| 671 | - } // reperer des eventuelles cases vides |
|
| 672 | - if (is_numeric($v) and $v < 0) { |
|
| 673 | - $v = "__" . $v; |
|
| 674 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | - if (is_numeric($v)) { |
|
| 676 | - $v = "_" . $v; |
|
| 677 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | - foreach ($csv as &$item) { |
|
| 680 | - $item[$v] = &$item[$k]; |
|
| 681 | - } |
|
| 682 | - $i++; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $csv; |
|
| 662 | + include_spip('inc/csv'); |
|
| 663 | + list($entete, $csv) = analyse_csv($data); |
|
| 664 | + array_unshift($csv, $entete); |
|
| 665 | + |
|
| 666 | + include_spip('inc/charsets'); |
|
| 667 | + $i = 1; |
|
| 668 | + foreach ($entete as $k => $v) { |
|
| 669 | + if (trim($v) == "") { |
|
| 670 | + $v = "col" . $i; |
|
| 671 | + } // reperer des eventuelles cases vides |
|
| 672 | + if (is_numeric($v) and $v < 0) { |
|
| 673 | + $v = "__" . $v; |
|
| 674 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | + if (is_numeric($v)) { |
|
| 676 | + $v = "_" . $v; |
|
| 677 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | + foreach ($csv as &$item) { |
|
| 680 | + $item[$v] = &$item[$k]; |
|
| 681 | + } |
|
| 682 | + $i++; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $csv; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
@@ -692,12 +692,12 @@ discard block |
||
| 692 | 692 | * @return array|bool |
| 693 | 693 | */ |
| 694 | 694 | function inc_rss_to_array_dist($data) { |
| 695 | - include_spip('inc/syndic'); |
|
| 696 | - if (is_array($rss = analyser_backend($data))) { |
|
| 697 | - $tableau = $rss; |
|
| 698 | - } |
|
| 695 | + include_spip('inc/syndic'); |
|
| 696 | + if (is_array($rss = analyser_backend($data))) { |
|
| 697 | + $tableau = $rss; |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - return $tableau; |
|
| 700 | + return $tableau; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -707,9 +707,9 @@ discard block |
||
| 707 | 707 | * @return array|bool |
| 708 | 708 | */ |
| 709 | 709 | function inc_atom_to_array_dist($data) { |
| 710 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 710 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 711 | 711 | |
| 712 | - return $rss_to_array($data); |
|
| 712 | + return $rss_to_array($data); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -720,11 +720,11 @@ discard block |
||
| 720 | 720 | * @return array|bool |
| 721 | 721 | */ |
| 722 | 722 | function inc_glob_to_array_dist($data) { |
| 723 | - $a = glob($data, |
|
| 724 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | - ); |
|
| 723 | + $a = glob($data, |
|
| 724 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | + ); |
|
| 726 | 726 | |
| 727 | - return $a ? $a : array(); |
|
| 727 | + return $a ? $a : array(); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -735,14 +735,14 @@ discard block |
||
| 735 | 735 | * @throws Exception |
| 736 | 736 | */ |
| 737 | 737 | function inc_yaml_to_array_dist($data) { |
| 738 | - include_spip('inc/yaml-mini'); |
|
| 739 | - if (!function_exists("yaml_decode")) { |
|
| 740 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 738 | + include_spip('inc/yaml-mini'); |
|
| 739 | + if (!function_exists("yaml_decode")) { |
|
| 740 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 741 | 741 | |
| 742 | - return false; |
|
| 743 | - } |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - return yaml_decode($data); |
|
| 745 | + return yaml_decode($data); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return array|bool |
| 758 | 758 | */ |
| 759 | 759 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 760 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 760 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -769,23 +769,23 @@ discard block |
||
| 769 | 769 | * @return array|bool |
| 770 | 770 | */ |
| 771 | 771 | function inc_ls_to_array_dist($data) { |
| 772 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | - $a = $glob_to_array($data); |
|
| 774 | - foreach ($a as &$v) { |
|
| 775 | - $b = (array)@stat($v); |
|
| 776 | - foreach ($b as $k => $ignore) { |
|
| 777 | - if (is_numeric($k)) { |
|
| 778 | - unset($b[$k]); |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | - $v = array_merge( |
|
| 783 | - pathinfo($v), |
|
| 784 | - $b |
|
| 785 | - ); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - return $a; |
|
| 772 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | + $a = $glob_to_array($data); |
|
| 774 | + foreach ($a as &$v) { |
|
| 775 | + $b = (array)@stat($v); |
|
| 776 | + foreach ($b as $k => $ignore) { |
|
| 777 | + if (is_numeric($k)) { |
|
| 778 | + unset($b[$k]); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | + $v = array_merge( |
|
| 783 | + pathinfo($v), |
|
| 784 | + $b |
|
| 785 | + ); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + return $a; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -795,24 +795,24 @@ discard block |
||
| 795 | 795 | * @return array|bool |
| 796 | 796 | */ |
| 797 | 797 | function XMLObjectToArray($object) { |
| 798 | - $xml_array = array(); |
|
| 799 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | - $key .= '-' . uniqid(); |
|
| 802 | - } |
|
| 803 | - $vars = get_object_vars($object->current()); |
|
| 804 | - if (isset($vars['@attributes'])) { |
|
| 805 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | - $xml_array[$key][$k] = $v; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if ($object->hasChildren()) { |
|
| 810 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | - $object->current()); |
|
| 812 | - } else { |
|
| 813 | - $xml_array[$key][] = strval($object->current()); |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - return $xml_array; |
|
| 798 | + $xml_array = array(); |
|
| 799 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | + $key .= '-' . uniqid(); |
|
| 802 | + } |
|
| 803 | + $vars = get_object_vars($object->current()); |
|
| 804 | + if (isset($vars['@attributes'])) { |
|
| 805 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | + $xml_array[$key][$k] = $v; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if ($object->hasChildren()) { |
|
| 810 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | + $object->current()); |
|
| 812 | + } else { |
|
| 813 | + $xml_array[$key][] = strval($object->current()); |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + return $xml_array; |
|
| 818 | 818 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // Si a ce stade on n'a pas de table, il y a un bug |
| 232 | 232 | if (!is_array($this->tableau)) { |
| 233 | 233 | $this->err = true; |
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 234 | + spip_log("erreur datasource ".var_export($command, true)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // {datapath query.results} |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($this->command['sourcemode']) |
| 272 | 272 | and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
| 273 | 273 | ) { |
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 274 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | # le premier argument peut etre un array, une URL etc. |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | # avons-nous un cache dispo ? |
| 281 | 281 | $cle = null; |
| 282 | 282 | if (is_string($src)) { |
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 283 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $cache = $this->cache_get($cle); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | if (!$this->err |
| 335 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 335 | + and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 336 | 336 | ) { |
| 337 | 337 | $args = $this->command['source']; |
| 338 | 338 | $args[0] = $data; |
@@ -467,13 +467,13 @@ discard block |
||
| 467 | 467 | $tv = '%s'; |
| 468 | 468 | } # {par valeur/xx/yy} ?? |
| 469 | 469 | else { |
| 470 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 470 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 471 | 471 | } |
| 472 | 472 | $sortfunc .= ' |
| 473 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 474 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 473 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 474 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 475 | 475 | if ($a <> $b) |
| 476 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 476 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | } |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | function inc_sql_to_array_dist($data) { |
| 627 | 627 | # sortir le connecteur de $data |
| 628 | 628 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 629 | - $serveur = (string)$v[1]; |
|
| 629 | + $serveur = (string) $v[1]; |
|
| 630 | 630 | $req = trim($v[2]); |
| 631 | 631 | if ($s = sql_query($req, $serveur)) { |
| 632 | 632 | $r = array(); |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | */ |
| 649 | 649 | function inc_json_to_array_dist($data) { |
| 650 | 650 | if (is_array($json = json_decode($data, true))) { |
| 651 | - return (array)$json; |
|
| 651 | + return (array) $json; |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | $i = 1; |
| 668 | 668 | foreach ($entete as $k => $v) { |
| 669 | 669 | if (trim($v) == "") { |
| 670 | - $v = "col" . $i; |
|
| 670 | + $v = "col".$i; |
|
| 671 | 671 | } // reperer des eventuelles cases vides |
| 672 | 672 | if (is_numeric($v) and $v < 0) { |
| 673 | - $v = "__" . $v; |
|
| 673 | + $v = "__".$v; |
|
| 674 | 674 | } // ne pas risquer d'ecraser une cle numerique |
| 675 | 675 | if (is_numeric($v)) { |
| 676 | - $v = "_" . $v; |
|
| 676 | + $v = "_".$v; |
|
| 677 | 677 | } // ne pas risquer d'ecraser une cle numerique |
| 678 | 678 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 679 | 679 | foreach ($csv as &$item) { |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return array|bool |
| 758 | 758 | */ |
| 759 | 759 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 760 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 760 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -772,13 +772,13 @@ discard block |
||
| 772 | 772 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 773 | 773 | $a = $glob_to_array($data); |
| 774 | 774 | foreach ($a as &$v) { |
| 775 | - $b = (array)@stat($v); |
|
| 775 | + $b = (array) @stat($v); |
|
| 776 | 776 | foreach ($b as $k => $ignore) { |
| 777 | 777 | if (is_numeric($k)) { |
| 778 | 778 | unset($b[$k]); |
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 781 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 782 | 782 | $v = array_merge( |
| 783 | 783 | pathinfo($v), |
| 784 | 784 | $b |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | $xml_array = array(); |
| 799 | 799 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 800 | 800 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 801 | - $key .= '-' . uniqid(); |
|
| 801 | + $key .= '-'.uniqid(); |
|
| 802 | 802 | } |
| 803 | 803 | $vars = get_object_vars($object->current()); |
| 804 | 804 | if (isset($vars['@attributes'])) { |
@@ -457,6 +457,10 @@ |
||
| 457 | 457 | * aller a la position $n en parcourant |
| 458 | 458 | * un par un tous les elements |
| 459 | 459 | */ |
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @param integer $n |
|
| 463 | + */ |
|
| 460 | 464 | private function seek_loop($n) { |
| 461 | 465 | if ($this->pos > $n) { |
| 462 | 466 | $this->rewind(); |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // chercher la classe d'iterateur |
| 80 | 80 | // IterateurXXX |
| 81 | 81 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 82 | + $class = "Iterateur".$iterateur; |
|
| 83 | 83 | if (!class_exists($class)) { |
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 84 | + if (!include_spip("iterateur/".strtolower($iterateur)) |
|
| 85 | 85 | or !class_exists($class) |
| 86 | 86 | ) { |
| 87 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | return $this->iter->$nom(); |
| 209 | 209 | } catch (Exception $e) { |
| 210 | 210 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 211 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 212 | 212 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 213 | 213 | |
| 214 | 214 | return ''; |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | // Creer la fonction de filtrage sur $this |
| 292 | 292 | if ($this->filtre) { |
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 293 | + $filtres = 'return ('.join(') AND (', $this->filtre).');'; |
|
| 294 | + $this->func_filtre = function() use ($filtres) { |
|
| 295 | 295 | return eval($filtres); |
| 296 | 296 | }; |
| 297 | 297 | } |
@@ -313,28 +313,28 @@ discard block |
||
| 313 | 313 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 314 | 314 | # return; |
| 315 | 315 | |
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 316 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 317 | 317 | |
| 318 | 318 | $filtre = ''; |
| 319 | 319 | |
| 320 | 320 | if ($op == 'REGEXP') { |
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 321 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 322 | 322 | $op = ''; |
| 323 | 323 | } else { |
| 324 | 324 | if ($op == 'LIKE') { |
| 325 | 325 | $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 326 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 327 | 327 | $op = ''; |
| 328 | 328 | } else { |
| 329 | 329 | if ($op == '=') { |
| 330 | 330 | $op = '=='; |
| 331 | 331 | } else { |
| 332 | 332 | if ($op == 'IN') { |
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 333 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 334 | 334 | $op = ''; |
| 335 | 335 | } else { |
| 336 | 336 | if (!in_array($op, array('<', '<=', '>', '>='))) { |
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 337 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 338 | 338 | $op = ''; |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | if ($op) { |
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 346 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | if ($not) { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -22,578 +22,578 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | 24 | class IterFactory { |
| 25 | - public static function create($iterateur, $command, $info = null) { |
|
| 26 | - |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (count($a)) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 25 | + public static function create($iterateur, $command, $info = null) { |
|
| 26 | + |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (count($a)) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = "Iterateur" . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = array(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if (is_object($this->iter) |
|
| 205 | - and method_exists($this->iter, $nom) |
|
| 206 | - ) { |
|
| 207 | - try { |
|
| 208 | - return $this->iter->$nom(); |
|
| 209 | - } catch (Exception $e) { |
|
| 210 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | - |
|
| 214 | - return ''; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = array(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if (is_object($this->iter) |
|
| 205 | + and method_exists($this->iter, $nom) |
|
| 206 | + ) { |
|
| 207 | + try { |
|
| 208 | + return $this->iter->$nom(); |
|
| 209 | + } catch (Exception $e) { |
|
| 210 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | + |
|
| 214 | + return ''; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + /* |
|
| 218 | 218 | if (property_exists($this->iter, $nom)) { |
| 219 | 219 | return $this->iter->$nom; |
| 220 | 220 | }*/ |
| 221 | - // cle et valeur par defaut |
|
| 222 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | - and method_exists($this, $nom) |
|
| 225 | - ) { |
|
| 226 | - return $this->$nom(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Par defaut chercher en xpath dans la valeur() |
|
| 230 | - return table_valeur($this->valeur(), $nom, null); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - private function calculer_filtres() { |
|
| 235 | - |
|
| 236 | - // Issu de calculer_select() de public/composer L.519 |
|
| 237 | - // TODO: externaliser... |
|
| 238 | - // |
|
| 239 | - // retirer les criteres vides: |
|
| 240 | - // {X ?} avec X absent de l'URL |
|
| 241 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | - if ($where = &$this->command['where']) { |
|
| 244 | - foreach ($where as $k => $v) { |
|
| 245 | - if (is_array($v)) { |
|
| 246 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | - $op = false; |
|
| 248 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | - $op = false; |
|
| 250 | - } else { |
|
| 251 | - $op = $v[0] ? $v[0] : $v; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $op = $v; |
|
| 255 | - } |
|
| 256 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | - unset($where[$k]); |
|
| 258 | - } |
|
| 259 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | - $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | - unset($op, $where[$k]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - foreach ($where as $k => $v) { |
|
| 266 | - // 3 possibilites : count($v) = |
|
| 267 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | - |
|
| 271 | - // 1 : forcement traite par un critere, on passe |
|
| 272 | - if (!$v or count($v) == 1) { |
|
| 273 | - continue; |
|
| 274 | - } |
|
| 275 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | - } |
|
| 278 | - if (count($v) == 3) { |
|
| 279 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // critere {2,7} |
|
| 285 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | - $limit = explode(',', $this->command['limit']); |
|
| 287 | - $this->offset = $limit[0]; |
|
| 288 | - $this->limit = $limit[1]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // Creer la fonction de filtrage sur $this |
|
| 292 | - if ($this->filtre) { |
|
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 295 | - return eval($filtres); |
|
| 296 | - }; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | - |
|
| 313 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | - # return; |
|
| 315 | - |
|
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | - |
|
| 318 | - $filtre = ''; |
|
| 319 | - |
|
| 320 | - if ($op == 'REGEXP') { |
|
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | - $op = ''; |
|
| 323 | - } else { |
|
| 324 | - if ($op == 'LIKE') { |
|
| 325 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | - $op = ''; |
|
| 328 | - } else { |
|
| 329 | - if ($op == '=') { |
|
| 330 | - $op = '=='; |
|
| 331 | - } else { |
|
| 332 | - if ($op == 'IN') { |
|
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | - $op = ''; |
|
| 335 | - } else { |
|
| 336 | - if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | - $op = ''; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ($op) { |
|
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($not) { |
|
| 350 | - $filtre = "!($filtre)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if ($filtre) { |
|
| 354 | - $this->filtre[] = $filtre; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - public function next() { |
|
| 360 | - $this->pos++; |
|
| 361 | - parent::next(); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * revient au depart |
|
| 366 | - * |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function rewind() { |
|
| 370 | - $this->pos = 0; |
|
| 371 | - $this->fetched = 0; |
|
| 372 | - parent::rewind(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - # Extension SPIP des iterateurs PHP |
|
| 377 | - /** |
|
| 378 | - * type de l'iterateur |
|
| 379 | - * |
|
| 380 | - * @var string |
|
| 381 | - */ |
|
| 382 | - protected $type; |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * parametres de l'iterateur |
|
| 386 | - * |
|
| 387 | - * @var array |
|
| 388 | - */ |
|
| 389 | - protected $command; |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * infos de compilateur |
|
| 393 | - * |
|
| 394 | - * @var array |
|
| 395 | - */ |
|
| 396 | - protected $info; |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * position courante de l'iterateur |
|
| 400 | - * |
|
| 401 | - * @var int |
|
| 402 | - */ |
|
| 403 | - protected $pos = null; |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * nombre total resultats dans l'iterateur |
|
| 407 | - * |
|
| 408 | - * @var int |
|
| 409 | - */ |
|
| 410 | - protected $total = null; |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * nombre maximal de recherche pour $total |
|
| 414 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | - */ |
|
| 416 | - protected $max = 100000; |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Liste des champs a inserer dans les $row |
|
| 421 | - * retournes par ->fetch() |
|
| 422 | - */ |
|
| 423 | - protected $select = array(); |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * aller a la position absolue n, |
|
| 428 | - * comptee depuis le debut |
|
| 429 | - * |
|
| 430 | - * @param int $n |
|
| 431 | - * absolute pos |
|
| 432 | - * @param string $continue |
|
| 433 | - * param for sql_ api |
|
| 434 | - * @return bool |
|
| 435 | - * success or fail if not implemented |
|
| 436 | - */ |
|
| 437 | - public function seek($n = 0, $continue = null) { |
|
| 438 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | - $this->seek_loop($n); |
|
| 440 | - } |
|
| 441 | - $this->pos = $n; |
|
| 442 | - $this->fetched = $n; |
|
| 443 | - |
|
| 444 | - return true; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /* |
|
| 221 | + // cle et valeur par defaut |
|
| 222 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | + and method_exists($this, $nom) |
|
| 225 | + ) { |
|
| 226 | + return $this->$nom(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Par defaut chercher en xpath dans la valeur() |
|
| 230 | + return table_valeur($this->valeur(), $nom, null); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + private function calculer_filtres() { |
|
| 235 | + |
|
| 236 | + // Issu de calculer_select() de public/composer L.519 |
|
| 237 | + // TODO: externaliser... |
|
| 238 | + // |
|
| 239 | + // retirer les criteres vides: |
|
| 240 | + // {X ?} avec X absent de l'URL |
|
| 241 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | + if ($where = &$this->command['where']) { |
|
| 244 | + foreach ($where as $k => $v) { |
|
| 245 | + if (is_array($v)) { |
|
| 246 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | + $op = false; |
|
| 248 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | + $op = false; |
|
| 250 | + } else { |
|
| 251 | + $op = $v[0] ? $v[0] : $v; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $op = $v; |
|
| 255 | + } |
|
| 256 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | + unset($where[$k]); |
|
| 258 | + } |
|
| 259 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | + $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | + unset($op, $where[$k]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + foreach ($where as $k => $v) { |
|
| 266 | + // 3 possibilites : count($v) = |
|
| 267 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | + |
|
| 271 | + // 1 : forcement traite par un critere, on passe |
|
| 272 | + if (!$v or count($v) == 1) { |
|
| 273 | + continue; |
|
| 274 | + } |
|
| 275 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | + } |
|
| 278 | + if (count($v) == 3) { |
|
| 279 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // critere {2,7} |
|
| 285 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | + $limit = explode(',', $this->command['limit']); |
|
| 287 | + $this->offset = $limit[0]; |
|
| 288 | + $this->limit = $limit[1]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // Creer la fonction de filtrage sur $this |
|
| 292 | + if ($this->filtre) { |
|
| 293 | + $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | + $this->func_filtre = function () use ($filtres) { |
|
| 295 | + return eval($filtres); |
|
| 296 | + }; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | + |
|
| 313 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | + # return; |
|
| 315 | + |
|
| 316 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | + |
|
| 318 | + $filtre = ''; |
|
| 319 | + |
|
| 320 | + if ($op == 'REGEXP') { |
|
| 321 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | + $op = ''; |
|
| 323 | + } else { |
|
| 324 | + if ($op == 'LIKE') { |
|
| 325 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | + $op = ''; |
|
| 328 | + } else { |
|
| 329 | + if ($op == '=') { |
|
| 330 | + $op = '=='; |
|
| 331 | + } else { |
|
| 332 | + if ($op == 'IN') { |
|
| 333 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | + $op = ''; |
|
| 335 | + } else { |
|
| 336 | + if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | + $op = ''; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ($op) { |
|
| 346 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($not) { |
|
| 350 | + $filtre = "!($filtre)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if ($filtre) { |
|
| 354 | + $this->filtre[] = $filtre; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + public function next() { |
|
| 360 | + $this->pos++; |
|
| 361 | + parent::next(); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * revient au depart |
|
| 366 | + * |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function rewind() { |
|
| 370 | + $this->pos = 0; |
|
| 371 | + $this->fetched = 0; |
|
| 372 | + parent::rewind(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + # Extension SPIP des iterateurs PHP |
|
| 377 | + /** |
|
| 378 | + * type de l'iterateur |
|
| 379 | + * |
|
| 380 | + * @var string |
|
| 381 | + */ |
|
| 382 | + protected $type; |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * parametres de l'iterateur |
|
| 386 | + * |
|
| 387 | + * @var array |
|
| 388 | + */ |
|
| 389 | + protected $command; |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * infos de compilateur |
|
| 393 | + * |
|
| 394 | + * @var array |
|
| 395 | + */ |
|
| 396 | + protected $info; |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * position courante de l'iterateur |
|
| 400 | + * |
|
| 401 | + * @var int |
|
| 402 | + */ |
|
| 403 | + protected $pos = null; |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * nombre total resultats dans l'iterateur |
|
| 407 | + * |
|
| 408 | + * @var int |
|
| 409 | + */ |
|
| 410 | + protected $total = null; |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * nombre maximal de recherche pour $total |
|
| 414 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | + */ |
|
| 416 | + protected $max = 100000; |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Liste des champs a inserer dans les $row |
|
| 421 | + * retournes par ->fetch() |
|
| 422 | + */ |
|
| 423 | + protected $select = array(); |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * aller a la position absolue n, |
|
| 428 | + * comptee depuis le debut |
|
| 429 | + * |
|
| 430 | + * @param int $n |
|
| 431 | + * absolute pos |
|
| 432 | + * @param string $continue |
|
| 433 | + * param for sql_ api |
|
| 434 | + * @return bool |
|
| 435 | + * success or fail if not implemented |
|
| 436 | + */ |
|
| 437 | + public function seek($n = 0, $continue = null) { |
|
| 438 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | + $this->seek_loop($n); |
|
| 440 | + } |
|
| 441 | + $this->pos = $n; |
|
| 442 | + $this->fetched = $n; |
|
| 443 | + |
|
| 444 | + return true; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | * aller a la position $n en parcourant |
| 449 | 449 | * un par un tous les elements |
| 450 | 450 | */ |
| 451 | - private function seek_loop($n) { |
|
| 452 | - if ($this->pos > $n) { |
|
| 453 | - $this->rewind(); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - while ($this->pos < $n and $this->valid()) { |
|
| 457 | - $this->next(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return true; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Avancer de $saut pas |
|
| 465 | - * |
|
| 466 | - * @param $saut |
|
| 467 | - * @param $max |
|
| 468 | - * @return int |
|
| 469 | - */ |
|
| 470 | - public function skip($saut, $max = null) { |
|
| 471 | - // pas de saut en arriere autorise pour cette fonction |
|
| 472 | - if (($saut = intval($saut)) <= 0) { |
|
| 473 | - return $this->pos; |
|
| 474 | - } |
|
| 475 | - $seek = $this->pos + $saut; |
|
| 476 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | - // et on sort |
|
| 478 | - if (is_null($max)) { |
|
| 479 | - $max = $this->count(); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | - $this->free(); |
|
| 485 | - |
|
| 486 | - return $max; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $this->seek($seek); |
|
| 490 | - |
|
| 491 | - return $this->pos; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Renvoyer un tableau des donnees correspondantes |
|
| 496 | - * a la position courante de l'iterateur |
|
| 497 | - * en controlant si on respecte le filtre |
|
| 498 | - * Appliquer aussi le critere {offset,limit} |
|
| 499 | - * |
|
| 500 | - * @return array|bool |
|
| 501 | - */ |
|
| 502 | - public function fetch() { |
|
| 503 | - if (method_exists($this->iter, 'fetch')) { |
|
| 504 | - return $this->iter->fetch(); |
|
| 505 | - } else { |
|
| 506 | - |
|
| 507 | - while ($this->valid() |
|
| 508 | - and ( |
|
| 509 | - !$this->accept() |
|
| 510 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | - )) { |
|
| 512 | - $this->next(); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - if (!$this->valid()) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - if (isset($this->limit) |
|
| 520 | - and $this->fetched > $this->offset + $this->limit |
|
| 521 | - ) { |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $r = array(); |
|
| 526 | - foreach ($this->select as $nom) { |
|
| 527 | - $r[$nom] = $this->get_select($nom); |
|
| 528 | - } |
|
| 529 | - $this->next(); |
|
| 530 | - |
|
| 531 | - return $r; |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - // retourner la cle pour #CLE |
|
| 536 | - public function cle() { |
|
| 537 | - return $this->key(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // retourner la valeur pour #VALEUR |
|
| 541 | - public function valeur() { |
|
| 542 | - return $this->current(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Accepte-t-on l'entree courante lue ? |
|
| 547 | - * On execute les filtres pour le savoir. |
|
| 548 | - **/ |
|
| 549 | - public function accept() { |
|
| 550 | - if ($f = $this->func_filtre) { |
|
| 551 | - return $f(); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * liberer la ressource |
|
| 559 | - * |
|
| 560 | - * @return bool |
|
| 561 | - */ |
|
| 562 | - public function free() { |
|
| 563 | - if (method_exists($this->iter, 'free')) { |
|
| 564 | - $this->iter->free(); |
|
| 565 | - } |
|
| 566 | - $this->pos = $this->total = 0; |
|
| 567 | - |
|
| 568 | - return true; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Compter le nombre total de resultats |
|
| 573 | - * pour #TOTAL_BOUCLE |
|
| 574 | - * |
|
| 575 | - * @return int |
|
| 576 | - */ |
|
| 577 | - public function count() { |
|
| 578 | - if (is_null($this->total)) { |
|
| 579 | - if (method_exists($this->iter, 'count') |
|
| 580 | - and !$this->func_filtre |
|
| 581 | - ) { |
|
| 582 | - return $this->total = $this->iter->count(); |
|
| 583 | - } else { |
|
| 584 | - // compter les lignes et rembobiner |
|
| 585 | - $total = 0; |
|
| 586 | - $pos = $this->pos; // sauver la position |
|
| 587 | - $this->rewind(); |
|
| 588 | - while ($this->fetch() and $total < $this->max) { |
|
| 589 | - $total++; |
|
| 590 | - } |
|
| 591 | - $this->seek($pos); |
|
| 592 | - $this->total = $total; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $this->total; |
|
| 597 | - } |
|
| 451 | + private function seek_loop($n) { |
|
| 452 | + if ($this->pos > $n) { |
|
| 453 | + $this->rewind(); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + while ($this->pos < $n and $this->valid()) { |
|
| 457 | + $this->next(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + return true; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Avancer de $saut pas |
|
| 465 | + * |
|
| 466 | + * @param $saut |
|
| 467 | + * @param $max |
|
| 468 | + * @return int |
|
| 469 | + */ |
|
| 470 | + public function skip($saut, $max = null) { |
|
| 471 | + // pas de saut en arriere autorise pour cette fonction |
|
| 472 | + if (($saut = intval($saut)) <= 0) { |
|
| 473 | + return $this->pos; |
|
| 474 | + } |
|
| 475 | + $seek = $this->pos + $saut; |
|
| 476 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | + // et on sort |
|
| 478 | + if (is_null($max)) { |
|
| 479 | + $max = $this->count(); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | + $this->free(); |
|
| 485 | + |
|
| 486 | + return $max; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $this->seek($seek); |
|
| 490 | + |
|
| 491 | + return $this->pos; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Renvoyer un tableau des donnees correspondantes |
|
| 496 | + * a la position courante de l'iterateur |
|
| 497 | + * en controlant si on respecte le filtre |
|
| 498 | + * Appliquer aussi le critere {offset,limit} |
|
| 499 | + * |
|
| 500 | + * @return array|bool |
|
| 501 | + */ |
|
| 502 | + public function fetch() { |
|
| 503 | + if (method_exists($this->iter, 'fetch')) { |
|
| 504 | + return $this->iter->fetch(); |
|
| 505 | + } else { |
|
| 506 | + |
|
| 507 | + while ($this->valid() |
|
| 508 | + and ( |
|
| 509 | + !$this->accept() |
|
| 510 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | + )) { |
|
| 512 | + $this->next(); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + if (!$this->valid()) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + if (isset($this->limit) |
|
| 520 | + and $this->fetched > $this->offset + $this->limit |
|
| 521 | + ) { |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $r = array(); |
|
| 526 | + foreach ($this->select as $nom) { |
|
| 527 | + $r[$nom] = $this->get_select($nom); |
|
| 528 | + } |
|
| 529 | + $this->next(); |
|
| 530 | + |
|
| 531 | + return $r; |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + // retourner la cle pour #CLE |
|
| 536 | + public function cle() { |
|
| 537 | + return $this->key(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // retourner la valeur pour #VALEUR |
|
| 541 | + public function valeur() { |
|
| 542 | + return $this->current(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Accepte-t-on l'entree courante lue ? |
|
| 547 | + * On execute les filtres pour le savoir. |
|
| 548 | + **/ |
|
| 549 | + public function accept() { |
|
| 550 | + if ($f = $this->func_filtre) { |
|
| 551 | + return $f(); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * liberer la ressource |
|
| 559 | + * |
|
| 560 | + * @return bool |
|
| 561 | + */ |
|
| 562 | + public function free() { |
|
| 563 | + if (method_exists($this->iter, 'free')) { |
|
| 564 | + $this->iter->free(); |
|
| 565 | + } |
|
| 566 | + $this->pos = $this->total = 0; |
|
| 567 | + |
|
| 568 | + return true; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Compter le nombre total de resultats |
|
| 573 | + * pour #TOTAL_BOUCLE |
|
| 574 | + * |
|
| 575 | + * @return int |
|
| 576 | + */ |
|
| 577 | + public function count() { |
|
| 578 | + if (is_null($this->total)) { |
|
| 579 | + if (method_exists($this->iter, 'count') |
|
| 580 | + and !$this->func_filtre |
|
| 581 | + ) { |
|
| 582 | + return $this->total = $this->iter->count(); |
|
| 583 | + } else { |
|
| 584 | + // compter les lignes et rembobiner |
|
| 585 | + $total = 0; |
|
| 586 | + $pos = $this->pos; // sauver la position |
|
| 587 | + $this->rewind(); |
|
| 588 | + while ($this->fetch() and $total < $this->max) { |
|
| 589 | + $total++; |
|
| 590 | + } |
|
| 591 | + $this->seek($pos); |
|
| 592 | + $this->total = $total; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $this->total; |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | 599 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @param array $depart |
| 233 | 233 | * @param array $arrivee |
| 234 | - * @param string|array $col |
|
| 234 | + * @param string $col |
|
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
@@ -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 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return array('id_objet', 'objet', objet_type($champ)); |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return array('id_objet', 'objet', objet_type($champ)); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | - or array_key_exists($champ, $desc['field']) |
|
| 61 | - ) { |
|
| 62 | - return array($champ); |
|
| 63 | - } |
|
| 64 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | - array_pop($decompose); |
|
| 67 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | - return $decompose; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array($champ); |
|
| 59 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | + or array_key_exists($champ, $desc['field']) |
|
| 61 | + ) { |
|
| 62 | + return array($champ); |
|
| 63 | + } |
|
| 64 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | + array_pop($decompose); |
|
| 67 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | + return $decompose; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array($champ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | * Alias de la table de jointure (Lx) |
| 100 | 100 | */ |
| 101 | 101 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 102 | - // les jointures minimales sont optimales : |
|
| 103 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | - $max = 1; |
|
| 106 | - $res = false; |
|
| 107 | - $milieu_exclus = ($col ? $col : array()); |
|
| 108 | - while ($max <= $max_liens and !$res) { |
|
| 109 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | - $max++; |
|
| 111 | - } |
|
| 112 | - if (!$res) { |
|
| 113 | - return ""; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - list($nom, $desc) = $depart; |
|
| 117 | - |
|
| 118 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 102 | + // les jointures minimales sont optimales : |
|
| 103 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | + $max = 1; |
|
| 106 | + $res = false; |
|
| 107 | + $milieu_exclus = ($col ? $col : array()); |
|
| 108 | + while ($max <= $max_liens and !$res) { |
|
| 109 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | + $max++; |
|
| 111 | + } |
|
| 112 | + if (!$res) { |
|
| 113 | + return ""; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + list($nom, $desc) = $depart; |
|
| 117 | + |
|
| 118 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -154,78 +154,78 @@ discard block |
||
| 154 | 154 | * Alias de la table de jointure (Lx) |
| 155 | 155 | */ |
| 156 | 156 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true) { |
| 157 | - static $num = array(); |
|
| 158 | - $id_table = ""; |
|
| 159 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | - foreach ($res as $cle => $r) { |
|
| 161 | - list($d, $a, $j) = $r; |
|
| 162 | - if (!$id_table) { |
|
| 163 | - $id_table = $d; |
|
| 164 | - } |
|
| 165 | - $n = ++$cpt; |
|
| 166 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | - list($j1, $j2, $obj, $type) = $j; |
|
| 168 | - // trouver de quel cote est (id_objet,objet) |
|
| 169 | - if ($j1 == "id_$obj") { |
|
| 170 | - $obj = "$id_table.$obj"; |
|
| 171 | - } else { |
|
| 172 | - $obj = "L$n.$obj"; |
|
| 173 | - } |
|
| 174 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 175 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 176 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 177 | - $boucle->where["JOIN-L$n"] = |
|
| 178 | - $echap ? |
|
| 179 | - array("'='","'$obj'","sql_quote('$type')") |
|
| 180 | - : |
|
| 181 | - array("=","$obj",sql_quote($type)); |
|
| 182 | - $boucle->join["L$n"] = |
|
| 183 | - $echap ? |
|
| 184 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 185 | - : |
|
| 186 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 187 | - } else { |
|
| 188 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 189 | - } |
|
| 190 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - // pas besoin de group by |
|
| 195 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 196 | - // si une seule jointure et sur une table avec primary key formee |
|
| 197 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 198 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 199 | - |
|
| 200 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 201 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // pas de group by |
|
| 205 | - // si une seule jointure |
|
| 206 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 207 | - if (!$pk |
|
| 208 | - and (count($boucle->from) == 2) |
|
| 209 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 210 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 211 | - ) { |
|
| 212 | - $pk = true; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 216 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 217 | - if (!$pk) { |
|
| 218 | - foreach ($groups as $id_prim) { |
|
| 219 | - $id_field = $nom . '.' . $id_prim; |
|
| 220 | - if (!in_array($id_field, $boucle->group)) { |
|
| 221 | - $boucle->group[] = $id_field; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $boucle->modificateur['lien'] = true; |
|
| 227 | - |
|
| 228 | - return "L$n"; |
|
| 157 | + static $num = array(); |
|
| 158 | + $id_table = ""; |
|
| 159 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | + foreach ($res as $cle => $r) { |
|
| 161 | + list($d, $a, $j) = $r; |
|
| 162 | + if (!$id_table) { |
|
| 163 | + $id_table = $d; |
|
| 164 | + } |
|
| 165 | + $n = ++$cpt; |
|
| 166 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | + list($j1, $j2, $obj, $type) = $j; |
|
| 168 | + // trouver de quel cote est (id_objet,objet) |
|
| 169 | + if ($j1 == "id_$obj") { |
|
| 170 | + $obj = "$id_table.$obj"; |
|
| 171 | + } else { |
|
| 172 | + $obj = "L$n.$obj"; |
|
| 173 | + } |
|
| 174 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 175 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 176 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 177 | + $boucle->where["JOIN-L$n"] = |
|
| 178 | + $echap ? |
|
| 179 | + array("'='","'$obj'","sql_quote('$type')") |
|
| 180 | + : |
|
| 181 | + array("=","$obj",sql_quote($type)); |
|
| 182 | + $boucle->join["L$n"] = |
|
| 183 | + $echap ? |
|
| 184 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 185 | + : |
|
| 186 | + array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 187 | + } else { |
|
| 188 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 189 | + } |
|
| 190 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + // pas besoin de group by |
|
| 195 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 196 | + // si une seule jointure et sur une table avec primary key formee |
|
| 197 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 198 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 199 | + |
|
| 200 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 201 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // pas de group by |
|
| 205 | + // si une seule jointure |
|
| 206 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 207 | + if (!$pk |
|
| 208 | + and (count($boucle->from) == 2) |
|
| 209 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 210 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 211 | + ) { |
|
| 212 | + $pk = true; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 216 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 217 | + if (!$pk) { |
|
| 218 | + foreach ($groups as $id_prim) { |
|
| 219 | + $id_field = $nom . '.' . $id_prim; |
|
| 220 | + if (!in_array($id_field, $boucle->group)) { |
|
| 221 | + $boucle->group[] = $id_field; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $boucle->modificateur['lien'] = true; |
|
| 227 | + |
|
| 228 | + return "L$n"; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | * @return bool |
| 241 | 241 | */ |
| 242 | 242 | function nogroupby_if($depart, $arrivee, $col) { |
| 243 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 244 | - if (!$pk) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 248 | - if (is_array($col)) { |
|
| 249 | - $col = implode(', *', $col); |
|
| 250 | - } // cas id_objet, objet |
|
| 251 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 252 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 243 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 244 | + if (!$pk) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 248 | + if (is_array($col)) { |
|
| 249 | + $col = implode(', *', $col); |
|
| 250 | + } // cas id_objet, objet |
|
| 251 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 252 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -267,46 +267,46 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 269 | 269 | |
| 270 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 270 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 271 | 271 | |
| 272 | - // si cle primaire demandee, la privilegier |
|
| 273 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 274 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 275 | - } |
|
| 272 | + // si cle primaire demandee, la privilegier |
|
| 273 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 274 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - // les champs declares explicitement pour les jointures |
|
| 278 | - if (isset($desc['join'])) { |
|
| 279 | - return $desc['join']; |
|
| 280 | - } |
|
| 281 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 277 | + // les champs declares explicitement pour les jointures |
|
| 278 | + if (isset($desc['join'])) { |
|
| 279 | + return $desc['join']; |
|
| 280 | + } |
|
| 281 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 282 | 282 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 283 | 283 | |
| 284 | - // si pas de cle, c'est fichu |
|
| 285 | - if (!isset($desc['key'])) { |
|
| 286 | - return array(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // si cle primaire |
|
| 290 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 291 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // ici on se rabat sur les cles secondaires, |
|
| 295 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 296 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 297 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 298 | - |
|
| 299 | - $join = array(); |
|
| 300 | - foreach ($desc['key'] as $v) { |
|
| 301 | - $join = split_key($v, $join); |
|
| 302 | - } |
|
| 303 | - foreach ($join as $k) { |
|
| 304 | - if (in_array($k, $nojoin)) { |
|
| 305 | - unset($join[$k]); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return $join; |
|
| 284 | + // si pas de cle, c'est fichu |
|
| 285 | + if (!isset($desc['key'])) { |
|
| 286 | + return array(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // si cle primaire |
|
| 290 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 291 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // ici on se rabat sur les cles secondaires, |
|
| 295 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 296 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 297 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 298 | + |
|
| 299 | + $join = array(); |
|
| 300 | + foreach ($desc['key'] as $v) { |
|
| 301 | + $join = split_key($v, $join); |
|
| 302 | + } |
|
| 303 | + foreach ($join as $k) { |
|
| 304 | + if (in_array($k, $nojoin)) { |
|
| 305 | + unset($join[$k]); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return $join; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * @return array |
| 318 | 318 | */ |
| 319 | 319 | function split_key($v, $join = array()) { |
| 320 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 321 | - if (strpos($k, '(') !== false) { |
|
| 322 | - $k = explode('(', $k); |
|
| 323 | - $k = trim(reset($k)); |
|
| 324 | - } |
|
| 325 | - $join[$k] = $k; |
|
| 326 | - } |
|
| 327 | - return $join; |
|
| 320 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 321 | + if (strpos($k, '(') !== false) { |
|
| 322 | + $k = explode('(', $k); |
|
| 323 | + $k = trim(reset($k)); |
|
| 324 | + } |
|
| 325 | + $join[$k] = $k; |
|
| 326 | + } |
|
| 327 | + return $join; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -347,126 +347,126 @@ discard block |
||
| 347 | 347 | * @return array |
| 348 | 348 | */ |
| 349 | 349 | function calculer_chaine_jointures( |
| 350 | - &$boucle, |
|
| 351 | - $depart, |
|
| 352 | - $arrivee, |
|
| 353 | - $vu = array(), |
|
| 354 | - $milieu_exclus = array(), |
|
| 355 | - $max_liens = 5 |
|
| 350 | + &$boucle, |
|
| 351 | + $depart, |
|
| 352 | + $arrivee, |
|
| 353 | + $vu = array(), |
|
| 354 | + $milieu_exclus = array(), |
|
| 355 | + $max_liens = 5 |
|
| 356 | 356 | ) { |
| 357 | - static $trouver_table; |
|
| 358 | - if (!$trouver_table) { |
|
| 359 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (is_string($milieu_exclus)) { |
|
| 363 | - $milieu_exclus = array($milieu_exclus); |
|
| 364 | - } |
|
| 365 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 366 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 367 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 368 | - $milieu_exclus[] = 'objet'; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - list($dnom, $ddesc) = $depart; |
|
| 372 | - list($anom, $adesc) = $arrivee; |
|
| 373 | - if (!count($vu)) { |
|
| 374 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 375 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $akeys = array(); |
|
| 379 | - foreach ($adesc['key'] as $k) { |
|
| 380 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 381 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 385 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 386 | - |
|
| 387 | - // cles candidates au depart |
|
| 388 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 389 | - // enlever les cles dde depart exclues par l'appel |
|
| 390 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 391 | - |
|
| 392 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 393 | - |
|
| 394 | - if ($v) { |
|
| 395 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 399 | - if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 400 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 401 | - // id_objet,objet |
|
| 402 | - // si oui on la prend |
|
| 403 | - foreach ($akeys as $key) { |
|
| 404 | - $v = decompose_champ_id_objet($key); |
|
| 405 | - if (is_array($v)) { |
|
| 406 | - $objet = array_shift($v); // objet,'article' |
|
| 407 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 408 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 409 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } else { |
|
| 413 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 414 | - // id_objet,objet a l'arrivee |
|
| 415 | - // si oui on la prend |
|
| 416 | - foreach ($keys as $key) { |
|
| 417 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 418 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 419 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 420 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 421 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 427 | - if ($max_liens <= 1) { |
|
| 428 | - return array(); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // sinon essayer de passer par une autre table |
|
| 432 | - $new = $vu; |
|
| 433 | - foreach ($boucle->jointures as $v) { |
|
| 434 | - if ($v |
|
| 435 | - and !in_array($v, $vu) |
|
| 436 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 437 | - and !in_array($def['table_sql'], $vu) |
|
| 438 | - ) { |
|
| 439 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 440 | - // ie la cle de la jointure precedente |
|
| 441 | - $test_cles = $milieu_exclus; |
|
| 442 | - $new[] = $v; |
|
| 443 | - $max_iter = 50; // securite |
|
| 444 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 445 | - $test_cles, 1)) |
|
| 446 | - and $max_iter--) { |
|
| 447 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 448 | - $milieu = end($jointure_directe_possible); |
|
| 449 | - $exclure_fin = $milieu_exclus; |
|
| 450 | - if (is_string($milieu)) { |
|
| 451 | - $exclure_fin[] = $milieu; |
|
| 452 | - $test_cles[] = $milieu; |
|
| 453 | - } else { |
|
| 454 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 455 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 456 | - } |
|
| 457 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 458 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 459 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 460 | - if ($r) { |
|
| 461 | - array_unshift($r, $jointure_directe_possible); |
|
| 462 | - |
|
| 463 | - return $r; |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return array(); |
|
| 357 | + static $trouver_table; |
|
| 358 | + if (!$trouver_table) { |
|
| 359 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (is_string($milieu_exclus)) { |
|
| 363 | + $milieu_exclus = array($milieu_exclus); |
|
| 364 | + } |
|
| 365 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 366 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 367 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 368 | + $milieu_exclus[] = 'objet'; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + list($dnom, $ddesc) = $depart; |
|
| 372 | + list($anom, $adesc) = $arrivee; |
|
| 373 | + if (!count($vu)) { |
|
| 374 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 375 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $akeys = array(); |
|
| 379 | + foreach ($adesc['key'] as $k) { |
|
| 380 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 381 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 385 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 386 | + |
|
| 387 | + // cles candidates au depart |
|
| 388 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 389 | + // enlever les cles dde depart exclues par l'appel |
|
| 390 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 391 | + |
|
| 392 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 393 | + |
|
| 394 | + if ($v) { |
|
| 395 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 399 | + if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 400 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 401 | + // id_objet,objet |
|
| 402 | + // si oui on la prend |
|
| 403 | + foreach ($akeys as $key) { |
|
| 404 | + $v = decompose_champ_id_objet($key); |
|
| 405 | + if (is_array($v)) { |
|
| 406 | + $objet = array_shift($v); // objet,'article' |
|
| 407 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 408 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 409 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } else { |
|
| 413 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 414 | + // id_objet,objet a l'arrivee |
|
| 415 | + // si oui on la prend |
|
| 416 | + foreach ($keys as $key) { |
|
| 417 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 418 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 419 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 420 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 421 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 427 | + if ($max_liens <= 1) { |
|
| 428 | + return array(); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // sinon essayer de passer par une autre table |
|
| 432 | + $new = $vu; |
|
| 433 | + foreach ($boucle->jointures as $v) { |
|
| 434 | + if ($v |
|
| 435 | + and !in_array($v, $vu) |
|
| 436 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 437 | + and !in_array($def['table_sql'], $vu) |
|
| 438 | + ) { |
|
| 439 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 440 | + // ie la cle de la jointure precedente |
|
| 441 | + $test_cles = $milieu_exclus; |
|
| 442 | + $new[] = $v; |
|
| 443 | + $max_iter = 50; // securite |
|
| 444 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 445 | + $test_cles, 1)) |
|
| 446 | + and $max_iter--) { |
|
| 447 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 448 | + $milieu = end($jointure_directe_possible); |
|
| 449 | + $exclure_fin = $milieu_exclus; |
|
| 450 | + if (is_string($milieu)) { |
|
| 451 | + $exclure_fin[] = $milieu; |
|
| 452 | + $test_cles[] = $milieu; |
|
| 453 | + } else { |
|
| 454 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 455 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 456 | + } |
|
| 457 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 458 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 459 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 460 | + if ($r) { |
|
| 461 | + array_unshift($r, $jointure_directe_possible); |
|
| 462 | + |
|
| 463 | + return $r; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return array(); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -477,18 +477,18 @@ discard block |
||
| 477 | 477 | * @return array |
| 478 | 478 | */ |
| 479 | 479 | function trouver_cles_table($keys) { |
| 480 | - $res = array(); |
|
| 481 | - foreach ($keys as $v) { |
|
| 482 | - if (!strpos($v, ",")) { |
|
| 483 | - $res[$v] = 1; |
|
| 484 | - } else { |
|
| 485 | - foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 486 | - $res[$k] = 1; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return array_keys($res); |
|
| 480 | + $res = array(); |
|
| 481 | + foreach ($keys as $v) { |
|
| 482 | + if (!strpos($v, ",")) { |
|
| 483 | + $res[$v] = 1; |
|
| 484 | + } else { |
|
| 485 | + foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 486 | + $res[$k] = 1; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return array_keys($res); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -515,33 +515,33 @@ discard block |
||
| 515 | 515 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 516 | 516 | */ |
| 517 | 517 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 518 | - static $trouver_table = ''; |
|
| 519 | - if (!$trouver_table) { |
|
| 520 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if (!is_array($cle)) { |
|
| 524 | - $cle = array($cle); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - foreach ($tables as $k => $table) { |
|
| 528 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 529 | - if (isset($desc['field']) |
|
| 530 | - // verifier que toutes les cles cherchees sont la |
|
| 531 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 532 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 533 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 534 | - ) { |
|
| 535 | - return array( |
|
| 536 | - 'desc' => $desc, |
|
| 537 | - 'table' => $desc['table'], |
|
| 538 | - 'alias' => $k, |
|
| 539 | - ); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return false; |
|
| 518 | + static $trouver_table = ''; |
|
| 519 | + if (!$trouver_table) { |
|
| 520 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if (!is_array($cle)) { |
|
| 524 | + $cle = array($cle); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + foreach ($tables as $k => $table) { |
|
| 528 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 529 | + if (isset($desc['field']) |
|
| 530 | + // verifier que toutes les cles cherchees sont la |
|
| 531 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 532 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 533 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 534 | + ) { |
|
| 535 | + return array( |
|
| 536 | + 'desc' => $desc, |
|
| 537 | + 'table' => $desc['table'], |
|
| 538 | + 'alias' => $k, |
|
| 539 | + ); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return false; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -567,52 +567,52 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 569 | 569 | |
| 570 | - // support de la recherche multi champ : |
|
| 571 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 572 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 573 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 574 | - if (!is_array($cle)) { |
|
| 575 | - $cle = array($cle); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 579 | - return array($infos['table'], $infos['desc'], $cle); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - // au premier coup, on essaye de decomposer, si possible |
|
| 583 | - if (count($cle) == 1 |
|
| 584 | - and $c = reset($cle) |
|
| 585 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 586 | - ) { |
|
| 587 | - |
|
| 588 | - $desc = $boucle->show; |
|
| 589 | - |
|
| 590 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 591 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 592 | - if (isset($desc['field'][$c])) { |
|
| 593 | - $cle = array(); |
|
| 594 | - $cle[] = array_shift($decompose); // id_objet |
|
| 595 | - $cle[] = array_shift($decompose); // objet |
|
| 596 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 597 | - } |
|
| 598 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 599 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 600 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 601 | - else { |
|
| 602 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 603 | - foreach ($depart as $d) { |
|
| 604 | - $cle = array(); |
|
| 605 | - $cle[] = array_shift($decompose); // id_objet |
|
| 606 | - $cle[] = array_shift($decompose); // objet |
|
| 607 | - $cle[] = $d; |
|
| 608 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 609 | - return $ext; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return ""; |
|
| 570 | + // support de la recherche multi champ : |
|
| 571 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 572 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 573 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 574 | + if (!is_array($cle)) { |
|
| 575 | + $cle = array($cle); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 579 | + return array($infos['table'], $infos['desc'], $cle); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + // au premier coup, on essaye de decomposer, si possible |
|
| 583 | + if (count($cle) == 1 |
|
| 584 | + and $c = reset($cle) |
|
| 585 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 586 | + ) { |
|
| 587 | + |
|
| 588 | + $desc = $boucle->show; |
|
| 589 | + |
|
| 590 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 591 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 592 | + if (isset($desc['field'][$c])) { |
|
| 593 | + $cle = array(); |
|
| 594 | + $cle[] = array_shift($decompose); // id_objet |
|
| 595 | + $cle[] = array_shift($decompose); // objet |
|
| 596 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 597 | + } |
|
| 598 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 599 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 600 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 601 | + else { |
|
| 602 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 603 | + foreach ($depart as $d) { |
|
| 604 | + $cle = array(); |
|
| 605 | + $cle[] = array_shift($decompose); // id_objet |
|
| 606 | + $cle[] = array_shift($decompose); // objet |
|
| 607 | + $cle[] = $d; |
|
| 608 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 609 | + return $ext; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return ""; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -644,21 +644,21 @@ discard block |
||
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | 646 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 647 | - if ($jointures === false) { |
|
| 648 | - $jointures = $boucle->jointures; |
|
| 649 | - } |
|
| 650 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 651 | - // mais pas poour construire la jointure ensuite |
|
| 652 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 653 | - if ($arrivee) { |
|
| 654 | - $desc = $boucle->show; |
|
| 655 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 656 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 657 | - if ($cle) { |
|
| 658 | - return $cle; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 662 | - |
|
| 663 | - return ''; |
|
| 647 | + if ($jointures === false) { |
|
| 648 | + $jointures = $boucle->jointures; |
|
| 649 | + } |
|
| 650 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 651 | + // mais pas poour construire la jointure ensuite |
|
| 652 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 653 | + if ($arrivee) { |
|
| 654 | + $desc = $boucle->show; |
|
| 655 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 656 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 657 | + if ($cle) { |
|
| 658 | + return $cle; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 662 | + |
|
| 663 | + return ''; |
|
| 664 | 664 | } |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | // sache qu'il peut enlever ce where si il enleve la jointure |
| 177 | 177 | $boucle->where["JOIN-L$n"] = |
| 178 | 178 | $echap ? |
| 179 | - array("'='","'$obj'","sql_quote('$type')") |
|
| 179 | + array("'='", "'$obj'", "sql_quote('$type')") |
|
| 180 | 180 | : |
| 181 | - array("=","$obj",sql_quote($type)); |
|
| 181 | + array("=", "$obj", sql_quote($type)); |
|
| 182 | 182 | $boucle->join["L$n"] = |
| 183 | 183 | $echap ? |
| 184 | 184 | array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
| 185 | 185 | : |
| 186 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 186 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 187 | 187 | } else { |
| 188 | 188 | $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
| 189 | 189 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $groups = liste_champs_jointures($nom, $desc, true); |
| 217 | 217 | if (!$pk) { |
| 218 | 218 | foreach ($groups as $id_prim) { |
| 219 | - $id_field = $nom . '.' . $id_prim; |
|
| 219 | + $id_field = $nom.'.'.$id_prim; |
|
| 220 | 220 | if (!in_array($id_field, $boucle->group)) { |
| 221 | 221 | $boucle->group[] = $id_field; |
| 222 | 222 | } |
@@ -75,6 +75,9 @@ |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | +/** |
|
| 79 | + * @param string $nom |
|
| 80 | + */ |
|
| 78 | 81 | function phraser_logo_faux_filtres($nom) { |
| 79 | 82 | switch ($nom) { |
| 80 | 83 | case 'top': |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | 55 | |
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 57 | 57 | $champ = new Champ(); |
| 58 | 58 | $champ->nom_boucle = $m[2]; |
| 59 | 59 | $champ->nom_champ = $m[3]; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $p->param[0][1] = array($c); |
| 132 | 132 | $p->param[0][0] = ''; |
| 133 | 133 | $p->fonctions = array(); |
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -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 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,135 +25,135 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = array(''); |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte; |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = array($c); |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - |
|
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | - $champ = new Champ(); |
|
| 58 | - $champ->nom_boucle = $m[2]; |
|
| 59 | - $champ->nom_champ = $m[3]; |
|
| 60 | - $champ->etoile = $m[5]; |
|
| 61 | - $champ = array($champ); |
|
| 62 | - if ($m[6]) { |
|
| 63 | - $r = new Texte; |
|
| 64 | - $r->texte = $m[6]; |
|
| 65 | - $champ[] = $r; |
|
| 66 | - } |
|
| 67 | - $args[] = $champ; |
|
| 68 | - array_shift($p->param); |
|
| 69 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | - |
|
| 71 | - } // le cas else est la seule incompatibilite |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = array(''); |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte; |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = array($c); |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + |
|
| 56 | + } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | + $champ = new Champ(); |
|
| 58 | + $champ->nom_boucle = $m[2]; |
|
| 59 | + $champ->nom_champ = $m[3]; |
|
| 60 | + $champ->etoile = $m[5]; |
|
| 61 | + $champ = array($champ); |
|
| 62 | + if ($m[6]) { |
|
| 63 | + $r = new Texte; |
|
| 64 | + $r->texte = $m[6]; |
|
| 65 | + $champ[] = $r; |
|
| 66 | + } |
|
| 67 | + $args[] = $champ; |
|
| 68 | + array_shift($p->param); |
|
| 69 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | + |
|
| 71 | + } // le cas else est la seule incompatibilite |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + array_unshift($p->param, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function phraser_logo_faux_filtres($nom) { |
| 79 | - switch ($nom) { |
|
| 80 | - case 'top': |
|
| 81 | - case 'left': |
|
| 82 | - case 'right': |
|
| 83 | - case 'center': |
|
| 84 | - case 'bottom': |
|
| 85 | - return 0; |
|
| 86 | - case 'lien': |
|
| 87 | - return 1; |
|
| 88 | - case 'fichier': |
|
| 89 | - return 2; |
|
| 90 | - default: |
|
| 91 | - return $nom; |
|
| 92 | - } |
|
| 79 | + switch ($nom) { |
|
| 80 | + case 'top': |
|
| 81 | + case 'left': |
|
| 82 | + case 'right': |
|
| 83 | + case 'center': |
|
| 84 | + case 'bottom': |
|
| 85 | + return 0; |
|
| 86 | + case 'lien': |
|
| 87 | + return 1; |
|
| 88 | + case 'fichier': |
|
| 89 | + return 2; |
|
| 90 | + default: |
|
| 91 | + return $nom; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | // La balise embed_document est a present le modele emb |
| 97 | 97 | |
| 98 | 98 | function phraser_vieux_emb(&$p) { |
| 99 | - if (!is_array($p->param)) { |
|
| 100 | - $p->param = array(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Produire le premier argument {emb} |
|
| 104 | - $texte = new Texte; |
|
| 105 | - $texte->texte = 'emb'; |
|
| 106 | - $param = array('', array($texte)); |
|
| 107 | - |
|
| 108 | - // Transformer les filtres en arguments |
|
| 109 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | - if ($p->param[$i][0]) { |
|
| 111 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | - break; |
|
| 113 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | - $texte = new Texte; |
|
| 115 | - $texte->texte = $p->param[$i][0]; |
|
| 116 | - $param[] = array($texte); |
|
| 117 | - } |
|
| 118 | - array_shift($p->param); |
|
| 119 | - } |
|
| 120 | - array_unshift($p->param, $param); |
|
| 121 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | - $p->nom_champ = 'MODELE'; |
|
| 99 | + if (!is_array($p->param)) { |
|
| 100 | + $p->param = array(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Produire le premier argument {emb} |
|
| 104 | + $texte = new Texte; |
|
| 105 | + $texte->texte = 'emb'; |
|
| 106 | + $param = array('', array($texte)); |
|
| 107 | + |
|
| 108 | + // Transformer les filtres en arguments |
|
| 109 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | + if ($p->param[$i][0]) { |
|
| 111 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | + break; |
|
| 113 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | + $texte = new Texte; |
|
| 115 | + $texte->texte = $p->param[$i][0]; |
|
| 116 | + $param[] = array($texte); |
|
| 117 | + } |
|
| 118 | + array_shift($p->param); |
|
| 119 | + } |
|
| 120 | + array_unshift($p->param, $param); |
|
| 121 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | + $p->nom_champ = 'MODELE'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Vieux formulaire de recherch |
| 126 | 126 | |
| 127 | 127 | function phraser_vieux_recherche($p) { |
| 128 | - if ($p->param[0][0]) { |
|
| 129 | - $c = new Texte; |
|
| 130 | - $c->texte = $p->param[0][0]; |
|
| 131 | - $p->param[0][1] = array($c); |
|
| 132 | - $p->param[0][0] = ''; |
|
| 133 | - $p->fonctions = array(); |
|
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | - } |
|
| 128 | + if ($p->param[0][0]) { |
|
| 129 | + $c = new Texte; |
|
| 130 | + $c->texte = $p->param[0][0]; |
|
| 131 | + $p->param[0][1] = array($c); |
|
| 132 | + $p->param[0][0] = ''; |
|
| 133 | + $p->fonctions = array(); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Gerer la notation [(#EXPOSER|on,off)] |
| 139 | 139 | function phraser_vieux_exposer($p) { |
| 140 | - if ($a = $p->fonctions) { |
|
| 141 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | - $args = array(); |
|
| 143 | - if ($regs[1]) { |
|
| 144 | - $a = new Texte; |
|
| 145 | - $a->texte = $regs[1]; |
|
| 146 | - $args = array('', array($a)); |
|
| 147 | - if ($regs[3]) { |
|
| 148 | - $a = new Texte; |
|
| 149 | - $a->texte = $regs[3]; |
|
| 150 | - $args[] = array($a); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $p->param[0] = $args; |
|
| 154 | - $p->fonctions = array(); |
|
| 155 | - $p->nom_champ = 'EXPOSE'; |
|
| 156 | - } |
|
| 140 | + if ($a = $p->fonctions) { |
|
| 141 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | + $args = array(); |
|
| 143 | + if ($regs[1]) { |
|
| 144 | + $a = new Texte; |
|
| 145 | + $a->texte = $regs[1]; |
|
| 146 | + $args = array('', array($a)); |
|
| 147 | + if ($regs[3]) { |
|
| 148 | + $a = new Texte; |
|
| 149 | + $a->texte = $regs[3]; |
|
| 150 | + $args[] = array($a); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $p->param[0] = $args; |
|
| 154 | + $p->fonctions = array(); |
|
| 155 | + $p->nom_champ = 'EXPOSE'; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); } |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); } |
| 162 | 162 | |
| 163 | 163 | function normaliser_args_inclumodel($p) { |
| 164 | - $params = $p->param; |
|
| 165 | - if (!$params) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $args = $params[0]; |
|
| 169 | - if ($args[0]) { |
|
| 170 | - return; |
|
| 171 | - } // filtre immediat |
|
| 172 | - array_shift($p->param); |
|
| 173 | - foreach ($p->param as $l) { |
|
| 174 | - if (!array_shift($l)) { |
|
| 175 | - $args = array_merge($args, $l); |
|
| 176 | - array_shift($p->param); |
|
| 177 | - } else { |
|
| 178 | - break; |
|
| 179 | - } // filtre |
|
| 180 | - } |
|
| 181 | - array_unshift($p->param, $args); |
|
| 164 | + $params = $p->param; |
|
| 165 | + if (!$params) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $args = $params[0]; |
|
| 169 | + if ($args[0]) { |
|
| 170 | + return; |
|
| 171 | + } // filtre immediat |
|
| 172 | + array_shift($p->param); |
|
| 173 | + foreach ($p->param as $l) { |
|
| 174 | + if (!array_shift($l)) { |
|
| 175 | + $args = array_merge($args, $l); |
|
| 176 | + array_shift($p->param); |
|
| 177 | + } else { |
|
| 178 | + break; |
|
| 179 | + } // filtre |
|
| 180 | + } |
|
| 181 | + array_unshift($p->param, $args); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function normaliser_inclure($champ) { |
| 185 | - normaliser_args_inclumodel($champ); |
|
| 186 | - $l = $champ->param[0]; |
|
| 187 | - if (is_array($l) and !$l[0]) { |
|
| 188 | - foreach ($l as $k => $p) { |
|
| 189 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | - $p[0]->texte = trim($p[0]->texte); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - foreach ($l as $k => $p) { |
|
| 194 | - if (!$p or $p[0]->type != 'texte' or |
|
| 195 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | - ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($r[1]) { |
|
| 201 | - $p[0]->texte = $r[1]; |
|
| 202 | - } else { |
|
| 203 | - unset($p[0]); |
|
| 204 | - } |
|
| 205 | - $champ->texte = $p; |
|
| 206 | - unset($champ->param[0][$k]); |
|
| 207 | - if (count($champ->param[0]) == 1) { |
|
| 208 | - array_shift($champ->param); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - spip_log("inclure sans fond ni fichier"); |
|
| 185 | + normaliser_args_inclumodel($champ); |
|
| 186 | + $l = $champ->param[0]; |
|
| 187 | + if (is_array($l) and !$l[0]) { |
|
| 188 | + foreach ($l as $k => $p) { |
|
| 189 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | + $p[0]->texte = trim($p[0]->texte); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + foreach ($l as $k => $p) { |
|
| 194 | + if (!$p or $p[0]->type != 'texte' or |
|
| 195 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | + ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($r[1]) { |
|
| 201 | + $p[0]->texte = $r[1]; |
|
| 202 | + } else { |
|
| 203 | + unset($p[0]); |
|
| 204 | + } |
|
| 205 | + $champ->texte = $p; |
|
| 206 | + unset($champ->param[0][$k]); |
|
| 207 | + if (count($champ->param[0]) == 1) { |
|
| 208 | + array_shift($champ->param); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + spip_log("inclure sans fond ni fichier"); |
|
| 215 | 215 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @uses public_tester_redirection_dist() |
| 233 | 233 | * @param string $fond |
| 234 | - * @param array $contexte |
|
| 234 | + * @param string $contexte |
|
| 235 | 235 | * @param string $connect |
| 236 | 236 | * @return array|bool |
| 237 | 237 | */ |
@@ -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 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - |
|
| 61 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | - // (recursion possible a cause des modeles) |
|
| 63 | - if ($debug) { |
|
| 64 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // charger le squelette en specifiant les langages cibles et source |
|
| 69 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | - |
|
| 71 | - if (!$composer) { |
|
| 72 | - $composer = charger_fonction('composer', 'public'); |
|
| 73 | - } |
|
| 74 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | - } else { |
|
| 76 | - $fonc = ''; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | - $page = $fonc; |
|
| 81 | - } else { |
|
| 82 | - // Preparer l'appel de la fonction principale du squelette |
|
| 83 | - |
|
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | - |
|
| 86 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | - // et on enregistre l'etat courant des globales de notes... |
|
| 88 | - if (is_null($notes)) { |
|
| 89 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | - } |
|
| 91 | - if ($notes) { |
|
| 92 | - $notes('', 'empiler'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Rajouter d'office ces deux parametres |
|
| 96 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | - if (!isset($contexte['date'])) { |
|
| 99 | - $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | - $contexte['date_default'] = true; |
|
| 101 | - } else { |
|
| 102 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if (!isset($contexte['date_redac'])) { |
|
| 106 | - $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | - $contexte['date_redac_default'] = true; |
|
| 108 | - } else { |
|
| 109 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | - try { |
|
| 114 | - $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 115 | - } catch (Throwable $e) { |
|
| 116 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 118 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 119 | - $corps = "<pre>$msg</pre>"; |
|
| 120 | - $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
|
| 121 | - erreur_squelette($full_msg); |
|
| 122 | - unset($msg, $full_msg, $corps); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 126 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 127 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 128 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 129 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 130 | - if ($notes) { |
|
| 131 | - $notes('', 'depiler'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // reinjecter en dynamique la pile des notes |
|
| 135 | - // si il y a des inclure dynamiques |
|
| 136 | - // si la pile n'est pas vide |
|
| 137 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 138 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 139 | - if ($notes) { |
|
| 140 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // spip_log: un joli contexte |
|
| 144 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 145 | - |
|
| 146 | - $profile = spip_timer($a); |
|
| 147 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 148 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 149 | - |
|
| 150 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 151 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 152 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ($debug) { |
|
| 156 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 157 | - $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 158 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 159 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 160 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 161 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 189 | - . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + |
|
| 61 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | + // (recursion possible a cause des modeles) |
|
| 63 | + if ($debug) { |
|
| 64 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // charger le squelette en specifiant les langages cibles et source |
|
| 69 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | + |
|
| 71 | + if (!$composer) { |
|
| 72 | + $composer = charger_fonction('composer', 'public'); |
|
| 73 | + } |
|
| 74 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | + } else { |
|
| 76 | + $fonc = ''; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | + $page = $fonc; |
|
| 81 | + } else { |
|
| 82 | + // Preparer l'appel de la fonction principale du squelette |
|
| 83 | + |
|
| 84 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | + |
|
| 86 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | + // et on enregistre l'etat courant des globales de notes... |
|
| 88 | + if (is_null($notes)) { |
|
| 89 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | + } |
|
| 91 | + if ($notes) { |
|
| 92 | + $notes('', 'empiler'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Rajouter d'office ces deux parametres |
|
| 96 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | + if (!isset($contexte['date'])) { |
|
| 99 | + $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | + $contexte['date_default'] = true; |
|
| 101 | + } else { |
|
| 102 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if (!isset($contexte['date_redac'])) { |
|
| 106 | + $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | + $contexte['date_redac_default'] = true; |
|
| 108 | + } else { |
|
| 109 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | + try { |
|
| 114 | + $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 115 | + } catch (Throwable $e) { |
|
| 116 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 118 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 119 | + $corps = "<pre>$msg</pre>"; |
|
| 120 | + $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
|
| 121 | + erreur_squelette($full_msg); |
|
| 122 | + unset($msg, $full_msg, $corps); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 126 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 127 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 128 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 129 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 130 | + if ($notes) { |
|
| 131 | + $notes('', 'depiler'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // reinjecter en dynamique la pile des notes |
|
| 135 | + // si il y a des inclure dynamiques |
|
| 136 | + // si la pile n'est pas vide |
|
| 137 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 138 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 139 | + if ($notes) { |
|
| 140 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // spip_log: un joli contexte |
|
| 144 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 145 | + |
|
| 146 | + $profile = spip_timer($a); |
|
| 147 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 148 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 149 | + |
|
| 150 | + if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 151 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 152 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ($debug) { |
|
| 156 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 157 | + $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 158 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 159 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 160 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 161 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 189 | + . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,33 +210,33 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = array(); |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = get_class($val); |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr($val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } |
|
| 237 | - $infos[] = $var . '=' . $val; |
|
| 238 | - } |
|
| 239 | - return join(', ', $infos); |
|
| 213 | + $infos = array(); |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = get_class($val); |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr($val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } |
|
| 237 | + $infos[] = $var . '=' . $val; |
|
| 238 | + } |
|
| 239 | + return join(', ', $infos); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @return array|bool |
| 254 | 254 | */ |
| 255 | 255 | function tester_redirection($fond, $contexte, $connect) { |
| 256 | - static $tester_redirection = null; |
|
| 257 | - if (is_null($tester_redirection)) { |
|
| 258 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | - } |
|
| 260 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 256 | + static $tester_redirection = null; |
|
| 257 | + if (is_null($tester_redirection)) { |
|
| 258 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | + } |
|
| 260 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -273,41 +273,41 @@ discard block |
||
| 273 | 273 | * @return array|bool |
| 274 | 274 | */ |
| 275 | 275 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 276 | - if ($fond == 'article' |
|
| 277 | - and !empty($contexte['id_article']) |
|
| 278 | - and $id_article = intval($contexte['id_article']) |
|
| 279 | - ) { |
|
| 280 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 281 | - $m = quete_virtuel($id_article, $connect); |
|
| 282 | - if (strlen($m)) { |
|
| 283 | - include_spip('inc/texte'); |
|
| 284 | - // les navigateurs pataugent si l'URL est vide |
|
| 285 | - if ($url = virtuel_redirige($m, true)) { |
|
| 286 | - // passer en url absolue car cette redirection pourra |
|
| 287 | - // etre utilisee dans un contexte d'url qui change |
|
| 288 | - // y compris url arbo |
|
| 289 | - $status = 302; |
|
| 290 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 291 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 292 | - } |
|
| 293 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 294 | - include_spip('inc/filtres_mini'); |
|
| 295 | - $url = url_absolue($url); |
|
| 296 | - } |
|
| 297 | - $url = str_replace('&', '&', $url); |
|
| 298 | - |
|
| 299 | - return array( |
|
| 300 | - 'texte' => "<" |
|
| 301 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 302 | - . texte_script($url) |
|
| 303 | - . "','',$status);" |
|
| 304 | - . "?" . ">", |
|
| 305 | - 'process_ins' => 'php', |
|
| 306 | - 'status' => $status |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return false; |
|
| 276 | + if ($fond == 'article' |
|
| 277 | + and !empty($contexte['id_article']) |
|
| 278 | + and $id_article = intval($contexte['id_article']) |
|
| 279 | + ) { |
|
| 280 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 281 | + $m = quete_virtuel($id_article, $connect); |
|
| 282 | + if (strlen($m)) { |
|
| 283 | + include_spip('inc/texte'); |
|
| 284 | + // les navigateurs pataugent si l'URL est vide |
|
| 285 | + if ($url = virtuel_redirige($m, true)) { |
|
| 286 | + // passer en url absolue car cette redirection pourra |
|
| 287 | + // etre utilisee dans un contexte d'url qui change |
|
| 288 | + // y compris url arbo |
|
| 289 | + $status = 302; |
|
| 290 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 291 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 292 | + } |
|
| 293 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 294 | + include_spip('inc/filtres_mini'); |
|
| 295 | + $url = url_absolue($url); |
|
| 296 | + } |
|
| 297 | + $url = str_replace('&', '&', $url); |
|
| 298 | + |
|
| 299 | + return array( |
|
| 300 | + 'texte' => "<" |
|
| 301 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 302 | + . texte_script($url) |
|
| 303 | + . "','',$status);" |
|
| 304 | + . "?" . ">", |
|
| 305 | + 'process_ins' => 'php', |
|
| 306 | + 'status' => $status |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return false; |
|
| 313 | 313 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } else { |
| 82 | 82 | // Preparer l'appel de la fonction principale du squelette |
| 83 | 83 | |
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 85 | 85 | |
| 86 | 86 | // On cree un marqueur de notes unique lie a cette composition |
| 87 | 87 | // et on enregistre l'etat courant des globales de notes... |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | try { |
| 114 | 114 | $page = $fonc(array('cache' => $cache), array($contexte)); |
| 115 | 115 | } catch (Throwable $e) { |
| 116 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 116 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 117 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 118 | 118 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 119 | 119 | $corps = "<pre>$msg</pre>"; |
| 120 | 120 | $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $profile = spip_timer($a); |
| 147 | 147 | spip_log("calcul ($profile) [$skel] $infos" |
| 148 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 149 | 149 | |
| 150 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 150 | + if (defined('_CALCUL_PROFILER') AND intval($profile) > _CALCUL_PROFILER) { |
|
| 151 | 151 | spip_log("calcul ($profile) [$skel] $infos" |
| 152 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 152 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], "profiler"._LOG_AVERTISSEMENT); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if ($debug) { |
| 156 | 156 | // si c'est ce que demande le debusqueur, lui passer la main |
| 157 | 157 | $t = strlen($page['texte']) ? $page['texte'] : " "; |
| 158 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 159 | 159 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 160 | 160 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 161 | 161 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 189 | 189 | . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -220,21 +220,21 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | if (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = get_class($val); |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
| 234 | 234 | } elseif (strstr($val, ' ')) { |
| 235 | 235 | $val = "'$val'"; |
| 236 | 236 | } |
| 237 | - $infos[] = $var . '=' . $val; |
|
| 237 | + $infos[] = $var.'='.$val; |
|
| 238 | 238 | } |
| 239 | 239 | return join(', ', $infos); |
| 240 | 240 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 302 | 302 | . texte_script($url) |
| 303 | 303 | . "','',$status);" |
| 304 | - . "?" . ">", |
|
| 304 | + . "?".">", |
|
| 305 | 305 | 'process_ins' => 'php', |
| 306 | 306 | 'status' => $status |
| 307 | 307 | ); |