@@ -184,6 +184,9 @@ |
||
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | // http://doc.spip.org/@install_premier_auteur |
| 187 | +/** |
|
| 188 | + * @param string $hidden |
|
| 189 | + */ |
|
| 187 | 190 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) |
| 188 | 191 | { |
| 189 | 192 | return info_progression_etape(3,'etape_','install/') . |
@@ -17,306 +17,306 @@ |
||
| 17 | 17 | |
| 18 | 18 | // http://doc.spip.org/@install_bases |
| 19 | 19 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db){ |
| 20 | - global $spip_version_base; |
|
| 21 | - |
|
| 22 | - // Prefix des tables : |
|
| 23 | - // contrairement a ce qui est dit dans le message (trop strict mais c'est |
|
| 24 | - // pour notre bien), on va tolerer les chiffres en plus des minuscules |
|
| 25 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 26 | - // a partir de ce qui est envoye a l'installation |
|
| 27 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 28 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 29 | - ? $GLOBALS['table_prefix'] |
|
| 30 | - : trim(preg_replace(',[^a-z0-9],','',strtolower(_request('tprefix')))); |
|
| 31 | - // S'il est vide on remet spip |
|
| 32 | - if (!$table_prefix) |
|
| 33 | - $table_prefix = 'spip'; |
|
| 34 | - } else { |
|
| 35 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - $GLOBALS['connexions'][$server_db] |
|
| 39 | - = spip_connect_db($adresse_db, 0, $login_db, $pass_db, '', $server_db); |
|
| 40 | - |
|
| 41 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 42 | - = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 43 | - |
|
| 44 | - $fquery = sql_serveur('query', $server_db); |
|
| 45 | - if ($choix_db == "new_spip") { |
|
| 46 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 47 | - if (preg_match($re, $sel_db)) |
|
| 48 | - sql_create_base($sel_db, $server_db); |
|
| 49 | - else { |
|
| 50 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 51 | - spip_log($re); |
|
| 52 | - return "<p>"._T("avis_connexion_erreur_nom_base")."</p><!--\n$re\n-->"; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 57 | - // un sql_mode |
|
| 58 | - install_mode_appel($server_db, false); |
|
| 59 | - $GLOBALS['connexions'][$server_db] |
|
| 60 | - = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 61 | - |
|
| 62 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 63 | - = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 64 | - |
|
| 65 | - // Completer le tableau decrivant la connexion |
|
| 66 | - |
|
| 67 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 68 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 69 | - |
|
| 70 | - $old = sql_showbase($table_prefix . "_meta", $server_db); |
|
| 71 | - if ($old) $old = sql_fetch($old, $server_db); |
|
| 72 | - if (!$old) { |
|
| 73 | - |
|
| 74 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 75 | - // dans le codage std de SPIP, |
|
| 76 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 77 | - |
|
| 78 | - if ($charset) { |
|
| 79 | - sql_set_charset($charset['charset'], $server_db); |
|
| 80 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 81 | - $charset['charset']; |
|
| 82 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 83 | - $charset['collation']; |
|
| 84 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 85 | - $charset['charset']; |
|
| 86 | - $charsetbase = $charset['charset']; |
|
| 87 | - } else { |
|
| 88 | - spip_log(_DEFAULT_CHARSET . " inconnu du serveur SQL"); |
|
| 89 | - $charsetbase = 'standard'; |
|
| 90 | - } |
|
| 91 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 92 | - creer_base($server_db); // AT LAST |
|
| 93 | - // memoriser avec quel charset on l'a creee |
|
| 94 | - |
|
| 95 | - if ($charset) { |
|
| 96 | - $t = array('nom' => 'charset_sql_base', |
|
| 97 | - 'valeur' => $charset['charset'], |
|
| 98 | - 'impt' => 'non'); |
|
| 99 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 100 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 101 | - $t['valeur'] = $charset['collation']; |
|
| 102 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 103 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 104 | - $t['valeur'] = $charset['charset']; |
|
| 105 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 106 | - } |
|
| 107 | - $t = array('nom' => 'version_installee', |
|
| 108 | - 'valeur' => $spip_version_base, |
|
| 109 | - 'impt' => 'non'); |
|
| 110 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 111 | - $t['nom'] = 'nouvelle_install'; |
|
| 112 | - $t['valeur'] = 1; |
|
| 113 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 114 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 115 | - if (isset($_COOKIE['spip_lang_ecrire'])){ |
|
| 116 | - @sql_insertq('spip_meta', array('nom'=>'langue_site','valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - |
|
| 120 | - // pour recreer les tables disparues au besoin |
|
| 121 | - spip_log("Table des Meta deja la. Verification des autres."); |
|
| 122 | - creer_base($server_db); |
|
| 123 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 124 | - |
|
| 125 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 126 | - |
|
| 127 | - if ($r) $r = sql_fetch($r, $server_db); |
|
| 128 | - $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 129 | - if (!$version_installee OR ($spip_version_base < $version_installee)) { |
|
| 130 | - $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
|
| 131 | - spip_log("nouvelle version installee: $spip_version_base"); |
|
| 132 | - } |
|
| 133 | - // eliminer la derniere operation d'admin mal terminee |
|
| 134 | - // notamment la mise a jour |
|
| 135 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 139 | - |
|
| 140 | - $result_ok = @$fquery("SELECT COUNT(*) FROM spip_meta", $server_db); |
|
| 141 | - if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 142 | - |
|
| 143 | - if ($chmod_db) { |
|
| 144 | - install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
|
| 148 | - list(,$adresse_db, $port) = $r; |
|
| 149 | - else $port = ''; |
|
| 150 | - |
|
| 151 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 152 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 153 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 154 | - |
|
| 155 | - if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) |
|
| 156 | - spip_unlink(_FILE_CONNECT); |
|
| 157 | - |
|
| 158 | - install_fichier_connexion(_FILE_CONNECT_TMP, |
|
| 159 | - $ligne_rappel |
|
| 160 | - . install_connexion($adresse_db, |
|
| 161 | - $port, |
|
| 162 | - $login_db, |
|
| 163 | - $pass_db, |
|
| 164 | - $sel_db, |
|
| 165 | - $server_db, |
|
| 166 | - $table_prefix)); |
|
| 167 | - return ''; |
|
| 20 | + global $spip_version_base; |
|
| 21 | + |
|
| 22 | + // Prefix des tables : |
|
| 23 | + // contrairement a ce qui est dit dans le message (trop strict mais c'est |
|
| 24 | + // pour notre bien), on va tolerer les chiffres en plus des minuscules |
|
| 25 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 26 | + // a partir de ce qui est envoye a l'installation |
|
| 27 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 28 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 29 | + ? $GLOBALS['table_prefix'] |
|
| 30 | + : trim(preg_replace(',[^a-z0-9],','',strtolower(_request('tprefix')))); |
|
| 31 | + // S'il est vide on remet spip |
|
| 32 | + if (!$table_prefix) |
|
| 33 | + $table_prefix = 'spip'; |
|
| 34 | + } else { |
|
| 35 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + $GLOBALS['connexions'][$server_db] |
|
| 39 | + = spip_connect_db($adresse_db, 0, $login_db, $pass_db, '', $server_db); |
|
| 40 | + |
|
| 41 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 42 | + = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 43 | + |
|
| 44 | + $fquery = sql_serveur('query', $server_db); |
|
| 45 | + if ($choix_db == "new_spip") { |
|
| 46 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 47 | + if (preg_match($re, $sel_db)) |
|
| 48 | + sql_create_base($sel_db, $server_db); |
|
| 49 | + else { |
|
| 50 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 51 | + spip_log($re); |
|
| 52 | + return "<p>"._T("avis_connexion_erreur_nom_base")."</p><!--\n$re\n-->"; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 57 | + // un sql_mode |
|
| 58 | + install_mode_appel($server_db, false); |
|
| 59 | + $GLOBALS['connexions'][$server_db] |
|
| 60 | + = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 61 | + |
|
| 62 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 63 | + = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 64 | + |
|
| 65 | + // Completer le tableau decrivant la connexion |
|
| 66 | + |
|
| 67 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 68 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 69 | + |
|
| 70 | + $old = sql_showbase($table_prefix . "_meta", $server_db); |
|
| 71 | + if ($old) $old = sql_fetch($old, $server_db); |
|
| 72 | + if (!$old) { |
|
| 73 | + |
|
| 74 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 75 | + // dans le codage std de SPIP, |
|
| 76 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 77 | + |
|
| 78 | + if ($charset) { |
|
| 79 | + sql_set_charset($charset['charset'], $server_db); |
|
| 80 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 81 | + $charset['charset']; |
|
| 82 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 83 | + $charset['collation']; |
|
| 84 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 85 | + $charset['charset']; |
|
| 86 | + $charsetbase = $charset['charset']; |
|
| 87 | + } else { |
|
| 88 | + spip_log(_DEFAULT_CHARSET . " inconnu du serveur SQL"); |
|
| 89 | + $charsetbase = 'standard'; |
|
| 90 | + } |
|
| 91 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 92 | + creer_base($server_db); // AT LAST |
|
| 93 | + // memoriser avec quel charset on l'a creee |
|
| 94 | + |
|
| 95 | + if ($charset) { |
|
| 96 | + $t = array('nom' => 'charset_sql_base', |
|
| 97 | + 'valeur' => $charset['charset'], |
|
| 98 | + 'impt' => 'non'); |
|
| 99 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 100 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 101 | + $t['valeur'] = $charset['collation']; |
|
| 102 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 103 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 104 | + $t['valeur'] = $charset['charset']; |
|
| 105 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 106 | + } |
|
| 107 | + $t = array('nom' => 'version_installee', |
|
| 108 | + 'valeur' => $spip_version_base, |
|
| 109 | + 'impt' => 'non'); |
|
| 110 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 111 | + $t['nom'] = 'nouvelle_install'; |
|
| 112 | + $t['valeur'] = 1; |
|
| 113 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 114 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 115 | + if (isset($_COOKIE['spip_lang_ecrire'])){ |
|
| 116 | + @sql_insertq('spip_meta', array('nom'=>'langue_site','valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + |
|
| 120 | + // pour recreer les tables disparues au besoin |
|
| 121 | + spip_log("Table des Meta deja la. Verification des autres."); |
|
| 122 | + creer_base($server_db); |
|
| 123 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 124 | + |
|
| 125 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 126 | + |
|
| 127 | + if ($r) $r = sql_fetch($r, $server_db); |
|
| 128 | + $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 129 | + if (!$version_installee OR ($spip_version_base < $version_installee)) { |
|
| 130 | + $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
|
| 131 | + spip_log("nouvelle version installee: $spip_version_base"); |
|
| 132 | + } |
|
| 133 | + // eliminer la derniere operation d'admin mal terminee |
|
| 134 | + // notamment la mise a jour |
|
| 135 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 139 | + |
|
| 140 | + $result_ok = @$fquery("SELECT COUNT(*) FROM spip_meta", $server_db); |
|
| 141 | + if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 142 | + |
|
| 143 | + if ($chmod_db) { |
|
| 144 | + install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
|
| 148 | + list(,$adresse_db, $port) = $r; |
|
| 149 | + else $port = ''; |
|
| 150 | + |
|
| 151 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 152 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 153 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 154 | + |
|
| 155 | + if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) |
|
| 156 | + spip_unlink(_FILE_CONNECT); |
|
| 157 | + |
|
| 158 | + install_fichier_connexion(_FILE_CONNECT_TMP, |
|
| 159 | + $ligne_rappel |
|
| 160 | + . install_connexion($adresse_db, |
|
| 161 | + $port, |
|
| 162 | + $login_db, |
|
| 163 | + $pass_db, |
|
| 164 | + $sel_db, |
|
| 165 | + $server_db, |
|
| 166 | + $table_prefix)); |
|
| 167 | + return ''; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // http://doc.spip.org/@install_propose_ldap |
| 171 | 171 | function install_propose_ldap() |
| 172 | 172 | { |
| 173 | - return generer_form_ecrire('install', ( |
|
| 174 | - fieldset(_T('info_authentification_externe'), |
|
| 175 | - array( |
|
| 176 | - 'etape' => array( |
|
| 177 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 178 | - 'valeur' => 'ldap1', |
|
| 179 | - 'hidden' => true |
|
| 180 | - )), |
|
| 181 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 182 | - ))); |
|
| 173 | + return generer_form_ecrire('install', ( |
|
| 174 | + fieldset(_T('info_authentification_externe'), |
|
| 175 | + array( |
|
| 176 | + 'etape' => array( |
|
| 177 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 178 | + 'valeur' => 'ldap1', |
|
| 179 | + 'hidden' => true |
|
| 180 | + )), |
|
| 181 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 182 | + ))); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | // http://doc.spip.org/@install_premier_auteur |
| 187 | 187 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) |
| 188 | 188 | { |
| 189 | - return info_progression_etape(3,'etape_','install/') . |
|
| 190 | - info_etape(_T('info_informations_personnelles'), |
|
| 191 | - |
|
| 192 | - "<b>"._T('texte_informations_personnelles_1')."</b>" . |
|
| 193 | - aide ("install5", true) . |
|
| 194 | - "<p>" . |
|
| 195 | - ($auteur_obligatoire? |
|
| 196 | - '' |
|
| 197 | - : |
|
| 198 | - _T('texte_informations_personnelles_2') . " " . _T('info_laisser_champs_vides') |
|
| 199 | - )) |
|
| 200 | - . generer_form_ecrire('install', ( |
|
| 201 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 202 | - . $hidden |
|
| 203 | - . fieldset(_T('info_identification_publique'), |
|
| 204 | - array( |
|
| 205 | - 'nom' => array( |
|
| 206 | - 'label' => "<b>"._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 207 | - 'valeur' => $nom, |
|
| 208 | - 'required' => $auteur_obligatoire, |
|
| 209 | - ), |
|
| 210 | - 'email' => array( |
|
| 211 | - 'label' => "<b>"._T('entree_adresse_email')."</b>\n", |
|
| 212 | - 'valeur' => $email, |
|
| 213 | - ) |
|
| 214 | - ) |
|
| 215 | - ) |
|
| 216 | - |
|
| 217 | - . fieldset(_T('entree_identifiants_connexion'), |
|
| 218 | - array( |
|
| 219 | - 'login' => array( |
|
| 220 | - 'label' => "<b>"._T('entree_login')."</b><br />\n"._T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT))."\n", |
|
| 221 | - 'valeur' => $login, |
|
| 222 | - 'required' => $auteur_obligatoire, |
|
| 223 | - ), |
|
| 224 | - 'pass' => array( |
|
| 225 | - 'label' => "<b>"._T('entree_mot_passe')."</b><br />\n"._T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI))."\n", |
|
| 226 | - 'valeur' => $pass, |
|
| 227 | - 'required' => $auteur_obligatoire, |
|
| 228 | - ), |
|
| 229 | - 'pass_verif' => array( |
|
| 230 | - 'label' => "<b>"._T('info_confirmer_passe')."</b><br />\n", |
|
| 231 | - 'valeur' => $pass, |
|
| 232 | - 'required' => $auteur_obligatoire, |
|
| 233 | - ) |
|
| 234 | - ) |
|
| 235 | - ) |
|
| 236 | - . bouton_suivant())); |
|
| 189 | + return info_progression_etape(3,'etape_','install/') . |
|
| 190 | + info_etape(_T('info_informations_personnelles'), |
|
| 191 | + |
|
| 192 | + "<b>"._T('texte_informations_personnelles_1')."</b>" . |
|
| 193 | + aide ("install5", true) . |
|
| 194 | + "<p>" . |
|
| 195 | + ($auteur_obligatoire? |
|
| 196 | + '' |
|
| 197 | + : |
|
| 198 | + _T('texte_informations_personnelles_2') . " " . _T('info_laisser_champs_vides') |
|
| 199 | + )) |
|
| 200 | + . generer_form_ecrire('install', ( |
|
| 201 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 202 | + . $hidden |
|
| 203 | + . fieldset(_T('info_identification_publique'), |
|
| 204 | + array( |
|
| 205 | + 'nom' => array( |
|
| 206 | + 'label' => "<b>"._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 207 | + 'valeur' => $nom, |
|
| 208 | + 'required' => $auteur_obligatoire, |
|
| 209 | + ), |
|
| 210 | + 'email' => array( |
|
| 211 | + 'label' => "<b>"._T('entree_adresse_email')."</b>\n", |
|
| 212 | + 'valeur' => $email, |
|
| 213 | + ) |
|
| 214 | + ) |
|
| 215 | + ) |
|
| 216 | + |
|
| 217 | + . fieldset(_T('entree_identifiants_connexion'), |
|
| 218 | + array( |
|
| 219 | + 'login' => array( |
|
| 220 | + 'label' => "<b>"._T('entree_login')."</b><br />\n"._T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT))."\n", |
|
| 221 | + 'valeur' => $login, |
|
| 222 | + 'required' => $auteur_obligatoire, |
|
| 223 | + ), |
|
| 224 | + 'pass' => array( |
|
| 225 | + 'label' => "<b>"._T('entree_mot_passe')."</b><br />\n"._T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI))."\n", |
|
| 226 | + 'valeur' => $pass, |
|
| 227 | + 'required' => $auteur_obligatoire, |
|
| 228 | + ), |
|
| 229 | + 'pass_verif' => array( |
|
| 230 | + 'label' => "<b>"._T('info_confirmer_passe')."</b><br />\n", |
|
| 231 | + 'valeur' => $pass, |
|
| 232 | + 'required' => $auteur_obligatoire, |
|
| 233 | + ) |
|
| 234 | + ) |
|
| 235 | + ) |
|
| 236 | + . bouton_suivant())); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // http://doc.spip.org/@install_etape_3_dist |
| 240 | 240 | function install_etape_3_dist() |
| 241 | 241 | { |
| 242 | - $ldap_present = _request('ldap_present'); |
|
| 242 | + $ldap_present = _request('ldap_present'); |
|
| 243 | 243 | |
| 244 | - if (!$ldap_present) { |
|
| 245 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 246 | - ? _INSTALL_HOST_DB |
|
| 247 | - : _request('adresse_db'); |
|
| 244 | + if (!$ldap_present) { |
|
| 245 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 246 | + ? _INSTALL_HOST_DB |
|
| 247 | + : _request('adresse_db'); |
|
| 248 | 248 | |
| 249 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 250 | - ? _INSTALL_USER_DB |
|
| 251 | - : _request('login_db'); |
|
| 249 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 250 | + ? _INSTALL_USER_DB |
|
| 251 | + : _request('login_db'); |
|
| 252 | 252 | |
| 253 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 254 | - ? _INSTALL_PASS_DB |
|
| 255 | - : _request('pass_db'); |
|
| 253 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 254 | + ? _INSTALL_PASS_DB |
|
| 255 | + : _request('pass_db'); |
|
| 256 | 256 | |
| 257 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 258 | - ? _INSTALL_SERVER_DB |
|
| 259 | - : _request('server_db'); |
|
| 257 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 258 | + ? _INSTALL_SERVER_DB |
|
| 259 | + : _request('server_db'); |
|
| 260 | 260 | |
| 261 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 262 | - ? _SPIP_CHMOD |
|
| 263 | - : _request('chmod'); |
|
| 261 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 262 | + ? _SPIP_CHMOD |
|
| 263 | + : _request('chmod'); |
|
| 264 | 264 | |
| 265 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 266 | - ? _INSTALL_NAME_DB |
|
| 267 | - : _request('choix_db'); |
|
| 265 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 266 | + ? _INSTALL_NAME_DB |
|
| 267 | + : _request('choix_db'); |
|
| 268 | 268 | |
| 269 | - $sel_db = ($choix_db == "new_spip") |
|
| 270 | - ? _request('table_new') : $choix_db; |
|
| 269 | + $sel_db = ($choix_db == "new_spip") |
|
| 270 | + ? _request('table_new') : $choix_db; |
|
| 271 | 271 | |
| 272 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 272 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 273 | 273 | |
| 274 | - if ($res) { |
|
| 275 | - $res = info_progression_etape(2,'etape_','install/', true) |
|
| 276 | - . "<div class='error'><h3>"._T('avis_operation_echec')."</h3>" |
|
| 277 | - . $res |
|
| 278 | - . "<p>"._T('texte_operation_echec')."</p>" |
|
| 279 | - . "</div>"; |
|
| 280 | - } |
|
| 274 | + if ($res) { |
|
| 275 | + $res = info_progression_etape(2,'etape_','install/', true) |
|
| 276 | + . "<div class='error'><h3>"._T('avis_operation_echec')."</h3>" |
|
| 277 | + . $res |
|
| 278 | + . "<p>"._T('texte_operation_echec')."</p>" |
|
| 279 | + . "</div>"; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - } else { |
|
| 283 | - $res = ''; |
|
| 284 | - list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 285 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$res) { |
|
| 289 | - if (file_exists(_FILE_CONNECT_TMP)) |
|
| 290 | - include(_FILE_CONNECT_TMP); |
|
| 291 | - else |
|
| 292 | - redirige_url_ecrire('install'); |
|
| 282 | + } else { |
|
| 283 | + $res = ''; |
|
| 284 | + list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 285 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$res) { |
|
| 289 | + if (file_exists(_FILE_CONNECT_TMP)) |
|
| 290 | + include(_FILE_CONNECT_TMP); |
|
| 291 | + else |
|
| 292 | + redirige_url_ecrire('install'); |
|
| 293 | 293 | |
| 294 | - if (file_exists(_FILE_CHMOD_TMP)) |
|
| 295 | - include(_FILE_CHMOD_TMP); |
|
| 296 | - else |
|
| 297 | - redirige_url_ecrire('install'); |
|
| 298 | - |
|
| 299 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 300 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 301 | - : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 302 | - |
|
| 303 | - $auteur_obligatoire = ($ldap_present?0:!sql_countsel('spip_auteurs','','','',$server_db)); |
|
| 304 | - |
|
| 305 | - $res = "<div class='success'><b>" |
|
| 306 | - . _T('info_base_installee') |
|
| 307 | - . "</b></div>" |
|
| 308 | - . install_premier_auteur(_request('email'), |
|
| 309 | - _request('login'), |
|
| 310 | - _request('nom'), |
|
| 311 | - _request('pass'), |
|
| 312 | - $hidden, $auteur_obligatoire) |
|
| 313 | - . (($ldap_present OR !function_exists('ldap_connect')) |
|
| 314 | - ? '' : install_propose_ldap()); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - echo install_debut_html(); |
|
| 318 | - echo $res; |
|
| 319 | - echo install_fin_html(); |
|
| 294 | + if (file_exists(_FILE_CHMOD_TMP)) |
|
| 295 | + include(_FILE_CHMOD_TMP); |
|
| 296 | + else |
|
| 297 | + redirige_url_ecrire('install'); |
|
| 298 | + |
|
| 299 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 300 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 301 | + : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 302 | + |
|
| 303 | + $auteur_obligatoire = ($ldap_present?0:!sql_countsel('spip_auteurs','','','',$server_db)); |
|
| 304 | + |
|
| 305 | + $res = "<div class='success'><b>" |
|
| 306 | + . _T('info_base_installee') |
|
| 307 | + . "</b></div>" |
|
| 308 | + . install_premier_auteur(_request('email'), |
|
| 309 | + _request('login'), |
|
| 310 | + _request('nom'), |
|
| 311 | + _request('pass'), |
|
| 312 | + $hidden, $auteur_obligatoire) |
|
| 313 | + . (($ldap_present OR !function_exists('ldap_connect')) |
|
| 314 | + ? '' : install_propose_ldap()); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + echo install_debut_html(); |
|
| 318 | + echo $res; |
|
| 319 | + echo install_fin_html(); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | ?> |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | include_spip('base/abstract_sql'); |
| 17 | 17 | |
| 18 | 18 | // http://doc.spip.org/@install_bases |
| 19 | -function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db){ |
|
| 19 | +function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
|
| 20 | 20 | global $spip_version_base; |
| 21 | 21 | |
| 22 | 22 | // Prefix des tables : |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | if (!defined('_INSTALL_TABLE_PREFIX')) { |
| 28 | 28 | $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
| 29 | 29 | ? $GLOBALS['table_prefix'] |
| 30 | - : trim(preg_replace(',[^a-z0-9],','',strtolower(_request('tprefix')))); |
|
| 30 | + : trim(preg_replace(',[^a-z0-9],', '', strtolower(_request('tprefix')))); |
|
| 31 | 31 | // S'il est vide on remet spip |
| 32 | 32 | if (!$table_prefix) |
| 33 | 33 | $table_prefix = 'spip'; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | = spip_connect_db($adresse_db, 0, $login_db, $pass_db, '', $server_db); |
| 40 | 40 | |
| 41 | 41 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 42 | - = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 42 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 43 | 43 | |
| 44 | 44 | $fquery = sql_serveur('query', $server_db); |
| 45 | 45 | if ($choix_db == "new_spip") { |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
| 61 | 61 | |
| 62 | 62 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 63 | - = $GLOBALS['spip_' . $server_db .'_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 63 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 64 | 64 | |
| 65 | 65 | // Completer le tableau decrivant la connexion |
| 66 | 66 | |
| 67 | 67 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 68 | 68 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 69 | 69 | |
| 70 | - $old = sql_showbase($table_prefix . "_meta", $server_db); |
|
| 70 | + $old = sql_showbase($table_prefix."_meta", $server_db); |
|
| 71 | 71 | if ($old) $old = sql_fetch($old, $server_db); |
| 72 | 72 | if (!$old) { |
| 73 | 73 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $charset['charset']; |
| 86 | 86 | $charsetbase = $charset['charset']; |
| 87 | 87 | } else { |
| 88 | - spip_log(_DEFAULT_CHARSET . " inconnu du serveur SQL"); |
|
| 88 | + spip_log(_DEFAULT_CHARSET." inconnu du serveur SQL"); |
|
| 89 | 89 | $charsetbase = 'standard'; |
| 90 | 90 | } |
| 91 | 91 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | $t['valeur'] = 1; |
| 113 | 113 | @sql_insertq('spip_meta', $t, '', $server_db); |
| 114 | 114 | // positionner la langue par defaut du site si un cookie de lang a ete mis |
| 115 | - if (isset($_COOKIE['spip_lang_ecrire'])){ |
|
| 116 | - @sql_insertq('spip_meta', array('nom'=>'langue_site','valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
|
| 115 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 116 | + @sql_insertq('spip_meta', array('nom'=>'langue_site', 'valeur'=>$_COOKIE['spip_lang_ecrire']), '', $server_db); |
|
| 117 | 117 | } |
| 118 | 118 | } else { |
| 119 | 119 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | if ($r) $r = sql_fetch($r, $server_db); |
| 128 | 128 | $version_installee = !$r ? 0 : (double) $r['valeur']; |
| 129 | 129 | if (!$version_installee OR ($spip_version_base < $version_installee)) { |
| 130 | - $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
|
| 130 | + $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'", '', $server_db); |
|
| 131 | 131 | spip_log("nouvelle version installee: $spip_version_base"); |
| 132 | 132 | } |
| 133 | 133 | // eliminer la derniere operation d'admin mal terminee |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
| 142 | 142 | |
| 143 | 143 | if ($chmod_db) { |
| 144 | - install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
|
| 144 | + install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
@@ -186,16 +186,16 @@ discard block |
||
| 186 | 186 | // http://doc.spip.org/@install_premier_auteur |
| 187 | 187 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) |
| 188 | 188 | { |
| 189 | - return info_progression_etape(3,'etape_','install/') . |
|
| 189 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 190 | 190 | info_etape(_T('info_informations_personnelles'), |
| 191 | 191 | |
| 192 | - "<b>"._T('texte_informations_personnelles_1')."</b>" . |
|
| 193 | - aide ("install5", true) . |
|
| 194 | - "<p>" . |
|
| 195 | - ($auteur_obligatoire? |
|
| 192 | + "<b>"._T('texte_informations_personnelles_1')."</b>". |
|
| 193 | + aide("install5", true). |
|
| 194 | + "<p>". |
|
| 195 | + ($auteur_obligatoire ? |
|
| 196 | 196 | '' |
| 197 | 197 | : |
| 198 | - _T('texte_informations_personnelles_2') . " " . _T('info_laisser_champs_vides') |
|
| 198 | + _T('texte_informations_personnelles_2')." "._T('info_laisser_champs_vides') |
|
| 199 | 199 | )) |
| 200 | 200 | . generer_form_ecrire('install', ( |
| 201 | 201 | "\n<input type='hidden' name='etape' value='3b' />" |
@@ -269,10 +269,10 @@ discard block |
||
| 269 | 269 | $sel_db = ($choix_db == "new_spip") |
| 270 | 270 | ? _request('table_new') : $choix_db; |
| 271 | 271 | |
| 272 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 272 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 273 | 273 | |
| 274 | 274 | if ($res) { |
| 275 | - $res = info_progression_etape(2,'etape_','install/', true) |
|
| 275 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 276 | 276 | . "<div class='error'><h3>"._T('avis_operation_echec')."</h3>" |
| 277 | 277 | . $res |
| 278 | 278 | . "<p>"._T('texte_operation_echec')."</p>" |
@@ -300,9 +300,9 @@ discard block |
||
| 300 | 300 | . (defined('_INSTALL_NAME_DB') ? '' |
| 301 | 301 | : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
| 302 | 302 | |
| 303 | - $auteur_obligatoire = ($ldap_present?0:!sql_countsel('spip_auteurs','','','',$server_db)); |
|
| 303 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 304 | 304 | |
| 305 | - $res = "<div class='success'><b>" |
|
| 305 | + $res = "<div class='success'><b>" |
|
| 306 | 306 | . _T('info_base_installee') |
| 307 | 307 | . "</b></div>" |
| 308 | 308 | . install_premier_auteur(_request('email'), |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | _request('nom'), |
| 311 | 311 | _request('pass'), |
| 312 | 312 | $hidden, $auteur_obligatoire) |
| 313 | - . (($ldap_present OR !function_exists('ldap_connect')) |
|
| 314 | - ? '' : install_propose_ldap()); |
|
| 313 | + . (($ldap_present OR !function_exists('ldap_connect')) |
|
| 314 | + ? '' : install_propose_ldap()); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | echo install_debut_html(); |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/headers'); |
| 16 | 18 | include_spip('base/abstract_sql'); |
@@ -29,8 +31,9 @@ discard block |
||
| 29 | 31 | ? $GLOBALS['table_prefix'] |
| 30 | 32 | : trim(preg_replace(',[^a-z0-9],','',strtolower(_request('tprefix')))); |
| 31 | 33 | // S'il est vide on remet spip |
| 32 | - if (!$table_prefix) |
|
| 33 | - $table_prefix = 'spip'; |
|
| 34 | + if (!$table_prefix) { |
|
| 35 | + $table_prefix = 'spip'; |
|
| 36 | + } |
|
| 34 | 37 | } else { |
| 35 | 38 | $table_prefix = _INSTALL_TABLE_PREFIX; |
| 36 | 39 | } |
@@ -44,9 +47,9 @@ discard block |
||
| 44 | 47 | $fquery = sql_serveur('query', $server_db); |
| 45 | 48 | if ($choix_db == "new_spip") { |
| 46 | 49 | $re = ',^[a-z_][a-z_0-9-]*$,i'; |
| 47 | - if (preg_match($re, $sel_db)) |
|
| 48 | - sql_create_base($sel_db, $server_db); |
|
| 49 | - else { |
|
| 50 | + if (preg_match($re, $sel_db)) { |
|
| 51 | + sql_create_base($sel_db, $server_db); |
|
| 52 | + } else { |
|
| 50 | 53 | $re = "Le nom de la base doit correspondre a $re"; |
| 51 | 54 | spip_log($re); |
| 52 | 55 | return "<p>"._T("avis_connexion_erreur_nom_base")."</p><!--\n$re\n-->"; |
@@ -68,7 +71,9 @@ discard block |
||
| 68 | 71 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 69 | 72 | |
| 70 | 73 | $old = sql_showbase($table_prefix . "_meta", $server_db); |
| 71 | - if ($old) $old = sql_fetch($old, $server_db); |
|
| 74 | + if ($old) { |
|
| 75 | + $old = sql_fetch($old, $server_db); |
|
| 76 | + } |
|
| 72 | 77 | if (!$old) { |
| 73 | 78 | |
| 74 | 79 | // Si possible, demander au serveur d'envoyer les textes |
@@ -124,7 +129,9 @@ discard block |
||
| 124 | 129 | |
| 125 | 130 | $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
| 126 | 131 | |
| 127 | - if ($r) $r = sql_fetch($r, $server_db); |
|
| 132 | + if ($r) { |
|
| 133 | + $r = sql_fetch($r, $server_db); |
|
| 134 | + } |
|
| 128 | 135 | $version_installee = !$r ? 0 : (double) $r['valeur']; |
| 129 | 136 | if (!$version_installee OR ($spip_version_base < $version_installee)) { |
| 130 | 137 | $fupdateq('spip_meta', array('valeur'=>$spip_version_base, 'impt'=>'non'), "nom='version_installee'",'', $server_db); |
@@ -138,22 +145,27 @@ discard block |
||
| 138 | 145 | $ligne_rappel = install_mode_appel($server_db); |
| 139 | 146 | |
| 140 | 147 | $result_ok = @$fquery("SELECT COUNT(*) FROM spip_meta", $server_db); |
| 141 | - if (!$result_ok) return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 148 | + if (!$result_ok) { |
|
| 149 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 150 | + } |
|
| 142 | 151 | |
| 143 | 152 | if ($chmod_db) { |
| 144 | 153 | install_fichier_connexion(_FILE_CHMOD_TMP, "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ". sprintf('0%3o',$chmod_db).");\n"); |
| 145 | 154 | } |
| 146 | 155 | |
| 147 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) |
|
| 148 | - list(,$adresse_db, $port) = $r; |
|
| 149 | - else $port = ''; |
|
| 156 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 157 | + list(,$adresse_db, $port) = $r; |
|
| 158 | + } else { |
|
| 159 | + $port = ''; |
|
| 160 | + } |
|
| 150 | 161 | |
| 151 | 162 | // si ce fichier existe a cette etape c'est qu'il provient |
| 152 | 163 | // d'une installation qui ne l'a pas cree correctement. |
| 153 | 164 | // Le supprimer pour que _FILE_CONNECT_TMP prime. |
| 154 | 165 | |
| 155 | - if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) |
|
| 156 | - spip_unlink(_FILE_CONNECT); |
|
| 166 | + if (_FILE_CONNECT AND file_exists(_FILE_CONNECT)) { |
|
| 167 | + spip_unlink(_FILE_CONNECT); |
|
| 168 | + } |
|
| 157 | 169 | |
| 158 | 170 | install_fichier_connexion(_FILE_CONNECT_TMP, |
| 159 | 171 | $ligne_rappel |
@@ -286,15 +298,17 @@ discard block |
||
| 286 | 298 | } |
| 287 | 299 | |
| 288 | 300 | if (!$res) { |
| 289 | - if (file_exists(_FILE_CONNECT_TMP)) |
|
| 290 | - include(_FILE_CONNECT_TMP); |
|
| 291 | - else |
|
| 292 | - redirige_url_ecrire('install'); |
|
| 301 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 302 | + include(_FILE_CONNECT_TMP); |
|
| 303 | + } else { |
|
| 304 | + redirige_url_ecrire('install'); |
|
| 305 | + } |
|
| 293 | 306 | |
| 294 | - if (file_exists(_FILE_CHMOD_TMP)) |
|
| 295 | - include(_FILE_CHMOD_TMP); |
|
| 296 | - else |
|
| 297 | - redirige_url_ecrire('install'); |
|
| 307 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 308 | + include(_FILE_CHMOD_TMP); |
|
| 309 | + } else { |
|
| 310 | + redirige_url_ecrire('install'); |
|
| 311 | + } |
|
| 298 | 312 | |
| 299 | 313 | $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
| 300 | 314 | . (defined('_INSTALL_NAME_DB') ? '' |
@@ -113,6 +113,9 @@ discard block |
||
| 113 | 113 | return $nom ? $nom : false; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | +/** |
|
| 117 | + * @param string $phpfile |
|
| 118 | + */ |
|
| 116 | 119 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) |
| 117 | 120 | { |
| 118 | 121 | |
@@ -135,6 +138,9 @@ discard block |
||
| 135 | 138 | |
| 136 | 139 | // Le squelette compile est-il trop vieux ? |
| 137 | 140 | // http://doc.spip.org/@squelette_obsolete |
| 141 | +/** |
|
| 142 | + * @param string $skel |
|
| 143 | + */ |
|
| 138 | 144 | function squelette_obsolete($skel, $squelette) { |
| 139 | 145 | static $date_change = null; |
| 140 | 146 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
@@ -470,6 +476,9 @@ discard block |
||
| 470 | 476 | return false; |
| 471 | 477 | } |
| 472 | 478 | // http://doc.spip.org/@remplace_sous_requete |
| 479 | +/** |
|
| 480 | + * @param string $sousrequete |
|
| 481 | + */ |
|
| 473 | 482 | function remplace_sous_requete($w,$sousrequete){ |
| 474 | 483 | if (is_array($w)) { |
| 475 | 484 | if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
@@ -33,93 +33,93 @@ discard block |
||
| 33 | 33 | // http://doc.spip.org/@public_composer_dist |
| 34 | 34 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect='') { |
| 35 | 35 | |
| 36 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 37 | - |
|
| 38 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 39 | - if (function_exists($nom)) return $nom; |
|
| 40 | - |
|
| 41 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
|
| 42 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 43 | - |
|
| 44 | - $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
|
| 45 | - |
|
| 46 | - // si squelette est deja compile et perenne, le charger |
|
| 47 | - if (!squelette_obsolete($phpfile, $source)){ |
|
| 48 | - include_once $phpfile; |
|
| 49 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 50 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 51 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 52 | - ## eval('?'.'>'.$skel_code); |
|
| 53 | - # spip_log($skel_code, 'comp') |
|
| 54 | - #} |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if (file_exists($lib = $squelette . '_fonctions'.'.php')){ |
|
| 58 | - include_once $lib; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 62 | - |
|
| 63 | - if (function_exists($nom)) return $nom; |
|
| 64 | - |
|
| 65 | - // charger le source, si possible, et compiler |
|
| 66 | - if (lire_fichier ($source, $skel)) { |
|
| 67 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 68 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 72 | - if (!$skel_code) return false; |
|
| 73 | - |
|
| 74 | - foreach($skel_code as $id => $boucle) { |
|
| 75 | - $f = $boucle->return; |
|
| 76 | - if (@eval("return true; $f ;") === false) { |
|
| 77 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 78 | - $msg = _T('zbug_erreur_compilation'); |
|
| 79 | - erreur_squelette($msg, $boucle); |
|
| 80 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 81 | - // mais prevenir que c'est mort |
|
| 82 | - $nom = ''; |
|
| 83 | - } |
|
| 84 | - // Contexte de compil inutile a present |
|
| 85 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 86 | - $skel_code[$id] = $f; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if ($nom) { |
|
| 90 | - // Si le code est bon, concatener et mettre en cache |
|
| 91 | - if (function_exists($nom)) |
|
| 92 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 93 | - else { |
|
| 94 | - // code semantiquement faux: bug du compilateur |
|
| 95 | - // $boucle est en fait ici la fct principale du squelette |
|
| 96 | - $msg = _T('zbug_erreur_compilation'); |
|
| 97 | - erreur_squelette($msg, $boucle); |
|
| 98 | - $nom = ''; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 103 | - |
|
| 104 | - // Tracer ce qui vient d'etre compile |
|
| 105 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 106 | - |
|
| 107 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 108 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 109 | - AND (_request('var_mode_objet') == $nom) |
|
| 110 | - AND (_request('var_mode_affiche') == 'code') ) |
|
| 111 | - erreur_squelette(); |
|
| 112 | - } |
|
| 113 | - return $nom ? $nom : false; |
|
| 36 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 37 | + |
|
| 38 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 39 | + if (function_exists($nom)) return $nom; |
|
| 40 | + |
|
| 41 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
|
| 42 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 43 | + |
|
| 44 | + $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
|
| 45 | + |
|
| 46 | + // si squelette est deja compile et perenne, le charger |
|
| 47 | + if (!squelette_obsolete($phpfile, $source)){ |
|
| 48 | + include_once $phpfile; |
|
| 49 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 50 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 51 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 52 | + ## eval('?'.'>'.$skel_code); |
|
| 53 | + # spip_log($skel_code, 'comp') |
|
| 54 | + #} |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if (file_exists($lib = $squelette . '_fonctions'.'.php')){ |
|
| 58 | + include_once $lib; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 62 | + |
|
| 63 | + if (function_exists($nom)) return $nom; |
|
| 64 | + |
|
| 65 | + // charger le source, si possible, et compiler |
|
| 66 | + if (lire_fichier ($source, $skel)) { |
|
| 67 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 68 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 72 | + if (!$skel_code) return false; |
|
| 73 | + |
|
| 74 | + foreach($skel_code as $id => $boucle) { |
|
| 75 | + $f = $boucle->return; |
|
| 76 | + if (@eval("return true; $f ;") === false) { |
|
| 77 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 78 | + $msg = _T('zbug_erreur_compilation'); |
|
| 79 | + erreur_squelette($msg, $boucle); |
|
| 80 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 81 | + // mais prevenir que c'est mort |
|
| 82 | + $nom = ''; |
|
| 83 | + } |
|
| 84 | + // Contexte de compil inutile a present |
|
| 85 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 86 | + $skel_code[$id] = $f; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if ($nom) { |
|
| 90 | + // Si le code est bon, concatener et mettre en cache |
|
| 91 | + if (function_exists($nom)) |
|
| 92 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 93 | + else { |
|
| 94 | + // code semantiquement faux: bug du compilateur |
|
| 95 | + // $boucle est en fait ici la fct principale du squelette |
|
| 96 | + $msg = _T('zbug_erreur_compilation'); |
|
| 97 | + erreur_squelette($msg, $boucle); |
|
| 98 | + $nom = ''; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 103 | + |
|
| 104 | + // Tracer ce qui vient d'etre compile |
|
| 105 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 106 | + |
|
| 107 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 108 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 109 | + AND (_request('var_mode_objet') == $nom) |
|
| 110 | + AND (_request('var_mode_affiche') == 'code') ) |
|
| 111 | + erreur_squelette(); |
|
| 112 | + } |
|
| 113 | + return $nom ? $nom : false; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) |
| 117 | 117 | { |
| 118 | 118 | |
| 119 | - // Le dernier index est '' (fonction principale) |
|
| 120 | - $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
|
| 121 | - if (CODE_COMMENTE) |
|
| 122 | - $code = " |
|
| 119 | + // Le dernier index est '' (fonction principale) |
|
| 120 | + $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
|
| 121 | + if (CODE_COMMENTE) |
|
| 122 | + $code = " |
|
| 123 | 123 | /* |
| 124 | 124 | * Squelette : $sourcefile |
| 125 | 125 | * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
@@ -127,97 +127,97 @@ discard block |
||
| 127 | 127 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) ." |
| 128 | 128 | */ " ; |
| 129 | 129 | |
| 130 | - $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
|
| 131 | - if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
|
| 132 | - ecrire_fichier($phpfile, $code); |
|
| 133 | - return $code; |
|
| 130 | + $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
|
| 131 | + if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
|
| 132 | + ecrire_fichier($phpfile, $code); |
|
| 133 | + return $code; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Le squelette compile est-il trop vieux ? |
| 137 | 137 | // http://doc.spip.org/@squelette_obsolete |
| 138 | 138 | function squelette_obsolete($skel, $squelette) { |
| 139 | - static $date_change = null; |
|
| 140 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 141 | - // par hit |
|
| 142 | - if (is_null($date_change)){ |
|
| 143 | - if (@file_exists($fonc = 'mes_fonctions.php')) |
|
| 144 | - $date_change = @filemtime($fonc); # compatibilite |
|
| 145 | - if (defined('_FILE_OPTIONS')) |
|
| 146 | - $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 147 | - } |
|
| 148 | - return ( |
|
| 149 | - (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
|
| 150 | - OR !@file_exists($skel) |
|
| 151 | - OR ((@file_exists($squelette)?@filemtime($squelette):0) |
|
| 152 | - > ($date = @filemtime($skel))) |
|
| 153 | - OR ($date_change > $date) |
|
| 154 | - ); |
|
| 139 | + static $date_change = null; |
|
| 140 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 141 | + // par hit |
|
| 142 | + if (is_null($date_change)){ |
|
| 143 | + if (@file_exists($fonc = 'mes_fonctions.php')) |
|
| 144 | + $date_change = @filemtime($fonc); # compatibilite |
|
| 145 | + if (defined('_FILE_OPTIONS')) |
|
| 146 | + $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 147 | + } |
|
| 148 | + return ( |
|
| 149 | + (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
|
| 150 | + OR !@file_exists($skel) |
|
| 151 | + OR ((@file_exists($squelette)?@filemtime($squelette):0) |
|
| 152 | + > ($date = @filemtime($skel))) |
|
| 153 | + OR ($date_change > $date) |
|
| 154 | + ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Activer l'invalideur de session |
| 158 | 158 | // http://doc.spip.org/@invalideur_session |
| 159 | 159 | function invalideur_session(&$Cache, $code=NULL) { |
| 160 | - $Cache['session']=spip_session(); |
|
| 161 | - return $code; |
|
| 160 | + $Cache['session']=spip_session(); |
|
| 161 | + return $code; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | // http://doc.spip.org/@analyse_resultat_skel |
| 166 | 166 | function analyse_resultat_skel($nom, $cache, $corps, $source='') { |
| 167 | - static $filtres = array(); |
|
| 168 | - $headers = array(); |
|
| 169 | - |
|
| 170 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 171 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 172 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 173 | - if (stripos($corps,'header')!==false |
|
| 174 | - AND preg_match_all( |
|
| 175 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 176 | - $corps, $regs, PREG_SET_ORDER)){ |
|
| 177 | - foreach ($regs as $r) { |
|
| 178 | - $corps = str_replace($r[0], '', $corps); |
|
| 179 | - # $j = Content-Type, et pas content-TYPE. |
|
| 180 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 181 | - |
|
| 182 | - if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | - $headers[$j].="|".$r[3]; |
|
| 184 | - else |
|
| 185 | - $headers[$j] = $r[3]; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 189 | - $process_ins = ( |
|
| 190 | - strpos($corps,'<'.'?') === false |
|
| 191 | - OR |
|
| 192 | - (strpos($corps,'<'.'?xml')!==false AND |
|
| 193 | - strpos(str_replace('<'.'?xml', '', $corps),'<'.'?') === false) |
|
| 194 | - ) |
|
| 195 | - ? 'html' |
|
| 196 | - : 'php'; |
|
| 197 | - |
|
| 198 | - $skel = array( |
|
| 199 | - 'squelette' => $nom, |
|
| 200 | - 'source' => $source, |
|
| 201 | - 'process_ins' => $process_ins, |
|
| 202 | - 'invalideurs' => $cache, |
|
| 203 | - 'entetes' => $headers, |
|
| 204 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 205 | - ); |
|
| 206 | - |
|
| 207 | - // traiter #FILTRE{} et filtres |
|
| 208 | - if (!isset($filtres[$nom])) { |
|
| 209 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes',array('args'=>$skel,'data'=>array())); |
|
| 210 | - } |
|
| 211 | - if (count($filtres[$nom]) OR (isset($headers['X-Spip-Filtre']) AND strlen($headers['X-Spip-Filtre']))) { |
|
| 212 | - include_spip('public/sandbox'); |
|
| 213 | - $corps = sandbox_filtrer_squelette($skel,$corps,strlen($headers['X-Spip-Filtre'])?explode('|', $headers['X-Spip-Filtre']):array(),$filtres[$nom]); |
|
| 214 | - unset($headers['X-Spip-Filtre']); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $skel['entetes'] = $headers; |
|
| 218 | - $skel['texte'] = $corps; |
|
| 219 | - |
|
| 220 | - return $skel; |
|
| 167 | + static $filtres = array(); |
|
| 168 | + $headers = array(); |
|
| 169 | + |
|
| 170 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 171 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 172 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 173 | + if (stripos($corps,'header')!==false |
|
| 174 | + AND preg_match_all( |
|
| 175 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 176 | + $corps, $regs, PREG_SET_ORDER)){ |
|
| 177 | + foreach ($regs as $r) { |
|
| 178 | + $corps = str_replace($r[0], '', $corps); |
|
| 179 | + # $j = Content-Type, et pas content-TYPE. |
|
| 180 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 181 | + |
|
| 182 | + if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | + $headers[$j].="|".$r[3]; |
|
| 184 | + else |
|
| 185 | + $headers[$j] = $r[3]; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 189 | + $process_ins = ( |
|
| 190 | + strpos($corps,'<'.'?') === false |
|
| 191 | + OR |
|
| 192 | + (strpos($corps,'<'.'?xml')!==false AND |
|
| 193 | + strpos(str_replace('<'.'?xml', '', $corps),'<'.'?') === false) |
|
| 194 | + ) |
|
| 195 | + ? 'html' |
|
| 196 | + : 'php'; |
|
| 197 | + |
|
| 198 | + $skel = array( |
|
| 199 | + 'squelette' => $nom, |
|
| 200 | + 'source' => $source, |
|
| 201 | + 'process_ins' => $process_ins, |
|
| 202 | + 'invalideurs' => $cache, |
|
| 203 | + 'entetes' => $headers, |
|
| 204 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 205 | + ); |
|
| 206 | + |
|
| 207 | + // traiter #FILTRE{} et filtres |
|
| 208 | + if (!isset($filtres[$nom])) { |
|
| 209 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes',array('args'=>$skel,'data'=>array())); |
|
| 210 | + } |
|
| 211 | + if (count($filtres[$nom]) OR (isset($headers['X-Spip-Filtre']) AND strlen($headers['X-Spip-Filtre']))) { |
|
| 212 | + include_spip('public/sandbox'); |
|
| 213 | + $corps = sandbox_filtrer_squelette($skel,$corps,strlen($headers['X-Spip-Filtre'])?explode('|', $headers['X-Spip-Filtre']):array(),$filtres[$nom]); |
|
| 214 | + unset($headers['X-Spip-Filtre']); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $skel['entetes'] = $headers; |
|
| 218 | + $skel['texte'] = $corps; |
|
| 219 | + |
|
| 220 | + return $skel; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // |
@@ -236,62 +236,62 @@ discard block |
||
| 236 | 236 | // |
| 237 | 237 | // http://doc.spip.org/@filtre_introduction_dist |
| 238 | 238 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect) { |
| 239 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 240 | - if (strlen($descriptif)) |
|
| 241 | - return propre($descriptif,$connect); |
|
| 242 | - |
|
| 243 | - // De preference ce qui est marque <intro>...</intro> |
|
| 244 | - $intro = ''; |
|
| 245 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 246 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 247 | - $zone = substr($texte, 0, $fin); |
|
| 248 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 249 | - if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") |
|
| 250 | - $zone = substr($zone, $deb + 7); |
|
| 251 | - $intro .= $zone; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 255 | - // qui inclus raccourcis et modeles |
|
| 256 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 257 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 258 | - // des surcharges et enrichissement de propre |
|
| 259 | - // couper doit se faire apres propre |
|
| 260 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 261 | - |
|
| 262 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 263 | - // large et en se mefiant des tableaux #1323 |
|
| 264 | - |
|
| 265 | - if (strlen($intro)) |
|
| 266 | - $texte = $intro; |
|
| 267 | - |
|
| 268 | - else |
|
| 269 | - if (strpos("\n".$texte, "\n|")===false |
|
| 270 | - AND strlen($texte) > 2.5*$longueur){ |
|
| 271 | - if (strpos($texte,"<multi")!==false) |
|
| 272 | - $texte = extraire_multi($texte); |
|
| 273 | - $texte = couper($texte, 2*$longueur); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // ne pas tenir compte des notes |
|
| 277 | - if ($notes = charger_fonction('notes', 'inc', true)) |
|
| 278 | - $notes('','empiler'); |
|
| 279 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 280 | - // dans l'introduction. |
|
| 281 | - $texte = supprime_img($texte, ''); |
|
| 282 | - $texte = propre($texte,$connect); |
|
| 283 | - if ($notes) |
|
| 284 | - $notes('','depiler'); |
|
| 285 | - |
|
| 286 | - if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 287 | - $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
|
| 288 | - |
|
| 289 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 290 | - if ($GLOBALS['toujours_paragrapher']) |
|
| 291 | - // Fermer les paragraphes |
|
| 292 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 293 | - |
|
| 294 | - return $texte; |
|
| 239 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 240 | + if (strlen($descriptif)) |
|
| 241 | + return propre($descriptif,$connect); |
|
| 242 | + |
|
| 243 | + // De preference ce qui est marque <intro>...</intro> |
|
| 244 | + $intro = ''; |
|
| 245 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 246 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 247 | + $zone = substr($texte, 0, $fin); |
|
| 248 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 249 | + if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") |
|
| 250 | + $zone = substr($zone, $deb + 7); |
|
| 251 | + $intro .= $zone; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 255 | + // qui inclus raccourcis et modeles |
|
| 256 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 257 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 258 | + // des surcharges et enrichissement de propre |
|
| 259 | + // couper doit se faire apres propre |
|
| 260 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 261 | + |
|
| 262 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 263 | + // large et en se mefiant des tableaux #1323 |
|
| 264 | + |
|
| 265 | + if (strlen($intro)) |
|
| 266 | + $texte = $intro; |
|
| 267 | + |
|
| 268 | + else |
|
| 269 | + if (strpos("\n".$texte, "\n|")===false |
|
| 270 | + AND strlen($texte) > 2.5*$longueur){ |
|
| 271 | + if (strpos($texte,"<multi")!==false) |
|
| 272 | + $texte = extraire_multi($texte); |
|
| 273 | + $texte = couper($texte, 2*$longueur); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // ne pas tenir compte des notes |
|
| 277 | + if ($notes = charger_fonction('notes', 'inc', true)) |
|
| 278 | + $notes('','empiler'); |
|
| 279 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 280 | + // dans l'introduction. |
|
| 281 | + $texte = supprime_img($texte, ''); |
|
| 282 | + $texte = propre($texte,$connect); |
|
| 283 | + if ($notes) |
|
| 284 | + $notes('','depiler'); |
|
| 285 | + |
|
| 286 | + if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 287 | + $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
|
| 288 | + |
|
| 289 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 290 | + if ($GLOBALS['toujours_paragrapher']) |
|
| 291 | + // Fermer les paragraphes |
|
| 292 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 293 | + |
|
| 294 | + return $texte; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // |
@@ -307,137 +307,137 @@ discard block |
||
| 307 | 307 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 308 | 308 | if ($lang_select) lang_select(); |
| 309 | 309 | ?' |
| 310 | - .'>'); |
|
| 310 | + .'>'); |
|
| 311 | 311 | |
| 312 | 312 | |
| 313 | 313 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 314 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 315 | - $file, |
|
| 316 | - $context_compil[4]?$context_compil[4]:'', |
|
| 317 | - $nom, |
|
| 318 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 319 | - join(', ', array_map('_q', $context_compil))); |
|
| 320 | - return $r; |
|
| 314 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 315 | + $file, |
|
| 316 | + $context_compil[4]?$context_compil[4]:'', |
|
| 317 | + $nom, |
|
| 318 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 319 | + join(', ', array_map('_q', $context_compil))); |
|
| 320 | + return $r; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // http://doc.spip.org/@argumenter_squelette |
| 324 | 324 | function argumenter_squelette($v) { |
| 325 | 325 | |
| 326 | - if (!is_array($v)) |
|
| 327 | - return "'" . texte_script($v) . "'"; |
|
| 328 | - else { |
|
| 329 | - $out = array(); |
|
| 330 | - foreach($v as $k=>$val) |
|
| 331 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 332 | - return 'array(' . join(", ", $out) . ')'; |
|
| 333 | - } |
|
| 326 | + if (!is_array($v)) |
|
| 327 | + return "'" . texte_script($v) . "'"; |
|
| 328 | + else { |
|
| 329 | + $out = array(); |
|
| 330 | + foreach($v as $k=>$val) |
|
| 331 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 332 | + return 'array(' . join(", ", $out) . ')'; |
|
| 333 | + } |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // verifier leurs arguments et filtres, et calculer le code a inclure |
| 337 | 337 | // http://doc.spip.org/@executer_balise_dynamique |
| 338 | 338 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 339 | - $p = strpos($nom,"_"); |
|
| 340 | - $nomfonction = $nom; |
|
| 341 | - $nomfonction_generique = substr($nom,0,$p+1); |
|
| 342 | - if (!$file = include_spip("balise/". strtolower($nomfonction))) { |
|
| 343 | - // pas de fichier associe, passer au traitement generique |
|
| 344 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 345 | - if ($file) { |
|
| 346 | - // et injecter en premier arg le nom de la balise |
|
| 347 | - array_unshift($args,$nom); |
|
| 348 | - // et passer sur la fonction generique pour la suite |
|
| 349 | - $nomfonction = $nomfonction_generique; |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 353 | - erreur_squelette($msg, $context_compil); |
|
| 354 | - return ''; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 358 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 359 | - |
|
| 360 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 361 | - |
|
| 362 | - if (!is_array($r)) return $r; |
|
| 363 | - |
|
| 364 | - // verifier que la fonction dyn est la, |
|
| 365 | - // sinon se replier sur la generique si elle existe |
|
| 366 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 367 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 368 | - if (function_exists('balise_' . $nomfonction_generique . '_dyn')) { |
|
| 369 | - // et lui injecter en premier arg le nom de la balise |
|
| 370 | - array_unshift($r,$nom); |
|
| 371 | - $nomfonction = $nomfonction_generique; |
|
| 372 | - } else { |
|
| 373 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 374 | - erreur_squelette($msg, $context_compil); |
|
| 375 | - return ''; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (!_DIR_RESTREINT) |
|
| 380 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 381 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 339 | + $p = strpos($nom,"_"); |
|
| 340 | + $nomfonction = $nom; |
|
| 341 | + $nomfonction_generique = substr($nom,0,$p+1); |
|
| 342 | + if (!$file = include_spip("balise/". strtolower($nomfonction))) { |
|
| 343 | + // pas de fichier associe, passer au traitement generique |
|
| 344 | + $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 345 | + if ($file) { |
|
| 346 | + // et injecter en premier arg le nom de la balise |
|
| 347 | + array_unshift($args,$nom); |
|
| 348 | + // et passer sur la fonction generique pour la suite |
|
| 349 | + $nomfonction = $nomfonction_generique; |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 353 | + erreur_squelette($msg, $context_compil); |
|
| 354 | + return ''; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 358 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 359 | + |
|
| 360 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 361 | + |
|
| 362 | + if (!is_array($r)) return $r; |
|
| 363 | + |
|
| 364 | + // verifier que la fonction dyn est la, |
|
| 365 | + // sinon se replier sur la generique si elle existe |
|
| 366 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 367 | + $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 368 | + if (function_exists('balise_' . $nomfonction_generique . '_dyn')) { |
|
| 369 | + // et lui injecter en premier arg le nom de la balise |
|
| 370 | + array_unshift($r,$nom); |
|
| 371 | + $nomfonction = $nomfonction_generique; |
|
| 372 | + } else { |
|
| 373 | + $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 374 | + erreur_squelette($msg, $context_compil); |
|
| 375 | + return ''; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (!_DIR_RESTREINT) |
|
| 380 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 381 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // http://doc.spip.org/@lister_objets_avec_logos |
| 385 | 385 | function lister_objets_avec_logos ($type) { |
| 386 | - global $formats_logos; |
|
| 387 | - $logos = array(); |
|
| 388 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 389 | - $type = '/' |
|
| 390 | - . type_du_logo($type) |
|
| 391 | - . "on(\d+)\.(" |
|
| 392 | - . join('|',$formats_logos) |
|
| 393 | - . ")$/"; |
|
| 394 | - |
|
| 395 | - if ($d = @opendir(_DIR_LOGOS)) { |
|
| 396 | - while($f = readdir($d)) { |
|
| 397 | - if (preg_match($type, $f, $r)) |
|
| 398 | - $logos[] = $r[1]; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - @closedir($d); |
|
| 402 | - return join(',',$logos); |
|
| 386 | + global $formats_logos; |
|
| 387 | + $logos = array(); |
|
| 388 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 389 | + $type = '/' |
|
| 390 | + . type_du_logo($type) |
|
| 391 | + . "on(\d+)\.(" |
|
| 392 | + . join('|',$formats_logos) |
|
| 393 | + . ")$/"; |
|
| 394 | + |
|
| 395 | + if ($d = @opendir(_DIR_LOGOS)) { |
|
| 396 | + while($f = readdir($d)) { |
|
| 397 | + if (preg_match($type, $f, $r)) |
|
| 398 | + $logos[] = $r[1]; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + @closedir($d); |
|
| 402 | + return join(',',$logos); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // fonction appelee par la balise #NOTES |
| 406 | 406 | // Renvoyer l'etat courant des notes, le purger et en preparer un nouveau |
| 407 | 407 | // http://doc.spip.org/@calculer_notes |
| 408 | 408 | function calculer_notes() { |
| 409 | - $r=''; |
|
| 410 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 411 | - $r = $notes(array()); |
|
| 412 | - $notes('','depiler'); |
|
| 413 | - $notes('','empiler'); |
|
| 414 | - } |
|
| 415 | - return $r; |
|
| 409 | + $r=''; |
|
| 410 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 411 | + $r = $notes(array()); |
|
| 412 | + $notes('','depiler'); |
|
| 413 | + $notes('','empiler'); |
|
| 414 | + } |
|
| 415 | + return $r; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Selectionner la langue de l'objet dans la boucle, sauf dans les |
| 419 | 419 | // cas ou il ne le faut pas :-) |
| 420 | 420 | function lang_select_public($lang, $lang_select, $titre=null) { |
| 421 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 422 | - if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
|
| 423 | - AND $lang_select !== 'oui') |
|
| 424 | - $lang = $GLOBALS['spip_lang']; |
|
| 425 | - |
|
| 426 | - // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 427 | - elseif (!strlen($lang)) |
|
| 428 | - $lang = $GLOBALS['spip_lang']; |
|
| 429 | - |
|
| 430 | - // Cas 3. l'objet est multilingue ! |
|
| 431 | - elseif ($lang_select !== 'oui' |
|
| 432 | - AND strlen($titre) > 10 |
|
| 433 | - AND strpos($titre, '<multi>') !== false |
|
| 434 | - AND strpos(echappe_html($titre), '<multi>') !== false) |
|
| 435 | - $lang = $GLOBALS['spip_lang']; |
|
| 436 | - |
|
| 437 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 438 | - lang_select($lang); |
|
| 439 | - |
|
| 440 | - return; |
|
| 421 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 422 | + if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
|
| 423 | + AND $lang_select !== 'oui') |
|
| 424 | + $lang = $GLOBALS['spip_lang']; |
|
| 425 | + |
|
| 426 | + // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 427 | + elseif (!strlen($lang)) |
|
| 428 | + $lang = $GLOBALS['spip_lang']; |
|
| 429 | + |
|
| 430 | + // Cas 3. l'objet est multilingue ! |
|
| 431 | + elseif ($lang_select !== 'oui' |
|
| 432 | + AND strlen($titre) > 10 |
|
| 433 | + AND strpos($titre, '<multi>') !== false |
|
| 434 | + AND strpos(echappe_html($titre), '<multi>') !== false) |
|
| 435 | + $lang = $GLOBALS['spip_lang']; |
|
| 436 | + |
|
| 437 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 438 | + lang_select($lang); |
|
| 439 | + |
|
| 440 | + return; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -445,48 +445,48 @@ discard block |
||
| 445 | 445 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 446 | 446 | // http://doc.spip.org/@nettoyer_env_doublons |
| 447 | 447 | function nettoyer_env_doublons($envd) { |
| 448 | - foreach ($envd as $table => $liste) { |
|
| 449 | - $n = ''; |
|
| 450 | - foreach(explode(',',$liste) as $val) { |
|
| 451 | - if ($a = intval($val) AND $val === strval($a)) |
|
| 452 | - $n.= ','.$val; |
|
| 453 | - } |
|
| 454 | - if (strlen($n)) |
|
| 455 | - $envd[$table] = $n; |
|
| 456 | - else |
|
| 457 | - unset($envd[$table]); |
|
| 458 | - } |
|
| 459 | - return $envd; |
|
| 448 | + foreach ($envd as $table => $liste) { |
|
| 449 | + $n = ''; |
|
| 450 | + foreach(explode(',',$liste) as $val) { |
|
| 451 | + if ($a = intval($val) AND $val === strval($a)) |
|
| 452 | + $n.= ','.$val; |
|
| 453 | + } |
|
| 454 | + if (strlen($n)) |
|
| 455 | + $envd[$table] = $n; |
|
| 456 | + else |
|
| 457 | + unset($envd[$table]); |
|
| 458 | + } |
|
| 459 | + return $envd; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // http://doc.spip.org/@match_self |
| 463 | 463 | function match_self($w){ |
| 464 | - if (is_string($w)) return false; |
|
| 465 | - if (is_array($w)) { |
|
| 466 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | - foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | - if ($m=match_self($sw)) return $m; |
|
| 469 | - } |
|
| 470 | - return false; |
|
| 464 | + if (is_string($w)) return false; |
|
| 465 | + if (is_array($w)) { |
|
| 466 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | + foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | + if ($m=match_self($sw)) return $m; |
|
| 469 | + } |
|
| 470 | + return false; |
|
| 471 | 471 | } |
| 472 | 472 | // http://doc.spip.org/@remplace_sous_requete |
| 473 | 473 | function remplace_sous_requete($w,$sousrequete){ |
| 474 | - if (is_array($w)) { |
|
| 475 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | - foreach($w as $k=>$sw) |
|
| 477 | - $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 478 | - } |
|
| 479 | - return $w; |
|
| 474 | + if (is_array($w)) { |
|
| 475 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | + foreach($w as $k=>$sw) |
|
| 477 | + $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 478 | + } |
|
| 479 | + return $w; |
|
| 480 | 480 | } |
| 481 | 481 | // http://doc.spip.org/@trouver_sous_requetes |
| 482 | 482 | function trouver_sous_requetes($where){ |
| 483 | - $where_simples = array(); |
|
| 484 | - $where_sous = array(); |
|
| 485 | - foreach($where as $k=>$w){ |
|
| 486 | - if (match_self($w)) $where_sous[$k] = $w; |
|
| 487 | - else $where_simples[$k] = $w; |
|
| 488 | - } |
|
| 489 | - return array($where_simples,$where_sous); |
|
| 483 | + $where_simples = array(); |
|
| 484 | + $where_sous = array(); |
|
| 485 | + foreach($where as $k=>$w){ |
|
| 486 | + if (match_self($w)) $where_sous[$k] = $w; |
|
| 487 | + else $where_simples[$k] = $w; |
|
| 488 | + } |
|
| 489 | + return array($where_simples,$where_sous); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -511,224 +511,224 @@ discard block |
||
| 511 | 511 | * @return resource |
| 512 | 512 | */ |
| 513 | 513 | function calculer_select ($select = array(), $from = array(), |
| 514 | - $from_type = array(), |
|
| 515 | - $where = array(), $join=array(), |
|
| 516 | - $groupby = array(), $orderby = array(), $limit = '', |
|
| 517 | - $having=array(), $table = '', $id = '', $serveur='', $requeter=true) { |
|
| 518 | - |
|
| 519 | - // retirer les criteres vides: |
|
| 520 | - // {X ?} avec X absent de l'URL |
|
| 521 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 522 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 523 | - $menage = false; |
|
| 524 | - foreach($where as $k => $v) { |
|
| 525 | - if (is_array($v)){ |
|
| 526 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 528 | - else $op = $v[0] ? $v[0] : $v; |
|
| 529 | - } else $op = $v; |
|
| 530 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 531 | - unset($where[$k]); |
|
| 532 | - $menage = true; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 537 | - $groupby = array_diff($groupby,array('')); |
|
| 538 | - |
|
| 539 | - // remplacer les sous requetes recursives au calcul |
|
| 540 | - list($where_simples,$where_sous) = trouver_sous_requetes($where); |
|
| 541 | - foreach($where_sous as $k=>$w) { |
|
| 542 | - $menage = true; |
|
| 543 | - // on recupere la sous requete |
|
| 544 | - $sous = match_self($w); |
|
| 545 | - if ($sous[0]=='SELF') { |
|
| 546 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 547 | - array_push($where_simples,$sous[2]); |
|
| 548 | - $wheresub = array($sous[2],'0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 549 | - $jsub = $join; |
|
| 550 | - // trouver les jointures utiles a |
|
| 551 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 552 | - // ie L1.objet='article' |
|
| 553 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 554 | - $i = 0; |
|
| 555 | - do { |
|
| 556 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 557 | - array($sous[1]." AS id"), |
|
| 558 | - $from, |
|
| 559 | - $from_type, |
|
| 560 | - $wheresub, |
|
| 561 | - $jsub, |
|
| 562 | - array(),array(),'', |
|
| 563 | - $having,$table,$id,$serveur,false).")"); |
|
| 564 | - if (!$i){ |
|
| 565 | - $i = 1; |
|
| 566 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 567 | - foreach ($join as $cle=>$wj){ |
|
| 568 | - if (count($wj)==4 |
|
| 569 | - AND strpos($wherestring,"{$cle}.")!==FALSE |
|
| 570 | - ){ |
|
| 571 | - $i = 0; |
|
| 572 | - $wheresub[] = $wj[3]; |
|
| 573 | - unset($jsub[$cle][3]); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } while ($i++<1); |
|
| 578 | - } |
|
| 579 | - if ($sous[0]=='SUBSELECT') { |
|
| 580 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 581 | - array_push($where_simples,$sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 583 | - $sous[1], # select |
|
| 584 | - $sous[2], #from |
|
| 585 | - array(), #from_type |
|
| 586 | - $sous[3]?(is_array($sous[3])?$sous[3]:array($sous[3])):array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 587 | - array(), #join |
|
| 588 | - $sous[4]?$sous[4]:array(), #groupby |
|
| 589 | - $sous[5]?$sous[5]:array(), #orderby |
|
| 590 | - $sous[6], #limit |
|
| 591 | - $sous[7]?$sous[7]:array(), #having |
|
| 592 | - $table,$id,$serveur,false |
|
| 593 | - ).")"); |
|
| 594 | - } |
|
| 595 | - array_pop($where_simples); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - foreach($having as $k => $v) { |
|
| 599 | - if ((!$v) OR ($v==1) OR ($v=='0=0')) { |
|
| 600 | - unset($having[$k]); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - // Installer les jointures. |
|
| 605 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 606 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 607 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 514 | + $from_type = array(), |
|
| 515 | + $where = array(), $join=array(), |
|
| 516 | + $groupby = array(), $orderby = array(), $limit = '', |
|
| 517 | + $having=array(), $table = '', $id = '', $serveur='', $requeter=true) { |
|
| 518 | + |
|
| 519 | + // retirer les criteres vides: |
|
| 520 | + // {X ?} avec X absent de l'URL |
|
| 521 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 522 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 523 | + $menage = false; |
|
| 524 | + foreach($where as $k => $v) { |
|
| 525 | + if (is_array($v)){ |
|
| 526 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | + elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 528 | + else $op = $v[0] ? $v[0] : $v; |
|
| 529 | + } else $op = $v; |
|
| 530 | + if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 531 | + unset($where[$k]); |
|
| 532 | + $menage = true; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 537 | + $groupby = array_diff($groupby,array('')); |
|
| 538 | + |
|
| 539 | + // remplacer les sous requetes recursives au calcul |
|
| 540 | + list($where_simples,$where_sous) = trouver_sous_requetes($where); |
|
| 541 | + foreach($where_sous as $k=>$w) { |
|
| 542 | + $menage = true; |
|
| 543 | + // on recupere la sous requete |
|
| 544 | + $sous = match_self($w); |
|
| 545 | + if ($sous[0]=='SELF') { |
|
| 546 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 547 | + array_push($where_simples,$sous[2]); |
|
| 548 | + $wheresub = array($sous[2],'0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 549 | + $jsub = $join; |
|
| 550 | + // trouver les jointures utiles a |
|
| 551 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 552 | + // ie L1.objet='article' |
|
| 553 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 554 | + $i = 0; |
|
| 555 | + do { |
|
| 556 | + $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 557 | + array($sous[1]." AS id"), |
|
| 558 | + $from, |
|
| 559 | + $from_type, |
|
| 560 | + $wheresub, |
|
| 561 | + $jsub, |
|
| 562 | + array(),array(),'', |
|
| 563 | + $having,$table,$id,$serveur,false).")"); |
|
| 564 | + if (!$i){ |
|
| 565 | + $i = 1; |
|
| 566 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 567 | + foreach ($join as $cle=>$wj){ |
|
| 568 | + if (count($wj)==4 |
|
| 569 | + AND strpos($wherestring,"{$cle}.")!==FALSE |
|
| 570 | + ){ |
|
| 571 | + $i = 0; |
|
| 572 | + $wheresub[] = $wj[3]; |
|
| 573 | + unset($jsub[$cle][3]); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } while ($i++<1); |
|
| 578 | + } |
|
| 579 | + if ($sous[0]=='SUBSELECT') { |
|
| 580 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 581 | + array_push($where_simples,$sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | + $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 583 | + $sous[1], # select |
|
| 584 | + $sous[2], #from |
|
| 585 | + array(), #from_type |
|
| 586 | + $sous[3]?(is_array($sous[3])?$sous[3]:array($sous[3])):array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 587 | + array(), #join |
|
| 588 | + $sous[4]?$sous[4]:array(), #groupby |
|
| 589 | + $sous[5]?$sous[5]:array(), #orderby |
|
| 590 | + $sous[6], #limit |
|
| 591 | + $sous[7]?$sous[7]:array(), #having |
|
| 592 | + $table,$id,$serveur,false |
|
| 593 | + ).")"); |
|
| 594 | + } |
|
| 595 | + array_pop($where_simples); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + foreach($having as $k => $v) { |
|
| 599 | + if ((!$v) OR ($v==1) OR ($v=='0=0')) { |
|
| 600 | + unset($having[$k]); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + // Installer les jointures. |
|
| 605 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 606 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 607 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 608 | 608 | |
| 609 | - $afrom = array(); |
|
| 610 | - $equiv = array(); |
|
| 611 | - $k = count($join); |
|
| 612 | - foreach(array_reverse($join,true) as $cledef=>$j) { |
|
| 613 | - $cle = $cledef; |
|
| 614 | - // le format de join est : |
|
| 615 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 616 | - if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | - if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 618 | - list($t,$c,$carr,$and) = $join[$cle]; |
|
| 619 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 620 | - // pour compat avec ancienne convention |
|
| 621 | - if (is_numeric($cle)) |
|
| 622 | - $cle = "L$k"; |
|
| 623 | - if (!$menage |
|
| 624 | - OR isset($afrom[$cle]) |
|
| 625 | - OR calculer_jointnul($cle, $select) |
|
| 626 | - OR calculer_jointnul($cle, array_diff_key($join, array($cle=>$join[$cle]))) |
|
| 627 | - OR calculer_jointnul($cle, $having) |
|
| 628 | - OR calculer_jointnul($cle, $where_simples)) { |
|
| 629 | - // corriger les references non explicites dans select |
|
| 630 | - // ou groupby |
|
| 631 | - foreach($select as $i=>$s) { |
|
| 632 | - if ($s == $c) { |
|
| 633 | - $select[$i] = "$cle.$c AS $c"; |
|
| 634 | - break; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - foreach($groupby as $i=>$g) { |
|
| 638 | - if ($g == $c) { |
|
| 639 | - $groupby[$i] = "$cle.$c"; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 644 | - // sans recours a preg_match |
|
| 645 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 646 | - $afrom[$t][$cle] = array("\n" . |
|
| 647 | - (isset($from_type[$cle])?$from_type[$cle]:"INNER")." JOIN", |
|
| 648 | - $from[$cle], |
|
| 649 | - "AS $cle", |
|
| 650 | - "ON (", |
|
| 651 | - "$cle.$c", |
|
| 652 | - "=", |
|
| 653 | - "$t.$carr", |
|
| 654 | - ($and ? "AND ". $and:"") . |
|
| 655 | - ")"); |
|
| 656 | - if (isset($afrom[$cle])){ |
|
| 657 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 658 | - unset($afrom[$cle]); |
|
| 659 | - } |
|
| 660 | - $equiv[]= $carr; |
|
| 661 | - } else { unset($join[$cledef]);} |
|
| 662 | - unset($from[$cle]); |
|
| 663 | - $k--; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - if (count($afrom)) { |
|
| 667 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 668 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 669 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 670 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 671 | - // ou dans |
|
| 672 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 673 | - // qui comporte plusieurs jointures |
|
| 674 | - // ou dans |
|
| 675 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 676 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 677 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 678 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 679 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 680 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 609 | + $afrom = array(); |
|
| 610 | + $equiv = array(); |
|
| 611 | + $k = count($join); |
|
| 612 | + foreach(array_reverse($join,true) as $cledef=>$j) { |
|
| 613 | + $cle = $cledef; |
|
| 614 | + // le format de join est : |
|
| 615 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 616 | + if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | + if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 618 | + list($t,$c,$carr,$and) = $join[$cle]; |
|
| 619 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 620 | + // pour compat avec ancienne convention |
|
| 621 | + if (is_numeric($cle)) |
|
| 622 | + $cle = "L$k"; |
|
| 623 | + if (!$menage |
|
| 624 | + OR isset($afrom[$cle]) |
|
| 625 | + OR calculer_jointnul($cle, $select) |
|
| 626 | + OR calculer_jointnul($cle, array_diff_key($join, array($cle=>$join[$cle]))) |
|
| 627 | + OR calculer_jointnul($cle, $having) |
|
| 628 | + OR calculer_jointnul($cle, $where_simples)) { |
|
| 629 | + // corriger les references non explicites dans select |
|
| 630 | + // ou groupby |
|
| 631 | + foreach($select as $i=>$s) { |
|
| 632 | + if ($s == $c) { |
|
| 633 | + $select[$i] = "$cle.$c AS $c"; |
|
| 634 | + break; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + foreach($groupby as $i=>$g) { |
|
| 638 | + if ($g == $c) { |
|
| 639 | + $groupby[$i] = "$cle.$c"; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 644 | + // sans recours a preg_match |
|
| 645 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 646 | + $afrom[$t][$cle] = array("\n" . |
|
| 647 | + (isset($from_type[$cle])?$from_type[$cle]:"INNER")." JOIN", |
|
| 648 | + $from[$cle], |
|
| 649 | + "AS $cle", |
|
| 650 | + "ON (", |
|
| 651 | + "$cle.$c", |
|
| 652 | + "=", |
|
| 653 | + "$t.$carr", |
|
| 654 | + ($and ? "AND ". $and:"") . |
|
| 655 | + ")"); |
|
| 656 | + if (isset($afrom[$cle])){ |
|
| 657 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 658 | + unset($afrom[$cle]); |
|
| 659 | + } |
|
| 660 | + $equiv[]= $carr; |
|
| 661 | + } else { unset($join[$cledef]);} |
|
| 662 | + unset($from[$cle]); |
|
| 663 | + $k--; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + if (count($afrom)) { |
|
| 667 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 668 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 669 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 670 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 671 | + // ou dans |
|
| 672 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 673 | + // qui comporte plusieurs jointures |
|
| 674 | + // ou dans |
|
| 675 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 676 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 677 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 678 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 679 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 680 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 681 | 681 | |
| 682 | - list($t,$c) = each($from); |
|
| 683 | - reset($from); |
|
| 684 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 685 | - if (!(strpos($t, ' ') OR // jointure des le depart cf boucle_doc |
|
| 686 | - calculer_jointnul($t, $select, $e) OR |
|
| 687 | - calculer_jointnul($t, $join, $e) OR |
|
| 688 | - calculer_jointnul($t, $where, $e) OR |
|
| 689 | - calculer_jointnul($t, $orderby, $e) OR |
|
| 690 | - calculer_jointnul($t, $groupby, $e) OR |
|
| 691 | - calculer_jointnul($t, $having, $e)) |
|
| 692 | - && count($afrom[$t])) { |
|
| 693 | - reset($afrom[$t]); |
|
| 694 | - list($nt,$nfrom) = each($afrom[$t]); |
|
| 695 | - unset($from[$t]); |
|
| 696 | - $from[$nt] = $nfrom[1]; |
|
| 697 | - unset($afrom[$t][$nt]); |
|
| 698 | - $afrom[$nt] = $afrom[$t]; |
|
| 699 | - unset($afrom[$t]); |
|
| 700 | - $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 701 | - $t = $nfrom[4]; |
|
| 702 | - $alias = ""; |
|
| 703 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 704 | - $oldcle = explode('.',$nfrom[6]); |
|
| 705 | - $oldcle = end($oldcle); |
|
| 706 | - $newcle = explode('.',$nfrom[4]); |
|
| 707 | - $newcle = end($newcle); |
|
| 708 | - if ($newcle!=$oldcle){ |
|
| 709 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 710 | - // reprendre simplement ce AS |
|
| 711 | - $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 712 | - if (preg_match($as,implode(',',$select),$m)){ |
|
| 713 | - $alias = ""; |
|
| 714 | - } |
|
| 715 | - else |
|
| 716 | - $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 717 | - } |
|
| 718 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 719 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 720 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 721 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 722 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 723 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 724 | - } |
|
| 725 | - $from = reinjecte_joint($afrom, $from); |
|
| 726 | - } |
|
| 727 | - $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur, $requeter); |
|
| 728 | - $r = sql_select($select, $from, $where, |
|
| 729 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 730 | - unset($GLOBALS['debug']['aucasou']); |
|
| 731 | - return $r; |
|
| 682 | + list($t,$c) = each($from); |
|
| 683 | + reset($from); |
|
| 684 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 685 | + if (!(strpos($t, ' ') OR // jointure des le depart cf boucle_doc |
|
| 686 | + calculer_jointnul($t, $select, $e) OR |
|
| 687 | + calculer_jointnul($t, $join, $e) OR |
|
| 688 | + calculer_jointnul($t, $where, $e) OR |
|
| 689 | + calculer_jointnul($t, $orderby, $e) OR |
|
| 690 | + calculer_jointnul($t, $groupby, $e) OR |
|
| 691 | + calculer_jointnul($t, $having, $e)) |
|
| 692 | + && count($afrom[$t])) { |
|
| 693 | + reset($afrom[$t]); |
|
| 694 | + list($nt,$nfrom) = each($afrom[$t]); |
|
| 695 | + unset($from[$t]); |
|
| 696 | + $from[$nt] = $nfrom[1]; |
|
| 697 | + unset($afrom[$t][$nt]); |
|
| 698 | + $afrom[$nt] = $afrom[$t]; |
|
| 699 | + unset($afrom[$t]); |
|
| 700 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 701 | + $t = $nfrom[4]; |
|
| 702 | + $alias = ""; |
|
| 703 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 704 | + $oldcle = explode('.',$nfrom[6]); |
|
| 705 | + $oldcle = end($oldcle); |
|
| 706 | + $newcle = explode('.',$nfrom[4]); |
|
| 707 | + $newcle = end($newcle); |
|
| 708 | + if ($newcle!=$oldcle){ |
|
| 709 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 710 | + // reprendre simplement ce AS |
|
| 711 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 712 | + if (preg_match($as,implode(',',$select),$m)){ |
|
| 713 | + $alias = ""; |
|
| 714 | + } |
|
| 715 | + else |
|
| 716 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 717 | + } |
|
| 718 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 719 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 720 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 721 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 722 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 723 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 724 | + } |
|
| 725 | + $from = reinjecte_joint($afrom, $from); |
|
| 726 | + } |
|
| 727 | + $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur, $requeter); |
|
| 728 | + $r = sql_select($select, $from, $where, |
|
| 729 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 730 | + unset($GLOBALS['debug']['aucasou']); |
|
| 731 | + return $r; |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -738,18 +738,18 @@ discard block |
||
| 738 | 738 | * @return string |
| 739 | 739 | */ |
| 740 | 740 | function calculer_where_to_string($v, $join = 'AND'){ |
| 741 | - if (empty($v)) |
|
| 742 | - return ''; |
|
| 743 | - |
|
| 744 | - if (!is_array($v)) { |
|
| 745 | - return $v; |
|
| 746 | - } else { |
|
| 747 | - $exp = ""; |
|
| 748 | - if (strtoupper($join) === 'AND') |
|
| 749 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | - else |
|
| 751 | - return $exp . join($join, $v); |
|
| 752 | - } |
|
| 741 | + if (empty($v)) |
|
| 742 | + return ''; |
|
| 743 | + |
|
| 744 | + if (!is_array($v)) { |
|
| 745 | + return $v; |
|
| 746 | + } else { |
|
| 747 | + $exp = ""; |
|
| 748 | + if (strtoupper($join) === 'AND') |
|
| 749 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | + else |
|
| 751 | + return $exp . join($join, $v); |
|
| 752 | + } |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -758,55 +758,55 @@ discard block |
||
| 758 | 758 | // http://doc.spip.org/@calculer_jointnul |
| 759 | 759 | function calculer_jointnul($cle, $exp, $equiv='') |
| 760 | 760 | { |
| 761 | - if (!is_array($exp)) { |
|
| 762 | - if ($equiv) $exp = preg_replace($equiv, '', $exp); |
|
| 763 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 764 | - } else { |
|
| 765 | - foreach($exp as $v) { |
|
| 766 | - if (calculer_jointnul($cle, $v, $equiv)) return true; |
|
| 767 | - } |
|
| 768 | - return false; |
|
| 769 | - } |
|
| 761 | + if (!is_array($exp)) { |
|
| 762 | + if ($equiv) $exp = preg_replace($equiv, '', $exp); |
|
| 763 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 764 | + } else { |
|
| 765 | + foreach($exp as $v) { |
|
| 766 | + if (calculer_jointnul($cle, $v, $equiv)) return true; |
|
| 767 | + } |
|
| 768 | + return false; |
|
| 769 | + } |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // http://doc.spip.org/@reinjecte_joint |
| 773 | 773 | function reinjecte_joint($afrom, $from) |
| 774 | 774 | { |
| 775 | - $from_synth = array(); |
|
| 776 | - foreach($from as $k=>$v){ |
|
| 777 | - $from_synth[$k]=$from[$k]; |
|
| 778 | - if (isset($afrom[$k])) { |
|
| 779 | - foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 780 | - $from_synth["$k@"]= implode(' ',$afrom[$k]); |
|
| 781 | - unset($afrom[$k]); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - return $from_synth; |
|
| 775 | + $from_synth = array(); |
|
| 776 | + foreach($from as $k=>$v){ |
|
| 777 | + $from_synth[$k]=$from[$k]; |
|
| 778 | + if (isset($afrom[$k])) { |
|
| 779 | + foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 780 | + $from_synth["$k@"]= implode(' ',$afrom[$k]); |
|
| 781 | + unset($afrom[$k]); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + return $from_synth; |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // http://doc.spip.org/@remplacer_jointnul |
| 788 | 788 | function remplacer_jointnul($cle, $exp, $equiv='') |
| 789 | 789 | { |
| 790 | - if (!is_array($exp)) { |
|
| 791 | - return preg_replace($equiv, $cle, $exp); |
|
| 792 | - } else { |
|
| 793 | - foreach($exp as $k => $v) { |
|
| 794 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 795 | - } |
|
| 796 | - return $exp; |
|
| 797 | - } |
|
| 790 | + if (!is_array($exp)) { |
|
| 791 | + return preg_replace($equiv, $cle, $exp); |
|
| 792 | + } else { |
|
| 793 | + foreach($exp as $k => $v) { |
|
| 794 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 795 | + } |
|
| 796 | + return $exp; |
|
| 797 | + } |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | // calcul du nom du squelette |
| 801 | 801 | // http://doc.spip.org/@calculer_nom_fonction_squel |
| 802 | 802 | function calculer_nom_fonction_squel($skel, $mime_type='html', $connect='') |
| 803 | 803 | { |
| 804 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 805 | - if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | - $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 807 | - return $mime_type |
|
| 808 | - . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
|
| 809 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
|
| 804 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 805 | + if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | + $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 807 | + return $mime_type |
|
| 808 | + . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
|
| 809 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | ?> |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/texte'); |
| 16 | 18 | include_spip('inc/documents'); |
@@ -36,10 +38,13 @@ discard block |
||
| 36 | 38 | $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
| 37 | 39 | |
| 38 | 40 | // si deja en memoire (INCLURE a repetition) c'est bon. |
| 39 | - if (function_exists($nom)) return $nom; |
|
| 41 | + if (function_exists($nom)) { |
|
| 42 | + return $nom; |
|
| 43 | + } |
|
| 40 | 44 | |
| 41 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
|
| 42 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 45 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 46 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 47 | + } |
|
| 43 | 48 | |
| 44 | 49 | $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
| 45 | 50 | |
@@ -60,7 +65,9 @@ discard block |
||
| 60 | 65 | |
| 61 | 66 | // tester si le eval ci-dessus a mis le squelette en memoire |
| 62 | 67 | |
| 63 | - if (function_exists($nom)) return $nom; |
|
| 68 | + if (function_exists($nom)) { |
|
| 69 | + return $nom; |
|
| 70 | + } |
|
| 64 | 71 | |
| 65 | 72 | // charger le source, si possible, et compiler |
| 66 | 73 | if (lire_fichier ($source, $skel)) { |
@@ -69,7 +76,9 @@ discard block |
||
| 69 | 76 | } |
| 70 | 77 | |
| 71 | 78 | // Ne plus rien faire si le compilateur n'a pas pu operer. |
| 72 | - if (!$skel_code) return false; |
|
| 79 | + if (!$skel_code) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 73 | 82 | |
| 74 | 83 | foreach($skel_code as $id => $boucle) { |
| 75 | 84 | $f = $boucle->return; |
@@ -88,9 +97,9 @@ discard block |
||
| 88 | 97 | |
| 89 | 98 | if ($nom) { |
| 90 | 99 | // Si le code est bon, concatener et mettre en cache |
| 91 | - if (function_exists($nom)) |
|
| 92 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 93 | - else { |
|
| 100 | + if (function_exists($nom)) { |
|
| 101 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 102 | + } else { |
|
| 94 | 103 | // code semantiquement faux: bug du compilateur |
| 95 | 104 | // $boucle est en fait ici la fct principale du squelette |
| 96 | 105 | $msg = _T('zbug_erreur_compilation'); |
@@ -107,8 +116,9 @@ discard block |
||
| 107 | 116 | // si c'est ce que demande le debusqueur, lui passer la main |
| 108 | 117 | if ($GLOBALS['debug_objets']['sourcefile'] |
| 109 | 118 | AND (_request('var_mode_objet') == $nom) |
| 110 | - AND (_request('var_mode_affiche') == 'code') ) |
|
| 111 | - erreur_squelette(); |
|
| 119 | + AND (_request('var_mode_affiche') == 'code') ) { |
|
| 120 | + erreur_squelette(); |
|
| 121 | + } |
|
| 112 | 122 | } |
| 113 | 123 | return $nom ? $nom : false; |
| 114 | 124 | } |
@@ -118,18 +128,20 @@ discard block |
||
| 118 | 128 | |
| 119 | 129 | // Le dernier index est '' (fonction principale) |
| 120 | 130 | $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
| 121 | - if (CODE_COMMENTE) |
|
| 122 | - $code = " |
|
| 131 | + if (CODE_COMMENTE) { |
|
| 132 | + $code = " |
|
| 123 | 133 | /* |
| 124 | 134 | * Squelette : $sourcefile |
| 125 | 135 | * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
| 126 | 136 | * Compile : ".gmdate("D, d M Y H:i:s", time())." GMT |
| 127 | 137 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) ." |
| 128 | 138 | */ " ; |
| 139 | + } |
|
| 129 | 140 | |
| 130 | 141 | $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
| 131 | - if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
|
| 132 | - ecrire_fichier($phpfile, $code); |
|
| 142 | + if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) { |
|
| 143 | + ecrire_fichier($phpfile, $code); |
|
| 144 | + } |
|
| 133 | 145 | return $code; |
| 134 | 146 | } |
| 135 | 147 | |
@@ -140,10 +152,13 @@ discard block |
||
| 140 | 152 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
| 141 | 153 | // par hit |
| 142 | 154 | if (is_null($date_change)){ |
| 143 | - if (@file_exists($fonc = 'mes_fonctions.php')) |
|
| 144 | - $date_change = @filemtime($fonc); # compatibilite |
|
| 145 | - if (defined('_FILE_OPTIONS')) |
|
| 146 | - $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 155 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 156 | + $date_change = @filemtime($fonc); |
|
| 157 | + } |
|
| 158 | + # compatibilite |
|
| 159 | + if (defined('_FILE_OPTIONS')) { |
|
| 160 | + $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 161 | + } |
|
| 147 | 162 | } |
| 148 | 163 | return ( |
| 149 | 164 | (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
@@ -179,10 +194,11 @@ discard block |
||
| 179 | 194 | # $j = Content-Type, et pas content-TYPE. |
| 180 | 195 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 181 | 196 | |
| 182 | - if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | - $headers[$j].="|".$r[3]; |
|
| 184 | - else |
|
| 185 | - $headers[$j] = $r[3]; |
|
| 197 | + if ($j=='X-Spip-Filtre' AND isset($headers[$j])) { |
|
| 198 | + $headers[$j].="|".$r[3]; |
|
| 199 | + } else { |
|
| 200 | + $headers[$j] = $r[3]; |
|
| 201 | + } |
|
| 186 | 202 | } |
| 187 | 203 | } |
| 188 | 204 | // S'agit-il d'un resultat constant ou contenant du code php |
@@ -237,8 +253,9 @@ discard block |
||
| 237 | 253 | // http://doc.spip.org/@filtre_introduction_dist |
| 238 | 254 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect) { |
| 239 | 255 | // Si un descriptif est envoye, on l'utilise directement |
| 240 | - if (strlen($descriptif)) |
|
| 241 | - return propre($descriptif,$connect); |
|
| 256 | + if (strlen($descriptif)) { |
|
| 257 | + return propre($descriptif,$connect); |
|
| 258 | + } |
|
| 242 | 259 | |
| 243 | 260 | // De preference ce qui est marque <intro>...</intro> |
| 244 | 261 | $intro = ''; |
@@ -246,8 +263,9 @@ discard block |
||
| 246 | 263 | while ($fin = strpos($texte, "</intro>")) { |
| 247 | 264 | $zone = substr($texte, 0, $fin); |
| 248 | 265 | $texte = substr($texte, $fin + strlen("</intro>")); |
| 249 | - if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") |
|
| 250 | - $zone = substr($zone, $deb + 7); |
|
| 266 | + if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") { |
|
| 267 | + $zone = substr($zone, $deb + 7); |
|
| 268 | + } |
|
| 251 | 269 | $intro .= $zone; |
| 252 | 270 | } |
| 253 | 271 | |
@@ -262,34 +280,39 @@ discard block |
||
| 262 | 280 | // Cependant pour des questions de perfs on coupe quand meme, en prenant |
| 263 | 281 | // large et en se mefiant des tableaux #1323 |
| 264 | 282 | |
| 265 | - if (strlen($intro)) |
|
| 266 | - $texte = $intro; |
|
| 267 | - |
|
| 268 | - else |
|
| 283 | + if (strlen($intro)) { |
|
| 284 | + $texte = $intro; |
|
| 285 | + } else |
|
| 269 | 286 | if (strpos("\n".$texte, "\n|")===false |
| 270 | 287 | AND strlen($texte) > 2.5*$longueur){ |
| 271 | - if (strpos($texte,"<multi")!==false) |
|
| 272 | - $texte = extraire_multi($texte); |
|
| 288 | + if (strpos($texte,"<multi")!==false) { |
|
| 289 | + $texte = extraire_multi($texte); |
|
| 290 | + } |
|
| 273 | 291 | $texte = couper($texte, 2*$longueur); |
| 274 | 292 | } |
| 275 | 293 | |
| 276 | 294 | // ne pas tenir compte des notes |
| 277 | - if ($notes = charger_fonction('notes', 'inc', true)) |
|
| 278 | - $notes('','empiler'); |
|
| 295 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 296 | + $notes('','empiler'); |
|
| 297 | + } |
|
| 279 | 298 | // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
| 280 | 299 | // dans l'introduction. |
| 281 | 300 | $texte = supprime_img($texte, ''); |
| 282 | 301 | $texte = propre($texte,$connect); |
| 283 | - if ($notes) |
|
| 284 | - $notes('','depiler'); |
|
| 302 | + if ($notes) { |
|
| 303 | + $notes('','depiler'); |
|
| 304 | + } |
|
| 285 | 305 | |
| 286 | - if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 306 | + if (!defined('_INTRODUCTION_SUITE')) { |
|
| 307 | + define('_INTRODUCTION_SUITE', ' (...)'); |
|
| 308 | + } |
|
| 287 | 309 | $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
| 288 | 310 | |
| 289 | 311 | // et reparagrapher si necessaire (coherence avec le cas descriptif) |
| 290 | - if ($GLOBALS['toujours_paragrapher']) |
|
| 291 | - // Fermer les paragraphes |
|
| 312 | + if ($GLOBALS['toujours_paragrapher']) { |
|
| 313 | + // Fermer les paragraphes |
|
| 292 | 314 | $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
| 315 | + } |
|
| 293 | 316 | |
| 294 | 317 | return $texte; |
| 295 | 318 | } |
@@ -323,12 +346,13 @@ discard block |
||
| 323 | 346 | // http://doc.spip.org/@argumenter_squelette |
| 324 | 347 | function argumenter_squelette($v) { |
| 325 | 348 | |
| 326 | - if (!is_array($v)) |
|
| 327 | - return "'" . texte_script($v) . "'"; |
|
| 328 | - else { |
|
| 349 | + if (!is_array($v)) { |
|
| 350 | + return "'" . texte_script($v) . "'"; |
|
| 351 | + } else { |
|
| 329 | 352 | $out = array(); |
| 330 | - foreach($v as $k=>$val) |
|
| 331 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 353 | + foreach($v as $k=>$val) { |
|
| 354 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | + } |
|
| 332 | 356 | return 'array(' . join(", ", $out) . ')'; |
| 333 | 357 | } |
| 334 | 358 | } |
@@ -347,8 +371,7 @@ discard block |
||
| 347 | 371 | array_unshift($args,$nom); |
| 348 | 372 | // et passer sur la fonction generique pour la suite |
| 349 | 373 | $nomfonction = $nomfonction_generique; |
| 350 | - } |
|
| 351 | - else { |
|
| 374 | + } else { |
|
| 352 | 375 | $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
| 353 | 376 | erreur_squelette($msg, $context_compil); |
| 354 | 377 | return ''; |
@@ -359,7 +382,9 @@ discard block |
||
| 359 | 382 | |
| 360 | 383 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 361 | 384 | |
| 362 | - if (!is_array($r)) return $r; |
|
| 385 | + if (!is_array($r)) { |
|
| 386 | + return $r; |
|
| 387 | + } |
|
| 363 | 388 | |
| 364 | 389 | // verifier que la fonction dyn est la, |
| 365 | 390 | // sinon se replier sur la generique si elle existe |
@@ -376,8 +401,9 @@ discard block |
||
| 376 | 401 | } |
| 377 | 402 | } |
| 378 | 403 | |
| 379 | - if (!_DIR_RESTREINT) |
|
| 380 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 404 | + if (!_DIR_RESTREINT) { |
|
| 405 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 406 | + } |
|
| 381 | 407 | return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
| 382 | 408 | } |
| 383 | 409 | |
@@ -394,8 +420,9 @@ discard block |
||
| 394 | 420 | |
| 395 | 421 | if ($d = @opendir(_DIR_LOGOS)) { |
| 396 | 422 | while($f = readdir($d)) { |
| 397 | - if (preg_match($type, $f, $r)) |
|
| 398 | - $logos[] = $r[1]; |
|
| 423 | + if (preg_match($type, $f, $r)) { |
|
| 424 | + $logos[] = $r[1]; |
|
| 425 | + } |
|
| 399 | 426 | } |
| 400 | 427 | } |
| 401 | 428 | @closedir($d); |
@@ -420,19 +447,22 @@ discard block |
||
| 420 | 447 | function lang_select_public($lang, $lang_select, $titre=null) { |
| 421 | 448 | // Cas 1. forcer_lang = true et pas de critere {lang_select} |
| 422 | 449 | if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
| 423 | - AND $lang_select !== 'oui') |
|
| 424 | - $lang = $GLOBALS['spip_lang']; |
|
| 450 | + AND $lang_select !== 'oui') { |
|
| 451 | + $lang = $GLOBALS['spip_lang']; |
|
| 452 | + } |
|
| 425 | 453 | |
| 426 | 454 | // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
| 427 | - elseif (!strlen($lang)) |
|
| 428 | - $lang = $GLOBALS['spip_lang']; |
|
| 455 | + elseif (!strlen($lang)) { |
|
| 456 | + $lang = $GLOBALS['spip_lang']; |
|
| 457 | + } |
|
| 429 | 458 | |
| 430 | 459 | // Cas 3. l'objet est multilingue ! |
| 431 | 460 | elseif ($lang_select !== 'oui' |
| 432 | 461 | AND strlen($titre) > 10 |
| 433 | 462 | AND strpos($titre, '<multi>') !== false |
| 434 | - AND strpos(echappe_html($titre), '<multi>') !== false) |
|
| 435 | - $lang = $GLOBALS['spip_lang']; |
|
| 463 | + AND strpos(echappe_html($titre), '<multi>') !== false) { |
|
| 464 | + $lang = $GLOBALS['spip_lang']; |
|
| 465 | + } |
|
| 436 | 466 | |
| 437 | 467 | // faire un lang_select() eventuellement sur la langue inchangee |
| 438 | 468 | lang_select($lang); |
@@ -448,33 +478,43 @@ discard block |
||
| 448 | 478 | foreach ($envd as $table => $liste) { |
| 449 | 479 | $n = ''; |
| 450 | 480 | foreach(explode(',',$liste) as $val) { |
| 451 | - if ($a = intval($val) AND $val === strval($a)) |
|
| 452 | - $n.= ','.$val; |
|
| 481 | + if ($a = intval($val) AND $val === strval($a)) { |
|
| 482 | + $n.= ','.$val; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + if (strlen($n)) { |
|
| 486 | + $envd[$table] = $n; |
|
| 487 | + } else { |
|
| 488 | + unset($envd[$table]); |
|
| 453 | 489 | } |
| 454 | - if (strlen($n)) |
|
| 455 | - $envd[$table] = $n; |
|
| 456 | - else |
|
| 457 | - unset($envd[$table]); |
|
| 458 | 490 | } |
| 459 | 491 | return $envd; |
| 460 | 492 | } |
| 461 | 493 | |
| 462 | 494 | // http://doc.spip.org/@match_self |
| 463 | 495 | function match_self($w){ |
| 464 | - if (is_string($w)) return false; |
|
| 496 | + if (is_string($w)) { |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 465 | 499 | if (is_array($w)) { |
| 466 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | - foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | - if ($m=match_self($sw)) return $m; |
|
| 500 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) { |
|
| 501 | + return $w; |
|
| 502 | + } |
|
| 503 | + foreach(array_filter($w,'is_array') as $sw) { |
|
| 504 | + if ($m=match_self($sw)) return $m; |
|
| 505 | + } |
|
| 469 | 506 | } |
| 470 | 507 | return false; |
| 471 | 508 | } |
| 472 | 509 | // http://doc.spip.org/@remplace_sous_requete |
| 473 | 510 | function remplace_sous_requete($w,$sousrequete){ |
| 474 | 511 | if (is_array($w)) { |
| 475 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | - foreach($w as $k=>$sw) |
|
| 477 | - $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 512 | + if (in_array(reset($w),array("SELF","SUBSELECT"))) { |
|
| 513 | + return $sousrequete; |
|
| 514 | + } |
|
| 515 | + foreach($w as $k=>$sw) { |
|
| 516 | + $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 517 | + } |
|
| 478 | 518 | } |
| 479 | 519 | return $w; |
| 480 | 520 | } |
@@ -483,8 +523,11 @@ discard block |
||
| 483 | 523 | $where_simples = array(); |
| 484 | 524 | $where_sous = array(); |
| 485 | 525 | foreach($where as $k=>$w){ |
| 486 | - if (match_self($w)) $where_sous[$k] = $w; |
|
| 487 | - else $where_simples[$k] = $w; |
|
| 526 | + if (match_self($w)) { |
|
| 527 | + $where_sous[$k] = $w; |
|
| 528 | + } else { |
|
| 529 | + $where_simples[$k] = $w; |
|
| 530 | + } |
|
| 488 | 531 | } |
| 489 | 532 | return array($where_simples,$where_sous); |
| 490 | 533 | } |
@@ -523,10 +566,16 @@ discard block |
||
| 523 | 566 | $menage = false; |
| 524 | 567 | foreach($where as $k => $v) { |
| 525 | 568 | if (is_array($v)){ |
| 526 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 528 | - else $op = $v[0] ? $v[0] : $v; |
|
| 529 | - } else $op = $v; |
|
| 569 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) { |
|
| 570 | + $op= false; |
|
| 571 | + } elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) { |
|
| 572 | + $op= false; |
|
| 573 | + } else { |
|
| 574 | + $op = $v[0] ? $v[0] : $v; |
|
| 575 | + } |
|
| 576 | + } else { |
|
| 577 | + $op = $v; |
|
| 578 | + } |
|
| 530 | 579 | if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
| 531 | 580 | unset($where[$k]); |
| 532 | 581 | $menage = true; |
@@ -613,13 +662,18 @@ discard block |
||
| 613 | 662 | $cle = $cledef; |
| 614 | 663 | // le format de join est : |
| 615 | 664 | // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
| 616 | - if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | - if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 665 | + if (count($join[$cle])==2) { |
|
| 666 | + $join[$cle][] = $join[$cle][1]; |
|
| 667 | + } |
|
| 668 | + if (count($join[$cle])==3) { |
|
| 669 | + $join[$cle][] = ''; |
|
| 670 | + } |
|
| 618 | 671 | list($t,$c,$carr,$and) = $join[$cle]; |
| 619 | 672 | // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
| 620 | 673 | // pour compat avec ancienne convention |
| 621 | - if (is_numeric($cle)) |
|
| 622 | - $cle = "L$k"; |
|
| 674 | + if (is_numeric($cle)) { |
|
| 675 | + $cle = "L$k"; |
|
| 676 | + } |
|
| 623 | 677 | if (!$menage |
| 624 | 678 | OR isset($afrom[$cle]) |
| 625 | 679 | OR calculer_jointnul($cle, $select) |
@@ -711,9 +765,9 @@ discard block |
||
| 711 | 765 | $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
| 712 | 766 | if (preg_match($as,implode(',',$select),$m)){ |
| 713 | 767 | $alias = ""; |
| 768 | + } else { |
|
| 769 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 714 | 770 | } |
| 715 | - else |
|
| 716 | - $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 717 | 771 | } |
| 718 | 772 | $select = remplacer_jointnul($t . $alias, $select, $e); |
| 719 | 773 | $join = remplacer_jointnul($t, $join, $e); |
@@ -738,17 +792,19 @@ discard block |
||
| 738 | 792 | * @return string |
| 739 | 793 | */ |
| 740 | 794 | function calculer_where_to_string($v, $join = 'AND'){ |
| 741 | - if (empty($v)) |
|
| 742 | - return ''; |
|
| 795 | + if (empty($v)) { |
|
| 796 | + return ''; |
|
| 797 | + } |
|
| 743 | 798 | |
| 744 | 799 | if (!is_array($v)) { |
| 745 | 800 | return $v; |
| 746 | 801 | } else { |
| 747 | 802 | $exp = ""; |
| 748 | - if (strtoupper($join) === 'AND') |
|
| 749 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | - else |
|
| 751 | - return $exp . join($join, $v); |
|
| 803 | + if (strtoupper($join) === 'AND') { |
|
| 804 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 805 | + } else { |
|
| 806 | + return $exp . join($join, $v); |
|
| 807 | + } |
|
| 752 | 808 | } |
| 753 | 809 | } |
| 754 | 810 | |
@@ -759,11 +815,15 @@ discard block |
||
| 759 | 815 | function calculer_jointnul($cle, $exp, $equiv='') |
| 760 | 816 | { |
| 761 | 817 | if (!is_array($exp)) { |
| 762 | - if ($equiv) $exp = preg_replace($equiv, '', $exp); |
|
| 818 | + if ($equiv) { |
|
| 819 | + $exp = preg_replace($equiv, '', $exp); |
|
| 820 | + } |
|
| 763 | 821 | return preg_match("/\\b$cle\\./", $exp); |
| 764 | 822 | } else { |
| 765 | 823 | foreach($exp as $v) { |
| 766 | - if (calculer_jointnul($cle, $v, $equiv)) return true; |
|
| 824 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 825 | + return true; |
|
| 826 | + } |
|
| 767 | 827 | } |
| 768 | 828 | return false; |
| 769 | 829 | } |
@@ -776,7 +836,9 @@ discard block |
||
| 776 | 836 | foreach($from as $k=>$v){ |
| 777 | 837 | $from_synth[$k]=$from[$k]; |
| 778 | 838 | if (isset($afrom[$k])) { |
| 779 | - foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 839 | + foreach($afrom[$k] as $kk=>$vv) { |
|
| 840 | + $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 841 | + } |
|
| 780 | 842 | $from_synth["$k@"]= implode(' ',$afrom[$k]); |
| 781 | 843 | unset($afrom[$k]); |
| 782 | 844 | } |
@@ -802,8 +864,9 @@ discard block |
||
| 802 | 864 | function calculer_nom_fonction_squel($skel, $mime_type='html', $connect='') |
| 803 | 865 | { |
| 804 | 866 | // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
| 805 | - if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | - $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 867 | + if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) { |
|
| 868 | + $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 869 | + } |
|
| 807 | 870 | return $mime_type |
| 808 | 871 | . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
| 809 | 872 | . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | # Toutefois pour 2. et 3. preferer la technique de la surcharge |
| 32 | 32 | |
| 33 | 33 | // http://doc.spip.org/@public_composer_dist |
| 34 | -function public_composer_dist($squelette, $mime_type, $gram, $source, $connect='') { |
|
| 34 | +function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
|
| 35 | 35 | |
| 36 | 36 | $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
| 37 | 37 | |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') |
| 42 | 42 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 43 | 43 | |
| 44 | - $phpfile = sous_repertoire(_DIR_SKELS,'',false,true) . $nom . '.php'; |
|
| 44 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 45 | 45 | |
| 46 | 46 | // si squelette est deja compile et perenne, le charger |
| 47 | - if (!squelette_obsolete($phpfile, $source)){ |
|
| 47 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 48 | 48 | include_once $phpfile; |
| 49 | 49 | #if (!squelette_obsolete($phpfile, $source) |
| 50 | 50 | # AND lire_fichier ($phpfile, $skel_code, |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | #} |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (file_exists($lib = $squelette . '_fonctions'.'.php')){ |
|
| 57 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 58 | 58 | include_once $lib; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | if (function_exists($nom)) return $nom; |
| 64 | 64 | |
| 65 | 65 | // charger le source, si possible, et compiler |
| 66 | - if (lire_fichier ($source, $skel)) { |
|
| 66 | + if (lire_fichier($source, $skel)) { |
|
| 67 | 67 | $compiler = charger_fonction('compiler', 'public'); |
| 68 | 68 | $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
| 69 | 69 | } |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | // Ne plus rien faire si le compilateur n'a pas pu operer. |
| 72 | 72 | if (!$skel_code) return false; |
| 73 | 73 | |
| 74 | - foreach($skel_code as $id => $boucle) { |
|
| 74 | + foreach ($skel_code as $id => $boucle) { |
|
| 75 | 75 | $f = $boucle->return; |
| 76 | - if (@eval("return true; $f ;") === false) { |
|
| 76 | + if (@eval("return true; $f ;") === false) { |
|
| 77 | 77 | // Code syntaxiquement faux (critere etc mal programme') |
| 78 | 78 | $msg = _T('zbug_erreur_compilation'); |
| 79 | 79 | erreur_squelette($msg, $boucle); |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
| 103 | 103 | |
| 104 | 104 | // Tracer ce qui vient d'etre compile |
| 105 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 105 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 106 | 106 | |
| 107 | 107 | // si c'est ce que demande le debusqueur, lui passer la main |
| 108 | 108 | if ($GLOBALS['debug_objets']['sourcefile'] |
| 109 | 109 | AND (_request('var_mode_objet') == $nom) |
| 110 | - AND (_request('var_mode_affiche') == 'code') ) |
|
| 110 | + AND (_request('var_mode_affiche') == 'code')) |
|
| 111 | 111 | erreur_squelette(); |
| 112 | 112 | } |
| 113 | 113 | return $nom ? $nom : false; |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | |
| 119 | 119 | // Le dernier index est '' (fonction principale) |
| 120 | - $noms = substr(join (', ', array_keys($boucles)), 0, -2); |
|
| 120 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 121 | 121 | if (CODE_COMMENTE) |
| 122 | 122 | $code = " |
| 123 | 123 | /* |
| 124 | 124 | * Squelette : $sourcefile |
| 125 | 125 | * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
| 126 | 126 | * Compile : ".gmdate("D, d M Y H:i:s", time())." GMT |
| 127 | - * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) ." |
|
| 127 | + * " . (!$boucles ? "Pas de boucle" : ("Boucles : ".$noms))." |
|
| 128 | 128 | */ " ; |
| 129 | 129 | |
| 130 | - $code = '<'. "?php\n" . $code . join('', $boucles) . "\n?" .'>'; |
|
| 130 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 131 | 131 | if (!defined('_VAR_NOCACHE') OR !_VAR_NOCACHE) |
| 132 | 132 | ecrire_fichier($phpfile, $code); |
| 133 | 133 | return $code; |
@@ -139,16 +139,16 @@ discard block |
||
| 139 | 139 | static $date_change = null; |
| 140 | 140 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
| 141 | 141 | // par hit |
| 142 | - if (is_null($date_change)){ |
|
| 142 | + if (is_null($date_change)) { |
|
| 143 | 143 | if (@file_exists($fonc = 'mes_fonctions.php')) |
| 144 | 144 | $date_change = @filemtime($fonc); # compatibilite |
| 145 | 145 | if (defined('_FILE_OPTIONS')) |
| 146 | - $date_change = max($date_change,@filemtime(_FILE_OPTIONS)); |
|
| 146 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 147 | 147 | } |
| 148 | 148 | return ( |
| 149 | - (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul','preview','debug'))) |
|
| 149 | + (defined('_VAR_MODE') AND in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 150 | 150 | OR !@file_exists($skel) |
| 151 | - OR ((@file_exists($squelette)?@filemtime($squelette):0) |
|
| 151 | + OR ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 152 | 152 | > ($date = @filemtime($skel))) |
| 153 | 153 | OR ($date_change > $date) |
| 154 | 154 | ); |
@@ -156,41 +156,41 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | // Activer l'invalideur de session |
| 158 | 158 | // http://doc.spip.org/@invalideur_session |
| 159 | -function invalideur_session(&$Cache, $code=NULL) { |
|
| 160 | - $Cache['session']=spip_session(); |
|
| 159 | +function invalideur_session(&$Cache, $code = NULL) { |
|
| 160 | + $Cache['session'] = spip_session(); |
|
| 161 | 161 | return $code; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | // http://doc.spip.org/@analyse_resultat_skel |
| 166 | -function analyse_resultat_skel($nom, $cache, $corps, $source='') { |
|
| 166 | +function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
|
| 167 | 167 | static $filtres = array(); |
| 168 | 168 | $headers = array(); |
| 169 | 169 | |
| 170 | 170 | // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
| 171 | 171 | // note: on essaie d'attrapper aussi certains de ces entetes codes |
| 172 | 172 | // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
| 173 | - if (stripos($corps,'header')!==false |
|
| 173 | + if (stripos($corps, 'header') !== false |
|
| 174 | 174 | AND preg_match_all( |
| 175 | 175 | '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
| 176 | - $corps, $regs, PREG_SET_ORDER)){ |
|
| 176 | + $corps, $regs, PREG_SET_ORDER)) { |
|
| 177 | 177 | foreach ($regs as $r) { |
| 178 | 178 | $corps = str_replace($r[0], '', $corps); |
| 179 | 179 | # $j = Content-Type, et pas content-TYPE. |
| 180 | 180 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 181 | 181 | |
| 182 | - if ($j=='X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | - $headers[$j].="|".$r[3]; |
|
| 182 | + if ($j == 'X-Spip-Filtre' AND isset($headers[$j])) |
|
| 183 | + $headers[$j] .= "|".$r[3]; |
|
| 184 | 184 | else |
| 185 | 185 | $headers[$j] = $r[3]; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | // S'agit-il d'un resultat constant ou contenant du code php |
| 189 | 189 | $process_ins = ( |
| 190 | - strpos($corps,'<'.'?') === false |
|
| 190 | + strpos($corps, '<'.'?') === false |
|
| 191 | 191 | OR |
| 192 | - (strpos($corps,'<'.'?xml')!==false AND |
|
| 193 | - strpos(str_replace('<'.'?xml', '', $corps),'<'.'?') === false) |
|
| 192 | + (strpos($corps, '<'.'?xml') !== false AND |
|
| 193 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 194 | 194 | ) |
| 195 | 195 | ? 'html' |
| 196 | 196 | : 'php'; |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // traiter #FILTRE{} et filtres |
| 208 | 208 | if (!isset($filtres[$nom])) { |
| 209 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes',array('args'=>$skel,'data'=>array())); |
|
| 209 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args'=>$skel, 'data'=>array())); |
|
| 210 | 210 | } |
| 211 | 211 | if (count($filtres[$nom]) OR (isset($headers['X-Spip-Filtre']) AND strlen($headers['X-Spip-Filtre']))) { |
| 212 | 212 | include_spip('public/sandbox'); |
| 213 | - $corps = sandbox_filtrer_squelette($skel,$corps,strlen($headers['X-Spip-Filtre'])?explode('|', $headers['X-Spip-Filtre']):array(),$filtres[$nom]); |
|
| 213 | + $corps = sandbox_filtrer_squelette($skel, $corps, strlen($headers['X-Spip-Filtre']) ?explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 214 | 214 | unset($headers['X-Spip-Filtre']); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect) { |
| 239 | 239 | // Si un descriptif est envoye, on l'utilise directement |
| 240 | 240 | if (strlen($descriptif)) |
| 241 | - return propre($descriptif,$connect); |
|
| 241 | + return propre($descriptif, $connect); |
|
| 242 | 242 | |
| 243 | 243 | // De preference ce qui est marque <intro>...</intro> |
| 244 | 244 | $intro = ''; |
@@ -266,22 +266,22 @@ discard block |
||
| 266 | 266 | $texte = $intro; |
| 267 | 267 | |
| 268 | 268 | else |
| 269 | - if (strpos("\n".$texte, "\n|")===false |
|
| 270 | - AND strlen($texte) > 2.5*$longueur){ |
|
| 271 | - if (strpos($texte,"<multi")!==false) |
|
| 269 | + if (strpos("\n".$texte, "\n|") === false |
|
| 270 | + AND strlen($texte) > 2.5 * $longueur) { |
|
| 271 | + if (strpos($texte, "<multi") !== false) |
|
| 272 | 272 | $texte = extraire_multi($texte); |
| 273 | - $texte = couper($texte, 2*$longueur); |
|
| 273 | + $texte = couper($texte, 2 * $longueur); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // ne pas tenir compte des notes |
| 277 | 277 | if ($notes = charger_fonction('notes', 'inc', true)) |
| 278 | - $notes('','empiler'); |
|
| 278 | + $notes('', 'empiler'); |
|
| 279 | 279 | // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
| 280 | 280 | // dans l'introduction. |
| 281 | 281 | $texte = supprime_img($texte, ''); |
| 282 | - $texte = propre($texte,$connect); |
|
| 282 | + $texte = propre($texte, $connect); |
|
| 283 | 283 | if ($notes) |
| 284 | - $notes('','depiler'); |
|
| 284 | + $notes('', 'depiler'); |
|
| 285 | 285 | |
| 286 | 286 | if (!defined('_INTRODUCTION_SUITE')) define('_INTRODUCTION_SUITE', ' (...)'); |
| 287 | 287 | $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | // elles sont traitees comme des inclusions |
| 302 | 302 | // http://doc.spip.org/@synthetiser_balise_dynamique |
| 303 | 303 | |
| 304 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 304 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 305 | 305 | include_once("./" . _DIR_RACINE . "%s"); |
| 306 | 306 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 307 | 307 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 314 | 314 | $r = sprintf(CODE_INCLURE_BALISE, |
| 315 | 315 | $file, |
| 316 | - $context_compil[4]?$context_compil[4]:'', |
|
| 316 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 317 | 317 | $nom, |
| 318 | 318 | join(', ', array_map('argumenter_squelette', $args)), |
| 319 | 319 | join(', ', array_map('_q', $context_compil))); |
@@ -324,38 +324,38 @@ discard block |
||
| 324 | 324 | function argumenter_squelette($v) { |
| 325 | 325 | |
| 326 | 326 | if (!is_array($v)) |
| 327 | - return "'" . texte_script($v) . "'"; |
|
| 327 | + return "'".texte_script($v)."'"; |
|
| 328 | 328 | else { |
| 329 | 329 | $out = array(); |
| 330 | - foreach($v as $k=>$val) |
|
| 331 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 332 | - return 'array(' . join(", ", $out) . ')'; |
|
| 330 | + foreach ($v as $k=>$val) |
|
| 331 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 332 | + return 'array('.join(", ", $out).')'; |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // verifier leurs arguments et filtres, et calculer le code a inclure |
| 337 | 337 | // http://doc.spip.org/@executer_balise_dynamique |
| 338 | 338 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 339 | - $p = strpos($nom,"_"); |
|
| 339 | + $p = strpos($nom, "_"); |
|
| 340 | 340 | $nomfonction = $nom; |
| 341 | - $nomfonction_generique = substr($nom,0,$p+1); |
|
| 342 | - if (!$file = include_spip("balise/". strtolower($nomfonction))) { |
|
| 341 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 342 | + if (!$file = include_spip("balise/".strtolower($nomfonction))) { |
|
| 343 | 343 | // pas de fichier associe, passer au traitement generique |
| 344 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 344 | + $file = include_spip("balise/".strtolower($nomfonction_generique)); |
|
| 345 | 345 | if ($file) { |
| 346 | 346 | // et injecter en premier arg le nom de la balise |
| 347 | - array_unshift($args,$nom); |
|
| 347 | + array_unshift($args, $nom); |
|
| 348 | 348 | // et passer sur la fonction generique pour la suite |
| 349 | 349 | $nomfonction = $nomfonction_generique; |
| 350 | 350 | } |
| 351 | 351 | else { |
| 352 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 352 | + $msg = array('zbug_balise_inexistante', array('from'=>'CVT', 'balise'=>$nom)); |
|
| 353 | 353 | erreur_squelette($msg, $context_compil); |
| 354 | 354 | return ''; |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | // Y a-t-il une fonction de traitement des arguments ? |
| 358 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 358 | + $f = 'balise_'.$nomfonction.'_stat'; |
|
| 359 | 359 | |
| 360 | 360 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 361 | 361 | |
@@ -363,61 +363,61 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | // verifier que la fonction dyn est la, |
| 365 | 365 | // sinon se replier sur la generique si elle existe |
| 366 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 367 | - $file = include_spip("balise/" .strtolower($nomfonction_generique)); |
|
| 368 | - if (function_exists('balise_' . $nomfonction_generique . '_dyn')) { |
|
| 366 | + if (!function_exists('balise_'.$nomfonction.'_dyn')) { |
|
| 367 | + $file = include_spip("balise/".strtolower($nomfonction_generique)); |
|
| 368 | + if (function_exists('balise_'.$nomfonction_generique.'_dyn')) { |
|
| 369 | 369 | // et lui injecter en premier arg le nom de la balise |
| 370 | - array_unshift($r,$nom); |
|
| 370 | + array_unshift($r, $nom); |
|
| 371 | 371 | $nomfonction = $nomfonction_generique; |
| 372 | 372 | } else { |
| 373 | - $msg = array('zbug_balise_inexistante',array('from'=>'CVT','balise'=>$nom)); |
|
| 373 | + $msg = array('zbug_balise_inexistante', array('from'=>'CVT', 'balise'=>$nom)); |
|
| 374 | 374 | erreur_squelette($msg, $context_compil); |
| 375 | 375 | return ''; |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | if (!_DIR_RESTREINT) |
| 380 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 380 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 381 | 381 | return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // http://doc.spip.org/@lister_objets_avec_logos |
| 385 | -function lister_objets_avec_logos ($type) { |
|
| 385 | +function lister_objets_avec_logos($type) { |
|
| 386 | 386 | global $formats_logos; |
| 387 | 387 | $logos = array(); |
| 388 | 388 | $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
| 389 | 389 | $type = '/' |
| 390 | 390 | . type_du_logo($type) |
| 391 | 391 | . "on(\d+)\.(" |
| 392 | - . join('|',$formats_logos) |
|
| 392 | + . join('|', $formats_logos) |
|
| 393 | 393 | . ")$/"; |
| 394 | 394 | |
| 395 | 395 | if ($d = @opendir(_DIR_LOGOS)) { |
| 396 | - while($f = readdir($d)) { |
|
| 396 | + while ($f = readdir($d)) { |
|
| 397 | 397 | if (preg_match($type, $f, $r)) |
| 398 | 398 | $logos[] = $r[1]; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | @closedir($d); |
| 402 | - return join(',',$logos); |
|
| 402 | + return join(',', $logos); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // fonction appelee par la balise #NOTES |
| 406 | 406 | // Renvoyer l'etat courant des notes, le purger et en preparer un nouveau |
| 407 | 407 | // http://doc.spip.org/@calculer_notes |
| 408 | 408 | function calculer_notes() { |
| 409 | - $r=''; |
|
| 409 | + $r = ''; |
|
| 410 | 410 | if ($notes = charger_fonction('notes', 'inc', true)) { |
| 411 | 411 | $r = $notes(array()); |
| 412 | - $notes('','depiler'); |
|
| 413 | - $notes('','empiler'); |
|
| 412 | + $notes('', 'depiler'); |
|
| 413 | + $notes('', 'empiler'); |
|
| 414 | 414 | } |
| 415 | 415 | return $r; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Selectionner la langue de l'objet dans la boucle, sauf dans les |
| 419 | 419 | // cas ou il ne le faut pas :-) |
| 420 | -function lang_select_public($lang, $lang_select, $titre=null) { |
|
| 420 | +function lang_select_public($lang, $lang_select, $titre = null) { |
|
| 421 | 421 | // Cas 1. forcer_lang = true et pas de critere {lang_select} |
| 422 | 422 | if (isset($GLOBALS['forcer_lang']) AND $GLOBALS['forcer_lang'] |
| 423 | 423 | AND $lang_select !== 'oui') |
@@ -447,9 +447,9 @@ discard block |
||
| 447 | 447 | function nettoyer_env_doublons($envd) { |
| 448 | 448 | foreach ($envd as $table => $liste) { |
| 449 | 449 | $n = ''; |
| 450 | - foreach(explode(',',$liste) as $val) { |
|
| 450 | + foreach (explode(',', $liste) as $val) { |
|
| 451 | 451 | if ($a = intval($val) AND $val === strval($a)) |
| 452 | - $n.= ','.$val; |
|
| 452 | + $n .= ','.$val; |
|
| 453 | 453 | } |
| 454 | 454 | if (strlen($n)) |
| 455 | 455 | $envd[$table] = $n; |
@@ -460,33 +460,33 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // http://doc.spip.org/@match_self |
| 463 | -function match_self($w){ |
|
| 463 | +function match_self($w) { |
|
| 464 | 464 | if (is_string($w)) return false; |
| 465 | 465 | if (is_array($w)) { |
| 466 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $w; |
|
| 467 | - foreach(array_filter($w,'is_array') as $sw) |
|
| 468 | - if ($m=match_self($sw)) return $m; |
|
| 466 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) return $w; |
|
| 467 | + foreach (array_filter($w, 'is_array') as $sw) |
|
| 468 | + if ($m = match_self($sw)) return $m; |
|
| 469 | 469 | } |
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | // http://doc.spip.org/@remplace_sous_requete |
| 473 | -function remplace_sous_requete($w,$sousrequete){ |
|
| 473 | +function remplace_sous_requete($w, $sousrequete) { |
|
| 474 | 474 | if (is_array($w)) { |
| 475 | - if (in_array(reset($w),array("SELF","SUBSELECT"))) return $sousrequete; |
|
| 476 | - foreach($w as $k=>$sw) |
|
| 477 | - $w[$k] = remplace_sous_requete($sw,$sousrequete); |
|
| 475 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) return $sousrequete; |
|
| 476 | + foreach ($w as $k=>$sw) |
|
| 477 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 478 | 478 | } |
| 479 | 479 | return $w; |
| 480 | 480 | } |
| 481 | 481 | // http://doc.spip.org/@trouver_sous_requetes |
| 482 | -function trouver_sous_requetes($where){ |
|
| 482 | +function trouver_sous_requetes($where) { |
|
| 483 | 483 | $where_simples = array(); |
| 484 | 484 | $where_sous = array(); |
| 485 | - foreach($where as $k=>$w){ |
|
| 485 | + foreach ($where as $k=>$w) { |
|
| 486 | 486 | if (match_self($w)) $where_sous[$k] = $w; |
| 487 | 487 | else $where_simples[$k] = $w; |
| 488 | 488 | } |
| 489 | - return array($where_simples,$where_sous); |
|
| 489 | + return array($where_simples, $where_sous); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -510,42 +510,42 @@ discard block |
||
| 510 | 510 | * @param bool $requeter |
| 511 | 511 | * @return resource |
| 512 | 512 | */ |
| 513 | -function calculer_select ($select = array(), $from = array(), |
|
| 513 | +function calculer_select($select = array(), $from = array(), |
|
| 514 | 514 | $from_type = array(), |
| 515 | - $where = array(), $join=array(), |
|
| 515 | + $where = array(), $join = array(), |
|
| 516 | 516 | $groupby = array(), $orderby = array(), $limit = '', |
| 517 | - $having=array(), $table = '', $id = '', $serveur='', $requeter=true) { |
|
| 517 | + $having = array(), $table = '', $id = '', $serveur = '', $requeter = true) { |
|
| 518 | 518 | |
| 519 | 519 | // retirer les criteres vides: |
| 520 | 520 | // {X ?} avec X absent de l'URL |
| 521 | 521 | // {par #ENV{X}} avec X absent de l'URL |
| 522 | 522 | // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
| 523 | 523 | $menage = false; |
| 524 | - foreach($where as $k => $v) { |
|
| 525 | - if (is_array($v)){ |
|
| 526 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 527 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 524 | + foreach ($where as $k => $v) { |
|
| 525 | + if (is_array($v)) { |
|
| 526 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) $op = false; |
|
| 527 | + elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) $op = false; |
|
| 528 | 528 | else $op = $v[0] ? $v[0] : $v; |
| 529 | 529 | } else $op = $v; |
| 530 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 530 | + if ((!$op) OR ($op == 1) OR ($op == '0=0')) { |
|
| 531 | 531 | unset($where[$k]); |
| 532 | 532 | $menage = true; |
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // evacuer les eventuels groupby vide issus d'un calcul dynamique |
| 537 | - $groupby = array_diff($groupby,array('')); |
|
| 537 | + $groupby = array_diff($groupby, array('')); |
|
| 538 | 538 | |
| 539 | 539 | // remplacer les sous requetes recursives au calcul |
| 540 | - list($where_simples,$where_sous) = trouver_sous_requetes($where); |
|
| 541 | - foreach($where_sous as $k=>$w) { |
|
| 540 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 541 | + foreach ($where_sous as $k=>$w) { |
|
| 542 | 542 | $menage = true; |
| 543 | 543 | // on recupere la sous requete |
| 544 | 544 | $sous = match_self($w); |
| 545 | - if ($sous[0]=='SELF') { |
|
| 545 | + if ($sous[0] == 'SELF') { |
|
| 546 | 546 | // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
| 547 | - array_push($where_simples,$sous[2]); |
|
| 548 | - $wheresub = array($sous[2],'0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 547 | + array_push($where_simples, $sous[2]); |
|
| 548 | + $wheresub = array($sous[2], '0=0'); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 549 | 549 | $jsub = $join; |
| 550 | 550 | // trouver les jointures utiles a |
| 551 | 551 | // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
@@ -553,50 +553,50 @@ discard block |
||
| 553 | 553 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 554 | 554 | $i = 0; |
| 555 | 555 | do { |
| 556 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 556 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 557 | 557 | array($sous[1]." AS id"), |
| 558 | 558 | $from, |
| 559 | 559 | $from_type, |
| 560 | 560 | $wheresub, |
| 561 | 561 | $jsub, |
| 562 | - array(),array(),'', |
|
| 563 | - $having,$table,$id,$serveur,false).")"); |
|
| 564 | - if (!$i){ |
|
| 562 | + array(), array(), '', |
|
| 563 | + $having, $table, $id, $serveur, false).")"); |
|
| 564 | + if (!$i) { |
|
| 565 | 565 | $i = 1; |
| 566 | 566 | $wherestring = calculer_where_to_string($where[$k]); |
| 567 | - foreach ($join as $cle=>$wj){ |
|
| 568 | - if (count($wj)==4 |
|
| 569 | - AND strpos($wherestring,"{$cle}.")!==FALSE |
|
| 570 | - ){ |
|
| 567 | + foreach ($join as $cle=>$wj) { |
|
| 568 | + if (count($wj) == 4 |
|
| 569 | + AND strpos($wherestring, "{$cle}.") !== FALSE |
|
| 570 | + ) { |
|
| 571 | 571 | $i = 0; |
| 572 | 572 | $wheresub[] = $wj[3]; |
| 573 | 573 | unset($jsub[$cle][3]); |
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | - } while ($i++<1); |
|
| 577 | + } while ($i++ < 1); |
|
| 578 | 578 | } |
| 579 | - if ($sous[0]=='SUBSELECT') { |
|
| 579 | + if ($sous[0] == 'SUBSELECT') { |
|
| 580 | 580 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 581 | - array_push($where_simples,$sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | - $where[$k] = remplace_sous_requete($w,"(".calculer_select( |
|
| 581 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 582 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 583 | 583 | $sous[1], # select |
| 584 | 584 | $sous[2], #from |
| 585 | 585 | array(), #from_type |
| 586 | - $sous[3]?(is_array($sous[3])?$sous[3]:array($sous[3])):array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 586 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), #where, qui peut etre de la forme string comme dans sql_select |
|
| 587 | 587 | array(), #join |
| 588 | - $sous[4]?$sous[4]:array(), #groupby |
|
| 589 | - $sous[5]?$sous[5]:array(), #orderby |
|
| 588 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 589 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 590 | 590 | $sous[6], #limit |
| 591 | - $sous[7]?$sous[7]:array(), #having |
|
| 592 | - $table,$id,$serveur,false |
|
| 591 | + $sous[7] ? $sous[7] : array(), #having |
|
| 592 | + $table, $id, $serveur, false |
|
| 593 | 593 | ).")"); |
| 594 | 594 | } |
| 595 | 595 | array_pop($where_simples); |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - foreach($having as $k => $v) { |
|
| 599 | - if ((!$v) OR ($v==1) OR ($v=='0=0')) { |
|
| 598 | + foreach ($having as $k => $v) { |
|
| 599 | + if ((!$v) OR ($v == 1) OR ($v == '0=0')) { |
|
| 600 | 600 | unset($having[$k]); |
| 601 | 601 | } |
| 602 | 602 | } |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | $afrom = array(); |
| 610 | 610 | $equiv = array(); |
| 611 | 611 | $k = count($join); |
| 612 | - foreach(array_reverse($join,true) as $cledef=>$j) { |
|
| 612 | + foreach (array_reverse($join, true) as $cledef=>$j) { |
|
| 613 | 613 | $cle = $cledef; |
| 614 | 614 | // le format de join est : |
| 615 | 615 | // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
| 616 | - if (count($join[$cle])==2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | - if (count($join[$cle])==3) $join[$cle][] = ''; |
|
| 618 | - list($t,$c,$carr,$and) = $join[$cle]; |
|
| 616 | + if (count($join[$cle]) == 2) $join[$cle][] = $join[$cle][1]; |
|
| 617 | + if (count($join[$cle]) == 3) $join[$cle][] = ''; |
|
| 618 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 619 | 619 | // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
| 620 | 620 | // pour compat avec ancienne convention |
| 621 | 621 | if (is_numeric($cle)) |
@@ -628,13 +628,13 @@ discard block |
||
| 628 | 628 | OR calculer_jointnul($cle, $where_simples)) { |
| 629 | 629 | // corriger les references non explicites dans select |
| 630 | 630 | // ou groupby |
| 631 | - foreach($select as $i=>$s) { |
|
| 631 | + foreach ($select as $i=>$s) { |
|
| 632 | 632 | if ($s == $c) { |
| 633 | 633 | $select[$i] = "$cle.$c AS $c"; |
| 634 | 634 | break; |
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | - foreach($groupby as $i=>$g) { |
|
| 637 | + foreach ($groupby as $i=>$g) { |
|
| 638 | 638 | if ($g == $c) { |
| 639 | 639 | $groupby[$i] = "$cle.$c"; |
| 640 | 640 | break; |
@@ -643,22 +643,22 @@ discard block |
||
| 643 | 643 | // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
| 644 | 644 | // sans recours a preg_match |
| 645 | 645 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 646 | - $afrom[$t][$cle] = array("\n" . |
|
| 647 | - (isset($from_type[$cle])?$from_type[$cle]:"INNER")." JOIN", |
|
| 646 | + $afrom[$t][$cle] = array("\n". |
|
| 647 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER")." JOIN", |
|
| 648 | 648 | $from[$cle], |
| 649 | 649 | "AS $cle", |
| 650 | 650 | "ON (", |
| 651 | 651 | "$cle.$c", |
| 652 | 652 | "=", |
| 653 | 653 | "$t.$carr", |
| 654 | - ($and ? "AND ". $and:"") . |
|
| 654 | + ($and ? "AND ".$and : ""). |
|
| 655 | 655 | ")"); |
| 656 | - if (isset($afrom[$cle])){ |
|
| 656 | + if (isset($afrom[$cle])) { |
|
| 657 | 657 | $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
| 658 | 658 | unset($afrom[$cle]); |
| 659 | 659 | } |
| 660 | - $equiv[]= $carr; |
|
| 661 | - } else { unset($join[$cledef]);} |
|
| 660 | + $equiv[] = $carr; |
|
| 661 | + } else { unset($join[$cledef]); } |
|
| 662 | 662 | unset($from[$cle]); |
| 663 | 663 | $k--; |
| 664 | 664 | } |
@@ -679,9 +679,9 @@ discard block |
||
| 679 | 679 | // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
| 680 | 680 | // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
| 681 | 681 | |
| 682 | - list($t,$c) = each($from); |
|
| 682 | + list($t, $c) = each($from); |
|
| 683 | 683 | reset($from); |
| 684 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 684 | + $e = '/\b('."$t\\.".join("|".$t.'\.', $equiv).')\b/'; |
|
| 685 | 685 | if (!(strpos($t, ' ') OR // jointure des le depart cf boucle_doc |
| 686 | 686 | calculer_jointnul($t, $select, $e) OR |
| 687 | 687 | calculer_jointnul($t, $join, $e) OR |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | calculer_jointnul($t, $having, $e)) |
| 692 | 692 | && count($afrom[$t])) { |
| 693 | 693 | reset($afrom[$t]); |
| 694 | - list($nt,$nfrom) = each($afrom[$t]); |
|
| 694 | + list($nt, $nfrom) = each($afrom[$t]); |
|
| 695 | 695 | unset($from[$t]); |
| 696 | 696 | $from[$nt] = $nfrom[1]; |
| 697 | 697 | unset($afrom[$t][$nt]); |
@@ -701,21 +701,21 @@ discard block |
||
| 701 | 701 | $t = $nfrom[4]; |
| 702 | 702 | $alias = ""; |
| 703 | 703 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
| 704 | - $oldcle = explode('.',$nfrom[6]); |
|
| 704 | + $oldcle = explode('.', $nfrom[6]); |
|
| 705 | 705 | $oldcle = end($oldcle); |
| 706 | - $newcle = explode('.',$nfrom[4]); |
|
| 706 | + $newcle = explode('.', $nfrom[4]); |
|
| 707 | 707 | $newcle = end($newcle); |
| 708 | - if ($newcle!=$oldcle){ |
|
| 708 | + if ($newcle != $oldcle) { |
|
| 709 | 709 | // si l'ancienne cle etait deja dans le select avec un AS |
| 710 | 710 | // reprendre simplement ce AS |
| 711 | 711 | $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
| 712 | - if (preg_match($as,implode(',',$select),$m)){ |
|
| 712 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 713 | 713 | $alias = ""; |
| 714 | 714 | } |
| 715 | 715 | else |
| 716 | 716 | $alias = ", ".$nfrom[4]." AS $oldcle"; |
| 717 | 717 | } |
| 718 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 718 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 719 | 719 | $join = remplacer_jointnul($t, $join, $e); |
| 720 | 720 | $where = remplacer_jointnul($t, $where, $e); |
| 721 | 721 | $having = remplacer_jointnul($t, $having, $e); |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | } |
| 725 | 725 | $from = reinjecte_joint($afrom, $from); |
| 726 | 726 | } |
| 727 | - $GLOBALS['debug']['aucasou'] = array ($table, $id, $serveur, $requeter); |
|
| 727 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 728 | 728 | $r = sql_select($select, $from, $where, |
| 729 | 729 | $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
| 730 | 730 | unset($GLOBALS['debug']['aucasou']); |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * @param string $join |
| 738 | 738 | * @return string |
| 739 | 739 | */ |
| 740 | -function calculer_where_to_string($v, $join = 'AND'){ |
|
| 740 | +function calculer_where_to_string($v, $join = 'AND') { |
|
| 741 | 741 | if (empty($v)) |
| 742 | 742 | return ''; |
| 743 | 743 | |
@@ -746,9 +746,9 @@ discard block |
||
| 746 | 746 | } else { |
| 747 | 747 | $exp = ""; |
| 748 | 748 | if (strtoupper($join) === 'AND') |
| 749 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 749 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 750 | 750 | else |
| 751 | - return $exp . join($join, $v); |
|
| 751 | + return $exp.join($join, $v); |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | |
@@ -756,13 +756,13 @@ discard block |
||
| 756 | 756 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 757 | 757 | |
| 758 | 758 | // http://doc.spip.org/@calculer_jointnul |
| 759 | -function calculer_jointnul($cle, $exp, $equiv='') |
|
| 759 | +function calculer_jointnul($cle, $exp, $equiv = '') |
|
| 760 | 760 | { |
| 761 | 761 | if (!is_array($exp)) { |
| 762 | 762 | if ($equiv) $exp = preg_replace($equiv, '', $exp); |
| 763 | 763 | return preg_match("/\\b$cle\\./", $exp); |
| 764 | 764 | } else { |
| 765 | - foreach($exp as $v) { |
|
| 765 | + foreach ($exp as $v) { |
|
| 766 | 766 | if (calculer_jointnul($cle, $v, $equiv)) return true; |
| 767 | 767 | } |
| 768 | 768 | return false; |
@@ -773,11 +773,11 @@ discard block |
||
| 773 | 773 | function reinjecte_joint($afrom, $from) |
| 774 | 774 | { |
| 775 | 775 | $from_synth = array(); |
| 776 | - foreach($from as $k=>$v){ |
|
| 777 | - $from_synth[$k]=$from[$k]; |
|
| 776 | + foreach ($from as $k=>$v) { |
|
| 777 | + $from_synth[$k] = $from[$k]; |
|
| 778 | 778 | if (isset($afrom[$k])) { |
| 779 | - foreach($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ',$afrom[$k][$kk]); |
|
| 780 | - $from_synth["$k@"]= implode(' ',$afrom[$k]); |
|
| 779 | + foreach ($afrom[$k] as $kk=>$vv) $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 780 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 781 | 781 | unset($afrom[$k]); |
| 782 | 782 | } |
| 783 | 783 | } |
@@ -785,12 +785,12 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // http://doc.spip.org/@remplacer_jointnul |
| 788 | -function remplacer_jointnul($cle, $exp, $equiv='') |
|
| 788 | +function remplacer_jointnul($cle, $exp, $equiv = '') |
|
| 789 | 789 | { |
| 790 | 790 | if (!is_array($exp)) { |
| 791 | 791 | return preg_replace($equiv, $cle, $exp); |
| 792 | 792 | } else { |
| 793 | - foreach($exp as $k => $v) { |
|
| 793 | + foreach ($exp as $k => $v) { |
|
| 794 | 794 | $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
| 795 | 795 | } |
| 796 | 796 | return $exp; |
@@ -799,14 +799,14 @@ discard block |
||
| 799 | 799 | |
| 800 | 800 | // calcul du nom du squelette |
| 801 | 801 | // http://doc.spip.org/@calculer_nom_fonction_squel |
| 802 | -function calculer_nom_fonction_squel($skel, $mime_type='html', $connect='') |
|
| 802 | +function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') |
|
| 803 | 803 | { |
| 804 | 804 | // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
| 805 | - if ($l=strlen(_DIR_RACINE) AND strncmp($skel,_DIR_RACINE,$l)==0) |
|
| 806 | - $skel = substr($skel,strlen(_DIR_RACINE)); |
|
| 805 | + if ($l = strlen(_DIR_RACINE) AND strncmp($skel, _DIR_RACINE, $l) == 0) |
|
| 806 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 807 | 807 | return $mime_type |
| 808 | - . (!$connect ? '' : preg_replace('/\W/',"_", $connect)) . '_' |
|
| 809 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel'])?'*'.$GLOBALS['marqueur_skel']:'')); |
|
| 808 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)).'_' |
|
| 809 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | ?> |
@@ -200,6 +200,9 @@ discard block |
||
| 200 | 200 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 201 | 201 | |
| 202 | 202 | // http://doc.spip.org/@phraser_champs_etendus |
| 203 | +/** |
|
| 204 | + * @param integer $ligne |
|
| 205 | + */ |
|
| 203 | 206 | function phraser_champs_etendus($texte, $ligne, $result){ |
| 204 | 207 | if ($texte==="") return $result; |
| 205 | 208 | $sep = '##'; |
@@ -216,6 +219,9 @@ discard block |
||
| 216 | 219 | // Tres chevelu |
| 217 | 220 | |
| 218 | 221 | // http://doc.spip.org/@phraser_args |
| 222 | +/** |
|
| 223 | + * @param string $fin |
|
| 224 | + */ |
|
| 219 | 225 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ){ |
| 220 | 226 | $texte = ltrim($texte); |
| 221 | 227 | while (($texte!=="") && strpos($fin, $texte[0])===false){ |
@@ -230,6 +236,9 @@ discard block |
||
| 230 | 236 | } |
| 231 | 237 | |
| 232 | 238 | // http://doc.spip.org/@phraser_arg |
| 239 | +/** |
|
| 240 | + * @param string $texte |
|
| 241 | + */ |
|
| 233 | 242 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ){ |
| 234 | 243 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 235 | 244 | $suite = ltrim($match[2]); |
@@ -355,6 +364,9 @@ discard block |
||
| 355 | 364 | |
| 356 | 365 | |
| 357 | 366 | // http://doc.spip.org/@phraser_champs_exterieurs |
| 367 | +/** |
|
| 368 | + * @param string $texte |
|
| 369 | + */ |
|
| 358 | 370 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested){ |
| 359 | 371 | $res = array(); |
| 360 | 372 | while (($p = strpos($texte, "%$sep"))!==false){ |
@@ -372,6 +384,9 @@ discard block |
||
| 372 | 384 | } |
| 373 | 385 | |
| 374 | 386 | // http://doc.spip.org/@phraser_champs_interieurs |
| 387 | +/** |
|
| 388 | + * @param string $sep |
|
| 389 | + */ |
|
| 375 | 390 | function phraser_champs_interieurs($texte, $ligne, $sep, $result){ |
| 376 | 391 | $i = 0; // en fait count($result) |
| 377 | 392 | $x = ""; |
@@ -634,6 +649,10 @@ discard block |
||
| 634 | 649 | } |
| 635 | 650 | |
| 636 | 651 | // http://doc.spip.org/@phraser_critere_infixe |
| 652 | +/** |
|
| 653 | + * @param string $arg1 |
|
| 654 | + * @param string $arg2 |
|
| 655 | + */ |
|
| 637 | 656 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond){ |
| 638 | 657 | $args[0] = new Texte; |
| 639 | 658 | $args[0]->texte = $arg1; |
@@ -41,77 +41,77 @@ discard block |
||
| 41 | 41 | // http://doc.spip.org/@phraser_inclure |
| 42 | 42 | function phraser_inclure($texte, $ligne, $result){ |
| 43 | 43 | |
| 44 | - while (preg_match(BALISE_INCLURE, $texte, $match)){ |
|
| 45 | - $p = strpos($texte, $match[0]); |
|
| 46 | - $debut = substr($texte, 0, $p); |
|
| 47 | - if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
|
| 48 | - $ligne += substr_count($debut, "\n"); |
|
| 49 | - $champ = new Inclure; |
|
| 50 | - $champ->ligne = $ligne; |
|
| 51 | - $ligne += substr_count($match[0], "\n"); |
|
| 52 | - $fichier = @$match[2]; |
|
| 53 | - # assurer ici la migration .php3 => .php |
|
| 54 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 55 | - if (preg_match(',^(.*[.]php)3$,', $fichier, $r)){ |
|
| 56 | - $fichier = $r[1]; |
|
| 57 | - } |
|
| 58 | - $champ->texte = ($fichier!=='page.php') ? $fichier : ''; |
|
| 59 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 60 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 61 | - phraser_args($texte, "/>", "", $result, $champ); |
|
| 62 | - if (!$champ->texte OR count($champ->param)>1){ |
|
| 63 | - if (!function_exists('normaliser_inclure')) |
|
| 64 | - include_spip('public/normaliser'); |
|
| 65 | - normaliser_inclure($champ); |
|
| 66 | - } |
|
| 67 | - $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
|
| 68 | - $champ->apres = ""; |
|
| 69 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 70 | - $result[] = $champ; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 44 | + while (preg_match(BALISE_INCLURE, $texte, $match)){ |
|
| 45 | + $p = strpos($texte, $match[0]); |
|
| 46 | + $debut = substr($texte, 0, $p); |
|
| 47 | + if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
|
| 48 | + $ligne += substr_count($debut, "\n"); |
|
| 49 | + $champ = new Inclure; |
|
| 50 | + $champ->ligne = $ligne; |
|
| 51 | + $ligne += substr_count($match[0], "\n"); |
|
| 52 | + $fichier = @$match[2]; |
|
| 53 | + # assurer ici la migration .php3 => .php |
|
| 54 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 55 | + if (preg_match(',^(.*[.]php)3$,', $fichier, $r)){ |
|
| 56 | + $fichier = $r[1]; |
|
| 57 | + } |
|
| 58 | + $champ->texte = ($fichier!=='page.php') ? $fichier : ''; |
|
| 59 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 60 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 61 | + phraser_args($texte, "/>", "", $result, $champ); |
|
| 62 | + if (!$champ->texte OR count($champ->param)>1){ |
|
| 63 | + if (!function_exists('normaliser_inclure')) |
|
| 64 | + include_spip('public/normaliser'); |
|
| 65 | + normaliser_inclure($champ); |
|
| 66 | + } |
|
| 67 | + $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
|
| 68 | + $champ->apres = ""; |
|
| 69 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 70 | + $result[] = $champ; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // http://doc.spip.org/@phraser_polyglotte |
| 77 | 77 | function phraser_polyglotte($texte, $ligne, $result){ |
| 78 | 78 | |
| 79 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
|
| 80 | - foreach ($m as $match){ |
|
| 81 | - $p = strpos($texte, $match[0]); |
|
| 82 | - $debut = substr($texte, 0, $p); |
|
| 83 | - if ($p){ |
|
| 84 | - $champ = new Texte; |
|
| 85 | - $champ->texte = $debut; |
|
| 86 | - $champ->ligne = $ligne; |
|
| 87 | - $result[] = $champ; |
|
| 88 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champ = new Polyglotte; |
|
| 92 | - $champ->ligne = $ligne; |
|
| 93 | - $ligne += substr_count($match[0], "\n"); |
|
| 94 | - $lang = ''; |
|
| 95 | - $bloc = $match[1]; |
|
| 96 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 97 | - while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
|
| 98 | - $trad = $regs[1]; |
|
| 99 | - if ($trad OR $lang) |
|
| 100 | - $champ->traductions[$lang] = $trad; |
|
| 101 | - $lang = $regs[2]; |
|
| 102 | - $bloc = $regs[3]; |
|
| 103 | - } |
|
| 104 | - $champ->traductions[$lang] = $bloc; |
|
| 105 | - $result[] = $champ; |
|
| 106 | - } |
|
| 107 | - if ($texte!==""){ |
|
| 108 | - $champ = new Texte; |
|
| 109 | - $champ->texte = $texte; |
|
| 110 | - $champ->ligne = $ligne; |
|
| 111 | - $result[] = $champ; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $result; |
|
| 79 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
|
| 80 | + foreach ($m as $match){ |
|
| 81 | + $p = strpos($texte, $match[0]); |
|
| 82 | + $debut = substr($texte, 0, $p); |
|
| 83 | + if ($p){ |
|
| 84 | + $champ = new Texte; |
|
| 85 | + $champ->texte = $debut; |
|
| 86 | + $champ->ligne = $ligne; |
|
| 87 | + $result[] = $champ; |
|
| 88 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champ = new Polyglotte; |
|
| 92 | + $champ->ligne = $ligne; |
|
| 93 | + $ligne += substr_count($match[0], "\n"); |
|
| 94 | + $lang = ''; |
|
| 95 | + $bloc = $match[1]; |
|
| 96 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 97 | + while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
|
| 98 | + $trad = $regs[1]; |
|
| 99 | + if ($trad OR $lang) |
|
| 100 | + $champ->traductions[$lang] = $trad; |
|
| 101 | + $lang = $regs[2]; |
|
| 102 | + $bloc = $regs[3]; |
|
| 103 | + } |
|
| 104 | + $champ->traductions[$lang] = $bloc; |
|
| 105 | + $result[] = $champ; |
|
| 106 | + } |
|
| 107 | + if ($texte!==""){ |
|
| 108 | + $champ = new Texte; |
|
| 109 | + $champ->texte = $texte; |
|
| 110 | + $champ->ligne = $ligne; |
|
| 111 | + $result[] = $champ; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $result; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -121,77 +121,77 @@ discard block |
||
| 121 | 121 | // sinon ce n'est pas un idiome |
| 122 | 122 | // http://doc.spip.org/@phraser_idiomes |
| 123 | 123 | function phraser_idiomes($texte, $ligne, $result){ |
| 124 | - while (preg_match(BALISE_IDIOMES, $texte, $match)){ |
|
| 125 | - $p = strpos($texte, $match[0]); |
|
| 126 | - $ko = (!$match[3] && ($match[5][0]!=='=')); |
|
| 127 | - $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
|
| 128 | - if ($debut) $result = phraser_champs($debut, $ligne, $result); |
|
| 129 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 130 | - $ligne += substr_count($debut, "\n"); |
|
| 131 | - if ($ko) continue; // faux idiome |
|
| 132 | - $champ = new Idiome; |
|
| 133 | - $champ->ligne = $ligne; |
|
| 134 | - $ligne += substr_count($match[0], "\n"); |
|
| 135 | - // Stocker les arguments de la balise de traduction |
|
| 136 | - $args = array(); |
|
| 137 | - $largs = $match[5]; |
|
| 138 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)){ |
|
| 139 | - $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 140 | - $largs = substr($largs, strlen($r[0])); |
|
| 141 | - } |
|
| 142 | - $champ->arg = $args; |
|
| 143 | - $champ->nom_champ = strtolower($match[3]); |
|
| 144 | - $champ->module = $match[2]; |
|
| 145 | - // pas d'imbrication pour les filtres sur langue |
|
| 146 | - phraser_args(@$match[7], ":", '', array(), $champ); |
|
| 147 | - $result[] = $champ; |
|
| 148 | - } |
|
| 149 | - if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 150 | - |
|
| 151 | - return $result; |
|
| 124 | + while (preg_match(BALISE_IDIOMES, $texte, $match)){ |
|
| 125 | + $p = strpos($texte, $match[0]); |
|
| 126 | + $ko = (!$match[3] && ($match[5][0]!=='=')); |
|
| 127 | + $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
|
| 128 | + if ($debut) $result = phraser_champs($debut, $ligne, $result); |
|
| 129 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 130 | + $ligne += substr_count($debut, "\n"); |
|
| 131 | + if ($ko) continue; // faux idiome |
|
| 132 | + $champ = new Idiome; |
|
| 133 | + $champ->ligne = $ligne; |
|
| 134 | + $ligne += substr_count($match[0], "\n"); |
|
| 135 | + // Stocker les arguments de la balise de traduction |
|
| 136 | + $args = array(); |
|
| 137 | + $largs = $match[5]; |
|
| 138 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)){ |
|
| 139 | + $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 140 | + $largs = substr($largs, strlen($r[0])); |
|
| 141 | + } |
|
| 142 | + $champ->arg = $args; |
|
| 143 | + $champ->nom_champ = strtolower($match[3]); |
|
| 144 | + $champ->module = $match[2]; |
|
| 145 | + // pas d'imbrication pour les filtres sur langue |
|
| 146 | + phraser_args(@$match[7], ":", '', array(), $champ); |
|
| 147 | + $result[] = $champ; |
|
| 148 | + } |
|
| 149 | + if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 150 | + |
|
| 151 | + return $result; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // http://doc.spip.org/@phraser_champs |
| 155 | 155 | function phraser_champs($texte, $ligne, $result){ |
| 156 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)){ |
|
| 157 | - $p = strpos($texte, $match[0]); |
|
| 158 | - $suite = substr($texte, $p+strlen($match[0])); |
|
| 159 | - if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
|
| 160 | - $debut = substr($texte, 0, $p); |
|
| 161 | - if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 162 | - $ligne += substr_count($debut, "\n"); |
|
| 163 | - $champ = new Champ; |
|
| 164 | - $champ->ligne = $ligne; |
|
| 165 | - $ligne += substr_count($match[0], "\n"); |
|
| 166 | - $champ->nom_boucle = $match[2]; |
|
| 167 | - $champ->nom_champ = $match[3]; |
|
| 168 | - $champ->etoile = $match[5]; |
|
| 169 | - |
|
| 170 | - if ($suite[0]=='{'){ |
|
| 171 | - phraser_arg($suite, '', array(), $champ); |
|
| 172 | - // ce ltrim est une ereur de conception |
|
| 173 | - // mais on le conserve par souci de compatibilite |
|
| 174 | - $texte = ltrim($suite); |
|
| 175 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 176 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 177 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 156 | + while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)){ |
|
| 157 | + $p = strpos($texte, $match[0]); |
|
| 158 | + $suite = substr($texte, $p+strlen($match[0])); |
|
| 159 | + if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
|
| 160 | + $debut = substr($texte, 0, $p); |
|
| 161 | + if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 162 | + $ligne += substr_count($debut, "\n"); |
|
| 163 | + $champ = new Champ; |
|
| 164 | + $champ->ligne = $ligne; |
|
| 165 | + $ligne += substr_count($match[0], "\n"); |
|
| 166 | + $champ->nom_boucle = $match[2]; |
|
| 167 | + $champ->nom_champ = $match[3]; |
|
| 168 | + $champ->etoile = $match[5]; |
|
| 169 | + |
|
| 170 | + if ($suite[0]=='{'){ |
|
| 171 | + phraser_arg($suite, '', array(), $champ); |
|
| 172 | + // ce ltrim est une ereur de conception |
|
| 173 | + // mais on le conserve par souci de compatibilite |
|
| 174 | + $texte = ltrim($suite); |
|
| 175 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 176 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 177 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 178 | 178 | if ($n = (strlen($suite) - strlen($texte))) { |
| 179 | 179 | $champ->apres = array(new Texte); |
| 180 | 180 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 181 | 181 | } |
| 182 | 182 | */ |
| 183 | - } else $texte = $suite; |
|
| 184 | - phraser_vieux($champ); |
|
| 185 | - $result[] = $champ; |
|
| 186 | - } else { |
|
| 187 | - // faux champ |
|
| 188 | - $result = phraser_polyglotte(substr($texte, 0, $p+1), $ligne, $result); |
|
| 189 | - $texte = (substr($texte, $p+1)); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 193 | - |
|
| 194 | - return $result; |
|
| 183 | + } else $texte = $suite; |
|
| 184 | + phraser_vieux($champ); |
|
| 185 | + $result[] = $champ; |
|
| 186 | + } else { |
|
| 187 | + // faux champ |
|
| 188 | + $result = phraser_polyglotte(substr($texte, 0, $p+1), $ligne, $result); |
|
| 189 | + $texte = (substr($texte, $p+1)); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 193 | + |
|
| 194 | + return $result; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Gestion des imbrications: |
@@ -201,12 +201,12 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | // http://doc.spip.org/@phraser_champs_etendus |
| 203 | 203 | function phraser_champs_etendus($texte, $ligne, $result){ |
| 204 | - if ($texte==="") return $result; |
|
| 205 | - $sep = '##'; |
|
| 206 | - while (strpos($texte, $sep)!==false) |
|
| 207 | - $sep .= '#'; |
|
| 204 | + if ($texte==="") return $result; |
|
| 205 | + $sep = '##'; |
|
| 206 | + while (strpos($texte, $sep)!==false) |
|
| 207 | + $sep .= '#'; |
|
| 208 | 208 | |
| 209 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 209 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Analyse les filtres d'un champ etendu et affecte le resultat |
@@ -217,248 +217,248 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | // http://doc.spip.org/@phraser_args |
| 219 | 219 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ){ |
| 220 | - $texte = ltrim($texte); |
|
| 221 | - while (($texte!=="") && strpos($fin, $texte[0])===false){ |
|
| 222 | - $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 223 | - $texte = ltrim($texte); |
|
| 224 | - } |
|
| 220 | + $texte = ltrim($texte); |
|
| 221 | + while (($texte!=="") && strpos($fin, $texte[0])===false){ |
|
| 222 | + $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 223 | + $texte = ltrim($texte); |
|
| 224 | + } |
|
| 225 | 225 | # mettre ici la suite du texte, |
| 226 | 226 | # notamment pour que l'appelant vire le caractere fermant si besoin |
| 227 | - $pointeur_champ->apres = $texte; |
|
| 227 | + $pointeur_champ->apres = $texte; |
|
| 228 | 228 | |
| 229 | - return $result; |
|
| 229 | + return $result; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // http://doc.spip.org/@phraser_arg |
| 233 | 233 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ){ |
| 234 | - preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 235 | - $suite = ltrim($match[2]); |
|
| 236 | - $fonc = trim($match[1]); |
|
| 237 | - if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 238 | - $res = array($fonc); |
|
| 239 | - $err_f = ''; |
|
| 240 | - // cas du filtre sans argument ou du critere / |
|
| 241 | - if (($suite && ($suite[0]!='{')) || ($fonc && $fonc[0]=='/')){ |
|
| 242 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 243 | - if (!$match[1]){ |
|
| 244 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 245 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 246 | - $texte = ''; |
|
| 247 | - } else $texte = $suite; |
|
| 248 | - if ($err_f) $pointeur_champ->param = false; |
|
| 249 | - elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 250 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 251 | - $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 252 | - |
|
| 253 | - return $result; |
|
| 254 | - } |
|
| 255 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 256 | - $collecte = array(); |
|
| 257 | - while ($args && $args[0]!='}'){ |
|
| 258 | - if ($args[0]=='"') |
|
| 259 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 260 | - else if ($args[0]=="'") |
|
| 261 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 262 | - else { |
|
| 263 | - preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 264 | - if (!strlen($regs[2])){ |
|
| 265 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 266 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 267 | - $champ = new Texte; |
|
| 268 | - $champ->apres = $champ->avant = $args = ""; |
|
| 269 | - break; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $arg = $regs[2]; |
|
| 273 | - if (trim($regs[1])){ |
|
| 274 | - $champ = new Texte; |
|
| 275 | - $champ->texte = $arg; |
|
| 276 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 277 | - $result[] = $champ; |
|
| 278 | - $collecte[] = $champ; |
|
| 279 | - $args = ltrim($regs[count($regs)-1]); |
|
| 280 | - } else { |
|
| 281 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)){ |
|
| 282 | - // 0 est un aveu d'impuissance. A completer |
|
| 283 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 284 | - |
|
| 285 | - $args = ltrim($regs[count($regs)-1]); |
|
| 286 | - $collecte = array_merge($collecte, $arg); |
|
| 287 | - $result = array_merge($result, $arg); |
|
| 288 | - } else { |
|
| 289 | - $n = strpos($args, $r[0]); |
|
| 290 | - $pred = substr($args, 0, $n); |
|
| 291 | - $par = ',}'; |
|
| 292 | - if (preg_match('/^(.*)\($/', $pred, $m)){ |
|
| 293 | - $pred = $m[1]; |
|
| 294 | - $par = ')'; |
|
| 295 | - } |
|
| 296 | - if ($pred){ |
|
| 297 | - $champ = new Texte; |
|
| 298 | - $champ->texte = $pred; |
|
| 299 | - $champ->apres = $champ->avant = ""; |
|
| 300 | - $result[] = $champ; |
|
| 301 | - $collecte[] = $champ; |
|
| 302 | - } |
|
| 303 | - $rec = substr($args, $n+strlen($r[0])-1); |
|
| 304 | - $champ = new Champ; |
|
| 305 | - $champ->nom_boucle = $r[2]; |
|
| 306 | - $champ->nom_champ = $r[3]; |
|
| 307 | - $champ->etoile = $r[5]; |
|
| 308 | - $next = $r[6]; |
|
| 309 | - while ($next=='{'){ |
|
| 310 | - phraser_arg($rec, $sep, array(), $champ); |
|
| 311 | - $args = ltrim($rec); |
|
| 312 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 313 | - } |
|
| 314 | - while ($next=='|'){ |
|
| 315 | - phraser_args($rec, $par, $sep, array(), $champ); |
|
| 316 | - $args = $champ->apres; |
|
| 317 | - $champ->apres = ''; |
|
| 318 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 319 | - } |
|
| 320 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 321 | - if ($champ->param===false) |
|
| 322 | - $err_f = true; |
|
| 323 | - else phraser_vieux($champ); |
|
| 324 | - if ($par==')') $args = substr($args, 1); |
|
| 325 | - $collecte[] = $champ; |
|
| 326 | - $result[] = $champ; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if (isset($args[0]) AND $args[0]==','){ |
|
| 330 | - $args = ltrim(substr($args, 1)); |
|
| 331 | - if ($collecte){ |
|
| 332 | - $res[] = $collecte; |
|
| 333 | - $collecte = array(); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - if ($collecte){ |
|
| 338 | - $res[] = $collecte; |
|
| 339 | - $collecte = array(); |
|
| 340 | - } |
|
| 341 | - $texte = substr($args, 1); |
|
| 342 | - $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
|
| 343 | - // propager les erreurs, et ignorer les param vides |
|
| 344 | - if ($pointeur_champ->param!==false){ |
|
| 345 | - if ($err_f) |
|
| 346 | - $pointeur_champ->param = false; |
|
| 347 | - elseif ($fonc!=='' || count($res)>1) |
|
| 348 | - $pointeur_champ->param[] = $res; |
|
| 349 | - } |
|
| 350 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 351 | - $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 352 | - |
|
| 353 | - return $result; |
|
| 234 | + preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 235 | + $suite = ltrim($match[2]); |
|
| 236 | + $fonc = trim($match[1]); |
|
| 237 | + if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 238 | + $res = array($fonc); |
|
| 239 | + $err_f = ''; |
|
| 240 | + // cas du filtre sans argument ou du critere / |
|
| 241 | + if (($suite && ($suite[0]!='{')) || ($fonc && $fonc[0]=='/')){ |
|
| 242 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 243 | + if (!$match[1]){ |
|
| 244 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 245 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 246 | + $texte = ''; |
|
| 247 | + } else $texte = $suite; |
|
| 248 | + if ($err_f) $pointeur_champ->param = false; |
|
| 249 | + elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 250 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 251 | + $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 252 | + |
|
| 253 | + return $result; |
|
| 254 | + } |
|
| 255 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 256 | + $collecte = array(); |
|
| 257 | + while ($args && $args[0]!='}'){ |
|
| 258 | + if ($args[0]=='"') |
|
| 259 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 260 | + else if ($args[0]=="'") |
|
| 261 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 262 | + else { |
|
| 263 | + preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 264 | + if (!strlen($regs[2])){ |
|
| 265 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 266 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 267 | + $champ = new Texte; |
|
| 268 | + $champ->apres = $champ->avant = $args = ""; |
|
| 269 | + break; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $arg = $regs[2]; |
|
| 273 | + if (trim($regs[1])){ |
|
| 274 | + $champ = new Texte; |
|
| 275 | + $champ->texte = $arg; |
|
| 276 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 277 | + $result[] = $champ; |
|
| 278 | + $collecte[] = $champ; |
|
| 279 | + $args = ltrim($regs[count($regs)-1]); |
|
| 280 | + } else { |
|
| 281 | + if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)){ |
|
| 282 | + // 0 est un aveu d'impuissance. A completer |
|
| 283 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 284 | + |
|
| 285 | + $args = ltrim($regs[count($regs)-1]); |
|
| 286 | + $collecte = array_merge($collecte, $arg); |
|
| 287 | + $result = array_merge($result, $arg); |
|
| 288 | + } else { |
|
| 289 | + $n = strpos($args, $r[0]); |
|
| 290 | + $pred = substr($args, 0, $n); |
|
| 291 | + $par = ',}'; |
|
| 292 | + if (preg_match('/^(.*)\($/', $pred, $m)){ |
|
| 293 | + $pred = $m[1]; |
|
| 294 | + $par = ')'; |
|
| 295 | + } |
|
| 296 | + if ($pred){ |
|
| 297 | + $champ = new Texte; |
|
| 298 | + $champ->texte = $pred; |
|
| 299 | + $champ->apres = $champ->avant = ""; |
|
| 300 | + $result[] = $champ; |
|
| 301 | + $collecte[] = $champ; |
|
| 302 | + } |
|
| 303 | + $rec = substr($args, $n+strlen($r[0])-1); |
|
| 304 | + $champ = new Champ; |
|
| 305 | + $champ->nom_boucle = $r[2]; |
|
| 306 | + $champ->nom_champ = $r[3]; |
|
| 307 | + $champ->etoile = $r[5]; |
|
| 308 | + $next = $r[6]; |
|
| 309 | + while ($next=='{'){ |
|
| 310 | + phraser_arg($rec, $sep, array(), $champ); |
|
| 311 | + $args = ltrim($rec); |
|
| 312 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 313 | + } |
|
| 314 | + while ($next=='|'){ |
|
| 315 | + phraser_args($rec, $par, $sep, array(), $champ); |
|
| 316 | + $args = $champ->apres; |
|
| 317 | + $champ->apres = ''; |
|
| 318 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 319 | + } |
|
| 320 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 321 | + if ($champ->param===false) |
|
| 322 | + $err_f = true; |
|
| 323 | + else phraser_vieux($champ); |
|
| 324 | + if ($par==')') $args = substr($args, 1); |
|
| 325 | + $collecte[] = $champ; |
|
| 326 | + $result[] = $champ; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if (isset($args[0]) AND $args[0]==','){ |
|
| 330 | + $args = ltrim(substr($args, 1)); |
|
| 331 | + if ($collecte){ |
|
| 332 | + $res[] = $collecte; |
|
| 333 | + $collecte = array(); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + if ($collecte){ |
|
| 338 | + $res[] = $collecte; |
|
| 339 | + $collecte = array(); |
|
| 340 | + } |
|
| 341 | + $texte = substr($args, 1); |
|
| 342 | + $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
|
| 343 | + // propager les erreurs, et ignorer les param vides |
|
| 344 | + if ($pointeur_champ->param!==false){ |
|
| 345 | + if ($err_f) |
|
| 346 | + $pointeur_champ->param = false; |
|
| 347 | + elseif ($fonc!=='' || count($res)>1) |
|
| 348 | + $pointeur_champ->param[] = $res; |
|
| 349 | + } |
|
| 350 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 351 | + $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 352 | + |
|
| 353 | + return $result; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
| 357 | 357 | // http://doc.spip.org/@phraser_champs_exterieurs |
| 358 | 358 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested){ |
| 359 | - $res = array(); |
|
| 360 | - while (($p = strpos($texte, "%$sep"))!==false){ |
|
| 361 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | - break; |
|
| 363 | - $debut = substr($texte, 0, $p); |
|
| 364 | - $texte = substr($texte, $p+strlen($m[0])); |
|
| 365 | - if ($p) |
|
| 366 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 367 | - $ligne += substr_count($debut, "\n"); |
|
| 368 | - $res[] = $nested[$m[1]]; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return (($texte==='') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 359 | + $res = array(); |
|
| 360 | + while (($p = strpos($texte, "%$sep"))!==false){ |
|
| 361 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | + break; |
|
| 363 | + $debut = substr($texte, 0, $p); |
|
| 364 | + $texte = substr($texte, $p+strlen($m[0])); |
|
| 365 | + if ($p) |
|
| 366 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 367 | + $ligne += substr_count($debut, "\n"); |
|
| 368 | + $res[] = $nested[$m[1]]; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return (($texte==='') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // http://doc.spip.org/@phraser_champs_interieurs |
| 375 | 375 | function phraser_champs_interieurs($texte, $ligne, $sep, $result){ |
| 376 | - $i = 0; // en fait count($result) |
|
| 377 | - $x = ""; |
|
| 378 | - |
|
| 379 | - while (true){ |
|
| 380 | - $j = $i; |
|
| 381 | - $n = $ligne; |
|
| 382 | - while (preg_match(CHAMP_ETENDU, $texte, $match)){ |
|
| 383 | - $p = strpos($texte, $match[0]); |
|
| 384 | - $debut = substr($texte, 0, $p); |
|
| 385 | - if ($p){ |
|
| 386 | - $result[$i] = $debut; |
|
| 387 | - $i++; |
|
| 388 | - } |
|
| 389 | - $nom = $match[4]; |
|
| 390 | - $champ = new Champ; |
|
| 391 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 392 | - $champ->ligne = $x ? 0 : ($n+substr_count($debut, "\n")); |
|
| 393 | - $champ->nom_boucle = $match[3]; |
|
| 394 | - $champ->nom_champ = $nom; |
|
| 395 | - $champ->etoile = $match[6]; |
|
| 396 | - // phraser_args indiquera ou commence apres |
|
| 397 | - $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 398 | - phraser_vieux($champ); |
|
| 399 | - $champ->avant = |
|
| 400 | - phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 401 | - $debut = substr($champ->apres, 1); |
|
| 402 | - if (!empty($debut)){ |
|
| 403 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 404 | - } |
|
| 405 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 406 | - |
|
| 407 | - $result[$i] = $champ; |
|
| 408 | - $i++; |
|
| 409 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 410 | - } |
|
| 411 | - if ($texte!==""){ |
|
| 412 | - $result[$i] = $texte; |
|
| 413 | - $i++; |
|
| 414 | - } |
|
| 415 | - $x = ''; |
|
| 416 | - |
|
| 417 | - while ($j<$i){ |
|
| 418 | - $z = $result[$j]; |
|
| 419 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 420 | - if (is_object($z)) |
|
| 421 | - $x .= "%$sep$j@"; |
|
| 422 | - else |
|
| 423 | - $x .= $z; |
|
| 424 | - $j++; |
|
| 425 | - } |
|
| 426 | - if (preg_match(CHAMP_ETENDU, $x)) |
|
| 427 | - $texte = $x; |
|
| 428 | - else |
|
| 429 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 430 | - } |
|
| 376 | + $i = 0; // en fait count($result) |
|
| 377 | + $x = ""; |
|
| 378 | + |
|
| 379 | + while (true){ |
|
| 380 | + $j = $i; |
|
| 381 | + $n = $ligne; |
|
| 382 | + while (preg_match(CHAMP_ETENDU, $texte, $match)){ |
|
| 383 | + $p = strpos($texte, $match[0]); |
|
| 384 | + $debut = substr($texte, 0, $p); |
|
| 385 | + if ($p){ |
|
| 386 | + $result[$i] = $debut; |
|
| 387 | + $i++; |
|
| 388 | + } |
|
| 389 | + $nom = $match[4]; |
|
| 390 | + $champ = new Champ; |
|
| 391 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 392 | + $champ->ligne = $x ? 0 : ($n+substr_count($debut, "\n")); |
|
| 393 | + $champ->nom_boucle = $match[3]; |
|
| 394 | + $champ->nom_champ = $nom; |
|
| 395 | + $champ->etoile = $match[6]; |
|
| 396 | + // phraser_args indiquera ou commence apres |
|
| 397 | + $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 398 | + phraser_vieux($champ); |
|
| 399 | + $champ->avant = |
|
| 400 | + phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 401 | + $debut = substr($champ->apres, 1); |
|
| 402 | + if (!empty($debut)){ |
|
| 403 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 404 | + } |
|
| 405 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 406 | + |
|
| 407 | + $result[$i] = $champ; |
|
| 408 | + $i++; |
|
| 409 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 410 | + } |
|
| 411 | + if ($texte!==""){ |
|
| 412 | + $result[$i] = $texte; |
|
| 413 | + $i++; |
|
| 414 | + } |
|
| 415 | + $x = ''; |
|
| 416 | + |
|
| 417 | + while ($j<$i){ |
|
| 418 | + $z = $result[$j]; |
|
| 419 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 420 | + if (is_object($z)) |
|
| 421 | + $x .= "%$sep$j@"; |
|
| 422 | + else |
|
| 423 | + $x .= $z; |
|
| 424 | + $j++; |
|
| 425 | + } |
|
| 426 | + if (preg_match(CHAMP_ETENDU, $x)) |
|
| 427 | + $texte = $x; |
|
| 428 | + else |
|
| 429 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 430 | + } |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | function phraser_vieux(&$champ){ |
| 434 | - $nom = $champ->nom_champ; |
|
| 435 | - if ($nom=='EMBED_DOCUMENT'){ |
|
| 436 | - if (!function_exists('phraser_vieux_emb')) |
|
| 437 | - include_spip('public/normaliser'); |
|
| 438 | - phraser_vieux_emb($champ); |
|
| 439 | - } elseif ($nom=='EXPOSER') { |
|
| 440 | - if (!function_exists('phraser_vieux_exposer')) |
|
| 441 | - include_spip('public/normaliser'); |
|
| 442 | - phraser_vieux_exposer($champ); |
|
| 443 | - } elseif ($champ->param) { |
|
| 444 | - if ($nom=='FORMULAIRE_RECHERCHE'){ |
|
| 445 | - if (!function_exists('phraser_vieux_recherche')) |
|
| 446 | - include_spip('public/normaliser'); |
|
| 447 | - phraser_vieux_recherche($champ); |
|
| 448 | - } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 449 | - if (!function_exists('phraser_vieux_logos')) |
|
| 450 | - include_spip('public/normaliser'); |
|
| 451 | - phraser_vieux_logos($champ); |
|
| 452 | - } elseif ($nom=='MODELE') { |
|
| 453 | - if (!function_exists('phraser_vieux_modele')) |
|
| 454 | - include_spip('public/normaliser'); |
|
| 455 | - phraser_vieux_modele($champ); |
|
| 456 | - } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
|
| 457 | - if (!function_exists('phraser_vieux_inclu')) |
|
| 458 | - include_spip('public/normaliser'); |
|
| 459 | - phraser_vieux_inclu($champ); |
|
| 460 | - } |
|
| 461 | - } |
|
| 434 | + $nom = $champ->nom_champ; |
|
| 435 | + if ($nom=='EMBED_DOCUMENT'){ |
|
| 436 | + if (!function_exists('phraser_vieux_emb')) |
|
| 437 | + include_spip('public/normaliser'); |
|
| 438 | + phraser_vieux_emb($champ); |
|
| 439 | + } elseif ($nom=='EXPOSER') { |
|
| 440 | + if (!function_exists('phraser_vieux_exposer')) |
|
| 441 | + include_spip('public/normaliser'); |
|
| 442 | + phraser_vieux_exposer($champ); |
|
| 443 | + } elseif ($champ->param) { |
|
| 444 | + if ($nom=='FORMULAIRE_RECHERCHE'){ |
|
| 445 | + if (!function_exists('phraser_vieux_recherche')) |
|
| 446 | + include_spip('public/normaliser'); |
|
| 447 | + phraser_vieux_recherche($champ); |
|
| 448 | + } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 449 | + if (!function_exists('phraser_vieux_logos')) |
|
| 450 | + include_spip('public/normaliser'); |
|
| 451 | + phraser_vieux_logos($champ); |
|
| 452 | + } elseif ($nom=='MODELE') { |
|
| 453 | + if (!function_exists('phraser_vieux_modele')) |
|
| 454 | + include_spip('public/normaliser'); |
|
| 455 | + phraser_vieux_modele($champ); |
|
| 456 | + } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
|
| 457 | + if (!function_exists('phraser_vieux_inclu')) |
|
| 458 | + include_spip('public/normaliser'); |
|
| 459 | + phraser_vieux_inclu($champ); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -486,340 +486,340 @@ discard block |
||
| 486 | 486 | **/ |
| 487 | 487 | function phraser_criteres($params, &$result){ |
| 488 | 488 | |
| 489 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 490 | - $args = array(); |
|
| 491 | - $type = $result->type_requete; |
|
| 492 | - $doublons = array(); |
|
| 493 | - foreach ($params as $v){ |
|
| 494 | - $var = $v[1][0]; |
|
| 495 | - $param = ($var->type!='texte') ? "" : $var->texte; |
|
| 496 | - if ((count($v)>2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))){ |
|
| 489 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 490 | + $args = array(); |
|
| 491 | + $type = $result->type_requete; |
|
| 492 | + $doublons = array(); |
|
| 493 | + foreach ($params as $v){ |
|
| 494 | + $var = $v[1][0]; |
|
| 495 | + $param = ($var->type!='texte') ? "" : $var->texte; |
|
| 496 | + if ((count($v)>2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))){ |
|
| 497 | 497 | // plus d'un argument et pas le critere IN: |
| 498 | 498 | // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
| 499 | 499 | |
| 500 | - if ($var->type!='texte' |
|
| 501 | - OR preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 502 | - ){ |
|
| 503 | - $op = ','; |
|
| 504 | - $not = ""; |
|
| 505 | - } else { |
|
| 506 | - // Le debut du premier argument est l'operateur |
|
| 507 | - preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 508 | - $op = $m[2]; |
|
| 509 | - $not = $m[1]; |
|
| 510 | - $cond = $m[3]; |
|
| 511 | - // virer le premier argument, |
|
| 512 | - // et mettre son reliquat eventuel |
|
| 513 | - // Recopier pour ne pas alterer le texte source |
|
| 514 | - // utile au debusqueur |
|
| 515 | - if ($m[4]){ |
|
| 516 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 517 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
|
| 518 | - $c = null; |
|
| 519 | - eval ('$c = ' . $m[4] . ';'); |
|
| 520 | - if (isset($c)) |
|
| 521 | - $m[4] = $c; |
|
| 522 | - } |
|
| 523 | - $texte = new Texte; |
|
| 524 | - $texte->texte = $m[4]; |
|
| 525 | - $v[1][0] = $texte; |
|
| 526 | - } else array_shift($v[1]); |
|
| 527 | - } |
|
| 528 | - array_shift($v); // $v[O] est vide |
|
| 529 | - $crit = new Critere; |
|
| 530 | - $crit->op = $op; |
|
| 531 | - $crit->not = $not; |
|
| 532 | - $crit->cond = $cond; |
|
| 533 | - $crit->exclus = ""; |
|
| 534 | - $crit->param = $v; |
|
| 535 | - $args[] = $crit; |
|
| 536 | - } else { |
|
| 537 | - if ($var->type!='texte'){ |
|
| 538 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 539 | - // erreur ou critere infixe "/" |
|
| 540 | - if (($v[1][1]->type!='texte') || (trim($v[1][1]->texte)!='/')){ |
|
| 541 | - $err_ci = array('zbug_critere_inconnu', |
|
| 542 | - array('critere' => $var->nom_champ)); |
|
| 543 | - erreur_squelette($err_ci, $result); |
|
| 544 | - } else { |
|
| 545 | - $crit = new Critere; |
|
| 546 | - $crit->op = '/'; |
|
| 547 | - $crit->not = ""; |
|
| 548 | - $crit->exclus = ""; |
|
| 549 | - $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 550 | - $args[] = $crit; |
|
| 551 | - } |
|
| 552 | - } else { |
|
| 553 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 554 | - // les separateurs |
|
| 555 | - if ($var->apres) |
|
| 556 | - $result->separateur[] = $param; |
|
| 557 | - elseif (($param=='tout') OR ($param=='tous')) |
|
| 558 | - $result->modificateur['tout'] = true; |
|
| 559 | - elseif ($param=='plat') |
|
| 560 | - $result->modificateur['plat'] = true; |
|
| 561 | - |
|
| 562 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 563 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 564 | - // ceux-ci pour avoir la rubrique mere... |
|
| 565 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 566 | - // traités normalement. |
|
| 567 | - elseif (strcasecmp($type, 'hierarchie')==0 |
|
| 568 | - AND !preg_match(",^id_rubrique\b,", $param) |
|
| 569 | - AND preg_match(",^id_\w+\s*$,", $param) |
|
| 570 | - ) { |
|
| 571 | - $result->modificateur['tout'] = true; |
|
| 572 | - } elseif (strcasecmp($type, 'hierarchie')==0 AND $param=="id_rubrique") { |
|
| 573 | - // rien a faire sur {id_rubrique} tout seul |
|
| 574 | - } else { |
|
| 575 | - // pas d'emplacement statique, faut un dynamique |
|
| 576 | - /// mais il y a 2 cas qui ont les 2 ! |
|
| 577 | - if (($param=='unique') || (preg_match(',^!?doublons *,', $param))){ |
|
| 578 | - // cette variable sera inseree dans le code |
|
| 579 | - // et son nom sert d'indicateur des maintenant |
|
| 580 | - $result->doublons = '$doublons_index'; |
|
| 581 | - if ($param=='unique') $param = 'doublons'; |
|
| 582 | - } elseif ($param=='recherche') |
|
| 583 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 584 | - $result->hash = ' '; |
|
| 585 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
|
| 586 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 587 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 588 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 589 | - $a2 = trim($m[8]); |
|
| 590 | - if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 591 | - $a2 = substr($a2, 1, -1); |
|
| 592 | - $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 593 | - (($m[2]=='lang_select') ? $m[2] : $m[7]), |
|
| 594 | - $m[6], $m[5]); |
|
| 595 | - $crit->exclus = $m[1]; |
|
| 596 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 597 | - CHAMP_SQL_PLUS_FONC . |
|
| 598 | - ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 599 | - // contient aussi les comparaisons implicites ! |
|
| 600 | - // Comme ci-dessus: |
|
| 601 | - // le premier arg contient l'operateur |
|
| 602 | - array_shift($v); |
|
| 603 | - if ($m[6]){ |
|
| 604 | - $v[0][0] = new Texte; |
|
| 605 | - $v[0][0]->texte = $m[6]; |
|
| 606 | - } else { |
|
| 607 | - array_shift($v[0]); |
|
| 608 | - if (!$v[0]) array_shift($v); |
|
| 609 | - } |
|
| 610 | - $crit = new Critere; |
|
| 611 | - $crit->op = $m[2]; |
|
| 612 | - $crit->param = $v; |
|
| 613 | - $crit->not = $m[1]; |
|
| 614 | - $crit->cond = $m[5]; |
|
| 615 | - } else { |
|
| 616 | - $err_ci = array('zbug_critere_inconnu', |
|
| 617 | - array('critere' => $param)); |
|
| 618 | - erreur_squelette($err_ci, $result); |
|
| 619 | - } |
|
| 620 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) |
|
| 621 | - $args[] = $crit; |
|
| 622 | - else |
|
| 623 | - $doublons[] = $crit; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - // les doublons non nies doivent etre le dernier critere |
|
| 629 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 630 | - // cf critere_doublon |
|
| 631 | - if ($doublons) $args = array_merge($args, $doublons); |
|
| 632 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 633 | - if (!$err_ci) $result->criteres = $args; |
|
| 500 | + if ($var->type!='texte' |
|
| 501 | + OR preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 502 | + ){ |
|
| 503 | + $op = ','; |
|
| 504 | + $not = ""; |
|
| 505 | + } else { |
|
| 506 | + // Le debut du premier argument est l'operateur |
|
| 507 | + preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 508 | + $op = $m[2]; |
|
| 509 | + $not = $m[1]; |
|
| 510 | + $cond = $m[3]; |
|
| 511 | + // virer le premier argument, |
|
| 512 | + // et mettre son reliquat eventuel |
|
| 513 | + // Recopier pour ne pas alterer le texte source |
|
| 514 | + // utile au debusqueur |
|
| 515 | + if ($m[4]){ |
|
| 516 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 517 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
|
| 518 | + $c = null; |
|
| 519 | + eval ('$c = ' . $m[4] . ';'); |
|
| 520 | + if (isset($c)) |
|
| 521 | + $m[4] = $c; |
|
| 522 | + } |
|
| 523 | + $texte = new Texte; |
|
| 524 | + $texte->texte = $m[4]; |
|
| 525 | + $v[1][0] = $texte; |
|
| 526 | + } else array_shift($v[1]); |
|
| 527 | + } |
|
| 528 | + array_shift($v); // $v[O] est vide |
|
| 529 | + $crit = new Critere; |
|
| 530 | + $crit->op = $op; |
|
| 531 | + $crit->not = $not; |
|
| 532 | + $crit->cond = $cond; |
|
| 533 | + $crit->exclus = ""; |
|
| 534 | + $crit->param = $v; |
|
| 535 | + $args[] = $crit; |
|
| 536 | + } else { |
|
| 537 | + if ($var->type!='texte'){ |
|
| 538 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 539 | + // erreur ou critere infixe "/" |
|
| 540 | + if (($v[1][1]->type!='texte') || (trim($v[1][1]->texte)!='/')){ |
|
| 541 | + $err_ci = array('zbug_critere_inconnu', |
|
| 542 | + array('critere' => $var->nom_champ)); |
|
| 543 | + erreur_squelette($err_ci, $result); |
|
| 544 | + } else { |
|
| 545 | + $crit = new Critere; |
|
| 546 | + $crit->op = '/'; |
|
| 547 | + $crit->not = ""; |
|
| 548 | + $crit->exclus = ""; |
|
| 549 | + $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 550 | + $args[] = $crit; |
|
| 551 | + } |
|
| 552 | + } else { |
|
| 553 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 554 | + // les separateurs |
|
| 555 | + if ($var->apres) |
|
| 556 | + $result->separateur[] = $param; |
|
| 557 | + elseif (($param=='tout') OR ($param=='tous')) |
|
| 558 | + $result->modificateur['tout'] = true; |
|
| 559 | + elseif ($param=='plat') |
|
| 560 | + $result->modificateur['plat'] = true; |
|
| 561 | + |
|
| 562 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 563 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 564 | + // ceux-ci pour avoir la rubrique mere... |
|
| 565 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 566 | + // traités normalement. |
|
| 567 | + elseif (strcasecmp($type, 'hierarchie')==0 |
|
| 568 | + AND !preg_match(",^id_rubrique\b,", $param) |
|
| 569 | + AND preg_match(",^id_\w+\s*$,", $param) |
|
| 570 | + ) { |
|
| 571 | + $result->modificateur['tout'] = true; |
|
| 572 | + } elseif (strcasecmp($type, 'hierarchie')==0 AND $param=="id_rubrique") { |
|
| 573 | + // rien a faire sur {id_rubrique} tout seul |
|
| 574 | + } else { |
|
| 575 | + // pas d'emplacement statique, faut un dynamique |
|
| 576 | + /// mais il y a 2 cas qui ont les 2 ! |
|
| 577 | + if (($param=='unique') || (preg_match(',^!?doublons *,', $param))){ |
|
| 578 | + // cette variable sera inseree dans le code |
|
| 579 | + // et son nom sert d'indicateur des maintenant |
|
| 580 | + $result->doublons = '$doublons_index'; |
|
| 581 | + if ($param=='unique') $param = 'doublons'; |
|
| 582 | + } elseif ($param=='recherche') |
|
| 583 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 584 | + $result->hash = ' '; |
|
| 585 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
|
| 586 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 587 | + } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 588 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 589 | + $a2 = trim($m[8]); |
|
| 590 | + if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 591 | + $a2 = substr($a2, 1, -1); |
|
| 592 | + $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 593 | + (($m[2]=='lang_select') ? $m[2] : $m[7]), |
|
| 594 | + $m[6], $m[5]); |
|
| 595 | + $crit->exclus = $m[1]; |
|
| 596 | + } elseif (preg_match("/^([!]?)\s*(" . |
|
| 597 | + CHAMP_SQL_PLUS_FONC . |
|
| 598 | + ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 599 | + // contient aussi les comparaisons implicites ! |
|
| 600 | + // Comme ci-dessus: |
|
| 601 | + // le premier arg contient l'operateur |
|
| 602 | + array_shift($v); |
|
| 603 | + if ($m[6]){ |
|
| 604 | + $v[0][0] = new Texte; |
|
| 605 | + $v[0][0]->texte = $m[6]; |
|
| 606 | + } else { |
|
| 607 | + array_shift($v[0]); |
|
| 608 | + if (!$v[0]) array_shift($v); |
|
| 609 | + } |
|
| 610 | + $crit = new Critere; |
|
| 611 | + $crit->op = $m[2]; |
|
| 612 | + $crit->param = $v; |
|
| 613 | + $crit->not = $m[1]; |
|
| 614 | + $crit->cond = $m[5]; |
|
| 615 | + } else { |
|
| 616 | + $err_ci = array('zbug_critere_inconnu', |
|
| 617 | + array('critere' => $param)); |
|
| 618 | + erreur_squelette($err_ci, $result); |
|
| 619 | + } |
|
| 620 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) |
|
| 621 | + $args[] = $crit; |
|
| 622 | + else |
|
| 623 | + $doublons[] = $crit; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + // les doublons non nies doivent etre le dernier critere |
|
| 629 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 630 | + // cf critere_doublon |
|
| 631 | + if ($doublons) $args = array_merge($args, $doublons); |
|
| 632 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 633 | + if (!$err_ci) $result->criteres = $args; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | // http://doc.spip.org/@phraser_critere_infixe |
| 637 | 637 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond){ |
| 638 | - $args[0] = new Texte; |
|
| 639 | - $args[0]->texte = $arg1; |
|
| 640 | - $args[0] = array($args[0]); |
|
| 641 | - $args[1][0] = new Texte; |
|
| 642 | - $args[1][0]->texte = $arg2; |
|
| 643 | - $crit = new Critere; |
|
| 644 | - $crit->op = $op; |
|
| 645 | - $crit->not = $not; |
|
| 646 | - $crit->cond = $cond; |
|
| 647 | - $crit->param = $args; |
|
| 648 | - |
|
| 649 | - return $crit; |
|
| 638 | + $args[0] = new Texte; |
|
| 639 | + $args[0]->texte = $arg1; |
|
| 640 | + $args[0] = array($args[0]); |
|
| 641 | + $args[1][0] = new Texte; |
|
| 642 | + $args[1][0]->texte = $arg2; |
|
| 643 | + $crit = new Critere; |
|
| 644 | + $crit->op = $op; |
|
| 645 | + $crit->not = $not; |
|
| 646 | + $crit->cond = $cond; |
|
| 647 | + $crit->param = $args; |
|
| 648 | + |
|
| 649 | + return $crit; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1){ |
| 653 | 653 | |
| 654 | - $all_res = array(); |
|
| 654 | + $all_res = array(); |
|
| 655 | 655 | |
| 656 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE))!==false){ |
|
| 656 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE))!==false){ |
|
| 657 | 657 | |
| 658 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 659 | - $result = new Boucle; |
|
| 660 | - $result->id_parent = $id_parent; |
|
| 661 | - $result->descr = $descr; |
|
| 658 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 659 | + $result = new Boucle; |
|
| 660 | + $result->id_parent = $id_parent; |
|
| 661 | + $result->descr = $descr; |
|
| 662 | 662 | # attention: reperer la premiere des 2 balises: pre_boucle ou boucle |
| 663 | 663 | |
| 664 | - if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 665 | - OR ($n = strpos($texte, $r[0]))===false |
|
| 666 | - OR ($n>$pos_boucle) |
|
| 667 | - ){ |
|
| 668 | - $debut = substr($texte, 0, $pos_boucle); |
|
| 669 | - $milieu = substr($texte, $pos_boucle); |
|
| 670 | - $k = strpos($milieu, '('); |
|
| 671 | - $id_boucle = trim(substr($milieu, |
|
| 672 | - strlen(BALISE_BOUCLE), |
|
| 673 | - $k-strlen(BALISE_BOUCLE))); |
|
| 674 | - $milieu = substr($milieu, $k); |
|
| 675 | - |
|
| 676 | - } else { |
|
| 677 | - $debut = substr($texte, 0, $n); |
|
| 678 | - $milieu = substr($texte, $n); |
|
| 679 | - $k = strpos($milieu, '>'); |
|
| 680 | - $id_boucle = substr($milieu, |
|
| 681 | - strlen(BALISE_PRE_BOUCLE), |
|
| 682 | - $k-strlen(BALISE_PRE_BOUCLE)); |
|
| 683 | - |
|
| 684 | - if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)){ |
|
| 685 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 686 | - erreur_squelette($err_b, $result); |
|
| 687 | - $texte = substr($texte, $n+1); |
|
| 688 | - continue; |
|
| 689 | - } else { |
|
| 690 | - $pos_boucle = $n; |
|
| 691 | - $n = strpos($milieu, $r[0]); |
|
| 692 | - $result->avant = substr($milieu, $k+1, $n-$k-1); |
|
| 693 | - $milieu = substr($milieu, $n+strlen($id_boucle)+strlen(BALISE_BOUCLE)); |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - $result->id_boucle = $id_boucle; |
|
| 697 | - |
|
| 698 | - preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 699 | - $result->type_requete = $match[0]; |
|
| 700 | - $milieu = substr($milieu, strlen($match[0])); |
|
| 701 | - $type = $match[1]; |
|
| 702 | - $jointures = trim($match[2]); |
|
| 703 | - $table_optionnelle = ($match[3]); |
|
| 704 | - if ($jointures){ |
|
| 705 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 706 | - // ou elles seront completees des jointures declarees |
|
| 707 | - $result->jointures_explicites = $jointures; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if ($table_optionnelle){ |
|
| 711 | - $result->table_optionnelle = $type; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 715 | - // Resultat mis dans result->param |
|
| 716 | - phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 717 | - |
|
| 718 | - // En 2e passe result->criteres contiendra un tableau |
|
| 719 | - // pour l'instant on met le source (chaine) : |
|
| 720 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 721 | - $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 722 | - $milieu = $result->apres; |
|
| 723 | - $result->apres = ""; |
|
| 724 | - |
|
| 725 | - // |
|
| 726 | - // Recuperer la fin : |
|
| 727 | - // |
|
| 728 | - if ($milieu[0]==='/'){ |
|
| 729 | - $suite = substr($milieu, 2); |
|
| 730 | - $milieu = ''; |
|
| 731 | - } else { |
|
| 732 | - $milieu = substr($milieu, 1); |
|
| 733 | - $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 734 | - $p = strpos($milieu, $s); |
|
| 735 | - if ($p===false){ |
|
| 736 | - $err_b = array('zbug_erreur_boucle_fermant', |
|
| 737 | - array('id' => $id_boucle)); |
|
| 738 | - erreur_squelette($err_b, $result); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - $suite = substr($milieu, $p+strlen($s)); |
|
| 742 | - $milieu = substr($milieu, 0, $p); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $result->milieu = $milieu; |
|
| 746 | - |
|
| 747 | - // |
|
| 748 | - // 1. Recuperer la partie conditionnelle apres |
|
| 749 | - // |
|
| 750 | - $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 751 | - $p = strpos($suite, $s); |
|
| 752 | - if ($p!==false){ |
|
| 753 | - $result->apres = substr($suite, 0, $p); |
|
| 754 | - $suite = substr($suite, $p+strlen($s)); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - // |
|
| 758 | - // 2. Recuperer la partie alternative |
|
| 759 | - // |
|
| 760 | - $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 761 | - $p = strpos($suite, $s); |
|
| 762 | - if ($p!==false){ |
|
| 763 | - $result->altern = substr($suite, 0, $p); |
|
| 764 | - $suite = substr($suite, $p+strlen($s)); |
|
| 765 | - } |
|
| 766 | - $result->ligne = $ligne+substr_count($debut, "\n"); |
|
| 767 | - $m = substr_count($milieu, "\n"); |
|
| 768 | - $b = substr_count($result->avant, "\n"); |
|
| 769 | - $a = substr_count($result->apres, "\n"); |
|
| 770 | - |
|
| 771 | - if ($p = strpos($type, ':')){ |
|
| 772 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 773 | - $type = substr($type, $p+1); |
|
| 774 | - } |
|
| 775 | - $soustype = strtolower($type); |
|
| 776 | - |
|
| 777 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) |
|
| 778 | - $soustype = $type; |
|
| 779 | - |
|
| 780 | - $result->type_requete = $soustype; |
|
| 781 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 782 | - if (!is_array($result->param)) |
|
| 783 | - $err_b = true; |
|
| 784 | - else { |
|
| 785 | - phraser_criteres($result->param, $result); |
|
| 786 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
|
| 787 | - $result->type_requete = TYPE_RECURSIF; |
|
| 788 | - $args = $result->param; |
|
| 789 | - array_unshift($args, |
|
| 790 | - substr($type, strlen(TYPE_RECURSIF))); |
|
| 791 | - $result->param = $args; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 796 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne+$b+$m); |
|
| 797 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne+$a+$m+$b); |
|
| 798 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
|
| 799 | - |
|
| 800 | - // Prevenir le generateur de code que le squelette est faux |
|
| 801 | - if ($err_b) $result->type_requete = false; |
|
| 802 | - |
|
| 803 | - // Verifier qu'il n'y a pas double definition |
|
| 804 | - // apres analyse des sous-parties (pas avant). |
|
| 805 | - |
|
| 806 | - if (isset($boucles[$id_boucle])){ |
|
| 807 | - $err_b_d = array('zbug_erreur_boucle_double', |
|
| 808 | - array('id' => $id_boucle)); |
|
| 809 | - erreur_squelette($err_b_d, $result); |
|
| 810 | - // Prevenir le generateur de code que le squelette est faux |
|
| 811 | - $boucles[$id_boucle]->type_requete = false; |
|
| 812 | - } else |
|
| 813 | - $boucles[$id_boucle] = $result; |
|
| 814 | - $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 815 | - $all_res[] = &$boucles[$id_boucle]; |
|
| 816 | - if (!empty($suite)){ |
|
| 817 | - $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 818 | - } |
|
| 819 | - $texte = $suite; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 664 | + if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 665 | + OR ($n = strpos($texte, $r[0]))===false |
|
| 666 | + OR ($n>$pos_boucle) |
|
| 667 | + ){ |
|
| 668 | + $debut = substr($texte, 0, $pos_boucle); |
|
| 669 | + $milieu = substr($texte, $pos_boucle); |
|
| 670 | + $k = strpos($milieu, '('); |
|
| 671 | + $id_boucle = trim(substr($milieu, |
|
| 672 | + strlen(BALISE_BOUCLE), |
|
| 673 | + $k-strlen(BALISE_BOUCLE))); |
|
| 674 | + $milieu = substr($milieu, $k); |
|
| 675 | + |
|
| 676 | + } else { |
|
| 677 | + $debut = substr($texte, 0, $n); |
|
| 678 | + $milieu = substr($texte, $n); |
|
| 679 | + $k = strpos($milieu, '>'); |
|
| 680 | + $id_boucle = substr($milieu, |
|
| 681 | + strlen(BALISE_PRE_BOUCLE), |
|
| 682 | + $k-strlen(BALISE_PRE_BOUCLE)); |
|
| 683 | + |
|
| 684 | + if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)){ |
|
| 685 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 686 | + erreur_squelette($err_b, $result); |
|
| 687 | + $texte = substr($texte, $n+1); |
|
| 688 | + continue; |
|
| 689 | + } else { |
|
| 690 | + $pos_boucle = $n; |
|
| 691 | + $n = strpos($milieu, $r[0]); |
|
| 692 | + $result->avant = substr($milieu, $k+1, $n-$k-1); |
|
| 693 | + $milieu = substr($milieu, $n+strlen($id_boucle)+strlen(BALISE_BOUCLE)); |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + $result->id_boucle = $id_boucle; |
|
| 697 | + |
|
| 698 | + preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 699 | + $result->type_requete = $match[0]; |
|
| 700 | + $milieu = substr($milieu, strlen($match[0])); |
|
| 701 | + $type = $match[1]; |
|
| 702 | + $jointures = trim($match[2]); |
|
| 703 | + $table_optionnelle = ($match[3]); |
|
| 704 | + if ($jointures){ |
|
| 705 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 706 | + // ou elles seront completees des jointures declarees |
|
| 707 | + $result->jointures_explicites = $jointures; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if ($table_optionnelle){ |
|
| 711 | + $result->table_optionnelle = $type; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 715 | + // Resultat mis dans result->param |
|
| 716 | + phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 717 | + |
|
| 718 | + // En 2e passe result->criteres contiendra un tableau |
|
| 719 | + // pour l'instant on met le source (chaine) : |
|
| 720 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 721 | + $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 722 | + $milieu = $result->apres; |
|
| 723 | + $result->apres = ""; |
|
| 724 | + |
|
| 725 | + // |
|
| 726 | + // Recuperer la fin : |
|
| 727 | + // |
|
| 728 | + if ($milieu[0]==='/'){ |
|
| 729 | + $suite = substr($milieu, 2); |
|
| 730 | + $milieu = ''; |
|
| 731 | + } else { |
|
| 732 | + $milieu = substr($milieu, 1); |
|
| 733 | + $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 734 | + $p = strpos($milieu, $s); |
|
| 735 | + if ($p===false){ |
|
| 736 | + $err_b = array('zbug_erreur_boucle_fermant', |
|
| 737 | + array('id' => $id_boucle)); |
|
| 738 | + erreur_squelette($err_b, $result); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + $suite = substr($milieu, $p+strlen($s)); |
|
| 742 | + $milieu = substr($milieu, 0, $p); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $result->milieu = $milieu; |
|
| 746 | + |
|
| 747 | + // |
|
| 748 | + // 1. Recuperer la partie conditionnelle apres |
|
| 749 | + // |
|
| 750 | + $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 751 | + $p = strpos($suite, $s); |
|
| 752 | + if ($p!==false){ |
|
| 753 | + $result->apres = substr($suite, 0, $p); |
|
| 754 | + $suite = substr($suite, $p+strlen($s)); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + // |
|
| 758 | + // 2. Recuperer la partie alternative |
|
| 759 | + // |
|
| 760 | + $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 761 | + $p = strpos($suite, $s); |
|
| 762 | + if ($p!==false){ |
|
| 763 | + $result->altern = substr($suite, 0, $p); |
|
| 764 | + $suite = substr($suite, $p+strlen($s)); |
|
| 765 | + } |
|
| 766 | + $result->ligne = $ligne+substr_count($debut, "\n"); |
|
| 767 | + $m = substr_count($milieu, "\n"); |
|
| 768 | + $b = substr_count($result->avant, "\n"); |
|
| 769 | + $a = substr_count($result->apres, "\n"); |
|
| 770 | + |
|
| 771 | + if ($p = strpos($type, ':')){ |
|
| 772 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 773 | + $type = substr($type, $p+1); |
|
| 774 | + } |
|
| 775 | + $soustype = strtolower($type); |
|
| 776 | + |
|
| 777 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) |
|
| 778 | + $soustype = $type; |
|
| 779 | + |
|
| 780 | + $result->type_requete = $soustype; |
|
| 781 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 782 | + if (!is_array($result->param)) |
|
| 783 | + $err_b = true; |
|
| 784 | + else { |
|
| 785 | + phraser_criteres($result->param, $result); |
|
| 786 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
|
| 787 | + $result->type_requete = TYPE_RECURSIF; |
|
| 788 | + $args = $result->param; |
|
| 789 | + array_unshift($args, |
|
| 790 | + substr($type, strlen(TYPE_RECURSIF))); |
|
| 791 | + $result->param = $args; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 796 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne+$b+$m); |
|
| 797 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne+$a+$m+$b); |
|
| 798 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
|
| 799 | + |
|
| 800 | + // Prevenir le generateur de code que le squelette est faux |
|
| 801 | + if ($err_b) $result->type_requete = false; |
|
| 802 | + |
|
| 803 | + // Verifier qu'il n'y a pas double definition |
|
| 804 | + // apres analyse des sous-parties (pas avant). |
|
| 805 | + |
|
| 806 | + if (isset($boucles[$id_boucle])){ |
|
| 807 | + $err_b_d = array('zbug_erreur_boucle_double', |
|
| 808 | + array('id' => $id_boucle)); |
|
| 809 | + erreur_squelette($err_b_d, $result); |
|
| 810 | + // Prevenir le generateur de code que le squelette est faux |
|
| 811 | + $boucles[$id_boucle]->type_requete = false; |
|
| 812 | + } else |
|
| 813 | + $boucles[$id_boucle] = $result; |
|
| 814 | + $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 815 | + $all_res[] = &$boucles[$id_boucle]; |
|
| 816 | + if (!empty($suite)){ |
|
| 817 | + $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 818 | + } |
|
| 819 | + $texte = $suite; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | ?> |
@@ -27,21 +27,21 @@ discard block |
||
| 27 | 27 | define('SPEC_BOUCLE', '/\s*\(\s*([^\s?)]+)(\s*[^)?]*)([?]?)\)/'); |
| 28 | 28 | define('NOM_DE_BOUCLE', "[0-9]+|[-_][-_.a-zA-Z0-9]*"); |
| 29 | 29 | # ecriture alambiquee pour rester compatible avec les hexadecimaux des vieux squelettes |
| 30 | -define('NOM_DE_CHAMP', "#((" . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)(\*{0,2})"); |
|
| 31 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 30 | +define('NOM_DE_CHAMP', "#((".NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)(\*{0,2})"); |
|
| 31 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 32 | 32 | |
| 33 | 33 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 34 | 34 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 35 | 35 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:>),iS'); |
| 36 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 36 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 37 | 37 | |
| 38 | 38 | define('SQL_ARGS', '(\([^)]*\))'); |
| 39 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 39 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 40 | 40 | |
| 41 | 41 | // http://doc.spip.org/@phraser_inclure |
| 42 | -function phraser_inclure($texte, $ligne, $result){ |
|
| 42 | +function phraser_inclure($texte, $ligne, $result) { |
|
| 43 | 43 | |
| 44 | - while (preg_match(BALISE_INCLURE, $texte, $match)){ |
|
| 44 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 45 | 45 | $p = strpos($texte, $match[0]); |
| 46 | 46 | $debut = substr($texte, 0, $p); |
| 47 | 47 | if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
@@ -52,35 +52,35 @@ discard block |
||
| 52 | 52 | $fichier = @$match[2]; |
| 53 | 53 | # assurer ici la migration .php3 => .php |
| 54 | 54 | # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
| 55 | - if (preg_match(',^(.*[.]php)3$,', $fichier, $r)){ |
|
| 55 | + if (preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 56 | 56 | $fichier = $r[1]; |
| 57 | 57 | } |
| 58 | - $champ->texte = ($fichier!=='page.php') ? $fichier : ''; |
|
| 59 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 58 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 59 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 60 | 60 | // on assimile {var=val} a une liste de un argument sans fonction |
| 61 | 61 | phraser_args($texte, "/>", "", $result, $champ); |
| 62 | - if (!$champ->texte OR count($champ->param)>1){ |
|
| 62 | + if (!$champ->texte OR count($champ->param) > 1) { |
|
| 63 | 63 | if (!function_exists('normaliser_inclure')) |
| 64 | 64 | include_spip('public/normaliser'); |
| 65 | 65 | normaliser_inclure($champ); |
| 66 | 66 | } |
| 67 | - $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
|
| 67 | + $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 68 | 68 | $champ->apres = ""; |
| 69 | 69 | $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
| 70 | 70 | $result[] = $champ; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 73 | + return (($texte === "") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // http://doc.spip.org/@phraser_polyglotte |
| 77 | -function phraser_polyglotte($texte, $ligne, $result){ |
|
| 77 | +function phraser_polyglotte($texte, $ligne, $result) { |
|
| 78 | 78 | |
| 79 | 79 | if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
| 80 | - foreach ($m as $match){ |
|
| 80 | + foreach ($m as $match) { |
|
| 81 | 81 | $p = strpos($texte, $match[0]); |
| 82 | 82 | $debut = substr($texte, 0, $p); |
| 83 | - if ($p){ |
|
| 83 | + if ($p) { |
|
| 84 | 84 | $champ = new Texte; |
| 85 | 85 | $champ->texte = $debut; |
| 86 | 86 | $champ->ligne = $ligne; |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | $ligne += substr_count($match[0], "\n"); |
| 94 | 94 | $lang = ''; |
| 95 | 95 | $bloc = $match[1]; |
| 96 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 97 | - while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
|
| 96 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 97 | + while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)) { |
|
| 98 | 98 | $trad = $regs[1]; |
| 99 | 99 | if ($trad OR $lang) |
| 100 | 100 | $champ->traductions[$lang] = $trad; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $champ->traductions[$lang] = $bloc; |
| 105 | 105 | $result[] = $champ; |
| 106 | 106 | } |
| 107 | - if ($texte!==""){ |
|
| 107 | + if ($texte !== "") { |
|
| 108 | 108 | $champ = new Texte; |
| 109 | 109 | $champ->texte = $texte; |
| 110 | 110 | $champ->ligne = $ligne; |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | // chaine peut etre vide si =texte1 est present et arg1 est vide |
| 121 | 121 | // sinon ce n'est pas un idiome |
| 122 | 122 | // http://doc.spip.org/@phraser_idiomes |
| 123 | -function phraser_idiomes($texte, $ligne, $result){ |
|
| 124 | - while (preg_match(BALISE_IDIOMES, $texte, $match)){ |
|
| 123 | +function phraser_idiomes($texte, $ligne, $result) { |
|
| 124 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 125 | 125 | $p = strpos($texte, $match[0]); |
| 126 | - $ko = (!$match[3] && ($match[5][0]!=='=')); |
|
| 127 | - $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
|
| 126 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 127 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 128 | 128 | if ($debut) $result = phraser_champs($debut, $ligne, $result); |
| 129 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 129 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 130 | 130 | $ligne += substr_count($debut, "\n"); |
| 131 | 131 | if ($ko) continue; // faux idiome |
| 132 | 132 | $champ = new Idiome; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | // Stocker les arguments de la balise de traduction |
| 136 | 136 | $args = array(); |
| 137 | 137 | $largs = $match[5]; |
| 138 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)){ |
|
| 138 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 139 | 139 | $args[$r[1]] = phraser_champs($r[2], 0, array()); |
| 140 | 140 | $largs = substr($largs, strlen($r[0])); |
| 141 | 141 | } |
@@ -146,17 +146,17 @@ discard block |
||
| 146 | 146 | phraser_args(@$match[7], ":", '', array(), $champ); |
| 147 | 147 | $result[] = $champ; |
| 148 | 148 | } |
| 149 | - if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 149 | + if ($texte !== "") $result = phraser_champs($texte, $ligne, $result); |
|
| 150 | 150 | |
| 151 | 151 | return $result; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // http://doc.spip.org/@phraser_champs |
| 155 | -function phraser_champs($texte, $ligne, $result){ |
|
| 156 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)){ |
|
| 155 | +function phraser_champs($texte, $ligne, $result) { |
|
| 156 | + while (preg_match("/".NOM_DE_CHAMP."/S", $texte, $match)) { |
|
| 157 | 157 | $p = strpos($texte, $match[0]); |
| 158 | - $suite = substr($texte, $p+strlen($match[0])); |
|
| 159 | - if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
|
| 158 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 159 | + if ($match[5] || (strpos($suite[0], "[0-9]") === false)) { |
|
| 160 | 160 | $debut = substr($texte, 0, $p); |
| 161 | 161 | if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
| 162 | 162 | $ligne += substr_count($debut, "\n"); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $champ->nom_champ = $match[3]; |
| 168 | 168 | $champ->etoile = $match[5]; |
| 169 | 169 | |
| 170 | - if ($suite[0]=='{'){ |
|
| 170 | + if ($suite[0] == '{') { |
|
| 171 | 171 | phraser_arg($suite, '', array(), $champ); |
| 172 | 172 | // ce ltrim est une ereur de conception |
| 173 | 173 | // mais on le conserve par souci de compatibilite |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | $result[] = $champ; |
| 186 | 186 | } else { |
| 187 | 187 | // faux champ |
| 188 | - $result = phraser_polyglotte(substr($texte, 0, $p+1), $ligne, $result); |
|
| 189 | - $texte = (substr($texte, $p+1)); |
|
| 188 | + $result = phraser_polyglotte(substr($texte, 0, $p + 1), $ligne, $result); |
|
| 189 | + $texte = (substr($texte, $p + 1)); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | - if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 192 | + if ($texte !== "") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 193 | 193 | |
| 194 | 194 | return $result; |
| 195 | 195 | } |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 201 | 201 | |
| 202 | 202 | // http://doc.spip.org/@phraser_champs_etendus |
| 203 | -function phraser_champs_etendus($texte, $ligne, $result){ |
|
| 204 | - if ($texte==="") return $result; |
|
| 203 | +function phraser_champs_etendus($texte, $ligne, $result) { |
|
| 204 | + if ($texte === "") return $result; |
|
| 205 | 205 | $sep = '##'; |
| 206 | - while (strpos($texte, $sep)!==false) |
|
| 206 | + while (strpos($texte, $sep) !== false) |
|
| 207 | 207 | $sep .= '#'; |
| 208 | 208 | |
| 209 | 209 | return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | // Tres chevelu |
| 217 | 217 | |
| 218 | 218 | // http://doc.spip.org/@phraser_args |
| 219 | -function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ){ |
|
| 219 | +function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) { |
|
| 220 | 220 | $texte = ltrim($texte); |
| 221 | - while (($texte!=="") && strpos($fin, $texte[0])===false){ |
|
| 221 | + while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 222 | 222 | $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
| 223 | 223 | $texte = ltrim($texte); |
| 224 | 224 | } |
@@ -230,23 +230,23 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // http://doc.spip.org/@phraser_arg |
| 233 | -function phraser_arg(&$texte, $sep, $result, &$pointeur_champ){ |
|
| 233 | +function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
|
| 234 | 234 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 235 | 235 | $suite = ltrim($match[2]); |
| 236 | 236 | $fonc = trim($match[1]); |
| 237 | - if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 237 | + if ($fonc && $fonc[0] == "|") $fonc = ltrim(substr($fonc, 1)); |
|
| 238 | 238 | $res = array($fonc); |
| 239 | 239 | $err_f = ''; |
| 240 | 240 | // cas du filtre sans argument ou du critere / |
| 241 | - if (($suite && ($suite[0]!='{')) || ($fonc && $fonc[0]=='/')){ |
|
| 241 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 242 | 242 | // si pas d'argument, alors il faut une fonction ou un double | |
| 243 | - if (!$match[1]){ |
|
| 243 | + if (!$match[1]) { |
|
| 244 | 244 | $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
| 245 | 245 | erreur_squelette($err_f, $pointeur_champ); |
| 246 | 246 | $texte = ''; |
| 247 | 247 | } else $texte = $suite; |
| 248 | 248 | if ($err_f) $pointeur_champ->param = false; |
| 249 | - elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 249 | + elseif ($fonc !== '') $pointeur_champ->param[] = $res; |
|
| 250 | 250 | // pour les balises avec faux filtres qui boudent ce dur larbeur |
| 251 | 251 | $pointeur_champ->fonctions[] = array($fonc, ''); |
| 252 | 252 | |
@@ -254,14 +254,14 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | $args = ltrim(substr($suite, 1)); // virer le '(' initial |
| 256 | 256 | $collecte = array(); |
| 257 | - while ($args && $args[0]!='}'){ |
|
| 258 | - if ($args[0]=='"') |
|
| 257 | + while ($args && $args[0] != '}') { |
|
| 258 | + if ($args[0] == '"') |
|
| 259 | 259 | preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
| 260 | - else if ($args[0]=="'") |
|
| 260 | + else if ($args[0] == "'") |
|
| 261 | 261 | preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
| 262 | 262 | else { |
| 263 | 263 | preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
| 264 | - if (!strlen($regs[2])){ |
|
| 264 | + if (!strlen($regs[2])) { |
|
| 265 | 265 | $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
| 266 | 266 | erreur_squelette($err_f, $pointeur_champ); |
| 267 | 267 | $champ = new Texte; |
@@ -270,81 +270,81 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | $arg = $regs[2]; |
| 273 | - if (trim($regs[1])){ |
|
| 273 | + if (trim($regs[1])) { |
|
| 274 | 274 | $champ = new Texte; |
| 275 | 275 | $champ->texte = $arg; |
| 276 | 276 | $champ->apres = $champ->avant = $regs[1]; |
| 277 | 277 | $result[] = $champ; |
| 278 | 278 | $collecte[] = $champ; |
| 279 | - $args = ltrim($regs[count($regs)-1]); |
|
| 279 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 280 | 280 | } else { |
| 281 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)){ |
|
| 281 | + if (!preg_match("/".NOM_DE_CHAMP."([{|])/", $arg, $r)) { |
|
| 282 | 282 | // 0 est un aveu d'impuissance. A completer |
| 283 | 283 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 284 | 284 | |
| 285 | - $args = ltrim($regs[count($regs)-1]); |
|
| 285 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 286 | 286 | $collecte = array_merge($collecte, $arg); |
| 287 | 287 | $result = array_merge($result, $arg); |
| 288 | 288 | } else { |
| 289 | 289 | $n = strpos($args, $r[0]); |
| 290 | 290 | $pred = substr($args, 0, $n); |
| 291 | 291 | $par = ',}'; |
| 292 | - if (preg_match('/^(.*)\($/', $pred, $m)){ |
|
| 292 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 293 | 293 | $pred = $m[1]; |
| 294 | 294 | $par = ')'; |
| 295 | 295 | } |
| 296 | - if ($pred){ |
|
| 296 | + if ($pred) { |
|
| 297 | 297 | $champ = new Texte; |
| 298 | 298 | $champ->texte = $pred; |
| 299 | 299 | $champ->apres = $champ->avant = ""; |
| 300 | 300 | $result[] = $champ; |
| 301 | 301 | $collecte[] = $champ; |
| 302 | 302 | } |
| 303 | - $rec = substr($args, $n+strlen($r[0])-1); |
|
| 303 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 304 | 304 | $champ = new Champ; |
| 305 | 305 | $champ->nom_boucle = $r[2]; |
| 306 | 306 | $champ->nom_champ = $r[3]; |
| 307 | 307 | $champ->etoile = $r[5]; |
| 308 | 308 | $next = $r[6]; |
| 309 | - while ($next=='{'){ |
|
| 309 | + while ($next == '{') { |
|
| 310 | 310 | phraser_arg($rec, $sep, array(), $champ); |
| 311 | 311 | $args = ltrim($rec); |
| 312 | 312 | $next = isset($args[0]) ? $args[0] : ''; |
| 313 | 313 | } |
| 314 | - while ($next=='|'){ |
|
| 314 | + while ($next == '|') { |
|
| 315 | 315 | phraser_args($rec, $par, $sep, array(), $champ); |
| 316 | 316 | $args = $champ->apres; |
| 317 | 317 | $champ->apres = ''; |
| 318 | 318 | $next = isset($args[0]) ? $args[0] : ''; |
| 319 | 319 | } |
| 320 | 320 | // Si erreur de syntaxe dans un sous-argument, propager. |
| 321 | - if ($champ->param===false) |
|
| 321 | + if ($champ->param === false) |
|
| 322 | 322 | $err_f = true; |
| 323 | 323 | else phraser_vieux($champ); |
| 324 | - if ($par==')') $args = substr($args, 1); |
|
| 324 | + if ($par == ')') $args = substr($args, 1); |
|
| 325 | 325 | $collecte[] = $champ; |
| 326 | 326 | $result[] = $champ; |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | - if (isset($args[0]) AND $args[0]==','){ |
|
| 329 | + if (isset($args[0]) AND $args[0] == ',') { |
|
| 330 | 330 | $args = ltrim(substr($args, 1)); |
| 331 | - if ($collecte){ |
|
| 331 | + if ($collecte) { |
|
| 332 | 332 | $res[] = $collecte; |
| 333 | 333 | $collecte = array(); |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | - if ($collecte){ |
|
| 337 | + if ($collecte) { |
|
| 338 | 338 | $res[] = $collecte; |
| 339 | 339 | $collecte = array(); |
| 340 | 340 | } |
| 341 | 341 | $texte = substr($args, 1); |
| 342 | - $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
|
| 342 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 343 | 343 | // propager les erreurs, et ignorer les param vides |
| 344 | - if ($pointeur_champ->param!==false){ |
|
| 344 | + if ($pointeur_champ->param !== false) { |
|
| 345 | 345 | if ($err_f) |
| 346 | 346 | $pointeur_champ->param = false; |
| 347 | - elseif ($fonc!=='' || count($res)>1) |
|
| 347 | + elseif ($fonc !== '' || count($res) > 1) |
|
| 348 | 348 | $pointeur_champ->param[] = $res; |
| 349 | 349 | } |
| 350 | 350 | // pour les balises avec faux filtres qui boudent ce dur larbeur |
@@ -355,41 +355,41 @@ discard block |
||
| 355 | 355 | |
| 356 | 356 | |
| 357 | 357 | // http://doc.spip.org/@phraser_champs_exterieurs |
| 358 | -function phraser_champs_exterieurs($texte, $ligne, $sep, $nested){ |
|
| 358 | +function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
|
| 359 | 359 | $res = array(); |
| 360 | - while (($p = strpos($texte, "%$sep"))!==false){ |
|
| 361 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 360 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 361 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | 362 | break; |
| 363 | 363 | $debut = substr($texte, 0, $p); |
| 364 | - $texte = substr($texte, $p+strlen($m[0])); |
|
| 364 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 365 | 365 | if ($p) |
| 366 | 366 | $res = phraser_inclure($debut, $ligne, $res); |
| 367 | 367 | $ligne += substr_count($debut, "\n"); |
| 368 | 368 | $res[] = $nested[$m[1]]; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - return (($texte==='') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 371 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // http://doc.spip.org/@phraser_champs_interieurs |
| 375 | -function phraser_champs_interieurs($texte, $ligne, $sep, $result){ |
|
| 375 | +function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
|
| 376 | 376 | $i = 0; // en fait count($result) |
| 377 | 377 | $x = ""; |
| 378 | 378 | |
| 379 | - while (true){ |
|
| 379 | + while (true) { |
|
| 380 | 380 | $j = $i; |
| 381 | 381 | $n = $ligne; |
| 382 | - while (preg_match(CHAMP_ETENDU, $texte, $match)){ |
|
| 382 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 383 | 383 | $p = strpos($texte, $match[0]); |
| 384 | 384 | $debut = substr($texte, 0, $p); |
| 385 | - if ($p){ |
|
| 385 | + if ($p) { |
|
| 386 | 386 | $result[$i] = $debut; |
| 387 | 387 | $i++; |
| 388 | 388 | } |
| 389 | 389 | $nom = $match[4]; |
| 390 | 390 | $champ = new Champ; |
| 391 | 391 | // ca ne marche pas encore en cas de champ imbrique |
| 392 | - $champ->ligne = $x ? 0 : ($n+substr_count($debut, "\n")); |
|
| 392 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 393 | 393 | $champ->nom_boucle = $match[3]; |
| 394 | 394 | $champ->nom_champ = $nom; |
| 395 | 395 | $champ->etoile = $match[6]; |
@@ -399,22 +399,22 @@ discard block |
||
| 399 | 399 | $champ->avant = |
| 400 | 400 | phraser_champs_exterieurs($match[1], $n, $sep, $result); |
| 401 | 401 | $debut = substr($champ->apres, 1); |
| 402 | - if (!empty($debut)){ |
|
| 402 | + if (!empty($debut)) { |
|
| 403 | 403 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
| 404 | 404 | } |
| 405 | 405 | $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
| 406 | 406 | |
| 407 | 407 | $result[$i] = $champ; |
| 408 | 408 | $i++; |
| 409 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 409 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 410 | 410 | } |
| 411 | - if ($texte!==""){ |
|
| 411 | + if ($texte !== "") { |
|
| 412 | 412 | $result[$i] = $texte; |
| 413 | 413 | $i++; |
| 414 | 414 | } |
| 415 | 415 | $x = ''; |
| 416 | 416 | |
| 417 | - while ($j<$i){ |
|
| 417 | + while ($j < $i) { |
|
| 418 | 418 | $z = $result[$j]; |
| 419 | 419 | // j'aurais besoin de connaitre le nombre de lignes... |
| 420 | 420 | if (is_object($z)) |
@@ -430,18 +430,18 @@ discard block |
||
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | -function phraser_vieux(&$champ){ |
|
| 433 | +function phraser_vieux(&$champ) { |
|
| 434 | 434 | $nom = $champ->nom_champ; |
| 435 | - if ($nom=='EMBED_DOCUMENT'){ |
|
| 435 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 436 | 436 | if (!function_exists('phraser_vieux_emb')) |
| 437 | 437 | include_spip('public/normaliser'); |
| 438 | 438 | phraser_vieux_emb($champ); |
| 439 | - } elseif ($nom=='EXPOSER') { |
|
| 439 | + } elseif ($nom == 'EXPOSER') { |
|
| 440 | 440 | if (!function_exists('phraser_vieux_exposer')) |
| 441 | 441 | include_spip('public/normaliser'); |
| 442 | 442 | phraser_vieux_exposer($champ); |
| 443 | 443 | } elseif ($champ->param) { |
| 444 | - if ($nom=='FORMULAIRE_RECHERCHE'){ |
|
| 444 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 445 | 445 | if (!function_exists('phraser_vieux_recherche')) |
| 446 | 446 | include_spip('public/normaliser'); |
| 447 | 447 | phraser_vieux_recherche($champ); |
@@ -449,11 +449,11 @@ discard block |
||
| 449 | 449 | if (!function_exists('phraser_vieux_logos')) |
| 450 | 450 | include_spip('public/normaliser'); |
| 451 | 451 | phraser_vieux_logos($champ); |
| 452 | - } elseif ($nom=='MODELE') { |
|
| 452 | + } elseif ($nom == 'MODELE') { |
|
| 453 | 453 | if (!function_exists('phraser_vieux_modele')) |
| 454 | 454 | include_spip('public/normaliser'); |
| 455 | 455 | phraser_vieux_modele($champ); |
| 456 | - } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
|
| 456 | + } elseif ($nom == 'INCLURE' OR $nom == 'INCLUDE') { |
|
| 457 | 457 | if (!function_exists('phraser_vieux_inclu')) |
| 458 | 458 | include_spip('public/normaliser'); |
| 459 | 459 | phraser_vieux_inclu($champ); |
@@ -484,22 +484,22 @@ discard block |
||
| 484 | 484 | * Elle sera complété de la liste de ses critères |
| 485 | 485 | * @return void |
| 486 | 486 | **/ |
| 487 | -function phraser_criteres($params, &$result){ |
|
| 487 | +function phraser_criteres($params, &$result) { |
|
| 488 | 488 | |
| 489 | 489 | $err_ci = ''; // indiquera s'il y a eu une erreur |
| 490 | 490 | $args = array(); |
| 491 | 491 | $type = $result->type_requete; |
| 492 | 492 | $doublons = array(); |
| 493 | - foreach ($params as $v){ |
|
| 493 | + foreach ($params as $v) { |
|
| 494 | 494 | $var = $v[1][0]; |
| 495 | - $param = ($var->type!='texte') ? "" : $var->texte; |
|
| 496 | - if ((count($v)>2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))){ |
|
| 495 | + $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 496 | + if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 497 | 497 | // plus d'un argument et pas le critere IN: |
| 498 | 498 | // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
| 499 | 499 | |
| 500 | - if ($var->type!='texte' |
|
| 500 | + if ($var->type != 'texte' |
|
| 501 | 501 | OR preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
| 502 | - ){ |
|
| 502 | + ) { |
|
| 503 | 503 | $op = ','; |
| 504 | 504 | $not = ""; |
| 505 | 505 | } else { |
@@ -512,11 +512,11 @@ discard block |
||
| 512 | 512 | // et mettre son reliquat eventuel |
| 513 | 513 | // Recopier pour ne pas alterer le texte source |
| 514 | 514 | // utile au debusqueur |
| 515 | - if ($m[4]){ |
|
| 515 | + if ($m[4]) { |
|
| 516 | 516 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 517 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
|
| 517 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 518 | 518 | $c = null; |
| 519 | - eval ('$c = ' . $m[4] . ';'); |
|
| 519 | + eval ('$c = '.$m[4].';'); |
|
| 520 | 520 | if (isset($c)) |
| 521 | 521 | $m[4] = $c; |
| 522 | 522 | } |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | $crit->param = $v; |
| 535 | 535 | $args[] = $crit; |
| 536 | 536 | } else { |
| 537 | - if ($var->type!='texte'){ |
|
| 537 | + if ($var->type != 'texte') { |
|
| 538 | 538 | // cas 1 seul arg ne commencant pas par du texte brut: |
| 539 | 539 | // erreur ou critere infixe "/" |
| 540 | - if (($v[1][1]->type!='texte') || (trim($v[1][1]->texte)!='/')){ |
|
| 540 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 541 | 541 | $err_ci = array('zbug_critere_inconnu', |
| 542 | 542 | array('critere' => $var->nom_champ)); |
| 543 | 543 | erreur_squelette($err_ci, $result); |
@@ -554,9 +554,9 @@ discard block |
||
| 554 | 554 | // les separateurs |
| 555 | 555 | if ($var->apres) |
| 556 | 556 | $result->separateur[] = $param; |
| 557 | - elseif (($param=='tout') OR ($param=='tous')) |
|
| 557 | + elseif (($param == 'tout') OR ($param == 'tous')) |
|
| 558 | 558 | $result->modificateur['tout'] = true; |
| 559 | - elseif ($param=='plat') |
|
| 559 | + elseif ($param == 'plat') |
|
| 560 | 560 | $result->modificateur['plat'] = true; |
| 561 | 561 | |
| 562 | 562 | // Boucle hierarchie, analyser le critere id_rubrique |
@@ -564,43 +564,43 @@ discard block |
||
| 564 | 564 | // ceux-ci pour avoir la rubrique mere... |
| 565 | 565 | // Les autres critères de la boucle hierarchie doivent être |
| 566 | 566 | // traités normalement. |
| 567 | - elseif (strcasecmp($type, 'hierarchie')==0 |
|
| 567 | + elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 568 | 568 | AND !preg_match(",^id_rubrique\b,", $param) |
| 569 | 569 | AND preg_match(",^id_\w+\s*$,", $param) |
| 570 | 570 | ) { |
| 571 | 571 | $result->modificateur['tout'] = true; |
| 572 | - } elseif (strcasecmp($type, 'hierarchie')==0 AND $param=="id_rubrique") { |
|
| 572 | + } elseif (strcasecmp($type, 'hierarchie') == 0 AND $param == "id_rubrique") { |
|
| 573 | 573 | // rien a faire sur {id_rubrique} tout seul |
| 574 | 574 | } else { |
| 575 | 575 | // pas d'emplacement statique, faut un dynamique |
| 576 | 576 | /// mais il y a 2 cas qui ont les 2 ! |
| 577 | - if (($param=='unique') || (preg_match(',^!?doublons *,', $param))){ |
|
| 577 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 578 | 578 | // cette variable sera inseree dans le code |
| 579 | 579 | // et son nom sert d'indicateur des maintenant |
| 580 | 580 | $result->doublons = '$doublons_index'; |
| 581 | - if ($param=='unique') $param = 'doublons'; |
|
| 582 | - } elseif ($param=='recherche') |
|
| 581 | + if ($param == 'unique') $param = 'doublons'; |
|
| 582 | + } elseif ($param == 'recherche') |
|
| 583 | 583 | // meme chose (a cause de #nom_de_boucle:URL_*) |
| 584 | 584 | $result->hash = ' '; |
| 585 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
|
| 585 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 586 | 586 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 587 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 587 | + } elseif (preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 588 | 588 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
| 589 | 589 | $a2 = trim($m[8]); |
| 590 | - if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 590 | + if ($a2 AND ($a2[0] == "'" OR $a2[0] == '"') AND ($a2[0] == substr($a2, -1))) |
|
| 591 | 591 | $a2 = substr($a2, 1, -1); |
| 592 | 592 | $crit = phraser_critere_infixe($m[2], $a2, $v, |
| 593 | - (($m[2]=='lang_select') ? $m[2] : $m[7]), |
|
| 593 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 594 | 594 | $m[6], $m[5]); |
| 595 | 595 | $crit->exclus = $m[1]; |
| 596 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 597 | - CHAMP_SQL_PLUS_FONC . |
|
| 596 | + } elseif (preg_match("/^([!]?)\s*(". |
|
| 597 | + CHAMP_SQL_PLUS_FONC. |
|
| 598 | 598 | ")\s*(\??)(.*)$/is", $param, $m)) { |
| 599 | 599 | // contient aussi les comparaisons implicites ! |
| 600 | 600 | // Comme ci-dessus: |
| 601 | 601 | // le premier arg contient l'operateur |
| 602 | 602 | array_shift($v); |
| 603 | - if ($m[6]){ |
|
| 603 | + if ($m[6]) { |
|
| 604 | 604 | $v[0][0] = new Texte; |
| 605 | 605 | $v[0][0]->texte = $m[6]; |
| 606 | 606 | } else { |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | // http://doc.spip.org/@phraser_critere_infixe |
| 637 | -function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond){ |
|
| 637 | +function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
|
| 638 | 638 | $args[0] = new Texte; |
| 639 | 639 | $args[0]->texte = $arg1; |
| 640 | 640 | $args[0] = array($args[0]); |
@@ -649,11 +649,11 @@ discard block |
||
| 649 | 649 | return $crit; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | -function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1){ |
|
| 652 | +function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1) { |
|
| 653 | 653 | |
| 654 | 654 | $all_res = array(); |
| 655 | 655 | |
| 656 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE))!==false){ |
|
| 656 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE)) !== false) { |
|
| 657 | 657 | |
| 658 | 658 | $err_b = ''; // indiquera s'il y a eu une erreur |
| 659 | 659 | $result = new Boucle; |
@@ -661,16 +661,16 @@ discard block |
||
| 661 | 661 | $result->descr = $descr; |
| 662 | 662 | # attention: reperer la premiere des 2 balises: pre_boucle ou boucle |
| 663 | 663 | |
| 664 | - if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 665 | - OR ($n = strpos($texte, $r[0]))===false |
|
| 666 | - OR ($n>$pos_boucle) |
|
| 667 | - ){ |
|
| 664 | + if (!preg_match(",".BALISE_PRE_BOUCLE.'[0-9_],', $texte, $r) |
|
| 665 | + OR ($n = strpos($texte, $r[0])) === false |
|
| 666 | + OR ($n > $pos_boucle) |
|
| 667 | + ) { |
|
| 668 | 668 | $debut = substr($texte, 0, $pos_boucle); |
| 669 | 669 | $milieu = substr($texte, $pos_boucle); |
| 670 | 670 | $k = strpos($milieu, '('); |
| 671 | 671 | $id_boucle = trim(substr($milieu, |
| 672 | 672 | strlen(BALISE_BOUCLE), |
| 673 | - $k-strlen(BALISE_BOUCLE))); |
|
| 673 | + $k - strlen(BALISE_BOUCLE))); |
|
| 674 | 674 | $milieu = substr($milieu, $k); |
| 675 | 675 | |
| 676 | 676 | } else { |
@@ -679,18 +679,18 @@ discard block |
||
| 679 | 679 | $k = strpos($milieu, '>'); |
| 680 | 680 | $id_boucle = substr($milieu, |
| 681 | 681 | strlen(BALISE_PRE_BOUCLE), |
| 682 | - $k-strlen(BALISE_PRE_BOUCLE)); |
|
| 682 | + $k - strlen(BALISE_PRE_BOUCLE)); |
|
| 683 | 683 | |
| 684 | - if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)){ |
|
| 684 | + if (!preg_match(",".BALISE_BOUCLE.$id_boucle."[[:space:]]*\(,", $milieu, $r)) { |
|
| 685 | 685 | $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
| 686 | 686 | erreur_squelette($err_b, $result); |
| 687 | - $texte = substr($texte, $n+1); |
|
| 687 | + $texte = substr($texte, $n + 1); |
|
| 688 | 688 | continue; |
| 689 | 689 | } else { |
| 690 | 690 | $pos_boucle = $n; |
| 691 | 691 | $n = strpos($milieu, $r[0]); |
| 692 | - $result->avant = substr($milieu, $k+1, $n-$k-1); |
|
| 693 | - $milieu = substr($milieu, $n+strlen($id_boucle)+strlen(BALISE_BOUCLE)); |
|
| 692 | + $result->avant = substr($milieu, $k + 1, $n - $k - 1); |
|
| 693 | + $milieu = substr($milieu, $n + strlen($id_boucle) + strlen(BALISE_BOUCLE)); |
|
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | 696 | $result->id_boucle = $id_boucle; |
@@ -701,13 +701,13 @@ discard block |
||
| 701 | 701 | $type = $match[1]; |
| 702 | 702 | $jointures = trim($match[2]); |
| 703 | 703 | $table_optionnelle = ($match[3]); |
| 704 | - if ($jointures){ |
|
| 704 | + if ($jointures) { |
|
| 705 | 705 | // on affecte pas ici les jointures explicites, mais dans la compilation |
| 706 | 706 | // ou elles seront completees des jointures declarees |
| 707 | 707 | $result->jointures_explicites = $jointures; |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | - if ($table_optionnelle){ |
|
| 710 | + if ($table_optionnelle) { |
|
| 711 | 711 | $result->table_optionnelle = $type; |
| 712 | 712 | } |
| 713 | 713 | |
@@ -725,20 +725,20 @@ discard block |
||
| 725 | 725 | // |
| 726 | 726 | // Recuperer la fin : |
| 727 | 727 | // |
| 728 | - if ($milieu[0]==='/'){ |
|
| 728 | + if ($milieu[0] === '/') { |
|
| 729 | 729 | $suite = substr($milieu, 2); |
| 730 | 730 | $milieu = ''; |
| 731 | 731 | } else { |
| 732 | 732 | $milieu = substr($milieu, 1); |
| 733 | - $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 733 | + $s = BALISE_FIN_BOUCLE.$id_boucle.">"; |
|
| 734 | 734 | $p = strpos($milieu, $s); |
| 735 | - if ($p===false){ |
|
| 735 | + if ($p === false) { |
|
| 736 | 736 | $err_b = array('zbug_erreur_boucle_fermant', |
| 737 | 737 | array('id' => $id_boucle)); |
| 738 | 738 | erreur_squelette($err_b, $result); |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - $suite = substr($milieu, $p+strlen($s)); |
|
| 741 | + $suite = substr($milieu, $p + strlen($s)); |
|
| 742 | 742 | $milieu = substr($milieu, 0, $p); |
| 743 | 743 | } |
| 744 | 744 | |
@@ -747,30 +747,30 @@ discard block |
||
| 747 | 747 | // |
| 748 | 748 | // 1. Recuperer la partie conditionnelle apres |
| 749 | 749 | // |
| 750 | - $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 750 | + $s = BALISE_POST_BOUCLE.$id_boucle.">"; |
|
| 751 | 751 | $p = strpos($suite, $s); |
| 752 | - if ($p!==false){ |
|
| 752 | + if ($p !== false) { |
|
| 753 | 753 | $result->apres = substr($suite, 0, $p); |
| 754 | - $suite = substr($suite, $p+strlen($s)); |
|
| 754 | + $suite = substr($suite, $p + strlen($s)); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // |
| 758 | 758 | // 2. Recuperer la partie alternative |
| 759 | 759 | // |
| 760 | - $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 760 | + $s = BALISE_ALT_BOUCLE.$id_boucle.">"; |
|
| 761 | 761 | $p = strpos($suite, $s); |
| 762 | - if ($p!==false){ |
|
| 762 | + if ($p !== false) { |
|
| 763 | 763 | $result->altern = substr($suite, 0, $p); |
| 764 | - $suite = substr($suite, $p+strlen($s)); |
|
| 764 | + $suite = substr($suite, $p + strlen($s)); |
|
| 765 | 765 | } |
| 766 | - $result->ligne = $ligne+substr_count($debut, "\n"); |
|
| 766 | + $result->ligne = $ligne + substr_count($debut, "\n"); |
|
| 767 | 767 | $m = substr_count($milieu, "\n"); |
| 768 | 768 | $b = substr_count($result->avant, "\n"); |
| 769 | 769 | $a = substr_count($result->apres, "\n"); |
| 770 | 770 | |
| 771 | - if ($p = strpos($type, ':')){ |
|
| 771 | + if ($p = strpos($type, ':')) { |
|
| 772 | 772 | $result->sql_serveur = substr($type, 0, $p); |
| 773 | - $type = substr($type, $p+1); |
|
| 773 | + $type = substr($type, $p + 1); |
|
| 774 | 774 | } |
| 775 | 775 | $soustype = strtolower($type); |
| 776 | 776 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | $err_b = true; |
| 784 | 784 | else { |
| 785 | 785 | phraser_criteres($result->param, $result); |
| 786 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
|
| 786 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 787 | 787 | $result->type_requete = TYPE_RECURSIF; |
| 788 | 788 | $args = $result->param; |
| 789 | 789 | array_unshift($args, |
@@ -793,9 +793,9 @@ discard block |
||
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
| 796 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne+$b+$m); |
|
| 797 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne+$a+$m+$b); |
|
| 798 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
|
| 796 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne + $b + $m); |
|
| 797 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne + $a + $m + $b); |
|
| 798 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne + $b); |
|
| 799 | 799 | |
| 800 | 800 | // Prevenir le generateur de code que le squelette est faux |
| 801 | 801 | if ($err_b) $result->type_requete = false; |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | // Verifier qu'il n'y a pas double definition |
| 804 | 804 | // apres analyse des sous-parties (pas avant). |
| 805 | 805 | |
| 806 | - if (isset($boucles[$id_boucle])){ |
|
| 806 | + if (isset($boucles[$id_boucle])) { |
|
| 807 | 807 | $err_b_d = array('zbug_erreur_boucle_double', |
| 808 | 808 | array('id' => $id_boucle)); |
| 809 | 809 | erreur_squelette($err_b_d, $result); |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | $boucles[$id_boucle] = $result; |
| 814 | 814 | $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
| 815 | 815 | $all_res[] = &$boucles[$id_boucle]; |
| 816 | - if (!empty($suite)){ |
|
| 816 | + if (!empty($suite)) { |
|
| 817 | 817 | $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
| 818 | 818 | } |
| 819 | 819 | $texte = $suite; |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | * \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | # Ce fichier transforme un squelette en un tableau d'objets de classe Boucle |
| 17 | 19 | # il est charge par un include calcule |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | while (preg_match(BALISE_INCLURE, $texte, $match)){ |
| 45 | 47 | $p = strpos($texte, $match[0]); |
| 46 | 48 | $debut = substr($texte, 0, $p); |
| 47 | - if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
|
| 49 | + if ($p) { |
|
| 50 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 51 | + } |
|
| 48 | 52 | $ligne += substr_count($debut, "\n"); |
| 49 | 53 | $champ = new Inclure; |
| 50 | 54 | $champ->ligne = $ligne; |
@@ -60,8 +64,9 @@ discard block |
||
| 60 | 64 | // on assimile {var=val} a une liste de un argument sans fonction |
| 61 | 65 | phraser_args($texte, "/>", "", $result, $champ); |
| 62 | 66 | if (!$champ->texte OR count($champ->param)>1){ |
| 63 | - if (!function_exists('normaliser_inclure')) |
|
| 64 | - include_spip('public/normaliser'); |
|
| 67 | + if (!function_exists('normaliser_inclure')) { |
|
| 68 | + include_spip('public/normaliser'); |
|
| 69 | + } |
|
| 65 | 70 | normaliser_inclure($champ); |
| 66 | 71 | } |
| 67 | 72 | $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
@@ -76,9 +81,10 @@ discard block |
||
| 76 | 81 | // http://doc.spip.org/@phraser_polyglotte |
| 77 | 82 | function phraser_polyglotte($texte, $ligne, $result){ |
| 78 | 83 | |
| 79 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
|
| 80 | - foreach ($m as $match){ |
|
| 84 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 85 | + foreach ($m as $match){ |
|
| 81 | 86 | $p = strpos($texte, $match[0]); |
| 87 | + } |
|
| 82 | 88 | $debut = substr($texte, 0, $p); |
| 83 | 89 | if ($p){ |
| 84 | 90 | $champ = new Texte; |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | $texte = substr($texte, $p+strlen($match[0])); |
| 97 | 103 | while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
| 98 | 104 | $trad = $regs[1]; |
| 99 | - if ($trad OR $lang) |
|
| 100 | - $champ->traductions[$lang] = $trad; |
|
| 105 | + if ($trad OR $lang) { |
|
| 106 | + $champ->traductions[$lang] = $trad; |
|
| 107 | + } |
|
| 101 | 108 | $lang = $regs[2]; |
| 102 | 109 | $bloc = $regs[3]; |
| 103 | 110 | } |
@@ -125,10 +132,15 @@ discard block |
||
| 125 | 132 | $p = strpos($texte, $match[0]); |
| 126 | 133 | $ko = (!$match[3] && ($match[5][0]!=='=')); |
| 127 | 134 | $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
| 128 | - if ($debut) $result = phraser_champs($debut, $ligne, $result); |
|
| 135 | + if ($debut) { |
|
| 136 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 137 | + } |
|
| 129 | 138 | $texte = substr($texte, $p+strlen($match[0])); |
| 130 | 139 | $ligne += substr_count($debut, "\n"); |
| 131 | - if ($ko) continue; // faux idiome |
|
| 140 | + if ($ko) { |
|
| 141 | + continue; |
|
| 142 | + } |
|
| 143 | + // faux idiome |
|
| 132 | 144 | $champ = new Idiome; |
| 133 | 145 | $champ->ligne = $ligne; |
| 134 | 146 | $ligne += substr_count($match[0], "\n"); |
@@ -146,7 +158,9 @@ discard block |
||
| 146 | 158 | phraser_args(@$match[7], ":", '', array(), $champ); |
| 147 | 159 | $result[] = $champ; |
| 148 | 160 | } |
| 149 | - if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 161 | + if ($texte!=="") { |
|
| 162 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 163 | + } |
|
| 150 | 164 | |
| 151 | 165 | return $result; |
| 152 | 166 | } |
@@ -158,7 +172,9 @@ discard block |
||
| 158 | 172 | $suite = substr($texte, $p+strlen($match[0])); |
| 159 | 173 | if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
| 160 | 174 | $debut = substr($texte, 0, $p); |
| 161 | - if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 175 | + if ($p) { |
|
| 176 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 177 | + } |
|
| 162 | 178 | $ligne += substr_count($debut, "\n"); |
| 163 | 179 | $champ = new Champ; |
| 164 | 180 | $champ->ligne = $ligne; |
@@ -180,7 +196,9 @@ discard block |
||
| 180 | 196 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 181 | 197 | } |
| 182 | 198 | */ |
| 183 | - } else $texte = $suite; |
|
| 199 | + } else { |
|
| 200 | + $texte = $suite; |
|
| 201 | + } |
|
| 184 | 202 | phraser_vieux($champ); |
| 185 | 203 | $result[] = $champ; |
| 186 | 204 | } else { |
@@ -189,7 +207,9 @@ discard block |
||
| 189 | 207 | $texte = (substr($texte, $p+1)); |
| 190 | 208 | } |
| 191 | 209 | } |
| 192 | - if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 210 | + if ($texte!=="") { |
|
| 211 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 212 | + } |
|
| 193 | 213 | |
| 194 | 214 | return $result; |
| 195 | 215 | } |
@@ -201,10 +221,13 @@ discard block |
||
| 201 | 221 | |
| 202 | 222 | // http://doc.spip.org/@phraser_champs_etendus |
| 203 | 223 | function phraser_champs_etendus($texte, $ligne, $result){ |
| 204 | - if ($texte==="") return $result; |
|
| 224 | + if ($texte==="") { |
|
| 225 | + return $result; |
|
| 226 | + } |
|
| 205 | 227 | $sep = '##'; |
| 206 | - while (strpos($texte, $sep)!==false) |
|
| 207 | - $sep .= '#'; |
|
| 228 | + while (strpos($texte, $sep)!==false) { |
|
| 229 | + $sep .= '#'; |
|
| 230 | + } |
|
| 208 | 231 | |
| 209 | 232 | return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
| 210 | 233 | } |
@@ -234,7 +257,9 @@ discard block |
||
| 234 | 257 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 235 | 258 | $suite = ltrim($match[2]); |
| 236 | 259 | $fonc = trim($match[1]); |
| 237 | - if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 260 | + if ($fonc && $fonc[0]=="|") { |
|
| 261 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 262 | + } |
|
| 238 | 263 | $res = array($fonc); |
| 239 | 264 | $err_f = ''; |
| 240 | 265 | // cas du filtre sans argument ou du critere / |
@@ -244,9 +269,14 @@ discard block |
||
| 244 | 269 | $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
| 245 | 270 | erreur_squelette($err_f, $pointeur_champ); |
| 246 | 271 | $texte = ''; |
| 247 | - } else $texte = $suite; |
|
| 248 | - if ($err_f) $pointeur_champ->param = false; |
|
| 249 | - elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 272 | + } else { |
|
| 273 | + $texte = $suite; |
|
| 274 | + } |
|
| 275 | + if ($err_f) { |
|
| 276 | + $pointeur_champ->param = false; |
|
| 277 | + } elseif ($fonc!=='') { |
|
| 278 | + $pointeur_champ->param[] = $res; |
|
| 279 | + } |
|
| 250 | 280 | // pour les balises avec faux filtres qui boudent ce dur larbeur |
| 251 | 281 | $pointeur_champ->fonctions[] = array($fonc, ''); |
| 252 | 282 | |
@@ -255,11 +285,11 @@ discard block |
||
| 255 | 285 | $args = ltrim(substr($suite, 1)); // virer le '(' initial |
| 256 | 286 | $collecte = array(); |
| 257 | 287 | while ($args && $args[0]!='}'){ |
| 258 | - if ($args[0]=='"') |
|
| 259 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 260 | - else if ($args[0]=="'") |
|
| 261 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 262 | - else { |
|
| 288 | + if ($args[0]=='"') { |
|
| 289 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 290 | + } else if ($args[0]=="'") { |
|
| 291 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 292 | + } else { |
|
| 263 | 293 | preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
| 264 | 294 | if (!strlen($regs[2])){ |
| 265 | 295 | $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
@@ -318,10 +348,14 @@ discard block |
||
| 318 | 348 | $next = isset($args[0]) ? $args[0] : ''; |
| 319 | 349 | } |
| 320 | 350 | // Si erreur de syntaxe dans un sous-argument, propager. |
| 321 | - if ($champ->param===false) |
|
| 322 | - $err_f = true; |
|
| 323 | - else phraser_vieux($champ); |
|
| 324 | - if ($par==')') $args = substr($args, 1); |
|
| 351 | + if ($champ->param===false) { |
|
| 352 | + $err_f = true; |
|
| 353 | + } else { |
|
| 354 | + phraser_vieux($champ); |
|
| 355 | + } |
|
| 356 | + if ($par==')') { |
|
| 357 | + $args = substr($args, 1); |
|
| 358 | + } |
|
| 325 | 359 | $collecte[] = $champ; |
| 326 | 360 | $result[] = $champ; |
| 327 | 361 | } |
@@ -342,10 +376,11 @@ discard block |
||
| 342 | 376 | $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
| 343 | 377 | // propager les erreurs, et ignorer les param vides |
| 344 | 378 | if ($pointeur_champ->param!==false){ |
| 345 | - if ($err_f) |
|
| 346 | - $pointeur_champ->param = false; |
|
| 347 | - elseif ($fonc!=='' || count($res)>1) |
|
| 348 | - $pointeur_champ->param[] = $res; |
|
| 379 | + if ($err_f) { |
|
| 380 | + $pointeur_champ->param = false; |
|
| 381 | + } elseif ($fonc!=='' || count($res)>1) { |
|
| 382 | + $pointeur_champ->param[] = $res; |
|
| 383 | + } |
|
| 349 | 384 | } |
| 350 | 385 | // pour les balises avec faux filtres qui boudent ce dur larbeur |
| 351 | 386 | $pointeur_champ->fonctions[] = array($fonc, $source); |
@@ -358,12 +393,14 @@ discard block |
||
| 358 | 393 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested){ |
| 359 | 394 | $res = array(); |
| 360 | 395 | while (($p = strpos($texte, "%$sep"))!==false){ |
| 361 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | - break; |
|
| 396 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 397 | + break; |
|
| 398 | + } |
|
| 363 | 399 | $debut = substr($texte, 0, $p); |
| 364 | 400 | $texte = substr($texte, $p+strlen($m[0])); |
| 365 | - if ($p) |
|
| 366 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 401 | + if ($p) { |
|
| 402 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 403 | + } |
|
| 367 | 404 | $ligne += substr_count($debut, "\n"); |
| 368 | 405 | $res[] = $nested[$m[1]]; |
| 369 | 406 | } |
@@ -417,45 +454,53 @@ discard block |
||
| 417 | 454 | while ($j<$i){ |
| 418 | 455 | $z = $result[$j]; |
| 419 | 456 | // j'aurais besoin de connaitre le nombre de lignes... |
| 420 | - if (is_object($z)) |
|
| 421 | - $x .= "%$sep$j@"; |
|
| 422 | - else |
|
| 423 | - $x .= $z; |
|
| 457 | + if (is_object($z)) { |
|
| 458 | + $x .= "%$sep$j@"; |
|
| 459 | + } else { |
|
| 460 | + $x .= $z; |
|
| 461 | + } |
|
| 424 | 462 | $j++; |
| 425 | 463 | } |
| 426 | - if (preg_match(CHAMP_ETENDU, $x)) |
|
| 427 | - $texte = $x; |
|
| 428 | - else |
|
| 429 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 464 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 465 | + $texte = $x; |
|
| 466 | + } else { |
|
| 467 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 468 | + } |
|
| 430 | 469 | } |
| 431 | 470 | } |
| 432 | 471 | |
| 433 | 472 | function phraser_vieux(&$champ){ |
| 434 | 473 | $nom = $champ->nom_champ; |
| 435 | 474 | if ($nom=='EMBED_DOCUMENT'){ |
| 436 | - if (!function_exists('phraser_vieux_emb')) |
|
| 437 | - include_spip('public/normaliser'); |
|
| 475 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 476 | + include_spip('public/normaliser'); |
|
| 477 | + } |
|
| 438 | 478 | phraser_vieux_emb($champ); |
| 439 | 479 | } elseif ($nom=='EXPOSER') { |
| 440 | - if (!function_exists('phraser_vieux_exposer')) |
|
| 441 | - include_spip('public/normaliser'); |
|
| 480 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 481 | + include_spip('public/normaliser'); |
|
| 482 | + } |
|
| 442 | 483 | phraser_vieux_exposer($champ); |
| 443 | 484 | } elseif ($champ->param) { |
| 444 | 485 | if ($nom=='FORMULAIRE_RECHERCHE'){ |
| 445 | - if (!function_exists('phraser_vieux_recherche')) |
|
| 446 | - include_spip('public/normaliser'); |
|
| 486 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 487 | + include_spip('public/normaliser'); |
|
| 488 | + } |
|
| 447 | 489 | phraser_vieux_recherche($champ); |
| 448 | 490 | } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
| 449 | - if (!function_exists('phraser_vieux_logos')) |
|
| 450 | - include_spip('public/normaliser'); |
|
| 491 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 492 | + include_spip('public/normaliser'); |
|
| 493 | + } |
|
| 451 | 494 | phraser_vieux_logos($champ); |
| 452 | 495 | } elseif ($nom=='MODELE') { |
| 453 | - if (!function_exists('phraser_vieux_modele')) |
|
| 454 | - include_spip('public/normaliser'); |
|
| 496 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 497 | + include_spip('public/normaliser'); |
|
| 498 | + } |
|
| 455 | 499 | phraser_vieux_modele($champ); |
| 456 | 500 | } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
| 457 | - if (!function_exists('phraser_vieux_inclu')) |
|
| 458 | - include_spip('public/normaliser'); |
|
| 501 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 502 | + include_spip('public/normaliser'); |
|
| 503 | + } |
|
| 459 | 504 | phraser_vieux_inclu($champ); |
| 460 | 505 | } |
| 461 | 506 | } |
@@ -517,13 +562,16 @@ discard block |
||
| 517 | 562 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
| 518 | 563 | $c = null; |
| 519 | 564 | eval ('$c = ' . $m[4] . ';'); |
| 520 | - if (isset($c)) |
|
| 521 | - $m[4] = $c; |
|
| 565 | + if (isset($c)) { |
|
| 566 | + $m[4] = $c; |
|
| 567 | + } |
|
| 522 | 568 | } |
| 523 | 569 | $texte = new Texte; |
| 524 | 570 | $texte->texte = $m[4]; |
| 525 | 571 | $v[1][0] = $texte; |
| 526 | - } else array_shift($v[1]); |
|
| 572 | + } else { |
|
| 573 | + array_shift($v[1]); |
|
| 574 | + } |
|
| 527 | 575 | } |
| 528 | 576 | array_shift($v); // $v[O] est vide |
| 529 | 577 | $crit = new Critere; |
@@ -552,12 +600,13 @@ discard block |
||
| 552 | 600 | } else { |
| 553 | 601 | // traiter qq lexemes particuliers pour faciliter la suite |
| 554 | 602 | // les separateurs |
| 555 | - if ($var->apres) |
|
| 556 | - $result->separateur[] = $param; |
|
| 557 | - elseif (($param=='tout') OR ($param=='tous')) |
|
| 558 | - $result->modificateur['tout'] = true; |
|
| 559 | - elseif ($param=='plat') |
|
| 560 | - $result->modificateur['plat'] = true; |
|
| 603 | + if ($var->apres) { |
|
| 604 | + $result->separateur[] = $param; |
|
| 605 | + } elseif (($param=='tout') OR ($param=='tous')) { |
|
| 606 | + $result->modificateur['tout'] = true; |
|
| 607 | + } elseif ($param=='plat') { |
|
| 608 | + $result->modificateur['plat'] = true; |
|
| 609 | + } |
|
| 561 | 610 | |
| 562 | 611 | // Boucle hierarchie, analyser le critere id_rubrique |
| 563 | 612 | // et les autres critères {id_x} pour forcer {tout} sur |
@@ -578,17 +627,21 @@ discard block |
||
| 578 | 627 | // cette variable sera inseree dans le code |
| 579 | 628 | // et son nom sert d'indicateur des maintenant |
| 580 | 629 | $result->doublons = '$doublons_index'; |
| 581 | - if ($param=='unique') $param = 'doublons'; |
|
| 582 | - } elseif ($param=='recherche') |
|
| 583 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 630 | + if ($param=='unique') { |
|
| 631 | + $param = 'doublons'; |
|
| 632 | + } |
|
| 633 | + } elseif ($param=='recherche') { |
|
| 634 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 584 | 635 | $result->hash = ' '; |
| 636 | + } |
|
| 585 | 637 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
| 586 | 638 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 587 | 639 | } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
| 588 | 640 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
| 589 | 641 | $a2 = trim($m[8]); |
| 590 | - if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 591 | - $a2 = substr($a2, 1, -1); |
|
| 642 | + if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) { |
|
| 643 | + $a2 = substr($a2, 1, -1); |
|
| 644 | + } |
|
| 592 | 645 | $crit = phraser_critere_infixe($m[2], $a2, $v, |
| 593 | 646 | (($m[2]=='lang_select') ? $m[2] : $m[7]), |
| 594 | 647 | $m[6], $m[5]); |
@@ -605,7 +658,9 @@ discard block |
||
| 605 | 658 | $v[0][0]->texte = $m[6]; |
| 606 | 659 | } else { |
| 607 | 660 | array_shift($v[0]); |
| 608 | - if (!$v[0]) array_shift($v); |
|
| 661 | + if (!$v[0]) { |
|
| 662 | + array_shift($v); |
|
| 663 | + } |
|
| 609 | 664 | } |
| 610 | 665 | $crit = new Critere; |
| 611 | 666 | $crit->op = $m[2]; |
@@ -617,10 +672,11 @@ discard block |
||
| 617 | 672 | array('critere' => $param)); |
| 618 | 673 | erreur_squelette($err_ci, $result); |
| 619 | 674 | } |
| 620 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) |
|
| 621 | - $args[] = $crit; |
|
| 622 | - else |
|
| 623 | - $doublons[] = $crit; |
|
| 675 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 676 | + $args[] = $crit; |
|
| 677 | + } else { |
|
| 678 | + $doublons[] = $crit; |
|
| 679 | + } |
|
| 624 | 680 | } |
| 625 | 681 | } |
| 626 | 682 | } |
@@ -628,10 +684,14 @@ discard block |
||
| 628 | 684 | // les doublons non nies doivent etre le dernier critere |
| 629 | 685 | // pour que la variable $doublon_index ait la bonne valeur |
| 630 | 686 | // cf critere_doublon |
| 631 | - if ($doublons) $args = array_merge($args, $doublons); |
|
| 687 | + if ($doublons) { |
|
| 688 | + $args = array_merge($args, $doublons); |
|
| 689 | + } |
|
| 632 | 690 | // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
| 633 | - if (!$err_ci) $result->criteres = $args; |
|
| 634 | -} |
|
| 691 | + if (!$err_ci) { |
|
| 692 | + $result->criteres = $args; |
|
| 693 | + } |
|
| 694 | + } |
|
| 635 | 695 | |
| 636 | 696 | // http://doc.spip.org/@phraser_critere_infixe |
| 637 | 697 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond){ |
@@ -774,14 +834,15 @@ discard block |
||
| 774 | 834 | } |
| 775 | 835 | $soustype = strtolower($type); |
| 776 | 836 | |
| 777 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) |
|
| 778 | - $soustype = $type; |
|
| 837 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 838 | + $soustype = $type; |
|
| 839 | + } |
|
| 779 | 840 | |
| 780 | 841 | $result->type_requete = $soustype; |
| 781 | 842 | // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
| 782 | - if (!is_array($result->param)) |
|
| 783 | - $err_b = true; |
|
| 784 | - else { |
|
| 843 | + if (!is_array($result->param)) { |
|
| 844 | + $err_b = true; |
|
| 845 | + } else { |
|
| 785 | 846 | phraser_criteres($result->param, $result); |
| 786 | 847 | if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
| 787 | 848 | $result->type_requete = TYPE_RECURSIF; |
@@ -798,7 +859,9 @@ discard block |
||
| 798 | 859 | $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
| 799 | 860 | |
| 800 | 861 | // Prevenir le generateur de code que le squelette est faux |
| 801 | - if ($err_b) $result->type_requete = false; |
|
| 862 | + if ($err_b) { |
|
| 863 | + $result->type_requete = false; |
|
| 864 | + } |
|
| 802 | 865 | |
| 803 | 866 | // Verifier qu'il n'y a pas double definition |
| 804 | 867 | // apres analyse des sous-parties (pas avant). |
@@ -809,8 +872,9 @@ discard block |
||
| 809 | 872 | erreur_squelette($err_b_d, $result); |
| 810 | 873 | // Prevenir le generateur de code que le squelette est faux |
| 811 | 874 | $boucles[$id_boucle]->type_requete = false; |
| 812 | - } else |
|
| 813 | - $boucles[$id_boucle] = $result; |
|
| 875 | + } else { |
|
| 876 | + $boucles[$id_boucle] = $result; |
|
| 877 | + } |
|
| 814 | 878 | $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
| 815 | 879 | $all_res[] = &$boucles[$id_boucle]; |
| 816 | 880 | if (!empty($suite)){ |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * retourne l'url de redirection d'un article virtuel, seulement si il est publié |
| 25 | 25 | * http://doc.spip.org/@quete_chapo |
| 26 | 26 | * |
| 27 | - * @param $id_article |
|
| 28 | - * @param $connect |
|
| 29 | - * @return array|bool|null |
|
| 27 | + * @param integer $id_article |
|
| 28 | + * @param string $connect |
|
| 29 | + * @return string |
|
| 30 | 30 | */ |
| 31 | 31 | function quete_virtuel($id_article, $connect) { |
| 32 | 32 | return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * http://doc.spip.org/@quete_rubrique |
| 92 | 92 | * |
| 93 | 93 | * @param int $id_article |
| 94 | - * @param $serveur |
|
| 94 | + * @param string $serveur |
|
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | 97 | function quete_rubrique($id_article, $serveur) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @param int $id_document |
| 222 | 222 | * @param string $serveur |
| 223 | - * @return array|bool|null |
|
| 223 | + * @return string |
|
| 224 | 224 | */ |
| 225 | 225 | function quete_fichier($id_document, $serveur='') { |
| 226 | 226 | return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * http://doc.spip.org/@quete_meta |
| 244 | 244 | * |
| 245 | - * @param $nom |
|
| 246 | - * @param $serveur |
|
| 245 | + * @param string $nom |
|
| 246 | + * @param string $serveur |
|
| 247 | 247 | * @return array|bool|null |
| 248 | 248 | */ |
| 249 | 249 | function quete_meta($nom, $serveur) { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return array|bool|null |
| 30 | 30 | */ |
| 31 | 31 | function quete_virtuel($id_article, $connect) { |
| 32 | - return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
|
| 32 | + return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | function quete_parent_lang($table,$id,$connect=''){ |
| 46 | - static $cache_quete = array(); |
|
| 47 | - |
|
| 48 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 49 | - if (!isset($cache_quete[$connect][$table]['_select'])){ |
|
| 50 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 51 | - if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | - // pas de parent rubrique, on passe |
|
| 53 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 54 | - else { |
|
| 55 | - $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
|
| 56 | - $select .= isset($desc['field']['lang'])?", lang":""; |
|
| 57 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 58 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - if ($cache_quete[$connect][$table]['_select']) |
|
| 62 | - $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 63 | - } |
|
| 64 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 46 | + static $cache_quete = array(); |
|
| 47 | + |
|
| 48 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 49 | + if (!isset($cache_quete[$connect][$table]['_select'])){ |
|
| 50 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 51 | + if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | + // pas de parent rubrique, on passe |
|
| 53 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 54 | + else { |
|
| 55 | + $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
|
| 56 | + $select .= isset($desc['field']['lang'])?", lang":""; |
|
| 57 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 58 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + if ($cache_quete[$connect][$table]['_select']) |
|
| 62 | + $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 63 | + } |
|
| 64 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | 79 | function quete_parent($id_rubrique, $connect='') { |
| 80 | - if (!$id_rubrique = intval($id_rubrique)) |
|
| 81 | - return 0; |
|
| 82 | - $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
|
| 83 | - return $id_parent['id_parent']; |
|
| 80 | + if (!$id_rubrique = intval($id_rubrique)) |
|
| 81 | + return 0; |
|
| 82 | + $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
|
| 83 | + return $id_parent['id_parent']; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | 97 | function quete_rubrique($id_article, $serveur) { |
| 98 | - $id_parent = quete_parent_lang('spip_articles',$id_article,$serveur); |
|
| 99 | - return $id_parent['id_rubrique']; |
|
| 98 | + $id_parent = quete_parent_lang('spip_articles',$id_article,$serveur); |
|
| 99 | + return $id_parent['id_rubrique']; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | * @return int |
| 111 | 111 | */ |
| 112 | 112 | function quete_profondeur($id, $connect='') { |
| 113 | - $n = 0; |
|
| 114 | - while ($id) { |
|
| 115 | - $n++; |
|
| 116 | - $id = quete_parent($id, $connect); |
|
| 117 | - } |
|
| 118 | - return $n; |
|
| 113 | + $n = 0; |
|
| 114 | + while ($id) { |
|
| 115 | + $n++; |
|
| 116 | + $id = quete_parent($id, $connect); |
|
| 117 | + } |
|
| 118 | + return $n; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | 128 | function quete_condition_postdates($champ_date, $serveur='', $ignore_previsu=false) { |
| 129 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 130 | - return "1=1"; |
|
| 131 | - return |
|
| 132 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 133 | - AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 134 | - ? "$champ_date<".sql_quote(date('Y-m-d H:i:s',$GLOBALS['meta']['date_prochain_postdate']),$serveur) |
|
| 135 | - : "1=1" ; |
|
| 129 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 130 | + return "1=1"; |
|
| 131 | + return |
|
| 132 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 133 | + AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 134 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s',$GLOBALS['meta']['date_prochain_postdate']),$serveur) |
|
| 135 | + : "1=1" ; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -150,67 +150,67 @@ discard block |
||
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | 152 | function quete_condition_statut($mstatut,$previsu,$publie, $serveur='', $ignore_previsu=false){ |
| 153 | - static $cond = array(); |
|
| 154 | - $key = func_get_args(); |
|
| 155 | - $key = implode("-",$key); |
|
| 156 | - if (isset($cond[$key])) return $cond[$key]; |
|
| 157 | - |
|
| 158 | - $liste = $publie; |
|
| 159 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 160 | - $liste = $previsu; |
|
| 161 | - $not = false; |
|
| 162 | - if (strncmp($liste,'!',1)==0){ |
|
| 163 | - $not = true; |
|
| 164 | - $liste = substr($liste,1); |
|
| 165 | - } |
|
| 166 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 167 | - if (!strlen($liste)) |
|
| 168 | - return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 169 | - |
|
| 170 | - $liste = explode(',',$liste); |
|
| 171 | - $where = array(); |
|
| 172 | - foreach($liste as $k=>$v) { |
|
| 173 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 174 | - // a ceux de l'auteur identifie |
|
| 175 | - if (strpos($v,"/")!==false){ |
|
| 176 | - $v = explode("/",$v); |
|
| 177 | - $filtre = end($v); |
|
| 178 | - $v = reset($v); |
|
| 179 | - $v = preg_replace(",\W,","",$v); |
|
| 180 | - if ($filtre=="auteur" |
|
| 181 | - AND isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 182 | - AND intval($GLOBALS['visiteur_session']['id_auteur']) |
|
| 183 | - AND (strpos($mstatut,".")!==false) |
|
| 184 | - AND $objet = explode(".",$mstatut) |
|
| 185 | - AND $id_table = reset($objet) |
|
| 186 | - AND $objet = objet_type($id_table)){ |
|
| 187 | - $primary = id_table_objet($objet); |
|
| 188 | - $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
|
| 189 | - } |
|
| 190 | - // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 191 | - else |
|
| 192 | - $v = ""; |
|
| 193 | - } |
|
| 194 | - // securite |
|
| 195 | - $liste[$k] = preg_replace(",\W,","",$v); |
|
| 196 | - } |
|
| 197 | - $liste = array_filter($liste); |
|
| 198 | - if (count($liste)==1){ |
|
| 199 | - $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
|
| 200 | - } |
|
| 201 | - else { |
|
| 202 | - $where[] = sql_in($mstatut,$liste,$not,$serveur); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - while (count($where)>1){ |
|
| 206 | - $and = array('AND',array_pop($where),array_pop($where)); |
|
| 207 | - $where[] = $and; |
|
| 208 | - } |
|
| 209 | - $cond[$key] = reset($where); |
|
| 210 | - if ($not) |
|
| 211 | - $cond[$key] = array('NOT',$cond[$key]); |
|
| 212 | - |
|
| 213 | - return $cond[$key]; |
|
| 153 | + static $cond = array(); |
|
| 154 | + $key = func_get_args(); |
|
| 155 | + $key = implode("-",$key); |
|
| 156 | + if (isset($cond[$key])) return $cond[$key]; |
|
| 157 | + |
|
| 158 | + $liste = $publie; |
|
| 159 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 160 | + $liste = $previsu; |
|
| 161 | + $not = false; |
|
| 162 | + if (strncmp($liste,'!',1)==0){ |
|
| 163 | + $not = true; |
|
| 164 | + $liste = substr($liste,1); |
|
| 165 | + } |
|
| 166 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 167 | + if (!strlen($liste)) |
|
| 168 | + return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 169 | + |
|
| 170 | + $liste = explode(',',$liste); |
|
| 171 | + $where = array(); |
|
| 172 | + foreach($liste as $k=>$v) { |
|
| 173 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 174 | + // a ceux de l'auteur identifie |
|
| 175 | + if (strpos($v,"/")!==false){ |
|
| 176 | + $v = explode("/",$v); |
|
| 177 | + $filtre = end($v); |
|
| 178 | + $v = reset($v); |
|
| 179 | + $v = preg_replace(",\W,","",$v); |
|
| 180 | + if ($filtre=="auteur" |
|
| 181 | + AND isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 182 | + AND intval($GLOBALS['visiteur_session']['id_auteur']) |
|
| 183 | + AND (strpos($mstatut,".")!==false) |
|
| 184 | + AND $objet = explode(".",$mstatut) |
|
| 185 | + AND $id_table = reset($objet) |
|
| 186 | + AND $objet = objet_type($id_table)){ |
|
| 187 | + $primary = id_table_objet($objet); |
|
| 188 | + $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
|
| 189 | + } |
|
| 190 | + // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 191 | + else |
|
| 192 | + $v = ""; |
|
| 193 | + } |
|
| 194 | + // securite |
|
| 195 | + $liste[$k] = preg_replace(",\W,","",$v); |
|
| 196 | + } |
|
| 197 | + $liste = array_filter($liste); |
|
| 198 | + if (count($liste)==1){ |
|
| 199 | + $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
|
| 200 | + } |
|
| 201 | + else { |
|
| 202 | + $where[] = sql_in($mstatut,$liste,$not,$serveur); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + while (count($where)>1){ |
|
| 206 | + $and = array('AND',array_pop($where),array_pop($where)); |
|
| 207 | + $where[] = $and; |
|
| 208 | + } |
|
| 209 | + $cond[$key] = reset($where); |
|
| 210 | + if ($not) |
|
| 211 | + $cond[$key] = array('NOT',$cond[$key]); |
|
| 212 | + |
|
| 213 | + return $cond[$key]; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @return array|bool|null |
| 224 | 224 | */ |
| 225 | 225 | function quete_fichier($id_document, $serveur='') { |
| 226 | - return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 226 | + return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @return array|bool |
| 235 | 235 | */ |
| 236 | 236 | function quete_document($id_document, $serveur='') { |
| 237 | - return sql_fetsel('*', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 237 | + return sql_fetsel('*', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * @return array|bool|null |
| 248 | 248 | */ |
| 249 | 249 | function quete_meta($nom, $serveur) { |
| 250 | - return sql_getfetsel("valeur", "spip_meta", "nom=" . sql_quote($nom), |
|
| 251 | - '','','','',$serveur); |
|
| 250 | + return sql_getfetsel("valeur", "spip_meta", "nom=" . sql_quote($nom), |
|
| 251 | + '','','','',$serveur); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -265,38 +265,38 @@ discard block |
||
| 265 | 265 | * @return array|string |
| 266 | 266 | */ |
| 267 | 267 | function quete_logo($type, $onoff, $id, $id_rubrique, $flag) { |
| 268 | - static $chercher_logo; |
|
| 269 | - if (is_null($chercher_logo)) |
|
| 270 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 271 | - $nom = strtolower($onoff); |
|
| 272 | - |
|
| 273 | - while (1) { |
|
| 274 | - $on = $chercher_logo($id, $type, $nom); |
|
| 275 | - if ($on) { |
|
| 276 | - if ($flag) |
|
| 277 | - return "$on[2].$on[3]"; |
|
| 278 | - else { |
|
| 279 | - $taille = @getimagesize($on[0]); |
|
| 280 | - $off = ($onoff != 'ON') ? '' : |
|
| 281 | - $chercher_logo($id, $type, 'off'); |
|
| 282 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 283 | - // qui permet de distinguer le changement de logo |
|
| 284 | - // et placer un expire sur le dossier IMG/ |
|
| 285 | - return array ($on[0].($on[4]?"?$on[4]":""), |
|
| 286 | - ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
|
| 287 | - (!$taille ? '' : (" ".$taille[3]))); |
|
| 288 | - } |
|
| 289 | - } |
|
| 268 | + static $chercher_logo; |
|
| 269 | + if (is_null($chercher_logo)) |
|
| 270 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 271 | + $nom = strtolower($onoff); |
|
| 272 | + |
|
| 273 | + while (1) { |
|
| 274 | + $on = $chercher_logo($id, $type, $nom); |
|
| 275 | + if ($on) { |
|
| 276 | + if ($flag) |
|
| 277 | + return "$on[2].$on[3]"; |
|
| 278 | + else { |
|
| 279 | + $taille = @getimagesize($on[0]); |
|
| 280 | + $off = ($onoff != 'ON') ? '' : |
|
| 281 | + $chercher_logo($id, $type, 'off'); |
|
| 282 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 283 | + // qui permet de distinguer le changement de logo |
|
| 284 | + // et placer un expire sur le dossier IMG/ |
|
| 285 | + return array ($on[0].($on[4]?"?$on[4]":""), |
|
| 286 | + ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
|
| 287 | + (!$taille ? '' : (" ".$taille[3]))); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) |
| 291 | 291 | return ''; |
| 292 | - else if ($id_rubrique) { |
|
| 293 | - $type = 'id_rubrique'; |
|
| 294 | - $id = $id_rubrique; |
|
| 295 | - $id_rubrique = 0; |
|
| 296 | - } else if ($id AND $type == 'id_rubrique') |
|
| 297 | - $id = quete_parent($id); |
|
| 298 | - else return ''; |
|
| 299 | - } |
|
| 292 | + else if ($id_rubrique) { |
|
| 293 | + $type = 'id_rubrique'; |
|
| 294 | + $id = $id_rubrique; |
|
| 295 | + $id_rubrique = 0; |
|
| 296 | + } else if ($id AND $type == 'id_rubrique') |
|
| 297 | + $id = quete_parent($id); |
|
| 298 | + else return ''; |
|
| 299 | + } |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -309,19 +309,19 @@ discard block |
||
| 309 | 309 | * @return bool|string |
| 310 | 310 | */ |
| 311 | 311 | function quete_logo_file($row, $connect=NULL) { |
| 312 | - include_spip('inc/documents'); |
|
| 313 | - $logo = vignette_logo_document($row, $connect); |
|
| 314 | - if (!$logo) $logo = image_du_document($row); |
|
| 315 | - if (!$logo){ |
|
| 316 | - $f = charger_fonction('vignette','inc'); |
|
| 317 | - $logo = $f($row['extension'], false); |
|
| 318 | - } |
|
| 319 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 320 | - if (strcmp($logo,_DIR_PLUGINS)==0 |
|
| 321 | - OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
|
| 322 | - OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 323 | - return $logo; |
|
| 324 | - return get_spip_doc($logo); |
|
| 312 | + include_spip('inc/documents'); |
|
| 313 | + $logo = vignette_logo_document($row, $connect); |
|
| 314 | + if (!$logo) $logo = image_du_document($row); |
|
| 315 | + if (!$logo){ |
|
| 316 | + $f = charger_fonction('vignette','inc'); |
|
| 317 | + $logo = $f($row['extension'], false); |
|
| 318 | + } |
|
| 319 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 320 | + if (strcmp($logo,_DIR_PLUGINS)==0 |
|
| 321 | + OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
|
| 322 | + OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 323 | + return $logo; |
|
| 324 | + return get_spip_doc($logo); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -348,16 +348,16 @@ discard block |
||
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | 350 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect=NULL) { |
| 351 | - include_spip('inc/documents'); |
|
| 352 | - $logo = ''; |
|
| 353 | - if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 354 | - $logo = vignette_logo_document($row, $connect); |
|
| 355 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 356 | - if ($mode_logo == 'vignette' AND !$logo) |
|
| 357 | - return ''; |
|
| 358 | - if ($mode_logo == 'icone') |
|
| 359 | - $row['fichier'] = ''; |
|
| 360 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align); |
|
| 351 | + include_spip('inc/documents'); |
|
| 352 | + $logo = ''; |
|
| 353 | + if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 354 | + $logo = vignette_logo_document($row, $connect); |
|
| 355 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 356 | + if ($mode_logo == 'vignette' AND !$logo) |
|
| 357 | + return ''; |
|
| 358 | + if ($mode_logo == 'icone') |
|
| 359 | + $row['fichier'] = ''; |
|
| 360 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -371,17 +371,17 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | function vignette_logo_document($row, $connect='') |
| 373 | 373 | { |
| 374 | - if (!$row['id_vignette']) return ''; |
|
| 375 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 376 | - if ($connect) { |
|
| 377 | - $site = quete_meta('adresse_site', $connect); |
|
| 378 | - $dir = quete_meta('dir_img', $connect); |
|
| 379 | - return "$site/$dir$fichier"; |
|
| 380 | - } |
|
| 381 | - $f = get_spip_doc($fichier); |
|
| 382 | - if ($f AND @file_exists($f)) return $f; |
|
| 383 | - if ($row['mode'] !== 'vignette') return ''; |
|
| 384 | - return generer_url_entite($row['id_document'], 'document','','', $connect); |
|
| 374 | + if (!$row['id_vignette']) return ''; |
|
| 375 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 376 | + if ($connect) { |
|
| 377 | + $site = quete_meta('adresse_site', $connect); |
|
| 378 | + $dir = quete_meta('dir_img', $connect); |
|
| 379 | + return "$site/$dir$fichier"; |
|
| 380 | + } |
|
| 381 | + $f = get_spip_doc($fichier); |
|
| 382 | + if ($f AND @file_exists($f)) return $f; |
|
| 383 | + if ($row['mode'] !== 'vignette') return ''; |
|
| 384 | + return generer_url_entite($row['id_document'], 'document','','', $connect); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -399,60 +399,60 @@ discard block |
||
| 399 | 399 | * @return bool|string |
| 400 | 400 | */ |
| 401 | 401 | function calcul_exposer ($id, $prim, $reference, $parent, $type, $connect='') { |
| 402 | - static $exposer = array(); |
|
| 403 | - |
|
| 404 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 405 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 406 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 407 | - // en static. |
|
| 408 | - if (!isset($exposer[$m=md5(serialize($reference))][$prim])) { |
|
| 409 | - $principal = isset($reference[$type])?$reference[$type]: |
|
| 410 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 411 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 412 | - (isset($reference["@$type"])?$reference["@$type"]:''); |
|
| 413 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 414 | - // il n'est donc pas utile |
|
| 415 | - $parent = 0; |
|
| 416 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 417 | - $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
|
| 418 | - if (isset($enfants[$type])) |
|
| 419 | - foreach($enfants[$type] as $t) |
|
| 420 | - if (isset($reference[$t]) |
|
| 421 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 422 | - OR isset($reference["@$t"])) { |
|
| 423 | - $type = $t; |
|
| 424 | - $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
|
| 425 | - continue; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - $exposer[$m][$type] = array(); |
|
| 429 | - if ($principal) { |
|
| 430 | - $principaux = is_array($principal)?$principal:array($principal); |
|
| 431 | - foreach($principaux as $principal){ |
|
| 432 | - $exposer[$m][$type][$principal] = true; |
|
| 433 | - if ($type == 'id_mot'){ |
|
| 434 | - if (!$parent) { |
|
| 435 | - $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
|
| 436 | - } |
|
| 437 | - if ($parent) |
|
| 438 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 439 | - } |
|
| 440 | - else if ($type != 'id_groupe') { |
|
| 441 | - if (!$parent) { |
|
| 442 | - if ($type == 'id_rubrique') |
|
| 443 | - $parent = $principal; |
|
| 444 | - if ($type == 'id_article') { |
|
| 445 | - $parent = quete_rubrique($principal,$connect); |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - do { $exposer[$m]['id_rubrique'][$parent] = true; } |
|
| 449 | - while ($parent = quete_parent($parent, $connect)); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - // And the winner is... |
|
| 455 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 402 | + static $exposer = array(); |
|
| 403 | + |
|
| 404 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 405 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 406 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 407 | + // en static. |
|
| 408 | + if (!isset($exposer[$m=md5(serialize($reference))][$prim])) { |
|
| 409 | + $principal = isset($reference[$type])?$reference[$type]: |
|
| 410 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 411 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 412 | + (isset($reference["@$type"])?$reference["@$type"]:''); |
|
| 413 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 414 | + // il n'est donc pas utile |
|
| 415 | + $parent = 0; |
|
| 416 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 417 | + $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
|
| 418 | + if (isset($enfants[$type])) |
|
| 419 | + foreach($enfants[$type] as $t) |
|
| 420 | + if (isset($reference[$t]) |
|
| 421 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 422 | + OR isset($reference["@$t"])) { |
|
| 423 | + $type = $t; |
|
| 424 | + $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
|
| 425 | + continue; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + $exposer[$m][$type] = array(); |
|
| 429 | + if ($principal) { |
|
| 430 | + $principaux = is_array($principal)?$principal:array($principal); |
|
| 431 | + foreach($principaux as $principal){ |
|
| 432 | + $exposer[$m][$type][$principal] = true; |
|
| 433 | + if ($type == 'id_mot'){ |
|
| 434 | + if (!$parent) { |
|
| 435 | + $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
|
| 436 | + } |
|
| 437 | + if ($parent) |
|
| 438 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 439 | + } |
|
| 440 | + else if ($type != 'id_groupe') { |
|
| 441 | + if (!$parent) { |
|
| 442 | + if ($type == 'id_rubrique') |
|
| 443 | + $parent = $principal; |
|
| 444 | + if ($type == 'id_article') { |
|
| 445 | + $parent = quete_rubrique($principal,$connect); |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + do { $exposer[$m]['id_rubrique'][$parent] = true; } |
|
| 449 | + while ($parent = quete_parent($parent, $connect)); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + // And the winner is... |
|
| 455 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -467,20 +467,20 @@ discard block |
||
| 467 | 467 | * @return int |
| 468 | 468 | */ |
| 469 | 469 | function quete_debut_pagination($primary,$valeur,$pas,$iter){ |
| 470 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 471 | - // ou composee, mais verifions |
|
| 472 | - if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 473 | - return 0; |
|
| 474 | - |
|
| 475 | - $pos = 0; |
|
| 476 | - while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
|
| 477 | - $pos++; |
|
| 478 | - } |
|
| 479 | - // si on a pas trouve |
|
| 480 | - if ($row[$primary]!=$valeur) |
|
| 481 | - return 0; |
|
| 482 | - |
|
| 483 | - // sinon, calculer le bon numero de page |
|
| 484 | - return floor($pos/$pas)*$pas; |
|
| 470 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 471 | + // ou composee, mais verifions |
|
| 472 | + if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 473 | + return 0; |
|
| 474 | + |
|
| 475 | + $pos = 0; |
|
| 476 | + while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
|
| 477 | + $pos++; |
|
| 478 | + } |
|
| 479 | + // si on a pas trouve |
|
| 480 | + if ($row[$primary]!=$valeur) |
|
| 481 | + return 0; |
|
| 482 | + |
|
| 483 | + // sinon, calculer le bon numero de page |
|
| 484 | + return floor($pos/$pas)*$pas; |
|
| 485 | 485 | } |
| 486 | 486 | ?> |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return array|bool|null |
| 30 | 30 | */ |
| 31 | 31 | function quete_virtuel($id_article, $connect) { |
| 32 | - return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '','','','',$connect); |
|
| 32 | + return sql_getfetsel('virtuel', 'spip_articles', array("id_article=".intval($id_article), "statut='publie'"), '', '', '', '', $connect); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -42,24 +42,24 @@ discard block |
||
| 42 | 42 | * @param string $connect |
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | -function quete_parent_lang($table,$id,$connect=''){ |
|
| 45 | +function quete_parent_lang($table, $id, $connect = '') { |
|
| 46 | 46 | static $cache_quete = array(); |
| 47 | 47 | |
| 48 | 48 | if (!isset($cache_quete[$connect][$table][$id])) { |
| 49 | - if (!isset($cache_quete[$connect][$table]['_select'])){ |
|
| 50 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 51 | - if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 49 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 50 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | + if (!$desc = $trouver_table($table, $connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | 52 | // pas de parent rubrique, on passe |
| 53 | 53 | $cache_quete[$connect][$table]['_select'] = false; |
| 54 | 54 | else { |
| 55 | - $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
|
| 56 | - $select .= isset($desc['field']['lang'])?", lang":""; |
|
| 55 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 56 | + $select .= isset($desc['field']['lang']) ? ", lang" : ""; |
|
| 57 | 57 | $cache_quete[$connect][$table]['_select'] = $select; |
| 58 | 58 | $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | if ($cache_quete[$connect][$table]['_select']) |
| 62 | - $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 62 | + $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table, $cache_quete[$connect][$table]['_id']."=".intval($id), '', '', '', '', $connect); |
|
| 63 | 63 | } |
| 64 | 64 | return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
| 65 | 65 | } |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | * @param string $connect |
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | -function quete_parent($id_rubrique, $connect='') { |
|
| 79 | +function quete_parent($id_rubrique, $connect = '') { |
|
| 80 | 80 | if (!$id_rubrique = intval($id_rubrique)) |
| 81 | 81 | return 0; |
| 82 | - $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
|
| 82 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 83 | 83 | return $id_parent['id_parent']; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | 97 | function quete_rubrique($id_article, $serveur) { |
| 98 | - $id_parent = quete_parent_lang('spip_articles',$id_article,$serveur); |
|
| 98 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 99 | 99 | return $id_parent['id_rubrique']; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param string $connect |
| 110 | 110 | * @return int |
| 111 | 111 | */ |
| 112 | -function quete_profondeur($id, $connect='') { |
|
| 112 | +function quete_profondeur($id, $connect = '') { |
|
| 113 | 113 | $n = 0; |
| 114 | 114 | while ($id) { |
| 115 | 115 | $n++; |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | * @param string $serveur |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | -function quete_condition_postdates($champ_date, $serveur='', $ignore_previsu=false) { |
|
| 128 | +function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
|
| 129 | 129 | if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
| 130 | 130 | return "1=1"; |
| 131 | 131 | return |
| 132 | 132 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 133 | 133 | AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 134 | - ? "$champ_date<".sql_quote(date('Y-m-d H:i:s',$GLOBALS['meta']['date_prochain_postdate']),$serveur) |
|
| 135 | - : "1=1" ; |
|
| 134 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 135 | + : "1=1"; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -149,66 +149,66 @@ discard block |
||
| 149 | 149 | * serveur de BDD |
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | -function quete_condition_statut($mstatut,$previsu,$publie, $serveur='', $ignore_previsu=false){ |
|
| 152 | +function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
|
| 153 | 153 | static $cond = array(); |
| 154 | 154 | $key = func_get_args(); |
| 155 | - $key = implode("-",$key); |
|
| 155 | + $key = implode("-", $key); |
|
| 156 | 156 | if (isset($cond[$key])) return $cond[$key]; |
| 157 | 157 | |
| 158 | 158 | $liste = $publie; |
| 159 | 159 | if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
| 160 | 160 | $liste = $previsu; |
| 161 | 161 | $not = false; |
| 162 | - if (strncmp($liste,'!',1)==0){ |
|
| 162 | + if (strncmp($liste, '!', 1) == 0) { |
|
| 163 | 163 | $not = true; |
| 164 | - $liste = substr($liste,1); |
|
| 164 | + $liste = substr($liste, 1); |
|
| 165 | 165 | } |
| 166 | 166 | // '' => ne rien afficher, '!'=> ne rien filtrer |
| 167 | 167 | if (!strlen($liste)) |
| 168 | - return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 168 | + return $cond[$key] = ($not ? "1=1" : "'0=1'"); |
|
| 169 | 169 | |
| 170 | - $liste = explode(',',$liste); |
|
| 170 | + $liste = explode(',', $liste); |
|
| 171 | 171 | $where = array(); |
| 172 | - foreach($liste as $k=>$v) { |
|
| 172 | + foreach ($liste as $k=>$v) { |
|
| 173 | 173 | // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
| 174 | 174 | // a ceux de l'auteur identifie |
| 175 | - if (strpos($v,"/")!==false){ |
|
| 176 | - $v = explode("/",$v); |
|
| 175 | + if (strpos($v, "/") !== false) { |
|
| 176 | + $v = explode("/", $v); |
|
| 177 | 177 | $filtre = end($v); |
| 178 | 178 | $v = reset($v); |
| 179 | - $v = preg_replace(",\W,","",$v); |
|
| 180 | - if ($filtre=="auteur" |
|
| 179 | + $v = preg_replace(",\W,", "", $v); |
|
| 180 | + if ($filtre == "auteur" |
|
| 181 | 181 | AND isset($GLOBALS['visiteur_session']['id_auteur']) |
| 182 | 182 | AND intval($GLOBALS['visiteur_session']['id_auteur']) |
| 183 | - AND (strpos($mstatut,".")!==false) |
|
| 184 | - AND $objet = explode(".",$mstatut) |
|
| 183 | + AND (strpos($mstatut, ".") !== false) |
|
| 184 | + AND $objet = explode(".", $mstatut) |
|
| 185 | 185 | AND $id_table = reset($objet) |
| 186 | - AND $objet = objet_type($id_table)){ |
|
| 186 | + AND $objet = objet_type($id_table)) { |
|
| 187 | 187 | $primary = id_table_objet($objet); |
| 188 | - $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
|
| 188 | + $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet", "spip_auteurs_liens AS ssss", "ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']), '', '', '', '', $serveur)."))"; |
|
| 189 | 189 | } |
| 190 | 190 | // ignorer ce statut si on ne sait pas comment le filtrer |
| 191 | 191 | else |
| 192 | 192 | $v = ""; |
| 193 | 193 | } |
| 194 | 194 | // securite |
| 195 | - $liste[$k] = preg_replace(",\W,","",$v); |
|
| 195 | + $liste[$k] = preg_replace(",\W,", "", $v); |
|
| 196 | 196 | } |
| 197 | 197 | $liste = array_filter($liste); |
| 198 | - if (count($liste)==1){ |
|
| 199 | - $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
|
| 198 | + if (count($liste) == 1) { |
|
| 199 | + $where[] = array('=', $mstatut, sql_quote(reset($liste), $serveur)); |
|
| 200 | 200 | } |
| 201 | 201 | else { |
| 202 | - $where[] = sql_in($mstatut,$liste,$not,$serveur); |
|
| 202 | + $where[] = sql_in($mstatut, $liste, $not, $serveur); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - while (count($where)>1){ |
|
| 206 | - $and = array('AND',array_pop($where),array_pop($where)); |
|
| 205 | + while (count($where) > 1) { |
|
| 206 | + $and = array('AND', array_pop($where), array_pop($where)); |
|
| 207 | 207 | $where[] = $and; |
| 208 | 208 | } |
| 209 | 209 | $cond[$key] = reset($where); |
| 210 | 210 | if ($not) |
| 211 | - $cond[$key] = array('NOT',$cond[$key]); |
|
| 211 | + $cond[$key] = array('NOT', $cond[$key]); |
|
| 212 | 212 | |
| 213 | 213 | return $cond[$key]; |
| 214 | 214 | } |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | * @param string $serveur |
| 223 | 223 | * @return array|bool|null |
| 224 | 224 | */ |
| 225 | -function quete_fichier($id_document, $serveur='') { |
|
| 226 | - return sql_getfetsel('fichier', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 225 | +function quete_fichier($id_document, $serveur = '') { |
|
| 226 | + return sql_getfetsel('fichier', 'spip_documents', ("id_document=".intval($id_document)), '', array(), '', '', $serveur); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param string $serveur |
| 234 | 234 | * @return array|bool |
| 235 | 235 | */ |
| 236 | -function quete_document($id_document, $serveur='') { |
|
| 237 | - return sql_fetsel('*', 'spip_documents', ("id_document=" . intval($id_document)), '',array(), '', '', $serveur); |
|
| 236 | +function quete_document($id_document, $serveur = '') { |
|
| 237 | + return sql_fetsel('*', 'spip_documents', ("id_document=".intval($id_document)), '', array(), '', '', $serveur); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * @return array|bool|null |
| 248 | 248 | */ |
| 249 | 249 | function quete_meta($nom, $serveur) { |
| 250 | - return sql_getfetsel("valeur", "spip_meta", "nom=" . sql_quote($nom), |
|
| 251 | - '','','','',$serveur); |
|
| 250 | + return sql_getfetsel("valeur", "spip_meta", "nom=".sql_quote($nom), |
|
| 251 | + '', '', '', '', $serveur); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -277,13 +277,12 @@ discard block |
||
| 277 | 277 | return "$on[2].$on[3]"; |
| 278 | 278 | else { |
| 279 | 279 | $taille = @getimagesize($on[0]); |
| 280 | - $off = ($onoff != 'ON') ? '' : |
|
| 281 | - $chercher_logo($id, $type, 'off'); |
|
| 280 | + $off = ($onoff != 'ON') ? '' : $chercher_logo($id, $type, 'off'); |
|
| 282 | 281 | // on retourne une url du type IMG/artonXX?timestamp |
| 283 | 282 | // qui permet de distinguer le changement de logo |
| 284 | 283 | // et placer un expire sur le dossier IMG/ |
| 285 | - return array ($on[0].($on[4]?"?$on[4]":""), |
|
| 286 | - ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
|
| 284 | + return array($on[0].($on[4] ? "?$on[4]" : ""), |
|
| 285 | + ($off ? $off[0].($off[4] ? "?$off[4]" : "") : ''), |
|
| 287 | 286 | (!$taille ? '' : (" ".$taille[3]))); |
| 288 | 287 | } |
| 289 | 288 | } |
@@ -308,18 +307,18 @@ discard block |
||
| 308 | 307 | * @param string $connect |
| 309 | 308 | * @return bool|string |
| 310 | 309 | */ |
| 311 | -function quete_logo_file($row, $connect=NULL) { |
|
| 310 | +function quete_logo_file($row, $connect = NULL) { |
|
| 312 | 311 | include_spip('inc/documents'); |
| 313 | 312 | $logo = vignette_logo_document($row, $connect); |
| 314 | 313 | if (!$logo) $logo = image_du_document($row); |
| 315 | - if (!$logo){ |
|
| 316 | - $f = charger_fonction('vignette','inc'); |
|
| 314 | + if (!$logo) { |
|
| 315 | + $f = charger_fonction('vignette', 'inc'); |
|
| 317 | 316 | $logo = $f($row['extension'], false); |
| 318 | 317 | } |
| 319 | 318 | // si c'est une vignette type doc, la renvoyer direct |
| 320 | - if (strcmp($logo,_DIR_PLUGINS)==0 |
|
| 321 | - OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
|
| 322 | - OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 319 | + if (strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 320 | + OR strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 321 | + OR strcmp($logo, _DIR_RACINE.'prive/') == 0) |
|
| 323 | 322 | return $logo; |
| 324 | 323 | return get_spip_doc($logo); |
| 325 | 324 | } |
@@ -347,10 +346,10 @@ discard block |
||
| 347 | 346 | * serveur |
| 348 | 347 | * @return string |
| 349 | 348 | */ |
| 350 | -function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect=NULL) { |
|
| 349 | +function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = NULL) { |
|
| 351 | 350 | include_spip('inc/documents'); |
| 352 | 351 | $logo = ''; |
| 353 | - if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 352 | + if (!in_array($mode_logo, array('icone', 'apercu'))) |
|
| 354 | 353 | $logo = vignette_logo_document($row, $connect); |
| 355 | 354 | // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
| 356 | 355 | if ($mode_logo == 'vignette' AND !$logo) |
@@ -369,7 +368,7 @@ discard block |
||
| 369 | 368 | * @param string $connect |
| 370 | 369 | * @return string |
| 371 | 370 | */ |
| 372 | -function vignette_logo_document($row, $connect='') |
|
| 371 | +function vignette_logo_document($row, $connect = '') |
|
| 373 | 372 | { |
| 374 | 373 | if (!$row['id_vignette']) return ''; |
| 375 | 374 | $fichier = quete_fichier($row['id_vignette'], $connect); |
@@ -381,7 +380,7 @@ discard block |
||
| 381 | 380 | $f = get_spip_doc($fichier); |
| 382 | 381 | if ($f AND @file_exists($f)) return $f; |
| 383 | 382 | if ($row['mode'] !== 'vignette') return ''; |
| 384 | - return generer_url_entite($row['id_document'], 'document','','', $connect); |
|
| 383 | + return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 385 | 384 | } |
| 386 | 385 | |
| 387 | 386 | /** |
@@ -398,41 +397,40 @@ discard block |
||
| 398 | 397 | * @param string $connect |
| 399 | 398 | * @return bool|string |
| 400 | 399 | */ |
| 401 | -function calcul_exposer ($id, $prim, $reference, $parent, $type, $connect='') { |
|
| 400 | +function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') { |
|
| 402 | 401 | static $exposer = array(); |
| 403 | 402 | |
| 404 | 403 | // Que faut-il exposer ? Tous les elements de $reference |
| 405 | 404 | // ainsi que leur hierarchie ; on ne fait donc ce calcul |
| 406 | 405 | // qu'une fois (par squelette) et on conserve le resultat |
| 407 | 406 | // en static. |
| 408 | - if (!isset($exposer[$m=md5(serialize($reference))][$prim])) { |
|
| 409 | - $principal = isset($reference[$type])?$reference[$type]: |
|
| 410 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 407 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 408 | + $principal = isset($reference[$type]) ? $reference[$type] : // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 411 | 409 | // et donne la reference dynamique @type=xx dans le contexte |
| 412 | - (isset($reference["@$type"])?$reference["@$type"]:''); |
|
| 410 | + (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 413 | 411 | // le parent fournit en argument est le parent de $id, pas celui de $principal |
| 414 | 412 | // il n'est donc pas utile |
| 415 | 413 | $parent = 0; |
| 416 | 414 | if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
| 417 | - $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
|
| 415 | + $enfants = array('id_rubrique'=>array('id_article'), 'id_groupe'=>array('id_mot')); |
|
| 418 | 416 | if (isset($enfants[$type])) |
| 419 | - foreach($enfants[$type] as $t) |
|
| 417 | + foreach ($enfants[$type] as $t) |
|
| 420 | 418 | if (isset($reference[$t]) |
| 421 | 419 | // cas de la reference donnee dynamiquement par la pagination |
| 422 | 420 | OR isset($reference["@$t"])) { |
| 423 | 421 | $type = $t; |
| 424 | - $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
|
| 422 | + $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 425 | 423 | continue; |
| 426 | 424 | } |
| 427 | 425 | } |
| 428 | 426 | $exposer[$m][$type] = array(); |
| 429 | 427 | if ($principal) { |
| 430 | - $principaux = is_array($principal)?$principal:array($principal); |
|
| 431 | - foreach($principaux as $principal){ |
|
| 428 | + $principaux = is_array($principal) ? $principal : array($principal); |
|
| 429 | + foreach ($principaux as $principal) { |
|
| 432 | 430 | $exposer[$m][$type][$principal] = true; |
| 433 | - if ($type == 'id_mot'){ |
|
| 431 | + if ($type == 'id_mot') { |
|
| 434 | 432 | if (!$parent) { |
| 435 | - $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
|
| 433 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', "id_mot=".intval($principal), '', '', '', '', $connect); |
|
| 436 | 434 | } |
| 437 | 435 | if ($parent) |
| 438 | 436 | $exposer[$m]['id_groupe'][$parent] = true; |
@@ -442,7 +440,7 @@ discard block |
||
| 442 | 440 | if ($type == 'id_rubrique') |
| 443 | 441 | $parent = $principal; |
| 444 | 442 | if ($type == 'id_article') { |
| 445 | - $parent = quete_rubrique($principal,$connect); |
|
| 443 | + $parent = quete_rubrique($principal, $connect); |
|
| 446 | 444 | } |
| 447 | 445 | } |
| 448 | 446 | do { $exposer[$m]['id_rubrique'][$parent] = true; } |
@@ -466,21 +464,21 @@ discard block |
||
| 466 | 464 | * @param objetc $iter |
| 467 | 465 | * @return int |
| 468 | 466 | */ |
| 469 | -function quete_debut_pagination($primary,$valeur,$pas,$iter){ |
|
| 467 | +function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
|
| 470 | 468 | // on ne devrait pas arriver ici si la cle primaire est inexistante |
| 471 | 469 | // ou composee, mais verifions |
| 472 | - if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 470 | + if (!$primary OR preg_match('/[,\s]/', $primary)) |
|
| 473 | 471 | return 0; |
| 474 | 472 | |
| 475 | 473 | $pos = 0; |
| 476 | - while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
|
| 474 | + while ($row = $iter->fetch() AND $row[$primary] != $valeur) { |
|
| 477 | 475 | $pos++; |
| 478 | 476 | } |
| 479 | 477 | // si on a pas trouve |
| 480 | - if ($row[$primary]!=$valeur) |
|
| 478 | + if ($row[$primary] != $valeur) |
|
| 481 | 479 | return 0; |
| 482 | 480 | |
| 483 | 481 | // sinon, calculer le bon numero de page |
| 484 | - return floor($pos/$pas)*$pas; |
|
| 482 | + return floor($pos / $pas) * $pas; |
|
| 485 | 483 | } |
| 486 | 484 | ?> |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // |
| 16 | 18 | // Fonctions d'appel aux serveurs SQL presentes dans le code compile |
@@ -48,18 +50,19 @@ discard block |
||
| 48 | 50 | if (!isset($cache_quete[$connect][$table][$id])) { |
| 49 | 51 | if (!isset($cache_quete[$connect][$table]['_select'])){ |
| 50 | 52 | $trouver_table = charger_fonction('trouver_table','base'); |
| 51 | - if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) |
|
| 52 | - // pas de parent rubrique, on passe |
|
| 53 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 54 | - else { |
|
| 53 | + if (!$desc=$trouver_table($table,$connect) OR !isset($desc['field']['id_rubrique'])) { |
|
| 54 | + // pas de parent rubrique, on passe |
|
| 55 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 56 | + } else { |
|
| 55 | 57 | $select = ($table=='spip_rubriques'?'id_parent':'id_rubrique'); |
| 56 | 58 | $select .= isset($desc['field']['lang'])?", lang":""; |
| 57 | 59 | $cache_quete[$connect][$table]['_select'] = $select; |
| 58 | 60 | $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
| 59 | 61 | } |
| 60 | 62 | } |
| 61 | - if ($cache_quete[$connect][$table]['_select']) |
|
| 62 | - $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 63 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 64 | + $cache_quete[$connect][$table][$id] = sql_fetsel($cache_quete[$connect][$table]['_select'], $table,$cache_quete[$connect][$table]['_id']."=".intval($id),'','','','',$connect); |
|
| 65 | + } |
|
| 63 | 66 | } |
| 64 | 67 | return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
| 65 | 68 | } |
@@ -77,8 +80,9 @@ discard block |
||
| 77 | 80 | * @return int |
| 78 | 81 | */ |
| 79 | 82 | function quete_parent($id_rubrique, $connect='') { |
| 80 | - if (!$id_rubrique = intval($id_rubrique)) |
|
| 81 | - return 0; |
|
| 83 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 84 | + return 0; |
|
| 85 | + } |
|
| 82 | 86 | $id_parent = quete_parent_lang('spip_rubriques',$id_rubrique,$connect); |
| 83 | 87 | return $id_parent['id_parent']; |
| 84 | 88 | } |
@@ -126,8 +130,9 @@ discard block |
||
| 126 | 130 | * @return string |
| 127 | 131 | */ |
| 128 | 132 | function quete_condition_postdates($champ_date, $serveur='', $ignore_previsu=false) { |
| 129 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 130 | - return "1=1"; |
|
| 133 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) { |
|
| 134 | + return "1=1"; |
|
| 135 | + } |
|
| 131 | 136 | return |
| 132 | 137 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 133 | 138 | AND $GLOBALS['meta']['date_prochain_postdate'] > time()) |
@@ -153,19 +158,23 @@ discard block |
||
| 153 | 158 | static $cond = array(); |
| 154 | 159 | $key = func_get_args(); |
| 155 | 160 | $key = implode("-",$key); |
| 156 | - if (isset($cond[$key])) return $cond[$key]; |
|
| 161 | + if (isset($cond[$key])) { |
|
| 162 | + return $cond[$key]; |
|
| 163 | + } |
|
| 157 | 164 | |
| 158 | 165 | $liste = $publie; |
| 159 | - if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) |
|
| 160 | - $liste = $previsu; |
|
| 166 | + if (defined('_VAR_PREVIEW') AND _VAR_PREVIEW AND !$ignore_previsu) { |
|
| 167 | + $liste = $previsu; |
|
| 168 | + } |
|
| 161 | 169 | $not = false; |
| 162 | 170 | if (strncmp($liste,'!',1)==0){ |
| 163 | 171 | $not = true; |
| 164 | 172 | $liste = substr($liste,1); |
| 165 | 173 | } |
| 166 | 174 | // '' => ne rien afficher, '!'=> ne rien filtrer |
| 167 | - if (!strlen($liste)) |
|
| 168 | - return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 175 | + if (!strlen($liste)) { |
|
| 176 | + return $cond[$key]=($not?"1=1":"'0=1'"); |
|
| 177 | + } |
|
| 169 | 178 | |
| 170 | 179 | $liste = explode(',',$liste); |
| 171 | 180 | $where = array(); |
@@ -188,8 +197,9 @@ discard block |
||
| 188 | 197 | $where[] = "($mstatut<>".sql_quote($v)." OR $id_table.$primary IN (".sql_get_select("ssss.id_objet","spip_auteurs_liens AS ssss","ssss.objet=".sql_quote($objet)." AND ssss.id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']),'','','','',$serveur)."))"; |
| 189 | 198 | } |
| 190 | 199 | // ignorer ce statut si on ne sait pas comment le filtrer |
| 191 | - else |
|
| 192 | - $v = ""; |
|
| 200 | + else { |
|
| 201 | + $v = ""; |
|
| 202 | + } |
|
| 193 | 203 | } |
| 194 | 204 | // securite |
| 195 | 205 | $liste[$k] = preg_replace(",\W,","",$v); |
@@ -197,8 +207,7 @@ discard block |
||
| 197 | 207 | $liste = array_filter($liste); |
| 198 | 208 | if (count($liste)==1){ |
| 199 | 209 | $where[] = array('=', $mstatut, sql_quote(reset($liste),$serveur)); |
| 200 | - } |
|
| 201 | - else { |
|
| 210 | + } else { |
|
| 202 | 211 | $where[] = sql_in($mstatut,$liste,$not,$serveur); |
| 203 | 212 | } |
| 204 | 213 | |
@@ -207,8 +216,9 @@ discard block |
||
| 207 | 216 | $where[] = $and; |
| 208 | 217 | } |
| 209 | 218 | $cond[$key] = reset($where); |
| 210 | - if ($not) |
|
| 211 | - $cond[$key] = array('NOT',$cond[$key]); |
|
| 219 | + if ($not) { |
|
| 220 | + $cond[$key] = array('NOT',$cond[$key]); |
|
| 221 | + } |
|
| 212 | 222 | |
| 213 | 223 | return $cond[$key]; |
| 214 | 224 | } |
@@ -266,16 +276,17 @@ discard block |
||
| 266 | 276 | */ |
| 267 | 277 | function quete_logo($type, $onoff, $id, $id_rubrique, $flag) { |
| 268 | 278 | static $chercher_logo; |
| 269 | - if (is_null($chercher_logo)) |
|
| 270 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 279 | + if (is_null($chercher_logo)) { |
|
| 280 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 281 | + } |
|
| 271 | 282 | $nom = strtolower($onoff); |
| 272 | 283 | |
| 273 | 284 | while (1) { |
| 274 | 285 | $on = $chercher_logo($id, $type, $nom); |
| 275 | 286 | if ($on) { |
| 276 | - if ($flag) |
|
| 277 | - return "$on[2].$on[3]"; |
|
| 278 | - else { |
|
| 287 | + if ($flag) { |
|
| 288 | + return "$on[2].$on[3]"; |
|
| 289 | + } else { |
|
| 279 | 290 | $taille = @getimagesize($on[0]); |
| 280 | 291 | $off = ($onoff != 'ON') ? '' : |
| 281 | 292 | $chercher_logo($id, $type, 'off'); |
@@ -286,16 +297,17 @@ discard block |
||
| 286 | 297 | ($off ? $off[0] . ($off[4]?"?$off[4]":"") : ''), |
| 287 | 298 | (!$taille ? '' : (" ".$taille[3]))); |
| 288 | 299 | } |
| 289 | - } |
|
| 290 | - else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) |
|
| 291 | - return ''; |
|
| 292 | - else if ($id_rubrique) { |
|
| 300 | + } else if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 301 | + return ''; |
|
| 302 | + } else if ($id_rubrique) { |
|
| 293 | 303 | $type = 'id_rubrique'; |
| 294 | 304 | $id = $id_rubrique; |
| 295 | 305 | $id_rubrique = 0; |
| 296 | - } else if ($id AND $type == 'id_rubrique') |
|
| 297 | - $id = quete_parent($id); |
|
| 298 | - else return ''; |
|
| 306 | + } else if ($id AND $type == 'id_rubrique') { |
|
| 307 | + $id = quete_parent($id); |
|
| 308 | + } else { |
|
| 309 | + return ''; |
|
| 310 | + } |
|
| 299 | 311 | } |
| 300 | 312 | } |
| 301 | 313 | |
@@ -311,7 +323,9 @@ discard block |
||
| 311 | 323 | function quete_logo_file($row, $connect=NULL) { |
| 312 | 324 | include_spip('inc/documents'); |
| 313 | 325 | $logo = vignette_logo_document($row, $connect); |
| 314 | - if (!$logo) $logo = image_du_document($row); |
|
| 326 | + if (!$logo) { |
|
| 327 | + $logo = image_du_document($row); |
|
| 328 | + } |
|
| 315 | 329 | if (!$logo){ |
| 316 | 330 | $f = charger_fonction('vignette','inc'); |
| 317 | 331 | $logo = $f($row['extension'], false); |
@@ -319,8 +333,9 @@ discard block |
||
| 319 | 333 | // si c'est une vignette type doc, la renvoyer direct |
| 320 | 334 | if (strcmp($logo,_DIR_PLUGINS)==0 |
| 321 | 335 | OR strcmp($logo,_DIR_PLUGINS_DIST)==0 |
| 322 | - OR strcmp($logo,_DIR_RACINE.'prive/')==0) |
|
| 323 | - return $logo; |
|
| 336 | + OR strcmp($logo,_DIR_RACINE.'prive/')==0) { |
|
| 337 | + return $logo; |
|
| 338 | + } |
|
| 324 | 339 | return get_spip_doc($logo); |
| 325 | 340 | } |
| 326 | 341 | |
@@ -350,13 +365,16 @@ discard block |
||
| 350 | 365 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect=NULL) { |
| 351 | 366 | include_spip('inc/documents'); |
| 352 | 367 | $logo = ''; |
| 353 | - if (!in_array($mode_logo,array('icone','apercu'))) |
|
| 354 | - $logo = vignette_logo_document($row, $connect); |
|
| 368 | + if (!in_array($mode_logo,array('icone','apercu'))) { |
|
| 369 | + $logo = vignette_logo_document($row, $connect); |
|
| 370 | + } |
|
| 355 | 371 | // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
| 356 | - if ($mode_logo == 'vignette' AND !$logo) |
|
| 357 | - return ''; |
|
| 358 | - if ($mode_logo == 'icone') |
|
| 359 | - $row['fichier'] = ''; |
|
| 372 | + if ($mode_logo == 'vignette' AND !$logo) { |
|
| 373 | + return ''; |
|
| 374 | + } |
|
| 375 | + if ($mode_logo == 'icone') { |
|
| 376 | + $row['fichier'] = ''; |
|
| 377 | + } |
|
| 360 | 378 | return vignette_automatique($logo, $row, $lien, $x, $y, $align); |
| 361 | 379 | } |
| 362 | 380 | |
@@ -371,7 +389,9 @@ discard block |
||
| 371 | 389 | */ |
| 372 | 390 | function vignette_logo_document($row, $connect='') |
| 373 | 391 | { |
| 374 | - if (!$row['id_vignette']) return ''; |
|
| 392 | + if (!$row['id_vignette']) { |
|
| 393 | + return ''; |
|
| 394 | + } |
|
| 375 | 395 | $fichier = quete_fichier($row['id_vignette'], $connect); |
| 376 | 396 | if ($connect) { |
| 377 | 397 | $site = quete_meta('adresse_site', $connect); |
@@ -379,8 +399,12 @@ discard block |
||
| 379 | 399 | return "$site/$dir$fichier"; |
| 380 | 400 | } |
| 381 | 401 | $f = get_spip_doc($fichier); |
| 382 | - if ($f AND @file_exists($f)) return $f; |
|
| 383 | - if ($row['mode'] !== 'vignette') return ''; |
|
| 402 | + if ($f AND @file_exists($f)) { |
|
| 403 | + return $f; |
|
| 404 | + } |
|
| 405 | + if ($row['mode'] !== 'vignette') { |
|
| 406 | + return ''; |
|
| 407 | + } |
|
| 384 | 408 | return generer_url_entite($row['id_document'], 'document','','', $connect); |
| 385 | 409 | } |
| 386 | 410 | |
@@ -415,12 +439,13 @@ discard block |
||
| 415 | 439 | $parent = 0; |
| 416 | 440 | if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
| 417 | 441 | $enfants = array('id_rubrique'=>array('id_article'),'id_groupe'=>array('id_mot')); |
| 418 | - if (isset($enfants[$type])) |
|
| 419 | - foreach($enfants[$type] as $t) |
|
| 442 | + if (isset($enfants[$type])) { |
|
| 443 | + foreach($enfants[$type] as $t) |
|
| 420 | 444 | if (isset($reference[$t]) |
| 421 | 445 | // cas de la reference donnee dynamiquement par la pagination |
| 422 | 446 | OR isset($reference["@$t"])) { |
| 423 | 447 | $type = $t; |
| 448 | + } |
|
| 424 | 449 | $principal = isset($reference[$type])?$reference[$type]:$reference["@$type"]; |
| 425 | 450 | continue; |
| 426 | 451 | } |
@@ -434,13 +459,14 @@ discard block |
||
| 434 | 459 | if (!$parent) { |
| 435 | 460 | $parent = sql_getfetsel('id_groupe','spip_mots',"id_mot=" . intval($principal), '','','','',$connect); |
| 436 | 461 | } |
| 437 | - if ($parent) |
|
| 438 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 439 | - } |
|
| 440 | - else if ($type != 'id_groupe') { |
|
| 462 | + if ($parent) { |
|
| 463 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 464 | + } |
|
| 465 | + } else if ($type != 'id_groupe') { |
|
| 441 | 466 | if (!$parent) { |
| 442 | - if ($type == 'id_rubrique') |
|
| 443 | - $parent = $principal; |
|
| 467 | + if ($type == 'id_rubrique') { |
|
| 468 | + $parent = $principal; |
|
| 469 | + } |
|
| 444 | 470 | if ($type == 'id_article') { |
| 445 | 471 | $parent = quete_rubrique($principal,$connect); |
| 446 | 472 | } |
@@ -469,16 +495,18 @@ discard block |
||
| 469 | 495 | function quete_debut_pagination($primary,$valeur,$pas,$iter){ |
| 470 | 496 | // on ne devrait pas arriver ici si la cle primaire est inexistante |
| 471 | 497 | // ou composee, mais verifions |
| 472 | - if (!$primary OR preg_match('/[,\s]/',$primary)) |
|
| 473 | - return 0; |
|
| 498 | + if (!$primary OR preg_match('/[,\s]/',$primary)) { |
|
| 499 | + return 0; |
|
| 500 | + } |
|
| 474 | 501 | |
| 475 | 502 | $pos = 0; |
| 476 | 503 | while ($row = $iter->fetch() AND $row[$primary]!=$valeur){ |
| 477 | 504 | $pos++; |
| 478 | 505 | } |
| 479 | 506 | // si on a pas trouve |
| 480 | - if ($row[$primary]!=$valeur) |
|
| 481 | - return 0; |
|
| 507 | + if ($row[$primary]!=$valeur) { |
|
| 508 | + return 0; |
|
| 509 | + } |
|
| 482 | 510 | |
| 483 | 511 | // sinon, calculer le bon numero de page |
| 484 | 512 | return floor($pos/$pas)*$pas; |
@@ -21,6 +21,9 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | // http://doc.spip.org/@_sqlite_init_functions |
| 24 | +/** |
|
| 25 | + * @param PDO $sqlite |
|
| 26 | + */ |
|
| 24 | 27 | function _sqlite_init_functions(&$sqlite){ |
| 25 | 28 | |
| 26 | 29 | if (!$sqlite) return false; |
@@ -89,6 +92,9 @@ discard block |
||
| 89 | 92 | |
| 90 | 93 | // permet au besoin de charger des fonctions ailleurs par _sqlite_init_functions(); |
| 91 | 94 | // http://doc.spip.org/@_sqlite_add_function |
| 95 | +/** |
|
| 96 | + * @param string $f |
|
| 97 | + */ |
|
| 92 | 98 | function _sqlite_add_function(&$sqlite, &$f, &$r){ |
| 93 | 99 | if (_sqlite_is_version(3, $sqlite)){ |
| 94 | 100 | isset($r[1]) |
@@ -23,82 +23,82 @@ discard block |
||
| 23 | 23 | // http://doc.spip.org/@_sqlite_init_functions |
| 24 | 24 | function _sqlite_init_functions(&$sqlite){ |
| 25 | 25 | |
| 26 | - if (!$sqlite) return false; |
|
| 26 | + if (!$sqlite) return false; |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - $fonctions = array( |
|
| 30 | - 'CONCAT' => array( '_sqlite_func_concat' ,-1), |
|
| 31 | - 'CEIL' => array( '_sqlite_func_ceil', 1), // absent de sqlite2 |
|
| 29 | + $fonctions = array( |
|
| 30 | + 'CONCAT' => array( '_sqlite_func_concat' ,-1), |
|
| 31 | + 'CEIL' => array( '_sqlite_func_ceil', 1), // absent de sqlite2 |
|
| 32 | 32 | |
| 33 | - 'DATE_FORMAT' => array( '_sqlite_func_strftime' ,2), |
|
| 34 | - 'DAYOFMONTH' => array( '_sqlite_func_dayofmonth' ,1), |
|
| 33 | + 'DATE_FORMAT' => array( '_sqlite_func_strftime' ,2), |
|
| 34 | + 'DAYOFMONTH' => array( '_sqlite_func_dayofmonth' ,1), |
|
| 35 | 35 | |
| 36 | - 'EXTRAIRE_MULTI' => array( '_sqlite_func_extraire_multi', 2), // specifique a SPIP/sql_multi() |
|
| 37 | - 'EXP' => array( 'exp' ,1),//exponentielle |
|
| 38 | - 'FIND_IN_SET' => array( '_sqlite_func_find_in_set' ,2), |
|
| 39 | - 'FLOOR' => array( '_sqlite_func_floor', 1), // absent de sqlite2 |
|
| 36 | + 'EXTRAIRE_MULTI' => array( '_sqlite_func_extraire_multi', 2), // specifique a SPIP/sql_multi() |
|
| 37 | + 'EXP' => array( 'exp' ,1),//exponentielle |
|
| 38 | + 'FIND_IN_SET' => array( '_sqlite_func_find_in_set' ,2), |
|
| 39 | + 'FLOOR' => array( '_sqlite_func_floor', 1), // absent de sqlite2 |
|
| 40 | 40 | |
| 41 | - 'IF' => array( '_sqlite_func_if' ,3), |
|
| 42 | - 'INSERT' => array( '_sqlite_func_insert' ,4), |
|
| 43 | - 'INSTR' => array( '_sqlite_func_instr' ,2), |
|
| 41 | + 'IF' => array( '_sqlite_func_if' ,3), |
|
| 42 | + 'INSERT' => array( '_sqlite_func_insert' ,4), |
|
| 43 | + 'INSTR' => array( '_sqlite_func_instr' ,2), |
|
| 44 | 44 | |
| 45 | - 'LEAST' => array( '_sqlite_func_least' ,3), |
|
| 46 | - '_LEFT' => array( '_sqlite_func_left' ,2), |
|
| 45 | + 'LEAST' => array( '_sqlite_func_least' ,3), |
|
| 46 | + '_LEFT' => array( '_sqlite_func_left' ,2), |
|
| 47 | 47 | # 'LENGTH' => array( 'strlen' ,1), // present v1.0.4 |
| 48 | 48 | # 'LOWER' => array( 'strtolower' ,1), // present v2.4 |
| 49 | 49 | # 'LTRIM' => array( 'ltrim' ,1), // present en theorie |
| 50 | 50 | |
| 51 | - 'NOW' => array( '_sqlite_func_now' ,0), |
|
| 51 | + 'NOW' => array( '_sqlite_func_now' ,0), |
|
| 52 | 52 | |
| 53 | - 'MD5' => array( 'md5' ,1), |
|
| 54 | - 'MONTH' => array( '_sqlite_func_month' ,1), |
|
| 53 | + 'MD5' => array( 'md5' ,1), |
|
| 54 | + 'MONTH' => array( '_sqlite_func_month' ,1), |
|
| 55 | 55 | |
| 56 | - 'PREG_REPLACE' => array( '_sqlite_func_preg_replace' ,3), |
|
| 56 | + 'PREG_REPLACE' => array( '_sqlite_func_preg_replace' ,3), |
|
| 57 | 57 | |
| 58 | - 'RAND' => array( '_sqlite_func_rand' ,0), // sinon random() v2.4 |
|
| 59 | - 'REGEXP' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 60 | - //'REGEXP_MATCH' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 58 | + 'RAND' => array( '_sqlite_func_rand' ,0), // sinon random() v2.4 |
|
| 59 | + 'REGEXP' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 60 | + //'REGEXP_MATCH' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 61 | 61 | |
| 62 | - 'RIGHT' => array( '_sqlite_func_right' ,2), |
|
| 62 | + 'RIGHT' => array( '_sqlite_func_right' ,2), |
|
| 63 | 63 | # 'RTRIM' => array( 'rtrim' ,1), // present en theorie |
| 64 | 64 | |
| 65 | - 'SETTYPE' => array( 'settype' ,2), // CAST present en v3.2.3 |
|
| 66 | - 'SQRT' => array( 'sqrt' ,1), |
|
| 67 | - 'SUBSTRING' => array( '_sqlite_func_substring' /*,3*/), // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 65 | + 'SETTYPE' => array( 'settype' ,2), // CAST present en v3.2.3 |
|
| 66 | + 'SQRT' => array( 'sqrt' ,1), |
|
| 67 | + 'SUBSTRING' => array( '_sqlite_func_substring' /*,3*/), // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 68 | 68 | |
| 69 | - 'TO_DAYS' => array( '_sqlite_func_to_days' ,1), |
|
| 69 | + 'TO_DAYS' => array( '_sqlite_func_to_days' ,1), |
|
| 70 | 70 | # 'TRIM' => array( 'trim' ,1), // present en theorie |
| 71 | 71 | |
| 72 | - 'TIMESTAMPDIFF' => array('_sqlite_timestampdiff' /*,3*/), |
|
| 72 | + 'TIMESTAMPDIFF' => array('_sqlite_timestampdiff' /*,3*/), |
|
| 73 | 73 | |
| 74 | - 'UNIX_TIMESTAMP'=> array( '_sqlite_func_unix_timestamp' ,1), |
|
| 74 | + 'UNIX_TIMESTAMP'=> array( '_sqlite_func_unix_timestamp' ,1), |
|
| 75 | 75 | # 'UPPER' => array( 'strtoupper' ,1), // present v2.4 |
| 76 | 76 | |
| 77 | - 'VIDE' => array( '_sqlite_func_vide' ,0), // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 77 | + 'VIDE' => array( '_sqlite_func_vide' ,0), // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 78 | 78 | |
| 79 | - 'YEAR' => array( '_sqlite_func_year' ,1) |
|
| 80 | - ); |
|
| 79 | + 'YEAR' => array( '_sqlite_func_year' ,1) |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - foreach ($fonctions as $f=>$r){ |
|
| 84 | - _sqlite_add_function($sqlite, $f, $r); |
|
| 85 | - } |
|
| 83 | + foreach ($fonctions as $f=>$r){ |
|
| 84 | + _sqlite_add_function($sqlite, $f, $r); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 87 | + #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // permet au besoin de charger des fonctions ailleurs par _sqlite_init_functions(); |
| 91 | 91 | // http://doc.spip.org/@_sqlite_add_function |
| 92 | 92 | function _sqlite_add_function(&$sqlite, &$f, &$r){ |
| 93 | - if (_sqlite_is_version(3, $sqlite)){ |
|
| 94 | - isset($r[1]) |
|
| 95 | - ?$sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 96 | - :$sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 97 | - } else { |
|
| 98 | - isset($r[1]) |
|
| 99 | - ?sqlite_create_function($sqlite, $f, $r[0], $r[1]) |
|
| 100 | - :sqlite_create_function($sqlite, $f, $r[0]); |
|
| 101 | - } |
|
| 93 | + if (_sqlite_is_version(3, $sqlite)){ |
|
| 94 | + isset($r[1]) |
|
| 95 | + ?$sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 96 | + :$sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 97 | + } else { |
|
| 98 | + isset($r[1]) |
|
| 99 | + ?sqlite_create_function($sqlite, $f, $r[0], $r[1]) |
|
| 100 | + :sqlite_create_function($sqlite, $f, $r[0]); |
|
| 101 | + } |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // |
@@ -107,34 +107,34 @@ discard block |
||
| 107 | 107 | // |
| 108 | 108 | |
| 109 | 109 | function _sqlite_func_ceil($a) { |
| 110 | - return ceil($a); |
|
| 110 | + return ceil($a); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // http://doc.spip.org/@_sqlite_func_concat |
| 114 | 114 | function _sqlite_func_concat () { |
| 115 | - $args = func_get_args(); |
|
| 116 | - return join('',$args); |
|
| 115 | + $args = func_get_args(); |
|
| 116 | + return join('',$args); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | // http://doc.spip.org/@_sqlite_func_dayofmonth |
| 121 | 121 | function _sqlite_func_dayofmonth ($d) { |
| 122 | - return _sqlite_func_date("d",$d); |
|
| 122 | + return _sqlite_func_date("d",$d); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | // http://doc.spip.org/@_sqlite_func_find_in_set |
| 127 | 127 | function _sqlite_func_find_in_set($num, $set) { |
| 128 | - $rank=0; |
|
| 129 | - foreach (explode(",",$set) as $v) { |
|
| 130 | - if ($v == $num) return (++$rank); |
|
| 131 | - $rank++; |
|
| 132 | - } |
|
| 133 | - return 0; |
|
| 128 | + $rank=0; |
|
| 129 | + foreach (explode(",",$set) as $v) { |
|
| 130 | + if ($v == $num) return (++$rank); |
|
| 131 | + $rank++; |
|
| 132 | + } |
|
| 133 | + return 0; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | function _sqlite_func_floor($a) { |
| 137 | - return floor($a); |
|
| 137 | + return floor($a); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // http://doc.spip.org/@_sqlite_func_if |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | // http://doc.spip.org/@_sqlite_func_insert |
| 152 | 152 | function _sqlite_func_insert ($s, $index, $longueur, $chaine) { |
| 153 | - return |
|
| 154 | - substr($s,0, $index) |
|
| 155 | - . $chaine |
|
| 156 | - . substr(substr($s, $index), $longueur); |
|
| 153 | + return |
|
| 154 | + substr($s,0, $index) |
|
| 155 | + . $chaine |
|
| 156 | + . substr(substr($s, $index), $longueur); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | // http://doc.spip.org/@_sqlite_func_least |
| 167 | 167 | function _sqlite_func_least () { |
| 168 | - $arg_list = func_get_args(); |
|
| 168 | + $arg_list = func_get_args(); |
|
| 169 | 169 | $least = min($arg_list); |
| 170 | - #spip_log("Passage avec LEAST : $least",'sqlite.'._LOG_DEBUG); |
|
| 171 | - return $least; |
|
| 170 | + #spip_log("Passage avec LEAST : $least",'sqlite.'._LOG_DEBUG); |
|
| 171 | + return $least; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -180,26 +180,26 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | // http://doc.spip.org/@_sqlite_func_now |
| 182 | 182 | function _sqlite_func_now(){ |
| 183 | - static $now = null; |
|
| 184 | - if (is_null($now)) |
|
| 185 | - $now = date("Y-m-d H:i:s"); |
|
| 186 | - #spip_log("Passage avec NOW : $now",'sqlite.'._LOG_DEBUG); |
|
| 187 | - return $now; |
|
| 183 | + static $now = null; |
|
| 184 | + if (is_null($now)) |
|
| 185 | + $now = date("Y-m-d H:i:s"); |
|
| 186 | + #spip_log("Passage avec NOW : $now",'sqlite.'._LOG_DEBUG); |
|
| 187 | + return $now; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | // http://doc.spip.org/@_sqlite_func_month |
| 192 | 192 | function _sqlite_func_month ($d) { |
| 193 | - return _sqlite_func_date("m",$d); |
|
| 193 | + return _sqlite_func_date("m",$d); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | // http://doc.spip.org/@_sqlite_func_preg_replace |
| 199 | 199 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 200 | - $return = preg_replace('%'.$cherche.'%', $remplace, $quoi); |
|
| 201 | - #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 202 | - return $return; |
|
| 200 | + $return = preg_replace('%'.$cherche.'%', $remplace, $quoi); |
|
| 201 | + #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 202 | + return $return; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,51 +210,51 @@ discard block |
||
| 210 | 210 | * @return string, l'extrait trouve. |
| 211 | 211 | **/ |
| 212 | 212 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 213 | - if (!defined('_EXTRAIRE_MULTI')) |
|
| 214 | - include_spip('inc/filtres'); |
|
| 215 | - if (!function_exists('approcher_langue')) |
|
| 216 | - include_spip('inc/lang'); |
|
| 217 | - if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) { |
|
| 218 | - foreach ($regs as $reg) { |
|
| 219 | - // chercher la version de la langue courante |
|
| 220 | - $trads = extraire_trads($reg[1]); |
|
| 221 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 222 | - $trad = $trads[$l]; |
|
| 223 | - } else { |
|
| 224 | - $trad = reset($trads); |
|
| 225 | - } |
|
| 226 | - $quoi = str_replace($reg[0], $trad, $quoi); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - return $quoi; |
|
| 213 | + if (!defined('_EXTRAIRE_MULTI')) |
|
| 214 | + include_spip('inc/filtres'); |
|
| 215 | + if (!function_exists('approcher_langue')) |
|
| 216 | + include_spip('inc/lang'); |
|
| 217 | + if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) { |
|
| 218 | + foreach ($regs as $reg) { |
|
| 219 | + // chercher la version de la langue courante |
|
| 220 | + $trads = extraire_trads($reg[1]); |
|
| 221 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 222 | + $trad = $trads[$l]; |
|
| 223 | + } else { |
|
| 224 | + $trad = reset($trads); |
|
| 225 | + } |
|
| 226 | + $quoi = str_replace($reg[0], $trad, $quoi); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + return $quoi; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | // http://doc.spip.org/@_sqlite_func_rand |
| 234 | 234 | function _sqlite_func_rand() { |
| 235 | - return rand(); |
|
| 235 | + return rand(); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | // http://doc.spip.org/@_sqlite_func_right |
| 240 | 240 | function _sqlite_func_right ($s, $length) { |
| 241 | - return substr($s,0 - $length); |
|
| 241 | + return substr($s,0 - $length); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | // http://doc.spip.org/@_sqlite_func_regexp_match |
| 246 | 246 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 247 | - // optimiser un cas tres courant avec les requetes en base |
|
| 248 | - if (!$quoi AND !strlen($quoi)) return false; |
|
| 249 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 250 | - $return = preg_match('%'.$cherche.'%imsS'.$u, $quoi); |
|
| 251 | - #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 252 | - return $return; |
|
| 247 | + // optimiser un cas tres courant avec les requetes en base |
|
| 248 | + if (!$quoi AND !strlen($quoi)) return false; |
|
| 249 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 250 | + $return = preg_match('%'.$cherche.'%imsS'.$u, $quoi); |
|
| 251 | + #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 252 | + return $return; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // http://doc.spip.org/@_sqlite_func_strftime |
| 256 | 256 | function _sqlite_func_strftime($date, $conv){ |
| 257 | - return strftime($conv, is_int($date)?$date:strtotime($date)); |
|
| 257 | + return strftime($conv, is_int($date)?$date:strtotime($date)); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -265,19 +265,19 @@ discard block |
||
| 265 | 265 | * @return int |
| 266 | 266 | */ |
| 267 | 267 | function _sqlite_func_to_days ($d) { |
| 268 | - static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 269 | - $result = $offset+(int)ceil(_sqlite_func_unix_timestamp($d)/(24*3600)); |
|
| 270 | - #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 271 | - return $result; |
|
| 268 | + static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 269 | + $result = $offset+(int)ceil(_sqlite_func_unix_timestamp($d)/(24*3600)); |
|
| 270 | + #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 271 | + return $result; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | function _sqlite_func_substring($string,$start,$len=null){ |
| 275 | - // SQL compte a partir de 1, php a partir de 0 |
|
| 276 | - $start = ($start>0)?$start-1:$start; |
|
| 277 | - if (is_null($len)) |
|
| 278 | - return substr($string,$start); |
|
| 279 | - else |
|
| 280 | - return substr($string,$start,$len); |
|
| 275 | + // SQL compte a partir de 1, php a partir de 0 |
|
| 276 | + $start = ($start>0)?$start-1:$start; |
|
| 277 | + if (is_null($len)) |
|
| 278 | + return substr($string,$start); |
|
| 279 | + else |
|
| 280 | + return substr($string,$start,$len); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -289,84 +289,84 @@ discard block |
||
| 289 | 289 | * @return int |
| 290 | 290 | */ |
| 291 | 291 | function _sqlite_timestampdiff($unit,$date1,$date2){ |
| 292 | - // PHP >= 5.3 |
|
| 293 | - if (function_exists("date_diff")){ |
|
| 294 | - $d1 = date_create($date1); |
|
| 295 | - $d2 = date_create($date2); |
|
| 296 | - $diff = date_diff($d1,$d2); |
|
| 297 | - $inv = $diff->invert?-1:1; |
|
| 298 | - switch($unit){ |
|
| 299 | - case "YEAR": |
|
| 300 | - return $inv*$diff->y; |
|
| 301 | - case "QUARTER": |
|
| 302 | - return $inv*(4*$diff->y+intval(floor($diff->m/3))); |
|
| 303 | - case "MONTH": |
|
| 304 | - return $inv*(12*$diff->y+$diff->m); |
|
| 305 | - case "WEEK": |
|
| 306 | - return $inv*intval(floor($diff->days/7)); |
|
| 307 | - case "DAY": |
|
| 308 | - #var_dump($inv*$diff->days); |
|
| 309 | - return $inv*$diff->days; |
|
| 310 | - case "HOUR": |
|
| 311 | - return $inv*(24*$diff->days+$diff->h); |
|
| 312 | - case "MINUTE": |
|
| 313 | - return $inv*((24*$diff->days+$diff->h)*60+$diff->i); |
|
| 314 | - case "SECOND": |
|
| 315 | - return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s); |
|
| 316 | - case "MICROSECOND": |
|
| 317 | - return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s)*1000000; |
|
| 318 | - } |
|
| 319 | - return 0; |
|
| 320 | - } |
|
| 321 | - // PHP < 5.3 |
|
| 322 | - else { |
|
| 323 | - $d1 = strtotime($date1); |
|
| 324 | - $d2 = strtotime($date2); |
|
| 325 | - $diff = $d2 - $d1; |
|
| 326 | - $sign = ($diff<0?-1:1); |
|
| 327 | - $diff = $sign * $diff; |
|
| 328 | - switch($unit){ |
|
| 329 | - case "YEAR": |
|
| 330 | - $diff = $d2-$d1; |
|
| 331 | - return $sign*(date('Y',abs($diff))-date('Y',0)); |
|
| 332 | - case "QUARTER": |
|
| 333 | - return $sign*(4*(date('Y',abs($diff))-date('Y',0))+intval(floor((date('m',$diff)-1)/3))); |
|
| 334 | - case "MONTH": |
|
| 335 | - return $sign*((date('Y',$diff)-date('Y',0))*12+date('m',$diff)-1); |
|
| 336 | - case "WEEK": |
|
| 337 | - return intval(floor(($d2-$d1)/3600/7)); |
|
| 338 | - case "DAY": |
|
| 339 | - return intval(floor(($d2-$d1)/3600/24)); |
|
| 340 | - case "HOUR": |
|
| 341 | - return intval(floor(($d2-$d1)/3600)); |
|
| 342 | - case "MINUTE": |
|
| 343 | - return intval(floor(($d2-$d1)/60)); |
|
| 344 | - case "SECOND": |
|
| 345 | - return $d2-$d1; |
|
| 346 | - case "MICROSECOND": |
|
| 347 | - return $d2-$d1*1000000; |
|
| 348 | - } |
|
| 349 | - } |
|
| 292 | + // PHP >= 5.3 |
|
| 293 | + if (function_exists("date_diff")){ |
|
| 294 | + $d1 = date_create($date1); |
|
| 295 | + $d2 = date_create($date2); |
|
| 296 | + $diff = date_diff($d1,$d2); |
|
| 297 | + $inv = $diff->invert?-1:1; |
|
| 298 | + switch($unit){ |
|
| 299 | + case "YEAR": |
|
| 300 | + return $inv*$diff->y; |
|
| 301 | + case "QUARTER": |
|
| 302 | + return $inv*(4*$diff->y+intval(floor($diff->m/3))); |
|
| 303 | + case "MONTH": |
|
| 304 | + return $inv*(12*$diff->y+$diff->m); |
|
| 305 | + case "WEEK": |
|
| 306 | + return $inv*intval(floor($diff->days/7)); |
|
| 307 | + case "DAY": |
|
| 308 | + #var_dump($inv*$diff->days); |
|
| 309 | + return $inv*$diff->days; |
|
| 310 | + case "HOUR": |
|
| 311 | + return $inv*(24*$diff->days+$diff->h); |
|
| 312 | + case "MINUTE": |
|
| 313 | + return $inv*((24*$diff->days+$diff->h)*60+$diff->i); |
|
| 314 | + case "SECOND": |
|
| 315 | + return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s); |
|
| 316 | + case "MICROSECOND": |
|
| 317 | + return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s)*1000000; |
|
| 318 | + } |
|
| 319 | + return 0; |
|
| 320 | + } |
|
| 321 | + // PHP < 5.3 |
|
| 322 | + else { |
|
| 323 | + $d1 = strtotime($date1); |
|
| 324 | + $d2 = strtotime($date2); |
|
| 325 | + $diff = $d2 - $d1; |
|
| 326 | + $sign = ($diff<0?-1:1); |
|
| 327 | + $diff = $sign * $diff; |
|
| 328 | + switch($unit){ |
|
| 329 | + case "YEAR": |
|
| 330 | + $diff = $d2-$d1; |
|
| 331 | + return $sign*(date('Y',abs($diff))-date('Y',0)); |
|
| 332 | + case "QUARTER": |
|
| 333 | + return $sign*(4*(date('Y',abs($diff))-date('Y',0))+intval(floor((date('m',$diff)-1)/3))); |
|
| 334 | + case "MONTH": |
|
| 335 | + return $sign*((date('Y',$diff)-date('Y',0))*12+date('m',$diff)-1); |
|
| 336 | + case "WEEK": |
|
| 337 | + return intval(floor(($d2-$d1)/3600/7)); |
|
| 338 | + case "DAY": |
|
| 339 | + return intval(floor(($d2-$d1)/3600/24)); |
|
| 340 | + case "HOUR": |
|
| 341 | + return intval(floor(($d2-$d1)/3600)); |
|
| 342 | + case "MINUTE": |
|
| 343 | + return intval(floor(($d2-$d1)/60)); |
|
| 344 | + case "SECOND": |
|
| 345 | + return $d2-$d1; |
|
| 346 | + case "MICROSECOND": |
|
| 347 | + return $d2-$d1*1000000; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // http://doc.spip.org/@_sqlite_func_unix_timestamp |
| 353 | 353 | function _sqlite_func_unix_timestamp($d) { |
| 354 | - static $mem = array(); |
|
| 355 | - static $n = 0; |
|
| 356 | - if (isset($mem[$d])) return $mem[$d]; |
|
| 357 | - if ($n++>100) {$mem = array();$n=0;} |
|
| 358 | - |
|
| 359 | - //2005-12-02 20:53:53 |
|
| 360 | - #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 361 | - if (!$d) return $mem[$d] = mktime(); |
|
| 362 | - // une pile plus grosse n'accelere pas le calcul |
|
| 363 | - return $mem[$d] = strtotime($d); |
|
| 354 | + static $mem = array(); |
|
| 355 | + static $n = 0; |
|
| 356 | + if (isset($mem[$d])) return $mem[$d]; |
|
| 357 | + if ($n++>100) {$mem = array();$n=0;} |
|
| 358 | + |
|
| 359 | + //2005-12-02 20:53:53 |
|
| 360 | + #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 361 | + if (!$d) return $mem[$d] = mktime(); |
|
| 362 | + // une pile plus grosse n'accelere pas le calcul |
|
| 363 | + return $mem[$d] = strtotime($d); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | // http://doc.spip.org/@_sqlite_func_year |
| 368 | 368 | function _sqlite_func_year ($d) { |
| 369 | - return _sqlite_func_date("Y",$d); |
|
| 369 | + return _sqlite_func_date("Y",$d); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -379,19 +379,19 @@ discard block |
||
| 379 | 379 | * @return int |
| 380 | 380 | */ |
| 381 | 381 | function _sqlite_func_date($quoi,$d) { |
| 382 | - static $mem = array(); |
|
| 383 | - static $n = 0; |
|
| 384 | - if (isset($mem[$d])) return $mem[$d][$quoi]; |
|
| 385 | - if ($n++>100) {$mem = array();$n=0;} |
|
| 386 | - |
|
| 387 | - $dec = date("Y-m-d",_sqlite_func_unix_timestamp($d)); |
|
| 388 | - $mem[$d] = array("Y"=>substr($dec,0,4),"m"=>substr($dec,5,2),"d"=>substr($dec,8,2)); |
|
| 389 | - return $mem[$d][$quoi]; |
|
| 382 | + static $mem = array(); |
|
| 383 | + static $n = 0; |
|
| 384 | + if (isset($mem[$d])) return $mem[$d][$quoi]; |
|
| 385 | + if ($n++>100) {$mem = array();$n=0;} |
|
| 386 | + |
|
| 387 | + $dec = date("Y-m-d",_sqlite_func_unix_timestamp($d)); |
|
| 388 | + $mem[$d] = array("Y"=>substr($dec,0,4),"m"=>substr($dec,5,2),"d"=>substr($dec,8,2)); |
|
| 389 | + return $mem[$d][$quoi]; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | // http://doc.spip.org/@_sqlite_func_vide |
| 393 | 393 | function _sqlite_func_vide(){ |
| 394 | - return; |
|
| 394 | + return; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | /* |
| 17 | 19 | * Des fonctions pour les requetes SQL |
@@ -23,7 +25,9 @@ discard block |
||
| 23 | 25 | // http://doc.spip.org/@_sqlite_init_functions |
| 24 | 26 | function _sqlite_init_functions(&$sqlite){ |
| 25 | 27 | |
| 26 | - if (!$sqlite) return false; |
|
| 28 | + if (!$sqlite) { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 27 | 31 | |
| 28 | 32 | |
| 29 | 33 | $fonctions = array( |
@@ -127,7 +131,9 @@ discard block |
||
| 127 | 131 | function _sqlite_func_find_in_set($num, $set) { |
| 128 | 132 | $rank=0; |
| 129 | 133 | foreach (explode(",",$set) as $v) { |
| 130 | - if ($v == $num) return (++$rank); |
|
| 134 | + if ($v == $num) { |
|
| 135 | + return (++$rank); |
|
| 136 | + } |
|
| 131 | 137 | $rank++; |
| 132 | 138 | } |
| 133 | 139 | return 0; |
@@ -181,8 +187,9 @@ discard block |
||
| 181 | 187 | // http://doc.spip.org/@_sqlite_func_now |
| 182 | 188 | function _sqlite_func_now(){ |
| 183 | 189 | static $now = null; |
| 184 | - if (is_null($now)) |
|
| 185 | - $now = date("Y-m-d H:i:s"); |
|
| 190 | + if (is_null($now)) { |
|
| 191 | + $now = date("Y-m-d H:i:s"); |
|
| 192 | + } |
|
| 186 | 193 | #spip_log("Passage avec NOW : $now",'sqlite.'._LOG_DEBUG); |
| 187 | 194 | return $now; |
| 188 | 195 | } |
@@ -210,10 +217,12 @@ discard block |
||
| 210 | 217 | * @return string, l'extrait trouve. |
| 211 | 218 | **/ |
| 212 | 219 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 213 | - if (!defined('_EXTRAIRE_MULTI')) |
|
| 214 | - include_spip('inc/filtres'); |
|
| 215 | - if (!function_exists('approcher_langue')) |
|
| 216 | - include_spip('inc/lang'); |
|
| 220 | + if (!defined('_EXTRAIRE_MULTI')) { |
|
| 221 | + include_spip('inc/filtres'); |
|
| 222 | + } |
|
| 223 | + if (!function_exists('approcher_langue')) { |
|
| 224 | + include_spip('inc/lang'); |
|
| 225 | + } |
|
| 217 | 226 | if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) { |
| 218 | 227 | foreach ($regs as $reg) { |
| 219 | 228 | // chercher la version de la langue courante |
@@ -245,7 +254,9 @@ discard block |
||
| 245 | 254 | // http://doc.spip.org/@_sqlite_func_regexp_match |
| 246 | 255 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 247 | 256 | // optimiser un cas tres courant avec les requetes en base |
| 248 | - if (!$quoi AND !strlen($quoi)) return false; |
|
| 257 | + if (!$quoi AND !strlen($quoi)) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 249 | 260 | $u = $GLOBALS['meta']['pcre_u']; |
| 250 | 261 | $return = preg_match('%'.$cherche.'%imsS'.$u, $quoi); |
| 251 | 262 | #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
@@ -274,11 +285,12 @@ discard block |
||
| 274 | 285 | function _sqlite_func_substring($string,$start,$len=null){ |
| 275 | 286 | // SQL compte a partir de 1, php a partir de 0 |
| 276 | 287 | $start = ($start>0)?$start-1:$start; |
| 277 | - if (is_null($len)) |
|
| 278 | - return substr($string,$start); |
|
| 279 | - else |
|
| 280 | - return substr($string,$start,$len); |
|
| 281 | -} |
|
| 288 | + if (is_null($len)) { |
|
| 289 | + return substr($string,$start); |
|
| 290 | + } else { |
|
| 291 | + return substr($string,$start,$len); |
|
| 292 | + } |
|
| 293 | + } |
|
| 282 | 294 | |
| 283 | 295 | /** |
| 284 | 296 | * Calcul de la difference entre 2 timestamp, exprimes dans l'unite fournie en premier argument |
@@ -353,12 +365,16 @@ discard block |
||
| 353 | 365 | function _sqlite_func_unix_timestamp($d) { |
| 354 | 366 | static $mem = array(); |
| 355 | 367 | static $n = 0; |
| 356 | - if (isset($mem[$d])) return $mem[$d]; |
|
| 368 | + if (isset($mem[$d])) { |
|
| 369 | + return $mem[$d]; |
|
| 370 | + } |
|
| 357 | 371 | if ($n++>100) {$mem = array();$n=0;} |
| 358 | 372 | |
| 359 | 373 | //2005-12-02 20:53:53 |
| 360 | 374 | #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
| 361 | - if (!$d) return $mem[$d] = mktime(); |
|
| 375 | + if (!$d) { |
|
| 376 | + return $mem[$d] = mktime(); |
|
| 377 | + } |
|
| 362 | 378 | // une pile plus grosse n'accelere pas le calcul |
| 363 | 379 | return $mem[$d] = strtotime($d); |
| 364 | 380 | } |
@@ -381,7 +397,9 @@ discard block |
||
| 381 | 397 | function _sqlite_func_date($quoi,$d) { |
| 382 | 398 | static $mem = array(); |
| 383 | 399 | static $n = 0; |
| 384 | - if (isset($mem[$d])) return $mem[$d][$quoi]; |
|
| 400 | + if (isset($mem[$d])) { |
|
| 401 | + return $mem[$d][$quoi]; |
|
| 402 | + } |
|
| 385 | 403 | if ($n++>100) {$mem = array();$n=0;} |
| 386 | 404 | |
| 387 | 405 | $dec = date("Y-m-d",_sqlite_func_unix_timestamp($d)); |
@@ -21,66 +21,66 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | // http://doc.spip.org/@_sqlite_init_functions |
| 24 | -function _sqlite_init_functions(&$sqlite){ |
|
| 24 | +function _sqlite_init_functions(&$sqlite) { |
|
| 25 | 25 | |
| 26 | 26 | if (!$sqlite) return false; |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | $fonctions = array( |
| 30 | - 'CONCAT' => array( '_sqlite_func_concat' ,-1), |
|
| 31 | - 'CEIL' => array( '_sqlite_func_ceil', 1), // absent de sqlite2 |
|
| 30 | + 'CONCAT' => array('_sqlite_func_concat', -1), |
|
| 31 | + 'CEIL' => array('_sqlite_func_ceil', 1), // absent de sqlite2 |
|
| 32 | 32 | |
| 33 | - 'DATE_FORMAT' => array( '_sqlite_func_strftime' ,2), |
|
| 34 | - 'DAYOFMONTH' => array( '_sqlite_func_dayofmonth' ,1), |
|
| 33 | + 'DATE_FORMAT' => array('_sqlite_func_strftime', 2), |
|
| 34 | + 'DAYOFMONTH' => array('_sqlite_func_dayofmonth', 1), |
|
| 35 | 35 | |
| 36 | - 'EXTRAIRE_MULTI' => array( '_sqlite_func_extraire_multi', 2), // specifique a SPIP/sql_multi() |
|
| 37 | - 'EXP' => array( 'exp' ,1),//exponentielle |
|
| 38 | - 'FIND_IN_SET' => array( '_sqlite_func_find_in_set' ,2), |
|
| 39 | - 'FLOOR' => array( '_sqlite_func_floor', 1), // absent de sqlite2 |
|
| 36 | + 'EXTRAIRE_MULTI' => array('_sqlite_func_extraire_multi', 2), // specifique a SPIP/sql_multi() |
|
| 37 | + 'EXP' => array('exp', 1), //exponentielle |
|
| 38 | + 'FIND_IN_SET' => array('_sqlite_func_find_in_set', 2), |
|
| 39 | + 'FLOOR' => array('_sqlite_func_floor', 1), // absent de sqlite2 |
|
| 40 | 40 | |
| 41 | - 'IF' => array( '_sqlite_func_if' ,3), |
|
| 42 | - 'INSERT' => array( '_sqlite_func_insert' ,4), |
|
| 43 | - 'INSTR' => array( '_sqlite_func_instr' ,2), |
|
| 41 | + 'IF' => array('_sqlite_func_if', 3), |
|
| 42 | + 'INSERT' => array('_sqlite_func_insert', 4), |
|
| 43 | + 'INSTR' => array('_sqlite_func_instr', 2), |
|
| 44 | 44 | |
| 45 | - 'LEAST' => array( '_sqlite_func_least' ,3), |
|
| 46 | - '_LEFT' => array( '_sqlite_func_left' ,2), |
|
| 45 | + 'LEAST' => array('_sqlite_func_least', 3), |
|
| 46 | + '_LEFT' => array('_sqlite_func_left', 2), |
|
| 47 | 47 | # 'LENGTH' => array( 'strlen' ,1), // present v1.0.4 |
| 48 | 48 | # 'LOWER' => array( 'strtolower' ,1), // present v2.4 |
| 49 | 49 | # 'LTRIM' => array( 'ltrim' ,1), // present en theorie |
| 50 | 50 | |
| 51 | - 'NOW' => array( '_sqlite_func_now' ,0), |
|
| 51 | + 'NOW' => array('_sqlite_func_now', 0), |
|
| 52 | 52 | |
| 53 | - 'MD5' => array( 'md5' ,1), |
|
| 54 | - 'MONTH' => array( '_sqlite_func_month' ,1), |
|
| 53 | + 'MD5' => array('md5', 1), |
|
| 54 | + 'MONTH' => array('_sqlite_func_month', 1), |
|
| 55 | 55 | |
| 56 | - 'PREG_REPLACE' => array( '_sqlite_func_preg_replace' ,3), |
|
| 56 | + 'PREG_REPLACE' => array('_sqlite_func_preg_replace', 3), |
|
| 57 | 57 | |
| 58 | - 'RAND' => array( '_sqlite_func_rand' ,0), // sinon random() v2.4 |
|
| 59 | - 'REGEXP' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 58 | + 'RAND' => array('_sqlite_func_rand', 0), // sinon random() v2.4 |
|
| 59 | + 'REGEXP' => array('_sqlite_func_regexp_match', 2), // critere REGEXP supporte a partir de v3.3.2 |
|
| 60 | 60 | //'REGEXP_MATCH' => array( '_sqlite_func_regexp_match' ,2), // critere REGEXP supporte a partir de v3.3.2 |
| 61 | 61 | |
| 62 | - 'RIGHT' => array( '_sqlite_func_right' ,2), |
|
| 62 | + 'RIGHT' => array('_sqlite_func_right', 2), |
|
| 63 | 63 | # 'RTRIM' => array( 'rtrim' ,1), // present en theorie |
| 64 | 64 | |
| 65 | - 'SETTYPE' => array( 'settype' ,2), // CAST present en v3.2.3 |
|
| 66 | - 'SQRT' => array( 'sqrt' ,1), |
|
| 67 | - 'SUBSTRING' => array( '_sqlite_func_substring' /*,3*/), // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 65 | + 'SETTYPE' => array('settype', 2), // CAST present en v3.2.3 |
|
| 66 | + 'SQRT' => array('sqrt', 1), |
|
| 67 | + 'SUBSTRING' => array('_sqlite_func_substring' /*,3*/), // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 68 | 68 | |
| 69 | - 'TO_DAYS' => array( '_sqlite_func_to_days' ,1), |
|
| 69 | + 'TO_DAYS' => array('_sqlite_func_to_days', 1), |
|
| 70 | 70 | # 'TRIM' => array( 'trim' ,1), // present en theorie |
| 71 | 71 | |
| 72 | 72 | 'TIMESTAMPDIFF' => array('_sqlite_timestampdiff' /*,3*/), |
| 73 | 73 | |
| 74 | - 'UNIX_TIMESTAMP'=> array( '_sqlite_func_unix_timestamp' ,1), |
|
| 74 | + 'UNIX_TIMESTAMP'=> array('_sqlite_func_unix_timestamp', 1), |
|
| 75 | 75 | # 'UPPER' => array( 'strtoupper' ,1), // present v2.4 |
| 76 | 76 | |
| 77 | - 'VIDE' => array( '_sqlite_func_vide' ,0), // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 77 | + 'VIDE' => array('_sqlite_func_vide', 0), // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 78 | 78 | |
| 79 | - 'YEAR' => array( '_sqlite_func_year' ,1) |
|
| 79 | + 'YEAR' => array('_sqlite_func_year', 1) |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | |
| 83 | - foreach ($fonctions as $f=>$r){ |
|
| 83 | + foreach ($fonctions as $f=>$r) { |
|
| 84 | 84 | _sqlite_add_function($sqlite, $f, $r); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | // permet au besoin de charger des fonctions ailleurs par _sqlite_init_functions(); |
| 91 | 91 | // http://doc.spip.org/@_sqlite_add_function |
| 92 | -function _sqlite_add_function(&$sqlite, &$f, &$r){ |
|
| 93 | - if (_sqlite_is_version(3, $sqlite)){ |
|
| 92 | +function _sqlite_add_function(&$sqlite, &$f, &$r) { |
|
| 93 | + if (_sqlite_is_version(3, $sqlite)) { |
|
| 94 | 94 | isset($r[1]) |
| 95 | - ?$sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 95 | + ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 96 | 96 | :$sqlite->sqliteCreateFunction($f, $r[0]); |
| 97 | 97 | } else { |
| 98 | 98 | isset($r[1]) |
@@ -111,22 +111,22 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // http://doc.spip.org/@_sqlite_func_concat |
| 114 | -function _sqlite_func_concat () { |
|
| 114 | +function _sqlite_func_concat() { |
|
| 115 | 115 | $args = func_get_args(); |
| 116 | - return join('',$args); |
|
| 116 | + return join('', $args); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | // http://doc.spip.org/@_sqlite_func_dayofmonth |
| 121 | -function _sqlite_func_dayofmonth ($d) { |
|
| 122 | - return _sqlite_func_date("d",$d); |
|
| 121 | +function _sqlite_func_dayofmonth($d) { |
|
| 122 | + return _sqlite_func_date("d", $d); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | // http://doc.spip.org/@_sqlite_func_find_in_set |
| 127 | 127 | function _sqlite_func_find_in_set($num, $set) { |
| 128 | - $rank=0; |
|
| 129 | - foreach (explode(",",$set) as $v) { |
|
| 128 | + $rank = 0; |
|
| 129 | + foreach (explode(",", $set) as $v) { |
|
| 130 | 130 | if ($v == $num) return (++$rank); |
| 131 | 131 | $rank++; |
| 132 | 132 | } |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // http://doc.spip.org/@_sqlite_func_if |
| 141 | -function _sqlite_func_if ($bool, $oui, $non) { |
|
| 142 | - return ($bool)?$oui:$non; |
|
| 141 | +function _sqlite_func_if($bool, $oui, $non) { |
|
| 142 | + return ($bool) ? $oui : $non; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -149,22 +149,22 @@ discard block |
||
| 149 | 149 | * a ete inseree a la position "index" en remplacant "longueur" caracteres. |
| 150 | 150 | */ |
| 151 | 151 | // http://doc.spip.org/@_sqlite_func_insert |
| 152 | -function _sqlite_func_insert ($s, $index, $longueur, $chaine) { |
|
| 152 | +function _sqlite_func_insert($s, $index, $longueur, $chaine) { |
|
| 153 | 153 | return |
| 154 | - substr($s,0, $index) |
|
| 154 | + substr($s, 0, $index) |
|
| 155 | 155 | . $chaine |
| 156 | 156 | . substr(substr($s, $index), $longueur); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | // http://doc.spip.org/@_sqlite_func_instr |
| 161 | -function _sqlite_func_instr ($s, $search) { |
|
| 162 | - return strpos($s,$search); |
|
| 161 | +function _sqlite_func_instr($s, $search) { |
|
| 162 | + return strpos($s, $search); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | // http://doc.spip.org/@_sqlite_func_least |
| 167 | -function _sqlite_func_least () { |
|
| 167 | +function _sqlite_func_least() { |
|
| 168 | 168 | $arg_list = func_get_args(); |
| 169 | 169 | $least = min($arg_list); |
| 170 | 170 | #spip_log("Passage avec LEAST : $least",'sqlite.'._LOG_DEBUG); |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | |
| 175 | 175 | // http://doc.spip.org/@_sqlite_func_left |
| 176 | -function _sqlite_func_left ($s, $lenght) { |
|
| 177 | - return substr($s,0,$lenght); |
|
| 176 | +function _sqlite_func_left($s, $lenght) { |
|
| 177 | + return substr($s, 0, $lenght); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | // http://doc.spip.org/@_sqlite_func_now |
| 182 | -function _sqlite_func_now(){ |
|
| 182 | +function _sqlite_func_now() { |
|
| 183 | 183 | static $now = null; |
| 184 | 184 | if (is_null($now)) |
| 185 | 185 | $now = date("Y-m-d H:i:s"); |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | // http://doc.spip.org/@_sqlite_func_month |
| 192 | -function _sqlite_func_month ($d) { |
|
| 193 | - return _sqlite_func_date("m",$d); |
|
| 192 | +function _sqlite_func_month($d) { |
|
| 193 | + return _sqlite_func_date("m", $d); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | // http://doc.spip.org/@_sqlite_func_right |
| 240 | -function _sqlite_func_right ($s, $length) { |
|
| 241 | - return substr($s,0 - $length); |
|
| 240 | +function _sqlite_func_right($s, $length) { |
|
| 241 | + return substr($s, 0 - $length); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // http://doc.spip.org/@_sqlite_func_strftime |
| 256 | -function _sqlite_func_strftime($date, $conv){ |
|
| 257 | - return strftime($conv, is_int($date)?$date:strtotime($date)); |
|
| 256 | +function _sqlite_func_strftime($date, $conv) { |
|
| 257 | + return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -264,20 +264,20 @@ discard block |
||
| 264 | 264 | * @param string $d |
| 265 | 265 | * @return int |
| 266 | 266 | */ |
| 267 | -function _sqlite_func_to_days ($d) { |
|
| 267 | +function _sqlite_func_to_days($d) { |
|
| 268 | 268 | static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
| 269 | - $result = $offset+(int)ceil(_sqlite_func_unix_timestamp($d)/(24*3600)); |
|
| 269 | + $result = $offset + (int) ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 270 | 270 | #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
| 271 | 271 | return $result; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | -function _sqlite_func_substring($string,$start,$len=null){ |
|
| 274 | +function _sqlite_func_substring($string, $start, $len = null) { |
|
| 275 | 275 | // SQL compte a partir de 1, php a partir de 0 |
| 276 | - $start = ($start>0)?$start-1:$start; |
|
| 276 | + $start = ($start > 0) ? $start - 1 : $start; |
|
| 277 | 277 | if (is_null($len)) |
| 278 | - return substr($string,$start); |
|
| 278 | + return substr($string, $start); |
|
| 279 | 279 | else |
| 280 | - return substr($string,$start,$len); |
|
| 280 | + return substr($string, $start, $len); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -288,33 +288,33 @@ discard block |
||
| 288 | 288 | * @param string $date2 |
| 289 | 289 | * @return int |
| 290 | 290 | */ |
| 291 | -function _sqlite_timestampdiff($unit,$date1,$date2){ |
|
| 291 | +function _sqlite_timestampdiff($unit, $date1, $date2) { |
|
| 292 | 292 | // PHP >= 5.3 |
| 293 | - if (function_exists("date_diff")){ |
|
| 293 | + if (function_exists("date_diff")) { |
|
| 294 | 294 | $d1 = date_create($date1); |
| 295 | 295 | $d2 = date_create($date2); |
| 296 | - $diff = date_diff($d1,$d2); |
|
| 297 | - $inv = $diff->invert?-1:1; |
|
| 298 | - switch($unit){ |
|
| 296 | + $diff = date_diff($d1, $d2); |
|
| 297 | + $inv = $diff->invert ?-1 : 1; |
|
| 298 | + switch ($unit) { |
|
| 299 | 299 | case "YEAR": |
| 300 | - return $inv*$diff->y; |
|
| 300 | + return $inv * $diff->y; |
|
| 301 | 301 | case "QUARTER": |
| 302 | - return $inv*(4*$diff->y+intval(floor($diff->m/3))); |
|
| 302 | + return $inv * (4 * $diff->y + intval(floor($diff->m / 3))); |
|
| 303 | 303 | case "MONTH": |
| 304 | - return $inv*(12*$diff->y+$diff->m); |
|
| 304 | + return $inv * (12 * $diff->y + $diff->m); |
|
| 305 | 305 | case "WEEK": |
| 306 | - return $inv*intval(floor($diff->days/7)); |
|
| 306 | + return $inv * intval(floor($diff->days / 7)); |
|
| 307 | 307 | case "DAY": |
| 308 | 308 | #var_dump($inv*$diff->days); |
| 309 | - return $inv*$diff->days; |
|
| 309 | + return $inv * $diff->days; |
|
| 310 | 310 | case "HOUR": |
| 311 | - return $inv*(24*$diff->days+$diff->h); |
|
| 311 | + return $inv * (24 * $diff->days + $diff->h); |
|
| 312 | 312 | case "MINUTE": |
| 313 | - return $inv*((24*$diff->days+$diff->h)*60+$diff->i); |
|
| 313 | + return $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i); |
|
| 314 | 314 | case "SECOND": |
| 315 | - return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s); |
|
| 315 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s); |
|
| 316 | 316 | case "MICROSECOND": |
| 317 | - return $inv*(((24*$diff->days+$diff->h)*60+$diff->i)*60+$diff->s)*1000000; |
|
| 317 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1000000; |
|
| 318 | 318 | } |
| 319 | 319 | return 0; |
| 320 | 320 | } |
@@ -323,28 +323,28 @@ discard block |
||
| 323 | 323 | $d1 = strtotime($date1); |
| 324 | 324 | $d2 = strtotime($date2); |
| 325 | 325 | $diff = $d2 - $d1; |
| 326 | - $sign = ($diff<0?-1:1); |
|
| 326 | + $sign = ($diff < 0 ?-1 : 1); |
|
| 327 | 327 | $diff = $sign * $diff; |
| 328 | - switch($unit){ |
|
| 328 | + switch ($unit) { |
|
| 329 | 329 | case "YEAR": |
| 330 | - $diff = $d2-$d1; |
|
| 331 | - return $sign*(date('Y',abs($diff))-date('Y',0)); |
|
| 330 | + $diff = $d2 - $d1; |
|
| 331 | + return $sign * (date('Y', abs($diff)) - date('Y', 0)); |
|
| 332 | 332 | case "QUARTER": |
| 333 | - return $sign*(4*(date('Y',abs($diff))-date('Y',0))+intval(floor((date('m',$diff)-1)/3))); |
|
| 333 | + return $sign * (4 * (date('Y', abs($diff)) - date('Y', 0)) + intval(floor((date('m', $diff) - 1) / 3))); |
|
| 334 | 334 | case "MONTH": |
| 335 | - return $sign*((date('Y',$diff)-date('Y',0))*12+date('m',$diff)-1); |
|
| 335 | + return $sign * ((date('Y', $diff) - date('Y', 0)) * 12 + date('m', $diff) - 1); |
|
| 336 | 336 | case "WEEK": |
| 337 | - return intval(floor(($d2-$d1)/3600/7)); |
|
| 337 | + return intval(floor(($d2 - $d1) / 3600 / 7)); |
|
| 338 | 338 | case "DAY": |
| 339 | - return intval(floor(($d2-$d1)/3600/24)); |
|
| 339 | + return intval(floor(($d2 - $d1) / 3600 / 24)); |
|
| 340 | 340 | case "HOUR": |
| 341 | - return intval(floor(($d2-$d1)/3600)); |
|
| 341 | + return intval(floor(($d2 - $d1) / 3600)); |
|
| 342 | 342 | case "MINUTE": |
| 343 | - return intval(floor(($d2-$d1)/60)); |
|
| 343 | + return intval(floor(($d2 - $d1) / 60)); |
|
| 344 | 344 | case "SECOND": |
| 345 | - return $d2-$d1; |
|
| 345 | + return $d2 - $d1; |
|
| 346 | 346 | case "MICROSECOND": |
| 347 | - return $d2-$d1*1000000; |
|
| 347 | + return $d2 - $d1 * 1000000; |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | static $mem = array(); |
| 355 | 355 | static $n = 0; |
| 356 | 356 | if (isset($mem[$d])) return $mem[$d]; |
| 357 | - if ($n++>100) {$mem = array();$n=0;} |
|
| 357 | + if ($n++ > 100) {$mem = array(); $n = 0; } |
|
| 358 | 358 | |
| 359 | 359 | //2005-12-02 20:53:53 |
| 360 | 360 | #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | // http://doc.spip.org/@_sqlite_func_year |
| 368 | -function _sqlite_func_year ($d) { |
|
| 369 | - return _sqlite_func_date("Y",$d); |
|
| 368 | +function _sqlite_func_year($d) { |
|
| 369 | + return _sqlite_func_date("Y", $d); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -378,19 +378,19 @@ discard block |
||
| 378 | 378 | * timestamp |
| 379 | 379 | * @return int |
| 380 | 380 | */ |
| 381 | -function _sqlite_func_date($quoi,$d) { |
|
| 381 | +function _sqlite_func_date($quoi, $d) { |
|
| 382 | 382 | static $mem = array(); |
| 383 | 383 | static $n = 0; |
| 384 | 384 | if (isset($mem[$d])) return $mem[$d][$quoi]; |
| 385 | - if ($n++>100) {$mem = array();$n=0;} |
|
| 385 | + if ($n++ > 100) {$mem = array(); $n = 0; } |
|
| 386 | 386 | |
| 387 | - $dec = date("Y-m-d",_sqlite_func_unix_timestamp($d)); |
|
| 388 | - $mem[$d] = array("Y"=>substr($dec,0,4),"m"=>substr($dec,5,2),"d"=>substr($dec,8,2)); |
|
| 387 | + $dec = date("Y-m-d", _sqlite_func_unix_timestamp($d)); |
|
| 388 | + $mem[$d] = array("Y"=>substr($dec, 0, 4), "m"=>substr($dec, 5, 2), "d"=>substr($dec, 8, 2)); |
|
| 389 | 389 | return $mem[$d][$quoi]; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | // http://doc.spip.org/@_sqlite_func_vide |
| 393 | -function _sqlite_func_vide(){ |
|
| 393 | +function _sqlite_func_vide() { |
|
| 394 | 394 | return; |
| 395 | 395 | } |
| 396 | 396 | |
@@ -96,6 +96,9 @@ discard block |
||
| 96 | 96 | : xml_entites_html($data); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | +/** |
|
| 100 | + * @param IndenteurXML $phraseur |
|
| 101 | + */ |
|
| 99 | 102 | function xml_piElement($phraseur, $target, $data) |
| 100 | 103 | { |
| 101 | 104 | $depth = $phraseur->depth; |
@@ -113,6 +116,9 @@ discard block |
||
| 113 | 116 | |
| 114 | 117 | |
| 115 | 118 | // http://doc.spip.org/@xml_defautElement |
| 119 | +/** |
|
| 120 | + * @param IndenteurXML $phraseur |
|
| 121 | + */ |
|
| 116 | 122 | function xml_defaultElement($phraseur, $data) |
| 117 | 123 | { |
| 118 | 124 | $depth = $phraseur->depth; |
@@ -144,6 +150,9 @@ discard block |
||
| 144 | 150 | } |
| 145 | 151 | |
| 146 | 152 | // http://doc.spip.org/@coordonnees_erreur |
| 153 | +/** |
|
| 154 | + * @param string $msg |
|
| 155 | + */ |
|
| 147 | 156 | function coordonnees_erreur($phraseur, $msg) |
| 148 | 157 | { |
| 149 | 158 | $entete_length = substr_count($phraseur->entete,"\n"); |
@@ -21,207 +21,207 @@ discard block |
||
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | 23 | function xml_entites_html($texte){ |
| 24 | - if (!is_string($texte) OR !$texte |
|
| 25 | - OR strpbrk($texte, "&\"'<>")==false |
|
| 26 | - ) return $texte; |
|
| 27 | - |
|
| 28 | - if (!function_exists('spip_htmlspecialchars')) |
|
| 29 | - include_spip("inc/filtres_mini"); |
|
| 30 | - $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 31 | - return $texte; |
|
| 24 | + if (!is_string($texte) OR !$texte |
|
| 25 | + OR strpbrk($texte, "&\"'<>")==false |
|
| 26 | + ) return $texte; |
|
| 27 | + |
|
| 28 | + if (!function_exists('spip_htmlspecialchars')) |
|
| 29 | + include_spip("inc/filtres_mini"); |
|
| 30 | + $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 31 | + return $texte; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // http://doc.spip.org/@xml_debutElement |
| 35 | 35 | function xml_debutElement($phraseur, $name, $attrs) |
| 36 | 36 | { |
| 37 | - $depth = $phraseur->depth; |
|
| 38 | - |
|
| 39 | - $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 40 | - // espace initial signifie: deja integree au resultat |
|
| 41 | - if ($t[0] != ' ') |
|
| 42 | - { |
|
| 43 | - $phraseur->res .= '<' . $t . '>'; |
|
| 44 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 45 | - } |
|
| 46 | - $t = $phraseur->contenu[$depth]; |
|
| 47 | - // n'indenter que s'il y a un separateur avant |
|
| 48 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 49 | - $phraseur->contenu[$depth] = ""; |
|
| 50 | - $att = ''; |
|
| 51 | - $sep = ' '; |
|
| 52 | - foreach ($attrs as $k => $v) { |
|
| 53 | - $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 54 | - $val = xml_entites_html($v); |
|
| 55 | - $att .= $sep . $k . "=" . $delim |
|
| 56 | - . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 57 | - . $delim; |
|
| 58 | - $sep = "\n $depth"; |
|
| 59 | - } |
|
| 60 | - $phraseur->depth .= ' '; |
|
| 61 | - $phraseur->contenu[$phraseur->depth] = ""; |
|
| 62 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 63 | - $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 37 | + $depth = $phraseur->depth; |
|
| 38 | + |
|
| 39 | + $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 40 | + // espace initial signifie: deja integree au resultat |
|
| 41 | + if ($t[0] != ' ') |
|
| 42 | + { |
|
| 43 | + $phraseur->res .= '<' . $t . '>'; |
|
| 44 | + $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 45 | + } |
|
| 46 | + $t = $phraseur->contenu[$depth]; |
|
| 47 | + // n'indenter que s'il y a un separateur avant |
|
| 48 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 49 | + $phraseur->contenu[$depth] = ""; |
|
| 50 | + $att = ''; |
|
| 51 | + $sep = ' '; |
|
| 52 | + foreach ($attrs as $k => $v) { |
|
| 53 | + $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 54 | + $val = xml_entites_html($v); |
|
| 55 | + $att .= $sep . $k . "=" . $delim |
|
| 56 | + . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 57 | + . $delim; |
|
| 58 | + $sep = "\n $depth"; |
|
| 59 | + } |
|
| 60 | + $phraseur->depth .= ' '; |
|
| 61 | + $phraseur->contenu[$phraseur->depth] = ""; |
|
| 62 | + $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 63 | + $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // http://doc.spip.org/@xml_finElement |
| 67 | 67 | function xml_finElement($phraseur, $name, $fusion_bal=false) |
| 68 | 68 | { |
| 69 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 70 | - |
|
| 71 | - if ($ouv[0] != ' ') |
|
| 72 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 73 | - else $ouv= ""; |
|
| 74 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 75 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 76 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 77 | - |
|
| 78 | - // fusion <balise></balise> en <balise />. |
|
| 79 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 80 | - // en particulier pour les balises Script et A. |
|
| 81 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 82 | - // (param fusion_bal) |
|
| 83 | - |
|
| 84 | - if ($t || (($ouv != $name) AND !$fusion_bal)) |
|
| 85 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 86 | - else |
|
| 87 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 69 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 70 | + |
|
| 71 | + if ($ouv[0] != ' ') |
|
| 72 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 73 | + else $ouv= ""; |
|
| 74 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 75 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 76 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 77 | + |
|
| 78 | + // fusion <balise></balise> en <balise />. |
|
| 79 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 80 | + // en particulier pour les balises Script et A. |
|
| 81 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 82 | + // (param fusion_bal) |
|
| 83 | + |
|
| 84 | + if ($t || (($ouv != $name) AND !$fusion_bal)) |
|
| 85 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 86 | + else |
|
| 87 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // http://doc.spip.org/@xml_textElement |
| 91 | 91 | function xml_textElement($phraseur, $data) |
| 92 | 92 | { |
| 93 | - $depth = $phraseur->depth; |
|
| 94 | - $phraseur->contenu[$depth] .= preg_match('/^script/',$phraseur->ouvrant[$depth]) |
|
| 95 | - ? $data |
|
| 96 | - : xml_entites_html($data); |
|
| 93 | + $depth = $phraseur->depth; |
|
| 94 | + $phraseur->contenu[$depth] .= preg_match('/^script/',$phraseur->ouvrant[$depth]) |
|
| 95 | + ? $data |
|
| 96 | + : xml_entites_html($data); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | function xml_piElement($phraseur, $target, $data) |
| 100 | 100 | { |
| 101 | - $depth = $phraseur->depth; |
|
| 102 | - |
|
| 103 | - if (strtolower($target) != "php") |
|
| 104 | - $phraseur->contenu[$depth] .= $data; |
|
| 105 | - else { |
|
| 106 | - ob_start(); |
|
| 107 | - eval($data); |
|
| 108 | - $data = ob_get_contents(); |
|
| 109 | - ob_end_clean(); |
|
| 110 | - $phraseur->contenu[$depth] .= $data; |
|
| 111 | - } |
|
| 101 | + $depth = $phraseur->depth; |
|
| 102 | + |
|
| 103 | + if (strtolower($target) != "php") |
|
| 104 | + $phraseur->contenu[$depth] .= $data; |
|
| 105 | + else { |
|
| 106 | + ob_start(); |
|
| 107 | + eval($data); |
|
| 108 | + $data = ob_get_contents(); |
|
| 109 | + ob_end_clean(); |
|
| 110 | + $phraseur->contenu[$depth] .= $data; |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | // http://doc.spip.org/@xml_defautElement |
| 116 | 116 | function xml_defaultElement($phraseur, $data) |
| 117 | 117 | { |
| 118 | - $depth = $phraseur->depth; |
|
| 118 | + $depth = $phraseur->depth; |
|
| 119 | 119 | |
| 120 | - if (!isset($phraseur->contenu[$depth])) $phraseur->contenu[$depth]=''; |
|
| 121 | - $phraseur->contenu[$depth] .= $data; |
|
| 120 | + if (!isset($phraseur->contenu[$depth])) $phraseur->contenu[$depth]=''; |
|
| 121 | + $phraseur->contenu[$depth] .= $data; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // http://doc.spip.org/@xml_parsestring |
| 125 | 125 | function xml_parsestring($phraseur, $data) |
| 126 | 126 | { |
| 127 | - $phraseur->contenu[$phraseur->depth] =''; |
|
| 128 | - |
|
| 129 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 130 | - coordonnees_erreur($phraseur, |
|
| 131 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 132 | - . "<br />\n" . |
|
| 133 | - (!$phraseur->depth ? '' : |
|
| 134 | - ('(' . |
|
| 135 | - _T('erreur_balise_non_fermee') . |
|
| 136 | - " <tt>" . |
|
| 137 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 138 | - "</tt> " . |
|
| 139 | - _T('ligne') . |
|
| 140 | - " " . |
|
| 141 | - $phraseur->reperes[$phraseur->depth] . |
|
| 142 | - ") <br />\n" ))); |
|
| 143 | - } |
|
| 127 | + $phraseur->contenu[$phraseur->depth] =''; |
|
| 128 | + |
|
| 129 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 130 | + coordonnees_erreur($phraseur, |
|
| 131 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 132 | + . "<br />\n" . |
|
| 133 | + (!$phraseur->depth ? '' : |
|
| 134 | + ('(' . |
|
| 135 | + _T('erreur_balise_non_fermee') . |
|
| 136 | + " <tt>" . |
|
| 137 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 138 | + "</tt> " . |
|
| 139 | + _T('ligne') . |
|
| 140 | + " " . |
|
| 141 | + $phraseur->reperes[$phraseur->depth] . |
|
| 142 | + ") <br />\n" ))); |
|
| 143 | + } |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // http://doc.spip.org/@coordonnees_erreur |
| 147 | 147 | function coordonnees_erreur($phraseur, $msg) |
| 148 | 148 | { |
| 149 | - $entete_length = substr_count($phraseur->entete,"\n"); |
|
| 150 | - $phraseur->err[] = array($msg, |
|
| 151 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 152 | - xml_get_current_column_number($phraseur->sax)); |
|
| 149 | + $entete_length = substr_count($phraseur->entete,"\n"); |
|
| 150 | + $phraseur->err[] = array($msg, |
|
| 151 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 152 | + xml_get_current_column_number($phraseur->sax)); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // http://doc.spip.org/@xml_sax_dist |
| 156 | 156 | function xml_sax_dist($page, $apply=false, $phraseur=NULL, $doctype='', $charset=null) |
| 157 | 157 | { |
| 158 | - if (is_null($charset)) |
|
| 159 | - $charset = $GLOBALS['meta']['charset']; |
|
| 160 | - if ($apply) { |
|
| 161 | - ob_start(); |
|
| 162 | - if (is_array($apply)) |
|
| 163 | - $r = call_user_func_array($page, $apply); |
|
| 164 | - else $r = $page(); |
|
| 165 | - $page = ob_get_contents(); |
|
| 166 | - ob_end_clean(); |
|
| 167 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 168 | - if (!$page) $page = $r; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if (!$page) return ''; |
|
| 172 | - // charger la DTD et transcoder les entites, |
|
| 173 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 174 | - if (!$doctype) { |
|
| 175 | - if (!$r = analyser_doctype($page)) { |
|
| 176 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 177 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 178 | - $r = analyser_doctype($page); |
|
| 179 | - } |
|
| 180 | - list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 181 | - $page = substr($page,strlen($entete)); |
|
| 182 | - } else { |
|
| 183 | - $avail = 'SYSTEM'; |
|
| 184 | - $grammaire = $doctype; |
|
| 185 | - $rotlvl = basename($grammaire); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - include_spip('xml/analyser_dtd'); |
|
| 189 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 190 | - $page = sax_bug($page, $dtc, $charset); |
|
| 191 | - |
|
| 192 | - // compatibilite Tidy espace public |
|
| 193 | - if (!$phraseur) { |
|
| 194 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 195 | - return $indenter_xml($page, $apply); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $xml_parser = xml_parser_create($charset); |
|
| 199 | - |
|
| 200 | - xml_set_element_handler($xml_parser, |
|
| 201 | - array($phraseur, "debutElement"), |
|
| 202 | - array($phraseur, "finElement")); |
|
| 203 | - |
|
| 204 | - xml_set_character_data_handler($xml_parser, |
|
| 205 | - array($phraseur, "textElement")); |
|
| 206 | - |
|
| 207 | - xml_set_processing_instruction_handler($xml_parser, |
|
| 208 | - array($phraseur, 'piElement')); |
|
| 209 | - |
|
| 210 | - xml_set_default_handler($xml_parser, |
|
| 211 | - array($phraseur, "defaultElement")); |
|
| 212 | - |
|
| 213 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 214 | - |
|
| 215 | - $phraseur->sax = $xml_parser; |
|
| 216 | - if (isset($entete)) { |
|
| 217 | - $phraseur->entete = $entete; |
|
| 218 | - } |
|
| 219 | - $phraseur->page = $page; |
|
| 220 | - $phraseur->dtc = $dtc; |
|
| 221 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 222 | - xml_parser_free($xml_parser); |
|
| 223 | - $phraseur->sax = ''; |
|
| 224 | - return $phraseur; |
|
| 158 | + if (is_null($charset)) |
|
| 159 | + $charset = $GLOBALS['meta']['charset']; |
|
| 160 | + if ($apply) { |
|
| 161 | + ob_start(); |
|
| 162 | + if (is_array($apply)) |
|
| 163 | + $r = call_user_func_array($page, $apply); |
|
| 164 | + else $r = $page(); |
|
| 165 | + $page = ob_get_contents(); |
|
| 166 | + ob_end_clean(); |
|
| 167 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 168 | + if (!$page) $page = $r; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if (!$page) return ''; |
|
| 172 | + // charger la DTD et transcoder les entites, |
|
| 173 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 174 | + if (!$doctype) { |
|
| 175 | + if (!$r = analyser_doctype($page)) { |
|
| 176 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 177 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 178 | + $r = analyser_doctype($page); |
|
| 179 | + } |
|
| 180 | + list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 181 | + $page = substr($page,strlen($entete)); |
|
| 182 | + } else { |
|
| 183 | + $avail = 'SYSTEM'; |
|
| 184 | + $grammaire = $doctype; |
|
| 185 | + $rotlvl = basename($grammaire); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + include_spip('xml/analyser_dtd'); |
|
| 189 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 190 | + $page = sax_bug($page, $dtc, $charset); |
|
| 191 | + |
|
| 192 | + // compatibilite Tidy espace public |
|
| 193 | + if (!$phraseur) { |
|
| 194 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 195 | + return $indenter_xml($page, $apply); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $xml_parser = xml_parser_create($charset); |
|
| 199 | + |
|
| 200 | + xml_set_element_handler($xml_parser, |
|
| 201 | + array($phraseur, "debutElement"), |
|
| 202 | + array($phraseur, "finElement")); |
|
| 203 | + |
|
| 204 | + xml_set_character_data_handler($xml_parser, |
|
| 205 | + array($phraseur, "textElement")); |
|
| 206 | + |
|
| 207 | + xml_set_processing_instruction_handler($xml_parser, |
|
| 208 | + array($phraseur, 'piElement')); |
|
| 209 | + |
|
| 210 | + xml_set_default_handler($xml_parser, |
|
| 211 | + array($phraseur, "defaultElement")); |
|
| 212 | + |
|
| 213 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 214 | + |
|
| 215 | + $phraseur->sax = $xml_parser; |
|
| 216 | + if (isset($entete)) { |
|
| 217 | + $phraseur->entete = $entete; |
|
| 218 | + } |
|
| 219 | + $phraseur->page = $page; |
|
| 220 | + $phraseur->dtc = $dtc; |
|
| 221 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 222 | + xml_parser_free($xml_parser); |
|
| 223 | + $phraseur->sax = ''; |
|
| 224 | + return $phraseur; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -234,21 +234,21 @@ discard block |
||
| 234 | 234 | // http://doc.spip.org/@sax_bug |
| 235 | 235 | function sax_bug($data, $dtc, $charset=null) |
| 236 | 236 | { |
| 237 | - if (is_null($charset)) |
|
| 238 | - $charset = $GLOBALS['meta']['charset']; |
|
| 237 | + if (is_null($charset)) |
|
| 238 | + $charset = $GLOBALS['meta']['charset']; |
|
| 239 | 239 | |
| 240 | - if ($dtc) { |
|
| 241 | - $trans = array(); |
|
| 240 | + if ($dtc) { |
|
| 241 | + $trans = array(); |
|
| 242 | 242 | |
| 243 | - foreach($dtc->entites as $k => $v) { |
|
| 244 | - if (!strpos(" amp lt gt quot ", $k)) |
|
| 245 | - $trans["&$k;"] = $v; |
|
| 246 | - } |
|
| 247 | - $data = strtr($data, $trans); |
|
| 248 | - } else { |
|
| 249 | - $data = html2unicode($data, true); |
|
| 250 | - } |
|
| 251 | - return unicode2charset($data, $charset); |
|
| 243 | + foreach($dtc->entites as $k => $v) { |
|
| 244 | + if (!strpos(" amp lt gt quot ", $k)) |
|
| 245 | + $trans["&$k;"] = $v; |
|
| 246 | + } |
|
| 247 | + $data = strtr($data, $trans); |
|
| 248 | + } else { |
|
| 249 | + $data = html2unicode($data, true); |
|
| 250 | + } |
|
| 251 | + return unicode2charset($data, $charset); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -260,42 +260,42 @@ discard block |
||
| 260 | 260 | // http://doc.spip.org/@analyser_doctype |
| 261 | 261 | function analyser_doctype($data) |
| 262 | 262 | { |
| 263 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 264 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 265 | - list(,$entete, $topelement) = $page; |
|
| 266 | - if ($topelement == 'rss') |
|
| 267 | - return array($entete, 'PUBLIC', |
|
| 268 | - _DOCTYPE_RSS, |
|
| 269 | - 'rss-0.91.dtd'); |
|
| 270 | - else { |
|
| 271 | - $dtd = $topelement . '.dtd'; |
|
| 272 | - $f = find_in_path($dtd); |
|
| 273 | - if (file_exists($f)) |
|
| 274 | - return array($entete, 'SYSTEM', $f, $dtd); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 278 | - return array(); |
|
| 279 | - } |
|
| 280 | - list($entete,, $topelement, $avail,$suite) = $page; |
|
| 281 | - |
|
| 282 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) |
|
| 283 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) |
|
| 284 | - return array(); |
|
| 285 | - list(,$rotlvl, $suite) = $r; |
|
| 286 | - |
|
| 287 | - if (!$suite) { |
|
| 288 | - if ($avail != 'SYSTEM') return array(); |
|
| 289 | - $grammaire = $rotlvl; |
|
| 290 | - $rotlvl = ''; |
|
| 291 | - } else { |
|
| 292 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) |
|
| 293 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) |
|
| 294 | - return array(); |
|
| 295 | - |
|
| 296 | - $grammaire = $r[1]; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return array($entete, $avail, $grammaire, $rotlvl); |
|
| 263 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 264 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 265 | + list(,$entete, $topelement) = $page; |
|
| 266 | + if ($topelement == 'rss') |
|
| 267 | + return array($entete, 'PUBLIC', |
|
| 268 | + _DOCTYPE_RSS, |
|
| 269 | + 'rss-0.91.dtd'); |
|
| 270 | + else { |
|
| 271 | + $dtd = $topelement . '.dtd'; |
|
| 272 | + $f = find_in_path($dtd); |
|
| 273 | + if (file_exists($f)) |
|
| 274 | + return array($entete, 'SYSTEM', $f, $dtd); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 278 | + return array(); |
|
| 279 | + } |
|
| 280 | + list($entete,, $topelement, $avail,$suite) = $page; |
|
| 281 | + |
|
| 282 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) |
|
| 283 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) |
|
| 284 | + return array(); |
|
| 285 | + list(,$rotlvl, $suite) = $r; |
|
| 286 | + |
|
| 287 | + if (!$suite) { |
|
| 288 | + if ($avail != 'SYSTEM') return array(); |
|
| 289 | + $grammaire = $rotlvl; |
|
| 290 | + $rotlvl = ''; |
|
| 291 | + } else { |
|
| 292 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) |
|
| 293 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) |
|
| 294 | + return array(); |
|
| 295 | + |
|
| 296 | + $grammaire = $r[1]; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return array($entete, $avail, $grammaire, $rotlvl); |
|
| 300 | 300 | } |
| 301 | 301 | ?> |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | * @param string $texte |
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | -function xml_entites_html($texte){ |
|
| 23 | +function xml_entites_html($texte) { |
|
| 24 | 24 | if (!is_string($texte) OR !$texte |
| 25 | - OR strpbrk($texte, "&\"'<>")==false |
|
| 25 | + OR strpbrk($texte, "&\"'<>") == false |
|
| 26 | 26 | ) return $texte; |
| 27 | 27 | |
| 28 | 28 | if (!function_exists('spip_htmlspecialchars')) |
| 29 | 29 | include_spip("inc/filtres_mini"); |
| 30 | - $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
|
| 30 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 31 | 31 | return $texte; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -40,40 +40,40 @@ discard block |
||
| 40 | 40 | // espace initial signifie: deja integree au resultat |
| 41 | 41 | if ($t[0] != ' ') |
| 42 | 42 | { |
| 43 | - $phraseur->res .= '<' . $t . '>'; |
|
| 44 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 43 | + $phraseur->res .= '<'.$t.'>'; |
|
| 44 | + $phraseur->ouvrant[$depth] = ' '.$t; |
|
| 45 | 45 | } |
| 46 | 46 | $t = $phraseur->contenu[$depth]; |
| 47 | 47 | // n'indenter que s'il y a un separateur avant |
| 48 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 48 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 49 | 49 | $phraseur->contenu[$depth] = ""; |
| 50 | 50 | $att = ''; |
| 51 | 51 | $sep = ' '; |
| 52 | 52 | foreach ($attrs as $k => $v) { |
| 53 | 53 | $delim = strpos($v, "'") === false ? "'" : '"'; |
| 54 | 54 | $val = xml_entites_html($v); |
| 55 | - $att .= $sep . $k . "=" . $delim |
|
| 55 | + $att .= $sep.$k."=".$delim |
|
| 56 | 56 | . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
| 57 | 57 | . $delim; |
| 58 | 58 | $sep = "\n $depth"; |
| 59 | 59 | } |
| 60 | 60 | $phraseur->depth .= ' '; |
| 61 | 61 | $phraseur->contenu[$phraseur->depth] = ""; |
| 62 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 62 | + $phraseur->ouvrant[$phraseur->depth] = $name.$att; |
|
| 63 | 63 | $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // http://doc.spip.org/@xml_finElement |
| 67 | -function xml_finElement($phraseur, $name, $fusion_bal=false) |
|
| 67 | +function xml_finElement($phraseur, $name, $fusion_bal = false) |
|
| 68 | 68 | { |
| 69 | 69 | $ouv = $phraseur->ouvrant[$phraseur->depth]; |
| 70 | 70 | |
| 71 | 71 | if ($ouv[0] != ' ') |
| 72 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 73 | - else $ouv= ""; |
|
| 72 | + $phraseur->ouvrant[$phraseur->depth] = ' '.$ouv; |
|
| 73 | + else $ouv = ""; |
|
| 74 | 74 | $t = $phraseur->contenu[$phraseur->depth]; |
| 75 | 75 | $phraseur->depth = substr($phraseur->depth, 2); |
| 76 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 76 | + $t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t); |
|
| 77 | 77 | |
| 78 | 78 | // fusion <balise></balise> en <balise />. |
| 79 | 79 | // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | // (param fusion_bal) |
| 83 | 83 | |
| 84 | 84 | if ($t || (($ouv != $name) AND !$fusion_bal)) |
| 85 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 85 | + $phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t."</".$name.">"; |
|
| 86 | 86 | else |
| 87 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 87 | + $phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ("</".$name.">")); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // http://doc.spip.org/@xml_textElement |
| 91 | 91 | function xml_textElement($phraseur, $data) |
| 92 | 92 | { |
| 93 | 93 | $depth = $phraseur->depth; |
| 94 | - $phraseur->contenu[$depth] .= preg_match('/^script/',$phraseur->ouvrant[$depth]) |
|
| 94 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 95 | 95 | ? $data |
| 96 | 96 | : xml_entites_html($data); |
| 97 | 97 | } |
@@ -117,43 +117,42 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $depth = $phraseur->depth; |
| 119 | 119 | |
| 120 | - if (!isset($phraseur->contenu[$depth])) $phraseur->contenu[$depth]=''; |
|
| 120 | + if (!isset($phraseur->contenu[$depth])) $phraseur->contenu[$depth] = ''; |
|
| 121 | 121 | $phraseur->contenu[$depth] .= $data; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // http://doc.spip.org/@xml_parsestring |
| 125 | 125 | function xml_parsestring($phraseur, $data) |
| 126 | 126 | { |
| 127 | - $phraseur->contenu[$phraseur->depth] =''; |
|
| 127 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 128 | 128 | |
| 129 | 129 | if (!xml_parse($phraseur->sax, $data, true)) { |
| 130 | 130 | coordonnees_erreur($phraseur, |
| 131 | 131 | xml_error_string(xml_get_error_code($phraseur->sax)) |
| 132 | - . "<br />\n" . |
|
| 133 | - (!$phraseur->depth ? '' : |
|
| 134 | - ('(' . |
|
| 135 | - _T('erreur_balise_non_fermee') . |
|
| 136 | - " <tt>" . |
|
| 137 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 138 | - "</tt> " . |
|
| 139 | - _T('ligne') . |
|
| 140 | - " " . |
|
| 141 | - $phraseur->reperes[$phraseur->depth] . |
|
| 142 | - ") <br />\n" ))); |
|
| 132 | + . "<br />\n". |
|
| 133 | + (!$phraseur->depth ? '' : ('('. |
|
| 134 | + _T('erreur_balise_non_fermee'). |
|
| 135 | + " <tt>". |
|
| 136 | + $phraseur->ouvrant[$phraseur->depth]. |
|
| 137 | + "</tt> ". |
|
| 138 | + _T('ligne'). |
|
| 139 | + " ". |
|
| 140 | + $phraseur->reperes[$phraseur->depth]. |
|
| 141 | + ") <br />\n"))); |
|
| 143 | 142 | } |
| 144 | 143 | } |
| 145 | 144 | |
| 146 | 145 | // http://doc.spip.org/@coordonnees_erreur |
| 147 | 146 | function coordonnees_erreur($phraseur, $msg) |
| 148 | 147 | { |
| 149 | - $entete_length = substr_count($phraseur->entete,"\n"); |
|
| 148 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 150 | 149 | $phraseur->err[] = array($msg, |
| 151 | 150 | xml_get_current_line_number($phraseur->sax) + $entete_length, |
| 152 | 151 | xml_get_current_column_number($phraseur->sax)); |
| 153 | 152 | } |
| 154 | 153 | |
| 155 | 154 | // http://doc.spip.org/@xml_sax_dist |
| 156 | -function xml_sax_dist($page, $apply=false, $phraseur=NULL, $doctype='', $charset=null) |
|
| 155 | +function xml_sax_dist($page, $apply = false, $phraseur = NULL, $doctype = '', $charset = null) |
|
| 157 | 156 | { |
| 158 | 157 | if (is_null($charset)) |
| 159 | 158 | $charset = $GLOBALS['meta']['charset']; |
@@ -173,12 +172,12 @@ discard block |
||
| 173 | 172 | // et escamoter le doctype que sax mange en php5 mais pas en php4 |
| 174 | 173 | if (!$doctype) { |
| 175 | 174 | if (!$r = analyser_doctype($page)) { |
| 176 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 175 | + $page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE |
|
| 177 | 176 | . preg_replace(_REGEXP_DOCTYPE, '', $page); |
| 178 | - $r = analyser_doctype($page); |
|
| 177 | + $r = analyser_doctype($page); |
|
| 179 | 178 | } |
| 180 | 179 | list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
| 181 | - $page = substr($page,strlen($entete)); |
|
| 180 | + $page = substr($page, strlen($entete)); |
|
| 182 | 181 | } else { |
| 183 | 182 | $avail = 'SYSTEM'; |
| 184 | 183 | $grammaire = $doctype; |
@@ -232,7 +231,7 @@ discard block |
||
| 232 | 231 | // sinon on se rabat sur ce qu'en connait SPIP en standard. |
| 233 | 232 | |
| 234 | 233 | // http://doc.spip.org/@sax_bug |
| 235 | -function sax_bug($data, $dtc, $charset=null) |
|
| 234 | +function sax_bug($data, $dtc, $charset = null) |
|
| 236 | 235 | { |
| 237 | 236 | if (is_null($charset)) |
| 238 | 237 | $charset = $GLOBALS['meta']['charset']; |
@@ -240,7 +239,7 @@ discard block |
||
| 240 | 239 | if ($dtc) { |
| 241 | 240 | $trans = array(); |
| 242 | 241 | |
| 243 | - foreach($dtc->entites as $k => $v) { |
|
| 242 | + foreach ($dtc->entites as $k => $v) { |
|
| 244 | 243 | if (!strpos(" amp lt gt quot ", $k)) |
| 245 | 244 | $trans["&$k;"] = $v; |
| 246 | 245 | } |
@@ -268,16 +267,16 @@ discard block |
||
| 268 | 267 | _DOCTYPE_RSS, |
| 269 | 268 | 'rss-0.91.dtd'); |
| 270 | 269 | else { |
| 271 | - $dtd = $topelement . '.dtd'; |
|
| 270 | + $dtd = $topelement.'.dtd'; |
|
| 272 | 271 | $f = find_in_path($dtd); |
| 273 | 272 | if (file_exists($f)) |
| 274 | 273 | return array($entete, 'SYSTEM', $f, $dtd); |
| 275 | 274 | } |
| 276 | 275 | } |
| 277 | - spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 276 | + spip_log("Dtd pas vu pour ".substr($data, 0, 100)); |
|
| 278 | 277 | return array(); |
| 279 | 278 | } |
| 280 | - list($entete,, $topelement, $avail,$suite) = $page; |
|
| 279 | + list($entete,, $topelement, $avail, $suite) = $page; |
|
| 281 | 280 | |
| 282 | 281 | if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) |
| 283 | 282 | if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/charsets'); |
| 16 | 18 | include_spip('xml/interfaces'); |
@@ -23,10 +25,13 @@ discard block |
||
| 23 | 25 | function xml_entites_html($texte){ |
| 24 | 26 | if (!is_string($texte) OR !$texte |
| 25 | 27 | OR strpbrk($texte, "&\"'<>")==false |
| 26 | - ) return $texte; |
|
| 28 | + ) { |
|
| 29 | + return $texte; |
|
| 30 | + } |
|
| 27 | 31 | |
| 28 | - if (!function_exists('spip_htmlspecialchars')) |
|
| 29 | - include_spip("inc/filtres_mini"); |
|
| 32 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 33 | + include_spip("inc/filtres_mini"); |
|
| 34 | + } |
|
| 30 | 35 | $texte = spip_htmlspecialchars($texte,ENT_QUOTES); |
| 31 | 36 | return $texte; |
| 32 | 37 | } |
@@ -68,9 +73,11 @@ discard block |
||
| 68 | 73 | { |
| 69 | 74 | $ouv = $phraseur->ouvrant[$phraseur->depth]; |
| 70 | 75 | |
| 71 | - if ($ouv[0] != ' ') |
|
| 72 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 73 | - else $ouv= ""; |
|
| 76 | + if ($ouv[0] != ' ') { |
|
| 77 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 78 | + } else { |
|
| 79 | + $ouv= ""; |
|
| 80 | + } |
|
| 74 | 81 | $t = $phraseur->contenu[$phraseur->depth]; |
| 75 | 82 | $phraseur->depth = substr($phraseur->depth, 2); |
| 76 | 83 | $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
@@ -81,11 +88,12 @@ discard block |
||
| 81 | 88 | // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
| 82 | 89 | // (param fusion_bal) |
| 83 | 90 | |
| 84 | - if ($t || (($ouv != $name) AND !$fusion_bal)) |
|
| 85 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 86 | - else |
|
| 87 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 88 | -} |
|
| 91 | + if ($t || (($ouv != $name) AND !$fusion_bal)) { |
|
| 92 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 93 | + } else { |
|
| 94 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 95 | + } |
|
| 96 | + } |
|
| 89 | 97 | |
| 90 | 98 | // http://doc.spip.org/@xml_textElement |
| 91 | 99 | function xml_textElement($phraseur, $data) |
@@ -100,9 +108,9 @@ discard block |
||
| 100 | 108 | { |
| 101 | 109 | $depth = $phraseur->depth; |
| 102 | 110 | |
| 103 | - if (strtolower($target) != "php") |
|
| 104 | - $phraseur->contenu[$depth] .= $data; |
|
| 105 | - else { |
|
| 111 | + if (strtolower($target) != "php") { |
|
| 112 | + $phraseur->contenu[$depth] .= $data; |
|
| 113 | + } else { |
|
| 106 | 114 | ob_start(); |
| 107 | 115 | eval($data); |
| 108 | 116 | $data = ob_get_contents(); |
@@ -117,7 +125,9 @@ discard block |
||
| 117 | 125 | { |
| 118 | 126 | $depth = $phraseur->depth; |
| 119 | 127 | |
| 120 | - if (!isset($phraseur->contenu[$depth])) $phraseur->contenu[$depth]=''; |
|
| 128 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 129 | + $phraseur->contenu[$depth]=''; |
|
| 130 | + } |
|
| 121 | 131 | $phraseur->contenu[$depth] .= $data; |
| 122 | 132 | } |
| 123 | 133 | |
@@ -155,20 +165,27 @@ discard block |
||
| 155 | 165 | // http://doc.spip.org/@xml_sax_dist |
| 156 | 166 | function xml_sax_dist($page, $apply=false, $phraseur=NULL, $doctype='', $charset=null) |
| 157 | 167 | { |
| 158 | - if (is_null($charset)) |
|
| 159 | - $charset = $GLOBALS['meta']['charset']; |
|
| 168 | + if (is_null($charset)) { |
|
| 169 | + $charset = $GLOBALS['meta']['charset']; |
|
| 170 | + } |
|
| 160 | 171 | if ($apply) { |
| 161 | 172 | ob_start(); |
| 162 | - if (is_array($apply)) |
|
| 163 | - $r = call_user_func_array($page, $apply); |
|
| 164 | - else $r = $page(); |
|
| 173 | + if (is_array($apply)) { |
|
| 174 | + $r = call_user_func_array($page, $apply); |
|
| 175 | + } else { |
|
| 176 | + $r = $page(); |
|
| 177 | + } |
|
| 165 | 178 | $page = ob_get_contents(); |
| 166 | 179 | ob_end_clean(); |
| 167 | 180 | // fonction sans aucun "echo", ca doit etre le resultat |
| 168 | - if (!$page) $page = $r; |
|
| 181 | + if (!$page) { |
|
| 182 | + $page = $r; |
|
| 183 | + } |
|
| 169 | 184 | } |
| 170 | 185 | |
| 171 | - if (!$page) return ''; |
|
| 186 | + if (!$page) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 172 | 189 | // charger la DTD et transcoder les entites, |
| 173 | 190 | // et escamoter le doctype que sax mange en php5 mais pas en php4 |
| 174 | 191 | if (!$doctype) { |
@@ -234,15 +251,17 @@ discard block |
||
| 234 | 251 | // http://doc.spip.org/@sax_bug |
| 235 | 252 | function sax_bug($data, $dtc, $charset=null) |
| 236 | 253 | { |
| 237 | - if (is_null($charset)) |
|
| 238 | - $charset = $GLOBALS['meta']['charset']; |
|
| 254 | + if (is_null($charset)) { |
|
| 255 | + $charset = $GLOBALS['meta']['charset']; |
|
| 256 | + } |
|
| 239 | 257 | |
| 240 | 258 | if ($dtc) { |
| 241 | 259 | $trans = array(); |
| 242 | 260 | |
| 243 | 261 | foreach($dtc->entites as $k => $v) { |
| 244 | - if (!strpos(" amp lt gt quot ", $k)) |
|
| 245 | - $trans["&$k;"] = $v; |
|
| 262 | + if (!strpos(" amp lt gt quot ", $k)) { |
|
| 263 | + $trans["&$k;"] = $v; |
|
| 264 | + } |
|
| 246 | 265 | } |
| 247 | 266 | $data = strtr($data, $trans); |
| 248 | 267 | } else { |
@@ -263,15 +282,16 @@ discard block |
||
| 263 | 282 | if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
| 264 | 283 | if (preg_match(_REGEXP_XML, $data, $page)) { |
| 265 | 284 | list(,$entete, $topelement) = $page; |
| 266 | - if ($topelement == 'rss') |
|
| 267 | - return array($entete, 'PUBLIC', |
|
| 285 | + if ($topelement == 'rss') { |
|
| 286 | + return array($entete, 'PUBLIC', |
|
| 268 | 287 | _DOCTYPE_RSS, |
| 269 | 288 | 'rss-0.91.dtd'); |
| 270 | - else { |
|
| 289 | + } else { |
|
| 271 | 290 | $dtd = $topelement . '.dtd'; |
| 272 | 291 | $f = find_in_path($dtd); |
| 273 | - if (file_exists($f)) |
|
| 274 | - return array($entete, 'SYSTEM', $f, $dtd); |
|
| 292 | + if (file_exists($f)) { |
|
| 293 | + return array($entete, 'SYSTEM', $f, $dtd); |
|
| 294 | + } |
|
| 275 | 295 | } |
| 276 | 296 | } |
| 277 | 297 | spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
@@ -279,19 +299,23 @@ discard block |
||
| 279 | 299 | } |
| 280 | 300 | list($entete,, $topelement, $avail,$suite) = $page; |
| 281 | 301 | |
| 282 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) |
|
| 283 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) |
|
| 302 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 303 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) |
|
| 284 | 304 | return array(); |
| 305 | + } |
|
| 285 | 306 | list(,$rotlvl, $suite) = $r; |
| 286 | 307 | |
| 287 | 308 | if (!$suite) { |
| 288 | - if ($avail != 'SYSTEM') return array(); |
|
| 309 | + if ($avail != 'SYSTEM') { |
|
| 310 | + return array(); |
|
| 311 | + } |
|
| 289 | 312 | $grammaire = $rotlvl; |
| 290 | 313 | $rotlvl = ''; |
| 291 | 314 | } else { |
| 292 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) |
|
| 293 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) |
|
| 315 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 316 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) |
|
| 294 | 317 | return array(); |
| 318 | + } |
|
| 295 | 319 | |
| 296 | 320 | $grammaire = $r[1]; |
| 297 | 321 | } |
@@ -80,6 +80,9 @@ |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
| 83 | +/** |
|
| 84 | + * @param string $name |
|
| 85 | + */ |
|
| 83 | 86 | function saisie_langues_utiles($name, $selection) { |
| 84 | 87 | include_spip('inc/lang_liste'); |
| 85 | 88 | $langues = $GLOBALS['codes_langues']; |
@@ -13,44 +13,44 @@ discard block |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | function formulaires_configurer_multilinguisme_charger_dist(){ |
| 16 | - $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
|
| 17 | - foreach(array('multi_objets','gerer_trad_objets') as $m) |
|
| 18 | - $valeurs[$m] = explode(',',isset($GLOBALS['meta'][$m])?$GLOBALS['meta'][$m]:''); |
|
| 16 | + $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
|
| 17 | + foreach(array('multi_objets','gerer_trad_objets') as $m) |
|
| 18 | + $valeurs[$m] = explode(',',isset($GLOBALS['meta'][$m])?$GLOBALS['meta'][$m]:''); |
|
| 19 | 19 | |
| 20 | - if (count($valeurs['multi_objets']) |
|
| 21 | - OR count(explode(',',$GLOBALS['meta']['langues_utilisees'])) > 1) { |
|
| 20 | + if (count($valeurs['multi_objets']) |
|
| 21 | + OR count(explode(',',$GLOBALS['meta']['langues_utilisees'])) > 1) { |
|
| 22 | 22 | |
| 23 | - $selection = (is_null(_request('multi_objets'))?explode(',', $GLOBALS['meta']['langues_multilingue']):_request('langues_auth')); |
|
| 24 | - $valeurs['_langues'] = saisie_langues_utiles('langues_auth',$selection?$selection:array()); |
|
| 25 | - $valeurs['_nb_langues_selection'] = count($selection); |
|
| 26 | - } |
|
| 23 | + $selection = (is_null(_request('multi_objets'))?explode(',', $GLOBALS['meta']['langues_multilingue']):_request('langues_auth')); |
|
| 24 | + $valeurs['_langues'] = saisie_langues_utiles('langues_auth',$selection?$selection:array()); |
|
| 25 | + $valeurs['_nb_langues_selection'] = count($selection); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return $valeurs; |
|
| 28 | + return $valeurs; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | function formulaires_configurer_multilinguisme_traiter_dist(){ |
| 33 | - $res = array('editable'=>true); |
|
| 34 | - // un checkbox seul de name X non coche n'est pas poste. |
|
| 35 | - // on verifie le champ X_check qui indique que la checkbox etait presente dans le formulaire. |
|
| 36 | - foreach(array('multi_secteurs') as $m) { |
|
| 37 | - if (!is_null(_request($m . '_check'))) { |
|
| 38 | - ecrire_meta($m, _request($m) ? 'oui' : 'non'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - foreach(array('multi_objets','gerer_trad_objets') as $m) { |
|
| 42 | - if (!is_null($v=_request($m))) { |
|
| 43 | - // join et enlever la valeur vide '' |
|
| 44 | - ecrire_meta($m, implode(',',array_diff($v,array('')))); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - if ($i = _request('langues_auth') AND is_array($i)) { |
|
| 49 | - $i = array_unique(array_merge($i,explode(',',$GLOBALS['meta']['langues_utilisees']))); |
|
| 50 | - ecrire_meta('langues_multilingue', implode(",",$i)); |
|
| 51 | - } |
|
| 52 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 53 | - return $res; |
|
| 33 | + $res = array('editable'=>true); |
|
| 34 | + // un checkbox seul de name X non coche n'est pas poste. |
|
| 35 | + // on verifie le champ X_check qui indique que la checkbox etait presente dans le formulaire. |
|
| 36 | + foreach(array('multi_secteurs') as $m) { |
|
| 37 | + if (!is_null(_request($m . '_check'))) { |
|
| 38 | + ecrire_meta($m, _request($m) ? 'oui' : 'non'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + foreach(array('multi_objets','gerer_trad_objets') as $m) { |
|
| 42 | + if (!is_null($v=_request($m))) { |
|
| 43 | + // join et enlever la valeur vide '' |
|
| 44 | + ecrire_meta($m, implode(',',array_diff($v,array('')))); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + if ($i = _request('langues_auth') AND is_array($i)) { |
|
| 49 | + $i = array_unique(array_merge($i,explode(',',$GLOBALS['meta']['langues_utilisees']))); |
|
| 50 | + ecrire_meta('langues_multilingue', implode(",",$i)); |
|
| 51 | + } |
|
| 52 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 53 | + return $res; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function table_supporte_lang($table_sql){ |
| 62 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 63 | - $desc = $trouver_table($table_sql); |
|
| 64 | - if (!$desc OR !isset($desc['field']['lang'])) |
|
| 65 | - return ''; |
|
| 66 | - return ' '; |
|
| 62 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 63 | + $desc = $trouver_table($table_sql); |
|
| 64 | + if (!$desc OR !isset($desc['field']['lang'])) |
|
| 65 | + return ''; |
|
| 66 | + return ' '; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -72,64 +72,64 @@ discard block |
||
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | 74 | function table_supporte_trad($table_sql){ |
| 75 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 76 | - $desc = $trouver_table($table_sql); |
|
| 77 | - if (!$desc OR !isset($desc['field']['id_trad'])) |
|
| 78 | - return ''; |
|
| 79 | - return ' '; |
|
| 75 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 76 | + $desc = $trouver_table($table_sql); |
|
| 77 | + if (!$desc OR !isset($desc['field']['id_trad'])) |
|
| 78 | + return ''; |
|
| 79 | + return ' '; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | function saisie_langues_utiles($name, $selection) { |
| 84 | - include_spip('inc/lang_liste'); |
|
| 85 | - $langues = $GLOBALS['codes_langues']; |
|
| 84 | + include_spip('inc/lang_liste'); |
|
| 85 | + $langues = $GLOBALS['codes_langues']; |
|
| 86 | 86 | |
| 87 | - $langues_installees = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 88 | - $langues_trad = array_flip($langues_installees); |
|
| 89 | - |
|
| 90 | - $langues_bloquees = explode(',',$GLOBALS['meta']['langues_utilisees']); |
|
| 91 | - |
|
| 92 | - $res = ""; |
|
| 93 | - |
|
| 94 | - $i = 0; |
|
| 95 | - foreach($langues_bloquees as $code_langue) { |
|
| 96 | - $nom_langue = $langues[$code_langue]; |
|
| 97 | - $res .= "<li class='choix " |
|
| 98 | - . alterner($i++,'odd','even') |
|
| 99 | - . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 100 | - . "'>" |
|
| 101 | - . "<input type='hidden' name='{$name}[]' value='$code_langue'>" // necessaire ... |
|
| 102 | - . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue' checked='checked' disabled='disabled' />" |
|
| 103 | - . "<label for='{$name}_$code_langue'>" . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 104 | - . "</li>"; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($res) |
|
| 108 | - $res = "<ul id='langues_bloquees'>".$res."</ul><div class='nettoyeur'></div>"; |
|
| 109 | - |
|
| 110 | - $res .= "<ul id='langues_proposees'>"; |
|
| 111 | - |
|
| 112 | - $i = 0; |
|
| 113 | - $langues_bloquees = array_flip($langues_bloquees); |
|
| 114 | - foreach($langues as $code_langue=>$nom_langue) { |
|
| 115 | - if (!isset($langues_bloquees[$code_langue])) { |
|
| 116 | - $checked = (in_array($code_langue,$selection)?' checked="checked"':''); |
|
| 117 | - $res .= "<li class='choix " |
|
| 118 | - . alterner($i++,'odd','even') |
|
| 119 | - . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 120 | - . "'>" |
|
| 121 | - . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue'" |
|
| 122 | - . $checked |
|
| 123 | - . "/>" |
|
| 124 | - . "<label for='{$name}_$code_langue'" |
|
| 125 | - . ($checked?" class='on'":"") |
|
| 126 | - . ">" |
|
| 127 | - . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 128 | - . "</li>"; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $res .= "</ul><div class='nettoyeur'></div>"; |
|
| 133 | - return $res; |
|
| 87 | + $langues_installees = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 88 | + $langues_trad = array_flip($langues_installees); |
|
| 89 | + |
|
| 90 | + $langues_bloquees = explode(',',$GLOBALS['meta']['langues_utilisees']); |
|
| 91 | + |
|
| 92 | + $res = ""; |
|
| 93 | + |
|
| 94 | + $i = 0; |
|
| 95 | + foreach($langues_bloquees as $code_langue) { |
|
| 96 | + $nom_langue = $langues[$code_langue]; |
|
| 97 | + $res .= "<li class='choix " |
|
| 98 | + . alterner($i++,'odd','even') |
|
| 99 | + . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 100 | + . "'>" |
|
| 101 | + . "<input type='hidden' name='{$name}[]' value='$code_langue'>" // necessaire ... |
|
| 102 | + . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue' checked='checked' disabled='disabled' />" |
|
| 103 | + . "<label for='{$name}_$code_langue'>" . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 104 | + . "</li>"; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($res) |
|
| 108 | + $res = "<ul id='langues_bloquees'>".$res."</ul><div class='nettoyeur'></div>"; |
|
| 109 | + |
|
| 110 | + $res .= "<ul id='langues_proposees'>"; |
|
| 111 | + |
|
| 112 | + $i = 0; |
|
| 113 | + $langues_bloquees = array_flip($langues_bloquees); |
|
| 114 | + foreach($langues as $code_langue=>$nom_langue) { |
|
| 115 | + if (!isset($langues_bloquees[$code_langue])) { |
|
| 116 | + $checked = (in_array($code_langue,$selection)?' checked="checked"':''); |
|
| 117 | + $res .= "<li class='choix " |
|
| 118 | + . alterner($i++,'odd','even') |
|
| 119 | + . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 120 | + . "'>" |
|
| 121 | + . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue'" |
|
| 122 | + . $checked |
|
| 123 | + . "/>" |
|
| 124 | + . "<label for='{$name}_$code_langue'" |
|
| 125 | + . ($checked?" class='on'":"") |
|
| 126 | + . ">" |
|
| 127 | + . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 128 | + . "</li>"; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $res .= "</ul><div class='nettoyeur'></div>"; |
|
| 133 | + return $res; |
|
| 134 | 134 | } |
| 135 | 135 | ?> |
@@ -10,12 +10,15 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | function formulaires_configurer_multilinguisme_charger_dist(){ |
| 16 | 18 | $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
| 17 | - foreach(array('multi_objets','gerer_trad_objets') as $m) |
|
| 18 | - $valeurs[$m] = explode(',',isset($GLOBALS['meta'][$m])?$GLOBALS['meta'][$m]:''); |
|
| 19 | + foreach(array('multi_objets','gerer_trad_objets') as $m) { |
|
| 20 | + $valeurs[$m] = explode(',',isset($GLOBALS['meta'][$m])?$GLOBALS['meta'][$m]:''); |
|
| 21 | + } |
|
| 19 | 22 | |
| 20 | 23 | if (count($valeurs['multi_objets']) |
| 21 | 24 | OR count(explode(',',$GLOBALS['meta']['langues_utilisees'])) > 1) { |
@@ -61,8 +64,9 @@ discard block |
||
| 61 | 64 | function table_supporte_lang($table_sql){ |
| 62 | 65 | $trouver_table = charger_fonction('trouver_table','base'); |
| 63 | 66 | $desc = $trouver_table($table_sql); |
| 64 | - if (!$desc OR !isset($desc['field']['lang'])) |
|
| 65 | - return ''; |
|
| 67 | + if (!$desc OR !isset($desc['field']['lang'])) { |
|
| 68 | + return ''; |
|
| 69 | + } |
|
| 66 | 70 | return ' '; |
| 67 | 71 | } |
| 68 | 72 | |
@@ -74,8 +78,9 @@ discard block |
||
| 74 | 78 | function table_supporte_trad($table_sql){ |
| 75 | 79 | $trouver_table = charger_fonction('trouver_table','base'); |
| 76 | 80 | $desc = $trouver_table($table_sql); |
| 77 | - if (!$desc OR !isset($desc['field']['id_trad'])) |
|
| 78 | - return ''; |
|
| 81 | + if (!$desc OR !isset($desc['field']['id_trad'])) { |
|
| 82 | + return ''; |
|
| 83 | + } |
|
| 79 | 84 | return ' '; |
| 80 | 85 | } |
| 81 | 86 | |
@@ -104,8 +109,9 @@ discard block |
||
| 104 | 109 | . "</li>"; |
| 105 | 110 | } |
| 106 | 111 | |
| 107 | - if ($res) |
|
| 108 | - $res = "<ul id='langues_bloquees'>".$res."</ul><div class='nettoyeur'></div>"; |
|
| 112 | + if ($res) { |
|
| 113 | + $res = "<ul id='langues_bloquees'>".$res."</ul><div class='nettoyeur'></div>"; |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | $res .= "<ul id='langues_proposees'>"; |
| 111 | 117 | |
@@ -12,16 +12,16 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | -function formulaires_configurer_multilinguisme_charger_dist(){ |
|
| 15 | +function formulaires_configurer_multilinguisme_charger_dist() { |
|
| 16 | 16 | $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
| 17 | - foreach(array('multi_objets','gerer_trad_objets') as $m) |
|
| 18 | - $valeurs[$m] = explode(',',isset($GLOBALS['meta'][$m])?$GLOBALS['meta'][$m]:''); |
|
| 17 | + foreach (array('multi_objets', 'gerer_trad_objets') as $m) |
|
| 18 | + $valeurs[$m] = explode(',', isset($GLOBALS['meta'][$m]) ? $GLOBALS['meta'][$m] : ''); |
|
| 19 | 19 | |
| 20 | 20 | if (count($valeurs['multi_objets']) |
| 21 | - OR count(explode(',',$GLOBALS['meta']['langues_utilisees'])) > 1) { |
|
| 21 | + OR count(explode(',', $GLOBALS['meta']['langues_utilisees'])) > 1) { |
|
| 22 | 22 | |
| 23 | - $selection = (is_null(_request('multi_objets'))?explode(',', $GLOBALS['meta']['langues_multilingue']):_request('langues_auth')); |
|
| 24 | - $valeurs['_langues'] = saisie_langues_utiles('langues_auth',$selection?$selection:array()); |
|
| 23 | + $selection = (is_null(_request('multi_objets')) ?explode(',', $GLOBALS['meta']['langues_multilingue']) : _request('langues_auth')); |
|
| 24 | + $valeurs['_langues'] = saisie_langues_utiles('langues_auth', $selection ? $selection : array()); |
|
| 25 | 25 | $valeurs['_nb_langues_selection'] = count($selection); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -29,25 +29,25 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | -function formulaires_configurer_multilinguisme_traiter_dist(){ |
|
| 32 | +function formulaires_configurer_multilinguisme_traiter_dist() { |
|
| 33 | 33 | $res = array('editable'=>true); |
| 34 | 34 | // un checkbox seul de name X non coche n'est pas poste. |
| 35 | 35 | // on verifie le champ X_check qui indique que la checkbox etait presente dans le formulaire. |
| 36 | - foreach(array('multi_secteurs') as $m) { |
|
| 37 | - if (!is_null(_request($m . '_check'))) { |
|
| 36 | + foreach (array('multi_secteurs') as $m) { |
|
| 37 | + if (!is_null(_request($m.'_check'))) { |
|
| 38 | 38 | ecrire_meta($m, _request($m) ? 'oui' : 'non'); |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | - foreach(array('multi_objets','gerer_trad_objets') as $m) { |
|
| 42 | - if (!is_null($v=_request($m))) { |
|
| 41 | + foreach (array('multi_objets', 'gerer_trad_objets') as $m) { |
|
| 42 | + if (!is_null($v = _request($m))) { |
|
| 43 | 43 | // join et enlever la valeur vide '' |
| 44 | - ecrire_meta($m, implode(',',array_diff($v,array('')))); |
|
| 44 | + ecrire_meta($m, implode(',', array_diff($v, array('')))); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | if ($i = _request('langues_auth') AND is_array($i)) { |
| 49 | - $i = array_unique(array_merge($i,explode(',',$GLOBALS['meta']['langues_utilisees']))); |
|
| 50 | - ecrire_meta('langues_multilingue', implode(",",$i)); |
|
| 49 | + $i = array_unique(array_merge($i, explode(',', $GLOBALS['meta']['langues_utilisees']))); |
|
| 50 | + ecrire_meta('langues_multilingue', implode(",", $i)); |
|
| 51 | 51 | } |
| 52 | 52 | $res['message_ok'] = _T('config_info_enregistree'); |
| 53 | 53 | return $res; |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @param string $table_sql |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | -function table_supporte_lang($table_sql){ |
|
| 62 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 61 | +function table_supporte_lang($table_sql) { |
|
| 62 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 63 | 63 | $desc = $trouver_table($table_sql); |
| 64 | 64 | if (!$desc OR !isset($desc['field']['lang'])) |
| 65 | 65 | return ''; |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param string $table_sql |
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | -function table_supporte_trad($table_sql){ |
|
| 75 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 74 | +function table_supporte_trad($table_sql) { |
|
| 75 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 76 | 76 | $desc = $trouver_table($table_sql); |
| 77 | 77 | if (!$desc OR !isset($desc['field']['id_trad'])) |
| 78 | 78 | return ''; |
@@ -87,20 +87,20 @@ discard block |
||
| 87 | 87 | $langues_installees = explode(',', $GLOBALS['meta']['langues_proposees']); |
| 88 | 88 | $langues_trad = array_flip($langues_installees); |
| 89 | 89 | |
| 90 | - $langues_bloquees = explode(',',$GLOBALS['meta']['langues_utilisees']); |
|
| 90 | + $langues_bloquees = explode(',', $GLOBALS['meta']['langues_utilisees']); |
|
| 91 | 91 | |
| 92 | 92 | $res = ""; |
| 93 | 93 | |
| 94 | 94 | $i = 0; |
| 95 | - foreach($langues_bloquees as $code_langue) { |
|
| 95 | + foreach ($langues_bloquees as $code_langue) { |
|
| 96 | 96 | $nom_langue = $langues[$code_langue]; |
| 97 | 97 | $res .= "<li class='choix " |
| 98 | - . alterner($i++,'odd','even') |
|
| 99 | - . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 98 | + . alterner($i++, 'odd', 'even') |
|
| 99 | + . (isset($langues_trad[$code_langue]) ? " traduite" : "") |
|
| 100 | 100 | . "'>" |
| 101 | 101 | . "<input type='hidden' name='{$name}[]' value='$code_langue'>" // necessaire ... |
| 102 | 102 | . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue' checked='checked' disabled='disabled' />" |
| 103 | - . "<label for='{$name}_$code_langue'>" . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 103 | + . "<label for='{$name}_$code_langue'>".$nom_langue." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 104 | 104 | . "</li>"; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -111,20 +111,20 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | $i = 0; |
| 113 | 113 | $langues_bloquees = array_flip($langues_bloquees); |
| 114 | - foreach($langues as $code_langue=>$nom_langue) { |
|
| 114 | + foreach ($langues as $code_langue=>$nom_langue) { |
|
| 115 | 115 | if (!isset($langues_bloquees[$code_langue])) { |
| 116 | - $checked = (in_array($code_langue,$selection)?' checked="checked"':''); |
|
| 116 | + $checked = (in_array($code_langue, $selection) ? ' checked="checked"' : ''); |
|
| 117 | 117 | $res .= "<li class='choix " |
| 118 | - . alterner($i++,'odd','even') |
|
| 119 | - . (isset($langues_trad[$code_langue])?" traduite":"") |
|
| 118 | + . alterner($i++, 'odd', 'even') |
|
| 119 | + . (isset($langues_trad[$code_langue]) ? " traduite" : "") |
|
| 120 | 120 | . "'>" |
| 121 | 121 | . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue'" |
| 122 | 122 | . $checked |
| 123 | 123 | . "/>" |
| 124 | 124 | . "<label for='{$name}_$code_langue'" |
| 125 | - . ($checked?" class='on'":"") |
|
| 125 | + . ($checked ? " class='on'" : "") |
|
| 126 | 126 | . ">" |
| 127 | - . $nom_langue ." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 127 | + . $nom_langue." <span class='code_langue'>[$code_langue]</span></label>" |
|
| 128 | 128 | . "</li>"; |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | 1 | <?php |
| 2 | - # appel SPIP |
|
| 3 | - include ('spip.php'); |
|
| 2 | + # appel SPIP |
|
| 3 | + include ('spip.php'); |
|
| 4 | 4 | ?> |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * Test utilisateur |
| 16 | 16 | */ |
| 17 | 17 | if (isset($_GET['test_ecran_securite'])) |
| 18 | - $ecran_securite_raison = 'test '._ECRAN_SECURITE; |
|
| 18 | + $ecran_securite_raison = 'test '._ECRAN_SECURITE; |
|
| 19 | 19 | |
| 20 | 20 | /* |
| 21 | 21 | * Monitoring |
@@ -24,33 +24,33 @@ discard block |
||
| 24 | 24 | * le load depasse ECRAN_SECURITE_LOAD) |
| 25 | 25 | */ |
| 26 | 26 | if (!defined('_IS_BOT') and isset($_GET['var_isbot'])){ |
| 27 | - define('_IS_BOT', $_GET['var_isbot'] ? true : false); |
|
| 27 | + define('_IS_BOT', $_GET['var_isbot'] ? true : false); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /* |
| 31 | 31 | * Détecteur de robot d'indexation |
| 32 | 32 | */ |
| 33 | 33 | if (!defined('_IS_BOT')){ |
| 34 | - define('_IS_BOT', |
|
| 35 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 36 | - and preg_match( |
|
| 37 | - // mots generiques |
|
| 38 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 39 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 40 | - . 'MSIE 6\.0|' |
|
| 41 | - // UA plus cibles |
|
| 42 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebookexternalhit|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MegaIndex|MetaURI|Moreover|Rambler|Scrapy|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 43 | - . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 44 | - ); |
|
| 34 | + define('_IS_BOT', |
|
| 35 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 36 | + and preg_match( |
|
| 37 | + // mots generiques |
|
| 38 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 39 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 40 | + . 'MSIE 6\.0|' |
|
| 41 | + // UA plus cibles |
|
| 42 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebookexternalhit|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MegaIndex|MetaURI|Moreover|Rambler|Scrapy|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 43 | + . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 44 | + ); |
|
| 45 | 45 | } |
| 46 | 46 | if (!defined('_IS_BOT_FRIEND')){ |
| 47 | - define('_IS_BOT_FRIEND', |
|
| 48 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 49 | - and preg_match(',' |
|
| 50 | - // UA plus cibles |
|
| 51 | - . 'facebookexternalhit' |
|
| 52 | - . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 53 | - ); |
|
| 47 | + define('_IS_BOT_FRIEND', |
|
| 48 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 49 | + and preg_match(',' |
|
| 50 | + // UA plus cibles |
|
| 51 | + . 'facebookexternalhit' |
|
| 52 | + . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 53 | + ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /* |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | * (id_base est une variable de la config des widgets de WordPress) |
| 62 | 62 | */ |
| 63 | 63 | foreach ($_GET as $var => $val) |
| 64 | - if ($_GET[$var] and strncmp($var, "id_", 3) == 0 |
|
| 65 | - and !in_array($var, array('id_table', 'id_base'))) |
|
| 66 | - $_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]); |
|
| 64 | + if ($_GET[$var] and strncmp($var, "id_", 3) == 0 |
|
| 65 | + and !in_array($var, array('id_table', 'id_base'))) |
|
| 66 | + $_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]); |
|
| 67 | 67 | foreach ($_POST as $var => $val) |
| 68 | - if ($_POST[$var] and strncmp($var, "id_", 3) == 0 |
|
| 69 | - and !in_array($var, array('id_table', 'id_base'))) |
|
| 70 | - $_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]); |
|
| 68 | + if ($_POST[$var] and strncmp($var, "id_", 3) == 0 |
|
| 69 | + and !in_array($var, array('id_table', 'id_base'))) |
|
| 70 | + $_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]); |
|
| 71 | 71 | foreach ($GLOBALS as $var => $val) |
| 72 | - if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
|
| 73 | - and !in_array($var, array('id_table', 'id_base'))) |
|
| 74 | - $GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]); |
|
| 72 | + if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
|
| 73 | + and !in_array($var, array('id_table', 'id_base'))) |
|
| 74 | + $GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]); |
|
| 75 | 75 | |
| 76 | 76 | /* |
| 77 | 77 | * Interdit la variable $cjpeg_command, qui était utilisée sans |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * Contrôle de quelques variables (XSS) |
| 84 | 84 | */ |
| 85 | 85 | foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) { |
| 86 | - if (isset($_GET[$var])) |
|
| 87 | - $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 88 | - if (isset($_POST[$var])) |
|
| 89 | - $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 86 | + if (isset($_GET[$var])) |
|
| 87 | + $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 88 | + if (isset($_POST[$var])) |
|
| 89 | + $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /* |
| 93 | 93 | * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x) |
| 94 | 94 | */ |
| 95 | 95 | if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) { |
| 96 | - $file = addslashes((string)$_GET['file']); |
|
| 96 | + $file = addslashes((string)$_GET['file']); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /* |
@@ -102,79 +102,79 @@ discard block |
||
| 102 | 102 | if (isset($_REQUEST['mode']) and isset($_REQUEST['page']) |
| 103 | 103 | and !in_array($_REQUEST['mode'], array("6forum", "1comite")) |
| 104 | 104 | and $_REQUEST['page'] == "identifiants") |
| 105 | - $ecran_securite_raison = "identifiants"; |
|
| 105 | + $ecran_securite_raison = "identifiants"; |
|
| 106 | 106 | |
| 107 | 107 | /* |
| 108 | 108 | * Agenda joue à l'injection php |
| 109 | 109 | */ |
| 110 | 110 | if (isset($_REQUEST['partie_cal']) |
| 111 | 111 | and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) |
| 112 | - $ecran_securite_raison = "partie_cal"; |
|
| 112 | + $ecran_securite_raison = "partie_cal"; |
|
| 113 | 113 | if (isset($_REQUEST['echelle']) |
| 114 | 114 | and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) |
| 115 | - $ecran_securite_raison = "echelle"; |
|
| 115 | + $ecran_securite_raison = "echelle"; |
|
| 116 | 116 | |
| 117 | 117 | /* |
| 118 | 118 | * Espace privé |
| 119 | 119 | */ |
| 120 | 120 | if (isset($_REQUEST['exec']) |
| 121 | 121 | and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) |
| 122 | - $ecran_securite_raison = "exec"; |
|
| 122 | + $ecran_securite_raison = "exec"; |
|
| 123 | 123 | if (isset($_REQUEST['cherche_auteur']) |
| 124 | 124 | and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) |
| 125 | - $ecran_securite_raison = "cherche_auteur"; |
|
| 125 | + $ecran_securite_raison = "cherche_auteur"; |
|
| 126 | 126 | if (isset($_REQUEST['exec']) |
| 127 | 127 | and $_REQUEST['exec'] == 'auteurs' |
| 128 | 128 | and preg_match(',[<],', (string)$_REQUEST['recherche'])) |
| 129 | - $ecran_securite_raison = "recherche"; |
|
| 129 | + $ecran_securite_raison = "recherche"; |
|
| 130 | 130 | if (isset($_REQUEST['exec']) |
| 131 | 131 | and $_REQUEST['exec'] == 'info_plugin' |
| 132 | 132 | and preg_match(',[<],', (string)$_REQUEST['plugin'])) |
| 133 | - $ecran_securite_raison = "plugin"; |
|
| 133 | + $ecran_securite_raison = "plugin"; |
|
| 134 | 134 | if (isset($_REQUEST['exec']) |
| 135 | 135 | and $_REQUEST['exec'] == 'puce_statut' |
| 136 | 136 | and isset($_REQUEST['id']) |
| 137 | 137 | and !intval($_REQUEST['id'])) |
| 138 | - $ecran_securite_raison = "puce_statut"; |
|
| 138 | + $ecran_securite_raison = "puce_statut"; |
|
| 139 | 139 | if (isset($_REQUEST['action']) |
| 140 | 140 | and $_REQUEST['action'] == 'configurer') { |
| 141 | - if (@file_exists('inc_version.php') |
|
| 142 | - or @file_exists('ecrire/inc_version.php')) { |
|
| 143 | - function action_configurer() { |
|
| 144 | - include_spip('inc/autoriser'); |
|
| 145 | - if(!autoriser('configurer', _request('configuration'))) { |
|
| 146 | - include_spip('inc/minipres'); |
|
| 147 | - echo minipres(_T('info_acces_interdit')); |
|
| 148 | - exit; |
|
| 149 | - } |
|
| 150 | - require _DIR_RESTREINT.'action/configurer.php'; |
|
| 151 | - action_configurer_dist(); |
|
| 152 | - } |
|
| 153 | - } |
|
| 141 | + if (@file_exists('inc_version.php') |
|
| 142 | + or @file_exists('ecrire/inc_version.php')) { |
|
| 143 | + function action_configurer() { |
|
| 144 | + include_spip('inc/autoriser'); |
|
| 145 | + if(!autoriser('configurer', _request('configuration'))) { |
|
| 146 | + include_spip('inc/minipres'); |
|
| 147 | + echo minipres(_T('info_acces_interdit')); |
|
| 148 | + exit; |
|
| 149 | + } |
|
| 150 | + require _DIR_RESTREINT.'action/configurer.php'; |
|
| 151 | + action_configurer_dist(); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /* |
| 157 | 157 | * Bloque les requêtes contenant %00 (manipulation d'include) |
| 158 | 158 | */ |
| 159 | 159 | if (strpos( |
| 160 | - @get_magic_quotes_gpc() ? |
|
| 161 | - stripslashes(serialize($_REQUEST)) : serialize($_REQUEST), |
|
| 162 | - chr(0) |
|
| 160 | + @get_magic_quotes_gpc() ? |
|
| 161 | + stripslashes(serialize($_REQUEST)) : serialize($_REQUEST), |
|
| 162 | + chr(0) |
|
| 163 | 163 | ) !== false) |
| 164 | - $ecran_securite_raison = "%00"; |
|
| 164 | + $ecran_securite_raison = "%00"; |
|
| 165 | 165 | |
| 166 | 166 | /* |
| 167 | 167 | * Bloque les requêtes fond=formulaire_ |
| 168 | 168 | */ |
| 169 | 169 | if (isset($_REQUEST['fond']) |
| 170 | 170 | and preg_match(',^formulaire_,i', $_REQUEST['fond'])) |
| 171 | - $ecran_securite_raison = "fond=formulaire_"; |
|
| 171 | + $ecran_securite_raison = "fond=formulaire_"; |
|
| 172 | 172 | |
| 173 | 173 | /* |
| 174 | 174 | * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php) |
| 175 | 175 | */ |
| 176 | 176 | if (isset($_REQUEST['GLOBALS'])) |
| 177 | - $ecran_securite_raison = "GLOBALS[GLOBALS]"; |
|
| 177 | + $ecran_securite_raison = "GLOBALS[GLOBALS]"; |
|
| 178 | 178 | |
| 179 | 179 | /* |
| 180 | 180 | * Bloque les requêtes des bots sur: |
@@ -182,24 +182,24 @@ discard block |
||
| 182 | 182 | * les paginations entremélées |
| 183 | 183 | */ |
| 184 | 184 | if (_IS_BOT and ( |
| 185 | - (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
|
| 186 | - or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
|
| 185 | + (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
|
| 186 | + or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
|
| 187 | 187 | ) |
| 188 | 188 | ) |
| 189 | - $ecran_securite_raison = "robot agenda/double pagination"; |
|
| 189 | + $ecran_securite_raison = "robot agenda/double pagination"; |
|
| 190 | 190 | |
| 191 | 191 | /* |
| 192 | 192 | * Bloque une vieille page de tests de CFG (<1.11) |
| 193 | 193 | * Bloque un XSS sur une page inexistante |
| 194 | 194 | */ |
| 195 | 195 | if (isset($_REQUEST['page'])) { |
| 196 | - if ($_REQUEST['page'] == 'test_cfg') |
|
| 197 | - $ecran_securite_raison = "test_cfg"; |
|
| 198 | - if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) |
|
| 199 | - $ecran_securite_raison = "xsspage"; |
|
| 200 | - if ($_REQUEST['page'] == '404' |
|
| 201 | - and isset($_REQUEST['erreur'])) |
|
| 202 | - $ecran_securite_raison = "xss404"; |
|
| 196 | + if ($_REQUEST['page'] == 'test_cfg') |
|
| 197 | + $ecran_securite_raison = "test_cfg"; |
|
| 198 | + if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) |
|
| 199 | + $ecran_securite_raison = "xsspage"; |
|
| 200 | + if ($_REQUEST['page'] == '404' |
|
| 201 | + and isset($_REQUEST['erreur'])) |
|
| 202 | + $ecran_securite_raison = "xss404"; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /* |
@@ -207,39 +207,39 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | foreach (array('var_login') as $var) |
| 209 | 209 | if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) |
| 210 | - $ecran_securite_raison = "xss ".$var; |
|
| 210 | + $ecran_securite_raison = "xss ".$var; |
|
| 211 | 211 | |
| 212 | 212 | /* |
| 213 | 213 | * Parade antivirale contre un cheval de troie |
| 214 | 214 | */ |
| 215 | 215 | if (!function_exists('tmp_lkojfghx')) { |
| 216 | - function tmp_lkojfghx() {} |
|
| 217 | - function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) { |
|
| 218 | - // si jamais on est arrivé ici sur une erreur php |
|
| 219 | - // et qu'un autre gestionnaire d'erreur est défini, l'appeller |
|
| 220 | - if ($b && $GLOBALS['tmp_xhgfjokl']) |
|
| 221 | - call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 222 | - } |
|
| 216 | + function tmp_lkojfghx() {} |
|
| 217 | + function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) { |
|
| 218 | + // si jamais on est arrivé ici sur une erreur php |
|
| 219 | + // et qu'un autre gestionnaire d'erreur est défini, l'appeller |
|
| 220 | + if ($b && $GLOBALS['tmp_xhgfjokl']) |
|
| 221 | + call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 222 | + } |
|
| 223 | 223 | } |
| 224 | 224 | if (isset($_POST['tmp_lkojfghx3'])) |
| 225 | - $ecran_securite_raison = "gumblar"; |
|
| 225 | + $ecran_securite_raison = "gumblar"; |
|
| 226 | 226 | |
| 227 | 227 | /* |
| 228 | 228 | * Outils XML mal sécurisés < 2.0.9 |
| 229 | 229 | */ |
| 230 | 230 | if (isset($_REQUEST['transformer_xml'])) |
| 231 | - $ecran_securite_raison = "transformer_xml"; |
|
| 231 | + $ecran_securite_raison = "transformer_xml"; |
|
| 232 | 232 | |
| 233 | 233 | /* |
| 234 | 234 | * Outils XML mal sécurisés again |
| 235 | 235 | */ |
| 236 | 236 | if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec']=='valider_xml'){ |
| 237 | - $url = trim($_REQUEST['var_url']); |
|
| 238 | - if (strncmp($url,'/',1)==0 |
|
| 239 | - or (($p=strpos($url,'..'))!==false AND strpos($url,'..',$p+3)!==false) |
|
| 240 | - or (strpos($url,'://')!==false or strpos($url,':\\')!==false)) { |
|
| 241 | - $ecran_securite_raison = 'URL interdite pour var_url'; |
|
| 242 | - } |
|
| 237 | + $url = trim($_REQUEST['var_url']); |
|
| 238 | + if (strncmp($url,'/',1)==0 |
|
| 239 | + or (($p=strpos($url,'..'))!==false AND strpos($url,'..',$p+3)!==false) |
|
| 240 | + or (strpos($url,'://')!==false or strpos($url,':\\')!==false)) { |
|
| 241 | + $ecran_securite_raison = 'URL interdite pour var_url'; |
|
| 242 | + } |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /* |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | if (isset($_REQUEST['nom_sauvegarde']) |
| 249 | 249 | and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) |
| 250 | - $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
|
| 250 | + $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
|
| 251 | 251 | if (isset($_REQUEST['znom_sauvegarde']) |
| 252 | 252 | and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) |
| 253 | - $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
|
| 253 | + $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
|
| 254 | 254 | |
| 255 | 255 | |
| 256 | 256 | /* |
@@ -259,26 +259,26 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | if (isset($_REQUEST['op']) and isset($_REQUEST['page']) |
| 261 | 261 | and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op'])) |
| 262 | - $ecran_securite_raison = 'op'; |
|
| 262 | + $ecran_securite_raison = 'op'; |
|
| 263 | 263 | |
| 264 | 264 | /* |
| 265 | 265 | * Forms & Table ne se méfiait pas assez des uploads de fichiers |
| 266 | 266 | */ |
| 267 | 267 | if (count($_FILES)){ |
| 268 | - foreach($_FILES as $k => $v){ |
|
| 269 | - if (preg_match(',^fichier_\d+$,', $k) |
|
| 270 | - and preg_match(',\.php,i', $v['name'])) |
|
| 271 | - unset($_FILES[$k]); |
|
| 272 | - } |
|
| 268 | + foreach($_FILES as $k => $v){ |
|
| 269 | + if (preg_match(',^fichier_\d+$,', $k) |
|
| 270 | + and preg_match(',\.php,i', $v['name'])) |
|
| 271 | + unset($_FILES[$k]); |
|
| 272 | + } |
|
| 273 | 273 | } |
| 274 | 274 | /* |
| 275 | 275 | * et Contact trop laxiste avec une variable externe |
| 276 | 276 | * on bloque pas le post pour eviter de perdre des donnees mais on unset la variable et c'est tout |
| 277 | 277 | */ |
| 278 | 278 | if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']){ |
| 279 | - unset($_REQUEST['pj_enregistrees_nom']); |
|
| 280 | - unset($_GET['pj_enregistrees_nom']); |
|
| 281 | - unset($_POST['pj_enregistrees_nom']); |
|
| 279 | + unset($_REQUEST['pj_enregistrees_nom']); |
|
| 280 | + unset($_GET['pj_enregistrees_nom']); |
|
| 281 | + unset($_POST['pj_enregistrees_nom']); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /* |
@@ -286,66 +286,66 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | if (isset($_REQUEST['reinstall']) |
| 288 | 288 | and $_REQUEST['reinstall'] == 'oui') |
| 289 | - $ecran_securite_raison = 'reinstall=oui'; |
|
| 289 | + $ecran_securite_raison = 'reinstall=oui'; |
|
| 290 | 290 | |
| 291 | 291 | /* |
| 292 | 292 | * Échappement xss referer |
| 293 | 293 | */ |
| 294 | 294 | if (isset($_SERVER['HTTP_REFERER'])) |
| 295 | - $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##'); |
|
| 295 | + $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##'); |
|
| 296 | 296 | |
| 297 | 297 | |
| 298 | 298 | /* |
| 299 | 299 | * Echappement HTTP_X_FORWARDED_HOST |
| 300 | 300 | */ |
| 301 | 301 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) |
| 302 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 302 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | /* |
| 306 | 306 | * Réinjection des clés en html dans l'admin r19561 |
| 307 | 307 | */ |
| 308 | 308 | if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false){ |
| 309 | - $zzzz = implode("", array_keys($_REQUEST)); |
|
| 310 | - if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) |
|
| 311 | - $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 309 | + $zzzz = implode("", array_keys($_REQUEST)); |
|
| 310 | + if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) |
|
| 311 | + $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /* |
| 315 | 315 | * Injection par connect |
| 316 | 316 | */ |
| 317 | 317 | if (isset($_REQUEST['connect']) |
| 318 | - and |
|
| 319 | - // cas qui permettent de sortir d'un commentaire PHP |
|
| 320 | - (strpos($_REQUEST['connect'], "?") !== false |
|
| 321 | - or strpos($_REQUEST['connect'], "<") !== false |
|
| 322 | - or strpos($_REQUEST['connect'], ">") !== false |
|
| 323 | - or strpos($_REQUEST['connect'], "\n") !== false |
|
| 324 | - or strpos($_REQUEST['connect'], "\r") !== false) |
|
| 325 | - ) { |
|
| 326 | - $ecran_securite_raison = "malformed connect argument"; |
|
| 318 | + and |
|
| 319 | + // cas qui permettent de sortir d'un commentaire PHP |
|
| 320 | + (strpos($_REQUEST['connect'], "?") !== false |
|
| 321 | + or strpos($_REQUEST['connect'], "<") !== false |
|
| 322 | + or strpos($_REQUEST['connect'], ">") !== false |
|
| 323 | + or strpos($_REQUEST['connect'], "\n") !== false |
|
| 324 | + or strpos($_REQUEST['connect'], "\r") !== false) |
|
| 325 | + ) { |
|
| 326 | + $ecran_securite_raison = "malformed connect argument"; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /* |
| 330 | 330 | * S'il y a une raison de mourir, mourons |
| 331 | 331 | */ |
| 332 | 332 | if (isset($ecran_securite_raison)) { |
| 333 | - header("HTTP/1.0 403 Forbidden"); |
|
| 334 | - header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 335 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 336 | - header("Pragma: no-cache"); |
|
| 337 | - header("Content-Type: text/html"); |
|
| 338 | - die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>"); |
|
| 333 | + header("HTTP/1.0 403 Forbidden"); |
|
| 334 | + header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 335 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 336 | + header("Pragma: no-cache"); |
|
| 337 | + header("Content-Type: text/html"); |
|
| 338 | + die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>"); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /* |
| 342 | 342 | * Un filtre filtrer_entites securise |
| 343 | 343 | */ |
| 344 | 344 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 345 | - function filtre_filtrer_entites_dist($t) { |
|
| 346 | - include_spip('inc/texte'); |
|
| 347 | - return interdire_scripts(filtrer_entites($t)); |
|
| 348 | - } |
|
| 345 | + function filtre_filtrer_entites_dist($t) { |
|
| 346 | + include_spip('inc/texte'); |
|
| 347 | + return interdire_scripts(filtrer_entites($t)); |
|
| 348 | + } |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | |
@@ -359,34 +359,34 @@ discard block |
||
| 359 | 359 | * Bloque les bots quand le load déborde |
| 360 | 360 | */ |
| 361 | 361 | if (!defined('_ECRAN_SECURITE_LOAD')) |
| 362 | - define('_ECRAN_SECURITE_LOAD', 4); |
|
| 362 | + define('_ECRAN_SECURITE_LOAD', 4); |
|
| 363 | 363 | |
| 364 | 364 | if ( |
| 365 | - defined('_ECRAN_SECURITE_LOAD') |
|
| 366 | - and _ECRAN_SECURITE_LOAD > 0 |
|
| 367 | - and _IS_BOT |
|
| 368 | - and !_IS_BOT_FRIEND |
|
| 369 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 370 | - and ( |
|
| 371 | - (function_exists('sys_getloadavg') |
|
| 372 | - and $load = sys_getloadavg() |
|
| 373 | - and is_array($load) |
|
| 374 | - and $load = array_shift($load) |
|
| 375 | - ) |
|
| 376 | - or |
|
| 377 | - (@is_readable('/proc/loadavg') |
|
| 378 | - and $load = file_get_contents('/proc/loadavg') |
|
| 379 | - and $load = floatval($load) |
|
| 380 | - ) |
|
| 381 | - ) |
|
| 382 | - and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite |
|
| 383 | - and rand(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD |
|
| 365 | + defined('_ECRAN_SECURITE_LOAD') |
|
| 366 | + and _ECRAN_SECURITE_LOAD > 0 |
|
| 367 | + and _IS_BOT |
|
| 368 | + and !_IS_BOT_FRIEND |
|
| 369 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 370 | + and ( |
|
| 371 | + (function_exists('sys_getloadavg') |
|
| 372 | + and $load = sys_getloadavg() |
|
| 373 | + and is_array($load) |
|
| 374 | + and $load = array_shift($load) |
|
| 375 | + ) |
|
| 376 | + or |
|
| 377 | + (@is_readable('/proc/loadavg') |
|
| 378 | + and $load = file_get_contents('/proc/loadavg') |
|
| 379 | + and $load = floatval($load) |
|
| 380 | + ) |
|
| 381 | + ) |
|
| 382 | + and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite |
|
| 383 | + and rand(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD |
|
| 384 | 384 | ) { |
| 385 | - header("HTTP/1.0 503 Service Unavailable"); |
|
| 386 | - header("Retry-After: 300"); |
|
| 387 | - header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 388 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 389 | - header("Pragma: no-cache"); |
|
| 390 | - header("Content-Type: text/html"); |
|
| 391 | - die("<html><title>Status 503: Site temporarily unavailable</title><body><h1>Status 503</h1><p>Site temporarily unavailable (load average $load)</p></body></html>"); |
|
| 385 | + header("HTTP/1.0 503 Service Unavailable"); |
|
| 386 | + header("Retry-After: 300"); |
|
| 387 | + header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 388 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 389 | + header("Pragma: no-cache"); |
|
| 390 | + header("Content-Type: text/html"); |
|
| 391 | + die("<html><title>Status 503: Site temporarily unavailable</title><body><h1>Status 503</h1><p>Site temporarily unavailable (load average $load)</p></body></html>"); |
|
| 392 | 392 | } |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * var_isbot=1 peut etre utilise pour monitorer la disponibilite pour les bots (sujets a 503 de delestage si |
| 24 | 24 | * le load depasse ECRAN_SECURITE_LOAD) |
| 25 | 25 | */ |
| 26 | -if (!defined('_IS_BOT') and isset($_GET['var_isbot'])){ |
|
| 26 | +if (!defined('_IS_BOT') and isset($_GET['var_isbot'])) { |
|
| 27 | 27 | define('_IS_BOT', $_GET['var_isbot'] ? true : false); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /* |
| 31 | 31 | * Détecteur de robot d'indexation |
| 32 | 32 | */ |
| 33 | -if (!defined('_IS_BOT')){ |
|
| 33 | +if (!defined('_IS_BOT')) { |
|
| 34 | 34 | define('_IS_BOT', |
| 35 | 35 | isset($_SERVER['HTTP_USER_AGENT']) |
| 36 | 36 | and preg_match( |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | . 'MSIE 6\.0|' |
| 41 | 41 | // UA plus cibles |
| 42 | 42 | . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebookexternalhit|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MegaIndex|MetaURI|Moreover|Rambler|Scrapy|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
| 43 | - . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 43 | + . ',i', (string) $_SERVER['HTTP_USER_AGENT']) |
|
| 44 | 44 | ); |
| 45 | 45 | } |
| 46 | -if (!defined('_IS_BOT_FRIEND')){ |
|
| 46 | +if (!defined('_IS_BOT_FRIEND')) { |
|
| 47 | 47 | define('_IS_BOT_FRIEND', |
| 48 | 48 | isset($_SERVER['HTTP_USER_AGENT']) |
| 49 | 49 | and preg_match(',' |
| 50 | 50 | // UA plus cibles |
| 51 | 51 | . 'facebookexternalhit' |
| 52 | - . ',i', (string)$_SERVER['HTTP_USER_AGENT']) |
|
| 52 | + . ',i', (string) $_SERVER['HTTP_USER_AGENT']) |
|
| 53 | 53 | ); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | foreach ($_GET as $var => $val) |
| 64 | 64 | if ($_GET[$var] and strncmp($var, "id_", 3) == 0 |
| 65 | 65 | and !in_array($var, array('id_table', 'id_base'))) |
| 66 | - $_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]); |
|
| 66 | + $_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]); |
|
| 67 | 67 | foreach ($_POST as $var => $val) |
| 68 | 68 | if ($_POST[$var] and strncmp($var, "id_", 3) == 0 |
| 69 | 69 | and !in_array($var, array('id_table', 'id_base'))) |
| 70 | - $_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]); |
|
| 70 | + $_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]); |
|
| 71 | 71 | foreach ($GLOBALS as $var => $val) |
| 72 | 72 | if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
| 73 | 73 | and !in_array($var, array('id_table', 'id_base'))) |
| 74 | - $GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]); |
|
| 74 | + $GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]); |
|
| 75 | 75 | |
| 76 | 76 | /* |
| 77 | 77 | * Interdit la variable $cjpeg_command, qui était utilisée sans |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | /* |
| 83 | 83 | * Contrôle de quelques variables (XSS) |
| 84 | 84 | */ |
| 85 | -foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) { |
|
| 85 | +foreach (array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) { |
|
| 86 | 86 | if (isset($_GET[$var])) |
| 87 | - $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 87 | + $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string) $_GET[$var]); |
|
| 88 | 88 | if (isset($_POST[$var])) |
| 89 | - $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 89 | + $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string) $_POST[$var]); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /* |
| 93 | 93 | * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x) |
| 94 | 94 | */ |
| 95 | -if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) { |
|
| 96 | - $file = addslashes((string)$_GET['file']); |
|
| 95 | +if (preg_match(',^(.*/)?spip_acces_doc\.,', (string) $_SERVER['REQUEST_URI'])) { |
|
| 96 | + $file = addslashes((string) $_GET['file']); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /* |
@@ -108,28 +108,28 @@ discard block |
||
| 108 | 108 | * Agenda joue à l'injection php |
| 109 | 109 | */ |
| 110 | 110 | if (isset($_REQUEST['partie_cal']) |
| 111 | -and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) |
|
| 111 | +and $_REQUEST['partie_cal'] !== htmlentities((string) $_REQUEST['partie_cal'])) |
|
| 112 | 112 | $ecran_securite_raison = "partie_cal"; |
| 113 | 113 | if (isset($_REQUEST['echelle']) |
| 114 | -and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) |
|
| 114 | +and $_REQUEST['echelle'] !== htmlentities((string) $_REQUEST['echelle'])) |
|
| 115 | 115 | $ecran_securite_raison = "echelle"; |
| 116 | 116 | |
| 117 | 117 | /* |
| 118 | 118 | * Espace privé |
| 119 | 119 | */ |
| 120 | 120 | if (isset($_REQUEST['exec']) |
| 121 | -and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) |
|
| 121 | +and !preg_match(',^[\w-]+$,', (string) $_REQUEST['exec'])) |
|
| 122 | 122 | $ecran_securite_raison = "exec"; |
| 123 | 123 | if (isset($_REQUEST['cherche_auteur']) |
| 124 | -and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) |
|
| 124 | +and preg_match(',[<],', (string) $_REQUEST['cherche_auteur'])) |
|
| 125 | 125 | $ecran_securite_raison = "cherche_auteur"; |
| 126 | 126 | if (isset($_REQUEST['exec']) |
| 127 | 127 | and $_REQUEST['exec'] == 'auteurs' |
| 128 | -and preg_match(',[<],', (string)$_REQUEST['recherche'])) |
|
| 128 | +and preg_match(',[<],', (string) $_REQUEST['recherche'])) |
|
| 129 | 129 | $ecran_securite_raison = "recherche"; |
| 130 | 130 | if (isset($_REQUEST['exec']) |
| 131 | 131 | and $_REQUEST['exec'] == 'info_plugin' |
| 132 | -and preg_match(',[<],', (string)$_REQUEST['plugin'])) |
|
| 132 | +and preg_match(',[<],', (string) $_REQUEST['plugin'])) |
|
| 133 | 133 | $ecran_securite_raison = "plugin"; |
| 134 | 134 | if (isset($_REQUEST['exec']) |
| 135 | 135 | and $_REQUEST['exec'] == 'puce_statut' |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | or @file_exists('ecrire/inc_version.php')) { |
| 143 | 143 | function action_configurer() { |
| 144 | 144 | include_spip('inc/autoriser'); |
| 145 | - if(!autoriser('configurer', _request('configuration'))) { |
|
| 145 | + if (!autoriser('configurer', _request('configuration'))) { |
|
| 146 | 146 | include_spip('inc/minipres'); |
| 147 | 147 | echo minipres(_T('info_acces_interdit')); |
| 148 | 148 | exit; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | if (_IS_BOT and ( |
| 185 | 185 | (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
| 186 | - or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
|
| 186 | + or (strpos((string) $_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string) $_SERVER['REQUEST_URI'])) |
|
| 187 | 187 | ) |
| 188 | 188 | ) |
| 189 | 189 | $ecran_securite_raison = "robot agenda/double pagination"; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | if (isset($_REQUEST['page'])) { |
| 196 | 196 | if ($_REQUEST['page'] == 'test_cfg') |
| 197 | 197 | $ecran_securite_raison = "test_cfg"; |
| 198 | - if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) |
|
| 198 | + if ($_REQUEST['page'] !== htmlspecialchars((string) $_REQUEST['page'])) |
|
| 199 | 199 | $ecran_securite_raison = "xsspage"; |
| 200 | 200 | if ($_REQUEST['page'] == '404' |
| 201 | 201 | and isset($_REQUEST['erreur'])) |
@@ -233,11 +233,11 @@ discard block |
||
| 233 | 233 | /* |
| 234 | 234 | * Outils XML mal sécurisés again |
| 235 | 235 | */ |
| 236 | -if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec']=='valider_xml'){ |
|
| 236 | +if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec'] == 'valider_xml') { |
|
| 237 | 237 | $url = trim($_REQUEST['var_url']); |
| 238 | - if (strncmp($url,'/',1)==0 |
|
| 239 | - or (($p=strpos($url,'..'))!==false AND strpos($url,'..',$p+3)!==false) |
|
| 240 | - or (strpos($url,'://')!==false or strpos($url,':\\')!==false)) { |
|
| 238 | + if (strncmp($url, '/', 1) == 0 |
|
| 239 | + or (($p = strpos($url, '..')) !== false AND strpos($url, '..', $p + 3) !== false) |
|
| 240 | + or (strpos($url, '://') !== false or strpos($url, ':\\') !== false)) { |
|
| 241 | 241 | $ecran_securite_raison = 'URL interdite pour var_url'; |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | * Sauvegarde mal securisée < 2.0.9 |
| 247 | 247 | */ |
| 248 | 248 | if (isset($_REQUEST['nom_sauvegarde']) |
| 249 | -and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) |
|
| 249 | +and strstr((string) $_REQUEST['nom_sauvegarde'], '/')) |
|
| 250 | 250 | $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
| 251 | 251 | if (isset($_REQUEST['znom_sauvegarde']) |
| 252 | -and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) |
|
| 252 | +and strstr((string) $_REQUEST['znom_sauvegarde'], '/')) |
|
| 253 | 253 | $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
| 254 | 254 | |
| 255 | 255 | |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | /* |
| 265 | 265 | * Forms & Table ne se méfiait pas assez des uploads de fichiers |
| 266 | 266 | */ |
| 267 | -if (count($_FILES)){ |
|
| 268 | - foreach($_FILES as $k => $v){ |
|
| 267 | +if (count($_FILES)) { |
|
| 268 | + foreach ($_FILES as $k => $v) { |
|
| 269 | 269 | if (preg_match(',^fichier_\d+$,', $k) |
| 270 | 270 | and preg_match(',\.php,i', $v['name'])) |
| 271 | 271 | unset($_FILES[$k]); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * et Contact trop laxiste avec une variable externe |
| 276 | 276 | * on bloque pas le post pour eviter de perdre des donnees mais on unset la variable et c'est tout |
| 277 | 277 | */ |
| 278 | -if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']){ |
|
| 278 | +if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']) { |
|
| 279 | 279 | unset($_REQUEST['pj_enregistrees_nom']); |
| 280 | 280 | unset($_GET['pj_enregistrees_nom']); |
| 281 | 281 | unset($_POST['pj_enregistrees_nom']); |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | /* |
| 306 | 306 | * Réinjection des clés en html dans l'admin r19561 |
| 307 | 307 | */ |
| 308 | -if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false){ |
|
| 308 | +if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false) { |
|
| 309 | 309 | $zzzz = implode("", array_keys($_REQUEST)); |
| 310 | 310 | if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) |
| 311 | 311 | $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | /* |
| 15 | 15 | * Test utilisateur |
| 16 | 16 | */ |
| 17 | -if (isset($_GET['test_ecran_securite'])) |
|
| 17 | +if (isset($_GET['test_ecran_securite'])) { |
|
| 18 | 18 | $ecran_securite_raison = 'test '._ECRAN_SECURITE; |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /* |
| 21 | 22 | * Monitoring |
@@ -60,18 +61,21 @@ discard block |
||
| 60 | 61 | * (sauf pour id_table, qui n'est pas numérique jusqu'à [5743]) |
| 61 | 62 | * (id_base est une variable de la config des widgets de WordPress) |
| 62 | 63 | */ |
| 63 | -foreach ($_GET as $var => $val) |
|
| 64 | +foreach ($_GET as $var => $val) { |
|
| 64 | 65 | if ($_GET[$var] and strncmp($var, "id_", 3) == 0 |
| 65 | 66 | and !in_array($var, array('id_table', 'id_base'))) |
| 66 | 67 | $_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]); |
| 67 | -foreach ($_POST as $var => $val) |
|
| 68 | +} |
|
| 69 | +foreach ($_POST as $var => $val) { |
|
| 68 | 70 | if ($_POST[$var] and strncmp($var, "id_", 3) == 0 |
| 69 | 71 | and !in_array($var, array('id_table', 'id_base'))) |
| 70 | 72 | $_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]); |
| 71 | -foreach ($GLOBALS as $var => $val) |
|
| 73 | +} |
|
| 74 | +foreach ($GLOBALS as $var => $val) { |
|
| 72 | 75 | if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
| 73 | 76 | and !in_array($var, array('id_table', 'id_base'))) |
| 74 | 77 | $GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]); |
| 78 | +} |
|
| 75 | 79 | |
| 76 | 80 | /* |
| 77 | 81 | * Interdit la variable $cjpeg_command, qui était utilisée sans |
@@ -83,11 +87,13 @@ discard block |
||
| 83 | 87 | * Contrôle de quelques variables (XSS) |
| 84 | 88 | */ |
| 85 | 89 | foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) { |
| 86 | - if (isset($_GET[$var])) |
|
| 87 | - $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 88 | - if (isset($_POST[$var])) |
|
| 89 | - $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 90 | -} |
|
| 90 | + if (isset($_GET[$var])) { |
|
| 91 | + $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 92 | + } |
|
| 93 | + if (isset($_POST[$var])) { |
|
| 94 | + $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 95 | + } |
|
| 96 | + } |
|
| 91 | 97 | |
| 92 | 98 | /* |
| 93 | 99 | * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x) |
@@ -101,41 +107,49 @@ discard block |
||
| 101 | 107 | */ |
| 102 | 108 | if (isset($_REQUEST['mode']) and isset($_REQUEST['page']) |
| 103 | 109 | and !in_array($_REQUEST['mode'], array("6forum", "1comite")) |
| 104 | -and $_REQUEST['page'] == "identifiants") |
|
| 110 | +and $_REQUEST['page'] == "identifiants") { |
|
| 105 | 111 | $ecran_securite_raison = "identifiants"; |
| 112 | +} |
|
| 106 | 113 | |
| 107 | 114 | /* |
| 108 | 115 | * Agenda joue à l'injection php |
| 109 | 116 | */ |
| 110 | 117 | if (isset($_REQUEST['partie_cal']) |
| 111 | -and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) |
|
| 118 | +and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) { |
|
| 112 | 119 | $ecran_securite_raison = "partie_cal"; |
| 120 | +} |
|
| 113 | 121 | if (isset($_REQUEST['echelle']) |
| 114 | -and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) |
|
| 122 | +and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) { |
|
| 115 | 123 | $ecran_securite_raison = "echelle"; |
| 124 | +} |
|
| 116 | 125 | |
| 117 | 126 | /* |
| 118 | 127 | * Espace privé |
| 119 | 128 | */ |
| 120 | 129 | if (isset($_REQUEST['exec']) |
| 121 | -and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) |
|
| 130 | +and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) { |
|
| 122 | 131 | $ecran_securite_raison = "exec"; |
| 132 | +} |
|
| 123 | 133 | if (isset($_REQUEST['cherche_auteur']) |
| 124 | -and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) |
|
| 134 | +and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) { |
|
| 125 | 135 | $ecran_securite_raison = "cherche_auteur"; |
| 136 | +} |
|
| 126 | 137 | if (isset($_REQUEST['exec']) |
| 127 | 138 | and $_REQUEST['exec'] == 'auteurs' |
| 128 | -and preg_match(',[<],', (string)$_REQUEST['recherche'])) |
|
| 139 | +and preg_match(',[<],', (string)$_REQUEST['recherche'])) { |
|
| 129 | 140 | $ecran_securite_raison = "recherche"; |
| 141 | +} |
|
| 130 | 142 | if (isset($_REQUEST['exec']) |
| 131 | 143 | and $_REQUEST['exec'] == 'info_plugin' |
| 132 | -and preg_match(',[<],', (string)$_REQUEST['plugin'])) |
|
| 144 | +and preg_match(',[<],', (string)$_REQUEST['plugin'])) { |
|
| 133 | 145 | $ecran_securite_raison = "plugin"; |
| 146 | +} |
|
| 134 | 147 | if (isset($_REQUEST['exec']) |
| 135 | 148 | and $_REQUEST['exec'] == 'puce_statut' |
| 136 | 149 | and isset($_REQUEST['id']) |
| 137 | -and !intval($_REQUEST['id'])) |
|
| 150 | +and !intval($_REQUEST['id'])) { |
|
| 138 | 151 | $ecran_securite_raison = "puce_statut"; |
| 152 | +} |
|
| 139 | 153 | if (isset($_REQUEST['action']) |
| 140 | 154 | and $_REQUEST['action'] == 'configurer') { |
| 141 | 155 | if (@file_exists('inc_version.php') |
@@ -160,21 +174,24 @@ discard block |
||
| 160 | 174 | @get_magic_quotes_gpc() ? |
| 161 | 175 | stripslashes(serialize($_REQUEST)) : serialize($_REQUEST), |
| 162 | 176 | chr(0) |
| 163 | -) !== false) |
|
| 177 | +) !== false) { |
|
| 164 | 178 | $ecran_securite_raison = "%00"; |
| 179 | +} |
|
| 165 | 180 | |
| 166 | 181 | /* |
| 167 | 182 | * Bloque les requêtes fond=formulaire_ |
| 168 | 183 | */ |
| 169 | 184 | if (isset($_REQUEST['fond']) |
| 170 | -and preg_match(',^formulaire_,i', $_REQUEST['fond'])) |
|
| 185 | +and preg_match(',^formulaire_,i', $_REQUEST['fond'])) { |
|
| 171 | 186 | $ecran_securite_raison = "fond=formulaire_"; |
| 187 | +} |
|
| 172 | 188 | |
| 173 | 189 | /* |
| 174 | 190 | * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php) |
| 175 | 191 | */ |
| 176 | -if (isset($_REQUEST['GLOBALS'])) |
|
| 192 | +if (isset($_REQUEST['GLOBALS'])) { |
|
| 177 | 193 | $ecran_securite_raison = "GLOBALS[GLOBALS]"; |
| 194 | +} |
|
| 178 | 195 | |
| 179 | 196 | /* |
| 180 | 197 | * Bloque les requêtes des bots sur: |
@@ -185,29 +202,34 @@ discard block |
||
| 185 | 202 | (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
| 186 | 203 | or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
| 187 | 204 | ) |
| 188 | -) |
|
| 205 | +) { |
|
| 189 | 206 | $ecran_securite_raison = "robot agenda/double pagination"; |
| 207 | +} |
|
| 190 | 208 | |
| 191 | 209 | /* |
| 192 | 210 | * Bloque une vieille page de tests de CFG (<1.11) |
| 193 | 211 | * Bloque un XSS sur une page inexistante |
| 194 | 212 | */ |
| 195 | 213 | if (isset($_REQUEST['page'])) { |
| 196 | - if ($_REQUEST['page'] == 'test_cfg') |
|
| 197 | - $ecran_securite_raison = "test_cfg"; |
|
| 198 | - if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) |
|
| 199 | - $ecran_securite_raison = "xsspage"; |
|
| 214 | + if ($_REQUEST['page'] == 'test_cfg') { |
|
| 215 | + $ecran_securite_raison = "test_cfg"; |
|
| 216 | + } |
|
| 217 | + if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) { |
|
| 218 | + $ecran_securite_raison = "xsspage"; |
|
| 219 | + } |
|
| 200 | 220 | if ($_REQUEST['page'] == '404' |
| 201 | - and isset($_REQUEST['erreur'])) |
|
| 202 | - $ecran_securite_raison = "xss404"; |
|
| 203 | -} |
|
| 221 | + and isset($_REQUEST['erreur'])) { |
|
| 222 | + $ecran_securite_raison = "xss404"; |
|
| 223 | + } |
|
| 224 | + } |
|
| 204 | 225 | |
| 205 | 226 | /* |
| 206 | 227 | * XSS par array |
| 207 | 228 | */ |
| 208 | -foreach (array('var_login') as $var) |
|
| 209 | -if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) |
|
| 229 | +foreach (array('var_login') as $var) { |
|
| 230 | + if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) |
|
| 210 | 231 | $ecran_securite_raison = "xss ".$var; |
| 232 | +} |
|
| 211 | 233 | |
| 212 | 234 | /* |
| 213 | 235 | * Parade antivirale contre un cheval de troie |
@@ -217,18 +239,21 @@ discard block |
||
| 217 | 239 | function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) { |
| 218 | 240 | // si jamais on est arrivé ici sur une erreur php |
| 219 | 241 | // et qu'un autre gestionnaire d'erreur est défini, l'appeller |
| 220 | - if ($b && $GLOBALS['tmp_xhgfjokl']) |
|
| 221 | - call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 242 | + if ($b && $GLOBALS['tmp_xhgfjokl']) { |
|
| 243 | + call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 244 | + } |
|
| 222 | 245 | } |
| 223 | 246 | } |
| 224 | -if (isset($_POST['tmp_lkojfghx3'])) |
|
| 247 | +if (isset($_POST['tmp_lkojfghx3'])) { |
|
| 225 | 248 | $ecran_securite_raison = "gumblar"; |
| 249 | +} |
|
| 226 | 250 | |
| 227 | 251 | /* |
| 228 | 252 | * Outils XML mal sécurisés < 2.0.9 |
| 229 | 253 | */ |
| 230 | -if (isset($_REQUEST['transformer_xml'])) |
|
| 254 | +if (isset($_REQUEST['transformer_xml'])) { |
|
| 231 | 255 | $ecran_securite_raison = "transformer_xml"; |
| 256 | +} |
|
| 232 | 257 | |
| 233 | 258 | /* |
| 234 | 259 | * Outils XML mal sécurisés again |
@@ -246,11 +271,13 @@ discard block |
||
| 246 | 271 | * Sauvegarde mal securisée < 2.0.9 |
| 247 | 272 | */ |
| 248 | 273 | if (isset($_REQUEST['nom_sauvegarde']) |
| 249 | -and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) |
|
| 274 | +and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) { |
|
| 250 | 275 | $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
| 276 | +} |
|
| 251 | 277 | if (isset($_REQUEST['znom_sauvegarde']) |
| 252 | -and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) |
|
| 278 | +and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) { |
|
| 253 | 279 | $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
| 280 | +} |
|
| 254 | 281 | |
| 255 | 282 | |
| 256 | 283 | /* |
@@ -258,8 +285,9 @@ discard block |
||
| 258 | 285 | * on vérifie 'page' pour ne pas bloquer ... drupal |
| 259 | 286 | */ |
| 260 | 287 | if (isset($_REQUEST['op']) and isset($_REQUEST['page']) |
| 261 | -and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op'])) |
|
| 288 | +and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op'])) { |
|
| 262 | 289 | $ecran_securite_raison = 'op'; |
| 290 | +} |
|
| 263 | 291 | |
| 264 | 292 | /* |
| 265 | 293 | * Forms & Table ne se méfiait pas assez des uploads de fichiers |
@@ -267,8 +295,9 @@ discard block |
||
| 267 | 295 | if (count($_FILES)){ |
| 268 | 296 | foreach($_FILES as $k => $v){ |
| 269 | 297 | if (preg_match(',^fichier_\d+$,', $k) |
| 270 | - and preg_match(',\.php,i', $v['name'])) |
|
| 271 | - unset($_FILES[$k]); |
|
| 298 | + and preg_match(',\.php,i', $v['name'])) { |
|
| 299 | + unset($_FILES[$k]); |
|
| 300 | + } |
|
| 272 | 301 | } |
| 273 | 302 | } |
| 274 | 303 | /* |
@@ -285,21 +314,24 @@ discard block |
||
| 285 | 314 | * reinstall=oui un peu trop permissif |
| 286 | 315 | */ |
| 287 | 316 | if (isset($_REQUEST['reinstall']) |
| 288 | -and $_REQUEST['reinstall'] == 'oui') |
|
| 317 | +and $_REQUEST['reinstall'] == 'oui') { |
|
| 289 | 318 | $ecran_securite_raison = 'reinstall=oui'; |
| 319 | +} |
|
| 290 | 320 | |
| 291 | 321 | /* |
| 292 | 322 | * Échappement xss referer |
| 293 | 323 | */ |
| 294 | -if (isset($_SERVER['HTTP_REFERER'])) |
|
| 324 | +if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 295 | 325 | $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##'); |
| 326 | +} |
|
| 296 | 327 | |
| 297 | 328 | |
| 298 | 329 | /* |
| 299 | 330 | * Echappement HTTP_X_FORWARDED_HOST |
| 300 | 331 | */ |
| 301 | -if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) |
|
| 332 | +if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 302 | 333 | $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________'); |
| 334 | +} |
|
| 303 | 335 | |
| 304 | 336 | |
| 305 | 337 | /* |
@@ -307,9 +339,10 @@ discard block |
||
| 307 | 339 | */ |
| 308 | 340 | if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false){ |
| 309 | 341 | $zzzz = implode("", array_keys($_REQUEST)); |
| 310 | - if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) |
|
| 311 | - $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 312 | -} |
|
| 342 | + if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) { |
|
| 343 | + $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 344 | + } |
|
| 345 | + } |
|
| 313 | 346 | |
| 314 | 347 | /* |
| 315 | 348 | * Injection par connect |
@@ -358,8 +391,9 @@ discard block |
||
| 358 | 391 | /* |
| 359 | 392 | * Bloque les bots quand le load déborde |
| 360 | 393 | */ |
| 361 | -if (!defined('_ECRAN_SECURITE_LOAD')) |
|
| 394 | +if (!defined('_ECRAN_SECURITE_LOAD')) { |
|
| 362 | 395 | define('_ECRAN_SECURITE_LOAD', 4); |
| 396 | +} |
|
| 363 | 397 | |
| 364 | 398 | if ( |
| 365 | 399 | defined('_ECRAN_SECURITE_LOAD') |