@@ -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 | /** |
@@ -40,36 +40,36 @@ discard block |
||
| 40 | 40 | * Liste (identifiant de l'article, Texte d'erreur éventuel) |
| 41 | 41 | */ |
| 42 | 42 | function action_editer_article_dist($arg = null) { |
| 43 | - include_spip('inc/autoriser'); |
|
| 44 | - $err = ''; |
|
| 45 | - if (is_null($arg)) { |
|
| 46 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | - $arg = $securiser_action(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id_article = intval($arg)) { |
|
| 53 | - $id_parent = _request('id_parent'); |
|
| 54 | - if (!$id_parent) { |
|
| 55 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 56 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 57 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 58 | - } else { |
|
| 59 | - $id_article = article_inserer($id_parent); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Enregistre l'envoi dans la BD |
|
| 64 | - if ($id_article > 0) { |
|
| 65 | - $err = article_modifier($id_article); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($err) { |
|
| 69 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return [$id_article, $err]; |
|
| 43 | + include_spip('inc/autoriser'); |
|
| 44 | + $err = ''; |
|
| 45 | + if (is_null($arg)) { |
|
| 46 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | + $arg = $securiser_action(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id_article = intval($arg)) { |
|
| 53 | + $id_parent = _request('id_parent'); |
|
| 54 | + if (!$id_parent) { |
|
| 55 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 56 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 57 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 58 | + } else { |
|
| 59 | + $id_article = article_inserer($id_parent); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Enregistre l'envoi dans la BD |
|
| 64 | + if ($id_article > 0) { |
|
| 65 | + $err = article_modifier($id_article); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($err) { |
|
| 69 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return [$id_article, $err]; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -91,50 +91,50 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function article_modifier($id_article, $set = null) { |
| 93 | 93 | |
| 94 | - // unifier $texte en cas de texte trop long |
|
| 95 | - trop_longs_articles(); |
|
| 96 | - |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - include_spip('inc/filtres'); |
|
| 99 | - $c = collecter_requests( |
|
| 100 | - // white list |
|
| 101 | - objet_info('article', 'champs_editables'), |
|
| 102 | - // black list |
|
| 103 | - ['date', 'statut', 'id_parent'], |
|
| 104 | - // donnees eventuellement fournies |
|
| 105 | - $set |
|
| 106 | - ); |
|
| 107 | - |
|
| 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)); |
|
| 110 | - $invalideur = $indexation = false; |
|
| 111 | - if ($t == 'publie') { |
|
| 112 | - $invalideur = "id='article/$id_article'"; |
|
| 113 | - $indexation = true; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ( |
|
| 117 | - $err = objet_modifier_champs( |
|
| 118 | - 'article', |
|
| 119 | - $id_article, |
|
| 120 | - [ |
|
| 121 | - 'data' => $set, |
|
| 122 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 123 | - 'invalideur' => $invalideur, |
|
| 124 | - 'indexation' => $indexation, |
|
| 125 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 126 | - ], |
|
| 127 | - $c |
|
| 128 | - ) |
|
| 129 | - ) { |
|
| 130 | - return $err; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Modification de statut, changement de rubrique ? |
|
| 134 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 135 | - $err = article_instituer($id_article, $c); |
|
| 136 | - |
|
| 137 | - return $err; |
|
| 94 | + // unifier $texte en cas de texte trop long |
|
| 95 | + trop_longs_articles(); |
|
| 96 | + |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + include_spip('inc/filtres'); |
|
| 99 | + $c = collecter_requests( |
|
| 100 | + // white list |
|
| 101 | + objet_info('article', 'champs_editables'), |
|
| 102 | + // black list |
|
| 103 | + ['date', 'statut', 'id_parent'], |
|
| 104 | + // donnees eventuellement fournies |
|
| 105 | + $set |
|
| 106 | + ); |
|
| 107 | + |
|
| 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)); |
|
| 110 | + $invalideur = $indexation = false; |
|
| 111 | + if ($t == 'publie') { |
|
| 112 | + $invalideur = "id='article/$id_article'"; |
|
| 113 | + $indexation = true; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ( |
|
| 117 | + $err = objet_modifier_champs( |
|
| 118 | + 'article', |
|
| 119 | + $id_article, |
|
| 120 | + [ |
|
| 121 | + 'data' => $set, |
|
| 122 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 123 | + 'invalideur' => $invalideur, |
|
| 124 | + 'indexation' => $indexation, |
|
| 125 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 126 | + ], |
|
| 127 | + $c |
|
| 128 | + ) |
|
| 129 | + ) { |
|
| 130 | + return $err; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Modification de statut, changement de rubrique ? |
|
| 134 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 135 | + $err = article_instituer($id_article, $c); |
|
| 136 | + |
|
| 137 | + return $err; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -170,98 +170,98 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function article_inserer($id_rubrique, $set = null) { |
| 172 | 172 | |
| 173 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 174 | - // dans la premiere rubrique racine |
|
| 175 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 176 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 177 | - $id_rubrique = $row['id_rubrique']; |
|
| 178 | - } else { |
|
| 179 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 183 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 184 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 185 | - $lang_rub = $row['lang'] ?? ''; |
|
| 186 | - |
|
| 187 | - $lang = ''; |
|
| 188 | - $choisie = 'non'; |
|
| 189 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 190 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 191 | - // ou a defaut celle de la rubrique |
|
| 192 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 193 | - if ( |
|
| 194 | - !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 195 | - 'spip_articles', |
|
| 196 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 197 | - ) |
|
| 198 | - ) { |
|
| 199 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 200 | - if ( |
|
| 201 | - in_array( |
|
| 202 | - $GLOBALS['spip_lang'], |
|
| 203 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 204 | - ) |
|
| 205 | - ) { |
|
| 206 | - $lang = $GLOBALS['spip_lang']; |
|
| 207 | - $choisie = 'oui'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!$lang) { |
|
| 212 | - $choisie = 'non'; |
|
| 213 | - $lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $champs = [ |
|
| 217 | - 'id_rubrique' => $id_rubrique, |
|
| 218 | - 'id_secteur' => $id_secteur, |
|
| 219 | - 'statut' => 'prepa', |
|
| 220 | - 'date' => date('Y-m-d H:i:s'), |
|
| 221 | - 'lang' => $lang, |
|
| 222 | - 'langue_choisie' => $choisie |
|
| 223 | - ]; |
|
| 224 | - |
|
| 225 | - if ($set) { |
|
| 226 | - $champs = array_merge($champs, $set); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Envoyer aux plugins |
|
| 230 | - $champs = pipeline( |
|
| 231 | - 'pre_insertion', |
|
| 232 | - [ |
|
| 233 | - 'args' => [ |
|
| 234 | - 'table' => 'spip_articles', |
|
| 235 | - ], |
|
| 236 | - 'data' => $champs |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 241 | - |
|
| 242 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 243 | - if ($id_article > 0) { |
|
| 244 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 245 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 246 | - : _request('id_auteur')); |
|
| 247 | - if ($id_auteur) { |
|
| 248 | - include_spip('action/editer_auteur'); |
|
| 249 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - pipeline( |
|
| 254 | - 'post_insertion', |
|
| 255 | - [ |
|
| 256 | - 'args' => [ |
|
| 257 | - 'table' => 'spip_articles', |
|
| 258 | - 'id_objet' => $id_article |
|
| 259 | - ], |
|
| 260 | - 'data' => $champs |
|
| 261 | - ] |
|
| 262 | - ); |
|
| 263 | - |
|
| 264 | - return $id_article; |
|
| 173 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 174 | + // dans la premiere rubrique racine |
|
| 175 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 176 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 177 | + $id_rubrique = $row['id_rubrique']; |
|
| 178 | + } else { |
|
| 179 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 183 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 184 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 185 | + $lang_rub = $row['lang'] ?? ''; |
|
| 186 | + |
|
| 187 | + $lang = ''; |
|
| 188 | + $choisie = 'non'; |
|
| 189 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 190 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 191 | + // ou a defaut celle de la rubrique |
|
| 192 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 193 | + if ( |
|
| 194 | + !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 195 | + 'spip_articles', |
|
| 196 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 197 | + ) |
|
| 198 | + ) { |
|
| 199 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 200 | + if ( |
|
| 201 | + in_array( |
|
| 202 | + $GLOBALS['spip_lang'], |
|
| 203 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 204 | + ) |
|
| 205 | + ) { |
|
| 206 | + $lang = $GLOBALS['spip_lang']; |
|
| 207 | + $choisie = 'oui'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!$lang) { |
|
| 212 | + $choisie = 'non'; |
|
| 213 | + $lang = $lang_rub ? $lang_rub : $GLOBALS['meta']['langue_site']; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $champs = [ |
|
| 217 | + 'id_rubrique' => $id_rubrique, |
|
| 218 | + 'id_secteur' => $id_secteur, |
|
| 219 | + 'statut' => 'prepa', |
|
| 220 | + 'date' => date('Y-m-d H:i:s'), |
|
| 221 | + 'lang' => $lang, |
|
| 222 | + 'langue_choisie' => $choisie |
|
| 223 | + ]; |
|
| 224 | + |
|
| 225 | + if ($set) { |
|
| 226 | + $champs = array_merge($champs, $set); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Envoyer aux plugins |
|
| 230 | + $champs = pipeline( |
|
| 231 | + 'pre_insertion', |
|
| 232 | + [ |
|
| 233 | + 'args' => [ |
|
| 234 | + 'table' => 'spip_articles', |
|
| 235 | + ], |
|
| 236 | + 'data' => $champs |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 241 | + |
|
| 242 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 243 | + if ($id_article > 0) { |
|
| 244 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 245 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 246 | + : _request('id_auteur')); |
|
| 247 | + if ($id_auteur) { |
|
| 248 | + include_spip('action/editer_auteur'); |
|
| 249 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + pipeline( |
|
| 254 | + 'post_insertion', |
|
| 255 | + [ |
|
| 256 | + 'args' => [ |
|
| 257 | + 'table' => 'spip_articles', |
|
| 258 | + 'id_objet' => $id_article |
|
| 259 | + ], |
|
| 260 | + 'data' => $champs |
|
| 261 | + ] |
|
| 262 | + ); |
|
| 263 | + |
|
| 264 | + return $id_article; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -289,125 +289,125 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 291 | 291 | |
| 292 | - include_spip('inc/autoriser'); |
|
| 293 | - include_spip('inc/rubriques'); |
|
| 294 | - include_spip('inc/modifier'); |
|
| 295 | - |
|
| 296 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 297 | - $id_rubrique = $row['id_rubrique']; |
|
| 298 | - $statut_ancien = $statut = $row['statut']; |
|
| 299 | - $date_ancienne = $date = $row['date']; |
|
| 300 | - $champs = []; |
|
| 301 | - |
|
| 302 | - $d = $c['date'] ?? null; |
|
| 303 | - $s = $c['statut'] ?? $statut; |
|
| 304 | - |
|
| 305 | - // cf autorisations dans inc/instituer_article |
|
| 306 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 307 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 308 | - $statut = $champs['statut'] = $s; |
|
| 309 | - } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 310 | - $statut = $champs['statut'] = $s; |
|
| 311 | - } else { |
|
| 312 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // En cas de publication, fixer la date a "maintenant" |
|
| 316 | - // sauf si $c commande autre chose |
|
| 317 | - // ou si l'article est deja date dans le futur |
|
| 318 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 319 | - if ( |
|
| 320 | - $champs['statut'] == 'publie' |
|
| 321 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 322 | - ) { |
|
| 323 | - if ($d or strtotime($d = $date) > time()) { |
|
| 324 | - $champs['date'] = $date = $d; |
|
| 325 | - } else { |
|
| 326 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // Verifier que la rubrique demandee existe et est differente |
|
| 332 | - // de la rubrique actuelle |
|
| 333 | - if ( |
|
| 334 | - isset($c['id_parent']) |
|
| 335 | - and $id_parent = $c['id_parent'] |
|
| 336 | - and $id_parent != $id_rubrique |
|
| 337 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 338 | - ) { |
|
| 339 | - $champs['id_rubrique'] = $id_parent; |
|
| 340 | - |
|
| 341 | - // si l'article etait publie |
|
| 342 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 343 | - // repasser l'article en statut 'propose'. |
|
| 344 | - if ( |
|
| 345 | - $statut == 'publie' |
|
| 346 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 347 | - ) { |
|
| 348 | - $champs['statut'] = 'prop'; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // Envoyer aux plugins |
|
| 353 | - $champs = pipeline( |
|
| 354 | - 'pre_edition', |
|
| 355 | - [ |
|
| 356 | - 'args' => [ |
|
| 357 | - 'table' => 'spip_articles', |
|
| 358 | - 'id_objet' => $id_article, |
|
| 359 | - 'action' => 'instituer', |
|
| 360 | - 'statut_ancien' => $statut_ancien, |
|
| 361 | - 'date_ancienne' => $date_ancienne, |
|
| 362 | - ], |
|
| 363 | - 'data' => $champs |
|
| 364 | - ] |
|
| 365 | - ); |
|
| 366 | - |
|
| 367 | - if (!count($champs)) { |
|
| 368 | - return ''; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // Envoyer les modifs. |
|
| 372 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 373 | - |
|
| 374 | - // Invalider les caches |
|
| 375 | - include_spip('inc/invalideur'); |
|
| 376 | - suivre_invalideur("id='article/$id_article'"); |
|
| 377 | - |
|
| 378 | - if ($date) { |
|
| 379 | - $t = strtotime($date); |
|
| 380 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 381 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 382 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - // Pipeline |
|
| 387 | - pipeline( |
|
| 388 | - 'post_edition', |
|
| 389 | - [ |
|
| 390 | - 'args' => [ |
|
| 391 | - 'table' => 'spip_articles', |
|
| 392 | - 'id_objet' => $id_article, |
|
| 393 | - 'action' => 'instituer', |
|
| 394 | - 'statut_ancien' => $statut_ancien, |
|
| 395 | - 'date_ancienne' => $date_ancienne, |
|
| 396 | - ], |
|
| 397 | - 'data' => $champs |
|
| 398 | - ] |
|
| 399 | - ); |
|
| 400 | - |
|
| 401 | - // Notifications |
|
| 402 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 403 | - $notifications( |
|
| 404 | - 'instituerarticle', |
|
| 405 | - $id_article, |
|
| 406 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return ''; // pas d'erreur |
|
| 292 | + include_spip('inc/autoriser'); |
|
| 293 | + include_spip('inc/rubriques'); |
|
| 294 | + include_spip('inc/modifier'); |
|
| 295 | + |
|
| 296 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 297 | + $id_rubrique = $row['id_rubrique']; |
|
| 298 | + $statut_ancien = $statut = $row['statut']; |
|
| 299 | + $date_ancienne = $date = $row['date']; |
|
| 300 | + $champs = []; |
|
| 301 | + |
|
| 302 | + $d = $c['date'] ?? null; |
|
| 303 | + $s = $c['statut'] ?? $statut; |
|
| 304 | + |
|
| 305 | + // cf autorisations dans inc/instituer_article |
|
| 306 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 307 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 308 | + $statut = $champs['statut'] = $s; |
|
| 309 | + } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 310 | + $statut = $champs['statut'] = $s; |
|
| 311 | + } else { |
|
| 312 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // En cas de publication, fixer la date a "maintenant" |
|
| 316 | + // sauf si $c commande autre chose |
|
| 317 | + // ou si l'article est deja date dans le futur |
|
| 318 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 319 | + if ( |
|
| 320 | + $champs['statut'] == 'publie' |
|
| 321 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 322 | + ) { |
|
| 323 | + if ($d or strtotime($d = $date) > time()) { |
|
| 324 | + $champs['date'] = $date = $d; |
|
| 325 | + } else { |
|
| 326 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // Verifier que la rubrique demandee existe et est differente |
|
| 332 | + // de la rubrique actuelle |
|
| 333 | + if ( |
|
| 334 | + isset($c['id_parent']) |
|
| 335 | + and $id_parent = $c['id_parent'] |
|
| 336 | + and $id_parent != $id_rubrique |
|
| 337 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 338 | + ) { |
|
| 339 | + $champs['id_rubrique'] = $id_parent; |
|
| 340 | + |
|
| 341 | + // si l'article etait publie |
|
| 342 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 343 | + // repasser l'article en statut 'propose'. |
|
| 344 | + if ( |
|
| 345 | + $statut == 'publie' |
|
| 346 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 347 | + ) { |
|
| 348 | + $champs['statut'] = 'prop'; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // Envoyer aux plugins |
|
| 353 | + $champs = pipeline( |
|
| 354 | + 'pre_edition', |
|
| 355 | + [ |
|
| 356 | + 'args' => [ |
|
| 357 | + 'table' => 'spip_articles', |
|
| 358 | + 'id_objet' => $id_article, |
|
| 359 | + 'action' => 'instituer', |
|
| 360 | + 'statut_ancien' => $statut_ancien, |
|
| 361 | + 'date_ancienne' => $date_ancienne, |
|
| 362 | + ], |
|
| 363 | + 'data' => $champs |
|
| 364 | + ] |
|
| 365 | + ); |
|
| 366 | + |
|
| 367 | + if (!count($champs)) { |
|
| 368 | + return ''; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // Envoyer les modifs. |
|
| 372 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 373 | + |
|
| 374 | + // Invalider les caches |
|
| 375 | + include_spip('inc/invalideur'); |
|
| 376 | + suivre_invalideur("id='article/$id_article'"); |
|
| 377 | + |
|
| 378 | + if ($date) { |
|
| 379 | + $t = strtotime($date); |
|
| 380 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 381 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 382 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + // Pipeline |
|
| 387 | + pipeline( |
|
| 388 | + 'post_edition', |
|
| 389 | + [ |
|
| 390 | + 'args' => [ |
|
| 391 | + 'table' => 'spip_articles', |
|
| 392 | + 'id_objet' => $id_article, |
|
| 393 | + 'action' => 'instituer', |
|
| 394 | + 'statut_ancien' => $statut_ancien, |
|
| 395 | + 'date_ancienne' => $date_ancienne, |
|
| 396 | + ], |
|
| 397 | + 'data' => $champs |
|
| 398 | + ] |
|
| 399 | + ); |
|
| 400 | + |
|
| 401 | + // Notifications |
|
| 402 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 403 | + $notifications( |
|
| 404 | + 'instituerarticle', |
|
| 405 | + $id_article, |
|
| 406 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return ''; // pas d'erreur |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -432,37 +432,37 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 434 | 434 | |
| 435 | - // Si on deplace l'article |
|
| 436 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 437 | - if (isset($champs['id_rubrique'])) { |
|
| 438 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 439 | - |
|
| 440 | - $langue = $row_rub['lang']; |
|
| 441 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 442 | - if ( |
|
| 443 | - sql_fetsel( |
|
| 444 | - '1', |
|
| 445 | - 'spip_articles', |
|
| 446 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 447 | - ) |
|
| 448 | - ) { |
|
| 449 | - $champs['lang'] = $langue; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - if (!$champs) { |
|
| 454 | - return; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 458 | - |
|
| 459 | - // Changer le statut des rubriques concernees |
|
| 460 | - |
|
| 461 | - if ($cond) { |
|
| 462 | - include_spip('inc/rubriques'); |
|
| 463 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 464 | - calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 465 | - } |
|
| 435 | + // Si on deplace l'article |
|
| 436 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 437 | + if (isset($champs['id_rubrique'])) { |
|
| 438 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 439 | + |
|
| 440 | + $langue = $row_rub['lang']; |
|
| 441 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 442 | + if ( |
|
| 443 | + sql_fetsel( |
|
| 444 | + '1', |
|
| 445 | + 'spip_articles', |
|
| 446 | + 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 447 | + ) |
|
| 448 | + ) { |
|
| 449 | + $champs['lang'] = $langue; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + if (!$champs) { |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 458 | + |
|
| 459 | + // Changer le statut des rubriques concernees |
|
| 460 | + |
|
| 461 | + if ($cond) { |
|
| 462 | + include_spip('inc/rubriques'); |
|
| 463 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 464 | + calculer_rubriques_if($id_rubrique, $champs, $statut, $postdate); |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -471,10 +471,10 @@ discard block |
||
| 471 | 471 | * @return void |
| 472 | 472 | */ |
| 473 | 473 | function trop_longs_articles() { |
| 474 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 475 | - foreach ($plus as $n => $t) { |
|
| 476 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 477 | - } |
|
| 478 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 479 | - } |
|
| 474 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 475 | + foreach ($plus as $n => $t) { |
|
| 476 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 477 | + } |
|
| 478 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 479 | + } |
|
| 480 | 480 | } |
@@ -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 | include_spip('inc/actions'); |
@@ -33,93 +33,93 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | 35 | function action_cookie_dist($set_cookie_admin = null, $change_session = null) { |
| 36 | - $redirect_echec = $redirect = null; |
|
| 37 | - $test_echec_cookie = null; |
|
| 38 | - $url = ''; |
|
| 39 | - if (is_null($set_cookie_admin)) { |
|
| 40 | - $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | - $change_session = _request('change_session'); |
|
| 42 | - $test_echec_cookie = _request('test_echec_cookie'); |
|
| 36 | + $redirect_echec = $redirect = null; |
|
| 37 | + $test_echec_cookie = null; |
|
| 38 | + $url = ''; |
|
| 39 | + if (is_null($set_cookie_admin)) { |
|
| 40 | + $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | + $change_session = _request('change_session'); |
|
| 42 | + $test_echec_cookie = _request('test_echec_cookie'); |
|
| 43 | 43 | |
| 44 | - // La cible de notre operation de connexion |
|
| 45 | - $url = securiser_redirect_action(_request('url')); |
|
| 46 | - $redirect = $url ? $url : generer_url_ecrire('accueil'); |
|
| 47 | - $redirect_echec = _request('url_echec'); |
|
| 48 | - if (!isset($redirect_echec)) { |
|
| 49 | - if (strpos($redirect, _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | - $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | - } else { |
|
| 52 | - $redirect_echec = $redirect; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 44 | + // La cible de notre operation de connexion |
|
| 45 | + $url = securiser_redirect_action(_request('url')); |
|
| 46 | + $redirect = $url ? $url : generer_url_ecrire('accueil'); |
|
| 47 | + $redirect_echec = _request('url_echec'); |
|
| 48 | + if (!isset($redirect_echec)) { |
|
| 49 | + if (strpos($redirect, _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | + $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | + } else { |
|
| 52 | + $redirect_echec = $redirect; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - // rejoue le cookie pour renouveler spip_session |
|
| 59 | - if ($change_session == 'oui') { |
|
| 60 | - $session = charger_fonction('session', 'inc'); |
|
| 61 | - $session(true); |
|
| 62 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | - http_response_code(204); // No Content |
|
| 64 | - return; |
|
| 65 | - } |
|
| 58 | + // rejoue le cookie pour renouveler spip_session |
|
| 59 | + if ($change_session == 'oui') { |
|
| 60 | + $session = charger_fonction('session', 'inc'); |
|
| 61 | + $session(true); |
|
| 62 | + spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | + http_response_code(204); // No Content |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // tentative de connexion en auth_http |
|
| 68 | - if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | - include_spip('inc/auth'); |
|
| 70 | - if ( |
|
| 71 | - @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | - and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | - and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | - ) { |
|
| 75 | - auth_loger($auteur); |
|
| 76 | - redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | - } else { |
|
| 78 | - ask_php_auth( |
|
| 79 | - _T('info_connexion_refusee'), |
|
| 80 | - _T('login_login_pass_incorrect'), |
|
| 81 | - _T('login_retour_site'), |
|
| 82 | - 'url=' . rawurlencode($redirect), |
|
| 83 | - _T('login_nouvelle_tentative'), |
|
| 84 | - (strpos($url, _DIR_RESTREINT_ABS) !== false) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | - // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | - // le cas echeant. |
|
| 91 | - if ($test_echec_cookie == 'oui') { |
|
| 92 | - spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | - if ($redirect) { |
|
| 94 | - $redirect = parametre_url( |
|
| 95 | - parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | - 'url', |
|
| 97 | - rawurlencode($redirect), |
|
| 98 | - '&' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - } else { |
|
| 102 | - $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | - // Suppression cookie d'admin ? |
|
| 104 | - if ($set_cookie_admin == 'non') { |
|
| 105 | - if ($cook) { |
|
| 106 | - spip_setcookie('spip_admin', $cook, [ |
|
| 107 | - 'expires' => time() - 3600 * 24 |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 110 | - } // Ajout de cookie d'admin |
|
| 111 | - else { |
|
| 112 | - if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | - spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | - ]); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 67 | + // tentative de connexion en auth_http |
|
| 68 | + if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | + include_spip('inc/auth'); |
|
| 70 | + if ( |
|
| 71 | + @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | + and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | + and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | + ) { |
|
| 75 | + auth_loger($auteur); |
|
| 76 | + redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | + } else { |
|
| 78 | + ask_php_auth( |
|
| 79 | + _T('info_connexion_refusee'), |
|
| 80 | + _T('login_login_pass_incorrect'), |
|
| 81 | + _T('login_retour_site'), |
|
| 82 | + 'url=' . rawurlencode($redirect), |
|
| 83 | + _T('login_nouvelle_tentative'), |
|
| 84 | + (strpos($url, _DIR_RESTREINT_ABS) !== false) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | + // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | + // le cas echeant. |
|
| 91 | + if ($test_echec_cookie == 'oui') { |
|
| 92 | + spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | + if ($redirect) { |
|
| 94 | + $redirect = parametre_url( |
|
| 95 | + parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | + 'url', |
|
| 97 | + rawurlencode($redirect), |
|
| 98 | + '&' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + } else { |
|
| 102 | + $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | + // Suppression cookie d'admin ? |
|
| 104 | + if ($set_cookie_admin == 'non') { |
|
| 105 | + if ($cook) { |
|
| 106 | + spip_setcookie('spip_admin', $cook, [ |
|
| 107 | + 'expires' => time() - 3600 * 24 |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | + } // Ajout de cookie d'admin |
|
| 111 | + else { |
|
| 112 | + if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | + spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | + ]); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - // Redirection finale |
|
| 122 | - if ($redirect) { |
|
| 123 | - redirige_par_entete($redirect, true); |
|
| 124 | - } |
|
| 121 | + // Redirection finale |
|
| 122 | + if ($redirect) { |
|
| 123 | + redirige_par_entete($redirect, true); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, string $connect = '') { |
| 60 | - static $cache_quete = []; |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if ( |
|
| 66 | - !$desc = $trouver_table( |
|
| 67 | - $table, |
|
| 68 | - $connect |
|
| 69 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | - ) { |
|
| 71 | - // pas de parent rubrique, on passe |
|
| 72 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | - } else { |
|
| 74 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | - $cache_quete[$connect][$table]['_select'], |
|
| 83 | - $table, |
|
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - '', |
|
| 89 | - $connect |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 60 | + static $cache_quete = []; |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if ( |
|
| 66 | + !$desc = $trouver_table( |
|
| 67 | + $table, |
|
| 68 | + $connect |
|
| 69 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | + ) { |
|
| 71 | + // pas de parent rubrique, on passe |
|
| 72 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | + } else { |
|
| 74 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | + $cache_quete[$connect][$table]['_select'], |
|
| 83 | + $table, |
|
| 84 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + '', |
|
| 89 | + $connect |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | function quete_parent($id_rubrique, string $connect = '') { |
| 111 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | - return 0; |
|
| 113 | - } |
|
| 114 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 111 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | function quete_rubrique($id_article, $serveur) { |
| 131 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 132 | 132 | |
| 133 | - return $id_parent['id_rubrique']; |
|
| 133 | + return $id_parent['id_rubrique']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * @return int |
| 145 | 145 | */ |
| 146 | 146 | function quete_profondeur($id, string $connect = '') { |
| 147 | - $n = 0; |
|
| 148 | - while ($id) { |
|
| 149 | - $n++; |
|
| 150 | - $id = quete_parent($id, $connect); |
|
| 151 | - } |
|
| 147 | + $n = 0; |
|
| 148 | + while ($id) { |
|
| 149 | + $n++; |
|
| 150 | + $id = quete_parent($id, $connect); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $n; |
|
| 153 | + return $n; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * Morceau de la requête SQL testant la date |
| 167 | 167 | */ |
| 168 | 168 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 169 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | - return '1=1'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return |
|
| 174 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | - : '1=1'; |
|
| 169 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | + return '1=1'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return |
|
| 174 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | + : '1=1'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -194,101 +194,101 @@ discard block |
||
| 194 | 194 | * @return array|string |
| 195 | 195 | */ |
| 196 | 196 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 197 | - static $cond = []; |
|
| 198 | - $key = func_get_args(); |
|
| 199 | - $key = implode('-', $key); |
|
| 200 | - if (isset($cond[$key])) { |
|
| 201 | - return $cond[$key]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $liste_statuts = $publie; |
|
| 205 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | - $liste_statuts = $previsu; |
|
| 207 | - } |
|
| 208 | - $not = false; |
|
| 209 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | - $not = true; |
|
| 211 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | - } |
|
| 213 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | - if (!strlen($liste_statuts)) { |
|
| 215 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | - $where = []; |
|
| 220 | - foreach ($liste_statuts as $k => $v) { |
|
| 221 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | - // a ceux de l'auteur identifie |
|
| 223 | - if (strpos($v, '/') !== false) { |
|
| 224 | - $v = explode('/', $v); |
|
| 225 | - $filtre = end($v); |
|
| 226 | - $v = reset($v); |
|
| 227 | - $v = preg_replace(',\W,', '', $v); |
|
| 228 | - if ( |
|
| 229 | - $filtre == 'auteur' |
|
| 230 | - and (strpos($mstatut, '.') !== false) |
|
| 231 | - and $objet = explode('.', $mstatut) |
|
| 232 | - and $id_table = reset($objet) |
|
| 233 | - and $objet = objet_type($id_table) |
|
| 234 | - ) { |
|
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | - |
|
| 237 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | - // sinon l’auteur en session |
|
| 239 | - include_spip('inc/securiser_action'); |
|
| 240 | - if ($desc = decrire_token_previsu()) { |
|
| 241 | - $id_auteur = $desc['id_auteur']; |
|
| 242 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | - } else { |
|
| 245 | - $id_auteur = null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | - if (!$id_auteur) { |
|
| 252 | - $where[] = $w; |
|
| 253 | - } else { |
|
| 254 | - $primary = id_table_objet($objet); |
|
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | - 'ssss.id_objet', |
|
| 257 | - 'spip_auteurs_liens AS ssss', |
|
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - '', |
|
| 263 | - $serveur |
|
| 264 | - ) . '))'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | - else { |
|
| 269 | - $v = ''; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // securite |
|
| 273 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | - } |
|
| 275 | - $liste_statuts = array_filter($liste_statuts); |
|
| 276 | - if (count($liste_statuts) == 1) { |
|
| 277 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | - } else { |
|
| 279 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - while (count($where) > 1) { |
|
| 283 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | - $where[] = $and; |
|
| 285 | - } |
|
| 286 | - $cond[$key] = reset($where); |
|
| 287 | - if ($not) { |
|
| 288 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $cond[$key]; |
|
| 197 | + static $cond = []; |
|
| 198 | + $key = func_get_args(); |
|
| 199 | + $key = implode('-', $key); |
|
| 200 | + if (isset($cond[$key])) { |
|
| 201 | + return $cond[$key]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $liste_statuts = $publie; |
|
| 205 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | + $liste_statuts = $previsu; |
|
| 207 | + } |
|
| 208 | + $not = false; |
|
| 209 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | + $not = true; |
|
| 211 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | + } |
|
| 213 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | + if (!strlen($liste_statuts)) { |
|
| 215 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | + $where = []; |
|
| 220 | + foreach ($liste_statuts as $k => $v) { |
|
| 221 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | + // a ceux de l'auteur identifie |
|
| 223 | + if (strpos($v, '/') !== false) { |
|
| 224 | + $v = explode('/', $v); |
|
| 225 | + $filtre = end($v); |
|
| 226 | + $v = reset($v); |
|
| 227 | + $v = preg_replace(',\W,', '', $v); |
|
| 228 | + if ( |
|
| 229 | + $filtre == 'auteur' |
|
| 230 | + and (strpos($mstatut, '.') !== false) |
|
| 231 | + and $objet = explode('.', $mstatut) |
|
| 232 | + and $id_table = reset($objet) |
|
| 233 | + and $objet = objet_type($id_table) |
|
| 234 | + ) { |
|
| 235 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | + |
|
| 237 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | + // sinon l’auteur en session |
|
| 239 | + include_spip('inc/securiser_action'); |
|
| 240 | + if ($desc = decrire_token_previsu()) { |
|
| 241 | + $id_auteur = $desc['id_auteur']; |
|
| 242 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | + } else { |
|
| 245 | + $id_auteur = null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | + if (!$id_auteur) { |
|
| 252 | + $where[] = $w; |
|
| 253 | + } else { |
|
| 254 | + $primary = id_table_objet($objet); |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | + 'ssss.id_objet', |
|
| 257 | + 'spip_auteurs_liens AS ssss', |
|
| 258 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + '', |
|
| 263 | + $serveur |
|
| 264 | + ) . '))'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | + else { |
|
| 269 | + $v = ''; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // securite |
|
| 273 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | + } |
|
| 275 | + $liste_statuts = array_filter($liste_statuts); |
|
| 276 | + if (count($liste_statuts) == 1) { |
|
| 277 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | + } else { |
|
| 279 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + while (count($where) > 1) { |
|
| 283 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | + $where[] = $and; |
|
| 285 | + } |
|
| 286 | + $cond[$key] = reset($where); |
|
| 287 | + if ($not) { |
|
| 288 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $cond[$key]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -347,66 +347,66 @@ discard block |
||
| 347 | 347 | * Retourne soit un tableau, soit le chemin du fichier. |
| 348 | 348 | */ |
| 349 | 349 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 350 | - include_spip('base/objets'); |
|
| 351 | - $nom = strtolower($onoff); |
|
| 352 | - |
|
| 353 | - $cle_objet = id_table_objet($cle_objet); |
|
| 354 | - |
|
| 355 | - while (1) { |
|
| 356 | - $objet = objet_type($cle_objet); |
|
| 357 | - |
|
| 358 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | - |
|
| 360 | - if ($on) { |
|
| 361 | - if ($flag) { |
|
| 362 | - return basename($on['chemin']); |
|
| 363 | - } else { |
|
| 364 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | - |
|
| 366 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | - // alors on ne cherche pas du tout le survol ici |
|
| 369 | - if ($onoff != 'ON') { |
|
| 370 | - $off = ''; |
|
| 371 | - } else { |
|
| 372 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | - // qui permet de distinguer le changement de logo |
|
| 378 | - // et placer un expire sur le dossier IMG/ |
|
| 379 | - $res = [ |
|
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | - ]; |
|
| 384 | - $res['src'] = $res[0]; |
|
| 385 | - $res['logo_on'] = $res[0]; |
|
| 386 | - $res['logo_off'] = $res[1]; |
|
| 387 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | - |
|
| 390 | - return $res; |
|
| 391 | - } |
|
| 392 | - } else { |
|
| 393 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | - return ''; |
|
| 395 | - } else { |
|
| 396 | - if ($id_rubrique) { |
|
| 397 | - $cle_objet = 'id_rubrique'; |
|
| 398 | - $id = $id_rubrique; |
|
| 399 | - $id_rubrique = 0; |
|
| 400 | - } else { |
|
| 401 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | - $id = quete_parent($id); |
|
| 403 | - } else { |
|
| 404 | - return ''; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 350 | + include_spip('base/objets'); |
|
| 351 | + $nom = strtolower($onoff); |
|
| 352 | + |
|
| 353 | + $cle_objet = id_table_objet($cle_objet); |
|
| 354 | + |
|
| 355 | + while (1) { |
|
| 356 | + $objet = objet_type($cle_objet); |
|
| 357 | + |
|
| 358 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | + |
|
| 360 | + if ($on) { |
|
| 361 | + if ($flag) { |
|
| 362 | + return basename($on['chemin']); |
|
| 363 | + } else { |
|
| 364 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | + |
|
| 366 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | + // alors on ne cherche pas du tout le survol ici |
|
| 369 | + if ($onoff != 'ON') { |
|
| 370 | + $off = ''; |
|
| 371 | + } else { |
|
| 372 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | + // qui permet de distinguer le changement de logo |
|
| 378 | + // et placer un expire sur le dossier IMG/ |
|
| 379 | + $res = [ |
|
| 380 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | + ]; |
|
| 384 | + $res['src'] = $res[0]; |
|
| 385 | + $res['logo_on'] = $res[0]; |
|
| 386 | + $res['logo_off'] = $res[1]; |
|
| 387 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | + |
|
| 390 | + return $res; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | + return ''; |
|
| 395 | + } else { |
|
| 396 | + if ($id_rubrique) { |
|
| 397 | + $cle_objet = 'id_rubrique'; |
|
| 398 | + $id = $id_rubrique; |
|
| 399 | + $id_rubrique = 0; |
|
| 400 | + } else { |
|
| 401 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | + $id = quete_parent($id); |
|
| 403 | + } else { |
|
| 404 | + return ''; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,37 +420,37 @@ discard block |
||
| 420 | 420 | * "on" ou "off" suivant le logo normal ou survol |
| 421 | 421 | **/ |
| 422 | 422 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 423 | - static $chercher_logo; |
|
| 424 | - if (is_null($chercher_logo)) { |
|
| 425 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | - } |
|
| 427 | - $cle_objet = id_table_objet($objet); |
|
| 428 | - |
|
| 429 | - // On cherche pas la méthode classique |
|
| 430 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | - if (!empty($infos_logo)) { |
|
| 433 | - $infos_logo = [ |
|
| 434 | - 'chemin' => $infos_logo[0], |
|
| 435 | - 'timestamp' => $infos_logo[4], |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // On passe cette recherche de logo dans un pipeline |
|
| 440 | - $infos_logo = pipeline( |
|
| 441 | - 'quete_logo_objet', |
|
| 442 | - [ |
|
| 443 | - 'args' => [ |
|
| 444 | - 'id_objet' => $id_objet, |
|
| 445 | - 'objet' => $objet, |
|
| 446 | - 'cle_objet' => $cle_objet, |
|
| 447 | - 'mode' => $mode, |
|
| 448 | - ], |
|
| 449 | - 'data' => $infos_logo, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - return $infos_logo; |
|
| 423 | + static $chercher_logo; |
|
| 424 | + if (is_null($chercher_logo)) { |
|
| 425 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | + } |
|
| 427 | + $cle_objet = id_table_objet($objet); |
|
| 428 | + |
|
| 429 | + // On cherche pas la méthode classique |
|
| 430 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | + if (!empty($infos_logo)) { |
|
| 433 | + $infos_logo = [ |
|
| 434 | + 'chemin' => $infos_logo[0], |
|
| 435 | + 'timestamp' => $infos_logo[4], |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // On passe cette recherche de logo dans un pipeline |
|
| 440 | + $infos_logo = pipeline( |
|
| 441 | + 'quete_logo_objet', |
|
| 442 | + [ |
|
| 443 | + 'args' => [ |
|
| 444 | + 'id_objet' => $id_objet, |
|
| 445 | + 'objet' => $objet, |
|
| 446 | + 'cle_objet' => $cle_objet, |
|
| 447 | + 'mode' => $mode, |
|
| 448 | + ], |
|
| 449 | + 'data' => $infos_logo, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + return $infos_logo; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @return bool|string |
| 464 | 464 | */ |
| 465 | 465 | function quete_logo_file($row, $connect = null) { |
| 466 | - include_spip('inc/documents'); |
|
| 467 | - $logo = vignette_logo_document($row, $connect); |
|
| 468 | - if (!$logo) { |
|
| 469 | - $logo = image_du_document($row, $connect); |
|
| 470 | - } |
|
| 471 | - if (!$logo) { |
|
| 472 | - $f = charger_fonction('vignette', 'inc'); |
|
| 473 | - $logo = $f($row['extension'], false); |
|
| 474 | - } |
|
| 475 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | - if ( |
|
| 477 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | - ) { |
|
| 481 | - return $logo; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return get_spip_doc($logo); |
|
| 466 | + include_spip('inc/documents'); |
|
| 467 | + $logo = vignette_logo_document($row, $connect); |
|
| 468 | + if (!$logo) { |
|
| 469 | + $logo = image_du_document($row, $connect); |
|
| 470 | + } |
|
| 471 | + if (!$logo) { |
|
| 472 | + $f = charger_fonction('vignette', 'inc'); |
|
| 473 | + $logo = $f($row['extension'], false); |
|
| 474 | + } |
|
| 475 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | + if ( |
|
| 477 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | + ) { |
|
| 481 | + return $logo; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return get_spip_doc($logo); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 511 | 511 | |
| 512 | - include_spip('inc/documents'); |
|
| 513 | - $logo = ''; |
|
| 514 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | - $logo = vignette_logo_document($row, $connect); |
|
| 516 | - } |
|
| 517 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | - return ''; |
|
| 520 | - } |
|
| 521 | - if ($mode_logo == 'icone') { |
|
| 522 | - $row['fichier'] = ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 512 | + include_spip('inc/documents'); |
|
| 513 | + $logo = ''; |
|
| 514 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | + $logo = vignette_logo_document($row, $connect); |
|
| 516 | + } |
|
| 517 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | + return ''; |
|
| 520 | + } |
|
| 521 | + if ($mode_logo == 'icone') { |
|
| 522 | + $row['fichier'] = ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function quete_html_logo($logo, $align, $lien) { |
| 536 | 536 | |
| 537 | - if (!is_array($logo)) { |
|
| 538 | - return ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - $contexte = []; |
|
| 542 | - foreach ($logo as $k => $v) { |
|
| 543 | - if (!is_numeric($k)) { |
|
| 544 | - $contexte[$k] = $v; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - $contexte['align'] = $align; |
|
| 548 | - $contexte['lien'] = $lien; |
|
| 549 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 537 | + if (!is_array($logo)) { |
|
| 538 | + return ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + $contexte = []; |
|
| 542 | + foreach ($logo as $k => $v) { |
|
| 543 | + if (!is_numeric($k)) { |
|
| 544 | + $contexte[$k] = $v; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + $contexte['align'] = $align; |
|
| 548 | + $contexte['lien'] = $lien; |
|
| 549 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return string|false |
| 561 | 561 | */ |
| 562 | 562 | function document_spip_externe($fichier, $connect) { |
| 563 | - if ($connect) { |
|
| 564 | - $site = quete_meta('adresse_site', $connect); |
|
| 565 | - if ($site) { |
|
| 566 | - $dir = quete_meta('dir_img', $connect); |
|
| 567 | - return "$site/$dir$fichier"; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 563 | + if ($connect) { |
|
| 564 | + $site = quete_meta('adresse_site', $connect); |
|
| 565 | + if ($site) { |
|
| 566 | + $dir = quete_meta('dir_img', $connect); |
|
| 567 | + return "$site/$dir$fichier"; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -580,23 +580,23 @@ discard block |
||
| 580 | 580 | * @return string |
| 581 | 581 | */ |
| 582 | 582 | function vignette_logo_document($row, string $connect = '') { |
| 583 | - if (!$row['id_vignette']) { |
|
| 584 | - return ''; |
|
| 585 | - } |
|
| 586 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | - return $url; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - $f = get_spip_doc($fichier); |
|
| 592 | - if ($f and @file_exists($f)) { |
|
| 593 | - return $f; |
|
| 594 | - } |
|
| 595 | - if ($row['mode'] !== 'vignette') { |
|
| 596 | - return ''; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 583 | + if (!$row['id_vignette']) { |
|
| 584 | + return ''; |
|
| 585 | + } |
|
| 586 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | + return $url; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + $f = get_spip_doc($fichier); |
|
| 592 | + if ($f and @file_exists($f)) { |
|
| 593 | + return $f; |
|
| 594 | + } |
|
| 595 | + if ($row['mode'] !== 'vignette') { |
|
| 596 | + return ''; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -612,69 +612,69 @@ discard block |
||
| 612 | 612 | * @return bool|string |
| 613 | 613 | */ |
| 614 | 614 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 615 | - static $exposer = []; |
|
| 616 | - |
|
| 617 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | - // en static. |
|
| 621 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | - (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | - // il n'est donc pas utile |
|
| 628 | - $parent = 0; |
|
| 629 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | - if (isset($enfants[$type])) { |
|
| 632 | - foreach ($enfants[$type] as $t) { |
|
| 633 | - if ( |
|
| 634 | - isset($reference[$t]) |
|
| 635 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | - or isset($reference["@$t"]) |
|
| 637 | - ) { |
|
| 638 | - $type = $t; |
|
| 639 | - $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | - continue; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - $exposer[$m][$type] = []; |
|
| 646 | - if ($principal) { |
|
| 647 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | - foreach ($principaux as $principal) { |
|
| 649 | - $exposer[$m][$type][$principal] = true; |
|
| 650 | - if ($type == 'id_mot') { |
|
| 651 | - if (!$parent) { |
|
| 652 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | - } |
|
| 654 | - if ($parent) { |
|
| 655 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | - } |
|
| 657 | - } else { |
|
| 658 | - if ($type != 'id_groupe') { |
|
| 659 | - if (!$parent) { |
|
| 660 | - if ($type == 'id_rubrique') { |
|
| 661 | - $parent = $principal; |
|
| 662 | - } |
|
| 663 | - if ($type == 'id_article') { |
|
| 664 | - $parent = quete_rubrique($principal, $connect); |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - do { |
|
| 668 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // And the winner is... |
|
| 677 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 615 | + static $exposer = []; |
|
| 616 | + |
|
| 617 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | + // en static. |
|
| 621 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | + $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | + (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | + // il n'est donc pas utile |
|
| 628 | + $parent = 0; |
|
| 629 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | + if (isset($enfants[$type])) { |
|
| 632 | + foreach ($enfants[$type] as $t) { |
|
| 633 | + if ( |
|
| 634 | + isset($reference[$t]) |
|
| 635 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | + or isset($reference["@$t"]) |
|
| 637 | + ) { |
|
| 638 | + $type = $t; |
|
| 639 | + $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | + continue; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + $exposer[$m][$type] = []; |
|
| 646 | + if ($principal) { |
|
| 647 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | + foreach ($principaux as $principal) { |
|
| 649 | + $exposer[$m][$type][$principal] = true; |
|
| 650 | + if ($type == 'id_mot') { |
|
| 651 | + if (!$parent) { |
|
| 652 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | + } |
|
| 654 | + if ($parent) { |
|
| 655 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | + } |
|
| 657 | + } else { |
|
| 658 | + if ($type != 'id_groupe') { |
|
| 659 | + if (!$parent) { |
|
| 660 | + if ($type == 'id_rubrique') { |
|
| 661 | + $parent = $principal; |
|
| 662 | + } |
|
| 663 | + if ($type == 'id_article') { |
|
| 664 | + $parent = quete_rubrique($principal, $connect); |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + do { |
|
| 668 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + // And the winner is... |
|
| 677 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -689,23 +689,23 @@ discard block |
||
| 689 | 689 | * @return int |
| 690 | 690 | */ |
| 691 | 691 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 692 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | - // ou composee, mais verifions |
|
| 694 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | - return 0; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $pos = 0; |
|
| 699 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | - $pos++; |
|
| 701 | - } |
|
| 702 | - // si on a pas trouve |
|
| 703 | - if (!$row or $row[$primary] != $valeur) { |
|
| 704 | - return 0; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - // sinon, calculer le bon numero de page |
|
| 708 | - return floor($pos / $pas) * $pas; |
|
| 692 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | + // ou composee, mais verifions |
|
| 694 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | + return 0; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $pos = 0; |
|
| 699 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | + $pos++; |
|
| 701 | + } |
|
| 702 | + // si on a pas trouve |
|
| 703 | + if (!$row or $row[$primary] != $valeur) { |
|
| 704 | + return 0; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + // sinon, calculer le bon numero de page |
|
| 708 | + return floor($pos / $pas) * $pas; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -716,11 +716,11 @@ discard block |
||
| 716 | 716 | * @return boolean |
| 717 | 717 | */ |
| 718 | 718 | function is_whereable($value): bool { |
| 719 | - if (is_array($value) && count($value)) { |
|
| 720 | - return true; |
|
| 721 | - } |
|
| 722 | - if (is_scalar($value) && strlen($value)) { |
|
| 723 | - return true; |
|
| 724 | - } |
|
| 725 | - return false; |
|
| 719 | + if (is_array($value) && count($value)) { |
|
| 720 | + return true; |
|
| 721 | + } |
|
| 722 | + if (is_scalar($value) && strlen($value)) { |
|
| 723 | + return true; |
|
| 724 | + } |
|
| 725 | + return false; |
|
| 726 | 726 | } |
| 727 | 727 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,136 +66,136 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 69 | - static $tableau_des_erreurs = []; |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = []; |
|
| 78 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if ( |
|
| 119 | - ob_get_length() |
|
| 120 | - and |
|
| 121 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | - ) { |
|
| 123 | - ob_end_clean(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | - $fonc = _request('var_mode_objet'); |
|
| 128 | - $mode = _request('var_mode_affiche'); |
|
| 129 | - $self = str_replace("\\'", ''', self()); |
|
| 130 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | - |
|
| 132 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | - . '<br />' |
|
| 134 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | - |
|
| 136 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | - return $res; |
|
| 138 | - } |
|
| 139 | - if ($tableau_des_erreurs) { |
|
| 140 | - http_response_code(503); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - http_no_cache(); |
|
| 144 | - if (isset($_GET['var_profile'])) { |
|
| 145 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | - } else { |
|
| 148 | - if (!$fonc) { |
|
| 149 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | - } |
|
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | - } |
|
| 153 | - if ($message === false) { |
|
| 154 | - lang_select(); |
|
| 155 | - |
|
| 156 | - return debusquer_entete($titre, $res); |
|
| 157 | - } else { |
|
| 158 | - echo debusquer_entete($titre, $res); |
|
| 159 | - } |
|
| 160 | - exit; |
|
| 69 | + static $tableau_des_erreurs = []; |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = []; |
|
| 78 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if ( |
|
| 119 | + ob_get_length() |
|
| 120 | + and |
|
| 121 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | + ) { |
|
| 123 | + ob_end_clean(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | + $fonc = _request('var_mode_objet'); |
|
| 128 | + $mode = _request('var_mode_affiche'); |
|
| 129 | + $self = str_replace("\\'", ''', self()); |
|
| 130 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | + |
|
| 132 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | + . '<br />' |
|
| 134 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | + |
|
| 136 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | + return $res; |
|
| 138 | + } |
|
| 139 | + if ($tableau_des_erreurs) { |
|
| 140 | + http_response_code(503); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + http_no_cache(); |
|
| 144 | + if (isset($_GET['var_profile'])) { |
|
| 145 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | + } else { |
|
| 148 | + if (!$fonc) { |
|
| 149 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | + } |
|
| 151 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | + } |
|
| 153 | + if ($message === false) { |
|
| 154 | + lang_select(); |
|
| 155 | + |
|
| 156 | + return debusquer_entete($titre, $res); |
|
| 157 | + } else { |
|
| 158 | + echo debusquer_entete($titre, $res); |
|
| 159 | + } |
|
| 160 | + exit; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debusquer_compose_message($msg) { |
| 164 | - if (is_array($msg)) { |
|
| 165 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | - // message avec argument: instancier |
|
| 169 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | - } else { |
|
| 171 | - // message SQL: interpreter |
|
| 172 | - $msg = debusquer_requete($msg); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | - // une erreur critique sort $message en array |
|
| 179 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | - |
|
| 182 | - return $msg; |
|
| 164 | + if (is_array($msg)) { |
|
| 165 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | + // message avec argument: instancier |
|
| 169 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | + } else { |
|
| 171 | + // message SQL: interpreter |
|
| 172 | + $msg = debusquer_requete($msg); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | + // une erreur critique sort $message en array |
|
| 179 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | + |
|
| 182 | + return $msg; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | - if (!empty($erreurs)) { |
|
| 188 | - $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 187 | + if (!empty($erreurs)) { |
|
| 188 | + $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | - return debusquer_navigation($erreurs, $n); |
|
| 191 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | - include_spip('public/tracer'); |
|
| 193 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 190 | + return debusquer_navigation($erreurs, $n); |
|
| 191 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | + include_spip('public/tracer'); |
|
| 193 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 194 | 194 | |
| 195 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | - } else { |
|
| 197 | - return ''; |
|
| 198 | - } |
|
| 195 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | + } else { |
|
| 197 | + return ''; |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -205,42 +205,42 @@ discard block |
||
| 205 | 205 | * @return string Code HTML |
| 206 | 206 | **/ |
| 207 | 207 | function debusquer_contexte($env) { |
| 208 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | - $env = $env_tab; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!$env) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $res = ''; |
|
| 216 | - foreach ($env as $nom => $valeur) { |
|
| 217 | - if (is_array($valeur)) { |
|
| 218 | - $valeur_simple = []; |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - if (is_array($v)) { |
|
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 222 | - } elseif (is_object($v)) { |
|
| 223 | - $valeur_simple[] = get_class($v); |
|
| 224 | - } elseif (is_string($v)) { |
|
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | - } else { |
|
| 227 | - $valeur_simple[] = $v; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - $n = count($valeur); |
|
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | - } elseif (is_object($valeur)) { |
|
| 234 | - $valeur = get_class($valeur); |
|
| 235 | - } elseif (is_string($valeur)) { |
|
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 237 | - } |
|
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | - . "</td></tr>\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | + $env = $env_tab; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!$env) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $res = ''; |
|
| 216 | + foreach ($env as $nom => $valeur) { |
|
| 217 | + if (is_array($valeur)) { |
|
| 218 | + $valeur_simple = []; |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + if (is_array($v)) { |
|
| 221 | + $valeur_simple[] = 'array:' . count($v); |
|
| 222 | + } elseif (is_object($v)) { |
|
| 223 | + $valeur_simple[] = get_class($v); |
|
| 224 | + } elseif (is_string($v)) { |
|
| 225 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | + } else { |
|
| 227 | + $valeur_simple[] = $v; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + $n = count($valeur); |
|
| 231 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | + } elseif (is_object($valeur)) { |
|
| 234 | + $valeur = get_class($valeur); |
|
| 235 | + } elseif (is_string($valeur)) { |
|
| 236 | + $valeur = "'" . $valeur . "'"; |
|
| 237 | + } |
|
| 238 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | + . "</td></tr>\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 250 | 250 | |
| 251 | - if (_request('exec') == 'valider_xml') { |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 254 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | - $res = ''; |
|
| 256 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | - foreach ($tableau as $i => $err) { |
|
| 258 | - $boucle = $ligne = $skel = ''; |
|
| 259 | - list($msg, $lieu) = $err; |
|
| 260 | - if (is_object($lieu)) { |
|
| 261 | - $ligne = $lieu->ligne; |
|
| 262 | - $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | - if (isset($lieu->descr['nom'])) { |
|
| 264 | - $nom_code = $lieu->descr['nom']; |
|
| 265 | - $skel = $lieu->descr['sourcefile']; |
|
| 266 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | - if ($boucle) { |
|
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $j = ($i + 1); |
|
| 277 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | - . $j |
|
| 279 | - . " </td><td style='text-align: left'>" |
|
| 280 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | - . "</td><td style='text-align: left'>" |
|
| 282 | - . ($skel ? $skel : ' / ') |
|
| 283 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | - . ($boucle ? $boucle : ' / ') |
|
| 285 | - . "</td><td style='text-align: right'>" |
|
| 286 | - . $ligne |
|
| 287 | - . "</td></tr>\n"; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return "\n<table id='$id'>" |
|
| 291 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | - . $caption[0] |
|
| 251 | + if (_request('exec') == 'valider_xml') { |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | + $res = ''; |
|
| 256 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | + foreach ($tableau as $i => $err) { |
|
| 258 | + $boucle = $ligne = $skel = ''; |
|
| 259 | + list($msg, $lieu) = $err; |
|
| 260 | + if (is_object($lieu)) { |
|
| 261 | + $ligne = $lieu->ligne; |
|
| 262 | + $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | + if (isset($lieu->descr['nom'])) { |
|
| 264 | + $nom_code = $lieu->descr['nom']; |
|
| 265 | + $skel = $lieu->descr['sourcefile']; |
|
| 266 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | + if ($boucle) { |
|
| 270 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $j = ($i + 1); |
|
| 277 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | + . $j |
|
| 279 | + . " </td><td style='text-align: left'>" |
|
| 280 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | + . "</td><td style='text-align: left'>" |
|
| 282 | + . ($skel ? $skel : ' / ') |
|
| 283 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | + . ($boucle ? $boucle : ' / ') |
|
| 285 | + . "</td><td style='text-align: right'>" |
|
| 286 | + . $ligne |
|
| 287 | + . "</td></tr>\n"; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return "\n<table id='$id'>" |
|
| 291 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | + . $caption[0] |
|
| 293 | 293 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 294 | 294 | # aider('erreur_compilation'), |
| 295 | - . '</caption>' |
|
| 296 | - // fausse caption du chrono (mais vraie nav) |
|
| 297 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | - . '<tr><th>' |
|
| 299 | - . _T('numero') |
|
| 300 | - . '</th><th>' |
|
| 301 | - . _T('public:message') |
|
| 302 | - . '</th><th>' |
|
| 303 | - . _T('squelette') |
|
| 304 | - . '</th><th>' |
|
| 305 | - . _T('zbug_boucle') |
|
| 306 | - . '</th><th>' |
|
| 307 | - . _T('ligne') |
|
| 308 | - . '</th></tr>' |
|
| 309 | - . $res |
|
| 310 | - . '</table>'; |
|
| 295 | + . '</caption>' |
|
| 296 | + // fausse caption du chrono (mais vraie nav) |
|
| 297 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | + . '<tr><th>' |
|
| 299 | + . _T('numero') |
|
| 300 | + . '</th><th>' |
|
| 301 | + . _T('public:message') |
|
| 302 | + . '</th><th>' |
|
| 303 | + . _T('squelette') |
|
| 304 | + . '</th><th>' |
|
| 305 | + . _T('zbug_boucle') |
|
| 306 | + . '</th><th>' |
|
| 307 | + . _T('ligne') |
|
| 308 | + . '</th></tr>' |
|
| 309 | + . $res |
|
| 310 | + . '</table>'; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -327,124 +327,124 @@ discard block |
||
| 327 | 327 | * ou un tableau si l'erreur est critique |
| 328 | 328 | **/ |
| 329 | 329 | function debusquer_requete($message) { |
| 330 | - list($errno, $msg, $query) = $message; |
|
| 331 | - |
|
| 332 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | - $errno = $regs[2]; |
|
| 336 | - } elseif ( |
|
| 337 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | - ) { |
|
| 340 | - $errno = $regs[1]; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Erreur systeme |
|
| 344 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | - $retour = '<tt><br /><br /><blink>' |
|
| 346 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | - . "</blink><br />\n<b>" |
|
| 348 | - . _T( |
|
| 349 | - 'info_erreur_systeme2', |
|
| 350 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | - ) |
|
| 352 | - . '</b><br />'; |
|
| 353 | - spip_log("Erreur systeme $errno"); |
|
| 354 | - |
|
| 355 | - return [$retour, '']; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Requete erronee |
|
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | - . spip_htmlspecialchars($msg) |
|
| 361 | - . "\n<br /><span style='color: red'><b>" |
|
| 362 | - . spip_htmlspecialchars($query) |
|
| 363 | - . '</b></span></tt><br />'; |
|
| 364 | - |
|
| 365 | - //. aider('erreur_mysql'); |
|
| 366 | - |
|
| 367 | - return $err; |
|
| 330 | + list($errno, $msg, $query) = $message; |
|
| 331 | + |
|
| 332 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | + $errno = $regs[2]; |
|
| 336 | + } elseif ( |
|
| 337 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | + ) { |
|
| 340 | + $errno = $regs[1]; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Erreur systeme |
|
| 344 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | + $retour = '<tt><br /><br /><blink>' |
|
| 346 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | + . "</blink><br />\n<b>" |
|
| 348 | + . _T( |
|
| 349 | + 'info_erreur_systeme2', |
|
| 350 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | + ) |
|
| 352 | + . '</b><br />'; |
|
| 353 | + spip_log("Erreur systeme $errno"); |
|
| 354 | + |
|
| 355 | + return [$retour, '']; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Requete erronee |
|
| 359 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | + . spip_htmlspecialchars($msg) |
|
| 361 | + . "\n<br /><span style='color: red'><b>" |
|
| 362 | + . spip_htmlspecialchars($query) |
|
| 363 | + . '</b></span></tt><br />'; |
|
| 364 | + |
|
| 365 | + //. aider('erreur_mysql'); |
|
| 366 | + |
|
| 367 | + return $err; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 375 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | - $y = substr_count($v[0], "\n"); |
|
| 379 | - } else { |
|
| 380 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | - } else // inclusion |
|
| 383 | - { |
|
| 384 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | - } |
|
| 386 | - $y = substr_count($incl, "\n") |
|
| 387 | - + substr_count($r[1], "\n") |
|
| 388 | - + substr_count($r[3], "\n"); |
|
| 389 | - } |
|
| 390 | - if ($n <= ($y + $debut)) { |
|
| 391 | - if ($v[1][0] == '?') { |
|
| 392 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | - } elseif ($v[1][0] == '!') { |
|
| 394 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | - } |
|
| 401 | - $debut += $y; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return [$nom, $boucle, $n - $debut]; |
|
| 374 | + $id = $nom . $boucle; |
|
| 375 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | + $y = substr_count($v[0], "\n"); |
|
| 379 | + } else { |
|
| 380 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | + } else // inclusion |
|
| 383 | + { |
|
| 384 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | + } |
|
| 386 | + $y = substr_count($incl, "\n") |
|
| 387 | + + substr_count($r[1], "\n") |
|
| 388 | + + substr_count($r[3], "\n"); |
|
| 389 | + } |
|
| 390 | + if ($n <= ($y + $debut)) { |
|
| 391 | + if ($v[1][0] == '?') { |
|
| 392 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | + } elseif ($v[1][0] == '!') { |
|
| 394 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | + } |
|
| 401 | + $debut += $y; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return [$nom, $boucle, $n - $debut]; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // https://code.spip.net/@trouve_squelette_inclus |
| 409 | 409 | function trouve_squelette_inclus($script) { |
| 410 | 410 | |
| 411 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | - // si le script X.php n'est pas ecrire/public.php |
|
| 413 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | - $reg[1] = 'inconnu'; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | - |
|
| 423 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | - if (preg_match($incl, $v)) { |
|
| 425 | - return $k; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return ''; |
|
| 411 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | + // si le script X.php n'est pas ecrire/public.php |
|
| 413 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | + $reg[1] = 'inconnu'; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | + |
|
| 423 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | + if (preg_match($incl, $v)) { |
|
| 425 | + return $k; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return ''; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // https://code.spip.net/@reference_boucle_debug |
| 433 | 433 | function reference_boucle_debug($n, $nom, $self) { |
| 434 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | - |
|
| 436 | - if (!$boucle) { |
|
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 441 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | - } else { |
|
| 443 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | - |
|
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | - } |
|
| 434 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | + |
|
| 436 | + if (!$boucle) { |
|
| 437 | + return !$ligne ? '' : |
|
| 438 | + (' (' . |
|
| 439 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | + _T('squelette_ligne')) . |
|
| 441 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | + } else { |
|
| 443 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | + |
|
| 445 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // affiche un texte avec numero de ligne et ancre. |
@@ -452,397 +452,397 @@ discard block |
||
| 452 | 452 | // https://code.spip.net/@ancre_texte |
| 453 | 453 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 454 | 454 | |
| 455 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | - if ($var_mode_ligne) { |
|
| 457 | - $fautifs[] = [$var_mode_ligne]; |
|
| 458 | - } |
|
| 459 | - $res = ''; |
|
| 460 | - |
|
| 461 | - $s = highlight_string($texte, true); |
|
| 462 | - if (substr($s, 0, 6) == '<code>') { |
|
| 463 | - $s = substr($s, 6); |
|
| 464 | - $res = '<code>'; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $s = preg_replace( |
|
| 468 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | - $s |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - $tableau = explode('<br />', $s); |
|
| 475 | - |
|
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | - |
|
| 478 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | - $formaterr = 'color: red;'; |
|
| 480 | - $i = 1; |
|
| 481 | - $flignes = []; |
|
| 482 | - $loc = [0, 0]; |
|
| 483 | - foreach ($fautifs as $lc) { |
|
| 484 | - if (is_array($lc)) { |
|
| 485 | - $l = array_shift($lc); |
|
| 486 | - $flignes[$l] = $lc; |
|
| 487 | - } else { |
|
| 488 | - $flignes[$lc] = $loc; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - $ancre = md5($texte); |
|
| 493 | - foreach ($tableau as $ligne) { |
|
| 494 | - if (isset($flignes[$i])) { |
|
| 495 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | - $indexmesg = $flignes[$i][1]; |
|
| 497 | - $err = textebrut($flignes[$i][2]); |
|
| 498 | - // tentative de pointer sur la colonne fautive; |
|
| 499 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | - // $m = $flignes[$i][0]; |
|
| 501 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | - $bg = $formaterr; |
|
| 504 | - } else { |
|
| 505 | - $indexmesg = $ancre; |
|
| 506 | - $err = $bg = ''; |
|
| 507 | - } |
|
| 508 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | - $i++; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return "<div id='T$ancre'>" |
|
| 513 | - . '<div onclick="' |
|
| 514 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | - . '" title="' |
|
| 516 | - . _T('masquer_colonne') |
|
| 517 | - . '" style="cursor: pointer;">' |
|
| 518 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | - . '</div> |
|
| 455 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | + if ($var_mode_ligne) { |
|
| 457 | + $fautifs[] = [$var_mode_ligne]; |
|
| 458 | + } |
|
| 459 | + $res = ''; |
|
| 460 | + |
|
| 461 | + $s = highlight_string($texte, true); |
|
| 462 | + if (substr($s, 0, 6) == '<code>') { |
|
| 463 | + $s = substr($s, 6); |
|
| 464 | + $res = '<code>'; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $s = preg_replace( |
|
| 468 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | + $s |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + $tableau = explode('<br />', $s); |
|
| 475 | + |
|
| 476 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | + |
|
| 478 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | + $formaterr = 'color: red;'; |
|
| 480 | + $i = 1; |
|
| 481 | + $flignes = []; |
|
| 482 | + $loc = [0, 0]; |
|
| 483 | + foreach ($fautifs as $lc) { |
|
| 484 | + if (is_array($lc)) { |
|
| 485 | + $l = array_shift($lc); |
|
| 486 | + $flignes[$l] = $lc; |
|
| 487 | + } else { |
|
| 488 | + $flignes[$lc] = $loc; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + $ancre = md5($texte); |
|
| 493 | + foreach ($tableau as $ligne) { |
|
| 494 | + if (isset($flignes[$i])) { |
|
| 495 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | + $indexmesg = $flignes[$i][1]; |
|
| 497 | + $err = textebrut($flignes[$i][2]); |
|
| 498 | + // tentative de pointer sur la colonne fautive; |
|
| 499 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | + // $m = $flignes[$i][0]; |
|
| 501 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | + $bg = $formaterr; |
|
| 504 | + } else { |
|
| 505 | + $indexmesg = $ancre; |
|
| 506 | + $err = $bg = ''; |
|
| 507 | + } |
|
| 508 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | + $i++; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return "<div id='T$ancre'>" |
|
| 513 | + . '<div onclick="' |
|
| 514 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | + . '" title="' |
|
| 516 | + . _T('masquer_colonne') |
|
| 517 | + . '" style="cursor: pointer;">' |
|
| 518 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | + . '</div> |
|
| 520 | 520 | ' . $res . "</div>\n"; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | // l'environnement graphique du debuggueur |
| 524 | 524 | |
| 525 | 525 | function debusquer_squelette($fonc, $mode, $self) { |
| 526 | - $texte = ''; |
|
| 527 | - |
|
| 528 | - if ($mode !== 'validation') { |
|
| 529 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | - $res = "<div id='spip-boucles'>\n" |
|
| 531 | - . debusquer_navigation_squelettes($self) |
|
| 532 | - . '</div>'; |
|
| 533 | - } else { |
|
| 534 | - $res = ''; |
|
| 535 | - } |
|
| 536 | - if ($fonc) { |
|
| 537 | - $id = " id='$fonc'"; |
|
| 538 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | - $texte .= $res2; |
|
| 541 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | - $legend = _T('zbug_' . $mode); |
|
| 543 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | - $texte = ancre_texte($texte, ['', '']); |
|
| 545 | - } |
|
| 546 | - } else { |
|
| 547 | - if (strlen(trim($res))) { |
|
| 548 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | - } else { |
|
| 550 | - // cas de l'appel sur erreur: montre la page |
|
| 551 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | - : ''; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } else { |
|
| 557 | - $valider = charger_fonction('valider', 'xml'); |
|
| 558 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | - if ($err === false) { |
|
| 563 | - $err = _T('impossible'); |
|
| 564 | - } elseif ($err === true) { |
|
| 565 | - $err = _T('correcte'); |
|
| 566 | - } else { |
|
| 567 | - $err = ": $err"; |
|
| 568 | - } |
|
| 569 | - $legend = _T('validation') . ' ' . $err; |
|
| 570 | - $res = $id = ''; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return !trim($texte) ? '' : ( |
|
| 574 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | - . ($legend ? $legend : $mode) |
|
| 578 | - . '</a></legend>' |
|
| 579 | - . $texte |
|
| 580 | - . '</fieldset></div>' |
|
| 581 | - . '</div>'); |
|
| 526 | + $texte = ''; |
|
| 527 | + |
|
| 528 | + if ($mode !== 'validation') { |
|
| 529 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | + $res = "<div id='spip-boucles'>\n" |
|
| 531 | + . debusquer_navigation_squelettes($self) |
|
| 532 | + . '</div>'; |
|
| 533 | + } else { |
|
| 534 | + $res = ''; |
|
| 535 | + } |
|
| 536 | + if ($fonc) { |
|
| 537 | + $id = " id='$fonc'"; |
|
| 538 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | + $texte .= $res2; |
|
| 541 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | + $legend = _T('zbug_' . $mode); |
|
| 543 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | + $texte = ancre_texte($texte, ['', '']); |
|
| 545 | + } |
|
| 546 | + } else { |
|
| 547 | + if (strlen(trim($res))) { |
|
| 548 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | + } else { |
|
| 550 | + // cas de l'appel sur erreur: montre la page |
|
| 551 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | + : ''; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } else { |
|
| 557 | + $valider = charger_fonction('valider', 'xml'); |
|
| 558 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | + if ($err === false) { |
|
| 563 | + $err = _T('impossible'); |
|
| 564 | + } elseif ($err === true) { |
|
| 565 | + $err = _T('correcte'); |
|
| 566 | + } else { |
|
| 567 | + $err = ": $err"; |
|
| 568 | + } |
|
| 569 | + $legend = _T('validation') . ' ' . $err; |
|
| 570 | + $res = $id = ''; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return !trim($texte) ? '' : ( |
|
| 574 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | + . ($legend ? $legend : $mode) |
|
| 578 | + . '</a></legend>' |
|
| 579 | + . $texte |
|
| 580 | + . '</fieldset></div>' |
|
| 581 | + . '</div>'); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | // https://code.spip.net/@emboite_texte |
| 586 | 586 | function emboite_texte($res, $fonc = '', $self = '') { |
| 587 | - $errs = $res->err; |
|
| 588 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | - |
|
| 590 | - if (!$texte and !$errs) { |
|
| 591 | - return [ancre_texte('', ['', '']), false]; |
|
| 592 | - } |
|
| 593 | - if (!$errs) { |
|
| 594 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | - $encore = count_occ($errs); |
|
| 600 | - $encore2 = []; |
|
| 601 | - $fautifs = []; |
|
| 602 | - |
|
| 603 | - $err = '<tr><th>' |
|
| 604 | - . _T('numero') |
|
| 605 | - . '</th><th>' |
|
| 606 | - . _T('occurence') |
|
| 607 | - . '</th><th>' |
|
| 608 | - . _T('ligne') |
|
| 609 | - . '</th><th>' |
|
| 610 | - . _T('colonne') |
|
| 611 | - . '</th><th>' |
|
| 612 | - . _T('erreur') |
|
| 613 | - . '</th></tr>'; |
|
| 614 | - |
|
| 615 | - $i = 0; |
|
| 616 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | - foreach ($errs as $r) { |
|
| 618 | - $i++; |
|
| 619 | - list($msg, $ligne, $col) = $r; |
|
| 620 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | - if (isset($encore2[$msg])) { |
|
| 622 | - $ref = ++$encore2[$msg]; |
|
| 623 | - } else { |
|
| 624 | - $encore2[$msg] = $ref = 1; |
|
| 625 | - } |
|
| 626 | - $err .= "<tr style='background-color: " |
|
| 627 | - . $colors[$i % 2] |
|
| 628 | - . "'><td $style><a href='#debut_err'>" |
|
| 629 | - . $i |
|
| 630 | - . "</a></td><td $style>" |
|
| 631 | - . "$ref/$encore[$msg]</td>" |
|
| 632 | - . "<td $style><a href='#L" |
|
| 633 | - . $ligne |
|
| 634 | - . "' id='T$i'>" |
|
| 635 | - . $ligne |
|
| 636 | - . "</a></td><td $style>" |
|
| 637 | - . $col |
|
| 638 | - . "</td><td>$msg</td></tr>\n"; |
|
| 639 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | - } |
|
| 641 | - $err = "<h2 style='text-align: center'>" |
|
| 642 | - . $i |
|
| 643 | - . "<a href='#fin_err'>" |
|
| 644 | - . ' ' . _T('erreur_texte') |
|
| 645 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | - . $err |
|
| 647 | - . " </table><a id='fin_err'></a>"; |
|
| 648 | - |
|
| 649 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | - } else { |
|
| 651 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | - |
|
| 658 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | - } |
|
| 587 | + $errs = $res->err; |
|
| 588 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | + |
|
| 590 | + if (!$texte and !$errs) { |
|
| 591 | + return [ancre_texte('', ['', '']), false]; |
|
| 592 | + } |
|
| 593 | + if (!$errs) { |
|
| 594 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | + $encore = count_occ($errs); |
|
| 600 | + $encore2 = []; |
|
| 601 | + $fautifs = []; |
|
| 602 | + |
|
| 603 | + $err = '<tr><th>' |
|
| 604 | + . _T('numero') |
|
| 605 | + . '</th><th>' |
|
| 606 | + . _T('occurence') |
|
| 607 | + . '</th><th>' |
|
| 608 | + . _T('ligne') |
|
| 609 | + . '</th><th>' |
|
| 610 | + . _T('colonne') |
|
| 611 | + . '</th><th>' |
|
| 612 | + . _T('erreur') |
|
| 613 | + . '</th></tr>'; |
|
| 614 | + |
|
| 615 | + $i = 0; |
|
| 616 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | + foreach ($errs as $r) { |
|
| 618 | + $i++; |
|
| 619 | + list($msg, $ligne, $col) = $r; |
|
| 620 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | + if (isset($encore2[$msg])) { |
|
| 622 | + $ref = ++$encore2[$msg]; |
|
| 623 | + } else { |
|
| 624 | + $encore2[$msg] = $ref = 1; |
|
| 625 | + } |
|
| 626 | + $err .= "<tr style='background-color: " |
|
| 627 | + . $colors[$i % 2] |
|
| 628 | + . "'><td $style><a href='#debut_err'>" |
|
| 629 | + . $i |
|
| 630 | + . "</a></td><td $style>" |
|
| 631 | + . "$ref/$encore[$msg]</td>" |
|
| 632 | + . "<td $style><a href='#L" |
|
| 633 | + . $ligne |
|
| 634 | + . "' id='T$i'>" |
|
| 635 | + . $ligne |
|
| 636 | + . "</a></td><td $style>" |
|
| 637 | + . $col |
|
| 638 | + . "</td><td>$msg</td></tr>\n"; |
|
| 639 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | + } |
|
| 641 | + $err = "<h2 style='text-align: center'>" |
|
| 642 | + . $i |
|
| 643 | + . "<a href='#fin_err'>" |
|
| 644 | + . ' ' . _T('erreur_texte') |
|
| 645 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | + . $err |
|
| 647 | + . " </table><a id='fin_err'></a>"; |
|
| 648 | + |
|
| 649 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | + } else { |
|
| 651 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | + $err = $msg . |
|
| 655 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | + |
|
| 658 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | // https://code.spip.net/@count_occ |
| 663 | 663 | function count_occ($regs) { |
| 664 | - $encore = []; |
|
| 665 | - foreach ($regs as $r) { |
|
| 666 | - if (isset($encore[$r[0]])) { |
|
| 667 | - $encore[$r[0]]++; |
|
| 668 | - } else { |
|
| 669 | - $encore[$r[0]] = 1; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $encore; |
|
| 664 | + $encore = []; |
|
| 665 | + foreach ($regs as $r) { |
|
| 666 | + if (isset($encore[$r[0]])) { |
|
| 667 | + $encore[$r[0]]++; |
|
| 668 | + } else { |
|
| 669 | + $encore[$r[0]] = 1; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $encore; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | function debusquer_navigation_squelettes($self) { |
| 677 | 677 | |
| 678 | - $res = ''; |
|
| 679 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | - $t_skel = _T('squelette'); |
|
| 682 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | - 'zbug_profile', |
|
| 687 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | - ); |
|
| 689 | - |
|
| 690 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | - . $t_skel |
|
| 692 | - . ' ' |
|
| 693 | - . $sourcefile |
|
| 694 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | - . $t_skel |
|
| 696 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | - . _T('zbug_resultat') |
|
| 698 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | - . _T('zbug_code') |
|
| 700 | - . "</a>\n<a href='" |
|
| 701 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | - . "'>" |
|
| 703 | - . _T('zbug_calcul') |
|
| 704 | - . '</a></legend>' |
|
| 705 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | - . "</fieldset>\n"; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - return $res; |
|
| 678 | + $res = ''; |
|
| 679 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | + $t_skel = _T('squelette'); |
|
| 682 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | + 'zbug_profile', |
|
| 687 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | + ); |
|
| 689 | + |
|
| 690 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | + . $t_skel |
|
| 692 | + . ' ' |
|
| 693 | + . $sourcefile |
|
| 694 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | + . $t_skel |
|
| 696 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | + . _T('zbug_resultat') |
|
| 698 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | + . _T('zbug_code') |
|
| 700 | + . "</a>\n<a href='" |
|
| 701 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | + . "'>" |
|
| 703 | + . _T('zbug_calcul') |
|
| 704 | + . '</a></legend>' |
|
| 705 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | + . "</fieldset>\n"; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + return $res; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 715 | - $i = 0; |
|
| 716 | - $res = ''; |
|
| 717 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | - |
|
| 720 | - foreach ($boucles as $objet => $boucle) { |
|
| 721 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | - $i++; |
|
| 723 | - $nom = $boucle->id_boucle; |
|
| 724 | - $req = $boucle->type_requete; |
|
| 725 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | - |
|
| 728 | - $res .= "\n<tr style='background-color: " . |
|
| 729 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | - "'><td align='right'>$i</td><td>\n" . |
|
| 731 | - "<a class='debug_link_boucle' href='" . |
|
| 732 | - $self2 . |
|
| 733 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | - _T('zbug_boucle') . |
|
| 735 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | - $self2 . |
|
| 737 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | - _T('zbug_resultat') . |
|
| 739 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | - $self2 . |
|
| 741 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | - _T('zbug_code') . |
|
| 743 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | - "'>" . |
|
| 746 | - _T('zbug_calcul') . |
|
| 747 | - "</a></td><td>\n" . |
|
| 748 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - $req . |
|
| 751 | - "</td><td>\n" . |
|
| 752 | - spip_htmlspecialchars($crit) . |
|
| 753 | - '</td></tr>'; |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $res; |
|
| 715 | + $i = 0; |
|
| 716 | + $res = ''; |
|
| 717 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | + |
|
| 720 | + foreach ($boucles as $objet => $boucle) { |
|
| 721 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | + $i++; |
|
| 723 | + $nom = $boucle->id_boucle; |
|
| 724 | + $req = $boucle->type_requete; |
|
| 725 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | + |
|
| 728 | + $res .= "\n<tr style='background-color: " . |
|
| 729 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | + "'><td align='right'>$i</td><td>\n" . |
|
| 731 | + "<a class='debug_link_boucle' href='" . |
|
| 732 | + $self2 . |
|
| 733 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | + _T('zbug_boucle') . |
|
| 735 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | + $self2 . |
|
| 737 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | + _T('zbug_resultat') . |
|
| 739 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | + $self2 . |
|
| 741 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | + _T('zbug_code') . |
|
| 743 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | + "'>" . |
|
| 746 | + _T('zbug_calcul') . |
|
| 747 | + "</a></td><td>\n" . |
|
| 748 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | + "</td><td>\n" . |
|
| 750 | + $req . |
|
| 751 | + "</td><td>\n" . |
|
| 752 | + spip_htmlspecialchars($crit) . |
|
| 753 | + '</td></tr>'; |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $res; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | function debusquer_source($objet, $affiche) { |
| 761 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | - } else { |
|
| 765 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | - } |
|
| 767 | - $res2 = ''; |
|
| 768 | - |
|
| 769 | - if ($affiche == 'resultat') { |
|
| 770 | - $legend = $nom; |
|
| 771 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | - if (function_exists('_mysql_traite_query')) { |
|
| 773 | - $c = strtolower(_request('connect') ?? ''); |
|
| 774 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | - $req = _mysql_traite_query($req, '', $c); |
|
| 776 | - } |
|
| 777 | - // permettre le copier/coller facile |
|
| 778 | - // $res = ancre_texte($req, array(), true); |
|
| 779 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | - // formatage et affichage des resultats bruts de la requete |
|
| 781 | - $ress_req = spip_query($req); |
|
| 782 | - $brut_sql = ''; |
|
| 783 | - $num = 1; |
|
| 784 | - // eviter l'affichage de milliers de lignes |
|
| 785 | - // personnalisation possible dans mes_options |
|
| 786 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | - if ($num <= $max_aff) { |
|
| 789 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | - $brut_sql .= '<p>'; |
|
| 791 | - foreach ($retours_sql as $key => $val) { |
|
| 792 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | - } |
|
| 794 | - $brut_sql .= '</p>'; |
|
| 795 | - } |
|
| 796 | - $num++; |
|
| 797 | - } |
|
| 798 | - $res2 = interdire_scripts($brut_sql); |
|
| 799 | - foreach ($quoi as $view) { |
|
| 800 | - // ne pas afficher les $contexte_inclus |
|
| 801 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | - if ($view) { |
|
| 803 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - } elseif ($affiche == 'code') { |
|
| 807 | - $legend = $nom; |
|
| 808 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | - } elseif ($affiche == 'boucle') { |
|
| 810 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | - } elseif ($affiche == 'squelette') { |
|
| 815 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return [$legend, $res, $res2]; |
|
| 761 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | + } else { |
|
| 765 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | + } |
|
| 767 | + $res2 = ''; |
|
| 768 | + |
|
| 769 | + if ($affiche == 'resultat') { |
|
| 770 | + $legend = $nom; |
|
| 771 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | + if (function_exists('_mysql_traite_query')) { |
|
| 773 | + $c = strtolower(_request('connect') ?? ''); |
|
| 774 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | + $req = _mysql_traite_query($req, '', $c); |
|
| 776 | + } |
|
| 777 | + // permettre le copier/coller facile |
|
| 778 | + // $res = ancre_texte($req, array(), true); |
|
| 779 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | + // formatage et affichage des resultats bruts de la requete |
|
| 781 | + $ress_req = spip_query($req); |
|
| 782 | + $brut_sql = ''; |
|
| 783 | + $num = 1; |
|
| 784 | + // eviter l'affichage de milliers de lignes |
|
| 785 | + // personnalisation possible dans mes_options |
|
| 786 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | + if ($num <= $max_aff) { |
|
| 789 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | + $brut_sql .= '<p>'; |
|
| 791 | + foreach ($retours_sql as $key => $val) { |
|
| 792 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | + } |
|
| 794 | + $brut_sql .= '</p>'; |
|
| 795 | + } |
|
| 796 | + $num++; |
|
| 797 | + } |
|
| 798 | + $res2 = interdire_scripts($brut_sql); |
|
| 799 | + foreach ($quoi as $view) { |
|
| 800 | + // ne pas afficher les $contexte_inclus |
|
| 801 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | + if ($view) { |
|
| 803 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + } elseif ($affiche == 'code') { |
|
| 807 | + $legend = $nom; |
|
| 808 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | + } elseif ($affiche == 'boucle') { |
|
| 810 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | + } elseif ($affiche == 'squelette') { |
|
| 815 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return [$legend, $res, $res2]; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // https://code.spip.net/@debusquer_entete |
| 823 | 823 | function debusquer_entete($titre, $corps) { |
| 824 | 824 | |
| 825 | - include_spip('balise/formulaire_admin'); |
|
| 826 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | - |
|
| 829 | - return _DOCTYPE_ECRIRE . |
|
| 830 | - html_lang_attributes() . |
|
| 831 | - "<head>\n<title>" . |
|
| 832 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | - ")</title>\n" . |
|
| 836 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | - "' />\n" . |
|
| 839 | - http_script('', 'jquery.js') |
|
| 840 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | - . "' type='text/css' />" . |
|
| 842 | - "</head>\n" . |
|
| 843 | - "<body style='margin:0 10px;'>\n" . |
|
| 844 | - "<div id='spip-debug-header'>" . |
|
| 845 | - $corps . |
|
| 846 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | - '</div></body></html>'; |
|
| 825 | + include_spip('balise/formulaire_admin'); |
|
| 826 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | + |
|
| 829 | + return _DOCTYPE_ECRIRE . |
|
| 830 | + html_lang_attributes() . |
|
| 831 | + "<head>\n<title>" . |
|
| 832 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | + ")</title>\n" . |
|
| 836 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | + "' />\n" . |
|
| 839 | + http_script('', 'jquery.js') |
|
| 840 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | + . "' type='text/css' />" . |
|
| 842 | + "</head>\n" . |
|
| 843 | + "<body style='margin:0 10px;'>\n" . |
|
| 844 | + "<div id='spip-debug-header'>" . |
|
| 845 | + $corps . |
|
| 846 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | + '</div></body></html>'; |
|
| 848 | 848 | } |
@@ -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 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -59,92 +59,92 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // https://code.spip.net/@argumenter_inclure |
| 61 | 61 | function argumenter_inclure( |
| 62 | - $params, |
|
| 63 | - $rejet_filtres, |
|
| 64 | - $p, |
|
| 65 | - &$boucles, |
|
| 66 | - $id_boucle, |
|
| 67 | - $echap = true, |
|
| 68 | - $lang = '', |
|
| 69 | - $fond1 = false |
|
| 62 | + $params, |
|
| 63 | + $rejet_filtres, |
|
| 64 | + $p, |
|
| 65 | + &$boucles, |
|
| 66 | + $id_boucle, |
|
| 67 | + $echap = true, |
|
| 68 | + $lang = '', |
|
| 69 | + $fond1 = false |
|
| 70 | 70 | ) { |
| 71 | - $l = []; |
|
| 72 | - $erreur_p_i_i = ''; |
|
| 73 | - if (!is_array($params)) { |
|
| 74 | - return $l; |
|
| 75 | - } |
|
| 76 | - foreach ($params as $k => $couple) { |
|
| 77 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | - $filtre = array_shift($couple); |
|
| 79 | - if ($filtre) { |
|
| 80 | - break; |
|
| 81 | - } |
|
| 82 | - foreach ($couple as $n => $val) { |
|
| 83 | - $var = $val[0]; |
|
| 84 | - if ($var->type != 'texte') { |
|
| 85 | - if ($n or $k or $fond1) { |
|
| 86 | - $erreur_p_i_i = [ |
|
| 87 | - 'zbug_parametres_inclus_incorrects', |
|
| 88 | - ['param' => $var->nom_champ] |
|
| 89 | - ]; |
|
| 90 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | - break; |
|
| 92 | - } else { |
|
| 93 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | - } |
|
| 95 | - } else { |
|
| 96 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | - $m = array_pad($m, 3, null); |
|
| 98 | - $var = $m[1]; |
|
| 99 | - $auto = false; |
|
| 71 | + $l = []; |
|
| 72 | + $erreur_p_i_i = ''; |
|
| 73 | + if (!is_array($params)) { |
|
| 74 | + return $l; |
|
| 75 | + } |
|
| 76 | + foreach ($params as $k => $couple) { |
|
| 77 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | + $filtre = array_shift($couple); |
|
| 79 | + if ($filtre) { |
|
| 80 | + break; |
|
| 81 | + } |
|
| 82 | + foreach ($couple as $n => $val) { |
|
| 83 | + $var = $val[0]; |
|
| 84 | + if ($var->type != 'texte') { |
|
| 85 | + if ($n or $k or $fond1) { |
|
| 86 | + $erreur_p_i_i = [ |
|
| 87 | + 'zbug_parametres_inclus_incorrects', |
|
| 88 | + ['param' => $var->nom_champ] |
|
| 89 | + ]; |
|
| 90 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | + break; |
|
| 92 | + } else { |
|
| 93 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | + } |
|
| 95 | + } else { |
|
| 96 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | + $m = array_pad($m, 3, null); |
|
| 98 | + $var = $m[1]; |
|
| 99 | + $auto = false; |
|
| 100 | 100 | ; |
| 101 | - if ($m[2]) { |
|
| 102 | - $v = $m[3]; |
|
| 103 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | - $v = $m[1]; |
|
| 105 | - } |
|
| 106 | - $val[0] = new Texte(); |
|
| 107 | - $val[0]->texte = $v; |
|
| 108 | - } elseif ($k or $n or $fond1) { |
|
| 109 | - $auto = true; |
|
| 110 | - } else { |
|
| 111 | - $var = 1; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($var == 'lang') { |
|
| 115 | - $lang = !$auto |
|
| 116 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | - : '$GLOBALS["spip_lang"]'; |
|
| 118 | - } else { |
|
| 119 | - $val = $auto |
|
| 120 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | - if ($var !== 1) { |
|
| 123 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 125 | - } else { |
|
| 126 | - $val = $echap ? "'.$val.'" : $val; |
|
| 127 | - } |
|
| 128 | - $l[$var] = $val; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($erreur_p_i_i) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | - // sauf si on n'en veut pas |
|
| 139 | - if ($lang === false) { |
|
| 140 | - return $l; |
|
| 141 | - } |
|
| 142 | - if (!$lang) { |
|
| 143 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | - } |
|
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | - |
|
| 147 | - return $l; |
|
| 101 | + if ($m[2]) { |
|
| 102 | + $v = $m[3]; |
|
| 103 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | + $v = $m[1]; |
|
| 105 | + } |
|
| 106 | + $val[0] = new Texte(); |
|
| 107 | + $val[0]->texte = $v; |
|
| 108 | + } elseif ($k or $n or $fond1) { |
|
| 109 | + $auto = true; |
|
| 110 | + } else { |
|
| 111 | + $var = 1; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($var == 'lang') { |
|
| 115 | + $lang = !$auto |
|
| 116 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | + : '$GLOBALS["spip_lang"]'; |
|
| 118 | + } else { |
|
| 119 | + $val = $auto |
|
| 120 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | + if ($var !== 1) { |
|
| 123 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | + . $val . ($echap ? ") . '" : ' '); |
|
| 125 | + } else { |
|
| 126 | + $val = $echap ? "'.$val.'" : $val; |
|
| 127 | + } |
|
| 128 | + $l[$var] = $val; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($erreur_p_i_i) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | + // sauf si on n'en veut pas |
|
| 139 | + if ($lang === false) { |
|
| 140 | + return $l; |
|
| 141 | + } |
|
| 142 | + if (!$lang) { |
|
| 143 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | + } |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | + |
|
| 147 | + return $l; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,83 +168,83 @@ discard block |
||
| 168 | 168 | **/ |
| 169 | 169 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 170 | 170 | |
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,173 +478,173 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $boucle = &$boucles[$id_boucle]; |
|
| 482 | - $return = $boucle->return; |
|
| 483 | - $type_boucle = $boucle->type_requete; |
|
| 484 | - $primary = $boucle->primary; |
|
| 485 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | - $corps = ''; |
|
| 488 | - |
|
| 489 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | - // et puis faire un [] plutot qu'un "','." |
|
| 491 | - if ($boucle->doublons) { |
|
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | - index_pile($id_boucle, $primary, $boucles) |
|
| 494 | - . "; // doublons\n"; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // La boucle doit-elle selectionner la langue ? |
|
| 498 | - // - par defaut, les boucles suivantes le font |
|
| 499 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | - if ( |
|
| 502 | - !$constant && $boucle->lang_select != 'non' && |
|
| 503 | - (($boucle->lang_select == 'oui') || |
|
| 504 | - in_array($type_boucle, [ |
|
| 505 | - 'articles', |
|
| 506 | - 'rubriques', |
|
| 507 | - 'hierarchie', |
|
| 508 | - 'breves' |
|
| 509 | - ])) |
|
| 510 | - ) { |
|
| 511 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | - // afin que le corps de boucle affecte la globale directement |
|
| 513 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | - $fin_lang = "lang_select();\n\t"; |
|
| 515 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | - |
|
| 517 | - $corps .= |
|
| 518 | - "\n\t\tlang_select_public(" |
|
| 519 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 521 | - . (in_array($type_boucle, [ |
|
| 522 | - 'articles', |
|
| 523 | - 'rubriques', |
|
| 524 | - 'hierarchie', |
|
| 525 | - 'breves' |
|
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | - . ');'; |
|
| 528 | - } else { |
|
| 529 | - $init_lang = ''; |
|
| 530 | - $fin_lang = ''; |
|
| 531 | - $fin_lang_select_public = ''; |
|
| 532 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | - if ( |
|
| 534 | - strpos($return, '?php') === false |
|
| 535 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | - ) { |
|
| 537 | - $i = 1; |
|
| 538 | - foreach ($r[1] as $t) { |
|
| 539 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | - $return = str_replace($t, "\$l$i", $return); |
|
| 541 | - $i++; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // gestion optimale des separateurs et des boucles constantes |
|
| 547 | - if (count($boucle->separateur)) { |
|
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $corps .= |
|
| 552 | - ((!$boucle->separateur) ? |
|
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 557 | - ((strpos($return, '$t1.') === 0) ? |
|
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | - |
|
| 563 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | - // souhaite invalider ces elements |
|
| 565 | - if (!$constant and $primary) { |
|
| 566 | - include_spip('inc/invalideur'); |
|
| 567 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // gerer le compteur de boucle |
|
| 571 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | - |
|
| 573 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | - . $boucle->partie |
|
| 576 | - . $corps; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // depiler la lang de la boucle si besoin |
|
| 580 | - $corps .= $fin_lang_select_public; |
|
| 581 | - |
|
| 582 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | - |
|
| 584 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | - if (!$boucle->numrows) { |
|
| 587 | - return "\n\t\$t0 = '';"; |
|
| 588 | - } else { |
|
| 589 | - $corps = ''; |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $boucle->numrows = true; |
|
| 593 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $count = ''; |
|
| 600 | - if (!$boucle->select) { |
|
| 601 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | - $count = '1'; |
|
| 603 | - } else { |
|
| 604 | - $count = 'count(*)'; |
|
| 605 | - } |
|
| 606 | - $boucles[$id_boucle]->select[] = $count; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if ($flag_cpt) { |
|
| 610 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | - } else { |
|
| 613 | - $nums = ''; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | - . $boucle->mode_partie |
|
| 620 | - . "\n\t"; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Ne calculer la requete que maintenant |
|
| 624 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | - |
|
| 626 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | - ? ("\n\t$init = array();") : '') |
|
| 628 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | - |
|
| 630 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | - |
|
| 632 | - $a = sprintf( |
|
| 633 | - CODE_CORPS_BOUCLE, |
|
| 634 | - $init, |
|
| 635 | - $boucle->iterateur, |
|
| 636 | - '$command', |
|
| 637 | - $contexte, |
|
| 638 | - $nums, |
|
| 639 | - $init_lang, |
|
| 640 | - $corps, |
|
| 641 | - $fin_lang, |
|
| 642 | - $trace, |
|
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | - ); |
|
| 481 | + $boucle = &$boucles[$id_boucle]; |
|
| 482 | + $return = $boucle->return; |
|
| 483 | + $type_boucle = $boucle->type_requete; |
|
| 484 | + $primary = $boucle->primary; |
|
| 485 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | + $corps = ''; |
|
| 488 | + |
|
| 489 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | + // et puis faire un [] plutot qu'un "','." |
|
| 491 | + if ($boucle->doublons) { |
|
| 492 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | + index_pile($id_boucle, $primary, $boucles) |
|
| 494 | + . "; // doublons\n"; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // La boucle doit-elle selectionner la langue ? |
|
| 498 | + // - par defaut, les boucles suivantes le font |
|
| 499 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | + if ( |
|
| 502 | + !$constant && $boucle->lang_select != 'non' && |
|
| 503 | + (($boucle->lang_select == 'oui') || |
|
| 504 | + in_array($type_boucle, [ |
|
| 505 | + 'articles', |
|
| 506 | + 'rubriques', |
|
| 507 | + 'hierarchie', |
|
| 508 | + 'breves' |
|
| 509 | + ])) |
|
| 510 | + ) { |
|
| 511 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | + // afin que le corps de boucle affecte la globale directement |
|
| 513 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | + $fin_lang = "lang_select();\n\t"; |
|
| 515 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | + |
|
| 517 | + $corps .= |
|
| 518 | + "\n\t\tlang_select_public(" |
|
| 519 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | + . ", '" . $boucle->lang_select . "'" |
|
| 521 | + . (in_array($type_boucle, [ |
|
| 522 | + 'articles', |
|
| 523 | + 'rubriques', |
|
| 524 | + 'hierarchie', |
|
| 525 | + 'breves' |
|
| 526 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | + . ');'; |
|
| 528 | + } else { |
|
| 529 | + $init_lang = ''; |
|
| 530 | + $fin_lang = ''; |
|
| 531 | + $fin_lang_select_public = ''; |
|
| 532 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | + if ( |
|
| 534 | + strpos($return, '?php') === false |
|
| 535 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | + ) { |
|
| 537 | + $i = 1; |
|
| 538 | + foreach ($r[1] as $t) { |
|
| 539 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | + $return = str_replace($t, "\$l$i", $return); |
|
| 541 | + $i++; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // gestion optimale des separateurs et des boucles constantes |
|
| 547 | + if (count($boucle->separateur)) { |
|
| 548 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $corps .= |
|
| 552 | + ((!$boucle->separateur) ? |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | + (($return === "''") ? '' : |
|
| 555 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | + ("\n\t\t\$t1 " . |
|
| 557 | + ((strpos($return, '$t1.') === 0) ? |
|
| 558 | + ('.=' . substr($return, 4)) : |
|
| 559 | + ('= ' . $return)) . |
|
| 560 | + ";\n\t\t" . |
|
| 561 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | + |
|
| 563 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | + // souhaite invalider ces elements |
|
| 565 | + if (!$constant and $primary) { |
|
| 566 | + include_spip('inc/invalideur'); |
|
| 567 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // gerer le compteur de boucle |
|
| 571 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | + |
|
| 573 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | + . $boucle->partie |
|
| 576 | + . $corps; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // depiler la lang de la boucle si besoin |
|
| 580 | + $corps .= $fin_lang_select_public; |
|
| 581 | + |
|
| 582 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | + |
|
| 584 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | + if (!$boucle->numrows) { |
|
| 587 | + return "\n\t\$t0 = '';"; |
|
| 588 | + } else { |
|
| 589 | + $corps = ''; |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $boucle->numrows = true; |
|
| 593 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $count = ''; |
|
| 600 | + if (!$boucle->select) { |
|
| 601 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | + $count = '1'; |
|
| 603 | + } else { |
|
| 604 | + $count = 'count(*)'; |
|
| 605 | + } |
|
| 606 | + $boucles[$id_boucle]->select[] = $count; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if ($flag_cpt) { |
|
| 610 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | + } else { |
|
| 613 | + $nums = ''; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | + . $boucle->mode_partie |
|
| 620 | + . "\n\t"; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Ne calculer la requete que maintenant |
|
| 624 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | + |
|
| 626 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | + ? ("\n\t$init = array();") : '') |
|
| 628 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | + |
|
| 630 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | + |
|
| 632 | + $a = sprintf( |
|
| 633 | + CODE_CORPS_BOUCLE, |
|
| 634 | + $init, |
|
| 635 | + $boucle->iterateur, |
|
| 636 | + '$command', |
|
| 637 | + $contexte, |
|
| 638 | + $nums, |
|
| 639 | + $init_lang, |
|
| 640 | + $corps, |
|
| 641 | + $fin_lang, |
|
| 642 | + $trace, |
|
| 643 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | + ); |
|
| 645 | 645 | |
| 646 | 646 | # var_dump($a);exit; |
| 647 | - return $a; |
|
| 647 | + return $a; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | |
@@ -660,48 +660,48 @@ discard block |
||
| 660 | 660 | * Code PHP compilé définissant les informations de requête |
| 661 | 661 | **/ |
| 662 | 662 | function calculer_requete_sql($boucle) { |
| 663 | - $init = []; |
|
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | - # En absence de champ c'est un decompte : |
|
| 667 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | - $init[] = calculer_dec( |
|
| 670 | - 'groupby', |
|
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | - ); |
|
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | - $init[] = calculer_dec( |
|
| 678 | - 'limit', |
|
| 679 | - ( |
|
| 680 | - strpos($boucle->limit, 'intval') === false ? |
|
| 681 | - "'" . ($boucle->limit) . "'" : |
|
| 682 | - $boucle->limit |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 686 | - $s = $d = ''; |
|
| 687 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 688 | - // ou recalculée à chaque passage (vide) |
|
| 689 | - foreach ($init as $i) { |
|
| 690 | - if (reset($i)) { |
|
| 691 | - $s .= "\n\t\t" . end($i); |
|
| 692 | - } # statique |
|
| 693 | - else { |
|
| 694 | - $d .= "\n\t" . end($i); |
|
| 695 | - } # dynamique |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 699 | - . $boucle->in |
|
| 700 | - . $boucle->hash |
|
| 701 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 702 | - . $s |
|
| 703 | - . "\n\t}" |
|
| 704 | - . $d; |
|
| 663 | + $init = []; |
|
| 664 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | + # En absence de champ c'est un decompte : |
|
| 667 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | + $init[] = calculer_dec( |
|
| 670 | + 'groupby', |
|
| 671 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | + ); |
|
| 673 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | + $init[] = calculer_dec( |
|
| 678 | + 'limit', |
|
| 679 | + ( |
|
| 680 | + strpos($boucle->limit, 'intval') === false ? |
|
| 681 | + "'" . ($boucle->limit) . "'" : |
|
| 682 | + $boucle->limit |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 686 | + $s = $d = ''; |
|
| 687 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 688 | + // ou recalculée à chaque passage (vide) |
|
| 689 | + foreach ($init as $i) { |
|
| 690 | + if (reset($i)) { |
|
| 691 | + $s .= "\n\t\t" . end($i); |
|
| 692 | + } # statique |
|
| 693 | + else { |
|
| 694 | + $d .= "\n\t" . end($i); |
|
| 695 | + } # dynamique |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 699 | + . $boucle->in |
|
| 700 | + . $boucle->hash |
|
| 701 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 702 | + . $s |
|
| 703 | + . "\n\t}" |
|
| 704 | + . $d; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -719,13 +719,13 @@ discard block |
||
| 719 | 719 | * qui peut être utilisé pour la production d'un tableau array() |
| 720 | 720 | **/ |
| 721 | 721 | function memoriser_contexte_compil($p) { |
| 722 | - return join(',', [ |
|
| 723 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 724 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 725 | - _q(isset($p->id_boucle) ? $p->id_boucle : ''), |
|
| 726 | - intval($p->ligne), |
|
| 727 | - '$GLOBALS[\'spip_lang\']' |
|
| 728 | - ]); |
|
| 722 | + return join(',', [ |
|
| 723 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 724 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 725 | + _q(isset($p->id_boucle) ? $p->id_boucle : ''), |
|
| 726 | + intval($p->ligne), |
|
| 727 | + '$GLOBALS[\'spip_lang\']' |
|
| 728 | + ]); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -743,19 +743,19 @@ discard block |
||
| 743 | 743 | * Objet Contexte |
| 744 | 744 | **/ |
| 745 | 745 | function reconstruire_contexte_compil($context_compil) { |
| 746 | - if (!is_array($context_compil)) { |
|
| 747 | - return $context_compil; |
|
| 748 | - } |
|
| 749 | - $p = new Contexte(); |
|
| 750 | - $p->descr = [ |
|
| 751 | - 'sourcefile' => $context_compil[0], |
|
| 752 | - 'nom' => $context_compil[1] |
|
| 753 | - ]; |
|
| 754 | - $p->id_boucle = $context_compil[2]; |
|
| 755 | - $p->ligne = $context_compil[3]; |
|
| 756 | - $p->lang = $context_compil[4]; |
|
| 757 | - |
|
| 758 | - return $p; |
|
| 746 | + if (!is_array($context_compil)) { |
|
| 747 | + return $context_compil; |
|
| 748 | + } |
|
| 749 | + $p = new Contexte(); |
|
| 750 | + $p->descr = [ |
|
| 751 | + 'sourcefile' => $context_compil[0], |
|
| 752 | + 'nom' => $context_compil[1] |
|
| 753 | + ]; |
|
| 754 | + $p->id_boucle = $context_compil[2]; |
|
| 755 | + $p->ligne = $context_compil[3]; |
|
| 756 | + $p->lang = $context_compil[4]; |
|
| 757 | + |
|
| 758 | + return $p; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -781,12 +781,12 @@ discard block |
||
| 781 | 781 | * - index 1 : Code de l'affectation |
| 782 | 782 | **/ |
| 783 | 783 | function calculer_dec($nom, $val) { |
| 784 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 785 | - // si une variable apparait dans le calcul de la clause |
|
| 786 | - // il faut la re-evaluer a chaque passage |
|
| 787 | - if ( |
|
| 788 | - strpos($val, '$') !== false |
|
| 789 | - /* |
|
| 784 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 785 | + // si une variable apparait dans le calcul de la clause |
|
| 786 | + // il faut la re-evaluer a chaque passage |
|
| 787 | + if ( |
|
| 788 | + strpos($val, '$') !== false |
|
| 789 | + /* |
|
| 790 | 790 | OR strpos($val, 'sql_') !== false |
| 791 | 791 | OR ( |
| 792 | 792 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -794,11 +794,11 @@ discard block |
||
| 794 | 794 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 795 | 795 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 796 | 796 | )*/ |
| 797 | - ) { |
|
| 798 | - $static = ''; |
|
| 799 | - } |
|
| 797 | + ) { |
|
| 798 | + $static = ''; |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 801 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -818,33 +818,33 @@ discard block |
||
| 818 | 818 | * Expression PHP décrivant un texte ou un tableau |
| 819 | 819 | **/ |
| 820 | 820 | function calculer_dump_array($a) { |
| 821 | - if (!is_array($a)) { |
|
| 822 | - return $a; |
|
| 823 | - } |
|
| 824 | - $res = ''; |
|
| 825 | - if ($a and $a[0] == "'?'") { |
|
| 826 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 827 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 828 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 829 | - ')'); |
|
| 830 | - } else { |
|
| 831 | - foreach ($a as $k => $v) { |
|
| 832 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 833 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 837 | - } |
|
| 821 | + if (!is_array($a)) { |
|
| 822 | + return $a; |
|
| 823 | + } |
|
| 824 | + $res = ''; |
|
| 825 | + if ($a and $a[0] == "'?'") { |
|
| 826 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 827 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 828 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 829 | + ')'); |
|
| 830 | + } else { |
|
| 831 | + foreach ($a as $k => $v) { |
|
| 832 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 833 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 837 | + } |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | // https://code.spip.net/@calculer_dump_join |
| 841 | 841 | function calculer_dump_join($a) { |
| 842 | - $res = ''; |
|
| 843 | - foreach ($a as $k => $v) { |
|
| 844 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 845 | - } |
|
| 842 | + $res = ''; |
|
| 843 | + foreach ($a as $k => $v) { |
|
| 844 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return 'array(' . substr($res, 2) . ')'; |
|
| 847 | + return 'array(' . substr($res, 2) . ')'; |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
@@ -856,12 +856,12 @@ discard block |
||
| 856 | 856 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 857 | 857 | **/ |
| 858 | 858 | function calculer_from(&$boucle) { |
| 859 | - $res = ''; |
|
| 860 | - foreach ($boucle->from as $k => $v) { |
|
| 861 | - $res .= ",'$k' => '$v'"; |
|
| 862 | - } |
|
| 859 | + $res = ''; |
|
| 860 | + foreach ($boucle->from as $k => $v) { |
|
| 861 | + $res .= ",'$k' => '$v'"; |
|
| 862 | + } |
|
| 863 | 863 | |
| 864 | - return 'array(' . substr($res, 1) . ')'; |
|
| 864 | + return 'array(' . substr($res, 1) . ')'; |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | /** |
@@ -874,31 +874,31 @@ discard block |
||
| 874 | 874 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 875 | 875 | **/ |
| 876 | 876 | function calculer_from_type(&$boucle) { |
| 877 | - $res = ''; |
|
| 878 | - foreach ($boucle->from_type as $k => $v) { |
|
| 879 | - $res .= ",'$k' => '$v'"; |
|
| 880 | - } |
|
| 877 | + $res = ''; |
|
| 878 | + foreach ($boucle->from_type as $k => $v) { |
|
| 879 | + $res .= ",'$k' => '$v'"; |
|
| 880 | + } |
|
| 881 | 881 | |
| 882 | - return 'array(' . substr($res, 1) . ')'; |
|
| 882 | + return 'array(' . substr($res, 1) . ')'; |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | // https://code.spip.net/@calculer_order |
| 886 | 886 | function calculer_order(&$boucle) { |
| 887 | - if ( |
|
| 888 | - !$order = $boucle->order |
|
| 889 | - and !$order = $boucle->default_order |
|
| 890 | - ) { |
|
| 891 | - $order = []; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 887 | + if ( |
|
| 888 | + !$order = $boucle->order |
|
| 889 | + and !$order = $boucle->default_order |
|
| 890 | + ) { |
|
| 891 | + $order = []; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 895 | 895 | $col = "." . $boucle->modificateur['collate']; |
| 896 | 896 | foreach($order as $k=>$o) |
| 897 | 897 | if (strpos($order[$k],'COLLATE')===false) |
| 898 | 898 | $order[$k].= $col; |
| 899 | 899 | }*/ |
| 900 | 900 | |
| 901 | - return join(', ', $order); |
|
| 901 | + return join(', ', $order); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -908,62 +908,62 @@ discard block |
||
| 908 | 908 | |
| 909 | 909 | // https://code.spip.net/@calculer_liste |
| 910 | 910 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 911 | - if (!$tableau) { |
|
| 912 | - return "''"; |
|
| 913 | - } |
|
| 914 | - if (is_string($descr)) { |
|
| 915 | - if (isset($boucles[$descr])) { |
|
| 916 | - $idb = $descr; |
|
| 917 | - $descr = []; |
|
| 918 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 919 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 920 | - } |
|
| 921 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 922 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - else { |
|
| 926 | - $descr = []; |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - if (!isset($descr['niv'])) { |
|
| 930 | - $descr['niv'] = 0; |
|
| 931 | - } |
|
| 932 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 933 | - if ($codes === false) { |
|
| 934 | - return false; |
|
| 935 | - } |
|
| 936 | - $n = count($codes); |
|
| 937 | - if (!$n) { |
|
| 938 | - return "''"; |
|
| 939 | - } |
|
| 940 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 941 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 942 | - if ($n == 1) { |
|
| 943 | - return $codes[0]; |
|
| 944 | - } else { |
|
| 945 | - $res = ''; |
|
| 946 | - foreach ($codes as $code) { |
|
| 947 | - if ( |
|
| 948 | - !preg_match("/^'[^']*'$/", $code) |
|
| 949 | - or substr($res, -1, 1) !== "'" |
|
| 950 | - ) { |
|
| 951 | - $res .= " .\n$tab$code"; |
|
| 952 | - } else { |
|
| 953 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 954 | - } |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 958 | - } |
|
| 959 | - } else { |
|
| 960 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 961 | - |
|
| 962 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 963 | - " ,\n$tab", |
|
| 964 | - $codes |
|
| 965 | - ) . ')))'; |
|
| 966 | - } |
|
| 911 | + if (!$tableau) { |
|
| 912 | + return "''"; |
|
| 913 | + } |
|
| 914 | + if (is_string($descr)) { |
|
| 915 | + if (isset($boucles[$descr])) { |
|
| 916 | + $idb = $descr; |
|
| 917 | + $descr = []; |
|
| 918 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 919 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 920 | + } |
|
| 921 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 922 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + else { |
|
| 926 | + $descr = []; |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + if (!isset($descr['niv'])) { |
|
| 930 | + $descr['niv'] = 0; |
|
| 931 | + } |
|
| 932 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 933 | + if ($codes === false) { |
|
| 934 | + return false; |
|
| 935 | + } |
|
| 936 | + $n = count($codes); |
|
| 937 | + if (!$n) { |
|
| 938 | + return "''"; |
|
| 939 | + } |
|
| 940 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 941 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 942 | + if ($n == 1) { |
|
| 943 | + return $codes[0]; |
|
| 944 | + } else { |
|
| 945 | + $res = ''; |
|
| 946 | + foreach ($codes as $code) { |
|
| 947 | + if ( |
|
| 948 | + !preg_match("/^'[^']*'$/", $code) |
|
| 949 | + or substr($res, -1, 1) !== "'" |
|
| 950 | + ) { |
|
| 951 | + $res .= " .\n$tab$code"; |
|
| 952 | + } else { |
|
| 953 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 958 | + } |
|
| 959 | + } else { |
|
| 960 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 961 | + |
|
| 962 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 963 | + " ,\n$tab", |
|
| 964 | + $codes |
|
| 965 | + ) . ')))'; |
|
| 966 | + } |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | |
@@ -974,213 +974,213 @@ discard block |
||
| 974 | 974 | // https://code.spip.net/@compile_cas |
| 975 | 975 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 976 | 976 | |
| 977 | - $codes = []; |
|
| 978 | - // cas de la boucle recursive |
|
| 979 | - if (is_array($id_boucle)) { |
|
| 980 | - $id_boucle = $id_boucle[0]; |
|
| 981 | - } |
|
| 982 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 983 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 984 | - $mode = _request('var_mode_affiche'); |
|
| 985 | - $err_e_c = ''; |
|
| 986 | - // chaque commentaire introduit dans le code doit commencer |
|
| 987 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 988 | - foreach ($tableau as $p) { |
|
| 989 | - switch ($p->type) { |
|
| 990 | - // texte seul |
|
| 991 | - case 'texte': |
|
| 992 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 993 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 994 | - $avant = ''; |
|
| 995 | - $apres = ''; |
|
| 996 | - $altern = "''"; |
|
| 997 | - break; |
|
| 998 | - |
|
| 999 | - case 'polyglotte': |
|
| 1000 | - $code = ''; |
|
| 1001 | - foreach ($p->traductions as $k => $v) { |
|
| 1002 | - $code .= ",'" . |
|
| 1003 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1004 | - "' => '" . |
|
| 1005 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1006 | - "'"; |
|
| 1007 | - } |
|
| 1008 | - $code = 'choisir_traduction(array(' . |
|
| 1009 | - substr($code, 1) . |
|
| 1010 | - '))'; |
|
| 1011 | - $commentaire = '&'; |
|
| 1012 | - $avant = ''; |
|
| 1013 | - $apres = ''; |
|
| 1014 | - $altern = "''"; |
|
| 1015 | - break; |
|
| 1016 | - |
|
| 1017 | - // inclure |
|
| 1018 | - case 'include': |
|
| 1019 | - $p->descr = $descr; |
|
| 1020 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1021 | - if ($code === false) { |
|
| 1022 | - $err_e_c = true; |
|
| 1023 | - $code = "''"; |
|
| 1024 | - } else { |
|
| 1025 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1026 | - $avant = ''; |
|
| 1027 | - $apres = ''; |
|
| 1028 | - $altern = "''"; |
|
| 1029 | - } |
|
| 1030 | - break; |
|
| 1031 | - |
|
| 1032 | - // boucle |
|
| 1033 | - case TYPE_RECURSIF: |
|
| 1034 | - $nom = $p->id_boucle; |
|
| 1035 | - $newdescr = $descr; |
|
| 1036 | - $newdescr['id_mere'] = $nom; |
|
| 1037 | - $newdescr['niv']++; |
|
| 1038 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1039 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1040 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1041 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1042 | - $newdescr['niv']--; |
|
| 1043 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1044 | - if ( |
|
| 1045 | - $preaff === false |
|
| 1046 | - or $avant === false |
|
| 1047 | - or $apres === false |
|
| 1048 | - or $altern === false |
|
| 1049 | - or $postaff === false |
|
| 1050 | - ) { |
|
| 1051 | - $err_e_c = true; |
|
| 1052 | - $code = "''"; |
|
| 1053 | - } else { |
|
| 1054 | - $code = 'BOUCLE' . |
|
| 1055 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1056 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1057 | - $commentaire = "?$nom"; |
|
| 1058 | - if ( |
|
| 1059 | - !$boucles[$nom]->milieu |
|
| 1060 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1061 | - ) { |
|
| 1062 | - if ($preaff != "''") { |
|
| 1063 | - $code .= "\n. $preaff"; |
|
| 1064 | - } |
|
| 1065 | - if ($altern != "''") { |
|
| 1066 | - $code .= "\n. $altern"; |
|
| 1067 | - } |
|
| 1068 | - if ($postaff != "''") { |
|
| 1069 | - $code .= "\n. $postaff"; |
|
| 1070 | - } |
|
| 1071 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1072 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1073 | - } |
|
| 1074 | - $avant = $apres = $altern = "''"; |
|
| 1075 | - } else { |
|
| 1076 | - if ($preaff != "''") { |
|
| 1077 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1078 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1079 | - } |
|
| 1080 | - if ($postaff != "''") { |
|
| 1081 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1082 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1083 | - } |
|
| 1084 | - if ($altern != "''") { |
|
| 1085 | - $altern = "($altern)"; |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - break; |
|
| 1090 | - |
|
| 1091 | - case 'idiome': |
|
| 1092 | - $l = []; |
|
| 1093 | - $code = ''; |
|
| 1094 | - foreach ($p->arg as $k => $v) { |
|
| 1095 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1096 | - if ($k) { |
|
| 1097 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1098 | - } else { |
|
| 1099 | - $code = $_v; |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1103 | - if ($p->module) { |
|
| 1104 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1105 | - } elseif ($p->nom_champ) { |
|
| 1106 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1107 | - } else { |
|
| 1108 | - $m = ''; |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - $code = (!$code ? "'$m'" : |
|
| 1112 | - ($m ? "'$m' . $code" : |
|
| 1113 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1114 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1115 | - $code = "_T($code)"; |
|
| 1116 | - if ($p->param) { |
|
| 1117 | - $p->id_boucle = $id_boucle; |
|
| 1118 | - $p->boucles = &$boucles; |
|
| 1119 | - $code = compose_filtres($p, $code); |
|
| 1120 | - } |
|
| 1121 | - $commentaire = ':'; |
|
| 1122 | - $avant = ''; |
|
| 1123 | - $apres = ''; |
|
| 1124 | - $altern = "''"; |
|
| 1125 | - break; |
|
| 1126 | - |
|
| 1127 | - case 'champ': |
|
| 1128 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1129 | - $p->id_boucle = $id_boucle; |
|
| 1130 | - $p->boucles = &$boucles; |
|
| 1131 | - $p->descr = $descr; |
|
| 1132 | - #$p->interdire_scripts = true; |
|
| 1133 | - $p->type_requete = $type; |
|
| 1134 | - |
|
| 1135 | - $code = calculer_champ($p); |
|
| 1136 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1137 | - $avant = calculer_liste( |
|
| 1138 | - $p->avant, |
|
| 1139 | - $descr, |
|
| 1140 | - $boucles, |
|
| 1141 | - $id_boucle |
|
| 1142 | - ); |
|
| 1143 | - $apres = calculer_liste( |
|
| 1144 | - $p->apres, |
|
| 1145 | - $descr, |
|
| 1146 | - $boucles, |
|
| 1147 | - $id_boucle |
|
| 1148 | - ); |
|
| 1149 | - $altern = "''"; |
|
| 1150 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1151 | - // forcer la conversion en une chaine par strval |
|
| 1152 | - // si ca peut etre autre chose qu'une chaine |
|
| 1153 | - if ( |
|
| 1154 | - ($avant != "''" or $apres != "''") |
|
| 1155 | - and $code[0] != "'" |
|
| 977 | + $codes = []; |
|
| 978 | + // cas de la boucle recursive |
|
| 979 | + if (is_array($id_boucle)) { |
|
| 980 | + $id_boucle = $id_boucle[0]; |
|
| 981 | + } |
|
| 982 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 983 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 984 | + $mode = _request('var_mode_affiche'); |
|
| 985 | + $err_e_c = ''; |
|
| 986 | + // chaque commentaire introduit dans le code doit commencer |
|
| 987 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 988 | + foreach ($tableau as $p) { |
|
| 989 | + switch ($p->type) { |
|
| 990 | + // texte seul |
|
| 991 | + case 'texte': |
|
| 992 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 993 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 994 | + $avant = ''; |
|
| 995 | + $apres = ''; |
|
| 996 | + $altern = "''"; |
|
| 997 | + break; |
|
| 998 | + |
|
| 999 | + case 'polyglotte': |
|
| 1000 | + $code = ''; |
|
| 1001 | + foreach ($p->traductions as $k => $v) { |
|
| 1002 | + $code .= ",'" . |
|
| 1003 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1004 | + "' => '" . |
|
| 1005 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1006 | + "'"; |
|
| 1007 | + } |
|
| 1008 | + $code = 'choisir_traduction(array(' . |
|
| 1009 | + substr($code, 1) . |
|
| 1010 | + '))'; |
|
| 1011 | + $commentaire = '&'; |
|
| 1012 | + $avant = ''; |
|
| 1013 | + $apres = ''; |
|
| 1014 | + $altern = "''"; |
|
| 1015 | + break; |
|
| 1016 | + |
|
| 1017 | + // inclure |
|
| 1018 | + case 'include': |
|
| 1019 | + $p->descr = $descr; |
|
| 1020 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1021 | + if ($code === false) { |
|
| 1022 | + $err_e_c = true; |
|
| 1023 | + $code = "''"; |
|
| 1024 | + } else { |
|
| 1025 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1026 | + $avant = ''; |
|
| 1027 | + $apres = ''; |
|
| 1028 | + $altern = "''"; |
|
| 1029 | + } |
|
| 1030 | + break; |
|
| 1031 | + |
|
| 1032 | + // boucle |
|
| 1033 | + case TYPE_RECURSIF: |
|
| 1034 | + $nom = $p->id_boucle; |
|
| 1035 | + $newdescr = $descr; |
|
| 1036 | + $newdescr['id_mere'] = $nom; |
|
| 1037 | + $newdescr['niv']++; |
|
| 1038 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1039 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1040 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1041 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1042 | + $newdescr['niv']--; |
|
| 1043 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1044 | + if ( |
|
| 1045 | + $preaff === false |
|
| 1046 | + or $avant === false |
|
| 1047 | + or $apres === false |
|
| 1048 | + or $altern === false |
|
| 1049 | + or $postaff === false |
|
| 1050 | + ) { |
|
| 1051 | + $err_e_c = true; |
|
| 1052 | + $code = "''"; |
|
| 1053 | + } else { |
|
| 1054 | + $code = 'BOUCLE' . |
|
| 1055 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1056 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1057 | + $commentaire = "?$nom"; |
|
| 1058 | + if ( |
|
| 1059 | + !$boucles[$nom]->milieu |
|
| 1060 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1061 | + ) { |
|
| 1062 | + if ($preaff != "''") { |
|
| 1063 | + $code .= "\n. $preaff"; |
|
| 1064 | + } |
|
| 1065 | + if ($altern != "''") { |
|
| 1066 | + $code .= "\n. $altern"; |
|
| 1067 | + } |
|
| 1068 | + if ($postaff != "''") { |
|
| 1069 | + $code .= "\n. $postaff"; |
|
| 1070 | + } |
|
| 1071 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1072 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1073 | + } |
|
| 1074 | + $avant = $apres = $altern = "''"; |
|
| 1075 | + } else { |
|
| 1076 | + if ($preaff != "''") { |
|
| 1077 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1078 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1079 | + } |
|
| 1080 | + if ($postaff != "''") { |
|
| 1081 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1082 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1083 | + } |
|
| 1084 | + if ($altern != "''") { |
|
| 1085 | + $altern = "($altern)"; |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + break; |
|
| 1090 | + |
|
| 1091 | + case 'idiome': |
|
| 1092 | + $l = []; |
|
| 1093 | + $code = ''; |
|
| 1094 | + foreach ($p->arg as $k => $v) { |
|
| 1095 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1096 | + if ($k) { |
|
| 1097 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1098 | + } else { |
|
| 1099 | + $code = $_v; |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1103 | + if ($p->module) { |
|
| 1104 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1105 | + } elseif ($p->nom_champ) { |
|
| 1106 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1107 | + } else { |
|
| 1108 | + $m = ''; |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + $code = (!$code ? "'$m'" : |
|
| 1112 | + ($m ? "'$m' . $code" : |
|
| 1113 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1114 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1115 | + $code = "_T($code)"; |
|
| 1116 | + if ($p->param) { |
|
| 1117 | + $p->id_boucle = $id_boucle; |
|
| 1118 | + $p->boucles = &$boucles; |
|
| 1119 | + $code = compose_filtres($p, $code); |
|
| 1120 | + } |
|
| 1121 | + $commentaire = ':'; |
|
| 1122 | + $avant = ''; |
|
| 1123 | + $apres = ''; |
|
| 1124 | + $altern = "''"; |
|
| 1125 | + break; |
|
| 1126 | + |
|
| 1127 | + case 'champ': |
|
| 1128 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1129 | + $p->id_boucle = $id_boucle; |
|
| 1130 | + $p->boucles = &$boucles; |
|
| 1131 | + $p->descr = $descr; |
|
| 1132 | + #$p->interdire_scripts = true; |
|
| 1133 | + $p->type_requete = $type; |
|
| 1134 | + |
|
| 1135 | + $code = calculer_champ($p); |
|
| 1136 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1137 | + $avant = calculer_liste( |
|
| 1138 | + $p->avant, |
|
| 1139 | + $descr, |
|
| 1140 | + $boucles, |
|
| 1141 | + $id_boucle |
|
| 1142 | + ); |
|
| 1143 | + $apres = calculer_liste( |
|
| 1144 | + $p->apres, |
|
| 1145 | + $descr, |
|
| 1146 | + $boucles, |
|
| 1147 | + $id_boucle |
|
| 1148 | + ); |
|
| 1149 | + $altern = "''"; |
|
| 1150 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1151 | + // forcer la conversion en une chaine par strval |
|
| 1152 | + // si ca peut etre autre chose qu'une chaine |
|
| 1153 | + if ( |
|
| 1154 | + ($avant != "''" or $apres != "''") |
|
| 1155 | + and $code[0] != "'" |
|
| 1156 | 1156 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1157 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1158 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1159 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1160 | - ) { |
|
| 1161 | - $code = "strval($code)"; |
|
| 1162 | - } |
|
| 1163 | - break; |
|
| 1164 | - |
|
| 1165 | - default: |
|
| 1166 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1167 | - $code = "''"; |
|
| 1168 | - $p->descr = $descr; |
|
| 1169 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1170 | - erreur_squelette($err_e_c, $p); |
|
| 1171 | - } // switch |
|
| 1172 | - |
|
| 1173 | - if ($code != "''") { |
|
| 1174 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1175 | - $codes[] = (($mode == 'validation') ? |
|
| 1176 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1177 | - : (($mode == 'code') ? |
|
| 1178 | - "\n// $commentaire\n$code" : |
|
| 1179 | - $code)); |
|
| 1180 | - } |
|
| 1181 | - } // foreach |
|
| 1182 | - |
|
| 1183 | - return $err_e_c ? false : $codes; |
|
| 1157 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1158 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1159 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1160 | + ) { |
|
| 1161 | + $code = "strval($code)"; |
|
| 1162 | + } |
|
| 1163 | + break; |
|
| 1164 | + |
|
| 1165 | + default: |
|
| 1166 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1167 | + $code = "''"; |
|
| 1168 | + $p->descr = $descr; |
|
| 1169 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1170 | + erreur_squelette($err_e_c, $p); |
|
| 1171 | + } // switch |
|
| 1172 | + |
|
| 1173 | + if ($code != "''") { |
|
| 1174 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1175 | + $codes[] = (($mode == 'validation') ? |
|
| 1176 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1177 | + : (($mode == 'code') ? |
|
| 1178 | + "\n// $commentaire\n$code" : |
|
| 1179 | + $code)); |
|
| 1180 | + } |
|
| 1181 | + } // foreach |
|
| 1182 | + |
|
| 1183 | + return $err_e_c ? false : $codes; |
|
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | 1186 | /** |
@@ -1190,13 +1190,13 @@ discard block |
||
| 1190 | 1190 | * @return string |
| 1191 | 1191 | */ |
| 1192 | 1192 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1193 | - if ($partie1 === "''") { |
|
| 1194 | - return $partie2; |
|
| 1195 | - } |
|
| 1196 | - if ($partie2 === "''") { |
|
| 1197 | - return $partie1; |
|
| 1198 | - } |
|
| 1199 | - return "$partie1\n. $partie2"; |
|
| 1193 | + if ($partie1 === "''") { |
|
| 1194 | + return $partie2; |
|
| 1195 | + } |
|
| 1196 | + if ($partie2 === "''") { |
|
| 1197 | + return $partie1; |
|
| 1198 | + } |
|
| 1199 | + return "$partie1\n. $partie2"; |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | |
@@ -1221,56 +1221,56 @@ discard block |
||
| 1221 | 1221 | * @return mixed|string |
| 1222 | 1222 | */ |
| 1223 | 1223 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1224 | - if ($avant === "''") { |
|
| 1225 | - $avant = ''; |
|
| 1226 | - } |
|
| 1227 | - if ($apres === "''") { |
|
| 1228 | - $apres = ''; |
|
| 1229 | - } |
|
| 1230 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1231 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1232 | - $t = $code; |
|
| 1233 | - $cond = ''; |
|
| 1234 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1235 | - $t = $r[2]; |
|
| 1236 | - $cond = '!' . $r[1]; |
|
| 1237 | - } else { |
|
| 1238 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1239 | - $t = $r[2]; |
|
| 1240 | - $cond = $r[1]; |
|
| 1241 | - } else { |
|
| 1242 | - $t = '$t' . $n; |
|
| 1243 | - $cond = "($t = $code)!==''"; |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1248 | - $t . |
|
| 1249 | - (!$apres ? '' : " . $apres"); |
|
| 1250 | - |
|
| 1251 | - if ($res !== $t) { |
|
| 1252 | - $res = "($res)"; |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - return $code; |
|
| 1224 | + if ($avant === "''") { |
|
| 1225 | + $avant = ''; |
|
| 1226 | + } |
|
| 1227 | + if ($apres === "''") { |
|
| 1228 | + $apres = ''; |
|
| 1229 | + } |
|
| 1230 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1231 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1232 | + $t = $code; |
|
| 1233 | + $cond = ''; |
|
| 1234 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1235 | + $t = $r[2]; |
|
| 1236 | + $cond = '!' . $r[1]; |
|
| 1237 | + } else { |
|
| 1238 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1239 | + $t = $r[2]; |
|
| 1240 | + $cond = $r[1]; |
|
| 1241 | + } else { |
|
| 1242 | + $t = '$t' . $n; |
|
| 1243 | + $cond = "($t = $code)!==''"; |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1248 | + $t . |
|
| 1249 | + (!$apres ? '' : " . $apres"); |
|
| 1250 | + |
|
| 1251 | + if ($res !== $t) { |
|
| 1252 | + $res = "($res)"; |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + return $code; |
|
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | |
| 1262 | 1262 | function compile_inclure_doublons($lexemes) { |
| 1263 | - foreach ($lexemes as $v) { |
|
| 1264 | - if ($v->type === 'include' and $v->param) { |
|
| 1265 | - foreach ($v->param as $r) { |
|
| 1266 | - if (trim($r[0]) === 'doublons') { |
|
| 1267 | - return true; |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return false; |
|
| 1263 | + foreach ($lexemes as $v) { |
|
| 1264 | + if ($v->type === 'include' and $v->param) { |
|
| 1265 | + foreach ($v->param as $r) { |
|
| 1266 | + if (trim($r[0]) === 'doublons') { |
|
| 1267 | + return true; |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return false; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1290,360 +1290,360 @@ discard block |
||
| 1290 | 1290 | |
| 1291 | 1291 | // https://code.spip.net/@public_compiler_dist |
| 1292 | 1292 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, string $connect = '') { |
| 1293 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1294 | - // Bonus : supprime le BOM |
|
| 1295 | - include_spip('inc/charsets'); |
|
| 1296 | - $squelette = transcoder_page($squelette); |
|
| 1297 | - |
|
| 1298 | - // rendre inertes les echappements de #[](){}<> |
|
| 1299 | - $i = 0; |
|
| 1300 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1301 | - $i++; |
|
| 1302 | - } |
|
| 1303 | - $squelette = preg_replace_callback( |
|
| 1304 | - ',\\\\([#[()\]{}<>]),', |
|
| 1305 | - function ($a) use ($inerte) { |
|
| 1306 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1307 | - }, |
|
| 1308 | - $squelette, |
|
| 1309 | - -1, |
|
| 1310 | - $esc |
|
| 1311 | - ); |
|
| 1312 | - |
|
| 1313 | - $descr = [ |
|
| 1314 | - 'nom' => $nom, |
|
| 1315 | - 'gram' => $gram, |
|
| 1316 | - 'sourcefile' => $sourcefile, |
|
| 1317 | - 'squelette' => $squelette |
|
| 1318 | - ]; |
|
| 1319 | - |
|
| 1320 | - // Phraser le squelette, selon sa grammaire |
|
| 1321 | - |
|
| 1322 | - $boucles = []; |
|
| 1323 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1324 | - |
|
| 1325 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1326 | - |
|
| 1327 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1328 | - |
|
| 1329 | - // restituer les echappements |
|
| 1330 | - if ($esc) { |
|
| 1331 | - foreach ($boucles as $i => $boucle) { |
|
| 1332 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1333 | - ",$inerte-(\d+)-,", |
|
| 1334 | - function ($a) { |
|
| 1335 | - return chr($a[1]); |
|
| 1336 | - }, |
|
| 1337 | - $boucle->return |
|
| 1338 | - ); |
|
| 1339 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1340 | - ",$inerte-(\d+)-,", |
|
| 1341 | - function ($a) { |
|
| 1342 | - return '\\\\' . chr($a[1]); |
|
| 1343 | - }, |
|
| 1344 | - $boucle->descr['squelette'] |
|
| 1345 | - ); |
|
| 1346 | - } |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1350 | - if ($debug) { |
|
| 1351 | - include_spip('public/decompiler'); |
|
| 1352 | - foreach ($boucles as $id => $boucle) { |
|
| 1353 | - if ($id) { |
|
| 1354 | - $decomp = "\n/* BOUCLE " . |
|
| 1355 | - $boucle->type_requete . |
|
| 1356 | - ' ' . |
|
| 1357 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1358 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1359 | - " */\n"; |
|
| 1360 | - } else { |
|
| 1361 | - $decomp = ("\n/*\n" . |
|
| 1362 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1363 | - . "\n*/"); |
|
| 1364 | - } |
|
| 1365 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1366 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - return $boucles; |
|
| 1293 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1294 | + // Bonus : supprime le BOM |
|
| 1295 | + include_spip('inc/charsets'); |
|
| 1296 | + $squelette = transcoder_page($squelette); |
|
| 1297 | + |
|
| 1298 | + // rendre inertes les echappements de #[](){}<> |
|
| 1299 | + $i = 0; |
|
| 1300 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1301 | + $i++; |
|
| 1302 | + } |
|
| 1303 | + $squelette = preg_replace_callback( |
|
| 1304 | + ',\\\\([#[()\]{}<>]),', |
|
| 1305 | + function ($a) use ($inerte) { |
|
| 1306 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1307 | + }, |
|
| 1308 | + $squelette, |
|
| 1309 | + -1, |
|
| 1310 | + $esc |
|
| 1311 | + ); |
|
| 1312 | + |
|
| 1313 | + $descr = [ |
|
| 1314 | + 'nom' => $nom, |
|
| 1315 | + 'gram' => $gram, |
|
| 1316 | + 'sourcefile' => $sourcefile, |
|
| 1317 | + 'squelette' => $squelette |
|
| 1318 | + ]; |
|
| 1319 | + |
|
| 1320 | + // Phraser le squelette, selon sa grammaire |
|
| 1321 | + |
|
| 1322 | + $boucles = []; |
|
| 1323 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1324 | + |
|
| 1325 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1326 | + |
|
| 1327 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1328 | + |
|
| 1329 | + // restituer les echappements |
|
| 1330 | + if ($esc) { |
|
| 1331 | + foreach ($boucles as $i => $boucle) { |
|
| 1332 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1333 | + ",$inerte-(\d+)-,", |
|
| 1334 | + function ($a) { |
|
| 1335 | + return chr($a[1]); |
|
| 1336 | + }, |
|
| 1337 | + $boucle->return |
|
| 1338 | + ); |
|
| 1339 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1340 | + ",$inerte-(\d+)-,", |
|
| 1341 | + function ($a) { |
|
| 1342 | + return '\\\\' . chr($a[1]); |
|
| 1343 | + }, |
|
| 1344 | + $boucle->descr['squelette'] |
|
| 1345 | + ); |
|
| 1346 | + } |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1350 | + if ($debug) { |
|
| 1351 | + include_spip('public/decompiler'); |
|
| 1352 | + foreach ($boucles as $id => $boucle) { |
|
| 1353 | + if ($id) { |
|
| 1354 | + $decomp = "\n/* BOUCLE " . |
|
| 1355 | + $boucle->type_requete . |
|
| 1356 | + ' ' . |
|
| 1357 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1358 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1359 | + " */\n"; |
|
| 1360 | + } else { |
|
| 1361 | + $decomp = ("\n/*\n" . |
|
| 1362 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1363 | + . "\n*/"); |
|
| 1364 | + } |
|
| 1365 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1366 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + return $boucles; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1374 | 1374 | // Autres specifications comme ci-dessus |
| 1375 | 1375 | |
| 1376 | 1376 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, string $connect = '') { |
| 1377 | - static $trouver_table; |
|
| 1378 | - spip_timer('calcul_skel'); |
|
| 1379 | - |
|
| 1380 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1381 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1382 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1383 | - |
|
| 1384 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1385 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - foreach ($boucles as $id => $boucle) { |
|
| 1389 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1390 | - } |
|
| 1391 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1392 | - |
|
| 1393 | - // Demander la description des tables une fois pour toutes |
|
| 1394 | - if (!$trouver_table) { |
|
| 1395 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - // reperer si les doublons sont demandes |
|
| 1399 | - // pour un inclure ou une boucle document |
|
| 1400 | - // c'est utile a la fonction champs_traitements |
|
| 1401 | - foreach ($boucles as $id => $boucle) { |
|
| 1402 | - if (!($type = $boucle->type_requete)) { |
|
| 1403 | - continue; |
|
| 1404 | - } |
|
| 1405 | - if ( |
|
| 1406 | - !$descr['documents'] and ( |
|
| 1407 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1408 | - compile_inclure_doublons($boucle->avant) or |
|
| 1409 | - compile_inclure_doublons($boucle->apres) or |
|
| 1410 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1411 | - compile_inclure_doublons($boucle->altern)) |
|
| 1412 | - ) { |
|
| 1413 | - $descr['documents'] = true; |
|
| 1414 | - } |
|
| 1415 | - if ($type != TYPE_RECURSIF) { |
|
| 1416 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1417 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1421 | - if ( |
|
| 1422 | - $g = charger_fonction( |
|
| 1423 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1424 | - 'iterateur', |
|
| 1425 | - true |
|
| 1426 | - ) |
|
| 1427 | - ) { |
|
| 1428 | - $boucles[$id] = $g($boucle); |
|
| 1429 | - |
|
| 1430 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1431 | - // utiliser les informations donnees par le requeteur |
|
| 1432 | - // cas "php:xx" et "data:xx". |
|
| 1433 | - } else { |
|
| 1434 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1435 | - $requeteur($boucles, $boucle, $id); |
|
| 1436 | - |
|
| 1437 | - // utiliser la description des champs transmis |
|
| 1438 | - } else { |
|
| 1439 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1440 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1441 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1442 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1443 | - if ( |
|
| 1444 | - !$show |
|
| 1445 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1446 | - ) { |
|
| 1447 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1448 | - } |
|
| 1449 | - if ($show) { |
|
| 1450 | - $boucles[$id]->show = $show; |
|
| 1451 | - // recopie les infos les plus importantes |
|
| 1452 | - $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1453 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1454 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1455 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1456 | - |
|
| 1457 | - if (empty($boucles[$id]->descr)) { |
|
| 1458 | - $boucles[$id]->descr = &$descr; |
|
| 1459 | - } |
|
| 1460 | - if ( |
|
| 1461 | - (!$boucles[$id]->jointures) |
|
| 1462 | - and is_array($show['tables_jointures']) |
|
| 1463 | - and count($x = $show['tables_jointures']) |
|
| 1464 | - ) { |
|
| 1465 | - $boucles[$id]->jointures = $x; |
|
| 1466 | - } |
|
| 1467 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1468 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1469 | - while ($j = array_pop($jointures)) { |
|
| 1470 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - } else { |
|
| 1474 | - // Pas une erreur si la table est optionnelle |
|
| 1475 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1476 | - $boucles[$id]->type_requete = ''; |
|
| 1477 | - } else { |
|
| 1478 | - $boucles[$id]->type_requete = false; |
|
| 1479 | - $boucle = $boucles[$id]; |
|
| 1480 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1481 | - ($boucle->sql_serveur . ':')) . |
|
| 1482 | - $type; |
|
| 1483 | - $msg = [ |
|
| 1484 | - 'zbug_table_inconnue', |
|
| 1485 | - ['table' => $x] |
|
| 1486 | - ]; |
|
| 1487 | - erreur_squelette($msg, $boucle); |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1496 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1497 | - foreach ($boucles as $id => $boucle) { |
|
| 1498 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1499 | - $boucles[$id]->descr = &$descr; |
|
| 1500 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1501 | - if (!$rec) { |
|
| 1502 | - $msg = [ |
|
| 1503 | - 'zbug_boucle_recursive_undef', |
|
| 1504 | - ['nom' => $boucle->param[0]] |
|
| 1505 | - ]; |
|
| 1506 | - erreur_squelette($msg, $boucle); |
|
| 1507 | - $boucles[$id]->type_requete = false; |
|
| 1508 | - } else { |
|
| 1509 | - $rec->externe = $id; |
|
| 1510 | - $descr['id_mere'] = $id; |
|
| 1511 | - $boucles[$id]->return = |
|
| 1512 | - calculer_liste( |
|
| 1513 | - [$rec], |
|
| 1514 | - $descr, |
|
| 1515 | - $boucles, |
|
| 1516 | - $boucle->param |
|
| 1517 | - ); |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - foreach ($boucles as $id => $boucle) { |
|
| 1522 | - $id = strval($id); // attention au type dans index_pile |
|
| 1523 | - $type = $boucle->type_requete; |
|
| 1524 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1525 | - $res = ''; |
|
| 1526 | - if ($boucle->param) { |
|
| 1527 | - // retourne un tableau en cas d'erreur |
|
| 1528 | - $res = calculer_criteres($id, $boucles); |
|
| 1529 | - } |
|
| 1530 | - $descr['id_mere'] = $id; |
|
| 1531 | - $boucles[$id]->return = |
|
| 1532 | - calculer_liste( |
|
| 1533 | - $boucle->milieu, |
|
| 1534 | - $descr, |
|
| 1535 | - $boucles, |
|
| 1536 | - $id |
|
| 1537 | - ); |
|
| 1538 | - // Si les criteres se sont mal compiles |
|
| 1539 | - // ne pas tenter d'assembler le code final |
|
| 1540 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1541 | - if (is_array($res)) { |
|
| 1542 | - $boucles[$id]->type_requete = false; |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - // idem pour la racine |
|
| 1548 | - $descr['id_mere'] = ''; |
|
| 1549 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1553 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1554 | - // de'terminables seulement maintenant |
|
| 1555 | - |
|
| 1556 | - foreach ($boucles as $id => $boucle) { |
|
| 1557 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1558 | - if ($boucle->return === false) { |
|
| 1559 | - $corps = false; |
|
| 1560 | - continue; |
|
| 1561 | - } |
|
| 1562 | - // appeler la fonction de definition de la boucle |
|
| 1563 | - |
|
| 1564 | - if ($req = $boucle->type_requete) { |
|
| 1565 | - // boucle personnalisée ? |
|
| 1566 | - $table = strtoupper($boucle->type_requete); |
|
| 1567 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1568 | - if ( |
|
| 1569 | - // fonction de boucle avec serveur & table |
|
| 1570 | - (!$serveur or |
|
| 1571 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1572 | - and (!function_exists($f = $f . '_dist')) |
|
| 1573 | - ) |
|
| 1574 | - ) |
|
| 1575 | - // fonction de boucle avec table |
|
| 1576 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1577 | - and (!function_exists($f = $f . '_dist')) |
|
| 1578 | - ) { |
|
| 1579 | - // fonction de boucle standard |
|
| 1580 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1581 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1586 | - "static \$connect;\n\t" . |
|
| 1587 | - "\$command['connect'] = \$connect = " . |
|
| 1588 | - _q($boucle->sql_serveur) . |
|
| 1589 | - ';' . |
|
| 1590 | - $f($id, $boucles); |
|
| 1591 | - } else { |
|
| 1592 | - $req = ("\n\treturn '';"); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - $boucles[$id]->return = |
|
| 1596 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1597 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1598 | - $req . |
|
| 1599 | - "\n}\n"; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1603 | - // retourner False, sinon inserer leur decompilation |
|
| 1604 | - if (is_bool($corps)) { |
|
| 1605 | - return false; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1377 | + static $trouver_table; |
|
| 1378 | + spip_timer('calcul_skel'); |
|
| 1379 | + |
|
| 1380 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1381 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1382 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1383 | + |
|
| 1384 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1385 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + foreach ($boucles as $id => $boucle) { |
|
| 1389 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1390 | + } |
|
| 1391 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1392 | + |
|
| 1393 | + // Demander la description des tables une fois pour toutes |
|
| 1394 | + if (!$trouver_table) { |
|
| 1395 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + // reperer si les doublons sont demandes |
|
| 1399 | + // pour un inclure ou une boucle document |
|
| 1400 | + // c'est utile a la fonction champs_traitements |
|
| 1401 | + foreach ($boucles as $id => $boucle) { |
|
| 1402 | + if (!($type = $boucle->type_requete)) { |
|
| 1403 | + continue; |
|
| 1404 | + } |
|
| 1405 | + if ( |
|
| 1406 | + !$descr['documents'] and ( |
|
| 1407 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1408 | + compile_inclure_doublons($boucle->avant) or |
|
| 1409 | + compile_inclure_doublons($boucle->apres) or |
|
| 1410 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1411 | + compile_inclure_doublons($boucle->altern)) |
|
| 1412 | + ) { |
|
| 1413 | + $descr['documents'] = true; |
|
| 1414 | + } |
|
| 1415 | + if ($type != TYPE_RECURSIF) { |
|
| 1416 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1417 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1421 | + if ( |
|
| 1422 | + $g = charger_fonction( |
|
| 1423 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1424 | + 'iterateur', |
|
| 1425 | + true |
|
| 1426 | + ) |
|
| 1427 | + ) { |
|
| 1428 | + $boucles[$id] = $g($boucle); |
|
| 1429 | + |
|
| 1430 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1431 | + // utiliser les informations donnees par le requeteur |
|
| 1432 | + // cas "php:xx" et "data:xx". |
|
| 1433 | + } else { |
|
| 1434 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1435 | + $requeteur($boucles, $boucle, $id); |
|
| 1436 | + |
|
| 1437 | + // utiliser la description des champs transmis |
|
| 1438 | + } else { |
|
| 1439 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1440 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1441 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1442 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1443 | + if ( |
|
| 1444 | + !$show |
|
| 1445 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1446 | + ) { |
|
| 1447 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1448 | + } |
|
| 1449 | + if ($show) { |
|
| 1450 | + $boucles[$id]->show = $show; |
|
| 1451 | + // recopie les infos les plus importantes |
|
| 1452 | + $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1453 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1454 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1455 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1456 | + |
|
| 1457 | + if (empty($boucles[$id]->descr)) { |
|
| 1458 | + $boucles[$id]->descr = &$descr; |
|
| 1459 | + } |
|
| 1460 | + if ( |
|
| 1461 | + (!$boucles[$id]->jointures) |
|
| 1462 | + and is_array($show['tables_jointures']) |
|
| 1463 | + and count($x = $show['tables_jointures']) |
|
| 1464 | + ) { |
|
| 1465 | + $boucles[$id]->jointures = $x; |
|
| 1466 | + } |
|
| 1467 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1468 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1469 | + while ($j = array_pop($jointures)) { |
|
| 1470 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + } else { |
|
| 1474 | + // Pas une erreur si la table est optionnelle |
|
| 1475 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1476 | + $boucles[$id]->type_requete = ''; |
|
| 1477 | + } else { |
|
| 1478 | + $boucles[$id]->type_requete = false; |
|
| 1479 | + $boucle = $boucles[$id]; |
|
| 1480 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1481 | + ($boucle->sql_serveur . ':')) . |
|
| 1482 | + $type; |
|
| 1483 | + $msg = [ |
|
| 1484 | + 'zbug_table_inconnue', |
|
| 1485 | + ['table' => $x] |
|
| 1486 | + ]; |
|
| 1487 | + erreur_squelette($msg, $boucle); |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1496 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1497 | + foreach ($boucles as $id => $boucle) { |
|
| 1498 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1499 | + $boucles[$id]->descr = &$descr; |
|
| 1500 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1501 | + if (!$rec) { |
|
| 1502 | + $msg = [ |
|
| 1503 | + 'zbug_boucle_recursive_undef', |
|
| 1504 | + ['nom' => $boucle->param[0]] |
|
| 1505 | + ]; |
|
| 1506 | + erreur_squelette($msg, $boucle); |
|
| 1507 | + $boucles[$id]->type_requete = false; |
|
| 1508 | + } else { |
|
| 1509 | + $rec->externe = $id; |
|
| 1510 | + $descr['id_mere'] = $id; |
|
| 1511 | + $boucles[$id]->return = |
|
| 1512 | + calculer_liste( |
|
| 1513 | + [$rec], |
|
| 1514 | + $descr, |
|
| 1515 | + $boucles, |
|
| 1516 | + $boucle->param |
|
| 1517 | + ); |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + foreach ($boucles as $id => $boucle) { |
|
| 1522 | + $id = strval($id); // attention au type dans index_pile |
|
| 1523 | + $type = $boucle->type_requete; |
|
| 1524 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1525 | + $res = ''; |
|
| 1526 | + if ($boucle->param) { |
|
| 1527 | + // retourne un tableau en cas d'erreur |
|
| 1528 | + $res = calculer_criteres($id, $boucles); |
|
| 1529 | + } |
|
| 1530 | + $descr['id_mere'] = $id; |
|
| 1531 | + $boucles[$id]->return = |
|
| 1532 | + calculer_liste( |
|
| 1533 | + $boucle->milieu, |
|
| 1534 | + $descr, |
|
| 1535 | + $boucles, |
|
| 1536 | + $id |
|
| 1537 | + ); |
|
| 1538 | + // Si les criteres se sont mal compiles |
|
| 1539 | + // ne pas tenter d'assembler le code final |
|
| 1540 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1541 | + if (is_array($res)) { |
|
| 1542 | + $boucles[$id]->type_requete = false; |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + // idem pour la racine |
|
| 1548 | + $descr['id_mere'] = ''; |
|
| 1549 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1550 | + |
|
| 1551 | + |
|
| 1552 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1553 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1554 | + // de'terminables seulement maintenant |
|
| 1555 | + |
|
| 1556 | + foreach ($boucles as $id => $boucle) { |
|
| 1557 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1558 | + if ($boucle->return === false) { |
|
| 1559 | + $corps = false; |
|
| 1560 | + continue; |
|
| 1561 | + } |
|
| 1562 | + // appeler la fonction de definition de la boucle |
|
| 1563 | + |
|
| 1564 | + if ($req = $boucle->type_requete) { |
|
| 1565 | + // boucle personnalisée ? |
|
| 1566 | + $table = strtoupper($boucle->type_requete); |
|
| 1567 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1568 | + if ( |
|
| 1569 | + // fonction de boucle avec serveur & table |
|
| 1570 | + (!$serveur or |
|
| 1571 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1572 | + and (!function_exists($f = $f . '_dist')) |
|
| 1573 | + ) |
|
| 1574 | + ) |
|
| 1575 | + // fonction de boucle avec table |
|
| 1576 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1577 | + and (!function_exists($f = $f . '_dist')) |
|
| 1578 | + ) { |
|
| 1579 | + // fonction de boucle standard |
|
| 1580 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1581 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1586 | + "static \$connect;\n\t" . |
|
| 1587 | + "\$command['connect'] = \$connect = " . |
|
| 1588 | + _q($boucle->sql_serveur) . |
|
| 1589 | + ';' . |
|
| 1590 | + $f($id, $boucles); |
|
| 1591 | + } else { |
|
| 1592 | + $req = ("\n\treturn '';"); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + $boucles[$id]->return = |
|
| 1596 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1597 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1598 | + $req . |
|
| 1599 | + "\n}\n"; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1603 | + // retourner False, sinon inserer leur decompilation |
|
| 1604 | + if (is_bool($corps)) { |
|
| 1605 | + return false; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1609 | 1609 | ' |
| 1610 | - // reporter de maniere securisee les doublons inclus |
|
| 1611 | - . ' |
|
| 1610 | + // reporter de maniere securisee les doublons inclus |
|
| 1611 | + . ' |
|
| 1612 | 1612 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1613 | 1613 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1614 | 1614 | |
| 1615 | 1615 | $connect = ' . |
| 1616 | - _q($connect) . '; |
|
| 1616 | + _q($connect) . '; |
|
| 1617 | 1617 | $page = ' . |
| 1618 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1619 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1620 | - // avant de referencer $Cache |
|
| 1621 | - $corps . '; |
|
| 1618 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1619 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1620 | + // avant de referencer $Cache |
|
| 1621 | + $corps . '; |
|
| 1622 | 1622 | |
| 1623 | 1623 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1624 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1624 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1625 | 1625 | }'; |
| 1626 | 1626 | |
| 1627 | - $secondes = spip_timer('calcul_skel'); |
|
| 1628 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1629 | - // $connect n'est pas sûr : on nettoie |
|
| 1630 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1627 | + $secondes = spip_timer('calcul_skel'); |
|
| 1628 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1629 | + // $connect n'est pas sûr : on nettoie |
|
| 1630 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1631 | 1631 | |
| 1632 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1633 | - $code = new Boucle(); |
|
| 1634 | - $code->descr = $descr; |
|
| 1635 | - $code->return = ' |
|
| 1632 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1633 | + $code = new Boucle(); |
|
| 1634 | + $code->descr = $descr; |
|
| 1635 | + $code->return = ' |
|
| 1636 | 1636 | // |
| 1637 | 1637 | // Fonction principale du squelette ' . |
| 1638 | - $sourcefile . |
|
| 1639 | - ($connect ? " pour $connect" : '') . |
|
| 1640 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1641 | - "\n//\n" . |
|
| 1642 | - $principal; |
|
| 1638 | + $sourcefile . |
|
| 1639 | + ($connect ? " pour $connect" : '') . |
|
| 1640 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1641 | + "\n//\n" . |
|
| 1642 | + $principal; |
|
| 1643 | 1643 | |
| 1644 | - $boucles[''] = $code; |
|
| 1644 | + $boucles[''] = $code; |
|
| 1645 | 1645 | |
| 1646 | - return $boucles; |
|
| 1646 | + return $boucles; |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | |
@@ -1660,18 +1660,18 @@ discard block |
||
| 1660 | 1660 | * |
| 1661 | 1661 | **/ |
| 1662 | 1662 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1663 | - if (class_exists($boucle->type_requete)) { |
|
| 1664 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1665 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1666 | - } else { |
|
| 1667 | - $x = $boucle->type_requete; |
|
| 1668 | - $boucle->type_requete = false; |
|
| 1669 | - $msg = [ |
|
| 1670 | - 'zbug_iterateur_inconnu', |
|
| 1671 | - ['iterateur' => $x] |
|
| 1672 | - ]; |
|
| 1673 | - erreur_squelette($msg, $boucle); |
|
| 1674 | - } |
|
| 1663 | + if (class_exists($boucle->type_requete)) { |
|
| 1664 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1665 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1666 | + } else { |
|
| 1667 | + $x = $boucle->type_requete; |
|
| 1668 | + $boucle->type_requete = false; |
|
| 1669 | + $msg = [ |
|
| 1670 | + 'zbug_iterateur_inconnu', |
|
| 1671 | + ['iterateur' => $x] |
|
| 1672 | + ]; |
|
| 1673 | + erreur_squelette($msg, $boucle); |
|
| 1674 | + } |
|
| 1675 | 1675 | } |
| 1676 | 1676 | |
| 1677 | 1677 | |
@@ -1689,22 +1689,22 @@ discard block |
||
| 1689 | 1689 | * |
| 1690 | 1690 | **/ |
| 1691 | 1691 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1692 | - include_spip('iterateur/data'); |
|
| 1693 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1694 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1695 | - $boucles[$id] = $g($boucle); |
|
| 1696 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1697 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1698 | - } else { |
|
| 1699 | - $x = $boucle->type_requete; |
|
| 1700 | - $boucle->type_requete = false; |
|
| 1701 | - $msg = [ |
|
| 1702 | - 'zbug_requeteur_inconnu', |
|
| 1703 | - [ |
|
| 1704 | - 'requeteur' => 'data', |
|
| 1705 | - 'type' => $x |
|
| 1706 | - ] |
|
| 1707 | - ]; |
|
| 1708 | - erreur_squelette($msg, $boucle); |
|
| 1709 | - } |
|
| 1692 | + include_spip('iterateur/data'); |
|
| 1693 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1694 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1695 | + $boucles[$id] = $g($boucle); |
|
| 1696 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1697 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1698 | + } else { |
|
| 1699 | + $x = $boucle->type_requete; |
|
| 1700 | + $boucle->type_requete = false; |
|
| 1701 | + $msg = [ |
|
| 1702 | + 'zbug_requeteur_inconnu', |
|
| 1703 | + [ |
|
| 1704 | + 'requeteur' => 'data', |
|
| 1705 | + 'type' => $x |
|
| 1706 | + ] |
|
| 1707 | + ]; |
|
| 1708 | + erreur_squelette($msg, $boucle); |
|
| 1709 | + } |
|
| 1710 | 1710 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 122 | 122 | if ($var !== 1) { |
| 123 | 123 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + . $val.($echap ? ") . '" : ' '); |
|
| 125 | 125 | } else { |
| 126 | 126 | $val = $echap ? "'.$val.'" : $val; |
| 127 | 127 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (!$lang) { |
| 143 | 143 | $lang = '$GLOBALS["spip_lang"]'; |
| 144 | 144 | } |
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : ' '); |
|
| 146 | 146 | |
| 147 | 147 | return $l; |
| 148 | 148 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 174 | + $code = '"'.str_replace('"', '\"', $fichier).'"'; |
|
| 175 | 175 | } else { |
| 176 | 176 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
| 177 | 177 | if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | return false; |
| 221 | 221 | } // j'aurais voulu toucher le fond ... |
| 222 | 222 | |
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 223 | + $contexte = 'array('.$_contexte.')'; |
|
| 224 | 224 | |
| 225 | 225 | if ($env) { |
| 226 | 226 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | $_options[] = $ajax; |
| 236 | 236 | } |
| 237 | 237 | $code = " ' . argumenter_squelette($code) . '"; |
| 238 | - $code = 'echo ' . sprintf( |
|
| 238 | + $code = 'echo '.sprintf( |
|
| 239 | 239 | CODE_RECUPERER_FOND, |
| 240 | 240 | $code, |
| 241 | 241 | $contexte, |
| 242 | 242 | implode(',', $_options), |
| 243 | 243 | "_request(\\'connect\\') ?? \\'\\'" |
| 244 | - ) . ';'; |
|
| 244 | + ).';'; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 247 | + return "\n'<'.'".'?php '.$code."\n?'."."'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $id = $id_table; |
| 325 | 325 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 326 | 326 | } |
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 327 | + $mstatut = $id.'.'.$statut; |
|
| 328 | 328 | |
| 329 | 329 | $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
| 330 | 330 | include_spip('public/quete'); |
@@ -332,11 +332,11 @@ discard block |
||
| 332 | 332 | isset($s['post_date']) and $s['post_date'] |
| 333 | 333 | and $GLOBALS['meta']['post_dates'] == 'non' |
| 334 | 334 | ) { |
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 335 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | 336 | array_unshift( |
| 337 | 337 | $boucle->where, |
| 338 | 338 | $echapper ? |
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 339 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 340 | 340 | : |
| 341 | 341 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 342 | 342 | ); |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | $boucle->where, |
| 346 | 346 | $echapper ? |
| 347 | 347 | "\nquete_condition_statut('$mstatut'," |
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 348 | + . _q($s['previsu']).',' |
|
| 349 | + . _q($s['publie']).',' |
|
| 350 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 351 | 351 | : |
| 352 | 352 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 353 | 353 | ); |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | if (_request('var_mode_affiche') != 'resultat') { |
| 382 | 382 | $trace = ''; |
| 383 | 383 | } else { |
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 385 | 385 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 386 | 386 | $trace = " |
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | - $_trace" . '[] = $t0; |
|
| 391 | + $_trace".'[] = $t0; |
|
| 392 | 392 | }'; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | return |
| 423 | 423 | // Numrows[$nom] peut ne pas être encore defini |
| 424 | 424 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 425 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.';' |
|
| 426 | 426 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 427 | 427 | . $trace |
| 428 | 428 | . "\n\treturn \$t0;"; |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 490 | 490 | // et puis faire un [] plutot qu'un "','." |
| 491 | 491 | if ($boucle->doublons) { |
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 492 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 493 | 493 | index_pile($id_boucle, $primary, $boucles) |
| 494 | 494 | . "; // doublons\n"; |
| 495 | 495 | } |
@@ -517,13 +517,13 @@ discard block |
||
| 517 | 517 | $corps .= |
| 518 | 518 | "\n\t\tlang_select_public(" |
| 519 | 519 | . index_pile($id_boucle, 'lang', $boucles) |
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 520 | + . ", '".$boucle->lang_select."'" |
|
| 521 | 521 | . (in_array($type_boucle, [ |
| 522 | 522 | 'articles', |
| 523 | 523 | 'rubriques', |
| 524 | 524 | 'hierarchie', |
| 525 | 525 | 'breves' |
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 526 | + ]) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | 527 | . ');'; |
| 528 | 528 | } else { |
| 529 | 529 | $init_lang = ''; |
@@ -545,20 +545,16 @@ discard block |
||
| 545 | 545 | |
| 546 | 546 | // gestion optimale des separateurs et des boucles constantes |
| 547 | 547 | if (count($boucle->separateur)) { |
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 548 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | $corps .= |
| 552 | 552 | ((!$boucle->separateur) ? |
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.';'))) : ("\n\t\t\$t1 ". |
|
| 557 | 554 | ((strpos($return, '$t1.') === 0) ? |
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 555 | + ('.='.substr($return, 4)) : ('= '.$return)). |
|
| 556 | + ";\n\t\t". |
|
| 557 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 562 | 558 | |
| 563 | 559 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 564 | 560 | // souhaite invalider ces elements |
@@ -640,7 +636,7 @@ discard block |
||
| 640 | 636 | $corps, |
| 641 | 637 | $fin_lang, |
| 642 | 638 | $trace, |
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 639 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 644 | 640 | ); |
| 645 | 641 | |
| 646 | 642 | # var_dump($a);exit; |
@@ -661,25 +657,24 @@ discard block |
||
| 661 | 657 | **/ |
| 662 | 658 | function calculer_requete_sql($boucle) { |
| 663 | 659 | $init = []; |
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 660 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 661 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 666 | 662 | # En absence de champ c'est un decompte : |
| 667 | 663 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 668 | 664 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 669 | 665 | $init[] = calculer_dec( |
| 670 | 666 | 'groupby', |
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 667 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').')' |
|
| 672 | 668 | ); |
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 669 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select).'")'); |
|
| 670 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).')'); |
|
| 675 | 671 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 676 | 672 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 677 | 673 | $init[] = calculer_dec( |
| 678 | 674 | 'limit', |
| 679 | 675 | ( |
| 680 | 676 | strpos($boucle->limit, 'intval') === false ? |
| 681 | - "'" . ($boucle->limit) . "'" : |
|
| 682 | - $boucle->limit |
|
| 677 | + "'".($boucle->limit)."'" : $boucle->limit |
|
| 683 | 678 | ) |
| 684 | 679 | ); |
| 685 | 680 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -688,17 +683,17 @@ discard block |
||
| 688 | 683 | // ou recalculée à chaque passage (vide) |
| 689 | 684 | foreach ($init as $i) { |
| 690 | 685 | if (reset($i)) { |
| 691 | - $s .= "\n\t\t" . end($i); |
|
| 686 | + $s .= "\n\t\t".end($i); |
|
| 692 | 687 | } # statique |
| 693 | 688 | else { |
| 694 | - $d .= "\n\t" . end($i); |
|
| 689 | + $d .= "\n\t".end($i); |
|
| 695 | 690 | } # dynamique |
| 696 | 691 | } |
| 697 | 692 | |
| 698 | 693 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 699 | 694 | . $boucle->in |
| 700 | 695 | . $boucle->hash |
| 701 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 696 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 702 | 697 | . $s |
| 703 | 698 | . "\n\t}" |
| 704 | 699 | . $d; |
@@ -781,7 +776,7 @@ discard block |
||
| 781 | 776 | * - index 1 : Code de l'affectation |
| 782 | 777 | **/ |
| 783 | 778 | function calculer_dec($nom, $val) { |
| 784 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 779 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 785 | 780 | // si une variable apparait dans le calcul de la clause |
| 786 | 781 | // il faut la re-evaluer a chaque passage |
| 787 | 782 | if ( |
@@ -798,7 +793,7 @@ discard block |
||
| 798 | 793 | $static = ''; |
| 799 | 794 | } |
| 800 | 795 | |
| 801 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 796 | + return [$static, '$command[\''.$nom.'\'] = '.$val.';']; |
|
| 802 | 797 | } |
| 803 | 798 | |
| 804 | 799 | /** |
@@ -823,17 +818,17 @@ discard block |
||
| 823 | 818 | } |
| 824 | 819 | $res = ''; |
| 825 | 820 | if ($a and $a[0] == "'?'") { |
| 826 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 827 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 828 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 821 | + return ('('.calculer_dump_array($a[1]). |
|
| 822 | + ' ? '.calculer_dump_array($a[2]). |
|
| 823 | + ' : '.calculer_dump_array($a[3]). |
|
| 829 | 824 | ')'); |
| 830 | 825 | } else { |
| 831 | 826 | foreach ($a as $k => $v) { |
| 832 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 833 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 827 | + $showk = (is_numeric($k) ? '' : sql_quote($k).' => '); |
|
| 828 | + $res .= ', '.$showk.calculer_dump_array($v); |
|
| 834 | 829 | } |
| 835 | 830 | |
| 836 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 831 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 837 | 832 | } |
| 838 | 833 | } |
| 839 | 834 | |
@@ -841,10 +836,10 @@ discard block |
||
| 841 | 836 | function calculer_dump_join($a) { |
| 842 | 837 | $res = ''; |
| 843 | 838 | foreach ($a as $k => $v) { |
| 844 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 839 | + $res .= ", '$k' => array(".implode(',', $v).')'; |
|
| 845 | 840 | } |
| 846 | 841 | |
| 847 | - return 'array(' . substr($res, 2) . ')'; |
|
| 842 | + return 'array('.substr($res, 2).')'; |
|
| 848 | 843 | } |
| 849 | 844 | |
| 850 | 845 | /** |
@@ -861,7 +856,7 @@ discard block |
||
| 861 | 856 | $res .= ",'$k' => '$v'"; |
| 862 | 857 | } |
| 863 | 858 | |
| 864 | - return 'array(' . substr($res, 1) . ')'; |
|
| 859 | + return 'array('.substr($res, 1).')'; |
|
| 865 | 860 | } |
| 866 | 861 | |
| 867 | 862 | /** |
@@ -879,7 +874,7 @@ discard block |
||
| 879 | 874 | $res .= ",'$k' => '$v'"; |
| 880 | 875 | } |
| 881 | 876 | |
| 882 | - return 'array(' . substr($res, 1) . ')'; |
|
| 877 | + return 'array('.substr($res, 1).')'; |
|
| 883 | 878 | } |
| 884 | 879 | |
| 885 | 880 | // https://code.spip.net/@calculer_order |
@@ -950,19 +945,19 @@ discard block |
||
| 950 | 945 | ) { |
| 951 | 946 | $res .= " .\n$tab$code"; |
| 952 | 947 | } else { |
| 953 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 948 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 954 | 949 | } |
| 955 | 950 | } |
| 956 | 951 | |
| 957 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 952 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 958 | 953 | } |
| 959 | 954 | } else { |
| 960 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 955 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 961 | 956 | |
| 962 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 957 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join( |
|
| 963 | 958 | " ,\n$tab", |
| 964 | 959 | $codes |
| 965 | - ) . ')))'; |
|
| 960 | + ).')))'; |
|
| 966 | 961 | } |
| 967 | 962 | } |
| 968 | 963 | |
@@ -990,7 +985,7 @@ discard block |
||
| 990 | 985 | // texte seul |
| 991 | 986 | case 'texte': |
| 992 | 987 | $code = sandbox_composer_texte($p->texte, $p); |
| 993 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 988 | + $commentaire = strlen($p->texte).' signes'; |
|
| 994 | 989 | $avant = ''; |
| 995 | 990 | $apres = ''; |
| 996 | 991 | $altern = "''"; |
@@ -999,14 +994,14 @@ discard block |
||
| 999 | 994 | case 'polyglotte': |
| 1000 | 995 | $code = ''; |
| 1001 | 996 | foreach ($p->traductions as $k => $v) { |
| 1002 | - $code .= ",'" . |
|
| 1003 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1004 | - "' => '" . |
|
| 1005 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 997 | + $code .= ",'". |
|
| 998 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k). |
|
| 999 | + "' => '". |
|
| 1000 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v). |
|
| 1006 | 1001 | "'"; |
| 1007 | 1002 | } |
| 1008 | - $code = 'choisir_traduction(array(' . |
|
| 1009 | - substr($code, 1) . |
|
| 1003 | + $code = 'choisir_traduction(array('. |
|
| 1004 | + substr($code, 1). |
|
| 1010 | 1005 | '))'; |
| 1011 | 1006 | $commentaire = '&'; |
| 1012 | 1007 | $avant = ''; |
@@ -1022,7 +1017,7 @@ discard block |
||
| 1022 | 1017 | $err_e_c = true; |
| 1023 | 1018 | $code = "''"; |
| 1024 | 1019 | } else { |
| 1025 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1020 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 1026 | 1021 | $avant = ''; |
| 1027 | 1022 | $apres = ''; |
| 1028 | 1023 | $altern = "''"; |
@@ -1051,8 +1046,8 @@ discard block |
||
| 1051 | 1046 | $err_e_c = true; |
| 1052 | 1047 | $code = "''"; |
| 1053 | 1048 | } else { |
| 1054 | - $code = 'BOUCLE' . |
|
| 1055 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1049 | + $code = 'BOUCLE'. |
|
| 1050 | + str_replace('-', '_', $nom).$descr['nom']. |
|
| 1056 | 1051 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1057 | 1052 | $commentaire = "?$nom"; |
| 1058 | 1053 | if ( |
@@ -1094,24 +1089,22 @@ discard block |
||
| 1094 | 1089 | foreach ($p->arg as $k => $v) { |
| 1095 | 1090 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1096 | 1091 | if ($k) { |
| 1097 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1092 | + $l[] = _q($k).' => '.$_v; |
|
| 1098 | 1093 | } else { |
| 1099 | 1094 | $code = $_v; |
| 1100 | 1095 | } |
| 1101 | 1096 | } |
| 1102 | 1097 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1103 | 1098 | if ($p->module) { |
| 1104 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1099 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1105 | 1100 | } elseif ($p->nom_champ) { |
| 1106 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1101 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1107 | 1102 | } else { |
| 1108 | 1103 | $m = ''; |
| 1109 | 1104 | } |
| 1110 | 1105 | |
| 1111 | - $code = (!$code ? "'$m'" : |
|
| 1112 | - ($m ? "'$m' . $code" : |
|
| 1113 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1114 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1106 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1107 | + . (!$l ? '' : (', array('.implode(",\n", $l).')')); |
|
| 1115 | 1108 | $code = "_T($code)"; |
| 1116 | 1109 | if ($p->param) { |
| 1117 | 1110 | $p->id_boucle = $id_boucle; |
@@ -1133,7 +1126,7 @@ discard block |
||
| 1133 | 1126 | $p->type_requete = $type; |
| 1134 | 1127 | |
| 1135 | 1128 | $code = calculer_champ($p); |
| 1136 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1129 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1137 | 1130 | $avant = calculer_liste( |
| 1138 | 1131 | $p->avant, |
| 1139 | 1132 | $descr, |
@@ -1173,10 +1166,9 @@ discard block |
||
| 1173 | 1166 | if ($code != "''") { |
| 1174 | 1167 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1175 | 1168 | $codes[] = (($mode == 'validation') ? |
| 1176 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1169 | + "array($code, '$commentaire', ".$p->ligne.')' |
|
| 1177 | 1170 | : (($mode == 'code') ? |
| 1178 | - "\n// $commentaire\n$code" : |
|
| 1179 | - $code)); |
|
| 1171 | + "\n// $commentaire\n$code" : $code)); |
|
| 1180 | 1172 | } |
| 1181 | 1173 | } // foreach |
| 1182 | 1174 | |
@@ -1233,19 +1225,19 @@ discard block |
||
| 1233 | 1225 | $cond = ''; |
| 1234 | 1226 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1235 | 1227 | $t = $r[2]; |
| 1236 | - $cond = '!' . $r[1]; |
|
| 1228 | + $cond = '!'.$r[1]; |
|
| 1237 | 1229 | } else { |
| 1238 | 1230 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1239 | 1231 | $t = $r[2]; |
| 1240 | 1232 | $cond = $r[1]; |
| 1241 | 1233 | } else { |
| 1242 | - $t = '$t' . $n; |
|
| 1234 | + $t = '$t'.$n; |
|
| 1243 | 1235 | $cond = "($t = $code)!==''"; |
| 1244 | 1236 | } |
| 1245 | 1237 | } |
| 1246 | 1238 | |
| 1247 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1248 | - $t . |
|
| 1239 | + $res = (!$avant ? '' : "$avant . "). |
|
| 1240 | + $t. |
|
| 1249 | 1241 | (!$apres ? '' : " . $apres"); |
| 1250 | 1242 | |
| 1251 | 1243 | if ($res !== $t) { |
@@ -1297,13 +1289,13 @@ discard block |
||
| 1297 | 1289 | |
| 1298 | 1290 | // rendre inertes les echappements de #[](){}<> |
| 1299 | 1291 | $i = 0; |
| 1300 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1292 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1301 | 1293 | $i++; |
| 1302 | 1294 | } |
| 1303 | 1295 | $squelette = preg_replace_callback( |
| 1304 | 1296 | ',\\\\([#[()\]{}<>]),', |
| 1305 | - function ($a) use ($inerte) { |
|
| 1306 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1297 | + function($a) use ($inerte) { |
|
| 1298 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1307 | 1299 | }, |
| 1308 | 1300 | $squelette, |
| 1309 | 1301 | -1, |
@@ -1320,7 +1312,7 @@ discard block |
||
| 1320 | 1312 | // Phraser le squelette, selon sa grammaire |
| 1321 | 1313 | |
| 1322 | 1314 | $boucles = []; |
| 1323 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1315 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1324 | 1316 | |
| 1325 | 1317 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1326 | 1318 | |
@@ -1331,15 +1323,15 @@ discard block |
||
| 1331 | 1323 | foreach ($boucles as $i => $boucle) { |
| 1332 | 1324 | $boucles[$i]->return = preg_replace_callback( |
| 1333 | 1325 | ",$inerte-(\d+)-,", |
| 1334 | - function ($a) { |
|
| 1326 | + function($a) { |
|
| 1335 | 1327 | return chr($a[1]); |
| 1336 | 1328 | }, |
| 1337 | 1329 | $boucle->return |
| 1338 | 1330 | ); |
| 1339 | 1331 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1340 | 1332 | ",$inerte-(\d+)-,", |
| 1341 | - function ($a) { |
|
| 1342 | - return '\\\\' . chr($a[1]); |
|
| 1333 | + function($a) { |
|
| 1334 | + return '\\\\'.chr($a[1]); |
|
| 1343 | 1335 | }, |
| 1344 | 1336 | $boucle->descr['squelette'] |
| 1345 | 1337 | ); |
@@ -1351,19 +1343,19 @@ discard block |
||
| 1351 | 1343 | include_spip('public/decompiler'); |
| 1352 | 1344 | foreach ($boucles as $id => $boucle) { |
| 1353 | 1345 | if ($id) { |
| 1354 | - $decomp = "\n/* BOUCLE " . |
|
| 1355 | - $boucle->type_requete . |
|
| 1356 | - ' ' . |
|
| 1357 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1358 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1346 | + $decomp = "\n/* BOUCLE ". |
|
| 1347 | + $boucle->type_requete. |
|
| 1348 | + ' '. |
|
| 1349 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1350 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1359 | 1351 | " */\n"; |
| 1360 | 1352 | } else { |
| 1361 | - $decomp = ("\n/*\n" . |
|
| 1353 | + $decomp = ("\n/*\n". |
|
| 1362 | 1354 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1363 | 1355 | . "\n*/"); |
| 1364 | 1356 | } |
| 1365 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1366 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1358 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1367 | 1359 | } |
| 1368 | 1360 | } |
| 1369 | 1361 | |
@@ -1386,7 +1378,7 @@ discard block |
||
| 1386 | 1378 | } |
| 1387 | 1379 | } |
| 1388 | 1380 | foreach ($boucles as $id => $boucle) { |
| 1389 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1381 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1390 | 1382 | } |
| 1391 | 1383 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1392 | 1384 | |
@@ -1477,8 +1469,7 @@ discard block |
||
| 1477 | 1469 | } else { |
| 1478 | 1470 | $boucles[$id]->type_requete = false; |
| 1479 | 1471 | $boucle = $boucles[$id]; |
| 1480 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1481 | - ($boucle->sql_serveur . ':')) . |
|
| 1472 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.':')). |
|
| 1482 | 1473 | $type; |
| 1483 | 1474 | $msg = [ |
| 1484 | 1475 | 'zbug_table_inconnue', |
@@ -1568,13 +1559,13 @@ discard block |
||
| 1568 | 1559 | if ( |
| 1569 | 1560 | // fonction de boucle avec serveur & table |
| 1570 | 1561 | (!$serveur or |
| 1571 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1572 | - and (!function_exists($f = $f . '_dist')) |
|
| 1562 | + ((!function_exists($f = 'boucle_'.$serveur.'_'.$table)) |
|
| 1563 | + and (!function_exists($f = $f.'_dist')) |
|
| 1573 | 1564 | ) |
| 1574 | 1565 | ) |
| 1575 | 1566 | // fonction de boucle avec table |
| 1576 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1577 | - and (!function_exists($f = $f . '_dist')) |
|
| 1567 | + and (!function_exists($f = 'boucle_'.$table)) |
|
| 1568 | + and (!function_exists($f = $f.'_dist')) |
|
| 1578 | 1569 | ) { |
| 1579 | 1570 | // fonction de boucle standard |
| 1580 | 1571 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1582,20 +1573,20 @@ discard block |
||
| 1582 | 1573 | } |
| 1583 | 1574 | } |
| 1584 | 1575 | |
| 1585 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1586 | - "static \$connect;\n\t" . |
|
| 1587 | - "\$command['connect'] = \$connect = " . |
|
| 1588 | - _q($boucle->sql_serveur) . |
|
| 1589 | - ';' . |
|
| 1576 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1577 | + "static \$connect;\n\t". |
|
| 1578 | + "\$command['connect'] = \$connect = ". |
|
| 1579 | + _q($boucle->sql_serveur). |
|
| 1580 | + ';'. |
|
| 1590 | 1581 | $f($id, $boucles); |
| 1591 | 1582 | } else { |
| 1592 | 1583 | $req = ("\n\treturn '';"); |
| 1593 | 1584 | } |
| 1594 | 1585 | |
| 1595 | 1586 | $boucles[$id]->return = |
| 1596 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1597 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1598 | - $req . |
|
| 1587 | + "\n\nfunction BOUCLE".strtr($id, '-', '_').$nom. |
|
| 1588 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1589 | + $req. |
|
| 1599 | 1590 | "\n}\n"; |
| 1600 | 1591 | } |
| 1601 | 1592 | |
@@ -1605,7 +1596,7 @@ discard block |
||
| 1605 | 1596 | return false; |
| 1606 | 1597 | } |
| 1607 | 1598 | |
| 1608 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1609 | 1600 | ' |
| 1610 | 1601 | // reporter de maniere securisee les doublons inclus |
| 1611 | 1602 | . ' |
@@ -1613,15 +1604,15 @@ discard block |
||
| 1613 | 1604 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1614 | 1605 | |
| 1615 | 1606 | $connect = ' . |
| 1616 | - _q($connect) . '; |
|
| 1607 | + _q($connect).'; |
|
| 1617 | 1608 | $page = ' . |
| 1618 | 1609 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1619 | 1610 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1620 | 1611 | // avant de referencer $Cache |
| 1621 | - $corps . '; |
|
| 1612 | + $corps.'; |
|
| 1622 | 1613 | |
| 1623 | 1614 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1624 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1615 | + . ', $Cache, $page, '.var_export($sourcefile, true).'); |
|
| 1625 | 1616 | }'; |
| 1626 | 1617 | |
| 1627 | 1618 | $secondes = spip_timer('calcul_skel'); |
@@ -1635,10 +1626,10 @@ discard block |
||
| 1635 | 1626 | $code->return = ' |
| 1636 | 1627 | // |
| 1637 | 1628 | // Fonction principale du squelette ' . |
| 1638 | - $sourcefile . |
|
| 1639 | - ($connect ? " pour $connect" : '') . |
|
| 1640 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1641 | - "\n//\n" . |
|
| 1629 | + $sourcefile. |
|
| 1630 | + ($connect ? " pour $connect" : ''). |
|
| 1631 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1632 | + "\n//\n". |
|
| 1642 | 1633 | $principal; |
| 1643 | 1634 | |
| 1644 | 1635 | $boucles[''] = $code; |
@@ -1690,7 +1681,7 @@ discard block |
||
| 1690 | 1681 | **/ |
| 1691 | 1682 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1692 | 1683 | include_spip('iterateur/data'); |
| 1693 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1694 | 1685 | $g = charger_fonction('data', 'iterateur'); |
| 1695 | 1686 | $boucles[$id] = $g($boucle); |
| 1696 | 1687 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if ( |
|
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 88 | - and strlen($texte) > 2.5 * $longueur |
|
| 89 | - ) { |
|
| 90 | - if (strpos($texte, '<multi') !== false) { |
|
| 91 | - $texte = extraire_multi($texte); |
|
| 92 | - } |
|
| 93 | - $texte = couper($texte, 2 * $longueur); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // ne pas tenir compte des notes |
|
| 98 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | - $notes('', 'empiler'); |
|
| 100 | - } |
|
| 101 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | - // dans l'introduction. |
|
| 103 | - $texte = supprime_img($texte, ''); |
|
| 104 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | - |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'depiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | - $suite = _INTRODUCTION_SUITE; |
|
| 112 | - } |
|
| 113 | - $texte = couper($texte, $longueur, $suite); |
|
| 114 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | - $texte = typo($texte, true, $connect, []); |
|
| 116 | - |
|
| 117 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | - // une introduction a tojours un <p> |
|
| 119 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if ( |
|
| 87 | + strpos("\n" . $texte, "\n|") === false |
|
| 88 | + and strlen($texte) > 2.5 * $longueur |
|
| 89 | + ) { |
|
| 90 | + if (strpos($texte, '<multi') !== false) { |
|
| 91 | + $texte = extraire_multi($texte); |
|
| 92 | + } |
|
| 93 | + $texte = couper($texte, 2 * $longueur); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // ne pas tenir compte des notes |
|
| 98 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | + $notes('', 'empiler'); |
|
| 100 | + } |
|
| 101 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | + // dans l'introduction. |
|
| 103 | + $texte = supprime_img($texte, ''); |
|
| 104 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | + |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'depiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | + $suite = _INTRODUCTION_SUITE; |
|
| 112 | + } |
|
| 113 | + $texte = couper($texte, $longueur, $suite); |
|
| 114 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | + $texte = typo($texte, true, $connect, []); |
|
| 116 | + |
|
| 117 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | + // une introduction a tojours un <p> |
|
| 119 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -155,73 +155,73 @@ discard block |
||
| 155 | 155 | * Code HTML de la pagination |
| 156 | 156 | **/ |
| 157 | 157 | function filtre_pagination_dist( |
| 158 | - $total, |
|
| 159 | - $nom, |
|
| 160 | - $position, |
|
| 161 | - $pas, |
|
| 162 | - $liste = true, |
|
| 163 | - $modele = '', |
|
| 164 | - string $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + string $connect = '', |
|
| 165 | + $env = [] |
|
| 166 | 166 | ) { |
| 167 | - static $ancres = []; |
|
| 168 | - if ($pas < 1) { |
|
| 169 | - return ''; |
|
| 170 | - } |
|
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | - |
|
| 174 | - // n'afficher l'ancre qu'une fois |
|
| 175 | - if (!isset($ancres[$ancre])) { |
|
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | - } else { |
|
| 178 | - $bloc_ancre = ''; |
|
| 179 | - } |
|
| 180 | - // liste = false : on ne veut que l'ancre |
|
| 181 | - if (!$liste) { |
|
| 182 | - return $ancres[$ancre]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | - $pagination = [ |
|
| 187 | - 'debut' => $debut, |
|
| 188 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | - 'total' => $total, |
|
| 190 | - 'position' => intval($position), |
|
| 191 | - 'pas' => $pas, |
|
| 192 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | - 'ancre' => $ancre, |
|
| 195 | - 'bloc_ancre' => $bloc_ancre |
|
| 196 | - ]; |
|
| 197 | - if (is_array($env)) { |
|
| 198 | - $pagination = array_merge($env, $pagination); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Pas de pagination |
|
| 202 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($modele) { |
|
| 207 | - $pagination['type_pagination'] = $modele; |
|
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - $modele = ''; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | - } |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 167 | + static $ancres = []; |
|
| 168 | + if ($pas < 1) { |
|
| 169 | + return ''; |
|
| 170 | + } |
|
| 171 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + |
|
| 174 | + // n'afficher l'ancre qu'une fois |
|
| 175 | + if (!isset($ancres[$ancre])) { |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | + } else { |
|
| 178 | + $bloc_ancre = ''; |
|
| 179 | + } |
|
| 180 | + // liste = false : on ne veut que l'ancre |
|
| 181 | + if (!$liste) { |
|
| 182 | + return $ancres[$ancre]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | + $pagination = [ |
|
| 187 | + 'debut' => $debut, |
|
| 188 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | + 'total' => $total, |
|
| 190 | + 'position' => intval($position), |
|
| 191 | + 'pas' => $pas, |
|
| 192 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | + 'ancre' => $ancre, |
|
| 195 | + 'bloc_ancre' => $bloc_ancre |
|
| 196 | + ]; |
|
| 197 | + if (is_array($env)) { |
|
| 198 | + $pagination = array_merge($env, $pagination); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Pas de pagination |
|
| 202 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($modele) { |
|
| 207 | + $pagination['type_pagination'] = $modele; |
|
| 208 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | + $modele = '_' . $modele; |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + $modele = ''; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | + } |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -240,44 +240,44 @@ discard block |
||
| 240 | 240 | * Liste (première page, dernière page). |
| 241 | 241 | **/ |
| 242 | 242 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 243 | - if ($max <= 0 or $max >= $nombre) { |
|
| 244 | - return [1, $nombre]; |
|
| 245 | - } |
|
| 246 | - if ($max <= 1) { |
|
| 247 | - return [$courante, $courante]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | - |
|
| 254 | - return [$premiere, $derniere]; |
|
| 243 | + if ($max <= 0 or $max >= $nombre) { |
|
| 244 | + return [1, $nombre]; |
|
| 245 | + } |
|
| 246 | + if ($max <= 1) { |
|
| 247 | + return [$courante, $courante]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | + |
|
| 254 | + return [$premiere, $derniere]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 258 | - if ($numero_page === 'tous') { |
|
| 259 | - return '∞'; |
|
| 260 | - } |
|
| 261 | - if ($numero_page === 'prev') { |
|
| 262 | - return '<'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'next') { |
|
| 265 | - return '>'; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - switch ($type_pagination) { |
|
| 269 | - case 'resultats': |
|
| 270 | - return $rang_item + 1; // 1 11 21 31... |
|
| 271 | - case 'naturel': |
|
| 272 | - return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | - case 'rang': |
|
| 274 | - return $rang_item; // 0 10 20 30... |
|
| 275 | - |
|
| 276 | - case 'page': |
|
| 277 | - case 'prive': |
|
| 278 | - default: |
|
| 279 | - return $numero_page; // 1 2 3 4 5... |
|
| 280 | - } |
|
| 258 | + if ($numero_page === 'tous') { |
|
| 259 | + return '∞'; |
|
| 260 | + } |
|
| 261 | + if ($numero_page === 'prev') { |
|
| 262 | + return '<'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'next') { |
|
| 265 | + return '>'; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + switch ($type_pagination) { |
|
| 269 | + case 'resultats': |
|
| 270 | + return $rang_item + 1; // 1 11 21 31... |
|
| 271 | + case 'naturel': |
|
| 272 | + return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | + case 'rang': |
|
| 274 | + return $rang_item; // 0 10 20 30... |
|
| 275 | + |
|
| 276 | + case 'page': |
|
| 277 | + case 'prive': |
|
| 278 | + default: |
|
| 279 | + return $numero_page; // 1 2 3 4 5... |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | - $objet = objet_type($type); |
|
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | - if ($ids) { |
|
| 296 | - $ids = array_column($ids, 'id_objet'); |
|
| 297 | - return implode(',', $ids); |
|
| 298 | - } |
|
| 299 | - else { |
|
| 300 | - return '0'; |
|
| 301 | - } |
|
| 293 | + $objet = objet_type($type); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | + if ($ids) { |
|
| 296 | + $ids = array_column($ids, 'id_objet'); |
|
| 297 | + return implode(',', $ids); |
|
| 298 | + } |
|
| 299 | + else { |
|
| 300 | + return '0'; |
|
| 301 | + } |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | * Code HTML des notes |
| 315 | 315 | **/ |
| 316 | 316 | function calculer_notes() { |
| 317 | - $r = ''; |
|
| 318 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | - $r = $notes([]); |
|
| 320 | - $notes('', 'depiler'); |
|
| 321 | - $notes('', 'empiler'); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $r; |
|
| 317 | + $r = ''; |
|
| 318 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | + $r = $notes([]); |
|
| 320 | + $notes('', 'depiler'); |
|
| 321 | + $notes('', 'empiler'); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $r; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | 340 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 341 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 341 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 343 | 343 | |
| 344 | - return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 344 | + return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @private |
| 359 | 359 | */ |
| 360 | 360 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 361 | - static $liens = []; |
|
| 362 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | - include_spip('action/editer_liens'); |
|
| 364 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | - } else { |
|
| 368 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | - } |
|
| 373 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | + static $liens = []; |
|
| 362 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | + include_spip('action/editer_liens'); |
|
| 364 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | + } else { |
|
| 368 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | + } |
|
| 373 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | * @return int|string |
| 385 | 385 | */ |
| 386 | 386 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 387 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | - if ( |
|
| 390 | - isset($env['form']) and $env['form'] |
|
| 391 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | - and $r = objet_associable($env['_objet_lien']) |
|
| 394 | - and list($p, $table_lien) = $r |
|
| 395 | - and lien_triables($table_lien) |
|
| 396 | - and isset($env['objet']) and $env['objet'] |
|
| 397 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | - and $objet_source |
|
| 399 | - and $id = intval($id) |
|
| 400 | - ) { |
|
| 401 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | - return ($rang ? $rang : ''); |
|
| 403 | - } |
|
| 404 | - return recuperer_numero($titre); |
|
| 387 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | + if ( |
|
| 390 | + isset($env['form']) and $env['form'] |
|
| 391 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | + and $r = objet_associable($env['_objet_lien']) |
|
| 394 | + and list($p, $table_lien) = $r |
|
| 395 | + and lien_triables($table_lien) |
|
| 396 | + and isset($env['objet']) and $env['objet'] |
|
| 397 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | + and $objet_source |
|
| 399 | + and $id = intval($id) |
|
| 400 | + ) { |
|
| 401 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | + return ($rang ? $rang : ''); |
|
| 403 | + } |
|
| 404 | + return recuperer_numero($titre); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function tri_protege_champ($t) { |
| 420 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 420 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -430,43 +430,43 @@ discard block |
||
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | 432 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 433 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | - return 'multi'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $champ = $t; |
|
| 438 | - |
|
| 439 | - $prefixe = ''; |
|
| 440 | - foreach (['num ', 'sinum '] as $p) { |
|
| 441 | - if (strpos($t, $p) === 0) { |
|
| 442 | - $champ = substr($t, strlen($p)); |
|
| 443 | - $prefixe = $p; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | - |
|
| 450 | - if (is_array($from)) { |
|
| 451 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | - foreach ($from as $idt => $table_sql) { |
|
| 453 | - if ( |
|
| 454 | - $desc = $trouver_table($table_sql) |
|
| 455 | - and isset($desc['field'][$champ]) |
|
| 456 | - ) { |
|
| 457 | - $champ = "$idt.$champ"; |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - switch ($prefixe) { |
|
| 463 | - case 'num ': |
|
| 464 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | - case 'sinum ': |
|
| 466 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | - default: |
|
| 468 | - return $champ . $senstri; |
|
| 469 | - } |
|
| 433 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | + return 'multi'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $champ = $t; |
|
| 438 | + |
|
| 439 | + $prefixe = ''; |
|
| 440 | + foreach (['num ', 'sinum '] as $p) { |
|
| 441 | + if (strpos($t, $p) === 0) { |
|
| 442 | + $champ = substr($t, strlen($p)); |
|
| 443 | + $prefixe = $p; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | + |
|
| 450 | + if (is_array($from)) { |
|
| 451 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | + foreach ($from as $idt => $table_sql) { |
|
| 453 | + if ( |
|
| 454 | + $desc = $trouver_table($table_sql) |
|
| 455 | + and isset($desc['field'][$champ]) |
|
| 456 | + ) { |
|
| 457 | + $champ = "$idt.$champ"; |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + switch ($prefixe) { |
|
| 463 | + case 'num ': |
|
| 464 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | + case 'sinum ': |
|
| 466 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | + default: |
|
| 468 | + return $champ . $senstri; |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,18 +480,18 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function tri_champ_select($t) { |
| 483 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | - $t = substr($t, 6); |
|
| 485 | - $t = preg_replace(',\s,', '', $t); |
|
| 486 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | - |
|
| 488 | - return $t; |
|
| 489 | - } |
|
| 490 | - if (trim($t) == 'hasard') { |
|
| 491 | - return 'rand() AS hasard'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return "''"; |
|
| 483 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | + $t = substr($t, 6); |
|
| 485 | + $t = preg_replace(',\s,', '', $t); |
|
| 486 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | + |
|
| 488 | + return $t; |
|
| 489 | + } |
|
| 490 | + if (trim($t) == 'hasard') { |
|
| 491 | + return 'rand() AS hasard'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return "''"; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 506 | - if (!is_array($valeurs)) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $f = sql_serveur('quote', $serveur, true); |
|
| 510 | - if (!is_string($f) or !$f) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | - |
|
| 515 | - return $valeurs; |
|
| 506 | + if (!is_array($valeurs)) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $f = sql_serveur('quote', $serveur, true); |
|
| 510 | + if (!is_string($f) or !$f) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | + |
|
| 515 | + return $valeurs; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * Valeur $defaut sinon. |
| 536 | 536 | **/ |
| 537 | 537 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 538 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | - $args[1] = $args[0]; |
|
| 543 | - $args[0] = $filtre; |
|
| 544 | - return image_graver(image_filtrer($args)); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $f = chercher_filtre($filtre); |
|
| 548 | - if (!$f) { |
|
| 549 | - return $defaut; |
|
| 550 | - } |
|
| 551 | - array_shift($args); // enlever $arg |
|
| 552 | - array_shift($args); // enlever $filtre |
|
| 553 | - array_unshift($args, $arg); // remettre $arg |
|
| 554 | - return call_user_func_array($f, $args); |
|
| 538 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | + $args[1] = $args[0]; |
|
| 543 | + $args[0] = $filtre; |
|
| 544 | + return image_graver(image_filtrer($args)); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $f = chercher_filtre($filtre); |
|
| 548 | + if (!$f) { |
|
| 549 | + return $defaut; |
|
| 550 | + } |
|
| 551 | + array_shift($args); // enlever $arg |
|
| 552 | + array_shift($args); // enlever $filtre |
|
| 553 | + array_unshift($args, $arg); // remettre $arg |
|
| 554 | + return call_user_func_array($f, $args); |
|
| 555 | 555 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -43,233 +43,233 @@ discard block |
||
| 43 | 43 | // https://code.spip.net/@public_composer_dist |
| 44 | 44 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 45 | 45 | |
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - eval("return true; $f ;"); |
|
| 96 | - } catch (\ParseError $e) { |
|
| 97 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | - erreur_squelette($msg, $boucle); |
|
| 100 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | - // mais prevenir que c'est mort |
|
| 102 | - $nom = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Contexte de compil inutile a present |
|
| 106 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | - $skel_code[$id] = $f; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $code = ''; |
|
| 111 | - if ($nom) { |
|
| 112 | - // Si le code est bon, concatener et mettre en cache |
|
| 113 | - if (function_exists($nom)) { |
|
| 114 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | - } else { |
|
| 116 | - // code semantiquement faux: bug du compilateur |
|
| 117 | - // $boucle est en fait ici la fct principale du squelette |
|
| 118 | - $msg = _T('zbug_erreur_compilation'); |
|
| 119 | - erreur_squelette($msg, $boucle); |
|
| 120 | - $nom = ''; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | - // Tracer ce qui vient d'etre compile |
|
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | - |
|
| 128 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | - if ( |
|
| 130 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | - and (_request('var_mode_objet') == $nom) |
|
| 132 | - and (_request('var_mode_affiche') == 'code') |
|
| 133 | - ) { |
|
| 134 | - erreur_squelette(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $nom ? $nom : false; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + eval("return true; $f ;"); |
|
| 96 | + } catch (\ParseError $e) { |
|
| 97 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + erreur_squelette($msg, $boucle); |
|
| 100 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | + // mais prevenir que c'est mort |
|
| 102 | + $nom = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Contexte de compil inutile a present |
|
| 106 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | + $skel_code[$id] = $f; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $code = ''; |
|
| 111 | + if ($nom) { |
|
| 112 | + // Si le code est bon, concatener et mettre en cache |
|
| 113 | + if (function_exists($nom)) { |
|
| 114 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | + } else { |
|
| 116 | + // code semantiquement faux: bug du compilateur |
|
| 117 | + // $boucle est en fait ici la fct principale du squelette |
|
| 118 | + $msg = _T('zbug_erreur_compilation'); |
|
| 119 | + erreur_squelette($msg, $boucle); |
|
| 120 | + $nom = ''; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | + // Tracer ce qui vient d'etre compile |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + |
|
| 128 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | + if ( |
|
| 130 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | + and (_request('var_mode_objet') == $nom) |
|
| 132 | + and (_request('var_mode_affiche') == 'code') |
|
| 133 | + ) { |
|
| 134 | + erreur_squelette(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $nom ? $nom : false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - // Le dernier index est '' (fonction principale) |
|
| 144 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | - if (CODE_COMMENTE) { |
|
| 146 | - $code = " |
|
| 143 | + // Le dernier index est '' (fonction principale) |
|
| 144 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | + if (CODE_COMMENTE) { |
|
| 146 | + $code = " |
|
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | 149 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 150 | 150 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 151 | 151 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 152 | 152 | */ '; |
| 153 | - } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | - ecrire_fichier($phpfile, $code); |
|
| 158 | - } |
|
| 155 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | + ecrire_fichier($phpfile, $code); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - return $code; |
|
| 160 | + return $code; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Le squelette compile est-il trop vieux ? |
| 164 | 164 | // https://code.spip.net/@squelette_obsolete |
| 165 | 165 | function squelette_obsolete($skel, $squelette) { |
| 166 | - static $date_change = null; |
|
| 167 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | - // par hit |
|
| 169 | - if (is_null($date_change)) { |
|
| 170 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | - $date_change = @filemtime($fonc); |
|
| 172 | - } # compatibilite |
|
| 173 | - if (defined('_FILE_OPTIONS')) { |
|
| 174 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return ( |
|
| 179 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | - or !@file_exists($skel) |
|
| 181 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | - > ($date = @filemtime($skel))) |
|
| 183 | - or ($date_change > $date) |
|
| 184 | - ); |
|
| 166 | + static $date_change = null; |
|
| 167 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | + // par hit |
|
| 169 | + if (is_null($date_change)) { |
|
| 170 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | + $date_change = @filemtime($fonc); |
|
| 172 | + } # compatibilite |
|
| 173 | + if (defined('_FILE_OPTIONS')) { |
|
| 174 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return ( |
|
| 179 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | + or !@file_exists($skel) |
|
| 181 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | + > ($date = @filemtime($skel))) |
|
| 183 | + or ($date_change > $date) |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | // https://code.spip.net/@invalideur_session |
| 189 | 189 | function invalideur_session(&$Cache, $code = null) { |
| 190 | - $Cache['session'] = spip_session(); |
|
| 190 | + $Cache['session'] = spip_session(); |
|
| 191 | 191 | |
| 192 | - return $code; |
|
| 192 | + return $code; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | // https://code.spip.net/@analyse_resultat_skel |
| 197 | 197 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 198 | - static $filtres = []; |
|
| 199 | - $headers = []; |
|
| 200 | - |
|
| 201 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | - if ( |
|
| 205 | - stripos($corps, 'header') !== false |
|
| 206 | - and preg_match_all( |
|
| 207 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | - $corps, |
|
| 209 | - $regs, |
|
| 210 | - PREG_SET_ORDER |
|
| 211 | - ) |
|
| 212 | - ) { |
|
| 213 | - foreach ($regs as $r) { |
|
| 214 | - $corps = str_replace($r[0], '', $corps); |
|
| 215 | - # $j = Content-Type, et pas content-TYPE. |
|
| 216 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | - |
|
| 218 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 220 | - } else { |
|
| 221 | - $headers[$j] = $r[3]; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | - $process_ins = ( |
|
| 227 | - strpos($corps, '<' . '?') === false |
|
| 228 | - or |
|
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | - ) |
|
| 232 | - ? 'html' |
|
| 233 | - : 'php'; |
|
| 234 | - |
|
| 235 | - $skel = [ |
|
| 236 | - 'squelette' => $nom, |
|
| 237 | - 'source' => $source, |
|
| 238 | - 'process_ins' => $process_ins, |
|
| 239 | - 'invalideurs' => $cache, |
|
| 240 | - 'entetes' => $headers, |
|
| 241 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | - ]; |
|
| 243 | - |
|
| 244 | - // traiter #FILTRE{} et filtres |
|
| 245 | - if (!isset($filtres[$nom])) { |
|
| 246 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | - } |
|
| 248 | - $filtres_headers = []; |
|
| 249 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | - unset($headers['X-Spip-Filtre']); |
|
| 252 | - } |
|
| 253 | - if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | - include_spip('public/sandbox'); |
|
| 255 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | - |
|
| 257 | - if ($process_ins == 'html') { |
|
| 258 | - $skel['process_ins'] = ( |
|
| 259 | - strpos($corps, '<' . '?') === false |
|
| 260 | - or |
|
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | - ) |
|
| 264 | - ? 'html' |
|
| 265 | - : 'php'; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $skel['entetes'] = $headers; |
|
| 270 | - $skel['texte'] = $corps; |
|
| 271 | - |
|
| 272 | - return $skel; |
|
| 198 | + static $filtres = []; |
|
| 199 | + $headers = []; |
|
| 200 | + |
|
| 201 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | + if ( |
|
| 205 | + stripos($corps, 'header') !== false |
|
| 206 | + and preg_match_all( |
|
| 207 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | + $corps, |
|
| 209 | + $regs, |
|
| 210 | + PREG_SET_ORDER |
|
| 211 | + ) |
|
| 212 | + ) { |
|
| 213 | + foreach ($regs as $r) { |
|
| 214 | + $corps = str_replace($r[0], '', $corps); |
|
| 215 | + # $j = Content-Type, et pas content-TYPE. |
|
| 216 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | + |
|
| 218 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | + $headers[$j] .= '|' . $r[3]; |
|
| 220 | + } else { |
|
| 221 | + $headers[$j] = $r[3]; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | + $process_ins = ( |
|
| 227 | + strpos($corps, '<' . '?') === false |
|
| 228 | + or |
|
| 229 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | + ) |
|
| 232 | + ? 'html' |
|
| 233 | + : 'php'; |
|
| 234 | + |
|
| 235 | + $skel = [ |
|
| 236 | + 'squelette' => $nom, |
|
| 237 | + 'source' => $source, |
|
| 238 | + 'process_ins' => $process_ins, |
|
| 239 | + 'invalideurs' => $cache, |
|
| 240 | + 'entetes' => $headers, |
|
| 241 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | + ]; |
|
| 243 | + |
|
| 244 | + // traiter #FILTRE{} et filtres |
|
| 245 | + if (!isset($filtres[$nom])) { |
|
| 246 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | + } |
|
| 248 | + $filtres_headers = []; |
|
| 249 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | + unset($headers['X-Spip-Filtre']); |
|
| 252 | + } |
|
| 253 | + if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | + include_spip('public/sandbox'); |
|
| 255 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | + |
|
| 257 | + if ($process_ins == 'html') { |
|
| 258 | + $skel['process_ins'] = ( |
|
| 259 | + strpos($corps, '<' . '?') === false |
|
| 260 | + or |
|
| 261 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | + ) |
|
| 264 | + ? 'html' |
|
| 265 | + : 'php'; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $skel['entetes'] = $headers; |
|
| 270 | + $skel['texte'] = $corps; |
|
| 271 | + |
|
| 272 | + return $skel; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 284 | 284 | if ($lang_select) lang_select(); |
| 285 | 285 | ?' |
| 286 | - . '>'); |
|
| 286 | + . '>'); |
|
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -303,35 +303,35 @@ discard block |
||
| 303 | 303 | * Code PHP pour inclure le squelette de la balise dynamique |
| 304 | 304 | **/ |
| 305 | 305 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 306 | - if ( |
|
| 307 | - strncmp($file, '/', 1) !== 0 |
|
| 308 | - // pas de lien symbolique sous Windows |
|
| 309 | - and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | - ) { |
|
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $lang = $context_compil[4]; |
|
| 315 | - if (preg_match(',\W,', $lang)) { |
|
| 316 | - $lang = ''; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $args = array_map('argumenter_squelette', $args); |
|
| 320 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | - } |
|
| 323 | - $args = join(', ', $args); |
|
| 324 | - |
|
| 325 | - $r = sprintf( |
|
| 326 | - CODE_INCLURE_BALISE, |
|
| 327 | - $file, |
|
| 328 | - $lang, |
|
| 329 | - $nom, |
|
| 330 | - $args, |
|
| 331 | - join(', ', array_map('_q', $context_compil)) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - return $r; |
|
| 306 | + if ( |
|
| 307 | + strncmp($file, '/', 1) !== 0 |
|
| 308 | + // pas de lien symbolique sous Windows |
|
| 309 | + and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | + ) { |
|
| 311 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $lang = $context_compil[4]; |
|
| 315 | + if (preg_match(',\W,', $lang)) { |
|
| 316 | + $lang = ''; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $args = array_map('argumenter_squelette', $args); |
|
| 320 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | + } |
|
| 323 | + $args = join(', ', $args); |
|
| 324 | + |
|
| 325 | + $r = sprintf( |
|
| 326 | + CODE_INCLURE_BALISE, |
|
| 327 | + $file, |
|
| 328 | + $lang, |
|
| 329 | + $nom, |
|
| 330 | + $args, |
|
| 331 | + join(', ', array_map('_q', $context_compil)) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + return $r; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | **/ |
| 350 | 350 | function argumenter_squelette($v) { |
| 351 | 351 | |
| 352 | - if (is_object($v)) { |
|
| 353 | - return var_export($v, true); |
|
| 354 | - } elseif (!is_array($v)) { |
|
| 355 | - return "'" . texte_script((string) $v) . "'"; |
|
| 356 | - } else { |
|
| 357 | - $out = []; |
|
| 358 | - foreach ($v as $k => $val) { |
|
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 363 | - } |
|
| 352 | + if (is_object($v)) { |
|
| 353 | + return var_export($v, true); |
|
| 354 | + } elseif (!is_array($v)) { |
|
| 355 | + return "'" . texte_script((string) $v) . "'"; |
|
| 356 | + } else { |
|
| 357 | + $out = []; |
|
| 358 | + foreach ($v as $k => $val) { |
|
| 359 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return 'array(' . join(', ', $out) . ')'; |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -391,87 +391,87 @@ discard block |
||
| 391 | 391 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 392 | 392 | **/ |
| 393 | 393 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 394 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | - $nom_balise = $nom; |
|
| 396 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | - $nom_balise_generique = ''; |
|
| 398 | - |
|
| 399 | - $appel_php_depuis_modele = false; |
|
| 400 | - if ( |
|
| 401 | - is_array($context_compil) |
|
| 402 | - and !is_numeric($context_compil[3]) |
|
| 403 | - and empty($context_compil[0]) |
|
| 404 | - and empty($context_compil[1]) |
|
| 405 | - and empty($context_compil[2]) |
|
| 406 | - and empty($context_compil[3]) |
|
| 407 | - ) { |
|
| 408 | - $appel_php_depuis_modele = true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | - // injecter en premier arg le nom de la balise |
|
| 415 | - array_unshift($args, $nom); |
|
| 416 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | - $nom_balise = $nom_balise_generique; |
|
| 419 | - } |
|
| 420 | - unset($balise_generique); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!$fonction_balise) { |
|
| 424 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | - erreur_squelette($msg, $context_compil); |
|
| 426 | - |
|
| 427 | - return ''; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // retrouver le fichier qui a déclaré la fonction |
|
| 431 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | - |
|
| 442 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | - |
|
| 444 | - if (!is_array($r)) { |
|
| 445 | - return $r; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // verifier que la fonction dyn est la, |
|
| 449 | - // sinon se replier sur la generique si elle existe |
|
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | - if ( |
|
| 452 | - $balise_generique = chercher_balise_generique($nom) |
|
| 453 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | - ) { |
|
| 457 | - // et lui injecter en premier arg le nom de la balise |
|
| 458 | - array_unshift($r, $nom); |
|
| 459 | - $nom_balise = $nom_balise_generique; |
|
| 460 | - if (!_DIR_RESTREINT) { |
|
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | - } |
|
| 463 | - } else { |
|
| 464 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | - erreur_squelette($msg, $context_compil); |
|
| 466 | - |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($appel_php_depuis_modele) { |
|
| 472 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | - } |
|
| 474 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 394 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | + $nom_balise = $nom; |
|
| 396 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | + $nom_balise_generique = ''; |
|
| 398 | + |
|
| 399 | + $appel_php_depuis_modele = false; |
|
| 400 | + if ( |
|
| 401 | + is_array($context_compil) |
|
| 402 | + and !is_numeric($context_compil[3]) |
|
| 403 | + and empty($context_compil[0]) |
|
| 404 | + and empty($context_compil[1]) |
|
| 405 | + and empty($context_compil[2]) |
|
| 406 | + and empty($context_compil[3]) |
|
| 407 | + ) { |
|
| 408 | + $appel_php_depuis_modele = true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | + // injecter en premier arg le nom de la balise |
|
| 415 | + array_unshift($args, $nom); |
|
| 416 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | + $nom_balise = $nom_balise_generique; |
|
| 419 | + } |
|
| 420 | + unset($balise_generique); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!$fonction_balise) { |
|
| 424 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | + erreur_squelette($msg, $context_compil); |
|
| 426 | + |
|
| 427 | + return ''; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // retrouver le fichier qui a déclaré la fonction |
|
| 431 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | + |
|
| 442 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | + |
|
| 444 | + if (!is_array($r)) { |
|
| 445 | + return $r; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // verifier que la fonction dyn est la, |
|
| 449 | + // sinon se replier sur la generique si elle existe |
|
| 450 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | + if ( |
|
| 452 | + $balise_generique = chercher_balise_generique($nom) |
|
| 453 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | + ) { |
|
| 457 | + // et lui injecter en premier arg le nom de la balise |
|
| 458 | + array_unshift($r, $nom); |
|
| 459 | + $nom_balise = $nom_balise_generique; |
|
| 460 | + if (!_DIR_RESTREINT) { |
|
| 461 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | + } |
|
| 463 | + } else { |
|
| 464 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | + erreur_squelette($msg, $context_compil); |
|
| 466 | + |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($appel_php_depuis_modele) { |
|
| 472 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | + } |
|
| 474 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -486,23 +486,23 @@ discard block |
||
| 486 | 486 | * @return array|null |
| 487 | 487 | */ |
| 488 | 488 | function chercher_balise_generique($nom) { |
| 489 | - if (false === strpos($nom, '_')) { |
|
| 490 | - return null; |
|
| 491 | - } |
|
| 492 | - $nom_generique = $nom; |
|
| 493 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | - if ($fonction_generique) { |
|
| 497 | - return [ |
|
| 498 | - 'nom' => $nom, |
|
| 499 | - 'nom_generique' => $nom_generique, |
|
| 500 | - 'fonction_generique' => $fonction_generique, |
|
| 501 | - ]; |
|
| 502 | - } |
|
| 503 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | - } |
|
| 505 | - return null; |
|
| 489 | + if (false === strpos($nom, '_')) { |
|
| 490 | + return null; |
|
| 491 | + } |
|
| 492 | + $nom_generique = $nom; |
|
| 493 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | + if ($fonction_generique) { |
|
| 497 | + return [ |
|
| 498 | + 'nom' => $nom, |
|
| 499 | + 'nom_generique' => $nom_generique, |
|
| 500 | + 'fonction_generique' => $fonction_generique, |
|
| 501 | + ]; |
|
| 502 | + } |
|
| 503 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | + } |
|
| 505 | + return null; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | |
@@ -526,29 +526,29 @@ discard block |
||
| 526 | 526 | * @return null; |
| 527 | 527 | **/ |
| 528 | 528 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 529 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | - if ( |
|
| 531 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | - and $lang_select !== 'oui' |
|
| 533 | - ) { |
|
| 534 | - $lang = $GLOBALS['spip_lang']; |
|
| 535 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | - elseif (!strlen($lang)) { |
|
| 537 | - $lang = $GLOBALS['spip_lang']; |
|
| 538 | - } // Cas 3. l'objet est multilingue ! |
|
| 539 | - elseif ( |
|
| 540 | - $lang_select !== 'oui' |
|
| 541 | - and strlen($titre) > 10 |
|
| 542 | - and strpos($titre, '<multi>') !== false |
|
| 543 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | - ) { |
|
| 545 | - $lang = $GLOBALS['spip_lang']; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | - lang_select($lang); |
|
| 550 | - |
|
| 551 | - return; |
|
| 529 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | + if ( |
|
| 531 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | + and $lang_select !== 'oui' |
|
| 533 | + ) { |
|
| 534 | + $lang = $GLOBALS['spip_lang']; |
|
| 535 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | + elseif (!strlen($lang)) { |
|
| 537 | + $lang = $GLOBALS['spip_lang']; |
|
| 538 | + } // Cas 3. l'objet est multilingue ! |
|
| 539 | + elseif ( |
|
| 540 | + $lang_select !== 'oui' |
|
| 541 | + and strlen($titre) > 10 |
|
| 542 | + and strpos($titre, '<multi>') !== false |
|
| 543 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | + ) { |
|
| 545 | + $lang = $GLOBALS['spip_lang']; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | + lang_select($lang); |
|
| 550 | + |
|
| 551 | + return; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -556,21 +556,21 @@ discard block |
||
| 556 | 556 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 557 | 557 | // https://code.spip.net/@nettoyer_env_doublons |
| 558 | 558 | function nettoyer_env_doublons($envd) { |
| 559 | - foreach ($envd as $table => $liste) { |
|
| 560 | - $n = ''; |
|
| 561 | - foreach (explode(',', $liste) as $val) { |
|
| 562 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | - $n .= ',' . $val; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - if (strlen($n)) { |
|
| 567 | - $envd[$table] = $n; |
|
| 568 | - } else { |
|
| 569 | - unset($envd[$table]); |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $envd; |
|
| 559 | + foreach ($envd as $table => $liste) { |
|
| 560 | + $n = ''; |
|
| 561 | + foreach (explode(',', $liste) as $val) { |
|
| 562 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | + $n .= ',' . $val; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + if (strlen($n)) { |
|
| 567 | + $envd[$table] = $n; |
|
| 568 | + } else { |
|
| 569 | + unset($envd[$table]); |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $envd; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -589,21 +589,21 @@ discard block |
||
| 589 | 589 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 590 | 590 | **/ |
| 591 | 591 | function match_self($w) { |
| 592 | - if (is_string($w)) { |
|
| 593 | - return false; |
|
| 594 | - } |
|
| 595 | - if (is_array($w)) { |
|
| 596 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | - return $w; |
|
| 598 | - } |
|
| 599 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | - if ($m = match_self($sw)) { |
|
| 601 | - return $m; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return false; |
|
| 592 | + if (is_string($w)) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 595 | + if (is_array($w)) { |
|
| 596 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | + return $w; |
|
| 598 | + } |
|
| 599 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | + if ($m = match_self($sw)) { |
|
| 601 | + return $m; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return false; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -619,16 +619,16 @@ discard block |
||
| 619 | 619 | * est remplacée par son code. |
| 620 | 620 | **/ |
| 621 | 621 | function remplace_sous_requete($w, $sousrequete) { |
| 622 | - if (is_array($w)) { |
|
| 623 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | - return $sousrequete; |
|
| 625 | - } |
|
| 626 | - foreach ($w as $k => $sw) { |
|
| 627 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return $w; |
|
| 622 | + if (is_array($w)) { |
|
| 623 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | + return $sousrequete; |
|
| 625 | + } |
|
| 626 | + foreach ($w as $k => $sw) { |
|
| 627 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return $w; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -642,17 +642,17 @@ discard block |
||
| 642 | 642 | * - Conditions avec des sous requêtes |
| 643 | 643 | **/ |
| 644 | 644 | function trouver_sous_requetes($where) { |
| 645 | - $where_simples = []; |
|
| 646 | - $where_sous = []; |
|
| 647 | - foreach ($where as $k => $w) { |
|
| 648 | - if (match_self($w)) { |
|
| 649 | - $where_sous[$k] = $w; |
|
| 650 | - } else { |
|
| 651 | - $where_simples[$k] = $w; |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return [$where_simples, $where_sous]; |
|
| 645 | + $where_simples = []; |
|
| 646 | + $where_sous = []; |
|
| 647 | + foreach ($where as $k => $w) { |
|
| 648 | + if (match_self($w)) { |
|
| 649 | + $where_sous[$k] = $w; |
|
| 650 | + } else { |
|
| 651 | + $where_simples[$k] = $w; |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return [$where_simples, $where_sous]; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -678,292 +678,292 @@ discard block |
||
| 678 | 678 | * @return resource |
| 679 | 679 | */ |
| 680 | 680 | function calculer_select( |
| 681 | - $select = [], |
|
| 682 | - $from = [], |
|
| 683 | - $from_type = [], |
|
| 684 | - $where = [], |
|
| 685 | - $join = [], |
|
| 686 | - $groupby = [], |
|
| 687 | - $orderby = [], |
|
| 688 | - $limit = '', |
|
| 689 | - $having = [], |
|
| 690 | - $table = '', |
|
| 691 | - $id = '', |
|
| 692 | - $serveur = '', |
|
| 693 | - $requeter = true |
|
| 681 | + $select = [], |
|
| 682 | + $from = [], |
|
| 683 | + $from_type = [], |
|
| 684 | + $where = [], |
|
| 685 | + $join = [], |
|
| 686 | + $groupby = [], |
|
| 687 | + $orderby = [], |
|
| 688 | + $limit = '', |
|
| 689 | + $having = [], |
|
| 690 | + $table = '', |
|
| 691 | + $id = '', |
|
| 692 | + $serveur = '', |
|
| 693 | + $requeter = true |
|
| 694 | 694 | ) { |
| 695 | 695 | |
| 696 | - // retirer les criteres vides: |
|
| 697 | - // {X ?} avec X absent de l'URL |
|
| 698 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | - $menage = false; |
|
| 701 | - foreach ($where as $k => $v) { |
|
| 702 | - if (is_array($v)) { |
|
| 703 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | - $op = false; |
|
| 705 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | - $op = false; |
|
| 707 | - } else { |
|
| 708 | - $op = $v[0] ? $v[0] : $v; |
|
| 709 | - } |
|
| 710 | - } else { |
|
| 711 | - $op = $v; |
|
| 712 | - } |
|
| 713 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | - unset($where[$k]); |
|
| 715 | - $menage = true; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | - $groupby = array_diff($groupby, ['']); |
|
| 721 | - |
|
| 722 | - // remplacer les sous requetes recursives au calcul |
|
| 723 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | - foreach ($where_sous as $k => $w) { |
|
| 725 | - $menage = true; |
|
| 726 | - // on recupere la sous requete |
|
| 727 | - $sous = match_self($w); |
|
| 728 | - if ($sous[0] == 'SELF') { |
|
| 729 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | - array_push($where_simples, $sous[2]); |
|
| 731 | - $wheresub = [ |
|
| 732 | - $sous[2], |
|
| 733 | - '0=0' |
|
| 734 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | - $jsub = $join; |
|
| 736 | - // trouver les jointures utiles a |
|
| 737 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | - // ie L1.objet='article' |
|
| 739 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | - $i = 0; |
|
| 741 | - do { |
|
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 744 | - $from, |
|
| 745 | - $from_type, |
|
| 746 | - $wheresub, |
|
| 747 | - $jsub, |
|
| 748 | - [], |
|
| 749 | - [], |
|
| 750 | - '', |
|
| 751 | - $having, |
|
| 752 | - $table, |
|
| 753 | - $id, |
|
| 754 | - $serveur, |
|
| 755 | - false |
|
| 756 | - ) . ')'); |
|
| 757 | - if (!$i) { |
|
| 758 | - $i = 1; |
|
| 759 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | - foreach ($join as $cle => $wj) { |
|
| 761 | - if ( |
|
| 762 | - count($wj) == 4 |
|
| 763 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | - ) { |
|
| 765 | - $i = 0; |
|
| 766 | - $wheresub[] = $wj[3]; |
|
| 767 | - unset($jsub[$cle][3]); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - } while ($i++ < 1); |
|
| 772 | - } |
|
| 773 | - if ($sous[0] == 'SUBSELECT') { |
|
| 774 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | - $sous[1], # select |
|
| 778 | - $sous[2], #from |
|
| 779 | - [], #from_type |
|
| 780 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | - [], #join |
|
| 783 | - $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | - $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | - $sous[6], #limit |
|
| 786 | - $sous[7] ? $sous[7] : [], #having |
|
| 787 | - $table, |
|
| 788 | - $id, |
|
| 789 | - $serveur, |
|
| 790 | - false |
|
| 791 | - ) . ')'); |
|
| 792 | - } |
|
| 793 | - array_pop($where_simples); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - foreach ($having as $k => $v) { |
|
| 797 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | - unset($having[$k]); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - // Installer les jointures. |
|
| 803 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | - |
|
| 807 | - $afrom = []; |
|
| 808 | - $equiv = []; |
|
| 809 | - $k = count($join); |
|
| 810 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | - $cle = $cledef; |
|
| 812 | - // le format de join est : |
|
| 813 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | - if (count($join[$cle]) == 2) { |
|
| 816 | - $join[$cle][] = $join[$cle][1]; |
|
| 817 | - } |
|
| 818 | - if (count($join[$cle]) == 3) { |
|
| 819 | - $join[$cle][] = ''; |
|
| 820 | - } |
|
| 821 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | - // pour compat avec ancienne convention |
|
| 824 | - if (is_numeric($cle)) { |
|
| 825 | - $cle = "L$k"; |
|
| 826 | - } |
|
| 827 | - $cle_where_lie = "JOIN-$cle"; |
|
| 828 | - if ( |
|
| 829 | - !$menage |
|
| 830 | - or isset($afrom[$cle]) |
|
| 831 | - or calculer_jointnul($cle, $select) |
|
| 832 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | - or calculer_jointnul($cle, $having) |
|
| 834 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | - ) { |
|
| 836 | - // corriger les references non explicites dans select |
|
| 837 | - // ou groupby |
|
| 838 | - foreach ($select as $i => $s) { |
|
| 839 | - if ($s == $c) { |
|
| 840 | - $select[$i] = "$cle.$c AS $c"; |
|
| 841 | - break; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - foreach ($groupby as $i => $g) { |
|
| 845 | - if ($g == $c) { |
|
| 846 | - $groupby[$i] = "$cle.$c"; |
|
| 847 | - break; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | - // sans recours a preg_match |
|
| 852 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | - $afrom[$t][$cle] = [ |
|
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | - $from[$cle], |
|
| 857 | - "AS $cle", |
|
| 858 | - 'ON (', |
|
| 859 | - "$cle.$c", |
|
| 860 | - '=', |
|
| 861 | - "$t.$carr", |
|
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 863 | - ')' |
|
| 864 | - ]; |
|
| 865 | - if (isset($afrom[$cle])) { |
|
| 866 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | - unset($afrom[$cle]); |
|
| 868 | - } |
|
| 869 | - $equiv[] = $carr; |
|
| 870 | - } else { |
|
| 871 | - unset($join[$cledef]); |
|
| 872 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | - unset($where_simples[$cle_where_lie]); |
|
| 874 | - unset($where[$cle_where_lie]); |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - unset($from[$cle]); |
|
| 878 | - $k--; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if (count($afrom)) { |
|
| 882 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | - // ou dans |
|
| 887 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | - // qui comporte plusieurs jointures |
|
| 889 | - // ou dans |
|
| 890 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | - |
|
| 897 | - $t = key($from); |
|
| 898 | - $c = current($from); |
|
| 899 | - reset($from); |
|
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | - if ( |
|
| 902 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | - calculer_jointnul($t, $select, $e) or |
|
| 904 | - calculer_jointnul($t, $join, $e) or |
|
| 905 | - calculer_jointnul($t, $where, $e) or |
|
| 906 | - calculer_jointnul($t, $orderby, $e) or |
|
| 907 | - calculer_jointnul($t, $groupby, $e) or |
|
| 908 | - calculer_jointnul($t, $having, $e)) |
|
| 909 | - && count($afrom[$t]) |
|
| 910 | - ) { |
|
| 911 | - $nfrom = reset($afrom[$t]); |
|
| 912 | - $nt = key($afrom[$t]); |
|
| 913 | - unset($from[$t]); |
|
| 914 | - $from[$nt] = $nfrom[1]; |
|
| 915 | - unset($afrom[$t][$nt]); |
|
| 916 | - $afrom[$nt] = $afrom[$t]; |
|
| 917 | - unset($afrom[$t]); |
|
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | - $t = $nfrom[4]; |
|
| 920 | - $alias = ''; |
|
| 921 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | - $oldcle = explode('.', $nfrom[6]); |
|
| 923 | - $oldcle = end($oldcle); |
|
| 924 | - $newcle = explode('.', $nfrom[4]); |
|
| 925 | - $newcle = end($newcle); |
|
| 926 | - if ($newcle != $oldcle) { |
|
| 927 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | - // reprendre simplement ce AS |
|
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | - $alias = ''; |
|
| 932 | - } else { |
|
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | - } |
|
| 943 | - $from = reinjecte_joint($afrom, $from); |
|
| 944 | - } |
|
| 945 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | - $GLOBALS['debug'] = []; |
|
| 948 | - if ($wasdebug) { |
|
| 949 | - $GLOBALS['debug']['debug'] = true; |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | - $r = sql_select( |
|
| 954 | - $select, |
|
| 955 | - $from, |
|
| 956 | - $where, |
|
| 957 | - $groupby, |
|
| 958 | - array_filter($orderby), |
|
| 959 | - $limit, |
|
| 960 | - $having, |
|
| 961 | - $serveur, |
|
| 962 | - $requeter |
|
| 963 | - ); |
|
| 964 | - unset($GLOBALS['debug']['aucasou']); |
|
| 965 | - |
|
| 966 | - return $r; |
|
| 696 | + // retirer les criteres vides: |
|
| 697 | + // {X ?} avec X absent de l'URL |
|
| 698 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | + $menage = false; |
|
| 701 | + foreach ($where as $k => $v) { |
|
| 702 | + if (is_array($v)) { |
|
| 703 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | + $op = false; |
|
| 705 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | + $op = false; |
|
| 707 | + } else { |
|
| 708 | + $op = $v[0] ? $v[0] : $v; |
|
| 709 | + } |
|
| 710 | + } else { |
|
| 711 | + $op = $v; |
|
| 712 | + } |
|
| 713 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | + unset($where[$k]); |
|
| 715 | + $menage = true; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | + $groupby = array_diff($groupby, ['']); |
|
| 721 | + |
|
| 722 | + // remplacer les sous requetes recursives au calcul |
|
| 723 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | + foreach ($where_sous as $k => $w) { |
|
| 725 | + $menage = true; |
|
| 726 | + // on recupere la sous requete |
|
| 727 | + $sous = match_self($w); |
|
| 728 | + if ($sous[0] == 'SELF') { |
|
| 729 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | + array_push($where_simples, $sous[2]); |
|
| 731 | + $wheresub = [ |
|
| 732 | + $sous[2], |
|
| 733 | + '0=0' |
|
| 734 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | + $jsub = $join; |
|
| 736 | + // trouver les jointures utiles a |
|
| 737 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | + // ie L1.objet='article' |
|
| 739 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | + $i = 0; |
|
| 741 | + do { |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | + [$sous[1] . ' AS id'], |
|
| 744 | + $from, |
|
| 745 | + $from_type, |
|
| 746 | + $wheresub, |
|
| 747 | + $jsub, |
|
| 748 | + [], |
|
| 749 | + [], |
|
| 750 | + '', |
|
| 751 | + $having, |
|
| 752 | + $table, |
|
| 753 | + $id, |
|
| 754 | + $serveur, |
|
| 755 | + false |
|
| 756 | + ) . ')'); |
|
| 757 | + if (!$i) { |
|
| 758 | + $i = 1; |
|
| 759 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | + foreach ($join as $cle => $wj) { |
|
| 761 | + if ( |
|
| 762 | + count($wj) == 4 |
|
| 763 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | + ) { |
|
| 765 | + $i = 0; |
|
| 766 | + $wheresub[] = $wj[3]; |
|
| 767 | + unset($jsub[$cle][3]); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + } while ($i++ < 1); |
|
| 772 | + } |
|
| 773 | + if ($sous[0] == 'SUBSELECT') { |
|
| 774 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | + $sous[1], # select |
|
| 778 | + $sous[2], #from |
|
| 779 | + [], #from_type |
|
| 780 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | + [], #join |
|
| 783 | + $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | + $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | + $sous[6], #limit |
|
| 786 | + $sous[7] ? $sous[7] : [], #having |
|
| 787 | + $table, |
|
| 788 | + $id, |
|
| 789 | + $serveur, |
|
| 790 | + false |
|
| 791 | + ) . ')'); |
|
| 792 | + } |
|
| 793 | + array_pop($where_simples); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + foreach ($having as $k => $v) { |
|
| 797 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | + unset($having[$k]); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + // Installer les jointures. |
|
| 803 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | + |
|
| 807 | + $afrom = []; |
|
| 808 | + $equiv = []; |
|
| 809 | + $k = count($join); |
|
| 810 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | + $cle = $cledef; |
|
| 812 | + // le format de join est : |
|
| 813 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | + if (count($join[$cle]) == 2) { |
|
| 816 | + $join[$cle][] = $join[$cle][1]; |
|
| 817 | + } |
|
| 818 | + if (count($join[$cle]) == 3) { |
|
| 819 | + $join[$cle][] = ''; |
|
| 820 | + } |
|
| 821 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | + // pour compat avec ancienne convention |
|
| 824 | + if (is_numeric($cle)) { |
|
| 825 | + $cle = "L$k"; |
|
| 826 | + } |
|
| 827 | + $cle_where_lie = "JOIN-$cle"; |
|
| 828 | + if ( |
|
| 829 | + !$menage |
|
| 830 | + or isset($afrom[$cle]) |
|
| 831 | + or calculer_jointnul($cle, $select) |
|
| 832 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | + or calculer_jointnul($cle, $having) |
|
| 834 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | + ) { |
|
| 836 | + // corriger les references non explicites dans select |
|
| 837 | + // ou groupby |
|
| 838 | + foreach ($select as $i => $s) { |
|
| 839 | + if ($s == $c) { |
|
| 840 | + $select[$i] = "$cle.$c AS $c"; |
|
| 841 | + break; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + foreach ($groupby as $i => $g) { |
|
| 845 | + if ($g == $c) { |
|
| 846 | + $groupby[$i] = "$cle.$c"; |
|
| 847 | + break; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | + // sans recours a preg_match |
|
| 852 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | + $afrom[$t][$cle] = [ |
|
| 854 | + "\n" . |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | + $from[$cle], |
|
| 857 | + "AS $cle", |
|
| 858 | + 'ON (', |
|
| 859 | + "$cle.$c", |
|
| 860 | + '=', |
|
| 861 | + "$t.$carr", |
|
| 862 | + ($and ? 'AND ' . $and : '') . |
|
| 863 | + ')' |
|
| 864 | + ]; |
|
| 865 | + if (isset($afrom[$cle])) { |
|
| 866 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | + unset($afrom[$cle]); |
|
| 868 | + } |
|
| 869 | + $equiv[] = $carr; |
|
| 870 | + } else { |
|
| 871 | + unset($join[$cledef]); |
|
| 872 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | + unset($where_simples[$cle_where_lie]); |
|
| 874 | + unset($where[$cle_where_lie]); |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + unset($from[$cle]); |
|
| 878 | + $k--; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if (count($afrom)) { |
|
| 882 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | + // ou dans |
|
| 887 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | + // qui comporte plusieurs jointures |
|
| 889 | + // ou dans |
|
| 890 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | + |
|
| 897 | + $t = key($from); |
|
| 898 | + $c = current($from); |
|
| 899 | + reset($from); |
|
| 900 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | + if ( |
|
| 902 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | + calculer_jointnul($t, $select, $e) or |
|
| 904 | + calculer_jointnul($t, $join, $e) or |
|
| 905 | + calculer_jointnul($t, $where, $e) or |
|
| 906 | + calculer_jointnul($t, $orderby, $e) or |
|
| 907 | + calculer_jointnul($t, $groupby, $e) or |
|
| 908 | + calculer_jointnul($t, $having, $e)) |
|
| 909 | + && count($afrom[$t]) |
|
| 910 | + ) { |
|
| 911 | + $nfrom = reset($afrom[$t]); |
|
| 912 | + $nt = key($afrom[$t]); |
|
| 913 | + unset($from[$t]); |
|
| 914 | + $from[$nt] = $nfrom[1]; |
|
| 915 | + unset($afrom[$t][$nt]); |
|
| 916 | + $afrom[$nt] = $afrom[$t]; |
|
| 917 | + unset($afrom[$t]); |
|
| 918 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | + $t = $nfrom[4]; |
|
| 920 | + $alias = ''; |
|
| 921 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | + $oldcle = explode('.', $nfrom[6]); |
|
| 923 | + $oldcle = end($oldcle); |
|
| 924 | + $newcle = explode('.', $nfrom[4]); |
|
| 925 | + $newcle = end($newcle); |
|
| 926 | + if ($newcle != $oldcle) { |
|
| 927 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | + // reprendre simplement ce AS |
|
| 929 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | + $alias = ''; |
|
| 932 | + } else { |
|
| 933 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | + } |
|
| 943 | + $from = reinjecte_joint($afrom, $from); |
|
| 944 | + } |
|
| 945 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | + $GLOBALS['debug'] = []; |
|
| 948 | + if ($wasdebug) { |
|
| 949 | + $GLOBALS['debug']['debug'] = true; |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | + $r = sql_select( |
|
| 954 | + $select, |
|
| 955 | + $from, |
|
| 956 | + $where, |
|
| 957 | + $groupby, |
|
| 958 | + array_filter($orderby), |
|
| 959 | + $limit, |
|
| 960 | + $having, |
|
| 961 | + $serveur, |
|
| 962 | + $requeter |
|
| 963 | + ); |
|
| 964 | + unset($GLOBALS['debug']['aucasou']); |
|
| 965 | + |
|
| 966 | + return $r; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | /** |
@@ -974,20 +974,20 @@ discard block |
||
| 974 | 974 | * @return string |
| 975 | 975 | */ |
| 976 | 976 | function calculer_where_to_string($v, $join = 'AND') { |
| 977 | - if (empty($v)) { |
|
| 978 | - return ''; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - if (!is_array($v)) { |
|
| 982 | - return $v; |
|
| 983 | - } else { |
|
| 984 | - $exp = ''; |
|
| 985 | - if (strtoupper($join) === 'AND') { |
|
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | - } else { |
|
| 988 | - return $exp . join($join, $v); |
|
| 989 | - } |
|
| 990 | - } |
|
| 977 | + if (empty($v)) { |
|
| 978 | + return ''; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + if (!is_array($v)) { |
|
| 982 | + return $v; |
|
| 983 | + } else { |
|
| 984 | + $exp = ''; |
|
| 985 | + if (strtoupper($join) === 'AND') { |
|
| 986 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | + } else { |
|
| 988 | + return $exp . join($join, $v); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | |
@@ -995,62 +995,62 @@ discard block |
||
| 995 | 995 | |
| 996 | 996 | // https://code.spip.net/@calculer_jointnul |
| 997 | 997 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 998 | - if (!is_array($exp)) { |
|
| 999 | - if ($equiv) { |
|
| 1000 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | - } else { |
|
| 1005 | - foreach ($exp as $v) { |
|
| 1006 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | - return true; |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 998 | + if (!is_array($exp)) { |
|
| 999 | + if ($equiv) { |
|
| 1000 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | + } else { |
|
| 1005 | + foreach ($exp as $v) { |
|
| 1006 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | + return true; |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | // https://code.spip.net/@reinjecte_joint |
| 1016 | 1016 | function reinjecte_joint($afrom, $from) { |
| 1017 | - $from_synth = []; |
|
| 1018 | - foreach ($from as $k => $v) { |
|
| 1019 | - $from_synth[$k] = $from[$k]; |
|
| 1020 | - if (isset($afrom[$k])) { |
|
| 1021 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | - } |
|
| 1024 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | - unset($afrom[$k]); |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - return $from_synth; |
|
| 1017 | + $from_synth = []; |
|
| 1018 | + foreach ($from as $k => $v) { |
|
| 1019 | + $from_synth[$k] = $from[$k]; |
|
| 1020 | + if (isset($afrom[$k])) { |
|
| 1021 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | + } |
|
| 1024 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | + unset($afrom[$k]); |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + return $from_synth; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // https://code.spip.net/@remplacer_jointnul |
| 1033 | 1033 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1034 | - if (!is_array($exp)) { |
|
| 1035 | - return preg_replace($equiv, $cle, $exp); |
|
| 1036 | - } else { |
|
| 1037 | - foreach ($exp as $k => $v) { |
|
| 1038 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return $exp; |
|
| 1042 | - } |
|
| 1034 | + if (!is_array($exp)) { |
|
| 1035 | + return preg_replace($equiv, $cle, $exp); |
|
| 1036 | + } else { |
|
| 1037 | + foreach ($exp as $k => $v) { |
|
| 1038 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return $exp; |
|
| 1042 | + } |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | // calcul du nom du squelette |
| 1046 | 1046 | // https://code.spip.net/@calculer_nom_fonction_squel |
| 1047 | 1047 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1048 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - return $mime_type |
|
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1048 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + return $mime_type |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 58 | 58 | |
| 59 | 59 | // si squelette est deja compile et perenne, le charger |
| 60 | 60 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | #} |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 71 | 71 | include_once $lib; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | eval("return true; $f ;"); |
| 96 | 96 | } catch (\ParseError $e) { |
| 97 | 97 | // Code syntaxiquement faux (critere etc mal programme') |
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 98 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 99 | 99 | erreur_squelette($msg, $boucle); |
| 100 | 100 | // continuer pour trouver d'autres fautes eventuelles |
| 101 | 101 | // mais prevenir que c'est mort |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 125 | 125 | // Tracer ce qui vient d'etre compile |
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 127 | 127 | |
| 128 | 128 | // si c'est ce que demande le debusqueur, lui passer la main |
| 129 | 129 | if ( |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $code = " |
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 150 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 151 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 149 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 150 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 151 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 152 | 152 | */ '; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 155 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 156 | 156 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 157 | 157 | ecrire_fichier($phpfile, $code); |
| 158 | 158 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 217 | 217 | |
| 218 | 218 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | + $headers[$j] .= '|'.$r[3]; |
|
| 220 | 220 | } else { |
| 221 | 221 | $headers[$j] = $r[3]; |
| 222 | 222 | } |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | // S'agit-il d'un resultat constant ou contenant du code php |
| 226 | 226 | $process_ins = ( |
| 227 | - strpos($corps, '<' . '?') === false |
|
| 227 | + strpos($corps, '<'.'?') === false |
|
| 228 | 228 | or |
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 229 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 230 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 231 | 231 | ) |
| 232 | 232 | ? 'html' |
| 233 | 233 | : 'php'; |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | if ($process_ins == 'html') { |
| 258 | 258 | $skel['process_ins'] = ( |
| 259 | - strpos($corps, '<' . '?') === false |
|
| 259 | + strpos($corps, '<'.'?') === false |
|
| 260 | 260 | or |
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 261 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 262 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 263 | 263 | ) |
| 264 | 264 | ? 'html' |
| 265 | 265 | : 'php'; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | // |
| 278 | 278 | |
| 279 | 279 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 280 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 280 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 281 | 281 | include_once("%s"); |
| 282 | 282 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | // pas de lien symbolique sous Windows |
| 309 | 309 | and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
| 310 | 310 | ) { |
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $lang = $context_compil[4]; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | $args = array_map('argumenter_squelette', $args); |
| 320 | 320 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 322 | 322 | } |
| 323 | 323 | $args = join(', ', $args); |
| 324 | 324 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | if (is_object($v)) { |
| 353 | 353 | return var_export($v, true); |
| 354 | 354 | } elseif (!is_array($v)) { |
| 355 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + return "'".texte_script((string) $v)."'"; |
|
| 356 | 356 | } else { |
| 357 | 357 | $out = []; |
| 358 | 358 | foreach ($v as $k => $val) { |
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + return 'array('.join(', ', $out).')'; |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Y a-t-il une fonction de traitement des arguments ? |
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 440 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 441 | 441 | |
| 442 | 442 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | // verifier que la fonction dyn est la, |
| 449 | 449 | // sinon se replier sur la generique si elle existe |
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 450 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 451 | 451 | if ( |
| 452 | 452 | $balise_generique = chercher_balise_generique($nom) |
| 453 | 453 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 454 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 456 | 456 | ) { |
| 457 | 457 | // et lui injecter en premier arg le nom de la balise |
| 458 | 458 | array_unshift($r, $nom); |
| 459 | 459 | $nom_balise = $nom_balise_generique; |
| 460 | 460 | if (!_DIR_RESTREINT) { |
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 461 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 462 | 462 | } |
| 463 | 463 | } else { |
| 464 | 464 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $n = ''; |
| 561 | 561 | foreach (explode(',', $liste) as $val) { |
| 562 | 562 | if ($a = intval($val) and $val === strval($a)) { |
| 563 | - $n .= ',' . $val; |
|
| 563 | + $n .= ','.$val; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | if (strlen($n)) { |
@@ -739,8 +739,8 @@ discard block |
||
| 739 | 739 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 740 | 740 | $i = 0; |
| 741 | 741 | do { |
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 743 | + [$sous[1].' AS id'], |
|
| 744 | 744 | $from, |
| 745 | 745 | $from_type, |
| 746 | 746 | $wheresub, |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | $id, |
| 754 | 754 | $serveur, |
| 755 | 755 | false |
| 756 | - ) . ')'); |
|
| 756 | + ).')'); |
|
| 757 | 757 | if (!$i) { |
| 758 | 758 | $i = 1; |
| 759 | 759 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | if ($sous[0] == 'SUBSELECT') { |
| 774 | 774 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 775 | 775 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 777 | 777 | $sous[1], # select |
| 778 | 778 | $sous[2], #from |
| 779 | 779 | [], #from_type |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | $id, |
| 789 | 789 | $serveur, |
| 790 | 790 | false |
| 791 | - ) . ')'); |
|
| 791 | + ).')'); |
|
| 792 | 792 | } |
| 793 | 793 | array_pop($where_simples); |
| 794 | 794 | } |
@@ -851,15 +851,15 @@ discard block |
||
| 851 | 851 | // sans recours a preg_match |
| 852 | 852 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 853 | 853 | $afrom[$t][$cle] = [ |
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 854 | + "\n". |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER').' JOIN', |
|
| 856 | 856 | $from[$cle], |
| 857 | 857 | "AS $cle", |
| 858 | 858 | 'ON (', |
| 859 | 859 | "$cle.$c", |
| 860 | 860 | '=', |
| 861 | 861 | "$t.$carr", |
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 862 | + ($and ? 'AND '.$and : ''). |
|
| 863 | 863 | ')' |
| 864 | 864 | ]; |
| 865 | 865 | if (isset($afrom[$cle])) { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | $t = key($from); |
| 898 | 898 | $c = current($from); |
| 899 | 899 | reset($from); |
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 900 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 901 | 901 | if ( |
| 902 | 902 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 903 | 903 | calculer_jointnul($t, $select, $e) or |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | unset($afrom[$t][$nt]); |
| 916 | 916 | $afrom[$nt] = $afrom[$t]; |
| 917 | 917 | unset($afrom[$t]); |
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 918 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 919 | 919 | $t = $nfrom[4]; |
| 920 | 920 | $alias = ''; |
| 921 | 921 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -926,14 +926,14 @@ discard block |
||
| 926 | 926 | if ($newcle != $oldcle) { |
| 927 | 927 | // si l'ancienne cle etait deja dans le select avec un AS |
| 928 | 928 | // reprendre simplement ce AS |
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 929 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 930 | 930 | if (preg_match($as, implode(',', $select), $m)) { |
| 931 | 931 | $alias = ''; |
| 932 | 932 | } else { |
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 933 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 936 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 937 | 937 | $join = remplacer_jointnul($t, $join, $e); |
| 938 | 938 | $where = remplacer_jointnul($t, $where, $e); |
| 939 | 939 | $having = remplacer_jointnul($t, $having, $e); |
@@ -983,9 +983,9 @@ discard block |
||
| 983 | 983 | } else { |
| 984 | 984 | $exp = ''; |
| 985 | 985 | if (strtoupper($join) === 'AND') { |
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 986 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | 987 | } else { |
| 988 | - return $exp . join($join, $v); |
|
| 988 | + return $exp.join($join, $v); |
|
| 989 | 989 | } |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -1051,6 +1051,6 @@ discard block |
||
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | return $mime_type |
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,668 +21,668 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - // cas des SI {si expression} analises tres tot |
|
| 27 | - // pour eviter le chargement de tout iterateur |
|
| 28 | - if (isset($command['si'])) { |
|
| 29 | - foreach ($command['si'] as $si) { |
|
| 30 | - if (!$si) { |
|
| 31 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 32 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 33 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 39 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 40 | - // pour etre certain qu'on est sur un "php:") |
|
| 41 | - if (class_exists($iterateur)) { |
|
| 42 | - $a = isset($command['args']) ? $command['args'] : []; |
|
| 43 | - |
|
| 44 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 45 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 46 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 47 | - $iter = $a[0]; |
|
| 48 | - |
|
| 49 | - // sinon, on cree un iterateur du type donne |
|
| 50 | - } else { |
|
| 51 | - // arguments de creation de l'iterateur... |
|
| 52 | - // (pas glop) |
|
| 53 | - try { |
|
| 54 | - switch (count($a)) { |
|
| 55 | - case 0: |
|
| 56 | - $iter = new $iterateur(); |
|
| 57 | - break; |
|
| 58 | - case 1: |
|
| 59 | - $iter = new $iterateur($a[0]); |
|
| 60 | - break; |
|
| 61 | - case 2: |
|
| 62 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 63 | - break; |
|
| 64 | - case 3: |
|
| 65 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 66 | - break; |
|
| 67 | - case 4: |
|
| 68 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - } catch (Exception $e) { |
|
| 72 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 73 | - spip_log($e->getMessage()); |
|
| 74 | - $iter = new EmptyIterator(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - // chercher la classe d'iterateur |
|
| 79 | - // IterateurXXX |
|
| 80 | - // definie dans le fichier iterateurs/xxx.php |
|
| 81 | - $class = 'Iterateur' . $iterateur; |
|
| 82 | - if (!class_exists($class)) { |
|
| 83 | - if ( |
|
| 84 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + // cas des SI {si expression} analises tres tot |
|
| 27 | + // pour eviter le chargement de tout iterateur |
|
| 28 | + if (isset($command['si'])) { |
|
| 29 | + foreach ($command['si'] as $si) { |
|
| 30 | + if (!$si) { |
|
| 31 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 32 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 33 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 39 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 40 | + // pour etre certain qu'on est sur un "php:") |
|
| 41 | + if (class_exists($iterateur)) { |
|
| 42 | + $a = isset($command['args']) ? $command['args'] : []; |
|
| 43 | + |
|
| 44 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 45 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 46 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 47 | + $iter = $a[0]; |
|
| 48 | + |
|
| 49 | + // sinon, on cree un iterateur du type donne |
|
| 50 | + } else { |
|
| 51 | + // arguments de creation de l'iterateur... |
|
| 52 | + // (pas glop) |
|
| 53 | + try { |
|
| 54 | + switch (count($a)) { |
|
| 55 | + case 0: |
|
| 56 | + $iter = new $iterateur(); |
|
| 57 | + break; |
|
| 58 | + case 1: |
|
| 59 | + $iter = new $iterateur($a[0]); |
|
| 60 | + break; |
|
| 61 | + case 2: |
|
| 62 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 63 | + break; |
|
| 64 | + case 3: |
|
| 65 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 66 | + break; |
|
| 67 | + case 4: |
|
| 68 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + } catch (Exception $e) { |
|
| 72 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 73 | + spip_log($e->getMessage()); |
|
| 74 | + $iter = new EmptyIterator(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + // chercher la classe d'iterateur |
|
| 79 | + // IterateurXXX |
|
| 80 | + // definie dans le fichier iterateurs/xxx.php |
|
| 81 | + $class = 'Iterateur' . $iterateur; |
|
| 82 | + if (!class_exists($class)) { |
|
| 83 | + if ( |
|
| 84 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = []; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if ( |
|
| 205 | - is_object($this->iter) |
|
| 206 | - and method_exists($this->iter, $nom) |
|
| 207 | - ) { |
|
| 208 | - try { |
|
| 209 | - return $this->iter->$nom(); |
|
| 210 | - } catch (Exception $e) { |
|
| 211 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 212 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 213 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = []; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if ( |
|
| 205 | + is_object($this->iter) |
|
| 206 | + and method_exists($this->iter, $nom) |
|
| 207 | + ) { |
|
| 208 | + try { |
|
| 209 | + return $this->iter->$nom(); |
|
| 210 | + } catch (Exception $e) { |
|
| 211 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 212 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 213 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + /* |
|
| 219 | 219 | if (property_exists($this->iter, $nom)) { |
| 220 | 220 | return $this->iter->$nom; |
| 221 | 221 | }*/ |
| 222 | - // cle et valeur par defaut |
|
| 223 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 224 | - if ( |
|
| 225 | - in_array($nom, ['cle', 'valeur']) |
|
| 226 | - and method_exists($this, $nom) |
|
| 227 | - ) { |
|
| 228 | - return $this->$nom(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Par defaut chercher en xpath dans la valeur() |
|
| 232 | - return table_valeur($this->valeur(), $nom, null); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - private function calculer_filtres() { |
|
| 237 | - |
|
| 238 | - // Issu de calculer_select() de public/composer L.519 |
|
| 239 | - // TODO: externaliser... |
|
| 240 | - // |
|
| 241 | - // retirer les criteres vides: |
|
| 242 | - // {X ?} avec X absent de l'URL |
|
| 243 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 244 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 245 | - if ($where = &$this->command['where']) { |
|
| 246 | - foreach ($where as $k => $v) { |
|
| 247 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // critere {2,7} |
|
| 252 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 253 | - $limit = explode(',', $this->command['limit']); |
|
| 254 | - $this->offset = $limit[0]; |
|
| 255 | - $this->limit = $limit[1]; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // Creer la fonction de filtrage sur $this |
|
| 259 | - if ($this->filtre) { |
|
| 260 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 261 | - $filtres = 'return ' . $filtres . ';'; |
|
| 262 | - $this->func_filtre = function () use ($filtres) { |
|
| 263 | - return eval($filtres); |
|
| 264 | - }; |
|
| 265 | - } |
|
| 266 | - else { |
|
| 267 | - $this->func_filtre = null; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 274 | - * les filtres vides ou null sont ignores |
|
| 275 | - * @param $filtres |
|
| 276 | - * @param string $operateur |
|
| 277 | - * @return string|null |
|
| 278 | - */ |
|
| 279 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 280 | - |
|
| 281 | - $filtres_string = []; |
|
| 282 | - foreach ($filtres as $k => $v) { |
|
| 283 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 284 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 285 | - $op = array_shift($v); |
|
| 286 | - $v = $this->assembler_filtres($v, $op); |
|
| 287 | - } |
|
| 288 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 289 | - continue; |
|
| 290 | - } |
|
| 291 | - $filtres_string[] = $v; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!count($filtres_string)) { |
|
| 295 | - return null; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Traduire un element du tableau where SQL en un filtre |
|
| 303 | - * @param $v |
|
| 304 | - * @return string|array|null |
|
| 305 | - */ |
|
| 306 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 307 | - if (is_array($v)) { |
|
| 308 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 309 | - return 'true'; |
|
| 310 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 311 | - return 'true'; |
|
| 312 | - } else { |
|
| 313 | - $op = $v[0] ?: $v; |
|
| 314 | - } |
|
| 315 | - } else { |
|
| 316 | - $op = $v; |
|
| 317 | - } |
|
| 318 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 319 | - return 'true'; |
|
| 320 | - } |
|
| 321 | - if ($op === '0=1') { |
|
| 322 | - return 'false'; |
|
| 323 | - } |
|
| 324 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 325 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 326 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // 3 possibilites : count($v) = |
|
| 330 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 331 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 332 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 333 | - |
|
| 334 | - // 1 : forcement traite par un critere, on passe |
|
| 335 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 336 | - return null; // sera ignore |
|
| 337 | - } |
|
| 338 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 339 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 340 | - } |
|
| 341 | - if (count($v) == 3) { |
|
| 342 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 343 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 344 | - array_shift($v); |
|
| 345 | - foreach (array_keys($v) as $k) { |
|
| 346 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 347 | - if ($v[$k] === null) { |
|
| 348 | - unset($v[$k]); |
|
| 349 | - } |
|
| 350 | - elseif ($v[$k] === 'true') { |
|
| 351 | - if ($op === 'OR') { |
|
| 352 | - return 'true'; |
|
| 353 | - } |
|
| 354 | - if ($op === 'AND') { |
|
| 355 | - unset($v[$k]); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - elseif ($v[$k] === 'false') { |
|
| 359 | - if ($op === 'OR') { |
|
| 360 | - unset($v[$k]); |
|
| 361 | - } |
|
| 362 | - if ($op === 'AND') { |
|
| 363 | - return 'false'; |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - if (!count($v)) { |
|
| 368 | - return null; |
|
| 369 | - } |
|
| 370 | - if (count($v) === 1) { |
|
| 371 | - return reset($v); |
|
| 372 | - } |
|
| 373 | - array_unshift($v, $op); |
|
| 374 | - return $v; |
|
| 375 | - } |
|
| 376 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return null; // sera ignore |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Calculer un filtre sur un champ du tableau |
|
| 384 | - * @param $cle |
|
| 385 | - * @param $op |
|
| 386 | - * @param $valeur |
|
| 387 | - * @param false $not |
|
| 388 | - * @return string|null |
|
| 389 | - */ |
|
| 390 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 391 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 392 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 393 | - return null; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 397 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 398 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 399 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 400 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 401 | - |
|
| 402 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 403 | - # return; |
|
| 404 | - |
|
| 405 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 406 | - |
|
| 407 | - $filtre = ''; |
|
| 408 | - |
|
| 409 | - if ($op == 'REGEXP') { |
|
| 410 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 411 | - $op = ''; |
|
| 412 | - } else { |
|
| 413 | - if ($op == 'LIKE') { |
|
| 414 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 415 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 416 | - $op = ''; |
|
| 417 | - } else { |
|
| 418 | - if ($op == '=') { |
|
| 419 | - $op = '=='; |
|
| 420 | - } else { |
|
| 421 | - if ($op == 'IN') { |
|
| 422 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 423 | - $op = ''; |
|
| 424 | - } else { |
|
| 425 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 426 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 427 | - $op = ''; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - if ($op) { |
|
| 435 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if ($not) { |
|
| 439 | - $filtre = "!($filtre)"; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $filtre; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - public function next() : void { |
|
| 447 | - $this->pos++; |
|
| 448 | - parent::next(); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * revient au depart |
|
| 453 | - * |
|
| 454 | - * @return void |
|
| 455 | - */ |
|
| 456 | - public function rewind() : void { |
|
| 457 | - $this->pos = 0; |
|
| 458 | - $this->fetched = 0; |
|
| 459 | - parent::rewind(); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - # Extension SPIP des iterateurs PHP |
|
| 464 | - /** |
|
| 465 | - * type de l'iterateur |
|
| 466 | - * |
|
| 467 | - * @var string |
|
| 468 | - */ |
|
| 469 | - protected $type; |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * parametres de l'iterateur |
|
| 473 | - * |
|
| 474 | - * @var array |
|
| 475 | - */ |
|
| 476 | - protected $command; |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * infos de compilateur |
|
| 480 | - * |
|
| 481 | - * @var array |
|
| 482 | - */ |
|
| 483 | - protected $info; |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * position courante de l'iterateur |
|
| 487 | - * |
|
| 488 | - * @var int |
|
| 489 | - */ |
|
| 490 | - protected $pos = null; |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * nombre total resultats dans l'iterateur |
|
| 494 | - * |
|
| 495 | - * @var int |
|
| 496 | - */ |
|
| 497 | - protected $total = null; |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * nombre maximal de recherche pour $total |
|
| 501 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 502 | - */ |
|
| 503 | - protected $max = 100000; |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Liste des champs a inserer dans les $row |
|
| 508 | - * retournes par ->fetch() |
|
| 509 | - */ |
|
| 510 | - protected $select = []; |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * aller a la position absolue n, |
|
| 515 | - * comptee depuis le debut |
|
| 516 | - * |
|
| 517 | - * @param int $n |
|
| 518 | - * absolute pos |
|
| 519 | - * @param string $continue |
|
| 520 | - * param for sql_ api |
|
| 521 | - * @return bool |
|
| 522 | - * success or fail if not implemented |
|
| 523 | - */ |
|
| 524 | - public function seek($n = 0, $continue = null) { |
|
| 525 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 526 | - $this->seek_loop($n); |
|
| 527 | - } |
|
| 528 | - $this->pos = $n; |
|
| 529 | - $this->fetched = $n; |
|
| 530 | - |
|
| 531 | - return true; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /* |
|
| 222 | + // cle et valeur par defaut |
|
| 223 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 224 | + if ( |
|
| 225 | + in_array($nom, ['cle', 'valeur']) |
|
| 226 | + and method_exists($this, $nom) |
|
| 227 | + ) { |
|
| 228 | + return $this->$nom(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Par defaut chercher en xpath dans la valeur() |
|
| 232 | + return table_valeur($this->valeur(), $nom, null); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + private function calculer_filtres() { |
|
| 237 | + |
|
| 238 | + // Issu de calculer_select() de public/composer L.519 |
|
| 239 | + // TODO: externaliser... |
|
| 240 | + // |
|
| 241 | + // retirer les criteres vides: |
|
| 242 | + // {X ?} avec X absent de l'URL |
|
| 243 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 244 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 245 | + if ($where = &$this->command['where']) { |
|
| 246 | + foreach ($where as $k => $v) { |
|
| 247 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // critere {2,7} |
|
| 252 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 253 | + $limit = explode(',', $this->command['limit']); |
|
| 254 | + $this->offset = $limit[0]; |
|
| 255 | + $this->limit = $limit[1]; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // Creer la fonction de filtrage sur $this |
|
| 259 | + if ($this->filtre) { |
|
| 260 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 261 | + $filtres = 'return ' . $filtres . ';'; |
|
| 262 | + $this->func_filtre = function () use ($filtres) { |
|
| 263 | + return eval($filtres); |
|
| 264 | + }; |
|
| 265 | + } |
|
| 266 | + else { |
|
| 267 | + $this->func_filtre = null; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 274 | + * les filtres vides ou null sont ignores |
|
| 275 | + * @param $filtres |
|
| 276 | + * @param string $operateur |
|
| 277 | + * @return string|null |
|
| 278 | + */ |
|
| 279 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 280 | + |
|
| 281 | + $filtres_string = []; |
|
| 282 | + foreach ($filtres as $k => $v) { |
|
| 283 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 284 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 285 | + $op = array_shift($v); |
|
| 286 | + $v = $this->assembler_filtres($v, $op); |
|
| 287 | + } |
|
| 288 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 289 | + continue; |
|
| 290 | + } |
|
| 291 | + $filtres_string[] = $v; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!count($filtres_string)) { |
|
| 295 | + return null; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Traduire un element du tableau where SQL en un filtre |
|
| 303 | + * @param $v |
|
| 304 | + * @return string|array|null |
|
| 305 | + */ |
|
| 306 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 307 | + if (is_array($v)) { |
|
| 308 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 309 | + return 'true'; |
|
| 310 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 311 | + return 'true'; |
|
| 312 | + } else { |
|
| 313 | + $op = $v[0] ?: $v; |
|
| 314 | + } |
|
| 315 | + } else { |
|
| 316 | + $op = $v; |
|
| 317 | + } |
|
| 318 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 319 | + return 'true'; |
|
| 320 | + } |
|
| 321 | + if ($op === '0=1') { |
|
| 322 | + return 'false'; |
|
| 323 | + } |
|
| 324 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 325 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 326 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // 3 possibilites : count($v) = |
|
| 330 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 331 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 332 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 333 | + |
|
| 334 | + // 1 : forcement traite par un critere, on passe |
|
| 335 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 336 | + return null; // sera ignore |
|
| 337 | + } |
|
| 338 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 339 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 340 | + } |
|
| 341 | + if (count($v) == 3) { |
|
| 342 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 343 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 344 | + array_shift($v); |
|
| 345 | + foreach (array_keys($v) as $k) { |
|
| 346 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 347 | + if ($v[$k] === null) { |
|
| 348 | + unset($v[$k]); |
|
| 349 | + } |
|
| 350 | + elseif ($v[$k] === 'true') { |
|
| 351 | + if ($op === 'OR') { |
|
| 352 | + return 'true'; |
|
| 353 | + } |
|
| 354 | + if ($op === 'AND') { |
|
| 355 | + unset($v[$k]); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + elseif ($v[$k] === 'false') { |
|
| 359 | + if ($op === 'OR') { |
|
| 360 | + unset($v[$k]); |
|
| 361 | + } |
|
| 362 | + if ($op === 'AND') { |
|
| 363 | + return 'false'; |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + if (!count($v)) { |
|
| 368 | + return null; |
|
| 369 | + } |
|
| 370 | + if (count($v) === 1) { |
|
| 371 | + return reset($v); |
|
| 372 | + } |
|
| 373 | + array_unshift($v, $op); |
|
| 374 | + return $v; |
|
| 375 | + } |
|
| 376 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return null; // sera ignore |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Calculer un filtre sur un champ du tableau |
|
| 384 | + * @param $cle |
|
| 385 | + * @param $op |
|
| 386 | + * @param $valeur |
|
| 387 | + * @param false $not |
|
| 388 | + * @return string|null |
|
| 389 | + */ |
|
| 390 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 391 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 392 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 393 | + return null; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 397 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 398 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 399 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 400 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 401 | + |
|
| 402 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 403 | + # return; |
|
| 404 | + |
|
| 405 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 406 | + |
|
| 407 | + $filtre = ''; |
|
| 408 | + |
|
| 409 | + if ($op == 'REGEXP') { |
|
| 410 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 411 | + $op = ''; |
|
| 412 | + } else { |
|
| 413 | + if ($op == 'LIKE') { |
|
| 414 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 415 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 416 | + $op = ''; |
|
| 417 | + } else { |
|
| 418 | + if ($op == '=') { |
|
| 419 | + $op = '=='; |
|
| 420 | + } else { |
|
| 421 | + if ($op == 'IN') { |
|
| 422 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 423 | + $op = ''; |
|
| 424 | + } else { |
|
| 425 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 426 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 427 | + $op = ''; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + if ($op) { |
|
| 435 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if ($not) { |
|
| 439 | + $filtre = "!($filtre)"; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $filtre; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + public function next() : void { |
|
| 447 | + $this->pos++; |
|
| 448 | + parent::next(); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * revient au depart |
|
| 453 | + * |
|
| 454 | + * @return void |
|
| 455 | + */ |
|
| 456 | + public function rewind() : void { |
|
| 457 | + $this->pos = 0; |
|
| 458 | + $this->fetched = 0; |
|
| 459 | + parent::rewind(); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + # Extension SPIP des iterateurs PHP |
|
| 464 | + /** |
|
| 465 | + * type de l'iterateur |
|
| 466 | + * |
|
| 467 | + * @var string |
|
| 468 | + */ |
|
| 469 | + protected $type; |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * parametres de l'iterateur |
|
| 473 | + * |
|
| 474 | + * @var array |
|
| 475 | + */ |
|
| 476 | + protected $command; |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * infos de compilateur |
|
| 480 | + * |
|
| 481 | + * @var array |
|
| 482 | + */ |
|
| 483 | + protected $info; |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * position courante de l'iterateur |
|
| 487 | + * |
|
| 488 | + * @var int |
|
| 489 | + */ |
|
| 490 | + protected $pos = null; |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * nombre total resultats dans l'iterateur |
|
| 494 | + * |
|
| 495 | + * @var int |
|
| 496 | + */ |
|
| 497 | + protected $total = null; |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * nombre maximal de recherche pour $total |
|
| 501 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 502 | + */ |
|
| 503 | + protected $max = 100000; |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Liste des champs a inserer dans les $row |
|
| 508 | + * retournes par ->fetch() |
|
| 509 | + */ |
|
| 510 | + protected $select = []; |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * aller a la position absolue n, |
|
| 515 | + * comptee depuis le debut |
|
| 516 | + * |
|
| 517 | + * @param int $n |
|
| 518 | + * absolute pos |
|
| 519 | + * @param string $continue |
|
| 520 | + * param for sql_ api |
|
| 521 | + * @return bool |
|
| 522 | + * success or fail if not implemented |
|
| 523 | + */ |
|
| 524 | + public function seek($n = 0, $continue = null) { |
|
| 525 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 526 | + $this->seek_loop($n); |
|
| 527 | + } |
|
| 528 | + $this->pos = $n; |
|
| 529 | + $this->fetched = $n; |
|
| 530 | + |
|
| 531 | + return true; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /* |
|
| 535 | 535 | * aller a la position $n en parcourant |
| 536 | 536 | * un par un tous les elements |
| 537 | 537 | */ |
| 538 | - private function seek_loop($n) { |
|
| 539 | - if ($this->pos > $n) { |
|
| 540 | - $this->rewind(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - while ($this->pos < $n and $this->valid()) { |
|
| 544 | - $this->next(); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return true; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Avancer de $saut pas |
|
| 552 | - * |
|
| 553 | - * @param $saut |
|
| 554 | - * @param $max |
|
| 555 | - * @return int |
|
| 556 | - */ |
|
| 557 | - public function skip($saut, $max = null) { |
|
| 558 | - // pas de saut en arriere autorise pour cette fonction |
|
| 559 | - if (($saut = intval($saut)) <= 0) { |
|
| 560 | - return $this->pos; |
|
| 561 | - } |
|
| 562 | - $seek = $this->pos + $saut; |
|
| 563 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 564 | - // et on sort |
|
| 565 | - if (is_null($max)) { |
|
| 566 | - $max = $this->count(); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 570 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 571 | - $this->free(); |
|
| 572 | - |
|
| 573 | - return $max; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - $this->seek($seek); |
|
| 577 | - |
|
| 578 | - return $this->pos; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Renvoyer un tableau des donnees correspondantes |
|
| 583 | - * a la position courante de l'iterateur |
|
| 584 | - * en controlant si on respecte le filtre |
|
| 585 | - * Appliquer aussi le critere {offset,limit} |
|
| 586 | - * |
|
| 587 | - * @return array|bool |
|
| 588 | - */ |
|
| 589 | - public function fetch() { |
|
| 590 | - if (method_exists($this->iter, 'fetch')) { |
|
| 591 | - return $this->iter->fetch(); |
|
| 592 | - } else { |
|
| 593 | - while ( |
|
| 594 | - $this->valid() |
|
| 595 | - and ( |
|
| 596 | - !$this->accept() |
|
| 597 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 598 | - ) |
|
| 599 | - ) { |
|
| 600 | - $this->next(); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - if (!$this->valid()) { |
|
| 604 | - return false; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - if ( |
|
| 608 | - isset($this->limit) |
|
| 609 | - and $this->fetched > $this->offset + $this->limit |
|
| 610 | - ) { |
|
| 611 | - return false; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - $r = []; |
|
| 615 | - foreach ($this->select as $nom) { |
|
| 616 | - $r[$nom] = $this->get_select($nom); |
|
| 617 | - } |
|
| 618 | - $this->next(); |
|
| 619 | - |
|
| 620 | - return $r; |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // retourner la cle pour #CLE |
|
| 625 | - public function cle() { |
|
| 626 | - return $this->key(); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - // retourner la valeur pour #VALEUR |
|
| 630 | - public function valeur() { |
|
| 631 | - return $this->current(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Accepte-t-on l'entree courante lue ? |
|
| 636 | - * On execute les filtres pour le savoir. |
|
| 637 | - **/ |
|
| 638 | - public function accept(): bool { |
|
| 639 | - if ($f = $this->func_filtre) { |
|
| 640 | - return $f(); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - return true; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * liberer la ressource |
|
| 648 | - * |
|
| 649 | - * @return bool |
|
| 650 | - */ |
|
| 651 | - public function free() { |
|
| 652 | - if (method_exists($this->iter, 'free')) { |
|
| 653 | - $this->iter->free(); |
|
| 654 | - } |
|
| 655 | - $this->pos = $this->total = 0; |
|
| 656 | - |
|
| 657 | - return true; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Compter le nombre total de resultats |
|
| 662 | - * pour #TOTAL_BOUCLE |
|
| 663 | - * |
|
| 664 | - * @return int |
|
| 665 | - */ |
|
| 666 | - public function count() { |
|
| 667 | - if (is_null($this->total)) { |
|
| 668 | - if ( |
|
| 669 | - method_exists($this->iter, 'count') |
|
| 670 | - and !$this->func_filtre |
|
| 671 | - ) { |
|
| 672 | - return $this->total = $this->iter->count(); |
|
| 673 | - } else { |
|
| 674 | - // compter les lignes et rembobiner |
|
| 675 | - $total = 0; |
|
| 676 | - $pos = $this->pos; // sauver la position |
|
| 677 | - $this->rewind(); |
|
| 678 | - while ($this->fetch() and $total < $this->max) { |
|
| 679 | - $total++; |
|
| 680 | - } |
|
| 681 | - $this->seek($pos); |
|
| 682 | - $this->total = $total; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return $this->total; |
|
| 687 | - } |
|
| 538 | + private function seek_loop($n) { |
|
| 539 | + if ($this->pos > $n) { |
|
| 540 | + $this->rewind(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + while ($this->pos < $n and $this->valid()) { |
|
| 544 | + $this->next(); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return true; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Avancer de $saut pas |
|
| 552 | + * |
|
| 553 | + * @param $saut |
|
| 554 | + * @param $max |
|
| 555 | + * @return int |
|
| 556 | + */ |
|
| 557 | + public function skip($saut, $max = null) { |
|
| 558 | + // pas de saut en arriere autorise pour cette fonction |
|
| 559 | + if (($saut = intval($saut)) <= 0) { |
|
| 560 | + return $this->pos; |
|
| 561 | + } |
|
| 562 | + $seek = $this->pos + $saut; |
|
| 563 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 564 | + // et on sort |
|
| 565 | + if (is_null($max)) { |
|
| 566 | + $max = $this->count(); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 570 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 571 | + $this->free(); |
|
| 572 | + |
|
| 573 | + return $max; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + $this->seek($seek); |
|
| 577 | + |
|
| 578 | + return $this->pos; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Renvoyer un tableau des donnees correspondantes |
|
| 583 | + * a la position courante de l'iterateur |
|
| 584 | + * en controlant si on respecte le filtre |
|
| 585 | + * Appliquer aussi le critere {offset,limit} |
|
| 586 | + * |
|
| 587 | + * @return array|bool |
|
| 588 | + */ |
|
| 589 | + public function fetch() { |
|
| 590 | + if (method_exists($this->iter, 'fetch')) { |
|
| 591 | + return $this->iter->fetch(); |
|
| 592 | + } else { |
|
| 593 | + while ( |
|
| 594 | + $this->valid() |
|
| 595 | + and ( |
|
| 596 | + !$this->accept() |
|
| 597 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 598 | + ) |
|
| 599 | + ) { |
|
| 600 | + $this->next(); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + if (!$this->valid()) { |
|
| 604 | + return false; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + if ( |
|
| 608 | + isset($this->limit) |
|
| 609 | + and $this->fetched > $this->offset + $this->limit |
|
| 610 | + ) { |
|
| 611 | + return false; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + $r = []; |
|
| 615 | + foreach ($this->select as $nom) { |
|
| 616 | + $r[$nom] = $this->get_select($nom); |
|
| 617 | + } |
|
| 618 | + $this->next(); |
|
| 619 | + |
|
| 620 | + return $r; |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // retourner la cle pour #CLE |
|
| 625 | + public function cle() { |
|
| 626 | + return $this->key(); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + // retourner la valeur pour #VALEUR |
|
| 630 | + public function valeur() { |
|
| 631 | + return $this->current(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Accepte-t-on l'entree courante lue ? |
|
| 636 | + * On execute les filtres pour le savoir. |
|
| 637 | + **/ |
|
| 638 | + public function accept(): bool { |
|
| 639 | + if ($f = $this->func_filtre) { |
|
| 640 | + return $f(); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + return true; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * liberer la ressource |
|
| 648 | + * |
|
| 649 | + * @return bool |
|
| 650 | + */ |
|
| 651 | + public function free() { |
|
| 652 | + if (method_exists($this->iter, 'free')) { |
|
| 653 | + $this->iter->free(); |
|
| 654 | + } |
|
| 655 | + $this->pos = $this->total = 0; |
|
| 656 | + |
|
| 657 | + return true; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Compter le nombre total de resultats |
|
| 662 | + * pour #TOTAL_BOUCLE |
|
| 663 | + * |
|
| 664 | + * @return int |
|
| 665 | + */ |
|
| 666 | + public function count() { |
|
| 667 | + if (is_null($this->total)) { |
|
| 668 | + if ( |
|
| 669 | + method_exists($this->iter, 'count') |
|
| 670 | + and !$this->func_filtre |
|
| 671 | + ) { |
|
| 672 | + return $this->total = $this->iter->count(); |
|
| 673 | + } else { |
|
| 674 | + // compter les lignes et rembobiner |
|
| 675 | + $total = 0; |
|
| 676 | + $pos = $this->pos; // sauver la position |
|
| 677 | + $this->rewind(); |
|
| 678 | + while ($this->fetch() and $total < $this->max) { |
|
| 679 | + $total++; |
|
| 680 | + } |
|
| 681 | + $this->seek($pos); |
|
| 682 | + $this->total = $total; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return $this->total; |
|
| 687 | + } |
|
| 688 | 688 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - list($id_rubrique, $lang) = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + list($id_rubrique, $lang) = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |