@@ -235,6 +235,9 @@ |
||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | +/** |
|
| 239 | + * @param string $hidden |
|
| 240 | + */ |
|
| 238 | 241 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | 242 | return info_progression_etape(3, 'etape_', 'install/') . |
| 240 | 243 | info_etape( |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
| 48 | 48 | |
| 49 | 49 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 50 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 50 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 51 | 51 | |
| 52 | 52 | $fquery = sql_serveur('query', $server_db); |
| 53 | 53 | if ($choix_db == 'new_spip') { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | if (!$ok) { |
| 58 | 58 | $re = "Impossible de creer la base $re"; |
| 59 | 59 | spip_log($re); |
| 60 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 60 | + return '<p>'._T('avis_connexion_erreur_creer_base')."</p><!--\n$re\n-->"; |
|
| 61 | 61 | } |
| 62 | 62 | } else { |
| 63 | 63 | $re = "Le nom de la base doit correspondre a $re"; |
| 64 | 64 | spip_log($re); |
| 65 | 65 | |
| 66 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 66 | + return '<p>'._T('avis_connexion_erreur_nom_base')."</p><!--\n$re\n-->"; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
| 75 | 75 | |
| 76 | 76 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 77 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 77 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 78 | 78 | |
| 79 | 79 | // Completer le tableau decrivant la connexion |
| 80 | 80 | |
| 81 | 81 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 82 | 82 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 83 | 83 | |
| 84 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 84 | + $old = sql_showbase($table_prefix.'_meta', $server_db); |
|
| 85 | 85 | if ($old) { |
| 86 | 86 | $old = sql_fetch($old, $server_db); |
| 87 | 87 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $charset['charset']; |
| 101 | 101 | $charsetbase = $charset['charset']; |
| 102 | 102 | } else { |
| 103 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 103 | + spip_log(_DEFAULT_CHARSET.' inconnu du serveur SQL'); |
|
| 104 | 104 | $charsetbase = 'standard'; |
| 105 | 105 | } |
| 106 | 106 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | if ($r) { |
| 151 | 151 | $r = sql_fetch($r, $server_db); |
| 152 | 152 | } |
| 153 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 153 | + $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 154 | 154 | if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
| 155 | 155 | $fupdateq( |
| 156 | 156 | 'spip_meta', |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | '', |
| 160 | 160 | $server_db |
| 161 | 161 | ); |
| 162 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 162 | + spip_log('nouvelle version installee: '.$GLOBALS['spip_version_base']); |
|
| 163 | 163 | } |
| 164 | 164 | // eliminer la derniere operation d'admin mal terminee |
| 165 | 165 | // notamment la mise a jour |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if ($chmod_db) { |
| 187 | 187 | install_fichier_connexion( |
| 188 | 188 | _FILE_CHMOD_TMP, |
| 189 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 189 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n" |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -236,16 +236,16 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | 238 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 239 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 240 | 240 | info_etape( |
| 241 | 241 | _T('info_informations_personnelles'), |
| 242 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 243 | - aider('install5', true) . |
|
| 244 | - '<p>' . |
|
| 242 | + '<b>'._T('texte_informations_personnelles_1').'</b>'. |
|
| 243 | + aider('install5', true). |
|
| 244 | + '<p>'. |
|
| 245 | 245 | ($auteur_obligatoire ? |
| 246 | 246 | '' |
| 247 | 247 | : |
| 248 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 248 | + _T('texte_informations_personnelles_2').' '._T('info_laisser_champs_vides') |
|
| 249 | 249 | ) |
| 250 | 250 | ) |
| 251 | 251 | . generer_form_ecrire('install', ( |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | _T('info_identification_publique'), |
| 256 | 256 | array( |
| 257 | 257 | 'nom' => array( |
| 258 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 258 | + 'label' => '<b>'._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 259 | 259 | 'valeur' => $nom, |
| 260 | 260 | 'required' => $auteur_obligatoire, |
| 261 | 261 | ), |
| 262 | 262 | 'email' => array( |
| 263 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 263 | + 'label' => '<b>'._T('entree_adresse_email')."</b>\n", |
|
| 264 | 264 | 'valeur' => $email, |
| 265 | 265 | ) |
| 266 | 266 | ) |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | _T('entree_identifiants_connexion'), |
| 271 | 271 | array( |
| 272 | 272 | 'login' => array( |
| 273 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 273 | + 'label' => '<b>'._T('entree_login')."</b><br />\n"._T( |
|
| 274 | 274 | 'info_login_trop_court_car_pluriel', |
| 275 | 275 | array('nb' => _LOGIN_TROP_COURT) |
| 276 | - ) . "\n", |
|
| 276 | + )."\n", |
|
| 277 | 277 | 'valeur' => $login, |
| 278 | 278 | 'required' => $auteur_obligatoire, |
| 279 | 279 | ), |
| 280 | 280 | 'pass' => array( |
| 281 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 281 | + 'label' => '<b>'._T('entree_mot_passe')."</b><br />\n"._T( |
|
| 282 | 282 | 'info_passe_trop_court_car_pluriel', |
| 283 | 283 | array('nb' => _PASS_LONGUEUR_MINI) |
| 284 | - ) . "\n", |
|
| 284 | + )."\n", |
|
| 285 | 285 | 'valeur' => $pass, |
| 286 | 286 | 'required' => $auteur_obligatoire, |
| 287 | 287 | ), |
| 288 | 288 | 'pass_verif' => array( |
| 289 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 289 | + 'label' => '<b>'._T('info_confirmer_passe')."</b><br />\n", |
|
| 290 | 290 | 'valeur' => $pass, |
| 291 | 291 | 'required' => $auteur_obligatoire, |
| 292 | 292 | ) |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | if ($res) { |
| 333 | 333 | $res = info_progression_etape(2, 'etape_', 'install/', true) |
| 334 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 334 | + . "<div class='error'><h3>"._T('avis_operation_echec').'</h3>' |
|
| 335 | 335 | . $res |
| 336 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 336 | + . '<p>'._T('texte_operation_echec').'</p>' |
|
| 337 | 337 | . '</div>'; |
| 338 | 338 | } |
| 339 | 339 | } else { |
@@ -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('inc/headers'); |
@@ -20,199 +20,199 @@ discard block |
||
| 20 | 20 | // http://code.spip.net/@install_bases |
| 21 | 21 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 22 | 22 | |
| 23 | - // Prefix des tables : |
|
| 24 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | - // a partir de ce qui est envoye a l'installation |
|
| 26 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | - ? $GLOBALS['table_prefix'] |
|
| 29 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | - // S'il est vide on remet spip |
|
| 31 | - if (!$table_prefix) { |
|
| 32 | - $table_prefix = 'spip'; |
|
| 33 | - } |
|
| 34 | - } else { |
|
| 35 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | - list(, $adresse_db, $port) = $r; |
|
| 40 | - } else { |
|
| 41 | - $port = ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $GLOBALS['connexions'][$server_db] |
|
| 45 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | - |
|
| 47 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | - |
|
| 50 | - $fquery = sql_serveur('query', $server_db); |
|
| 51 | - if ($choix_db == 'new_spip') { |
|
| 52 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | - if (preg_match($re, $sel_db)) { |
|
| 54 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | - if (!$ok) { |
|
| 56 | - $re = "Impossible de creer la base $re"; |
|
| 57 | - spip_log($re); |
|
| 58 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | - } |
|
| 60 | - } else { |
|
| 61 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | - spip_log($re); |
|
| 63 | - |
|
| 64 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | - // un sql_mode |
|
| 70 | - install_mode_appel($server_db, false); |
|
| 71 | - $GLOBALS['connexions'][$server_db] |
|
| 72 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | - |
|
| 74 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | - |
|
| 77 | - // Completer le tableau decrivant la connexion |
|
| 78 | - |
|
| 79 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | - |
|
| 82 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | - if ($old) { |
|
| 84 | - $old = sql_fetch($old, $server_db); |
|
| 85 | - } |
|
| 86 | - if (!$old) { |
|
| 87 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | - // dans le codage std de SPIP, |
|
| 89 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | - |
|
| 91 | - if ($charset) { |
|
| 92 | - sql_set_charset($charset['charset'], $server_db); |
|
| 93 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | - $charset['charset']; |
|
| 95 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | - $charset['collation']; |
|
| 97 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | - $charset['charset']; |
|
| 99 | - $charsetbase = $charset['charset']; |
|
| 100 | - } else { |
|
| 101 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | - $charsetbase = 'standard'; |
|
| 103 | - } |
|
| 104 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | - creer_base($server_db); // AT LAST |
|
| 106 | - // memoriser avec quel charset on l'a creee |
|
| 107 | - |
|
| 108 | - if ($charset) { |
|
| 109 | - $t = array( |
|
| 110 | - 'nom' => 'charset_sql_base', |
|
| 111 | - 'valeur' => $charset['charset'], |
|
| 112 | - 'impt' => 'non' |
|
| 113 | - ); |
|
| 114 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | - $t['valeur'] = $charset['collation']; |
|
| 117 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | - $t['valeur'] = $charset['charset']; |
|
| 120 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | - } |
|
| 122 | - $t = array( |
|
| 123 | - 'nom' => 'version_installee', |
|
| 124 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | - 'impt' => 'non' |
|
| 126 | - ); |
|
| 127 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | - $t['nom'] = 'nouvelle_install'; |
|
| 129 | - $t['valeur'] = 1; |
|
| 130 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | - @sql_insertq( |
|
| 134 | - 'spip_meta', |
|
| 135 | - array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | - '', |
|
| 137 | - $server_db |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - // pour recreer les tables disparues au besoin |
|
| 142 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | - creer_base($server_db); |
|
| 144 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | - |
|
| 146 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | - |
|
| 148 | - if ($r) { |
|
| 149 | - $r = sql_fetch($r, $server_db); |
|
| 150 | - } |
|
| 151 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | - $fupdateq( |
|
| 154 | - 'spip_meta', |
|
| 155 | - array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | - "nom='version_installee'", |
|
| 157 | - '', |
|
| 158 | - $server_db |
|
| 159 | - ); |
|
| 160 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | - } |
|
| 162 | - // eliminer la derniere operation d'admin mal terminee |
|
| 163 | - // notamment la mise a jour |
|
| 164 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // recuperer le charset de la connexion dans les meta |
|
| 168 | - $charset = ''; |
|
| 169 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | - if ($r) { |
|
| 171 | - $r = sql_fetch($r, $server_db); |
|
| 172 | - } |
|
| 173 | - if ($r) { |
|
| 174 | - $charset = $r['valeur']; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | - |
|
| 179 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | - if (!$result_ok) { |
|
| 181 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($chmod_db) { |
|
| 185 | - install_fichier_connexion( |
|
| 186 | - _FILE_CHMOD_TMP, |
|
| 187 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | - |
|
| 195 | - if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | - spip_unlink(_FILE_CONNECT); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - install_fichier_connexion( |
|
| 200 | - _FILE_CONNECT_TMP, |
|
| 201 | - $ligne_rappel |
|
| 202 | - . install_connexion( |
|
| 203 | - $adresse_db, |
|
| 204 | - $port, |
|
| 205 | - $login_db, |
|
| 206 | - $pass_db, |
|
| 207 | - $sel_db, |
|
| 208 | - $server_db, |
|
| 209 | - $table_prefix, |
|
| 210 | - '', |
|
| 211 | - $charset |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 23 | + // Prefix des tables : |
|
| 24 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | + // a partir de ce qui est envoye a l'installation |
|
| 26 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | + ? $GLOBALS['table_prefix'] |
|
| 29 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | + // S'il est vide on remet spip |
|
| 31 | + if (!$table_prefix) { |
|
| 32 | + $table_prefix = 'spip'; |
|
| 33 | + } |
|
| 34 | + } else { |
|
| 35 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | + list(, $adresse_db, $port) = $r; |
|
| 40 | + } else { |
|
| 41 | + $port = ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $GLOBALS['connexions'][$server_db] |
|
| 45 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | + |
|
| 47 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | + |
|
| 50 | + $fquery = sql_serveur('query', $server_db); |
|
| 51 | + if ($choix_db == 'new_spip') { |
|
| 52 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | + if (preg_match($re, $sel_db)) { |
|
| 54 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | + if (!$ok) { |
|
| 56 | + $re = "Impossible de creer la base $re"; |
|
| 57 | + spip_log($re); |
|
| 58 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | + } |
|
| 60 | + } else { |
|
| 61 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | + spip_log($re); |
|
| 63 | + |
|
| 64 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | + // un sql_mode |
|
| 70 | + install_mode_appel($server_db, false); |
|
| 71 | + $GLOBALS['connexions'][$server_db] |
|
| 72 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | + |
|
| 74 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | + |
|
| 77 | + // Completer le tableau decrivant la connexion |
|
| 78 | + |
|
| 79 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | + |
|
| 82 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | + if ($old) { |
|
| 84 | + $old = sql_fetch($old, $server_db); |
|
| 85 | + } |
|
| 86 | + if (!$old) { |
|
| 87 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | + // dans le codage std de SPIP, |
|
| 89 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | + |
|
| 91 | + if ($charset) { |
|
| 92 | + sql_set_charset($charset['charset'], $server_db); |
|
| 93 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | + $charset['charset']; |
|
| 95 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | + $charset['collation']; |
|
| 97 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | + $charset['charset']; |
|
| 99 | + $charsetbase = $charset['charset']; |
|
| 100 | + } else { |
|
| 101 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | + $charsetbase = 'standard'; |
|
| 103 | + } |
|
| 104 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | + creer_base($server_db); // AT LAST |
|
| 106 | + // memoriser avec quel charset on l'a creee |
|
| 107 | + |
|
| 108 | + if ($charset) { |
|
| 109 | + $t = array( |
|
| 110 | + 'nom' => 'charset_sql_base', |
|
| 111 | + 'valeur' => $charset['charset'], |
|
| 112 | + 'impt' => 'non' |
|
| 113 | + ); |
|
| 114 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | + $t['valeur'] = $charset['collation']; |
|
| 117 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | + $t['valeur'] = $charset['charset']; |
|
| 120 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | + } |
|
| 122 | + $t = array( |
|
| 123 | + 'nom' => 'version_installee', |
|
| 124 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | + 'impt' => 'non' |
|
| 126 | + ); |
|
| 127 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | + $t['nom'] = 'nouvelle_install'; |
|
| 129 | + $t['valeur'] = 1; |
|
| 130 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | + @sql_insertq( |
|
| 134 | + 'spip_meta', |
|
| 135 | + array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | + '', |
|
| 137 | + $server_db |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + // pour recreer les tables disparues au besoin |
|
| 142 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | + creer_base($server_db); |
|
| 144 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | + |
|
| 146 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | + |
|
| 148 | + if ($r) { |
|
| 149 | + $r = sql_fetch($r, $server_db); |
|
| 150 | + } |
|
| 151 | + $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | + $fupdateq( |
|
| 154 | + 'spip_meta', |
|
| 155 | + array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | + "nom='version_installee'", |
|
| 157 | + '', |
|
| 158 | + $server_db |
|
| 159 | + ); |
|
| 160 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | + } |
|
| 162 | + // eliminer la derniere operation d'admin mal terminee |
|
| 163 | + // notamment la mise a jour |
|
| 164 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // recuperer le charset de la connexion dans les meta |
|
| 168 | + $charset = ''; |
|
| 169 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | + if ($r) { |
|
| 171 | + $r = sql_fetch($r, $server_db); |
|
| 172 | + } |
|
| 173 | + if ($r) { |
|
| 174 | + $charset = $r['valeur']; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | + |
|
| 179 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | + if (!$result_ok) { |
|
| 181 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($chmod_db) { |
|
| 185 | + install_fichier_connexion( |
|
| 186 | + _FILE_CHMOD_TMP, |
|
| 187 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | + |
|
| 195 | + if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | + spip_unlink(_FILE_CONNECT); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + install_fichier_connexion( |
|
| 200 | + _FILE_CONNECT_TMP, |
|
| 201 | + $ligne_rappel |
|
| 202 | + . install_connexion( |
|
| 203 | + $adresse_db, |
|
| 204 | + $port, |
|
| 205 | + $login_db, |
|
| 206 | + $pass_db, |
|
| 207 | + $sel_db, |
|
| 208 | + $server_db, |
|
| 209 | + $table_prefix, |
|
| 210 | + '', |
|
| 211 | + $charset |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,169 +227,169 @@ discard block |
||
| 227 | 227 | * @return string Le préfixe corrigé |
| 228 | 228 | */ |
| 229 | 229 | function preparer_prefixe_tables($prefixe) { |
| 230 | - return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 230 | + return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // http://code.spip.net/@install_propose_ldap |
| 234 | 234 | function install_propose_ldap() { |
| 235 | - return generer_form_ecrire('install', ( |
|
| 236 | - fieldset( |
|
| 237 | - _T('info_authentification_externe'), |
|
| 238 | - array( |
|
| 239 | - 'etape' => array( |
|
| 240 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | - 'valeur' => 'ldap1', |
|
| 242 | - 'hidden' => true |
|
| 243 | - ) |
|
| 244 | - ), |
|
| 245 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | - ))); |
|
| 235 | + return generer_form_ecrire('install', ( |
|
| 236 | + fieldset( |
|
| 237 | + _T('info_authentification_externe'), |
|
| 238 | + array( |
|
| 239 | + 'etape' => array( |
|
| 240 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | + 'valeur' => 'ldap1', |
|
| 242 | + 'hidden' => true |
|
| 243 | + ) |
|
| 244 | + ), |
|
| 245 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | + ))); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
| 250 | 250 | // http://code.spip.net/@install_premier_auteur |
| 251 | 251 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 252 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | - info_etape( |
|
| 254 | - _T('info_informations_personnelles'), |
|
| 255 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | - aider('install5', true) . |
|
| 257 | - '<p>' . |
|
| 258 | - ($auteur_obligatoire ? |
|
| 259 | - '' |
|
| 260 | - : |
|
| 261 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | - ) |
|
| 263 | - ) |
|
| 264 | - . generer_form_ecrire('install', ( |
|
| 265 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | - . $hidden |
|
| 267 | - . fieldset( |
|
| 268 | - _T('info_identification_publique'), |
|
| 269 | - array( |
|
| 270 | - 'nom' => array( |
|
| 271 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | - 'valeur' => $nom, |
|
| 273 | - 'required' => $auteur_obligatoire, |
|
| 274 | - ), |
|
| 275 | - 'email' => array( |
|
| 276 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | - 'valeur' => $email, |
|
| 278 | - ) |
|
| 279 | - ) |
|
| 280 | - ) |
|
| 281 | - |
|
| 282 | - . fieldset( |
|
| 283 | - _T('entree_identifiants_connexion'), |
|
| 284 | - array( |
|
| 285 | - 'login' => array( |
|
| 286 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | - 'info_login_trop_court_car_pluriel', |
|
| 288 | - array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | - ) . "\n", |
|
| 290 | - 'valeur' => $login, |
|
| 291 | - 'required' => $auteur_obligatoire, |
|
| 292 | - ), |
|
| 293 | - 'pass' => array( |
|
| 294 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | - 'info_passe_trop_court_car_pluriel', |
|
| 296 | - array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | - ) . "\n", |
|
| 298 | - 'valeur' => $pass, |
|
| 299 | - 'required' => $auteur_obligatoire, |
|
| 300 | - ), |
|
| 301 | - 'pass_verif' => array( |
|
| 302 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | - 'valeur' => $pass, |
|
| 304 | - 'required' => $auteur_obligatoire, |
|
| 305 | - ) |
|
| 306 | - ) |
|
| 307 | - ) |
|
| 308 | - . bouton_suivant())); |
|
| 252 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | + info_etape( |
|
| 254 | + _T('info_informations_personnelles'), |
|
| 255 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | + aider('install5', true) . |
|
| 257 | + '<p>' . |
|
| 258 | + ($auteur_obligatoire ? |
|
| 259 | + '' |
|
| 260 | + : |
|
| 261 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | + ) |
|
| 263 | + ) |
|
| 264 | + . generer_form_ecrire('install', ( |
|
| 265 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | + . $hidden |
|
| 267 | + . fieldset( |
|
| 268 | + _T('info_identification_publique'), |
|
| 269 | + array( |
|
| 270 | + 'nom' => array( |
|
| 271 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | + 'valeur' => $nom, |
|
| 273 | + 'required' => $auteur_obligatoire, |
|
| 274 | + ), |
|
| 275 | + 'email' => array( |
|
| 276 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | + 'valeur' => $email, |
|
| 278 | + ) |
|
| 279 | + ) |
|
| 280 | + ) |
|
| 281 | + |
|
| 282 | + . fieldset( |
|
| 283 | + _T('entree_identifiants_connexion'), |
|
| 284 | + array( |
|
| 285 | + 'login' => array( |
|
| 286 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | + 'info_login_trop_court_car_pluriel', |
|
| 288 | + array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | + ) . "\n", |
|
| 290 | + 'valeur' => $login, |
|
| 291 | + 'required' => $auteur_obligatoire, |
|
| 292 | + ), |
|
| 293 | + 'pass' => array( |
|
| 294 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | + 'info_passe_trop_court_car_pluriel', |
|
| 296 | + array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | + ) . "\n", |
|
| 298 | + 'valeur' => $pass, |
|
| 299 | + 'required' => $auteur_obligatoire, |
|
| 300 | + ), |
|
| 301 | + 'pass_verif' => array( |
|
| 302 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | + 'valeur' => $pass, |
|
| 304 | + 'required' => $auteur_obligatoire, |
|
| 305 | + ) |
|
| 306 | + ) |
|
| 307 | + ) |
|
| 308 | + . bouton_suivant())); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // http://code.spip.net/@install_etape_3_dist |
| 312 | 312 | function install_etape_3_dist() { |
| 313 | - $ldap_present = _request('ldap_present'); |
|
| 314 | - |
|
| 315 | - if (!$ldap_present) { |
|
| 316 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | - ? _INSTALL_HOST_DB |
|
| 318 | - : _request('adresse_db'); |
|
| 319 | - |
|
| 320 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | - ? _INSTALL_USER_DB |
|
| 322 | - : _request('login_db'); |
|
| 323 | - |
|
| 324 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | - ? _INSTALL_PASS_DB |
|
| 326 | - : _request('pass_db'); |
|
| 327 | - |
|
| 328 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | - ? _INSTALL_SERVER_DB |
|
| 330 | - : _request('server_db'); |
|
| 331 | - |
|
| 332 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | - ? _SPIP_CHMOD |
|
| 334 | - : _request('chmod'); |
|
| 335 | - |
|
| 336 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | - ? _INSTALL_NAME_DB |
|
| 338 | - : _request('choix_db'); |
|
| 339 | - |
|
| 340 | - $sel_db = ($choix_db == 'new_spip') |
|
| 341 | - ? _request('table_new') : $choix_db; |
|
| 342 | - |
|
| 343 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | - |
|
| 345 | - if ($res) { |
|
| 346 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | - . $res |
|
| 349 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | - . '</div>'; |
|
| 351 | - } |
|
| 352 | - } else { |
|
| 353 | - $res = ''; |
|
| 354 | - list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if (!$res) { |
|
| 359 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | - include(_FILE_CONNECT_TMP); |
|
| 361 | - } else { |
|
| 362 | - redirige_url_ecrire('install'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | - include(_FILE_CHMOD_TMP); |
|
| 367 | - } else { |
|
| 368 | - redirige_url_ecrire('install'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | - : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | - |
|
| 375 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | - |
|
| 377 | - $res = "<div class='success'><b>" |
|
| 378 | - . _T('info_base_installee') |
|
| 379 | - . '</b></div>' |
|
| 380 | - . install_premier_auteur( |
|
| 381 | - _request('email'), |
|
| 382 | - _request('login'), |
|
| 383 | - _request('nom'), |
|
| 384 | - _request('pass'), |
|
| 385 | - $hidden, |
|
| 386 | - $auteur_obligatoire |
|
| 387 | - ) |
|
| 388 | - . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | - ? '' : install_propose_ldap()); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - echo install_debut_html(); |
|
| 393 | - echo $res; |
|
| 394 | - echo install_fin_html(); |
|
| 313 | + $ldap_present = _request('ldap_present'); |
|
| 314 | + |
|
| 315 | + if (!$ldap_present) { |
|
| 316 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | + ? _INSTALL_HOST_DB |
|
| 318 | + : _request('adresse_db'); |
|
| 319 | + |
|
| 320 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | + ? _INSTALL_USER_DB |
|
| 322 | + : _request('login_db'); |
|
| 323 | + |
|
| 324 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | + ? _INSTALL_PASS_DB |
|
| 326 | + : _request('pass_db'); |
|
| 327 | + |
|
| 328 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | + ? _INSTALL_SERVER_DB |
|
| 330 | + : _request('server_db'); |
|
| 331 | + |
|
| 332 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | + ? _SPIP_CHMOD |
|
| 334 | + : _request('chmod'); |
|
| 335 | + |
|
| 336 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | + ? _INSTALL_NAME_DB |
|
| 338 | + : _request('choix_db'); |
|
| 339 | + |
|
| 340 | + $sel_db = ($choix_db == 'new_spip') |
|
| 341 | + ? _request('table_new') : $choix_db; |
|
| 342 | + |
|
| 343 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | + |
|
| 345 | + if ($res) { |
|
| 346 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | + . $res |
|
| 349 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | + . '</div>'; |
|
| 351 | + } |
|
| 352 | + } else { |
|
| 353 | + $res = ''; |
|
| 354 | + list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if (!$res) { |
|
| 359 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | + include(_FILE_CONNECT_TMP); |
|
| 361 | + } else { |
|
| 362 | + redirige_url_ecrire('install'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | + include(_FILE_CHMOD_TMP); |
|
| 367 | + } else { |
|
| 368 | + redirige_url_ecrire('install'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | + : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | + |
|
| 375 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | + |
|
| 377 | + $res = "<div class='success'><b>" |
|
| 378 | + . _T('info_base_installee') |
|
| 379 | + . '</b></div>' |
|
| 380 | + . install_premier_auteur( |
|
| 381 | + _request('email'), |
|
| 382 | + _request('login'), |
|
| 383 | + _request('nom'), |
|
| 384 | + _request('pass'), |
|
| 385 | + $hidden, |
|
| 386 | + $auteur_obligatoire |
|
| 387 | + ) |
|
| 388 | + . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | + ? '' : install_propose_ldap()); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + echo install_debut_html(); |
|
| 393 | + echo $res; |
|
| 394 | + echo install_fin_html(); |
|
| 395 | 395 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * Déclarer les critères exceptions |
| 135 | 135 | * |
| 136 | - * @return array |
|
| 136 | + * @return string[] |
|
| 137 | 137 | */ |
| 138 | 138 | public function exception_des_criteres() { |
| 139 | 139 | return array('tableau'); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * pour la syntaxe cf la fonction spip preg_files |
| 788 | 788 | * |
| 789 | 789 | * @param string $dir |
| 790 | - * @param string $regexp |
|
| 790 | + * @param integer $regexp |
|
| 791 | 791 | * @param int $limit |
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | /** |
| 827 | 827 | * Object -> tableau |
| 828 | 828 | * |
| 829 | - * @param Object $object |
|
| 829 | + * @param SimpleXMLIterator $object |
|
| 830 | 830 | * @return array|bool |
| 831 | 831 | */ |
| 832 | 832 | function XMLObjectToArray($object) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // Si a ce stade on n'a pas de table, il y a un bug |
| 232 | 232 | if (!is_array($this->tableau)) { |
| 233 | 233 | $this->err = true; |
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 234 | + spip_log("erreur datasource ".var_export($command, true)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // {datapath query.results} |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($this->command['sourcemode']) |
| 272 | 272 | and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
| 273 | 273 | ) { |
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 274 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | # le premier argument peut etre un array, une URL etc. |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | # avons-nous un cache dispo ? |
| 281 | 281 | $cle = null; |
| 282 | 282 | if (is_string($src)) { |
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 283 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $cache = $this->cache_get($cle); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | if (!$this->err |
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 351 | 351 | ) { |
| 352 | 352 | $args = $this->command['source']; |
| 353 | 353 | $args[0] = $u; |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | $tv = '%s'; |
| 483 | 483 | } # {par valeur/xx/yy} ?? |
| 484 | 484 | else { |
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 485 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 486 | 486 | } |
| 487 | 487 | $sortfunc .= ' |
| 488 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 489 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 488 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 489 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 490 | 490 | if ($a <> $b) |
| 491 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 491 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | 643 | define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT.urlencode($u).'&format=json'); |
|
| 645 | 645 | if (!$v['page'] |
| 646 | 646 | or !$w = json_decode($v['page'], true) |
| 647 | 647 | ) { |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | 664 | # sortir le connecteur de $u |
| 665 | 665 | preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
| 666 | - $serveur = (string)$v[1]; |
|
| 666 | + $serveur = (string) $v[1]; |
|
| 667 | 667 | $req = trim($v[2]); |
| 668 | 668 | if ($s = sql_query($req, $serveur)) { |
| 669 | 669 | $r = array(); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | if (is_array($json = json_decode($u)) |
| 688 | 688 | or is_object($json) |
| 689 | 689 | ) { |
| 690 | - return (array)$json; |
|
| 690 | + return (array) $json; |
|
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | |
@@ -706,13 +706,13 @@ discard block |
||
| 706 | 706 | $i = 1; |
| 707 | 707 | foreach ($entete as $k => $v) { |
| 708 | 708 | if (trim($v) == "") { |
| 709 | - $v = "col" . $i; |
|
| 709 | + $v = "col".$i; |
|
| 710 | 710 | } // reperer des eventuelles cases vides |
| 711 | 711 | if (is_numeric($v) and $v < 0) { |
| 712 | - $v = "__" . $v; |
|
| 712 | + $v = "__".$v; |
|
| 713 | 713 | } // ne pas risquer d'ecraser une cle numerique |
| 714 | 714 | if (is_numeric($v)) { |
| 715 | - $v = "_" . $v; |
|
| 715 | + $v = "_".$v; |
|
| 716 | 716 | } // ne pas risquer d'ecraser une cle numerique |
| 717 | 717 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 718 | 718 | foreach ($csv as &$item) { |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | $glob = charger_fonction('glob_to_array', 'inc'); |
| 812 | 812 | $a = $glob($u); |
| 813 | 813 | foreach ($a as &$v) { |
| 814 | - $b = (array)@stat($v); |
|
| 814 | + $b = (array) @stat($v); |
|
| 815 | 815 | foreach ($b as $k => $ignore) { |
| 816 | 816 | if (is_numeric($k)) { |
| 817 | 817 | unset($b[$k]); |
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 820 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 821 | 821 | $v = array_merge( |
| 822 | 822 | pathinfo($v), |
| 823 | 823 | $b |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | $xml_array = array(); |
| 838 | 838 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 839 | 839 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 840 | - $key .= '-' . uniqid(); |
|
| 840 | + $key .= '-'.uniqid(); |
|
| 841 | 841 | } |
| 842 | 842 | $vars = get_object_vars($object->current()); |
| 843 | 843 | if (isset($vars['@attributes'])) { |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = array( |
|
| 47 | - 'field' => array( |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = array( |
|
| 47 | + 'field' => array( |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,520 +62,520 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = array()) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return array('tableau'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set($cle, |
|
| 183 | - array( |
|
| 184 | - 'data' => $valeur, |
|
| 185 | - 'time' => time(), |
|
| 186 | - 'ttl' => $ttl |
|
| 187 | - ), |
|
| 188 | - 3600 + $ttl); |
|
| 189 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Aller chercher les données de la boucle DATA |
|
| 195 | - * |
|
| 196 | - * @throws Exception |
|
| 197 | - * @param array $command |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - protected function select($command) { |
|
| 201 | - |
|
| 202 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | - // le type se retrouve dans la commande 'from' |
|
| 204 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | - if (isset($this->command['from'][0])) { |
|
| 206 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | - } |
|
| 209 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | - // les commandes connues pour l'iterateur DATA |
|
| 214 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | - |
|
| 216 | - // {source format, [URL], [arg2]...} |
|
| 217 | - if (isset($this->command['source']) |
|
| 218 | - and isset($this->command['sourcemode']) |
|
| 219 | - ) { |
|
| 220 | - $this->select_source(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Critere {liste X1, X2, X3} |
|
| 224 | - if (isset($this->command['liste'])) { |
|
| 225 | - $this->select_liste(); |
|
| 226 | - } |
|
| 227 | - if (isset($this->command['enum'])) { |
|
| 228 | - $this->select_enum(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | - if (!is_array($this->tableau)) { |
|
| 233 | - $this->err = true; |
|
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // {datapath query.results} |
|
| 238 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | - if (!$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if (isset($this->command['sourcemode']) |
|
| 272 | - and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | - ) { |
|
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - # le premier argument peut etre un array, une URL etc. |
|
| 278 | - $src = $this->command['source'][0]; |
|
| 279 | - |
|
| 280 | - # avons-nous un cache dispo ? |
|
| 281 | - $cle = null; |
|
| 282 | - if (is_string($src)) { |
|
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $cache = $this->cache_get($cle); |
|
| 287 | - if (isset($this->command['datacache'])) { |
|
| 288 | - $ttl = intval($this->command['datacache']); |
|
| 289 | - } |
|
| 290 | - if ($cache |
|
| 291 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | - > time()) |
|
| 293 | - and !(_request('var_mode') === 'recalcul' |
|
| 294 | - and include_spip('inc/autoriser') |
|
| 295 | - and autoriser('recalcul') |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - $this->tableau = $cache['data']; |
|
| 299 | - } else { |
|
| 300 | - try { |
|
| 301 | - # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | - if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | - if (!isset($ttl)) { |
|
| 304 | - $ttl = 3600; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if (isset($this->command['sourcemode']) |
|
| 309 | - and in_array($this->command['sourcemode'], |
|
| 310 | - array('table', 'array', 'tableau')) |
|
| 311 | - ) { |
|
| 312 | - if (is_array($a = $src) |
|
| 313 | - or (is_string($a) |
|
| 314 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | - and is_array($a = @unserialize($a))) |
|
| 316 | - ) { |
|
| 317 | - $this->tableau = $a; |
|
| 318 | - } |
|
| 319 | - } else { |
|
| 320 | - if (tester_url_absolue($src)) { |
|
| 321 | - include_spip('inc/distant'); |
|
| 322 | - $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | - if (!$u) { |
|
| 324 | - throw new Exception("404"); |
|
| 325 | - } |
|
| 326 | - if (!isset($ttl)) { |
|
| 327 | - $ttl = 24 * 3600; |
|
| 328 | - } |
|
| 329 | - } else { |
|
| 330 | - if (@is_dir($src)) { |
|
| 331 | - $u = $src; |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 10; |
|
| 334 | - } |
|
| 335 | - } else { |
|
| 336 | - if (@is_readable($src) && @is_file($src)) { |
|
| 337 | - $u = spip_file_get_contents($src); |
|
| 338 | - if (!isset($ttl)) { |
|
| 339 | - $ttl = 10; |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $u = $src; |
|
| 343 | - if (!isset($ttl)) { |
|
| 344 | - $ttl = 10; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - if (!$this->err |
|
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | - ) { |
|
| 352 | - $args = $this->command['source']; |
|
| 353 | - $args[0] = $u; |
|
| 354 | - if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | - $this->tableau = $a; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - if (!is_array($this->tableau)) { |
|
| 361 | - $this->err = true; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | - $this->cache_set($cle, $ttl); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - } catch (Exception $e) { |
|
| 369 | - $e = $e->getMessage(); |
|
| 370 | - $err = sprintf("[%s, %s] $e", |
|
| 371 | - $src, |
|
| 372 | - $this->command['sourcemode']); |
|
| 373 | - erreur_squelette(array($err, array())); |
|
| 374 | - $this->err = true; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | - if ($this->err |
|
| 380 | - and $cache |
|
| 381 | - ) { |
|
| 382 | - $this->tableau = $cache['data']; |
|
| 383 | - $this->err = false; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Retourne un tableau donne depuis un critère liste |
|
| 390 | - * |
|
| 391 | - * Critère `{liste X1, X2, X3}` |
|
| 392 | - * |
|
| 393 | - * @see critere_DATA_liste_dist() |
|
| 394 | - * |
|
| 395 | - **/ |
|
| 396 | - protected function select_liste() { |
|
| 397 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | - if (!isset($this->command['liste'][1])) { |
|
| 399 | - if (!is_array($this->command['liste'][0])) { |
|
| 400 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | - } else { |
|
| 402 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - $this->tableau = $this->command['liste']; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Retourne un tableau donne depuis un critere liste |
|
| 410 | - * Critere {enum Xmin, Xmax} |
|
| 411 | - * |
|
| 412 | - **/ |
|
| 413 | - protected function select_enum() { |
|
| 414 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | - if (!isset($this->command['enum'][1])) { |
|
| 416 | - if (!is_array($this->command['enum'][0])) { |
|
| 417 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | - } else { |
|
| 419 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - if (count($this->command['enum']) >= 3) { |
|
| 423 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum'])); |
|
| 425 | - } else { |
|
| 426 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | - } |
|
| 428 | - $this->tableau = $enum; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | - * {datapath query.results} |
|
| 435 | - * |
|
| 436 | - **/ |
|
| 437 | - protected function select_datapath() { |
|
| 438 | - $base = reset($this->command['datapath']); |
|
| 439 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | - if (!is_array($this->tableau)) { |
|
| 442 | - $this->tableau = array(); |
|
| 443 | - $this->err = true; |
|
| 444 | - spip_log("datapath '$base' absent"); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Ordonner les resultats |
|
| 451 | - * {par x} |
|
| 452 | - * |
|
| 453 | - **/ |
|
| 454 | - protected function select_orderby() { |
|
| 455 | - $sortfunc = ''; |
|
| 456 | - $aleas = 0; |
|
| 457 | - foreach ($this->command['orderby'] as $tri) { |
|
| 458 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | - $r = array_pad($r, 3, null); |
|
| 461 | - |
|
| 462 | - // tri par cle |
|
| 463 | - if ($r[1] == 'cle') { |
|
| 464 | - if (isset($r[2]) and $r[2]) { |
|
| 465 | - krsort($this->tableau); |
|
| 466 | - } else { |
|
| 467 | - ksort($this->tableau); |
|
| 468 | - } |
|
| 469 | - } # {par hasard} |
|
| 470 | - else { |
|
| 471 | - if ($r[1] == 'hasard') { |
|
| 472 | - $k = array_keys($this->tableau); |
|
| 473 | - shuffle($k); |
|
| 474 | - $v = array(); |
|
| 475 | - foreach ($k as $cle) { |
|
| 476 | - $v[$cle] = $this->tableau[$cle]; |
|
| 477 | - } |
|
| 478 | - $this->tableau = $v; |
|
| 479 | - } else { |
|
| 480 | - # {par valeur} |
|
| 481 | - if ($r[1] == 'valeur') { |
|
| 482 | - $tv = '%s'; |
|
| 483 | - } # {par valeur/xx/yy} ?? |
|
| 484 | - else { |
|
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | - } |
|
| 487 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = array()) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return array('tableau'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set($cle, |
|
| 183 | + array( |
|
| 184 | + 'data' => $valeur, |
|
| 185 | + 'time' => time(), |
|
| 186 | + 'ttl' => $ttl |
|
| 187 | + ), |
|
| 188 | + 3600 + $ttl); |
|
| 189 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Aller chercher les données de la boucle DATA |
|
| 195 | + * |
|
| 196 | + * @throws Exception |
|
| 197 | + * @param array $command |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + protected function select($command) { |
|
| 201 | + |
|
| 202 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | + // le type se retrouve dans la commande 'from' |
|
| 204 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | + if (isset($this->command['from'][0])) { |
|
| 206 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | + } |
|
| 209 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | + // les commandes connues pour l'iterateur DATA |
|
| 214 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | + |
|
| 216 | + // {source format, [URL], [arg2]...} |
|
| 217 | + if (isset($this->command['source']) |
|
| 218 | + and isset($this->command['sourcemode']) |
|
| 219 | + ) { |
|
| 220 | + $this->select_source(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Critere {liste X1, X2, X3} |
|
| 224 | + if (isset($this->command['liste'])) { |
|
| 225 | + $this->select_liste(); |
|
| 226 | + } |
|
| 227 | + if (isset($this->command['enum'])) { |
|
| 228 | + $this->select_enum(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | + if (!is_array($this->tableau)) { |
|
| 233 | + $this->err = true; |
|
| 234 | + spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // {datapath query.results} |
|
| 238 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | + if (!$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if (isset($this->command['sourcemode']) |
|
| 272 | + and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | + ) { |
|
| 274 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + # le premier argument peut etre un array, une URL etc. |
|
| 278 | + $src = $this->command['source'][0]; |
|
| 279 | + |
|
| 280 | + # avons-nous un cache dispo ? |
|
| 281 | + $cle = null; |
|
| 282 | + if (is_string($src)) { |
|
| 283 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $cache = $this->cache_get($cle); |
|
| 287 | + if (isset($this->command['datacache'])) { |
|
| 288 | + $ttl = intval($this->command['datacache']); |
|
| 289 | + } |
|
| 290 | + if ($cache |
|
| 291 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | + > time()) |
|
| 293 | + and !(_request('var_mode') === 'recalcul' |
|
| 294 | + and include_spip('inc/autoriser') |
|
| 295 | + and autoriser('recalcul') |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + $this->tableau = $cache['data']; |
|
| 299 | + } else { |
|
| 300 | + try { |
|
| 301 | + # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | + if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | + if (!isset($ttl)) { |
|
| 304 | + $ttl = 3600; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if (isset($this->command['sourcemode']) |
|
| 309 | + and in_array($this->command['sourcemode'], |
|
| 310 | + array('table', 'array', 'tableau')) |
|
| 311 | + ) { |
|
| 312 | + if (is_array($a = $src) |
|
| 313 | + or (is_string($a) |
|
| 314 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | + and is_array($a = @unserialize($a))) |
|
| 316 | + ) { |
|
| 317 | + $this->tableau = $a; |
|
| 318 | + } |
|
| 319 | + } else { |
|
| 320 | + if (tester_url_absolue($src)) { |
|
| 321 | + include_spip('inc/distant'); |
|
| 322 | + $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | + if (!$u) { |
|
| 324 | + throw new Exception("404"); |
|
| 325 | + } |
|
| 326 | + if (!isset($ttl)) { |
|
| 327 | + $ttl = 24 * 3600; |
|
| 328 | + } |
|
| 329 | + } else { |
|
| 330 | + if (@is_dir($src)) { |
|
| 331 | + $u = $src; |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 10; |
|
| 334 | + } |
|
| 335 | + } else { |
|
| 336 | + if (@is_readable($src) && @is_file($src)) { |
|
| 337 | + $u = spip_file_get_contents($src); |
|
| 338 | + if (!isset($ttl)) { |
|
| 339 | + $ttl = 10; |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $u = $src; |
|
| 343 | + if (!isset($ttl)) { |
|
| 344 | + $ttl = 10; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + if (!$this->err |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | + ) { |
|
| 352 | + $args = $this->command['source']; |
|
| 353 | + $args[0] = $u; |
|
| 354 | + if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | + $this->tableau = $a; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + if (!is_array($this->tableau)) { |
|
| 361 | + $this->err = true; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | + $this->cache_set($cle, $ttl); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + $e = $e->getMessage(); |
|
| 370 | + $err = sprintf("[%s, %s] $e", |
|
| 371 | + $src, |
|
| 372 | + $this->command['sourcemode']); |
|
| 373 | + erreur_squelette(array($err, array())); |
|
| 374 | + $this->err = true; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | + if ($this->err |
|
| 380 | + and $cache |
|
| 381 | + ) { |
|
| 382 | + $this->tableau = $cache['data']; |
|
| 383 | + $this->err = false; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Retourne un tableau donne depuis un critère liste |
|
| 390 | + * |
|
| 391 | + * Critère `{liste X1, X2, X3}` |
|
| 392 | + * |
|
| 393 | + * @see critere_DATA_liste_dist() |
|
| 394 | + * |
|
| 395 | + **/ |
|
| 396 | + protected function select_liste() { |
|
| 397 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | + if (!isset($this->command['liste'][1])) { |
|
| 399 | + if (!is_array($this->command['liste'][0])) { |
|
| 400 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | + } else { |
|
| 402 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + $this->tableau = $this->command['liste']; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Retourne un tableau donne depuis un critere liste |
|
| 410 | + * Critere {enum Xmin, Xmax} |
|
| 411 | + * |
|
| 412 | + **/ |
|
| 413 | + protected function select_enum() { |
|
| 414 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | + if (!isset($this->command['enum'][1])) { |
|
| 416 | + if (!is_array($this->command['enum'][0])) { |
|
| 417 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | + } else { |
|
| 419 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + if (count($this->command['enum']) >= 3) { |
|
| 423 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum'])); |
|
| 425 | + } else { |
|
| 426 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | + } |
|
| 428 | + $this->tableau = $enum; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | + * {datapath query.results} |
|
| 435 | + * |
|
| 436 | + **/ |
|
| 437 | + protected function select_datapath() { |
|
| 438 | + $base = reset($this->command['datapath']); |
|
| 439 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | + if (!is_array($this->tableau)) { |
|
| 442 | + $this->tableau = array(); |
|
| 443 | + $this->err = true; |
|
| 444 | + spip_log("datapath '$base' absent"); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Ordonner les resultats |
|
| 451 | + * {par x} |
|
| 452 | + * |
|
| 453 | + **/ |
|
| 454 | + protected function select_orderby() { |
|
| 455 | + $sortfunc = ''; |
|
| 456 | + $aleas = 0; |
|
| 457 | + foreach ($this->command['orderby'] as $tri) { |
|
| 458 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | + $r = array_pad($r, 3, null); |
|
| 461 | + |
|
| 462 | + // tri par cle |
|
| 463 | + if ($r[1] == 'cle') { |
|
| 464 | + if (isset($r[2]) and $r[2]) { |
|
| 465 | + krsort($this->tableau); |
|
| 466 | + } else { |
|
| 467 | + ksort($this->tableau); |
|
| 468 | + } |
|
| 469 | + } # {par hasard} |
|
| 470 | + else { |
|
| 471 | + if ($r[1] == 'hasard') { |
|
| 472 | + $k = array_keys($this->tableau); |
|
| 473 | + shuffle($k); |
|
| 474 | + $v = array(); |
|
| 475 | + foreach ($k as $cle) { |
|
| 476 | + $v[$cle] = $this->tableau[$cle]; |
|
| 477 | + } |
|
| 478 | + $this->tableau = $v; |
|
| 479 | + } else { |
|
| 480 | + # {par valeur} |
|
| 481 | + if ($r[1] == 'valeur') { |
|
| 482 | + $tv = '%s'; |
|
| 483 | + } # {par valeur/xx/yy} ?? |
|
| 484 | + else { |
|
| 485 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | + } |
|
| 487 | + $sortfunc .= ' |
|
| 488 | 488 | $a = ' . sprintf($tv, '$aa') . '; |
| 489 | 489 | $b = ' . sprintf($tv, '$bb') . '; |
| 490 | 490 | if ($a <> $b) |
| 491 | 491 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($sortfunc) { |
|
| 498 | - $sortfunc .= "\n return 0;"; |
|
| 499 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | - return eval($sortfunc); |
|
| 501 | - }); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = array(); |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid() { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return null |
|
| 540 | - */ |
|
| 541 | - public function current() { |
|
| 542 | - return $this->valeur; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Retourner la cle |
|
| 547 | - * |
|
| 548 | - * @return null |
|
| 549 | - */ |
|
| 550 | - public function key() { |
|
| 551 | - return $this->cle; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Passer a la valeur suivante |
|
| 556 | - * |
|
| 557 | - * @return void |
|
| 558 | - */ |
|
| 559 | - public function next() { |
|
| 560 | - if ($this->valid()) { |
|
| 561 | - $this->cle = key($this->tableau); |
|
| 562 | - $this->valeur = current($this->tableau); |
|
| 563 | - next($this->tableau); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Compter le nombre total de resultats |
|
| 569 | - * |
|
| 570 | - * @return int |
|
| 571 | - */ |
|
| 572 | - public function count() { |
|
| 573 | - if (is_null($this->total)) { |
|
| 574 | - $this->total = count($this->tableau); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $this->total; |
|
| 578 | - } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($sortfunc) { |
|
| 498 | + $sortfunc .= "\n return 0;"; |
|
| 499 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | + return eval($sortfunc); |
|
| 501 | + }); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = array(); |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid() { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return null |
|
| 540 | + */ |
|
| 541 | + public function current() { |
|
| 542 | + return $this->valeur; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Retourner la cle |
|
| 547 | + * |
|
| 548 | + * @return null |
|
| 549 | + */ |
|
| 550 | + public function key() { |
|
| 551 | + return $this->cle; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Passer a la valeur suivante |
|
| 556 | + * |
|
| 557 | + * @return void |
|
| 558 | + */ |
|
| 559 | + public function next() { |
|
| 560 | + if ($this->valid()) { |
|
| 561 | + $this->cle = key($this->tableau); |
|
| 562 | + $this->valeur = current($this->tableau); |
|
| 563 | + next($this->tableau); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Compter le nombre total de resultats |
|
| 569 | + * |
|
| 570 | + * @return int |
|
| 571 | + */ |
|
| 572 | + public function count() { |
|
| 573 | + if (is_null($this->total)) { |
|
| 574 | + $this->total = count($this->tableau); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $this->total; |
|
| 578 | + } |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /* |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | 591 | function inc_file_to_array_dist($u) { |
| 592 | - return preg_split('/\r?\n/', $u); |
|
| 592 | + return preg_split('/\r?\n/', $u); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | * @return unknown |
| 599 | 599 | */ |
| 600 | 600 | function inc_plugins_to_array_dist() { |
| 601 | - include_spip('inc/plugin'); |
|
| 601 | + include_spip('inc/plugin'); |
|
| 602 | 602 | |
| 603 | - return liste_chemin_plugin_actifs(); |
|
| 603 | + return liste_chemin_plugin_actifs(); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @return array |
| 611 | 611 | */ |
| 612 | 612 | function inc_xml_to_array_dist($u) { |
| 613 | - return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 613 | + return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -622,14 +622,14 @@ discard block |
||
| 622 | 622 | * |
| 623 | 623 | */ |
| 624 | 624 | function inc_object_to_array($object) { |
| 625 | - if (!is_object($object) && !is_array($object)) { |
|
| 626 | - return $object; |
|
| 627 | - } |
|
| 628 | - if (is_object($object)) { |
|
| 629 | - $object = get_object_vars($object); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - return array_map('inc_object_to_array', $object); |
|
| 625 | + if (!is_object($object) && !is_array($object)) { |
|
| 626 | + return $object; |
|
| 627 | + } |
|
| 628 | + if (is_object($object)) { |
|
| 629 | + $object = get_object_vars($object); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + return array_map('inc_object_to_array', $object); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -640,18 +640,18 @@ discard block |
||
| 640 | 640 | * @return array|bool |
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | - define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | - if (!$v['page'] |
|
| 646 | - or !$w = json_decode($v['page'], true) |
|
| 647 | - ) { |
|
| 648 | - throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | - } |
|
| 650 | - if (isset($w['error'])) { |
|
| 651 | - throw new Exception($w['error']['description']); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return inc_object_to_array($w); |
|
| 643 | + define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | + if (!$v['page'] |
|
| 646 | + or !$w = json_decode($v['page'], true) |
|
| 647 | + ) { |
|
| 648 | + throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | + } |
|
| 650 | + if (isset($w['error'])) { |
|
| 651 | + throw new Exception($w['error']['description']); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return inc_object_to_array($w); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -661,20 +661,20 @@ discard block |
||
| 661 | 661 | * @return array|bool |
| 662 | 662 | */ |
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | - # sortir le connecteur de $u |
|
| 665 | - preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | - $serveur = (string)$v[1]; |
|
| 667 | - $req = trim($v[2]); |
|
| 668 | - if ($s = sql_query($req, $serveur)) { |
|
| 669 | - $r = array(); |
|
| 670 | - while ($t = sql_fetch($s)) { |
|
| 671 | - $r[] = $t; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return $r; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - return false; |
|
| 664 | + # sortir le connecteur de $u |
|
| 665 | + preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | + $serveur = (string)$v[1]; |
|
| 667 | + $req = trim($v[2]); |
|
| 668 | + if ($s = sql_query($req, $serveur)) { |
|
| 669 | + $r = array(); |
|
| 670 | + while ($t = sql_fetch($s)) { |
|
| 671 | + $r[] = $t; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return $r; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + return false; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -684,11 +684,11 @@ discard block |
||
| 684 | 684 | * @return array|bool |
| 685 | 685 | */ |
| 686 | 686 | function inc_json_to_array_dist($u) { |
| 687 | - if (is_array($json = json_decode($u)) |
|
| 688 | - or is_object($json) |
|
| 689 | - ) { |
|
| 690 | - return (array)$json; |
|
| 691 | - } |
|
| 687 | + if (is_array($json = json_decode($u)) |
|
| 688 | + or is_object($json) |
|
| 689 | + ) { |
|
| 690 | + return (array)$json; |
|
| 691 | + } |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -698,30 +698,30 @@ discard block |
||
| 698 | 698 | * @return array|bool |
| 699 | 699 | */ |
| 700 | 700 | function inc_csv_to_array_dist($u) { |
| 701 | - include_spip('inc/csv'); |
|
| 702 | - list($entete, $csv) = analyse_csv($u); |
|
| 703 | - array_unshift($csv, $entete); |
|
| 704 | - |
|
| 705 | - include_spip('inc/charsets'); |
|
| 706 | - $i = 1; |
|
| 707 | - foreach ($entete as $k => $v) { |
|
| 708 | - if (trim($v) == "") { |
|
| 709 | - $v = "col" . $i; |
|
| 710 | - } // reperer des eventuelles cases vides |
|
| 711 | - if (is_numeric($v) and $v < 0) { |
|
| 712 | - $v = "__" . $v; |
|
| 713 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | - if (is_numeric($v)) { |
|
| 715 | - $v = "_" . $v; |
|
| 716 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | - foreach ($csv as &$item) { |
|
| 719 | - $item[$v] = &$item[$k]; |
|
| 720 | - } |
|
| 721 | - $i++; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $csv; |
|
| 701 | + include_spip('inc/csv'); |
|
| 702 | + list($entete, $csv) = analyse_csv($u); |
|
| 703 | + array_unshift($csv, $entete); |
|
| 704 | + |
|
| 705 | + include_spip('inc/charsets'); |
|
| 706 | + $i = 1; |
|
| 707 | + foreach ($entete as $k => $v) { |
|
| 708 | + if (trim($v) == "") { |
|
| 709 | + $v = "col" . $i; |
|
| 710 | + } // reperer des eventuelles cases vides |
|
| 711 | + if (is_numeric($v) and $v < 0) { |
|
| 712 | + $v = "__" . $v; |
|
| 713 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | + if (is_numeric($v)) { |
|
| 715 | + $v = "_" . $v; |
|
| 716 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | + foreach ($csv as &$item) { |
|
| 719 | + $item[$v] = &$item[$k]; |
|
| 720 | + } |
|
| 721 | + $i++; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $csv; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -731,12 +731,12 @@ discard block |
||
| 731 | 731 | * @return array|bool |
| 732 | 732 | */ |
| 733 | 733 | function inc_rss_to_array_dist($u) { |
| 734 | - include_spip('inc/syndic'); |
|
| 735 | - if (is_array($rss = analyser_backend($u))) { |
|
| 736 | - $tableau = $rss; |
|
| 737 | - } |
|
| 734 | + include_spip('inc/syndic'); |
|
| 735 | + if (is_array($rss = analyser_backend($u))) { |
|
| 736 | + $tableau = $rss; |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - return $tableau; |
|
| 739 | + return $tableau; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -746,9 +746,9 @@ discard block |
||
| 746 | 746 | * @return array|bool |
| 747 | 747 | */ |
| 748 | 748 | function inc_atom_to_array_dist($u) { |
| 749 | - $g = charger_fonction('rss_to_array', 'inc'); |
|
| 749 | + $g = charger_fonction('rss_to_array', 'inc'); |
|
| 750 | 750 | |
| 751 | - return $g($u); |
|
| 751 | + return $g($u); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | * @return array|bool |
| 760 | 760 | */ |
| 761 | 761 | function inc_glob_to_array_dist($u) { |
| 762 | - $a = glob($u, |
|
| 763 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | - ); |
|
| 762 | + $a = glob($u, |
|
| 763 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | + ); |
|
| 765 | 765 | |
| 766 | - return $a ? $a : array(); |
|
| 766 | + return $a ? $a : array(); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -774,14 +774,14 @@ discard block |
||
| 774 | 774 | * @throws Exception |
| 775 | 775 | */ |
| 776 | 776 | function inc_yaml_to_array_dist($u) { |
| 777 | - include_spip('inc/yaml-mini'); |
|
| 778 | - if (!function_exists("yaml_decode")) { |
|
| 779 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 777 | + include_spip('inc/yaml-mini'); |
|
| 778 | + if (!function_exists("yaml_decode")) { |
|
| 779 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 780 | 780 | |
| 781 | - return false; |
|
| 782 | - } |
|
| 781 | + return false; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return yaml_decode($u); |
|
| 784 | + return yaml_decode($u); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -808,23 +808,23 @@ discard block |
||
| 808 | 808 | * @return array|bool |
| 809 | 809 | */ |
| 810 | 810 | function inc_ls_to_array_dist($u) { |
| 811 | - $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | - $a = $glob($u); |
|
| 813 | - foreach ($a as &$v) { |
|
| 814 | - $b = (array)@stat($v); |
|
| 815 | - foreach ($b as $k => $ignore) { |
|
| 816 | - if (is_numeric($k)) { |
|
| 817 | - unset($b[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | - $v = array_merge( |
|
| 822 | - pathinfo($v), |
|
| 823 | - $b |
|
| 824 | - ); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return $a; |
|
| 811 | + $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | + $a = $glob($u); |
|
| 813 | + foreach ($a as &$v) { |
|
| 814 | + $b = (array)@stat($v); |
|
| 815 | + foreach ($b as $k => $ignore) { |
|
| 816 | + if (is_numeric($k)) { |
|
| 817 | + unset($b[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | + $v = array_merge( |
|
| 822 | + pathinfo($v), |
|
| 823 | + $b |
|
| 824 | + ); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return $a; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -834,24 +834,24 @@ discard block |
||
| 834 | 834 | * @return array|bool |
| 835 | 835 | */ |
| 836 | 836 | function XMLObjectToArray($object) { |
| 837 | - $xml_array = array(); |
|
| 838 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | - $key .= '-' . uniqid(); |
|
| 841 | - } |
|
| 842 | - $vars = get_object_vars($object->current()); |
|
| 843 | - if (isset($vars['@attributes'])) { |
|
| 844 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | - $xml_array[$key][$k] = $v; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - if ($object->hasChildren()) { |
|
| 849 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | - $object->current()); |
|
| 851 | - } else { |
|
| 852 | - $xml_array[$key][] = strval($object->current()); |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $xml_array; |
|
| 837 | + $xml_array = array(); |
|
| 838 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | + $key .= '-' . uniqid(); |
|
| 841 | + } |
|
| 842 | + $vars = get_object_vars($object->current()); |
|
| 843 | + if (isset($vars['@attributes'])) { |
|
| 844 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | + $xml_array[$key][$k] = $v; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + if ($object->hasChildren()) { |
|
| 849 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | + $object->current()); |
|
| 851 | + } else { |
|
| 852 | + $xml_array[$key][] = strval($object->current()); |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $xml_array; |
|
| 857 | 857 | } |
@@ -121,6 +121,10 @@ discard block |
||
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | +/** |
|
| 125 | + * @param integer $id_input |
|
| 126 | + * @param string $file |
|
| 127 | + */ |
|
| 124 | 128 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | 129 | $name = substr(md5($file), 0, 16); |
| 126 | 130 | |
@@ -185,6 +189,9 @@ discard block |
||
| 185 | 189 | . "</div>"; |
| 186 | 190 | } |
| 187 | 191 | |
| 192 | +/** |
|
| 193 | + * @param string $nom |
|
| 194 | + */ |
|
| 188 | 195 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | 196 | if (!$dir_plugins) { |
| 190 | 197 | $dir_plugins = _DIR_PLUGINS; |
@@ -102,10 +102,12 @@ |
||
| 102 | 102 | |
| 103 | 103 | // si le plugin CFG est la, l'essayer |
| 104 | 104 | if (defined('_DIR_PLUGIN_CFG')) { |
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 105 | + if (include_spip('inc/cfg')) { |
|
| 106 | + // test CFG version >= 1.0.5 |
|
| 106 | 107 | { |
| 107 | 108 | if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
| 108 | 109 | return "<div class='cfg_link'>$cfg</div>"; |
| 110 | + } |
|
| 109 | 111 | } |
| 110 | 112 | } |
| 111 | 113 | } |
@@ -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 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
@@ -25,181 +25,181 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // http://code.spip.net/@ligne_plug |
| 27 | 27 | function plugins_afficher_plugin_dist( |
| 28 | - $url_page, |
|
| 29 | - $plug_file, |
|
| 30 | - $checked, |
|
| 31 | - $actif, |
|
| 32 | - $expose = false, |
|
| 33 | - $class_li = "item", |
|
| 34 | - $dir_plugins = _DIR_PLUGINS |
|
| 28 | + $url_page, |
|
| 29 | + $plug_file, |
|
| 30 | + $checked, |
|
| 31 | + $actif, |
|
| 32 | + $expose = false, |
|
| 33 | + $class_li = "item", |
|
| 34 | + $dir_plugins = _DIR_PLUGINS |
|
| 35 | 35 | ) { |
| 36 | 36 | |
| 37 | - static $id_input = 0; |
|
| 38 | - static $versions = array(); |
|
| 39 | - |
|
| 40 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | - $prefix = $info['prefix']; |
|
| 44 | - $cfg = ""; |
|
| 45 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | - $erreur = ""; |
|
| 48 | - |
|
| 49 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | - $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | - _T('plugin_info_non_compatible_spip')); |
|
| 53 | - $class_li .= " disabled"; |
|
| 54 | - $checkable = false; |
|
| 55 | - } elseif (isset($info['erreur'])) { |
|
| 56 | - $class_li .= " error"; |
|
| 57 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | - _T('plugin_info_erreur_xml')) |
|
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | - $checkable = false; |
|
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | - $class_li .= " error"; |
|
| 63 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | - " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | - } else { |
|
| 68 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // numerotons les occurrences d'un meme prefix |
|
| 72 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | - |
|
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | - |
|
| 76 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | - . ((!$checkable and !$checked) |
|
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | - . $cfg |
|
| 81 | - . $erreur |
|
| 82 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | - . "</div>" |
|
| 87 | - . "</li>"; |
|
| 37 | + static $id_input = 0; |
|
| 38 | + static $versions = array(); |
|
| 39 | + |
|
| 40 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | + $prefix = $info['prefix']; |
|
| 44 | + $cfg = ""; |
|
| 45 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | + $erreur = ""; |
|
| 48 | + |
|
| 49 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | + _T('plugin_info_non_compatible_spip')); |
|
| 53 | + $class_li .= " disabled"; |
|
| 54 | + $checkable = false; |
|
| 55 | + } elseif (isset($info['erreur'])) { |
|
| 56 | + $class_li .= " error"; |
|
| 57 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | + _T('plugin_info_erreur_xml')) |
|
| 59 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | + $checkable = false; |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | + $class_li .= " error"; |
|
| 63 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | + " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | + . "<div class='erreur'>" . implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | + } else { |
|
| 68 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // numerotons les occurrences d'un meme prefix |
|
| 72 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 73 | + |
|
| 74 | + $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | + |
|
| 76 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | + . ((!$checkable and !$checked) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | + . $cfg |
|
| 81 | + . $erreur |
|
| 82 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | + . "</div>" |
|
| 87 | + . "</li>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function plugin_bouton_config($nom, $infos, $dir) { |
| 91 | - // la verification se base sur le filesystem |
|
| 92 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | - $prefix = strtolower($infos['prefix']); |
|
| 94 | - // si paquet.xml fournit un squelette, le prendre |
|
| 95 | - if (isset($infos['config']) and $infos['config']) { |
|
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | - array( |
|
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 99 | - 'nom' => $nom |
|
| 100 | - )); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si le plugin CFG est la, l'essayer |
|
| 104 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | - { |
|
| 107 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // sinon prendre le squelette std sur le nom std |
|
| 114 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | - array( |
|
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 117 | - 'nom' => $nom |
|
| 118 | - )); |
|
| 91 | + // la verification se base sur le filesystem |
|
| 92 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | + $prefix = strtolower($infos['prefix']); |
|
| 94 | + // si paquet.xml fournit un squelette, le prendre |
|
| 95 | + if (isset($infos['config']) and $infos['config']) { |
|
| 96 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | + array( |
|
| 98 | + 'script' => 'configurer_' . $prefix, |
|
| 99 | + 'nom' => $nom |
|
| 100 | + )); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si le plugin CFG est la, l'essayer |
|
| 104 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | + { |
|
| 107 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // sinon prendre le squelette std sur le nom std |
|
| 114 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | + array( |
|
| 116 | + 'script' => 'configurer_' . $prefix, |
|
| 117 | + 'nom' => $nom |
|
| 118 | + )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | 124 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | - $name = substr(md5($file), 0, 16); |
|
| 126 | - |
|
| 127 | - return "<div class='check'>\n" |
|
| 128 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | - . ($actif ? " checked='checked'" : "") |
|
| 130 | - . " class='checkbox' value='O' />" |
|
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | - . "</div>"; |
|
| 125 | + $name = substr(md5($file), 0, 16); |
|
| 126 | + |
|
| 127 | + return "<div class='check'>\n" |
|
| 128 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | + . ($actif ? " checked='checked'" : "") |
|
| 130 | + . " class='checkbox' value='O' />" |
|
| 131 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | + . "</div>"; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 136 | - $prefix = $info['prefix']; |
|
| 137 | - $dir = "$dir_plugins$plug_file"; |
|
| 138 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | - if ($info['dtd'] == "paquet") { |
|
| 140 | - $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | - if (!$nom) { |
|
| 142 | - $nom = PtoBR(propre($info['nom'])); |
|
| 143 | - } |
|
| 144 | - } else { |
|
| 145 | - $nom = typo(attribut_html($info['nom'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return trim($nom); |
|
| 136 | + $prefix = $info['prefix']; |
|
| 137 | + $dir = "$dir_plugins$plug_file"; |
|
| 138 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | + if ($info['dtd'] == "paquet") { |
|
| 140 | + $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | + if (!$nom) { |
|
| 142 | + $nom = PtoBR(propre($info['nom'])); |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $nom = typo(attribut_html($info['nom'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return trim($nom); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Cartouche Resume |
| 152 | 152 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 153 | - $prefix = $info['prefix']; |
|
| 154 | - $dir = "$dir_plugins$plug_file"; |
|
| 155 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | - // une seule ligne dans le slogan : couper si besoin |
|
| 157 | - if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | - $slogan = substr($slogan, 0, $p); |
|
| 159 | - } |
|
| 160 | - // couper par securite |
|
| 161 | - $slogan = couper($slogan, 80); |
|
| 162 | - |
|
| 163 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | - |
|
| 165 | - $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | - |
|
| 167 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | - include_spip("inc/filtres_images_mini"); |
|
| 169 | - $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | - $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | - } else { |
|
| 172 | - $i = ''; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return "<div class='resume'>" |
|
| 176 | - . "<h3><a href='$url' rel='info'>" |
|
| 177 | - . $nom |
|
| 178 | - . "</a></h3>" |
|
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | - . " <span class='etat'> - " |
|
| 181 | - . plugin_etat_en_clair($info['etat']) |
|
| 182 | - . "</span>" |
|
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | - . $i |
|
| 185 | - . "</div>"; |
|
| 153 | + $prefix = $info['prefix']; |
|
| 154 | + $dir = "$dir_plugins$plug_file"; |
|
| 155 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | + // une seule ligne dans le slogan : couper si besoin |
|
| 157 | + if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | + $slogan = substr($slogan, 0, $p); |
|
| 159 | + } |
|
| 160 | + // couper par securite |
|
| 161 | + $slogan = couper($slogan, 80); |
|
| 162 | + |
|
| 163 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | + |
|
| 165 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | + |
|
| 167 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | + include_spip("inc/filtres_images_mini"); |
|
| 169 | + $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | + $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | + } else { |
|
| 172 | + $i = ''; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return "<div class='resume'>" |
|
| 176 | + . "<h3><a href='$url' rel='info'>" |
|
| 177 | + . $nom |
|
| 178 | + . "</a></h3>" |
|
| 179 | + . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | + . " <span class='etat'> - " |
|
| 181 | + . plugin_etat_en_clair($info['etat']) |
|
| 182 | + . "</span>" |
|
| 183 | + . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | + . $i |
|
| 185 | + . "</div>"; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | - if (!$dir_plugins) { |
|
| 190 | - $dir_plugins = _DIR_PLUGINS; |
|
| 191 | - } |
|
| 189 | + if (!$dir_plugins) { |
|
| 190 | + $dir_plugins = _DIR_PLUGINS; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | - $text = _T('bouton_desinstaller'); |
|
| 195 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | - $file = basename($plug_file); |
|
| 193 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | + $text = _T('bouton_desinstaller'); |
|
| 195 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | + $file = basename($plug_file); |
|
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 199 | - "<a href='$action' |
|
| 198 | + return "<div class='actions'>[" . |
|
| 199 | + "<a href='$action' |
|
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | - . $text |
|
| 202 | - . "</a>]</div>"; |
|
| 201 | + . $text |
|
| 202 | + . "</a>]</div>"; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -213,133 +213,133 @@ discard block |
||
| 213 | 213 | * Traduction de l'état dans la langue en cours |
| 214 | 214 | **/ |
| 215 | 215 | function plugin_etat_en_clair($etat) { |
| 216 | - if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | - $etat = 'developpement'; |
|
| 218 | - } |
|
| 216 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | + $etat = 'developpement'; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_' . $etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
| 224 | 224 | function plugin_propre($texte, $module = '') { |
| 225 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | - } |
|
| 229 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return propre($texte); |
|
| 225 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | + } |
|
| 229 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return propre($texte); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@affiche_bloc_plugin |
| 238 | 238 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 239 | - if (!$dir_plugins) { |
|
| 240 | - $dir_plugins = _DIR_PLUGINS; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $prefix = $info['prefix']; |
|
| 244 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | - |
|
| 246 | - $s = ""; |
|
| 247 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | - // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 250 | - $description = ""; |
|
| 251 | - if (isset($info['description'])) { |
|
| 252 | - $description = plugin_propre($info['description'], $dir); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - if (isset($info['documentation']) |
|
| 256 | - and $lien = $info['documentation'] |
|
| 257 | - ) { |
|
| 258 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 259 | - } |
|
| 260 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 261 | - |
|
| 262 | - if (isset($info['auteur'])) { |
|
| 263 | - if (is_array($info['auteur'])) { |
|
| 264 | - $a = formater_credits($info['auteur'], ', '); |
|
| 265 | - } // pour compat mais ne doit plus arriver |
|
| 266 | - else { |
|
| 267 | - $a = trim($info['auteur']); |
|
| 268 | - } |
|
| 269 | - if ($a) { |
|
| 270 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 271 | - $dir)) . "</dd>\n"; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if (isset($info['credit'])) { |
|
| 276 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 277 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 278 | - $dir)) . "</dd>\n"; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - if (isset($info['licence'])) { |
|
| 283 | - if (is_array($info['licence'])) { |
|
| 284 | - $a = formater_credits($info['licence'], ', '); |
|
| 285 | - } // pour compat mais ne doit plus arriver |
|
| 286 | - else { |
|
| 287 | - $a = trim($info['licence']); |
|
| 288 | - } |
|
| 289 | - if ($a) { |
|
| 290 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 291 | - $dir)) . "</dd>\n"; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $s = "<dl class='description'>$s</dl>"; |
|
| 296 | - |
|
| 297 | - // |
|
| 298 | - // Ajouter les infos techniques |
|
| 299 | - // |
|
| 300 | - $infotech = array(); |
|
| 301 | - |
|
| 302 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 303 | - // Version SVN |
|
| 304 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 305 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 306 | - } |
|
| 307 | - $version .= "</dd>"; |
|
| 308 | - $infotech[] = $version; |
|
| 309 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 310 | - // source zip le cas echeant |
|
| 311 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 312 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 313 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 314 | - : ''; |
|
| 315 | - |
|
| 316 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 317 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 318 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 319 | - |
|
| 320 | - $s .= "<dl class='tech'>" |
|
| 321 | - . join('', $infotech) |
|
| 322 | - . "</dl>"; |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - return $s; |
|
| 239 | + if (!$dir_plugins) { |
|
| 240 | + $dir_plugins = _DIR_PLUGINS; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $prefix = $info['prefix']; |
|
| 244 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | + |
|
| 246 | + $s = ""; |
|
| 247 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | + // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 250 | + $description = ""; |
|
| 251 | + if (isset($info['description'])) { |
|
| 252 | + $description = plugin_propre($info['description'], $dir); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + if (isset($info['documentation']) |
|
| 256 | + and $lien = $info['documentation'] |
|
| 257 | + ) { |
|
| 258 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 259 | + } |
|
| 260 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 261 | + |
|
| 262 | + if (isset($info['auteur'])) { |
|
| 263 | + if (is_array($info['auteur'])) { |
|
| 264 | + $a = formater_credits($info['auteur'], ', '); |
|
| 265 | + } // pour compat mais ne doit plus arriver |
|
| 266 | + else { |
|
| 267 | + $a = trim($info['auteur']); |
|
| 268 | + } |
|
| 269 | + if ($a) { |
|
| 270 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 271 | + $dir)) . "</dd>\n"; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if (isset($info['credit'])) { |
|
| 276 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 277 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 278 | + $dir)) . "</dd>\n"; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + if (isset($info['licence'])) { |
|
| 283 | + if (is_array($info['licence'])) { |
|
| 284 | + $a = formater_credits($info['licence'], ', '); |
|
| 285 | + } // pour compat mais ne doit plus arriver |
|
| 286 | + else { |
|
| 287 | + $a = trim($info['licence']); |
|
| 288 | + } |
|
| 289 | + if ($a) { |
|
| 290 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 291 | + $dir)) . "</dd>\n"; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $s = "<dl class='description'>$s</dl>"; |
|
| 296 | + |
|
| 297 | + // |
|
| 298 | + // Ajouter les infos techniques |
|
| 299 | + // |
|
| 300 | + $infotech = array(); |
|
| 301 | + |
|
| 302 | + $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 303 | + // Version SVN |
|
| 304 | + if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 305 | + $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 306 | + } |
|
| 307 | + $version .= "</dd>"; |
|
| 308 | + $infotech[] = $version; |
|
| 309 | + $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 310 | + // source zip le cas echeant |
|
| 311 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 312 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 313 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 314 | + : ''; |
|
| 315 | + |
|
| 316 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 317 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 318 | + array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 319 | + |
|
| 320 | + $s .= "<dl class='tech'>" |
|
| 321 | + . join('', $infotech) |
|
| 322 | + . "</dl>"; |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + return $s; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | function formater_credits($infos, $sep = ', ') { |
| 329 | - $texte = ''; |
|
| 330 | - |
|
| 331 | - foreach ($infos as $_credit) { |
|
| 332 | - if ($texte) { |
|
| 333 | - $texte .= $sep; |
|
| 334 | - } |
|
| 335 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 336 | - $texte .= |
|
| 337 | - (!is_array($_credit)) |
|
| 338 | - ? PtoBR(propre($_credit)) |
|
| 339 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 340 | - $_credit['nom'] . |
|
| 341 | - ($_credit['url'] ? '</a>' : ''); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return $texte; |
|
| 329 | + $texte = ''; |
|
| 330 | + |
|
| 331 | + foreach ($infos as $_credit) { |
|
| 332 | + if ($texte) { |
|
| 333 | + $texte .= $sep; |
|
| 334 | + } |
|
| 335 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 336 | + $texte .= |
|
| 337 | + (!is_array($_credit)) |
|
| 338 | + ? PtoBR(propre($_credit)) |
|
| 339 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 340 | + $_credit['nom'] . |
|
| 341 | + ($_credit['url'] ? '</a>' : ''); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return $texte; |
|
| 345 | 345 | } |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | $class_li .= " error"; |
| 57 | 57 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
| 58 | 58 | _T('plugin_info_erreur_xml')) |
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 59 | + . "<div class='erreur'>".join('<br >', $info['erreur'])."</div>"; |
|
| 60 | 60 | $checkable = false; |
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 62 | 62 | $class_li .= " error"; |
| 63 | 63 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
| 64 | 64 | " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 65 | + . "<div class='erreur'>".implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])."</div>"; |
|
| 67 | 67 | } else { |
| 68 | 68 | $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
| 69 | 69 | } |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | // numerotons les occurrences d'un meme prefix |
| 72 | 72 | $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
| 73 | 73 | |
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 74 | + $class_li .= ($actif ? " actif" : "").($expose ? " on" : ""); |
|
| 75 | 75 | |
| 76 | 76 | return "<li id='$prefix$id' class='$class_li'>" |
| 77 | 77 | . ((!$checkable and !$checked) |
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 79 | 79 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 80 | 80 | . $cfg |
| 81 | 81 | . $erreur |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | $prefix = strtolower($infos['prefix']); |
| 94 | 94 | // si paquet.xml fournit un squelette, le prendre |
| 95 | 95 | if (isset($infos['config']) and $infos['config']) { |
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 96 | + return recuperer_fond("$dir$nom/".$infos['config'], |
|
| 97 | 97 | array( |
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 98 | + 'script' => 'configurer_'.$prefix, |
|
| 99 | 99 | 'nom' => $nom |
| 100 | 100 | )); |
| 101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // sinon prendre le squelette std sur le nom std |
| 114 | 114 | return recuperer_fond("prive/squelettes/inclure/cfg", |
| 115 | 115 | array( |
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 116 | + 'script' => 'configurer_'.$prefix, |
|
| 117 | 117 | 'nom' => $nom |
| 118 | 118 | )); |
| 119 | 119 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 129 | 129 | . ($actif ? " checked='checked'" : "") |
| 130 | 130 | . " class='checkbox' value='O' />" |
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 131 | + . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
|
| 132 | 132 | . "</div>"; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | . "<h3><a href='$url' rel='info'>" |
| 177 | 177 | . $nom |
| 178 | 178 | . "</a></h3>" |
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 179 | + . " <span class='version'>".$info['version']."</span>" |
|
| 180 | 180 | . " <span class='etat'> - " |
| 181 | 181 | . plugin_etat_en_clair($info['etat']) |
| 182 | 182 | . "</span>" |
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 183 | + . "<div class='short'>".$slogan."</div>" |
|
| 184 | 184 | . $i |
| 185 | 185 | . "</div>"; |
| 186 | 186 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $text2 = _T('info_desinstaller_plugin'); |
| 196 | 196 | $file = basename($plug_file); |
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 198 | + return "<div class='actions'>[". |
|
| 199 | 199 | "<a href='$action' |
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | 201 | . $text |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $etat = 'developpement'; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_'.$etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $module = substr($module, strlen(_DIR_RACINE)); |
| 228 | 228 | } |
| 229 | 229 | if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 230 | + $texte = _T(($module ? "$module:" : '').$texte, array(), array('force' => false)); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return propre($texte); |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | if (isset($info['documentation']) |
| 256 | 256 | and $lien = $info['documentation'] |
| 257 | 257 | ) { |
| 258 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 258 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 259 | 259 | } |
| 260 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 260 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 261 | 261 | |
| 262 | 262 | if (isset($info['auteur'])) { |
| 263 | 263 | if (is_array($info['auteur'])) { |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | $a = trim($info['auteur']); |
| 268 | 268 | } |
| 269 | 269 | if ($a) { |
| 270 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 271 | - $dir)) . "</dd>\n"; |
|
| 270 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre($a, |
|
| 271 | + $dir))."</dd>\n"; |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | if (isset($info['credit'])) { |
| 276 | 276 | if ($a = formater_credits($info['credit'], ', ')) { |
| 277 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 278 | - $dir)) . "</dd>\n"; |
|
| 277 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre($a, |
|
| 278 | + $dir))."</dd>\n"; |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | $a = trim($info['licence']); |
| 288 | 288 | } |
| 289 | 289 | if ($a) { |
| 290 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 291 | - $dir)) . "</dd>\n"; |
|
| 290 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre($a, |
|
| 291 | + $dir))."</dd>\n"; |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
@@ -299,23 +299,22 @@ discard block |
||
| 299 | 299 | // |
| 300 | 300 | $infotech = array(); |
| 301 | 301 | |
| 302 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 302 | + $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
|
| 303 | 303 | // Version SVN |
| 304 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 305 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 304 | + if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) { |
|
| 305 | + $version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']'; |
|
| 306 | 306 | } |
| 307 | 307 | $version .= "</dd>"; |
| 308 | 308 | $infotech[] = $version; |
| 309 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 309 | + $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
|
| 310 | 310 | // source zip le cas echeant |
| 311 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 311 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 312 | 312 | and preg_match(',^source:(.*)$,m', $log, $r)) |
| 313 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 313 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
|
| 314 | 314 | : ''; |
| 315 | 315 | |
| 316 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 317 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 318 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 316 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join(' ', |
|
| 317 | + array_map('array_shift', $info['necessite'])).'</dd>'); |
|
| 319 | 318 | |
| 320 | 319 | $s .= "<dl class='tech'>" |
| 321 | 320 | . join('', $infotech) |
@@ -336,8 +335,8 @@ discard block |
||
| 336 | 335 | $texte .= |
| 337 | 336 | (!is_array($_credit)) |
| 338 | 337 | ? PtoBR(propre($_credit)) |
| 339 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 340 | - $_credit['nom'] . |
|
| 338 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 339 | + $_credit['nom']. |
|
| 341 | 340 | ($_credit['url'] ? '</a>' : ''); |
| 342 | 341 | } |
| 343 | 342 | |
@@ -75,11 +75,19 @@ |
||
| 75 | 75 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | +/** |
|
| 79 | + * @param string $racine |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 78 | 83 | function chemin_plug($racine, $plug) { |
| 79 | 84 | return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | // http://code.spip.net/@tree_open_close_dir |
| 88 | +/** |
|
| 89 | + * @param string $target |
|
| 90 | + */ |
|
| 83 | 91 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | 92 | if ($current == $target) { |
| 85 | 93 | return ""; |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // http://code.spip.net/@affiche_arbre_plugins |
| 18 | 18 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 19 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | - $racine = basename(_DIR_PLUGINS); |
|
| 21 | - $init_dir = $current_dir = ""; |
|
| 22 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | - // des qu'un path est deja note deplie on s'arrete |
|
| 24 | - $deplie = array($racine => true); |
|
| 25 | - $fast_liste_plugins_actifs = array(); |
|
| 26 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | - $dir = dirname($chemin_plug); |
|
| 30 | - $maxiter = 100; |
|
| 31 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | - $deplie[$dir] = true; |
|
| 33 | - $dir = dirname($dir); |
|
| 34 | - } |
|
| 35 | - } |
|
| 19 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | + $racine = basename(_DIR_PLUGINS); |
|
| 21 | + $init_dir = $current_dir = ""; |
|
| 22 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | + // des qu'un path est deja note deplie on s'arrete |
|
| 24 | + $deplie = array($racine => true); |
|
| 25 | + $fast_liste_plugins_actifs = array(); |
|
| 26 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | + $dir = dirname($chemin_plug); |
|
| 30 | + $maxiter = 100; |
|
| 31 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | + $deplie[$dir] = true; |
|
| 33 | + $dir = dirname($dir); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // index repertoires --> plugin |
|
| 38 | - $dir_index = array(); |
|
| 39 | - foreach ($liste_plugins as $key => $plug) { |
|
| 40 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | - } |
|
| 37 | + // index repertoires --> plugin |
|
| 38 | + $dir_index = array(); |
|
| 39 | + foreach ($liste_plugins as $key => $plug) { |
|
| 40 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $visible = @isset($deplie[$current_dir]); |
|
| 45 | - $maxiter = 1000; |
|
| 44 | + $visible = @isset($deplie[$current_dir]); |
|
| 45 | + $maxiter = 1000; |
|
| 46 | 46 | |
| 47 | - $res = ''; |
|
| 48 | - while (count($liste_plugins) && $maxiter--) { |
|
| 49 | - // le rep suivant |
|
| 50 | - $dir = dirname(reset($liste_plugins)); |
|
| 51 | - if ($dir != $current_dir) { |
|
| 52 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | - } |
|
| 47 | + $res = ''; |
|
| 48 | + while (count($liste_plugins) && $maxiter--) { |
|
| 49 | + // le rep suivant |
|
| 50 | + $dir = dirname(reset($liste_plugins)); |
|
| 51 | + if ($dir != $current_dir) { |
|
| 52 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // d'abord tous les plugins du rep courant |
|
| 56 | - if (isset($dir_index[$current_dir])) { |
|
| 57 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | - $plug = $liste_plugins[$key]; |
|
| 59 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | - $id = substr(md5($plug), 0, 16); |
|
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 63 | - unset($liste_plugins[$key]); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 55 | + // d'abord tous les plugins du rep courant |
|
| 56 | + if (isset($dir_index[$current_dir])) { |
|
| 57 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | + $plug = $liste_plugins[$key]; |
|
| 59 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | + $id = substr(md5($plug), 0, 16); |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | + 'menu-entree') . "\n"; |
|
| 63 | + unset($liste_plugins[$key]); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 68 | 68 | |
| 69 | - return "<ul class='menu-liste plugins'>" |
|
| 70 | - . $res |
|
| 71 | - . "</ul>"; |
|
| 69 | + return "<ul class='menu-liste plugins'>" |
|
| 70 | + . $res |
|
| 71 | + . "</ul>"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -76,44 +76,44 @@ discard block |
||
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | 78 | function chemin_plug($racine, $plug) { |
| 79 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 79 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // http://code.spip.net/@tree_open_close_dir |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ""; |
|
| 86 | - } |
|
| 87 | - $tcur = explode("/", $current); |
|
| 88 | - $ttarg = explode("/", $target); |
|
| 89 | - $tcom = array(); |
|
| 90 | - $output = ""; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) == reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ""; |
|
| 103 | - if (count($tcom)) { |
|
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 110 | - $output .= "<li>"; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ""; |
|
| 86 | + } |
|
| 87 | + $tcur = explode("/", $current); |
|
| 88 | + $ttarg = explode("/", $target); |
|
| 89 | + $tcom = array(); |
|
| 90 | + $output = ""; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) == reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ""; |
|
| 103 | + if (count($tcom)) { |
|
| 104 | + $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . "/"; |
|
| 110 | + $output .= "<li>"; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | $plug = $liste_plugins[$key]; |
| 59 | 59 | $actif = @isset($fast_liste_plugins_actifs[$plug]); |
| 60 | 60 | $id = substr(md5($plug), 0, 16); |
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), $actif, |
|
| 62 | + 'menu-entree')."\n"; |
|
| 63 | 63 | unset($liste_plugins[$key]); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ""; |
| 103 | 103 | if (count($tcom)) { |
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 104 | + $chemin .= implode("/", $tcom)."/"; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open."/"; |
|
| 110 | 110 | $output .= "<li>"; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |
@@ -14,6 +14,9 @@ |
||
| 14 | 14 | return; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | +/** |
|
| 18 | + * @return string|null |
|
| 19 | + */ |
|
| 17 | 20 | function securiser_redirect_action($redirect) { |
| 18 | 21 | if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
| 19 | 22 | and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
@@ -11,146 +11,146 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 19 | - and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 20 | - // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 21 | - // c'est encore le plus simple |
|
| 22 | - $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 23 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 24 | - return $redirect; |
|
| 25 | - } |
|
| 26 | - $base = url_de_base(); |
|
| 27 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 28 | - return $redirect; |
|
| 29 | - } |
|
| 18 | + if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 19 | + and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 20 | + // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 21 | + // c'est encore le plus simple |
|
| 22 | + $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 23 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 24 | + return $redirect; |
|
| 25 | + } |
|
| 26 | + $base = url_de_base(); |
|
| 27 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 28 | + return $redirect; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return ""; |
|
| 32 | - } |
|
| 31 | + return ""; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return $redirect; |
|
| 34 | + return $redirect; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // http://code.spip.net/@traiter_appels_actions |
| 38 | 38 | function traiter_appels_actions() { |
| 39 | - // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 40 | - if ($action = _request('action')) { |
|
| 41 | - include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 42 | - include_spip('inc/autoriser'); |
|
| 43 | - include_spip('inc/headers'); |
|
| 44 | - include_spip('inc/actions'); |
|
| 45 | - // des actions peuvent appeler _T |
|
| 46 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 47 | - include_spip('inc/lang'); |
|
| 48 | - utiliser_langue_visiteur(); |
|
| 49 | - } |
|
| 50 | - // si l'action est provoque par un hit {ajax} |
|
| 51 | - // il faut transmettre l'env ajax au redirect |
|
| 52 | - // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 53 | - if (($v = _request('var_ajax')) |
|
| 54 | - and ($v !== 'form') |
|
| 55 | - and ($args = _request('var_ajax_env')) |
|
| 56 | - and ($url = _request('redirect')) |
|
| 57 | - ) { |
|
| 58 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 59 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 60 | - set_request('redirect', $url); |
|
| 61 | - } else { |
|
| 62 | - if (_request('redirect')) { |
|
| 63 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $var_f = charger_fonction($action, 'action'); |
|
| 67 | - $var_f(); |
|
| 68 | - if (!isset($GLOBALS['redirect'])) { |
|
| 69 | - $GLOBALS['redirect'] = _request('redirect'); |
|
| 70 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 71 | - $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 72 | - } |
|
| 73 | - $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 74 | - } |
|
| 75 | - if ($url = $GLOBALS['redirect']) { |
|
| 76 | - // si l'action est provoque par un hit {ajax} |
|
| 77 | - // il faut transmettre l'env ajax au redirect |
|
| 78 | - // qui a pu etre defini par l'action |
|
| 79 | - if (($v = _request('var_ajax')) |
|
| 80 | - and ($v !== 'form') |
|
| 81 | - and ($args = _request('var_ajax_env')) |
|
| 82 | - ) { |
|
| 83 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 84 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 85 | - // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 86 | - $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 87 | - } |
|
| 88 | - $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 89 | - redirige_par_entete($url); |
|
| 90 | - } |
|
| 91 | - if (!headers_sent() |
|
| 92 | - and !ob_get_length() |
|
| 93 | - ) { |
|
| 94 | - http_status(204); |
|
| 95 | - } // No Content |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 39 | + // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 40 | + if ($action = _request('action')) { |
|
| 41 | + include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 42 | + include_spip('inc/autoriser'); |
|
| 43 | + include_spip('inc/headers'); |
|
| 44 | + include_spip('inc/actions'); |
|
| 45 | + // des actions peuvent appeler _T |
|
| 46 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 47 | + include_spip('inc/lang'); |
|
| 48 | + utiliser_langue_visiteur(); |
|
| 49 | + } |
|
| 50 | + // si l'action est provoque par un hit {ajax} |
|
| 51 | + // il faut transmettre l'env ajax au redirect |
|
| 52 | + // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 53 | + if (($v = _request('var_ajax')) |
|
| 54 | + and ($v !== 'form') |
|
| 55 | + and ($args = _request('var_ajax_env')) |
|
| 56 | + and ($url = _request('redirect')) |
|
| 57 | + ) { |
|
| 58 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 59 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 60 | + set_request('redirect', $url); |
|
| 61 | + } else { |
|
| 62 | + if (_request('redirect')) { |
|
| 63 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $var_f = charger_fonction($action, 'action'); |
|
| 67 | + $var_f(); |
|
| 68 | + if (!isset($GLOBALS['redirect'])) { |
|
| 69 | + $GLOBALS['redirect'] = _request('redirect'); |
|
| 70 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 71 | + $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 72 | + } |
|
| 73 | + $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 74 | + } |
|
| 75 | + if ($url = $GLOBALS['redirect']) { |
|
| 76 | + // si l'action est provoque par un hit {ajax} |
|
| 77 | + // il faut transmettre l'env ajax au redirect |
|
| 78 | + // qui a pu etre defini par l'action |
|
| 79 | + if (($v = _request('var_ajax')) |
|
| 80 | + and ($v !== 'form') |
|
| 81 | + and ($args = _request('var_ajax_env')) |
|
| 82 | + ) { |
|
| 83 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 84 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 85 | + // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 86 | + $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 87 | + } |
|
| 88 | + $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 89 | + redirige_par_entete($url); |
|
| 90 | + } |
|
| 91 | + if (!headers_sent() |
|
| 92 | + and !ob_get_length() |
|
| 93 | + ) { |
|
| 94 | + http_status(204); |
|
| 95 | + } // No Content |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - return false; |
|
| 99 | + return false; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | // http://code.spip.net/@refuser_traiter_formulaire_ajax |
| 104 | 104 | function refuser_traiter_formulaire_ajax() { |
| 105 | - if ($v = _request('var_ajax') |
|
| 106 | - and $v == 'form' |
|
| 107 | - and $form = _request('formulaire_action') |
|
| 108 | - and $args = _request('formulaire_action_args') |
|
| 109 | - and decoder_contexte_ajax($args, $form) !== false |
|
| 110 | - ) { |
|
| 111 | - // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 112 | - // mais traiter ne veut pas |
|
| 113 | - // on le dit a la page qui va resumbit |
|
| 114 | - // sans ajax |
|
| 115 | - include_spip('inc/actions'); |
|
| 116 | - ajax_retour('noajax', false); |
|
| 117 | - exit; |
|
| 118 | - } |
|
| 105 | + if ($v = _request('var_ajax') |
|
| 106 | + and $v == 'form' |
|
| 107 | + and $form = _request('formulaire_action') |
|
| 108 | + and $args = _request('formulaire_action_args') |
|
| 109 | + and decoder_contexte_ajax($args, $form) !== false |
|
| 110 | + ) { |
|
| 111 | + // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 112 | + // mais traiter ne veut pas |
|
| 113 | + // on le dit a la page qui va resumbit |
|
| 114 | + // sans ajax |
|
| 115 | + include_spip('inc/actions'); |
|
| 116 | + ajax_retour('noajax', false); |
|
| 117 | + exit; |
|
| 118 | + } |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // http://code.spip.net/@traiter_appels_inclusions_ajax |
| 122 | 122 | function traiter_appels_inclusions_ajax() { |
| 123 | - // traiter les appels de bloc ajax (ex: pagination) |
|
| 124 | - if ($v = _request('var_ajax') |
|
| 125 | - and $v !== 'form' |
|
| 126 | - and $args = _request('var_ajax_env') |
|
| 127 | - ) { |
|
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - include_spip('inc/actions'); |
|
| 130 | - if ($args = decoder_contexte_ajax($args) |
|
| 131 | - and $fond = $args['fond'] |
|
| 132 | - ) { |
|
| 133 | - include_spip('public/assembler'); |
|
| 134 | - $contexte = calculer_contexte(); |
|
| 135 | - $contexte = array_merge($args, $contexte); |
|
| 136 | - $page = recuperer_fond($fond, $contexte, array('trim' => false)); |
|
| 137 | - $texte = $page; |
|
| 138 | - if ($ancre = _request('var_ajax_ancre')) { |
|
| 139 | - // pas n'importe quoi quand meme dans la variable ! |
|
| 140 | - $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
|
| 141 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 142 | - } |
|
| 143 | - } else { |
|
| 144 | - include_spip('inc/headers'); |
|
| 145 | - http_status(403); |
|
| 146 | - $texte = _L('signature ajax bloc incorrecte'); |
|
| 147 | - } |
|
| 148 | - ajax_retour($texte, false); |
|
| 123 | + // traiter les appels de bloc ajax (ex: pagination) |
|
| 124 | + if ($v = _request('var_ajax') |
|
| 125 | + and $v !== 'form' |
|
| 126 | + and $args = _request('var_ajax_env') |
|
| 127 | + ) { |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + include_spip('inc/actions'); |
|
| 130 | + if ($args = decoder_contexte_ajax($args) |
|
| 131 | + and $fond = $args['fond'] |
|
| 132 | + ) { |
|
| 133 | + include_spip('public/assembler'); |
|
| 134 | + $contexte = calculer_contexte(); |
|
| 135 | + $contexte = array_merge($args, $contexte); |
|
| 136 | + $page = recuperer_fond($fond, $contexte, array('trim' => false)); |
|
| 137 | + $texte = $page; |
|
| 138 | + if ($ancre = _request('var_ajax_ancre')) { |
|
| 139 | + // pas n'importe quoi quand meme dans la variable ! |
|
| 140 | + $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
|
| 141 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 142 | + } |
|
| 143 | + } else { |
|
| 144 | + include_spip('inc/headers'); |
|
| 145 | + http_status(403); |
|
| 146 | + $texte = _L('signature ajax bloc incorrecte'); |
|
| 147 | + } |
|
| 148 | + ajax_retour($texte, false); |
|
| 149 | 149 | |
| 150 | - return true; // on a fini le hit |
|
| 151 | - } |
|
| 150 | + return true; // on a fini le hit |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return false; |
|
| 153 | + return false; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter |
@@ -159,148 +159,148 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // http://code.spip.net/@traiter_formulaires_dynamiques |
| 161 | 161 | function traiter_formulaires_dynamiques($get = false) { |
| 162 | - static $post = array(); |
|
| 163 | - static $done = false; |
|
| 162 | + static $post = array(); |
|
| 163 | + static $done = false; |
|
| 164 | 164 | |
| 165 | - if ($get) { |
|
| 166 | - return $post; |
|
| 167 | - } |
|
| 168 | - if ($done) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - $done = true; |
|
| 165 | + if ($get) { |
|
| 166 | + return $post; |
|
| 167 | + } |
|
| 168 | + if ($done) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + $done = true; |
|
| 172 | 172 | |
| 173 | - if (!($form = _request('formulaire_action') |
|
| 174 | - and $args = _request('formulaire_action_args')) |
|
| 175 | - ) { |
|
| 176 | - return false; |
|
| 177 | - } // le hit peut continuer normalement |
|
| 173 | + if (!($form = _request('formulaire_action') |
|
| 174 | + and $args = _request('formulaire_action_args')) |
|
| 175 | + ) { |
|
| 176 | + return false; |
|
| 177 | + } // le hit peut continuer normalement |
|
| 178 | 178 | |
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 181 | - spip_log("signature ajax form incorrecte : $form"); |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 181 | + spip_log("signature ajax form incorrecte : $form"); |
|
| 182 | 182 | |
| 183 | - return false; // continuons le hit comme si de rien etait |
|
| 184 | - } else { |
|
| 185 | - include_spip('inc/lang'); |
|
| 186 | - // sauvegarder la lang en cours |
|
| 187 | - $old_lang = $GLOBALS['spip_lang']; |
|
| 188 | - // changer la langue avec celle qui a cours dans le formulaire |
|
| 189 | - // on la depile de $args car c'est un argument implicite masque |
|
| 190 | - changer_langue(array_shift($args)); |
|
| 183 | + return false; // continuons le hit comme si de rien etait |
|
| 184 | + } else { |
|
| 185 | + include_spip('inc/lang'); |
|
| 186 | + // sauvegarder la lang en cours |
|
| 187 | + $old_lang = $GLOBALS['spip_lang']; |
|
| 188 | + // changer la langue avec celle qui a cours dans le formulaire |
|
| 189 | + // on la depile de $args car c'est un argument implicite masque |
|
| 190 | + changer_langue(array_shift($args)); |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | - // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 194 | - include_spip('public/parametrer'); |
|
| 195 | - // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 196 | - include_spip('base/abstract_sql'); |
|
| 193 | + // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 194 | + include_spip('public/parametrer'); |
|
| 195 | + // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 196 | + include_spip('base/abstract_sql'); |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 200 | - * mais avant l'appel de la fonction de vérification. |
|
| 201 | - */ |
|
| 202 | - pipeline( |
|
| 203 | - 'formulaire_receptionner', |
|
| 204 | - array( |
|
| 205 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 206 | - 'data' => null, |
|
| 207 | - ) |
|
| 208 | - ); |
|
| 198 | + /** |
|
| 199 | + * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 200 | + * mais avant l'appel de la fonction de vérification. |
|
| 201 | + */ |
|
| 202 | + pipeline( |
|
| 203 | + 'formulaire_receptionner', |
|
| 204 | + array( |
|
| 205 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 206 | + 'data' => null, |
|
| 207 | + ) |
|
| 208 | + ); |
|
| 209 | 209 | |
| 210 | - $verifier = charger_fonction("verifier", "formulaires/$form/", true); |
|
| 211 | - $post["erreurs_$form"] = pipeline( |
|
| 212 | - 'formulaire_verifier', |
|
| 213 | - array( |
|
| 214 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 215 | - 'data' => $verifier ? call_user_func_array($verifier, $args) : array() |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 218 | - // prise en charge CVT multi etape si besoin |
|
| 219 | - if (_request('cvtm_prev_post')) { |
|
| 220 | - include_spip('inc/cvt_multietapes'); |
|
| 221 | - $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 222 | - array('form' => $form, 'args' => $args), |
|
| 223 | - $post["erreurs_$form"] |
|
| 224 | - ); |
|
| 225 | - } |
|
| 210 | + $verifier = charger_fonction("verifier", "formulaires/$form/", true); |
|
| 211 | + $post["erreurs_$form"] = pipeline( |
|
| 212 | + 'formulaire_verifier', |
|
| 213 | + array( |
|
| 214 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 215 | + 'data' => $verifier ? call_user_func_array($verifier, $args) : array() |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | + // prise en charge CVT multi etape si besoin |
|
| 219 | + if (_request('cvtm_prev_post')) { |
|
| 220 | + include_spip('inc/cvt_multietapes'); |
|
| 221 | + $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 222 | + array('form' => $form, 'args' => $args), |
|
| 223 | + $post["erreurs_$form"] |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 228 | - if (count($post["erreurs_$form"]) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 229 | - $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(count($post["erreurs_$form"]), |
|
| 230 | - 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 231 | - } |
|
| 227 | + // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 228 | + if (count($post["erreurs_$form"]) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 229 | + $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(count($post["erreurs_$form"]), |
|
| 230 | + 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // si on ne demandait qu'une verif json |
|
| 234 | - if (_request('formulaire_action_verifier_json')) { |
|
| 235 | - include_spip('inc/json'); |
|
| 236 | - include_spip('inc/actions'); |
|
| 237 | - ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 233 | + // si on ne demandait qu'une verif json |
|
| 234 | + if (_request('formulaire_action_verifier_json')) { |
|
| 235 | + include_spip('inc/json'); |
|
| 236 | + include_spip('inc/actions'); |
|
| 237 | + ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 238 | 238 | |
| 239 | - return true; // on a fini le hit |
|
| 240 | - } |
|
| 241 | - $retour = ""; |
|
| 242 | - if ((count($post["erreurs_$form"]) == 0)) { |
|
| 243 | - $rev = ""; |
|
| 244 | - if ($traiter = charger_fonction("traiter", "formulaires/$form/", true)) { |
|
| 245 | - $rev = call_user_func_array($traiter, $args); |
|
| 246 | - } |
|
| 239 | + return true; // on a fini le hit |
|
| 240 | + } |
|
| 241 | + $retour = ""; |
|
| 242 | + if ((count($post["erreurs_$form"]) == 0)) { |
|
| 243 | + $rev = ""; |
|
| 244 | + if ($traiter = charger_fonction("traiter", "formulaires/$form/", true)) { |
|
| 245 | + $rev = call_user_func_array($traiter, $args); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - $rev = pipeline( |
|
| 249 | - 'formulaire_traiter', |
|
| 250 | - array( |
|
| 251 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 252 | - 'data' => $rev |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - // le retour de traiter est |
|
| 256 | - // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 257 | - // il permet le pipelinage, en particulier |
|
| 258 | - // en y passant l'id de l'objet cree/modifie |
|
| 259 | - // si message_erreur est present, on considere que le traitement a echoue |
|
| 260 | - $post["message_ok_$form"] = ''; |
|
| 261 | - // on peut avoir message_ok et message_erreur |
|
| 262 | - if (isset($rev['message_ok'])) { |
|
| 263 | - $post["message_ok_$form"] = $rev['message_ok']; |
|
| 264 | - } |
|
| 248 | + $rev = pipeline( |
|
| 249 | + 'formulaire_traiter', |
|
| 250 | + array( |
|
| 251 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 252 | + 'data' => $rev |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + // le retour de traiter est |
|
| 256 | + // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 257 | + // il permet le pipelinage, en particulier |
|
| 258 | + // en y passant l'id de l'objet cree/modifie |
|
| 259 | + // si message_erreur est present, on considere que le traitement a echoue |
|
| 260 | + $post["message_ok_$form"] = ''; |
|
| 261 | + // on peut avoir message_ok et message_erreur |
|
| 262 | + if (isset($rev['message_ok'])) { |
|
| 263 | + $post["message_ok_$form"] = $rev['message_ok']; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // verifier si traiter n'a pas echoue avec une erreur : |
|
| 267 | - if (isset($rev['message_erreur'])) { |
|
| 268 | - $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 269 | - // si il y a une erreur on ne redirige pas |
|
| 270 | - } else { |
|
| 271 | - // sinon faire ce qu'il faut : |
|
| 272 | - if (isset($rev['editable'])) { |
|
| 273 | - $post["editable_$form"] = $rev['editable']; |
|
| 274 | - } |
|
| 275 | - // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 276 | - // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 277 | - if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 278 | - include_spip('inc/headers'); |
|
| 279 | - list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 280 | - $post["message_ok_$form"] .= $message; |
|
| 281 | - $retour .= $masque; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 286 | - if (_request('var_ajax')) { |
|
| 287 | - if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 288 | - include_spip('inc/actions'); |
|
| 289 | - include_spip('public/assembler'); |
|
| 290 | - array_unshift($args, $form); |
|
| 291 | - $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 292 | - // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 293 | - // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 294 | - // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 295 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 296 | - ajax_retour($retour, false); |
|
| 266 | + // verifier si traiter n'a pas echoue avec une erreur : |
|
| 267 | + if (isset($rev['message_erreur'])) { |
|
| 268 | + $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 269 | + // si il y a une erreur on ne redirige pas |
|
| 270 | + } else { |
|
| 271 | + // sinon faire ce qu'il faut : |
|
| 272 | + if (isset($rev['editable'])) { |
|
| 273 | + $post["editable_$form"] = $rev['editable']; |
|
| 274 | + } |
|
| 275 | + // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 276 | + // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 277 | + if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 278 | + include_spip('inc/headers'); |
|
| 279 | + list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 280 | + $post["message_ok_$form"] .= $message; |
|
| 281 | + $retour .= $masque; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 286 | + if (_request('var_ajax')) { |
|
| 287 | + if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 288 | + include_spip('inc/actions'); |
|
| 289 | + include_spip('public/assembler'); |
|
| 290 | + array_unshift($args, $form); |
|
| 291 | + $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 292 | + // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 293 | + // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 294 | + // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 295 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 296 | + ajax_retour($retour, false); |
|
| 297 | 297 | |
| 298 | - return true; // on a fini le hit |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - // restaurer la lang en cours |
|
| 302 | - changer_langue($old_lang); |
|
| 303 | - } |
|
| 298 | + return true; // on a fini le hit |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + // restaurer la lang en cours |
|
| 302 | + changer_langue($old_lang); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - return false; // le hit peut continuer normalement |
|
| 305 | + return false; // le hit peut continuer normalement |
|
| 306 | 306 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 18 | + if ((tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 19 | 19 | and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
| 20 | 20 | // si l'url est une url du site, on la laisse passer sans rien faire |
| 21 | 21 | // c'est encore le plus simple |
| 22 | - $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 22 | + $base = $GLOBALS['meta']['adresse_site']."/"; |
|
| 23 | 23 | if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
| 24 | 24 | return $redirect; |
| 25 | 25 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | if ($ancre = _request('var_ajax_ancre')) { |
| 139 | 139 | // pas n'importe quoi quand meme dans la variable ! |
| 140 | 140 | $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
| 141 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 141 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>".$texte; |
|
| 142 | 142 | } |
| 143 | 143 | } else { |
| 144 | 144 | include_spip('inc/headers'); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
| 293 | 293 | // sans cela le formulaire n'est pas actif apres le hit ajax |
| 294 | 294 | // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
| 295 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 295 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>".$retour; |
|
| 296 | 296 | ajax_retour($retour, false); |
| 297 | 297 | |
| 298 | 298 | return true; // on a fini le hit |
@@ -59,6 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | +/** |
|
| 63 | + * @param boolean $rejet_filtres |
|
| 64 | + * @param string $id_boucle |
|
| 65 | + */ |
|
| 62 | 66 | function argumenter_inclure( |
| 63 | 67 | $params, |
| 64 | 68 | $rejet_filtres, |
@@ -747,7 +751,7 @@ discard block |
||
| 747 | 751 | * Nom de la commande |
| 748 | 752 | * @param string $val |
| 749 | 753 | * Code PHP décrivant la valeur à affecter |
| 750 | - * @return array |
|
| 754 | + * @return string[] |
|
| 751 | 755 | * |
| 752 | 756 | * - index 0 : Code pour une affectation statique. Si non rempli, la propriété devra |
| 753 | 757 | * être ré-affectée à chaque appel de la boucle. |
@@ -855,6 +859,9 @@ discard block |
||
| 855 | 859 | } |
| 856 | 860 | |
| 857 | 861 | // http://code.spip.net/@calculer_order |
| 862 | +/** |
|
| 863 | + * @param Boucle $boucle |
|
| 864 | + */ |
|
| 858 | 865 | function calculer_order(&$boucle) { |
| 859 | 866 | if (!$order = $boucle->order |
| 860 | 867 | and !$order = $boucle->default_order |
@@ -924,6 +931,9 @@ discard block |
||
| 924 | 931 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 925 | 932 | |
| 926 | 933 | // http://code.spip.net/@compile_cas |
| 934 | +/** |
|
| 935 | + * @param string $id_boucle |
|
| 936 | + */ |
|
| 927 | 937 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 928 | 938 | |
| 929 | 939 | $codes = array(); |
@@ -1113,6 +1123,9 @@ discard block |
||
| 1113 | 1123 | // de meme si EXP est de la forme (t ? '' : 'C') |
| 1114 | 1124 | |
| 1115 | 1125 | // http://code.spip.net/@compile_retour |
| 1126 | +/** |
|
| 1127 | + * @param string $tab |
|
| 1128 | + */ |
|
| 1116 | 1129 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1117 | 1130 | if ($avant == "''") { |
| 1118 | 1131 | $avant = ''; |
@@ -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 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -60,91 +60,91 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | 62 | function argumenter_inclure( |
| 63 | - $params, |
|
| 64 | - $rejet_filtres, |
|
| 65 | - $p, |
|
| 66 | - &$boucles, |
|
| 67 | - $id_boucle, |
|
| 68 | - $echap = true, |
|
| 69 | - $lang = '', |
|
| 70 | - $fond1 = false |
|
| 63 | + $params, |
|
| 64 | + $rejet_filtres, |
|
| 65 | + $p, |
|
| 66 | + &$boucles, |
|
| 67 | + $id_boucle, |
|
| 68 | + $echap = true, |
|
| 69 | + $lang = '', |
|
| 70 | + $fond1 = false |
|
| 71 | 71 | ) { |
| 72 | - $l = array(); |
|
| 73 | - $erreur_p_i_i = ''; |
|
| 74 | - if (!is_array($params)) { |
|
| 75 | - return $l; |
|
| 76 | - } |
|
| 77 | - foreach ($params as $k => $couple) { |
|
| 78 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | - $filtre = array_shift($couple); |
|
| 80 | - if ($filtre) { |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - foreach ($couple as $n => $val) { |
|
| 84 | - $var = $val[0]; |
|
| 85 | - if ($var->type != 'texte') { |
|
| 86 | - if ($n or $k or $fond1) { |
|
| 87 | - $erreur_p_i_i = array( |
|
| 88 | - 'zbug_parametres_inclus_incorrects', |
|
| 89 | - array('param' => $var->nom_champ) |
|
| 90 | - ); |
|
| 91 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | - break; |
|
| 93 | - } else { |
|
| 94 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | - $m = array_pad($m, 3, null); |
|
| 99 | - $var = $m[1]; |
|
| 100 | - $auto = false;; |
|
| 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; |
|
| 72 | + $l = array(); |
|
| 73 | + $erreur_p_i_i = ''; |
|
| 74 | + if (!is_array($params)) { |
|
| 75 | + return $l; |
|
| 76 | + } |
|
| 77 | + foreach ($params as $k => $couple) { |
|
| 78 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | + $filtre = array_shift($couple); |
|
| 80 | + if ($filtre) { |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + foreach ($couple as $n => $val) { |
|
| 84 | + $var = $val[0]; |
|
| 85 | + if ($var->type != 'texte') { |
|
| 86 | + if ($n or $k or $fond1) { |
|
| 87 | + $erreur_p_i_i = array( |
|
| 88 | + 'zbug_parametres_inclus_incorrects', |
|
| 89 | + array('param' => $var->nom_champ) |
|
| 90 | + ); |
|
| 91 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | + break; |
|
| 93 | + } else { |
|
| 94 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | + $m = array_pad($m, 3, null); |
|
| 99 | + $var = $m[1]; |
|
| 100 | + $auto = false;; |
|
| 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,71 +168,71 @@ 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 | - |
|
| 176 | - } else { |
|
| 177 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | - $fichier = $r[1]; |
|
| 180 | - } else { |
|
| 181 | - $fichier = ''; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - if (!$code or $code === '""') { |
|
| 185 | - $erreur_p_i_i = array( |
|
| 186 | - 'zbug_parametres_inclus_incorrects', |
|
| 187 | - array('param' => $code) |
|
| 188 | - ); |
|
| 189 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | - |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | - |
|
| 195 | - if (is_array($_contexte)) { |
|
| 196 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | - unset($_contexte['env']); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // noter les doublons dans l'appel a public.php |
|
| 202 | - if (isset($_contexte['doublons'])) { |
|
| 203 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | - $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | - unset($_contexte['ajax']); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $_contexte = join(",\n\t", $_contexte); |
|
| 212 | - } else { |
|
| 213 | - return false; |
|
| 214 | - } // j'aurais voulu toucher le fond ... |
|
| 215 | - |
|
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | - |
|
| 218 | - if ($env) { |
|
| 219 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | - } else { |
|
| 226 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | - if ($ajax) { |
|
| 228 | - $_options[] = $ajax; |
|
| 229 | - } |
|
| 230 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - 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 | + |
|
| 176 | + } else { |
|
| 177 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | + $fichier = $r[1]; |
|
| 180 | + } else { |
|
| 181 | + $fichier = ''; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + if (!$code or $code === '""') { |
|
| 185 | + $erreur_p_i_i = array( |
|
| 186 | + 'zbug_parametres_inclus_incorrects', |
|
| 187 | + array('param' => $code) |
|
| 188 | + ); |
|
| 189 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | + |
|
| 195 | + if (is_array($_contexte)) { |
|
| 196 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | + unset($_contexte['env']); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // noter les doublons dans l'appel a public.php |
|
| 202 | + if (isset($_contexte['doublons'])) { |
|
| 203 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | + $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | + unset($_contexte['ajax']); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $_contexte = join(",\n\t", $_contexte); |
|
| 212 | + } else { |
|
| 213 | + return false; |
|
| 214 | + } // j'aurais voulu toucher le fond ... |
|
| 215 | + |
|
| 216 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | + |
|
| 218 | + if ($env) { |
|
| 219 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | + } else { |
|
| 226 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | + if ($ajax) { |
|
| 228 | + $_options[] = $ajax; |
|
| 229 | + } |
|
| 230 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")") . ';'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 251 | 251 | */ |
| 252 | 252 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 253 | - /* |
|
| 253 | + /* |
|
| 254 | 254 | $show['statut'][] = array( |
| 255 | 255 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 256 | 256 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -274,71 +274,71 @@ discard block |
||
| 274 | 274 | champstatut est alors le champ statut sur la tablen |
| 275 | 275 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 276 | 276 | */ |
| 277 | - $id_table = $boucle->id_table; |
|
| 278 | - $show = $boucle->show; |
|
| 279 | - if (isset($show['statut']) and $show['statut']) { |
|
| 280 | - foreach ($show['statut'] as $k => $s) { |
|
| 281 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | - $filtrer = true; |
|
| 283 | - if (isset($s['exception'])) { |
|
| 284 | - foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | - $filtrer = false; |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($filtrer) { |
|
| 293 | - if (is_array($s['champ'])) { |
|
| 294 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | - $jointures = array(); |
|
| 296 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | - foreach ($s['champ'] as $j) { |
|
| 300 | - $id = reset($j); |
|
| 301 | - $def = $trouver_table($id); |
|
| 302 | - $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | - } |
|
| 304 | - $jointures[0][0] = $id_table; |
|
| 305 | - if (!array_search($id, $boucle->from)) { |
|
| 306 | - include_spip('public/jointures'); |
|
| 307 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | - } |
|
| 309 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | - $id = array_search($id, $boucle->from); |
|
| 311 | - } else { |
|
| 312 | - $id = $id_table; |
|
| 313 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | - } |
|
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 316 | - |
|
| 317 | - $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | - include_spip('public/quete'); |
|
| 319 | - if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | - and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | - ) { |
|
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | - array_unshift($boucle->where, |
|
| 324 | - $echapper ? |
|
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | - : |
|
| 327 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - array_unshift($boucle->where, |
|
| 331 | - $echapper ? |
|
| 332 | - "\nquete_condition_statut('$mstatut'," |
|
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | - : |
|
| 337 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 277 | + $id_table = $boucle->id_table; |
|
| 278 | + $show = $boucle->show; |
|
| 279 | + if (isset($show['statut']) and $show['statut']) { |
|
| 280 | + foreach ($show['statut'] as $k => $s) { |
|
| 281 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | + $filtrer = true; |
|
| 283 | + if (isset($s['exception'])) { |
|
| 284 | + foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | + $filtrer = false; |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($filtrer) { |
|
| 293 | + if (is_array($s['champ'])) { |
|
| 294 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | + $jointures = array(); |
|
| 296 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | + foreach ($s['champ'] as $j) { |
|
| 300 | + $id = reset($j); |
|
| 301 | + $def = $trouver_table($id); |
|
| 302 | + $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | + } |
|
| 304 | + $jointures[0][0] = $id_table; |
|
| 305 | + if (!array_search($id, $boucle->from)) { |
|
| 306 | + include_spip('public/jointures'); |
|
| 307 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | + } |
|
| 309 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | + $id = array_search($id, $boucle->from); |
|
| 311 | + } else { |
|
| 312 | + $id = $id_table; |
|
| 313 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | + } |
|
| 315 | + $mstatut = $id . '.' . $statut; |
|
| 316 | + |
|
| 317 | + $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | + include_spip('public/quete'); |
|
| 319 | + if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | + and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | + ) { |
|
| 322 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | + array_unshift($boucle->where, |
|
| 324 | + $echapper ? |
|
| 325 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | + : |
|
| 327 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + array_unshift($boucle->where, |
|
| 331 | + $echapper ? |
|
| 332 | + "\nquete_condition_statut('$mstatut'," |
|
| 333 | + . _q($s['previsu']) . "," |
|
| 334 | + . _q($s['publie']) . "," |
|
| 335 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | + : |
|
| 337 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -357,23 +357,23 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function calculer_boucle($id_boucle, &$boucles) { |
| 359 | 359 | |
| 360 | - $boucle = &$boucles[$id_boucle]; |
|
| 361 | - instituer_boucle($boucle); |
|
| 362 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | - |
|
| 364 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | - // mais pas tous, sinon ca pete. |
|
| 366 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | - $trace = ''; |
|
| 368 | - } else { |
|
| 369 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | - $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 360 | + $boucle = &$boucles[$id_boucle]; |
|
| 361 | + instituer_boucle($boucle); |
|
| 362 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | + |
|
| 364 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | + // mais pas tous, sinon ca pete. |
|
| 366 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | + $trace = ''; |
|
| 368 | + } else { |
|
| 369 | + $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | + $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 371 | 371 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 372 | - } |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 375 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 376 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 374 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 375 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 376 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
@@ -396,15 +396,15 @@ discard block |
||
| 396 | 396 | * Code PHP compilé de la boucle récursive |
| 397 | 397 | **/ |
| 398 | 398 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 399 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 400 | - |
|
| 401 | - return |
|
| 402 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 403 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 404 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 405 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 406 | - . $trace |
|
| 407 | - . "\n\treturn \$t0;"; |
|
| 399 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 400 | + |
|
| 401 | + return |
|
| 402 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 403 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 404 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 405 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 406 | + . $trace |
|
| 407 | + . "\n\treturn \$t0;"; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -458,169 +458,169 @@ discard block |
||
| 458 | 458 | **/ |
| 459 | 459 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 460 | 460 | |
| 461 | - $boucle = &$boucles[$id_boucle]; |
|
| 462 | - $return = $boucle->return; |
|
| 463 | - $type_boucle = $boucle->type_requete; |
|
| 464 | - $primary = $boucle->primary; |
|
| 465 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 466 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 467 | - $corps = ''; |
|
| 468 | - |
|
| 469 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 470 | - // et puis faire un [] plutot qu'un "','." |
|
| 471 | - if ($boucle->doublons) { |
|
| 472 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 473 | - index_pile($id_boucle, $primary, $boucles) |
|
| 474 | - . "; // doublons\n"; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - // La boucle doit-elle selectionner la langue ? |
|
| 478 | - // - par defaut, les boucles suivantes le font |
|
| 479 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 480 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 481 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 482 | - (($boucle->lang_select == 'oui') || |
|
| 483 | - in_array($type_boucle, array( |
|
| 484 | - 'articles', |
|
| 485 | - 'rubriques', |
|
| 486 | - 'hierarchie', |
|
| 487 | - 'breves' |
|
| 488 | - ))) |
|
| 489 | - ) { |
|
| 490 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 491 | - // afin que le corps de boucle affecte la globale directement |
|
| 492 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 493 | - $fin_lang = "lang_select();\n\t"; |
|
| 494 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 495 | - |
|
| 496 | - $corps .= |
|
| 497 | - "\n\t\tlang_select_public(" |
|
| 498 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 499 | - . ", '" . $boucle->lang_select . "'" |
|
| 500 | - . (in_array($type_boucle, array( |
|
| 501 | - 'articles', |
|
| 502 | - 'rubriques', |
|
| 503 | - 'hierarchie', |
|
| 504 | - 'breves' |
|
| 505 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | - . ');'; |
|
| 507 | - } else { |
|
| 508 | - $init_lang = ''; |
|
| 509 | - $fin_lang = ''; |
|
| 510 | - $fin_lang_select_public = ''; |
|
| 511 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 512 | - if (strpos($return, '?php') === false |
|
| 513 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 514 | - ) { |
|
| 515 | - $i = 1; |
|
| 516 | - foreach ($r[1] as $t) { |
|
| 517 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 518 | - $return = str_replace($t, "\$l$i", $return); |
|
| 519 | - $i++; |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // gestion optimale des separateurs et des boucles constantes |
|
| 525 | - if (count($boucle->separateur)) { |
|
| 526 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $corps .= |
|
| 530 | - ((!$boucle->separateur) ? |
|
| 531 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | - (($return === "''") ? '' : |
|
| 533 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | - ("\n\t\t\$t1 " . |
|
| 535 | - ((strpos($return, '$t1.') === 0) ? |
|
| 536 | - (".=" . substr($return, 4)) : |
|
| 537 | - ('= ' . $return)) . |
|
| 538 | - ";\n\t\t" . |
|
| 539 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 540 | - |
|
| 541 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 542 | - // souhaite invalider ces elements |
|
| 543 | - if (!$constant and $primary) { |
|
| 544 | - include_spip('inc/invalideur'); |
|
| 545 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // gerer le compteur de boucle |
|
| 549 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 550 | - |
|
| 551 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 552 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 553 | - . $boucle->partie |
|
| 554 | - . $corps; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // depiler la lang de la boucle si besoin |
|
| 558 | - $corps .= $fin_lang_select_public; |
|
| 559 | - |
|
| 560 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 561 | - |
|
| 562 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 563 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 564 | - if (!$boucle->numrows) { |
|
| 565 | - return "\n\t\$t0 = '';"; |
|
| 566 | - } else { |
|
| 567 | - $corps = ""; |
|
| 568 | - } |
|
| 569 | - } else { |
|
| 570 | - $boucle->numrows = true; |
|
| 571 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 572 | - } |
|
| 573 | - } else { |
|
| 574 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $count = ''; |
|
| 578 | - if (!$boucle->select) { |
|
| 579 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 580 | - $count = '1'; |
|
| 581 | - } else { |
|
| 582 | - $count = 'count(*)'; |
|
| 583 | - } |
|
| 584 | - $boucles[$id_boucle]->select[] = $count; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - if ($flag_cpt) { |
|
| 588 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 589 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 590 | - } else { |
|
| 591 | - $nums = ''; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 595 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 596 | - . $boucle->mode_partie |
|
| 597 | - . "\n\t"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // Ne calculer la requete que maintenant |
|
| 601 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 602 | - |
|
| 603 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 604 | - ? ("\n\t$init = array();") : '') |
|
| 605 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 606 | - |
|
| 607 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 608 | - |
|
| 609 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 610 | - $init, |
|
| 611 | - $boucle->iterateur, |
|
| 612 | - "\$command", |
|
| 613 | - $contexte, |
|
| 614 | - $nums, |
|
| 615 | - $init_lang, |
|
| 616 | - $corps, |
|
| 617 | - $fin_lang, |
|
| 618 | - $trace, |
|
| 619 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 620 | - ); |
|
| 461 | + $boucle = &$boucles[$id_boucle]; |
|
| 462 | + $return = $boucle->return; |
|
| 463 | + $type_boucle = $boucle->type_requete; |
|
| 464 | + $primary = $boucle->primary; |
|
| 465 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 466 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 467 | + $corps = ''; |
|
| 468 | + |
|
| 469 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 470 | + // et puis faire un [] plutot qu'un "','." |
|
| 471 | + if ($boucle->doublons) { |
|
| 472 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 473 | + index_pile($id_boucle, $primary, $boucles) |
|
| 474 | + . "; // doublons\n"; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + // La boucle doit-elle selectionner la langue ? |
|
| 478 | + // - par defaut, les boucles suivantes le font |
|
| 479 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 480 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 481 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 482 | + (($boucle->lang_select == 'oui') || |
|
| 483 | + in_array($type_boucle, array( |
|
| 484 | + 'articles', |
|
| 485 | + 'rubriques', |
|
| 486 | + 'hierarchie', |
|
| 487 | + 'breves' |
|
| 488 | + ))) |
|
| 489 | + ) { |
|
| 490 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 491 | + // afin que le corps de boucle affecte la globale directement |
|
| 492 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 493 | + $fin_lang = "lang_select();\n\t"; |
|
| 494 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 495 | + |
|
| 496 | + $corps .= |
|
| 497 | + "\n\t\tlang_select_public(" |
|
| 498 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 499 | + . ", '" . $boucle->lang_select . "'" |
|
| 500 | + . (in_array($type_boucle, array( |
|
| 501 | + 'articles', |
|
| 502 | + 'rubriques', |
|
| 503 | + 'hierarchie', |
|
| 504 | + 'breves' |
|
| 505 | + )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | + . ');'; |
|
| 507 | + } else { |
|
| 508 | + $init_lang = ''; |
|
| 509 | + $fin_lang = ''; |
|
| 510 | + $fin_lang_select_public = ''; |
|
| 511 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 512 | + if (strpos($return, '?php') === false |
|
| 513 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 514 | + ) { |
|
| 515 | + $i = 1; |
|
| 516 | + foreach ($r[1] as $t) { |
|
| 517 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 518 | + $return = str_replace($t, "\$l$i", $return); |
|
| 519 | + $i++; |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // gestion optimale des separateurs et des boucles constantes |
|
| 525 | + if (count($boucle->separateur)) { |
|
| 526 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $corps .= |
|
| 530 | + ((!$boucle->separateur) ? |
|
| 531 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | + (($return === "''") ? '' : |
|
| 533 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | + ("\n\t\t\$t1 " . |
|
| 535 | + ((strpos($return, '$t1.') === 0) ? |
|
| 536 | + (".=" . substr($return, 4)) : |
|
| 537 | + ('= ' . $return)) . |
|
| 538 | + ";\n\t\t" . |
|
| 539 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 540 | + |
|
| 541 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 542 | + // souhaite invalider ces elements |
|
| 543 | + if (!$constant and $primary) { |
|
| 544 | + include_spip('inc/invalideur'); |
|
| 545 | + $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // gerer le compteur de boucle |
|
| 549 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 550 | + |
|
| 551 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 552 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 553 | + . $boucle->partie |
|
| 554 | + . $corps; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // depiler la lang de la boucle si besoin |
|
| 558 | + $corps .= $fin_lang_select_public; |
|
| 559 | + |
|
| 560 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 561 | + |
|
| 562 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 563 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 564 | + if (!$boucle->numrows) { |
|
| 565 | + return "\n\t\$t0 = '';"; |
|
| 566 | + } else { |
|
| 567 | + $corps = ""; |
|
| 568 | + } |
|
| 569 | + } else { |
|
| 570 | + $boucle->numrows = true; |
|
| 571 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $count = ''; |
|
| 578 | + if (!$boucle->select) { |
|
| 579 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 580 | + $count = '1'; |
|
| 581 | + } else { |
|
| 582 | + $count = 'count(*)'; |
|
| 583 | + } |
|
| 584 | + $boucles[$id_boucle]->select[] = $count; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + if ($flag_cpt) { |
|
| 588 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 589 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 590 | + } else { |
|
| 591 | + $nums = ''; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 595 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 596 | + . $boucle->mode_partie |
|
| 597 | + . "\n\t"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // Ne calculer la requete que maintenant |
|
| 601 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 602 | + |
|
| 603 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 604 | + ? ("\n\t$init = array();") : '') |
|
| 605 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 606 | + |
|
| 607 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 608 | + |
|
| 609 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 610 | + $init, |
|
| 611 | + $boucle->iterateur, |
|
| 612 | + "\$command", |
|
| 613 | + $contexte, |
|
| 614 | + $nums, |
|
| 615 | + $init_lang, |
|
| 616 | + $corps, |
|
| 617 | + $fin_lang, |
|
| 618 | + $trace, |
|
| 619 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 620 | + ); |
|
| 621 | 621 | |
| 622 | 622 | # var_dump($a);exit; |
| 623 | - return $a; |
|
| 623 | + return $a; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -636,43 +636,43 @@ discard block |
||
| 636 | 636 | * Code PHP compilé définissant les informations de requête |
| 637 | 637 | **/ |
| 638 | 638 | function calculer_requete_sql($boucle) { |
| 639 | - $init = array(); |
|
| 640 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | - # En absence de champ c'est un decompte : |
|
| 643 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 644 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 645 | - $init[] = calculer_dec('groupby', |
|
| 646 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 649 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 650 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 651 | - $init[] = calculer_dec('limit', |
|
| 652 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 653 | - "'" . $boucle->limit . "'" |
|
| 654 | - : |
|
| 655 | - $boucle->limit)); |
|
| 656 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 657 | - $s = $d = ""; |
|
| 658 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 659 | - // ou recalculée à chaque passage (vide) |
|
| 660 | - foreach ($init as $i) { |
|
| 661 | - if (reset($i)) { |
|
| 662 | - $s .= "\n\t\t" . end($i); |
|
| 663 | - } # statique |
|
| 664 | - else { |
|
| 665 | - $d .= "\n\t" . end($i); |
|
| 666 | - } # dynamique |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 670 | - . $boucle->in |
|
| 671 | - . $boucle->hash |
|
| 672 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 673 | - . $s |
|
| 674 | - . "\n\t}" |
|
| 675 | - . $d; |
|
| 639 | + $init = array(); |
|
| 640 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | + # En absence de champ c'est un decompte : |
|
| 643 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 644 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 645 | + $init[] = calculer_dec('groupby', |
|
| 646 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 649 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 650 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 651 | + $init[] = calculer_dec('limit', |
|
| 652 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 653 | + "'" . $boucle->limit . "'" |
|
| 654 | + : |
|
| 655 | + $boucle->limit)); |
|
| 656 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 657 | + $s = $d = ""; |
|
| 658 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 659 | + // ou recalculée à chaque passage (vide) |
|
| 660 | + foreach ($init as $i) { |
|
| 661 | + if (reset($i)) { |
|
| 662 | + $s .= "\n\t\t" . end($i); |
|
| 663 | + } # statique |
|
| 664 | + else { |
|
| 665 | + $d .= "\n\t" . end($i); |
|
| 666 | + } # dynamique |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 670 | + . $boucle->in |
|
| 671 | + . $boucle->hash |
|
| 672 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 673 | + . $s |
|
| 674 | + . "\n\t}" |
|
| 675 | + . $d; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -690,13 +690,13 @@ discard block |
||
| 690 | 690 | * qui peut être utilisé pour la production d'un tableau array() |
| 691 | 691 | **/ |
| 692 | 692 | function memoriser_contexte_compil($p) { |
| 693 | - return join(',', array( |
|
| 694 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 695 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 696 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 697 | - intval($p->ligne), |
|
| 698 | - '$GLOBALS[\'spip_lang\']' |
|
| 699 | - )); |
|
| 693 | + return join(',', array( |
|
| 694 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 695 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 696 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 697 | + intval($p->ligne), |
|
| 698 | + '$GLOBALS[\'spip_lang\']' |
|
| 699 | + )); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -714,19 +714,19 @@ discard block |
||
| 714 | 714 | * Objet Contexte |
| 715 | 715 | **/ |
| 716 | 716 | function reconstruire_contexte_compil($context_compil) { |
| 717 | - if (!is_array($context_compil)) { |
|
| 718 | - return $context_compil; |
|
| 719 | - } |
|
| 720 | - $p = new Contexte; |
|
| 721 | - $p->descr = array( |
|
| 722 | - 'sourcefile' => $context_compil[0], |
|
| 723 | - 'nom' => $context_compil[1] |
|
| 724 | - ); |
|
| 725 | - $p->id_boucle = $context_compil[2]; |
|
| 726 | - $p->ligne = $context_compil[3]; |
|
| 727 | - $p->lang = $context_compil[4]; |
|
| 728 | - |
|
| 729 | - return $p; |
|
| 717 | + if (!is_array($context_compil)) { |
|
| 718 | + return $context_compil; |
|
| 719 | + } |
|
| 720 | + $p = new Contexte; |
|
| 721 | + $p->descr = array( |
|
| 722 | + 'sourcefile' => $context_compil[0], |
|
| 723 | + 'nom' => $context_compil[1] |
|
| 724 | + ); |
|
| 725 | + $p->id_boucle = $context_compil[2]; |
|
| 726 | + $p->ligne = $context_compil[3]; |
|
| 727 | + $p->lang = $context_compil[4]; |
|
| 728 | + |
|
| 729 | + return $p; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | * - index 1 : Code de l'affectation |
| 753 | 753 | **/ |
| 754 | 754 | function calculer_dec($nom, $val) { |
| 755 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 756 | - // si une variable apparait dans le calcul de la clause |
|
| 757 | - // il faut la re-evaluer a chaque passage |
|
| 758 | - if ( |
|
| 759 | - strpos($val, '$') !== false |
|
| 760 | - /* |
|
| 755 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 756 | + // si une variable apparait dans le calcul de la clause |
|
| 757 | + // il faut la re-evaluer a chaque passage |
|
| 758 | + if ( |
|
| 759 | + strpos($val, '$') !== false |
|
| 760 | + /* |
|
| 761 | 761 | OR strpos($val, 'sql_') !== false |
| 762 | 762 | OR ( |
| 763 | 763 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -765,11 +765,11 @@ discard block |
||
| 765 | 765 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 766 | 766 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 767 | 767 | )*/ |
| 768 | - ) { |
|
| 769 | - $static = ""; |
|
| 770 | - } |
|
| 768 | + ) { |
|
| 769 | + $static = ""; |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 772 | + return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /** |
@@ -789,32 +789,32 @@ discard block |
||
| 789 | 789 | * Expression PHP décrivant un texte ou un tableau |
| 790 | 790 | **/ |
| 791 | 791 | function calculer_dump_array($a) { |
| 792 | - if (!is_array($a)) { |
|
| 793 | - return $a; |
|
| 794 | - } |
|
| 795 | - $res = ""; |
|
| 796 | - if ($a and $a[0] == "'?'") { |
|
| 797 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | - " ? " . calculer_dump_array($a[2]) . |
|
| 799 | - " : " . calculer_dump_array($a[3]) . |
|
| 800 | - ")"); |
|
| 801 | - } else { |
|
| 802 | - foreach ($a as $v) { |
|
| 803 | - $res .= ", " . calculer_dump_array($v); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 807 | - } |
|
| 792 | + if (!is_array($a)) { |
|
| 793 | + return $a; |
|
| 794 | + } |
|
| 795 | + $res = ""; |
|
| 796 | + if ($a and $a[0] == "'?'") { |
|
| 797 | + return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | + " ? " . calculer_dump_array($a[2]) . |
|
| 799 | + " : " . calculer_dump_array($a[3]) . |
|
| 800 | + ")"); |
|
| 801 | + } else { |
|
| 802 | + foreach ($a as $v) { |
|
| 803 | + $res .= ", " . calculer_dump_array($v); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | // http://code.spip.net/@calculer_dump_join |
| 811 | 811 | function calculer_dump_join($a) { |
| 812 | - $res = ""; |
|
| 813 | - foreach ($a as $k => $v) { |
|
| 814 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 815 | - } |
|
| 812 | + $res = ""; |
|
| 813 | + foreach ($a as $k => $v) { |
|
| 814 | + $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | - return 'array(' . substr($res, 2) . ')'; |
|
| 817 | + return 'array(' . substr($res, 2) . ')'; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
@@ -826,12 +826,12 @@ discard block |
||
| 826 | 826 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_from(&$boucle) { |
| 829 | - $res = ""; |
|
| 830 | - foreach ($boucle->from as $k => $v) { |
|
| 831 | - $res .= ",'$k' => '$v'"; |
|
| 832 | - } |
|
| 829 | + $res = ""; |
|
| 830 | + foreach ($boucle->from as $k => $v) { |
|
| 831 | + $res .= ",'$k' => '$v'"; |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | - return 'array(' . substr($res, 1) . ')'; |
|
| 834 | + return 'array(' . substr($res, 1) . ')'; |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -844,30 +844,30 @@ discard block |
||
| 844 | 844 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 845 | 845 | **/ |
| 846 | 846 | function calculer_from_type(&$boucle) { |
| 847 | - $res = ""; |
|
| 848 | - foreach ($boucle->from_type as $k => $v) { |
|
| 849 | - $res .= ",'$k' => '$v'"; |
|
| 850 | - } |
|
| 847 | + $res = ""; |
|
| 848 | + foreach ($boucle->from_type as $k => $v) { |
|
| 849 | + $res .= ",'$k' => '$v'"; |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - return 'array(' . substr($res, 1) . ')'; |
|
| 852 | + return 'array(' . substr($res, 1) . ')'; |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | // http://code.spip.net/@calculer_order |
| 856 | 856 | function calculer_order(&$boucle) { |
| 857 | - if (!$order = $boucle->order |
|
| 858 | - and !$order = $boucle->default_order |
|
| 859 | - ) { |
|
| 860 | - $order = array(); |
|
| 861 | - } |
|
| 857 | + if (!$order = $boucle->order |
|
| 858 | + and !$order = $boucle->default_order |
|
| 859 | + ) { |
|
| 860 | + $order = array(); |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 863 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 864 | 864 | $col = "." . $boucle->modificateur['collate']; |
| 865 | 865 | foreach($order as $k=>$o) |
| 866 | 866 | if (strpos($order[$k],'COLLATE')===false) |
| 867 | 867 | $order[$k].= $col; |
| 868 | 868 | }*/ |
| 869 | 869 | |
| 870 | - return join(', ', $order); |
|
| 870 | + return join(', ', $order); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -877,44 +877,44 @@ discard block |
||
| 877 | 877 | |
| 878 | 878 | // http://code.spip.net/@calculer_liste |
| 879 | 879 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 880 | - if (!$tableau) { |
|
| 881 | - return "''"; |
|
| 882 | - } |
|
| 883 | - if (!isset($descr['niv'])) { |
|
| 884 | - $descr['niv'] = 0; |
|
| 885 | - } |
|
| 886 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 887 | - if ($codes === false) { |
|
| 888 | - return false; |
|
| 889 | - } |
|
| 890 | - $n = count($codes); |
|
| 891 | - if (!$n) { |
|
| 892 | - return "''"; |
|
| 893 | - } |
|
| 894 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 895 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 896 | - if ($n == 1) { |
|
| 897 | - return $codes[0]; |
|
| 898 | - } else { |
|
| 899 | - $res = ''; |
|
| 900 | - foreach ($codes as $code) { |
|
| 901 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 902 | - or substr($res, -1, 1) !== "'" |
|
| 903 | - ) { |
|
| 904 | - $res .= " .\n$tab$code"; |
|
| 905 | - } else { |
|
| 906 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 911 | - } |
|
| 912 | - } else { |
|
| 913 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | - |
|
| 915 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | - $codes) . ")))"; |
|
| 917 | - } |
|
| 880 | + if (!$tableau) { |
|
| 881 | + return "''"; |
|
| 882 | + } |
|
| 883 | + if (!isset($descr['niv'])) { |
|
| 884 | + $descr['niv'] = 0; |
|
| 885 | + } |
|
| 886 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 887 | + if ($codes === false) { |
|
| 888 | + return false; |
|
| 889 | + } |
|
| 890 | + $n = count($codes); |
|
| 891 | + if (!$n) { |
|
| 892 | + return "''"; |
|
| 893 | + } |
|
| 894 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 895 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 896 | + if ($n == 1) { |
|
| 897 | + return $codes[0]; |
|
| 898 | + } else { |
|
| 899 | + $res = ''; |
|
| 900 | + foreach ($codes as $code) { |
|
| 901 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 902 | + or substr($res, -1, 1) !== "'" |
|
| 903 | + ) { |
|
| 904 | + $res .= " .\n$tab$code"; |
|
| 905 | + } else { |
|
| 906 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 911 | + } |
|
| 912 | + } else { |
|
| 913 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | + |
|
| 915 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | + $codes) . ")))"; |
|
| 917 | + } |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | define('_REGEXP_COND_VIDE_NONVIDE', "/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
@@ -924,186 +924,186 @@ discard block |
||
| 924 | 924 | // http://code.spip.net/@compile_cas |
| 925 | 925 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 926 | 926 | |
| 927 | - $codes = array(); |
|
| 928 | - // cas de la boucle recursive |
|
| 929 | - if (is_array($id_boucle)) { |
|
| 930 | - $id_boucle = $id_boucle[0]; |
|
| 931 | - } |
|
| 932 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 933 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 934 | - $mode = _request('var_mode_affiche'); |
|
| 935 | - $err_e_c = ''; |
|
| 936 | - // chaque commentaire introduit dans le code doit commencer |
|
| 937 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 938 | - foreach ($tableau as $p) { |
|
| 939 | - |
|
| 940 | - switch ($p->type) { |
|
| 941 | - // texte seul |
|
| 942 | - case 'texte': |
|
| 943 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 944 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 945 | - $avant = ''; |
|
| 946 | - $apres = ''; |
|
| 947 | - $altern = "''"; |
|
| 948 | - break; |
|
| 949 | - |
|
| 950 | - case 'polyglotte': |
|
| 951 | - $code = ""; |
|
| 952 | - foreach ($p->traductions as $k => $v) { |
|
| 953 | - $code .= ",'" . |
|
| 954 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | - "' => '" . |
|
| 956 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 957 | - "'"; |
|
| 958 | - } |
|
| 959 | - $code = "choisir_traduction(array(" . |
|
| 960 | - substr($code, 1) . |
|
| 961 | - "))"; |
|
| 962 | - $commentaire = '&'; |
|
| 963 | - $avant = ''; |
|
| 964 | - $apres = ''; |
|
| 965 | - $altern = "''"; |
|
| 966 | - break; |
|
| 967 | - |
|
| 968 | - // inclure |
|
| 969 | - case 'include': |
|
| 970 | - $p->descr = $descr; |
|
| 971 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 972 | - if ($code === false) { |
|
| 973 | - $err_e_c = true; |
|
| 974 | - $code = "''"; |
|
| 975 | - } else { |
|
| 976 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 977 | - $avant = ''; |
|
| 978 | - $apres = ''; |
|
| 979 | - $altern = "''"; |
|
| 980 | - } |
|
| 981 | - break; |
|
| 982 | - |
|
| 983 | - // boucle |
|
| 984 | - case TYPE_RECURSIF: |
|
| 985 | - $nom = $p->id_boucle; |
|
| 986 | - $newdescr = $descr; |
|
| 987 | - $newdescr['id_mere'] = $nom; |
|
| 988 | - $newdescr['niv']++; |
|
| 989 | - $avant = calculer_liste($p->avant, |
|
| 990 | - $newdescr, $boucles, $id_boucle); |
|
| 991 | - $apres = calculer_liste($p->apres, |
|
| 992 | - $newdescr, $boucles, $id_boucle); |
|
| 993 | - $newdescr['niv']--; |
|
| 994 | - $altern = calculer_liste($p->altern, |
|
| 995 | - $newdescr, $boucles, $id_boucle); |
|
| 996 | - if (($avant === false) or ($apres === false) or ($altern === false)) { |
|
| 997 | - $err_e_c = true; |
|
| 998 | - $code = "''"; |
|
| 999 | - } else { |
|
| 1000 | - $code = 'BOUCLE' . |
|
| 1001 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1002 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1003 | - $commentaire = "?$nom"; |
|
| 1004 | - if (!$boucles[$nom]->milieu |
|
| 1005 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1006 | - ) { |
|
| 1007 | - if ($altern != "''") { |
|
| 1008 | - $code .= "\n. $altern"; |
|
| 1009 | - } |
|
| 1010 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1011 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1012 | - } |
|
| 1013 | - $avant = $apres = $altern = "''"; |
|
| 1014 | - } else { |
|
| 1015 | - if ($altern != "''") { |
|
| 1016 | - $altern = "($altern)"; |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - break; |
|
| 1021 | - |
|
| 1022 | - case 'idiome': |
|
| 1023 | - $l = array(); |
|
| 1024 | - $code = ''; |
|
| 1025 | - foreach ($p->arg as $k => $v) { |
|
| 1026 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1027 | - if ($k) { |
|
| 1028 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1029 | - } else { |
|
| 1030 | - $code = $_v; |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1034 | - if ($p->module) { |
|
| 1035 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1036 | - } elseif ($p->nom_champ) { |
|
| 1037 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1038 | - } else { |
|
| 1039 | - $m = ''; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - $code = (!$code ? "'$m'" : |
|
| 1043 | - ($m ? "'$m' . $code" : |
|
| 1044 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1046 | - $code = "_T($code)"; |
|
| 1047 | - if ($p->param) { |
|
| 1048 | - $p->id_boucle = $id_boucle; |
|
| 1049 | - $p->boucles = &$boucles; |
|
| 1050 | - $code = compose_filtres($p, $code); |
|
| 1051 | - } |
|
| 1052 | - $commentaire = ":"; |
|
| 1053 | - $avant = ''; |
|
| 1054 | - $apres = ''; |
|
| 1055 | - $altern = "''"; |
|
| 1056 | - break; |
|
| 1057 | - |
|
| 1058 | - case 'champ': |
|
| 1059 | - |
|
| 1060 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1061 | - $p->id_boucle = $id_boucle; |
|
| 1062 | - $p->boucles = &$boucles; |
|
| 1063 | - $p->descr = $descr; |
|
| 1064 | - #$p->interdire_scripts = true; |
|
| 1065 | - $p->type_requete = $type; |
|
| 1066 | - |
|
| 1067 | - $code = calculer_champ($p); |
|
| 1068 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1069 | - $avant = calculer_liste($p->avant, |
|
| 1070 | - $descr, $boucles, $id_boucle); |
|
| 1071 | - $apres = calculer_liste($p->apres, |
|
| 1072 | - $descr, $boucles, $id_boucle); |
|
| 1073 | - $altern = "''"; |
|
| 1074 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1075 | - // forcer la conversion en une chaine par strval |
|
| 1076 | - // si ca peut etre autre chose qu'une chaine |
|
| 1077 | - if (($avant != "''" or $apres != "''") |
|
| 1078 | - and $code[0] != "'" |
|
| 927 | + $codes = array(); |
|
| 928 | + // cas de la boucle recursive |
|
| 929 | + if (is_array($id_boucle)) { |
|
| 930 | + $id_boucle = $id_boucle[0]; |
|
| 931 | + } |
|
| 932 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 933 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 934 | + $mode = _request('var_mode_affiche'); |
|
| 935 | + $err_e_c = ''; |
|
| 936 | + // chaque commentaire introduit dans le code doit commencer |
|
| 937 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 938 | + foreach ($tableau as $p) { |
|
| 939 | + |
|
| 940 | + switch ($p->type) { |
|
| 941 | + // texte seul |
|
| 942 | + case 'texte': |
|
| 943 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 944 | + $commentaire = strlen($p->texte) . " signes"; |
|
| 945 | + $avant = ''; |
|
| 946 | + $apres = ''; |
|
| 947 | + $altern = "''"; |
|
| 948 | + break; |
|
| 949 | + |
|
| 950 | + case 'polyglotte': |
|
| 951 | + $code = ""; |
|
| 952 | + foreach ($p->traductions as $k => $v) { |
|
| 953 | + $code .= ",'" . |
|
| 954 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | + "' => '" . |
|
| 956 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 957 | + "'"; |
|
| 958 | + } |
|
| 959 | + $code = "choisir_traduction(array(" . |
|
| 960 | + substr($code, 1) . |
|
| 961 | + "))"; |
|
| 962 | + $commentaire = '&'; |
|
| 963 | + $avant = ''; |
|
| 964 | + $apres = ''; |
|
| 965 | + $altern = "''"; |
|
| 966 | + break; |
|
| 967 | + |
|
| 968 | + // inclure |
|
| 969 | + case 'include': |
|
| 970 | + $p->descr = $descr; |
|
| 971 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 972 | + if ($code === false) { |
|
| 973 | + $err_e_c = true; |
|
| 974 | + $code = "''"; |
|
| 975 | + } else { |
|
| 976 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 977 | + $avant = ''; |
|
| 978 | + $apres = ''; |
|
| 979 | + $altern = "''"; |
|
| 980 | + } |
|
| 981 | + break; |
|
| 982 | + |
|
| 983 | + // boucle |
|
| 984 | + case TYPE_RECURSIF: |
|
| 985 | + $nom = $p->id_boucle; |
|
| 986 | + $newdescr = $descr; |
|
| 987 | + $newdescr['id_mere'] = $nom; |
|
| 988 | + $newdescr['niv']++; |
|
| 989 | + $avant = calculer_liste($p->avant, |
|
| 990 | + $newdescr, $boucles, $id_boucle); |
|
| 991 | + $apres = calculer_liste($p->apres, |
|
| 992 | + $newdescr, $boucles, $id_boucle); |
|
| 993 | + $newdescr['niv']--; |
|
| 994 | + $altern = calculer_liste($p->altern, |
|
| 995 | + $newdescr, $boucles, $id_boucle); |
|
| 996 | + if (($avant === false) or ($apres === false) or ($altern === false)) { |
|
| 997 | + $err_e_c = true; |
|
| 998 | + $code = "''"; |
|
| 999 | + } else { |
|
| 1000 | + $code = 'BOUCLE' . |
|
| 1001 | + str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1002 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1003 | + $commentaire = "?$nom"; |
|
| 1004 | + if (!$boucles[$nom]->milieu |
|
| 1005 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1006 | + ) { |
|
| 1007 | + if ($altern != "''") { |
|
| 1008 | + $code .= "\n. $altern"; |
|
| 1009 | + } |
|
| 1010 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1011 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1012 | + } |
|
| 1013 | + $avant = $apres = $altern = "''"; |
|
| 1014 | + } else { |
|
| 1015 | + if ($altern != "''") { |
|
| 1016 | + $altern = "($altern)"; |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + break; |
|
| 1021 | + |
|
| 1022 | + case 'idiome': |
|
| 1023 | + $l = array(); |
|
| 1024 | + $code = ''; |
|
| 1025 | + foreach ($p->arg as $k => $v) { |
|
| 1026 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1027 | + if ($k) { |
|
| 1028 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1029 | + } else { |
|
| 1030 | + $code = $_v; |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1034 | + if ($p->module) { |
|
| 1035 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1036 | + } elseif ($p->nom_champ) { |
|
| 1037 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1038 | + } else { |
|
| 1039 | + $m = ''; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + $code = (!$code ? "'$m'" : |
|
| 1043 | + ($m ? "'$m' . $code" : |
|
| 1044 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1046 | + $code = "_T($code)"; |
|
| 1047 | + if ($p->param) { |
|
| 1048 | + $p->id_boucle = $id_boucle; |
|
| 1049 | + $p->boucles = &$boucles; |
|
| 1050 | + $code = compose_filtres($p, $code); |
|
| 1051 | + } |
|
| 1052 | + $commentaire = ":"; |
|
| 1053 | + $avant = ''; |
|
| 1054 | + $apres = ''; |
|
| 1055 | + $altern = "''"; |
|
| 1056 | + break; |
|
| 1057 | + |
|
| 1058 | + case 'champ': |
|
| 1059 | + |
|
| 1060 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1061 | + $p->id_boucle = $id_boucle; |
|
| 1062 | + $p->boucles = &$boucles; |
|
| 1063 | + $p->descr = $descr; |
|
| 1064 | + #$p->interdire_scripts = true; |
|
| 1065 | + $p->type_requete = $type; |
|
| 1066 | + |
|
| 1067 | + $code = calculer_champ($p); |
|
| 1068 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1069 | + $avant = calculer_liste($p->avant, |
|
| 1070 | + $descr, $boucles, $id_boucle); |
|
| 1071 | + $apres = calculer_liste($p->apres, |
|
| 1072 | + $descr, $boucles, $id_boucle); |
|
| 1073 | + $altern = "''"; |
|
| 1074 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1075 | + // forcer la conversion en une chaine par strval |
|
| 1076 | + // si ca peut etre autre chose qu'une chaine |
|
| 1077 | + if (($avant != "''" or $apres != "''") |
|
| 1078 | + and $code[0] != "'" |
|
| 1079 | 1079 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1080 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1081 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1082 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1083 | - ) { |
|
| 1084 | - $code = "strval($code)"; |
|
| 1085 | - } |
|
| 1086 | - break; |
|
| 1087 | - |
|
| 1088 | - default: |
|
| 1089 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1090 | - $code = "''"; |
|
| 1091 | - $p->descr = $descr; |
|
| 1092 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1093 | - erreur_squelette($err_e_c, $p); |
|
| 1094 | - } // switch |
|
| 1095 | - |
|
| 1096 | - if ($code != "''") { |
|
| 1097 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1098 | - $codes[] = (($mode == 'validation') ? |
|
| 1099 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1100 | - : (($mode == 'code') ? |
|
| 1101 | - "\n// $commentaire\n$code" : |
|
| 1102 | - $code)); |
|
| 1103 | - } |
|
| 1104 | - } // foreach |
|
| 1105 | - |
|
| 1106 | - return $err_e_c ? false : $codes; |
|
| 1080 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1081 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1082 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1083 | + ) { |
|
| 1084 | + $code = "strval($code)"; |
|
| 1085 | + } |
|
| 1086 | + break; |
|
| 1087 | + |
|
| 1088 | + default: |
|
| 1089 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1090 | + $code = "''"; |
|
| 1091 | + $p->descr = $descr; |
|
| 1092 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1093 | + erreur_squelette($err_e_c, $p); |
|
| 1094 | + } // switch |
|
| 1095 | + |
|
| 1096 | + if ($code != "''") { |
|
| 1097 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1098 | + $codes[] = (($mode == 'validation') ? |
|
| 1099 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1100 | + : (($mode == 'code') ? |
|
| 1101 | + "\n// $commentaire\n$code" : |
|
| 1102 | + $code)); |
|
| 1103 | + } |
|
| 1104 | + } // foreach |
|
| 1105 | + |
|
| 1106 | + return $err_e_c ? false : $codes; |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | // production d'une expression conditionnelle ((v=EXP) ? (p . v .s) : a) |
@@ -1112,56 +1112,56 @@ discard block |
||
| 1112 | 1112 | |
| 1113 | 1113 | // http://code.spip.net/@compile_retour |
| 1114 | 1114 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1115 | - if ($avant == "''") { |
|
| 1116 | - $avant = ''; |
|
| 1117 | - } |
|
| 1118 | - if ($apres == "''") { |
|
| 1119 | - $apres = ''; |
|
| 1120 | - } |
|
| 1121 | - if (!$avant and !$apres and ($altern === "''")) { |
|
| 1122 | - return $code; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1126 | - $t = $code; |
|
| 1127 | - $cond = ''; |
|
| 1128 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1129 | - $t = $r[2]; |
|
| 1130 | - $cond = '!' . $r[1]; |
|
| 1131 | - } else { |
|
| 1132 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1133 | - $t = $r[2]; |
|
| 1134 | - $cond = $r[1]; |
|
| 1135 | - } else { |
|
| 1136 | - $t = '$t' . $n; |
|
| 1137 | - $cond = "($t = $code)!==''"; |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | - $t . |
|
| 1143 | - (!$apres ? "" : " . $apres"); |
|
| 1144 | - |
|
| 1145 | - if ($res !== $t) { |
|
| 1146 | - $res = "($res)"; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 1115 | + if ($avant == "''") { |
|
| 1116 | + $avant = ''; |
|
| 1117 | + } |
|
| 1118 | + if ($apres == "''") { |
|
| 1119 | + $apres = ''; |
|
| 1120 | + } |
|
| 1121 | + if (!$avant and !$apres and ($altern === "''")) { |
|
| 1122 | + return $code; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1126 | + $t = $code; |
|
| 1127 | + $cond = ''; |
|
| 1128 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1129 | + $t = $r[2]; |
|
| 1130 | + $cond = '!' . $r[1]; |
|
| 1131 | + } else { |
|
| 1132 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1133 | + $t = $r[2]; |
|
| 1134 | + $cond = $r[1]; |
|
| 1135 | + } else { |
|
| 1136 | + $t = '$t' . $n; |
|
| 1137 | + $cond = "($t = $code)!==''"; |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | + $t . |
|
| 1143 | + (!$apres ? "" : " . $apres"); |
|
| 1144 | + |
|
| 1145 | + if ($res !== $t) { |
|
| 1146 | + $res = "($res)"; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | |
| 1153 | 1153 | function compile_inclure_doublons($lexemes) { |
| 1154 | - foreach ($lexemes as $v) { |
|
| 1155 | - if ($v->type === 'include' and $v->param) { |
|
| 1156 | - foreach ($v->param as $r) { |
|
| 1157 | - if (trim($r[0]) === 'doublons') { |
|
| 1158 | - return true; |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - return false; |
|
| 1154 | + foreach ($lexemes as $v) { |
|
| 1155 | + if ($v->type === 'include' and $v->param) { |
|
| 1156 | + foreach ($v->param as $r) { |
|
| 1157 | + if (trim($r[0]) === 'doublons') { |
|
| 1158 | + return true; |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + return false; |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1181,346 +1181,346 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | // http://code.spip.net/@public_compiler_dist |
| 1183 | 1183 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1184 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1185 | - // Bonus : supprime le BOM |
|
| 1186 | - include_spip('inc/charsets'); |
|
| 1187 | - $squelette = transcoder_page($squelette); |
|
| 1188 | - |
|
| 1189 | - // rendre inertes les echappements de #[](){}<> |
|
| 1190 | - $i = 0; |
|
| 1191 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1192 | - $i++; |
|
| 1193 | - } |
|
| 1194 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1195 | - function($a) use ($inerte) { |
|
| 1196 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1197 | - }, |
|
| 1198 | - $squelette, |
|
| 1199 | - -1, |
|
| 1200 | - $esc |
|
| 1201 | - ); |
|
| 1202 | - |
|
| 1203 | - $descr = array( |
|
| 1204 | - 'nom' => $nom, |
|
| 1205 | - 'gram' => $gram, |
|
| 1206 | - 'sourcefile' => $sourcefile, |
|
| 1207 | - 'squelette' => $squelette |
|
| 1208 | - ); |
|
| 1209 | - |
|
| 1210 | - // Phraser le squelette, selon sa grammaire |
|
| 1211 | - |
|
| 1212 | - $boucles = array(); |
|
| 1213 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1214 | - |
|
| 1215 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1216 | - |
|
| 1217 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1218 | - |
|
| 1219 | - // restituer les echappements |
|
| 1220 | - if ($esc) { |
|
| 1221 | - foreach ($boucles as $i => $boucle) { |
|
| 1222 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1223 | - ",$inerte-(\d+)-,", |
|
| 1224 | - function($a) { |
|
| 1225 | - return chr($a[1]); |
|
| 1226 | - }, |
|
| 1227 | - $boucle->return |
|
| 1228 | - ); |
|
| 1229 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1230 | - ",$inerte-(\d+)-,", |
|
| 1231 | - function($a) { |
|
| 1232 | - return "\\\\" . chr($a[1]); |
|
| 1233 | - }, |
|
| 1234 | - $boucle->descr['squelette'] |
|
| 1235 | - ); |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1240 | - if ($debug) { |
|
| 1241 | - include_spip('public/decompiler'); |
|
| 1242 | - foreach ($boucles as $id => $boucle) { |
|
| 1243 | - if ($id) { |
|
| 1244 | - $decomp = "\n/* BOUCLE " . |
|
| 1245 | - $boucle->type_requete . |
|
| 1246 | - " " . |
|
| 1247 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1249 | - " */\n"; |
|
| 1250 | - } else { |
|
| 1251 | - $decomp = ("\n/*\n" . |
|
| 1252 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1253 | - . "\n*/"); |
|
| 1254 | - } |
|
| 1255 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - return $boucles; |
|
| 1184 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1185 | + // Bonus : supprime le BOM |
|
| 1186 | + include_spip('inc/charsets'); |
|
| 1187 | + $squelette = transcoder_page($squelette); |
|
| 1188 | + |
|
| 1189 | + // rendre inertes les echappements de #[](){}<> |
|
| 1190 | + $i = 0; |
|
| 1191 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1192 | + $i++; |
|
| 1193 | + } |
|
| 1194 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1195 | + function($a) use ($inerte) { |
|
| 1196 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1197 | + }, |
|
| 1198 | + $squelette, |
|
| 1199 | + -1, |
|
| 1200 | + $esc |
|
| 1201 | + ); |
|
| 1202 | + |
|
| 1203 | + $descr = array( |
|
| 1204 | + 'nom' => $nom, |
|
| 1205 | + 'gram' => $gram, |
|
| 1206 | + 'sourcefile' => $sourcefile, |
|
| 1207 | + 'squelette' => $squelette |
|
| 1208 | + ); |
|
| 1209 | + |
|
| 1210 | + // Phraser le squelette, selon sa grammaire |
|
| 1211 | + |
|
| 1212 | + $boucles = array(); |
|
| 1213 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1214 | + |
|
| 1215 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1216 | + |
|
| 1217 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1218 | + |
|
| 1219 | + // restituer les echappements |
|
| 1220 | + if ($esc) { |
|
| 1221 | + foreach ($boucles as $i => $boucle) { |
|
| 1222 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1223 | + ",$inerte-(\d+)-,", |
|
| 1224 | + function($a) { |
|
| 1225 | + return chr($a[1]); |
|
| 1226 | + }, |
|
| 1227 | + $boucle->return |
|
| 1228 | + ); |
|
| 1229 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1230 | + ",$inerte-(\d+)-,", |
|
| 1231 | + function($a) { |
|
| 1232 | + return "\\\\" . chr($a[1]); |
|
| 1233 | + }, |
|
| 1234 | + $boucle->descr['squelette'] |
|
| 1235 | + ); |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1240 | + if ($debug) { |
|
| 1241 | + include_spip('public/decompiler'); |
|
| 1242 | + foreach ($boucles as $id => $boucle) { |
|
| 1243 | + if ($id) { |
|
| 1244 | + $decomp = "\n/* BOUCLE " . |
|
| 1245 | + $boucle->type_requete . |
|
| 1246 | + " " . |
|
| 1247 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1249 | + " */\n"; |
|
| 1250 | + } else { |
|
| 1251 | + $decomp = ("\n/*\n" . |
|
| 1252 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1253 | + . "\n*/"); |
|
| 1254 | + } |
|
| 1255 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + return $boucles; |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1264 | 1264 | // Autres specifications comme ci-dessus |
| 1265 | 1265 | |
| 1266 | 1266 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1267 | - static $trouver_table; |
|
| 1268 | - spip_timer('calcul_skel'); |
|
| 1269 | - |
|
| 1270 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1271 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1272 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1273 | - |
|
| 1274 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1275 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - foreach ($boucles as $id => $boucle) { |
|
| 1279 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1280 | - } |
|
| 1281 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1282 | - |
|
| 1283 | - // Demander la description des tables une fois pour toutes |
|
| 1284 | - if (!$trouver_table) { |
|
| 1285 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - // reperer si les doublons sont demandes |
|
| 1289 | - // pour un inclure ou une boucle document |
|
| 1290 | - // c'est utile a la fonction champs_traitements |
|
| 1291 | - foreach ($boucles as $id => $boucle) { |
|
| 1292 | - if (!($type = $boucle->type_requete)) { |
|
| 1293 | - continue; |
|
| 1294 | - } |
|
| 1295 | - if (!$descr['documents'] and ( |
|
| 1296 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1297 | - compile_inclure_doublons($boucle->avant) or |
|
| 1298 | - compile_inclure_doublons($boucle->apres) or |
|
| 1299 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1300 | - compile_inclure_doublons($boucle->altern)) |
|
| 1301 | - ) { |
|
| 1302 | - $descr['documents'] = true; |
|
| 1303 | - } |
|
| 1304 | - if ($type != TYPE_RECURSIF) { |
|
| 1305 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1306 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1310 | - if ($g = charger_fonction( |
|
| 1311 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1312 | - ) { |
|
| 1313 | - $boucles[$id] = $g($boucle); |
|
| 1314 | - |
|
| 1315 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1316 | - // utiliser les informations donnees par le requeteur |
|
| 1317 | - // cas "php:xx" et "data:xx". |
|
| 1318 | - } else { |
|
| 1319 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1320 | - $requeteur($boucles, $boucle, $id); |
|
| 1321 | - |
|
| 1322 | - // utiliser la description des champs transmis |
|
| 1323 | - } else { |
|
| 1324 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1325 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1326 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1327 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1328 | - if (!$show |
|
| 1329 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1330 | - ) { |
|
| 1331 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1332 | - } |
|
| 1333 | - if ($show) { |
|
| 1334 | - $boucles[$id]->show = $show; |
|
| 1335 | - // recopie les infos les plus importantes |
|
| 1336 | - $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1337 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1338 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1339 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1340 | - |
|
| 1341 | - $boucles[$id]->descr = &$descr; |
|
| 1342 | - if ((!$boucles[$id]->jointures) |
|
| 1343 | - and is_array($show['tables_jointures']) |
|
| 1344 | - and count($x = $show['tables_jointures']) |
|
| 1345 | - ) { |
|
| 1346 | - $boucles[$id]->jointures = $x; |
|
| 1347 | - } |
|
| 1348 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1349 | - $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1350 | - while ($j = array_pop($jointures)) { |
|
| 1351 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - } else { |
|
| 1355 | - // Pas une erreur si la table est optionnelle |
|
| 1356 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1357 | - $boucles[$id]->type_requete = ''; |
|
| 1358 | - } else { |
|
| 1359 | - $boucles[$id]->type_requete = false; |
|
| 1360 | - $boucle = $boucles[$id]; |
|
| 1361 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | - ($boucle->sql_serveur . ":")) . |
|
| 1363 | - $type; |
|
| 1364 | - $msg = array( |
|
| 1365 | - 'zbug_table_inconnue', |
|
| 1366 | - array('table' => $x) |
|
| 1367 | - ); |
|
| 1368 | - erreur_squelette($msg, $boucle); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1377 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1378 | - foreach ($boucles as $id => $boucle) { |
|
| 1379 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1380 | - $boucles[$id]->descr = &$descr; |
|
| 1381 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1382 | - if (!$rec) { |
|
| 1383 | - $msg = array( |
|
| 1384 | - 'zbug_boucle_recursive_undef', |
|
| 1385 | - array('nom' => $boucle->param[0]) |
|
| 1386 | - ); |
|
| 1387 | - erreur_squelette($msg, $boucle); |
|
| 1388 | - $boucles[$id]->type_requete = false; |
|
| 1389 | - } else { |
|
| 1390 | - $rec->externe = $id; |
|
| 1391 | - $descr['id_mere'] = $id; |
|
| 1392 | - $boucles[$id]->return = |
|
| 1393 | - calculer_liste(array($rec), |
|
| 1394 | - $descr, |
|
| 1395 | - $boucles, |
|
| 1396 | - $boucle->param); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - foreach ($boucles as $id => $boucle) { |
|
| 1401 | - $id = strval($id); // attention au type dans index_pile |
|
| 1402 | - $type = $boucle->type_requete; |
|
| 1403 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1404 | - $res = ''; |
|
| 1405 | - if ($boucle->param) { |
|
| 1406 | - // retourne un tableau en cas d'erreur |
|
| 1407 | - $res = calculer_criteres($id, $boucles); |
|
| 1408 | - } |
|
| 1409 | - $descr['id_mere'] = $id; |
|
| 1410 | - $boucles[$id]->return = |
|
| 1411 | - calculer_liste($boucle->milieu, |
|
| 1412 | - $descr, |
|
| 1413 | - $boucles, |
|
| 1414 | - $id); |
|
| 1415 | - // Si les criteres se sont mal compiles |
|
| 1416 | - // ne pas tenter d'assembler le code final |
|
| 1417 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1418 | - if (is_array($res)) { |
|
| 1419 | - $boucles[$id]->type_requete = false; |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - // idem pour la racine |
|
| 1425 | - $descr['id_mere'] = ''; |
|
| 1426 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1430 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1431 | - // de'terminables seulement maintenant |
|
| 1432 | - |
|
| 1433 | - foreach ($boucles as $id => $boucle) { |
|
| 1434 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1435 | - if ($boucle->return === false) { |
|
| 1436 | - $corps = false; |
|
| 1437 | - continue; |
|
| 1438 | - } |
|
| 1439 | - // appeler la fonction de definition de la boucle |
|
| 1440 | - |
|
| 1441 | - if ($req = $boucle->type_requete) { |
|
| 1442 | - // boucle personnalisée ? |
|
| 1443 | - $table = strtoupper($boucle->type_requete); |
|
| 1444 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1445 | - if ( |
|
| 1446 | - // fonction de boucle avec serveur & table |
|
| 1447 | - (!$serveur or |
|
| 1448 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | - and (!function_exists($f = $f . "_dist")) |
|
| 1450 | - ) |
|
| 1451 | - ) |
|
| 1452 | - // fonction de boucle avec table |
|
| 1453 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | - and (!function_exists($f = $f . "_dist")) |
|
| 1455 | - ) { |
|
| 1456 | - // fonction de boucle standard |
|
| 1457 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1458 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1459 | - } |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | - "static \$connect;\n\t" . |
|
| 1464 | - "\$command['connect'] = \$connect = " . |
|
| 1465 | - _q($boucle->sql_serveur) . |
|
| 1466 | - ";" . |
|
| 1467 | - $f($id, $boucles); |
|
| 1468 | - } else { |
|
| 1469 | - $req = ("\n\treturn '';"); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - $boucles[$id]->return = |
|
| 1473 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | - $req . |
|
| 1476 | - "\n}\n"; |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1480 | - // retourner False, sinon inserer leur decompilation |
|
| 1481 | - if (is_bool($corps)) { |
|
| 1482 | - return false; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1267 | + static $trouver_table; |
|
| 1268 | + spip_timer('calcul_skel'); |
|
| 1269 | + |
|
| 1270 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1271 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1272 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1273 | + |
|
| 1274 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1275 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + foreach ($boucles as $id => $boucle) { |
|
| 1279 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1280 | + } |
|
| 1281 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1282 | + |
|
| 1283 | + // Demander la description des tables une fois pour toutes |
|
| 1284 | + if (!$trouver_table) { |
|
| 1285 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + // reperer si les doublons sont demandes |
|
| 1289 | + // pour un inclure ou une boucle document |
|
| 1290 | + // c'est utile a la fonction champs_traitements |
|
| 1291 | + foreach ($boucles as $id => $boucle) { |
|
| 1292 | + if (!($type = $boucle->type_requete)) { |
|
| 1293 | + continue; |
|
| 1294 | + } |
|
| 1295 | + if (!$descr['documents'] and ( |
|
| 1296 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1297 | + compile_inclure_doublons($boucle->avant) or |
|
| 1298 | + compile_inclure_doublons($boucle->apres) or |
|
| 1299 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1300 | + compile_inclure_doublons($boucle->altern)) |
|
| 1301 | + ) { |
|
| 1302 | + $descr['documents'] = true; |
|
| 1303 | + } |
|
| 1304 | + if ($type != TYPE_RECURSIF) { |
|
| 1305 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1306 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1310 | + if ($g = charger_fonction( |
|
| 1311 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1312 | + ) { |
|
| 1313 | + $boucles[$id] = $g($boucle); |
|
| 1314 | + |
|
| 1315 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1316 | + // utiliser les informations donnees par le requeteur |
|
| 1317 | + // cas "php:xx" et "data:xx". |
|
| 1318 | + } else { |
|
| 1319 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1320 | + $requeteur($boucles, $boucle, $id); |
|
| 1321 | + |
|
| 1322 | + // utiliser la description des champs transmis |
|
| 1323 | + } else { |
|
| 1324 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1325 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1326 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1327 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1328 | + if (!$show |
|
| 1329 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1330 | + ) { |
|
| 1331 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1332 | + } |
|
| 1333 | + if ($show) { |
|
| 1334 | + $boucles[$id]->show = $show; |
|
| 1335 | + // recopie les infos les plus importantes |
|
| 1336 | + $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1337 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1338 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1339 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1340 | + |
|
| 1341 | + $boucles[$id]->descr = &$descr; |
|
| 1342 | + if ((!$boucles[$id]->jointures) |
|
| 1343 | + and is_array($show['tables_jointures']) |
|
| 1344 | + and count($x = $show['tables_jointures']) |
|
| 1345 | + ) { |
|
| 1346 | + $boucles[$id]->jointures = $x; |
|
| 1347 | + } |
|
| 1348 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1349 | + $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1350 | + while ($j = array_pop($jointures)) { |
|
| 1351 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + } else { |
|
| 1355 | + // Pas une erreur si la table est optionnelle |
|
| 1356 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1357 | + $boucles[$id]->type_requete = ''; |
|
| 1358 | + } else { |
|
| 1359 | + $boucles[$id]->type_requete = false; |
|
| 1360 | + $boucle = $boucles[$id]; |
|
| 1361 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | + ($boucle->sql_serveur . ":")) . |
|
| 1363 | + $type; |
|
| 1364 | + $msg = array( |
|
| 1365 | + 'zbug_table_inconnue', |
|
| 1366 | + array('table' => $x) |
|
| 1367 | + ); |
|
| 1368 | + erreur_squelette($msg, $boucle); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1377 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1378 | + foreach ($boucles as $id => $boucle) { |
|
| 1379 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1380 | + $boucles[$id]->descr = &$descr; |
|
| 1381 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1382 | + if (!$rec) { |
|
| 1383 | + $msg = array( |
|
| 1384 | + 'zbug_boucle_recursive_undef', |
|
| 1385 | + array('nom' => $boucle->param[0]) |
|
| 1386 | + ); |
|
| 1387 | + erreur_squelette($msg, $boucle); |
|
| 1388 | + $boucles[$id]->type_requete = false; |
|
| 1389 | + } else { |
|
| 1390 | + $rec->externe = $id; |
|
| 1391 | + $descr['id_mere'] = $id; |
|
| 1392 | + $boucles[$id]->return = |
|
| 1393 | + calculer_liste(array($rec), |
|
| 1394 | + $descr, |
|
| 1395 | + $boucles, |
|
| 1396 | + $boucle->param); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + foreach ($boucles as $id => $boucle) { |
|
| 1401 | + $id = strval($id); // attention au type dans index_pile |
|
| 1402 | + $type = $boucle->type_requete; |
|
| 1403 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1404 | + $res = ''; |
|
| 1405 | + if ($boucle->param) { |
|
| 1406 | + // retourne un tableau en cas d'erreur |
|
| 1407 | + $res = calculer_criteres($id, $boucles); |
|
| 1408 | + } |
|
| 1409 | + $descr['id_mere'] = $id; |
|
| 1410 | + $boucles[$id]->return = |
|
| 1411 | + calculer_liste($boucle->milieu, |
|
| 1412 | + $descr, |
|
| 1413 | + $boucles, |
|
| 1414 | + $id); |
|
| 1415 | + // Si les criteres se sont mal compiles |
|
| 1416 | + // ne pas tenter d'assembler le code final |
|
| 1417 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1418 | + if (is_array($res)) { |
|
| 1419 | + $boucles[$id]->type_requete = false; |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + // idem pour la racine |
|
| 1425 | + $descr['id_mere'] = ''; |
|
| 1426 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1430 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1431 | + // de'terminables seulement maintenant |
|
| 1432 | + |
|
| 1433 | + foreach ($boucles as $id => $boucle) { |
|
| 1434 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1435 | + if ($boucle->return === false) { |
|
| 1436 | + $corps = false; |
|
| 1437 | + continue; |
|
| 1438 | + } |
|
| 1439 | + // appeler la fonction de definition de la boucle |
|
| 1440 | + |
|
| 1441 | + if ($req = $boucle->type_requete) { |
|
| 1442 | + // boucle personnalisée ? |
|
| 1443 | + $table = strtoupper($boucle->type_requete); |
|
| 1444 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1445 | + if ( |
|
| 1446 | + // fonction de boucle avec serveur & table |
|
| 1447 | + (!$serveur or |
|
| 1448 | + ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | + and (!function_exists($f = $f . "_dist")) |
|
| 1450 | + ) |
|
| 1451 | + ) |
|
| 1452 | + // fonction de boucle avec table |
|
| 1453 | + and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | + and (!function_exists($f = $f . "_dist")) |
|
| 1455 | + ) { |
|
| 1456 | + // fonction de boucle standard |
|
| 1457 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1458 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1459 | + } |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | + "static \$connect;\n\t" . |
|
| 1464 | + "\$command['connect'] = \$connect = " . |
|
| 1465 | + _q($boucle->sql_serveur) . |
|
| 1466 | + ";" . |
|
| 1467 | + $f($id, $boucles); |
|
| 1468 | + } else { |
|
| 1469 | + $req = ("\n\treturn '';"); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + $boucles[$id]->return = |
|
| 1473 | + "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | + $req . |
|
| 1476 | + "\n}\n"; |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1480 | + // retourner False, sinon inserer leur decompilation |
|
| 1481 | + if (is_bool($corps)) { |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1486 | 1486 | ' |
| 1487 | - // reporter de maniere securisee les doublons inclus |
|
| 1488 | - . ' |
|
| 1487 | + // reporter de maniere securisee les doublons inclus |
|
| 1488 | + . ' |
|
| 1489 | 1489 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1490 | 1490 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1491 | 1491 | |
| 1492 | 1492 | $connect = ' . |
| 1493 | - _q($connect) . '; |
|
| 1493 | + _q($connect) . '; |
|
| 1494 | 1494 | $page = ' . |
| 1495 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1496 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1497 | - // avant de referencer $Cache |
|
| 1498 | - $corps . "; |
|
| 1495 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1496 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1497 | + // avant de referencer $Cache |
|
| 1498 | + $corps . "; |
|
| 1499 | 1499 | |
| 1500 | 1500 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1501 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1501 | + . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1502 | 1502 | }"; |
| 1503 | 1503 | |
| 1504 | - $secondes = spip_timer('calcul_skel'); |
|
| 1505 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1506 | - // $connect n'est pas sûr : on nettoie |
|
| 1507 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1504 | + $secondes = spip_timer('calcul_skel'); |
|
| 1505 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1506 | + // $connect n'est pas sûr : on nettoie |
|
| 1507 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1508 | 1508 | |
| 1509 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1510 | - $code = new Boucle; |
|
| 1511 | - $code->descr = $descr; |
|
| 1512 | - $code->return = ' |
|
| 1509 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1510 | + $code = new Boucle; |
|
| 1511 | + $code->descr = $descr; |
|
| 1512 | + $code->return = ' |
|
| 1513 | 1513 | // |
| 1514 | 1514 | // Fonction principale du squelette ' . |
| 1515 | - $sourcefile . |
|
| 1516 | - ($connect ? " pour $connect" : '') . |
|
| 1517 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | - "\n//\n" . |
|
| 1519 | - $principal; |
|
| 1515 | + $sourcefile . |
|
| 1516 | + ($connect ? " pour $connect" : '') . |
|
| 1517 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | + "\n//\n" . |
|
| 1519 | + $principal; |
|
| 1520 | 1520 | |
| 1521 | - $boucles[''] = $code; |
|
| 1521 | + $boucles[''] = $code; |
|
| 1522 | 1522 | |
| 1523 | - return $boucles; |
|
| 1523 | + return $boucles; |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | |
@@ -1537,18 +1537,18 @@ discard block |
||
| 1537 | 1537 | * |
| 1538 | 1538 | **/ |
| 1539 | 1539 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1540 | - if (class_exists($boucle->type_requete)) { |
|
| 1541 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1542 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1543 | - } else { |
|
| 1544 | - $x = $boucle->type_requete; |
|
| 1545 | - $boucle->type_requete = false; |
|
| 1546 | - $msg = array( |
|
| 1547 | - 'zbug_iterateur_inconnu', |
|
| 1548 | - array('iterateur' => $x) |
|
| 1549 | - ); |
|
| 1550 | - erreur_squelette($msg, $boucle); |
|
| 1551 | - } |
|
| 1540 | + if (class_exists($boucle->type_requete)) { |
|
| 1541 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1542 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1543 | + } else { |
|
| 1544 | + $x = $boucle->type_requete; |
|
| 1545 | + $boucle->type_requete = false; |
|
| 1546 | + $msg = array( |
|
| 1547 | + 'zbug_iterateur_inconnu', |
|
| 1548 | + array('iterateur' => $x) |
|
| 1549 | + ); |
|
| 1550 | + erreur_squelette($msg, $boucle); |
|
| 1551 | + } |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | |
@@ -1566,23 +1566,23 @@ discard block |
||
| 1566 | 1566 | * |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1569 | - include_spip('iterateur/data'); |
|
| 1570 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1571 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1572 | - $boucles[$id] = $g($boucle); |
|
| 1573 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1574 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1575 | - |
|
| 1576 | - } else { |
|
| 1577 | - $x = $boucle->type_requete; |
|
| 1578 | - $boucle->type_requete = false; |
|
| 1579 | - $msg = array( |
|
| 1580 | - 'zbug_requeteur_inconnu', |
|
| 1581 | - array( |
|
| 1582 | - 'requeteur' => 'data', |
|
| 1583 | - 'type' => $x |
|
| 1584 | - ) |
|
| 1585 | - ); |
|
| 1586 | - erreur_squelette($msg, $boucle); |
|
| 1587 | - } |
|
| 1569 | + include_spip('iterateur/data'); |
|
| 1570 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1571 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1572 | + $boucles[$id] = $g($boucle); |
|
| 1573 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1574 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1575 | + |
|
| 1576 | + } else { |
|
| 1577 | + $x = $boucle->type_requete; |
|
| 1578 | + $boucle->type_requete = false; |
|
| 1579 | + $msg = array( |
|
| 1580 | + 'zbug_requeteur_inconnu', |
|
| 1581 | + array( |
|
| 1582 | + 'requeteur' => 'data', |
|
| 1583 | + 'type' => $x |
|
| 1584 | + ) |
|
| 1585 | + ); |
|
| 1586 | + erreur_squelette($msg, $boucle); |
|
| 1587 | + } |
|
| 1588 | 1588 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
| 98 | 98 | $m = array_pad($m, 3, null); |
| 99 | 99 | $var = $m[1]; |
| 100 | - $auto = false;; |
|
| 100 | + $auto = false; ; |
|
| 101 | 101 | if ($m[2]) { |
| 102 | 102 | $v = $m[3]; |
| 103 | 103 | if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
@@ -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 | |
| 176 | 176 | } else { |
| 177 | 177 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | return false; |
| 214 | 214 | } // j'aurais voulu toucher le fond ... |
| 215 | 215 | |
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 216 | + $contexte = 'array('.$_contexte.')'; |
|
| 217 | 217 | |
| 218 | 218 | if ($env) { |
| 219 | 219 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $_options[] = $ajax; |
| 229 | 229 | } |
| 230 | 230 | $code = " ' . argumenter_squelette($code) . '"; |
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 231 | + $code = "echo ".sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")").';'; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 235 | + return "\n'<'.'"."?php ".$code."\n?'."."'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | $id = $id_table; |
| 313 | 313 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 314 | 314 | } |
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 315 | + $mstatut = $id.'.'.$statut; |
|
| 316 | 316 | |
| 317 | 317 | $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
| 318 | 318 | include_spip('public/quete'); |
| 319 | 319 | if (isset($s['post_date']) and $s['post_date'] |
| 320 | 320 | and $GLOBALS['meta']["post_dates"] == 'non' |
| 321 | 321 | ) { |
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 322 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | 323 | array_unshift($boucle->where, |
| 324 | 324 | $echapper ? |
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 325 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 326 | 326 | : |
| 327 | 327 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 328 | 328 | ); |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | array_unshift($boucle->where, |
| 331 | 331 | $echapper ? |
| 332 | 332 | "\nquete_condition_statut('$mstatut'," |
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 333 | + . _q($s['previsu'])."," |
|
| 334 | + . _q($s['publie'])."," |
|
| 335 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 336 | 336 | : |
| 337 | 337 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 338 | 338 | ); |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | if (_request('var_mode_affiche') != 'resultat') { |
| 367 | 367 | $trace = ''; |
| 368 | 368 | } else { |
| 369 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 369 | + $trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 370 | 370 | $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
| 371 | 371 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 372 | 372 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | return |
| 402 | 402 | // Numrows[$nom] peut ne pas être encore defini |
| 403 | 403 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 404 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 404 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.";" |
|
| 405 | 405 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 406 | 406 | . $trace |
| 407 | 407 | . "\n\treturn \$t0;"; |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 470 | 470 | // et puis faire un [] plutot qu'un "','." |
| 471 | 471 | if ($boucle->doublons) { |
| 472 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 472 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 473 | 473 | index_pile($id_boucle, $primary, $boucles) |
| 474 | 474 | . "; // doublons\n"; |
| 475 | 475 | } |
@@ -496,13 +496,13 @@ discard block |
||
| 496 | 496 | $corps .= |
| 497 | 497 | "\n\t\tlang_select_public(" |
| 498 | 498 | . index_pile($id_boucle, 'lang', $boucles) |
| 499 | - . ", '" . $boucle->lang_select . "'" |
|
| 499 | + . ", '".$boucle->lang_select."'" |
|
| 500 | 500 | . (in_array($type_boucle, array( |
| 501 | 501 | 'articles', |
| 502 | 502 | 'rubriques', |
| 503 | 503 | 'hierarchie', |
| 504 | 504 | 'breves' |
| 505 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 505 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | 506 | . ');'; |
| 507 | 507 | } else { |
| 508 | 508 | $init_lang = ''; |
@@ -523,26 +523,22 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | // gestion optimale des separateurs et des boucles constantes |
| 525 | 525 | if (count($boucle->separateur)) { |
| 526 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 526 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | $corps .= |
| 530 | 530 | ((!$boucle->separateur) ? |
| 531 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | - (($return === "''") ? '' : |
|
| 533 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | - ("\n\t\t\$t1 " . |
|
| 531 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.";"))) : ("\n\t\t\$t1 ". |
|
| 535 | 532 | ((strpos($return, '$t1.') === 0) ? |
| 536 | - (".=" . substr($return, 4)) : |
|
| 537 | - ('= ' . $return)) . |
|
| 538 | - ";\n\t\t" . |
|
| 539 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 533 | + (".=".substr($return, 4)) : ('= '.$return)). |
|
| 534 | + ";\n\t\t". |
|
| 535 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 540 | 536 | |
| 541 | 537 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 542 | 538 | // souhaite invalider ces elements |
| 543 | 539 | if (!$constant and $primary) { |
| 544 | 540 | include_spip('inc/invalideur'); |
| 545 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 541 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 546 | 542 | } |
| 547 | 543 | |
| 548 | 544 | // gerer le compteur de boucle |
@@ -616,7 +612,7 @@ discard block |
||
| 616 | 612 | $corps, |
| 617 | 613 | $fin_lang, |
| 618 | 614 | $trace, |
| 619 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 615 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 620 | 616 | ); |
| 621 | 617 | |
| 622 | 618 | # var_dump($a);exit; |
@@ -637,20 +633,20 @@ discard block |
||
| 637 | 633 | **/ |
| 638 | 634 | function calculer_requete_sql($boucle) { |
| 639 | 635 | $init = array(); |
| 640 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 636 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 637 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 642 | 638 | # En absence de champ c'est un decompte : |
| 643 | 639 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 644 | 640 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 645 | 641 | $init[] = calculer_dec('groupby', |
| 646 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 642 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').")"); |
|
| 643 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select)."\")"); |
|
| 644 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).")"); |
|
| 649 | 645 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 650 | 646 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 651 | 647 | $init[] = calculer_dec('limit', |
| 652 | 648 | (strpos($boucle->limit, 'intval') === false ? |
| 653 | - "'" . $boucle->limit . "'" |
|
| 649 | + "'".$boucle->limit."'" |
|
| 654 | 650 | : |
| 655 | 651 | $boucle->limit)); |
| 656 | 652 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -659,17 +655,17 @@ discard block |
||
| 659 | 655 | // ou recalculée à chaque passage (vide) |
| 660 | 656 | foreach ($init as $i) { |
| 661 | 657 | if (reset($i)) { |
| 662 | - $s .= "\n\t\t" . end($i); |
|
| 658 | + $s .= "\n\t\t".end($i); |
|
| 663 | 659 | } # statique |
| 664 | 660 | else { |
| 665 | - $d .= "\n\t" . end($i); |
|
| 661 | + $d .= "\n\t".end($i); |
|
| 666 | 662 | } # dynamique |
| 667 | 663 | } |
| 668 | 664 | |
| 669 | 665 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 670 | 666 | . $boucle->in |
| 671 | 667 | . $boucle->hash |
| 672 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 668 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 673 | 669 | . $s |
| 674 | 670 | . "\n\t}" |
| 675 | 671 | . $d; |
@@ -752,7 +748,7 @@ discard block |
||
| 752 | 748 | * - index 1 : Code de l'affectation |
| 753 | 749 | **/ |
| 754 | 750 | function calculer_dec($nom, $val) { |
| 755 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 751 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 756 | 752 | // si une variable apparait dans le calcul de la clause |
| 757 | 753 | // il faut la re-evaluer a chaque passage |
| 758 | 754 | if ( |
@@ -769,7 +765,7 @@ discard block |
||
| 769 | 765 | $static = ""; |
| 770 | 766 | } |
| 771 | 767 | |
| 772 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 768 | + return array($static, '$command[\''.$nom.'\'] = '.$val.';'); |
|
| 773 | 769 | } |
| 774 | 770 | |
| 775 | 771 | /** |
@@ -794,16 +790,16 @@ discard block |
||
| 794 | 790 | } |
| 795 | 791 | $res = ""; |
| 796 | 792 | if ($a and $a[0] == "'?'") { |
| 797 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | - " ? " . calculer_dump_array($a[2]) . |
|
| 799 | - " : " . calculer_dump_array($a[3]) . |
|
| 793 | + return ("(".calculer_dump_array($a[1]). |
|
| 794 | + " ? ".calculer_dump_array($a[2]). |
|
| 795 | + " : ".calculer_dump_array($a[3]). |
|
| 800 | 796 | ")"); |
| 801 | 797 | } else { |
| 802 | 798 | foreach ($a as $v) { |
| 803 | - $res .= ", " . calculer_dump_array($v); |
|
| 799 | + $res .= ", ".calculer_dump_array($v); |
|
| 804 | 800 | } |
| 805 | 801 | |
| 806 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 802 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 807 | 803 | } |
| 808 | 804 | } |
| 809 | 805 | |
@@ -811,10 +807,10 @@ discard block |
||
| 811 | 807 | function calculer_dump_join($a) { |
| 812 | 808 | $res = ""; |
| 813 | 809 | foreach ($a as $k => $v) { |
| 814 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 810 | + $res .= ", '$k' => array(".implode(',', $v).")"; |
|
| 815 | 811 | } |
| 816 | 812 | |
| 817 | - return 'array(' . substr($res, 2) . ')'; |
|
| 813 | + return 'array('.substr($res, 2).')'; |
|
| 818 | 814 | } |
| 819 | 815 | |
| 820 | 816 | /** |
@@ -831,7 +827,7 @@ discard block |
||
| 831 | 827 | $res .= ",'$k' => '$v'"; |
| 832 | 828 | } |
| 833 | 829 | |
| 834 | - return 'array(' . substr($res, 1) . ')'; |
|
| 830 | + return 'array('.substr($res, 1).')'; |
|
| 835 | 831 | } |
| 836 | 832 | |
| 837 | 833 | /** |
@@ -849,7 +845,7 @@ discard block |
||
| 849 | 845 | $res .= ",'$k' => '$v'"; |
| 850 | 846 | } |
| 851 | 847 | |
| 852 | - return 'array(' . substr($res, 1) . ')'; |
|
| 848 | + return 'array('.substr($res, 1).')'; |
|
| 853 | 849 | } |
| 854 | 850 | |
| 855 | 851 | // http://code.spip.net/@calculer_order |
@@ -903,17 +899,17 @@ discard block |
||
| 903 | 899 | ) { |
| 904 | 900 | $res .= " .\n$tab$code"; |
| 905 | 901 | } else { |
| 906 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 902 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 907 | 903 | } |
| 908 | 904 | } |
| 909 | 905 | |
| 910 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 906 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 911 | 907 | } |
| 912 | 908 | } else { |
| 913 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 909 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | 910 | |
| 915 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | - $codes) . ")))"; |
|
| 911 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join(" ,\n$tab", |
|
| 912 | + $codes).")))"; |
|
| 917 | 913 | } |
| 918 | 914 | } |
| 919 | 915 | |
@@ -941,7 +937,7 @@ discard block |
||
| 941 | 937 | // texte seul |
| 942 | 938 | case 'texte': |
| 943 | 939 | $code = sandbox_composer_texte($p->texte, $p); |
| 944 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 940 | + $commentaire = strlen($p->texte)." signes"; |
|
| 945 | 941 | $avant = ''; |
| 946 | 942 | $apres = ''; |
| 947 | 943 | $altern = "''"; |
@@ -950,14 +946,14 @@ discard block |
||
| 950 | 946 | case 'polyglotte': |
| 951 | 947 | $code = ""; |
| 952 | 948 | foreach ($p->traductions as $k => $v) { |
| 953 | - $code .= ",'" . |
|
| 954 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | - "' => '" . |
|
| 956 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 949 | + $code .= ",'". |
|
| 950 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k). |
|
| 951 | + "' => '". |
|
| 952 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v). |
|
| 957 | 953 | "'"; |
| 958 | 954 | } |
| 959 | - $code = "choisir_traduction(array(" . |
|
| 960 | - substr($code, 1) . |
|
| 955 | + $code = "choisir_traduction(array(". |
|
| 956 | + substr($code, 1). |
|
| 961 | 957 | "))"; |
| 962 | 958 | $commentaire = '&'; |
| 963 | 959 | $avant = ''; |
@@ -973,7 +969,7 @@ discard block |
||
| 973 | 969 | $err_e_c = true; |
| 974 | 970 | $code = "''"; |
| 975 | 971 | } else { |
| 976 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 972 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 977 | 973 | $avant = ''; |
| 978 | 974 | $apres = ''; |
| 979 | 975 | $altern = "''"; |
@@ -997,8 +993,8 @@ discard block |
||
| 997 | 993 | $err_e_c = true; |
| 998 | 994 | $code = "''"; |
| 999 | 995 | } else { |
| 1000 | - $code = 'BOUCLE' . |
|
| 1001 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 996 | + $code = 'BOUCLE'. |
|
| 997 | + str_replace("-", "_", $nom).$descr['nom']. |
|
| 1002 | 998 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1003 | 999 | $commentaire = "?$nom"; |
| 1004 | 1000 | if (!$boucles[$nom]->milieu |
@@ -1025,24 +1021,22 @@ discard block |
||
| 1025 | 1021 | foreach ($p->arg as $k => $v) { |
| 1026 | 1022 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1027 | 1023 | if ($k) { |
| 1028 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1024 | + $l[] = _q($k).' => '.$_v; |
|
| 1029 | 1025 | } else { |
| 1030 | 1026 | $code = $_v; |
| 1031 | 1027 | } |
| 1032 | 1028 | } |
| 1033 | 1029 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1034 | 1030 | if ($p->module) { |
| 1035 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1031 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1036 | 1032 | } elseif ($p->nom_champ) { |
| 1037 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1033 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1038 | 1034 | } else { |
| 1039 | 1035 | $m = ''; |
| 1040 | 1036 | } |
| 1041 | 1037 | |
| 1042 | - $code = (!$code ? "'$m'" : |
|
| 1043 | - ($m ? "'$m' . $code" : |
|
| 1044 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1038 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1039 | + . (!$l ? '' : (", array(".implode(",\n", $l).")")); |
|
| 1046 | 1040 | $code = "_T($code)"; |
| 1047 | 1041 | if ($p->param) { |
| 1048 | 1042 | $p->id_boucle = $id_boucle; |
@@ -1065,7 +1059,7 @@ discard block |
||
| 1065 | 1059 | $p->type_requete = $type; |
| 1066 | 1060 | |
| 1067 | 1061 | $code = calculer_champ($p); |
| 1068 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1062 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1069 | 1063 | $avant = calculer_liste($p->avant, |
| 1070 | 1064 | $descr, $boucles, $id_boucle); |
| 1071 | 1065 | $apres = calculer_liste($p->apres, |
@@ -1096,10 +1090,9 @@ discard block |
||
| 1096 | 1090 | if ($code != "''") { |
| 1097 | 1091 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1098 | 1092 | $codes[] = (($mode == 'validation') ? |
| 1099 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1093 | + "array($code, '$commentaire', ".$p->ligne.")" |
|
| 1100 | 1094 | : (($mode == 'code') ? |
| 1101 | - "\n// $commentaire\n$code" : |
|
| 1102 | - $code)); |
|
| 1095 | + "\n// $commentaire\n$code" : $code)); |
|
| 1103 | 1096 | } |
| 1104 | 1097 | } // foreach |
| 1105 | 1098 | |
@@ -1127,19 +1120,19 @@ discard block |
||
| 1127 | 1120 | $cond = ''; |
| 1128 | 1121 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1129 | 1122 | $t = $r[2]; |
| 1130 | - $cond = '!' . $r[1]; |
|
| 1123 | + $cond = '!'.$r[1]; |
|
| 1131 | 1124 | } else { |
| 1132 | 1125 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1133 | 1126 | $t = $r[2]; |
| 1134 | 1127 | $cond = $r[1]; |
| 1135 | 1128 | } else { |
| 1136 | - $t = '$t' . $n; |
|
| 1129 | + $t = '$t'.$n; |
|
| 1137 | 1130 | $cond = "($t = $code)!==''"; |
| 1138 | 1131 | } |
| 1139 | 1132 | } |
| 1140 | 1133 | |
| 1141 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | - $t . |
|
| 1134 | + $res = (!$avant ? "" : "$avant . "). |
|
| 1135 | + $t. |
|
| 1143 | 1136 | (!$apres ? "" : " . $apres"); |
| 1144 | 1137 | |
| 1145 | 1138 | if ($res !== $t) { |
@@ -1188,12 +1181,12 @@ discard block |
||
| 1188 | 1181 | |
| 1189 | 1182 | // rendre inertes les echappements de #[](){}<> |
| 1190 | 1183 | $i = 0; |
| 1191 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1184 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1192 | 1185 | $i++; |
| 1193 | 1186 | } |
| 1194 | 1187 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1195 | 1188 | function($a) use ($inerte) { |
| 1196 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1189 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1197 | 1190 | }, |
| 1198 | 1191 | $squelette, |
| 1199 | 1192 | -1, |
@@ -1210,7 +1203,7 @@ discard block |
||
| 1210 | 1203 | // Phraser le squelette, selon sa grammaire |
| 1211 | 1204 | |
| 1212 | 1205 | $boucles = array(); |
| 1213 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1206 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1214 | 1207 | |
| 1215 | 1208 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1216 | 1209 | |
@@ -1229,7 +1222,7 @@ discard block |
||
| 1229 | 1222 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1230 | 1223 | ",$inerte-(\d+)-,", |
| 1231 | 1224 | function($a) { |
| 1232 | - return "\\\\" . chr($a[1]); |
|
| 1225 | + return "\\\\".chr($a[1]); |
|
| 1233 | 1226 | }, |
| 1234 | 1227 | $boucle->descr['squelette'] |
| 1235 | 1228 | ); |
@@ -1241,19 +1234,19 @@ discard block |
||
| 1241 | 1234 | include_spip('public/decompiler'); |
| 1242 | 1235 | foreach ($boucles as $id => $boucle) { |
| 1243 | 1236 | if ($id) { |
| 1244 | - $decomp = "\n/* BOUCLE " . |
|
| 1245 | - $boucle->type_requete . |
|
| 1246 | - " " . |
|
| 1247 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1237 | + $decomp = "\n/* BOUCLE ". |
|
| 1238 | + $boucle->type_requete. |
|
| 1239 | + " ". |
|
| 1240 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1241 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1249 | 1242 | " */\n"; |
| 1250 | 1243 | } else { |
| 1251 | - $decomp = ("\n/*\n" . |
|
| 1244 | + $decomp = ("\n/*\n". |
|
| 1252 | 1245 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1253 | 1246 | . "\n*/"); |
| 1254 | 1247 | } |
| 1255 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1248 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1249 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1257 | 1250 | } |
| 1258 | 1251 | } |
| 1259 | 1252 | |
@@ -1276,7 +1269,7 @@ discard block |
||
| 1276 | 1269 | } |
| 1277 | 1270 | } |
| 1278 | 1271 | foreach ($boucles as $id => $boucle) { |
| 1279 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1272 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1280 | 1273 | } |
| 1281 | 1274 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1282 | 1275 | |
@@ -1358,8 +1351,7 @@ discard block |
||
| 1358 | 1351 | } else { |
| 1359 | 1352 | $boucles[$id]->type_requete = false; |
| 1360 | 1353 | $boucle = $boucles[$id]; |
| 1361 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | - ($boucle->sql_serveur . ":")) . |
|
| 1354 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.":")). |
|
| 1363 | 1355 | $type; |
| 1364 | 1356 | $msg = array( |
| 1365 | 1357 | 'zbug_table_inconnue', |
@@ -1445,13 +1437,13 @@ discard block |
||
| 1445 | 1437 | if ( |
| 1446 | 1438 | // fonction de boucle avec serveur & table |
| 1447 | 1439 | (!$serveur or |
| 1448 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | - and (!function_exists($f = $f . "_dist")) |
|
| 1440 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1441 | + and (!function_exists($f = $f."_dist")) |
|
| 1450 | 1442 | ) |
| 1451 | 1443 | ) |
| 1452 | 1444 | // fonction de boucle avec table |
| 1453 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | - and (!function_exists($f = $f . "_dist")) |
|
| 1445 | + and (!function_exists($f = "boucle_".$table)) |
|
| 1446 | + and (!function_exists($f = $f."_dist")) |
|
| 1455 | 1447 | ) { |
| 1456 | 1448 | // fonction de boucle standard |
| 1457 | 1449 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1459,20 +1451,20 @@ discard block |
||
| 1459 | 1451 | } |
| 1460 | 1452 | } |
| 1461 | 1453 | |
| 1462 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | - "static \$connect;\n\t" . |
|
| 1464 | - "\$command['connect'] = \$connect = " . |
|
| 1465 | - _q($boucle->sql_serveur) . |
|
| 1466 | - ";" . |
|
| 1454 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1455 | + "static \$connect;\n\t". |
|
| 1456 | + "\$command['connect'] = \$connect = ". |
|
| 1457 | + _q($boucle->sql_serveur). |
|
| 1458 | + ";". |
|
| 1467 | 1459 | $f($id, $boucles); |
| 1468 | 1460 | } else { |
| 1469 | 1461 | $req = ("\n\treturn '';"); |
| 1470 | 1462 | } |
| 1471 | 1463 | |
| 1472 | 1464 | $boucles[$id]->return = |
| 1473 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | - $req . |
|
| 1465 | + "\n\nfunction BOUCLE".strtr($id, "-", "_").$nom. |
|
| 1466 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1467 | + $req. |
|
| 1476 | 1468 | "\n}\n"; |
| 1477 | 1469 | } |
| 1478 | 1470 | |
@@ -1482,7 +1474,7 @@ discard block |
||
| 1482 | 1474 | return false; |
| 1483 | 1475 | } |
| 1484 | 1476 | |
| 1485 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1477 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1486 | 1478 | ' |
| 1487 | 1479 | // reporter de maniere securisee les doublons inclus |
| 1488 | 1480 | . ' |
@@ -1490,15 +1482,15 @@ discard block |
||
| 1490 | 1482 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1491 | 1483 | |
| 1492 | 1484 | $connect = ' . |
| 1493 | - _q($connect) . '; |
|
| 1485 | + _q($connect).'; |
|
| 1494 | 1486 | $page = ' . |
| 1495 | 1487 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1496 | 1488 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1497 | 1489 | // avant de referencer $Cache |
| 1498 | - $corps . "; |
|
| 1490 | + $corps."; |
|
| 1499 | 1491 | |
| 1500 | 1492 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1501 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1493 | + . ", \$Cache, \$page, ".var_export($sourcefile, true)."); |
|
| 1502 | 1494 | }"; |
| 1503 | 1495 | |
| 1504 | 1496 | $secondes = spip_timer('calcul_skel'); |
@@ -1512,10 +1504,10 @@ discard block |
||
| 1512 | 1504 | $code->return = ' |
| 1513 | 1505 | // |
| 1514 | 1506 | // Fonction principale du squelette ' . |
| 1515 | - $sourcefile . |
|
| 1516 | - ($connect ? " pour $connect" : '') . |
|
| 1517 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | - "\n//\n" . |
|
| 1507 | + $sourcefile. |
|
| 1508 | + ($connect ? " pour $connect" : ''). |
|
| 1509 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1510 | + "\n//\n". |
|
| 1519 | 1511 | $principal; |
| 1520 | 1512 | |
| 1521 | 1513 | $boucles[''] = $code; |
@@ -1567,7 +1559,7 @@ discard block |
||
| 1567 | 1559 | **/ |
| 1568 | 1560 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1569 | 1561 | include_spip('iterateur/data'); |
| 1570 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1562 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1571 | 1563 | $g = charger_fonction('data', 'iterateur'); |
| 1572 | 1564 | $boucles[$id] = $g($boucle); |
| 1573 | 1565 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -133,6 +133,10 @@ discard block |
||
| 133 | 133 | return $nom ? $nom : false; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | +/** |
|
| 137 | + * @param string $squelette |
|
| 138 | + * @param string $phpfile |
|
| 139 | + */ |
|
| 136 | 140 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 137 | 141 | |
| 138 | 142 | // Le dernier index est '' (fonction principale) |
@@ -157,6 +161,9 @@ discard block |
||
| 157 | 161 | |
| 158 | 162 | // Le squelette compile est-il trop vieux ? |
| 159 | 163 | // http://code.spip.net/@squelette_obsolete |
| 164 | +/** |
|
| 165 | + * @param string $skel |
|
| 166 | + */ |
|
| 160 | 167 | function squelette_obsolete($skel, $squelette) { |
| 161 | 168 | static $date_change = null; |
| 162 | 169 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 57 | 57 | |
| 58 | 58 | // si squelette est deja compile et perenne, le charger |
| 59 | 59 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | #} |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 69 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 70 | 70 | include_once $lib; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 120 | 120 | |
| 121 | 121 | // Tracer ce qui vient d'etre compile |
| 122 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 122 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 123 | 123 | |
| 124 | 124 | // si c'est ce que demande le debusqueur, lui passer la main |
| 125 | 125 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | $code = " |
| 142 | 142 | /* |
| 143 | 143 | * Squelette : $sourcefile |
| 144 | - * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
|
| 145 | - * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
|
| 146 | - * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
|
| 144 | + * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
|
| 145 | + * Compile : " . gmdate("D, d M Y H:i:s", time())." GMT |
|
| 146 | + * " . (!$boucles ? "Pas de boucle" : ("Boucles : ".$noms))." |
|
| 147 | 147 | */ "; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 150 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 151 | 151 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 152 | 152 | ecrire_fichier($phpfile, $code); |
| 153 | 153 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 208 | 208 | |
| 209 | 209 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 210 | - $headers[$j] .= "|" . $r[3]; |
|
| 210 | + $headers[$j] .= "|".$r[3]; |
|
| 211 | 211 | } else { |
| 212 | 212 | $headers[$j] = $r[3]; |
| 213 | 213 | } |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | // S'agit-il d'un resultat constant ou contenant du code php |
| 217 | 217 | $process_ins = ( |
| 218 | - strpos($corps, '<' . '?') === false |
|
| 218 | + strpos($corps, '<'.'?') === false |
|
| 219 | 219 | or |
| 220 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 221 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 220 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 221 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 222 | 222 | ) |
| 223 | 223 | ? 'html' |
| 224 | 224 | : 'php'; |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | if ($process_ins == 'html') { |
| 246 | 246 | $skel['process_ins'] = ( |
| 247 | - strpos($corps, '<' . '?') === false |
|
| 247 | + strpos($corps, '<'.'?') === false |
|
| 248 | 248 | or |
| 249 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 250 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 249 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 250 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 251 | 251 | ) |
| 252 | 252 | ? 'html' |
| 253 | 253 | : 'php'; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | if (strlen($intro)) { |
| 326 | 326 | $texte = $intro; |
| 327 | 327 | } else { |
| 328 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 328 | + if (strpos("\n".$texte, "\n|") === false |
|
| 329 | 329 | and strlen($texte) > 2.5 * $longueur |
| 330 | 330 | ) { |
| 331 | 331 | if (strpos($texte, "<multi") !== false) { |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | // |
| 371 | 371 | |
| 372 | 372 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 373 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 373 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 374 | 374 | include_once("%s"); |
| 375 | 375 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 376 | 376 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | **/ |
| 398 | 398 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 399 | 399 | if (strncmp($file, "/", 1) !== 0) { |
| 400 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 400 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 401 | 401 | } |
| 402 | 402 | $r = sprintf(CODE_INCLURE_BALISE, |
| 403 | 403 | $file, |
@@ -425,14 +425,14 @@ discard block |
||
| 425 | 425 | function argumenter_squelette($v) { |
| 426 | 426 | |
| 427 | 427 | if (!is_array($v)) { |
| 428 | - return "'" . texte_script($v) . "'"; |
|
| 428 | + return "'".texte_script($v)."'"; |
|
| 429 | 429 | } else { |
| 430 | 430 | $out = array(); |
| 431 | 431 | foreach ($v as $k => $val) { |
| 432 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 432 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - return 'array(' . join(", ", $out) . ')'; |
|
| 435 | + return 'array('.join(", ", $out).')'; |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Y a-t-il une fonction de traitement des arguments ? |
| 500 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 500 | + $f = 'balise_'.$nomfonction.'_stat'; |
|
| 501 | 501 | |
| 502 | 502 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 503 | 503 | |
@@ -507,16 +507,16 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | // verifier que la fonction dyn est la, |
| 509 | 509 | // sinon se replier sur la generique si elle existe |
| 510 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 510 | + if (!function_exists('balise_'.$nomfonction.'_dyn')) { |
|
| 511 | 511 | if ($nomfonction_generique |
| 512 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 513 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 512 | + and $file = include_spip("balise/".strtolower($nomfonction_generique)) |
|
| 513 | + and function_exists('balise_'.$nomfonction_generique.'_dyn') |
|
| 514 | 514 | ) { |
| 515 | 515 | // et lui injecter en premier arg le nom de la balise |
| 516 | 516 | array_unshift($r, $nom); |
| 517 | 517 | $nomfonction = $nomfonction_generique; |
| 518 | 518 | if (!_DIR_RESTREINT) { |
| 519 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 519 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 520 | 520 | } |
| 521 | 521 | } else { |
| 522 | 522 | $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | $n = ''; |
| 638 | 638 | foreach (explode(',', $liste) as $val) { |
| 639 | 639 | if ($a = intval($val) and $val === strval($a)) { |
| 640 | - $n .= ',' . $val; |
|
| 640 | + $n .= ','.$val; |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | if (strlen($n)) { |
@@ -816,14 +816,14 @@ discard block |
||
| 816 | 816 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 817 | 817 | $i = 0; |
| 818 | 818 | do { |
| 819 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 820 | - array($sous[1] . " AS id"), |
|
| 819 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 820 | + array($sous[1]." AS id"), |
|
| 821 | 821 | $from, |
| 822 | 822 | $from_type, |
| 823 | 823 | $wheresub, |
| 824 | 824 | $jsub, |
| 825 | 825 | array(), array(), '', |
| 826 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 826 | + $having, $table, $id, $serveur, false).")"); |
|
| 827 | 827 | if (!$i) { |
| 828 | 828 | $i = 1; |
| 829 | 829 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if ($sous[0] == 'SUBSELECT') { |
| 843 | 843 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 844 | 844 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 845 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 845 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 846 | 846 | $sous[1], # select |
| 847 | 847 | $sous[2], #from |
| 848 | 848 | array(), #from_type |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | $sous[6], #limit |
| 855 | 855 | $sous[7] ? $sous[7] : array(), #having |
| 856 | 856 | $table, $id, $serveur, false |
| 857 | - ) . ")"); |
|
| 857 | + ).")"); |
|
| 858 | 858 | } |
| 859 | 859 | array_pop($where_simples); |
| 860 | 860 | } |
@@ -915,15 +915,15 @@ discard block |
||
| 915 | 915 | // sans recours a preg_match |
| 916 | 916 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 917 | 917 | $afrom[$t][$cle] = array( |
| 918 | - "\n" . |
|
| 919 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 918 | + "\n". |
|
| 919 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER")." JOIN", |
|
| 920 | 920 | $from[$cle], |
| 921 | 921 | "AS $cle", |
| 922 | 922 | "ON (", |
| 923 | 923 | "$cle.$c", |
| 924 | 924 | "=", |
| 925 | 925 | "$t.$carr", |
| 926 | - ($and ? "AND " . $and : "") . |
|
| 926 | + ($and ? "AND ".$and : ""). |
|
| 927 | 927 | ")" |
| 928 | 928 | ); |
| 929 | 929 | if (isset($afrom[$cle])) { |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | $t = key($from); |
| 958 | 958 | $c = current($from); |
| 959 | 959 | reset($from); |
| 960 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 960 | + $e = '/\b('."$t\\.".join("|".$t.'\.', $equiv).')\b/'; |
|
| 961 | 961 | if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 962 | 962 | calculer_jointnul($t, $select, $e) or |
| 963 | 963 | calculer_jointnul($t, $join, $e) or |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | unset($afrom[$t][$nt]); |
| 975 | 975 | $afrom[$nt] = $afrom[$t]; |
| 976 | 976 | unset($afrom[$t]); |
| 977 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 977 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 978 | 978 | $t = $nfrom[4]; |
| 979 | 979 | $alias = ""; |
| 980 | 980 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -985,14 +985,14 @@ discard block |
||
| 985 | 985 | if ($newcle != $oldcle) { |
| 986 | 986 | // si l'ancienne cle etait deja dans le select avec un AS |
| 987 | 987 | // reprendre simplement ce AS |
| 988 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 988 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 989 | 989 | if (preg_match($as, implode(',', $select), $m)) { |
| 990 | 990 | $alias = ""; |
| 991 | 991 | } else { |
| 992 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 992 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 993 | 993 | } |
| 994 | 994 | } |
| 995 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 995 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 996 | 996 | $join = remplacer_jointnul($t, $join, $e); |
| 997 | 997 | $where = remplacer_jointnul($t, $where, $e); |
| 998 | 998 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1026,9 +1026,9 @@ discard block |
||
| 1026 | 1026 | } else { |
| 1027 | 1027 | $exp = ""; |
| 1028 | 1028 | if (strtoupper($join) === 'AND') { |
| 1029 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1029 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1030 | 1030 | } else { |
| 1031 | - return $exp . join($join, $v); |
|
| 1031 | + return $exp.join($join, $v); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | } |
@@ -1094,6 +1094,6 @@ discard block |
||
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | return $mime_type |
| 1097 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1098 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1097 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)).'_' |
|
| 1098 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1099 | 1099 | } |
@@ -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'); |
@@ -42,223 +42,223 @@ discard block |
||
| 42 | 42 | // http://code.spip.net/@public_composer_dist |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 44 | 44 | |
| 45 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | - |
|
| 47 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | - if (function_exists($nom)) { |
|
| 49 | - return $nom; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | - |
|
| 58 | - // si squelette est deja compile et perenne, le charger |
|
| 59 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | - include_once $phpfile; |
|
| 61 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | - ## eval('?'.'>'.$skel_code); |
|
| 65 | - # spip_log($skel_code, 'comp') |
|
| 66 | - #} |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | - include_once $lib; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | - |
|
| 75 | - if (function_exists($nom)) { |
|
| 76 | - return $nom; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // charger le source, si possible, et compiler |
|
| 80 | - $skel_code = ''; |
|
| 81 | - if (lire_fichier($source, $skel)) { |
|
| 82 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | - if (!$skel_code) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - foreach ($skel_code as $id => $boucle) { |
|
| 92 | - $f = $boucle->return; |
|
| 93 | - if (@eval("return true; $f ;") === false) { |
|
| 94 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | - $msg = _T('zbug_erreur_compilation'); |
|
| 96 | - erreur_squelette($msg, $boucle); |
|
| 97 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | - // mais prevenir que c'est mort |
|
| 99 | - $nom = ''; |
|
| 100 | - } |
|
| 101 | - // Contexte de compil inutile a present |
|
| 102 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | - $skel_code[$id] = $f; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $code = ''; |
|
| 107 | - if ($nom) { |
|
| 108 | - // Si le code est bon, concatener et mettre en cache |
|
| 109 | - if (function_exists($nom)) { |
|
| 110 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | - } else { |
|
| 112 | - // code semantiquement faux: bug du compilateur |
|
| 113 | - // $boucle est en fait ici la fct principale du squelette |
|
| 114 | - $msg = _T('zbug_erreur_compilation'); |
|
| 115 | - erreur_squelette($msg, $boucle); |
|
| 116 | - $nom = ''; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | - |
|
| 122 | - // Tracer ce qui vient d'etre compile |
|
| 123 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | - |
|
| 125 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | - and (_request('var_mode_objet') == $nom) |
|
| 128 | - and (_request('var_mode_affiche') == 'code') |
|
| 129 | - ) { |
|
| 130 | - erreur_squelette(); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $nom ? $nom : false; |
|
| 45 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | + |
|
| 47 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | + if (function_exists($nom)) { |
|
| 49 | + return $nom; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + |
|
| 58 | + // si squelette est deja compile et perenne, le charger |
|
| 59 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | + include_once $phpfile; |
|
| 61 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | + ## eval('?'.'>'.$skel_code); |
|
| 65 | + # spip_log($skel_code, 'comp') |
|
| 66 | + #} |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + include_once $lib; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | + |
|
| 75 | + if (function_exists($nom)) { |
|
| 76 | + return $nom; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // charger le source, si possible, et compiler |
|
| 80 | + $skel_code = ''; |
|
| 81 | + if (lire_fichier($source, $skel)) { |
|
| 82 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | + if (!$skel_code) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + foreach ($skel_code as $id => $boucle) { |
|
| 92 | + $f = $boucle->return; |
|
| 93 | + if (@eval("return true; $f ;") === false) { |
|
| 94 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | + $msg = _T('zbug_erreur_compilation'); |
|
| 96 | + erreur_squelette($msg, $boucle); |
|
| 97 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | + // mais prevenir que c'est mort |
|
| 99 | + $nom = ''; |
|
| 100 | + } |
|
| 101 | + // Contexte de compil inutile a present |
|
| 102 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | + $skel_code[$id] = $f; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $code = ''; |
|
| 107 | + if ($nom) { |
|
| 108 | + // Si le code est bon, concatener et mettre en cache |
|
| 109 | + if (function_exists($nom)) { |
|
| 110 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | + } else { |
|
| 112 | + // code semantiquement faux: bug du compilateur |
|
| 113 | + // $boucle est en fait ici la fct principale du squelette |
|
| 114 | + $msg = _T('zbug_erreur_compilation'); |
|
| 115 | + erreur_squelette($msg, $boucle); |
|
| 116 | + $nom = ''; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | + |
|
| 122 | + // Tracer ce qui vient d'etre compile |
|
| 123 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | + |
|
| 125 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | + and (_request('var_mode_objet') == $nom) |
|
| 128 | + and (_request('var_mode_affiche') == 'code') |
|
| 129 | + ) { |
|
| 130 | + erreur_squelette(); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $nom ? $nom : false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 138 | 138 | |
| 139 | - // Le dernier index est '' (fonction principale) |
|
| 140 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | - if (CODE_COMMENTE) { |
|
| 142 | - $code = " |
|
| 139 | + // Le dernier index est '' (fonction principale) |
|
| 140 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | + if (CODE_COMMENTE) { |
|
| 142 | + $code = " |
|
| 143 | 143 | /* |
| 144 | 144 | * Squelette : $sourcefile |
| 145 | 145 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 146 | 146 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 147 | 147 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 148 | 148 | */ "; |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | - ecrire_fichier($phpfile, $code); |
|
| 154 | - } |
|
| 151 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | + ecrire_fichier($phpfile, $code); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $code; |
|
| 156 | + return $code; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Le squelette compile est-il trop vieux ? |
| 160 | 160 | // http://code.spip.net/@squelette_obsolete |
| 161 | 161 | function squelette_obsolete($skel, $squelette) { |
| 162 | - static $date_change = null; |
|
| 163 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | - // par hit |
|
| 165 | - if (is_null($date_change)) { |
|
| 166 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | - $date_change = @filemtime($fonc); |
|
| 168 | - } # compatibilite |
|
| 169 | - if (defined('_FILE_OPTIONS')) { |
|
| 170 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return ( |
|
| 175 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | - or !@file_exists($skel) |
|
| 177 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | - > ($date = @filemtime($skel))) |
|
| 179 | - or ($date_change > $date) |
|
| 180 | - ); |
|
| 162 | + static $date_change = null; |
|
| 163 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | + // par hit |
|
| 165 | + if (is_null($date_change)) { |
|
| 166 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | + $date_change = @filemtime($fonc); |
|
| 168 | + } # compatibilite |
|
| 169 | + if (defined('_FILE_OPTIONS')) { |
|
| 170 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return ( |
|
| 175 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | + or !@file_exists($skel) |
|
| 177 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | + > ($date = @filemtime($skel))) |
|
| 179 | + or ($date_change > $date) |
|
| 180 | + ); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Activer l'invalideur de session |
| 184 | 184 | // http://code.spip.net/@invalideur_session |
| 185 | 185 | function invalideur_session(&$Cache, $code = null) { |
| 186 | - $Cache['session'] = spip_session(); |
|
| 186 | + $Cache['session'] = spip_session(); |
|
| 187 | 187 | |
| 188 | - return $code; |
|
| 188 | + return $code; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | 192 | // http://code.spip.net/@analyse_resultat_skel |
| 193 | 193 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 194 | - static $filtres = array(); |
|
| 195 | - $headers = array(); |
|
| 196 | - |
|
| 197 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | - if (stripos($corps, 'header') !== false |
|
| 201 | - and preg_match_all( |
|
| 202 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | - $corps, $regs, PREG_SET_ORDER) |
|
| 204 | - ) { |
|
| 205 | - foreach ($regs as $r) { |
|
| 206 | - $corps = str_replace($r[0], '', $corps); |
|
| 207 | - # $j = Content-Type, et pas content-TYPE. |
|
| 208 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | - |
|
| 210 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | - $headers[$j] .= "|" . $r[3]; |
|
| 212 | - } else { |
|
| 213 | - $headers[$j] = $r[3]; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | - $process_ins = ( |
|
| 219 | - strpos($corps, '<' . '?') === false |
|
| 220 | - or |
|
| 221 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | - ) |
|
| 224 | - ? 'html' |
|
| 225 | - : 'php'; |
|
| 226 | - |
|
| 227 | - $skel = array( |
|
| 228 | - 'squelette' => $nom, |
|
| 229 | - 'source' => $source, |
|
| 230 | - 'process_ins' => $process_ins, |
|
| 231 | - 'invalideurs' => $cache, |
|
| 232 | - 'entetes' => $headers, |
|
| 233 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - // traiter #FILTRE{} et filtres |
|
| 237 | - if (!isset($filtres[$nom])) { |
|
| 238 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | - } |
|
| 240 | - if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | - include_spip('public/sandbox'); |
|
| 242 | - $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | - strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | - unset($headers['X-Spip-Filtre']); |
|
| 245 | - |
|
| 246 | - if ($process_ins == 'html') { |
|
| 247 | - $skel['process_ins'] = ( |
|
| 248 | - strpos($corps, '<' . '?') === false |
|
| 249 | - or |
|
| 250 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | - ) |
|
| 253 | - ? 'html' |
|
| 254 | - : 'php'; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $skel['entetes'] = $headers; |
|
| 259 | - $skel['texte'] = $corps; |
|
| 260 | - |
|
| 261 | - return $skel; |
|
| 194 | + static $filtres = array(); |
|
| 195 | + $headers = array(); |
|
| 196 | + |
|
| 197 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | + if (stripos($corps, 'header') !== false |
|
| 201 | + and preg_match_all( |
|
| 202 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | + $corps, $regs, PREG_SET_ORDER) |
|
| 204 | + ) { |
|
| 205 | + foreach ($regs as $r) { |
|
| 206 | + $corps = str_replace($r[0], '', $corps); |
|
| 207 | + # $j = Content-Type, et pas content-TYPE. |
|
| 208 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | + |
|
| 210 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | + $headers[$j] .= "|" . $r[3]; |
|
| 212 | + } else { |
|
| 213 | + $headers[$j] = $r[3]; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | + $process_ins = ( |
|
| 219 | + strpos($corps, '<' . '?') === false |
|
| 220 | + or |
|
| 221 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | + ) |
|
| 224 | + ? 'html' |
|
| 225 | + : 'php'; |
|
| 226 | + |
|
| 227 | + $skel = array( |
|
| 228 | + 'squelette' => $nom, |
|
| 229 | + 'source' => $source, |
|
| 230 | + 'process_ins' => $process_ins, |
|
| 231 | + 'invalideurs' => $cache, |
|
| 232 | + 'entetes' => $headers, |
|
| 233 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + // traiter #FILTRE{} et filtres |
|
| 237 | + if (!isset($filtres[$nom])) { |
|
| 238 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | + } |
|
| 240 | + if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | + include_spip('public/sandbox'); |
|
| 242 | + $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | + strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | + unset($headers['X-Spip-Filtre']); |
|
| 245 | + |
|
| 246 | + if ($process_ins == 'html') { |
|
| 247 | + $skel['process_ins'] = ( |
|
| 248 | + strpos($corps, '<' . '?') === false |
|
| 249 | + or |
|
| 250 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | + ) |
|
| 253 | + ? 'html' |
|
| 254 | + : 'php'; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $skel['entetes'] = $headers; |
|
| 259 | + $skel['texte'] = $corps; |
|
| 260 | + |
|
| 261 | + return $skel; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // |
@@ -295,75 +295,75 @@ discard block |
||
| 295 | 295 | * Introduction calculée |
| 296 | 296 | **/ |
| 297 | 297 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 298 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | - if (strlen($descriptif)) { |
|
| 300 | - return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // De preference ce qui est marque <intro>...</intro> |
|
| 304 | - $intro = ''; |
|
| 305 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | - $zone = substr($texte, 0, $fin); |
|
| 308 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | - if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | - $zone = substr($zone, $deb + 7); |
|
| 311 | - } |
|
| 312 | - $intro .= $zone; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | - // qui inclus raccourcis et modeles |
|
| 317 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | - // des surcharges et enrichissement de propre |
|
| 320 | - // couper doit se faire apres propre |
|
| 321 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | - |
|
| 323 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | - // large et en se mefiant des tableaux #1323 |
|
| 325 | - |
|
| 326 | - if (strlen($intro)) { |
|
| 327 | - $texte = $intro; |
|
| 328 | - } else { |
|
| 329 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | - and strlen($texte) > 2.5 * $longueur |
|
| 331 | - ) { |
|
| 332 | - if (strpos($texte, "<multi") !== false) { |
|
| 333 | - $texte = extraire_multi($texte); |
|
| 334 | - } |
|
| 335 | - $texte = couper($texte, 2 * $longueur); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // ne pas tenir compte des notes |
|
| 340 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | - $notes('', 'empiler'); |
|
| 342 | - } |
|
| 343 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | - // dans l'introduction. |
|
| 345 | - $texte = supprime_img($texte, ''); |
|
| 346 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | - |
|
| 348 | - if ($notes) { |
|
| 349 | - $notes('', 'depiler'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | - $suite = _INTRODUCTION_SUITE; |
|
| 354 | - } |
|
| 355 | - $texte = couper($texte, $longueur, $suite); |
|
| 356 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | - $texte = typo($texte, true, $connect, array()); |
|
| 358 | - |
|
| 359 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | - // une introduction a tojours un <p> |
|
| 361 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | - { |
|
| 363 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $texte; |
|
| 298 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | + if (strlen($descriptif)) { |
|
| 300 | + return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // De preference ce qui est marque <intro>...</intro> |
|
| 304 | + $intro = ''; |
|
| 305 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | + $zone = substr($texte, 0, $fin); |
|
| 308 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | + if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | + $zone = substr($zone, $deb + 7); |
|
| 311 | + } |
|
| 312 | + $intro .= $zone; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | + // qui inclus raccourcis et modeles |
|
| 317 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | + // des surcharges et enrichissement de propre |
|
| 320 | + // couper doit se faire apres propre |
|
| 321 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | + |
|
| 323 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | + // large et en se mefiant des tableaux #1323 |
|
| 325 | + |
|
| 326 | + if (strlen($intro)) { |
|
| 327 | + $texte = $intro; |
|
| 328 | + } else { |
|
| 329 | + if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | + and strlen($texte) > 2.5 * $longueur |
|
| 331 | + ) { |
|
| 332 | + if (strpos($texte, "<multi") !== false) { |
|
| 333 | + $texte = extraire_multi($texte); |
|
| 334 | + } |
|
| 335 | + $texte = couper($texte, 2 * $longueur); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // ne pas tenir compte des notes |
|
| 340 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | + $notes('', 'empiler'); |
|
| 342 | + } |
|
| 343 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | + // dans l'introduction. |
|
| 345 | + $texte = supprime_img($texte, ''); |
|
| 346 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | + |
|
| 348 | + if ($notes) { |
|
| 349 | + $notes('', 'depiler'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | + $suite = _INTRODUCTION_SUITE; |
|
| 354 | + } |
|
| 355 | + $texte = couper($texte, $longueur, $suite); |
|
| 356 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | + $texte = typo($texte, true, $connect, array()); |
|
| 358 | + |
|
| 359 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | + // une introduction a tojours un <p> |
|
| 361 | + if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | + { |
|
| 363 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $texte; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 378 | 378 | if ($lang_select) lang_select(); |
| 379 | 379 | ?' |
| 380 | - . '>'); |
|
| 380 | + . '>'); |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -397,17 +397,17 @@ discard block |
||
| 397 | 397 | * Code PHP pour inclure le squelette de la balise dynamique |
| 398 | 398 | **/ |
| 399 | 399 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 400 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | - } |
|
| 403 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | - $file, |
|
| 405 | - $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | - $nom, |
|
| 407 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | - join(', ', array_map('_q', $context_compil))); |
|
| 409 | - |
|
| 410 | - return $r; |
|
| 400 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | + } |
|
| 403 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | + $file, |
|
| 405 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | + $nom, |
|
| 407 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | + join(', ', array_map('_q', $context_compil))); |
|
| 409 | + |
|
| 410 | + return $r; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -425,16 +425,16 @@ discard block |
||
| 425 | 425 | **/ |
| 426 | 426 | function argumenter_squelette($v) { |
| 427 | 427 | |
| 428 | - if (!is_array($v)) { |
|
| 429 | - return "'" . texte_script($v) . "'"; |
|
| 430 | - } else { |
|
| 431 | - $out = array(); |
|
| 432 | - foreach ($v as $k => $val) { |
|
| 433 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | - } |
|
| 428 | + if (!is_array($v)) { |
|
| 429 | + return "'" . texte_script($v) . "'"; |
|
| 430 | + } else { |
|
| 431 | + $out = array(); |
|
| 432 | + foreach ($v as $k => $val) { |
|
| 433 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - return 'array(' . join(", ", $out) . ')'; |
|
| 437 | - } |
|
| 436 | + return 'array(' . join(", ", $out) . ')'; |
|
| 437 | + } |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -465,69 +465,69 @@ discard block |
||
| 465 | 465 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 466 | 466 | **/ |
| 467 | 467 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 468 | - $nomfonction = $nom; |
|
| 469 | - $nomfonction_generique = ""; |
|
| 470 | - |
|
| 471 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | - // et injecter en premier arg le nom de la balise |
|
| 479 | - array_unshift($args, $nom); |
|
| 480 | - $nomfonction = $nomfonction_generique; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (!$fonction_balise) { |
|
| 485 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | - erreur_squelette($msg, $context_compil); |
|
| 487 | - |
|
| 488 | - return ''; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - // retrouver le fichier qui a déclaré la fonction |
|
| 492 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | - |
|
| 503 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | - |
|
| 505 | - if (!is_array($r)) { |
|
| 506 | - return $r; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - // verifier que la fonction dyn est la, |
|
| 510 | - // sinon se replier sur la generique si elle existe |
|
| 511 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | - if ($nomfonction_generique |
|
| 513 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | - ) { |
|
| 516 | - // et lui injecter en premier arg le nom de la balise |
|
| 517 | - array_unshift($r, $nom); |
|
| 518 | - $nomfonction = $nomfonction_generique; |
|
| 519 | - if (!_DIR_RESTREINT) { |
|
| 520 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | - } |
|
| 522 | - } else { |
|
| 523 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | - erreur_squelette($msg, $context_compil); |
|
| 525 | - |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 468 | + $nomfonction = $nom; |
|
| 469 | + $nomfonction_generique = ""; |
|
| 470 | + |
|
| 471 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | + // et injecter en premier arg le nom de la balise |
|
| 479 | + array_unshift($args, $nom); |
|
| 480 | + $nomfonction = $nomfonction_generique; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (!$fonction_balise) { |
|
| 485 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | + erreur_squelette($msg, $context_compil); |
|
| 487 | + |
|
| 488 | + return ''; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + // retrouver le fichier qui a déclaré la fonction |
|
| 492 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | + |
|
| 503 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | + |
|
| 505 | + if (!is_array($r)) { |
|
| 506 | + return $r; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + // verifier que la fonction dyn est la, |
|
| 510 | + // sinon se replier sur la generique si elle existe |
|
| 511 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | + if ($nomfonction_generique |
|
| 513 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | + ) { |
|
| 516 | + // et lui injecter en premier arg le nom de la balise |
|
| 517 | + array_unshift($r, $nom); |
|
| 518 | + $nomfonction = $nomfonction_generique; |
|
| 519 | + if (!_DIR_RESTREINT) { |
|
| 520 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | + } |
|
| 522 | + } else { |
|
| 523 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | + erreur_squelette($msg, $context_compil); |
|
| 525 | + |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | |
@@ -541,15 +541,15 @@ discard block |
||
| 541 | 541 | **/ |
| 542 | 542 | function lister_objets_avec_logos($type) { |
| 543 | 543 | |
| 544 | - $objet = objet_type($type); |
|
| 545 | - $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)); |
|
| 546 | - if ($ids) { |
|
| 547 | - $ids = array_column($ids, 'id_objet'); |
|
| 548 | - return implode(',', $ids); |
|
| 549 | - } |
|
| 550 | - else { |
|
| 551 | - return "0"; |
|
| 552 | - } |
|
| 544 | + $objet = objet_type($type); |
|
| 545 | + $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)); |
|
| 546 | + if ($ids) { |
|
| 547 | + $ids = array_column($ids, 'id_objet'); |
|
| 548 | + return implode(',', $ids); |
|
| 549 | + } |
|
| 550 | + else { |
|
| 551 | + return "0"; |
|
| 552 | + } |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | |
@@ -565,14 +565,14 @@ discard block |
||
| 565 | 565 | * Code HTML des notes |
| 566 | 566 | **/ |
| 567 | 567 | function calculer_notes() { |
| 568 | - $r = ''; |
|
| 569 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 570 | - $r = $notes(array()); |
|
| 571 | - $notes('', 'depiler'); |
|
| 572 | - $notes('', 'empiler'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $r; |
|
| 568 | + $r = ''; |
|
| 569 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 570 | + $r = $notes(array()); |
|
| 571 | + $notes('', 'depiler'); |
|
| 572 | + $notes('', 'empiler'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $r; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -595,27 +595,27 @@ discard block |
||
| 595 | 595 | * @return null; |
| 596 | 596 | **/ |
| 597 | 597 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 598 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 599 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 600 | - and $lang_select !== 'oui' |
|
| 601 | - ) { |
|
| 602 | - $lang = $GLOBALS['spip_lang']; |
|
| 603 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 604 | - elseif (!strlen($lang)) { |
|
| 605 | - $lang = $GLOBALS['spip_lang']; |
|
| 606 | - } // Cas 3. l'objet est multilingue ! |
|
| 607 | - elseif ($lang_select !== 'oui' |
|
| 608 | - and strlen($titre) > 10 |
|
| 609 | - and strpos($titre, '<multi>') !== false |
|
| 610 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 611 | - ) { |
|
| 612 | - $lang = $GLOBALS['spip_lang']; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 616 | - lang_select($lang); |
|
| 617 | - |
|
| 618 | - return; |
|
| 598 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 599 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 600 | + and $lang_select !== 'oui' |
|
| 601 | + ) { |
|
| 602 | + $lang = $GLOBALS['spip_lang']; |
|
| 603 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 604 | + elseif (!strlen($lang)) { |
|
| 605 | + $lang = $GLOBALS['spip_lang']; |
|
| 606 | + } // Cas 3. l'objet est multilingue ! |
|
| 607 | + elseif ($lang_select !== 'oui' |
|
| 608 | + and strlen($titre) > 10 |
|
| 609 | + and strpos($titre, '<multi>') !== false |
|
| 610 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 611 | + ) { |
|
| 612 | + $lang = $GLOBALS['spip_lang']; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 616 | + lang_select($lang); |
|
| 617 | + |
|
| 618 | + return; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -623,21 +623,21 @@ discard block |
||
| 623 | 623 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 624 | 624 | // http://code.spip.net/@nettoyer_env_doublons |
| 625 | 625 | function nettoyer_env_doublons($envd) { |
| 626 | - foreach ($envd as $table => $liste) { |
|
| 627 | - $n = ''; |
|
| 628 | - foreach (explode(',', $liste) as $val) { |
|
| 629 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 630 | - $n .= ',' . $val; |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - if (strlen($n)) { |
|
| 634 | - $envd[$table] = $n; |
|
| 635 | - } else { |
|
| 636 | - unset($envd[$table]); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $envd; |
|
| 626 | + foreach ($envd as $table => $liste) { |
|
| 627 | + $n = ''; |
|
| 628 | + foreach (explode(',', $liste) as $val) { |
|
| 629 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 630 | + $n .= ',' . $val; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + if (strlen($n)) { |
|
| 634 | + $envd[$table] = $n; |
|
| 635 | + } else { |
|
| 636 | + unset($envd[$table]); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $envd; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -656,21 +656,21 @@ discard block |
||
| 656 | 656 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 657 | 657 | **/ |
| 658 | 658 | function match_self($w) { |
| 659 | - if (is_string($w)) { |
|
| 660 | - return false; |
|
| 661 | - } |
|
| 662 | - if (is_array($w)) { |
|
| 663 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 664 | - return $w; |
|
| 665 | - } |
|
| 666 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 667 | - if ($m = match_self($sw)) { |
|
| 668 | - return $m; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return false; |
|
| 659 | + if (is_string($w)) { |
|
| 660 | + return false; |
|
| 661 | + } |
|
| 662 | + if (is_array($w)) { |
|
| 663 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 664 | + return $w; |
|
| 665 | + } |
|
| 666 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 667 | + if ($m = match_self($sw)) { |
|
| 668 | + return $m; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return false; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
@@ -686,16 +686,16 @@ discard block |
||
| 686 | 686 | * est remplacée par son code. |
| 687 | 687 | **/ |
| 688 | 688 | function remplace_sous_requete($w, $sousrequete) { |
| 689 | - if (is_array($w)) { |
|
| 690 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 691 | - return $sousrequete; |
|
| 692 | - } |
|
| 693 | - foreach ($w as $k => $sw) { |
|
| 694 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return $w; |
|
| 689 | + if (is_array($w)) { |
|
| 690 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 691 | + return $sousrequete; |
|
| 692 | + } |
|
| 693 | + foreach ($w as $k => $sw) { |
|
| 694 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return $w; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | /** |
@@ -709,17 +709,17 @@ discard block |
||
| 709 | 709 | * - Conditions avec des sous requêtes |
| 710 | 710 | **/ |
| 711 | 711 | function trouver_sous_requetes($where) { |
| 712 | - $where_simples = array(); |
|
| 713 | - $where_sous = array(); |
|
| 714 | - foreach ($where as $k => $w) { |
|
| 715 | - if (match_self($w)) { |
|
| 716 | - $where_sous[$k] = $w; |
|
| 717 | - } else { |
|
| 718 | - $where_simples[$k] = $w; |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return array($where_simples, $where_sous); |
|
| 712 | + $where_simples = array(); |
|
| 713 | + $where_sous = array(); |
|
| 714 | + foreach ($where as $k => $w) { |
|
| 715 | + if (match_self($w)) { |
|
| 716 | + $where_sous[$k] = $w; |
|
| 717 | + } else { |
|
| 718 | + $where_simples[$k] = $w; |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return array($where_simples, $where_sous); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -745,258 +745,258 @@ discard block |
||
| 745 | 745 | * @return resource |
| 746 | 746 | */ |
| 747 | 747 | function calculer_select( |
| 748 | - $select = array(), |
|
| 749 | - $from = array(), |
|
| 750 | - $from_type = array(), |
|
| 751 | - $where = array(), |
|
| 752 | - $join = array(), |
|
| 753 | - $groupby = array(), |
|
| 754 | - $orderby = array(), |
|
| 755 | - $limit = '', |
|
| 756 | - $having = array(), |
|
| 757 | - $table = '', |
|
| 758 | - $id = '', |
|
| 759 | - $serveur = '', |
|
| 760 | - $requeter = true |
|
| 748 | + $select = array(), |
|
| 749 | + $from = array(), |
|
| 750 | + $from_type = array(), |
|
| 751 | + $where = array(), |
|
| 752 | + $join = array(), |
|
| 753 | + $groupby = array(), |
|
| 754 | + $orderby = array(), |
|
| 755 | + $limit = '', |
|
| 756 | + $having = array(), |
|
| 757 | + $table = '', |
|
| 758 | + $id = '', |
|
| 759 | + $serveur = '', |
|
| 760 | + $requeter = true |
|
| 761 | 761 | ) { |
| 762 | 762 | |
| 763 | - // retirer les criteres vides: |
|
| 764 | - // {X ?} avec X absent de l'URL |
|
| 765 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 766 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 767 | - $menage = false; |
|
| 768 | - foreach ($where as $k => $v) { |
|
| 769 | - if (is_array($v)) { |
|
| 770 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 771 | - $op = false; |
|
| 772 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 773 | - $op = false; |
|
| 774 | - } else { |
|
| 775 | - $op = $v[0] ? $v[0] : $v; |
|
| 776 | - } |
|
| 777 | - } else { |
|
| 778 | - $op = $v; |
|
| 779 | - } |
|
| 780 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 781 | - unset($where[$k]); |
|
| 782 | - $menage = true; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 787 | - $groupby = array_diff($groupby, array('')); |
|
| 788 | - |
|
| 789 | - // remplacer les sous requetes recursives au calcul |
|
| 790 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 791 | - foreach ($where_sous as $k => $w) { |
|
| 792 | - $menage = true; |
|
| 793 | - // on recupere la sous requete |
|
| 794 | - $sous = match_self($w); |
|
| 795 | - if ($sous[0] == 'SELF') { |
|
| 796 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 797 | - array_push($where_simples, $sous[2]); |
|
| 798 | - $wheresub = array( |
|
| 799 | - $sous[2], |
|
| 800 | - '0=0' |
|
| 801 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 802 | - $jsub = $join; |
|
| 803 | - // trouver les jointures utiles a |
|
| 804 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 805 | - // ie L1.objet='article' |
|
| 806 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 807 | - $i = 0; |
|
| 808 | - do { |
|
| 809 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 810 | - array($sous[1] . " AS id"), |
|
| 811 | - $from, |
|
| 812 | - $from_type, |
|
| 813 | - $wheresub, |
|
| 814 | - $jsub, |
|
| 815 | - array(), array(), '', |
|
| 816 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 817 | - if (!$i) { |
|
| 818 | - $i = 1; |
|
| 819 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 820 | - foreach ($join as $cle => $wj) { |
|
| 821 | - if (count($wj) == 4 |
|
| 822 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 823 | - ) { |
|
| 824 | - $i = 0; |
|
| 825 | - $wheresub[] = $wj[3]; |
|
| 826 | - unset($jsub[$cle][3]); |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - } |
|
| 830 | - } while ($i++ < 1); |
|
| 831 | - } |
|
| 832 | - if ($sous[0] == 'SUBSELECT') { |
|
| 833 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 834 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 835 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 836 | - $sous[1], # select |
|
| 837 | - $sous[2], #from |
|
| 838 | - array(), #from_type |
|
| 839 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 840 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 841 | - array(), #join |
|
| 842 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 843 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 844 | - $sous[6], #limit |
|
| 845 | - $sous[7] ? $sous[7] : array(), #having |
|
| 846 | - $table, $id, $serveur, false |
|
| 847 | - ) . ")"); |
|
| 848 | - } |
|
| 849 | - array_pop($where_simples); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - foreach ($having as $k => $v) { |
|
| 853 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 854 | - unset($having[$k]); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - // Installer les jointures. |
|
| 859 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 860 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 861 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 862 | - |
|
| 863 | - $afrom = array(); |
|
| 864 | - $equiv = array(); |
|
| 865 | - $k = count($join); |
|
| 866 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 867 | - $cle = $cledef; |
|
| 868 | - // le format de join est : |
|
| 869 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 870 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 871 | - if (count($join[$cle]) == 2) { |
|
| 872 | - $join[$cle][] = $join[$cle][1]; |
|
| 873 | - } |
|
| 874 | - if (count($join[$cle]) == 3) { |
|
| 875 | - $join[$cle][] = ''; |
|
| 876 | - } |
|
| 877 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 878 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 879 | - // pour compat avec ancienne convention |
|
| 880 | - if (is_numeric($cle)) { |
|
| 881 | - $cle = "L$k"; |
|
| 882 | - } |
|
| 883 | - if (!$menage |
|
| 884 | - or isset($afrom[$cle]) |
|
| 885 | - or calculer_jointnul($cle, $select) |
|
| 886 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 887 | - or calculer_jointnul($cle, $having) |
|
| 888 | - or calculer_jointnul($cle, $where_simples) |
|
| 889 | - ) { |
|
| 890 | - // corriger les references non explicites dans select |
|
| 891 | - // ou groupby |
|
| 892 | - foreach ($select as $i => $s) { |
|
| 893 | - if ($s == $c) { |
|
| 894 | - $select[$i] = "$cle.$c AS $c"; |
|
| 895 | - break; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - foreach ($groupby as $i => $g) { |
|
| 899 | - if ($g == $c) { |
|
| 900 | - $groupby[$i] = "$cle.$c"; |
|
| 901 | - break; |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 905 | - // sans recours a preg_match |
|
| 906 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 907 | - $afrom[$t][$cle] = array( |
|
| 908 | - "\n" . |
|
| 909 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 910 | - $from[$cle], |
|
| 911 | - "AS $cle", |
|
| 912 | - "ON (", |
|
| 913 | - "$cle.$c", |
|
| 914 | - "=", |
|
| 915 | - "$t.$carr", |
|
| 916 | - ($and ? "AND " . $and : "") . |
|
| 917 | - ")" |
|
| 918 | - ); |
|
| 919 | - if (isset($afrom[$cle])) { |
|
| 920 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 921 | - unset($afrom[$cle]); |
|
| 922 | - } |
|
| 923 | - $equiv[] = $carr; |
|
| 924 | - } else { |
|
| 925 | - unset($join[$cledef]); |
|
| 926 | - } |
|
| 927 | - unset($from[$cle]); |
|
| 928 | - $k--; |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - if (count($afrom)) { |
|
| 932 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 933 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 934 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 935 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 936 | - // ou dans |
|
| 937 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 938 | - // qui comporte plusieurs jointures |
|
| 939 | - // ou dans |
|
| 940 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 941 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 942 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 943 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 944 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 945 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 946 | - |
|
| 947 | - $t = key($from); |
|
| 948 | - $c = current($from); |
|
| 949 | - reset($from); |
|
| 950 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 951 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 952 | - calculer_jointnul($t, $select, $e) or |
|
| 953 | - calculer_jointnul($t, $join, $e) or |
|
| 954 | - calculer_jointnul($t, $where, $e) or |
|
| 955 | - calculer_jointnul($t, $orderby, $e) or |
|
| 956 | - calculer_jointnul($t, $groupby, $e) or |
|
| 957 | - calculer_jointnul($t, $having, $e)) |
|
| 958 | - && count($afrom[$t]) |
|
| 959 | - ) { |
|
| 960 | - $nfrom = reset($afrom[$t]); |
|
| 961 | - $nt = key($afrom[$t]); |
|
| 962 | - unset($from[$t]); |
|
| 963 | - $from[$nt] = $nfrom[1]; |
|
| 964 | - unset($afrom[$t][$nt]); |
|
| 965 | - $afrom[$nt] = $afrom[$t]; |
|
| 966 | - unset($afrom[$t]); |
|
| 967 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 968 | - $t = $nfrom[4]; |
|
| 969 | - $alias = ""; |
|
| 970 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 971 | - $oldcle = explode('.', $nfrom[6]); |
|
| 972 | - $oldcle = end($oldcle); |
|
| 973 | - $newcle = explode('.', $nfrom[4]); |
|
| 974 | - $newcle = end($newcle); |
|
| 975 | - if ($newcle != $oldcle) { |
|
| 976 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 977 | - // reprendre simplement ce AS |
|
| 978 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 979 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 980 | - $alias = ""; |
|
| 981 | - } else { |
|
| 982 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 986 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 987 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 988 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 989 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 990 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 991 | - } |
|
| 992 | - $from = reinjecte_joint($afrom, $from); |
|
| 993 | - } |
|
| 994 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 995 | - $r = sql_select($select, $from, $where, |
|
| 996 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 997 | - unset($GLOBALS['debug']['aucasou']); |
|
| 998 | - |
|
| 999 | - return $r; |
|
| 763 | + // retirer les criteres vides: |
|
| 764 | + // {X ?} avec X absent de l'URL |
|
| 765 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 766 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 767 | + $menage = false; |
|
| 768 | + foreach ($where as $k => $v) { |
|
| 769 | + if (is_array($v)) { |
|
| 770 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 771 | + $op = false; |
|
| 772 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 773 | + $op = false; |
|
| 774 | + } else { |
|
| 775 | + $op = $v[0] ? $v[0] : $v; |
|
| 776 | + } |
|
| 777 | + } else { |
|
| 778 | + $op = $v; |
|
| 779 | + } |
|
| 780 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 781 | + unset($where[$k]); |
|
| 782 | + $menage = true; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 787 | + $groupby = array_diff($groupby, array('')); |
|
| 788 | + |
|
| 789 | + // remplacer les sous requetes recursives au calcul |
|
| 790 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 791 | + foreach ($where_sous as $k => $w) { |
|
| 792 | + $menage = true; |
|
| 793 | + // on recupere la sous requete |
|
| 794 | + $sous = match_self($w); |
|
| 795 | + if ($sous[0] == 'SELF') { |
|
| 796 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 797 | + array_push($where_simples, $sous[2]); |
|
| 798 | + $wheresub = array( |
|
| 799 | + $sous[2], |
|
| 800 | + '0=0' |
|
| 801 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 802 | + $jsub = $join; |
|
| 803 | + // trouver les jointures utiles a |
|
| 804 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 805 | + // ie L1.objet='article' |
|
| 806 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 807 | + $i = 0; |
|
| 808 | + do { |
|
| 809 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 810 | + array($sous[1] . " AS id"), |
|
| 811 | + $from, |
|
| 812 | + $from_type, |
|
| 813 | + $wheresub, |
|
| 814 | + $jsub, |
|
| 815 | + array(), array(), '', |
|
| 816 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 817 | + if (!$i) { |
|
| 818 | + $i = 1; |
|
| 819 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 820 | + foreach ($join as $cle => $wj) { |
|
| 821 | + if (count($wj) == 4 |
|
| 822 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 823 | + ) { |
|
| 824 | + $i = 0; |
|
| 825 | + $wheresub[] = $wj[3]; |
|
| 826 | + unset($jsub[$cle][3]); |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | + } while ($i++ < 1); |
|
| 831 | + } |
|
| 832 | + if ($sous[0] == 'SUBSELECT') { |
|
| 833 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 834 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 835 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 836 | + $sous[1], # select |
|
| 837 | + $sous[2], #from |
|
| 838 | + array(), #from_type |
|
| 839 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 840 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 841 | + array(), #join |
|
| 842 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 843 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 844 | + $sous[6], #limit |
|
| 845 | + $sous[7] ? $sous[7] : array(), #having |
|
| 846 | + $table, $id, $serveur, false |
|
| 847 | + ) . ")"); |
|
| 848 | + } |
|
| 849 | + array_pop($where_simples); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + foreach ($having as $k => $v) { |
|
| 853 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 854 | + unset($having[$k]); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + // Installer les jointures. |
|
| 859 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 860 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 861 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 862 | + |
|
| 863 | + $afrom = array(); |
|
| 864 | + $equiv = array(); |
|
| 865 | + $k = count($join); |
|
| 866 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 867 | + $cle = $cledef; |
|
| 868 | + // le format de join est : |
|
| 869 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 870 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 871 | + if (count($join[$cle]) == 2) { |
|
| 872 | + $join[$cle][] = $join[$cle][1]; |
|
| 873 | + } |
|
| 874 | + if (count($join[$cle]) == 3) { |
|
| 875 | + $join[$cle][] = ''; |
|
| 876 | + } |
|
| 877 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 878 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 879 | + // pour compat avec ancienne convention |
|
| 880 | + if (is_numeric($cle)) { |
|
| 881 | + $cle = "L$k"; |
|
| 882 | + } |
|
| 883 | + if (!$menage |
|
| 884 | + or isset($afrom[$cle]) |
|
| 885 | + or calculer_jointnul($cle, $select) |
|
| 886 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 887 | + or calculer_jointnul($cle, $having) |
|
| 888 | + or calculer_jointnul($cle, $where_simples) |
|
| 889 | + ) { |
|
| 890 | + // corriger les references non explicites dans select |
|
| 891 | + // ou groupby |
|
| 892 | + foreach ($select as $i => $s) { |
|
| 893 | + if ($s == $c) { |
|
| 894 | + $select[$i] = "$cle.$c AS $c"; |
|
| 895 | + break; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + foreach ($groupby as $i => $g) { |
|
| 899 | + if ($g == $c) { |
|
| 900 | + $groupby[$i] = "$cle.$c"; |
|
| 901 | + break; |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 905 | + // sans recours a preg_match |
|
| 906 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 907 | + $afrom[$t][$cle] = array( |
|
| 908 | + "\n" . |
|
| 909 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 910 | + $from[$cle], |
|
| 911 | + "AS $cle", |
|
| 912 | + "ON (", |
|
| 913 | + "$cle.$c", |
|
| 914 | + "=", |
|
| 915 | + "$t.$carr", |
|
| 916 | + ($and ? "AND " . $and : "") . |
|
| 917 | + ")" |
|
| 918 | + ); |
|
| 919 | + if (isset($afrom[$cle])) { |
|
| 920 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 921 | + unset($afrom[$cle]); |
|
| 922 | + } |
|
| 923 | + $equiv[] = $carr; |
|
| 924 | + } else { |
|
| 925 | + unset($join[$cledef]); |
|
| 926 | + } |
|
| 927 | + unset($from[$cle]); |
|
| 928 | + $k--; |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + if (count($afrom)) { |
|
| 932 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 933 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 934 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 935 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 936 | + // ou dans |
|
| 937 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 938 | + // qui comporte plusieurs jointures |
|
| 939 | + // ou dans |
|
| 940 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 941 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 942 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 943 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 944 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 945 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 946 | + |
|
| 947 | + $t = key($from); |
|
| 948 | + $c = current($from); |
|
| 949 | + reset($from); |
|
| 950 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 951 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 952 | + calculer_jointnul($t, $select, $e) or |
|
| 953 | + calculer_jointnul($t, $join, $e) or |
|
| 954 | + calculer_jointnul($t, $where, $e) or |
|
| 955 | + calculer_jointnul($t, $orderby, $e) or |
|
| 956 | + calculer_jointnul($t, $groupby, $e) or |
|
| 957 | + calculer_jointnul($t, $having, $e)) |
|
| 958 | + && count($afrom[$t]) |
|
| 959 | + ) { |
|
| 960 | + $nfrom = reset($afrom[$t]); |
|
| 961 | + $nt = key($afrom[$t]); |
|
| 962 | + unset($from[$t]); |
|
| 963 | + $from[$nt] = $nfrom[1]; |
|
| 964 | + unset($afrom[$t][$nt]); |
|
| 965 | + $afrom[$nt] = $afrom[$t]; |
|
| 966 | + unset($afrom[$t]); |
|
| 967 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 968 | + $t = $nfrom[4]; |
|
| 969 | + $alias = ""; |
|
| 970 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 971 | + $oldcle = explode('.', $nfrom[6]); |
|
| 972 | + $oldcle = end($oldcle); |
|
| 973 | + $newcle = explode('.', $nfrom[4]); |
|
| 974 | + $newcle = end($newcle); |
|
| 975 | + if ($newcle != $oldcle) { |
|
| 976 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 977 | + // reprendre simplement ce AS |
|
| 978 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 979 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 980 | + $alias = ""; |
|
| 981 | + } else { |
|
| 982 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 986 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 987 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 988 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 989 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 990 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 991 | + } |
|
| 992 | + $from = reinjecte_joint($afrom, $from); |
|
| 993 | + } |
|
| 994 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 995 | + $r = sql_select($select, $from, $where, |
|
| 996 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 997 | + unset($GLOBALS['debug']['aucasou']); |
|
| 998 | + |
|
| 999 | + return $r; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /** |
@@ -1007,20 +1007,20 @@ discard block |
||
| 1007 | 1007 | * @return string |
| 1008 | 1008 | */ |
| 1009 | 1009 | function calculer_where_to_string($v, $join = 'AND') { |
| 1010 | - if (empty($v)) { |
|
| 1011 | - return ''; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - if (!is_array($v)) { |
|
| 1015 | - return $v; |
|
| 1016 | - } else { |
|
| 1017 | - $exp = ""; |
|
| 1018 | - if (strtoupper($join) === 'AND') { |
|
| 1019 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1020 | - } else { |
|
| 1021 | - return $exp . join($join, $v); |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1010 | + if (empty($v)) { |
|
| 1011 | + return ''; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + if (!is_array($v)) { |
|
| 1015 | + return $v; |
|
| 1016 | + } else { |
|
| 1017 | + $exp = ""; |
|
| 1018 | + if (strtoupper($join) === 'AND') { |
|
| 1019 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1020 | + } else { |
|
| 1021 | + return $exp . join($join, $v); |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1028,62 +1028,62 @@ discard block |
||
| 1028 | 1028 | |
| 1029 | 1029 | // http://code.spip.net/@calculer_jointnul |
| 1030 | 1030 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1031 | - if (!is_array($exp)) { |
|
| 1032 | - if ($equiv) { |
|
| 1033 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1037 | - } else { |
|
| 1038 | - foreach ($exp as $v) { |
|
| 1039 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1040 | - return true; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1031 | + if (!is_array($exp)) { |
|
| 1032 | + if ($equiv) { |
|
| 1033 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1037 | + } else { |
|
| 1038 | + foreach ($exp as $v) { |
|
| 1039 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1040 | + return true; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | // http://code.spip.net/@reinjecte_joint |
| 1049 | 1049 | function reinjecte_joint($afrom, $from) { |
| 1050 | - $from_synth = array(); |
|
| 1051 | - foreach ($from as $k => $v) { |
|
| 1052 | - $from_synth[$k] = $from[$k]; |
|
| 1053 | - if (isset($afrom[$k])) { |
|
| 1054 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1055 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1056 | - } |
|
| 1057 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1058 | - unset($afrom[$k]); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $from_synth; |
|
| 1050 | + $from_synth = array(); |
|
| 1051 | + foreach ($from as $k => $v) { |
|
| 1052 | + $from_synth[$k] = $from[$k]; |
|
| 1053 | + if (isset($afrom[$k])) { |
|
| 1054 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1055 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1056 | + } |
|
| 1057 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1058 | + unset($afrom[$k]); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $from_synth; |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // http://code.spip.net/@remplacer_jointnul |
| 1066 | 1066 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1067 | - if (!is_array($exp)) { |
|
| 1068 | - return preg_replace($equiv, $cle, $exp); |
|
| 1069 | - } else { |
|
| 1070 | - foreach ($exp as $k => $v) { |
|
| 1071 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - return $exp; |
|
| 1075 | - } |
|
| 1067 | + if (!is_array($exp)) { |
|
| 1068 | + return preg_replace($equiv, $cle, $exp); |
|
| 1069 | + } else { |
|
| 1070 | + foreach ($exp as $k => $v) { |
|
| 1071 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + return $exp; |
|
| 1075 | + } |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | // calcul du nom du squelette |
| 1079 | 1079 | // http://code.spip.net/@calculer_nom_fonction_squel |
| 1080 | 1080 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1081 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1082 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1083 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - return $mime_type |
|
| 1087 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1088 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1081 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1082 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1083 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + return $mime_type |
|
| 1087 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1088 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1089 | 1089 | } |
@@ -358,10 +358,12 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | // et reparagrapher si necessaire (coherence avec le cas descriptif) |
| 360 | 360 | // une introduction a tojours un <p> |
| 361 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 361 | + if ($GLOBALS['toujours_paragrapher']) { |
|
| 362 | + // Fermer les paragraphes |
|
| 362 | 363 | { |
| 363 | 364 | $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
| 364 | 365 | } |
| 366 | + } |
|
| 365 | 367 | |
| 366 | 368 | return $texte; |
| 367 | 369 | } |
@@ -546,8 +548,7 @@ discard block |
||
| 546 | 548 | if ($ids) { |
| 547 | 549 | $ids = array_column($ids, 'id_objet'); |
| 548 | 550 | return implode(',', $ids); |
| 549 | - } |
|
| 550 | - else { |
|
| 551 | + } else { |
|
| 551 | 552 | return "0"; |
| 552 | 553 | } |
| 553 | 554 | } |
@@ -661,6 +661,11 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | +/** |
|
| 665 | + * @param string $idb |
|
| 666 | + * |
|
| 667 | + * @return string |
|
| 668 | + */ |
|
| 664 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | 670 | $boucle = $boucles[$idb]; |
| 666 | 671 | $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
@@ -1509,6 +1514,10 @@ discard block |
||
| 1509 | 1514 | } |
| 1510 | 1515 | |
| 1511 | 1516 | // http://code.spip.net/@critere_IN_cas |
| 1517 | +/** |
|
| 1518 | + * @param string $idb |
|
| 1519 | + * @param string $crit2 |
|
| 1520 | + */ |
|
| 1512 | 1521 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1513 | 1522 | static $num = array(); |
| 1514 | 1523 | $descr = $boucles[$idb]->descr; |
@@ -1478,10 +1478,12 @@ discard block |
||
| 1478 | 1478 | if ($crit->cond) { |
| 1479 | 1479 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1480 | 1480 | $where = array("'?'", $pred, $where, "''"); |
| 1481 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1481 | + if ($where_complement) { |
|
| 1482 | + // condition annexe du type "AND (objet='article')" |
|
| 1482 | 1483 | { |
| 1483 | 1484 | $where_complement = array("'?'", $pred, $where_complement, "''"); |
| 1484 | 1485 | } |
| 1486 | + } |
|
| 1485 | 1487 | } |
| 1486 | 1488 | if ($crit->exclus) { |
| 1487 | 1489 | if (!preg_match(",^L[0-9]+[.],", $arg)) { |
@@ -1502,10 +1504,12 @@ discard block |
||
| 1502 | 1504 | } |
| 1503 | 1505 | |
| 1504 | 1506 | $boucles[$idb]->where[] = $where; |
| 1505 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1507 | + if ($where_complement) { |
|
| 1508 | + // condition annexe du type "AND (objet='article')" |
|
| 1506 | 1509 | { |
| 1507 | 1510 | $boucles[$idb]->where[] = $where_complement; |
| 1508 | 1511 | } |
| 1512 | + } |
|
| 1509 | 1513 | } |
| 1510 | 1514 | |
| 1511 | 1515 | // http://code.spip.net/@critere_IN_cas |
@@ -1755,17 +1759,21 @@ discard block |
||
| 1755 | 1759 | ); |
| 1756 | 1760 | } |
| 1757 | 1761 | $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
| 1758 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1762 | + if ($where_complement) { |
|
| 1763 | + // condition annexe du type "AND (objet='article')" |
|
| 1759 | 1764 | { |
| 1760 | 1765 | $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
| 1761 | 1766 | } |
| 1767 | + } |
|
| 1762 | 1768 | } |
| 1763 | 1769 | |
| 1764 | 1770 | $boucles[$idb]->where[] = $where; |
| 1765 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1771 | + if ($where_complement) { |
|
| 1772 | + // condition annexe du type "AND (objet='article')" |
|
| 1766 | 1773 | { |
| 1767 | 1774 | $boucles[$idb]->where[] = $where_complement; |
| 1768 | 1775 | } |
| 1776 | + } |
|
| 1769 | 1777 | } |
| 1770 | 1778 | |
| 1771 | 1779 | |
@@ -1876,8 +1884,7 @@ discard block |
||
| 1876 | 1884 | // Champ joker * des iterateurs DATA qui accepte tout |
| 1877 | 1885 | if (@array_key_exists('*', $desc['field'])) { |
| 1878 | 1886 | $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 1879 | - } |
|
| 1880 | - else { |
|
| 1887 | + } else { |
|
| 1881 | 1888 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 1882 | 1889 | if (!$r) { |
| 1883 | 1890 | return ''; |
@@ -1919,8 +1926,7 @@ discard block |
||
| 1919 | 1926 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 1920 | 1927 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 1921 | 1928 | $val[0] = "sql_quote($r)"; |
| 1922 | - } |
|
| 1923 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1929 | + } elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1924 | 1930 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 1925 | 1931 | $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
| 1926 | 1932 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 52 | + $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,57 +256,57 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ($boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ($boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - array( |
|
| 397 | - "'OR'", |
|
| 398 | - array( |
|
| 399 | - "'AND'", |
|
| 400 | - array("'='", "'$table.id_trad'", 0), |
|
| 401 | - array("'='", "'$table.$prim'", $dprim) |
|
| 402 | - ), |
|
| 403 | - array( |
|
| 404 | - "'AND'", |
|
| 405 | - array("'>'", "'$table.id_trad'", 0), |
|
| 406 | - array("'='", "'$table.id_trad'", $arg) |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + array( |
|
| 397 | + "'OR'", |
|
| 398 | + array( |
|
| 399 | + "'AND'", |
|
| 400 | + array("'='", "'$table.id_trad'", 0), |
|
| 401 | + array("'='", "'$table.$prim'", $dprim) |
|
| 402 | + ), |
|
| 403 | + array( |
|
| 404 | + "'AND'", |
|
| 405 | + array("'>'", "'$table.id_trad'", 0), |
|
| 406 | + array("'='", "'$table.id_trad'", $arg) |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - array( |
|
| 432 | - "'OR'", |
|
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | - ); |
|
| 436 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + array( |
|
| 432 | + "'OR'", |
|
| 433 | + array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | + ); |
|
| 436 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | + 'id_parent'; |
|
| 458 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 459 | 459 | |
| 460 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 460 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 462 | 462 | |
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | - } |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = "id_rubrique"; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = "id_rubrique"; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -631,45 +631,45 @@ discard block |
||
| 631 | 631 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 632 | 632 | */ |
| 633 | 633 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 634 | - if (isset($crit->param[0])) { |
|
| 635 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 636 | - $boucle = $boucles[$idb]; |
|
| 637 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | - $n = count($boucle->order); |
|
| 639 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | - if ( |
|
| 643 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | - ) { |
|
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | - } else { |
|
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | - } |
|
| 634 | + if (isset($crit->param[0])) { |
|
| 635 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 636 | + $boucle = $boucles[$idb]; |
|
| 637 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | + $n = count($boucle->order); |
|
| 639 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | + if ( |
|
| 643 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | + ) { |
|
| 646 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | + } else { |
|
| 648 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 657 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | - $boucle = $boucles[$idb]; |
|
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 661 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | - if (!$desc) { |
|
| 663 | - $desc = $boucle->show['field']; |
|
| 664 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | - } |
|
| 667 | - if ($desc) { |
|
| 668 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | - } |
|
| 670 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 671 | - |
|
| 672 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 658 | + $boucle = $boucles[$idb]; |
|
| 659 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | + $var = '$champs_' . $idb; |
|
| 661 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | + if (!$desc) { |
|
| 663 | + $desc = $boucle->show['field']; |
|
| 664 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | + } |
|
| 667 | + if ($desc) { |
|
| 668 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | + } |
|
| 670 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 671 | + |
|
| 672 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 709 | 709 | */ |
| 710 | 710 | function critere_par_dist($idb, &$boucles, $crit) { |
| 711 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 711 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -730,93 +730,93 @@ discard block |
||
| 730 | 730 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 731 | 731 | */ |
| 732 | 732 | function critere_parinverse($idb, &$boucles, $crit) { |
| 733 | - $boucle = &$boucles[$idb]; |
|
| 734 | - |
|
| 735 | - $sens = $collecte = ''; |
|
| 736 | - if ($crit->not) { |
|
| 737 | - $sens = " . ' DESC'"; |
|
| 738 | - } |
|
| 739 | - if (isset($boucle->modificateur['collate'])) { |
|
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Pour chaque paramètre du critère |
|
| 744 | - foreach ($crit->param as $tri) { |
|
| 745 | - $order = $fct = ''; |
|
| 746 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | - if ($tri[0]->type != 'texte') { |
|
| 748 | - // calculer le order dynamique qui verifie les champs |
|
| 749 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | - } |
|
| 753 | - // tris textuels {par titre} |
|
| 754 | - else { |
|
| 755 | - $par = array_shift($tri); |
|
| 756 | - $par = $par->texte; |
|
| 757 | - |
|
| 758 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | - $expression = trim($m[1]); |
|
| 761 | - $champ = trim($m[2]); |
|
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | - } else { |
|
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | - // {par FONCTION(champ)} |
|
| 771 | - if (count($match) > 2) { |
|
| 772 | - $par = substr($match[2], 1, -1); |
|
| 773 | - $fct = $match[1]; |
|
| 774 | - } |
|
| 775 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | - if ($par == 'hasard') { |
|
| 777 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | - } else { |
|
| 781 | - // cas général {par champ}, {par table.champ}, ... |
|
| 782 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // on ne sait pas traiter… |
|
| 787 | - else { |
|
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | - if (is_array($order)) { |
|
| 793 | - return $order; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | - $t = $m[1]; |
|
| 799 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | - $boucle->select[] = $t; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $sens = ''; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - if ($fct) { |
|
| 807 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | - } else { |
|
| 810 | - $order = "'$fct(' . $order . ')'"; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - $t = $order . $collecte . $sens; |
|
| 814 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | - $t = $r[1] . $r[2]; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $boucle->order[] = $t; |
|
| 819 | - } |
|
| 733 | + $boucle = &$boucles[$idb]; |
|
| 734 | + |
|
| 735 | + $sens = $collecte = ''; |
|
| 736 | + if ($crit->not) { |
|
| 737 | + $sens = " . ' DESC'"; |
|
| 738 | + } |
|
| 739 | + if (isset($boucle->modificateur['collate'])) { |
|
| 740 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Pour chaque paramètre du critère |
|
| 744 | + foreach ($crit->param as $tri) { |
|
| 745 | + $order = $fct = ''; |
|
| 746 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | + if ($tri[0]->type != 'texte') { |
|
| 748 | + // calculer le order dynamique qui verifie les champs |
|
| 749 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | + } |
|
| 753 | + // tris textuels {par titre} |
|
| 754 | + else { |
|
| 755 | + $par = array_shift($tri); |
|
| 756 | + $par = $par->texte; |
|
| 757 | + |
|
| 758 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | + $expression = trim($m[1]); |
|
| 761 | + $champ = trim($m[2]); |
|
| 762 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | + } else { |
|
| 765 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | + // {par FONCTION(champ)} |
|
| 771 | + if (count($match) > 2) { |
|
| 772 | + $par = substr($match[2], 1, -1); |
|
| 773 | + $fct = $match[1]; |
|
| 774 | + } |
|
| 775 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | + if ($par == 'hasard') { |
|
| 777 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | + } else { |
|
| 781 | + // cas général {par champ}, {par table.champ}, ... |
|
| 782 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // on ne sait pas traiter… |
|
| 787 | + else { |
|
| 788 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | + if (is_array($order)) { |
|
| 793 | + return $order; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | + $t = $m[1]; |
|
| 799 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | + $boucle->select[] = $t; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $sens = ''; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + if ($fct) { |
|
| 807 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | + } else { |
|
| 810 | + $order = "'$fct(' . $order . ')'"; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + $t = $order . $collecte . $sens; |
|
| 814 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | + $t = $r[1] . $r[2]; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $boucle->order[] = $t; |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * @return string Clause pour le Order by |
| 831 | 831 | */ |
| 832 | 832 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 833 | - $boucle = &$boucles[$idb]; |
|
| 834 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | - $parha = "rand() AS hasard"; |
|
| 836 | - if (!in_array($parha, $boucle->select)) { |
|
| 837 | - $boucle->select[] = $parha; |
|
| 838 | - } |
|
| 839 | - return "'hasard'"; |
|
| 833 | + $boucle = &$boucles[$idb]; |
|
| 834 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | + $parha = "rand() AS hasard"; |
|
| 836 | + if (!in_array($parha, $boucle->select)) { |
|
| 837 | + $boucle->select[] = $parha; |
|
| 838 | + } |
|
| 839 | + return "'hasard'"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,20 +860,20 @@ discard block |
||
| 860 | 860 | * @return string Clause pour le Order by |
| 861 | 861 | */ |
| 862 | 862 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | - if (is_array($_champ)) { |
|
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | - } |
|
| 867 | - $boucle = &$boucles[$idb]; |
|
| 868 | - $texte = '0+' . $_champ; |
|
| 869 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 870 | - if ($suite !== "''") { |
|
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | - } |
|
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 875 | - $order = "'$as'"; |
|
| 876 | - return $order; |
|
| 863 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | + if (is_array($_champ)) { |
|
| 865 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | + } |
|
| 867 | + $boucle = &$boucles[$idb]; |
|
| 868 | + $texte = '0+' . $_champ; |
|
| 869 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 870 | + if ($suite !== "''") { |
|
| 871 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | + } |
|
| 873 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | + $boucle->select[] = $texte . " AS $as"; |
|
| 875 | + $order = "'$as'"; |
|
| 876 | + return $order; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | * @return string Clause pour le Order by |
| 895 | 895 | */ |
| 896 | 896 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | - if (is_array($_champ)) { |
|
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | - } |
|
| 901 | - $boucle = &$boucles[$idb]; |
|
| 902 | - $texte = '0+' . $_champ; |
|
| 903 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 904 | - if ($suite !== "''") { |
|
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | - } |
|
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | - $order = "'$as'"; |
|
| 910 | - return $order; |
|
| 897 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | + if (is_array($_champ)) { |
|
| 899 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | + } |
|
| 901 | + $boucle = &$boucles[$idb]; |
|
| 902 | + $texte = '0+' . $_champ; |
|
| 903 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 904 | + if ($suite !== "''") { |
|
| 905 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | + } |
|
| 907 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | + $order = "'$as'"; |
|
| 910 | + return $order; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
@@ -927,14 +927,14 @@ discard block |
||
| 927 | 927 | * @return string Clause pour le Order by |
| 928 | 928 | */ |
| 929 | 929 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | - if (is_array($_champ)) { |
|
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | - } |
|
| 934 | - $boucle = &$boucles[$idb]; |
|
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | - $order = "'multi'"; |
|
| 937 | - return $order; |
|
| 930 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | + if (is_array($_champ)) { |
|
| 932 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | + } |
|
| 934 | + $boucle = &$boucles[$idb]; |
|
| 935 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | + $order = "'multi'"; |
|
| 937 | + return $order; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -953,56 +953,56 @@ discard block |
||
| 953 | 953 | * @return array|string |
| 954 | 954 | */ |
| 955 | 955 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 956 | - $boucle = &$boucles[$idb]; |
|
| 957 | - $desc = $boucle->show; |
|
| 958 | - |
|
| 959 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | - if (isset($desc['field'][$par])) { |
|
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 962 | - } |
|
| 963 | - // le champ est peut être une jointure |
|
| 964 | - else { |
|
| 965 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | - $champ = $par; |
|
| 967 | - |
|
| 968 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | - list(, $table, $champ) = $r; |
|
| 974 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | - $table = table_objet_sql($table); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 983 | - } elseif ( |
|
| 984 | - $boucle->jointures_explicites |
|
| 985 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | - ) { |
|
| 987 | - $par = $alias . "." . $champ; |
|
| 988 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | - $par = $alias . "." . $champ; |
|
| 990 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | - } elseif ( |
|
| 992 | - $table_alias |
|
| 993 | - and isset($boucle->from[$table_alias]) |
|
| 994 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | - ) { |
|
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 997 | - } elseif ($table) { |
|
| 998 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | - } else { |
|
| 1001 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return $raw ? $par : "'$par'"; |
|
| 956 | + $boucle = &$boucles[$idb]; |
|
| 957 | + $desc = $boucle->show; |
|
| 958 | + |
|
| 959 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | + if (isset($desc['field'][$par])) { |
|
| 961 | + $par = $boucle->id_table . "." . $par; |
|
| 962 | + } |
|
| 963 | + // le champ est peut être une jointure |
|
| 964 | + else { |
|
| 965 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | + $champ = $par; |
|
| 967 | + |
|
| 968 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | + list(, $table, $champ) = $r; |
|
| 974 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | + $table = table_objet_sql($table); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | + $par = $infos['alias'] . "." . $champ; |
|
| 983 | + } elseif ( |
|
| 984 | + $boucle->jointures_explicites |
|
| 985 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | + ) { |
|
| 987 | + $par = $alias . "." . $champ; |
|
| 988 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | + $par = $alias . "." . $champ; |
|
| 990 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | + } elseif ( |
|
| 992 | + $table_alias |
|
| 993 | + and isset($boucle->from[$table_alias]) |
|
| 994 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | + ) { |
|
| 996 | + $par = $infos['alias'] . "." . $champ; |
|
| 997 | + } elseif ($table) { |
|
| 998 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | + } else { |
|
| 1001 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return $raw ? $par : "'$par'"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1017 | 1017 | */ |
| 1018 | 1018 | function critere_par_joint($table, $champ, &$boucle) { |
| 1019 | - $t = array_search($table, $boucle->from); |
|
| 1020 | - if (!$t) { |
|
| 1021 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | - } |
|
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1019 | + $t = array_search($table, $boucle->from); |
|
| 1020 | + if (!$t) { |
|
| 1021 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | + } |
|
| 1023 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1045,143 +1045,143 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1047 | 1047 | |
| 1048 | - $boucle = &$boucles[$idb]; |
|
| 1049 | - // Classement par ordre inverse |
|
| 1050 | - if ($crit->not) { |
|
| 1051 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | - } else { |
|
| 1053 | - $order = "' DESC'"; |
|
| 1054 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | - if (isset($crit->param[0])) { |
|
| 1056 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | - $order = "(($critere)?' DESC':'')"; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - $n = count($boucle->order); |
|
| 1061 | - if (!$n) { |
|
| 1062 | - if (isset($boucle->default_order[0])) { |
|
| 1063 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | - } else { |
|
| 1065 | - $boucle->default_order[] = ' DESC'; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1071 | - } |
|
| 1072 | - $boucle->order[$n - 1] = $t; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1048 | + $boucle = &$boucles[$idb]; |
|
| 1049 | + // Classement par ordre inverse |
|
| 1050 | + if ($crit->not) { |
|
| 1051 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | + } else { |
|
| 1053 | + $order = "' DESC'"; |
|
| 1054 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | + if (isset($crit->param[0])) { |
|
| 1056 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | + $order = "(($critere)?' DESC':'')"; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + $n = count($boucle->order); |
|
| 1061 | + if (!$n) { |
|
| 1062 | + if (isset($boucle->default_order[0])) { |
|
| 1063 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | + } else { |
|
| 1065 | + $boucle->default_order[] = ' DESC'; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | + $t = $r[1] . $r[2]; |
|
| 1071 | + } |
|
| 1072 | + $boucle->order[$n - 1] = $t; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // http://code.spip.net/@critere_agenda_dist |
| 1078 | 1078 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1079 | - $params = $crit->param; |
|
| 1080 | - |
|
| 1081 | - if (count($params) < 1) { |
|
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - $boucle = &$boucles[$idb]; |
|
| 1086 | - $parent = $boucle->id_parent; |
|
| 1087 | - $fields = $boucle->show['field']; |
|
| 1088 | - |
|
| 1089 | - $date = array_shift($params); |
|
| 1090 | - $type = array_shift($params); |
|
| 1091 | - |
|
| 1092 | - // la valeur $type doit etre connue a la compilation |
|
| 1093 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | - |
|
| 1096 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | - $date = $date[0]->texte; |
|
| 1102 | - if (!isset($fields[$date])) { |
|
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | - } |
|
| 1105 | - } else { |
|
| 1106 | - $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1107 | - $noms = array_keys($fields); |
|
| 1108 | - $defaut = $noms[0]; |
|
| 1109 | - $noms = join(" ", $noms); |
|
| 1110 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | - } |
|
| 1114 | - $annee = $params ? array_shift($params) : ""; |
|
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1117 | - ') ? $x : date("Y"))'; |
|
| 1118 | - |
|
| 1119 | - $mois = $params ? array_shift($params) : ""; |
|
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1122 | - ') ? $x : date("m"))'; |
|
| 1123 | - |
|
| 1124 | - $jour = $params ? array_shift($params) : ""; |
|
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1127 | - ') ? $x : date("d"))'; |
|
| 1128 | - |
|
| 1129 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1132 | - ') ? $x : date("Y"))'; |
|
| 1133 | - |
|
| 1134 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1137 | - ') ? $x : date("m"))'; |
|
| 1138 | - |
|
| 1139 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1142 | - ') ? $x : date("d"))'; |
|
| 1143 | - |
|
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1145 | - |
|
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | - if ($type == 'jour') { |
|
| 1148 | - $boucle->where[] = array( |
|
| 1149 | - "'='", |
|
| 1150 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | - ); |
|
| 1153 | - } elseif ($type == 'mois') { |
|
| 1154 | - $boucle->where[] = array( |
|
| 1155 | - "'='", |
|
| 1156 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | - ); |
|
| 1159 | - } elseif ($type == 'semaine') { |
|
| 1160 | - $boucle->where[] = array( |
|
| 1161 | - "'AND'", |
|
| 1162 | - array( |
|
| 1163 | - "'>='", |
|
| 1164 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | - ), |
|
| 1167 | - array( |
|
| 1168 | - "'<='", |
|
| 1169 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | - ) |
|
| 1172 | - ); |
|
| 1173 | - } elseif (count($crit->param) > 2) { |
|
| 1174 | - $boucle->where[] = array( |
|
| 1175 | - "'AND'", |
|
| 1176 | - array( |
|
| 1177 | - "'>='", |
|
| 1178 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | - ), |
|
| 1181 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - // sinon on prend tout |
|
| 1079 | + $params = $crit->param; |
|
| 1080 | + |
|
| 1081 | + if (count($params) < 1) { |
|
| 1082 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + $boucle = &$boucles[$idb]; |
|
| 1086 | + $parent = $boucle->id_parent; |
|
| 1087 | + $fields = $boucle->show['field']; |
|
| 1088 | + |
|
| 1089 | + $date = array_shift($params); |
|
| 1090 | + $type = array_shift($params); |
|
| 1091 | + |
|
| 1092 | + // la valeur $type doit etre connue a la compilation |
|
| 1093 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | + |
|
| 1096 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | + $date = $date[0]->texte; |
|
| 1102 | + if (!isset($fields[$date])) { |
|
| 1103 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | + } |
|
| 1105 | + } else { |
|
| 1106 | + $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1107 | + $noms = array_keys($fields); |
|
| 1108 | + $defaut = $noms[0]; |
|
| 1109 | + $noms = join(" ", $noms); |
|
| 1110 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | + } |
|
| 1114 | + $annee = $params ? array_shift($params) : ""; |
|
| 1115 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | + calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1117 | + ') ? $x : date("Y"))'; |
|
| 1118 | + |
|
| 1119 | + $mois = $params ? array_shift($params) : ""; |
|
| 1120 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | + calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1122 | + ') ? $x : date("m"))'; |
|
| 1123 | + |
|
| 1124 | + $jour = $params ? array_shift($params) : ""; |
|
| 1125 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | + calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1127 | + ') ? $x : date("d"))'; |
|
| 1128 | + |
|
| 1129 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | + calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1132 | + ') ? $x : date("Y"))'; |
|
| 1133 | + |
|
| 1134 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | + calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1137 | + ') ? $x : date("m"))'; |
|
| 1138 | + |
|
| 1139 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | + calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1142 | + ') ? $x : date("d"))'; |
|
| 1143 | + |
|
| 1144 | + $date = $boucle->id_table . ".$date"; |
|
| 1145 | + |
|
| 1146 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | + if ($type == 'jour') { |
|
| 1148 | + $boucle->where[] = array( |
|
| 1149 | + "'='", |
|
| 1150 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | + ); |
|
| 1153 | + } elseif ($type == 'mois') { |
|
| 1154 | + $boucle->where[] = array( |
|
| 1155 | + "'='", |
|
| 1156 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | + ); |
|
| 1159 | + } elseif ($type == 'semaine') { |
|
| 1160 | + $boucle->where[] = array( |
|
| 1161 | + "'AND'", |
|
| 1162 | + array( |
|
| 1163 | + "'>='", |
|
| 1164 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | + ), |
|
| 1167 | + array( |
|
| 1168 | + "'<='", |
|
| 1169 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | + ) |
|
| 1172 | + ); |
|
| 1173 | + } elseif (count($crit->param) > 2) { |
|
| 1174 | + $boucle->where[] = array( |
|
| 1175 | + "'AND'", |
|
| 1176 | + array( |
|
| 1177 | + "'>='", |
|
| 1178 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | + ), |
|
| 1181 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + // sinon on prend tout |
|
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | |
@@ -1206,33 +1206,33 @@ discard block |
||
| 1206 | 1206 | * @return void |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1209 | - $boucle = &$boucles[$idb]; |
|
| 1210 | - $a1 = $crit->param[0]; |
|
| 1211 | - $a2 = $crit->param[1]; |
|
| 1212 | - $op = $crit->op; |
|
| 1213 | - |
|
| 1214 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | - |
|
| 1217 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | - } else { |
|
| 1220 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | - $boucle->limit = |
|
| 1229 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | - . ".','." |
|
| 1231 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | - } else { |
|
| 1233 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1209 | + $boucle = &$boucles[$idb]; |
|
| 1210 | + $a1 = $crit->param[0]; |
|
| 1211 | + $a2 = $crit->param[1]; |
|
| 1212 | + $op = $crit->op; |
|
| 1213 | + |
|
| 1214 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | + |
|
| 1217 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | + } else { |
|
| 1220 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | + $mode = (($op == '/') ? '/' : |
|
| 1225 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | + $boucle->limit = |
|
| 1229 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | + . ".','." |
|
| 1231 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | + } else { |
|
| 1233 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1260,63 +1260,63 @@ discard block |
||
| 1260 | 1260 | * @return void |
| 1261 | 1261 | **/ |
| 1262 | 1262 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1263 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | - |
|
| 1265 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | - // {1/3} |
|
| 1269 | - if ($op1 == '/') { |
|
| 1270 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1273 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | - } else { |
|
| 1276 | - // cas {n-1,x} |
|
| 1277 | - if ($op1 == '-') { |
|
| 1278 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - // cas {x,n-1} |
|
| 1282 | - if ($op2 == '-') { |
|
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1286 | - } else { |
|
| 1287 | - // {x,1} ou {pagination} |
|
| 1288 | - $fin = '$debut_boucle' |
|
| 1289 | - . (is_numeric($total_parties) ? |
|
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | - if ($op1 == 'p') { |
|
| 1296 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // Notes : |
|
| 1303 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | - |
|
| 1308 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | - . "\n\tif (\$debut_boucle>0" |
|
| 1315 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | - |
|
| 1319 | - $boucles[$id_boucle]->partie = " |
|
| 1263 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | + |
|
| 1265 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | + // {1/3} |
|
| 1269 | + if ($op1 == '/') { |
|
| 1270 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | + "($total_parties ? $total_parties : 1)"; |
|
| 1273 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | + } else { |
|
| 1276 | + // cas {n-1,x} |
|
| 1277 | + if ($op1 == '-') { |
|
| 1278 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + // cas {x,n-1} |
|
| 1282 | + if ($op2 == '-') { |
|
| 1283 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | + ($total_parties . ' - 1')); |
|
| 1286 | + } else { |
|
| 1287 | + // {x,1} ou {pagination} |
|
| 1288 | + $fin = '$debut_boucle' |
|
| 1289 | + . (is_numeric($total_parties) ? |
|
| 1290 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | + ('+' . $total_parties . ' - 1')); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | + if ($op1 == 'p') { |
|
| 1296 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // Notes : |
|
| 1303 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | + |
|
| 1308 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | + . "\n\tif (\$debut_boucle>0" |
|
| 1315 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | + |
|
| 1319 | + $boucles[$id_boucle]->partie = " |
|
| 1320 | 1320 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1321 | 1321 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1322 | 1322 | } |
@@ -1333,26 +1333,26 @@ discard block |
||
| 1333 | 1333 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1334 | 1334 | **/ |
| 1335 | 1335 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1336 | - if ($param[0]->type != 'texte') { |
|
| 1337 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | - if (isset($param[1]->texte)) { |
|
| 1339 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | - |
|
| 1341 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | - } else { |
|
| 1343 | - return array("intval($a1)", 0); |
|
| 1344 | - } |
|
| 1345 | - } else { |
|
| 1346 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | - $a1 = $m[1]; |
|
| 1348 | - if (empty($m[3])) { |
|
| 1349 | - return array($a1, 0); |
|
| 1350 | - } elseif (!empty($m[4])) { |
|
| 1351 | - return array($a1, $m[4]); |
|
| 1352 | - } else { |
|
| 1353 | - return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1336 | + if ($param[0]->type != 'texte') { |
|
| 1337 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | + if (isset($param[1]->texte)) { |
|
| 1339 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | + |
|
| 1341 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | + } else { |
|
| 1343 | + return array("intval($a1)", 0); |
|
| 1344 | + } |
|
| 1345 | + } else { |
|
| 1346 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | + $a1 = $m[1]; |
|
| 1348 | + if (empty($m[3])) { |
|
| 1349 | + return array($a1, 0); |
|
| 1350 | + } elseif (!empty($m[4])) { |
|
| 1351 | + return array($a1, $m[4]); |
|
| 1352 | + } else { |
|
| 1353 | + return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
@@ -1379,47 +1379,47 @@ discard block |
||
| 1379 | 1379 | * array : Erreur sur un des critères |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function calculer_criteres($idb, &$boucles) { |
| 1382 | - $msg = ''; |
|
| 1383 | - $boucle = $boucles[$idb]; |
|
| 1384 | - $table = strtoupper($boucle->type_requete); |
|
| 1385 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | - |
|
| 1387 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | - if (!is_array($boucle->criteres)) { |
|
| 1390 | - return array(); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - foreach ($boucle->criteres as $crit) { |
|
| 1394 | - $critere = $crit->op; |
|
| 1395 | - // critere personnalise ? |
|
| 1396 | - if ( |
|
| 1397 | - (!$serveur or |
|
| 1398 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | - and (!function_exists($f = $f . "_dist")) |
|
| 1400 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | - and (!function_exists($f = $f . "_dist")) |
|
| 1402 | - ) |
|
| 1403 | - ) |
|
| 1404 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1408 | - ) { |
|
| 1409 | - // fonction critere standard |
|
| 1410 | - $f = $defaut; |
|
| 1411 | - } |
|
| 1412 | - // compile le critere |
|
| 1413 | - $res = $f($idb, $boucles, $crit); |
|
| 1414 | - |
|
| 1415 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | - if (is_array($res)) { |
|
| 1417 | - $msg = $res; |
|
| 1418 | - erreur_squelette($msg, $boucle); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - return $msg; |
|
| 1382 | + $msg = ''; |
|
| 1383 | + $boucle = $boucles[$idb]; |
|
| 1384 | + $table = strtoupper($boucle->type_requete); |
|
| 1385 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | + |
|
| 1387 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | + if (!is_array($boucle->criteres)) { |
|
| 1390 | + return array(); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + foreach ($boucle->criteres as $crit) { |
|
| 1394 | + $critere = $crit->op; |
|
| 1395 | + // critere personnalise ? |
|
| 1396 | + if ( |
|
| 1397 | + (!$serveur or |
|
| 1398 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | + and (!function_exists($f = $f . "_dist")) |
|
| 1400 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | + and (!function_exists($f = $f . "_dist")) |
|
| 1402 | + ) |
|
| 1403 | + ) |
|
| 1404 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | + and (!function_exists($f = $f . "_dist")) |
|
| 1406 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | + and (!function_exists($f = $f . "_dist")) |
|
| 1408 | + ) { |
|
| 1409 | + // fonction critere standard |
|
| 1410 | + $f = $defaut; |
|
| 1411 | + } |
|
| 1412 | + // compile le critere |
|
| 1413 | + $res = $f($idb, $boucles, $crit); |
|
| 1414 | + |
|
| 1415 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | + if (is_array($res)) { |
|
| 1417 | + $msg = $res; |
|
| 1418 | + erreur_squelette($msg, $boucle); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + return $msg; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1436,11 +1436,11 @@ discard block |
||
| 1436 | 1436 | * @return string Code compilé rééchappé |
| 1437 | 1437 | */ |
| 1438 | 1438 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | - } else { |
|
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | - } |
|
| 1439 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | + } else { |
|
| 1442 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | + } |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1459,85 +1459,85 @@ discard block |
||
| 1459 | 1459 | * @return void |
| 1460 | 1460 | **/ |
| 1461 | 1461 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | - if (!$r) { |
|
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | - } |
|
| 1466 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | - |
|
| 1468 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | - |
|
| 1470 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | - $where = $in; |
|
| 1472 | - if ($crit->cond) { |
|
| 1473 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | - { |
|
| 1477 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - if ($crit->exclus) { |
|
| 1481 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | - $where = array("'NOT'", $where); |
|
| 1483 | - } else |
|
| 1484 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | - { |
|
| 1487 | - $where = array( |
|
| 1488 | - "'NOT'", |
|
| 1489 | - array( |
|
| 1490 | - "'IN'", |
|
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | - ) |
|
| 1494 | - ); |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $boucles[$idb]->where[] = $where; |
|
| 1499 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | - { |
|
| 1501 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | - } |
|
| 1462 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | + if (!$r) { |
|
| 1464 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | + } |
|
| 1466 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | + |
|
| 1468 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | + |
|
| 1470 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | + $where = $in; |
|
| 1472 | + if ($crit->cond) { |
|
| 1473 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | + { |
|
| 1477 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + if ($crit->exclus) { |
|
| 1481 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | + $where = array("'NOT'", $where); |
|
| 1483 | + } else |
|
| 1484 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | + { |
|
| 1487 | + $where = array( |
|
| 1488 | + "'NOT'", |
|
| 1489 | + array( |
|
| 1490 | + "'IN'", |
|
| 1491 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | + ) |
|
| 1494 | + ); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $boucles[$idb]->where[] = $where; |
|
| 1499 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | + { |
|
| 1501 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | + } |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | // http://code.spip.net/@critere_IN_cas |
| 1506 | 1506 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1507 | - static $num = array(); |
|
| 1508 | - $descr = $boucles[$idb]->descr; |
|
| 1509 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | - |
|
| 1511 | - $var = '$in' . $cpt++; |
|
| 1512 | - $x = "\n\t$var = array();"; |
|
| 1513 | - foreach ($val as $k => $v) { |
|
| 1514 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | - // optimiser le traitement des constantes |
|
| 1516 | - if (is_numeric($r[2])) { |
|
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | - } else { |
|
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | - } |
|
| 1521 | - } else { |
|
| 1522 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - $boucles[$idb]->in .= $x; |
|
| 1531 | - |
|
| 1532 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | - if (!$crit2) { |
|
| 1537 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1507 | + static $num = array(); |
|
| 1508 | + $descr = $boucles[$idb]->descr; |
|
| 1509 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | + |
|
| 1511 | + $var = '$in' . $cpt++; |
|
| 1512 | + $x = "\n\t$var = array();"; |
|
| 1513 | + foreach ($val as $k => $v) { |
|
| 1514 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | + // optimiser le traitement des constantes |
|
| 1516 | + if (is_numeric($r[2])) { |
|
| 1517 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | + } else { |
|
| 1519 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | + } |
|
| 1521 | + } else { |
|
| 1522 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + $boucles[$idb]->in .= $x; |
|
| 1531 | + |
|
| 1532 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | + if (!$crit2) { |
|
| 1537 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1553,22 +1553,22 @@ discard block |
||
| 1553 | 1553 | * @return void |
| 1554 | 1554 | */ |
| 1555 | 1555 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1556 | - $boucle = &$boucles[$idb]; |
|
| 1557 | - if (isset($crit->param[0])) { |
|
| 1558 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1559 | - } else { |
|
| 1560 | - $_where = '@$Pile[0]["where"]'; |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - if ($crit->cond) { |
|
| 1564 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - if ($crit->not) { |
|
| 1568 | - $_where = "array('NOT',$_where)"; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $boucle->where[] = $_where; |
|
| 1556 | + $boucle = &$boucles[$idb]; |
|
| 1557 | + if (isset($crit->param[0])) { |
|
| 1558 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1559 | + } else { |
|
| 1560 | + $_where = '@$Pile[0]["where"]'; |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + if ($crit->cond) { |
|
| 1564 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + if ($crit->not) { |
|
| 1568 | + $_where = "array('NOT',$_where)"; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $boucle->where[] = $_where; |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
@@ -1596,31 +1596,31 @@ discard block |
||
| 1596 | 1596 | * @return void |
| 1597 | 1597 | */ |
| 1598 | 1598 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1599 | - /** @var Boucle $boucle */ |
|
| 1600 | - $boucle = $boucles[$idb]; |
|
| 1601 | - |
|
| 1602 | - $champs = lister_champs_selection_conditionnelle( |
|
| 1603 | - $boucle->show['table'], |
|
| 1604 | - $boucle->show, |
|
| 1605 | - $boucle->sql_serveur |
|
| 1606 | - ); |
|
| 1607 | - |
|
| 1608 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | - } |
|
| 1612 | - // nous aider en mode debug. |
|
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | - $boucle->modificateur['id_'] = $champs; |
|
| 1615 | - |
|
| 1616 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | - foreach ($champs as $champ) { |
|
| 1618 | - $critere_id_table = new Critere; |
|
| 1619 | - $critere_id_table->op = $champ; |
|
| 1620 | - $critere_id_table->cond = '?'; |
|
| 1621 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | - } |
|
| 1599 | + /** @var Boucle $boucle */ |
|
| 1600 | + $boucle = $boucles[$idb]; |
|
| 1601 | + |
|
| 1602 | + $champs = lister_champs_selection_conditionnelle( |
|
| 1603 | + $boucle->show['table'], |
|
| 1604 | + $boucle->show, |
|
| 1605 | + $boucle->sql_serveur |
|
| 1606 | + ); |
|
| 1607 | + |
|
| 1608 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | + } |
|
| 1612 | + // nous aider en mode debug. |
|
| 1613 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | + $boucle->modificateur['id_'] = $champs; |
|
| 1615 | + |
|
| 1616 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | + foreach ($champs as $champ) { |
|
| 1618 | + $critere_id_table = new Critere; |
|
| 1619 | + $critere_id_table->op = $champ; |
|
| 1620 | + $critere_id_table->cond = '?'; |
|
| 1621 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | + } |
|
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | 1626 | /** |
@@ -1640,67 +1640,67 @@ discard block |
||
| 1640 | 1640 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1641 | 1641 | */ |
| 1642 | 1642 | function lister_champs_selection_conditionnelle($table, $desc = null, $serveur = '') { |
| 1643 | - // calculer la description de la table |
|
| 1644 | - if (!is_array($desc)) { |
|
| 1645 | - $desc = description_table($table, $serveur); |
|
| 1646 | - } |
|
| 1647 | - if (!$desc) { |
|
| 1648 | - return []; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - // Les champs id_xx de la table demandée |
|
| 1652 | - $champs = array_filter( |
|
| 1653 | - array_keys($desc['field']), |
|
| 1654 | - function($champ){ |
|
| 1655 | - return |
|
| 1656 | - strpos($champ, 'id_') === 0 |
|
| 1657 | - or (in_array($champ, array('objet'))); |
|
| 1658 | - } |
|
| 1659 | - ); |
|
| 1660 | - |
|
| 1661 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1662 | - if ($serveur) { |
|
| 1663 | - return $champs; |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - $primary = false; |
|
| 1667 | - $associable = false; |
|
| 1668 | - include_spip('action/editer_liens'); |
|
| 1669 | - |
|
| 1670 | - if (isset($desc['type'])) { |
|
| 1671 | - $primary = id_table_objet($desc['type']); |
|
| 1672 | - $associable = objet_associable($desc['type']); |
|
| 1673 | - } |
|
| 1674 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1675 | - $associable = true; |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - // liste de toutes les tables principales, sauf la notre |
|
| 1679 | - $tables = lister_tables_objets_sql(); |
|
| 1680 | - unset($tables[$table]); |
|
| 1681 | - |
|
| 1682 | - foreach ($tables as $_table => $_desc) { |
|
| 1683 | - if ( |
|
| 1684 | - $associable |
|
| 1685 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1686 | - or objet_associable($_desc['type']) |
|
| 1687 | - ) { |
|
| 1688 | - $champs[] = id_table_objet($_table); |
|
| 1689 | - } |
|
| 1690 | - } |
|
| 1691 | - $champs = array_values(array_unique($champs)); |
|
| 1692 | - $champs = pipeline( |
|
| 1693 | - 'lister_champs_selection_conditionnelle', |
|
| 1694 | - array( |
|
| 1695 | - 'args' => array( |
|
| 1696 | - 'table' => $table, |
|
| 1697 | - 'id_table_objet' => $primary, |
|
| 1698 | - 'associable' => $associable, |
|
| 1699 | - ), |
|
| 1700 | - 'data' => $champs, |
|
| 1701 | - ) |
|
| 1702 | - ); |
|
| 1703 | - return $champs; |
|
| 1643 | + // calculer la description de la table |
|
| 1644 | + if (!is_array($desc)) { |
|
| 1645 | + $desc = description_table($table, $serveur); |
|
| 1646 | + } |
|
| 1647 | + if (!$desc) { |
|
| 1648 | + return []; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + // Les champs id_xx de la table demandée |
|
| 1652 | + $champs = array_filter( |
|
| 1653 | + array_keys($desc['field']), |
|
| 1654 | + function($champ){ |
|
| 1655 | + return |
|
| 1656 | + strpos($champ, 'id_') === 0 |
|
| 1657 | + or (in_array($champ, array('objet'))); |
|
| 1658 | + } |
|
| 1659 | + ); |
|
| 1660 | + |
|
| 1661 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1662 | + if ($serveur) { |
|
| 1663 | + return $champs; |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + $primary = false; |
|
| 1667 | + $associable = false; |
|
| 1668 | + include_spip('action/editer_liens'); |
|
| 1669 | + |
|
| 1670 | + if (isset($desc['type'])) { |
|
| 1671 | + $primary = id_table_objet($desc['type']); |
|
| 1672 | + $associable = objet_associable($desc['type']); |
|
| 1673 | + } |
|
| 1674 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1675 | + $associable = true; |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + // liste de toutes les tables principales, sauf la notre |
|
| 1679 | + $tables = lister_tables_objets_sql(); |
|
| 1680 | + unset($tables[$table]); |
|
| 1681 | + |
|
| 1682 | + foreach ($tables as $_table => $_desc) { |
|
| 1683 | + if ( |
|
| 1684 | + $associable |
|
| 1685 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1686 | + or objet_associable($_desc['type']) |
|
| 1687 | + ) { |
|
| 1688 | + $champs[] = id_table_objet($_table); |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + $champs = array_values(array_unique($champs)); |
|
| 1692 | + $champs = pipeline( |
|
| 1693 | + 'lister_champs_selection_conditionnelle', |
|
| 1694 | + array( |
|
| 1695 | + 'args' => array( |
|
| 1696 | + 'table' => $table, |
|
| 1697 | + 'id_table_objet' => $primary, |
|
| 1698 | + 'associable' => $associable, |
|
| 1699 | + ), |
|
| 1700 | + 'data' => $champs, |
|
| 1701 | + ) |
|
| 1702 | + ); |
|
| 1703 | + return $champs; |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | /** |
@@ -1755,27 +1755,27 @@ discard block |
||
| 1755 | 1755 | * @return void |
| 1756 | 1756 | */ |
| 1757 | 1757 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1758 | - $boucle = &$boucles[$idb]; |
|
| 1759 | - |
|
| 1760 | - // definition du champ par defaut |
|
| 1761 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1762 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1763 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1764 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1765 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1766 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1767 | - |
|
| 1768 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1769 | - |
|
| 1770 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1771 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1772 | - |
|
| 1773 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1774 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1775 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1776 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1777 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1778 | - $boucle->hash .= " |
|
| 1758 | + $boucle = &$boucles[$idb]; |
|
| 1759 | + |
|
| 1760 | + // definition du champ par defaut |
|
| 1761 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1762 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1763 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1764 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1765 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1766 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1767 | + |
|
| 1768 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1769 | + |
|
| 1770 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1771 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1772 | + |
|
| 1773 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1774 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1775 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1776 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1777 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1778 | + $boucle->hash .= " |
|
| 1779 | 1779 | \$senstri = ''; |
| 1780 | 1780 | \$tri = $_tri; |
| 1781 | 1781 | if (\$tri){ |
@@ -1783,8 +1783,8 @@ discard block |
||
| 1783 | 1783 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1784 | 1784 | }; |
| 1785 | 1785 | "; |
| 1786 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1787 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1786 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1787 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | 1790 | # Criteres de comparaison |
@@ -1801,20 +1801,20 @@ discard block |
||
| 1801 | 1801 | * @return void |
| 1802 | 1802 | **/ |
| 1803 | 1803 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1804 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1805 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1806 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1810 | - if (!$r) { |
|
| 1811 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1812 | - # if (!$crit->cond) { |
|
| 1813 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1814 | - # } |
|
| 1815 | - } else { |
|
| 1816 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1817 | - } |
|
| 1804 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1805 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1806 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1810 | + if (!$r) { |
|
| 1811 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1812 | + # if (!$crit->cond) { |
|
| 1813 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1814 | + # } |
|
| 1815 | + } else { |
|
| 1816 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1817 | + } |
|
| 1818 | 1818 | } |
| 1819 | 1819 | |
| 1820 | 1820 | |
@@ -1834,63 +1834,63 @@ discard block |
||
| 1834 | 1834 | * @return void |
| 1835 | 1835 | **/ |
| 1836 | 1836 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1837 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1838 | - |
|
| 1839 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1840 | - |
|
| 1841 | - // inserer la negation (cf !...) |
|
| 1842 | - |
|
| 1843 | - if ($crit->not) { |
|
| 1844 | - $where = array("'NOT'", $where); |
|
| 1845 | - } |
|
| 1846 | - if ($crit->exclus) { |
|
| 1847 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1848 | - $where = array("'NOT'", $where); |
|
| 1849 | - } else |
|
| 1850 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1851 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1852 | - { |
|
| 1853 | - $where = array( |
|
| 1854 | - "'NOT'", |
|
| 1855 | - array( |
|
| 1856 | - "'IN'", |
|
| 1857 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1859 | - ) |
|
| 1860 | - ); |
|
| 1861 | - } |
|
| 1862 | - } |
|
| 1863 | - |
|
| 1864 | - // inserer la condition (cf {lang?}) |
|
| 1865 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1866 | - if ($crit->cond) { |
|
| 1867 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1868 | - if ($col == "date" or $col == "date_redac") { |
|
| 1869 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1870 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1871 | - } |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - if ($op == '=' and !$crit->not) { |
|
| 1875 | - $where = array( |
|
| 1876 | - "'?'", |
|
| 1877 | - "(is_array($pred))", |
|
| 1878 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1879 | - $where |
|
| 1880 | - ); |
|
| 1881 | - } |
|
| 1882 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1883 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1884 | - { |
|
| 1885 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1886 | - } |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - $boucles[$idb]->where[] = $where; |
|
| 1890 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | - { |
|
| 1892 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1893 | - } |
|
| 1837 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1838 | + |
|
| 1839 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1840 | + |
|
| 1841 | + // inserer la negation (cf !...) |
|
| 1842 | + |
|
| 1843 | + if ($crit->not) { |
|
| 1844 | + $where = array("'NOT'", $where); |
|
| 1845 | + } |
|
| 1846 | + if ($crit->exclus) { |
|
| 1847 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1848 | + $where = array("'NOT'", $where); |
|
| 1849 | + } else |
|
| 1850 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1851 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1852 | + { |
|
| 1853 | + $where = array( |
|
| 1854 | + "'NOT'", |
|
| 1855 | + array( |
|
| 1856 | + "'IN'", |
|
| 1857 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1859 | + ) |
|
| 1860 | + ); |
|
| 1861 | + } |
|
| 1862 | + } |
|
| 1863 | + |
|
| 1864 | + // inserer la condition (cf {lang?}) |
|
| 1865 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1866 | + if ($crit->cond) { |
|
| 1867 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1868 | + if ($col == "date" or $col == "date_redac") { |
|
| 1869 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1870 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1871 | + } |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + if ($op == '=' and !$crit->not) { |
|
| 1875 | + $where = array( |
|
| 1876 | + "'?'", |
|
| 1877 | + "(is_array($pred))", |
|
| 1878 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1879 | + $where |
|
| 1880 | + ); |
|
| 1881 | + } |
|
| 1882 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1883 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1884 | + { |
|
| 1885 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1886 | + } |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + $boucles[$idb]->where[] = $where; |
|
| 1890 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | + { |
|
| 1892 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1893 | + } |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | |
@@ -1931,167 +1931,167 @@ discard block |
||
| 1931 | 1931 | **/ |
| 1932 | 1932 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1933 | 1933 | |
| 1934 | - $boucle = &$boucles[$idb]; |
|
| 1935 | - $type = $boucle->type_requete; |
|
| 1936 | - $table = $boucle->id_table; |
|
| 1937 | - $desc = $boucle->show; |
|
| 1938 | - $col_vraie = null; |
|
| 1939 | - |
|
| 1940 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1941 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1942 | - |
|
| 1943 | - $col_alias = $col; |
|
| 1944 | - $where_complement = false; |
|
| 1945 | - |
|
| 1946 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1947 | - if ($col == 'id_enfant') { |
|
| 1948 | - $col = $boucle->primary; |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1952 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1953 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1954 | - ) { |
|
| 1955 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1956 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1957 | - else { |
|
| 1958 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1959 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1963 | - // sauf si exception declaree : sauter cette etape |
|
| 1964 | - else { |
|
| 1965 | - if ( |
|
| 1966 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1967 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1968 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1969 | - ) { |
|
| 1970 | - $e = decompose_champ_id_objet($col); |
|
| 1971 | - $col = array_shift($e); |
|
| 1972 | - $where_complement = primary_doublee($e, $table); |
|
| 1973 | - } // Cas particulier : expressions de date |
|
| 1974 | - else { |
|
| 1975 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1976 | - list($col, $col_vraie) = $c; |
|
| 1977 | - $table = ''; |
|
| 1978 | - } // table explicitée {mots.titre} |
|
| 1979 | - else { |
|
| 1980 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1981 | - list(, $table, $col) = $r; |
|
| 1982 | - $col_alias = $col; |
|
| 1983 | - |
|
| 1984 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1985 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1986 | - and isset($desc['field'][$col]) |
|
| 1987 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 1988 | - ) { |
|
| 1989 | - $table = $cle; |
|
| 1990 | - } else { |
|
| 1991 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1992 | - } |
|
| 1993 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1994 | - if (!$table) { |
|
| 1995 | - return ''; |
|
| 1996 | - } |
|
| 1997 | - } |
|
| 1998 | - // si le champ n'est pas trouvé dans la table, |
|
| 1999 | - // on cherche si une jointure peut l'obtenir |
|
| 2000 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2001 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2002 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2003 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2004 | - } |
|
| 2005 | - else { |
|
| 2006 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2007 | - if (!$r) { |
|
| 2008 | - return ''; |
|
| 2009 | - } |
|
| 2010 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2011 | - } |
|
| 2012 | - } |
|
| 2013 | - } |
|
| 2014 | - } |
|
| 2015 | - } |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2019 | - // Dans tous les cas, |
|
| 2020 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2021 | - // et passer dans sql_quote avec le type si connu |
|
| 2022 | - // et int sinon si la valeur est numerique |
|
| 2023 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2024 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2025 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2026 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2027 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2028 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2029 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2030 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2031 | - } |
|
| 2032 | - // sinon expliciter les |
|
| 2033 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2034 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2035 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2036 | - // sans toucher aux |
|
| 2037 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2038 | - // sql_quote(truc,'','varchar') |
|
| 2039 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2040 | - // si pas deja un type |
|
| 2041 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2042 | - ) { |
|
| 2043 | - $r = $r[1] |
|
| 2044 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2045 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2046 | - $val[0] = "sql_quote($r)"; |
|
| 2047 | - } |
|
| 2048 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2050 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2051 | - } |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2056 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2060 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2061 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2062 | - if ($table === $boucle->id_table) { |
|
| 2063 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2064 | - if ($col_alias != $col_vraie) { |
|
| 2065 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2070 | - // il faut alors interdire a la fonction de boucle |
|
| 2071 | - // de mettre ses propres criteres de statut |
|
| 2072 | - // http://www.spip.net/@statut (a documenter) |
|
| 2073 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2074 | - if ($col == 'statut') { |
|
| 2075 | - $boucles[$idb]->statut = true; |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2079 | - if ($table) { |
|
| 2080 | - if ($col[0] == "`") { |
|
| 2081 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2082 | - } else { |
|
| 2083 | - $arg = "$table.$col"; |
|
| 2084 | - } |
|
| 2085 | - } else { |
|
| 2086 | - $arg = $col; |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - // inserer la fonction SQL |
|
| 2090 | - if ($fct) { |
|
| 2091 | - $arg = "$fct($arg$args_sql)"; |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1934 | + $boucle = &$boucles[$idb]; |
|
| 1935 | + $type = $boucle->type_requete; |
|
| 1936 | + $table = $boucle->id_table; |
|
| 1937 | + $desc = $boucle->show; |
|
| 1938 | + $col_vraie = null; |
|
| 1939 | + |
|
| 1940 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1941 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1942 | + |
|
| 1943 | + $col_alias = $col; |
|
| 1944 | + $where_complement = false; |
|
| 1945 | + |
|
| 1946 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1947 | + if ($col == 'id_enfant') { |
|
| 1948 | + $col = $boucle->primary; |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1952 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1953 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1954 | + ) { |
|
| 1955 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1956 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1957 | + else { |
|
| 1958 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1959 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1963 | + // sauf si exception declaree : sauter cette etape |
|
| 1964 | + else { |
|
| 1965 | + if ( |
|
| 1966 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1967 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1968 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1969 | + ) { |
|
| 1970 | + $e = decompose_champ_id_objet($col); |
|
| 1971 | + $col = array_shift($e); |
|
| 1972 | + $where_complement = primary_doublee($e, $table); |
|
| 1973 | + } // Cas particulier : expressions de date |
|
| 1974 | + else { |
|
| 1975 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1976 | + list($col, $col_vraie) = $c; |
|
| 1977 | + $table = ''; |
|
| 1978 | + } // table explicitée {mots.titre} |
|
| 1979 | + else { |
|
| 1980 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1981 | + list(, $table, $col) = $r; |
|
| 1982 | + $col_alias = $col; |
|
| 1983 | + |
|
| 1984 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1985 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1986 | + and isset($desc['field'][$col]) |
|
| 1987 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 1988 | + ) { |
|
| 1989 | + $table = $cle; |
|
| 1990 | + } else { |
|
| 1991 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1992 | + } |
|
| 1993 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1994 | + if (!$table) { |
|
| 1995 | + return ''; |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | + // si le champ n'est pas trouvé dans la table, |
|
| 1999 | + // on cherche si une jointure peut l'obtenir |
|
| 2000 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2001 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2002 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2003 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2004 | + } |
|
| 2005 | + else { |
|
| 2006 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2007 | + if (!$r) { |
|
| 2008 | + return ''; |
|
| 2009 | + } |
|
| 2010 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2011 | + } |
|
| 2012 | + } |
|
| 2013 | + } |
|
| 2014 | + } |
|
| 2015 | + } |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2019 | + // Dans tous les cas, |
|
| 2020 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2021 | + // et passer dans sql_quote avec le type si connu |
|
| 2022 | + // et int sinon si la valeur est numerique |
|
| 2023 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2024 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2025 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2026 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2027 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2028 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2029 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2030 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2031 | + } |
|
| 2032 | + // sinon expliciter les |
|
| 2033 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2034 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2035 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2036 | + // sans toucher aux |
|
| 2037 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2038 | + // sql_quote(truc,'','varchar') |
|
| 2039 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2040 | + // si pas deja un type |
|
| 2041 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2042 | + ) { |
|
| 2043 | + $r = $r[1] |
|
| 2044 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2045 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2046 | + $val[0] = "sql_quote($r)"; |
|
| 2047 | + } |
|
| 2048 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2050 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2051 | + } |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2056 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2060 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2061 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2062 | + if ($table === $boucle->id_table) { |
|
| 2063 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2064 | + if ($col_alias != $col_vraie) { |
|
| 2065 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2070 | + // il faut alors interdire a la fonction de boucle |
|
| 2071 | + // de mettre ses propres criteres de statut |
|
| 2072 | + // http://www.spip.net/@statut (a documenter) |
|
| 2073 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2074 | + if ($col == 'statut') { |
|
| 2075 | + $boucles[$idb]->statut = true; |
|
| 2076 | + } |
|
| 2077 | + |
|
| 2078 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2079 | + if ($table) { |
|
| 2080 | + if ($col[0] == "`") { |
|
| 2081 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2082 | + } else { |
|
| 2083 | + $arg = "$table.$col"; |
|
| 2084 | + } |
|
| 2085 | + } else { |
|
| 2086 | + $arg = $col; |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + // inserer la fonction SQL |
|
| 2090 | + if ($fct) { |
|
| 2091 | + $arg = "$fct($arg$args_sql)"; |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2095 | 2095 | } |
| 2096 | 2096 | |
| 2097 | 2097 | |
@@ -2120,77 +2120,77 @@ discard block |
||
| 2120 | 2120 | **/ |
| 2121 | 2121 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2122 | 2122 | |
| 2123 | - $where = ''; |
|
| 2124 | - |
|
| 2125 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2126 | - // gestion par les plugins des jointures tordues |
|
| 2127 | - // pas automatiques mais necessaires |
|
| 2128 | - $table_sql = table_objet_sql($table); |
|
| 2129 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2130 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2131 | - and |
|
| 2132 | - ( |
|
| 2133 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2134 | - or |
|
| 2135 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2136 | - ) |
|
| 2137 | - ) { |
|
| 2138 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2139 | - $index = isset($t[$col]) |
|
| 2140 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2141 | - |
|
| 2142 | - if (count($index) == 3) { |
|
| 2143 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2144 | - } elseif (count($index) == 2) { |
|
| 2145 | - list($t, $col) = $t[$col]; |
|
| 2146 | - } elseif (count($index) == 1) { |
|
| 2147 | - list($calculer_critere_externe) = $index; |
|
| 2148 | - $t = $table; |
|
| 2149 | - } else { |
|
| 2150 | - $t = ''; |
|
| 2151 | - } // jointure non declaree. La trouver. |
|
| 2152 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2153 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2154 | - } else { |
|
| 2155 | - $t = ''; |
|
| 2156 | - } // jointure non declaree. La trouver. |
|
| 2157 | - |
|
| 2158 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2159 | - |
|
| 2160 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2161 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2162 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2163 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2164 | - $table = ""; |
|
| 2165 | - if ($boucle->jointures_explicites) { |
|
| 2166 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2167 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2171 | - if (!$table) { |
|
| 2172 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2173 | - } |
|
| 2174 | - |
|
| 2175 | - if (!$table) { |
|
| 2176 | - return ''; |
|
| 2177 | - } |
|
| 2178 | - |
|
| 2179 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2180 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2181 | - |
|
| 2182 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2183 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2184 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2185 | - $e = decompose_champ_id_objet($col); |
|
| 2186 | - $col = array_shift($e); |
|
| 2187 | - $where = primary_doublee($e, $table); |
|
| 2188 | - } else { |
|
| 2189 | - $col = reset($cle); |
|
| 2190 | - } |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2123 | + $where = ''; |
|
| 2124 | + |
|
| 2125 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2126 | + // gestion par les plugins des jointures tordues |
|
| 2127 | + // pas automatiques mais necessaires |
|
| 2128 | + $table_sql = table_objet_sql($table); |
|
| 2129 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2130 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2131 | + and |
|
| 2132 | + ( |
|
| 2133 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2134 | + or |
|
| 2135 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2136 | + ) |
|
| 2137 | + ) { |
|
| 2138 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2139 | + $index = isset($t[$col]) |
|
| 2140 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2141 | + |
|
| 2142 | + if (count($index) == 3) { |
|
| 2143 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2144 | + } elseif (count($index) == 2) { |
|
| 2145 | + list($t, $col) = $t[$col]; |
|
| 2146 | + } elseif (count($index) == 1) { |
|
| 2147 | + list($calculer_critere_externe) = $index; |
|
| 2148 | + $t = $table; |
|
| 2149 | + } else { |
|
| 2150 | + $t = ''; |
|
| 2151 | + } // jointure non declaree. La trouver. |
|
| 2152 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2153 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2154 | + } else { |
|
| 2155 | + $t = ''; |
|
| 2156 | + } // jointure non declaree. La trouver. |
|
| 2157 | + |
|
| 2158 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2159 | + |
|
| 2160 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2161 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2162 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2163 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2164 | + $table = ""; |
|
| 2165 | + if ($boucle->jointures_explicites) { |
|
| 2166 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2167 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2171 | + if (!$table) { |
|
| 2172 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2173 | + } |
|
| 2174 | + |
|
| 2175 | + if (!$table) { |
|
| 2176 | + return ''; |
|
| 2177 | + } |
|
| 2178 | + |
|
| 2179 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2180 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2181 | + |
|
| 2182 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2183 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2184 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2185 | + $e = decompose_champ_id_objet($col); |
|
| 2186 | + $col = array_shift($e); |
|
| 2187 | + $where = primary_doublee($e, $table); |
|
| 2188 | + } else { |
|
| 2189 | + $col = reset($cle); |
|
| 2190 | + } |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | |
@@ -2211,10 +2211,10 @@ discard block |
||
| 2211 | 2211 | * - valeur |
| 2212 | 2212 | **/ |
| 2213 | 2213 | function primary_doublee($decompose, $table) { |
| 2214 | - $e1 = reset($decompose); |
|
| 2215 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2214 | + $e1 = reset($decompose); |
|
| 2215 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2216 | 2216 | |
| 2217 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2217 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2218 | 2218 | } |
| 2219 | 2219 | |
| 2220 | 2220 | /** |
@@ -2245,56 +2245,56 @@ discard block |
||
| 2245 | 2245 | * Vide sinon. |
| 2246 | 2246 | */ |
| 2247 | 2247 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2248 | - // si on demande un truc du genre spip_mots |
|
| 2249 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2250 | - // et qu'on est la |
|
| 2251 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2252 | - if ($checkarrivee |
|
| 2253 | - and is_string($checkarrivee) |
|
| 2254 | - and $a = table_objet($checkarrivee) |
|
| 2255 | - and in_array($a . '_liens', $joints) |
|
| 2256 | - ) { |
|
| 2257 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2258 | - return $res; |
|
| 2259 | - } |
|
| 2260 | - } |
|
| 2261 | - foreach ($joints as $joint) { |
|
| 2262 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2263 | - // alias de table dans le from |
|
| 2264 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2265 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2266 | - $cols = $arrivee[2]; |
|
| 2267 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2268 | - if (count($cols) > 2) { |
|
| 2269 | - array_pop($cols); |
|
| 2270 | - } |
|
| 2271 | - if ($t) { |
|
| 2272 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2273 | - $joindre = false; |
|
| 2274 | - foreach ($cols as $col) { |
|
| 2275 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2276 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2277 | - $joindre = true; |
|
| 2278 | - } else { |
|
| 2279 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2280 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2281 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2282 | - $joindre = true; |
|
| 2283 | - } |
|
| 2284 | - } |
|
| 2285 | - } |
|
| 2286 | - if (!$joindre) { |
|
| 2287 | - return $t; |
|
| 2288 | - } |
|
| 2289 | - } |
|
| 2290 | - array_pop($arrivee); |
|
| 2291 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2292 | - return $res; |
|
| 2293 | - } |
|
| 2294 | - } |
|
| 2295 | - } |
|
| 2296 | - |
|
| 2297 | - return ''; |
|
| 2248 | + // si on demande un truc du genre spip_mots |
|
| 2249 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2250 | + // et qu'on est la |
|
| 2251 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2252 | + if ($checkarrivee |
|
| 2253 | + and is_string($checkarrivee) |
|
| 2254 | + and $a = table_objet($checkarrivee) |
|
| 2255 | + and in_array($a . '_liens', $joints) |
|
| 2256 | + ) { |
|
| 2257 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2258 | + return $res; |
|
| 2259 | + } |
|
| 2260 | + } |
|
| 2261 | + foreach ($joints as $joint) { |
|
| 2262 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2263 | + // alias de table dans le from |
|
| 2264 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2265 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2266 | + $cols = $arrivee[2]; |
|
| 2267 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2268 | + if (count($cols) > 2) { |
|
| 2269 | + array_pop($cols); |
|
| 2270 | + } |
|
| 2271 | + if ($t) { |
|
| 2272 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2273 | + $joindre = false; |
|
| 2274 | + foreach ($cols as $col) { |
|
| 2275 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2276 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2277 | + $joindre = true; |
|
| 2278 | + } else { |
|
| 2279 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2280 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2281 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2282 | + $joindre = true; |
|
| 2283 | + } |
|
| 2284 | + } |
|
| 2285 | + } |
|
| 2286 | + if (!$joindre) { |
|
| 2287 | + return $t; |
|
| 2288 | + } |
|
| 2289 | + } |
|
| 2290 | + array_pop($arrivee); |
|
| 2291 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2292 | + return $res; |
|
| 2293 | + } |
|
| 2294 | + } |
|
| 2295 | + } |
|
| 2296 | + |
|
| 2297 | + return ''; |
|
| 2298 | 2298 | |
| 2299 | 2299 | } |
| 2300 | 2300 | |
@@ -2321,29 +2321,29 @@ discard block |
||
| 2321 | 2321 | * Alias de la table de jointure (Lx) |
| 2322 | 2322 | */ |
| 2323 | 2323 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2324 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2325 | - |
|
| 2326 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2327 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2328 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2329 | - |
|
| 2330 | - if (!$intermediaire or !$arrivee) { |
|
| 2331 | - return ''; |
|
| 2332 | - } |
|
| 2333 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2334 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2335 | - |
|
| 2336 | - $res = fabrique_jointures($boucle, |
|
| 2337 | - array( |
|
| 2338 | - array( |
|
| 2339 | - $boucle->id_table, |
|
| 2340 | - $intermediaire, |
|
| 2341 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2342 | - ), |
|
| 2343 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2344 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2345 | - |
|
| 2346 | - return $res; |
|
| 2324 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2325 | + |
|
| 2326 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2327 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2328 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2329 | + |
|
| 2330 | + if (!$intermediaire or !$arrivee) { |
|
| 2331 | + return ''; |
|
| 2332 | + } |
|
| 2333 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2334 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2335 | + |
|
| 2336 | + $res = fabrique_jointures($boucle, |
|
| 2337 | + array( |
|
| 2338 | + array( |
|
| 2339 | + $boucle->id_table, |
|
| 2340 | + $intermediaire, |
|
| 2341 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2342 | + ), |
|
| 2343 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2344 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2345 | + |
|
| 2346 | + return $res; |
|
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 2349 | 2349 | |
@@ -2360,17 +2360,17 @@ discard block |
||
| 2360 | 2360 | * false sinon. |
| 2361 | 2361 | **/ |
| 2362 | 2362 | function trouver_champ($champ, $where) { |
| 2363 | - if (!is_array($where)) { |
|
| 2364 | - return preg_match($champ, $where); |
|
| 2365 | - } else { |
|
| 2366 | - foreach ($where as $clause) { |
|
| 2367 | - if (trouver_champ($champ, $clause)) { |
|
| 2368 | - return true; |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - return false; |
|
| 2373 | - } |
|
| 2363 | + if (!is_array($where)) { |
|
| 2364 | + return preg_match($champ, $where); |
|
| 2365 | + } else { |
|
| 2366 | + foreach ($where as $clause) { |
|
| 2367 | + if (trouver_champ($champ, $clause)) { |
|
| 2368 | + return true; |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + return false; |
|
| 2373 | + } |
|
| 2374 | 2374 | } |
| 2375 | 2375 | |
| 2376 | 2376 | |
@@ -2396,129 +2396,129 @@ discard block |
||
| 2396 | 2396 | * - string $args_sql Suite des arguments du critère. ? |
| 2397 | 2397 | **/ |
| 2398 | 2398 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2399 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2400 | - if (count($crit->param) == 0) { |
|
| 2401 | - $op = '='; |
|
| 2402 | - $col = $val = $crit->op; |
|
| 2403 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2404 | - $val = $r[2]; |
|
| 2405 | - } |
|
| 2406 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2407 | - if ($val == 'lang') { |
|
| 2408 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2409 | - } else { |
|
| 2410 | - $defaut = null; |
|
| 2411 | - if ($val == 'id_parent') { |
|
| 2412 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2413 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2414 | - // pour eviter l'erreur SQL |
|
| 2415 | - $val = $boucles[$idb]->primary; |
|
| 2416 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2417 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2418 | - } elseif ($val == 'id_enfant') { |
|
| 2419 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2420 | - // de la boucle superieure |
|
| 2421 | - $val = 'id_parent'; |
|
| 2422 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2423 | - // un critere conditionnel sur date est traite a part |
|
| 2424 | - // car la date est mise d'office par SPIP, |
|
| 2425 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2426 | - } |
|
| 2427 | - |
|
| 2428 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2429 | - $val = array(kwote($val)); |
|
| 2430 | - } |
|
| 2431 | - } else { |
|
| 2432 | - // comparaison explicite |
|
| 2433 | - // le phraseur impose que le premier param soit du texte |
|
| 2434 | - $params = $crit->param; |
|
| 2435 | - $op = $crit->op; |
|
| 2436 | - if ($op == '==') { |
|
| 2437 | - $op = 'REGEXP'; |
|
| 2438 | - } |
|
| 2439 | - $col = array_shift($params); |
|
| 2440 | - $col = $col[0]->texte; |
|
| 2441 | - |
|
| 2442 | - $val = array(); |
|
| 2443 | - $desc = array('id_mere' => $idb); |
|
| 2444 | - $parent = $boucles[$idb]->id_parent; |
|
| 2445 | - |
|
| 2446 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2447 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2448 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2449 | - if (count($params) == 1 |
|
| 2450 | - and count($params[0]) == 3 |
|
| 2451 | - and $params[0][0]->type == 'texte' |
|
| 2452 | - and $params[0][2]->type == 'texte' |
|
| 2453 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2454 | - and (($p == "'") or ($p == '"')) |
|
| 2455 | - and $params[0][1]->type == 'champ' |
|
| 2456 | - ) { |
|
| 2457 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2458 | - } else { |
|
| 2459 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2460 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2461 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2462 | - $val[] = $a; |
|
| 2463 | - } else { |
|
| 2464 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2465 | - } // toujours quoter en char ici |
|
| 2466 | - } |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - $fct = $args_sql = ''; |
|
| 2471 | - // fonction SQL ? |
|
| 2472 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2473 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2474 | - $fct = $m[1]; |
|
| 2475 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2476 | - $col = $a[1]; |
|
| 2477 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2478 | - $col = $m[1]; |
|
| 2479 | - $args_sql = $m[2]; |
|
| 2480 | - } |
|
| 2481 | - $args_sql .= $a[2]; |
|
| 2482 | - } |
|
| 2483 | - |
|
| 2484 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2399 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2400 | + if (count($crit->param) == 0) { |
|
| 2401 | + $op = '='; |
|
| 2402 | + $col = $val = $crit->op; |
|
| 2403 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2404 | + $val = $r[2]; |
|
| 2405 | + } |
|
| 2406 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2407 | + if ($val == 'lang') { |
|
| 2408 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2409 | + } else { |
|
| 2410 | + $defaut = null; |
|
| 2411 | + if ($val == 'id_parent') { |
|
| 2412 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2413 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2414 | + // pour eviter l'erreur SQL |
|
| 2415 | + $val = $boucles[$idb]->primary; |
|
| 2416 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2417 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2418 | + } elseif ($val == 'id_enfant') { |
|
| 2419 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2420 | + // de la boucle superieure |
|
| 2421 | + $val = 'id_parent'; |
|
| 2422 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2423 | + // un critere conditionnel sur date est traite a part |
|
| 2424 | + // car la date est mise d'office par SPIP, |
|
| 2425 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2426 | + } |
|
| 2427 | + |
|
| 2428 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2429 | + $val = array(kwote($val)); |
|
| 2430 | + } |
|
| 2431 | + } else { |
|
| 2432 | + // comparaison explicite |
|
| 2433 | + // le phraseur impose que le premier param soit du texte |
|
| 2434 | + $params = $crit->param; |
|
| 2435 | + $op = $crit->op; |
|
| 2436 | + if ($op == '==') { |
|
| 2437 | + $op = 'REGEXP'; |
|
| 2438 | + } |
|
| 2439 | + $col = array_shift($params); |
|
| 2440 | + $col = $col[0]->texte; |
|
| 2441 | + |
|
| 2442 | + $val = array(); |
|
| 2443 | + $desc = array('id_mere' => $idb); |
|
| 2444 | + $parent = $boucles[$idb]->id_parent; |
|
| 2445 | + |
|
| 2446 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2447 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2448 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2449 | + if (count($params) == 1 |
|
| 2450 | + and count($params[0]) == 3 |
|
| 2451 | + and $params[0][0]->type == 'texte' |
|
| 2452 | + and $params[0][2]->type == 'texte' |
|
| 2453 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2454 | + and (($p == "'") or ($p == '"')) |
|
| 2455 | + and $params[0][1]->type == 'champ' |
|
| 2456 | + ) { |
|
| 2457 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2458 | + } else { |
|
| 2459 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2460 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2461 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2462 | + $val[] = $a; |
|
| 2463 | + } else { |
|
| 2464 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2465 | + } // toujours quoter en char ici |
|
| 2466 | + } |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + $fct = $args_sql = ''; |
|
| 2471 | + // fonction SQL ? |
|
| 2472 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2473 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2474 | + $fct = $m[1]; |
|
| 2475 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2476 | + $col = $a[1]; |
|
| 2477 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2478 | + $col = $m[1]; |
|
| 2479 | + $args_sql = $m[2]; |
|
| 2480 | + } |
|
| 2481 | + $args_sql .= $a[2]; |
|
| 2482 | + } |
|
| 2483 | + |
|
| 2484 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2485 | 2485 | } |
| 2486 | 2486 | |
| 2487 | 2487 | // compatibilite ancienne version |
| 2488 | 2488 | |
| 2489 | 2489 | // http://code.spip.net/@calculer_vieux_in |
| 2490 | 2490 | function calculer_vieux_in($params) { |
| 2491 | - $deb = $params[0][0]; |
|
| 2492 | - $k = count($params) - 1; |
|
| 2493 | - $last = $params[$k]; |
|
| 2494 | - $j = count($last) - 1; |
|
| 2495 | - $last = $last[$j]; |
|
| 2496 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2497 | - |
|
| 2498 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2499 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2500 | - ) { |
|
| 2501 | - return $params; |
|
| 2502 | - } |
|
| 2503 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2504 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2505 | - $last = $params[$k][$j]; |
|
| 2506 | - $n = strlen($last->texte); |
|
| 2507 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2508 | - $newp = array(); |
|
| 2509 | - foreach ($params as $v) { |
|
| 2510 | - if ($v[0]->type != 'texte') { |
|
| 2511 | - $newp[] = $v; |
|
| 2512 | - } else { |
|
| 2513 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2514 | - $t = new Texte; |
|
| 2515 | - $t->texte = $x; |
|
| 2516 | - $newp[] = array($t); |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - return $newp; |
|
| 2491 | + $deb = $params[0][0]; |
|
| 2492 | + $k = count($params) - 1; |
|
| 2493 | + $last = $params[$k]; |
|
| 2494 | + $j = count($last) - 1; |
|
| 2495 | + $last = $last[$j]; |
|
| 2496 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2497 | + |
|
| 2498 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2499 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2500 | + ) { |
|
| 2501 | + return $params; |
|
| 2502 | + } |
|
| 2503 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2504 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2505 | + $last = $params[$k][$j]; |
|
| 2506 | + $n = strlen($last->texte); |
|
| 2507 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2508 | + $newp = array(); |
|
| 2509 | + foreach ($params as $v) { |
|
| 2510 | + if ($v[0]->type != 'texte') { |
|
| 2511 | + $newp[] = $v; |
|
| 2512 | + } else { |
|
| 2513 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2514 | + $t = new Texte; |
|
| 2515 | + $t->texte = $x; |
|
| 2516 | + $newp[] = array($t); |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + return $newp; |
|
| 2522 | 2522 | } |
| 2523 | 2523 | |
| 2524 | 2524 | /** |
@@ -2537,89 +2537,89 @@ discard block |
||
| 2537 | 2537 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2538 | 2538 | **/ |
| 2539 | 2539 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2540 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2541 | - return ''; |
|
| 2542 | - } |
|
| 2543 | - |
|
| 2544 | - $boucle = $boucles[$idb]; |
|
| 2545 | - $table = $boucle->show; |
|
| 2546 | - |
|
| 2547 | - // si c'est une colonne de la table, ne rien faire |
|
| 2548 | - if (isset($table['field'][$col])) { |
|
| 2549 | - return ''; |
|
| 2550 | - } |
|
| 2551 | - |
|
| 2552 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2553 | - return ''; |
|
| 2554 | - } |
|
| 2555 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2556 | - |
|
| 2557 | - $col = $regs[1]; |
|
| 2558 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2559 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2560 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2561 | - |
|
| 2562 | - if (isset($table['field']["date$suite"])) { |
|
| 2563 | - $date_orig = 'date' . $suite; |
|
| 2564 | - } else { |
|
| 2565 | - $date_orig = substr($suite, 1); |
|
| 2566 | - } |
|
| 2567 | - $pred = $date_orig; |
|
| 2568 | - } else { |
|
| 2569 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2570 | - $pred = 'date'; |
|
| 2571 | - } |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2576 | - ") . '\""; |
|
| 2577 | - |
|
| 2578 | - $col_vraie = $date_orig; |
|
| 2579 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2580 | - |
|
| 2581 | - switch ($col) { |
|
| 2582 | - case 'date': |
|
| 2583 | - $col = $date_orig; |
|
| 2584 | - break; |
|
| 2585 | - case 'jour': |
|
| 2586 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2587 | - break; |
|
| 2588 | - case 'mois': |
|
| 2589 | - $col = "MONTH($date_orig)"; |
|
| 2590 | - break; |
|
| 2591 | - case 'annee': |
|
| 2592 | - $col = "YEAR($date_orig)"; |
|
| 2593 | - break; |
|
| 2594 | - case 'heure': |
|
| 2595 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2596 | - break; |
|
| 2597 | - case 'age': |
|
| 2598 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2599 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2600 | - break; |
|
| 2601 | - case 'age_relatif': |
|
| 2602 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2603 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2604 | - break; |
|
| 2605 | - case 'jour_relatif': |
|
| 2606 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2608 | - break; |
|
| 2609 | - case 'mois_relatif': |
|
| 2610 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2611 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2612 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2613 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2614 | - break; |
|
| 2615 | - case 'annee_relatif': |
|
| 2616 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | - $date_orig . ")"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | - break; |
|
| 2620 | - } |
|
| 2621 | - |
|
| 2622 | - return array($col, $col_vraie); |
|
| 2540 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2541 | + return ''; |
|
| 2542 | + } |
|
| 2543 | + |
|
| 2544 | + $boucle = $boucles[$idb]; |
|
| 2545 | + $table = $boucle->show; |
|
| 2546 | + |
|
| 2547 | + // si c'est une colonne de la table, ne rien faire |
|
| 2548 | + if (isset($table['field'][$col])) { |
|
| 2549 | + return ''; |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2553 | + return ''; |
|
| 2554 | + } |
|
| 2555 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2556 | + |
|
| 2557 | + $col = $regs[1]; |
|
| 2558 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2559 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2560 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2561 | + |
|
| 2562 | + if (isset($table['field']["date$suite"])) { |
|
| 2563 | + $date_orig = 'date' . $suite; |
|
| 2564 | + } else { |
|
| 2565 | + $date_orig = substr($suite, 1); |
|
| 2566 | + } |
|
| 2567 | + $pred = $date_orig; |
|
| 2568 | + } else { |
|
| 2569 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2570 | + $pred = 'date'; |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2576 | + ") . '\""; |
|
| 2577 | + |
|
| 2578 | + $col_vraie = $date_orig; |
|
| 2579 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2580 | + |
|
| 2581 | + switch ($col) { |
|
| 2582 | + case 'date': |
|
| 2583 | + $col = $date_orig; |
|
| 2584 | + break; |
|
| 2585 | + case 'jour': |
|
| 2586 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2587 | + break; |
|
| 2588 | + case 'mois': |
|
| 2589 | + $col = "MONTH($date_orig)"; |
|
| 2590 | + break; |
|
| 2591 | + case 'annee': |
|
| 2592 | + $col = "YEAR($date_orig)"; |
|
| 2593 | + break; |
|
| 2594 | + case 'heure': |
|
| 2595 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2596 | + break; |
|
| 2597 | + case 'age': |
|
| 2598 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2599 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2600 | + break; |
|
| 2601 | + case 'age_relatif': |
|
| 2602 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2603 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2604 | + break; |
|
| 2605 | + case 'jour_relatif': |
|
| 2606 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2608 | + break; |
|
| 2609 | + case 'mois_relatif': |
|
| 2610 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2611 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2612 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2613 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2614 | + break; |
|
| 2615 | + case 'annee_relatif': |
|
| 2616 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | + $date_orig . ")"; |
|
| 2618 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | + break; |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + return array($col, $col_vraie); |
|
| 2623 | 2623 | } |
| 2624 | 2624 | |
| 2625 | 2625 | /** |
@@ -2638,16 +2638,16 @@ discard block |
||
| 2638 | 2638 | * de colonne SQL et une date. |
| 2639 | 2639 | **/ |
| 2640 | 2640 | function calculer_param_date($date_compare, $date_orig) { |
| 2641 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2642 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2643 | - $date_compare = '\'$x\''; |
|
| 2644 | - } else { |
|
| 2645 | - $init = $date_compare; |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - return |
|
| 2649 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2650 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2641 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2642 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2643 | + $date_compare = '\'$x\''; |
|
| 2644 | + } else { |
|
| 2645 | + $init = $date_compare; |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + return |
|
| 2649 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2650 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2651 | 2651 | } |
| 2652 | 2652 | |
| 2653 | 2653 | /** |
@@ -2665,18 +2665,18 @@ discard block |
||
| 2665 | 2665 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2666 | 2666 | */ |
| 2667 | 2667 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2668 | - $boucle = &$boucles[$idb]; |
|
| 2668 | + $boucle = &$boucles[$idb]; |
|
| 2669 | 2669 | |
| 2670 | - $args = array(); |
|
| 2671 | - foreach ($crit->param as &$param) { |
|
| 2672 | - array_push($args, |
|
| 2673 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2674 | - } |
|
| 2670 | + $args = array(); |
|
| 2671 | + foreach ($crit->param as &$param) { |
|
| 2672 | + array_push($args, |
|
| 2673 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2674 | + } |
|
| 2675 | 2675 | |
| 2676 | - $boucle->hash .= ' |
|
| 2676 | + $boucle->hash .= ' |
|
| 2677 | 2677 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2678 | 2678 | |
| 2679 | - $boucle->hash .= ' |
|
| 2679 | + $boucle->hash .= ' |
|
| 2680 | 2680 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2681 | 2681 | } |
| 2682 | 2682 | |
@@ -2693,8 +2693,8 @@ discard block |
||
| 2693 | 2693 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2694 | 2694 | */ |
| 2695 | 2695 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2696 | - $boucle = &$boucles[$idb]; |
|
| 2697 | - $boucle->hash .= ' |
|
| 2696 | + $boucle = &$boucles[$idb]; |
|
| 2697 | + $boucle->hash .= ' |
|
| 2698 | 2698 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2699 | 2699 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2700 | 2700 | } |
@@ -2714,8 +2714,8 @@ discard block |
||
| 2714 | 2714 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2715 | 2715 | */ |
| 2716 | 2716 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2717 | - $boucle = &$boucles[$idb]; |
|
| 2718 | - $boucle->hash .= ' |
|
| 2717 | + $boucle = &$boucles[$idb]; |
|
| 2718 | + $boucle->hash .= ' |
|
| 2719 | 2719 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2720 | 2720 | } |
| 2721 | 2721 | |
@@ -2731,12 +2731,12 @@ discard block |
||
| 2731 | 2731 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2732 | 2732 | */ |
| 2733 | 2733 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2734 | - $boucle = &$boucles[$idb]; |
|
| 2735 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2736 | - foreach ($crit->param as $param) { |
|
| 2737 | - $boucle->hash .= ' |
|
| 2734 | + $boucle = &$boucles[$idb]; |
|
| 2735 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2736 | + foreach ($crit->param as $param) { |
|
| 2737 | + $boucle->hash .= ' |
|
| 2738 | 2738 | $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2739 | - } |
|
| 2739 | + } |
|
| 2740 | 2740 | } |
| 2741 | 2741 | |
| 2742 | 2742 | /** |
@@ -2753,12 +2753,12 @@ discard block |
||
| 2753 | 2753 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2754 | 2754 | */ |
| 2755 | 2755 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2756 | - $boucle = &$boucles[$idb]; |
|
| 2757 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2758 | - foreach ($crit->param as $param) { |
|
| 2759 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2761 | - } |
|
| 2756 | + $boucle = &$boucles[$idb]; |
|
| 2757 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2758 | + foreach ($crit->param as $param) { |
|
| 2759 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2761 | + } |
|
| 2762 | 2762 | } |
| 2763 | 2763 | |
| 2764 | 2764 | /** |
@@ -2783,12 +2783,12 @@ discard block |
||
| 2783 | 2783 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2784 | 2784 | */ |
| 2785 | 2785 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2786 | - $boucle = &$boucles[$idb]; |
|
| 2787 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2788 | - foreach ($crit->param as $param) { |
|
| 2789 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2791 | - } |
|
| 2786 | + $boucle = &$boucles[$idb]; |
|
| 2787 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2788 | + foreach ($crit->param as $param) { |
|
| 2789 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2791 | + } |
|
| 2792 | 2792 | } |
| 2793 | 2793 | |
| 2794 | 2794 | /** |
@@ -2803,11 +2803,11 @@ discard block |
||
| 2803 | 2803 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2804 | 2804 | */ |
| 2805 | 2805 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2806 | - $boucle = &$boucles[$idb]; |
|
| 2807 | - foreach ($crit->param as $param) { |
|
| 2808 | - $boucle->hash .= ' |
|
| 2806 | + $boucle = &$boucles[$idb]; |
|
| 2807 | + foreach ($crit->param as $param) { |
|
| 2808 | + $boucle->hash .= ' |
|
| 2809 | 2809 | $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2810 | - } |
|
| 2810 | + } |
|
| 2811 | 2811 | } |
| 2812 | 2812 | |
| 2813 | 2813 | |
@@ -2839,20 +2839,20 @@ discard block |
||
| 2839 | 2839 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2840 | 2840 | */ |
| 2841 | 2841 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2842 | - $boucle = &$boucles[$idb]; |
|
| 2843 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2844 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2845 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2846 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2847 | - if ($crit->param) { |
|
| 2848 | - foreach ($crit->param as $param) { |
|
| 2849 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2850 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2851 | - } |
|
| 2852 | - // interdire {si 0} aussi ! |
|
| 2853 | - } else { |
|
| 2854 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2855 | - } |
|
| 2842 | + $boucle = &$boucles[$idb]; |
|
| 2843 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2844 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2845 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2846 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2847 | + if ($crit->param) { |
|
| 2848 | + foreach ($crit->param as $param) { |
|
| 2849 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2850 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2851 | + } |
|
| 2852 | + // interdire {si 0} aussi ! |
|
| 2853 | + } else { |
|
| 2854 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2855 | + } |
|
| 2856 | 2856 | } |
| 2857 | 2857 | |
| 2858 | 2858 | /** |
@@ -2868,8 +2868,8 @@ discard block |
||
| 2868 | 2868 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2869 | 2869 | */ |
| 2870 | 2870 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2871 | - $boucle = &$boucles[$idb]; |
|
| 2872 | - $boucle->hash .= ' |
|
| 2871 | + $boucle = &$boucles[$idb]; |
|
| 2872 | + $boucle->hash .= ' |
|
| 2873 | 2873 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2874 | 2874 | $command[\'sourcemode\'] = \'table\';'; |
| 2875 | 2875 | } |
@@ -2890,29 +2890,29 @@ discard block |
||
| 2890 | 2890 | */ |
| 2891 | 2891 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2892 | 2892 | |
| 2893 | - $not = $crit->not; |
|
| 2894 | - $boucle = &$boucles[$idb]; |
|
| 2895 | - $primary = $boucle->primary; |
|
| 2893 | + $not = $crit->not; |
|
| 2894 | + $boucle = &$boucles[$idb]; |
|
| 2895 | + $primary = $boucle->primary; |
|
| 2896 | 2896 | |
| 2897 | - if (!$primary or strpos($primary, ',')) { |
|
| 2898 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2897 | + if (!$primary or strpos($primary, ',')) { |
|
| 2898 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2899 | 2899 | |
| 2900 | - return; |
|
| 2901 | - } |
|
| 2902 | - $table = $boucle->type_requete; |
|
| 2903 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2900 | + return; |
|
| 2901 | + } |
|
| 2902 | + $table = $boucle->type_requete; |
|
| 2903 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2904 | 2904 | |
| 2905 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2906 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | - 'id_parent'; |
|
| 2905 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2906 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | + 'id_parent'; |
|
| 2908 | 2908 | |
| 2909 | - $in = "IN"; |
|
| 2910 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | - if ($not) { |
|
| 2912 | - $where = array("'NOT'", $where); |
|
| 2913 | - } |
|
| 2909 | + $in = "IN"; |
|
| 2910 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | + if ($not) { |
|
| 2912 | + $where = array("'NOT'", $where); |
|
| 2913 | + } |
|
| 2914 | 2914 | |
| 2915 | - $boucle->where[] = $where; |
|
| 2915 | + $boucle->where[] = $where; |
|
| 2916 | 2916 | } |
| 2917 | 2917 | |
| 2918 | 2918 | /** |
@@ -2928,8 +2928,8 @@ discard block |
||
| 2928 | 2928 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2929 | 2929 | */ |
| 2930 | 2930 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2931 | - $not = $crit->not; |
|
| 2932 | - $crit->not = $not ? false : true; |
|
| 2933 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2934 | - $crit->not = $not; |
|
| 2931 | + $not = $crit->not; |
|
| 2932 | + $crit->not = $not ? false : true; |
|
| 2933 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2934 | + $crit->not = $not; |
|
| 2935 | 2935 | } |
@@ -46,10 +46,9 @@ discard block |
||
| 46 | 46 | $not = $crit->not; |
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 51 | 50 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 51 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -72,10 +71,10 @@ discard block |
||
| 72 | 71 | $id = $boucle->primary; |
| 73 | 72 | |
| 74 | 73 | if ($not or !$id) { |
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 74 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 77 | + $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
@@ -106,12 +105,12 @@ discard block |
||
| 106 | 105 | $not = ($crit->not ? '' : 'NOT'); |
| 107 | 106 | |
| 108 | 107 | // le doublon s'applique sur un type de boucle (article) |
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + $nom = "'".$boucle->type_requete."'"; |
|
| 110 | 109 | |
| 111 | 110 | // compléter le nom avec un nom précisé {doublons nom} |
| 112 | 111 | // on obtient $nom = "'article' . 'nom'" |
| 113 | 112 | if (isset($crit->param[0])) { |
| 114 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= ".".calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | // $doublons et son index, ici $nom |
| 124 | 123 | |
| 125 | 124 | // debut du code "sql_in('articles.id_article', " |
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 127 | 126 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 128 | 127 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 128 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 130 | 129 | |
| 131 | 130 | // le debut complet du code des doublons |
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + $debut_doub = $debut_in.$debut_doub; |
|
| 133 | 132 | |
| 134 | 133 | // nom du doublon "('article' . 'nom')]" |
| 135 | 134 | $fin_doub = "($nom)]"; |
@@ -139,22 +138,22 @@ discard block |
||
| 139 | 138 | foreach ($boucle->where as $k => $w) { |
| 140 | 139 | if (strpos($w[0], $debut_doub) === 0) { |
| 141 | 140 | // fusionner le sql_in (du where) |
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 143 | 142 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 144 | 143 | $x = strpos($boucle->hash, $init_comment); |
| 145 | 144 | $len = strlen($init_comment); |
| 146 | 145 | $boucle->hash = |
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 148 | 147 | |
| 149 | 148 | return; |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 153 | + $boucle->where[] = array($debut_doub.$fin_doub.", '".$not."')"); |
|
| 155 | 154 | |
| 156 | 155 | // déclarer le doublon s'il n'existe pas encore |
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + $boucle->hash .= $init_comment.$init_code; |
|
| 158 | 157 | |
| 159 | 158 | |
| 160 | 159 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | $un = $un[0]->texte; |
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 217 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 218 | + $un. |
|
| 219 | + '"]) . ",'. |
|
| 220 | + $deux. |
|
| 222 | 221 | '"'; |
| 223 | 222 | } else { |
| 224 | 223 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
@@ -281,26 +280,26 @@ discard block |
||
| 281 | 280 | $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 285 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 286 | 285 | $partie = |
| 287 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 289 | 288 | . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 292 | 291 | . "\t}\n" |
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->hash .= ' |
| 296 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 297 | 296 | |
| 298 | 297 | $boucle->total_parties = $pas; |
| 299 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 300 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 301 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 302 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 304 | 303 | if ($boucle->primary |
| 305 | 304 | and !preg_match('/[,\s]/', $boucle->primary) |
| 306 | 305 | and !in_array($t, $boucle->select) |
@@ -346,24 +345,24 @@ discard block |
||
| 346 | 345 | $boucle->hash .= ' |
| 347 | 346 | // RECHERCHE' |
| 348 | 347 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 348 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 349 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 350 | + } else' : '').' |
|
| 352 | 351 | { |
| 353 | 352 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 354 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 353 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 354 | } |
| 356 | 355 | '; |
| 357 | 356 | |
| 358 | 357 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 359 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 360 | $boucle->select[] = $t; |
| 362 | 361 | } # pour postgres, neuneu ici |
| 363 | 362 | // jointure uniquement sur le serveur principal |
| 364 | 363 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 364 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 365 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 367 | 366 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 367 | } |
| 369 | 368 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | $c = |
| 431 | 430 | array( |
| 432 | 431 | "'OR'", |
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 432 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 434 | 433 | array("'='", "'$table.id_trad'", "'0'") |
| 435 | 434 | ); |
| 436 | 435 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
@@ -453,16 +452,15 @@ discard block |
||
| 453 | 452 | $boucle = &$boucles[$idb]; |
| 454 | 453 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 454 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 455 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 459 | 457 | |
| 460 | 458 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 461 | 459 | $boucle->where[] = array("'='", "'$mparent'", $arg); |
| 462 | 460 | |
| 463 | 461 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 464 | 462 | else { |
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 463 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |
@@ -515,16 +513,15 @@ discard block |
||
| 515 | 513 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 516 | 514 | $decompose = decompose_champ_id_objet($champ); |
| 517 | 515 | $champ = array_shift($decompose); |
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 516 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 519 | 517 | } |
| 520 | 518 | } else { |
| 521 | 519 | $cle = $boucle->id_table; |
| 522 | 520 | } |
| 523 | 521 | |
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 522 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 523 | + . ($not ? ", 'NOT'" : '').")"; |
|
| 524 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | /** |
@@ -544,9 +541,9 @@ discard block |
||
| 544 | 541 | $not = ($crit->not ? 'NOT' : ''); |
| 545 | 542 | $serveur = $boucle->sql_serveur; |
| 546 | 543 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('". |
|
| 545 | + $boucle->id_table.'.'.$boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 550 | 547 | |
| 551 | 548 | $boucle->where[] = $c; |
| 552 | 549 | } |
@@ -578,7 +575,7 @@ discard block |
||
| 578 | 575 | $t = table_objet_sql($r[1]); |
| 579 | 576 | $t = array_search($t, $boucles[$idb]->from); |
| 580 | 577 | if ($t) { |
| 581 | - $t .= '.' . $r[2]; |
|
| 578 | + $t .= '.'.$r[2]; |
|
| 582 | 579 | } |
| 583 | 580 | } |
| 584 | 581 | } else { |
@@ -593,7 +590,7 @@ discard block |
||
| 593 | 590 | $boucles[$idb]->select[] = $t; |
| 594 | 591 | } |
| 595 | 592 | } else { |
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 597 | 594 | } |
| 598 | 595 | } |
| 599 | 596 | |
@@ -643,26 +640,26 @@ discard block |
||
| 643 | 640 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 644 | 641 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 645 | 642 | ) { |
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 643 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 647 | 644 | } else { |
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 645 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 649 | 646 | } |
| 650 | 647 | } |
| 651 | 648 | } else { |
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 649 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 653 | 650 | } |
| 654 | 651 | } |
| 655 | 652 | |
| 656 | 653 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 654 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | 655 | $boucle = $boucles[$idb]; |
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 656 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 657 | + $var = '$champs_'.$idb; |
|
| 661 | 658 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 662 | 659 | if (!$desc) { |
| 663 | 660 | $desc = $boucle->show['field']; |
| 664 | 661 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 662 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 666 | 663 | } |
| 667 | 664 | if ($desc) { |
| 668 | 665 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -737,7 +734,7 @@ discard block |
||
| 737 | 734 | $sens = " . ' DESC'"; |
| 738 | 735 | } |
| 739 | 736 | if (isset($boucle->modificateur['collate'])) { |
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 737 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 741 | 738 | } |
| 742 | 739 | |
| 743 | 740 | // Pour chaque paramètre du critère |
@@ -759,14 +756,14 @@ discard block |
||
| 759 | 756 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 760 | 757 | $expression = trim($m[1]); |
| 761 | 758 | $champ = trim($m[2]); |
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 759 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 763 | 760 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 764 | 761 | } else { |
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 762 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 766 | 763 | } |
| 767 | 764 | |
| 768 | 765 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 766 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 770 | 767 | // {par FONCTION(champ)} |
| 771 | 768 | if (count($match) > 2) { |
| 772 | 769 | $par = substr($match[2], 1, -1); |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | if ($par == 'hasard') { |
| 777 | 774 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 778 | 775 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 776 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 780 | 777 | } else { |
| 781 | 778 | // cas général {par champ}, {par table.champ}, ... |
| 782 | 779 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -785,7 +782,7 @@ discard block |
||
| 785 | 782 | |
| 786 | 783 | // on ne sait pas traiter… |
| 787 | 784 | else { |
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 785 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 789 | 786 | } |
| 790 | 787 | |
| 791 | 788 | // En cas d'erreur de squelette retournée par une fonction |
@@ -805,14 +802,14 @@ discard block |
||
| 805 | 802 | |
| 806 | 803 | if ($fct) { |
| 807 | 804 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 805 | + $order = "'$fct(".$r[1].")'"; |
|
| 809 | 806 | } else { |
| 810 | 807 | $order = "'$fct(' . $order . ')'"; |
| 811 | 808 | } |
| 812 | 809 | } |
| 813 | - $t = $order . $collecte . $sens; |
|
| 810 | + $t = $order.$collecte.$sens; |
|
| 814 | 811 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 815 | - $t = $r[1] . $r[2]; |
|
| 812 | + $t = $r[1].$r[2]; |
|
| 816 | 813 | } |
| 817 | 814 | |
| 818 | 815 | $boucle->order[] = $t; |
@@ -862,16 +859,16 @@ discard block |
||
| 862 | 859 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | 860 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 864 | 861 | if (is_array($_champ)) { |
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 862 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 866 | 863 | } |
| 867 | 864 | $boucle = &$boucles[$idb]; |
| 868 | - $texte = '0+' . $_champ; |
|
| 865 | + $texte = '0+'.$_champ; |
|
| 869 | 866 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 870 | 867 | if ($suite !== "''") { |
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 868 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 872 | 869 | } |
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 870 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 871 | + $boucle->select[] = $texte." AS $as"; |
|
| 875 | 872 | $order = "'$as'"; |
| 876 | 873 | return $order; |
| 877 | 874 | } |
@@ -896,16 +893,16 @@ discard block |
||
| 896 | 893 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | 894 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 898 | 895 | if (is_array($_champ)) { |
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 896 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 900 | 897 | } |
| 901 | 898 | $boucle = &$boucles[$idb]; |
| 902 | - $texte = '0+' . $_champ; |
|
| 899 | + $texte = '0+'.$_champ; |
|
| 903 | 900 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 904 | 901 | if ($suite !== "''") { |
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 902 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 906 | 903 | } |
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 904 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 905 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 909 | 906 | $order = "'$as'"; |
| 910 | 907 | return $order; |
| 911 | 908 | } |
@@ -929,10 +926,10 @@ discard block |
||
| 929 | 926 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | 927 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 931 | 928 | if (is_array($_champ)) { |
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 929 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 933 | 930 | } |
| 934 | 931 | $boucle = &$boucles[$idb]; |
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 932 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 936 | 933 | $order = "'multi'"; |
| 937 | 934 | return $order; |
| 938 | 935 | } |
@@ -952,13 +949,13 @@ discard block |
||
| 952 | 949 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 953 | 950 | * @return array|string |
| 954 | 951 | */ |
| 955 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 952 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 956 | 953 | $boucle = &$boucles[$idb]; |
| 957 | 954 | $desc = $boucle->show; |
| 958 | 955 | |
| 959 | 956 | // le champ existe dans la table, pas de souci (le plus commun) |
| 960 | 957 | if (isset($desc['field'][$par])) { |
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 958 | + $par = $boucle->id_table.".".$par; |
|
| 962 | 959 | } |
| 963 | 960 | // le champ est peut être une jointure |
| 964 | 961 | else { |
@@ -979,24 +976,24 @@ discard block |
||
| 979 | 976 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 980 | 977 | // Si la table est déjà dans le from, on la réutilise. |
| 981 | 978 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 979 | + $par = $infos['alias'].".".$champ; |
|
| 983 | 980 | } elseif ( |
| 984 | 981 | $boucle->jointures_explicites |
| 985 | 982 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 986 | 983 | ) { |
| 987 | - $par = $alias . "." . $champ; |
|
| 984 | + $par = $alias.".".$champ; |
|
| 988 | 985 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 989 | - $par = $alias . "." . $champ; |
|
| 986 | + $par = $alias.".".$champ; |
|
| 990 | 987 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 991 | 988 | } elseif ( |
| 992 | 989 | $table_alias |
| 993 | 990 | and isset($boucle->from[$table_alias]) |
| 994 | 991 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 995 | 992 | ) { |
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 993 | + $par = $infos['alias'].".".$champ; |
|
| 997 | 994 | } elseif ($table) { |
| 998 | 995 | // On avait table + champ, mais on ne les a pas trouvés |
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 996 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1000 | 997 | } else { |
| 1001 | 998 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1002 | 999 | } |
@@ -1020,7 +1017,7 @@ discard block |
||
| 1020 | 1017 | if (!$t) { |
| 1021 | 1018 | $t = trouver_jointure_champ($champ, $boucle); |
| 1022 | 1019 | } |
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1020 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1024 | 1021 | } |
| 1025 | 1022 | |
| 1026 | 1023 | /** |
@@ -1065,9 +1062,9 @@ discard block |
||
| 1065 | 1062 | $boucle->default_order[] = ' DESC'; |
| 1066 | 1063 | } |
| 1067 | 1064 | } else { |
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1065 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1069 | 1066 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1067 | + $t = $r[1].$r[2]; |
|
| 1071 | 1068 | } |
| 1072 | 1069 | $boucle->order[$n - 1] = $t; |
| 1073 | 1070 | } |
@@ -1079,7 +1076,7 @@ discard block |
||
| 1079 | 1076 | $params = $crit->param; |
| 1080 | 1077 | |
| 1081 | 1078 | if (count($params) < 1) { |
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1079 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1083 | 1080 | } |
| 1084 | 1081 | |
| 1085 | 1082 | $boucle = &$boucles[$idb]; |
@@ -1100,7 +1097,7 @@ discard block |
||
| 1100 | 1097 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1101 | 1098 | $date = $date[0]->texte; |
| 1102 | 1099 | if (!isset($fields[$date])) { |
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1100 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1104 | 1101 | } |
| 1105 | 1102 | } else { |
| 1106 | 1103 | $a = calculer_liste($date, array(), $boucles, $parent); |
@@ -1112,38 +1109,38 @@ discard block |
||
| 1112 | 1109 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1113 | 1110 | } |
| 1114 | 1111 | $annee = $params ? array_shift($params) : ""; |
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1112 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1113 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 1117 | 1114 | ') ? $x : date("Y"))'; |
| 1118 | 1115 | |
| 1119 | 1116 | $mois = $params ? array_shift($params) : ""; |
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1117 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1118 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 1122 | 1119 | ') ? $x : date("m"))'; |
| 1123 | 1120 | |
| 1124 | 1121 | $jour = $params ? array_shift($params) : ""; |
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1122 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1123 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 1127 | 1124 | ') ? $x : date("d"))'; |
| 1128 | 1125 | |
| 1129 | 1126 | $annee2 = $params ? array_shift($params) : ""; |
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1127 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1128 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 1132 | 1129 | ') ? $x : date("Y"))'; |
| 1133 | 1130 | |
| 1134 | 1131 | $mois2 = $params ? array_shift($params) : ""; |
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1132 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1133 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 1137 | 1134 | ') ? $x : date("m"))'; |
| 1138 | 1135 | |
| 1139 | 1136 | $jour2 = $params ? array_shift($params) : ""; |
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1137 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1138 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 1142 | 1139 | ') ? $x : date("d"))'; |
| 1143 | 1140 | |
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1141 | + $date = $boucle->id_table.".$date"; |
|
| 1145 | 1142 | |
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1143 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1147 | 1144 | if ($type == 'jour') { |
| 1148 | 1145 | $boucle->where[] = array( |
| 1149 | 1146 | "'='", |
@@ -1215,14 +1212,13 @@ discard block |
||
| 1215 | 1212 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1216 | 1213 | |
| 1217 | 1214 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1215 | + $boucle->limit = $a11.','.$a21; |
|
| 1219 | 1216 | } else { |
| 1220 | 1217 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1221 | 1218 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1222 | 1219 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1223 | 1220 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1221 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1226 | 1222 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1227 | 1223 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1228 | 1224 | $boucle->limit = |
@@ -1268,8 +1264,7 @@ discard block |
||
| 1268 | 1264 | // {1/3} |
| 1269 | 1265 | if ($op1 == '/') { |
| 1270 | 1266 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1267 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1273 | 1268 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1274 | 1269 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1275 | 1270 | } else { |
@@ -1280,15 +1275,13 @@ discard block |
||
| 1280 | 1275 | |
| 1281 | 1276 | // cas {x,n-1} |
| 1282 | 1277 | if ($op2 == '-') { |
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1278 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1279 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1286 | 1280 | } else { |
| 1287 | 1281 | // {x,1} ou {pagination} |
| 1288 | 1282 | $fin = '$debut_boucle' |
| 1289 | 1283 | . (is_numeric($total_parties) ? |
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1284 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1292 | 1285 | } |
| 1293 | 1286 | |
| 1294 | 1287 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1306,11 +1299,11 @@ discard block |
||
| 1306 | 1299 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1307 | 1300 | |
| 1308 | 1301 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1302 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1310 | 1303 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1311 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1304 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1305 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1306 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | 1307 | . "\n\tif (\$debut_boucle>0" |
| 1315 | 1308 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1316 | 1309 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1395,16 +1388,16 @@ discard block |
||
| 1395 | 1388 | // critere personnalise ? |
| 1396 | 1389 | if ( |
| 1397 | 1390 | (!$serveur or |
| 1398 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | - and (!function_exists($f = $f . "_dist")) |
|
| 1400 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | - and (!function_exists($f = $f . "_dist")) |
|
| 1391 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1392 | + and (!function_exists($f = $f."_dist")) |
|
| 1393 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1394 | + and (!function_exists($f = $f."_dist")) |
|
| 1402 | 1395 | ) |
| 1403 | 1396 | ) |
| 1404 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1397 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1398 | + and (!function_exists($f = $f."_dist")) |
|
| 1399 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1400 | + and (!function_exists($f = $f."_dist")) |
|
| 1408 | 1401 | ) { |
| 1409 | 1402 | // fonction critere standard |
| 1410 | 1403 | $f = $defaut; |
@@ -1437,9 +1430,9 @@ discard block |
||
| 1437 | 1430 | */ |
| 1438 | 1431 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | 1432 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1433 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1441 | 1434 | } else { |
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1435 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1443 | 1436 | } |
| 1444 | 1437 | } |
| 1445 | 1438 | |
@@ -1461,7 +1454,7 @@ discard block |
||
| 1461 | 1454 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | 1455 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1463 | 1456 | if (!$r) { |
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1457 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1465 | 1458 | } |
| 1466 | 1459 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1467 | 1460 | |
@@ -1488,8 +1481,8 @@ discard block |
||
| 1488 | 1481 | "'NOT'", |
| 1489 | 1482 | array( |
| 1490 | 1483 | "'IN'", |
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1484 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1485 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1493 | 1486 | ) |
| 1494 | 1487 | ); |
| 1495 | 1488 | } |
@@ -1508,22 +1501,22 @@ discard block |
||
| 1508 | 1501 | $descr = $boucles[$idb]->descr; |
| 1509 | 1502 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1510 | 1503 | |
| 1511 | - $var = '$in' . $cpt++; |
|
| 1504 | + $var = '$in'.$cpt++; |
|
| 1512 | 1505 | $x = "\n\t$var = array();"; |
| 1513 | 1506 | foreach ($val as $k => $v) { |
| 1514 | 1507 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1515 | 1508 | // optimiser le traitement des constantes |
| 1516 | 1509 | if (is_numeric($r[2])) { |
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1510 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1518 | 1511 | } else { |
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1512 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1520 | 1513 | } |
| 1521 | 1514 | } else { |
| 1522 | 1515 | // Pour permettre de passer des tableaux de valeurs |
| 1523 | 1516 | // on repere l'utilisation brute de #ENV**{X}, |
| 1524 | 1517 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1525 | 1518 | // et on deballe mais en rajoutant l'anti XSS |
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1519 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | 1520 | } |
| 1528 | 1521 | } |
| 1529 | 1522 | |
@@ -1537,7 +1530,7 @@ discard block |
||
| 1537 | 1530 | $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
| 1538 | 1531 | } |
| 1539 | 1532 | |
| 1540 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1533 | + return "sql_in('$arg',sql_quote($var)".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1541 | 1534 | } |
| 1542 | 1535 | |
| 1543 | 1536 | /** |
@@ -1610,7 +1603,7 @@ discard block |
||
| 1610 | 1603 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1611 | 1604 | } |
| 1612 | 1605 | // nous aider en mode debug. |
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1606 | + $boucle->debug[] = "id_ : ".implode(', ', $champs); |
|
| 1614 | 1607 | $boucle->modificateur['id_'] = $champs; |
| 1615 | 1608 | |
| 1616 | 1609 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1651,7 +1644,7 @@ discard block |
||
| 1651 | 1644 | // Les champs id_xx de la table demandée |
| 1652 | 1645 | $champs = array_filter( |
| 1653 | 1646 | array_keys($desc['field']), |
| 1654 | - function($champ){ |
|
| 1647 | + function($champ) { |
|
| 1655 | 1648 | return |
| 1656 | 1649 | strpos($champ, 'id_') === 0 |
| 1657 | 1650 | or (in_array($champ, array('objet'))); |
@@ -1854,8 +1847,8 @@ discard block |
||
| 1854 | 1847 | "'NOT'", |
| 1855 | 1848 | array( |
| 1856 | 1849 | "'IN'", |
| 1857 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1850 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1851 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1859 | 1852 | ) |
| 1860 | 1853 | ); |
| 1861 | 1854 | } |
@@ -1866,7 +1859,7 @@ discard block |
||
| 1866 | 1859 | if ($crit->cond) { |
| 1867 | 1860 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1868 | 1861 | if ($col == "date" or $col == "date_redac") { |
| 1869 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1862 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1870 | 1863 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1871 | 1864 | } |
| 1872 | 1865 | } |
@@ -2027,7 +2020,7 @@ discard block |
||
| 2027 | 2020 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2028 | 2021 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2029 | 2022 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2030 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2023 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2031 | 2024 | } |
| 2032 | 2025 | // sinon expliciter les |
| 2033 | 2026 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2038,22 +2031,22 @@ discard block |
||
| 2038 | 2031 | // sql_quote(truc,'','varchar') |
| 2039 | 2032 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 2040 | 2033 | // si pas deja un type |
| 2041 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2034 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2042 | 2035 | ) { |
| 2043 | 2036 | $r = $r[1] |
| 2044 | 2037 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2045 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2038 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2046 | 2039 | $val[0] = "sql_quote($r)"; |
| 2047 | 2040 | } |
| 2048 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2041 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | 2042 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2050 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2043 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2051 | 2044 | } |
| 2052 | 2045 | } |
| 2053 | 2046 | |
| 2054 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2047 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | 2048 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2056 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2049 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2057 | 2050 | } |
| 2058 | 2051 | |
| 2059 | 2052 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2078,7 +2071,7 @@ discard block |
||
| 2078 | 2071 | // inserer le nom de la table SQL devant le nom du champ |
| 2079 | 2072 | if ($table) { |
| 2080 | 2073 | if ($col[0] == "`") { |
| 2081 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2074 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2082 | 2075 | } else { |
| 2083 | 2076 | $arg = "$table.$col"; |
| 2084 | 2077 | } |
@@ -2212,9 +2205,9 @@ discard block |
||
| 2212 | 2205 | **/ |
| 2213 | 2206 | function primary_doublee($decompose, $table) { |
| 2214 | 2207 | $e1 = reset($decompose); |
| 2215 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2208 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2216 | 2209 | |
| 2217 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2210 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2218 | 2211 | } |
| 2219 | 2212 | |
| 2220 | 2213 | /** |
@@ -2252,7 +2245,7 @@ discard block |
||
| 2252 | 2245 | if ($checkarrivee |
| 2253 | 2246 | and is_string($checkarrivee) |
| 2254 | 2247 | and $a = table_objet($checkarrivee) |
| 2255 | - and in_array($a . '_liens', $joints) |
|
| 2248 | + and in_array($a.'_liens', $joints) |
|
| 2256 | 2249 | ) { |
| 2257 | 2250 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2258 | 2251 | return $res; |
@@ -2272,12 +2265,12 @@ discard block |
||
| 2272 | 2265 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2273 | 2266 | $joindre = false; |
| 2274 | 2267 | foreach ($cols as $col) { |
| 2275 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2268 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2276 | 2269 | if (trouver_champ($c, $boucle->where)) { |
| 2277 | 2270 | $joindre = true; |
| 2278 | 2271 | } else { |
| 2279 | 2272 | // mais ca peut etre dans le FIELD pour le Having |
| 2280 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2273 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2281 | 2274 | if (trouver_champ($c, $boucle->select)) { |
| 2282 | 2275 | $joindre = true; |
| 2283 | 2276 | } |
@@ -2324,7 +2317,7 @@ discard block |
||
| 2324 | 2317 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2325 | 2318 | |
| 2326 | 2319 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2327 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2320 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2328 | 2321 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2329 | 2322 | |
| 2330 | 2323 | if (!$intermediaire or !$arrivee) { |
@@ -2422,7 +2415,7 @@ discard block |
||
| 2422 | 2415 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2423 | 2416 | // un critere conditionnel sur date est traite a part |
| 2424 | 2417 | // car la date est mise d'office par SPIP, |
| 2425 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2418 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2426 | 2419 | } |
| 2427 | 2420 | |
| 2428 | 2421 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2454,7 +2447,7 @@ discard block |
||
| 2454 | 2447 | and (($p == "'") or ($p == '"')) |
| 2455 | 2448 | and $params[0][1]->type == 'champ' |
| 2456 | 2449 | ) { |
| 2457 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2450 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2458 | 2451 | } else { |
| 2459 | 2452 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2460 | 2453 | $a = calculer_liste($p, $desc, $boucles, $parent); |
@@ -2470,7 +2463,7 @@ discard block |
||
| 2470 | 2463 | $fct = $args_sql = ''; |
| 2471 | 2464 | // fonction SQL ? |
| 2472 | 2465 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2473 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2466 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2474 | 2467 | $fct = $m[1]; |
| 2475 | 2468 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2476 | 2469 | $col = $a[1]; |
@@ -2560,7 +2553,7 @@ discard block |
||
| 2560 | 2553 | # si oui choisir ce champ, sinon choisir xxxx |
| 2561 | 2554 | |
| 2562 | 2555 | if (isset($table['field']["date$suite"])) { |
| 2563 | - $date_orig = 'date' . $suite; |
|
| 2556 | + $date_orig = 'date'.$suite; |
|
| 2564 | 2557 | } else { |
| 2565 | 2558 | $date_orig = substr($suite, 1); |
| 2566 | 2559 | } |
@@ -2571,12 +2564,12 @@ discard block |
||
| 2571 | 2564 | } |
| 2572 | 2565 | } |
| 2573 | 2566 | |
| 2574 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2567 | + $date_compare = "\"' . normaliser_date(". |
|
| 2568 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2576 | 2569 | ") . '\""; |
| 2577 | 2570 | |
| 2578 | 2571 | $col_vraie = $date_orig; |
| 2579 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2572 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2580 | 2573 | |
| 2581 | 2574 | switch ($col) { |
| 2582 | 2575 | case 'date': |
@@ -2596,26 +2589,26 @@ discard block |
||
| 2596 | 2589 | break; |
| 2597 | 2590 | case 'age': |
| 2598 | 2591 | $col = calculer_param_date("NOW()", $date_orig); |
| 2599 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2592 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2600 | 2593 | break; |
| 2601 | 2594 | case 'age_relatif': |
| 2602 | 2595 | $col = calculer_param_date($date_compare, $date_orig); |
| 2603 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2596 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2604 | 2597 | break; |
| 2605 | 2598 | case 'jour_relatif': |
| 2606 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2599 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2600 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2608 | 2601 | break; |
| 2609 | 2602 | case 'mois_relatif': |
| 2610 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2611 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2612 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2613 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2603 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2604 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2605 | + ")-YEAR(".$date_orig."))"; |
|
| 2606 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2614 | 2607 | break; |
| 2615 | 2608 | case 'annee_relatif': |
| 2616 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | - $date_orig . ")"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2609 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2610 | + $date_orig.")"; |
|
| 2611 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2619 | 2612 | break; |
| 2620 | 2613 | } |
| 2621 | 2614 | |
@@ -2674,10 +2667,10 @@ discard block |
||
| 2674 | 2667 | } |
| 2675 | 2668 | |
| 2676 | 2669 | $boucle->hash .= ' |
| 2677 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2670 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2678 | 2671 | |
| 2679 | 2672 | $boucle->hash .= ' |
| 2680 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2673 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2681 | 2674 | } |
| 2682 | 2675 | |
| 2683 | 2676 | |
@@ -2695,8 +2688,8 @@ discard block |
||
| 2695 | 2688 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2696 | 2689 | $boucle = &$boucles[$idb]; |
| 2697 | 2690 | $boucle->hash .= ' |
| 2698 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2699 | - $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2691 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2692 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2700 | 2693 | } |
| 2701 | 2694 | |
| 2702 | 2695 | |
@@ -2716,7 +2709,7 @@ discard block |
||
| 2716 | 2709 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2717 | 2710 | $boucle = &$boucles[$idb]; |
| 2718 | 2711 | $boucle->hash .= ' |
| 2719 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2712 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2720 | 2713 | } |
| 2721 | 2714 | |
| 2722 | 2715 | |
@@ -2735,7 +2728,7 @@ discard block |
||
| 2735 | 2728 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2736 | 2729 | foreach ($crit->param as $param) { |
| 2737 | 2730 | $boucle->hash .= ' |
| 2738 | - $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2731 | + $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2739 | 2732 | } |
| 2740 | 2733 | } |
| 2741 | 2734 | |
@@ -2754,10 +2747,10 @@ discard block |
||
| 2754 | 2747 | */ |
| 2755 | 2748 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2756 | 2749 | $boucle = &$boucles[$idb]; |
| 2757 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2750 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2758 | 2751 | foreach ($crit->param as $param) { |
| 2759 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2752 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2753 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2761 | 2754 | } |
| 2762 | 2755 | } |
| 2763 | 2756 | |
@@ -2784,10 +2777,10 @@ discard block |
||
| 2784 | 2777 | */ |
| 2785 | 2778 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2786 | 2779 | $boucle = &$boucles[$idb]; |
| 2787 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2780 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2788 | 2781 | foreach ($crit->param as $param) { |
| 2789 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2782 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2783 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2791 | 2784 | } |
| 2792 | 2785 | } |
| 2793 | 2786 | |
@@ -2806,7 +2799,7 @@ discard block |
||
| 2806 | 2799 | $boucle = &$boucles[$idb]; |
| 2807 | 2800 | foreach ($crit->param as $param) { |
| 2808 | 2801 | $boucle->hash .= ' |
| 2809 | - $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2802 | + $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2810 | 2803 | } |
| 2811 | 2804 | } |
| 2812 | 2805 | |
@@ -2847,7 +2840,7 @@ discard block |
||
| 2847 | 2840 | if ($crit->param) { |
| 2848 | 2841 | foreach ($crit->param as $param) { |
| 2849 | 2842 | $boucle->hash .= "\t\$command['si'][] = " |
| 2850 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2843 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2851 | 2844 | } |
| 2852 | 2845 | // interdire {si 0} aussi ! |
| 2853 | 2846 | } else { |
@@ -2870,7 +2863,7 @@ discard block |
||
| 2870 | 2863 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2871 | 2864 | $boucle = &$boucles[$idb]; |
| 2872 | 2865 | $boucle->hash .= ' |
| 2873 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2866 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2874 | 2867 | $command[\'sourcemode\'] = \'table\';'; |
| 2875 | 2868 | } |
| 2876 | 2869 | |
@@ -2903,11 +2896,10 @@ discard block |
||
| 2903 | 2896 | $table_sql = table_objet_sql(objet_type($table)); |
| 2904 | 2897 | |
| 2905 | 2898 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2906 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | - 'id_parent'; |
|
| 2899 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2908 | 2900 | |
| 2909 | 2901 | $in = "IN"; |
| 2910 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2902 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | 2903 | if ($not) { |
| 2912 | 2904 | $where = array("'NOT'", $where); |
| 2913 | 2905 | } |
@@ -418,6 +418,10 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // http://code.spip.net/@reference_boucle_debug |
| 421 | +/** |
|
| 422 | + * @param string $nom |
|
| 423 | + * @param string $self |
|
| 424 | + */ |
|
| 421 | 425 | function reference_boucle_debug($n, $nom, $self) { |
| 422 | 426 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 423 | 427 | |
@@ -806,6 +810,9 @@ discard block |
||
| 806 | 810 | } |
| 807 | 811 | |
| 808 | 812 | // http://code.spip.net/@debusquer_entete |
| 813 | +/** |
|
| 814 | + * @param string $corps |
|
| 815 | + */ |
|
| 809 | 816 | function debusquer_entete($titre, $corps) { |
| 810 | 817 | |
| 811 | 818 | include_spip('balise/formulaire_admin'); |
@@ -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,135 +66,135 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()) { |
| 69 | - static $tableau_des_erreurs = array(); |
|
| 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 = array(); |
|
| 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[] = array($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 (ob_get_length() |
|
| 119 | - and |
|
| 120 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | - ) { |
|
| 122 | - ob_end_clean(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | - $fonc = _request('var_mode_objet'); |
|
| 127 | - $mode = _request('var_mode_affiche'); |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_status(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 69 | + static $tableau_des_erreurs = array(); |
|
| 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 = array(); |
|
| 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[] = array($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 (ob_get_length() |
|
| 119 | + and |
|
| 120 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | + ) { |
|
| 122 | + ob_end_clean(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | + $fonc = _request('var_mode_objet'); |
|
| 127 | + $mode = _request('var_mode_affiche'); |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_status(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | 207 | |
| 208 | - if (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 = array(); |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 221 | - } |
|
| 222 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 223 | - } |
|
| 224 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 226 | - . "</td></tr>\n"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (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 = array(); |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 221 | + } |
|
| 222 | + $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 223 | + } |
|
| 224 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | + . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 226 | + . "</td></tr>\n"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -234,67 +234,67 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav') { |
| 236 | 236 | |
| 237 | - if (_request('exec') == 'valider_xml') { |
|
| 238 | - return ''; |
|
| 239 | - } |
|
| 240 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 241 | - $res = ''; |
|
| 242 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 243 | - foreach ($tableau as $i => $err) { |
|
| 244 | - $boucle = $ligne = $skel = ''; |
|
| 245 | - list($msg, $lieu) = $err; |
|
| 246 | - if (is_object($lieu)) { |
|
| 247 | - $ligne = $lieu->ligne; |
|
| 248 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 249 | - if (isset($lieu->descr['nom'])) { |
|
| 250 | - $nom_code = $lieu->descr['nom']; |
|
| 251 | - $skel = $lieu->descr['sourcefile']; |
|
| 252 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 253 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 254 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 255 | - if ($boucle) { |
|
| 256 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - $j = ($i + 1); |
|
| 263 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 264 | - . $j |
|
| 265 | - . " </td><td style='text-align: left'>" |
|
| 266 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 267 | - . "</td><td style='text-align: left'>" |
|
| 268 | - . ($skel ? $skel : " / ") |
|
| 269 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 270 | - . ($boucle ? $boucle : " / ") |
|
| 271 | - . "</td><td style='text-align: right'>" |
|
| 272 | - . $ligne |
|
| 273 | - . "</td></tr>\n"; |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return "\n<table id='$id'>" |
|
| 278 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 279 | - . $caption[0] |
|
| 237 | + if (_request('exec') == 'valider_xml') { |
|
| 238 | + return ''; |
|
| 239 | + } |
|
| 240 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 241 | + $res = ''; |
|
| 242 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 243 | + foreach ($tableau as $i => $err) { |
|
| 244 | + $boucle = $ligne = $skel = ''; |
|
| 245 | + list($msg, $lieu) = $err; |
|
| 246 | + if (is_object($lieu)) { |
|
| 247 | + $ligne = $lieu->ligne; |
|
| 248 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 249 | + if (isset($lieu->descr['nom'])) { |
|
| 250 | + $nom_code = $lieu->descr['nom']; |
|
| 251 | + $skel = $lieu->descr['sourcefile']; |
|
| 252 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 253 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 254 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 255 | + if ($boucle) { |
|
| 256 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + $j = ($i + 1); |
|
| 263 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 264 | + . $j |
|
| 265 | + . " </td><td style='text-align: left'>" |
|
| 266 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 267 | + . "</td><td style='text-align: left'>" |
|
| 268 | + . ($skel ? $skel : " / ") |
|
| 269 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 270 | + . ($boucle ? $boucle : " / ") |
|
| 271 | + . "</td><td style='text-align: right'>" |
|
| 272 | + . $ligne |
|
| 273 | + . "</td></tr>\n"; |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return "\n<table id='$id'>" |
|
| 278 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 279 | + . $caption[0] |
|
| 280 | 280 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 281 | 281 | # aider('erreur_compilation'), |
| 282 | - . "</caption>" |
|
| 283 | - // fausse caption du chrono (mais vraie nav) |
|
| 284 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 285 | - . "<tr><th>" |
|
| 286 | - . _T('numero') |
|
| 287 | - . "</th><th>" |
|
| 288 | - . _T('public:message') |
|
| 289 | - . "</th><th>" |
|
| 290 | - . _T('squelette') |
|
| 291 | - . "</th><th>" |
|
| 292 | - . _T('zbug_boucle') |
|
| 293 | - . "</th><th>" |
|
| 294 | - . _T('ligne') |
|
| 295 | - . "</th></tr>" |
|
| 296 | - . $res |
|
| 297 | - . "</table>"; |
|
| 282 | + . "</caption>" |
|
| 283 | + // fausse caption du chrono (mais vraie nav) |
|
| 284 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 285 | + . "<tr><th>" |
|
| 286 | + . _T('numero') |
|
| 287 | + . "</th><th>" |
|
| 288 | + . _T('public:message') |
|
| 289 | + . "</th><th>" |
|
| 290 | + . _T('squelette') |
|
| 291 | + . "</th><th>" |
|
| 292 | + . _T('zbug_boucle') |
|
| 293 | + . "</th><th>" |
|
| 294 | + . _T('ligne') |
|
| 295 | + . "</th></tr>" |
|
| 296 | + . $res |
|
| 297 | + . "</table>"; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -314,125 +314,125 @@ discard block |
||
| 314 | 314 | * ou un tableau si l'erreur est critique |
| 315 | 315 | **/ |
| 316 | 316 | function debusquer_requete($message) { |
| 317 | - list($errno, $msg, $query) = $message; |
|
| 318 | - |
|
| 319 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 320 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 321 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 322 | - $errno = $regs[2]; |
|
| 323 | - } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 324 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 325 | - ) { |
|
| 326 | - $errno = $regs[1]; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // Erreur systeme |
|
| 330 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 331 | - $retour = "<tt><br /><br /><blink>" |
|
| 332 | - . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 333 | - . "</blink><br />\n<b>" |
|
| 334 | - . _T('info_erreur_systeme2', |
|
| 335 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 336 | - . '</b><br />'; |
|
| 337 | - spip_log("Erreur systeme $errno"); |
|
| 338 | - |
|
| 339 | - return array($retour, ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // Requete erronee |
|
| 343 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 344 | - . spip_htmlspecialchars($msg) |
|
| 345 | - . "\n<br /><span style='color: red'><b>" |
|
| 346 | - . spip_htmlspecialchars($query) |
|
| 347 | - . "</b></span></tt><br />"; |
|
| 348 | - |
|
| 349 | - //. aider('erreur_mysql'); |
|
| 350 | - |
|
| 351 | - return $err; |
|
| 317 | + list($errno, $msg, $query) = $message; |
|
| 318 | + |
|
| 319 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 320 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 321 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 322 | + $errno = $regs[2]; |
|
| 323 | + } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 324 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 325 | + ) { |
|
| 326 | + $errno = $regs[1]; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // Erreur systeme |
|
| 330 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 331 | + $retour = "<tt><br /><br /><blink>" |
|
| 332 | + . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 333 | + . "</blink><br />\n<b>" |
|
| 334 | + . _T('info_erreur_systeme2', |
|
| 335 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 336 | + . '</b><br />'; |
|
| 337 | + spip_log("Erreur systeme $errno"); |
|
| 338 | + |
|
| 339 | + return array($retour, ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // Requete erronee |
|
| 343 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 344 | + . spip_htmlspecialchars($msg) |
|
| 345 | + . "\n<br /><span style='color: red'><b>" |
|
| 346 | + . spip_htmlspecialchars($query) |
|
| 347 | + . "</b></span></tt><br />"; |
|
| 348 | + |
|
| 349 | + //. aider('erreur_mysql'); |
|
| 350 | + |
|
| 351 | + return $err; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | // http://code.spip.net/@trouve_boucle_debug |
| 356 | 356 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 357 | 357 | |
| 358 | - $id = $nom . $boucle; |
|
| 359 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 360 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 361 | - |
|
| 362 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 363 | - $y = substr_count($v[0], "\n"); |
|
| 364 | - } else { |
|
| 365 | - if ($v[1][0] == '#') // balise dynamique |
|
| 366 | - { |
|
| 367 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 368 | - } else // inclusion |
|
| 369 | - { |
|
| 370 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 371 | - } |
|
| 372 | - $y = substr_count($incl, "\n") |
|
| 373 | - + substr_count($r[1], "\n") |
|
| 374 | - + substr_count($r[3], "\n"); |
|
| 375 | - } |
|
| 376 | - if ($n <= ($y + $debut)) { |
|
| 377 | - if ($v[1][0] == '?') { |
|
| 378 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 379 | - } elseif ($v[1][0] == '!') { |
|
| 380 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 381 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 386 | - } |
|
| 387 | - $debut += $y; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return array($nom, $boucle, $n - $debut); |
|
| 358 | + $id = $nom . $boucle; |
|
| 359 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 360 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 361 | + |
|
| 362 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 363 | + $y = substr_count($v[0], "\n"); |
|
| 364 | + } else { |
|
| 365 | + if ($v[1][0] == '#') // balise dynamique |
|
| 366 | + { |
|
| 367 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 368 | + } else // inclusion |
|
| 369 | + { |
|
| 370 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 371 | + } |
|
| 372 | + $y = substr_count($incl, "\n") |
|
| 373 | + + substr_count($r[1], "\n") |
|
| 374 | + + substr_count($r[3], "\n"); |
|
| 375 | + } |
|
| 376 | + if ($n <= ($y + $debut)) { |
|
| 377 | + if ($v[1][0] == '?') { |
|
| 378 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 379 | + } elseif ($v[1][0] == '!') { |
|
| 380 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 381 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 386 | + } |
|
| 387 | + $debut += $y; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return array($nom, $boucle, $n - $debut); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // http://code.spip.net/@trouve_squelette_inclus |
| 395 | 395 | function trouve_squelette_inclus($script) { |
| 396 | 396 | |
| 397 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 398 | - // si le script X.php n'est pas ecrire/public.php |
|
| 399 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 400 | - if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | - { |
|
| 402 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 403 | - { |
|
| 404 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 405 | - $reg[1] = "inconnu"; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 410 | - |
|
| 411 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 412 | - if (preg_match($incl, $v)) { |
|
| 413 | - return $k; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return ""; |
|
| 397 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 398 | + // si le script X.php n'est pas ecrire/public.php |
|
| 399 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 400 | + if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | + { |
|
| 402 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 403 | + { |
|
| 404 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 405 | + $reg[1] = "inconnu"; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 410 | + |
|
| 411 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 412 | + if (preg_match($incl, $v)) { |
|
| 413 | + return $k; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return ""; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // http://code.spip.net/@reference_boucle_debug |
| 421 | 421 | function reference_boucle_debug($n, $nom, $self) { |
| 422 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 423 | - |
|
| 424 | - if (!$boucle) { |
|
| 425 | - return !$ligne ? "" : |
|
| 426 | - (" (" . |
|
| 427 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | - _T('squelette_ligne')) . |
|
| 429 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 430 | - } else { |
|
| 431 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 432 | - |
|
| 433 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | - } |
|
| 422 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 423 | + |
|
| 424 | + if (!$boucle) { |
|
| 425 | + return !$ligne ? "" : |
|
| 426 | + (" (" . |
|
| 427 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | + _T('squelette_ligne')) . |
|
| 429 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 430 | + } else { |
|
| 431 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 432 | + |
|
| 433 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | + } |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // affiche un texte avec numero de ligne et ancre. |
@@ -440,395 +440,395 @@ discard block |
||
| 440 | 440 | // http://code.spip.net/@ancre_texte |
| 441 | 441 | function ancre_texte($texte, $fautifs = array(), $nocpt = false) { |
| 442 | 442 | |
| 443 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 444 | - if ($var_mode_ligne) { |
|
| 445 | - $fautifs[] = array($var_mode_ligne); |
|
| 446 | - } |
|
| 447 | - $res = ''; |
|
| 448 | - |
|
| 449 | - $s = highlight_string($texte, true); |
|
| 450 | - if (substr($s, 0, 6) == '<code>') { |
|
| 451 | - $s = substr($s, 6); |
|
| 452 | - $res = '<code>'; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 456 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 457 | - $s); |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - $tableau = explode("<br />", $s); |
|
| 461 | - |
|
| 462 | - $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"; |
|
| 463 | - |
|
| 464 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 465 | - $formaterr = "color: red;"; |
|
| 466 | - $i = 1; |
|
| 467 | - $flignes = array(); |
|
| 468 | - $loc = array(0, 0); |
|
| 469 | - foreach ($fautifs as $lc) { |
|
| 470 | - if (is_array($lc)) { |
|
| 471 | - $l = array_shift($lc); |
|
| 472 | - $flignes[$l] = $lc; |
|
| 473 | - } else { |
|
| 474 | - $flignes[$lc] = $loc; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $ancre = md5($texte); |
|
| 479 | - foreach ($tableau as $ligne) { |
|
| 480 | - if (isset($flignes[$i])) { |
|
| 481 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 482 | - $indexmesg = $flignes[$i][1]; |
|
| 483 | - $err = textebrut($flignes[$i][2]); |
|
| 484 | - // tentative de pointer sur la colonne fautive; |
|
| 485 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 486 | - // $m = $flignes[$i][0]; |
|
| 487 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 488 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 489 | - $bg = $formaterr; |
|
| 490 | - } else { |
|
| 491 | - $indexmesg = $ancre; |
|
| 492 | - $err = $bg = ''; |
|
| 493 | - } |
|
| 494 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 495 | - $i++; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return "<div id='T$ancre'>" |
|
| 499 | - . '<div onclick="' |
|
| 500 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 501 | - . '" title="' |
|
| 502 | - . _T('masquer_colonne') |
|
| 503 | - . '" style="cursor: pointer;">' |
|
| 504 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 505 | - . "</div> |
|
| 443 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 444 | + if ($var_mode_ligne) { |
|
| 445 | + $fautifs[] = array($var_mode_ligne); |
|
| 446 | + } |
|
| 447 | + $res = ''; |
|
| 448 | + |
|
| 449 | + $s = highlight_string($texte, true); |
|
| 450 | + if (substr($s, 0, 6) == '<code>') { |
|
| 451 | + $s = substr($s, 6); |
|
| 452 | + $res = '<code>'; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 456 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 457 | + $s); |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + $tableau = explode("<br />", $s); |
|
| 461 | + |
|
| 462 | + $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"; |
|
| 463 | + |
|
| 464 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 465 | + $formaterr = "color: red;"; |
|
| 466 | + $i = 1; |
|
| 467 | + $flignes = array(); |
|
| 468 | + $loc = array(0, 0); |
|
| 469 | + foreach ($fautifs as $lc) { |
|
| 470 | + if (is_array($lc)) { |
|
| 471 | + $l = array_shift($lc); |
|
| 472 | + $flignes[$l] = $lc; |
|
| 473 | + } else { |
|
| 474 | + $flignes[$lc] = $loc; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $ancre = md5($texte); |
|
| 479 | + foreach ($tableau as $ligne) { |
|
| 480 | + if (isset($flignes[$i])) { |
|
| 481 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 482 | + $indexmesg = $flignes[$i][1]; |
|
| 483 | + $err = textebrut($flignes[$i][2]); |
|
| 484 | + // tentative de pointer sur la colonne fautive; |
|
| 485 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 486 | + // $m = $flignes[$i][0]; |
|
| 487 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 488 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 489 | + $bg = $formaterr; |
|
| 490 | + } else { |
|
| 491 | + $indexmesg = $ancre; |
|
| 492 | + $err = $bg = ''; |
|
| 493 | + } |
|
| 494 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 495 | + $i++; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return "<div id='T$ancre'>" |
|
| 499 | + . '<div onclick="' |
|
| 500 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 501 | + . '" title="' |
|
| 502 | + . _T('masquer_colonne') |
|
| 503 | + . '" style="cursor: pointer;">' |
|
| 504 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 505 | + . "</div> |
|
| 506 | 506 | " . $res . "</div>\n"; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // l'environnement graphique du debuggueur |
| 510 | 510 | |
| 511 | 511 | function debusquer_squelette($fonc, $mode, $self) { |
| 512 | - $texte = ''; |
|
| 513 | - |
|
| 514 | - if ($mode !== 'validation') { |
|
| 515 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 516 | - $res = "<div id='spip-boucles'>\n" |
|
| 517 | - . debusquer_navigation_squelettes($self) |
|
| 518 | - . "</div>"; |
|
| 519 | - } else { |
|
| 520 | - $res = ''; |
|
| 521 | - } |
|
| 522 | - if ($fonc) { |
|
| 523 | - $id = " id='$fonc'"; |
|
| 524 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 525 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 526 | - $texte .= $res2; |
|
| 527 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | - $legend = _T('zbug_' . $mode); |
|
| 529 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 530 | - $texte = ancre_texte($texte, array('', '')); |
|
| 531 | - } |
|
| 532 | - } else { |
|
| 533 | - if (strlen(trim($res))) { |
|
| 534 | - return "<img src='" . chemin_image('compat-16.png') . "' 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>"; |
|
| 535 | - } else { |
|
| 536 | - // cas de l'appel sur erreur: montre la page |
|
| 537 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 538 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 539 | - : ''; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } else { |
|
| 543 | - $valider = charger_fonction('valider', 'xml'); |
|
| 544 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 545 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 546 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 547 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 548 | - if ($err === false) { |
|
| 549 | - $err = _T('impossible'); |
|
| 550 | - } elseif ($err === true) { |
|
| 551 | - $err = _T('correcte'); |
|
| 552 | - } else { |
|
| 553 | - $err = ": $err"; |
|
| 554 | - } |
|
| 555 | - $legend = _T('validation') . ' ' . $err; |
|
| 556 | - $res = $id = ''; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - return !trim($texte) ? '' : ( |
|
| 560 | - "<img src='" . chemin_image('compat-16.png') . "' 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" |
|
| 561 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 562 | - . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 563 | - . ($legend ? $legend : $mode) |
|
| 564 | - . "</a></legend>" |
|
| 565 | - . $texte |
|
| 566 | - . "</fieldset></div>" |
|
| 567 | - . "</div>"); |
|
| 512 | + $texte = ''; |
|
| 513 | + |
|
| 514 | + if ($mode !== 'validation') { |
|
| 515 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 516 | + $res = "<div id='spip-boucles'>\n" |
|
| 517 | + . debusquer_navigation_squelettes($self) |
|
| 518 | + . "</div>"; |
|
| 519 | + } else { |
|
| 520 | + $res = ''; |
|
| 521 | + } |
|
| 522 | + if ($fonc) { |
|
| 523 | + $id = " id='$fonc'"; |
|
| 524 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 525 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 526 | + $texte .= $res2; |
|
| 527 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | + $legend = _T('zbug_' . $mode); |
|
| 529 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 530 | + $texte = ancre_texte($texte, array('', '')); |
|
| 531 | + } |
|
| 532 | + } else { |
|
| 533 | + if (strlen(trim($res))) { |
|
| 534 | + return "<img src='" . chemin_image('compat-16.png') . "' 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>"; |
|
| 535 | + } else { |
|
| 536 | + // cas de l'appel sur erreur: montre la page |
|
| 537 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 538 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 539 | + : ''; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } else { |
|
| 543 | + $valider = charger_fonction('valider', 'xml'); |
|
| 544 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 545 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 546 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 547 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 548 | + if ($err === false) { |
|
| 549 | + $err = _T('impossible'); |
|
| 550 | + } elseif ($err === true) { |
|
| 551 | + $err = _T('correcte'); |
|
| 552 | + } else { |
|
| 553 | + $err = ": $err"; |
|
| 554 | + } |
|
| 555 | + $legend = _T('validation') . ' ' . $err; |
|
| 556 | + $res = $id = ''; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + return !trim($texte) ? '' : ( |
|
| 560 | + "<img src='" . chemin_image('compat-16.png') . "' 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" |
|
| 561 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 562 | + . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 563 | + . ($legend ? $legend : $mode) |
|
| 564 | + . "</a></legend>" |
|
| 565 | + . $texte |
|
| 566 | + . "</fieldset></div>" |
|
| 567 | + . "</div>"); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
| 571 | 571 | // http://code.spip.net/@emboite_texte |
| 572 | 572 | function emboite_texte($res, $fonc = '', $self = '') { |
| 573 | - $errs = $res->err; |
|
| 574 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 575 | - |
|
| 576 | - if (!$texte and !$errs) { |
|
| 577 | - return array(ancre_texte('', array('', '')), false); |
|
| 578 | - } |
|
| 579 | - if (!$errs) { |
|
| 580 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 584 | - |
|
| 585 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 586 | - $encore = count_occ($errs); |
|
| 587 | - $encore2 = array(); |
|
| 588 | - $fautifs = array(); |
|
| 589 | - |
|
| 590 | - $err = '<tr><th>' |
|
| 591 | - . _T('numero') |
|
| 592 | - . "</th><th>" |
|
| 593 | - . _T('occurence') |
|
| 594 | - . "</th><th>" |
|
| 595 | - . _T('ligne') |
|
| 596 | - . "</th><th>" |
|
| 597 | - . _T('colonne') |
|
| 598 | - . "</th><th>" |
|
| 599 | - . _T('erreur') |
|
| 600 | - . "</th></tr>"; |
|
| 601 | - |
|
| 602 | - $i = 0; |
|
| 603 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 604 | - foreach ($errs as $r) { |
|
| 605 | - $i++; |
|
| 606 | - list($msg, $ligne, $col) = $r; |
|
| 607 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 608 | - if (isset($encore2[$msg])) { |
|
| 609 | - $ref = ++$encore2[$msg]; |
|
| 610 | - } else { |
|
| 611 | - $encore2[$msg] = $ref = 1; |
|
| 612 | - } |
|
| 613 | - $err .= "<tr style='background-color: " |
|
| 614 | - . $colors[$i % 2] |
|
| 615 | - . "'><td $style><a href='#debut_err'>" |
|
| 616 | - . $i |
|
| 617 | - . "</a></td><td $style>" |
|
| 618 | - . "$ref/$encore[$msg]</td>" |
|
| 619 | - . "<td $style><a href='#L" |
|
| 620 | - . $ligne |
|
| 621 | - . "' id='T$i'>" |
|
| 622 | - . $ligne |
|
| 623 | - . "</a></td><td $style>" |
|
| 624 | - . $col |
|
| 625 | - . "</td><td>$msg</td></tr>\n"; |
|
| 626 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 627 | - } |
|
| 628 | - $err = "<h2 style='text-align: center'>" |
|
| 629 | - . $i |
|
| 630 | - . "<a href='#fin_err'>" |
|
| 631 | - . " " . _T('erreur_texte') |
|
| 632 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 633 | - . $err |
|
| 634 | - . " </table><a id='fin_err'></a>"; |
|
| 635 | - |
|
| 636 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 637 | - } else { |
|
| 638 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 639 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 640 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 641 | - $err = $msg . |
|
| 642 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 644 | - |
|
| 645 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 646 | - } |
|
| 573 | + $errs = $res->err; |
|
| 574 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 575 | + |
|
| 576 | + if (!$texte and !$errs) { |
|
| 577 | + return array(ancre_texte('', array('', '')), false); |
|
| 578 | + } |
|
| 579 | + if (!$errs) { |
|
| 580 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 584 | + |
|
| 585 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 586 | + $encore = count_occ($errs); |
|
| 587 | + $encore2 = array(); |
|
| 588 | + $fautifs = array(); |
|
| 589 | + |
|
| 590 | + $err = '<tr><th>' |
|
| 591 | + . _T('numero') |
|
| 592 | + . "</th><th>" |
|
| 593 | + . _T('occurence') |
|
| 594 | + . "</th><th>" |
|
| 595 | + . _T('ligne') |
|
| 596 | + . "</th><th>" |
|
| 597 | + . _T('colonne') |
|
| 598 | + . "</th><th>" |
|
| 599 | + . _T('erreur') |
|
| 600 | + . "</th></tr>"; |
|
| 601 | + |
|
| 602 | + $i = 0; |
|
| 603 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 604 | + foreach ($errs as $r) { |
|
| 605 | + $i++; |
|
| 606 | + list($msg, $ligne, $col) = $r; |
|
| 607 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 608 | + if (isset($encore2[$msg])) { |
|
| 609 | + $ref = ++$encore2[$msg]; |
|
| 610 | + } else { |
|
| 611 | + $encore2[$msg] = $ref = 1; |
|
| 612 | + } |
|
| 613 | + $err .= "<tr style='background-color: " |
|
| 614 | + . $colors[$i % 2] |
|
| 615 | + . "'><td $style><a href='#debut_err'>" |
|
| 616 | + . $i |
|
| 617 | + . "</a></td><td $style>" |
|
| 618 | + . "$ref/$encore[$msg]</td>" |
|
| 619 | + . "<td $style><a href='#L" |
|
| 620 | + . $ligne |
|
| 621 | + . "' id='T$i'>" |
|
| 622 | + . $ligne |
|
| 623 | + . "</a></td><td $style>" |
|
| 624 | + . $col |
|
| 625 | + . "</td><td>$msg</td></tr>\n"; |
|
| 626 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 627 | + } |
|
| 628 | + $err = "<h2 style='text-align: center'>" |
|
| 629 | + . $i |
|
| 630 | + . "<a href='#fin_err'>" |
|
| 631 | + . " " . _T('erreur_texte') |
|
| 632 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 633 | + . $err |
|
| 634 | + . " </table><a id='fin_err'></a>"; |
|
| 635 | + |
|
| 636 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 637 | + } else { |
|
| 638 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 639 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 640 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 641 | + $err = $msg . |
|
| 642 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 644 | + |
|
| 645 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 646 | + } |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | // http://code.spip.net/@count_occ |
| 650 | 650 | function count_occ($regs) { |
| 651 | - $encore = array(); |
|
| 652 | - foreach ($regs as $r) { |
|
| 653 | - if (isset($encore[$r[0]])) { |
|
| 654 | - $encore[$r[0]]++; |
|
| 655 | - } else { |
|
| 656 | - $encore[$r[0]] = 1; |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - return $encore; |
|
| 651 | + $encore = array(); |
|
| 652 | + foreach ($regs as $r) { |
|
| 653 | + if (isset($encore[$r[0]])) { |
|
| 654 | + $encore[$r[0]]++; |
|
| 655 | + } else { |
|
| 656 | + $encore[$r[0]] = 1; |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + return $encore; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function debusquer_navigation_squelettes($self) { |
| 664 | 664 | |
| 665 | - $res = ''; |
|
| 666 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 667 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 668 | - $t_skel = _T('squelette'); |
|
| 669 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 670 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 671 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 672 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 673 | - array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 674 | - |
|
| 675 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 676 | - . $t_skel |
|
| 677 | - . ' ' |
|
| 678 | - . $sourcefile |
|
| 679 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 680 | - . $t_skel |
|
| 681 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 682 | - . _T('zbug_resultat') |
|
| 683 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 684 | - . _T('zbug_code') |
|
| 685 | - . "</a>\n<a href='" |
|
| 686 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 687 | - . "'>" |
|
| 688 | - . _T('zbug_calcul') |
|
| 689 | - . "</a></legend>" |
|
| 690 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 691 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 692 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 693 | - . "</fieldset>\n"; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $res; |
|
| 665 | + $res = ''; |
|
| 666 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 667 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 668 | + $t_skel = _T('squelette'); |
|
| 669 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 670 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 671 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 672 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 673 | + array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 674 | + |
|
| 675 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 676 | + . $t_skel |
|
| 677 | + . ' ' |
|
| 678 | + . $sourcefile |
|
| 679 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 680 | + . $t_skel |
|
| 681 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 682 | + . _T('zbug_resultat') |
|
| 683 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 684 | + . _T('zbug_code') |
|
| 685 | + . "</a>\n<a href='" |
|
| 686 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 687 | + . "'>" |
|
| 688 | + . _T('zbug_calcul') |
|
| 689 | + . "</a></legend>" |
|
| 690 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 691 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 692 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 693 | + . "</fieldset>\n"; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $res; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 700 | - $i = 0; |
|
| 701 | - $res = ''; |
|
| 702 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 703 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 704 | - |
|
| 705 | - foreach ($boucles as $objet => $boucle) { |
|
| 706 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 707 | - $i++; |
|
| 708 | - $nom = $boucle->id_boucle; |
|
| 709 | - $req = $boucle->type_requete; |
|
| 710 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 711 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | - |
|
| 713 | - $res .= "\n<tr style='background-color: " . |
|
| 714 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | - "'><td align='right'>$i</td><td>\n" . |
|
| 716 | - "<a class='debug_link_boucle' href='" . |
|
| 717 | - $self2 . |
|
| 718 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | - _T('zbug_boucle') . |
|
| 720 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | - $self2 . |
|
| 722 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | - _T('zbug_resultat') . |
|
| 724 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | - $self2 . |
|
| 726 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | - _T('zbug_code') . |
|
| 728 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | - "'>" . |
|
| 731 | - _T('zbug_calcul') . |
|
| 732 | - "</a></td><td>\n" . |
|
| 733 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | - "</td><td>\n" . |
|
| 735 | - $req . |
|
| 736 | - "</td><td>\n" . |
|
| 737 | - spip_htmlspecialchars($crit) . |
|
| 738 | - "</td></tr>"; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $res; |
|
| 700 | + $i = 0; |
|
| 701 | + $res = ''; |
|
| 702 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 703 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 704 | + |
|
| 705 | + foreach ($boucles as $objet => $boucle) { |
|
| 706 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 707 | + $i++; |
|
| 708 | + $nom = $boucle->id_boucle; |
|
| 709 | + $req = $boucle->type_requete; |
|
| 710 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 711 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | + |
|
| 713 | + $res .= "\n<tr style='background-color: " . |
|
| 714 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | + "'><td align='right'>$i</td><td>\n" . |
|
| 716 | + "<a class='debug_link_boucle' href='" . |
|
| 717 | + $self2 . |
|
| 718 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | + _T('zbug_boucle') . |
|
| 720 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | + $self2 . |
|
| 722 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | + _T('zbug_resultat') . |
|
| 724 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | + $self2 . |
|
| 726 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | + _T('zbug_code') . |
|
| 728 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | + "'>" . |
|
| 731 | + _T('zbug_calcul') . |
|
| 732 | + "</a></td><td>\n" . |
|
| 733 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | + "</td><td>\n" . |
|
| 735 | + $req . |
|
| 736 | + "</td><td>\n" . |
|
| 737 | + spip_htmlspecialchars($crit) . |
|
| 738 | + "</td></tr>"; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $res; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | function debusquer_source($objet, $affiche) { |
| 746 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 747 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 748 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 749 | - } else { |
|
| 750 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 751 | - } |
|
| 752 | - $res2 = ""; |
|
| 753 | - |
|
| 754 | - if ($affiche == 'resultat') { |
|
| 755 | - $legend = $nom; |
|
| 756 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 757 | - if (function_exists('_mysql_traite_query')) { |
|
| 758 | - $c = strtolower(_request('connect')); |
|
| 759 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 760 | - $req = _mysql_traite_query($req, '', $c); |
|
| 761 | - } |
|
| 762 | - // permettre le copier/coller facile |
|
| 763 | - // $res = ancre_texte($req, array(), true); |
|
| 764 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 765 | - // formatage et affichage des resultats bruts de la requete |
|
| 766 | - $ress_req = spip_query($req); |
|
| 767 | - $brut_sql = ''; |
|
| 768 | - $num = 1; |
|
| 769 | - // eviter l'affichage de milliers de lignes |
|
| 770 | - // personnalisation possible dans mes_options |
|
| 771 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 772 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 773 | - if ($num <= $max_aff) { |
|
| 774 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 775 | - $brut_sql .= "<p>"; |
|
| 776 | - foreach ($retours_sql as $key => $val) { |
|
| 777 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 778 | - } |
|
| 779 | - $brut_sql .= "</p>"; |
|
| 780 | - } |
|
| 781 | - $num++; |
|
| 782 | - } |
|
| 783 | - $res2 = interdire_scripts($brut_sql); |
|
| 784 | - foreach ($quoi as $view) { |
|
| 785 | - // ne pas afficher les $contexte_inclus |
|
| 786 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 787 | - if ($view) { |
|
| 788 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - } elseif ($affiche == 'code') { |
|
| 793 | - $legend = $nom; |
|
| 794 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 795 | - } elseif ($affiche == 'boucle') { |
|
| 796 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 797 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 798 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 799 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 800 | - } elseif ($affiche == 'squelette') { |
|
| 801 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 802 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - return array($legend, $res, $res2); |
|
| 746 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 747 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 748 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 749 | + } else { |
|
| 750 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 751 | + } |
|
| 752 | + $res2 = ""; |
|
| 753 | + |
|
| 754 | + if ($affiche == 'resultat') { |
|
| 755 | + $legend = $nom; |
|
| 756 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 757 | + if (function_exists('_mysql_traite_query')) { |
|
| 758 | + $c = strtolower(_request('connect')); |
|
| 759 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 760 | + $req = _mysql_traite_query($req, '', $c); |
|
| 761 | + } |
|
| 762 | + // permettre le copier/coller facile |
|
| 763 | + // $res = ancre_texte($req, array(), true); |
|
| 764 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 765 | + // formatage et affichage des resultats bruts de la requete |
|
| 766 | + $ress_req = spip_query($req); |
|
| 767 | + $brut_sql = ''; |
|
| 768 | + $num = 1; |
|
| 769 | + // eviter l'affichage de milliers de lignes |
|
| 770 | + // personnalisation possible dans mes_options |
|
| 771 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 772 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 773 | + if ($num <= $max_aff) { |
|
| 774 | + $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 775 | + $brut_sql .= "<p>"; |
|
| 776 | + foreach ($retours_sql as $key => $val) { |
|
| 777 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 778 | + } |
|
| 779 | + $brut_sql .= "</p>"; |
|
| 780 | + } |
|
| 781 | + $num++; |
|
| 782 | + } |
|
| 783 | + $res2 = interdire_scripts($brut_sql); |
|
| 784 | + foreach ($quoi as $view) { |
|
| 785 | + // ne pas afficher les $contexte_inclus |
|
| 786 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 787 | + if ($view) { |
|
| 788 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + } elseif ($affiche == 'code') { |
|
| 793 | + $legend = $nom; |
|
| 794 | + $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 795 | + } elseif ($affiche == 'boucle') { |
|
| 796 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 797 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 798 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 799 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 800 | + } elseif ($affiche == 'squelette') { |
|
| 801 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 802 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + return array($legend, $res, $res2); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // http://code.spip.net/@debusquer_entete |
| 809 | 809 | function debusquer_entete($titre, $corps) { |
| 810 | 810 | |
| 811 | - include_spip('balise/formulaire_admin'); |
|
| 812 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 813 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 814 | - |
|
| 815 | - return _DOCTYPE_ECRIRE . |
|
| 816 | - html_lang_attributes() . |
|
| 817 | - "<head>\n<title>" . |
|
| 818 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | - ")</title>\n" . |
|
| 822 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | - "' />\n" . |
|
| 825 | - http_script('', 'jquery.js') |
|
| 826 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | - . "' type='text/css' />" . |
|
| 828 | - "</head>\n" . |
|
| 829 | - "<body style='margin:0 10px;'>\n" . |
|
| 830 | - "<div id='spip-debug-header'>" . |
|
| 831 | - $corps . |
|
| 832 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 833 | - '</div></body></html>'; |
|
| 811 | + include_spip('balise/formulaire_admin'); |
|
| 812 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 813 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 814 | + |
|
| 815 | + return _DOCTYPE_ECRIRE . |
|
| 816 | + html_lang_attributes() . |
|
| 817 | + "<head>\n<title>" . |
|
| 818 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | + ")</title>\n" . |
|
| 822 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | + "' />\n" . |
|
| 825 | + http_script('', 'jquery.js') |
|
| 826 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | + . "' type='text/css' />" . |
|
| 828 | + "</head>\n" . |
|
| 829 | + "<body style='margin:0 10px;'>\n" . |
|
| 830 | + "<div id='spip-debug-header'>" . |
|
| 831 | + $corps . |
|
| 832 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 833 | + '</div></body></html>'; |
|
| 834 | 834 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | if (!$fonc) { |
| 148 | 148 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 149 | 149 | } |
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 150 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " ".$GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | 151 | } |
| 152 | 152 | if ($message === false) { |
| 153 | 153 | lang_select(); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
| 177 | 177 | // une erreur critique sort $message en array |
| 178 | 178 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 179 | + spip_log("Debug: ".$debug." (".$fond.")"); |
|
| 180 | 180 | |
| 181 | 181 | return $msg; |
| 182 | 182 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | 186 | if (!empty($erreurs)) { |
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 187 | + $n = array(count($erreurs).' '._T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | 189 | return debusquer_navigation($erreurs, $n); |
| 190 | 190 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | if (is_array($valeur)) { |
| 218 | 218 | $valeur_simple = array(); |
| 219 | 219 | foreach ($valeur as $v) { |
| 220 | - $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 220 | + $valeur_simple[] = is_array($v) ? 'array(size='.count($v).')' : $v; |
|
| 221 | 221 | } |
| 222 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 222 | + $valeur = '('.count($valeur).' items) ['.join(',', $valeur_simple).']'; |
|
| 223 | 223 | } |
| 224 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 224 | + $res .= "\n<tr><td><strong>".nl2br(entites_html($nom)) |
|
| 225 | + . "</strong></td><td>: ".nl2br(entites_html($valeur)) |
|
| 226 | 226 | . "</td></tr>\n"; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | $nom_code = $lieu->descr['nom']; |
| 251 | 251 | $skel = $lieu->descr['sourcefile']; |
| 252 | 252 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 253 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 253 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 254 | 254 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 255 | 255 | if ($boucle) { |
| 256 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 256 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | 257 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // Requete erronee |
| 343 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 343 | + $err = "<b>"._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 344 | 344 | . spip_htmlspecialchars($msg) |
| 345 | 345 | . "\n<br /><span style='color: red'><b>" |
| 346 | 346 | . spip_htmlspecialchars($query) |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | // http://code.spip.net/@trouve_boucle_debug |
| 356 | 356 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 357 | 357 | |
| 358 | - $id = $nom . $boucle; |
|
| 358 | + $id = $nom.$boucle; |
|
| 359 | 359 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 360 | 360 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 361 | 361 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 409 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 410 | 410 | |
| 411 | 411 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 412 | 412 | if (preg_match($incl, $v)) { |
@@ -422,16 +422,13 @@ discard block |
||
| 422 | 422 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 423 | 423 | |
| 424 | 424 | if (!$boucle) { |
| 425 | - return !$ligne ? "" : |
|
| 426 | - (" (" . |
|
| 427 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | - _T('squelette_ligne')) . |
|
| 425 | + return !$ligne ? "" : (" (". |
|
| 426 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 429 | 427 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 430 | 428 | } else { |
| 431 | 429 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 432 | 430 | |
| 433 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 431 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | 432 | } |
| 436 | 433 | } |
| 437 | 434 | |
@@ -453,13 +450,13 @@ discard block |
||
| 453 | 450 | } |
| 454 | 451 | |
| 455 | 452 | $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 456 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 453 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 457 | 454 | $s); |
| 458 | 455 | |
| 459 | 456 | |
| 460 | 457 | $tableau = explode("<br />", $s); |
| 461 | 458 | |
| 462 | - $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"; |
|
| 459 | + $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"; |
|
| 463 | 460 | |
| 464 | 461 | $format10 = str_replace('white', 'lightgrey', $format); |
| 465 | 462 | $formaterr = "color: red;"; |
@@ -503,7 +500,7 @@ discard block |
||
| 503 | 500 | . '" style="cursor: pointer;">' |
| 504 | 501 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 505 | 502 | . "</div> |
| 506 | - " . $res . "</div>\n"; |
|
| 503 | + " . $res."</div>\n"; |
|
| 507 | 504 | } |
| 508 | 505 | |
| 509 | 506 | // l'environnement graphique du debuggueur |
@@ -524,14 +521,14 @@ discard block |
||
| 524 | 521 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 525 | 522 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 526 | 523 | $texte .= $res2; |
| 527 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | - $legend = _T('zbug_' . $mode); |
|
| 529 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 524 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 525 | + $legend = _T('zbug_'.$mode); |
|
| 526 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 530 | 527 | $texte = ancre_texte($texte, array('', '')); |
| 531 | 528 | } |
| 532 | 529 | } else { |
| 533 | 530 | if (strlen(trim($res))) { |
| 534 | - return "<img src='" . chemin_image('compat-16.png') . "' 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>"; |
|
| 531 | + return "<img src='".chemin_image('compat-16.png')."' 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>"; |
|
| 535 | 532 | } else { |
| 536 | 533 | // cas de l'appel sur erreur: montre la page |
| 537 | 534 | return isset($GLOBALS['debug_objets']['resultat']['tout']) |
@@ -541,7 +538,7 @@ discard block |
||
| 541 | 538 | } |
| 542 | 539 | } else { |
| 543 | 540 | $valider = charger_fonction('valider', 'xml'); |
| 544 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 541 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 545 | 542 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 546 | 543 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 547 | 544 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
@@ -552,14 +549,14 @@ discard block |
||
| 552 | 549 | } else { |
| 553 | 550 | $err = ": $err"; |
| 554 | 551 | } |
| 555 | - $legend = _T('validation') . ' ' . $err; |
|
| 552 | + $legend = _T('validation').' '.$err; |
|
| 556 | 553 | $res = $id = ''; |
| 557 | 554 | } |
| 558 | 555 | |
| 559 | 556 | return !trim($texte) ? '' : ( |
| 560 | - "<img src='" . chemin_image('compat-16.png') . "' 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" |
|
| 557 | + "<img src='".chemin_image('compat-16.png')."' 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" |
|
| 561 | 558 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 562 | - . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 559 | + . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 563 | 560 | . ($legend ? $legend : $mode) |
| 564 | 561 | . "</a></legend>" |
| 565 | 562 | . $texte |
@@ -571,7 +568,7 @@ discard block |
||
| 571 | 568 | // http://code.spip.net/@emboite_texte |
| 572 | 569 | function emboite_texte($res, $fonc = '', $self = '') { |
| 573 | 570 | $errs = $res->err; |
| 574 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 571 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 575 | 572 | |
| 576 | 573 | if (!$texte and !$errs) { |
| 577 | 574 | return array(ancre_texte('', array('', '')), false); |
@@ -628,7 +625,7 @@ discard block |
||
| 628 | 625 | $err = "<h2 style='text-align: center'>" |
| 629 | 626 | . $i |
| 630 | 627 | . "<a href='#fin_err'>" |
| 631 | - . " " . _T('erreur_texte') |
|
| 628 | + . " "._T('erreur_texte') |
|
| 632 | 629 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 633 | 630 | . $err |
| 634 | 631 | . " </table><a id='fin_err'></a>"; |
@@ -638,9 +635,9 @@ discard block |
||
| 638 | 635 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 639 | 636 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 640 | 637 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 641 | - $err = $msg . |
|
| 642 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 638 | + $err = $msg. |
|
| 639 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 640 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 644 | 641 | |
| 645 | 642 | return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
| 646 | 643 | } |
@@ -672,7 +669,7 @@ discard block |
||
| 672 | 669 | $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
| 673 | 670 | array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
| 674 | 671 | |
| 675 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 672 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 676 | 673 | . $t_skel |
| 677 | 674 | . ' ' |
| 678 | 675 | . $sourcefile |
@@ -687,7 +684,7 @@ discard block |
||
| 687 | 684 | . "'>" |
| 688 | 685 | . _T('zbug_calcul') |
| 689 | 686 | . "</a></legend>" |
| 690 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 687 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 691 | 688 | . debusquer_contexte($contexte[$sourcefile]) |
| 692 | 689 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 693 | 690 | . "</fieldset>\n"; |
@@ -708,33 +705,33 @@ discard block |
||
| 708 | 705 | $nom = $boucle->id_boucle; |
| 709 | 706 | $req = $boucle->type_requete; |
| 710 | 707 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 711 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | - |
|
| 713 | - $res .= "\n<tr style='background-color: " . |
|
| 714 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | - "'><td align='right'>$i</td><td>\n" . |
|
| 716 | - "<a class='debug_link_boucle' href='" . |
|
| 717 | - $self2 . |
|
| 718 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | - _T('zbug_boucle') . |
|
| 720 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | - $self2 . |
|
| 722 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | - _T('zbug_resultat') . |
|
| 724 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | - $self2 . |
|
| 726 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | - _T('zbug_code') . |
|
| 728 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | - "'>" . |
|
| 731 | - _T('zbug_calcul') . |
|
| 732 | - "</a></td><td>\n" . |
|
| 733 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | - "</td><td>\n" . |
|
| 735 | - $req . |
|
| 736 | - "</td><td>\n" . |
|
| 737 | - spip_htmlspecialchars($crit) . |
|
| 708 | + $self2 = $self."&var_mode_objet=".$objet; |
|
| 709 | + |
|
| 710 | + $res .= "\n<tr style='background-color: ". |
|
| 711 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 712 | + "'><td align='right'>$i</td><td>\n". |
|
| 713 | + "<a class='debug_link_boucle' href='". |
|
| 714 | + $self2. |
|
| 715 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 716 | + _T('zbug_boucle'). |
|
| 717 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 718 | + $self2. |
|
| 719 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 720 | + _T('zbug_resultat'). |
|
| 721 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 722 | + $self2. |
|
| 723 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 724 | + _T('zbug_code'). |
|
| 725 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 726 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 727 | + "'>". |
|
| 728 | + _T('zbug_calcul'). |
|
| 729 | + "</a></td><td>\n". |
|
| 730 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 731 | + "</td><td>\n". |
|
| 732 | + $req. |
|
| 733 | + "</td><td>\n". |
|
| 734 | + spip_htmlspecialchars($crit). |
|
| 738 | 735 | "</td></tr>"; |
| 739 | 736 | } |
| 740 | 737 | } |
@@ -761,7 +758,7 @@ discard block |
||
| 761 | 758 | } |
| 762 | 759 | // permettre le copier/coller facile |
| 763 | 760 | // $res = ancre_texte($req, array(), true); |
| 764 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 761 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 765 | 762 | // formatage et affichage des resultats bruts de la requete |
| 766 | 763 | $ress_req = spip_query($req); |
| 767 | 764 | $brut_sql = ''; |
@@ -771,10 +768,10 @@ discard block |
||
| 771 | 768 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 772 | 769 | while ($retours_sql = sql_fetch($ress_req)) { |
| 773 | 770 | if ($num <= $max_aff) { |
| 774 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 771 | + $brut_sql .= "<h3>".($num == 1 ? $num." sur ".sql_count($ress_req) : $num)."</h3>"; |
|
| 775 | 772 | $brut_sql .= "<p>"; |
| 776 | 773 | foreach ($retours_sql as $key => $val) { |
| 777 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 774 | + $brut_sql .= "<strong>".$key."</strong> => ".spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 778 | 775 | } |
| 779 | 776 | $brut_sql .= "</p>"; |
| 780 | 777 | } |
@@ -785,15 +782,15 @@ discard block |
||
| 785 | 782 | // ne pas afficher les $contexte_inclus |
| 786 | 783 | $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
| 787 | 784 | if ($view) { |
| 788 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 785 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view)."</fieldset>"; |
|
| 789 | 786 | } |
| 790 | 787 | } |
| 791 | 788 | |
| 792 | 789 | } elseif ($affiche == 'code') { |
| 793 | 790 | $legend = $nom; |
| 794 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 791 | + $res = ancre_texte("<"."?php\n".$quoi."\n?".">"); |
|
| 795 | 792 | } elseif ($affiche == 'boucle') { |
| 796 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 793 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 797 | 794 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 798 | 795 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 799 | 796 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -812,23 +809,23 @@ discard block |
||
| 812 | 809 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 813 | 810 | include_spip('inc/texte'); // pour corriger_typo |
| 814 | 811 | |
| 815 | - return _DOCTYPE_ECRIRE . |
|
| 816 | - html_lang_attributes() . |
|
| 817 | - "<head>\n<title>" . |
|
| 818 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | - ")</title>\n" . |
|
| 822 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | - "' />\n" . |
|
| 812 | + return _DOCTYPE_ECRIRE. |
|
| 813 | + html_lang_attributes(). |
|
| 814 | + "<head>\n<title>". |
|
| 815 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 816 | + _T('admin_debug').' '.$titre.' ('. |
|
| 817 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 818 | + ")</title>\n". |
|
| 819 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 820 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 821 | + "' />\n". |
|
| 825 | 822 | http_script('', 'jquery.js') |
| 826 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | - . "' type='text/css' />" . |
|
| 828 | - "</head>\n" . |
|
| 829 | - "<body style='margin:0 10px;'>\n" . |
|
| 830 | - "<div id='spip-debug-header'>" . |
|
| 831 | - $corps . |
|
| 832 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 823 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 824 | + . "' type='text/css' />". |
|
| 825 | + "</head>\n". |
|
| 826 | + "<body style='margin:0 10px;'>\n". |
|
| 827 | + "<div id='spip-debug-header'>". |
|
| 828 | + $corps. |
|
| 829 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 833 | 830 | '</div></body></html>'; |
| 834 | 831 | } |
@@ -362,9 +362,11 @@ discard block |
||
| 362 | 362 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
| 363 | 363 | $y = substr_count($v[0], "\n"); |
| 364 | 364 | } else { |
| 365 | - if ($v[1][0] == '#') // balise dynamique |
|
| 365 | + if ($v[1][0] == '#') { |
|
| 366 | + // balise dynamique |
|
| 366 | 367 | { |
| 367 | 368 | $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
| 369 | + } |
|
| 368 | 370 | } else // inclusion |
| 369 | 371 | { |
| 370 | 372 | $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
@@ -397,12 +399,14 @@ discard block |
||
| 397 | 399 | preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
| 398 | 400 | // si le script X.php n'est pas ecrire/public.php |
| 399 | 401 | // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
| 400 | - if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 402 | + if ($reg[1] == 'ecrire/public') { |
|
| 403 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | 404 | { |
| 402 | 405 | if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
| 403 | 406 | { |
| 404 | 407 | if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
| 405 | 408 | $reg[1] = "inconnu"; |
| 409 | + } |
|
| 406 | 410 | } |
| 407 | 411 | } |
| 408 | 412 | } |