@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | // si demande de traduction |
| 65 | 65 | // on recupere les valeurs de la traduction |
| 66 | 66 | if ($lier_trad) { |
| 67 | - if ($select = charger_fonction("precharger_traduction_" . $type, 'inc', true)) { |
|
| 67 | + if ($select = charger_fonction("precharger_traduction_".$type, 'inc', true)) { |
|
| 68 | 68 | $row = $select($id_objet, $id_rubrique, $lier_trad); |
| 69 | 69 | } else { |
| 70 | 70 | $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | // recuperer le secteur, pour affecter les bons champs extras |
| 103 | 103 | if ($id_rubrique and $is_secteur) { |
| 104 | 104 | if (!$row['id_secteur']) { |
| 105 | - $row_rub = sql_getfetsel("id_secteur", "spip_rubriques", "id_rubrique=" . sql_quote($id_rubrique)); |
|
| 105 | + $row_rub = sql_getfetsel("id_secteur", "spip_rubriques", "id_rubrique=".sql_quote($id_rubrique)); |
|
| 106 | 106 | $row['id_secteur'] = $row_rub; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $row = sql_fetsel("*", $table, "$_id_objet=".intval($lier_trad)); |
| 137 | 137 | if ($row) { |
| 138 | 138 | include_spip('inc/filtres'); |
| 139 | - $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 139 | + $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')).' '.$row[$champ_titre]; |
|
| 140 | 140 | } else { |
| 141 | 141 | $row = array(); |
| 142 | 142 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", |
| 180 | - "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=".intval($id_parent)); |
|
| 180 | + "lang='".$GLOBALS['spip_lang']."' AND id_parent=".intval($id_parent)); |
|
| 181 | 181 | if ($row_rub) { |
| 182 | 182 | $row['id_rubrique'] = $row_rub['id_rubrique']; |
| 183 | 183 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/autoriser'); // necessaire si appel de l'espace public |
@@ -45,69 +45,69 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function precharger_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 47 | 47 | |
| 48 | - $table = table_objet_sql($type); |
|
| 49 | - $_id_objet = id_table_objet($table); |
|
| 50 | - |
|
| 51 | - // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | - if (is_numeric($id_objet)) { |
|
| 53 | - return sql_fetsel("*", $table, "$_id_objet=".intval($id_objet)); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // ici, on demande une creation. |
|
| 57 | - // on prerempli certains elements : les champs si traduction, |
|
| 58 | - // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | - $desc = lister_tables_objets_sql($table); |
|
| 60 | - # il faudrait calculer $champ_titre ici |
|
| 61 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | - $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | - |
|
| 64 | - // si demande de traduction |
|
| 65 | - // on recupere les valeurs de la traduction |
|
| 66 | - if ($lier_trad) { |
|
| 67 | - if ($select = charger_fonction("precharger_traduction_" . $type, 'inc', true)) { |
|
| 68 | - $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | - } else { |
|
| 70 | - $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - $row[$champ_titre] = ''; |
|
| 74 | - if ($is_rubrique) { |
|
| 75 | - $row['id_rubrique'] = $id_rubrique; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // calcul de la rubrique |
|
| 80 | - # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | - if ($is_rubrique) { |
|
| 82 | - // appel du script a la racine, faut choisir |
|
| 83 | - // admin restreint ==> sa premiere rubrique |
|
| 84 | - // autre ==> la derniere rubrique cree |
|
| 85 | - if (!$row['id_rubrique']) { |
|
| 86 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 87 | - $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 88 | - } else { |
|
| 89 | - $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", "", "", "id_rubrique DESC", 1); |
|
| 90 | - $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 91 | - } |
|
| 92 | - if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 93 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 94 | - $res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0"); |
|
| 95 | - while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 96 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // recuperer le secteur, pour affecter les bons champs extras |
|
| 103 | - if ($id_rubrique and $is_secteur) { |
|
| 104 | - if (!$row['id_secteur']) { |
|
| 105 | - $row_rub = sql_getfetsel("id_secteur", "spip_rubriques", "id_rubrique=" . sql_quote($id_rubrique)); |
|
| 106 | - $row['id_secteur'] = $row_rub; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $row; |
|
| 48 | + $table = table_objet_sql($type); |
|
| 49 | + $_id_objet = id_table_objet($table); |
|
| 50 | + |
|
| 51 | + // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | + if (is_numeric($id_objet)) { |
|
| 53 | + return sql_fetsel("*", $table, "$_id_objet=".intval($id_objet)); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // ici, on demande une creation. |
|
| 57 | + // on prerempli certains elements : les champs si traduction, |
|
| 58 | + // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | + $desc = lister_tables_objets_sql($table); |
|
| 60 | + # il faudrait calculer $champ_titre ici |
|
| 61 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | + $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | + |
|
| 64 | + // si demande de traduction |
|
| 65 | + // on recupere les valeurs de la traduction |
|
| 66 | + if ($lier_trad) { |
|
| 67 | + if ($select = charger_fonction("precharger_traduction_" . $type, 'inc', true)) { |
|
| 68 | + $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | + } else { |
|
| 70 | + $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + $row[$champ_titre] = ''; |
|
| 74 | + if ($is_rubrique) { |
|
| 75 | + $row['id_rubrique'] = $id_rubrique; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // calcul de la rubrique |
|
| 80 | + # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | + if ($is_rubrique) { |
|
| 82 | + // appel du script a la racine, faut choisir |
|
| 83 | + // admin restreint ==> sa premiere rubrique |
|
| 84 | + // autre ==> la derniere rubrique cree |
|
| 85 | + if (!$row['id_rubrique']) { |
|
| 86 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 87 | + $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 88 | + } else { |
|
| 89 | + $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", "", "", "id_rubrique DESC", 1); |
|
| 90 | + $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 91 | + } |
|
| 92 | + if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 93 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 94 | + $res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0"); |
|
| 95 | + while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 96 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // recuperer le secteur, pour affecter les bons champs extras |
|
| 103 | + if ($id_rubrique and $is_secteur) { |
|
| 104 | + if (!$row['id_secteur']) { |
|
| 105 | + $row_rub = sql_getfetsel("id_secteur", "spip_rubriques", "id_rubrique=" . sql_quote($id_rubrique)); |
|
| 106 | + $row['id_secteur'] = $row_rub; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $row; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -129,76 +129,76 @@ discard block |
||
| 129 | 129 | * Couples clés / valeurs des champs du formulaire à charger |
| 130 | 130 | **/ |
| 131 | 131 | function precharger_traduction_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 132 | - $table = table_objet_sql($type); |
|
| 133 | - $_id_objet = id_table_objet($table); |
|
| 134 | - |
|
| 135 | - // Recuperer les donnees de l'objet original |
|
| 136 | - $row = sql_fetsel("*", $table, "$_id_objet=".intval($lier_trad)); |
|
| 137 | - if ($row) { |
|
| 138 | - include_spip('inc/filtres'); |
|
| 139 | - $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 140 | - } else { |
|
| 141 | - $row = array(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // on met l'objet dans une rubrique si l'objet le peut |
|
| 145 | - $desc = lister_tables_objets_sql($table); |
|
| 146 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 147 | - |
|
| 148 | - if ($is_rubrique) { |
|
| 149 | - $langues_dispo = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 150 | - // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 151 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo) and $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 152 | - $row['lang'] = $GLOBALS['spip_lang']; |
|
| 153 | - } |
|
| 154 | - // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 155 | - elseif (count($langues_dispo) == 2) { |
|
| 156 | - $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 157 | - if (count($autre_langue) == 1) { |
|
| 158 | - $row['lang'] = reset($autre_langue); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - else { |
|
| 162 | - $row['lang'] = 'en'; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - if ($id_rubrique) { |
|
| 166 | - $row['id_rubrique'] = $id_rubrique; |
|
| 167 | - |
|
| 168 | - return $row; |
|
| 169 | - } |
|
| 170 | - $id_rubrique = $row['id_rubrique']; |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - // Regler la langue, si possible, sur celle du redacteur |
|
| 174 | - // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 175 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 176 | - |
|
| 177 | - // Si le menu de langues est autorise sur l'objet, |
|
| 178 | - // on peut changer la langue quelle que soit la rubrique |
|
| 179 | - // donc on reste dans la meme rubrique |
|
| 180 | - if (in_array($table, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 181 | - $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 182 | - |
|
| 183 | - // Sinon, chercher la rubrique la plus adaptee pour |
|
| 184 | - // accueillir l'objet dans la langue du traducteur |
|
| 185 | - } elseif ($is_rubrique and $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 186 | - if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 187 | - $id_parent = 0; |
|
| 188 | - } else { |
|
| 189 | - // on cherche une rubrique soeur dans la bonne langue |
|
| 190 | - $row_rub = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=".intval($id_rubrique)); |
|
| 191 | - $id_parent = $row_rub['id_parent']; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", |
|
| 195 | - "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=".intval($id_parent)); |
|
| 196 | - if ($row_rub) { |
|
| 197 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return $row; |
|
| 132 | + $table = table_objet_sql($type); |
|
| 133 | + $_id_objet = id_table_objet($table); |
|
| 134 | + |
|
| 135 | + // Recuperer les donnees de l'objet original |
|
| 136 | + $row = sql_fetsel("*", $table, "$_id_objet=".intval($lier_trad)); |
|
| 137 | + if ($row) { |
|
| 138 | + include_spip('inc/filtres'); |
|
| 139 | + $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 140 | + } else { |
|
| 141 | + $row = array(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // on met l'objet dans une rubrique si l'objet le peut |
|
| 145 | + $desc = lister_tables_objets_sql($table); |
|
| 146 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 147 | + |
|
| 148 | + if ($is_rubrique) { |
|
| 149 | + $langues_dispo = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 150 | + // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 151 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo) and $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 152 | + $row['lang'] = $GLOBALS['spip_lang']; |
|
| 153 | + } |
|
| 154 | + // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 155 | + elseif (count($langues_dispo) == 2) { |
|
| 156 | + $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 157 | + if (count($autre_langue) == 1) { |
|
| 158 | + $row['lang'] = reset($autre_langue); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + else { |
|
| 162 | + $row['lang'] = 'en'; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + if ($id_rubrique) { |
|
| 166 | + $row['id_rubrique'] = $id_rubrique; |
|
| 167 | + |
|
| 168 | + return $row; |
|
| 169 | + } |
|
| 170 | + $id_rubrique = $row['id_rubrique']; |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + // Regler la langue, si possible, sur celle du redacteur |
|
| 174 | + // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 175 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 176 | + |
|
| 177 | + // Si le menu de langues est autorise sur l'objet, |
|
| 178 | + // on peut changer la langue quelle que soit la rubrique |
|
| 179 | + // donc on reste dans la meme rubrique |
|
| 180 | + if (in_array($table, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 181 | + $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 182 | + |
|
| 183 | + // Sinon, chercher la rubrique la plus adaptee pour |
|
| 184 | + // accueillir l'objet dans la langue du traducteur |
|
| 185 | + } elseif ($is_rubrique and $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 186 | + if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 187 | + $id_parent = 0; |
|
| 188 | + } else { |
|
| 189 | + // on cherche une rubrique soeur dans la bonne langue |
|
| 190 | + $row_rub = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=".intval($id_rubrique)); |
|
| 191 | + $id_parent = $row_rub['id_parent']; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", |
|
| 195 | + "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=".intval($id_parent)); |
|
| 196 | + if ($row_rub) { |
|
| 197 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return $row; |
|
| 204 | 204 | } |
@@ -157,8 +157,7 @@ |
||
| 157 | 157 | if (count($autre_langue) == 1) { |
| 158 | 158 | $row['lang'] = reset($autre_langue); |
| 159 | 159 | } |
| 160 | - } |
|
| 161 | - else { |
|
| 160 | + } else { |
|
| 162 | 161 | $row['lang'] = 'en'; |
| 163 | 162 | } |
| 164 | 163 | |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/rechercher'); |
| 24 | 24 | if (!defined('_DELAI_CACHE_resultats')) { |
| 25 | - define('_DELAI_CACHE_resultats', 600); |
|
| 25 | + define('_DELAI_CACHE_resultats', 600); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -49,111 +49,111 @@ discard block |
||
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | 51 | function inc_prepare_recherche_dist( |
| 52 | - $recherche, |
|
| 53 | - $table = 'articles', |
|
| 54 | - $cond = false, |
|
| 55 | - $serveur = '', |
|
| 56 | - $modificateurs = array(), |
|
| 57 | - $primary = '' |
|
| 52 | + $recherche, |
|
| 53 | + $table = 'articles', |
|
| 54 | + $cond = false, |
|
| 55 | + $serveur = '', |
|
| 56 | + $modificateurs = array(), |
|
| 57 | + $primary = '' |
|
| 58 | 58 | ) { |
| 59 | - static $cache = array(); |
|
| 60 | - $delai_fraicheur = min(_DELAI_CACHE_resultats, |
|
| 61 | - time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)); |
|
| 62 | - |
|
| 63 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 64 | - // ca permet de faire des inclure simple. |
|
| 65 | - if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 66 | - $recherche = $GLOBALS['recherche']; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // traiter le cas {recherche?} |
|
| 70 | - if ($cond and !strlen($recherche)) { |
|
| 71 | - return array( |
|
| 72 | - "0 as points" /* as points */, /* where */ |
|
| 73 | - '' |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - $rechercher = false; |
|
| 79 | - |
|
| 80 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
|
| 81 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 82 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 83 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | - $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
|
| 86 | - $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | - if (!$row |
|
| 88 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 89 | - ) { |
|
| 90 | - $rechercher = true; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 95 | - if ($rechercher) { |
|
| 96 | - //$tables = liste_des_champs(); |
|
| 97 | - $x = objet_type($table); |
|
| 98 | - $points = recherche_en_base($recherche, |
|
| 99 | - $x, |
|
| 100 | - array( |
|
| 101 | - 'score' => true, |
|
| 102 | - 'toutvoir' => true, |
|
| 103 | - 'jointures' => true |
|
| 104 | - ), |
|
| 105 | - $serveur); |
|
| 106 | - // pas de résultat, pas de point |
|
| 107 | - $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 108 | - |
|
| 109 | - // permettre aux plugins de modifier le resultat |
|
| 110 | - $points = pipeline('prepare_recherche', array( |
|
| 111 | - 'args' => array( |
|
| 112 | - 'type' => $x, |
|
| 113 | - 'recherche' => $recherche, |
|
| 114 | - 'serveur' => $serveur, |
|
| 115 | - 'modificateurs' => $modificateurs |
|
| 116 | - ), |
|
| 117 | - 'data' => $points |
|
| 118 | - )); |
|
| 119 | - |
|
| 120 | - // supprimer les anciens resultats de cette recherche |
|
| 121 | - // et les resultats trop vieux avec une marge |
|
| 122 | - // pas de AS resultats dans un delete (mysql) |
|
| 123 | - $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"), |
|
| 124 | - array("recherche", "table_objet", "serveur"), $where); |
|
| 125 | - |
|
| 126 | - sql_delete('spip_resultats', |
|
| 127 | - "NOT($where_resultat_recent) OR ($whered)"); |
|
| 128 | - |
|
| 129 | - // inserer les resultats dans la table de cache des resultats |
|
| 130 | - if (count($points)) { |
|
| 131 | - $tab_couples = array(); |
|
| 132 | - foreach ($points as $id => $p) { |
|
| 133 | - $tab_couples[] = array( |
|
| 134 | - 'recherche' => $hash, |
|
| 135 | - 'id' => $id, |
|
| 136 | - 'points' => $p['score'], |
|
| 137 | - 'table_objet' => $table, |
|
| 138 | - 'serveur' => $hash_serv, |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - sql_insertq_multi('spip_resultats', $tab_couples, array()); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 146 | - if (!$serveur) { |
|
| 147 | - $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where); |
|
| 148 | - } else { |
|
| 149 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 150 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 151 | - } |
|
| 152 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $cache[$serveur][$table][$recherche]; |
|
| 59 | + static $cache = array(); |
|
| 60 | + $delai_fraicheur = min(_DELAI_CACHE_resultats, |
|
| 61 | + time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)); |
|
| 62 | + |
|
| 63 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 64 | + // ca permet de faire des inclure simple. |
|
| 65 | + if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 66 | + $recherche = $GLOBALS['recherche']; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // traiter le cas {recherche?} |
|
| 70 | + if ($cond and !strlen($recherche)) { |
|
| 71 | + return array( |
|
| 72 | + "0 as points" /* as points */, /* where */ |
|
| 73 | + '' |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + $rechercher = false; |
|
| 79 | + |
|
| 80 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
|
| 81 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 82 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 83 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | + $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
|
| 86 | + $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | + if (!$row |
|
| 88 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 89 | + ) { |
|
| 90 | + $rechercher = true; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 95 | + if ($rechercher) { |
|
| 96 | + //$tables = liste_des_champs(); |
|
| 97 | + $x = objet_type($table); |
|
| 98 | + $points = recherche_en_base($recherche, |
|
| 99 | + $x, |
|
| 100 | + array( |
|
| 101 | + 'score' => true, |
|
| 102 | + 'toutvoir' => true, |
|
| 103 | + 'jointures' => true |
|
| 104 | + ), |
|
| 105 | + $serveur); |
|
| 106 | + // pas de résultat, pas de point |
|
| 107 | + $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 108 | + |
|
| 109 | + // permettre aux plugins de modifier le resultat |
|
| 110 | + $points = pipeline('prepare_recherche', array( |
|
| 111 | + 'args' => array( |
|
| 112 | + 'type' => $x, |
|
| 113 | + 'recherche' => $recherche, |
|
| 114 | + 'serveur' => $serveur, |
|
| 115 | + 'modificateurs' => $modificateurs |
|
| 116 | + ), |
|
| 117 | + 'data' => $points |
|
| 118 | + )); |
|
| 119 | + |
|
| 120 | + // supprimer les anciens resultats de cette recherche |
|
| 121 | + // et les resultats trop vieux avec une marge |
|
| 122 | + // pas de AS resultats dans un delete (mysql) |
|
| 123 | + $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"), |
|
| 124 | + array("recherche", "table_objet", "serveur"), $where); |
|
| 125 | + |
|
| 126 | + sql_delete('spip_resultats', |
|
| 127 | + "NOT($where_resultat_recent) OR ($whered)"); |
|
| 128 | + |
|
| 129 | + // inserer les resultats dans la table de cache des resultats |
|
| 130 | + if (count($points)) { |
|
| 131 | + $tab_couples = array(); |
|
| 132 | + foreach ($points as $id => $p) { |
|
| 133 | + $tab_couples[] = array( |
|
| 134 | + 'recherche' => $hash, |
|
| 135 | + 'id' => $id, |
|
| 136 | + 'points' => $p['score'], |
|
| 137 | + 'table_objet' => $table, |
|
| 138 | + 'serveur' => $hash_serv, |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + sql_insertq_multi('spip_resultats', $tab_couples, array()); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 146 | + if (!$serveur) { |
|
| 147 | + $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where); |
|
| 148 | + } else { |
|
| 149 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 150 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 151 | + } |
|
| 152 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $cache[$serveur][$table][$recherche]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -169,22 +169,22 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 172 | - # calculer le {id_article IN()} et le {... as points} |
|
| 173 | - if (!count($rows)) { |
|
| 174 | - return array("''", "0=1"); |
|
| 175 | - } else { |
|
| 176 | - $listes_ids = array(); |
|
| 177 | - $select = '0'; |
|
| 178 | - foreach ($rows as $r) { |
|
| 179 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - foreach ($listes_ids as $p => $ids) { |
|
| 183 | - $select .= "+$p*(" . |
|
| 184 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 185 | - . ") "; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)); |
|
| 189 | - } |
|
| 172 | + # calculer le {id_article IN()} et le {... as points} |
|
| 173 | + if (!count($rows)) { |
|
| 174 | + return array("''", "0=1"); |
|
| 175 | + } else { |
|
| 176 | + $listes_ids = array(); |
|
| 177 | + $select = '0'; |
|
| 178 | + foreach ($rows as $r) { |
|
| 179 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + foreach ($listes_ids as $p => $ids) { |
|
| 183 | + $select .= "+$p*(" . |
|
| 184 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 185 | + . ") "; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)); |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND"); |
| 81 | 81 | if (!isset($cache[$serveur][$table][$recherche])) { |
| 82 | 82 | $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
| 83 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 84 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 83 | + $hash = substr(md5($recherche.$table), 0, 16); |
|
| 84 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 85 | 85 | $row = sql_fetsel('recherche', 'spip_resultats AS resultats', |
| 86 | - $where . " AND $where_resultat_recent", '', '', '0,1'); |
|
| 86 | + $where." AND $where_resultat_recent", '', '', '0,1'); |
|
| 87 | 87 | if (!$row |
| 88 | 88 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 89 | 89 | ) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | foreach ($listes_ids as $p => $ids) { |
| 183 | - $select .= "+$p*(" . |
|
| 183 | + $select .= "+$p*(". |
|
| 184 | 184 | sql_in("$table.$primary", $ids, '', $serveur) |
| 185 | 185 | . ") "; |
| 186 | 186 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $contenu = @gzfile($fichier); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string) $contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | 317 | if (substr($fichier, -4) !== '.php') { |
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 318 | + spip_log('Erreur de programmation: '.$fichier.' doit finir par .php'); |
|
| 319 | 319 | } |
| 320 | - $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 320 | + $contenu = "<"."?php die ('Acces interdit'); ?".">\n".$contenu; |
|
| 321 | 321 | |
| 322 | 322 | return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
| 323 | 323 | } |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * @param bool $force |
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | -function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force=false, $use_copy=false) { |
|
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)){ |
|
| 332 | +function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
|
| 333 | + $fichier_tmp = $fichier.'.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | 335 | return false; |
| 336 | 336 | } |
| 337 | 337 | if ($force |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | function lire_fichier_securise($fichier, &$contenu, $options = array()) { |
| 370 | 370 | if ($res = lire_fichier($fichier, $contenu, $options)) { |
| 371 | - $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 371 | + $contenu = substr($contenu, strlen("<"."?php die ('Acces interdit'); ?".">\n")); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | return $res; |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | $invalidate = @opcache_invalidate($filepath, true); |
| 489 | 489 | // si l'invalidation a echoue lever un flag |
| 490 | 490 | if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
| 491 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 491 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 492 | 492 | } |
| 493 | 493 | } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
| 494 | 494 | // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
| 495 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 495 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 496 | 496 | } |
| 497 | 497 | // APC. |
| 498 | 498 | if (function_exists('apc_delete_file')) { |
@@ -532,11 +532,11 @@ discard block |
||
| 532 | 532 | $wait = $duree + 1; |
| 533 | 533 | if ($timestamp) { |
| 534 | 534 | $wait -= (time() - $timestamp); |
| 535 | - if ($wait<0) { |
|
| 535 | + if ($wait < 0) { |
|
| 536 | 536 | $wait = 0; |
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | - spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 539 | + spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 540 | 540 | if ($wait) { |
| 541 | 541 | sleep($duree + 1); |
| 542 | 542 | } |
@@ -564,9 +564,9 @@ discard block |
||
| 564 | 564 | if ($item == '.' || $item == '..') { |
| 565 | 565 | continue; |
| 566 | 566 | } |
| 567 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 568 | - @chmod($dir . "/" . $item, 0777); |
|
| 569 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 567 | + if (!supprimer_repertoire($dir."/".$item)) { |
|
| 568 | + @chmod($dir."/".$item, 0777); |
|
| 569 | + if (!supprimer_repertoire($dir."/".$item)) { |
|
| 570 | 570 | return false; |
| 571 | 571 | } |
| 572 | 572 | }; |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | if (!strlen($subdir)) { |
| 612 | 612 | $n = strrpos($base, "/"); |
| 613 | 613 | if ($n === false) { |
| 614 | - return $nobase ? '' : ($base . '/'); |
|
| 614 | + return $nobase ? '' : ($base.'/'); |
|
| 615 | 615 | } |
| 616 | 616 | $subdir = substr($base, $n + 1); |
| 617 | 617 | $base = substr($base, 0, $n + 1); |
@@ -621,14 +621,14 @@ discard block |
||
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | $baseaff = $nobase ? '' : $base; |
| 624 | - if (isset($dirs[$base . $subdir])) { |
|
| 625 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 624 | + if (isset($dirs[$base.$subdir])) { |
|
| 625 | + return $baseaff.$dirs[$base.$subdir]; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 628 | + $path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 629 | 629 | |
| 630 | 630 | if (file_exists("$path/.ok")) { |
| 631 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 631 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | @mkdir($path, _SPIP_CHMOD); |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | @touch("$path/.ok"); |
| 639 | 639 | spip_log("creation $base$subdir/"); |
| 640 | 640 | |
| 641 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 641 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
@@ -648,10 +648,10 @@ discard block |
||
| 648 | 648 | return ''; |
| 649 | 649 | } |
| 650 | 650 | if (!_DIR_RESTREINT) { |
| 651 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 651 | + $base = preg_replace(',^'._DIR_RACINE.',', '', $base); |
|
| 652 | 652 | } |
| 653 | 653 | $base .= $subdir; |
| 654 | - raler_fichier($base . '/.ok'); |
|
| 654 | + raler_fichier($base.'/.ok'); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $beginning = $fichiers; |
| 720 | 720 | $end = preg_files("$f/", $pattern, |
| 721 | 721 | $maxfiles - $nbfiles, $recurs); |
| 722 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 722 | + $fichiers = array_merge((array) $beginning, (array) $end); |
|
| 723 | 723 | $nbfiles = count($fichiers); |
| 724 | 724 | } |
| 725 | 725 | } |
@@ -339,8 +339,7 @@ |
||
| 339 | 339 | or md5_file($fichier) != md5_file($fichier_tmp)) { |
| 340 | 340 | if ($use_copy) { |
| 341 | 341 | @copy($fichier_tmp, $fichier); |
| 342 | - } |
|
| 343 | - else { |
|
| 342 | + } else { |
|
| 344 | 343 | @rename($fichier_tmp, $fichier); |
| 345 | 344 | } |
| 346 | 345 | // eviter que PHP ne reserve le vieux timestamp |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = array(); |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = array()) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, ".php") !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, ".php") !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,23 +330,23 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force=false, $use_copy=false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)){ |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ($force |
|
| 338 | - or !file_exists($fichier) |
|
| 339 | - or md5_file($fichier) != md5_file($fichier_tmp)) { |
|
| 340 | - if ($use_copy) { |
|
| 341 | - @copy($fichier_tmp, $fichier); |
|
| 342 | - } |
|
| 343 | - else { |
|
| 344 | - @rename($fichier_tmp, $fichier); |
|
| 345 | - } |
|
| 346 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 347 | - clearstatcache(true, $fichier); |
|
| 348 | - } |
|
| 349 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)){ |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ($force |
|
| 338 | + or !file_exists($fichier) |
|
| 339 | + or md5_file($fichier) != md5_file($fichier_tmp)) { |
|
| 340 | + if ($use_copy) { |
|
| 341 | + @copy($fichier_tmp, $fichier); |
|
| 342 | + } |
|
| 343 | + else { |
|
| 344 | + @rename($fichier_tmp, $fichier); |
|
| 345 | + } |
|
| 346 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 347 | + clearstatcache(true, $fichier); |
|
| 348 | + } |
|
| 349 | + return true; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -367,11 +367,11 @@ discard block |
||
| 367 | 367 | * true si l'opération a réussie, false sinon. |
| 368 | 368 | */ |
| 369 | 369 | function lire_fichier_securise($fichier, &$contenu, $options = array()) { |
| 370 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 371 | - $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 372 | - } |
|
| 370 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 371 | + $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - return $res; |
|
| 374 | + return $res; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -386,20 +386,20 @@ discard block |
||
| 386 | 386 | * Chemin du fichier |
| 387 | 387 | **/ |
| 388 | 388 | function raler_fichier($fichier) { |
| 389 | - include_spip('inc/minipres'); |
|
| 390 | - $dir = dirname($fichier); |
|
| 391 | - http_status(401); |
|
| 392 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 393 | - . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 394 | - . " <a href='" |
|
| 395 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 396 | - . "'>" |
|
| 397 | - . _T('texte_inc_meta_2') |
|
| 398 | - . "</a> " |
|
| 399 | - . _T('texte_inc_meta_3', |
|
| 400 | - array('repertoire' => joli_repertoire($dir))) |
|
| 401 | - . "</h4>\n"); |
|
| 402 | - exit; |
|
| 389 | + include_spip('inc/minipres'); |
|
| 390 | + $dir = dirname($fichier); |
|
| 391 | + http_status(401); |
|
| 392 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 393 | + . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 394 | + . " <a href='" |
|
| 395 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 396 | + . "'>" |
|
| 397 | + . _T('texte_inc_meta_2') |
|
| 398 | + . "</a> " |
|
| 399 | + . _T('texte_inc_meta_3', |
|
| 400 | + array('repertoire' => joli_repertoire($dir))) |
|
| 401 | + . "</h4>\n"); |
|
| 402 | + exit; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -414,14 +414,14 @@ discard block |
||
| 414 | 414 | * - true si récent, false sinon |
| 415 | 415 | */ |
| 416 | 416 | function jeune_fichier($fichier, $n) { |
| 417 | - if (!file_exists($fichier)) { |
|
| 418 | - return false; |
|
| 419 | - } |
|
| 420 | - if (!$c = @filemtime($fichier)) { |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return (time() - $n <= $c); |
|
| 417 | + if (!file_exists($fichier)) { |
|
| 418 | + return false; |
|
| 419 | + } |
|
| 420 | + if (!$c = @filemtime($fichier)) { |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return (time() - $n <= $c); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -436,22 +436,22 @@ discard block |
||
| 436 | 436 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 437 | 437 | */ |
| 438 | 438 | function supprimer_fichier($fichier, $lock = true) { |
| 439 | - if (!@file_exists($fichier)) { |
|
| 440 | - return true; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if ($lock) { |
|
| 444 | - // verrouiller le fichier destination |
|
| 445 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 446 | - return false; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - // liberer le verrou |
|
| 450 | - spip_fclose_unlock($fp); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // supprimer |
|
| 454 | - return @unlink($fichier); |
|
| 439 | + if (!@file_exists($fichier)) { |
|
| 440 | + return true; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if ($lock) { |
|
| 444 | + // verrouiller le fichier destination |
|
| 445 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 446 | + return false; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + // liberer le verrou |
|
| 450 | + spip_fclose_unlock($fp); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // supprimer |
|
| 454 | + return @unlink($fichier); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | * Chemin du fichier |
| 462 | 462 | */ |
| 463 | 463 | function spip_unlink($f) { |
| 464 | - if (!is_dir($f)) { |
|
| 465 | - supprimer_fichier($f, false); |
|
| 466 | - } else { |
|
| 467 | - @unlink("$f/.ok"); |
|
| 468 | - @rmdir($f); |
|
| 469 | - } |
|
| 464 | + if (!is_dir($f)) { |
|
| 465 | + supprimer_fichier($f, false); |
|
| 466 | + } else { |
|
| 467 | + @unlink("$f/.ok"); |
|
| 468 | + @rmdir($f); |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,26 +480,26 @@ discard block |
||
| 480 | 480 | * The absolute path of the PHP file to invalidate. |
| 481 | 481 | */ |
| 482 | 482 | function spip_clear_opcode_cache($filepath) { |
| 483 | - clearstatcache(true, $filepath); |
|
| 484 | - |
|
| 485 | - // Zend OPcache |
|
| 486 | - if (function_exists('opcache_invalidate')) { |
|
| 487 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 488 | - // si l'invalidation a echoue lever un flag |
|
| 489 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 490 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 491 | - } |
|
| 492 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 493 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 494 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 495 | - } |
|
| 496 | - // APC. |
|
| 497 | - if (function_exists('apc_delete_file')) { |
|
| 498 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 499 | - // not compiled yet. |
|
| 500 | - // @see http://php.net/apc-delete-file |
|
| 501 | - @apc_delete_file($filepath); |
|
| 502 | - } |
|
| 483 | + clearstatcache(true, $filepath); |
|
| 484 | + |
|
| 485 | + // Zend OPcache |
|
| 486 | + if (function_exists('opcache_invalidate')) { |
|
| 487 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 488 | + // si l'invalidation a echoue lever un flag |
|
| 489 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 490 | + define('_spip_attend_invalidation_opcode_cache',true); |
|
| 491 | + } |
|
| 492 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 493 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 494 | + define('_spip_attend_invalidation_opcode_cache',true); |
|
| 495 | + } |
|
| 496 | + // APC. |
|
| 497 | + if (function_exists('apc_delete_file')) { |
|
| 498 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 499 | + // not compiled yet. |
|
| 500 | + // @see http://php.net/apc-delete-file |
|
| 501 | + @apc_delete_file($filepath); |
|
| 502 | + } |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -522,24 +522,24 @@ discard block |
||
| 522 | 522 | * |
| 523 | 523 | */ |
| 524 | 524 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 525 | - if (function_exists('opcache_get_configuration') |
|
| 526 | - and @ini_get('opcache.enable') |
|
| 527 | - and @ini_get('opcache.validate_timestamps') |
|
| 528 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 529 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 530 | - ) { |
|
| 531 | - $wait = $duree + 1; |
|
| 532 | - if ($timestamp) { |
|
| 533 | - $wait -= (time() - $timestamp); |
|
| 534 | - if ($wait<0) { |
|
| 535 | - $wait = 0; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 539 | - if ($wait) { |
|
| 540 | - sleep($duree + 1); |
|
| 541 | - } |
|
| 542 | - } |
|
| 525 | + if (function_exists('opcache_get_configuration') |
|
| 526 | + and @ini_get('opcache.enable') |
|
| 527 | + and @ini_get('opcache.validate_timestamps') |
|
| 528 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 529 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 530 | + ) { |
|
| 531 | + $wait = $duree + 1; |
|
| 532 | + if ($timestamp) { |
|
| 533 | + $wait -= (time() - $timestamp); |
|
| 534 | + if ($wait<0) { |
|
| 535 | + $wait = 0; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 539 | + if ($wait) { |
|
| 540 | + sleep($duree + 1); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -552,26 +552,26 @@ discard block |
||
| 552 | 552 | * @return bool Suppression reussie. |
| 553 | 553 | */ |
| 554 | 554 | function supprimer_repertoire($dir) { |
| 555 | - if (!file_exists($dir)) { |
|
| 556 | - return true; |
|
| 557 | - } |
|
| 558 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 559 | - return @unlink($dir); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - foreach (scandir($dir) as $item) { |
|
| 563 | - if ($item == '.' || $item == '..') { |
|
| 564 | - continue; |
|
| 565 | - } |
|
| 566 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 567 | - @chmod($dir . "/" . $item, 0777); |
|
| 568 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 569 | - return false; |
|
| 570 | - } |
|
| 571 | - }; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - return @rmdir($dir); |
|
| 555 | + if (!file_exists($dir)) { |
|
| 556 | + return true; |
|
| 557 | + } |
|
| 558 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 559 | + return @unlink($dir); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + foreach (scandir($dir) as $item) { |
|
| 563 | + if ($item == '.' || $item == '..') { |
|
| 564 | + continue; |
|
| 565 | + } |
|
| 566 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 567 | + @chmod($dir . "/" . $item, 0777); |
|
| 568 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + }; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + return @rmdir($dir); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | |
@@ -600,57 +600,57 @@ discard block |
||
| 600 | 600 | * Chemin du répertoire créé. |
| 601 | 601 | **/ |
| 602 | 602 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 603 | - static $dirs = array(); |
|
| 604 | - |
|
| 605 | - $base = str_replace("//", "/", $base); |
|
| 606 | - |
|
| 607 | - # suppr le dernier caractere si c'est un / |
|
| 608 | - $base = rtrim($base, '/'); |
|
| 609 | - |
|
| 610 | - if (!strlen($subdir)) { |
|
| 611 | - $n = strrpos($base, "/"); |
|
| 612 | - if ($n === false) { |
|
| 613 | - return $nobase ? '' : ($base . '/'); |
|
| 614 | - } |
|
| 615 | - $subdir = substr($base, $n + 1); |
|
| 616 | - $base = substr($base, 0, $n + 1); |
|
| 617 | - } else { |
|
| 618 | - $base .= '/'; |
|
| 619 | - $subdir = str_replace("/", "", $subdir); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - $baseaff = $nobase ? '' : $base; |
|
| 623 | - if (isset($dirs[$base . $subdir])) { |
|
| 624 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 628 | - |
|
| 629 | - if (file_exists("$path/.ok")) { |
|
| 630 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - @mkdir($path, _SPIP_CHMOD); |
|
| 634 | - @chmod($path, _SPIP_CHMOD); |
|
| 635 | - |
|
| 636 | - if (is_dir($path) && is_writable($path)) { |
|
| 637 | - @touch("$path/.ok"); |
|
| 638 | - spip_log("creation $base$subdir/"); |
|
| 639 | - |
|
| 640 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 644 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 645 | - spip_log("echec creation $base${subdir}"); |
|
| 646 | - if ($tantpis) { |
|
| 647 | - return ''; |
|
| 648 | - } |
|
| 649 | - if (!_DIR_RESTREINT) { |
|
| 650 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 651 | - } |
|
| 652 | - $base .= $subdir; |
|
| 653 | - raler_fichier($base . '/.ok'); |
|
| 603 | + static $dirs = array(); |
|
| 604 | + |
|
| 605 | + $base = str_replace("//", "/", $base); |
|
| 606 | + |
|
| 607 | + # suppr le dernier caractere si c'est un / |
|
| 608 | + $base = rtrim($base, '/'); |
|
| 609 | + |
|
| 610 | + if (!strlen($subdir)) { |
|
| 611 | + $n = strrpos($base, "/"); |
|
| 612 | + if ($n === false) { |
|
| 613 | + return $nobase ? '' : ($base . '/'); |
|
| 614 | + } |
|
| 615 | + $subdir = substr($base, $n + 1); |
|
| 616 | + $base = substr($base, 0, $n + 1); |
|
| 617 | + } else { |
|
| 618 | + $base .= '/'; |
|
| 619 | + $subdir = str_replace("/", "", $subdir); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + $baseaff = $nobase ? '' : $base; |
|
| 623 | + if (isset($dirs[$base . $subdir])) { |
|
| 624 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 628 | + |
|
| 629 | + if (file_exists("$path/.ok")) { |
|
| 630 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + @mkdir($path, _SPIP_CHMOD); |
|
| 634 | + @chmod($path, _SPIP_CHMOD); |
|
| 635 | + |
|
| 636 | + if (is_dir($path) && is_writable($path)) { |
|
| 637 | + @touch("$path/.ok"); |
|
| 638 | + spip_log("creation $base$subdir/"); |
|
| 639 | + |
|
| 640 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 644 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 645 | + spip_log("echec creation $base${subdir}"); |
|
| 646 | + if ($tantpis) { |
|
| 647 | + return ''; |
|
| 648 | + } |
|
| 649 | + if (!_DIR_RESTREINT) { |
|
| 650 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 651 | + } |
|
| 652 | + $base .= $subdir; |
|
| 653 | + raler_fichier($base . '/.ok'); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | |
@@ -683,51 +683,51 @@ discard block |
||
| 683 | 683 | * Chemins des fichiers trouvés. |
| 684 | 684 | **/ |
| 685 | 685 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) { |
| 686 | - $nbfiles = 0; |
|
| 687 | - if ($pattern == -1) { |
|
| 688 | - $pattern = "^$dir"; |
|
| 689 | - } |
|
| 690 | - $fichiers = array(); |
|
| 691 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 692 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 693 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 694 | - if ($dir == '') { |
|
| 695 | - $dir = '.'; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 699 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 700 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 701 | - and $f != 'CVS' |
|
| 702 | - and $f != 'remove.txt' |
|
| 703 | - and is_readable($f = "$dir/$f") |
|
| 704 | - ) { |
|
| 705 | - if (is_file($f)) { |
|
| 706 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 707 | - $fichiers[] = $f; |
|
| 708 | - $nbfiles++; |
|
| 709 | - } |
|
| 710 | - } else { |
|
| 711 | - if (is_dir($f) and is_array($recurs)) { |
|
| 712 | - $rp = @realpath($f); |
|
| 713 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 714 | - $rp = $f; |
|
| 715 | - } # realpath n'est peut etre pas autorise |
|
| 716 | - if (!isset($recurs[$rp])) { |
|
| 717 | - $recurs[$rp] = true; |
|
| 718 | - $beginning = $fichiers; |
|
| 719 | - $end = preg_files("$f/", $pattern, |
|
| 720 | - $maxfiles - $nbfiles, $recurs); |
|
| 721 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 722 | - $nbfiles = count($fichiers); |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - closedir($d); |
|
| 729 | - } |
|
| 730 | - sort($fichiers); |
|
| 731 | - |
|
| 732 | - return $fichiers; |
|
| 686 | + $nbfiles = 0; |
|
| 687 | + if ($pattern == -1) { |
|
| 688 | + $pattern = "^$dir"; |
|
| 689 | + } |
|
| 690 | + $fichiers = array(); |
|
| 691 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 692 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 693 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 694 | + if ($dir == '') { |
|
| 695 | + $dir = '.'; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 699 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 700 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 701 | + and $f != 'CVS' |
|
| 702 | + and $f != 'remove.txt' |
|
| 703 | + and is_readable($f = "$dir/$f") |
|
| 704 | + ) { |
|
| 705 | + if (is_file($f)) { |
|
| 706 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 707 | + $fichiers[] = $f; |
|
| 708 | + $nbfiles++; |
|
| 709 | + } |
|
| 710 | + } else { |
|
| 711 | + if (is_dir($f) and is_array($recurs)) { |
|
| 712 | + $rp = @realpath($f); |
|
| 713 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 714 | + $rp = $f; |
|
| 715 | + } # realpath n'est peut etre pas autorise |
|
| 716 | + if (!isset($recurs[$rp])) { |
|
| 717 | + $recurs[$rp] = true; |
|
| 718 | + $beginning = $fichiers; |
|
| 719 | + $end = preg_files("$f/", $pattern, |
|
| 720 | + $maxfiles - $nbfiles, $recurs); |
|
| 721 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 722 | + $nbfiles = count($fichiers); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + closedir($d); |
|
| 729 | + } |
|
| 730 | + sort($fichiers); |
|
| 731 | + |
|
| 732 | + return $fichiers; |
|
| 733 | 733 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | $dir = constant($dir); |
| 70 | 70 | foreach ($infos['install'] as $file) { |
| 71 | - $file = $dir . $plug . "/" . trim($file); |
|
| 71 | + $file = $dir.$plug."/".trim($file); |
|
| 72 | 72 | if (file_exists($file)) { |
| 73 | 73 | include_once($file); |
| 74 | 74 | } |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
| 82 | 82 | lire_metas($table); |
| 83 | 83 | } |
| 84 | - $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 84 | + $nom_meta = $infos['prefix'].'_base_version'; |
|
| 85 | 85 | |
| 86 | 86 | // Détermination de la fonction à appeler et de ses arguments |
| 87 | - $f = $infos['prefix'] . "_install"; |
|
| 87 | + $f = $infos['prefix']."_install"; |
|
| 88 | 88 | if (!function_exists($f)) { |
| 89 | 89 | $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
| 90 | 90 | $arg = $infos; |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | and spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
| 169 | 169 | break; |
| 170 | 170 | case 'install': |
| 171 | - if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 171 | + if (function_exists($upgrade = $infos['prefix'].'_upgrade')) { |
|
| 172 | 172 | $upgrade($nom_meta, $version_cible, $table); |
| 173 | 173 | } |
| 174 | 174 | break; |
| 175 | 175 | case 'uninstall': |
| 176 | - if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 176 | + if (function_exists($vider_tables = $infos['prefix'].'_vider_tables')) { |
|
| 177 | 177 | $vider_tables($nom_meta, $table); |
| 178 | 178 | } |
| 179 | 179 | break; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -54,96 +54,96 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function plugins_installer_dist($plug, $action, $dir_type = '_DIR_PLUGINS') { |
| 56 | 56 | |
| 57 | - // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 58 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 59 | - $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 60 | - if (!isset($infos['install']) or !$infos['install']) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Passer en chemin absolu si possible, c'est plus efficace |
|
| 65 | - $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 66 | - if (!defined($dir)) { |
|
| 67 | - $dir = $dir_type; |
|
| 68 | - } |
|
| 69 | - $dir = constant($dir); |
|
| 70 | - foreach ($infos['install'] as $file) { |
|
| 71 | - $file = $dir . $plug . "/" . trim($file); |
|
| 72 | - if (file_exists($file)) { |
|
| 73 | - include_once($file); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // Détermination de la table meta et du nom de la meta plugin |
|
| 78 | - $table = 'meta'; |
|
| 79 | - if (isset($infos['meta']) and ($infos['meta'] !== 'meta')) { |
|
| 80 | - $table = $infos['meta']; |
|
| 81 | - // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 82 | - lire_metas($table); |
|
| 83 | - } |
|
| 84 | - $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 85 | - |
|
| 86 | - // Détermination de la fonction à appeler et de ses arguments |
|
| 87 | - $f = $infos['prefix'] . "_install"; |
|
| 88 | - if (!function_exists($f)) { |
|
| 89 | - $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 90 | - $arg = $infos; |
|
| 91 | - // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 92 | - $arg['meta'] = $table; |
|
| 93 | - $arg['nom_meta'] = $nom_meta; |
|
| 94 | - } else { |
|
| 95 | - // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 96 | - // stupide: info deja dans le nom |
|
| 97 | - $arg = $infos['prefix']; |
|
| 98 | - } |
|
| 99 | - $version = isset($infos['schema']) ? $infos['schema'] : ''; |
|
| 100 | - |
|
| 101 | - if (!$f) { |
|
| 102 | - // installation sans operation particuliere |
|
| 103 | - $infos['install_test'] = array(true, ''); |
|
| 104 | - return $infos; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Tester si l'action demandée est nécessaire ou pas. |
|
| 108 | - $test = $f('test', $arg, $version); |
|
| 109 | - if ($action == 'uninstall') { |
|
| 110 | - $test = !$test; |
|
| 111 | - } |
|
| 112 | - // Si deja fait, on ne fait rien et on ne dit rien |
|
| 113 | - if ($test) { |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 118 | - // pour renvoyer le bon message en retour de la fonction. |
|
| 119 | - if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 120 | - $infos['upgrade'] = true; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // executer l'installation ou l'inverse |
|
| 124 | - // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 125 | - ob_start(); |
|
| 126 | - $f($action, $arg, $version); |
|
| 127 | - $aff = ob_get_contents(); |
|
| 128 | - ob_end_clean(); |
|
| 129 | - |
|
| 130 | - // vider le cache des descriptions de tables a chaque (de)installation |
|
| 131 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 132 | - $trouver_table(''); |
|
| 133 | - $infos['install_test'] = array($f('test', $arg, $version), $aff); |
|
| 134 | - |
|
| 135 | - // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 136 | - // on force la création du fichier cache à la date du moment. |
|
| 137 | - // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 138 | - if ( |
|
| 139 | - ($table !== 'meta') |
|
| 140 | - and ($action == 'install') |
|
| 141 | - and empty($infos['upgrade']) |
|
| 142 | - ) { |
|
| 143 | - touch_meta(false, $table); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $infos; |
|
| 57 | + // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 58 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 59 | + $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 60 | + if (!isset($infos['install']) or !$infos['install']) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Passer en chemin absolu si possible, c'est plus efficace |
|
| 65 | + $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 66 | + if (!defined($dir)) { |
|
| 67 | + $dir = $dir_type; |
|
| 68 | + } |
|
| 69 | + $dir = constant($dir); |
|
| 70 | + foreach ($infos['install'] as $file) { |
|
| 71 | + $file = $dir . $plug . "/" . trim($file); |
|
| 72 | + if (file_exists($file)) { |
|
| 73 | + include_once($file); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // Détermination de la table meta et du nom de la meta plugin |
|
| 78 | + $table = 'meta'; |
|
| 79 | + if (isset($infos['meta']) and ($infos['meta'] !== 'meta')) { |
|
| 80 | + $table = $infos['meta']; |
|
| 81 | + // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 82 | + lire_metas($table); |
|
| 83 | + } |
|
| 84 | + $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 85 | + |
|
| 86 | + // Détermination de la fonction à appeler et de ses arguments |
|
| 87 | + $f = $infos['prefix'] . "_install"; |
|
| 88 | + if (!function_exists($f)) { |
|
| 89 | + $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 90 | + $arg = $infos; |
|
| 91 | + // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 92 | + $arg['meta'] = $table; |
|
| 93 | + $arg['nom_meta'] = $nom_meta; |
|
| 94 | + } else { |
|
| 95 | + // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 96 | + // stupide: info deja dans le nom |
|
| 97 | + $arg = $infos['prefix']; |
|
| 98 | + } |
|
| 99 | + $version = isset($infos['schema']) ? $infos['schema'] : ''; |
|
| 100 | + |
|
| 101 | + if (!$f) { |
|
| 102 | + // installation sans operation particuliere |
|
| 103 | + $infos['install_test'] = array(true, ''); |
|
| 104 | + return $infos; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Tester si l'action demandée est nécessaire ou pas. |
|
| 108 | + $test = $f('test', $arg, $version); |
|
| 109 | + if ($action == 'uninstall') { |
|
| 110 | + $test = !$test; |
|
| 111 | + } |
|
| 112 | + // Si deja fait, on ne fait rien et on ne dit rien |
|
| 113 | + if ($test) { |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 118 | + // pour renvoyer le bon message en retour de la fonction. |
|
| 119 | + if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 120 | + $infos['upgrade'] = true; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // executer l'installation ou l'inverse |
|
| 124 | + // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 125 | + ob_start(); |
|
| 126 | + $f($action, $arg, $version); |
|
| 127 | + $aff = ob_get_contents(); |
|
| 128 | + ob_end_clean(); |
|
| 129 | + |
|
| 130 | + // vider le cache des descriptions de tables a chaque (de)installation |
|
| 131 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 132 | + $trouver_table(''); |
|
| 133 | + $infos['install_test'] = array($f('test', $arg, $version), $aff); |
|
| 134 | + |
|
| 135 | + // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 136 | + // on force la création du fichier cache à la date du moment. |
|
| 137 | + // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 138 | + if ( |
|
| 139 | + ($table !== 'meta') |
|
| 140 | + and ($action == 'install') |
|
| 141 | + and empty($infos['upgrade']) |
|
| 142 | + ) { |
|
| 143 | + touch_meta(false, $table); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $infos; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -159,25 +159,25 @@ discard block |
||
| 159 | 159 | * @return bool|void |
| 160 | 160 | */ |
| 161 | 161 | function spip_plugin_install($action, $infos, $version_cible) { |
| 162 | - $nom_meta = $infos['nom_meta']; |
|
| 163 | - $table = $infos['meta']; |
|
| 164 | - switch ($action) { |
|
| 165 | - case 'test': |
|
| 166 | - return (isset($GLOBALS[$table]) |
|
| 167 | - and isset($GLOBALS[$table][$nom_meta]) |
|
| 168 | - and spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 169 | - break; |
|
| 170 | - case 'install': |
|
| 171 | - if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 172 | - $upgrade($nom_meta, $version_cible, $table); |
|
| 173 | - } |
|
| 174 | - break; |
|
| 175 | - case 'uninstall': |
|
| 176 | - if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 177 | - $vider_tables($nom_meta, $table); |
|
| 178 | - } |
|
| 179 | - break; |
|
| 180 | - } |
|
| 162 | + $nom_meta = $infos['nom_meta']; |
|
| 163 | + $table = $infos['meta']; |
|
| 164 | + switch ($action) { |
|
| 165 | + case 'test': |
|
| 166 | + return (isset($GLOBALS[$table]) |
|
| 167 | + and isset($GLOBALS[$table][$nom_meta]) |
|
| 168 | + and spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 169 | + break; |
|
| 170 | + case 'install': |
|
| 171 | + if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 172 | + $upgrade($nom_meta, $version_cible, $table); |
|
| 173 | + } |
|
| 174 | + break; |
|
| 175 | + case 'uninstall': |
|
| 176 | + if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 177 | + $vider_tables($nom_meta, $table); |
|
| 178 | + } |
|
| 179 | + break; |
|
| 180 | + } |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -196,29 +196,29 @@ discard block |
||
| 196 | 196 | * @return array Tableau des plugins actifs |
| 197 | 197 | **/ |
| 198 | 198 | function liste_plugin_actifs() { |
| 199 | - $liste = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 200 | - if (!$liste) { |
|
| 201 | - return array(); |
|
| 202 | - } |
|
| 203 | - if (!is_array($liste = unserialize($liste))) { |
|
| 204 | - // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 205 | - spip_log("MAJ meta plugin vieille version : $liste", "plugin"); |
|
| 206 | - $new = true; |
|
| 207 | - list(, $liste) = liste_plugin_valides(explode(",", $liste)); |
|
| 208 | - } else { |
|
| 209 | - $new = false; |
|
| 210 | - // compat au moment d'une migration depuis version anterieure |
|
| 211 | - // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 212 | - foreach ($liste as $prefix => $infos) { |
|
| 213 | - if (!isset($infos['dir_type'])) { |
|
| 214 | - $liste[$prefix]['dir_type'] = "_DIR_PLUGINS"; |
|
| 215 | - $new = true; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - if ($new) { |
|
| 220 | - ecrire_meta('plugin', serialize($liste)); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $liste; |
|
| 199 | + $liste = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 200 | + if (!$liste) { |
|
| 201 | + return array(); |
|
| 202 | + } |
|
| 203 | + if (!is_array($liste = unserialize($liste))) { |
|
| 204 | + // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 205 | + spip_log("MAJ meta plugin vieille version : $liste", "plugin"); |
|
| 206 | + $new = true; |
|
| 207 | + list(, $liste) = liste_plugin_valides(explode(",", $liste)); |
|
| 208 | + } else { |
|
| 209 | + $new = false; |
|
| 210 | + // compat au moment d'une migration depuis version anterieure |
|
| 211 | + // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 212 | + foreach ($liste as $prefix => $infos) { |
|
| 213 | + if (!isset($infos['dir_type'])) { |
|
| 214 | + $liste[$prefix]['dir_type'] = "_DIR_PLUGINS"; |
|
| 215 | + $new = true; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + if ($new) { |
|
| 220 | + ecrire_meta('plugin', serialize($liste)); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $liste; |
|
| 224 | 224 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL\Tables |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -64,141 +64,141 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | **/ |
| 66 | 66 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true) { |
| 67 | - static $nom_cache_desc_sql = array(); |
|
| 68 | - |
|
| 69 | - if (!spip_connect($serveur) |
|
| 70 | - or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 71 | - ) { |
|
| 72 | - return null; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 76 | - $objets_sql = lister_tables_objets_sql("::md5"); |
|
| 77 | - |
|
| 78 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 79 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 80 | - // de connexion, et tout risque d'ambiguite |
|
| 81 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 82 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 83 | - _DIR_CACHE . 'sql_desc_' |
|
| 84 | - . ($serveur ? "{$serveur}_" : "") |
|
| 85 | - . substr(md5($connexion['db'] . ":" . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 86 | - . '.txt'; |
|
| 87 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 88 | - unset($connexion['tables']); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 92 | - if (!$nom) { |
|
| 93 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 94 | - $connexion['tables'] = array(); |
|
| 95 | - |
|
| 96 | - return null; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $nom_sql = $nom; |
|
| 100 | - if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 101 | - $nom_sql = $s[1]; |
|
| 102 | - } else { |
|
| 103 | - $nom_sql = $nom; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $fdesc = $desc = ''; |
|
| 107 | - $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 108 | - |
|
| 109 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 110 | - if ($connexion['spip_connect_version']) { |
|
| 111 | - if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 112 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 113 | - $nom_sql = 'spip_' . $nom; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // si c'est la premiere table qu'on cherche |
|
| 118 | - // et si on est pas explicitement en recalcul |
|
| 119 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 120 | - // dans le fichier cache |
|
| 121 | - if (!isset($connexion['tables'][$nom_sql]) |
|
| 122 | - and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 123 | - and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 124 | - ) { |
|
| 125 | - if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 126 | - and $desc_cache = unserialize($desc_cache) |
|
| 127 | - ) { |
|
| 128 | - $connexion['tables'] = $desc_cache; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 132 | - |
|
| 133 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 134 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 135 | - } |
|
| 136 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 137 | - // si c'est une table principale, |
|
| 138 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 139 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 140 | - $nom_sql = 'spip_' . $nom; |
|
| 141 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 142 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 143 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 144 | - ) { |
|
| 145 | - $nom_sql = $n; |
|
| 146 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 147 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 148 | - } |
|
| 149 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 150 | - |
|
| 151 | - // La *vraie* base a la priorite |
|
| 152 | - $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
|
| 153 | - if (!$desc or !$desc['field']) { |
|
| 154 | - if (!$fdesc) { |
|
| 155 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 156 | - |
|
| 157 | - return null; |
|
| 158 | - } |
|
| 159 | - // on ne sait pas lire la structure de la table : |
|
| 160 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 161 | - $desc = $fdesc; |
|
| 162 | - $desc['exist'] = false; |
|
| 163 | - } else { |
|
| 164 | - $desc['exist'] = true; |
|
| 165 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 166 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 167 | - if (! $desc['key']) { |
|
| 168 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 169 | - unset($desc['key']); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 174 | - $desc['connexion'] = $serveur; |
|
| 175 | - |
|
| 176 | - // charger les infos declarees pour cette table |
|
| 177 | - // en lui passant les infos connues |
|
| 178 | - // $desc est prioritaire pour la description de la table |
|
| 179 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 180 | - // s'assurer qu'on a toujours un 'key' |
|
| 181 | - if (!isset($desc['key']) && !empty($fdesc['key'])){ |
|
| 182 | - $desc['key'] = $fdesc['key']; |
|
| 183 | - } |
|
| 184 | - if (! isset($desc['key'])) { |
|
| 185 | - $desc['key'] = array(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 189 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 190 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 191 | - // une nouvelle table a ete decrite |
|
| 192 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 193 | - if (is_writeable(_DIR_CACHE)) { |
|
| 194 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 195 | - } |
|
| 196 | - } else { |
|
| 197 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // toujours retourner $nom dans id_table |
|
| 201 | - $res['id_table'] = $nom; |
|
| 202 | - |
|
| 203 | - return $res; |
|
| 67 | + static $nom_cache_desc_sql = array(); |
|
| 68 | + |
|
| 69 | + if (!spip_connect($serveur) |
|
| 70 | + or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 71 | + ) { |
|
| 72 | + return null; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 76 | + $objets_sql = lister_tables_objets_sql("::md5"); |
|
| 77 | + |
|
| 78 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 79 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 80 | + // de connexion, et tout risque d'ambiguite |
|
| 81 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 82 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 83 | + _DIR_CACHE . 'sql_desc_' |
|
| 84 | + . ($serveur ? "{$serveur}_" : "") |
|
| 85 | + . substr(md5($connexion['db'] . ":" . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 86 | + . '.txt'; |
|
| 87 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 88 | + unset($connexion['tables']); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 92 | + if (!$nom) { |
|
| 93 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 94 | + $connexion['tables'] = array(); |
|
| 95 | + |
|
| 96 | + return null; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $nom_sql = $nom; |
|
| 100 | + if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 101 | + $nom_sql = $s[1]; |
|
| 102 | + } else { |
|
| 103 | + $nom_sql = $nom; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $fdesc = $desc = ''; |
|
| 107 | + $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 108 | + |
|
| 109 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 110 | + if ($connexion['spip_connect_version']) { |
|
| 111 | + if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 112 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 113 | + $nom_sql = 'spip_' . $nom; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // si c'est la premiere table qu'on cherche |
|
| 118 | + // et si on est pas explicitement en recalcul |
|
| 119 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 120 | + // dans le fichier cache |
|
| 121 | + if (!isset($connexion['tables'][$nom_sql]) |
|
| 122 | + and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 123 | + and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 124 | + ) { |
|
| 125 | + if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 126 | + and $desc_cache = unserialize($desc_cache) |
|
| 127 | + ) { |
|
| 128 | + $connexion['tables'] = $desc_cache; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 132 | + |
|
| 133 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 134 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 135 | + } |
|
| 136 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 137 | + // si c'est une table principale, |
|
| 138 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 139 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 140 | + $nom_sql = 'spip_' . $nom; |
|
| 141 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 142 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 143 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 144 | + ) { |
|
| 145 | + $nom_sql = $n; |
|
| 146 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 147 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 148 | + } |
|
| 149 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 150 | + |
|
| 151 | + // La *vraie* base a la priorite |
|
| 152 | + $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
|
| 153 | + if (!$desc or !$desc['field']) { |
|
| 154 | + if (!$fdesc) { |
|
| 155 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 156 | + |
|
| 157 | + return null; |
|
| 158 | + } |
|
| 159 | + // on ne sait pas lire la structure de la table : |
|
| 160 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 161 | + $desc = $fdesc; |
|
| 162 | + $desc['exist'] = false; |
|
| 163 | + } else { |
|
| 164 | + $desc['exist'] = true; |
|
| 165 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 166 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 167 | + if (! $desc['key']) { |
|
| 168 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 169 | + unset($desc['key']); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 174 | + $desc['connexion'] = $serveur; |
|
| 175 | + |
|
| 176 | + // charger les infos declarees pour cette table |
|
| 177 | + // en lui passant les infos connues |
|
| 178 | + // $desc est prioritaire pour la description de la table |
|
| 179 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 180 | + // s'assurer qu'on a toujours un 'key' |
|
| 181 | + if (!isset($desc['key']) && !empty($fdesc['key'])){ |
|
| 182 | + $desc['key'] = $fdesc['key']; |
|
| 183 | + } |
|
| 184 | + if (! isset($desc['key'])) { |
|
| 185 | + $desc['key'] = array(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 189 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 190 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 191 | + // une nouvelle table a ete decrite |
|
| 192 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 193 | + if (is_writeable(_DIR_CACHE)) { |
|
| 194 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 195 | + } |
|
| 196 | + } else { |
|
| 197 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // toujours retourner $nom dans id_table |
|
| 201 | + $res['id_table'] = $nom; |
|
| 202 | + |
|
| 203 | + return $res; |
|
| 204 | 204 | } |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // de connexion, et tout risque d'ambiguite |
| 81 | 81 | if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
| 82 | 82 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 83 | - _DIR_CACHE . 'sql_desc_' |
|
| 83 | + _DIR_CACHE.'sql_desc_' |
|
| 84 | 84 | . ($serveur ? "{$serveur}_" : "") |
| 85 | - . substr(md5($connexion['db'] . ":" . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 85 | + . substr(md5($connexion['db'].":".$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 86 | 86 | . '.txt'; |
| 87 | 87 | // nouveau nom de cache = nouvelle version en memoire |
| 88 | 88 | unset($connexion['tables']); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | if ($connexion['spip_connect_version']) { |
| 111 | 111 | if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
| 112 | 112 | $nom = $GLOBALS['table_des_tables'][$nom]; |
| 113 | - $nom_sql = 'spip_' . $nom; |
|
| 113 | + $nom_sql = 'spip_'.$nom; |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 137 | 137 | // si c'est une table principale, |
| 138 | 138 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 139 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 140 | - $nom_sql = 'spip_' . $nom; |
|
| 139 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_'.$nom])) { |
|
| 140 | + $nom_sql = 'spip_'.$nom; |
|
| 141 | 141 | $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
| 142 | 142 | } elseif (isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
| 143 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 143 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_'.$nom]) |
|
| 144 | 144 | ) { |
| 145 | 145 | $nom_sql = $n; |
| 146 | 146 | $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
| 153 | 153 | if (!$desc or !$desc['field']) { |
| 154 | 154 | if (!$fdesc) { |
| 155 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 155 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base'._LOG_INFO_IMPORTANTE); |
|
| 156 | 156 | |
| 157 | 157 | return null; |
| 158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $desc['exist'] = true; |
| 165 | 165 | // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
| 166 | 166 | // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
| 167 | - if (! $desc['key']) { |
|
| 167 | + if (!$desc['key']) { |
|
| 168 | 168 | spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
| 169 | 169 | unset($desc['key']); |
| 170 | 170 | } |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | // $desc est prioritaire pour la description de la table |
| 179 | 179 | $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
| 180 | 180 | // s'assurer qu'on a toujours un 'key' |
| 181 | - if (!isset($desc['key']) && !empty($fdesc['key'])){ |
|
| 181 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 182 | 182 | $desc['key'] = $fdesc['key']; |
| 183 | 183 | } |
| 184 | - if (! isset($desc['key'])) { |
|
| 184 | + if (!isset($desc['key'])) { |
|
| 185 | 185 | $desc['key'] = array(); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 31 | - |
|
| 32 | - if ($struct->jointures_explicites) { |
|
| 33 | - $type .= " " . $struct->jointures_explicites; |
|
| 34 | - } |
|
| 35 | - if ($struct->table_optionnelle) { |
|
| 36 | - $type .= "?"; |
|
| 37 | - } |
|
| 38 | - // Revoir le cas de la boucle recursive |
|
| 39 | - |
|
| 40 | - $crit = $struct->param; |
|
| 41 | - if ($crit and !is_array($crit[0])) { |
|
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 43 | - } |
|
| 44 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | - |
|
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 47 | - |
|
| 48 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | + $struct->table_optionnelle); |
|
| 31 | + |
|
| 32 | + if ($struct->jointures_explicites) { |
|
| 33 | + $type .= " " . $struct->jointures_explicites; |
|
| 34 | + } |
|
| 35 | + if ($struct->table_optionnelle) { |
|
| 36 | + $type .= "?"; |
|
| 37 | + } |
|
| 38 | + // Revoir le cas de la boucle recursive |
|
| 39 | + |
|
| 40 | + $crit = $struct->param; |
|
| 41 | + if ($crit and !is_array($crit[0])) { |
|
| 42 | + $type = strtolower($type) . array_shift($crit); |
|
| 43 | + } |
|
| 44 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | + |
|
| 46 | + $f = 'format_boucle_' . $fmt; |
|
| 47 | + |
|
| 48 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 52 | - $res = array(); |
|
| 53 | - foreach ($struct->param ? $struct->param : array() as $couple) { |
|
| 54 | - array_shift($couple); |
|
| 55 | - foreach ($couple as $v) { |
|
| 56 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 62 | - |
|
| 63 | - return $f($file, $res, $prof); |
|
| 52 | + $res = array(); |
|
| 53 | + foreach ($struct->param ? $struct->param : array() as $couple) { |
|
| 54 | + array_shift($couple); |
|
| 55 | + foreach ($couple as $v) { |
|
| 56 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | + $f = 'format_inclure_' . $fmt; |
|
| 62 | + |
|
| 63 | + return $f($file, $res, $prof); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 67 | + $f = 'format_texte_' . $fmt; |
|
| 68 | 68 | |
| 69 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 73 | + $f = 'format_polyglotte_' . $fmt; |
|
| 74 | 74 | |
| 75 | - return $f($struct->traductions, $prof); |
|
| 75 | + return $f($struct->traductions, $prof); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 79 | - $args = array(); |
|
| 80 | - foreach ($struct->arg as $k => $v) { |
|
| 81 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | - } |
|
| 79 | + $args = array(); |
|
| 80 | + foreach ($struct->arg as $k => $v) { |
|
| 81 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 85 | 85 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 86 | + $f = 'format_idiome_' . $fmt; |
|
| 87 | 87 | |
| 88 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 92 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | - $args = $filtres = ''; |
|
| 95 | - if ($p = $struct->param) { |
|
| 96 | - if ($p[0][0] === '') { |
|
| 97 | - $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 98 | - } |
|
| 99 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | - } |
|
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 102 | - |
|
| 103 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 92 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | + $args = $filtres = ''; |
|
| 95 | + if ($p = $struct->param) { |
|
| 96 | + if ($p[0][0] === '') { |
|
| 97 | + $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 98 | + } |
|
| 99 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | + } |
|
| 101 | + $f = 'format_champ_' . $fmt; |
|
| 102 | + |
|
| 103 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 107 | - if (!is_array($sources)) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 111 | - $res = ''; |
|
| 112 | - foreach ($sources as $arg) { |
|
| 113 | - if (!is_array($arg)) { |
|
| 114 | - continue; // ne devrait pas arriver. |
|
| 115 | - } else { |
|
| 116 | - $r = array_shift($arg); |
|
| 117 | - } |
|
| 118 | - $args = array(); |
|
| 119 | - foreach ($arg as $v) { |
|
| 120 | - // cas des arguments entoures de ' ou " |
|
| 121 | - if ((count($v) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 107 | + if (!is_array($sources)) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + $f = 'format_liste_' . $fmt; |
|
| 111 | + $res = ''; |
|
| 112 | + foreach ($sources as $arg) { |
|
| 113 | + if (!is_array($arg)) { |
|
| 114 | + continue; // ne devrait pas arriver. |
|
| 115 | + } else { |
|
| 116 | + $r = array_shift($arg); |
|
| 117 | + } |
|
| 118 | + $args = array(); |
|
| 119 | + foreach ($arg as $v) { |
|
| 120 | + // cas des arguments entoures de ' ou " |
|
| 121 | + if ((count($v) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,91 +141,91 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = array(); |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ((count($v) == 1) |
|
| 158 | - and $v[0]->type == 'texte' |
|
| 159 | - and $v[0]->apres |
|
| 160 | - ) { |
|
| 161 | - $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 162 | - } else { |
|
| 163 | - $res2 = array(); |
|
| 164 | - foreach ($v as $k => $p) { |
|
| 165 | - if (isset($p->type) |
|
| 166 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | - ) { |
|
| 168 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 169 | - $res2[] = array($p->type, $r); |
|
| 170 | - } else { |
|
| 171 | - spip_log("critere $i / $k mal forme"); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - $args[] = $res2; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - $res .= $f($args); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = array(); |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ((count($v) == 1) |
|
| 158 | + and $v[0]->type == 'texte' |
|
| 159 | + and $v[0]->apres |
|
| 160 | + ) { |
|
| 161 | + $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 162 | + } else { |
|
| 163 | + $res2 = array(); |
|
| 164 | + foreach ($v as $k => $p) { |
|
| 165 | + if (isset($p->type) |
|
| 166 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + ) { |
|
| 168 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 169 | + $res2[] = array($p->type, $r); |
|
| 170 | + } else { |
|
| 171 | + spip_log("critere $i / $k mal forme"); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + $args[] = $res2; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + $res .= $f($args); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $res; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 185 | - if (!is_array($liste)) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 189 | - $contenu = array(); |
|
| 190 | - foreach ($liste as $k => $p) { |
|
| 191 | - if (!isset($p->type)) { |
|
| 192 | - continue; |
|
| 193 | - } #?????? |
|
| 194 | - $d = 'decompiler_' . $p->type; |
|
| 195 | - $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 196 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 197 | - // contenait des args et s'il est suivi d'espaces, |
|
| 198 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 199 | - |
|
| 200 | - if ($next |
|
| 201 | - and ($next->type == 'texte') |
|
| 202 | - and $p->type == 'champ' |
|
| 203 | - and !$p->apres |
|
| 204 | - and !$p->avant |
|
| 205 | - and $p->fonctions |
|
| 206 | - ) { |
|
| 207 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 208 | - if ($n) { |
|
| 209 | - $champ = new Texte; |
|
| 210 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 211 | - $champ->ligne = $p->ligne; |
|
| 212 | - $p->apres = array($champ); |
|
| 213 | - $next->texte = substr($next->texte, $n); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - $f = 'format_suite_' . $fmt; |
|
| 220 | - |
|
| 221 | - return $f($contenu); |
|
| 185 | + if (!is_array($liste)) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 189 | + $contenu = array(); |
|
| 190 | + foreach ($liste as $k => $p) { |
|
| 191 | + if (!isset($p->type)) { |
|
| 192 | + continue; |
|
| 193 | + } #?????? |
|
| 194 | + $d = 'decompiler_' . $p->type; |
|
| 195 | + $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 196 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 197 | + // contenait des args et s'il est suivi d'espaces, |
|
| 198 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 199 | + |
|
| 200 | + if ($next |
|
| 201 | + and ($next->type == 'texte') |
|
| 202 | + and $p->type == 'champ' |
|
| 203 | + and !$p->apres |
|
| 204 | + and !$p->avant |
|
| 205 | + and $p->fonctions |
|
| 206 | + ) { |
|
| 207 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 208 | + if ($n) { |
|
| 209 | + $champ = new Texte; |
|
| 210 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 211 | + $champ->ligne = $p->ligne; |
|
| 212 | + $p->apres = array($champ); |
|
| 213 | + $next->texte = substr($next->texte, $n); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + $f = 'format_suite_' . $fmt; |
|
| 220 | + |
|
| 221 | + return $f($contenu); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 225 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | - return "'$fmt'?"; |
|
| 227 | - } |
|
| 228 | - $f = 'decompiler_' . $quoi; |
|
| 225 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + return "'$fmt'?"; |
|
| 227 | + } |
|
| 228 | + $f = 'decompiler_' . $quoi; |
|
| 229 | 229 | |
| 230 | - return $f($liste, $fmt, $prof); |
|
| 230 | + return $f($liste, $fmt, $prof); |
|
| 231 | 231 | } |
@@ -26,11 +26,10 @@ discard block |
||
| 26 | 26 | $postaff = decompiler_($struct->postaff, $fmt, $prof); |
| 27 | 27 | |
| 28 | 28 | $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : $struct->table_optionnelle); |
|
| 31 | 30 | |
| 32 | 31 | if ($struct->jointures_explicites) { |
| 33 | - $type .= " " . $struct->jointures_explicites; |
|
| 32 | + $type .= " ".$struct->jointures_explicites; |
|
| 34 | 33 | } |
| 35 | 34 | if ($struct->table_optionnelle) { |
| 36 | 35 | $type .= "?"; |
@@ -39,11 +38,11 @@ discard block |
||
| 39 | 38 | |
| 40 | 39 | $crit = $struct->param; |
| 41 | 40 | if ($crit and !is_array($crit[0])) { |
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 43 | 42 | } |
| 44 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 45 | 44 | |
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 47 | 46 | |
| 48 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 49 | 48 | } |
@@ -56,21 +55,20 @@ discard block |
||
| 56 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 57 | 56 | } |
| 58 | 57 | } |
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 62 | 60 | |
| 63 | 61 | return $f($file, $res, $prof); |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 68 | 66 | |
| 69 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 74 | 72 | |
| 75 | 73 | return $f($struct->traductions, $prof); |
| 76 | 74 | } |
@@ -83,7 +81,7 @@ discard block |
||
| 83 | 81 | |
| 84 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 85 | 83 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 87 | 85 | |
| 88 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 89 | 87 | } |
@@ -98,7 +96,7 @@ discard block |
||
| 98 | 96 | } |
| 99 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 100 | 98 | } |
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 102 | 100 | |
| 103 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 104 | 102 | } |
@@ -107,7 +105,7 @@ discard block |
||
| 107 | 105 | if (!is_array($sources)) { |
| 108 | 106 | return ''; |
| 109 | 107 | } |
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 111 | 109 | $res = ''; |
| 112 | 110 | foreach ($sources as $arg) { |
| 113 | 111 | if (!is_array($arg)) { |
@@ -123,7 +121,7 @@ discard block |
||
| 123 | 121 | and (strlen($v[0]->apres) == 1) |
| 124 | 122 | and $v[0]->apres == $v[0]->avant |
| 125 | 123 | ) { |
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 124 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 127 | 125 | } else { |
| 128 | 126 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 129 | 127 | } |
@@ -146,7 +144,7 @@ discard block |
||
| 146 | 144 | return ''; |
| 147 | 145 | } |
| 148 | 146 | $res = ''; |
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 147 | + $f = 'format_critere_'.$fmt; |
|
| 150 | 148 | foreach ($sources as $crit) { |
| 151 | 149 | if (!is_array($crit)) { |
| 152 | 150 | continue; |
@@ -158,12 +156,12 @@ discard block |
||
| 158 | 156 | and $v[0]->type == 'texte' |
| 159 | 157 | and $v[0]->apres |
| 160 | 158 | ) { |
| 161 | - $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 159 | + $args[] = array(array('texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres))); |
|
| 162 | 160 | } else { |
| 163 | 161 | $res2 = array(); |
| 164 | 162 | foreach ($v as $k => $p) { |
| 165 | 163 | if (isset($p->type) |
| 166 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 164 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 167 | 165 | ) { |
| 168 | 166 | $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
| 169 | 167 | $res2[] = array($p->type, $r); |
@@ -191,7 +189,7 @@ discard block |
||
| 191 | 189 | if (!isset($p->type)) { |
| 192 | 190 | continue; |
| 193 | 191 | } #?????? |
| 194 | - $d = 'decompiler_' . $p->type; |
|
| 192 | + $d = 'decompiler_'.$p->type; |
|
| 195 | 193 | $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
| 196 | 194 | // Forcer le champ etendu si son source (pas les reecritures) |
| 197 | 195 | // contenait des args et s'il est suivi d'espaces, |
@@ -216,16 +214,16 @@ discard block |
||
| 216 | 214 | $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
| 217 | 215 | |
| 218 | 216 | } |
| 219 | - $f = 'format_suite_' . $fmt; |
|
| 217 | + $f = 'format_suite_'.$fmt; |
|
| 220 | 218 | |
| 221 | 219 | return $f($contenu); |
| 222 | 220 | } |
| 223 | 221 | |
| 224 | 222 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 225 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 223 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 226 | 224 | return "'$fmt'?"; |
| 227 | 225 | } |
| 228 | - $f = 'decompiler_' . $quoi; |
|
| 226 | + $f = 'decompiler_'.$quoi; |
|
| 229 | 227 | |
| 230 | 228 | return $f($liste, $fmt, $prof); |
| 231 | 229 | } |
@@ -20,20 +20,20 @@ |
||
| 20 | 20 | $var_auth = $auth(); |
| 21 | 21 | |
| 22 | 22 | if ($var_auth !== '') { |
| 23 | - if (!is_int($var_auth)) { |
|
| 24 | - // si l'authentifie' n'a pas acces a l'espace de redac |
|
| 25 | - // c'est qu'on voulait forcer sa reconnaissance en tant que visiteur. |
|
| 26 | - // On reexecute pour deboucher sur le include public. |
|
| 27 | - // autrement on insiste |
|
| 28 | - if (is_array($var_auth)) { |
|
| 29 | - $var_auth = '../?' . $_SERVER['QUERY_STRING']; |
|
| 30 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 31 | - 'expires' => time() + 3600 * 24 * 14 |
|
| 32 | - ]); |
|
| 33 | - } |
|
| 34 | - include_spip('inc/headers'); |
|
| 35 | - redirige_formulaire($var_auth); |
|
| 36 | - } |
|
| 23 | + if (!is_int($var_auth)) { |
|
| 24 | + // si l'authentifie' n'a pas acces a l'espace de redac |
|
| 25 | + // c'est qu'on voulait forcer sa reconnaissance en tant que visiteur. |
|
| 26 | + // On reexecute pour deboucher sur le include public. |
|
| 27 | + // autrement on insiste |
|
| 28 | + if (is_array($var_auth)) { |
|
| 29 | + $var_auth = '../?' . $_SERVER['QUERY_STRING']; |
|
| 30 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 31 | + 'expires' => time() + 3600 * 24 * 14 |
|
| 32 | + ]); |
|
| 33 | + } |
|
| 34 | + include_spip('inc/headers'); |
|
| 35 | + redirige_formulaire($var_auth); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // En somme, est prive' ce qui est publiquement nomme'... |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | // On reexecute pour deboucher sur le include public. |
| 27 | 27 | // autrement on insiste |
| 28 | 28 | if (is_array($var_auth)) { |
| 29 | - $var_auth = '../?' . $_SERVER['QUERY_STRING']; |
|
| 29 | + $var_auth = '../?'.$_SERVER['QUERY_STRING']; |
|
| 30 | 30 | spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
| 31 | 31 | 'expires' => time() + 3600 * 24 * 14 |
| 32 | 32 | ]); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | * @return bool|null|void |
| 41 | 41 | */ |
| 42 | 42 | function inc_session_dist($auteur = false) { |
| 43 | - if (is_numeric($auteur)) { |
|
| 44 | - return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | - } else { |
|
| 46 | - if (is_array($auteur)) { |
|
| 47 | - return ajouter_session($auteur); |
|
| 48 | - } else { |
|
| 49 | - return verifier_session($auteur); |
|
| 50 | - } |
|
| 51 | - } |
|
| 43 | + if (is_numeric($auteur)) { |
|
| 44 | + return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | + } else { |
|
| 46 | + if (is_array($auteur)) { |
|
| 47 | + return ajouter_session($auteur); |
|
| 48 | + } else { |
|
| 49 | + return verifier_session($auteur); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,36 +77,36 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function supprimer_sessions($id_auteur, $toutes = true, $actives = true) { |
| 79 | 79 | |
| 80 | - $nb_files = 0; |
|
| 81 | - $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | - spip_log("supprimer sessions auteur $id_auteur", "session"); |
|
| 83 | - if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4*_RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA/4,3*3600); // 3h par defaut |
|
| 87 | - $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | - while (($f = readdir($dir)) !== false) { |
|
| 89 | - $nb_files++; |
|
| 90 | - if (preg_match(",^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,", $f, $regs)) { |
|
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 92 | - if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | - spip_unlink($f); |
|
| 94 | - } |
|
| 95 | - // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | - // cf http://core.spip.org/issues/3276 |
|
| 97 | - elseif ($nb_files>$nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | - spip_unlink($f); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - verifier_session(); |
|
| 105 | - spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // forcer le recalcul de la session courante |
|
| 109 | - spip_session(true); |
|
| 80 | + $nb_files = 0; |
|
| 81 | + $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | + spip_log("supprimer sessions auteur $id_auteur", "session"); |
|
| 83 | + if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4*_RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA/4,3*3600); // 3h par defaut |
|
| 87 | + $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | + while (($f = readdir($dir)) !== false) { |
|
| 89 | + $nb_files++; |
|
| 90 | + if (preg_match(",^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,", $f, $regs)) { |
|
| 91 | + $f = _DIR_SESSIONS . $f; |
|
| 92 | + if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | + spip_unlink($f); |
|
| 94 | + } |
|
| 95 | + // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | + // cf http://core.spip.org/issues/3276 |
|
| 97 | + elseif ($nb_files>$nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | + spip_unlink($f); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + verifier_session(); |
|
| 105 | + spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // forcer le recalcul de la session courante |
|
| 109 | + spip_session(true); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -124,122 +124,122 @@ discard block |
||
| 124 | 124 | * @return bool|string |
| 125 | 125 | */ |
| 126 | 126 | function ajouter_session($auteur) { |
| 127 | - // Si le client a deja une session valide pour son id_auteur |
|
| 128 | - // on conserve le meme fichier |
|
| 129 | - |
|
| 130 | - // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | - // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | - |
|
| 134 | - // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | - // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | - if (!$id_auteur) { |
|
| 137 | - // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | - $auteur_verif = $auteur; |
|
| 139 | - if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | - unset($auteur_verif['id_auteur']); |
|
| 141 | - } |
|
| 142 | - if (isset($auteur_verif['hash_env'])) { |
|
| 143 | - unset($auteur_verif['hash_env']); |
|
| 144 | - } |
|
| 145 | - if (isset($auteur_verif['ip_change'])) { |
|
| 146 | - unset($auteur_verif['ip_change']); |
|
| 147 | - } |
|
| 148 | - if (isset($auteur_verif['date_session'])) { |
|
| 149 | - unset($auteur_verif['date_session']); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | - foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | - if ($valeur === null) { |
|
| 155 | - unset($auteur_verif[$variable]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | - if (!$auteur_verif) { |
|
| 161 | - if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | - unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | - } |
|
| 164 | - if (isset($_COOKIE['spip_session'])) { |
|
| 165 | - unset($_COOKIE['spip_session']); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if (!isset($_COOKIE['spip_session']) |
|
| 173 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 174 | - ) { |
|
| 175 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true)); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant on sait qu'on a des choses à écrire |
|
| 179 | - // On s'assure d'avoir au moins ces valeurs |
|
| 180 | - $auteur['id_auteur'] = $id_auteur; |
|
| 181 | - if (!isset($auteur['hash_env'])) { |
|
| 182 | - $auteur['hash_env'] = hash_env(); |
|
| 183 | - } |
|
| 184 | - if (!isset($auteur['ip_change'])) { |
|
| 185 | - $auteur['ip_change'] = false; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!isset($auteur['date_session'])) { |
|
| 189 | - $auteur['date_session'] = time(); |
|
| 190 | - } |
|
| 191 | - if (isset($auteur['prefs']) |
|
| 192 | - and is_string($auteur['prefs']) |
|
| 193 | - and $prefs = @unserialize($auteur['prefs'])) { |
|
| 194 | - $auteur['prefs'] = $prefs; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $fichier_session = ""; |
|
| 198 | - |
|
| 199 | - // les sessions anonymes sont stockees dans $_SESSION |
|
| 200 | - if (!$id_auteur) { |
|
| 201 | - spip_php_session_start(); |
|
| 202 | - $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 203 | - } else { |
|
| 204 | - $fichier_session = fichier_session('alea_ephemere'); |
|
| 205 | - if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 206 | - spip_log('Echec ecriture fichier session ' . $fichier_session, "session" . _LOG_HS); |
|
| 207 | - include_spip('inc/minipres'); |
|
| 208 | - echo minipres(); |
|
| 209 | - exit; |
|
| 210 | - } |
|
| 211 | - // verifier et limiter le nombre maxi de sessions |
|
| 212 | - // https://core.spip.net/issues/3807 |
|
| 213 | - lister_sessions_auteur($id_auteur); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // poser le cookie de session SPIP |
|
| 217 | - include_spip('inc/cookie'); |
|
| 218 | - $duree = definir_duree_cookie_session($auteur); |
|
| 219 | - spip_setcookie( 'spip_session', $_COOKIE['spip_session'], [ |
|
| 220 | - 'expires' => time() + $duree |
|
| 221 | - ]); |
|
| 222 | - spip_log("ajoute session $fichier_session cookie $duree", "session"); |
|
| 223 | - |
|
| 224 | - // Si on est admin, poser le cookie de correspondance |
|
| 225 | - if (!function_exists('autoriser')) { |
|
| 226 | - include_spip('inc/autoriser'); |
|
| 227 | - } |
|
| 228 | - if (autoriser('ecrire','','',$auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 229 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 230 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 231 | - ]); |
|
| 232 | - } // sinon le supprimer ... |
|
| 233 | - else { |
|
| 234 | - spip_setcookie('spip_admin', '', [ |
|
| 235 | - 'expires' => 1 |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 240 | - # supprimer_sessions(0, true, false); |
|
| 241 | - |
|
| 242 | - return $_COOKIE['spip_session']; |
|
| 127 | + // Si le client a deja une session valide pour son id_auteur |
|
| 128 | + // on conserve le meme fichier |
|
| 129 | + |
|
| 130 | + // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | + // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | + |
|
| 134 | + // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | + // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | + if (!$id_auteur) { |
|
| 137 | + // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | + $auteur_verif = $auteur; |
|
| 139 | + if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | + unset($auteur_verif['id_auteur']); |
|
| 141 | + } |
|
| 142 | + if (isset($auteur_verif['hash_env'])) { |
|
| 143 | + unset($auteur_verif['hash_env']); |
|
| 144 | + } |
|
| 145 | + if (isset($auteur_verif['ip_change'])) { |
|
| 146 | + unset($auteur_verif['ip_change']); |
|
| 147 | + } |
|
| 148 | + if (isset($auteur_verif['date_session'])) { |
|
| 149 | + unset($auteur_verif['date_session']); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | + foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | + if ($valeur === null) { |
|
| 155 | + unset($auteur_verif[$variable]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | + if (!$auteur_verif) { |
|
| 161 | + if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | + unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | + } |
|
| 164 | + if (isset($_COOKIE['spip_session'])) { |
|
| 165 | + unset($_COOKIE['spip_session']); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if (!isset($_COOKIE['spip_session']) |
|
| 173 | + or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 174 | + ) { |
|
| 175 | + $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true)); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant on sait qu'on a des choses à écrire |
|
| 179 | + // On s'assure d'avoir au moins ces valeurs |
|
| 180 | + $auteur['id_auteur'] = $id_auteur; |
|
| 181 | + if (!isset($auteur['hash_env'])) { |
|
| 182 | + $auteur['hash_env'] = hash_env(); |
|
| 183 | + } |
|
| 184 | + if (!isset($auteur['ip_change'])) { |
|
| 185 | + $auteur['ip_change'] = false; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!isset($auteur['date_session'])) { |
|
| 189 | + $auteur['date_session'] = time(); |
|
| 190 | + } |
|
| 191 | + if (isset($auteur['prefs']) |
|
| 192 | + and is_string($auteur['prefs']) |
|
| 193 | + and $prefs = @unserialize($auteur['prefs'])) { |
|
| 194 | + $auteur['prefs'] = $prefs; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $fichier_session = ""; |
|
| 198 | + |
|
| 199 | + // les sessions anonymes sont stockees dans $_SESSION |
|
| 200 | + if (!$id_auteur) { |
|
| 201 | + spip_php_session_start(); |
|
| 202 | + $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 203 | + } else { |
|
| 204 | + $fichier_session = fichier_session('alea_ephemere'); |
|
| 205 | + if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 206 | + spip_log('Echec ecriture fichier session ' . $fichier_session, "session" . _LOG_HS); |
|
| 207 | + include_spip('inc/minipres'); |
|
| 208 | + echo minipres(); |
|
| 209 | + exit; |
|
| 210 | + } |
|
| 211 | + // verifier et limiter le nombre maxi de sessions |
|
| 212 | + // https://core.spip.net/issues/3807 |
|
| 213 | + lister_sessions_auteur($id_auteur); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // poser le cookie de session SPIP |
|
| 217 | + include_spip('inc/cookie'); |
|
| 218 | + $duree = definir_duree_cookie_session($auteur); |
|
| 219 | + spip_setcookie( 'spip_session', $_COOKIE['spip_session'], [ |
|
| 220 | + 'expires' => time() + $duree |
|
| 221 | + ]); |
|
| 222 | + spip_log("ajoute session $fichier_session cookie $duree", "session"); |
|
| 223 | + |
|
| 224 | + // Si on est admin, poser le cookie de correspondance |
|
| 225 | + if (!function_exists('autoriser')) { |
|
| 226 | + include_spip('inc/autoriser'); |
|
| 227 | + } |
|
| 228 | + if (autoriser('ecrire','','',$auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 229 | + spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 230 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 231 | + ]); |
|
| 232 | + } // sinon le supprimer ... |
|
| 233 | + else { |
|
| 234 | + spip_setcookie('spip_admin', '', [ |
|
| 235 | + 'expires' => 1 |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 240 | + # supprimer_sessions(0, true, false); |
|
| 241 | + |
|
| 242 | + return $_COOKIE['spip_session']; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -259,15 +259,15 @@ discard block |
||
| 259 | 259 | * Durée en secondes |
| 260 | 260 | **/ |
| 261 | 261 | function definir_duree_cookie_session($auteur) { |
| 262 | - $coef = 2; |
|
| 263 | - if (isset($auteur['cookie'])) { |
|
| 264 | - if (is_numeric($auteur['cookie'])) { |
|
| 265 | - $coef = $auteur['cookie']; |
|
| 266 | - } else { |
|
| 267 | - $coef = 20; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 262 | + $coef = 2; |
|
| 263 | + if (isset($auteur['cookie'])) { |
|
| 264 | + if (is_numeric($auteur['cookie'])) { |
|
| 265 | + $coef = $auteur['cookie']; |
|
| 266 | + } else { |
|
| 267 | + $coef = 20; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -287,90 +287,90 @@ discard block |
||
| 287 | 287 | * @return bool|int|null |
| 288 | 288 | */ |
| 289 | 289 | function verifier_session($change = false) { |
| 290 | - // si pas de cookie, c'est fichu |
|
| 291 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 292 | - return false; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $fichier_session = ""; |
|
| 296 | - |
|
| 297 | - // est-ce une session anonyme ? |
|
| 298 | - if (!intval($_COOKIE['spip_session'])) { |
|
| 299 | - spip_php_session_start(); |
|
| 300 | - if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 301 | - return false; |
|
| 302 | - } |
|
| 303 | - $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 304 | - } else { |
|
| 305 | - // Tester avec alea courant |
|
| 306 | - $fichier_session = fichier_session('alea_ephemere', true); |
|
| 307 | - if ($fichier_session and @file_exists($fichier_session)) { |
|
| 308 | - include($fichier_session); |
|
| 309 | - } else { |
|
| 310 | - // Sinon, tester avec alea precedent |
|
| 311 | - $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 312 | - if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - // Renouveler la session avec l'alea courant |
|
| 317 | - include($fichier_session); |
|
| 318 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], "session"); |
|
| 319 | - spip_unlink($fichier_session); |
|
| 320 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 325 | - // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 326 | - // n'etre qu'identifie, sans aucune authentification). |
|
| 327 | - |
|
| 328 | - if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 329 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 334 | - // avec un URL de rappel demandant a changer le nom de la session. |
|
| 335 | - // Seul celui qui a l'IP d'origine est rejoue |
|
| 336 | - // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 337 | - // sa victime, mais se ferait deconnecter par elle. |
|
| 338 | - if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 339 | - if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 340 | - define('_SESSION_REJOUER', true); |
|
| 341 | - $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 342 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 343 | - } else { |
|
| 344 | - if ($change) { |
|
| 345 | - spip_log("session non rejouee, vol de cookie ?", "session"); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } else { |
|
| 349 | - if ($change) { |
|
| 350 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], "session"); |
|
| 351 | - if ($fichier_session) { |
|
| 352 | - spip_unlink($fichier_session); |
|
| 353 | - } |
|
| 354 | - $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 355 | - unset($_COOKIE['spip_session']); |
|
| 356 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 361 | - if (isset($GLOBALS['visiteur_session']) |
|
| 362 | - and defined('_AGE_SESSION_MAX') |
|
| 363 | - and _AGE_SESSION_MAX > 0 |
|
| 364 | - and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 365 | - ) { |
|
| 366 | - unset($GLOBALS['visiteur_session']); |
|
| 367 | - |
|
| 368 | - return false; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 372 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 373 | - : null; |
|
| 290 | + // si pas de cookie, c'est fichu |
|
| 291 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $fichier_session = ""; |
|
| 296 | + |
|
| 297 | + // est-ce une session anonyme ? |
|
| 298 | + if (!intval($_COOKIE['spip_session'])) { |
|
| 299 | + spip_php_session_start(); |
|
| 300 | + if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 301 | + return false; |
|
| 302 | + } |
|
| 303 | + $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 304 | + } else { |
|
| 305 | + // Tester avec alea courant |
|
| 306 | + $fichier_session = fichier_session('alea_ephemere', true); |
|
| 307 | + if ($fichier_session and @file_exists($fichier_session)) { |
|
| 308 | + include($fichier_session); |
|
| 309 | + } else { |
|
| 310 | + // Sinon, tester avec alea precedent |
|
| 311 | + $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 312 | + if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + // Renouveler la session avec l'alea courant |
|
| 317 | + include($fichier_session); |
|
| 318 | + spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], "session"); |
|
| 319 | + spip_unlink($fichier_session); |
|
| 320 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 325 | + // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 326 | + // n'etre qu'identifie, sans aucune authentification). |
|
| 327 | + |
|
| 328 | + if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 329 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 334 | + // avec un URL de rappel demandant a changer le nom de la session. |
|
| 335 | + // Seul celui qui a l'IP d'origine est rejoue |
|
| 336 | + // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 337 | + // sa victime, mais se ferait deconnecter par elle. |
|
| 338 | + if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 339 | + if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 340 | + define('_SESSION_REJOUER', true); |
|
| 341 | + $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 342 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 343 | + } else { |
|
| 344 | + if ($change) { |
|
| 345 | + spip_log("session non rejouee, vol de cookie ?", "session"); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } else { |
|
| 349 | + if ($change) { |
|
| 350 | + spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], "session"); |
|
| 351 | + if ($fichier_session) { |
|
| 352 | + spip_unlink($fichier_session); |
|
| 353 | + } |
|
| 354 | + $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 355 | + unset($_COOKIE['spip_session']); |
|
| 356 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 361 | + if (isset($GLOBALS['visiteur_session']) |
|
| 362 | + and defined('_AGE_SESSION_MAX') |
|
| 363 | + and _AGE_SESSION_MAX > 0 |
|
| 364 | + and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 365 | + ) { |
|
| 366 | + unset($GLOBALS['visiteur_session']); |
|
| 367 | + |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 372 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 373 | + : null; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * Valeur, si trouvée, `null` sinon. |
| 386 | 386 | */ |
| 387 | 387 | function session_get($nom) { |
| 388 | - return isset($GLOBALS['visiteur_session'][$nom]) ? $GLOBALS['visiteur_session'][$nom] : null; |
|
| 388 | + return isset($GLOBALS['visiteur_session'][$nom]) ? $GLOBALS['visiteur_session'][$nom] : null; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | |
@@ -401,32 +401,32 @@ discard block |
||
| 401 | 401 | * @return void|array |
| 402 | 402 | */ |
| 403 | 403 | function session_set($nom, $val = null) { |
| 404 | - static $remove = array(); |
|
| 405 | - static $actualiser_sessions = false; |
|
| 406 | - if ($nom === false) { |
|
| 407 | - return $remove; |
|
| 408 | - } |
|
| 409 | - if (is_null($val)) { |
|
| 410 | - // rien a faire |
|
| 411 | - if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 412 | - return; |
|
| 413 | - } |
|
| 414 | - unset($GLOBALS['visiteur_session'][$nom]); |
|
| 415 | - $remove[] = $nom; |
|
| 416 | - } else { |
|
| 417 | - // On ajoute la valeur dans la globale |
|
| 418 | - $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 419 | - if ($remove) { |
|
| 420 | - $remove = array_diff($remove, array($nom)); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - if (!$actualiser_sessions) { |
|
| 424 | - // il faut creer la session si on en a pas, la premiere fois |
|
| 425 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 426 | - // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 427 | - register_shutdown_function('terminer_actualiser_sessions'); |
|
| 428 | - $actualiser_sessions = true; |
|
| 429 | - } |
|
| 404 | + static $remove = array(); |
|
| 405 | + static $actualiser_sessions = false; |
|
| 406 | + if ($nom === false) { |
|
| 407 | + return $remove; |
|
| 408 | + } |
|
| 409 | + if (is_null($val)) { |
|
| 410 | + // rien a faire |
|
| 411 | + if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 412 | + return; |
|
| 413 | + } |
|
| 414 | + unset($GLOBALS['visiteur_session'][$nom]); |
|
| 415 | + $remove[] = $nom; |
|
| 416 | + } else { |
|
| 417 | + // On ajoute la valeur dans la globale |
|
| 418 | + $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 419 | + if ($remove) { |
|
| 420 | + $remove = array_diff($remove, array($nom)); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + if (!$actualiser_sessions) { |
|
| 424 | + // il faut creer la session si on en a pas, la premiere fois |
|
| 425 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 426 | + // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 427 | + register_shutdown_function('terminer_actualiser_sessions'); |
|
| 428 | + $actualiser_sessions = true; |
|
| 429 | + } |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | * @uses actualiser_sessions() |
| 436 | 436 | */ |
| 437 | 437 | function terminer_actualiser_sessions() { |
| 438 | - // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 439 | - chdir(_ROOT_CWD); |
|
| 440 | - // recuperer les variables a effacer |
|
| 441 | - $remove = session_set(false); |
|
| 442 | - // mettre a jour toutes les sessions |
|
| 443 | - actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 438 | + // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 439 | + chdir(_ROOT_CWD); |
|
| 440 | + // recuperer les variables a effacer |
|
| 441 | + $remove = session_set(false); |
|
| 442 | + // mettre a jour toutes les sessions |
|
| 443 | + actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -465,82 +465,82 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function actualiser_sessions($auteur, $supprimer_cles = array()) { |
| 467 | 467 | |
| 468 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 469 | - $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 470 | - |
|
| 471 | - // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 472 | - $fichier_session_courante = ""; |
|
| 473 | - if ($id_auteur == $id_auteur_courant) { |
|
| 474 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 475 | - ajouter_session($auteur); |
|
| 476 | - if ($id_auteur) { |
|
| 477 | - $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 482 | - if (!$id_auteur) { |
|
| 483 | - return; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // les préférences sont désérialisées, toujours. |
|
| 487 | - // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 488 | - if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 489 | - $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 490 | - if (!is_array($auteur['prefs'])) { |
|
| 491 | - $auteur['prefs'] = []; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 496 | - $sauve = $GLOBALS['visiteur_session']; |
|
| 497 | - |
|
| 498 | - // .. mettre a jour les sessions de l'auteur cible |
|
| 499 | - // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 500 | - // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 501 | - $sessions = lister_sessions_auteur($id_auteur); |
|
| 502 | - |
|
| 503 | - // 1ere passe : lire et fusionner les sessions |
|
| 504 | - foreach ($sessions as $session) { |
|
| 505 | - $GLOBALS['visiteur_session'] = array(); |
|
| 506 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 507 | - if ($session !== $fichier_session_courante |
|
| 508 | - and @file_exists($session) |
|
| 509 | - ) { |
|
| 510 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 511 | - |
|
| 512 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - // supprimer les eventuelles cles dont on ne veut plus |
|
| 517 | - foreach ($supprimer_cles as $cle) { |
|
| 518 | - unset($auteur[$cle]); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $auteur_session = preparer_ecriture_session($auteur); |
|
| 522 | - |
|
| 523 | - // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 524 | - foreach ($sessions as $session) { |
|
| 525 | - $GLOBALS['visiteur_session'] = array(); |
|
| 526 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 527 | - if (@file_exists($session)) { |
|
| 528 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 529 | - |
|
| 530 | - // est-ce que cette session est a mettre a jour ? |
|
| 531 | - if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 532 | - ecrire_fichier_session($session, $auteur); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - if ($id_auteur == $id_auteur_courant) { |
|
| 538 | - $GLOBALS['visiteur_session'] = $auteur; |
|
| 539 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 540 | - } else { |
|
| 541 | - // restaurer l'auteur courant |
|
| 542 | - $GLOBALS['visiteur_session'] = $sauve; |
|
| 543 | - } |
|
| 468 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 469 | + $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 470 | + |
|
| 471 | + // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 472 | + $fichier_session_courante = ""; |
|
| 473 | + if ($id_auteur == $id_auteur_courant) { |
|
| 474 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 475 | + ajouter_session($auteur); |
|
| 476 | + if ($id_auteur) { |
|
| 477 | + $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 482 | + if (!$id_auteur) { |
|
| 483 | + return; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // les préférences sont désérialisées, toujours. |
|
| 487 | + // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 488 | + if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 489 | + $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 490 | + if (!is_array($auteur['prefs'])) { |
|
| 491 | + $auteur['prefs'] = []; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 496 | + $sauve = $GLOBALS['visiteur_session']; |
|
| 497 | + |
|
| 498 | + // .. mettre a jour les sessions de l'auteur cible |
|
| 499 | + // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 500 | + // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 501 | + $sessions = lister_sessions_auteur($id_auteur); |
|
| 502 | + |
|
| 503 | + // 1ere passe : lire et fusionner les sessions |
|
| 504 | + foreach ($sessions as $session) { |
|
| 505 | + $GLOBALS['visiteur_session'] = array(); |
|
| 506 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 507 | + if ($session !== $fichier_session_courante |
|
| 508 | + and @file_exists($session) |
|
| 509 | + ) { |
|
| 510 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 511 | + |
|
| 512 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + // supprimer les eventuelles cles dont on ne veut plus |
|
| 517 | + foreach ($supprimer_cles as $cle) { |
|
| 518 | + unset($auteur[$cle]); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $auteur_session = preparer_ecriture_session($auteur); |
|
| 522 | + |
|
| 523 | + // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 524 | + foreach ($sessions as $session) { |
|
| 525 | + $GLOBALS['visiteur_session'] = array(); |
|
| 526 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 527 | + if (@file_exists($session)) { |
|
| 528 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 529 | + |
|
| 530 | + // est-ce que cette session est a mettre a jour ? |
|
| 531 | + if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 532 | + ecrire_fichier_session($session, $auteur); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + if ($id_auteur == $id_auteur_courant) { |
|
| 538 | + $GLOBALS['visiteur_session'] = $auteur; |
|
| 539 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 540 | + } else { |
|
| 541 | + // restaurer l'auteur courant |
|
| 542 | + $GLOBALS['visiteur_session'] = $sauve; |
|
| 543 | + } |
|
| 544 | 544 | |
| 545 | 545 | } |
| 546 | 546 | |
@@ -555,46 +555,46 @@ discard block |
||
| 555 | 555 | */ |
| 556 | 556 | function lister_sessions_auteur($id_auteur, $nb_max = null) { |
| 557 | 557 | |
| 558 | - if (is_null($nb_max)) { |
|
| 559 | - if (!defined('_NB_SESSIONS_MAX')) { |
|
| 560 | - define('_NB_SESSIONS_MAX', 100); |
|
| 561 | - } |
|
| 562 | - $nb_max = _NB_SESSIONS_MAX; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // liste des sessions |
|
| 566 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 567 | - |
|
| 568 | - // si on en a plus que la limite, supprimer les plus vieilles |
|
| 569 | - // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 570 | - if ($id_auteur |
|
| 571 | - and count($sessions) > $nb_max) { |
|
| 572 | - |
|
| 573 | - // limiter le nombre de sessions ouvertes par un auteur |
|
| 574 | - // filemtime sur les sessions |
|
| 575 | - $sessions = array_flip($sessions); |
|
| 576 | - |
|
| 577 | - // 1ere passe : lire les filemtime |
|
| 578 | - foreach ($sessions as $session => $z) { |
|
| 579 | - if ($d = @filemtime($session) |
|
| 580 | - ) { |
|
| 581 | - $sessions[$session] = $d; |
|
| 582 | - } else { |
|
| 583 | - $sessions[$session] = 0; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // les plus anciennes en premier |
|
| 588 | - asort($sessions); |
|
| 589 | - |
|
| 590 | - $sessions = array_keys($sessions); |
|
| 591 | - while (count($sessions) > $nb_max) { |
|
| 592 | - $session = array_shift($sessions); |
|
| 593 | - @unlink($session); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return $sessions; |
|
| 558 | + if (is_null($nb_max)) { |
|
| 559 | + if (!defined('_NB_SESSIONS_MAX')) { |
|
| 560 | + define('_NB_SESSIONS_MAX', 100); |
|
| 561 | + } |
|
| 562 | + $nb_max = _NB_SESSIONS_MAX; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // liste des sessions |
|
| 566 | + $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 567 | + |
|
| 568 | + // si on en a plus que la limite, supprimer les plus vieilles |
|
| 569 | + // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 570 | + if ($id_auteur |
|
| 571 | + and count($sessions) > $nb_max) { |
|
| 572 | + |
|
| 573 | + // limiter le nombre de sessions ouvertes par un auteur |
|
| 574 | + // filemtime sur les sessions |
|
| 575 | + $sessions = array_flip($sessions); |
|
| 576 | + |
|
| 577 | + // 1ere passe : lire les filemtime |
|
| 578 | + foreach ($sessions as $session => $z) { |
|
| 579 | + if ($d = @filemtime($session) |
|
| 580 | + ) { |
|
| 581 | + $sessions[$session] = $d; |
|
| 582 | + } else { |
|
| 583 | + $sessions[$session] = 0; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // les plus anciennes en premier |
|
| 588 | + asort($sessions); |
|
| 589 | + |
|
| 590 | + $sessions = array_keys($sessions); |
|
| 591 | + while (count($sessions) > $nb_max) { |
|
| 592 | + $session = array_shift($sessions); |
|
| 593 | + @unlink($session); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return $sessions; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
@@ -608,26 +608,26 @@ discard block |
||
| 608 | 608 | * @return array |
| 609 | 609 | */ |
| 610 | 610 | function preparer_ecriture_session($auteur) { |
| 611 | - $row = $auteur; |
|
| 612 | - |
|
| 613 | - // ne pas enregistrer ces elements de securite |
|
| 614 | - // dans le fichier de session |
|
| 615 | - unset($auteur['pass']); |
|
| 616 | - unset($auteur['htpass']); |
|
| 617 | - unset($auteur['low_sec']); |
|
| 618 | - unset($auteur['alea_actuel']); |
|
| 619 | - unset($auteur['alea_futur']); |
|
| 620 | - |
|
| 621 | - $auteur = pipeline('preparer_fichier_session', array('args' => array('row' => $row), 'data' => $auteur)); |
|
| 622 | - |
|
| 623 | - // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 624 | - foreach ($auteur as $variable => $valeur) { |
|
| 625 | - if ($valeur === null) { |
|
| 626 | - unset($auteur[$variable]); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - return $auteur; |
|
| 611 | + $row = $auteur; |
|
| 612 | + |
|
| 613 | + // ne pas enregistrer ces elements de securite |
|
| 614 | + // dans le fichier de session |
|
| 615 | + unset($auteur['pass']); |
|
| 616 | + unset($auteur['htpass']); |
|
| 617 | + unset($auteur['low_sec']); |
|
| 618 | + unset($auteur['alea_actuel']); |
|
| 619 | + unset($auteur['alea_futur']); |
|
| 620 | + |
|
| 621 | + $auteur = pipeline('preparer_fichier_session', array('args' => array('row' => $row), 'data' => $auteur)); |
|
| 622 | + |
|
| 623 | + // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 624 | + foreach ($auteur as $variable => $valeur) { |
|
| 625 | + if ($valeur === null) { |
|
| 626 | + unset($auteur[$variable]); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + return $auteur; |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -639,17 +639,17 @@ discard block |
||
| 639 | 639 | */ |
| 640 | 640 | function ecrire_fichier_session($fichier, $auteur) { |
| 641 | 641 | |
| 642 | - $auteur = preparer_ecriture_session($auteur); |
|
| 642 | + $auteur = preparer_ecriture_session($auteur); |
|
| 643 | 643 | |
| 644 | - // enregistrer les autres donnees du visiteur |
|
| 645 | - $texte = "<" . "?php\n"; |
|
| 646 | - foreach ($auteur as $var => $val) { |
|
| 647 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 648 | - . var_export($val, true) . ";\n"; |
|
| 649 | - } |
|
| 650 | - $texte .= "?" . ">\n"; |
|
| 644 | + // enregistrer les autres donnees du visiteur |
|
| 645 | + $texte = "<" . "?php\n"; |
|
| 646 | + foreach ($auteur as $var => $val) { |
|
| 647 | + $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 648 | + . var_export($val, true) . ";\n"; |
|
| 649 | + } |
|
| 650 | + $texte .= "?" . ">\n"; |
|
| 651 | 651 | |
| 652 | - return ecrire_fichier($fichier, $texte); |
|
| 652 | + return ecrire_fichier($fichier, $texte); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | |
@@ -662,23 +662,23 @@ discard block |
||
| 662 | 662 | */ |
| 663 | 663 | function fichier_session($alea, $tantpis = false) { |
| 664 | 664 | |
| 665 | - include_spip('inc/acces'); |
|
| 666 | - charger_aleas(); |
|
| 665 | + include_spip('inc/acces'); |
|
| 666 | + charger_aleas(); |
|
| 667 | 667 | |
| 668 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 669 | - if (!$tantpis) { |
|
| 670 | - spip_log("fichier session ($tantpis): $alea indisponible", "session"); |
|
| 671 | - include_spip('inc/minipres'); |
|
| 672 | - echo minipres(); |
|
| 673 | - } |
|
| 668 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 669 | + if (!$tantpis) { |
|
| 670 | + spip_log("fichier session ($tantpis): $alea indisponible", "session"); |
|
| 671 | + include_spip('inc/minipres'); |
|
| 672 | + echo minipres(); |
|
| 673 | + } |
|
| 674 | 674 | |
| 675 | - return ''; // echec mais $tanpis |
|
| 676 | - } else { |
|
| 677 | - $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 678 | - $c = $_COOKIE['spip_session']; |
|
| 675 | + return ''; // echec mais $tanpis |
|
| 676 | + } else { |
|
| 677 | + $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 678 | + $c = $_COOKIE['spip_session']; |
|
| 679 | 679 | |
| 680 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 681 | - } |
|
| 680 | + return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 681 | + } |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | * @return string |
| 696 | 696 | */ |
| 697 | 697 | function rejouer_session() { |
| 698 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 698 | + return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | |
@@ -705,12 +705,12 @@ discard block |
||
| 705 | 705 | * @return string |
| 706 | 706 | */ |
| 707 | 707 | function hash_env() { |
| 708 | - static $res = ''; |
|
| 709 | - if ($res) { |
|
| 710 | - return $res; |
|
| 711 | - } |
|
| 708 | + static $res = ''; |
|
| 709 | + if ($res) { |
|
| 710 | + return $res; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')); |
|
| 713 | + return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | |
@@ -722,11 +722,11 @@ discard block |
||
| 722 | 722 | * @return bool True si une session PHP est ouverte. |
| 723 | 723 | **/ |
| 724 | 724 | function spip_php_session_start() { |
| 725 | - if (!is_php_session_started()) { |
|
| 726 | - return session_start(); |
|
| 727 | - } |
|
| 725 | + if (!is_php_session_started()) { |
|
| 726 | + return session_start(); |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | - return true; |
|
| 729 | + return true; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -736,9 +736,9 @@ discard block |
||
| 736 | 736 | * @return bool true si une session PHP est active |
| 737 | 737 | **/ |
| 738 | 738 | function is_php_session_started() { |
| 739 | - if (php_sapi_name() !== 'cli') { |
|
| 740 | - return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 741 | - } |
|
| 739 | + if (php_sapi_name() !== 'cli') { |
|
| 740 | + return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | - return false; |
|
| 743 | + return false; |
|
| 744 | 744 | } |
@@ -82,19 +82,19 @@ discard block |
||
| 82 | 82 | spip_log("supprimer sessions auteur $id_auteur", "session"); |
| 83 | 83 | if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
| 84 | 84 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4*_RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA/4,3*3600); // 3h par defaut |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | 87 | $t = time() - (4 * _RENOUVELLE_ALEA); |
| 88 | 88 | while (($f = readdir($dir)) !== false) { |
| 89 | 89 | $nb_files++; |
| 90 | 90 | if (preg_match(",^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,", $f, $regs)) { |
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 91 | + $f = _DIR_SESSIONS.$f; |
|
| 92 | 92 | if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
| 93 | 93 | spip_unlink($f); |
| 94 | 94 | } |
| 95 | 95 | // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
| 96 | 96 | // cf http://core.spip.org/issues/3276 |
| 97 | - elseif ($nb_files>$nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 97 | + elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | 98 | spip_unlink($f); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | if (!isset($_COOKIE['spip_session']) |
| 173 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 173 | + or !preg_match(',^'.$id_auteur.'_,', $_COOKIE['spip_session']) |
|
| 174 | 174 | ) { |
| 175 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true)); |
|
| 175 | + $_COOKIE['spip_session'] = $id_auteur.'_'.md5(uniqid(rand(), true)); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Maintenant on sait qu'on a des choses à écrire |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | } else { |
| 204 | 204 | $fichier_session = fichier_session('alea_ephemere'); |
| 205 | 205 | if (!ecrire_fichier_session($fichier_session, $auteur)) { |
| 206 | - spip_log('Echec ecriture fichier session ' . $fichier_session, "session" . _LOG_HS); |
|
| 206 | + spip_log('Echec ecriture fichier session '.$fichier_session, "session"._LOG_HS); |
|
| 207 | 207 | include_spip('inc/minipres'); |
| 208 | 208 | echo minipres(); |
| 209 | 209 | exit; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | // poser le cookie de session SPIP |
| 217 | 217 | include_spip('inc/cookie'); |
| 218 | 218 | $duree = definir_duree_cookie_session($auteur); |
| 219 | - spip_setcookie( 'spip_session', $_COOKIE['spip_session'], [ |
|
| 219 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 220 | 220 | 'expires' => time() + $duree |
| 221 | 221 | ]); |
| 222 | 222 | spip_log("ajoute session $fichier_session cookie $duree", "session"); |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | if (!function_exists('autoriser')) { |
| 226 | 226 | include_spip('inc/autoriser'); |
| 227 | 227 | } |
| 228 | - if (autoriser('ecrire','','',$auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 229 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 228 | + if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 229 | + spip_setcookie('spip_admin', '@'.($auteur['email'] ?: $auteur['login']), [ |
|
| 230 | 230 | 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
| 231 | 231 | ]); |
| 232 | 232 | } // sinon le supprimer ... |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | $coef = 20; |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 270 | + return (int) (_RENOUVELLE_ALEA * $coef); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | // Renouveler la session avec l'alea courant |
| 317 | 317 | include($fichier_session); |
| 318 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], "session"); |
|
| 318 | + spip_log('renouvelle session '.$GLOBALS['visiteur_session']['id_auteur'], "session"); |
|
| 319 | 319 | spip_unlink($fichier_session); |
| 320 | 320 | ajouter_session($GLOBALS['visiteur_session']); |
| 321 | 321 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } else { |
| 349 | 349 | if ($change) { |
| 350 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], "session"); |
|
| 350 | + spip_log("rejoue session $fichier_session ".$_COOKIE['spip_session'], "session"); |
|
| 351 | 351 | if ($fichier_session) { |
| 352 | 352 | spip_unlink($fichier_session); |
| 353 | 353 | } |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | // liste des sessions |
| 566 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 566 | + $sessions = preg_files(_DIR_SESSIONS, '/'.$id_auteur.'_.*\.php$'); |
|
| 567 | 567 | |
| 568 | 568 | // si on en a plus que la limite, supprimer les plus vieilles |
| 569 | 569 | // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
@@ -642,12 +642,12 @@ discard block |
||
| 642 | 642 | $auteur = preparer_ecriture_session($auteur); |
| 643 | 643 | |
| 644 | 644 | // enregistrer les autres donnees du visiteur |
| 645 | - $texte = "<" . "?php\n"; |
|
| 645 | + $texte = "<"."?php\n"; |
|
| 646 | 646 | foreach ($auteur as $var => $val) { |
| 647 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 648 | - . var_export($val, true) . ";\n"; |
|
| 647 | + $texte .= '$GLOBALS[\'visiteur_session\']['.var_export($var, true).'] = ' |
|
| 648 | + . var_export($val, true).";\n"; |
|
| 649 | 649 | } |
| 650 | - $texte .= "?" . ">\n"; |
|
| 650 | + $texte .= "?".">\n"; |
|
| 651 | 651 | |
| 652 | 652 | return ecrire_fichier($fichier, $texte); |
| 653 | 653 | } |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
| 678 | 678 | $c = $_COOKIE['spip_session']; |
| 679 | 679 | |
| 680 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 680 | + return $repertoire.intval($c).'_'.md5($c.' '.$GLOBALS['meta'][$alea]).'.php'; |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | * @return string |
| 696 | 696 | */ |
| 697 | 697 | function rejouer_session() { |
| 698 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 698 | + return '<img src="'.generer_url_action('cookie', 'change_session=oui', true).'" width="0" height="0" alt="" />'; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | return $res; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')); |
|
| 713 | + return $res = md5($GLOBALS['ip'].(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 77 | + $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'].'_', $name); |
|
| 78 | 78 | |
| 79 | 79 | // expires |
| 80 | 80 | if (!isset($options['expires'])) { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | foreach ($_COOKIE as $name => $value) { |
| 159 | 159 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 160 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 160 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 161 | 161 | $_COOKIE[$spipname] = $value; |
| 162 | 162 | $GLOBALS[$spipname] = $value; |
| 163 | 163 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -52,62 +52,62 @@ discard block |
||
| 52 | 52 | * cookie sécurisé ou non ? |
| 53 | 53 | **/ |
| 54 | 54 | function spip_setcookie($name = '', $value = '', $options = []) { |
| 55 | - static $to_secure_list = ['spip_session']; |
|
| 56 | - |
|
| 57 | - if (!is_array($options)) { |
|
| 58 | - // anciens paramètres : |
|
| 59 | - # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 60 | - $opt = func_get_args(); |
|
| 61 | - $opt = array_slice($opt, 2); |
|
| 62 | - $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 63 | - if (isset($opt[0])) { |
|
| 64 | - $options['expires'] = $opt[0]; |
|
| 65 | - } |
|
| 66 | - if (isset($opt[1])) { |
|
| 67 | - $options['path'] = $opt[1]; |
|
| 68 | - } |
|
| 69 | - if (isset($opt[2])) { |
|
| 70 | - $options['domain'] = $opt[2]; |
|
| 71 | - } |
|
| 72 | - if (isset($opt[3])) { |
|
| 73 | - $options['secure'] = $opt[3]; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 78 | - |
|
| 79 | - // expires |
|
| 80 | - if (!isset($options['expires'])) { |
|
| 81 | - $options['expires'] = 0; |
|
| 82 | - } |
|
| 83 | - if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 84 | - if (defined('_COOKIE_PATH')) { |
|
| 85 | - $options['path'] = _COOKIE_PATH; |
|
| 86 | - } else { |
|
| 87 | - $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 91 | - $options['domain'] = _COOKIE_DOMAIN; |
|
| 92 | - } |
|
| 93 | - if (in_array($name, $to_secure_list)) { |
|
| 94 | - if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 95 | - $options['secure'] = true; |
|
| 96 | - } |
|
| 97 | - if (empty($options['httponly'])) { |
|
| 98 | - $options['httponly'] = true; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - if (empty($options['samesite'])) { |
|
| 102 | - $options['samesite'] = 'Lax'; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 106 | - $a = @setcookie($name, $value, $options); |
|
| 107 | - |
|
| 108 | - spip_cookie_envoye(true); |
|
| 109 | - |
|
| 110 | - return $a; |
|
| 55 | + static $to_secure_list = ['spip_session']; |
|
| 56 | + |
|
| 57 | + if (!is_array($options)) { |
|
| 58 | + // anciens paramètres : |
|
| 59 | + # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 60 | + $opt = func_get_args(); |
|
| 61 | + $opt = array_slice($opt, 2); |
|
| 62 | + $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 63 | + if (isset($opt[0])) { |
|
| 64 | + $options['expires'] = $opt[0]; |
|
| 65 | + } |
|
| 66 | + if (isset($opt[1])) { |
|
| 67 | + $options['path'] = $opt[1]; |
|
| 68 | + } |
|
| 69 | + if (isset($opt[2])) { |
|
| 70 | + $options['domain'] = $opt[2]; |
|
| 71 | + } |
|
| 72 | + if (isset($opt[3])) { |
|
| 73 | + $options['secure'] = $opt[3]; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 78 | + |
|
| 79 | + // expires |
|
| 80 | + if (!isset($options['expires'])) { |
|
| 81 | + $options['expires'] = 0; |
|
| 82 | + } |
|
| 83 | + if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 84 | + if (defined('_COOKIE_PATH')) { |
|
| 85 | + $options['path'] = _COOKIE_PATH; |
|
| 86 | + } else { |
|
| 87 | + $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 91 | + $options['domain'] = _COOKIE_DOMAIN; |
|
| 92 | + } |
|
| 93 | + if (in_array($name, $to_secure_list)) { |
|
| 94 | + if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 95 | + $options['secure'] = true; |
|
| 96 | + } |
|
| 97 | + if (empty($options['httponly'])) { |
|
| 98 | + $options['httponly'] = true; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + if (empty($options['samesite'])) { |
|
| 102 | + $options['samesite'] = 'Lax'; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 106 | + $a = @setcookie($name, $value, $options); |
|
| 107 | + |
|
| 108 | + spip_cookie_envoye(true); |
|
| 109 | + |
|
| 110 | + return $a; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | * @return bool |
| 124 | 124 | **/ |
| 125 | 125 | function spip_cookie_envoye($set = '') { |
| 126 | - static $envoye = false; |
|
| 127 | - if ($set) { |
|
| 128 | - $envoye = true; |
|
| 129 | - } |
|
| 126 | + static $envoye = false; |
|
| 127 | + if ($set) { |
|
| 128 | + $envoye = true; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - return $envoye; |
|
| 131 | + return $envoye; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -147,21 +147,21 @@ discard block |
||
| 147 | 147 | * Préfixe des cookies de SPIP |
| 148 | 148 | **/ |
| 149 | 149 | function recuperer_cookies_spip($cookie_prefix) { |
| 150 | - $prefix_long = strlen($cookie_prefix); |
|
| 151 | - |
|
| 152 | - foreach ($_COOKIE as $name => $value) { |
|
| 153 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 154 | - unset($_COOKIE[$name]); |
|
| 155 | - unset($GLOBALS[$name]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - foreach ($_COOKIE as $name => $value) { |
|
| 159 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 160 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 161 | - $_COOKIE[$spipname] = $value; |
|
| 162 | - $GLOBALS[$spipname] = $value; |
|
| 163 | - } |
|
| 164 | - } |
|
| 150 | + $prefix_long = strlen($cookie_prefix); |
|
| 151 | + |
|
| 152 | + foreach ($_COOKIE as $name => $value) { |
|
| 153 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 154 | + unset($_COOKIE[$name]); |
|
| 155 | + unset($GLOBALS[$name]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + foreach ($_COOKIE as $name => $value) { |
|
| 159 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 160 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 161 | + $_COOKIE[$spipname] = $value; |
|
| 162 | + $GLOBALS[$spipname] = $value; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
@@ -181,18 +181,18 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | **/ |
| 183 | 183 | function exec_test_ajax_dist() { |
| 184 | - switch (_request('js')) { |
|
| 185 | - // on est appele par <noscript> |
|
| 186 | - case -1: |
|
| 187 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 188 | - include_spip('inc/headers'); |
|
| 189 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 190 | - break; |
|
| 191 | - |
|
| 192 | - // ou par ajax |
|
| 193 | - case 1: |
|
| 194 | - default: |
|
| 195 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 196 | - break; |
|
| 197 | - } |
|
| 184 | + switch (_request('js')) { |
|
| 185 | + // on est appele par <noscript> |
|
| 186 | + case -1: |
|
| 187 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 188 | + include_spip('inc/headers'); |
|
| 189 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 190 | + break; |
|
| 191 | + |
|
| 192 | + // ou par ajax |
|
| 193 | + case 1: |
|
| 194 | + default: |
|
| 195 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 196 | + break; |
|
| 197 | + } |
|
| 198 | 198 | } |