@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | // de connexion, et tout risque d'ambiguite |
| 91 | 91 | if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
| 92 | 92 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 93 | - _DIR_CACHE . 'sql_desc_' |
|
| 93 | + _DIR_CACHE.'sql_desc_' |
|
| 94 | 94 | . ($serveur ? "{$serveur}_" : '') |
| 95 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 95 | + . substr(md5($connexion['db'].':'.$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 96 | 96 | . '.txt'; |
| 97 | 97 | // nouveau nom de cache = nouvelle version en memoire |
| 98 | 98 | unset($connexion['tables']); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | if ($connexion['spip_connect_version']) { |
| 121 | 121 | if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
| 122 | 122 | $nom = $GLOBALS['table_des_tables'][$nom]; |
| 123 | - $nom_sql = 'spip_' . $nom; |
|
| 123 | + $nom_sql = 'spip_'.$nom; |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 148 | 148 | // si c'est une table principale, |
| 149 | 149 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 150 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 151 | - $nom_sql = 'spip_' . $nom; |
|
| 150 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_'.$nom])) { |
|
| 151 | + $nom_sql = 'spip_'.$nom; |
|
| 152 | 152 | $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
| 153 | 153 | } elseif ( |
| 154 | 154 | isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
| 155 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 155 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_'.$nom]) |
|
| 156 | 156 | ) { |
| 157 | 157 | $nom_sql = $n; |
| 158 | 158 | $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | ) { |
| 169 | 169 | if (!$fdesc) { |
| 170 | 170 | $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
| 171 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 171 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base'.$log_level); |
|
| 172 | 172 | |
| 173 | 173 | return null; |
| 174 | 174 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $desc['exist'] = true; |
| 181 | 181 | // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
| 182 | 182 | // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
| 183 | - if (! $desc['key']) { |
|
| 183 | + if (!$desc['key']) { |
|
| 184 | 184 | spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
| 185 | 185 | unset($desc['key']); |
| 186 | 186 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | if (!isset($desc['key']) && !empty($fdesc['key'])) { |
| 198 | 198 | $desc['key'] = $fdesc['key']; |
| 199 | 199 | } |
| 200 | - if (! isset($desc['key'])) { |
|
| 200 | + if (!isset($desc['key'])) { |
|
| 201 | 201 | $desc['key'] = []; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL\Tables |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -68,154 +68,154 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | **/ |
| 70 | 70 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true, array $options = []) { |
| 71 | - $desc_cache = null; |
|
| 72 | - static $nom_cache_desc_sql = []; |
|
| 73 | - |
|
| 74 | - if ( |
|
| 75 | - !spip_connect($serveur) |
|
| 76 | - or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | - ) { |
|
| 78 | - return null; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $options = $options + [ |
|
| 82 | - // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | - 'log_missing' => true, |
|
| 84 | - ]; |
|
| 85 | - |
|
| 86 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | - $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | - |
|
| 89 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | - // de connexion, et tout risque d'ambiguite |
|
| 92 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | - _DIR_CACHE . 'sql_desc_' |
|
| 95 | - . ($serveur ? "{$serveur}_" : '') |
|
| 96 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | - . '.txt'; |
|
| 98 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | - unset($connexion['tables']); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | - if (!$nom) { |
|
| 104 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | - $connexion['tables'] = []; |
|
| 106 | - |
|
| 107 | - return null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $nom_sql = $nom; |
|
| 111 | - if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | - $nom_sql = $s[1]; |
|
| 113 | - } else { |
|
| 114 | - $nom_sql = $nom; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $fdesc = $desc = ''; |
|
| 118 | - $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | - |
|
| 120 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | - if ($connexion['spip_connect_version']) { |
|
| 122 | - if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | - $nom_sql = 'spip_' . $nom; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // si c'est la premiere table qu'on cherche |
|
| 129 | - // et si on est pas explicitement en recalcul |
|
| 130 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | - // dans le fichier cache |
|
| 132 | - if ( |
|
| 133 | - !isset($connexion['tables'][$nom_sql]) |
|
| 134 | - and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | - and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | - ) { |
|
| 137 | - if ( |
|
| 138 | - lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | - and $desc_cache = unserialize($desc_cache) |
|
| 140 | - ) { |
|
| 141 | - $connexion['tables'] = $desc_cache; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | - } |
|
| 148 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | - // si c'est une table principale, |
|
| 150 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | - $nom_sql = 'spip_' . $nom; |
|
| 153 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | - } elseif ( |
|
| 155 | - isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | - ) { |
|
| 158 | - $nom_sql = $n; |
|
| 159 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | - } |
|
| 162 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | - // La *vraie* base a la priorite |
|
| 164 | - $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | - if ( |
|
| 166 | - !$exists |
|
| 167 | - or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | - or !$desc['field'] |
|
| 169 | - ) { |
|
| 170 | - if (!$fdesc) { |
|
| 171 | - $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | - |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - // on ne sait pas lire la structure de la table : |
|
| 177 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | - $desc = $fdesc; |
|
| 179 | - $desc['exist'] = false; |
|
| 180 | - } else { |
|
| 181 | - $desc['exist'] = true; |
|
| 182 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | - if (! $desc['key']) { |
|
| 185 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | - unset($desc['key']); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | - $desc['connexion'] = $serveur; |
|
| 192 | - |
|
| 193 | - // charger les infos declarees pour cette table |
|
| 194 | - // en lui passant les infos connues |
|
| 195 | - // $desc est prioritaire pour la description de la table |
|
| 196 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | - // s'assurer qu'on a toujours un 'key' |
|
| 198 | - if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | - $desc['key'] = $fdesc['key']; |
|
| 200 | - } |
|
| 201 | - if (! isset($desc['key'])) { |
|
| 202 | - $desc['key'] = []; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | - // une nouvelle table a ete decrite |
|
| 209 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | - if (is_writeable(_DIR_CACHE)) { |
|
| 211 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | - } |
|
| 213 | - } else { |
|
| 214 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // toujours retourner $nom dans id_table |
|
| 218 | - $res['id_table'] = $nom; |
|
| 219 | - |
|
| 220 | - return $res; |
|
| 71 | + $desc_cache = null; |
|
| 72 | + static $nom_cache_desc_sql = []; |
|
| 73 | + |
|
| 74 | + if ( |
|
| 75 | + !spip_connect($serveur) |
|
| 76 | + or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | + ) { |
|
| 78 | + return null; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $options = $options + [ |
|
| 82 | + // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | + 'log_missing' => true, |
|
| 84 | + ]; |
|
| 85 | + |
|
| 86 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | + $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | + |
|
| 89 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | + // de connexion, et tout risque d'ambiguite |
|
| 92 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | + _DIR_CACHE . 'sql_desc_' |
|
| 95 | + . ($serveur ? "{$serveur}_" : '') |
|
| 96 | + . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | + . '.txt'; |
|
| 98 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | + unset($connexion['tables']); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | + if (!$nom) { |
|
| 104 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | + $connexion['tables'] = []; |
|
| 106 | + |
|
| 107 | + return null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $nom_sql = $nom; |
|
| 111 | + if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | + $nom_sql = $s[1]; |
|
| 113 | + } else { |
|
| 114 | + $nom_sql = $nom; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $fdesc = $desc = ''; |
|
| 118 | + $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | + |
|
| 120 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | + if ($connexion['spip_connect_version']) { |
|
| 122 | + if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | + $nom_sql = 'spip_' . $nom; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // si c'est la premiere table qu'on cherche |
|
| 129 | + // et si on est pas explicitement en recalcul |
|
| 130 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | + // dans le fichier cache |
|
| 132 | + if ( |
|
| 133 | + !isset($connexion['tables'][$nom_sql]) |
|
| 134 | + and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | + and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | + ) { |
|
| 137 | + if ( |
|
| 138 | + lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | + and $desc_cache = unserialize($desc_cache) |
|
| 140 | + ) { |
|
| 141 | + $connexion['tables'] = $desc_cache; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | + } |
|
| 148 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | + // si c'est une table principale, |
|
| 150 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | + $nom_sql = 'spip_' . $nom; |
|
| 153 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | + } elseif ( |
|
| 155 | + isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | + ) { |
|
| 158 | + $nom_sql = $n; |
|
| 159 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | + } |
|
| 162 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | + // La *vraie* base a la priorite |
|
| 164 | + $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | + if ( |
|
| 166 | + !$exists |
|
| 167 | + or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | + or !$desc['field'] |
|
| 169 | + ) { |
|
| 170 | + if (!$fdesc) { |
|
| 171 | + $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | + |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + // on ne sait pas lire la structure de la table : |
|
| 177 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | + $desc = $fdesc; |
|
| 179 | + $desc['exist'] = false; |
|
| 180 | + } else { |
|
| 181 | + $desc['exist'] = true; |
|
| 182 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | + if (! $desc['key']) { |
|
| 185 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | + unset($desc['key']); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | + $desc['connexion'] = $serveur; |
|
| 192 | + |
|
| 193 | + // charger les infos declarees pour cette table |
|
| 194 | + // en lui passant les infos connues |
|
| 195 | + // $desc est prioritaire pour la description de la table |
|
| 196 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | + // s'assurer qu'on a toujours un 'key' |
|
| 198 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | + $desc['key'] = $fdesc['key']; |
|
| 200 | + } |
|
| 201 | + if (! isset($desc['key'])) { |
|
| 202 | + $desc['key'] = []; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | + // une nouvelle table a ete decrite |
|
| 209 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | + if (is_writeable(_DIR_CACHE)) { |
|
| 211 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // toujours retourner $nom dans id_table |
|
| 218 | + $res['id_table'] = $nom; |
|
| 219 | + |
|
| 220 | + return $res; |
|
| 221 | 221 | } |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | if (!is_null($options['range'])) { |
| 56 | 56 | spip_livrer_fichier_partie($fichier, $options['range']); |
| 57 | - } |
|
| 58 | - else { |
|
| 57 | + } else { |
|
| 59 | 58 | spip_livrer_fichier_entier($fichier); |
| 60 | 59 | } |
| 61 | 60 | } |
@@ -86,8 +85,7 @@ discard block |
||
| 86 | 85 | header('Expires: 0'); // set expiration time |
| 87 | 86 | header('Pragma: public'); |
| 88 | 87 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 89 | - } |
|
| 90 | - else { |
|
| 88 | + } else { |
|
| 91 | 89 | $f = basename($fichier); |
| 92 | 90 | header("Content-Disposition: inline; filename=\"$f\";"); |
| 93 | 91 | header('Expires: ' . $expires); // set expiration time |
@@ -154,8 +152,7 @@ discard block |
||
| 154 | 152 | } |
| 155 | 153 | |
| 156 | 154 | $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
| 157 | - } |
|
| 158 | - else { |
|
| 155 | + } else { |
|
| 159 | 156 | // si pas de range valide, on delegue a la methode d'envoi complet |
| 160 | 157 | spip_livrer_fichier_entier($fichier); |
| 161 | 158 | // redondant, mais facilite la comprehension du code |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Fichier |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -36,28 +36,28 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream', $options = []) { |
| 38 | 38 | |
| 39 | - $defaut = [ |
|
| 40 | - 'attachment' => false, |
|
| 41 | - 'expires' => 3600, |
|
| 42 | - 'range' => null |
|
| 43 | - ]; |
|
| 44 | - $options = array_merge($defaut, $options); |
|
| 45 | - if (is_numeric($options['expires']) and $options['expires'] > 0) { |
|
| 46 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) { |
|
| 50 | - $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']); |
|
| 54 | - |
|
| 55 | - if (!is_null($options['range'])) { |
|
| 56 | - spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 57 | - } |
|
| 58 | - else { |
|
| 59 | - spip_livrer_fichier_entier($fichier); |
|
| 60 | - } |
|
| 39 | + $defaut = [ |
|
| 40 | + 'attachment' => false, |
|
| 41 | + 'expires' => 3600, |
|
| 42 | + 'range' => null |
|
| 43 | + ]; |
|
| 44 | + $options = array_merge($defaut, $options); |
|
| 45 | + if (is_numeric($options['expires']) and $options['expires'] > 0) { |
|
| 46 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) { |
|
| 50 | + $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']); |
|
| 54 | + |
|
| 55 | + if (!is_null($options['range'])) { |
|
| 56 | + spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 57 | + } |
|
| 58 | + else { |
|
| 59 | + spip_livrer_fichier_entier($fichier); |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -70,28 +70,28 @@ discard block |
||
| 70 | 70 | * @param int|string $expires |
| 71 | 71 | */ |
| 72 | 72 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 73 | - // toujours envoyer un content type, meme vide ! |
|
| 74 | - header('Accept-Ranges: bytes'); |
|
| 75 | - header('Content-Type: ' . $content_type); |
|
| 76 | - |
|
| 77 | - if ($attachment) { |
|
| 78 | - $f = basename($fichier); |
|
| 79 | - // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 80 | - header('Content-Type: application/octet-stream'); |
|
| 81 | - |
|
| 82 | - header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 83 | - header('Content-Transfer-Encoding: binary'); |
|
| 84 | - |
|
| 85 | - // fix for IE caching or PHP bug issue |
|
| 86 | - header('Expires: 0'); // set expiration time |
|
| 87 | - header('Pragma: public'); |
|
| 88 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 89 | - } |
|
| 90 | - else { |
|
| 91 | - $f = basename($fichier); |
|
| 92 | - header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 93 | - header('Expires: ' . $expires); // set expiration time |
|
| 94 | - } |
|
| 73 | + // toujours envoyer un content type, meme vide ! |
|
| 74 | + header('Accept-Ranges: bytes'); |
|
| 75 | + header('Content-Type: ' . $content_type); |
|
| 76 | + |
|
| 77 | + if ($attachment) { |
|
| 78 | + $f = basename($fichier); |
|
| 79 | + // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 80 | + header('Content-Type: application/octet-stream'); |
|
| 81 | + |
|
| 82 | + header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 83 | + header('Content-Transfer-Encoding: binary'); |
|
| 84 | + |
|
| 85 | + // fix for IE caching or PHP bug issue |
|
| 86 | + header('Expires: 0'); // set expiration time |
|
| 87 | + header('Pragma: public'); |
|
| 88 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 89 | + } |
|
| 90 | + else { |
|
| 91 | + $f = basename($fichier); |
|
| 92 | + header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 93 | + header('Expires: ' . $expires); // set expiration time |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -99,20 +99,20 @@ discard block |
||
| 99 | 99 | * @param string $fichier |
| 100 | 100 | */ |
| 101 | 101 | function spip_livrer_fichier_entier($fichier) { |
| 102 | - if (!file_exists($fichier)) { |
|
| 103 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 104 | - } |
|
| 102 | + if (!file_exists($fichier)) { |
|
| 103 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if (!is_readable($fichier)) { |
|
| 107 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 108 | - } |
|
| 106 | + if (!is_readable($fichier)) { |
|
| 107 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if ($size = filesize($fichier)) { |
|
| 111 | - header(sprintf('Content-Length: %d', $size)); |
|
| 112 | - } |
|
| 110 | + if ($size = filesize($fichier)) { |
|
| 111 | + header(sprintf('Content-Length: %d', $size)); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - readfile($fichier); |
|
| 115 | - exit(); |
|
| 114 | + readfile($fichier); |
|
| 115 | + exit(); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -125,98 +125,98 @@ discard block |
||
| 125 | 125 | * @throws Exception |
| 126 | 126 | */ |
| 127 | 127 | function spip_livrer_fichier_partie($fichier, $range = null) { |
| 128 | - if (!file_exists($fichier)) { |
|
| 129 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 130 | - } |
|
| 128 | + if (!file_exists($fichier)) { |
|
| 129 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (!is_readable($fichier)) { |
|
| 133 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 134 | - } |
|
| 132 | + if (!is_readable($fichier)) { |
|
| 133 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | - // Par defaut on envoie tout |
|
| 138 | - $byteOffset = 0; |
|
| 139 | - $byteLength = $fileSize = filesize($fichier); |
|
| 137 | + // Par defaut on envoie tout |
|
| 138 | + $byteOffset = 0; |
|
| 139 | + $byteLength = $fileSize = filesize($fichier); |
|
| 140 | 140 | |
| 141 | 141 | |
| 142 | - // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 143 | - if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 144 | - ### Offset signifies where we should begin to read the file |
|
| 145 | - $byteOffset = (int)$match[1]; |
|
| 142 | + // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 143 | + if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 144 | + ### Offset signifies where we should begin to read the file |
|
| 145 | + $byteOffset = (int)$match[1]; |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | - ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 149 | - if (isset($match[2])) { |
|
| 150 | - $finishBytes = (int)$match[2]; |
|
| 151 | - $byteLength = $finishBytes + 1; |
|
| 152 | - } else { |
|
| 153 | - $finishBytes = $fileSize - 1; |
|
| 154 | - } |
|
| 148 | + ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 149 | + if (isset($match[2])) { |
|
| 150 | + $finishBytes = (int)$match[2]; |
|
| 151 | + $byteLength = $finishBytes + 1; |
|
| 152 | + } else { |
|
| 153 | + $finishBytes = $fileSize - 1; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 157 | - } |
|
| 158 | - else { |
|
| 159 | - // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 160 | - spip_livrer_fichier_entier($fichier); |
|
| 161 | - // redondant, mais facilite la comprehension du code |
|
| 162 | - exit(); |
|
| 163 | - } |
|
| 156 | + $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 157 | + } |
|
| 158 | + else { |
|
| 159 | + // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 160 | + spip_livrer_fichier_entier($fichier); |
|
| 161 | + // redondant, mais facilite la comprehension du code |
|
| 162 | + exit(); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Remove headers that might unnecessarily clutter up the output |
|
| 166 | - header_remove('Cache-Control'); |
|
| 167 | - header_remove('Pragma'); |
|
| 165 | + // Remove headers that might unnecessarily clutter up the output |
|
| 166 | + header_remove('Cache-Control'); |
|
| 167 | + header_remove('Pragma'); |
|
| 168 | 168 | |
| 169 | - // partial content |
|
| 170 | - header('HTTP/1.1 206 Partial content'); |
|
| 171 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 169 | + // partial content |
|
| 170 | + header('HTTP/1.1 206 Partial content'); |
|
| 171 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - $byteRange = $byteLength - $byteOffset; |
|
| 174 | + $byteRange = $byteLength - $byteOffset; |
|
| 175 | 175 | |
| 176 | - header(sprintf('Content-Length: %d', $byteRange)); |
|
| 176 | + header(sprintf('Content-Length: %d', $byteRange)); |
|
| 177 | 177 | |
| 178 | - // Variable containing the buffer |
|
| 179 | - $buffer = ''; |
|
| 180 | - // Just a reasonable buffer size |
|
| 181 | - $bufferSize = 512 * 16; |
|
| 182 | - // Contains how much is left to read of the byteRange |
|
| 183 | - $bytePool = $byteRange; |
|
| 178 | + // Variable containing the buffer |
|
| 179 | + $buffer = ''; |
|
| 180 | + // Just a reasonable buffer size |
|
| 181 | + $bufferSize = 512 * 16; |
|
| 182 | + // Contains how much is left to read of the byteRange |
|
| 183 | + $bytePool = $byteRange; |
|
| 184 | 184 | |
| 185 | - if (!$handle = fopen($fichier, 'r')) { |
|
| 186 | - throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 187 | - } |
|
| 185 | + if (!$handle = fopen($fichier, 'r')) { |
|
| 186 | + throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 190 | - throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 191 | - } |
|
| 189 | + if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 190 | + throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - while ($bytePool > 0) { |
|
| 195 | - // How many bytes we request on this iteration |
|
| 196 | - $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 194 | + while ($bytePool > 0) { |
|
| 195 | + // How many bytes we request on this iteration |
|
| 196 | + $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 197 | 197 | |
| 198 | - // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 199 | - $buffer = fread($handle, $chunkSizeRequested); |
|
| 198 | + // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 199 | + $buffer = fread($handle, $chunkSizeRequested); |
|
| 200 | 200 | |
| 201 | - // Store how many bytes were actually read |
|
| 202 | - $chunkSizeActual = strlen($buffer); |
|
| 201 | + // Store how many bytes were actually read |
|
| 202 | + $chunkSizeActual = strlen($buffer); |
|
| 203 | 203 | |
| 204 | - // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 205 | - if ($chunkSizeActual == 0) { |
|
| 206 | - // For production servers this should go in your php error log, since it will break the output |
|
| 207 | - trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 208 | - break; |
|
| 209 | - } |
|
| 204 | + // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 205 | + if ($chunkSizeActual == 0) { |
|
| 206 | + // For production servers this should go in your php error log, since it will break the output |
|
| 207 | + trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 208 | + break; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 212 | - $bytePool -= $chunkSizeActual; |
|
| 211 | + // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 212 | + $bytePool -= $chunkSizeActual; |
|
| 213 | 213 | |
| 214 | - // Write the buffer to output |
|
| 215 | - print $buffer; |
|
| 214 | + // Write the buffer to output |
|
| 215 | + print $buffer; |
|
| 216 | 216 | |
| 217 | - // Try to output the data to the client immediately |
|
| 218 | - flush(); |
|
| 219 | - } |
|
| 217 | + // Try to output the data to the client immediately |
|
| 218 | + flush(); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - exit(); |
|
| 221 | + exit(); |
|
| 222 | 222 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | ]; |
| 44 | 44 | $options = array_merge($defaut, $options); |
| 45 | 45 | if (is_numeric($options['expires']) and $options['expires'] > 0) { |
| 46 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 46 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']).' GMT'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 73 | 73 | // toujours envoyer un content type, meme vide ! |
| 74 | 74 | header('Accept-Ranges: bytes'); |
| 75 | - header('Content-Type: ' . $content_type); |
|
| 75 | + header('Content-Type: '.$content_type); |
|
| 76 | 76 | |
| 77 | 77 | if ($attachment) { |
| 78 | 78 | $f = basename($fichier); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | else { |
| 91 | 91 | $f = basename($fichier); |
| 92 | 92 | header("Content-Disposition: inline; filename=\"$f\";"); |
| 93 | - header('Expires: ' . $expires); // set expiration time |
|
| 93 | + header('Expires: '.$expires); // set expiration time |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
| 143 | 143 | if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
| 144 | 144 | ### Offset signifies where we should begin to read the file |
| 145 | - $byteOffset = (int)$match[1]; |
|
| 145 | + $byteOffset = (int) $match[1]; |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
| 149 | 149 | if (isset($match[2])) { |
| 150 | - $finishBytes = (int)$match[2]; |
|
| 150 | + $finishBytes = (int) $match[2]; |
|
| 151 | 151 | $byteLength = $finishBytes + 1; |
| 152 | 152 | } else { |
| 153 | 153 | $finishBytes = $fileSize - 1; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // partial content |
| 170 | 170 | header('HTTP/1.1 206 Partial content'); |
| 171 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 171 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | $byteRange = $byteLength - $byteOffset; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | // donc si on est dans le public avec un cache on va perdre le dynamisme |
| 148 | 148 | // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
| 149 | 149 | // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
| 150 | - $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'"; |
|
| 150 | + $p->code = "'<'.'?php echo (".texte_script($p->code)."); ?'.'>'"; |
|
| 151 | 151 | // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave) |
| 152 | 152 | } |
| 153 | 153 | return $p; |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | foreach ($erreurs as $k => $v) { |
| 328 | 328 | if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
| 329 | 329 | // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
| 330 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 330 | + $valeurs['erreurs'][$k] = "<span role='alert'>".$erreurs[$k].'</span>'; |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Formulaires |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/filtres'); |
@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | * Saisie protégée |
| 36 | 36 | **/ |
| 37 | 37 | function protege_champ($texte) { |
| 38 | - if (is_array($texte)) { |
|
| 39 | - return array_map('protege_champ', $texte); |
|
| 40 | - } elseif ($texte === null) { |
|
| 41 | - return $texte; |
|
| 42 | - } elseif (is_bool($texte)) { |
|
| 43 | - return $texte ? '1' : ''; |
|
| 44 | - } elseif (is_string($texte) and $texte) { |
|
| 45 | - if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | - // ne pas corrompre une valeur serialize |
|
| 47 | - return $texte; |
|
| 48 | - } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | - return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $texte; |
|
| 38 | + if (is_array($texte)) { |
|
| 39 | + return array_map('protege_champ', $texte); |
|
| 40 | + } elseif ($texte === null) { |
|
| 41 | + return $texte; |
|
| 42 | + } elseif (is_bool($texte)) { |
|
| 43 | + return $texte ? '1' : ''; |
|
| 44 | + } elseif (is_string($texte) and $texte) { |
|
| 45 | + if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | + // ne pas corrompre une valeur serialize |
|
| 47 | + return $texte; |
|
| 48 | + } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | + return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $texte; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * - false : pas de squelette trouvé |
| 65 | 65 | **/ |
| 66 | 66 | function existe_formulaire($form) { |
| 67 | - if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | - $form = strtolower(substr($form, 11)); |
|
| 69 | - } else { |
|
| 70 | - $form = strtolower($form); |
|
| 71 | - } |
|
| 67 | + if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | + $form = strtolower(substr($form, 11)); |
|
| 69 | + } else { |
|
| 70 | + $form = strtolower($form); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if (!$form) { |
|
| 74 | - return ''; |
|
| 75 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 73 | + if (!$form) { |
|
| 74 | + return ''; |
|
| 75 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 76 | 76 | |
| 77 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 77 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | * @return false|array |
| 84 | 84 | */ |
| 85 | 85 | function test_formulaire_inclus_par_modele() { |
| 86 | - $trace = debug_backtrace(0, 20); |
|
| 87 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | - |
|
| 90 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | - if ( |
|
| 92 | - function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | - and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | - ) { |
|
| 95 | - if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | - if ($trace[$k]['args'][0] === $form) { |
|
| 98 | - return $trace[$k]['args']; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | - if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | - return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | - } |
|
| 110 | - return false; |
|
| 86 | + $trace = debug_backtrace(0, 20); |
|
| 87 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | + |
|
| 90 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | + if ( |
|
| 92 | + function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | + and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | + ) { |
|
| 95 | + if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | + if ($trace[$k]['args'][0] === $form) { |
|
| 98 | + return $trace[$k]['args']; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | + if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | + } |
|
| 110 | + return false; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -122,32 +122,32 @@ discard block |
||
| 122 | 122 | **/ |
| 123 | 123 | function balise_FORMULAIRE__dist($p) { |
| 124 | 124 | |
| 125 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | - $p->code = "''"; |
|
| 129 | - $p->interdire_scripts = false; |
|
| 130 | - |
|
| 131 | - return $p; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // sinon renvoyer un code php dynamique |
|
| 135 | - $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 136 | - |
|
| 137 | - if ( |
|
| 138 | - !test_espace_prive() |
|
| 139 | - and !empty($p->descr['sourcefile']) |
|
| 140 | - and $f = $p->descr['sourcefile'] |
|
| 141 | - and basename(dirname($f)) === 'modeles' |
|
| 142 | - ) { |
|
| 143 | - // un modele est toujours inséré en texte dans son contenant |
|
| 144 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 145 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 146 | - // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 147 | - $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'"; |
|
| 148 | - // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave) |
|
| 149 | - } |
|
| 150 | - return $p; |
|
| 125 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | + $p->code = "''"; |
|
| 129 | + $p->interdire_scripts = false; |
|
| 130 | + |
|
| 131 | + return $p; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // sinon renvoyer un code php dynamique |
|
| 135 | + $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 136 | + |
|
| 137 | + if ( |
|
| 138 | + !test_espace_prive() |
|
| 139 | + and !empty($p->descr['sourcefile']) |
|
| 140 | + and $f = $p->descr['sourcefile'] |
|
| 141 | + and basename(dirname($f)) === 'modeles' |
|
| 142 | + ) { |
|
| 143 | + // un modele est toujours inséré en texte dans son contenant |
|
| 144 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 145 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 146 | + // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 147 | + $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'"; |
|
| 148 | + // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave) |
|
| 149 | + } |
|
| 150 | + return $p; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | * - string : texte à afficher directement |
| 168 | 168 | */ |
| 169 | 169 | function balise_FORMULAIRE__dyn($form, ...$args) { |
| 170 | - $form = existe_formulaire($form); |
|
| 171 | - if (!$form) { |
|
| 172 | - return ''; |
|
| 173 | - } |
|
| 170 | + $form = existe_formulaire($form); |
|
| 171 | + if (!$form) { |
|
| 172 | + return ''; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 176 | - if (!is_array($contexte)) { |
|
| 177 | - return $contexte; |
|
| 178 | - } |
|
| 175 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 176 | + if (!is_array($contexte)) { |
|
| 177 | + return $contexte; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - return ["formulaires/$form", 3600, $contexte]; |
|
| 180 | + return ["formulaires/$form", 3600, $contexte]; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -192,85 +192,85 @@ discard block |
||
| 192 | 192 | * string: Formulaire non applicable (message d’explication) |
| 193 | 193 | **/ |
| 194 | 194 | function balise_FORMULAIRE__contexte($form, $args) { |
| 195 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 196 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 197 | - // si poste, on recupere les erreurs |
|
| 198 | - |
|
| 199 | - $je_suis_poste = false; |
|
| 200 | - if ( |
|
| 201 | - $post_form = _request('formulaire_action') |
|
| 202 | - and $post_form == $form |
|
| 203 | - and $p = _request('formulaire_action_args') |
|
| 204 | - and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 205 | - ) { |
|
| 206 | - // enlever le faux attribut de langue masque |
|
| 207 | - array_shift($p); |
|
| 208 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 209 | - $je_suis_poste = true; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $editable = true; |
|
| 214 | - $erreurs = $post = []; |
|
| 215 | - if ($je_suis_poste) { |
|
| 216 | - $post = traiter_formulaires_dynamiques(true); |
|
| 217 | - $e = "erreurs_$form"; |
|
| 218 | - $erreurs = $post[$e] ?? []; |
|
| 219 | - $editable = "editable_$form"; |
|
| 220 | - $editable = (!isset($post[$e])) |
|
| 221 | - || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 222 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 226 | - |
|
| 227 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 228 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 229 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 230 | - if (!is_array($valeurs)) { |
|
| 231 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 235 | - // ou une action vide si elle ne sert pas |
|
| 236 | - $action = $valeurs['action'] ?? self('&', true); |
|
| 237 | - // bug IEx : si action finit par / |
|
| 238 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 239 | - if (substr($action, -1) == '/') { |
|
| 240 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 241 | - $action .= '#'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // recuperer la saisie en cours si erreurs |
|
| 245 | - // seulement si c'est ce formulaire qui est poste |
|
| 246 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 247 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 248 | - foreach (array_keys($valeurs) as $champ) { |
|
| 249 | - if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 250 | - if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 251 | - $valeurs[$champ] = $v; |
|
| 252 | - } |
|
| 253 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 254 | - if ($action) { |
|
| 255 | - $action = parametre_url($action, $champ, ''); |
|
| 256 | - } |
|
| 257 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 258 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($action) { |
|
| 263 | - // nettoyer l'url |
|
| 264 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 265 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 266 | - $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @deprecated 4.0 |
|
| 271 | - * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 272 | - */ |
|
| 273 | - /* |
|
| 195 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 196 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 197 | + // si poste, on recupere les erreurs |
|
| 198 | + |
|
| 199 | + $je_suis_poste = false; |
|
| 200 | + if ( |
|
| 201 | + $post_form = _request('formulaire_action') |
|
| 202 | + and $post_form == $form |
|
| 203 | + and $p = _request('formulaire_action_args') |
|
| 204 | + and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 205 | + ) { |
|
| 206 | + // enlever le faux attribut de langue masque |
|
| 207 | + array_shift($p); |
|
| 208 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 209 | + $je_suis_poste = true; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $editable = true; |
|
| 214 | + $erreurs = $post = []; |
|
| 215 | + if ($je_suis_poste) { |
|
| 216 | + $post = traiter_formulaires_dynamiques(true); |
|
| 217 | + $e = "erreurs_$form"; |
|
| 218 | + $erreurs = $post[$e] ?? []; |
|
| 219 | + $editable = "editable_$form"; |
|
| 220 | + $editable = (!isset($post[$e])) |
|
| 221 | + || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 222 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 226 | + |
|
| 227 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 228 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 229 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 230 | + if (!is_array($valeurs)) { |
|
| 231 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 235 | + // ou une action vide si elle ne sert pas |
|
| 236 | + $action = $valeurs['action'] ?? self('&', true); |
|
| 237 | + // bug IEx : si action finit par / |
|
| 238 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 239 | + if (substr($action, -1) == '/') { |
|
| 240 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 241 | + $action .= '#'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // recuperer la saisie en cours si erreurs |
|
| 245 | + // seulement si c'est ce formulaire qui est poste |
|
| 246 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 247 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 248 | + foreach (array_keys($valeurs) as $champ) { |
|
| 249 | + if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 250 | + if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 251 | + $valeurs[$champ] = $v; |
|
| 252 | + } |
|
| 253 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 254 | + if ($action) { |
|
| 255 | + $action = parametre_url($action, $champ, ''); |
|
| 256 | + } |
|
| 257 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 258 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($action) { |
|
| 263 | + // nettoyer l'url |
|
| 264 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 265 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 266 | + $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @deprecated 4.0 |
|
| 271 | + * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 272 | + */ |
|
| 273 | + /* |
|
| 274 | 274 | if (isset($valeurs['_action'])) { |
| 275 | 275 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 276 | 276 | $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
@@ -280,59 +280,59 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | */ |
| 282 | 282 | |
| 283 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 284 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 285 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 286 | - |
|
| 287 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 288 | - $valeurs['erreurs'] = $erreurs; |
|
| 289 | - $valeurs['action'] = $action; |
|
| 290 | - $valeurs['form'] = $form; |
|
| 291 | - |
|
| 292 | - $valeurs['formulaire_sign'] = ''; |
|
| 293 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 294 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 295 | - $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 296 | - $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - if (!isset($valeurs['id'])) { |
|
| 300 | - $valeurs['id'] = 'new'; |
|
| 301 | - } |
|
| 302 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 303 | - if (!isset($valeurs['editable'])) { |
|
| 304 | - $valeurs['editable'] = $editable; |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 307 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 308 | - |
|
| 309 | - if ($je_suis_poste) { |
|
| 310 | - $valeurs['message_erreur'] = ''; |
|
| 311 | - if (isset($erreurs['message_erreur'])) { |
|
| 312 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $valeurs['message_ok'] = ''; |
|
| 316 | - if (isset($post["message_ok_$form"])) { |
|
| 317 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 318 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 319 | - $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 323 | - // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 324 | - // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 325 | - if (html5_permis()) { |
|
| 326 | - foreach ($erreurs as $k => $v) { |
|
| 327 | - if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 328 | - // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 329 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $valeurs; |
|
| 283 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 284 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 285 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 286 | + |
|
| 287 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 288 | + $valeurs['erreurs'] = $erreurs; |
|
| 289 | + $valeurs['action'] = $action; |
|
| 290 | + $valeurs['form'] = $form; |
|
| 291 | + |
|
| 292 | + $valeurs['formulaire_sign'] = ''; |
|
| 293 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 294 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 295 | + $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 296 | + $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + if (!isset($valeurs['id'])) { |
|
| 300 | + $valeurs['id'] = 'new'; |
|
| 301 | + } |
|
| 302 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 303 | + if (!isset($valeurs['editable'])) { |
|
| 304 | + $valeurs['editable'] = $editable; |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 307 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 308 | + |
|
| 309 | + if ($je_suis_poste) { |
|
| 310 | + $valeurs['message_erreur'] = ''; |
|
| 311 | + if (isset($erreurs['message_erreur'])) { |
|
| 312 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $valeurs['message_ok'] = ''; |
|
| 316 | + if (isset($post["message_ok_$form"])) { |
|
| 317 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 318 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 319 | + $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 323 | + // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 324 | + // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 325 | + if (html5_permis()) { |
|
| 326 | + foreach ($erreurs as $k => $v) { |
|
| 327 | + if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 328 | + // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 329 | + $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $valeurs; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -344,51 +344,51 @@ discard block |
||
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | 346 | function formulaire__charger($form, $args, $poste) { |
| 347 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 348 | - $valeurs = $charger_valeurs(...$args); |
|
| 349 | - } else { |
|
| 350 | - $valeurs = []; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $valeurs = pipeline( |
|
| 354 | - 'formulaire_charger', |
|
| 355 | - [ |
|
| 356 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 357 | - 'data' => $valeurs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - // prise en charge CVT multi etape |
|
| 362 | - if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 363 | - include_spip('inc/cvt_multietapes'); |
|
| 364 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 365 | - ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 366 | - $valeurs |
|
| 367 | - ); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 371 | - if (is_array($valeurs)) { |
|
| 372 | - if (!isset($valeurs['_pipelines'])) { |
|
| 373 | - $valeurs['_pipelines'] = []; |
|
| 374 | - } |
|
| 375 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 376 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 377 | - if (isset($valeurs['_pipeline'])) { |
|
| 378 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 379 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 380 | - |
|
| 381 | - $pipelines = [$pipe => $args]; |
|
| 382 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 386 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 387 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 388 | - $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return $valeurs; |
|
| 347 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 348 | + $valeurs = $charger_valeurs(...$args); |
|
| 349 | + } else { |
|
| 350 | + $valeurs = []; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $valeurs = pipeline( |
|
| 354 | + 'formulaire_charger', |
|
| 355 | + [ |
|
| 356 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 357 | + 'data' => $valeurs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + // prise en charge CVT multi etape |
|
| 362 | + if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 363 | + include_spip('inc/cvt_multietapes'); |
|
| 364 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 365 | + ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 366 | + $valeurs |
|
| 367 | + ); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 371 | + if (is_array($valeurs)) { |
|
| 372 | + if (!isset($valeurs['_pipelines'])) { |
|
| 373 | + $valeurs['_pipelines'] = []; |
|
| 374 | + } |
|
| 375 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 376 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 377 | + if (isset($valeurs['_pipeline'])) { |
|
| 378 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 379 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 380 | + |
|
| 381 | + $pipelines = [$pipe => $args]; |
|
| 382 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 386 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 387 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 388 | + $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return $valeurs; |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -407,9 +407,9 @@ discard block |
||
| 407 | 407 | * @return bool |
| 408 | 408 | */ |
| 409 | 409 | function formulaire__identifier($form, $args, $p) { |
| 410 | - if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 411 | - return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 412 | - } |
|
| 410 | + if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 411 | + return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - return $args === $p; |
|
| 414 | + return $args === $p; |
|
| 415 | 415 | } |
@@ -975,9 +975,9 @@ |
||
| 975 | 975 | if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
| 976 | 976 | define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
| 977 | 977 | } |
| 978 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 978 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml('._TRAITEMENT_RACCOURCIS.')'; |
|
| 979 | 979 | $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
| 980 | - $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 980 | + $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml('._TRAITEMENT_TYPO_SANS_NUMERO.')'; |
|
| 981 | 981 | $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
| 982 | 982 | $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
| 983 | 983 | $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
@@ -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 | |
@@ -34,53 +34,53 @@ discard block |
||
| 34 | 34 | * @package SPIP\Core\Compilateur\AST |
| 35 | 35 | */ |
| 36 | 36 | class Contexte { |
| 37 | - /** |
|
| 38 | - * Description du squelette |
|
| 39 | - * |
|
| 40 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | - * |
|
| 42 | - * Peut contenir les index : |
|
| 43 | - * |
|
| 44 | - * - nom : Nom du fichier de cache |
|
| 45 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | - * - sourcefile : Chemin du squelette |
|
| 47 | - * - squelette : Code du squelette |
|
| 48 | - * - id_mere : Identifiant de la boucle parente |
|
| 49 | - * - documents : Pour embed et img dans les textes |
|
| 50 | - * - session : Pour un cache sessionné par auteur |
|
| 51 | - * - niv : Niveau de tabulation |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $descr = []; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Identifiant de la boucle |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $id_boucle = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Numéro de ligne dans le code source du squelette |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - public $ligne = 0; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Langue d'exécution |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $lang = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Résultat de la compilation: toujours une expression PHP |
|
| 80 | - * |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - public $code = ''; |
|
| 37 | + /** |
|
| 38 | + * Description du squelette |
|
| 39 | + * |
|
| 40 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | + * |
|
| 42 | + * Peut contenir les index : |
|
| 43 | + * |
|
| 44 | + * - nom : Nom du fichier de cache |
|
| 45 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | + * - sourcefile : Chemin du squelette |
|
| 47 | + * - squelette : Code du squelette |
|
| 48 | + * - id_mere : Identifiant de la boucle parente |
|
| 49 | + * - documents : Pour embed et img dans les textes |
|
| 50 | + * - session : Pour un cache sessionné par auteur |
|
| 51 | + * - niv : Niveau de tabulation |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $descr = []; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Identifiant de la boucle |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $id_boucle = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Numéro de ligne dans le code source du squelette |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + public $ligne = 0; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Langue d'exécution |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $lang = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Résultat de la compilation: toujours une expression PHP |
|
| 80 | + * |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + public $code = ''; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -90,44 +90,44 @@ discard block |
||
| 90 | 90 | * @package SPIP\Core\Compilateur\AST |
| 91 | 91 | **/ |
| 92 | 92 | class Texte { |
| 93 | - /** |
|
| 94 | - * Type de noeud |
|
| 95 | - * |
|
| 96 | - * @var string |
|
| 97 | - */ |
|
| 98 | - public $type = 'texte'; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Le texte |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $texte; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Contenu avant le texte. |
|
| 109 | - * |
|
| 110 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | - * |
|
| 112 | - * @var string|array |
|
| 113 | - */ |
|
| 114 | - public $avant = ''; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Contenu après le texte. |
|
| 118 | - * |
|
| 119 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | - * |
|
| 121 | - * @var string|array |
|
| 122 | - */ |
|
| 123 | - public $apres = ''; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Numéro de ligne dans le code source du squelette |
|
| 127 | - * |
|
| 128 | - * @var int |
|
| 129 | - */ |
|
| 130 | - public $ligne = 0; |
|
| 93 | + /** |
|
| 94 | + * Type de noeud |
|
| 95 | + * |
|
| 96 | + * @var string |
|
| 97 | + */ |
|
| 98 | + public $type = 'texte'; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Le texte |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $texte; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Contenu avant le texte. |
|
| 109 | + * |
|
| 110 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | + * |
|
| 112 | + * @var string|array |
|
| 113 | + */ |
|
| 114 | + public $avant = ''; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Contenu après le texte. |
|
| 118 | + * |
|
| 119 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | + * |
|
| 121 | + * @var string|array |
|
| 122 | + */ |
|
| 123 | + public $apres = ''; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Numéro de ligne dans le code source du squelette |
|
| 127 | + * |
|
| 128 | + * @var int |
|
| 129 | + */ |
|
| 130 | + public $ligne = 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,50 +136,50 @@ discard block |
||
| 136 | 136 | * @package SPIP\Core\Compilateur\AST |
| 137 | 137 | **/ |
| 138 | 138 | class Inclure { |
| 139 | - /** |
|
| 140 | - * Type de noeud |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - public $type = 'include'; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Nom d'un fichier inclu |
|
| 148 | - * |
|
| 149 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | - * |
|
| 152 | - * @var string|Texte |
|
| 153 | - */ |
|
| 154 | - public $texte; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Inutilisé, propriété générique de l'AST |
|
| 158 | - * |
|
| 159 | - * @var string|array |
|
| 160 | - */ |
|
| 161 | - public $avant = ''; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Inutilisé, propriété générique de l'AST |
|
| 165 | - * |
|
| 166 | - * @var string|array |
|
| 167 | - */ |
|
| 168 | - public $apres = ''; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Numéro de ligne dans le code source du squelette |
|
| 172 | - * |
|
| 173 | - * @var int |
|
| 174 | - */ |
|
| 175 | - public $ligne = 0; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Valeurs des paramètres |
|
| 179 | - * |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - public $param = []; |
|
| 139 | + /** |
|
| 140 | + * Type de noeud |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + public $type = 'include'; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Nom d'un fichier inclu |
|
| 148 | + * |
|
| 149 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | + * |
|
| 152 | + * @var string|Texte |
|
| 153 | + */ |
|
| 154 | + public $texte; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Inutilisé, propriété générique de l'AST |
|
| 158 | + * |
|
| 159 | + * @var string|array |
|
| 160 | + */ |
|
| 161 | + public $avant = ''; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Inutilisé, propriété générique de l'AST |
|
| 165 | + * |
|
| 166 | + * @var string|array |
|
| 167 | + */ |
|
| 168 | + public $apres = ''; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Numéro de ligne dans le code source du squelette |
|
| 172 | + * |
|
| 173 | + * @var int |
|
| 174 | + */ |
|
| 175 | + public $ligne = 0; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Valeurs des paramètres |
|
| 179 | + * |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + public $param = []; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -189,392 +189,392 @@ discard block |
||
| 189 | 189 | * @package SPIP\Core\Compilateur\AST |
| 190 | 190 | **/ |
| 191 | 191 | class Boucle { |
| 192 | - /** |
|
| 193 | - * Type de noeud |
|
| 194 | - * |
|
| 195 | - * @var string |
|
| 196 | - */ |
|
| 197 | - public $type = 'boucle'; |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Identifiant de la boucle |
|
| 201 | - * |
|
| 202 | - * @var string |
|
| 203 | - */ |
|
| 204 | - public $id_boucle; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Identifiant de la boucle parente |
|
| 208 | - * |
|
| 209 | - * @var string |
|
| 210 | - */ |
|
| 211 | - public $id_parent = ''; |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Partie avant toujours affichee |
|
| 215 | - * |
|
| 216 | - * @var string|array |
|
| 217 | - */ |
|
| 218 | - public $preaff = ''; |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Partie optionnelle avant |
|
| 222 | - * |
|
| 223 | - * @var string|array |
|
| 224 | - */ |
|
| 225 | - public $avant = ''; |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Pour chaque élément |
|
| 229 | - * |
|
| 230 | - * @var string|array |
|
| 231 | - */ |
|
| 232 | - public $milieu = ''; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Partie optionnelle après |
|
| 236 | - * |
|
| 237 | - * @var string|array |
|
| 238 | - */ |
|
| 239 | - public $apres = ''; |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | - * |
|
| 244 | - * @var string|array |
|
| 245 | - */ |
|
| 246 | - public $altern = ''; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Partie apres toujours affichee |
|
| 250 | - * |
|
| 251 | - * @var string|array |
|
| 252 | - */ |
|
| 253 | - public $postaff = ''; |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * La boucle doit-elle sélectionner la langue ? |
|
| 258 | - * |
|
| 259 | - * @var string|null |
|
| 260 | - */ |
|
| 261 | - public $lang_select; |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | - * |
|
| 266 | - * @var string|null |
|
| 267 | - */ |
|
| 268 | - public $type_requete; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * La table est elle optionnelle ? |
|
| 272 | - * |
|
| 273 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | - * |
|
| 275 | - * @var bool |
|
| 276 | - */ |
|
| 277 | - public $table_optionnelle = false; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Nom du fichier de connexion |
|
| 281 | - * |
|
| 282 | - * @var string |
|
| 283 | - */ |
|
| 284 | - public $sql_serveur = ''; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Paramètres de la boucle |
|
| 288 | - * |
|
| 289 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | - * au calcul des critères |
|
| 291 | - * |
|
| 292 | - * @var array |
|
| 293 | - */ |
|
| 294 | - public $param = []; |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Critères de la boucle |
|
| 298 | - * |
|
| 299 | - * @var Critere[] |
|
| 300 | - */ |
|
| 301 | - public $criteres = []; |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | - * |
|
| 306 | - * @var string[] |
|
| 307 | - */ |
|
| 308 | - public $separateur = []; |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Liste des jointures possibles avec cette table |
|
| 312 | - * |
|
| 313 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | - * des jointures déclarées explicitement sur la boucle |
|
| 315 | - * |
|
| 316 | - * @see base_trouver_table_dist() |
|
| 317 | - * @var array |
|
| 318 | - */ |
|
| 319 | - public $jointures = []; |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Jointures explicites avec cette table |
|
| 323 | - * |
|
| 324 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | - * à la boucle. |
|
| 327 | - * |
|
| 328 | - * @var string|bool |
|
| 329 | - */ |
|
| 330 | - public $jointures_explicites = false; |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | - * |
|
| 335 | - * @var string|null |
|
| 336 | - */ |
|
| 337 | - public $doublons; |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | - * |
|
| 342 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | - * |
|
| 344 | - * @var string |
|
| 345 | - */ |
|
| 346 | - public $partie = ''; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | - * ou de soustractions d'éléments à faire |
|
| 351 | - * |
|
| 352 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | - * |
|
| 355 | - * @var string |
|
| 356 | - */ |
|
| 357 | - public $total_parties = ''; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | - * |
|
| 362 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | - * |
|
| 365 | - * @var string |
|
| 366 | - */ |
|
| 367 | - public $mode_partie = ''; |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | - * |
|
| 372 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | - * de l'appelant (rec) |
|
| 376 | - * |
|
| 377 | - * @var string |
|
| 378 | - */ |
|
| 379 | - public $externe = ''; |
|
| 380 | - |
|
| 381 | - // champs pour la construction de la requete SQL |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Liste des champs à récupérer par la boucle |
|
| 385 | - * |
|
| 386 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | - * |
|
| 388 | - * @var string[] |
|
| 389 | - */ |
|
| 390 | - public $select = []; |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | - * |
|
| 395 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | - * |
|
| 398 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | - * |
|
| 400 | - * @var string[] |
|
| 401 | - */ |
|
| 402 | - public $from = []; |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | - * |
|
| 407 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | - * |
|
| 410 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | - * |
|
| 413 | - * @var string[] |
|
| 414 | - */ |
|
| 415 | - public $from_type = []; |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Liste des conditions WHERE de la boucle |
|
| 419 | - * |
|
| 420 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | - * |
|
| 423 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | - * |
|
| 425 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | - * chaque élément ajouté directement au where par |
|
| 427 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | - * est une condition AND en plus. |
|
| 429 | - * |
|
| 430 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | - * $expr = array(operateur, val1, val2) |
|
| 433 | - * |
|
| 434 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | - * à réaliser tel que : |
|
| 436 | - * |
|
| 437 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | - * suivant cet ordre : "val1 operateur val2". |
|
| 440 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | - * Exemples : |
|
| 445 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | - * |
|
| 448 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | - * |
|
| 452 | - * @var array |
|
| 453 | - */ |
|
| 454 | - public $where = []; |
|
| 455 | - |
|
| 456 | - public $join = []; |
|
| 457 | - public $having = []; |
|
| 458 | - public $limit = ''; |
|
| 459 | - public $group = []; |
|
| 460 | - public $order = []; |
|
| 461 | - public $default_order = []; |
|
| 462 | - public $date = 'date'; |
|
| 463 | - public $hash = ''; |
|
| 464 | - public $in = ''; |
|
| 465 | - public $sous_requete = false; |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | - * |
|
| 470 | - * Il sert à insérer le code calculant une hierarchie |
|
| 471 | - * |
|
| 472 | - * @var string |
|
| 473 | - */ |
|
| 474 | - public $hierarchie = ''; |
|
| 475 | - |
|
| 476 | - // champs pour la construction du corps PHP |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Description des sources de données de la boucle |
|
| 480 | - * |
|
| 481 | - * Description des données de la boucle issu de trouver_table |
|
| 482 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | - * |
|
| 484 | - * @see base_trouver_table_dist() |
|
| 485 | - * @var array |
|
| 486 | - */ |
|
| 487 | - public $show = []; |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | - * |
|
| 492 | - * @var string |
|
| 493 | - */ |
|
| 494 | - public $id_table; |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | - * |
|
| 499 | - * @var string |
|
| 500 | - */ |
|
| 501 | - public $primary; |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Code PHP compilé de la boucle |
|
| 505 | - * |
|
| 506 | - * @var string |
|
| 507 | - */ |
|
| 508 | - public $return; |
|
| 509 | - |
|
| 510 | - public $numrows = false; |
|
| 511 | - public $cptrows = false; |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Description du squelette |
|
| 515 | - * |
|
| 516 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | - * |
|
| 518 | - * Peut contenir les index : |
|
| 519 | - * |
|
| 520 | - * - nom : Nom du fichier de cache |
|
| 521 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | - * - sourcefile : Chemin du squelette |
|
| 523 | - * - squelette : Code du squelette |
|
| 524 | - * - id_mere : Identifiant de la boucle parente |
|
| 525 | - * - documents : Pour embed et img dans les textes |
|
| 526 | - * - session : Pour un cache sessionné par auteur |
|
| 527 | - * - niv : Niveau de tabulation |
|
| 528 | - * |
|
| 529 | - * @var array |
|
| 530 | - */ |
|
| 531 | - public $descr = []; |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Numéro de ligne dans le code source du squelette |
|
| 535 | - * |
|
| 536 | - * @var int |
|
| 537 | - */ |
|
| 538 | - public $ligne = 0; |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 543 | - * utilisable par les plugins egalement |
|
| 544 | - * |
|
| 545 | - * @var array<string, mixed> |
|
| 546 | - */ |
|
| 547 | - public $modificateur = []; |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Type d'itérateur utilisé pour cette boucle |
|
| 551 | - * |
|
| 552 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 553 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 554 | - * |
|
| 555 | - * @var string |
|
| 556 | - */ |
|
| 557 | - public $iterateur = ''; // type d'iterateur |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 561 | - */ |
|
| 562 | - public $debug = []; |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 566 | - * notamment si le champ a été trouve dans une boucle parente |
|
| 567 | - * |
|
| 568 | - * Tableau nom du champ => index de boucle |
|
| 569 | - * |
|
| 570 | - * @var array $index_champ |
|
| 571 | - */ |
|
| 572 | - public $index_champ = []; |
|
| 573 | - |
|
| 574 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 575 | - public $tout = false; |
|
| 576 | - public $plat = false; |
|
| 577 | - public $lien = false; |
|
| 192 | + /** |
|
| 193 | + * Type de noeud |
|
| 194 | + * |
|
| 195 | + * @var string |
|
| 196 | + */ |
|
| 197 | + public $type = 'boucle'; |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Identifiant de la boucle |
|
| 201 | + * |
|
| 202 | + * @var string |
|
| 203 | + */ |
|
| 204 | + public $id_boucle; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Identifiant de la boucle parente |
|
| 208 | + * |
|
| 209 | + * @var string |
|
| 210 | + */ |
|
| 211 | + public $id_parent = ''; |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Partie avant toujours affichee |
|
| 215 | + * |
|
| 216 | + * @var string|array |
|
| 217 | + */ |
|
| 218 | + public $preaff = ''; |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Partie optionnelle avant |
|
| 222 | + * |
|
| 223 | + * @var string|array |
|
| 224 | + */ |
|
| 225 | + public $avant = ''; |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Pour chaque élément |
|
| 229 | + * |
|
| 230 | + * @var string|array |
|
| 231 | + */ |
|
| 232 | + public $milieu = ''; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Partie optionnelle après |
|
| 236 | + * |
|
| 237 | + * @var string|array |
|
| 238 | + */ |
|
| 239 | + public $apres = ''; |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | + * |
|
| 244 | + * @var string|array |
|
| 245 | + */ |
|
| 246 | + public $altern = ''; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Partie apres toujours affichee |
|
| 250 | + * |
|
| 251 | + * @var string|array |
|
| 252 | + */ |
|
| 253 | + public $postaff = ''; |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * La boucle doit-elle sélectionner la langue ? |
|
| 258 | + * |
|
| 259 | + * @var string|null |
|
| 260 | + */ |
|
| 261 | + public $lang_select; |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | + * |
|
| 266 | + * @var string|null |
|
| 267 | + */ |
|
| 268 | + public $type_requete; |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * La table est elle optionnelle ? |
|
| 272 | + * |
|
| 273 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | + * |
|
| 275 | + * @var bool |
|
| 276 | + */ |
|
| 277 | + public $table_optionnelle = false; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Nom du fichier de connexion |
|
| 281 | + * |
|
| 282 | + * @var string |
|
| 283 | + */ |
|
| 284 | + public $sql_serveur = ''; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Paramètres de la boucle |
|
| 288 | + * |
|
| 289 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | + * au calcul des critères |
|
| 291 | + * |
|
| 292 | + * @var array |
|
| 293 | + */ |
|
| 294 | + public $param = []; |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Critères de la boucle |
|
| 298 | + * |
|
| 299 | + * @var Critere[] |
|
| 300 | + */ |
|
| 301 | + public $criteres = []; |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | + * |
|
| 306 | + * @var string[] |
|
| 307 | + */ |
|
| 308 | + public $separateur = []; |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Liste des jointures possibles avec cette table |
|
| 312 | + * |
|
| 313 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | + * des jointures déclarées explicitement sur la boucle |
|
| 315 | + * |
|
| 316 | + * @see base_trouver_table_dist() |
|
| 317 | + * @var array |
|
| 318 | + */ |
|
| 319 | + public $jointures = []; |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Jointures explicites avec cette table |
|
| 323 | + * |
|
| 324 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | + * à la boucle. |
|
| 327 | + * |
|
| 328 | + * @var string|bool |
|
| 329 | + */ |
|
| 330 | + public $jointures_explicites = false; |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | + * |
|
| 335 | + * @var string|null |
|
| 336 | + */ |
|
| 337 | + public $doublons; |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | + * |
|
| 342 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | + * |
|
| 344 | + * @var string |
|
| 345 | + */ |
|
| 346 | + public $partie = ''; |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | + * ou de soustractions d'éléments à faire |
|
| 351 | + * |
|
| 352 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | + * |
|
| 355 | + * @var string |
|
| 356 | + */ |
|
| 357 | + public $total_parties = ''; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | + * |
|
| 362 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | + * |
|
| 365 | + * @var string |
|
| 366 | + */ |
|
| 367 | + public $mode_partie = ''; |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | + * |
|
| 372 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | + * de l'appelant (rec) |
|
| 376 | + * |
|
| 377 | + * @var string |
|
| 378 | + */ |
|
| 379 | + public $externe = ''; |
|
| 380 | + |
|
| 381 | + // champs pour la construction de la requete SQL |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Liste des champs à récupérer par la boucle |
|
| 385 | + * |
|
| 386 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | + * |
|
| 388 | + * @var string[] |
|
| 389 | + */ |
|
| 390 | + public $select = []; |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | + * |
|
| 395 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | + * |
|
| 398 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | + * |
|
| 400 | + * @var string[] |
|
| 401 | + */ |
|
| 402 | + public $from = []; |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | + * |
|
| 407 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | + * |
|
| 410 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | + * |
|
| 413 | + * @var string[] |
|
| 414 | + */ |
|
| 415 | + public $from_type = []; |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Liste des conditions WHERE de la boucle |
|
| 419 | + * |
|
| 420 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | + * |
|
| 423 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | + * |
|
| 425 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | + * chaque élément ajouté directement au where par |
|
| 427 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | + * est une condition AND en plus. |
|
| 429 | + * |
|
| 430 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | + * $expr = array(operateur, val1, val2) |
|
| 433 | + * |
|
| 434 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | + * à réaliser tel que : |
|
| 436 | + * |
|
| 437 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | + * suivant cet ordre : "val1 operateur val2". |
|
| 440 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | + * Exemples : |
|
| 445 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | + * |
|
| 448 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | + * |
|
| 452 | + * @var array |
|
| 453 | + */ |
|
| 454 | + public $where = []; |
|
| 455 | + |
|
| 456 | + public $join = []; |
|
| 457 | + public $having = []; |
|
| 458 | + public $limit = ''; |
|
| 459 | + public $group = []; |
|
| 460 | + public $order = []; |
|
| 461 | + public $default_order = []; |
|
| 462 | + public $date = 'date'; |
|
| 463 | + public $hash = ''; |
|
| 464 | + public $in = ''; |
|
| 465 | + public $sous_requete = false; |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | + * |
|
| 470 | + * Il sert à insérer le code calculant une hierarchie |
|
| 471 | + * |
|
| 472 | + * @var string |
|
| 473 | + */ |
|
| 474 | + public $hierarchie = ''; |
|
| 475 | + |
|
| 476 | + // champs pour la construction du corps PHP |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Description des sources de données de la boucle |
|
| 480 | + * |
|
| 481 | + * Description des données de la boucle issu de trouver_table |
|
| 482 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | + * |
|
| 484 | + * @see base_trouver_table_dist() |
|
| 485 | + * @var array |
|
| 486 | + */ |
|
| 487 | + public $show = []; |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | + * |
|
| 492 | + * @var string |
|
| 493 | + */ |
|
| 494 | + public $id_table; |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | + * |
|
| 499 | + * @var string |
|
| 500 | + */ |
|
| 501 | + public $primary; |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Code PHP compilé de la boucle |
|
| 505 | + * |
|
| 506 | + * @var string |
|
| 507 | + */ |
|
| 508 | + public $return; |
|
| 509 | + |
|
| 510 | + public $numrows = false; |
|
| 511 | + public $cptrows = false; |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Description du squelette |
|
| 515 | + * |
|
| 516 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | + * |
|
| 518 | + * Peut contenir les index : |
|
| 519 | + * |
|
| 520 | + * - nom : Nom du fichier de cache |
|
| 521 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | + * - sourcefile : Chemin du squelette |
|
| 523 | + * - squelette : Code du squelette |
|
| 524 | + * - id_mere : Identifiant de la boucle parente |
|
| 525 | + * - documents : Pour embed et img dans les textes |
|
| 526 | + * - session : Pour un cache sessionné par auteur |
|
| 527 | + * - niv : Niveau de tabulation |
|
| 528 | + * |
|
| 529 | + * @var array |
|
| 530 | + */ |
|
| 531 | + public $descr = []; |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Numéro de ligne dans le code source du squelette |
|
| 535 | + * |
|
| 536 | + * @var int |
|
| 537 | + */ |
|
| 538 | + public $ligne = 0; |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 543 | + * utilisable par les plugins egalement |
|
| 544 | + * |
|
| 545 | + * @var array<string, mixed> |
|
| 546 | + */ |
|
| 547 | + public $modificateur = []; |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Type d'itérateur utilisé pour cette boucle |
|
| 551 | + * |
|
| 552 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 553 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 554 | + * |
|
| 555 | + * @var string |
|
| 556 | + */ |
|
| 557 | + public $iterateur = ''; // type d'iterateur |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 561 | + */ |
|
| 562 | + public $debug = []; |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 566 | + * notamment si le champ a été trouve dans une boucle parente |
|
| 567 | + * |
|
| 568 | + * Tableau nom du champ => index de boucle |
|
| 569 | + * |
|
| 570 | + * @var array $index_champ |
|
| 571 | + */ |
|
| 572 | + public $index_champ = []; |
|
| 573 | + |
|
| 574 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 575 | + public $tout = false; |
|
| 576 | + public $plat = false; |
|
| 577 | + public $lien = false; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -585,56 +585,56 @@ discard block |
||
| 585 | 585 | * @package SPIP\Core\Compilateur\AST |
| 586 | 586 | **/ |
| 587 | 587 | class Critere { |
| 588 | - /** |
|
| 589 | - * Type de noeud |
|
| 590 | - * |
|
| 591 | - * @var string |
|
| 592 | - */ |
|
| 593 | - public $type = 'critere'; |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Opérateur (>, <, >=, IN, ...) |
|
| 597 | - * |
|
| 598 | - * @var null|string |
|
| 599 | - */ |
|
| 600 | - public $op; |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Présence d'une négation (truc !op valeur) |
|
| 604 | - * |
|
| 605 | - * @var null|string |
|
| 606 | - */ |
|
| 607 | - public $not; |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Présence d'une exclusion (!truc op valeur) |
|
| 611 | - * |
|
| 612 | - * @var null|string |
|
| 613 | - */ |
|
| 614 | - public $exclus; |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Présence d'une condition dans le critère (truc ?) |
|
| 618 | - * |
|
| 619 | - * @var bool |
|
| 620 | - */ |
|
| 621 | - public $cond = false; |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Paramètres du critère |
|
| 625 | - * - $param[0] : élément avant l'opérateur |
|
| 626 | - * - $param[1..n] : éléments après l'opérateur |
|
| 627 | - * |
|
| 628 | - * @var array |
|
| 629 | - */ |
|
| 630 | - public $param = []; |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Numéro de ligne dans le code source du squelette |
|
| 634 | - * |
|
| 635 | - * @var int |
|
| 636 | - */ |
|
| 637 | - public $ligne = 0; |
|
| 588 | + /** |
|
| 589 | + * Type de noeud |
|
| 590 | + * |
|
| 591 | + * @var string |
|
| 592 | + */ |
|
| 593 | + public $type = 'critere'; |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Opérateur (>, <, >=, IN, ...) |
|
| 597 | + * |
|
| 598 | + * @var null|string |
|
| 599 | + */ |
|
| 600 | + public $op; |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Présence d'une négation (truc !op valeur) |
|
| 604 | + * |
|
| 605 | + * @var null|string |
|
| 606 | + */ |
|
| 607 | + public $not; |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Présence d'une exclusion (!truc op valeur) |
|
| 611 | + * |
|
| 612 | + * @var null|string |
|
| 613 | + */ |
|
| 614 | + public $exclus; |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Présence d'une condition dans le critère (truc ?) |
|
| 618 | + * |
|
| 619 | + * @var bool |
|
| 620 | + */ |
|
| 621 | + public $cond = false; |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Paramètres du critère |
|
| 625 | + * - $param[0] : élément avant l'opérateur |
|
| 626 | + * - $param[1..n] : éléments après l'opérateur |
|
| 627 | + * |
|
| 628 | + * @var array |
|
| 629 | + */ |
|
| 630 | + public $param = []; |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Numéro de ligne dans le code source du squelette |
|
| 634 | + * |
|
| 635 | + * @var int |
|
| 636 | + */ |
|
| 637 | + public $ligne = 0; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -643,139 +643,139 @@ discard block |
||
| 643 | 643 | * @package SPIP\Core\Compilateur\AST |
| 644 | 644 | **/ |
| 645 | 645 | class Champ { |
| 646 | - /** |
|
| 647 | - * Type de noeud |
|
| 648 | - * |
|
| 649 | - * @var string |
|
| 650 | - */ |
|
| 651 | - public $type = 'champ'; |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 655 | - * |
|
| 656 | - * @var string|null |
|
| 657 | - */ |
|
| 658 | - public $nom_champ; |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Identifiant de la boucle parente si explicité |
|
| 662 | - * |
|
| 663 | - * @var string|null |
|
| 664 | - */ |
|
| 665 | - public $nom_boucle = ''; |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Partie optionnelle avant |
|
| 669 | - * |
|
| 670 | - * @var null|string|array |
|
| 671 | - */ |
|
| 672 | - public $avant; |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Partie optionnelle après |
|
| 676 | - * |
|
| 677 | - * @var null|string|array |
|
| 678 | - */ |
|
| 679 | - public $apres; |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Étoiles : annuler des automatismes |
|
| 683 | - * |
|
| 684 | - * - '*' annule les filtres automatiques |
|
| 685 | - * - '**' annule en plus les protections de scripts |
|
| 686 | - * |
|
| 687 | - * @var null|string |
|
| 688 | - */ |
|
| 689 | - public $etoile; |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Arguments et filtres explicites sur la balise |
|
| 693 | - * |
|
| 694 | - * - $param[0] contient les arguments de la balise |
|
| 695 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 696 | - * |
|
| 697 | - * @var array |
|
| 698 | - */ |
|
| 699 | - public $param = []; |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Source des filtres (compatibilité) (?) |
|
| 703 | - * |
|
| 704 | - * @var array|null |
|
| 705 | - */ |
|
| 706 | - public $fonctions = []; |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Identifiant de la boucle |
|
| 710 | - * |
|
| 711 | - * @var string |
|
| 712 | - */ |
|
| 713 | - public $id_boucle = ''; |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * AST du squelette, liste de toutes les boucles |
|
| 717 | - * |
|
| 718 | - * @var Boucles[] |
|
| 719 | - */ |
|
| 720 | - public $boucles; |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 724 | - * |
|
| 725 | - * @var string|null |
|
| 726 | - */ |
|
| 727 | - public $type_requete; |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Résultat de la compilation: toujours une expression PHP |
|
| 731 | - * |
|
| 732 | - * @var string |
|
| 733 | - */ |
|
| 734 | - public $code = ''; |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Interdire les scripts |
|
| 738 | - * |
|
| 739 | - * false si on est sûr de cette balise |
|
| 740 | - * |
|
| 741 | - * @see interdire_scripts() |
|
| 742 | - * @var bool |
|
| 743 | - */ |
|
| 744 | - public $interdire_scripts = true; |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Description du squelette |
|
| 748 | - * |
|
| 749 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 750 | - * |
|
| 751 | - * Peut contenir les index : |
|
| 752 | - * |
|
| 753 | - * - nom : Nom du fichier de cache |
|
| 754 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 755 | - * - sourcefile : Chemin du squelette |
|
| 756 | - * - squelette : Code du squelette |
|
| 757 | - * - id_mere : Identifiant de la boucle parente |
|
| 758 | - * - documents : Pour embed et img dans les textes |
|
| 759 | - * - session : Pour un cache sessionné par auteur |
|
| 760 | - * - niv : Niveau de tabulation |
|
| 761 | - * |
|
| 762 | - * @var array |
|
| 763 | - */ |
|
| 764 | - public $descr = []; |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * Numéro de ligne dans le code source du squelette |
|
| 768 | - * |
|
| 769 | - * @var int |
|
| 770 | - */ |
|
| 771 | - public $ligne = 0; |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 775 | - * |
|
| 776 | - * @var bool |
|
| 777 | - */ |
|
| 778 | - public $balise_calculee = false; |
|
| 646 | + /** |
|
| 647 | + * Type de noeud |
|
| 648 | + * |
|
| 649 | + * @var string |
|
| 650 | + */ |
|
| 651 | + public $type = 'champ'; |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 655 | + * |
|
| 656 | + * @var string|null |
|
| 657 | + */ |
|
| 658 | + public $nom_champ; |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Identifiant de la boucle parente si explicité |
|
| 662 | + * |
|
| 663 | + * @var string|null |
|
| 664 | + */ |
|
| 665 | + public $nom_boucle = ''; |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Partie optionnelle avant |
|
| 669 | + * |
|
| 670 | + * @var null|string|array |
|
| 671 | + */ |
|
| 672 | + public $avant; |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Partie optionnelle après |
|
| 676 | + * |
|
| 677 | + * @var null|string|array |
|
| 678 | + */ |
|
| 679 | + public $apres; |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Étoiles : annuler des automatismes |
|
| 683 | + * |
|
| 684 | + * - '*' annule les filtres automatiques |
|
| 685 | + * - '**' annule en plus les protections de scripts |
|
| 686 | + * |
|
| 687 | + * @var null|string |
|
| 688 | + */ |
|
| 689 | + public $etoile; |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Arguments et filtres explicites sur la balise |
|
| 693 | + * |
|
| 694 | + * - $param[0] contient les arguments de la balise |
|
| 695 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 696 | + * |
|
| 697 | + * @var array |
|
| 698 | + */ |
|
| 699 | + public $param = []; |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Source des filtres (compatibilité) (?) |
|
| 703 | + * |
|
| 704 | + * @var array|null |
|
| 705 | + */ |
|
| 706 | + public $fonctions = []; |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Identifiant de la boucle |
|
| 710 | + * |
|
| 711 | + * @var string |
|
| 712 | + */ |
|
| 713 | + public $id_boucle = ''; |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * AST du squelette, liste de toutes les boucles |
|
| 717 | + * |
|
| 718 | + * @var Boucles[] |
|
| 719 | + */ |
|
| 720 | + public $boucles; |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 724 | + * |
|
| 725 | + * @var string|null |
|
| 726 | + */ |
|
| 727 | + public $type_requete; |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Résultat de la compilation: toujours une expression PHP |
|
| 731 | + * |
|
| 732 | + * @var string |
|
| 733 | + */ |
|
| 734 | + public $code = ''; |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Interdire les scripts |
|
| 738 | + * |
|
| 739 | + * false si on est sûr de cette balise |
|
| 740 | + * |
|
| 741 | + * @see interdire_scripts() |
|
| 742 | + * @var bool |
|
| 743 | + */ |
|
| 744 | + public $interdire_scripts = true; |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Description du squelette |
|
| 748 | + * |
|
| 749 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 750 | + * |
|
| 751 | + * Peut contenir les index : |
|
| 752 | + * |
|
| 753 | + * - nom : Nom du fichier de cache |
|
| 754 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 755 | + * - sourcefile : Chemin du squelette |
|
| 756 | + * - squelette : Code du squelette |
|
| 757 | + * - id_mere : Identifiant de la boucle parente |
|
| 758 | + * - documents : Pour embed et img dans les textes |
|
| 759 | + * - session : Pour un cache sessionné par auteur |
|
| 760 | + * - niv : Niveau de tabulation |
|
| 761 | + * |
|
| 762 | + * @var array |
|
| 763 | + */ |
|
| 764 | + public $descr = []; |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * Numéro de ligne dans le code source du squelette |
|
| 768 | + * |
|
| 769 | + * @var int |
|
| 770 | + */ |
|
| 771 | + public $ligne = 0; |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 775 | + * |
|
| 776 | + * @var bool |
|
| 777 | + */ |
|
| 778 | + public $balise_calculee = false; |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
@@ -783,123 +783,123 @@ discard block |
||
| 783 | 783 | * Description d'une chaîne de langue |
| 784 | 784 | **/ |
| 785 | 785 | class Idiome { |
| 786 | - /** |
|
| 787 | - * Type de noeud |
|
| 788 | - * |
|
| 789 | - * @var string |
|
| 790 | - */ |
|
| 791 | - public $type = 'idiome'; |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Clé de traduction demandée. Exemple 'item_oui' |
|
| 795 | - * |
|
| 796 | - * @var string |
|
| 797 | - */ |
|
| 798 | - public $nom_champ = ''; |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 802 | - * |
|
| 803 | - * @var string |
|
| 804 | - */ |
|
| 805 | - public $module = ''; |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Arguments à passer à la chaîne |
|
| 809 | - * |
|
| 810 | - * @var array |
|
| 811 | - */ |
|
| 812 | - public $arg = []; |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Filtres à appliquer au résultat |
|
| 816 | - * |
|
| 817 | - * @var array |
|
| 818 | - */ |
|
| 819 | - public $param = []; |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Source des filtres (compatibilité) (?) |
|
| 823 | - * |
|
| 824 | - * @var array|null |
|
| 825 | - */ |
|
| 826 | - public $fonctions = []; |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Inutilisé, propriété générique de l'AST |
|
| 830 | - * |
|
| 831 | - * @var string|array |
|
| 832 | - */ |
|
| 833 | - public $avant = ''; |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Inutilisé, propriété générique de l'AST |
|
| 837 | - * |
|
| 838 | - * @var string|array |
|
| 839 | - */ |
|
| 840 | - public $apres = ''; |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * Identifiant de la boucle |
|
| 844 | - * |
|
| 845 | - * @var string |
|
| 846 | - */ |
|
| 847 | - public $id_boucle = ''; |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * AST du squelette, liste de toutes les boucles |
|
| 851 | - * |
|
| 852 | - * @var Boucles[] |
|
| 853 | - */ |
|
| 854 | - public $boucles; |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 858 | - * |
|
| 859 | - * @var string|null |
|
| 860 | - */ |
|
| 861 | - public $type_requete; |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Résultat de la compilation: toujours une expression PHP |
|
| 865 | - * |
|
| 866 | - * @var string |
|
| 867 | - */ |
|
| 868 | - public $code = ''; |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Interdire les scripts |
|
| 872 | - * |
|
| 873 | - * @see interdire_scripts() |
|
| 874 | - * @var bool |
|
| 875 | - */ |
|
| 876 | - public $interdire_scripts = false; |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * Description du squelette |
|
| 880 | - * |
|
| 881 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 882 | - * |
|
| 883 | - * Peut contenir les index : |
|
| 884 | - * - nom : Nom du fichier de cache |
|
| 885 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 886 | - * - sourcefile : Chemin du squelette |
|
| 887 | - * - squelette : Code du squelette |
|
| 888 | - * - id_mere : Identifiant de la boucle parente |
|
| 889 | - * - documents : Pour embed et img dans les textes |
|
| 890 | - * - session : Pour un cache sessionné par auteur |
|
| 891 | - * - niv : Niveau de tabulation |
|
| 892 | - * |
|
| 893 | - * @var array |
|
| 894 | - */ |
|
| 895 | - public $descr = []; |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Numéro de ligne dans le code source du squelette |
|
| 899 | - * |
|
| 900 | - * @var int |
|
| 901 | - */ |
|
| 902 | - public $ligne = 0; |
|
| 786 | + /** |
|
| 787 | + * Type de noeud |
|
| 788 | + * |
|
| 789 | + * @var string |
|
| 790 | + */ |
|
| 791 | + public $type = 'idiome'; |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Clé de traduction demandée. Exemple 'item_oui' |
|
| 795 | + * |
|
| 796 | + * @var string |
|
| 797 | + */ |
|
| 798 | + public $nom_champ = ''; |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 802 | + * |
|
| 803 | + * @var string |
|
| 804 | + */ |
|
| 805 | + public $module = ''; |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Arguments à passer à la chaîne |
|
| 809 | + * |
|
| 810 | + * @var array |
|
| 811 | + */ |
|
| 812 | + public $arg = []; |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Filtres à appliquer au résultat |
|
| 816 | + * |
|
| 817 | + * @var array |
|
| 818 | + */ |
|
| 819 | + public $param = []; |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Source des filtres (compatibilité) (?) |
|
| 823 | + * |
|
| 824 | + * @var array|null |
|
| 825 | + */ |
|
| 826 | + public $fonctions = []; |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Inutilisé, propriété générique de l'AST |
|
| 830 | + * |
|
| 831 | + * @var string|array |
|
| 832 | + */ |
|
| 833 | + public $avant = ''; |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Inutilisé, propriété générique de l'AST |
|
| 837 | + * |
|
| 838 | + * @var string|array |
|
| 839 | + */ |
|
| 840 | + public $apres = ''; |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * Identifiant de la boucle |
|
| 844 | + * |
|
| 845 | + * @var string |
|
| 846 | + */ |
|
| 847 | + public $id_boucle = ''; |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * AST du squelette, liste de toutes les boucles |
|
| 851 | + * |
|
| 852 | + * @var Boucles[] |
|
| 853 | + */ |
|
| 854 | + public $boucles; |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 858 | + * |
|
| 859 | + * @var string|null |
|
| 860 | + */ |
|
| 861 | + public $type_requete; |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Résultat de la compilation: toujours une expression PHP |
|
| 865 | + * |
|
| 866 | + * @var string |
|
| 867 | + */ |
|
| 868 | + public $code = ''; |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Interdire les scripts |
|
| 872 | + * |
|
| 873 | + * @see interdire_scripts() |
|
| 874 | + * @var bool |
|
| 875 | + */ |
|
| 876 | + public $interdire_scripts = false; |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * Description du squelette |
|
| 880 | + * |
|
| 881 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 882 | + * |
|
| 883 | + * Peut contenir les index : |
|
| 884 | + * - nom : Nom du fichier de cache |
|
| 885 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 886 | + * - sourcefile : Chemin du squelette |
|
| 887 | + * - squelette : Code du squelette |
|
| 888 | + * - id_mere : Identifiant de la boucle parente |
|
| 889 | + * - documents : Pour embed et img dans les textes |
|
| 890 | + * - session : Pour un cache sessionné par auteur |
|
| 891 | + * - niv : Niveau de tabulation |
|
| 892 | + * |
|
| 893 | + * @var array |
|
| 894 | + */ |
|
| 895 | + public $descr = []; |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Numéro de ligne dans le code source du squelette |
|
| 899 | + * |
|
| 900 | + * @var int |
|
| 901 | + */ |
|
| 902 | + public $ligne = 0; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -908,28 +908,28 @@ discard block |
||
| 908 | 908 | * @package SPIP\Core\Compilateur\AST |
| 909 | 909 | **/ |
| 910 | 910 | class Polyglotte { |
| 911 | - /** |
|
| 912 | - * Type de noeud |
|
| 913 | - * |
|
| 914 | - * @var string |
|
| 915 | - */ |
|
| 916 | - public $type = 'polyglotte'; |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * Tableau des traductions possibles classées par langue |
|
| 920 | - * |
|
| 921 | - * Tableau code de langue => texte |
|
| 922 | - * |
|
| 923 | - * @var array |
|
| 924 | - */ |
|
| 925 | - public $traductions = []; |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Numéro de ligne dans le code source du squelette |
|
| 929 | - * |
|
| 930 | - * @var int |
|
| 931 | - */ |
|
| 932 | - public $ligne = 0; |
|
| 911 | + /** |
|
| 912 | + * Type de noeud |
|
| 913 | + * |
|
| 914 | + * @var string |
|
| 915 | + */ |
|
| 916 | + public $type = 'polyglotte'; |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * Tableau des traductions possibles classées par langue |
|
| 920 | + * |
|
| 921 | + * Tableau code de langue => texte |
|
| 922 | + * |
|
| 923 | + * @var array |
|
| 924 | + */ |
|
| 925 | + public $traductions = []; |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Numéro de ligne dans le code source du squelette |
|
| 929 | + * |
|
| 930 | + * @var int |
|
| 931 | + */ |
|
| 932 | + public $ligne = 0; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | |
@@ -952,90 +952,90 @@ discard block |
||
| 952 | 952 | */ |
| 953 | 953 | function declarer_interfaces() { |
| 954 | 954 | |
| 955 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 956 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 957 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 958 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 959 | - |
|
| 960 | - // definition des statuts de publication |
|
| 961 | - $GLOBALS['table_statut'] = []; |
|
| 962 | - |
|
| 963 | - // |
|
| 964 | - // tableau des tables de jointures |
|
| 965 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 966 | - $GLOBALS['tables_jointures'] = []; |
|
| 967 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 968 | - |
|
| 969 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 970 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - if (!defined('_TRAITEMENT_TYPO')) { |
|
| 974 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 975 | - } |
|
| 976 | - if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 977 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 978 | - } |
|
| 979 | - if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 980 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 981 | - } |
|
| 982 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 983 | - $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 984 | - $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 985 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 986 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 987 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 988 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 989 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 990 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 991 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 993 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 994 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 995 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 996 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 997 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 998 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 999 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 1000 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1001 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 1002 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 1003 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1004 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1005 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1006 | - |
|
| 1007 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 1008 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1009 | - // toujours securiser les DATA |
|
| 1010 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1011 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1012 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1016 | - $interfaces = pipeline( |
|
| 1017 | - 'declarer_tables_interfaces', |
|
| 1018 | - [ |
|
| 1019 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1020 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1021 | - 'table_date' => $GLOBALS['table_date'], |
|
| 1022 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 1023 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1024 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1025 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1026 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 1027 | - ] |
|
| 1028 | - ); |
|
| 1029 | - if ($interfaces) { |
|
| 1030 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1031 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1032 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1033 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1034 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1035 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1036 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1037 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1038 | - } |
|
| 955 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 956 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 957 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 958 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 959 | + |
|
| 960 | + // definition des statuts de publication |
|
| 961 | + $GLOBALS['table_statut'] = []; |
|
| 962 | + |
|
| 963 | + // |
|
| 964 | + // tableau des tables de jointures |
|
| 965 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 966 | + $GLOBALS['tables_jointures'] = []; |
|
| 967 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 968 | + |
|
| 969 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 970 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + if (!defined('_TRAITEMENT_TYPO')) { |
|
| 974 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 975 | + } |
|
| 976 | + if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 977 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 978 | + } |
|
| 979 | + if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 980 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 981 | + } |
|
| 982 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 983 | + $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 984 | + $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 985 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 986 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 987 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 988 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 989 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 990 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 991 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 993 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 994 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 995 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 996 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 997 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 998 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 999 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 1000 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1001 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 1002 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 1003 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1004 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1005 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1006 | + |
|
| 1007 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 1008 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1009 | + // toujours securiser les DATA |
|
| 1010 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1011 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1012 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1016 | + $interfaces = pipeline( |
|
| 1017 | + 'declarer_tables_interfaces', |
|
| 1018 | + [ |
|
| 1019 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1020 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1021 | + 'table_date' => $GLOBALS['table_date'], |
|
| 1022 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 1023 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1024 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1025 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1026 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 1027 | + ] |
|
| 1028 | + ); |
|
| 1029 | + if ($interfaces) { |
|
| 1030 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1031 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1032 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1033 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1034 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1035 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1036 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1037 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1038 | + } |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | declarer_interfaces(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | // Si l'article est publie, invalider les caches et demander sa reindexation |
| 109 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id_article)); |
|
| 110 | 110 | $invalideur = $indexation = false; |
| 111 | 111 | if ($t == 'publie') { |
| 112 | 112 | $invalideur = "id='article/$id_article'"; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $id_article, |
| 120 | 120 | [ |
| 121 | 121 | 'data' => $set, |
| 122 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | + 'nonvide' => ['titre' => _T('info_nouvel_article').' '._T('info_numero_abbreviation').$id_article], |
|
| 123 | 123 | 'invalideur' => $invalideur, |
| 124 | 124 | 'indexation' => $indexation, |
| 125 | 125 | 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
| 310 | 310 | $statut = $champs['statut'] = $s; |
| 311 | 311 | } else { |
| 312 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | + spip_log("editer_article $id_article refus ".join(' ', $c)); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // En cas de publication, fixer la date a "maintenant" |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | isset($c['id_parent']) |
| 335 | 335 | and $id_parent = $c['id_parent'] |
| 336 | 336 | and $id_parent != $id_rubrique |
| 337 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.intval($id_parent))) |
|
| 338 | 338 | ) { |
| 339 | 339 | $champs['id_rubrique'] = $id_parent; |
| 340 | 340 | |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | // Si on deplace l'article |
| 436 | 436 | // changer aussi son secteur et sa langue (si heritee) |
| 437 | 437 | if (isset($champs['id_rubrique'])) { |
| 438 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 439 | 439 | |
| 440 | 440 | $langue = $row_rub['lang']; |
| 441 | 441 | $champs['id_secteur'] = $row_rub['id_secteur']; |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | sql_fetsel( |
| 444 | 444 | '1', |
| 445 | 445 | 'spip_articles', |
| 446 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | + 'id_article='.intval($id_article)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 447 | 447 | ) |
| 448 | 448 | ) { |
| 449 | 449 | $champs['lang'] = $langue; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | return; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | + sql_updateq('spip_articles', $champs, 'id_article='.intval($id_article)); |
|
| 458 | 458 | |
| 459 | 459 | // Changer le statut des rubriques concernees |
| 460 | 460 | |
@@ -475,6 +475,6 @@ discard block |
||
| 475 | 475 | foreach ($plus as $n => $t) { |
| 476 | 476 | $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
| 477 | 477 | } |
| 478 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | + set_request('texte', join('', $plus)._request('texte')); |
|
| 479 | 479 | } |
| 480 | 480 | } |
@@ -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 | /** |
@@ -39,36 +39,36 @@ discard block |
||
| 39 | 39 | * Liste (identifiant de l'article, Texte d'erreur éventuel) |
| 40 | 40 | */ |
| 41 | 41 | function action_editer_article_dist($arg = null) { |
| 42 | - include_spip('inc/autoriser'); |
|
| 43 | - $err = ''; |
|
| 44 | - if (is_null($arg)) { |
|
| 45 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | - $arg = $securiser_action(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 50 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | - if (!$id_article = intval($arg)) { |
|
| 52 | - $id_parent = _request('id_parent'); |
|
| 53 | - if (!$id_parent) { |
|
| 54 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | - } else { |
|
| 58 | - $id_article = article_inserer($id_parent); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - if ($id_article > 0) { |
|
| 64 | - $err = article_modifier($id_article); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if ($err) { |
|
| 68 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return [$id_article, $err]; |
|
| 42 | + include_spip('inc/autoriser'); |
|
| 43 | + $err = ''; |
|
| 44 | + if (is_null($arg)) { |
|
| 45 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $arg = $securiser_action(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 50 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 51 | + if (!$id_article = intval($arg)) { |
|
| 52 | + $id_parent = _request('id_parent'); |
|
| 53 | + if (!$id_parent) { |
|
| 54 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 55 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 56 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 57 | + } else { |
|
| 58 | + $id_article = article_inserer($id_parent); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + if ($id_article > 0) { |
|
| 64 | + $err = article_modifier($id_article); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if ($err) { |
|
| 68 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return [$id_article, $err]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -90,50 +90,50 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | function article_modifier($id_article, $set = null) { |
| 92 | 92 | |
| 93 | - // unifier $texte en cas de texte trop long |
|
| 94 | - trop_longs_articles(); |
|
| 95 | - |
|
| 96 | - include_spip('inc/modifier'); |
|
| 97 | - include_spip('inc/filtres'); |
|
| 98 | - $c = collecter_requests( |
|
| 99 | - // include list |
|
| 100 | - objet_info('article', 'champs_editables'), |
|
| 101 | - // exclude list |
|
| 102 | - ['date', 'statut', 'id_parent'], |
|
| 103 | - // donnees eventuellement fournies |
|
| 104 | - $set |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | - $invalideur = $indexation = false; |
|
| 110 | - if ($t == 'publie') { |
|
| 111 | - $invalideur = "id='article/$id_article'"; |
|
| 112 | - $indexation = true; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( |
|
| 116 | - $err = objet_modifier_champs( |
|
| 117 | - 'article', |
|
| 118 | - $id_article, |
|
| 119 | - [ |
|
| 120 | - 'data' => $set, |
|
| 121 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | - 'invalideur' => $invalideur, |
|
| 123 | - 'indexation' => $indexation, |
|
| 124 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | - ], |
|
| 126 | - $c |
|
| 127 | - ) |
|
| 128 | - ) { |
|
| 129 | - return $err; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Modification de statut, changement de rubrique ? |
|
| 133 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | - $err = article_instituer($id_article, $c); |
|
| 135 | - |
|
| 136 | - return $err; |
|
| 93 | + // unifier $texte en cas de texte trop long |
|
| 94 | + trop_longs_articles(); |
|
| 95 | + |
|
| 96 | + include_spip('inc/modifier'); |
|
| 97 | + include_spip('inc/filtres'); |
|
| 98 | + $c = collecter_requests( |
|
| 99 | + // include list |
|
| 100 | + objet_info('article', 'champs_editables'), |
|
| 101 | + // exclude list |
|
| 102 | + ['date', 'statut', 'id_parent'], |
|
| 103 | + // donnees eventuellement fournies |
|
| 104 | + $set |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 108 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | + $invalideur = $indexation = false; |
|
| 110 | + if ($t == 'publie') { |
|
| 111 | + $invalideur = "id='article/$id_article'"; |
|
| 112 | + $indexation = true; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( |
|
| 116 | + $err = objet_modifier_champs( |
|
| 117 | + 'article', |
|
| 118 | + $id_article, |
|
| 119 | + [ |
|
| 120 | + 'data' => $set, |
|
| 121 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | + 'invalideur' => $invalideur, |
|
| 123 | + 'indexation' => $indexation, |
|
| 124 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 125 | + ], |
|
| 126 | + $c |
|
| 127 | + ) |
|
| 128 | + ) { |
|
| 129 | + return $err; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Modification de statut, changement de rubrique ? |
|
| 133 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 134 | + $err = article_instituer($id_article, $c); |
|
| 135 | + |
|
| 136 | + return $err; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -169,98 +169,98 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function article_inserer($id_rubrique, $set = null) { |
| 171 | 171 | |
| 172 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | - // dans la premiere rubrique racine |
|
| 174 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | - $id_rubrique = $row['id_rubrique']; |
|
| 177 | - } else { |
|
| 178 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | - $lang_rub = $row['lang'] ?? ''; |
|
| 185 | - |
|
| 186 | - $lang = ''; |
|
| 187 | - $choisie = 'non'; |
|
| 188 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | - // ou a defaut celle de la rubrique |
|
| 191 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | - if ( |
|
| 193 | - !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | - 'spip_articles', |
|
| 195 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | - if ( |
|
| 200 | - in_array( |
|
| 201 | - $GLOBALS['spip_lang'], |
|
| 202 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | - ) |
|
| 204 | - ) { |
|
| 205 | - $lang = $GLOBALS['spip_lang']; |
|
| 206 | - $choisie = 'oui'; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!$lang) { |
|
| 211 | - $choisie = 'non'; |
|
| 212 | - $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $champs = [ |
|
| 216 | - 'id_rubrique' => $id_rubrique, |
|
| 217 | - 'id_secteur' => $id_secteur, |
|
| 218 | - 'statut' => 'prepa', |
|
| 219 | - 'date' => date('Y-m-d H:i:s'), |
|
| 220 | - 'lang' => $lang, |
|
| 221 | - 'langue_choisie' => $choisie |
|
| 222 | - ]; |
|
| 223 | - |
|
| 224 | - if ($set) { |
|
| 225 | - $champs = array_merge($champs, $set); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Envoyer aux plugins |
|
| 229 | - $champs = pipeline( |
|
| 230 | - 'pre_insertion', |
|
| 231 | - [ |
|
| 232 | - 'args' => [ |
|
| 233 | - 'table' => 'spip_articles', |
|
| 234 | - ], |
|
| 235 | - 'data' => $champs |
|
| 236 | - ] |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | - |
|
| 241 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | - if ($id_article > 0) { |
|
| 243 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | - : _request('id_auteur')); |
|
| 246 | - if ($id_auteur) { |
|
| 247 | - include_spip('action/editer_auteur'); |
|
| 248 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - pipeline( |
|
| 253 | - 'post_insertion', |
|
| 254 | - [ |
|
| 255 | - 'args' => [ |
|
| 256 | - 'table' => 'spip_articles', |
|
| 257 | - 'id_objet' => $id_article |
|
| 258 | - ], |
|
| 259 | - 'data' => $champs |
|
| 260 | - ] |
|
| 261 | - ); |
|
| 262 | - |
|
| 263 | - return $id_article; |
|
| 172 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 173 | + // dans la premiere rubrique racine |
|
| 174 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 175 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 176 | + $id_rubrique = $row['id_rubrique']; |
|
| 177 | + } else { |
|
| 178 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 182 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 183 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 184 | + $lang_rub = $row['lang'] ?? ''; |
|
| 185 | + |
|
| 186 | + $lang = ''; |
|
| 187 | + $choisie = 'non'; |
|
| 188 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 189 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 190 | + // ou a defaut celle de la rubrique |
|
| 191 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 192 | + if ( |
|
| 193 | + !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 194 | + 'spip_articles', |
|
| 195 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 199 | + if ( |
|
| 200 | + in_array( |
|
| 201 | + $GLOBALS['spip_lang'], |
|
| 202 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 203 | + ) |
|
| 204 | + ) { |
|
| 205 | + $lang = $GLOBALS['spip_lang']; |
|
| 206 | + $choisie = 'oui'; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!$lang) { |
|
| 211 | + $choisie = 'non'; |
|
| 212 | + $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $champs = [ |
|
| 216 | + 'id_rubrique' => $id_rubrique, |
|
| 217 | + 'id_secteur' => $id_secteur, |
|
| 218 | + 'statut' => 'prepa', |
|
| 219 | + 'date' => date('Y-m-d H:i:s'), |
|
| 220 | + 'lang' => $lang, |
|
| 221 | + 'langue_choisie' => $choisie |
|
| 222 | + ]; |
|
| 223 | + |
|
| 224 | + if ($set) { |
|
| 225 | + $champs = array_merge($champs, $set); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Envoyer aux plugins |
|
| 229 | + $champs = pipeline( |
|
| 230 | + 'pre_insertion', |
|
| 231 | + [ |
|
| 232 | + 'args' => [ |
|
| 233 | + 'table' => 'spip_articles', |
|
| 234 | + ], |
|
| 235 | + 'data' => $champs |
|
| 236 | + ] |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 240 | + |
|
| 241 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 242 | + if ($id_article > 0) { |
|
| 243 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 244 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 245 | + : _request('id_auteur')); |
|
| 246 | + if ($id_auteur) { |
|
| 247 | + include_spip('action/editer_auteur'); |
|
| 248 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + pipeline( |
|
| 253 | + 'post_insertion', |
|
| 254 | + [ |
|
| 255 | + 'args' => [ |
|
| 256 | + 'table' => 'spip_articles', |
|
| 257 | + 'id_objet' => $id_article |
|
| 258 | + ], |
|
| 259 | + 'data' => $champs |
|
| 260 | + ] |
|
| 261 | + ); |
|
| 262 | + |
|
| 263 | + return $id_article; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -288,125 +288,125 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 290 | 290 | |
| 291 | - include_spip('inc/autoriser'); |
|
| 292 | - include_spip('inc/rubriques'); |
|
| 293 | - include_spip('inc/modifier'); |
|
| 294 | - |
|
| 295 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 296 | - $id_rubrique = $row['id_rubrique']; |
|
| 297 | - $statut_ancien = $statut = $row['statut']; |
|
| 298 | - $date_ancienne = $date = $row['date']; |
|
| 299 | - $champs = []; |
|
| 300 | - |
|
| 301 | - $d = $c['date'] ?? null; |
|
| 302 | - $s = $c['statut'] ?? $statut; |
|
| 303 | - |
|
| 304 | - // cf autorisations dans inc/instituer_article |
|
| 305 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 306 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 307 | - $statut = $champs['statut'] = $s; |
|
| 308 | - } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 309 | - $statut = $champs['statut'] = $s; |
|
| 310 | - } else { |
|
| 311 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // En cas de publication, fixer la date a "maintenant" |
|
| 315 | - // sauf si $c commande autre chose |
|
| 316 | - // ou si l'article est deja date dans le futur |
|
| 317 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 318 | - if ( |
|
| 319 | - $champs['statut'] == 'publie' |
|
| 320 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 321 | - ) { |
|
| 322 | - if ($d or strtotime($d = $date) > time()) { |
|
| 323 | - $champs['date'] = $date = $d; |
|
| 324 | - } else { |
|
| 325 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // Verifier que la rubrique demandee existe et est differente |
|
| 331 | - // de la rubrique actuelle |
|
| 332 | - if ( |
|
| 333 | - isset($c['id_parent']) |
|
| 334 | - and $id_parent = $c['id_parent'] |
|
| 335 | - and $id_parent != $id_rubrique |
|
| 336 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | - ) { |
|
| 338 | - $champs['id_rubrique'] = $id_parent; |
|
| 339 | - |
|
| 340 | - // si l'article etait publie |
|
| 341 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 342 | - // repasser l'article en statut 'propose'. |
|
| 343 | - if ( |
|
| 344 | - $statut == 'publie' |
|
| 345 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 346 | - ) { |
|
| 347 | - $champs['statut'] = 'prop'; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Envoyer aux plugins |
|
| 352 | - $champs = pipeline( |
|
| 353 | - 'pre_edition', |
|
| 354 | - [ |
|
| 355 | - 'args' => [ |
|
| 356 | - 'table' => 'spip_articles', |
|
| 357 | - 'id_objet' => $id_article, |
|
| 358 | - 'action' => 'instituer', |
|
| 359 | - 'statut_ancien' => $statut_ancien, |
|
| 360 | - 'date_ancienne' => $date_ancienne, |
|
| 361 | - ], |
|
| 362 | - 'data' => $champs |
|
| 363 | - ] |
|
| 364 | - ); |
|
| 365 | - |
|
| 366 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 367 | - return ''; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Envoyer les modifs. |
|
| 371 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 372 | - |
|
| 373 | - // Invalider les caches |
|
| 374 | - include_spip('inc/invalideur'); |
|
| 375 | - suivre_invalideur("id='article/$id_article'"); |
|
| 376 | - |
|
| 377 | - if ($date) { |
|
| 378 | - $t = strtotime($date); |
|
| 379 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 380 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 381 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // Pipeline |
|
| 386 | - pipeline( |
|
| 387 | - 'post_edition', |
|
| 388 | - [ |
|
| 389 | - 'args' => [ |
|
| 390 | - 'table' => 'spip_articles', |
|
| 391 | - 'id_objet' => $id_article, |
|
| 392 | - 'action' => 'instituer', |
|
| 393 | - 'statut_ancien' => $statut_ancien, |
|
| 394 | - 'date_ancienne' => $date_ancienne, |
|
| 395 | - ], |
|
| 396 | - 'data' => $champs |
|
| 397 | - ] |
|
| 398 | - ); |
|
| 399 | - |
|
| 400 | - // Notifications |
|
| 401 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 402 | - $notifications( |
|
| 403 | - 'instituerarticle', |
|
| 404 | - $id_article, |
|
| 405 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 406 | - ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return ''; // pas d'erreur |
|
| 291 | + include_spip('inc/autoriser'); |
|
| 292 | + include_spip('inc/rubriques'); |
|
| 293 | + include_spip('inc/modifier'); |
|
| 294 | + |
|
| 295 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 296 | + $id_rubrique = $row['id_rubrique']; |
|
| 297 | + $statut_ancien = $statut = $row['statut']; |
|
| 298 | + $date_ancienne = $date = $row['date']; |
|
| 299 | + $champs = []; |
|
| 300 | + |
|
| 301 | + $d = $c['date'] ?? null; |
|
| 302 | + $s = $c['statut'] ?? $statut; |
|
| 303 | + |
|
| 304 | + // cf autorisations dans inc/instituer_article |
|
| 305 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 306 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 307 | + $statut = $champs['statut'] = $s; |
|
| 308 | + } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 309 | + $statut = $champs['statut'] = $s; |
|
| 310 | + } else { |
|
| 311 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // En cas de publication, fixer la date a "maintenant" |
|
| 315 | + // sauf si $c commande autre chose |
|
| 316 | + // ou si l'article est deja date dans le futur |
|
| 317 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 318 | + if ( |
|
| 319 | + $champs['statut'] == 'publie' |
|
| 320 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 321 | + ) { |
|
| 322 | + if ($d or strtotime($d = $date) > time()) { |
|
| 323 | + $champs['date'] = $date = $d; |
|
| 324 | + } else { |
|
| 325 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // Verifier que la rubrique demandee existe et est differente |
|
| 331 | + // de la rubrique actuelle |
|
| 332 | + if ( |
|
| 333 | + isset($c['id_parent']) |
|
| 334 | + and $id_parent = $c['id_parent'] |
|
| 335 | + and $id_parent != $id_rubrique |
|
| 336 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | + ) { |
|
| 338 | + $champs['id_rubrique'] = $id_parent; |
|
| 339 | + |
|
| 340 | + // si l'article etait publie |
|
| 341 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 342 | + // repasser l'article en statut 'propose'. |
|
| 343 | + if ( |
|
| 344 | + $statut == 'publie' |
|
| 345 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 346 | + ) { |
|
| 347 | + $champs['statut'] = 'prop'; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Envoyer aux plugins |
|
| 352 | + $champs = pipeline( |
|
| 353 | + 'pre_edition', |
|
| 354 | + [ |
|
| 355 | + 'args' => [ |
|
| 356 | + 'table' => 'spip_articles', |
|
| 357 | + 'id_objet' => $id_article, |
|
| 358 | + 'action' => 'instituer', |
|
| 359 | + 'statut_ancien' => $statut_ancien, |
|
| 360 | + 'date_ancienne' => $date_ancienne, |
|
| 361 | + ], |
|
| 362 | + 'data' => $champs |
|
| 363 | + ] |
|
| 364 | + ); |
|
| 365 | + |
|
| 366 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 367 | + return ''; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Envoyer les modifs. |
|
| 371 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 372 | + |
|
| 373 | + // Invalider les caches |
|
| 374 | + include_spip('inc/invalideur'); |
|
| 375 | + suivre_invalideur("id='article/$id_article'"); |
|
| 376 | + |
|
| 377 | + if ($date) { |
|
| 378 | + $t = strtotime($date); |
|
| 379 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 380 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 381 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // Pipeline |
|
| 386 | + pipeline( |
|
| 387 | + 'post_edition', |
|
| 388 | + [ |
|
| 389 | + 'args' => [ |
|
| 390 | + 'table' => 'spip_articles', |
|
| 391 | + 'id_objet' => $id_article, |
|
| 392 | + 'action' => 'instituer', |
|
| 393 | + 'statut_ancien' => $statut_ancien, |
|
| 394 | + 'date_ancienne' => $date_ancienne, |
|
| 395 | + ], |
|
| 396 | + 'data' => $champs |
|
| 397 | + ] |
|
| 398 | + ); |
|
| 399 | + |
|
| 400 | + // Notifications |
|
| 401 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 402 | + $notifications( |
|
| 403 | + 'instituerarticle', |
|
| 404 | + $id_article, |
|
| 405 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return ''; // pas d'erreur |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -431,37 +431,37 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 433 | 433 | |
| 434 | - // Si on deplace l'article |
|
| 435 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 436 | - if (isset($champs['id_rubrique'])) { |
|
| 437 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | - |
|
| 439 | - $langue = $row_rub['lang']; |
|
| 440 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 441 | - if ( |
|
| 442 | - sql_fetsel( |
|
| 443 | - '1', |
|
| 444 | - 'spip_articles', |
|
| 445 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | - ) |
|
| 447 | - ) { |
|
| 448 | - $champs['lang'] = $langue; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - if (!$champs) { |
|
| 453 | - return; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | - |
|
| 458 | - // Changer le statut des rubriques concernees |
|
| 459 | - |
|
| 460 | - if ($cond) { |
|
| 461 | - include_spip('inc/rubriques'); |
|
| 462 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 463 | - calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 464 | - } |
|
| 434 | + // Si on deplace l'article |
|
| 435 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 436 | + if (isset($champs['id_rubrique'])) { |
|
| 437 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | + |
|
| 439 | + $langue = $row_rub['lang']; |
|
| 440 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 441 | + if ( |
|
| 442 | + sql_fetsel( |
|
| 443 | + '1', |
|
| 444 | + 'spip_articles', |
|
| 445 | + 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | + ) |
|
| 447 | + ) { |
|
| 448 | + $champs['lang'] = $langue; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + if (!$champs) { |
|
| 453 | + return; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | + |
|
| 458 | + // Changer le statut des rubriques concernees |
|
| 459 | + |
|
| 460 | + if ($cond) { |
|
| 461 | + include_spip('inc/rubriques'); |
|
| 462 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 463 | + calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -470,10 +470,10 @@ discard block |
||
| 470 | 470 | * @return void |
| 471 | 471 | */ |
| 472 | 472 | function trop_longs_articles() { |
| 473 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 474 | - foreach ($plus as $n => $t) { |
|
| 475 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 476 | - } |
|
| 477 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | - } |
|
| 473 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 474 | + foreach ($plus as $n => $t) { |
|
| 475 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 476 | + } |
|
| 477 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | + } |
|
| 479 | 479 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
| 69 | 69 | |
| 70 | 70 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | 72 | |
| 73 | 73 | if ($r) { |
| 74 | 74 | return array_merge($r, $credentials_ldap); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | if ($r) { |
| 93 | 93 | return array_merge( |
| 94 | 94 | $credentials_ldap, |
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur='.intval($r), '', '', '', '', $serveur) |
|
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $connexion = spip_connect($serveur); |
| 122 | 122 | if (!is_array($connexion['ldap'])) { |
| 123 | 123 | if ($connexion['authentification']['ldap']) { |
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 125 | 125 | unset($GLOBALS['ldap_link']); |
| 126 | 126 | if (is_readable($f)) { |
| 127 | 127 | include_once($f); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 335 | 335 | return false; |
| 336 | 336 | } |
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 337 | + $encoded_pass = '{MD5}'.base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | 338 | $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
| 339 | 339 | |
| 340 | 340 | return $success; |
@@ -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 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 26 | 26 | // ne pas ecraser une definition perso dans mes_options |
| 27 | 27 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 28 | - $GLOBALS['ldap_attributes'] = [ |
|
| 29 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | - 'nom' => 'cn', |
|
| 31 | - 'email' => 'mail', |
|
| 32 | - 'bio' => 'description' |
|
| 33 | - ]; |
|
| 28 | + $GLOBALS['ldap_attributes'] = [ |
|
| 29 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | + 'nom' => 'cn', |
|
| 31 | + 'email' => 'mail', |
|
| 32 | + 'bio' => 'description' |
|
| 33 | + ]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,50 +56,50 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 58 | 58 | |
| 59 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | - |
|
| 61 | - // Utilisateur connu ? |
|
| 62 | - // si http auth, inutile de reauthentifier: cela |
|
| 63 | - // ne marchera pas avec auth http autre que basic. |
|
| 64 | - $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | - |
|
| 70 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | - |
|
| 73 | - if ($r) { |
|
| 74 | - return array_merge($r, $credentials_ldap); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // sinon importer les infos depuis LDAP, |
|
| 78 | - |
|
| 79 | - if ( |
|
| 80 | - $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | - and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | - ) { |
|
| 83 | - // rajouter le statut indique a l'install |
|
| 84 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | - $desc['login'] = $login; |
|
| 86 | - $desc['source'] = 'ldap'; |
|
| 87 | - $desc['pass'] = ''; |
|
| 88 | - |
|
| 89 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($r) { |
|
| 93 | - return array_merge( |
|
| 94 | - $credentials_ldap, |
|
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // sinon echec |
|
| 100 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | - |
|
| 102 | - return []; |
|
| 59 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | + |
|
| 61 | + // Utilisateur connu ? |
|
| 62 | + // si http auth, inutile de reauthentifier: cela |
|
| 63 | + // ne marchera pas avec auth http autre que basic. |
|
| 64 | + $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | + |
|
| 70 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | + |
|
| 73 | + if ($r) { |
|
| 74 | + return array_merge($r, $credentials_ldap); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // sinon importer les infos depuis LDAP, |
|
| 78 | + |
|
| 79 | + if ( |
|
| 80 | + $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | + and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | + ) { |
|
| 83 | + // rajouter le statut indique a l'install |
|
| 84 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | + $desc['login'] = $login; |
|
| 86 | + $desc['source'] = 'ldap'; |
|
| 87 | + $desc['pass'] = ''; |
|
| 88 | + |
|
| 89 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($r) { |
|
| 93 | + return array_merge( |
|
| 94 | + $credentials_ldap, |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // sinon echec |
|
| 100 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | + |
|
| 102 | + return []; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,36 +113,36 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | function auth_ldap_connect($serveur = '') { |
| 116 | - include_spip('base/connect_sql'); |
|
| 117 | - static $connexions_ldap = []; |
|
| 118 | - if (isset($connexions_ldap[$serveur])) { |
|
| 119 | - return $connexions_ldap[$serveur]; |
|
| 120 | - } |
|
| 121 | - $connexion = spip_connect($serveur); |
|
| 122 | - if (!is_array($connexion['ldap'])) { |
|
| 123 | - if ($connexion['authentification']['ldap']) { |
|
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | - unset($GLOBALS['ldap_link']); |
|
| 126 | - if (is_readable($f)) { |
|
| 127 | - include_once($f); |
|
| 128 | - }; |
|
| 129 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | - $connexion['ldap'] = [ |
|
| 131 | - 'link' => $GLOBALS['ldap_link'], |
|
| 132 | - 'base' => $GLOBALS['ldap_base'] |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | - } |
|
| 137 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 116 | + include_spip('base/connect_sql'); |
|
| 117 | + static $connexions_ldap = []; |
|
| 118 | + if (isset($connexions_ldap[$serveur])) { |
|
| 119 | + return $connexions_ldap[$serveur]; |
|
| 120 | + } |
|
| 121 | + $connexion = spip_connect($serveur); |
|
| 122 | + if (!is_array($connexion['ldap'])) { |
|
| 123 | + if ($connexion['authentification']['ldap']) { |
|
| 124 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | + unset($GLOBALS['ldap_link']); |
|
| 126 | + if (is_readable($f)) { |
|
| 127 | + include_once($f); |
|
| 128 | + }; |
|
| 129 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | + $connexion['ldap'] = [ |
|
| 131 | + 'link' => $GLOBALS['ldap_link'], |
|
| 132 | + 'base' => $GLOBALS['ldap_base'] |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | + } |
|
| 137 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | * Le login trouvé ou chaine vide si non trouvé |
| 157 | 157 | */ |
| 158 | 158 | function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
| 159 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // verifier la connexion |
|
| 166 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | - return ''; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ldap_link = $ldap['link'] ?? null; |
|
| 171 | - $ldap_base = $ldap['base'] ?? null; |
|
| 172 | - $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | - |
|
| 174 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | - |
|
| 176 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | - foreach ($logins as $att) { |
|
| 178 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | - // (on veut un attribut unique) |
|
| 182 | - |
|
| 183 | - if (is_array($info) and $info['count'] == 1) { |
|
| 184 | - $dn = $info[0]['dn']; |
|
| 185 | - if (!$checkpass) { |
|
| 186 | - return $dn; |
|
| 187 | - } |
|
| 188 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | - return $dn; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($checkpass and !isset($dn)) { |
|
| 195 | - // Si echec, essayer de deviner le DN |
|
| 196 | - foreach ($logins as $att) { |
|
| 197 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | - return "$att=$login_search, $ldap_base"; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ''; |
|
| 159 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // verifier la connexion |
|
| 166 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | + return ''; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ldap_link = $ldap['link'] ?? null; |
|
| 171 | + $ldap_base = $ldap['base'] ?? null; |
|
| 172 | + $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | + |
|
| 174 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | + |
|
| 176 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | + foreach ($logins as $att) { |
|
| 178 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | + // (on veut un attribut unique) |
|
| 182 | + |
|
| 183 | + if (is_array($info) and $info['count'] == 1) { |
|
| 184 | + $dn = $info[0]['dn']; |
|
| 185 | + if (!$checkpass) { |
|
| 186 | + return $dn; |
|
| 187 | + } |
|
| 188 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | + return $dn; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($checkpass and !isset($dn)) { |
|
| 195 | + // Si echec, essayer de deviner le DN |
|
| 196 | + foreach ($logins as $att) { |
|
| 197 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | + return "$att=$login_search, $ldap_base"; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ''; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,40 +213,40 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 216 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 217 | 217 | |
| 218 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 219 | - spip_log("ldap $serveur injoignable"); |
|
| 218 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 219 | + spip_log("ldap $serveur injoignable"); |
|
| 220 | 220 | |
| 221 | - return []; |
|
| 222 | - } |
|
| 221 | + return []; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - $ldap_link = $ldap['link']; |
|
| 225 | - if (!$desc) { |
|
| 226 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 227 | - unset($desc['login']); |
|
| 228 | - } |
|
| 229 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 224 | + $ldap_link = $ldap['link']; |
|
| 225 | + if (!$desc) { |
|
| 226 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 227 | + unset($desc['login']); |
|
| 228 | + } |
|
| 229 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 230 | 230 | |
| 231 | - if (!$result) { |
|
| 232 | - return []; |
|
| 233 | - } |
|
| 231 | + if (!$result) { |
|
| 232 | + return []; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | - return []; |
|
| 239 | - } |
|
| 240 | - $val = $val[0]; |
|
| 235 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | + return []; |
|
| 239 | + } |
|
| 240 | + $val = $val[0]; |
|
| 241 | 241 | |
| 242 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | - include_spip('inc/charsets'); |
|
| 242 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | + include_spip('inc/charsets'); |
|
| 244 | 244 | |
| 245 | - foreach ($desc as $k => $v) { |
|
| 246 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | - } |
|
| 245 | + foreach ($desc as $k => $v) { |
|
| 246 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $desc; |
|
| 249 | + return $desc; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | 260 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 261 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * Message d'erreur si login non valide, chaîne vide sinon |
| 279 | 279 | */ |
| 280 | 280 | function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 281 | - include_spip('auth/spip'); |
|
| 281 | + include_spip('auth/spip'); |
|
| 282 | 282 | |
| 283 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * ``` |
| 302 | 302 | */ |
| 303 | 303 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 304 | - return true; |
|
| 304 | + return true; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | * Informe du succès ou de l'echec du changement du mot de passe |
| 320 | 320 | */ |
| 321 | 321 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 322 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - $link = $ldap['link']; |
|
| 329 | - include_spip('inc/session'); |
|
| 330 | - $dn = session_get('ldap_dn'); |
|
| 331 | - if ('' == $dn) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | - $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | - |
|
| 340 | - return $success; |
|
| 322 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + $link = $ldap['link']; |
|
| 329 | + include_spip('inc/session'); |
|
| 330 | + $dn = session_get('ldap_dn'); |
|
| 331 | + if ('' == $dn) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | + $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | + |
|
| 340 | + return $success; |
|
| 341 | 341 | } |
@@ -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 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,25 +157,25 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 160 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 161 | 161 | |
| 162 | - $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | - $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | - $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 162 | + $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | + $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | + $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 166 | 166 | |
| 167 | - $display_class = [ |
|
| 168 | - 0 => 'icones_img_texte' |
|
| 169 | - /*init*/, |
|
| 170 | - 1 => 'icones_texte', |
|
| 171 | - 2 => 'icones_img_texte', |
|
| 172 | - 3 => 'icones_img' |
|
| 173 | - ]; |
|
| 167 | + $display_class = [ |
|
| 168 | + 0 => 'icones_img_texte' |
|
| 169 | + /*init*/, |
|
| 170 | + 1 => 'icones_texte', |
|
| 171 | + 2 => 'icones_img_texte', |
|
| 172 | + 3 => 'icones_img' |
|
| 173 | + ]; |
|
| 174 | 174 | |
| 175 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 175 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | - return spip_sanitize_classname($classes); |
|
| 177 | + $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | + return spip_sanitize_classname($classes); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -186,5 +186,5 @@ discard block |
||
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | 188 | function auteurs_recemment_connectes($id_auteur) { |
| 189 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 189 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 190 | 190 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $couleur = intval($prefs['couleur'] ?? 2); |
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 177 | + $classes = $GLOBALS['spip_ecran']." spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils ".$display_class[$GLOBALS['spip_display']]; |
|
| 178 | 178 | return spip_sanitize_classname($classes); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -21,193 +21,193 @@ |
||
| 21 | 21 | // par souci de compatiilite). |
| 22 | 22 | |
| 23 | 23 | if (isset($GLOBALS['_INC_PUBLIC']) and $GLOBALS['_INC_PUBLIC']) { |
| 24 | - echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 24 | + echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 25 | 25 | } else { |
| 26 | - $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | - define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | - |
|
| 29 | - // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | - if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | - if ( |
|
| 32 | - defined('_DIR_RESTREINT') |
|
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | - ) { |
|
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | - } else { |
|
| 37 | - die('inc_version absent ?'); |
|
| 38 | - } |
|
| 39 | - } // $fond defini dans le fichier d'appel ? |
|
| 40 | - |
|
| 41 | - else { |
|
| 42 | - if (isset($fond) and !_request('fond')) { |
|
| 43 | - } // fond demande dans l'url par page=xxxx ? |
|
| 44 | - else { |
|
| 45 | - if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | - |
|
| 48 | - // Securite |
|
| 49 | - if ( |
|
| 50 | - strstr($fond, '/') |
|
| 51 | - and !( |
|
| 52 | - isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | - and include_spip('inc/autoriser') |
|
| 54 | - and autoriser('webmestre')) |
|
| 55 | - ) { |
|
| 56 | - include_spip('inc/minipres'); |
|
| 57 | - echo minipres(); |
|
| 58 | - exit; |
|
| 59 | - } |
|
| 60 | - // l'argument Page a priorite sur l'argument action |
|
| 61 | - // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | - // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | - // mais pas d'en retirer un en conservant les autres. |
|
| 64 | - if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | - unset($_GET['action']); |
|
| 66 | - } |
|
| 67 | - # sinon, fond par defaut |
|
| 68 | - } else { |
|
| 69 | - // sinon fond par defaut (cf. assembler.php) |
|
| 70 | - $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $tableau_des_temps = []; |
|
| 76 | - |
|
| 77 | - // Particularites de certains squelettes |
|
| 78 | - if ($fond == 'login') { |
|
| 79 | - $forcer_lang = true; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ( |
|
| 83 | - isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | - and !_request('action') |
|
| 85 | - and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | - ) { |
|
| 87 | - include_spip('inc/lang'); |
|
| 88 | - verifier_lang_url(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | - |
|
| 93 | - // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | - // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | - if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | - include_spip('public/aiguiller'); |
|
| 97 | - if ( |
|
| 98 | - // cas des appels actions ?action=xxx |
|
| 99 | - traiter_appels_actions() |
|
| 100 | - or |
|
| 101 | - // cas des hits ajax sur les inclusions ajax |
|
| 102 | - traiter_appels_inclusions_ajax() |
|
| 103 | - or |
|
| 104 | - // cas des formulaires charger/verifier/traiter |
|
| 105 | - traiter_formulaires_dynamiques() |
|
| 106 | - ) { |
|
| 107 | - // lancer les taches sur affichage final, comme le cron |
|
| 108 | - // mais sans rien afficher |
|
| 109 | - $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | - exit; // le hit est fini ! |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Il y a du texte a produire, charger le metteur en page |
|
| 116 | - include_spip('public/assembler'); |
|
| 117 | - $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | - |
|
| 119 | - if (isset($page['status'])) { |
|
| 120 | - include_spip('inc/headers'); |
|
| 121 | - http_response_code($page['status']); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Content-Type ? |
|
| 125 | - if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | - $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | - $html = true; |
|
| 129 | - } else { |
|
| 130 | - $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | - // type tableau pour y mettre des choses au besoin. |
|
| 135 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | - |
|
| 137 | - // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | - $affiche_boutons_admin = ($html and ( |
|
| 139 | - (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | - or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | - or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | - )); |
|
| 143 | - |
|
| 144 | - if ($affiche_boutons_admin) { |
|
| 145 | - include_spip('balise/formulaire_admin'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - // Execution de la page calculee |
|
| 150 | - |
|
| 151 | - // traitements sur les entetes avant envoi |
|
| 152 | - // peut servir pour le plugin de stats |
|
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - // eval $page et affecte $res |
|
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | - envoyer_entetes($page['entetes']); |
|
| 159 | - if ($res === false) { |
|
| 160 | - include_spip('inc/autoriser'); |
|
| 161 | - $err = _T('zbug_erreur_execution_page'); |
|
| 162 | - if (autoriser('webmestre')) { |
|
| 163 | - $err .= "\n<hr />\n" |
|
| 164 | - . highlight_string($page['codephp'], true) |
|
| 165 | - . "\n<hr />\n"; |
|
| 166 | - } |
|
| 167 | - $msg = [$err]; |
|
| 168 | - erreur_squelette($msg); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // |
|
| 172 | - // Envoyer le resultat apres post-traitements |
|
| 173 | - // |
|
| 174 | - // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | - // cf. public/assembler.php) |
|
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | - |
|
| 178 | - if ($lang) { |
|
| 179 | - lang_select(); |
|
| 180 | - } |
|
| 181 | - // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | - // il faut tester a nouveau |
|
| 183 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | - |
|
| 185 | - // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | - // at last |
|
| 187 | - if ($debug) { |
|
| 188 | - // en cas d'erreur, retester l'affichage |
|
| 189 | - if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | - $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | - echo erreur_squelette(false); |
|
| 194 | - } |
|
| 195 | - } else { |
|
| 196 | - if ( |
|
| 197 | - isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | - and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | - ) { |
|
| 200 | - include_spip('inc/rubriques'); |
|
| 201 | - calculer_prochain_postdate(true); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Effectuer une tache de fond ? |
|
| 205 | - // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | - cron(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // sauver le cache chemin si necessaire |
|
| 211 | - save_path_cache(); |
|
| 212 | - } |
|
| 26 | + $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | + define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | + |
|
| 29 | + // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | + if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | + if ( |
|
| 32 | + defined('_DIR_RESTREINT') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | + ) { |
|
| 35 | + include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | + } else { |
|
| 37 | + die('inc_version absent ?'); |
|
| 38 | + } |
|
| 39 | + } // $fond defini dans le fichier d'appel ? |
|
| 40 | + |
|
| 41 | + else { |
|
| 42 | + if (isset($fond) and !_request('fond')) { |
|
| 43 | + } // fond demande dans l'url par page=xxxx ? |
|
| 44 | + else { |
|
| 45 | + if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | + $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | + |
|
| 48 | + // Securite |
|
| 49 | + if ( |
|
| 50 | + strstr($fond, '/') |
|
| 51 | + and !( |
|
| 52 | + isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | + and include_spip('inc/autoriser') |
|
| 54 | + and autoriser('webmestre')) |
|
| 55 | + ) { |
|
| 56 | + include_spip('inc/minipres'); |
|
| 57 | + echo minipres(); |
|
| 58 | + exit; |
|
| 59 | + } |
|
| 60 | + // l'argument Page a priorite sur l'argument action |
|
| 61 | + // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | + // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | + // mais pas d'en retirer un en conservant les autres. |
|
| 64 | + if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | + unset($_GET['action']); |
|
| 66 | + } |
|
| 67 | + # sinon, fond par defaut |
|
| 68 | + } else { |
|
| 69 | + // sinon fond par defaut (cf. assembler.php) |
|
| 70 | + $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $tableau_des_temps = []; |
|
| 76 | + |
|
| 77 | + // Particularites de certains squelettes |
|
| 78 | + if ($fond == 'login') { |
|
| 79 | + $forcer_lang = true; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ( |
|
| 83 | + isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | + and !_request('action') |
|
| 85 | + and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | + ) { |
|
| 87 | + include_spip('inc/lang'); |
|
| 88 | + verifier_lang_url(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | + |
|
| 93 | + // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | + // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | + if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | + include_spip('public/aiguiller'); |
|
| 97 | + if ( |
|
| 98 | + // cas des appels actions ?action=xxx |
|
| 99 | + traiter_appels_actions() |
|
| 100 | + or |
|
| 101 | + // cas des hits ajax sur les inclusions ajax |
|
| 102 | + traiter_appels_inclusions_ajax() |
|
| 103 | + or |
|
| 104 | + // cas des formulaires charger/verifier/traiter |
|
| 105 | + traiter_formulaires_dynamiques() |
|
| 106 | + ) { |
|
| 107 | + // lancer les taches sur affichage final, comme le cron |
|
| 108 | + // mais sans rien afficher |
|
| 109 | + $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | + pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | + exit; // le hit est fini ! |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Il y a du texte a produire, charger le metteur en page |
|
| 116 | + include_spip('public/assembler'); |
|
| 117 | + $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | + |
|
| 119 | + if (isset($page['status'])) { |
|
| 120 | + include_spip('inc/headers'); |
|
| 121 | + http_response_code($page['status']); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Content-Type ? |
|
| 125 | + if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | + $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | + $html = true; |
|
| 129 | + } else { |
|
| 130 | + $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | + // type tableau pour y mettre des choses au besoin. |
|
| 135 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | + |
|
| 137 | + // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | + $affiche_boutons_admin = ($html and ( |
|
| 139 | + (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | + or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | + or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | + )); |
|
| 143 | + |
|
| 144 | + if ($affiche_boutons_admin) { |
|
| 145 | + include_spip('balise/formulaire_admin'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + // Execution de la page calculee |
|
| 150 | + |
|
| 151 | + // traitements sur les entetes avant envoi |
|
| 152 | + // peut servir pour le plugin de stats |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + // eval $page et affecte $res |
|
| 157 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | + envoyer_entetes($page['entetes']); |
|
| 159 | + if ($res === false) { |
|
| 160 | + include_spip('inc/autoriser'); |
|
| 161 | + $err = _T('zbug_erreur_execution_page'); |
|
| 162 | + if (autoriser('webmestre')) { |
|
| 163 | + $err .= "\n<hr />\n" |
|
| 164 | + . highlight_string($page['codephp'], true) |
|
| 165 | + . "\n<hr />\n"; |
|
| 166 | + } |
|
| 167 | + $msg = [$err]; |
|
| 168 | + erreur_squelette($msg); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // |
|
| 172 | + // Envoyer le resultat apres post-traitements |
|
| 173 | + // |
|
| 174 | + // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | + // cf. public/assembler.php) |
|
| 176 | + echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | + |
|
| 178 | + if ($lang) { |
|
| 179 | + lang_select(); |
|
| 180 | + } |
|
| 181 | + // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | + // il faut tester a nouveau |
|
| 183 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | + |
|
| 185 | + // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | + // at last |
|
| 187 | + if ($debug) { |
|
| 188 | + // en cas d'erreur, retester l'affichage |
|
| 189 | + if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | + $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | + echo erreur_squelette(false); |
|
| 194 | + } |
|
| 195 | + } else { |
|
| 196 | + if ( |
|
| 197 | + isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | + and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | + ) { |
|
| 200 | + include_spip('inc/rubriques'); |
|
| 201 | + calculer_prochain_postdate(true); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Effectuer une tache de fond ? |
|
| 205 | + // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | + cron(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // sauver le cache chemin si necessaire |
|
| 211 | + save_path_cache(); |
|
| 212 | + } |
|
| 213 | 213 | } |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 31 | 31 | if ( |
| 32 | 32 | defined('_DIR_RESTREINT') |
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT.'inc_version.php') |
|
| 34 | 34 | ) { |
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | + include_once _ROOT_RESTREINT.'inc_version.php'; |
|
| 36 | 36 | } else { |
| 37 | 37 | die('inc_version absent ?'); |
| 38 | 38 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } // fond demande dans l'url par page=xxxx ? |
| 44 | 44 | else { |
| 45 | 45 | if (isset($_GET[_SPIP_PAGE])) { |
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | + $fond = (string) $_GET[_SPIP_PAGE]; |
|
| 47 | 47 | |
| 48 | 48 | // Securite |
| 49 | 49 | if ( |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // lancer les taches sur affichage final, comme le cron |
| 108 | 108 | // mais sans rien afficher |
| 109 | 109 | $GLOBALS['html'] = false; // ne rien afficher |
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 110 | + pipeline('affichage_final'._PIPELINE_SUFFIX, ''); |
|
| 111 | 111 | exit; // le hit est fini ! |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | // Content-Type ? |
| 125 | 125 | if (!isset($page['entetes']['Content-Type'])) { |
| 126 | 126 | $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset='.$charset; |
|
| 128 | 128 | $html = true; |
| 129 | 129 | } else { |
| 130 | 130 | $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | // traitements sur les entetes avant envoi |
| 152 | 152 | // peut servir pour le plugin de stats |
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final'._PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | // eval $page et affecte $res |
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 157 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 158 | 158 | envoyer_entetes($page['entetes']); |
| 159 | 159 | if ($res === false) { |
| 160 | 160 | include_spip('inc/autoriser'); |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | // |
| 174 | 174 | // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
| 175 | 175 | // cf. public/assembler.php) |
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 176 | + echo pipeline('affichage_final'._PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | 177 | |
| 178 | 178 | if ($lang) { |
| 179 | 179 | lang_select(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | if ($html and ($affiche_boutons_admin or $debug)) { |
| 190 | 190 | $var_mode_affiche = _request('var_mode_affiche'); |
| 191 | 191 | $var_mode_objet = _request('var_mode_objet'); |
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet.'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | 193 | echo erreur_squelette(false); |
| 194 | 194 | } |
| 195 | 195 | } else { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // Si a ce stade on n'a pas de table, il y a un bug |
| 235 | 235 | if (!is_array($this->tableau)) { |
| 236 | 236 | $this->err = true; |
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 237 | + spip_log('erreur datasource '.var_export($command, true)); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // {datapath query.results} |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | isset($this->command['sourcemode']) |
| 277 | 277 | and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
| 278 | 278 | ) { |
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 279 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | # le premier argument peut etre un array, une URL etc. |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | # avons-nous un cache dispo ? |
| 286 | 286 | $cle = null; |
| 287 | 287 | if (is_string($src)) { |
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 288 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $cache = $this->cache_get($cle); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | if ( |
| 346 | 346 | !$this->err |
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 348 | 348 | ) { |
| 349 | 349 | $args = $this->command['source']; |
| 350 | 350 | $args[0] = $data; |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | $tv = '%s'; |
| 485 | 485 | } # {par valeur/xx/yy} ?? |
| 486 | 486 | else { |
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 487 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 488 | 488 | } |
| 489 | 489 | $sortfunc .= ' |
| 490 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 491 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 490 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 491 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 492 | 492 | if ($a <> $b) |
| 493 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 493 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | 644 | # sortir le connecteur de $data |
| 645 | 645 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 646 | - $serveur = (string)$v[1]; |
|
| 646 | + $serveur = (string) $v[1]; |
|
| 647 | 647 | $req = trim($v[2]); |
| 648 | 648 | if ($s = sql_query($req, $serveur)) { |
| 649 | 649 | $r = []; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 669 | 669 | } catch (JsonException $e) { |
| 670 | 670 | $json = null; |
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 671 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 672 | 672 | } |
| 673 | 673 | return is_array($json) ? (array) $json : []; |
| 674 | 674 | } |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | $i = 1; |
| 689 | 689 | foreach ($entete as $k => $v) { |
| 690 | 690 | if (trim($v) == '') { |
| 691 | - $v = 'col' . $i; |
|
| 691 | + $v = 'col'.$i; |
|
| 692 | 692 | } // reperer des eventuelles cases vides |
| 693 | 693 | if (is_numeric($v) and $v < 0) { |
| 694 | - $v = '__' . $v; |
|
| 694 | + $v = '__'.$v; |
|
| 695 | 695 | } // ne pas risquer d'ecraser une cle numerique |
| 696 | 696 | if (is_numeric($v)) { |
| 697 | - $v = '_' . $v; |
|
| 697 | + $v = '_'.$v; |
|
| 698 | 698 | } // ne pas risquer d'ecraser une cle numerique |
| 699 | 699 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 700 | 700 | foreach ($csv as &$item) { |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -795,13 +795,13 @@ discard block |
||
| 795 | 795 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 796 | 796 | $a = $glob_to_array($data); |
| 797 | 797 | foreach ($a as &$v) { |
| 798 | - $b = (array)@stat($v); |
|
| 798 | + $b = (array) @stat($v); |
|
| 799 | 799 | foreach ($b as $k => $ignore) { |
| 800 | 800 | if (is_numeric($k)) { |
| 801 | 801 | unset($b[$k]); |
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 805 | 805 | $v = array_merge( |
| 806 | 806 | pathinfo($v), |
| 807 | 807 | $b |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | $xml_array = []; |
| 822 | 822 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 823 | 823 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 824 | - $key .= '-' . uniqid(); |
|
| 824 | + $key .= '-'.uniqid(); |
|
| 825 | 825 | } |
| 826 | 826 | $vars = get_object_vars($object->current()); |
| 827 | 827 | if (isset($vars['@attributes'])) { |
@@ -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 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 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 = [ |
|
| 47 | - 'field' => [ |
|
| 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 = [ |
|
| 47 | + 'field' => [ |
|
| 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,522 +62,522 @@ 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 = []; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = []; |
|
| 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 = []) { |
|
| 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(): void { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = array_key_first($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 ['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( |
|
| 183 | - $cle, |
|
| 184 | - [ |
|
| 185 | - 'data' => $valeur, |
|
| 186 | - 'time' => time(), |
|
| 187 | - 'ttl' => $ttl |
|
| 188 | - ], |
|
| 189 | - 3600 + $ttl |
|
| 190 | - ); |
|
| 191 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Aller chercher les données de la boucle DATA |
|
| 197 | - * |
|
| 198 | - * @throws Exception |
|
| 199 | - * @param array $command |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function select($command) { |
|
| 203 | - |
|
| 204 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | - // le type se retrouve dans la commande 'from' |
|
| 206 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | - if (isset($this->command['from'][0])) { |
|
| 208 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | - } |
|
| 211 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | - // les commandes connues pour l'iterateur DATA |
|
| 216 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | - |
|
| 218 | - // {source format, [URL], [arg2]...} |
|
| 219 | - if ( |
|
| 220 | - isset($this->command['source']) |
|
| 221 | - and isset($this->command['sourcemode']) |
|
| 222 | - ) { |
|
| 223 | - $this->select_source(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Critere {liste X1, X2, X3} |
|
| 227 | - if (isset($this->command['liste'])) { |
|
| 228 | - $this->select_liste(); |
|
| 229 | - } |
|
| 230 | - if (isset($this->command['enum'])) { |
|
| 231 | - $this->select_enum(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | - if (!is_array($this->tableau)) { |
|
| 236 | - $this->err = true; |
|
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // {datapath query.results} |
|
| 241 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | - if ( |
|
| 243 | - !$this->err |
|
| 244 | - and isset($this->command['datapath']) |
|
| 245 | - and is_array($this->command['datapath']) |
|
| 246 | - ) { |
|
| 247 | - $this->select_datapath(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // tri {par x} |
|
| 251 | - if ($this->command['orderby']) { |
|
| 252 | - $this->select_orderby(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | - if ($this->command['groupby']) { |
|
| 257 | - $this->select_groupby(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $this->rewind(); |
|
| 261 | - #var_dump($this->tableau); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Aller chercher les donnees de la boucle DATA |
|
| 267 | - * depuis une source |
|
| 268 | - * {source format, [URL], [arg2]...} |
|
| 269 | - */ |
|
| 270 | - protected function select_source() { |
|
| 271 | - # un peu crado : avant de charger le cache il faut charger |
|
| 272 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | - # l'objet en cache ; cf plugins/icalendar |
|
| 274 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | - if ( |
|
| 276 | - isset($this->command['sourcemode']) |
|
| 277 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | - ) { |
|
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - # le premier argument peut etre un array, une URL etc. |
|
| 283 | - $src = $this->command['source'][0]; |
|
| 284 | - |
|
| 285 | - # avons-nous un cache dispo ? |
|
| 286 | - $cle = null; |
|
| 287 | - if (is_string($src)) { |
|
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $cache = $this->cache_get($cle); |
|
| 292 | - if (isset($this->command['datacache'])) { |
|
| 293 | - $ttl = intval($this->command['datacache']); |
|
| 294 | - } |
|
| 295 | - if ( |
|
| 296 | - $cache |
|
| 297 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | - > time()) |
|
| 299 | - and !(_request('var_mode') === 'recalcul' |
|
| 300 | - and include_spip('inc/autoriser') |
|
| 301 | - and autoriser('recalcul') |
|
| 302 | - ) |
|
| 303 | - ) { |
|
| 304 | - $this->tableau = $cache['data']; |
|
| 305 | - } else { |
|
| 306 | - try { |
|
| 307 | - if ( |
|
| 308 | - isset($this->command['sourcemode']) |
|
| 309 | - and in_array( |
|
| 310 | - $this->command['sourcemode'], |
|
| 311 | - ['table', 'array', 'tableau'] |
|
| 312 | - ) |
|
| 313 | - ) { |
|
| 314 | - if ( |
|
| 315 | - is_array($a = $src) |
|
| 316 | - or (is_string($a) |
|
| 317 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | - and is_array($a = @unserialize($a))) |
|
| 319 | - ) { |
|
| 320 | - $this->tableau = $a; |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - $data = $src; |
|
| 324 | - if (is_string($src)) { |
|
| 325 | - if (tester_url_absolue($src)) { |
|
| 326 | - include_spip('inc/distant'); |
|
| 327 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | - $data = $data['page'] ?? ''; |
|
| 329 | - if (!$data) { |
|
| 330 | - throw new Exception('404'); |
|
| 331 | - } |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 24 * 3600; |
|
| 334 | - } |
|
| 335 | - } elseif (@is_dir($src)) { |
|
| 336 | - $data = $src; |
|
| 337 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | - $data = spip_file_get_contents($src); |
|
| 339 | - } |
|
| 340 | - if (!isset($ttl)) { |
|
| 341 | - $ttl = 10; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( |
|
| 346 | - !$this->err |
|
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | - ) { |
|
| 349 | - $args = $this->command['source']; |
|
| 350 | - $args[0] = $data; |
|
| 351 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | - $this->tableau = $a; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!is_array($this->tableau)) { |
|
| 358 | - $this->err = true; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | - $this->cache_set($cle, $ttl); |
|
| 363 | - } |
|
| 364 | - } catch (Exception $e) { |
|
| 365 | - $e = $e->getMessage(); |
|
| 366 | - $err = sprintf( |
|
| 367 | - "[%s, %s] $e", |
|
| 368 | - $src, |
|
| 369 | - $this->command['sourcemode'] |
|
| 370 | - ); |
|
| 371 | - erreur_squelette([$err, []]); |
|
| 372 | - $this->err = true; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | - if ( |
|
| 378 | - $this->err |
|
| 379 | - and $cache |
|
| 380 | - ) { |
|
| 381 | - $this->tableau = $cache['data']; |
|
| 382 | - $this->err = false; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Retourne un tableau donne depuis un critère liste |
|
| 389 | - * |
|
| 390 | - * Critère `{liste X1, X2, X3}` |
|
| 391 | - * |
|
| 392 | - * @see critere_DATA_liste_dist() |
|
| 393 | - * |
|
| 394 | - **/ |
|
| 395 | - protected function select_liste() { |
|
| 396 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | - if (!isset($this->command['liste'][1])) { |
|
| 398 | - if (!is_array($this->command['liste'][0])) { |
|
| 399 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | - } else { |
|
| 401 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - $this->tableau = $this->command['liste']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Retourne un tableau donne depuis un critere liste |
|
| 409 | - * Critere {enum Xmin, Xmax} |
|
| 410 | - * |
|
| 411 | - **/ |
|
| 412 | - protected function select_enum() { |
|
| 413 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | - if (!isset($this->command['enum'][1])) { |
|
| 415 | - if (!is_array($this->command['enum'][0])) { |
|
| 416 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | - } else { |
|
| 418 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | - $enum = range( |
|
| 423 | - array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum']), |
|
| 425 | - array_shift($this->command['enum']) |
|
| 426 | - ); |
|
| 427 | - } else { |
|
| 428 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | - } |
|
| 430 | - $this->tableau = $enum; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | - * {datapath query.results} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_datapath() { |
|
| 440 | - $base = reset($this->command['datapath']); |
|
| 441 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | - if (!is_array($this->tableau)) { |
|
| 444 | - $this->tableau = []; |
|
| 445 | - $this->err = true; |
|
| 446 | - spip_log("datapath '$base' absent"); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Ordonner les resultats |
|
| 453 | - * {par x} |
|
| 454 | - * |
|
| 455 | - **/ |
|
| 456 | - protected function select_orderby() { |
|
| 457 | - $sortfunc = ''; |
|
| 458 | - $aleas = 0; |
|
| 459 | - foreach ($this->command['orderby'] as $tri) { |
|
| 460 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | - $r = array_pad($r, 3, null); |
|
| 463 | - |
|
| 464 | - // tri par cle |
|
| 465 | - if ($r[1] == 'cle') { |
|
| 466 | - if (isset($r[2]) and $r[2]) { |
|
| 467 | - krsort($this->tableau); |
|
| 468 | - } else { |
|
| 469 | - ksort($this->tableau); |
|
| 470 | - } |
|
| 471 | - } # {par hasard} |
|
| 472 | - else { |
|
| 473 | - if ($r[1] == 'hasard') { |
|
| 474 | - $k = array_keys($this->tableau); |
|
| 475 | - shuffle($k); |
|
| 476 | - $v = []; |
|
| 477 | - foreach ($k as $cle) { |
|
| 478 | - $v[$cle] = $this->tableau[$cle]; |
|
| 479 | - } |
|
| 480 | - $this->tableau = $v; |
|
| 481 | - } else { |
|
| 482 | - # {par valeur} |
|
| 483 | - if ($r[1] == 'valeur') { |
|
| 484 | - $tv = '%s'; |
|
| 485 | - } # {par valeur/xx/yy} ?? |
|
| 486 | - else { |
|
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | - } |
|
| 489 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = []; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = []; |
|
| 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 = []) { |
|
| 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(): void { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = array_key_first($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 ['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( |
|
| 183 | + $cle, |
|
| 184 | + [ |
|
| 185 | + 'data' => $valeur, |
|
| 186 | + 'time' => time(), |
|
| 187 | + 'ttl' => $ttl |
|
| 188 | + ], |
|
| 189 | + 3600 + $ttl |
|
| 190 | + ); |
|
| 191 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Aller chercher les données de la boucle DATA |
|
| 197 | + * |
|
| 198 | + * @throws Exception |
|
| 199 | + * @param array $command |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function select($command) { |
|
| 203 | + |
|
| 204 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | + // le type se retrouve dans la commande 'from' |
|
| 206 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | + if (isset($this->command['from'][0])) { |
|
| 208 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | + } |
|
| 211 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | + // les commandes connues pour l'iterateur DATA |
|
| 216 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | + |
|
| 218 | + // {source format, [URL], [arg2]...} |
|
| 219 | + if ( |
|
| 220 | + isset($this->command['source']) |
|
| 221 | + and isset($this->command['sourcemode']) |
|
| 222 | + ) { |
|
| 223 | + $this->select_source(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Critere {liste X1, X2, X3} |
|
| 227 | + if (isset($this->command['liste'])) { |
|
| 228 | + $this->select_liste(); |
|
| 229 | + } |
|
| 230 | + if (isset($this->command['enum'])) { |
|
| 231 | + $this->select_enum(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | + if (!is_array($this->tableau)) { |
|
| 236 | + $this->err = true; |
|
| 237 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // {datapath query.results} |
|
| 241 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | + if ( |
|
| 243 | + !$this->err |
|
| 244 | + and isset($this->command['datapath']) |
|
| 245 | + and is_array($this->command['datapath']) |
|
| 246 | + ) { |
|
| 247 | + $this->select_datapath(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // tri {par x} |
|
| 251 | + if ($this->command['orderby']) { |
|
| 252 | + $this->select_orderby(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | + if ($this->command['groupby']) { |
|
| 257 | + $this->select_groupby(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $this->rewind(); |
|
| 261 | + #var_dump($this->tableau); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Aller chercher les donnees de la boucle DATA |
|
| 267 | + * depuis une source |
|
| 268 | + * {source format, [URL], [arg2]...} |
|
| 269 | + */ |
|
| 270 | + protected function select_source() { |
|
| 271 | + # un peu crado : avant de charger le cache il faut charger |
|
| 272 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | + # l'objet en cache ; cf plugins/icalendar |
|
| 274 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | + if ( |
|
| 276 | + isset($this->command['sourcemode']) |
|
| 277 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | + ) { |
|
| 279 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + # le premier argument peut etre un array, une URL etc. |
|
| 283 | + $src = $this->command['source'][0]; |
|
| 284 | + |
|
| 285 | + # avons-nous un cache dispo ? |
|
| 286 | + $cle = null; |
|
| 287 | + if (is_string($src)) { |
|
| 288 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $cache = $this->cache_get($cle); |
|
| 292 | + if (isset($this->command['datacache'])) { |
|
| 293 | + $ttl = intval($this->command['datacache']); |
|
| 294 | + } |
|
| 295 | + if ( |
|
| 296 | + $cache |
|
| 297 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | + > time()) |
|
| 299 | + and !(_request('var_mode') === 'recalcul' |
|
| 300 | + and include_spip('inc/autoriser') |
|
| 301 | + and autoriser('recalcul') |
|
| 302 | + ) |
|
| 303 | + ) { |
|
| 304 | + $this->tableau = $cache['data']; |
|
| 305 | + } else { |
|
| 306 | + try { |
|
| 307 | + if ( |
|
| 308 | + isset($this->command['sourcemode']) |
|
| 309 | + and in_array( |
|
| 310 | + $this->command['sourcemode'], |
|
| 311 | + ['table', 'array', 'tableau'] |
|
| 312 | + ) |
|
| 313 | + ) { |
|
| 314 | + if ( |
|
| 315 | + is_array($a = $src) |
|
| 316 | + or (is_string($a) |
|
| 317 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | + and is_array($a = @unserialize($a))) |
|
| 319 | + ) { |
|
| 320 | + $this->tableau = $a; |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + $data = $src; |
|
| 324 | + if (is_string($src)) { |
|
| 325 | + if (tester_url_absolue($src)) { |
|
| 326 | + include_spip('inc/distant'); |
|
| 327 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | + $data = $data['page'] ?? ''; |
|
| 329 | + if (!$data) { |
|
| 330 | + throw new Exception('404'); |
|
| 331 | + } |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 24 * 3600; |
|
| 334 | + } |
|
| 335 | + } elseif (@is_dir($src)) { |
|
| 336 | + $data = $src; |
|
| 337 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | + $data = spip_file_get_contents($src); |
|
| 339 | + } |
|
| 340 | + if (!isset($ttl)) { |
|
| 341 | + $ttl = 10; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( |
|
| 346 | + !$this->err |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | + ) { |
|
| 349 | + $args = $this->command['source']; |
|
| 350 | + $args[0] = $data; |
|
| 351 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | + $this->tableau = $a; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!is_array($this->tableau)) { |
|
| 358 | + $this->err = true; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | + $this->cache_set($cle, $ttl); |
|
| 363 | + } |
|
| 364 | + } catch (Exception $e) { |
|
| 365 | + $e = $e->getMessage(); |
|
| 366 | + $err = sprintf( |
|
| 367 | + "[%s, %s] $e", |
|
| 368 | + $src, |
|
| 369 | + $this->command['sourcemode'] |
|
| 370 | + ); |
|
| 371 | + erreur_squelette([$err, []]); |
|
| 372 | + $this->err = true; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | + if ( |
|
| 378 | + $this->err |
|
| 379 | + and $cache |
|
| 380 | + ) { |
|
| 381 | + $this->tableau = $cache['data']; |
|
| 382 | + $this->err = false; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Retourne un tableau donne depuis un critère liste |
|
| 389 | + * |
|
| 390 | + * Critère `{liste X1, X2, X3}` |
|
| 391 | + * |
|
| 392 | + * @see critere_DATA_liste_dist() |
|
| 393 | + * |
|
| 394 | + **/ |
|
| 395 | + protected function select_liste() { |
|
| 396 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | + if (!isset($this->command['liste'][1])) { |
|
| 398 | + if (!is_array($this->command['liste'][0])) { |
|
| 399 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | + } else { |
|
| 401 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + $this->tableau = $this->command['liste']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Retourne un tableau donne depuis un critere liste |
|
| 409 | + * Critere {enum Xmin, Xmax} |
|
| 410 | + * |
|
| 411 | + **/ |
|
| 412 | + protected function select_enum() { |
|
| 413 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | + if (!isset($this->command['enum'][1])) { |
|
| 415 | + if (!is_array($this->command['enum'][0])) { |
|
| 416 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | + } else { |
|
| 418 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | + $enum = range( |
|
| 423 | + array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum']), |
|
| 425 | + array_shift($this->command['enum']) |
|
| 426 | + ); |
|
| 427 | + } else { |
|
| 428 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | + } |
|
| 430 | + $this->tableau = $enum; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | + * {datapath query.results} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_datapath() { |
|
| 440 | + $base = reset($this->command['datapath']); |
|
| 441 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | + if (!is_array($this->tableau)) { |
|
| 444 | + $this->tableau = []; |
|
| 445 | + $this->err = true; |
|
| 446 | + spip_log("datapath '$base' absent"); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Ordonner les resultats |
|
| 453 | + * {par x} |
|
| 454 | + * |
|
| 455 | + **/ |
|
| 456 | + protected function select_orderby() { |
|
| 457 | + $sortfunc = ''; |
|
| 458 | + $aleas = 0; |
|
| 459 | + foreach ($this->command['orderby'] as $tri) { |
|
| 460 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | + $r = array_pad($r, 3, null); |
|
| 463 | + |
|
| 464 | + // tri par cle |
|
| 465 | + if ($r[1] == 'cle') { |
|
| 466 | + if (isset($r[2]) and $r[2]) { |
|
| 467 | + krsort($this->tableau); |
|
| 468 | + } else { |
|
| 469 | + ksort($this->tableau); |
|
| 470 | + } |
|
| 471 | + } # {par hasard} |
|
| 472 | + else { |
|
| 473 | + if ($r[1] == 'hasard') { |
|
| 474 | + $k = array_keys($this->tableau); |
|
| 475 | + shuffle($k); |
|
| 476 | + $v = []; |
|
| 477 | + foreach ($k as $cle) { |
|
| 478 | + $v[$cle] = $this->tableau[$cle]; |
|
| 479 | + } |
|
| 480 | + $this->tableau = $v; |
|
| 481 | + } else { |
|
| 482 | + # {par valeur} |
|
| 483 | + if ($r[1] == 'valeur') { |
|
| 484 | + $tv = '%s'; |
|
| 485 | + } # {par valeur/xx/yy} ?? |
|
| 486 | + else { |
|
| 487 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | + } |
|
| 489 | + $sortfunc .= ' |
|
| 490 | 490 | $a = ' . sprintf($tv, '$aa') . '; |
| 491 | 491 | $b = ' . sprintf($tv, '$bb') . '; |
| 492 | 492 | if ($a <> $b) |
| 493 | 493 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if ($sortfunc) { |
|
| 500 | - $sortfunc .= "\n return 0;"; |
|
| 501 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = []; |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid(): bool { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return mixed |
|
| 540 | - */ |
|
| 541 | - #[\ReturnTypeWillChange] |
|
| 542 | - public function current() { |
|
| 543 | - return $this->valeur; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Retourner la cle |
|
| 548 | - * |
|
| 549 | - * @return mixed |
|
| 550 | - */ |
|
| 551 | - #[\ReturnTypeWillChange] |
|
| 552 | - public function key() { |
|
| 553 | - return $this->cle; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Passer a la valeur suivante |
|
| 558 | - * |
|
| 559 | - * @return void |
|
| 560 | - */ |
|
| 561 | - public function next(): void { |
|
| 562 | - if ($this->valid()) { |
|
| 563 | - $this->cle = key($this->tableau); |
|
| 564 | - $this->valeur = current($this->tableau); |
|
| 565 | - next($this->tableau); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Compter le nombre total de resultats |
|
| 571 | - * |
|
| 572 | - * @return int |
|
| 573 | - */ |
|
| 574 | - public function count() { |
|
| 575 | - if (is_null($this->total)) { |
|
| 576 | - $this->total = count($this->tableau); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $this->total; |
|
| 580 | - } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if ($sortfunc) { |
|
| 500 | + $sortfunc .= "\n return 0;"; |
|
| 501 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = []; |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid(): bool { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return mixed |
|
| 540 | + */ |
|
| 541 | + #[\ReturnTypeWillChange] |
|
| 542 | + public function current() { |
|
| 543 | + return $this->valeur; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Retourner la cle |
|
| 548 | + * |
|
| 549 | + * @return mixed |
|
| 550 | + */ |
|
| 551 | + #[\ReturnTypeWillChange] |
|
| 552 | + public function key() { |
|
| 553 | + return $this->cle; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Passer a la valeur suivante |
|
| 558 | + * |
|
| 559 | + * @return void |
|
| 560 | + */ |
|
| 561 | + public function next(): void { |
|
| 562 | + if ($this->valid()) { |
|
| 563 | + $this->cle = key($this->tableau); |
|
| 564 | + $this->valeur = current($this->tableau); |
|
| 565 | + next($this->tableau); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Compter le nombre total de resultats |
|
| 571 | + * |
|
| 572 | + * @return int |
|
| 573 | + */ |
|
| 574 | + public function count() { |
|
| 575 | + if (is_null($this->total)) { |
|
| 576 | + $this->total = count($this->tableau); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $this->total; |
|
| 580 | + } |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /* |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | * @return array |
| 592 | 592 | */ |
| 593 | 593 | function inc_file_to_array_dist($data) { |
| 594 | - return preg_split('/\r?\n/', $data); |
|
| 594 | + return preg_split('/\r?\n/', $data); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,9 +600,9 @@ discard block |
||
| 600 | 600 | * @return array |
| 601 | 601 | */ |
| 602 | 602 | function inc_plugins_to_array_dist() { |
| 603 | - include_spip('inc/plugin'); |
|
| 603 | + include_spip('inc/plugin'); |
|
| 604 | 604 | |
| 605 | - return liste_chemin_plugin_actifs(); |
|
| 605 | + return liste_chemin_plugin_actifs(); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | * @return array |
| 613 | 613 | */ |
| 614 | 614 | function inc_xml_to_array_dist($data) { |
| 615 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 615 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -624,14 +624,14 @@ discard block |
||
| 624 | 624 | * |
| 625 | 625 | */ |
| 626 | 626 | function inc_object_to_array($object) { |
| 627 | - if (!is_object($object) && !is_array($object)) { |
|
| 628 | - return $object; |
|
| 629 | - } |
|
| 630 | - if (is_object($object)) { |
|
| 631 | - $object = get_object_vars($object); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - return array_map('inc_object_to_array', $object); |
|
| 627 | + if (!is_object($object) && !is_array($object)) { |
|
| 628 | + return $object; |
|
| 629 | + } |
|
| 630 | + if (is_object($object)) { |
|
| 631 | + $object = get_object_vars($object); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + return array_map('inc_object_to_array', $object); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -641,20 +641,20 @@ discard block |
||
| 641 | 641 | * @return array|bool |
| 642 | 642 | */ |
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | - # sortir le connecteur de $data |
|
| 645 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | - $serveur = (string)$v[1]; |
|
| 647 | - $req = trim($v[2]); |
|
| 648 | - if ($s = sql_query($req, $serveur)) { |
|
| 649 | - $r = []; |
|
| 650 | - while ($t = sql_fetch($s)) { |
|
| 651 | - $r[] = $t; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $r; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return false; |
|
| 644 | + # sortir le connecteur de $data |
|
| 645 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | + $serveur = (string)$v[1]; |
|
| 647 | + $req = trim($v[2]); |
|
| 648 | + if ($s = sql_query($req, $serveur)) { |
|
| 649 | + $r = []; |
|
| 650 | + while ($t = sql_fetch($s)) { |
|
| 651 | + $r[] = $t; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $r; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return false; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | * @return array|bool |
| 665 | 665 | */ |
| 666 | 666 | function inc_json_to_array_dist($data) { |
| 667 | - try { |
|
| 668 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | - } catch (JsonException $e) { |
|
| 670 | - $json = null; |
|
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | - } |
|
| 673 | - return is_array($json) ? (array) $json : []; |
|
| 667 | + try { |
|
| 668 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | + } catch (JsonException $e) { |
|
| 670 | + $json = null; |
|
| 671 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | + } |
|
| 673 | + return is_array($json) ? (array) $json : []; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
@@ -680,30 +680,30 @@ discard block |
||
| 680 | 680 | * @return array|bool |
| 681 | 681 | */ |
| 682 | 682 | function inc_csv_to_array_dist($data) { |
| 683 | - include_spip('inc/csv'); |
|
| 684 | - [$entete, $csv] = analyse_csv($data); |
|
| 685 | - array_unshift($csv, $entete); |
|
| 686 | - |
|
| 687 | - include_spip('inc/charsets'); |
|
| 688 | - $i = 1; |
|
| 689 | - foreach ($entete as $k => $v) { |
|
| 690 | - if (trim($v) == '') { |
|
| 691 | - $v = 'col' . $i; |
|
| 692 | - } // reperer des eventuelles cases vides |
|
| 693 | - if (is_numeric($v) and $v < 0) { |
|
| 694 | - $v = '__' . $v; |
|
| 695 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | - if (is_numeric($v)) { |
|
| 697 | - $v = '_' . $v; |
|
| 698 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | - foreach ($csv as &$item) { |
|
| 701 | - $item[$v] = &$item[$k]; |
|
| 702 | - } |
|
| 703 | - $i++; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - return $csv; |
|
| 683 | + include_spip('inc/csv'); |
|
| 684 | + [$entete, $csv] = analyse_csv($data); |
|
| 685 | + array_unshift($csv, $entete); |
|
| 686 | + |
|
| 687 | + include_spip('inc/charsets'); |
|
| 688 | + $i = 1; |
|
| 689 | + foreach ($entete as $k => $v) { |
|
| 690 | + if (trim($v) == '') { |
|
| 691 | + $v = 'col' . $i; |
|
| 692 | + } // reperer des eventuelles cases vides |
|
| 693 | + if (is_numeric($v) and $v < 0) { |
|
| 694 | + $v = '__' . $v; |
|
| 695 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | + if (is_numeric($v)) { |
|
| 697 | + $v = '_' . $v; |
|
| 698 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | + foreach ($csv as &$item) { |
|
| 701 | + $item[$v] = &$item[$k]; |
|
| 702 | + } |
|
| 703 | + $i++; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + return $csv; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -713,13 +713,13 @@ discard block |
||
| 713 | 713 | * @return array|bool |
| 714 | 714 | */ |
| 715 | 715 | function inc_rss_to_array_dist($data) { |
| 716 | - $tableau = null; |
|
| 717 | - include_spip('inc/syndic'); |
|
| 718 | - if (is_array($rss = analyser_backend($data))) { |
|
| 719 | - $tableau = $rss; |
|
| 720 | - } |
|
| 716 | + $tableau = null; |
|
| 717 | + include_spip('inc/syndic'); |
|
| 718 | + if (is_array($rss = analyser_backend($data))) { |
|
| 719 | + $tableau = $rss; |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - return $tableau; |
|
| 722 | + return $tableau; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -729,9 +729,9 @@ discard block |
||
| 729 | 729 | * @return array|bool |
| 730 | 730 | */ |
| 731 | 731 | function inc_atom_to_array_dist($data) { |
| 732 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 732 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 733 | 733 | |
| 734 | - return $rss_to_array($data); |
|
| 734 | + return $rss_to_array($data); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -742,12 +742,12 @@ discard block |
||
| 742 | 742 | * @return array|bool |
| 743 | 743 | */ |
| 744 | 744 | function inc_glob_to_array_dist($data) { |
| 745 | - $a = glob( |
|
| 746 | - $data, |
|
| 747 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | - ); |
|
| 745 | + $a = glob( |
|
| 746 | + $data, |
|
| 747 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | + ); |
|
| 749 | 749 | |
| 750 | - return $a ?: []; |
|
| 750 | + return $a ?: []; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | /** |
@@ -758,14 +758,14 @@ discard block |
||
| 758 | 758 | * @throws Exception |
| 759 | 759 | */ |
| 760 | 760 | function inc_yaml_to_array_dist($data) { |
| 761 | - include_spip('inc/yaml-mini'); |
|
| 762 | - if (!function_exists('yaml_decode')) { |
|
| 763 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 761 | + include_spip('inc/yaml-mini'); |
|
| 762 | + if (!function_exists('yaml_decode')) { |
|
| 763 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 764 | 764 | |
| 765 | - return false; |
|
| 766 | - } |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - return yaml_decode($data); |
|
| 768 | + return yaml_decode($data); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -792,23 +792,23 @@ discard block |
||
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
| 794 | 794 | function inc_ls_to_array_dist($data) { |
| 795 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | - $a = $glob_to_array($data); |
|
| 797 | - foreach ($a as &$v) { |
|
| 798 | - $b = (array)@stat($v); |
|
| 799 | - foreach ($b as $k => $ignore) { |
|
| 800 | - if (is_numeric($k)) { |
|
| 801 | - unset($b[$k]); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | - $v = array_merge( |
|
| 806 | - pathinfo($v), |
|
| 807 | - $b |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - return $a; |
|
| 795 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | + $a = $glob_to_array($data); |
|
| 797 | + foreach ($a as &$v) { |
|
| 798 | + $b = (array)@stat($v); |
|
| 799 | + foreach ($b as $k => $ignore) { |
|
| 800 | + if (is_numeric($k)) { |
|
| 801 | + unset($b[$k]); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | + $v = array_merge( |
|
| 806 | + pathinfo($v), |
|
| 807 | + $b |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + return $a; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -818,25 +818,25 @@ discard block |
||
| 818 | 818 | * @return array|bool |
| 819 | 819 | */ |
| 820 | 820 | function XMLObjectToArray($object) { |
| 821 | - $xml_array = []; |
|
| 822 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | - $key .= '-' . uniqid(); |
|
| 825 | - } |
|
| 826 | - $vars = get_object_vars($object->current()); |
|
| 827 | - if (isset($vars['@attributes'])) { |
|
| 828 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | - $xml_array[$key][$k] = $v; |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - if ($object->hasChildren()) { |
|
| 833 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | - $object->current() |
|
| 835 | - ); |
|
| 836 | - } else { |
|
| 837 | - $xml_array[$key][] = strval($object->current()); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - return $xml_array; |
|
| 821 | + $xml_array = []; |
|
| 822 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | + $key .= '-' . uniqid(); |
|
| 825 | + } |
|
| 826 | + $vars = get_object_vars($object->current()); |
|
| 827 | + if (isset($vars['@attributes'])) { |
|
| 828 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | + $xml_array[$key][$k] = $v; |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + if ($object->hasChildren()) { |
|
| 833 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | + $object->current() |
|
| 835 | + ); |
|
| 836 | + } else { |
|
| 837 | + $xml_array[$key][] = strval($object->current()); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + return $xml_array; |
|
| 842 | 842 | } |