@@ -65,6 +65,9 @@ |
||
| 65 | 65 | // L'index du SELECT doit s'appeler "id" |
| 66 | 66 | |
| 67 | 67 | // http://doc.spip.org/@optimiser_sansref |
| 68 | +/** |
|
| 69 | + * @param string $id |
|
| 70 | + */ |
|
| 68 | 71 | function optimiser_sansref($table, $id, $sel, $and="") |
| 69 | 72 | { |
| 70 | 73 | $in = array(); |
@@ -17,44 +17,44 @@ discard block |
||
| 17 | 17 | // http://doc.spip.org/@genie_optimiser_dist |
| 18 | 18 | function genie_optimiser_dist($t) { |
| 19 | 19 | |
| 20 | - optimiser_base_une_table(); |
|
| 21 | - optimiser_base(); |
|
| 22 | - |
|
| 23 | - // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 24 | - // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 25 | - // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 26 | - // qui aurait beaucoup de sites SPIP |
|
| 27 | - return -(mktime(2,0,0) + rand(0, 3600*4)); |
|
| 20 | + optimiser_base_une_table(); |
|
| 21 | + optimiser_base(); |
|
| 22 | + |
|
| 23 | + // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 24 | + // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 25 | + // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 26 | + // qui aurait beaucoup de sites SPIP |
|
| 27 | + return -(mktime(2,0,0) + rand(0, 3600*4)); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // heure de reference pour le garbage collector = 24h auparavant |
| 31 | 31 | // http://doc.spip.org/@optimiser_base |
| 32 | 32 | function optimiser_base($attente = 86400) { |
| 33 | - optimiser_base_disparus($attente); |
|
| 33 | + optimiser_base_disparus($attente); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | // http://doc.spip.org/@optimiser_base_une_table |
| 38 | 38 | function optimiser_base_une_table() { |
| 39 | 39 | |
| 40 | - $tables = array(); |
|
| 41 | - $result = sql_showbase(); |
|
| 42 | - |
|
| 43 | - // on n'optimise qu'une seule table a chaque fois, |
|
| 44 | - // pour ne pas vautrer le systeme |
|
| 45 | - // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 46 | - while ($row = sql_fetch($result)) |
|
| 47 | - $tables[] = array_shift($row); |
|
| 48 | - |
|
| 49 | - if ($tables) { |
|
| 50 | - $table_op = intval($GLOBALS['meta']['optimiser_table']+1) % sizeof($tables); |
|
| 51 | - ecrire_meta('optimiser_table', $table_op); |
|
| 52 | - $q = $tables[$table_op]; |
|
| 53 | - spip_log("debut d'optimisation de la table $q"); |
|
| 54 | - if (sql_optimize($q)) |
|
| 55 | - spip_log("fin d'optimisation de la table $q"); |
|
| 56 | - else spip_log("Pas d'optimiseur necessaire"); |
|
| 57 | - } |
|
| 40 | + $tables = array(); |
|
| 41 | + $result = sql_showbase(); |
|
| 42 | + |
|
| 43 | + // on n'optimise qu'une seule table a chaque fois, |
|
| 44 | + // pour ne pas vautrer le systeme |
|
| 45 | + // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 46 | + while ($row = sql_fetch($result)) |
|
| 47 | + $tables[] = array_shift($row); |
|
| 48 | + |
|
| 49 | + if ($tables) { |
|
| 50 | + $table_op = intval($GLOBALS['meta']['optimiser_table']+1) % sizeof($tables); |
|
| 51 | + ecrire_meta('optimiser_table', $table_op); |
|
| 52 | + $q = $tables[$table_op]; |
|
| 53 | + spip_log("debut d'optimisation de la table $q"); |
|
| 54 | + if (sql_optimize($q)) |
|
| 55 | + spip_log("fin d'optimisation de la table $q"); |
|
| 56 | + else spip_log("Pas d'optimiseur necessaire"); |
|
| 57 | + } |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // mysql < 4.0 refuse les requetes DELETE multi table |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | // http://doc.spip.org/@optimiser_sansref |
| 68 | 68 | function optimiser_sansref($table, $id, $sel, $and="") |
| 69 | 69 | { |
| 70 | - $in = array(); |
|
| 71 | - while ($row = sql_fetch($sel)) $in[$row['id']]=true; |
|
| 72 | - sql_free($sel); |
|
| 73 | - |
|
| 74 | - if ($in) { |
|
| 75 | - sql_delete($table, sql_in($id,array_keys($in)) . ($and?" AND $and":"")); |
|
| 76 | - spip_log("Numeros des entrees $id supprimees dans la table $table: $in"); |
|
| 77 | - } |
|
| 78 | - return count($in); |
|
| 70 | + $in = array(); |
|
| 71 | + while ($row = sql_fetch($sel)) $in[$row['id']]=true; |
|
| 72 | + sql_free($sel); |
|
| 73 | + |
|
| 74 | + if ($in) { |
|
| 75 | + sql_delete($table, sql_in($id,array_keys($in)) . ($and?" AND $and":"")); |
|
| 76 | + spip_log("Numeros des entrees $id supprimees dans la table $table: $in"); |
|
| 77 | + } |
|
| 78 | + return count($in); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Nomenclature des liens morts entre les tables, |
@@ -86,63 +86,63 @@ discard block |
||
| 86 | 86 | // http://doc.spip.org/@optimiser_base_disparus |
| 87 | 87 | function optimiser_base_disparus($attente = 86400) { |
| 88 | 88 | |
| 89 | - # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 90 | - $mydate = sql_quote(date("Y-m-d H:i:s", time() - $attente)); |
|
| 89 | + # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 90 | + $mydate = sql_quote(date("Y-m-d H:i:s", time() - $attente)); |
|
| 91 | 91 | |
| 92 | - $n = 0; |
|
| 92 | + $n = 0; |
|
| 93 | 93 | |
| 94 | - // |
|
| 95 | - // Rubriques |
|
| 96 | - // |
|
| 94 | + // |
|
| 95 | + // Rubriques |
|
| 96 | + // |
|
| 97 | 97 | |
| 98 | - # les articles qui sont dans une id_rubrique inexistante |
|
| 99 | - # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 100 | - # specialement affectes a une rubrique non-existante (plugin, |
|
| 101 | - # cf. http://trac.rezo.net/trac/spip/ticket/1549 ) |
|
| 102 | - $res = sql_select("A.id_article AS id", |
|
| 103 | - "spip_articles AS A |
|
| 98 | + # les articles qui sont dans une id_rubrique inexistante |
|
| 99 | + # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 100 | + # specialement affectes a une rubrique non-existante (plugin, |
|
| 101 | + # cf. http://trac.rezo.net/trac/spip/ticket/1549 ) |
|
| 102 | + $res = sql_select("A.id_article AS id", |
|
| 103 | + "spip_articles AS A |
|
| 104 | 104 | LEFT JOIN spip_rubriques AS R |
| 105 | 105 | ON A.id_rubrique=R.id_rubrique", |
| 106 | - "A.id_rubrique > 0 |
|
| 106 | + "A.id_rubrique > 0 |
|
| 107 | 107 | AND R.id_rubrique IS NULL |
| 108 | 108 | AND A.maj < $mydate"); |
| 109 | 109 | |
| 110 | - $n+= optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 110 | + $n+= optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 111 | 111 | |
| 112 | - // les articles a la poubelle |
|
| 113 | - sql_delete("spip_articles", "statut='poubelle' AND maj < $mydate"); |
|
| 112 | + // les articles a la poubelle |
|
| 113 | + sql_delete("spip_articles", "statut='poubelle' AND maj < $mydate"); |
|
| 114 | 114 | |
| 115 | - // |
|
| 116 | - // Auteurs |
|
| 117 | - // |
|
| 115 | + // |
|
| 116 | + // Auteurs |
|
| 117 | + // |
|
| 118 | 118 | |
| 119 | - include_spip('action/editer_liens'); |
|
| 120 | - // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 121 | - // et depuis des auteurs effaces |
|
| 122 | - $n+= objet_optimiser_liens(array('auteur'=>'*'),'*'); |
|
| 119 | + include_spip('action/editer_liens'); |
|
| 120 | + // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 121 | + // et depuis des auteurs effaces |
|
| 122 | + $n+= objet_optimiser_liens(array('auteur'=>'*'),'*'); |
|
| 123 | 123 | |
| 124 | - # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 125 | - $res = sql_select("A.id_auteur AS id", |
|
| 126 | - "spip_auteurs AS A |
|
| 124 | + # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 125 | + $res = sql_select("A.id_auteur AS id", |
|
| 126 | + "spip_auteurs AS A |
|
| 127 | 127 | LEFT JOIN spip_auteurs_liens AS L |
| 128 | 128 | ON L.id_auteur=A.id_auteur", |
| 129 | - "L.id_auteur IS NULL |
|
| 129 | + "L.id_auteur IS NULL |
|
| 130 | 130 | AND A.statut='5poubelle' AND A.maj < $mydate"); |
| 131 | 131 | |
| 132 | - $n+= optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 132 | + $n+= optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 133 | 133 | |
| 134 | - # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 135 | - # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 136 | - sql_delete("spip_auteurs", "statut='nouveau' AND maj < ". sql_quote(date('Y-m-d', time()-45*24*3600))); |
|
| 134 | + # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 135 | + # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 136 | + sql_delete("spip_auteurs", "statut='nouveau' AND maj < ". sql_quote(date('Y-m-d', time()-45*24*3600))); |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - $n = pipeline('optimiser_base_disparus', array( |
|
| 140 | - 'args'=>array( |
|
| 141 | - 'attente' => $attente, |
|
| 142 | - 'date' => $mydate), |
|
| 143 | - 'data'=>$n |
|
| 144 | - )); |
|
| 139 | + $n = pipeline('optimiser_base_disparus', array( |
|
| 140 | + 'args'=>array( |
|
| 141 | + 'attente' => $attente, |
|
| 142 | + 'date' => $mydate), |
|
| 143 | + 'data'=>$n |
|
| 144 | + )); |
|
| 145 | 145 | |
| 146 | - if (!$n) spip_log("Optimisation des tables: aucun lien mort"); |
|
| 146 | + if (!$n) spip_log("Optimisation des tables: aucun lien mort"); |
|
| 147 | 147 | } |
| 148 | 148 | ?> |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
| 25 | 25 | // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
| 26 | 26 | // qui aurait beaucoup de sites SPIP |
| 27 | - return -(mktime(2,0,0) + rand(0, 3600*4)); |
|
| 27 | + return -(mktime(2, 0, 0) + rand(0, 3600 * 4)); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // heure de reference pour le garbage collector = 24h auparavant |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $tables[] = array_shift($row); |
| 48 | 48 | |
| 49 | 49 | if ($tables) { |
| 50 | - $table_op = intval($GLOBALS['meta']['optimiser_table']+1) % sizeof($tables); |
|
| 50 | + $table_op = intval($GLOBALS['meta']['optimiser_table'] + 1) % sizeof($tables); |
|
| 51 | 51 | ecrire_meta('optimiser_table', $table_op); |
| 52 | 52 | $q = $tables[$table_op]; |
| 53 | 53 | spip_log("debut d'optimisation de la table $q"); |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | // L'index du SELECT doit s'appeler "id" |
| 66 | 66 | |
| 67 | 67 | // http://doc.spip.org/@optimiser_sansref |
| 68 | -function optimiser_sansref($table, $id, $sel, $and="") |
|
| 68 | +function optimiser_sansref($table, $id, $sel, $and = "") |
|
| 69 | 69 | { |
| 70 | 70 | $in = array(); |
| 71 | - while ($row = sql_fetch($sel)) $in[$row['id']]=true; |
|
| 71 | + while ($row = sql_fetch($sel)) $in[$row['id']] = true; |
|
| 72 | 72 | sql_free($sel); |
| 73 | 73 | |
| 74 | 74 | if ($in) { |
| 75 | - sql_delete($table, sql_in($id,array_keys($in)) . ($and?" AND $and":"")); |
|
| 75 | + sql_delete($table, sql_in($id, array_keys($in)).($and ? " AND $and" : "")); |
|
| 76 | 76 | spip_log("Numeros des entrees $id supprimees dans la table $table: $in"); |
| 77 | 77 | } |
| 78 | 78 | return count($in); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | AND R.id_rubrique IS NULL |
| 108 | 108 | AND A.maj < $mydate"); |
| 109 | 109 | |
| 110 | - $n+= optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 110 | + $n += optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 111 | 111 | |
| 112 | 112 | // les articles a la poubelle |
| 113 | 113 | sql_delete("spip_articles", "statut='poubelle' AND maj < $mydate"); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | include_spip('action/editer_liens'); |
| 120 | 120 | // optimiser les liens de tous les auteurs vers des objets effaces |
| 121 | 121 | // et depuis des auteurs effaces |
| 122 | - $n+= objet_optimiser_liens(array('auteur'=>'*'),'*'); |
|
| 122 | + $n += objet_optimiser_liens(array('auteur'=>'*'), '*'); |
|
| 123 | 123 | |
| 124 | 124 | # effacer les auteurs poubelle qui ne sont lies a rien |
| 125 | 125 | $res = sql_select("A.id_auteur AS id", |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | "L.id_auteur IS NULL |
| 130 | 130 | AND A.statut='5poubelle' AND A.maj < $mydate"); |
| 131 | 131 | |
| 132 | - $n+= optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 132 | + $n += optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 133 | 133 | |
| 134 | 134 | # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
| 135 | 135 | # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
| 136 | - sql_delete("spip_auteurs", "statut='nouveau' AND maj < ". sql_quote(date('Y-m-d', time()-45*24*3600))); |
|
| 136 | + sql_delete("spip_auteurs", "statut='nouveau' AND maj < ".sql_quote(date('Y-m-d', time() - 45 * 24 * 3600))); |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | $n = pipeline('optimiser_base_disparus', array( |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('base/abstract_sql'); |
| 16 | 18 | |
@@ -43,17 +45,20 @@ discard block |
||
| 43 | 45 | // on n'optimise qu'une seule table a chaque fois, |
| 44 | 46 | // pour ne pas vautrer le systeme |
| 45 | 47 | // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
| 46 | - while ($row = sql_fetch($result)) |
|
| 47 | - $tables[] = array_shift($row); |
|
| 48 | + while ($row = sql_fetch($result)) { |
|
| 49 | + $tables[] = array_shift($row); |
|
| 50 | + } |
|
| 48 | 51 | |
| 49 | 52 | if ($tables) { |
| 50 | 53 | $table_op = intval($GLOBALS['meta']['optimiser_table']+1) % sizeof($tables); |
| 51 | 54 | ecrire_meta('optimiser_table', $table_op); |
| 52 | 55 | $q = $tables[$table_op]; |
| 53 | 56 | spip_log("debut d'optimisation de la table $q"); |
| 54 | - if (sql_optimize($q)) |
|
| 55 | - spip_log("fin d'optimisation de la table $q"); |
|
| 56 | - else spip_log("Pas d'optimiseur necessaire"); |
|
| 57 | + if (sql_optimize($q)) { |
|
| 58 | + spip_log("fin d'optimisation de la table $q"); |
|
| 59 | + } else { |
|
| 60 | + spip_log("Pas d'optimiseur necessaire"); |
|
| 61 | + } |
|
| 57 | 62 | } |
| 58 | 63 | } |
| 59 | 64 | |
@@ -68,7 +73,9 @@ discard block |
||
| 68 | 73 | function optimiser_sansref($table, $id, $sel, $and="") |
| 69 | 74 | { |
| 70 | 75 | $in = array(); |
| 71 | - while ($row = sql_fetch($sel)) $in[$row['id']]=true; |
|
| 76 | + while ($row = sql_fetch($sel)) { |
|
| 77 | + $in[$row['id']]=true; |
|
| 78 | + } |
|
| 72 | 79 | sql_free($sel); |
| 73 | 80 | |
| 74 | 81 | if ($in) { |
@@ -143,6 +150,8 @@ discard block |
||
| 143 | 150 | 'data'=>$n |
| 144 | 151 | )); |
| 145 | 152 | |
| 146 | - if (!$n) spip_log("Optimisation des tables: aucun lien mort"); |
|
| 147 | -} |
|
| 153 | + if (!$n) { |
|
| 154 | + spip_log("Optimisation des tables: aucun lien mort"); |
|
| 155 | + } |
|
| 156 | + } |
|
| 148 | 157 | ?> |
@@ -105,6 +105,9 @@ discard block |
||
| 105 | 105 | // Inclure les arguments significatifs pour le hachage |
| 106 | 106 | // cas particulier du statut pour compatibilite ancien rss/suivi_revisions |
| 107 | 107 | |
| 108 | +/** |
|
| 109 | + * @param string $op |
|
| 110 | + */ |
|
| 108 | 111 | function param_low_sec($op, $args=array(), $lang='', $mime='rss') |
| 109 | 112 | { |
| 110 | 113 | $a = $b = ''; |
@@ -202,6 +205,9 @@ discard block |
||
| 202 | 205 | // Installe ou verifie un .htaccess, y compris sa prise en compte par Apache |
| 203 | 206 | // |
| 204 | 207 | // http://doc.spip.org/@verifier_htaccess |
| 208 | +/** |
|
| 209 | + * @param string|null $rep |
|
| 210 | + */ |
|
| 205 | 211 | function verifier_htaccess($rep, $force=false) { |
| 206 | 212 | $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; |
| 207 | 213 | if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) |
@@ -14,31 +14,31 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | // http://doc.spip.org/@creer_pass_aleatoire |
| 16 | 16 | function creer_pass_aleatoire($longueur = 8, $sel = "") { |
| 17 | - $seed = (double) (microtime() + 1) * time(); |
|
| 18 | - mt_srand($seed); |
|
| 19 | - srand($seed); |
|
| 20 | - $s = ''; |
|
| 21 | - $pass = ''; |
|
| 22 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 23 | - if (!$s) { |
|
| 24 | - $s = mt_rand(); |
|
| 25 | - if (!$s) $s = rand(); |
|
| 26 | - $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 27 | - } |
|
| 28 | - $r = unpack("Cr", pack("H2", $s.$s)); |
|
| 29 | - $x = $r['r'] & 63; |
|
| 30 | - if ($x < 10) $x = chr($x + 48); |
|
| 31 | - else if ($x < 36) $x = chr($x + 55); |
|
| 32 | - else if ($x < 62) $x = chr($x + 61); |
|
| 33 | - else if ($x == 63) $x = '/'; |
|
| 34 | - else $x = '.'; |
|
| 35 | - $pass .= $x; |
|
| 36 | - $s = substr($s, 2); |
|
| 37 | - } |
|
| 38 | - $pass = preg_replace("@[./]@", "a", $pass); |
|
| 39 | - $pass = preg_replace("@[I1l]@", "L", $pass); |
|
| 40 | - $pass = preg_replace("@[0O]@", "o", $pass); |
|
| 41 | - return $pass; |
|
| 17 | + $seed = (double) (microtime() + 1) * time(); |
|
| 18 | + mt_srand($seed); |
|
| 19 | + srand($seed); |
|
| 20 | + $s = ''; |
|
| 21 | + $pass = ''; |
|
| 22 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 23 | + if (!$s) { |
|
| 24 | + $s = mt_rand(); |
|
| 25 | + if (!$s) $s = rand(); |
|
| 26 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 27 | + } |
|
| 28 | + $r = unpack("Cr", pack("H2", $s.$s)); |
|
| 29 | + $x = $r['r'] & 63; |
|
| 30 | + if ($x < 10) $x = chr($x + 48); |
|
| 31 | + else if ($x < 36) $x = chr($x + 55); |
|
| 32 | + else if ($x < 62) $x = chr($x + 61); |
|
| 33 | + else if ($x == 63) $x = '/'; |
|
| 34 | + else $x = '.'; |
|
| 35 | + $pass .= $x; |
|
| 36 | + $s = substr($s, 2); |
|
| 37 | + } |
|
| 38 | + $pass = preg_replace("@[./]@", "a", $pass); |
|
| 39 | + $pass = preg_replace("@[I1l]@", "L", $pass); |
|
| 40 | + $pass = preg_replace("@[0O]@", "o", $pass); |
|
| 41 | + return $pass; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -49,18 +49,18 @@ discard block |
||
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | 51 | function creer_uniqid() { |
| 52 | - static $seeded; |
|
| 53 | - |
|
| 54 | - if (!$seeded) { |
|
| 55 | - $seed = (double) (microtime() + 1) * time(); |
|
| 56 | - mt_srand($seed); |
|
| 57 | - srand($seed); |
|
| 58 | - $seeded = true; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $s = mt_rand(); |
|
| 62 | - if (!$s) $s = rand(); |
|
| 63 | - return uniqid($s, 1); |
|
| 52 | + static $seeded; |
|
| 53 | + |
|
| 54 | + if (!$seeded) { |
|
| 55 | + $seed = (double) (microtime() + 1) * time(); |
|
| 56 | + mt_srand($seed); |
|
| 57 | + srand($seed); |
|
| 58 | + $seeded = true; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $s = mt_rand(); |
|
| 62 | + if (!$s) $s = rand(); |
|
| 63 | + return uniqid($s, 1); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | // http://doc.spip.org/@renouvelle_alea |
| 71 | 71 | function renouvelle_alea() { |
| 72 | - if (!isset($GLOBALS['meta']['alea_ephemere'])){ |
|
| 73 | - include_spip('base/abstract_sql'); |
|
| 74 | - $GLOBALS['meta']['alea_ephemere'] = sql_getfetsel('valeur', 'spip_meta', "nom='alea_ephemere'"); |
|
| 75 | - } |
|
| 76 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 77 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 78 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 79 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 80 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 72 | + if (!isset($GLOBALS['meta']['alea_ephemere'])){ |
|
| 73 | + include_spip('base/abstract_sql'); |
|
| 74 | + $GLOBALS['meta']['alea_ephemere'] = sql_getfetsel('valeur', 'spip_meta', "nom='alea_ephemere'"); |
|
| 75 | + } |
|
| 76 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 77 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 78 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 79 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 80 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | // |
| 87 | 87 | // http://doc.spip.org/@low_sec |
| 88 | 88 | function low_sec($id_auteur) { |
| 89 | - // Pas d'id_auteur : low_sec |
|
| 90 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 91 | - if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 92 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - else { |
|
| 96 | - $low_sec = sql_getfetsel("low_sec", "spip_auteurs", "id_auteur = $id_auteur"); |
|
| 97 | - if (!$low_sec) { |
|
| 98 | - $low_sec = creer_pass_aleatoire(); |
|
| 99 | - sql_updateq("spip_auteurs", array("low_sec" => $low_sec), "id_auteur = $id_auteur"); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return $low_sec; |
|
| 89 | + // Pas d'id_auteur : low_sec |
|
| 90 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 91 | + if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 92 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + else { |
|
| 96 | + $low_sec = sql_getfetsel("low_sec", "spip_auteurs", "id_auteur = $id_auteur"); |
|
| 97 | + if (!$low_sec) { |
|
| 98 | + $low_sec = creer_pass_aleatoire(); |
|
| 99 | + sql_updateq("spip_auteurs", array("low_sec" => $low_sec), "id_auteur = $id_auteur"); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return $low_sec; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Inclure les arguments significatifs pour le hachage |
@@ -107,46 +107,46 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | function param_low_sec($op, $args=array(), $lang='', $mime='rss') |
| 109 | 109 | { |
| 110 | - $a = $b = ''; |
|
| 111 | - foreach ($args as $val => $var) |
|
| 112 | - if ($var) { |
|
| 113 | - if ($val<>'statut') $a .= ':' . $val.'-'.$var; |
|
| 114 | - $b .= $val.'='.$var . '&'; |
|
| 115 | - } |
|
| 116 | - $a = substr($a,1); |
|
| 117 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 118 | - return $b |
|
| 119 | - . "op=" |
|
| 120 | - . $op |
|
| 121 | - . "&id=" |
|
| 122 | - . $id |
|
| 123 | - . "&cle=" |
|
| 124 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 125 | - . (!$a ? '' : "&args=$a") |
|
| 126 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 110 | + $a = $b = ''; |
|
| 111 | + foreach ($args as $val => $var) |
|
| 112 | + if ($var) { |
|
| 113 | + if ($val<>'statut') $a .= ':' . $val.'-'.$var; |
|
| 114 | + $b .= $val.'='.$var . '&'; |
|
| 115 | + } |
|
| 116 | + $a = substr($a,1); |
|
| 117 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 118 | + return $b |
|
| 119 | + . "op=" |
|
| 120 | + . $op |
|
| 121 | + . "&id=" |
|
| 122 | + . $id |
|
| 123 | + . "&cle=" |
|
| 124 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 125 | + . (!$a ? '' : "&args=$a") |
|
| 126 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // http://doc.spip.org/@afficher_low_sec |
| 130 | 130 | function afficher_low_sec ($id_auteur, $action='') { |
| 131 | - return substr(md5($action.low_sec($id_auteur)),0,8); |
|
| 131 | + return substr(md5($action.low_sec($id_auteur)),0,8); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // http://doc.spip.org/@verifier_low_sec |
| 135 | 135 | function verifier_low_sec ($id_auteur, $cle, $action='') { |
| 136 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 136 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // http://doc.spip.org/@effacer_low_sec |
| 140 | 140 | function effacer_low_sec($id_auteur) { |
| 141 | - if (!$id_auteur = intval($id_auteur)) return; // jamais trop prudent ;) |
|
| 142 | - sql_updateq("spip_auteurs", array("low_sec" => ''), "id_auteur = $id_auteur"); |
|
| 141 | + if (!$id_auteur = intval($id_auteur)) return; // jamais trop prudent ;) |
|
| 142 | + sql_updateq("spip_auteurs", array("low_sec" => ''), "id_auteur = $id_auteur"); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // http://doc.spip.org/@initialiser_sel |
| 146 | 146 | function initialiser_sel() { |
| 147 | - global $htsalt; |
|
| 148 | - if (CRYPT_MD5) $htsalt = '$1$'.creer_pass_aleatoire(); |
|
| 149 | - else return ""; |
|
| 147 | + global $htsalt; |
|
| 148 | + if (CRYPT_MD5) $htsalt = '$1$'.creer_pass_aleatoire(); |
|
| 149 | + else return ""; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Cette fonction ne sert qu'a la connexion en mode http_auth.non LDAP |
@@ -154,48 +154,48 @@ discard block |
||
| 154 | 154 | // Voir le plugin "acces restreint" |
| 155 | 155 | // http://doc.spip.org/@ecrire_acces |
| 156 | 156 | function ecrire_acces() { |
| 157 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 158 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 159 | - |
|
| 160 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 161 | - // par exemple acces_restreint ; |
|
| 162 | - // si .htaccess existe, outrepasser spip_meta |
|
| 163 | - if (($GLOBALS['meta']['creer_htpasswd'] != 'oui') |
|
| 164 | - AND !@file_exists($htaccess)) { |
|
| 165 | - spip_unlink($htpasswd); |
|
| 166 | - spip_unlink($htpasswd."-admin"); |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 171 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 172 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 173 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 174 | - |
|
| 175 | - if (spip_connect_ldap()) return; |
|
| 176 | - $p1 = ''; // login:htpass pour tous |
|
| 177 | - $p2 = ''; // login:htpass pour les admins |
|
| 178 | - $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite','0minirezo','nouveau'))); |
|
| 179 | - while ($t = sql_fetch($s)) { |
|
| 180 | - if (strlen($t['login']) AND strlen($t['htpass'])) { |
|
| 181 | - $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 182 | - if ($t['statut'] == '0minirezo') |
|
| 183 | - $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - if ($p1) { |
|
| 187 | - ecrire_fichier($htpasswd, $p1); |
|
| 188 | - ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 189 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 190 | - } |
|
| 157 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 158 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 159 | + |
|
| 160 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 161 | + // par exemple acces_restreint ; |
|
| 162 | + // si .htaccess existe, outrepasser spip_meta |
|
| 163 | + if (($GLOBALS['meta']['creer_htpasswd'] != 'oui') |
|
| 164 | + AND !@file_exists($htaccess)) { |
|
| 165 | + spip_unlink($htpasswd); |
|
| 166 | + spip_unlink($htpasswd."-admin"); |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 171 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 172 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 173 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 174 | + |
|
| 175 | + if (spip_connect_ldap()) return; |
|
| 176 | + $p1 = ''; // login:htpass pour tous |
|
| 177 | + $p2 = ''; // login:htpass pour les admins |
|
| 178 | + $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite','0minirezo','nouveau'))); |
|
| 179 | + while ($t = sql_fetch($s)) { |
|
| 180 | + if (strlen($t['login']) AND strlen($t['htpass'])) { |
|
| 181 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 182 | + if ($t['statut'] == '0minirezo') |
|
| 183 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + if ($p1) { |
|
| 187 | + ecrire_fichier($htpasswd, $p1); |
|
| 188 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 189 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 190 | + } |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
| 194 | 194 | // http://doc.spip.org/@generer_htpass |
| 195 | 195 | function generer_htpass($pass) { |
| 196 | - global $htsalt; |
|
| 197 | - if (function_exists('crypt')) |
|
| 198 | - return crypt($pass, $htsalt); |
|
| 196 | + global $htsalt; |
|
| 197 | + if (function_exists('crypt')) |
|
| 198 | + return crypt($pass, $htsalt); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // |
@@ -203,46 +203,46 @@ discard block |
||
| 203 | 203 | // |
| 204 | 204 | // http://doc.spip.org/@verifier_htaccess |
| 205 | 205 | function verifier_htaccess($rep, $force=false) { |
| 206 | - $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; |
|
| 207 | - if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) |
|
| 208 | - return true; |
|
| 209 | - if ($ht = @fopen($htaccess, "w")) { |
|
| 210 | - fputs($ht, "deny from all\n"); |
|
| 211 | - fclose($ht); |
|
| 212 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 213 | - $t = rtrim($rep,"/") . "/.ok"; |
|
| 214 | - if ($ht = @fopen($t, "w")) { |
|
| 215 | - @fclose($ht); |
|
| 216 | - include_spip('inc/distant'); |
|
| 217 | - $t = substr($t,strlen(_DIR_RACINE)); |
|
| 218 | - $t = url_de_base() . $t; |
|
| 219 | - $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 220 | - // htaccess inoperant si on a recupere des entetes HTTP |
|
| 221 | - // (ignorer la reussite si connexion par fopen) |
|
| 222 | - $ht = !(isset($ht[0]) AND $ht[0]); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - spip_log("Creation de $htaccess " . ($ht ? " reussie" : " manquee")); |
|
| 226 | - return $ht; |
|
| 206 | + $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; |
|
| 207 | + if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) |
|
| 208 | + return true; |
|
| 209 | + if ($ht = @fopen($htaccess, "w")) { |
|
| 210 | + fputs($ht, "deny from all\n"); |
|
| 211 | + fclose($ht); |
|
| 212 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 213 | + $t = rtrim($rep,"/") . "/.ok"; |
|
| 214 | + if ($ht = @fopen($t, "w")) { |
|
| 215 | + @fclose($ht); |
|
| 216 | + include_spip('inc/distant'); |
|
| 217 | + $t = substr($t,strlen(_DIR_RACINE)); |
|
| 218 | + $t = url_de_base() . $t; |
|
| 219 | + $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 220 | + // htaccess inoperant si on a recupere des entetes HTTP |
|
| 221 | + // (ignorer la reussite si connexion par fopen) |
|
| 222 | + $ht = !(isset($ht[0]) AND $ht[0]); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + spip_log("Creation de $htaccess " . ($ht ? " reussie" : " manquee")); |
|
| 226 | + return $ht; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | // http://doc.spip.org/@gerer_htaccess |
| 232 | 232 | function gerer_htaccess() { |
| 233 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 234 | - // par exemple acces_restreint |
|
| 235 | - $f = ($GLOBALS['meta']['creer_htaccess'] === 'oui'); |
|
| 236 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 237 | - $dirs[] = array('extension' => 'distant'); |
|
| 238 | - foreach($dirs as $e) { |
|
| 239 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 240 | - if ($f) |
|
| 241 | - verifier_htaccess($dir); |
|
| 242 | - else spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - return $GLOBALS['meta']['creer_htaccess']; |
|
| 233 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 234 | + // par exemple acces_restreint |
|
| 235 | + $f = ($GLOBALS['meta']['creer_htaccess'] === 'oui'); |
|
| 236 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 237 | + $dirs[] = array('extension' => 'distant'); |
|
| 238 | + foreach($dirs as $e) { |
|
| 239 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 240 | + if ($f) |
|
| 241 | + verifier_htaccess($dir); |
|
| 242 | + else spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + return $GLOBALS['meta']['creer_htaccess']; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | initialiser_sel(); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | // http://doc.spip.org/@renouvelle_alea |
| 71 | 71 | function renouvelle_alea() { |
| 72 | - if (!isset($GLOBALS['meta']['alea_ephemere'])){ |
|
| 72 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 73 | 73 | include_spip('base/abstract_sql'); |
| 74 | 74 | $GLOBALS['meta']['alea_ephemere'] = sql_getfetsel('valeur', 'spip_meta', "nom='alea_ephemere'"); |
| 75 | 75 | } |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | // Inclure les arguments significatifs pour le hachage |
| 106 | 106 | // cas particulier du statut pour compatibilite ancien rss/suivi_revisions |
| 107 | 107 | |
| 108 | -function param_low_sec($op, $args=array(), $lang='', $mime='rss') |
|
| 108 | +function param_low_sec($op, $args = array(), $lang = '', $mime = 'rss') |
|
| 109 | 109 | { |
| 110 | 110 | $a = $b = ''; |
| 111 | 111 | foreach ($args as $val => $var) |
| 112 | 112 | if ($var) { |
| 113 | - if ($val<>'statut') $a .= ':' . $val.'-'.$var; |
|
| 114 | - $b .= $val.'='.$var . '&'; |
|
| 113 | + if ($val <> 'statut') $a .= ':'.$val.'-'.$var; |
|
| 114 | + $b .= $val.'='.$var.'&'; |
|
| 115 | 115 | } |
| 116 | - $a = substr($a,1); |
|
| 116 | + $a = substr($a, 1); |
|
| 117 | 117 | $id = intval(@$GLOBALS['connect_id_auteur']); |
| 118 | 118 | return $b |
| 119 | 119 | . "op=" |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // http://doc.spip.org/@afficher_low_sec |
| 130 | -function afficher_low_sec ($id_auteur, $action='') { |
|
| 131 | - return substr(md5($action.low_sec($id_auteur)),0,8); |
|
| 130 | +function afficher_low_sec($id_auteur, $action = '') { |
|
| 131 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // http://doc.spip.org/@verifier_low_sec |
| 135 | -function verifier_low_sec ($id_auteur, $cle, $action='') { |
|
| 135 | +function verifier_low_sec($id_auteur, $cle, $action = '') { |
|
| 136 | 136 | return ($cle == afficher_low_sec($id_auteur, $action)); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | // Voir le plugin "acces restreint" |
| 155 | 155 | // http://doc.spip.org/@ecrire_acces |
| 156 | 156 | function ecrire_acces() { |
| 157 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 158 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 157 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 158 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 159 | 159 | |
| 160 | 160 | // Cette variable de configuration peut etre posee par un plugin |
| 161 | 161 | // par exemple acces_restreint ; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | if (spip_connect_ldap()) return; |
| 176 | 176 | $p1 = ''; // login:htpass pour tous |
| 177 | 177 | $p2 = ''; // login:htpass pour les admins |
| 178 | - $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite','0minirezo','nouveau'))); |
|
| 178 | + $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite', '0minirezo', 'nouveau'))); |
|
| 179 | 179 | while ($t = sql_fetch($s)) { |
| 180 | 180 | if (strlen($t['login']) AND strlen($t['htpass'])) { |
| 181 | 181 | $p1 .= $t['login'].':'.$t['htpass']."\n"; |
@@ -202,27 +202,27 @@ discard block |
||
| 202 | 202 | // Installe ou verifie un .htaccess, y compris sa prise en compte par Apache |
| 203 | 203 | // |
| 204 | 204 | // http://doc.spip.org/@verifier_htaccess |
| 205 | -function verifier_htaccess($rep, $force=false) { |
|
| 206 | - $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; |
|
| 205 | +function verifier_htaccess($rep, $force = false) { |
|
| 206 | + $htaccess = rtrim($rep, "/")."/"._ACCESS_FILE_NAME; |
|
| 207 | 207 | if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) |
| 208 | 208 | return true; |
| 209 | 209 | if ($ht = @fopen($htaccess, "w")) { |
| 210 | 210 | fputs($ht, "deny from all\n"); |
| 211 | 211 | fclose($ht); |
| 212 | 212 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 213 | - $t = rtrim($rep,"/") . "/.ok"; |
|
| 213 | + $t = rtrim($rep, "/")."/.ok"; |
|
| 214 | 214 | if ($ht = @fopen($t, "w")) { |
| 215 | 215 | @fclose($ht); |
| 216 | 216 | include_spip('inc/distant'); |
| 217 | - $t = substr($t,strlen(_DIR_RACINE)); |
|
| 218 | - $t = url_de_base() . $t; |
|
| 217 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 218 | + $t = url_de_base().$t; |
|
| 219 | 219 | $ht = recuperer_lapage($t, false, 'HEAD', 0); |
| 220 | 220 | // htaccess inoperant si on a recupere des entetes HTTP |
| 221 | 221 | // (ignorer la reussite si connexion par fopen) |
| 222 | 222 | $ht = !(isset($ht[0]) AND $ht[0]); |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | - spip_log("Creation de $htaccess " . ($ht ? " reussie" : " manquee")); |
|
| 225 | + spip_log("Creation de $htaccess ".($ht ? " reussie" : " manquee")); |
|
| 226 | 226 | return $ht; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | $f = ($GLOBALS['meta']['creer_htaccess'] === 'oui'); |
| 236 | 236 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 237 | 237 | $dirs[] = array('extension' => 'distant'); |
| 238 | - foreach($dirs as $e) { |
|
| 239 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 238 | + foreach ($dirs as $e) { |
|
| 239 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 240 | 240 | if ($f) |
| 241 | 241 | verifier_htaccess($dir); |
| 242 | - else spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 242 | + else spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | return $GLOBALS['meta']['creer_htaccess']; |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // http://doc.spip.org/@creer_pass_aleatoire |
| 16 | 18 | function creer_pass_aleatoire($longueur = 8, $sel = "") { |
@@ -22,16 +24,24 @@ discard block |
||
| 22 | 24 | for ($i = 0; $i < $longueur; $i++) { |
| 23 | 25 | if (!$s) { |
| 24 | 26 | $s = mt_rand(); |
| 25 | - if (!$s) $s = rand(); |
|
| 27 | + if (!$s) { |
|
| 28 | + $s = rand(); |
|
| 29 | + } |
|
| 26 | 30 | $s = substr(md5(uniqid($s).$sel), 0, 16); |
| 27 | 31 | } |
| 28 | 32 | $r = unpack("Cr", pack("H2", $s.$s)); |
| 29 | 33 | $x = $r['r'] & 63; |
| 30 | - if ($x < 10) $x = chr($x + 48); |
|
| 31 | - else if ($x < 36) $x = chr($x + 55); |
|
| 32 | - else if ($x < 62) $x = chr($x + 61); |
|
| 33 | - else if ($x == 63) $x = '/'; |
|
| 34 | - else $x = '.'; |
|
| 34 | + if ($x < 10) { |
|
| 35 | + $x = chr($x + 48); |
|
| 36 | + } else if ($x < 36) { |
|
| 37 | + $x = chr($x + 55); |
|
| 38 | + } else if ($x < 62) { |
|
| 39 | + $x = chr($x + 61); |
|
| 40 | + } else if ($x == 63) { |
|
| 41 | + $x = '/'; |
|
| 42 | + } else { |
|
| 43 | + $x = '.'; |
|
| 44 | + } |
|
| 35 | 45 | $pass .= $x; |
| 36 | 46 | $s = substr($s, 2); |
| 37 | 47 | } |
@@ -59,7 +69,9 @@ discard block |
||
| 59 | 69 | } |
| 60 | 70 | |
| 61 | 71 | $s = mt_rand(); |
| 62 | - if (!$s) $s = rand(); |
|
| 72 | + if (!$s) { |
|
| 73 | + $s = rand(); |
|
| 74 | + } |
|
| 63 | 75 | return uniqid($s, 1); |
| 64 | 76 | } |
| 65 | 77 | |
@@ -91,8 +103,7 @@ discard block |
||
| 91 | 103 | if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
| 92 | 104 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 93 | 105 | } |
| 94 | - } |
|
| 95 | - else { |
|
| 106 | + } else { |
|
| 96 | 107 | $low_sec = sql_getfetsel("low_sec", "spip_auteurs", "id_auteur = $id_auteur"); |
| 97 | 108 | if (!$low_sec) { |
| 98 | 109 | $low_sec = creer_pass_aleatoire(); |
@@ -108,9 +119,10 @@ discard block |
||
| 108 | 119 | function param_low_sec($op, $args=array(), $lang='', $mime='rss') |
| 109 | 120 | { |
| 110 | 121 | $a = $b = ''; |
| 111 | - foreach ($args as $val => $var) |
|
| 112 | - if ($var) { |
|
| 122 | + foreach ($args as $val => $var) { |
|
| 123 | + if ($var) { |
|
| 113 | 124 | if ($val<>'statut') $a .= ':' . $val.'-'.$var; |
| 125 | + } |
|
| 114 | 126 | $b .= $val.'='.$var . '&'; |
| 115 | 127 | } |
| 116 | 128 | $a = substr($a,1); |
@@ -138,16 +150,22 @@ discard block |
||
| 138 | 150 | |
| 139 | 151 | // http://doc.spip.org/@effacer_low_sec |
| 140 | 152 | function effacer_low_sec($id_auteur) { |
| 141 | - if (!$id_auteur = intval($id_auteur)) return; // jamais trop prudent ;) |
|
| 153 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 154 | + return; |
|
| 155 | + } |
|
| 156 | + // jamais trop prudent ;) |
|
| 142 | 157 | sql_updateq("spip_auteurs", array("low_sec" => ''), "id_auteur = $id_auteur"); |
| 143 | 158 | } |
| 144 | 159 | |
| 145 | 160 | // http://doc.spip.org/@initialiser_sel |
| 146 | 161 | function initialiser_sel() { |
| 147 | 162 | global $htsalt; |
| 148 | - if (CRYPT_MD5) $htsalt = '$1$'.creer_pass_aleatoire(); |
|
| 149 | - else return ""; |
|
| 150 | -} |
|
| 163 | + if (CRYPT_MD5) { |
|
| 164 | + $htsalt = '$1$'.creer_pass_aleatoire(); |
|
| 165 | + } else { |
|
| 166 | + return ""; |
|
| 167 | + } |
|
| 168 | + } |
|
| 151 | 169 | |
| 152 | 170 | // Cette fonction ne sert qu'a la connexion en mode http_auth.non LDAP |
| 153 | 171 | // Son role est de creer le fichier htpasswd |
@@ -172,15 +190,18 @@ discard block |
||
| 172 | 190 | // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
| 173 | 191 | // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
| 174 | 192 | |
| 175 | - if (spip_connect_ldap()) return; |
|
| 193 | + if (spip_connect_ldap()) { |
|
| 194 | + return; |
|
| 195 | + } |
|
| 176 | 196 | $p1 = ''; // login:htpass pour tous |
| 177 | 197 | $p2 = ''; // login:htpass pour les admins |
| 178 | 198 | $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite','0minirezo','nouveau'))); |
| 179 | 199 | while ($t = sql_fetch($s)) { |
| 180 | 200 | if (strlen($t['login']) AND strlen($t['htpass'])) { |
| 181 | 201 | $p1 .= $t['login'].':'.$t['htpass']."\n"; |
| 182 | - if ($t['statut'] == '0minirezo') |
|
| 183 | - $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 202 | + if ($t['statut'] == '0minirezo') { |
|
| 203 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 204 | + } |
|
| 184 | 205 | } |
| 185 | 206 | } |
| 186 | 207 | if ($p1) { |
@@ -194,9 +215,10 @@ discard block |
||
| 194 | 215 | // http://doc.spip.org/@generer_htpass |
| 195 | 216 | function generer_htpass($pass) { |
| 196 | 217 | global $htsalt; |
| 197 | - if (function_exists('crypt')) |
|
| 198 | - return crypt($pass, $htsalt); |
|
| 199 | -} |
|
| 218 | + if (function_exists('crypt')) { |
|
| 219 | + return crypt($pass, $htsalt); |
|
| 220 | + } |
|
| 221 | + } |
|
| 200 | 222 | |
| 201 | 223 | // |
| 202 | 224 | // Installe ou verifie un .htaccess, y compris sa prise en compte par Apache |
@@ -204,8 +226,9 @@ discard block |
||
| 204 | 226 | // http://doc.spip.org/@verifier_htaccess |
| 205 | 227 | function verifier_htaccess($rep, $force=false) { |
| 206 | 228 | $htaccess = rtrim($rep,"/") . "/" . _ACCESS_FILE_NAME; |
| 207 | - if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) |
|
| 208 | - return true; |
|
| 229 | + if (((@file_exists($htaccess)) OR defined('_TEST_DIRS')) AND !$force) { |
|
| 230 | + return true; |
|
| 231 | + } |
|
| 209 | 232 | if ($ht = @fopen($htaccess, "w")) { |
| 210 | 233 | fputs($ht, "deny from all\n"); |
| 211 | 234 | fclose($ht); |
@@ -237,9 +260,11 @@ discard block |
||
| 237 | 260 | $dirs[] = array('extension' => 'distant'); |
| 238 | 261 | foreach($dirs as $e) { |
| 239 | 262 | if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
| 240 | - if ($f) |
|
| 241 | - verifier_htaccess($dir); |
|
| 242 | - else spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 263 | + if ($f) { |
|
| 264 | + verifier_htaccess($dir); |
|
| 265 | + } else { |
|
| 266 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 267 | + } |
|
| 243 | 268 | } |
| 244 | 269 | } |
| 245 | 270 | return $GLOBALS['meta']['creer_htaccess']; |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | * -1 : renvoyer action, arg et hash sous forme de array() |
| 25 | 25 | * true ou false : renvoyer une url, avec & (false) ou & (true) |
| 26 | 26 | * string : renvoyer un formulaire |
| 27 | - * @param string|int $att |
|
| 27 | + * @param string $att |
|
| 28 | 28 | * id_auteur pour lequel generer l'action en mode url ou array() |
| 29 | 29 | * atributs du formulaire en mode formulaire |
| 30 | 30 | * @param bool $public |
| 31 | - * @return array|string |
|
| 31 | + * @return string |
|
| 32 | 32 | */ |
| 33 | 33 | function generer_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false){ |
| 34 | 34 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
@@ -36,6 +36,10 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // http://doc.spip.org/@redirige_action_auteur |
| 39 | +/** |
|
| 40 | + * @param string $action |
|
| 41 | + * @param string $ret |
|
| 42 | + */ |
|
| 39 | 43 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 40 | 44 | |
| 41 | 45 | $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) .generer_url_ecrire($ret, $gra, true, true); |
@@ -44,6 +48,12 @@ discard block |
||
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | // http://doc.spip.org/@redirige_action_post |
| 51 | +/** |
|
| 52 | + * @param string $action |
|
| 53 | + * @param string $arg |
|
| 54 | + * @param string $ret |
|
| 55 | + * @param string $gra |
|
| 56 | + */ |
|
| 47 | 57 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = ''){ |
| 48 | 58 | $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true); |
| 49 | 59 | return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'"); |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | * @return array|string |
| 32 | 32 | */ |
| 33 | 33 | function generer_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false){ |
| 34 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | - return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 34 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | + return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // http://doc.spip.org/@redirige_action_auteur |
| 39 | 39 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 40 | 40 | |
| 41 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) .generer_url_ecrire($ret, $gra, true, true); |
|
| 41 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) .generer_url_ecrire($ret, $gra, true, true); |
|
| 42 | 42 | |
| 43 | - return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 43 | + return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // http://doc.spip.org/@redirige_action_post |
| 47 | 47 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = ''){ |
| 48 | - $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true); |
|
| 49 | - return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'"); |
|
| 48 | + $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true); |
|
| 49 | + return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'"); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,34 +63,34 @@ discard block |
||
| 63 | 63 | * passer "text/html" comme $content_type |
| 64 | 64 | */ |
| 65 | 65 | function ajax_retour($corps, $content_type = null){ |
| 66 | - $xml = false; |
|
| 67 | - if (is_null($content_type) OR $content_type===true){ |
|
| 68 | - $xml = true; |
|
| 69 | - $content_type = 'text/html'; |
|
| 70 | - } |
|
| 71 | - elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) { |
|
| 72 | - $content_type = 'text/html'; |
|
| 73 | - } |
|
| 66 | + $xml = false; |
|
| 67 | + if (is_null($content_type) OR $content_type===true){ |
|
| 68 | + $xml = true; |
|
| 69 | + $content_type = 'text/html'; |
|
| 70 | + } |
|
| 71 | + elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) { |
|
| 72 | + $content_type = 'text/html'; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $e = ""; |
|
| 76 | - if (isset($_COOKIE['spip_admin']) |
|
| 77 | - AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps']))) |
|
| 78 | - $e = erreur_squelette(); |
|
| 79 | - if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec']=='valider_xml')){ |
|
| 80 | - $debut = _DOCTYPE_ECRIRE |
|
| 81 | - ."<html><head><title>Debug Spip Ajax</title></head>" |
|
| 82 | - ."<body><div>\n\n" |
|
| 83 | - ."<!-- %%%%%%%%%%%%%%%%%%% Ajax %%%%%%%%%%%%%%%%%%% -->\n"; |
|
| 75 | + $e = ""; |
|
| 76 | + if (isset($_COOKIE['spip_admin']) |
|
| 77 | + AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps']))) |
|
| 78 | + $e = erreur_squelette(); |
|
| 79 | + if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec']=='valider_xml')){ |
|
| 80 | + $debut = _DOCTYPE_ECRIRE |
|
| 81 | + ."<html><head><title>Debug Spip Ajax</title></head>" |
|
| 82 | + ."<body><div>\n\n" |
|
| 83 | + ."<!-- %%%%%%%%%%%%%%%%%%% Ajax %%%%%%%%%%%%%%%%%%% -->\n"; |
|
| 84 | 84 | |
| 85 | - $fin = '</div></body></html>'; |
|
| 85 | + $fin = '</div></body></html>'; |
|
| 86 | 86 | |
| 87 | - } else { |
|
| 88 | - $c = $GLOBALS['meta']["charset"]; |
|
| 89 | - header('Content-Type: '.$content_type.'; charset='.$c); |
|
| 90 | - $debut = (($xml AND strlen(trim($corps))) ? '<'."?xml version='1.0' encoding='".$c."'?".">\n" : ''); |
|
| 91 | - $fin = ""; |
|
| 92 | - } |
|
| 93 | - echo $debut, $corps, $fin, $e; |
|
| 87 | + } else { |
|
| 88 | + $c = $GLOBALS['meta']["charset"]; |
|
| 89 | + header('Content-Type: '.$content_type.'; charset='.$c); |
|
| 90 | + $debut = (($xml AND strlen(trim($corps))) ? '<'."?xml version='1.0' encoding='".$c."'?".">\n" : ''); |
|
| 91 | + $fin = ""; |
|
| 92 | + } |
|
| 93 | + echo $debut, $corps, $fin, $e; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | ?> |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param bool $public |
| 31 | 31 | * @return array|string |
| 32 | 32 | */ |
| 33 | -function generer_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false){ |
|
| 33 | +function generer_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false) { |
|
| 34 | 34 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 35 | 35 | return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
| 36 | 36 | } |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | // http://doc.spip.org/@redirige_action_auteur |
| 39 | 39 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 40 | 40 | |
| 41 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) .generer_url_ecrire($ret, $gra, true, true); |
|
| 41 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT).generer_url_ecrire($ret, $gra, true, true); |
|
| 42 | 42 | |
| 43 | 43 | return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // http://doc.spip.org/@redirige_action_post |
| 47 | -function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = ''){ |
|
| 47 | +function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
|
| 48 | 48 | $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true); |
| 49 | 49 | return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'"); |
| 50 | 50 | } |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | * La valeur speciale false fournit text/html sans entete xml. Elle equivaut a |
| 63 | 63 | * passer "text/html" comme $content_type |
| 64 | 64 | */ |
| 65 | -function ajax_retour($corps, $content_type = null){ |
|
| 65 | +function ajax_retour($corps, $content_type = null) { |
|
| 66 | 66 | $xml = false; |
| 67 | - if (is_null($content_type) OR $content_type===true){ |
|
| 67 | + if (is_null($content_type) OR $content_type === true) { |
|
| 68 | 68 | $xml = true; |
| 69 | 69 | $content_type = 'text/html'; |
| 70 | 70 | } |
| 71 | - elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) { |
|
| 71 | + elseif (!$content_type OR !is_string($content_type) OR strpos($content_type, '/') === false) { |
|
| 72 | 72 | $content_type = 'text/html'; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $e = ""; |
| 76 | 76 | if (isset($_COOKIE['spip_admin']) |
| 77 | - AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps']))) |
|
| 77 | + AND ((_request('var_mode') == 'debug') OR !empty($GLOBALS['tableau_des_temps']))) |
|
| 78 | 78 | $e = erreur_squelette(); |
| 79 | - if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec']=='valider_xml')){ |
|
| 79 | + if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec'] == 'valider_xml')) { |
|
| 80 | 80 | $debut = _DOCTYPE_ECRIRE |
| 81 | 81 | ."<html><head><title>Debug Spip Ajax</title></head>" |
| 82 | 82 | ."<body><div>\n\n" |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * retourne une URL ou un formulaire securises |
@@ -67,15 +69,15 @@ discard block |
||
| 67 | 69 | if (is_null($content_type) OR $content_type===true){ |
| 68 | 70 | $xml = true; |
| 69 | 71 | $content_type = 'text/html'; |
| 70 | - } |
|
| 71 | - elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) { |
|
| 72 | + } elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) { |
|
| 72 | 73 | $content_type = 'text/html'; |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | 76 | $e = ""; |
| 76 | 77 | if (isset($_COOKIE['spip_admin']) |
| 77 | - AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps']))) |
|
| 78 | - $e = erreur_squelette(); |
|
| 78 | + AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps']))) { |
|
| 79 | + $e = erreur_squelette(); |
|
| 80 | + } |
|
| 79 | 81 | if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec']=='valider_xml')){ |
| 80 | 82 | $debut = _DOCTYPE_ECRIRE |
| 81 | 83 | ."<html><head><title>Debug Spip Ajax</title></head>" |
@@ -92,6 +92,9 @@ discard block |
||
| 92 | 92 | return aider_icone($url); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | +/** |
|
| 96 | + * @param null|string $url |
|
| 97 | + */ |
|
| 95 | 98 | function aider_icone($url, $clic= '') |
| 96 | 99 | { |
| 97 | 100 | global $spip_lang, $spip_lang_rtl; |
@@ -118,6 +121,9 @@ discard block |
||
| 118 | 121 | // Les sections d'un fichier aide sont reperees ainsi: |
| 119 | 122 | define('_SECTIONS_AIDE', ',<h([12])(?:\s+class="spip")?'. '>([^/]+?)(?:/(.+?))?</h\1>,ism'); |
| 120 | 123 | |
| 124 | +/** |
|
| 125 | + * @param string $path |
|
| 126 | + */ |
|
| 121 | 127 | function aide_fichier($path, $help_server) { |
| 122 | 128 | |
| 123 | 129 | $md5 = md5(serialize($help_server)); |
@@ -22,34 +22,34 @@ discard block |
||
| 22 | 22 | // Le tableau ci-dessous donne le repere correspondant a ces informations. |
| 23 | 23 | |
| 24 | 24 | $GLOBALS['aider_index'] = array( |
| 25 | - 'editer_article.html' => array ( |
|
| 26 | - 'surtitre' => 'arttitre', |
|
| 27 | - 'titre' => 'arttitre', |
|
| 28 | - 'soustitre' => 'arttitre', |
|
| 29 | - 'id_parent' => 'artrub', |
|
| 30 | - 'descriptif' => 'artdesc', |
|
| 31 | - 'virtuel' => 'artvirt', |
|
| 32 | - 'chapo' => 'arttitre', |
|
| 33 | - 'text_area' => 'arttexte'), |
|
| 25 | + 'editer_article.html' => array ( |
|
| 26 | + 'surtitre' => 'arttitre', |
|
| 27 | + 'titre' => 'arttitre', |
|
| 28 | + 'soustitre' => 'arttitre', |
|
| 29 | + 'id_parent' => 'artrub', |
|
| 30 | + 'descriptif' => 'artdesc', |
|
| 31 | + 'virtuel' => 'artvirt', |
|
| 32 | + 'chapo' => 'arttitre', |
|
| 33 | + 'text_area' => 'arttexte'), |
|
| 34 | 34 | |
| 35 | - 'editer_breve.html' => array( |
|
| 36 | - 'id_parent' => 'brevesrub', |
|
| 37 | - 'lien_titre' => 'breveslien', |
|
| 38 | - 'statut' => 'brevesstatut'), |
|
| 35 | + 'editer_breve.html' => array( |
|
| 36 | + 'id_parent' => 'brevesrub', |
|
| 37 | + 'lien_titre' => 'breveslien', |
|
| 38 | + 'statut' => 'brevesstatut'), |
|
| 39 | 39 | |
| 40 | - 'editer_groupe_mot.html' => array( |
|
| 41 | - 'titre' => 'motsgroupes'), |
|
| 40 | + 'editer_groupe_mot.html' => array( |
|
| 41 | + 'titre' => 'motsgroupes'), |
|
| 42 | 42 | |
| 43 | - 'editer_mot.html' => array( |
|
| 44 | - 'titre' => 'mots', |
|
| 45 | - 'id_groupe' => 'motsgroupes'), |
|
| 43 | + 'editer_mot.html' => array( |
|
| 44 | + 'titre' => 'mots', |
|
| 45 | + 'id_groupe' => 'motsgroupes'), |
|
| 46 | 46 | |
| 47 | - 'editer_rubrique.html' => array( |
|
| 48 | - 'titre' => 'arttitre', |
|
| 49 | - 'id_parent' => 'rubrub', |
|
| 50 | - 'text_area' => 'raccourcis') |
|
| 47 | + 'editer_rubrique.html' => array( |
|
| 48 | + 'titre' => 'arttitre', |
|
| 49 | + 'id_parent' => 'rubrub', |
|
| 50 | + 'text_area' => 'raccourcis') |
|
| 51 | 51 | |
| 52 | - ); |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
@@ -68,51 +68,51 @@ discard block |
||
| 68 | 68 | * @return |
| 69 | 69 | **/ |
| 70 | 70 | function inc_aider_dist($aide='', $skel='', $env=array(), $aide_spip_directe = false) { |
| 71 | - global $spip_lang, $aider_index; |
|
| 72 | - |
|
| 73 | - if (($skel = basename($skel)) |
|
| 74 | - AND isset($aider_index[$skel]) |
|
| 75 | - AND isset($aider_index[$skel][$aide])) |
|
| 76 | - $aide = $aider_index[$skel][$aide]; |
|
| 77 | - |
|
| 78 | - if ($aide_spip_directe) { |
|
| 79 | - // on suppose que spip.net est le premier present |
|
| 80 | - // dans la liste des serveurs. C'est forcement le cas |
|
| 81 | - // a l'installation tout du moins |
|
| 82 | - $help_server = $GLOBALS['help_server']; |
|
| 83 | - $url = array_shift($help_server) . '/'; |
|
| 84 | - $url = parametre_url($url, 'exec', 'aide'); |
|
| 85 | - $url = parametre_url($url, 'aide', $aide); |
|
| 86 | - $url = parametre_url($url, 'var_lang', $spip_lang); |
|
| 87 | - } else { |
|
| 88 | - $args = "aide=$aide&var_lang=$spip_lang"; |
|
| 89 | - $url = generer_url_ecrire("aide", $args); |
|
| 90 | - } |
|
| 71 | + global $spip_lang, $aider_index; |
|
| 72 | + |
|
| 73 | + if (($skel = basename($skel)) |
|
| 74 | + AND isset($aider_index[$skel]) |
|
| 75 | + AND isset($aider_index[$skel][$aide])) |
|
| 76 | + $aide = $aider_index[$skel][$aide]; |
|
| 77 | + |
|
| 78 | + if ($aide_spip_directe) { |
|
| 79 | + // on suppose que spip.net est le premier present |
|
| 80 | + // dans la liste des serveurs. C'est forcement le cas |
|
| 81 | + // a l'installation tout du moins |
|
| 82 | + $help_server = $GLOBALS['help_server']; |
|
| 83 | + $url = array_shift($help_server) . '/'; |
|
| 84 | + $url = parametre_url($url, 'exec', 'aide'); |
|
| 85 | + $url = parametre_url($url, 'aide', $aide); |
|
| 86 | + $url = parametre_url($url, 'var_lang', $spip_lang); |
|
| 87 | + } else { |
|
| 88 | + $args = "aide=$aide&var_lang=$spip_lang"; |
|
| 89 | + $url = generer_url_ecrire("aide", $args); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return aider_icone($url); |
|
| 92 | + return aider_icone($url); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function aider_icone($url, $clic= '') |
| 96 | 96 | { |
| 97 | - global $spip_lang, $spip_lang_rtl; |
|
| 98 | - |
|
| 99 | - if (!$clic) { |
|
| 100 | - $t = _T('titre_image_aide'); |
|
| 101 | - $clic = http_img_pack("aide".aide_lang_dir($spip_lang,$spip_lang_rtl)."-16.png", |
|
| 102 | - _T('info_image_aide'), |
|
| 103 | - " title=\"$t\" class='aide'"); |
|
| 104 | - } |
|
| 105 | - return "\n <a class='aide popin'\nhref='" |
|
| 106 | - . $url |
|
| 107 | - . "' target='_blank'>" |
|
| 108 | - . $clic |
|
| 109 | - . "</a>"; |
|
| 97 | + global $spip_lang, $spip_lang_rtl; |
|
| 98 | + |
|
| 99 | + if (!$clic) { |
|
| 100 | + $t = _T('titre_image_aide'); |
|
| 101 | + $clic = http_img_pack("aide".aide_lang_dir($spip_lang,$spip_lang_rtl)."-16.png", |
|
| 102 | + _T('info_image_aide'), |
|
| 103 | + " title=\"$t\" class='aide'"); |
|
| 104 | + } |
|
| 105 | + return "\n <a class='aide popin'\nhref='" |
|
| 106 | + . $url |
|
| 107 | + . "' target='_blank'>" |
|
| 108 | + . $clic |
|
| 109 | + . "</a>"; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // en hebreu le ? ne doit pas etre inverse |
| 113 | 113 | // http://doc.spip.org/@aide_lang_dir |
| 114 | 114 | function aide_lang_dir($spip_lang,$spip_lang_rtl) { |
| 115 | - return ($spip_lang<>'he') ? $spip_lang_rtl : ''; |
|
| 115 | + return ($spip_lang<>'he') ? $spip_lang_rtl : ''; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Les sections d'un fichier aide sont reperees ainsi: |
@@ -120,85 +120,85 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | function aide_fichier($path, $help_server) { |
| 122 | 122 | |
| 123 | - $md5 = md5(serialize($help_server)); |
|
| 124 | - $fichier_aide = _DIR_AIDE . substr($md5,0,16) . "-" . $path; |
|
| 125 | - $lastm = @filemtime($fichier_aide); |
|
| 126 | - $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php'); |
|
| 127 | - $here = @(is_readable($fichier_aide) AND ($lastm >= $lastversion)); |
|
| 128 | - $contenu = ''; |
|
| 129 | - |
|
| 130 | - if ($here) { |
|
| 131 | - lire_fichier($fichier_aide, $contenu); |
|
| 132 | - return array($contenu, $lastm); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // mettre en cache (tant pis si echec) |
|
| 136 | - sous_repertoire(_DIR_AIDE,'','',true); |
|
| 137 | - $contenu = array(); |
|
| 138 | - include_spip('inc/distant'); |
|
| 139 | - foreach ($help_server as $k => $server) { |
|
| 140 | - // Remplacer les liens aux images par leur gestionnaire de cache |
|
| 141 | - $url = "$server/$path"; |
|
| 142 | - $local = _DIR_AIDE.substr(md5($url),0,8)."-".preg_replace(",[^\w.]+,i","_",$url); |
|
| 143 | - $local = _DIR_RACINE . copie_locale($url, 'modif', $local); |
|
| 144 | - |
|
| 145 | - lire_fichier($local,$page); |
|
| 146 | - $page = aide_fixe_img($page,$server); |
|
| 147 | - // les liens internes ne doivent pas etre deguises en externes |
|
| 148 | - $url = parse_url($url); |
|
| 149 | - $re = '@(<a\b[^>]*\s+href=["\'])' . |
|
| 150 | - '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' . |
|
| 151 | - $url['path'] . '([^"\']*)@ims'; |
|
| 152 | - $page = preg_replace($re,'\\1\\2', $page); |
|
| 153 | - |
|
| 154 | - preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER); |
|
| 155 | - // Fusionner les aides ayant meme nom de section |
|
| 156 | - $vus = array(); |
|
| 157 | - foreach ($sections as $section) { |
|
| 158 | - list($tout,$prof, $sujet,) = $section; |
|
| 159 | - if (in_array($sujet, $vus)) continue; |
|
| 160 | - $corps = aide_section($sujet, $page, $prof); |
|
| 161 | - foreach ($contenu as $k => $s) { |
|
| 162 | - if ($sujet == $k) { |
|
| 163 | - // Section deja vue qu'il faut completer |
|
| 164 | - // Si le complement a des sous-sections, |
|
| 165 | - // ne pas en tenir compte quand on les rencontrera |
|
| 166 | - // lors des prochains passages dans la boucle |
|
| 167 | - preg_match_all(_SECTIONS_AIDE, $corps, $s, PREG_PATTERN_ORDER); |
|
| 168 | - if ($s) {$vus = array_merge($vus, $s[2]);} |
|
| 169 | - $contenu[$k] .= $corps; |
|
| 170 | - $corps = ''; |
|
| 171 | - break; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // Si totalement nouveau, inserer le titre |
|
| 175 | - // mais pas le corps s'il contient des sous-sections: |
|
| 176 | - // elles vont venir dans les passages suivants |
|
| 177 | - if ($corps) { |
|
| 178 | - $corps = aide_section($sujet, $page); |
|
| 179 | - $contenu[$sujet] = $tout . "\n" . $corps; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $contenu = '<div>' . join('',$contenu) . '</div>'; |
|
| 185 | - |
|
| 186 | - // Renvoyer les liens vraiment externes dans une autre fenetre |
|
| 187 | - $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@', |
|
| 188 | - '<a href="\\1"\\2 target="_blank">', |
|
| 189 | - $contenu); |
|
| 190 | - |
|
| 191 | - // Correction typo dans la langue demandee |
|
| 192 | - #changer_typo($lang_aide); |
|
| 193 | - $contenu = '<body>' . $contenu . '</body>'; |
|
| 194 | - |
|
| 195 | - if (strlen($contenu) <= 100) return array(false, false); |
|
| 196 | - ecrire_fichier ($fichier_aide, $contenu); |
|
| 197 | - return array($contenu, time()); |
|
| 123 | + $md5 = md5(serialize($help_server)); |
|
| 124 | + $fichier_aide = _DIR_AIDE . substr($md5,0,16) . "-" . $path; |
|
| 125 | + $lastm = @filemtime($fichier_aide); |
|
| 126 | + $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php'); |
|
| 127 | + $here = @(is_readable($fichier_aide) AND ($lastm >= $lastversion)); |
|
| 128 | + $contenu = ''; |
|
| 129 | + |
|
| 130 | + if ($here) { |
|
| 131 | + lire_fichier($fichier_aide, $contenu); |
|
| 132 | + return array($contenu, $lastm); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // mettre en cache (tant pis si echec) |
|
| 136 | + sous_repertoire(_DIR_AIDE,'','',true); |
|
| 137 | + $contenu = array(); |
|
| 138 | + include_spip('inc/distant'); |
|
| 139 | + foreach ($help_server as $k => $server) { |
|
| 140 | + // Remplacer les liens aux images par leur gestionnaire de cache |
|
| 141 | + $url = "$server/$path"; |
|
| 142 | + $local = _DIR_AIDE.substr(md5($url),0,8)."-".preg_replace(",[^\w.]+,i","_",$url); |
|
| 143 | + $local = _DIR_RACINE . copie_locale($url, 'modif', $local); |
|
| 144 | + |
|
| 145 | + lire_fichier($local,$page); |
|
| 146 | + $page = aide_fixe_img($page,$server); |
|
| 147 | + // les liens internes ne doivent pas etre deguises en externes |
|
| 148 | + $url = parse_url($url); |
|
| 149 | + $re = '@(<a\b[^>]*\s+href=["\'])' . |
|
| 150 | + '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' . |
|
| 151 | + $url['path'] . '([^"\']*)@ims'; |
|
| 152 | + $page = preg_replace($re,'\\1\\2', $page); |
|
| 153 | + |
|
| 154 | + preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER); |
|
| 155 | + // Fusionner les aides ayant meme nom de section |
|
| 156 | + $vus = array(); |
|
| 157 | + foreach ($sections as $section) { |
|
| 158 | + list($tout,$prof, $sujet,) = $section; |
|
| 159 | + if (in_array($sujet, $vus)) continue; |
|
| 160 | + $corps = aide_section($sujet, $page, $prof); |
|
| 161 | + foreach ($contenu as $k => $s) { |
|
| 162 | + if ($sujet == $k) { |
|
| 163 | + // Section deja vue qu'il faut completer |
|
| 164 | + // Si le complement a des sous-sections, |
|
| 165 | + // ne pas en tenir compte quand on les rencontrera |
|
| 166 | + // lors des prochains passages dans la boucle |
|
| 167 | + preg_match_all(_SECTIONS_AIDE, $corps, $s, PREG_PATTERN_ORDER); |
|
| 168 | + if ($s) {$vus = array_merge($vus, $s[2]);} |
|
| 169 | + $contenu[$k] .= $corps; |
|
| 170 | + $corps = ''; |
|
| 171 | + break; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // Si totalement nouveau, inserer le titre |
|
| 175 | + // mais pas le corps s'il contient des sous-sections: |
|
| 176 | + // elles vont venir dans les passages suivants |
|
| 177 | + if ($corps) { |
|
| 178 | + $corps = aide_section($sujet, $page); |
|
| 179 | + $contenu[$sujet] = $tout . "\n" . $corps; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $contenu = '<div>' . join('',$contenu) . '</div>'; |
|
| 185 | + |
|
| 186 | + // Renvoyer les liens vraiment externes dans une autre fenetre |
|
| 187 | + $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@', |
|
| 188 | + '<a href="\\1"\\2 target="_blank">', |
|
| 189 | + $contenu); |
|
| 190 | + |
|
| 191 | + // Correction typo dans la langue demandee |
|
| 192 | + #changer_typo($lang_aide); |
|
| 193 | + $contenu = '<body>' . $contenu . '</body>'; |
|
| 194 | + |
|
| 195 | + if (strlen($contenu) <= 100) return array(false, false); |
|
| 196 | + ecrire_fichier ($fichier_aide, $contenu); |
|
| 197 | + return array($contenu, time()); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | function generer_url_aide_img($args){ |
| 201 | - return generer_url_action('aide_img', $args, false, true); |
|
| 201 | + return generer_url_action('aide_img', $args, false, true); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -208,18 +208,18 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | // Remplacer les URL des images par l'URL du gestionnaire de cache local |
| 210 | 210 | function aide_fixe_img($contenu, $server){ |
| 211 | - $html = ""; |
|
| 212 | - $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS"; |
|
| 213 | - while (preg_match($re, $contenu, $r)) { |
|
| 214 | - $p = strpos($contenu, $r[0]); |
|
| 215 | - $i = $server . '/' . $r[3]; |
|
| 216 | - $html .= substr($contenu, 0, $p) . $r[1] . $i; |
|
| 217 | - $contenu = substr($contenu, $p + strlen($r[0])); |
|
| 218 | - } |
|
| 219 | - $html .= $contenu; |
|
| 220 | - |
|
| 221 | - // traiter les vieilles doc |
|
| 222 | - return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html); |
|
| 211 | + $html = ""; |
|
| 212 | + $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS"; |
|
| 213 | + while (preg_match($re, $contenu, $r)) { |
|
| 214 | + $p = strpos($contenu, $r[0]); |
|
| 215 | + $i = $server . '/' . $r[3]; |
|
| 216 | + $html .= substr($contenu, 0, $p) . $r[1] . $i; |
|
| 217 | + $contenu = substr($contenu, $p + strlen($r[0])); |
|
| 218 | + } |
|
| 219 | + $html .= $contenu; |
|
| 220 | + |
|
| 221 | + // traiter les vieilles doc |
|
| 222 | + return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | // et se termine par la prochaine balise h2 ou h1 ou le /body final. |
| 229 | 229 | |
| 230 | 230 | function aide_section($aide, $contenu, $prof=2){ |
| 231 | - $maxprof = ($prof >=2) ? "12" : "1"; |
|
| 232 | - $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
|
| 233 | - ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
|
| 231 | + $maxprof = ($prof >=2) ? "12" : "1"; |
|
| 232 | + $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
|
| 233 | + ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
|
| 234 | 234 | |
| 235 | - if (preg_match($r, $contenu, $m)) |
|
| 236 | - return $m[1]; |
|
| 235 | + if (preg_match($r, $contenu, $m)) |
|
| 236 | + return $m[1]; |
|
| 237 | 237 | # spip_log("aide inconnue $r dans " . substr($contenu, 0, 150)); |
| 238 | - return ''; |
|
| 238 | + return ''; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | // Le tableau ci-dessous donne le repere correspondant a ces informations. |
| 23 | 23 | |
| 24 | 24 | $GLOBALS['aider_index'] = array( |
| 25 | - 'editer_article.html' => array ( |
|
| 25 | + 'editer_article.html' => array( |
|
| 26 | 26 | 'surtitre' => 'arttitre', |
| 27 | 27 | 'titre' => 'arttitre', |
| 28 | 28 | 'soustitre' => 'arttitre', |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * true : Le lien est realise sur spip.net/aide/ directement ... |
| 68 | 68 | * @return |
| 69 | 69 | **/ |
| 70 | -function inc_aider_dist($aide='', $skel='', $env=array(), $aide_spip_directe = false) { |
|
| 70 | +function inc_aider_dist($aide = '', $skel = '', $env = array(), $aide_spip_directe = false) { |
|
| 71 | 71 | global $spip_lang, $aider_index; |
| 72 | 72 | |
| 73 | 73 | if (($skel = basename($skel)) |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | // dans la liste des serveurs. C'est forcement le cas |
| 81 | 81 | // a l'installation tout du moins |
| 82 | 82 | $help_server = $GLOBALS['help_server']; |
| 83 | - $url = array_shift($help_server) . '/'; |
|
| 83 | + $url = array_shift($help_server).'/'; |
|
| 84 | 84 | $url = parametre_url($url, 'exec', 'aide'); |
| 85 | 85 | $url = parametre_url($url, 'aide', $aide); |
| 86 | 86 | $url = parametre_url($url, 'var_lang', $spip_lang); |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | return aider_icone($url); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | -function aider_icone($url, $clic= '') |
|
| 95 | +function aider_icone($url, $clic = '') |
|
| 96 | 96 | { |
| 97 | 97 | global $spip_lang, $spip_lang_rtl; |
| 98 | 98 | |
| 99 | 99 | if (!$clic) { |
| 100 | 100 | $t = _T('titre_image_aide'); |
| 101 | - $clic = http_img_pack("aide".aide_lang_dir($spip_lang,$spip_lang_rtl)."-16.png", |
|
| 101 | + $clic = http_img_pack("aide".aide_lang_dir($spip_lang, $spip_lang_rtl)."-16.png", |
|
| 102 | 102 | _T('info_image_aide'), |
| 103 | 103 | " title=\"$t\" class='aide'"); |
| 104 | 104 | } |
@@ -111,19 +111,19 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | // en hebreu le ? ne doit pas etre inverse |
| 113 | 113 | // http://doc.spip.org/@aide_lang_dir |
| 114 | -function aide_lang_dir($spip_lang,$spip_lang_rtl) { |
|
| 115 | - return ($spip_lang<>'he') ? $spip_lang_rtl : ''; |
|
| 114 | +function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
|
| 115 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Les sections d'un fichier aide sont reperees ainsi: |
| 119 | -define('_SECTIONS_AIDE', ',<h([12])(?:\s+class="spip")?'. '>([^/]+?)(?:/(.+?))?</h\1>,ism'); |
|
| 119 | +define('_SECTIONS_AIDE', ',<h([12])(?:\s+class="spip")?'.'>([^/]+?)(?:/(.+?))?</h\1>,ism'); |
|
| 120 | 120 | |
| 121 | 121 | function aide_fichier($path, $help_server) { |
| 122 | 122 | |
| 123 | 123 | $md5 = md5(serialize($help_server)); |
| 124 | - $fichier_aide = _DIR_AIDE . substr($md5,0,16) . "-" . $path; |
|
| 124 | + $fichier_aide = _DIR_AIDE.substr($md5, 0, 16)."-".$path; |
|
| 125 | 125 | $lastm = @filemtime($fichier_aide); |
| 126 | - $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php'); |
|
| 126 | + $lastversion = @filemtime(_DIR_RESTREINT.'inc_version.php'); |
|
| 127 | 127 | $here = @(is_readable($fichier_aide) AND ($lastm >= $lastversion)); |
| 128 | 128 | $contenu = ''; |
| 129 | 129 | |
@@ -133,29 +133,29 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // mettre en cache (tant pis si echec) |
| 136 | - sous_repertoire(_DIR_AIDE,'','',true); |
|
| 136 | + sous_repertoire(_DIR_AIDE, '', '', true); |
|
| 137 | 137 | $contenu = array(); |
| 138 | 138 | include_spip('inc/distant'); |
| 139 | 139 | foreach ($help_server as $k => $server) { |
| 140 | 140 | // Remplacer les liens aux images par leur gestionnaire de cache |
| 141 | 141 | $url = "$server/$path"; |
| 142 | - $local = _DIR_AIDE.substr(md5($url),0,8)."-".preg_replace(",[^\w.]+,i","_",$url); |
|
| 143 | - $local = _DIR_RACINE . copie_locale($url, 'modif', $local); |
|
| 142 | + $local = _DIR_AIDE.substr(md5($url), 0, 8)."-".preg_replace(",[^\w.]+,i", "_", $url); |
|
| 143 | + $local = _DIR_RACINE.copie_locale($url, 'modif', $local); |
|
| 144 | 144 | |
| 145 | - lire_fichier($local,$page); |
|
| 146 | - $page = aide_fixe_img($page,$server); |
|
| 145 | + lire_fichier($local, $page); |
|
| 146 | + $page = aide_fixe_img($page, $server); |
|
| 147 | 147 | // les liens internes ne doivent pas etre deguises en externes |
| 148 | 148 | $url = parse_url($url); |
| 149 | - $re = '@(<a\b[^>]*\s+href=["\'])' . |
|
| 150 | - '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' . |
|
| 151 | - $url['path'] . '([^"\']*)@ims'; |
|
| 152 | - $page = preg_replace($re,'\\1\\2', $page); |
|
| 149 | + $re = '@(<a\b[^>]*\s+href=["\'])'. |
|
| 150 | + '(?:'.$url['scheme'].'://'.$url['host'].')?'. |
|
| 151 | + $url['path'].'([^"\']*)@ims'; |
|
| 152 | + $page = preg_replace($re, '\\1\\2', $page); |
|
| 153 | 153 | |
| 154 | 154 | preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER); |
| 155 | 155 | // Fusionner les aides ayant meme nom de section |
| 156 | 156 | $vus = array(); |
| 157 | 157 | foreach ($sections as $section) { |
| 158 | - list($tout,$prof, $sujet,) = $section; |
|
| 158 | + list($tout, $prof, $sujet,) = $section; |
|
| 159 | 159 | if (in_array($sujet, $vus)) continue; |
| 160 | 160 | $corps = aide_section($sujet, $page, $prof); |
| 161 | 161 | foreach ($contenu as $k => $s) { |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | // ne pas en tenir compte quand on les rencontrera |
| 166 | 166 | // lors des prochains passages dans la boucle |
| 167 | 167 | preg_match_all(_SECTIONS_AIDE, $corps, $s, PREG_PATTERN_ORDER); |
| 168 | - if ($s) {$vus = array_merge($vus, $s[2]);} |
|
| 168 | + if ($s) {$vus = array_merge($vus, $s[2]); } |
|
| 169 | 169 | $contenu[$k] .= $corps; |
| 170 | 170 | $corps = ''; |
| 171 | 171 | break; |
@@ -176,12 +176,12 @@ discard block |
||
| 176 | 176 | // elles vont venir dans les passages suivants |
| 177 | 177 | if ($corps) { |
| 178 | 178 | $corps = aide_section($sujet, $page); |
| 179 | - $contenu[$sujet] = $tout . "\n" . $corps; |
|
| 179 | + $contenu[$sujet] = $tout."\n".$corps; |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $contenu = '<div>' . join('',$contenu) . '</div>'; |
|
| 184 | + $contenu = '<div>'.join('', $contenu).'</div>'; |
|
| 185 | 185 | |
| 186 | 186 | // Renvoyer les liens vraiment externes dans une autre fenetre |
| 187 | 187 | $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@', |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | // Correction typo dans la langue demandee |
| 192 | 192 | #changer_typo($lang_aide); |
| 193 | - $contenu = '<body>' . $contenu . '</body>'; |
|
| 193 | + $contenu = '<body>'.$contenu.'</body>'; |
|
| 194 | 194 | |
| 195 | 195 | if (strlen($contenu) <= 100) return array(false, false); |
| 196 | - ecrire_fichier ($fichier_aide, $contenu); |
|
| 196 | + ecrire_fichier($fichier_aide, $contenu); |
|
| 197 | 197 | return array($contenu, time()); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | -function generer_url_aide_img($args){ |
|
| 200 | +function generer_url_aide_img($args) { |
|
| 201 | 201 | return generer_url_action('aide_img', $args, false, true); |
| 202 | 202 | } |
| 203 | 203 | |
@@ -207,19 +207,19 @@ discard block |
||
| 207 | 207 | define('_REPLACE_IMG_PACK', "@(<img([^<>]* +)?\s*src=['\"])img_pack\/@ims"); |
| 208 | 208 | |
| 209 | 209 | // Remplacer les URL des images par l'URL du gestionnaire de cache local |
| 210 | -function aide_fixe_img($contenu, $server){ |
|
| 210 | +function aide_fixe_img($contenu, $server) { |
|
| 211 | 211 | $html = ""; |
| 212 | 212 | $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS"; |
| 213 | 213 | while (preg_match($re, $contenu, $r)) { |
| 214 | 214 | $p = strpos($contenu, $r[0]); |
| 215 | - $i = $server . '/' . $r[3]; |
|
| 216 | - $html .= substr($contenu, 0, $p) . $r[1] . $i; |
|
| 215 | + $i = $server.'/'.$r[3]; |
|
| 216 | + $html .= substr($contenu, 0, $p).$r[1].$i; |
|
| 217 | 217 | $contenu = substr($contenu, $p + strlen($r[0])); |
| 218 | 218 | } |
| 219 | 219 | $html .= $contenu; |
| 220 | 220 | |
| 221 | 221 | // traiter les vieilles doc |
| 222 | - return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html); |
|
| 222 | + return preg_replace(_REPLACE_IMG_PACK, "\\1"._DIR_IMG_PACK, $html); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | // qui commence par son nom entouree d'une balise h2 |
| 228 | 228 | // et se termine par la prochaine balise h2 ou h1 ou le /body final. |
| 229 | 229 | |
| 230 | -function aide_section($aide, $contenu, $prof=2){ |
|
| 231 | - $maxprof = ($prof >=2) ? "12" : "1"; |
|
| 232 | - $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
|
| 230 | +function aide_section($aide, $contenu, $prof = 2) { |
|
| 231 | + $maxprof = ($prof >= 2) ? "12" : "1"; |
|
| 232 | + $r = "@<h$prof".'(?: class="spip")?'.'>\s*'.$aide |
|
| 233 | 233 | ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
| 234 | 234 | |
| 235 | 235 | if (preg_match($r, $contenu, $m)) |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/filtres'); |
| 16 | 18 | |
@@ -72,8 +74,9 @@ discard block |
||
| 72 | 74 | |
| 73 | 75 | if (($skel = basename($skel)) |
| 74 | 76 | AND isset($aider_index[$skel]) |
| 75 | - AND isset($aider_index[$skel][$aide])) |
|
| 76 | - $aide = $aider_index[$skel][$aide]; |
|
| 77 | + AND isset($aider_index[$skel][$aide])) { |
|
| 78 | + $aide = $aider_index[$skel][$aide]; |
|
| 79 | + } |
|
| 77 | 80 | |
| 78 | 81 | if ($aide_spip_directe) { |
| 79 | 82 | // on suppose que spip.net est le premier present |
@@ -156,7 +159,9 @@ discard block |
||
| 156 | 159 | $vus = array(); |
| 157 | 160 | foreach ($sections as $section) { |
| 158 | 161 | list($tout,$prof, $sujet,) = $section; |
| 159 | - if (in_array($sujet, $vus)) continue; |
|
| 162 | + if (in_array($sujet, $vus)) { |
|
| 163 | + continue; |
|
| 164 | + } |
|
| 160 | 165 | $corps = aide_section($sujet, $page, $prof); |
| 161 | 166 | foreach ($contenu as $k => $s) { |
| 162 | 167 | if ($sujet == $k) { |
@@ -192,7 +197,9 @@ discard block |
||
| 192 | 197 | #changer_typo($lang_aide); |
| 193 | 198 | $contenu = '<body>' . $contenu . '</body>'; |
| 194 | 199 | |
| 195 | - if (strlen($contenu) <= 100) return array(false, false); |
|
| 200 | + if (strlen($contenu) <= 100) { |
|
| 201 | + return array(false, false); |
|
| 202 | + } |
|
| 196 | 203 | ecrire_fichier ($fichier_aide, $contenu); |
| 197 | 204 | return array($contenu, time()); |
| 198 | 205 | } |
@@ -232,9 +239,10 @@ discard block |
||
| 232 | 239 | $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide |
| 233 | 240 | ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism"; |
| 234 | 241 | |
| 235 | - if (preg_match($r, $contenu, $m)) |
|
| 236 | - return $m[1]; |
|
| 237 | -# spip_log("aide inconnue $r dans " . substr($contenu, 0, 150)); |
|
| 242 | + if (preg_match($r, $contenu, $m)) { |
|
| 243 | + return $m[1]; |
|
| 244 | + } |
|
| 245 | + # spip_log("aide inconnue $r dans " . substr($contenu, 0, 150)); |
|
| 238 | 246 | return ''; |
| 239 | 247 | } |
| 240 | 248 | |
@@ -448,6 +448,10 @@ |
||
| 448 | 448 | return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | +/** |
|
| 452 | + * @param string $auth_methode |
|
| 453 | + * @param string $login |
|
| 454 | + */ |
|
| 451 | 455 | function auth_terminer_identifier_login($auth_methode, $login, $serveur=''){ |
| 452 | 456 | $args = func_get_args(); |
| 453 | 457 | $auteur = auth_administrer('terminer_identifier_login',$args); |
@@ -32,27 +32,27 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function inc_auth_dist() { |
| 34 | 34 | |
| 35 | - global $connect_login ; |
|
| 35 | + global $connect_login ; |
|
| 36 | 36 | |
| 37 | - $row = auth_mode(); |
|
| 37 | + $row = auth_mode(); |
|
| 38 | 38 | |
| 39 | - if ($row) return auth_init_droits($row); |
|
| 39 | + if ($row) return auth_init_droits($row); |
|
| 40 | 40 | |
| 41 | - if (!$connect_login) return auth_a_loger(); |
|
| 41 | + if (!$connect_login) return auth_a_loger(); |
|
| 42 | 42 | |
| 43 | - // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 44 | - // C'est soit parce que la base est inutilisable, |
|
| 45 | - // soit parce que la table des auteurs a changee (restauration etc) |
|
| 46 | - // Pas la peine d'insister. |
|
| 47 | - // Renvoyer le nom fautif et une URL de remise a zero |
|
| 43 | + // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 44 | + // C'est soit parce que la base est inutilisable, |
|
| 45 | + // soit parce que la table des auteurs a changee (restauration etc) |
|
| 46 | + // Pas la peine d'insister. |
|
| 47 | + // Renvoyer le nom fautif et une URL de remise a zero |
|
| 48 | 48 | |
| 49 | - if (spip_connect()) |
|
| 50 | - return array('login' => $connect_login, |
|
| 51 | - 'site' => generer_url_public('', "action=logout&logout=prive")); |
|
| 49 | + if (spip_connect()) |
|
| 50 | + return array('login' => $connect_login, |
|
| 51 | + 'site' => generer_url_public('', "action=logout&logout=prive")); |
|
| 52 | 52 | |
| 53 | - $n = intval(sql_errno()); |
|
| 54 | - spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 55 | - return $n ? $n : 1; |
|
| 53 | + $n = intval(sql_errno()); |
|
| 54 | + spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 55 | + return $n ? $n : 1; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -65,34 +65,34 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | function auth_echec($raison) |
| 67 | 67 | { |
| 68 | - include_spip('inc/minipres'); |
|
| 69 | - include_spip('inc/headers'); |
|
| 70 | - // pas authentifie. Pourquoi ? |
|
| 71 | - if (is_string($raison)) { |
|
| 72 | - // redirection vers une page d'authentification |
|
| 73 | - // on ne revient pas de cette fonction |
|
| 74 | - // sauf si pb de header |
|
| 75 | - $raison = redirige_formulaire($raison); |
|
| 76 | - } elseif (is_int($raison)) { |
|
| 77 | - // erreur SQL a afficher |
|
| 78 | - $raison = minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'). "<p><tt>".sql_errno()." ".sql_error()."</tt></p>"); |
|
| 79 | - } elseif (@$raison['statut']) { |
|
| 80 | - // un simple visiteur n'a pas acces a l'espace prive |
|
| 81 | - spip_log("connexion refusee a " . @$raison['id_auteur']); |
|
| 82 | - $raison = minipres(_T('avis_erreur_connexion'),_T('avis_erreur_visiteur')); |
|
| 83 | - } else { |
|
| 84 | - // auteur en fin de droits ... |
|
| 85 | - $h = $raison['site']; |
|
| 86 | - $raison = minipres(_T('avis_erreur_connexion'), |
|
| 87 | - "<br /><br /><p>" |
|
| 88 | - . _T('texte_inc_auth_1', |
|
| 89 | - array('auth_login' => $raison['login'])) |
|
| 90 | - . " <a href='$h'>" |
|
| 91 | - . _T('texte_inc_auth_2') |
|
| 92 | - . "</a>" |
|
| 93 | - . _T('texte_inc_auth_3')); |
|
| 94 | - } |
|
| 95 | - return $raison; |
|
| 68 | + include_spip('inc/minipres'); |
|
| 69 | + include_spip('inc/headers'); |
|
| 70 | + // pas authentifie. Pourquoi ? |
|
| 71 | + if (is_string($raison)) { |
|
| 72 | + // redirection vers une page d'authentification |
|
| 73 | + // on ne revient pas de cette fonction |
|
| 74 | + // sauf si pb de header |
|
| 75 | + $raison = redirige_formulaire($raison); |
|
| 76 | + } elseif (is_int($raison)) { |
|
| 77 | + // erreur SQL a afficher |
|
| 78 | + $raison = minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'). "<p><tt>".sql_errno()." ".sql_error()."</tt></p>"); |
|
| 79 | + } elseif (@$raison['statut']) { |
|
| 80 | + // un simple visiteur n'a pas acces a l'espace prive |
|
| 81 | + spip_log("connexion refusee a " . @$raison['id_auteur']); |
|
| 82 | + $raison = minipres(_T('avis_erreur_connexion'),_T('avis_erreur_visiteur')); |
|
| 83 | + } else { |
|
| 84 | + // auteur en fin de droits ... |
|
| 85 | + $h = $raison['site']; |
|
| 86 | + $raison = minipres(_T('avis_erreur_connexion'), |
|
| 87 | + "<br /><br /><p>" |
|
| 88 | + . _T('texte_inc_auth_1', |
|
| 89 | + array('auth_login' => $raison['login'])) |
|
| 90 | + . " <a href='$h'>" |
|
| 91 | + . _T('texte_inc_auth_2') |
|
| 92 | + . "</a>" |
|
| 93 | + . _T('texte_inc_auth_3')); |
|
| 94 | + } |
|
| 95 | + return $raison; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -103,78 +103,78 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | function auth_mode() |
| 105 | 105 | { |
| 106 | - global $auth_can_disconnect, $ignore_auth_http, $ignore_remote_user; |
|
| 107 | - global $connect_login ; |
|
| 108 | - |
|
| 109 | - // |
|
| 110 | - // Initialiser variables (eviter hacks par URL) |
|
| 111 | - // |
|
| 112 | - |
|
| 113 | - $connect_login = ''; |
|
| 114 | - $id_auteur = NULL; |
|
| 115 | - $auth_can_disconnect = false; |
|
| 116 | - |
|
| 117 | - // |
|
| 118 | - // Recuperer les donnees d'identification |
|
| 119 | - // |
|
| 120 | - |
|
| 121 | - // Session valide en cours ? |
|
| 122 | - if (isset($_COOKIE['spip_session'])) { |
|
| 123 | - $session = charger_fonction('session', 'inc'); |
|
| 124 | - if ($id_auteur = $session() |
|
| 125 | - OR $id_auteur===0 // reprise sur restauration |
|
| 126 | - ) { |
|
| 127 | - $auth_can_disconnect = true; |
|
| 128 | - $connect_login = $GLOBALS['visiteur_session']['login']; |
|
| 129 | - } else unset($_COOKIE['spip_session']); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Essayer auth http si significatif |
|
| 133 | - // (ignorer les login d'intranet independants de spip) |
|
| 134 | - if (!$ignore_auth_http) { |
|
| 135 | - if ( |
|
| 136 | - (isset($_SERVER['PHP_AUTH_USER']) AND isset($_SERVER['PHP_AUTH_PW']) |
|
| 137 | - AND $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 138 | - OR |
|
| 139 | - // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 140 | - // est indisponible mais tentons quand meme pour |
|
| 141 | - // autocreation via LDAP |
|
| 142 | - (isset($_SERVER['REMOTE_USER']) |
|
| 143 | - AND $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 144 | - ) { |
|
| 145 | - if (!$id_auteur) { |
|
| 146 | - $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 147 | - $auth_can_disconnect = true; |
|
| 148 | - $GLOBALS['visiteur_session'] = $r; |
|
| 149 | - $connect_login = $GLOBALS['visiteur_session']['login']; |
|
| 150 | - $id_auteur = $r['id_auteur']; |
|
| 151 | - } else { |
|
| 152 | - // cas de la session en plus de PHP_AUTH |
|
| 153 | - /* if ($id_auteur != $r['id_auteur']){ |
|
| 106 | + global $auth_can_disconnect, $ignore_auth_http, $ignore_remote_user; |
|
| 107 | + global $connect_login ; |
|
| 108 | + |
|
| 109 | + // |
|
| 110 | + // Initialiser variables (eviter hacks par URL) |
|
| 111 | + // |
|
| 112 | + |
|
| 113 | + $connect_login = ''; |
|
| 114 | + $id_auteur = NULL; |
|
| 115 | + $auth_can_disconnect = false; |
|
| 116 | + |
|
| 117 | + // |
|
| 118 | + // Recuperer les donnees d'identification |
|
| 119 | + // |
|
| 120 | + |
|
| 121 | + // Session valide en cours ? |
|
| 122 | + if (isset($_COOKIE['spip_session'])) { |
|
| 123 | + $session = charger_fonction('session', 'inc'); |
|
| 124 | + if ($id_auteur = $session() |
|
| 125 | + OR $id_auteur===0 // reprise sur restauration |
|
| 126 | + ) { |
|
| 127 | + $auth_can_disconnect = true; |
|
| 128 | + $connect_login = $GLOBALS['visiteur_session']['login']; |
|
| 129 | + } else unset($_COOKIE['spip_session']); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Essayer auth http si significatif |
|
| 133 | + // (ignorer les login d'intranet independants de spip) |
|
| 134 | + if (!$ignore_auth_http) { |
|
| 135 | + if ( |
|
| 136 | + (isset($_SERVER['PHP_AUTH_USER']) AND isset($_SERVER['PHP_AUTH_PW']) |
|
| 137 | + AND $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 138 | + OR |
|
| 139 | + // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 140 | + // est indisponible mais tentons quand meme pour |
|
| 141 | + // autocreation via LDAP |
|
| 142 | + (isset($_SERVER['REMOTE_USER']) |
|
| 143 | + AND $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 144 | + ) { |
|
| 145 | + if (!$id_auteur) { |
|
| 146 | + $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 147 | + $auth_can_disconnect = true; |
|
| 148 | + $GLOBALS['visiteur_session'] = $r; |
|
| 149 | + $connect_login = $GLOBALS['visiteur_session']['login']; |
|
| 150 | + $id_auteur = $r['id_auteur']; |
|
| 151 | + } else { |
|
| 152 | + // cas de la session en plus de PHP_AUTH |
|
| 153 | + /* if ($id_auteur != $r['id_auteur']){ |
|
| 154 | 154 | spip_log("vol de session $id_auteur" . join(', ', $r)); |
| 155 | 155 | unset($_COOKIE['spip_session']); |
| 156 | 156 | $id_auteur = ''; |
| 157 | 157 | } */ |
| 158 | - } |
|
| 159 | - } |
|
| 160 | - // Authentification .htaccess old style, car .htaccess semble |
|
| 161 | - // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 162 | - else if (isset($_SERVER['REMOTE_USER'])) |
|
| 163 | - $connect_login = $_SERVER['REMOTE_USER']; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $where = (is_numeric($id_auteur) |
|
| 167 | - /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 168 | - ) ? |
|
| 169 | - "id_auteur=$id_auteur" : |
|
| 170 | - (!strlen($connect_login) ? '' : "login=" . sql_quote($connect_login,'','text')); |
|
| 171 | - |
|
| 172 | - if (!$where) return ''; |
|
| 173 | - |
|
| 174 | - // Trouver les autres infos dans la table auteurs. |
|
| 175 | - // le champ 'quand' est utilise par l'agenda |
|
| 176 | - |
|
| 177 | - return sql_fetsel("*, en_ligne AS quand", "spip_auteurs", "$where AND statut!='5poubelle'"); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + // Authentification .htaccess old style, car .htaccess semble |
|
| 161 | + // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 162 | + else if (isset($_SERVER['REMOTE_USER'])) |
|
| 163 | + $connect_login = $_SERVER['REMOTE_USER']; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $where = (is_numeric($id_auteur) |
|
| 167 | + /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 168 | + ) ? |
|
| 169 | + "id_auteur=$id_auteur" : |
|
| 170 | + (!strlen($connect_login) ? '' : "login=" . sql_quote($connect_login,'','text')); |
|
| 171 | + |
|
| 172 | + if (!$where) return ''; |
|
| 173 | + |
|
| 174 | + // Trouver les autres infos dans la table auteurs. |
|
| 175 | + // le champ 'quand' est utilise par l'agenda |
|
| 176 | + |
|
| 177 | + return sql_fetsel("*, en_ligne AS quand", "spip_auteurs", "$where AND statut!='5poubelle'"); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,73 +190,73 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | function auth_init_droits($row) |
| 192 | 192 | { |
| 193 | - global $connect_statut, $connect_toutes_rubriques, $connect_id_rubrique, $connect_login, $connect_id_auteur; |
|
| 194 | - |
|
| 195 | - if ($row['statut']=='nouveau'){ |
|
| 196 | - include_spip('action/inscrire_auteur'); |
|
| 197 | - $row = confirmer_statut_inscription($row); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $connect_id_auteur = $row['id_auteur']; |
|
| 201 | - $connect_login = $row['login']; |
|
| 202 | - $connect_statut = $row['statut']; |
|
| 203 | - |
|
| 204 | - $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 205 | - |
|
| 206 | - // au cas ou : ne pas memoriser les champs sensibles |
|
| 207 | - unset($GLOBALS['visiteur_session']['pass']); |
|
| 208 | - unset($GLOBALS['visiteur_session']['htpass']); |
|
| 209 | - unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 210 | - unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 211 | - |
|
| 212 | - // creer la session au besoin |
|
| 213 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 214 | - $session = charger_fonction('session', 'inc'); |
|
| 215 | - $spip_session = $session($row); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 219 | - // car utilisees au retour par auth_loger() |
|
| 220 | - $r = @unserialize($row['prefs']); |
|
| 221 | - $GLOBALS['visiteur_session']['prefs'] = ($r ? $r : array()); |
|
| 222 | - // si prefs pas definies, les definir par defaut |
|
| 223 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])){ |
|
| 224 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = 1; |
|
| 225 | - $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 226 | - $GLOBALS['visiteur_session']['prefs']["display_navigation"] = "navigation_avec_icones"; |
|
| 227 | - $GLOBALS['visiteur_session']['prefs']["display_outils"] = "oui"; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $GLOBALS['visiteur_session'] = pipeline('preparer_visiteur_session',array('args'=>array('row'=>$row),'data'=>$GLOBALS['visiteur_session'])); |
|
| 231 | - |
|
| 232 | - // Etablir les droits selon le codage attendu |
|
| 233 | - // dans ecrire/index.php ecrire/prive.php |
|
| 234 | - |
|
| 235 | - // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 236 | - // A noter : le premier appel a autoriser() a le bon gout |
|
| 237 | - // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 238 | - // qui ne figure pas dans le fichier de session |
|
| 239 | - include_spip('inc/autoriser'); |
|
| 240 | - |
|
| 241 | - if (!autoriser('ecrire')) |
|
| 242 | - return $row; |
|
| 243 | - |
|
| 244 | - // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 245 | - |
|
| 246 | - auth_trace($row); |
|
| 247 | - |
|
| 248 | - // Administrateurs |
|
| 249 | - if (in_array($connect_statut, explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 250 | - if (is_array($GLOBALS['visiteur_session']['restreint'])) { |
|
| 251 | - $connect_id_rubrique = $GLOBALS['visiteur_session']['restreint']; |
|
| 252 | - } |
|
| 253 | - if ($connect_statut == '0minirezo') { |
|
| 254 | - $connect_toutes_rubriques = !$connect_id_rubrique; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 258 | - |
|
| 259 | - return ''; // i.e. pas de pb. |
|
| 193 | + global $connect_statut, $connect_toutes_rubriques, $connect_id_rubrique, $connect_login, $connect_id_auteur; |
|
| 194 | + |
|
| 195 | + if ($row['statut']=='nouveau'){ |
|
| 196 | + include_spip('action/inscrire_auteur'); |
|
| 197 | + $row = confirmer_statut_inscription($row); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $connect_id_auteur = $row['id_auteur']; |
|
| 201 | + $connect_login = $row['login']; |
|
| 202 | + $connect_statut = $row['statut']; |
|
| 203 | + |
|
| 204 | + $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 205 | + |
|
| 206 | + // au cas ou : ne pas memoriser les champs sensibles |
|
| 207 | + unset($GLOBALS['visiteur_session']['pass']); |
|
| 208 | + unset($GLOBALS['visiteur_session']['htpass']); |
|
| 209 | + unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 210 | + unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 211 | + |
|
| 212 | + // creer la session au besoin |
|
| 213 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 214 | + $session = charger_fonction('session', 'inc'); |
|
| 215 | + $spip_session = $session($row); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 219 | + // car utilisees au retour par auth_loger() |
|
| 220 | + $r = @unserialize($row['prefs']); |
|
| 221 | + $GLOBALS['visiteur_session']['prefs'] = ($r ? $r : array()); |
|
| 222 | + // si prefs pas definies, les definir par defaut |
|
| 223 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])){ |
|
| 224 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = 1; |
|
| 225 | + $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 226 | + $GLOBALS['visiteur_session']['prefs']["display_navigation"] = "navigation_avec_icones"; |
|
| 227 | + $GLOBALS['visiteur_session']['prefs']["display_outils"] = "oui"; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $GLOBALS['visiteur_session'] = pipeline('preparer_visiteur_session',array('args'=>array('row'=>$row),'data'=>$GLOBALS['visiteur_session'])); |
|
| 231 | + |
|
| 232 | + // Etablir les droits selon le codage attendu |
|
| 233 | + // dans ecrire/index.php ecrire/prive.php |
|
| 234 | + |
|
| 235 | + // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 236 | + // A noter : le premier appel a autoriser() a le bon gout |
|
| 237 | + // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 238 | + // qui ne figure pas dans le fichier de session |
|
| 239 | + include_spip('inc/autoriser'); |
|
| 240 | + |
|
| 241 | + if (!autoriser('ecrire')) |
|
| 242 | + return $row; |
|
| 243 | + |
|
| 244 | + // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 245 | + |
|
| 246 | + auth_trace($row); |
|
| 247 | + |
|
| 248 | + // Administrateurs |
|
| 249 | + if (in_array($connect_statut, explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 250 | + if (is_array($GLOBALS['visiteur_session']['restreint'])) { |
|
| 251 | + $connect_id_rubrique = $GLOBALS['visiteur_session']['restreint']; |
|
| 252 | + } |
|
| 253 | + if ($connect_statut == '0minirezo') { |
|
| 254 | + $connect_toutes_rubriques = !$connect_id_rubrique; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 258 | + |
|
| 259 | + return ''; // i.e. pas de pb. |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -266,21 +266,21 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | function auth_a_loger() |
| 268 | 268 | { |
| 269 | - $redirect = generer_url_public('login', |
|
| 270 | - "url=" . rawurlencode(self('&',true)), '&'); |
|
| 271 | - |
|
| 272 | - // un echec au "bonjour" (login initial) quand le statut est |
|
| 273 | - // inconnu signale sans doute un probleme de cookies |
|
| 274 | - if (isset($_GET['bonjour'])) |
|
| 275 | - $redirect = parametre_url($redirect, |
|
| 276 | - 'var_erreur', |
|
| 277 | - (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 278 | - ? 'cookie' |
|
| 279 | - : 'statut' |
|
| 280 | - ), |
|
| 281 | - '&' |
|
| 282 | - ); |
|
| 283 | - return $redirect; |
|
| 269 | + $redirect = generer_url_public('login', |
|
| 270 | + "url=" . rawurlencode(self('&',true)), '&'); |
|
| 271 | + |
|
| 272 | + // un echec au "bonjour" (login initial) quand le statut est |
|
| 273 | + // inconnu signale sans doute un probleme de cookies |
|
| 274 | + if (isset($_GET['bonjour'])) |
|
| 275 | + $redirect = parametre_url($redirect, |
|
| 276 | + 'var_erreur', |
|
| 277 | + (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 278 | + ? 'cookie' |
|
| 279 | + : 'statut' |
|
| 280 | + ), |
|
| 281 | + '&' |
|
| 282 | + ); |
|
| 283 | + return $redirect; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | function auth_trace($row, $date=null) |
| 294 | 294 | { |
| 295 | - // Indiquer la connexion. A la minute pres ca suffit. |
|
| 296 | - if (!is_numeric($connect_quand = $row['quand'])) |
|
| 297 | - $connect_quand = strtotime($connect_quand); |
|
| 295 | + // Indiquer la connexion. A la minute pres ca suffit. |
|
| 296 | + if (!is_numeric($connect_quand = $row['quand'])) |
|
| 297 | + $connect_quand = strtotime($connect_quand); |
|
| 298 | 298 | |
| 299 | - if (is_null($date)) |
|
| 300 | - $date = date('Y-m-d H:i:s'); |
|
| 299 | + if (is_null($date)) |
|
| 300 | + $date = date('Y-m-d H:i:s'); |
|
| 301 | 301 | |
| 302 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 303 | - sql_updateq("spip_auteurs", array("en_ligne" => $date), "id_auteur=" .$row['id_auteur']); |
|
| 304 | - $row['en_ligne'] = $date; |
|
| 305 | - } |
|
| 302 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 303 | + sql_updateq("spip_auteurs", array("en_ligne" => $date), "id_auteur=" .$row['id_auteur']); |
|
| 304 | + $row['en_ligne'] = $date; |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - pipeline('trig_auth_trace',array('args'=>array('row'=>$row,'date'=>$date))); |
|
| 307 | + pipeline('trig_auth_trace',array('args'=>array('row'=>$row,'date'=>$date))); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | |
@@ -320,23 +320,23 @@ discard block |
||
| 320 | 320 | * @return mixed |
| 321 | 321 | */ |
| 322 | 322 | function auth_administrer($fonction,$args,$defaut=false){ |
| 323 | - $auth_methode = array_shift($args); |
|
| 324 | - $auth_methode = $auth_methode ? $auth_methode : 'spip'; // valeur par defaut au cas ou |
|
| 325 | - if ($auth = charger_fonction($auth_methode,'auth',true) |
|
| 326 | - AND function_exists($f="auth_{$auth_methode}_$fonction") |
|
| 327 | - ) |
|
| 328 | - $res = call_user_func_array($f, $args); |
|
| 329 | - else |
|
| 330 | - $res = $defaut; |
|
| 331 | - $res = pipeline('auth_administrer',array( |
|
| 332 | - 'args' => array( |
|
| 333 | - 'fonction' => $fonction, |
|
| 334 | - 'methode' => $auth_methode, |
|
| 335 | - 'args' => $args |
|
| 336 | - ), |
|
| 337 | - 'data' => $res |
|
| 338 | - )); |
|
| 339 | - return $res; |
|
| 323 | + $auth_methode = array_shift($args); |
|
| 324 | + $auth_methode = $auth_methode ? $auth_methode : 'spip'; // valeur par defaut au cas ou |
|
| 325 | + if ($auth = charger_fonction($auth_methode,'auth',true) |
|
| 326 | + AND function_exists($f="auth_{$auth_methode}_$fonction") |
|
| 327 | + ) |
|
| 328 | + $res = call_user_func_array($f, $args); |
|
| 329 | + else |
|
| 330 | + $res = $defaut; |
|
| 331 | + $res = pipeline('auth_administrer',array( |
|
| 332 | + 'args' => array( |
|
| 333 | + 'fonction' => $fonction, |
|
| 334 | + 'methode' => $auth_methode, |
|
| 335 | + 'args' => $args |
|
| 336 | + ), |
|
| 337 | + 'data' => $res |
|
| 338 | + )); |
|
| 339 | + return $res; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -346,9 +346,9 @@ discard block |
||
| 346 | 346 | * @return array |
| 347 | 347 | */ |
| 348 | 348 | function auth_formulaire_login($flux){ |
| 349 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) |
|
| 350 | - $flux = auth_administrer('formulaire_login',array($methode,$flux),$flux); |
|
| 351 | - return $flux; |
|
| 349 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) |
|
| 350 | + $flux = auth_administrer('formulaire_login',array($methode,$flux),$flux); |
|
| 351 | + return $flux; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -363,19 +363,19 @@ discard block |
||
| 363 | 363 | * @return string/bool |
| 364 | 364 | */ |
| 365 | 365 | function auth_retrouver_login($login, $serveur=''){ |
| 366 | - if (!spip_connect($serveur)) { |
|
| 367 | - include_spip('inc/minipres'); |
|
| 368 | - echo minipres(_T('info_travaux_titre'), |
|
| 369 | - _T('titre_probleme_technique')); |
|
| 370 | - exit; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 374 | - if ($auteur = auth_administrer('retrouver_login',array($methode, $login, $serveur))) { |
|
| 375 | - return $auteur; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - return false; |
|
| 366 | + if (!spip_connect($serveur)) { |
|
| 367 | + include_spip('inc/minipres'); |
|
| 368 | + echo minipres(_T('info_travaux_titre'), |
|
| 369 | + _T('titre_probleme_technique')); |
|
| 370 | + exit; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 374 | + if ($auteur = auth_administrer('retrouver_login',array($methode, $login, $serveur))) { |
|
| 375 | + return $auteur; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + return false; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -391,28 +391,28 @@ discard block |
||
| 391 | 391 | * @return array |
| 392 | 392 | */ |
| 393 | 393 | function auth_informer_login($login, $serveur=''){ |
| 394 | - if (!$login |
|
| 395 | - OR !$login = auth_retrouver_login($login, $serveur) |
|
| 396 | - OR !$row = sql_fetsel('*','spip_auteurs','login='.sql_quote($login,$serveur,'text'),'','','','',$serveur) |
|
| 397 | - ) |
|
| 398 | - return array(); |
|
| 399 | - |
|
| 400 | - $prefs = unserialize($row['prefs']); |
|
| 401 | - $infos = array( |
|
| 402 | - 'id_auteur'=>$row['id_auteur'], |
|
| 403 | - 'login'=>$row['login'], |
|
| 404 | - 'cnx' => ($prefs['cnx'] == 'perma') ? '1' : '0', |
|
| 405 | - 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - // desactiver le hash md5 si pas auteur spip ? |
|
| 409 | - if ($row['source']!=='spip'){ |
|
| 410 | - $row['alea_actuel']= ''; |
|
| 411 | - $row['alea_futur']= ''; |
|
| 412 | - } |
|
| 413 | - verifier_visiteur(); |
|
| 414 | - |
|
| 415 | - return auth_administrer('informer_login',array($row['source'],$infos, $row, $serveur),$infos); |
|
| 394 | + if (!$login |
|
| 395 | + OR !$login = auth_retrouver_login($login, $serveur) |
|
| 396 | + OR !$row = sql_fetsel('*','spip_auteurs','login='.sql_quote($login,$serveur,'text'),'','','','',$serveur) |
|
| 397 | + ) |
|
| 398 | + return array(); |
|
| 399 | + |
|
| 400 | + $prefs = unserialize($row['prefs']); |
|
| 401 | + $infos = array( |
|
| 402 | + 'id_auteur'=>$row['id_auteur'], |
|
| 403 | + 'login'=>$row['login'], |
|
| 404 | + 'cnx' => ($prefs['cnx'] == 'perma') ? '1' : '0', |
|
| 405 | + 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + // desactiver le hash md5 si pas auteur spip ? |
|
| 409 | + if ($row['source']!=='spip'){ |
|
| 410 | + $row['alea_actuel']= ''; |
|
| 411 | + $row['alea_futur']= ''; |
|
| 412 | + } |
|
| 413 | + verifier_visiteur(); |
|
| 414 | + |
|
| 415 | + return auth_administrer('informer_login',array($row['source'],$infos, $row, $serveur),$infos); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -426,20 +426,20 @@ discard block |
||
| 426 | 426 | * @return mixed |
| 427 | 427 | */ |
| 428 | 428 | function auth_identifier_login($login, $password, $serveur=''){ |
| 429 | - $erreur = ""; |
|
| 430 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 431 | - if ($auth = charger_fonction($methode, 'auth',true)){ |
|
| 432 | - $auteur = $auth($login, $password, $serveur); |
|
| 433 | - if (is_array($auteur) AND count($auteur)) { |
|
| 434 | - spip_log("connexion de $login par methode $methode"); |
|
| 435 | - $auteur['auth'] = $methode; |
|
| 436 | - return $auteur; |
|
| 437 | - } |
|
| 438 | - elseif (is_string($auteur)) |
|
| 439 | - $erreur .= "$auteur "; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - return $erreur; |
|
| 429 | + $erreur = ""; |
|
| 430 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 431 | + if ($auth = charger_fonction($methode, 'auth',true)){ |
|
| 432 | + $auteur = $auth($login, $password, $serveur); |
|
| 433 | + if (is_array($auteur) AND count($auteur)) { |
|
| 434 | + spip_log("connexion de $login par methode $methode"); |
|
| 435 | + $auteur['auth'] = $methode; |
|
| 436 | + return $auteur; |
|
| 437 | + } |
|
| 438 | + elseif (is_string($auteur)) |
|
| 439 | + $erreur .= "$auteur "; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + return $erreur; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -453,14 +453,14 @@ discard block |
||
| 453 | 453 | * @return string |
| 454 | 454 | */ |
| 455 | 455 | function auth_url_retour_login($auth_methode, $login, $redirect='', $serveur=''){ |
| 456 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 457 | - return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 456 | + $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 457 | + return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | function auth_terminer_identifier_login($auth_methode, $login, $serveur=''){ |
| 461 | - $args = func_get_args(); |
|
| 462 | - $auteur = auth_administrer('terminer_identifier_login',$args); |
|
| 463 | - return $auteur; |
|
| 461 | + $args = func_get_args(); |
|
| 462 | + $auteur = auth_administrer('terminer_identifier_login',$args); |
|
| 463 | + return $auteur; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -470,41 +470,41 @@ discard block |
||
| 470 | 470 | * @return bool |
| 471 | 471 | */ |
| 472 | 472 | function auth_loger($auteur){ |
| 473 | - if (!is_array($auteur) OR !count($auteur)) |
|
| 474 | - return false; |
|
| 475 | - |
|
| 476 | - // initialiser et poser le cookie de session |
|
| 477 | - unset($_COOKIE['spip_session']); |
|
| 478 | - auth_init_droits($auteur); |
|
| 479 | - |
|
| 480 | - // initialiser les prefs |
|
| 481 | - $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 482 | - $p['cnx'] = ($auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 483 | - |
|
| 484 | - sql_updateq('spip_auteurs', |
|
| 485 | - array('prefs' => serialize($p)), |
|
| 486 | - "id_auteur=" . $auteur['id_auteur']); |
|
| 487 | - |
|
| 488 | - // Si on est admin, poser le cookie de correspondance |
|
| 489 | - include_spip('inc/cookie'); |
|
| 490 | - if ($auteur['statut'] == '0minirezo') { |
|
| 491 | - spip_setcookie('spip_admin', '@'.$auteur['login'], |
|
| 492 | - time() + 7 * 24 * 3600); |
|
| 493 | - } |
|
| 494 | - // sinon le supprimer ... |
|
| 495 | - else { |
|
| 496 | - spip_setcookie('spip_admin', '',1); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 500 | - verifier_visiteur(); |
|
| 501 | - return true; |
|
| 473 | + if (!is_array($auteur) OR !count($auteur)) |
|
| 474 | + return false; |
|
| 475 | + |
|
| 476 | + // initialiser et poser le cookie de session |
|
| 477 | + unset($_COOKIE['spip_session']); |
|
| 478 | + auth_init_droits($auteur); |
|
| 479 | + |
|
| 480 | + // initialiser les prefs |
|
| 481 | + $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 482 | + $p['cnx'] = ($auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 483 | + |
|
| 484 | + sql_updateq('spip_auteurs', |
|
| 485 | + array('prefs' => serialize($p)), |
|
| 486 | + "id_auteur=" . $auteur['id_auteur']); |
|
| 487 | + |
|
| 488 | + // Si on est admin, poser le cookie de correspondance |
|
| 489 | + include_spip('inc/cookie'); |
|
| 490 | + if ($auteur['statut'] == '0minirezo') { |
|
| 491 | + spip_setcookie('spip_admin', '@'.$auteur['login'], |
|
| 492 | + time() + 7 * 24 * 3600); |
|
| 493 | + } |
|
| 494 | + // sinon le supprimer ... |
|
| 495 | + else { |
|
| 496 | + spip_setcookie('spip_admin', '',1); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 500 | + verifier_visiteur(); |
|
| 501 | + return true; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | |
| 505 | 505 | function auth_deloger(){ |
| 506 | - $logout = charger_fonction('logout','action'); |
|
| 507 | - $logout(); |
|
| 506 | + $logout = charger_fonction('logout','action'); |
|
| 507 | + $logout(); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -516,8 +516,8 @@ discard block |
||
| 516 | 516 | * @return bool |
| 517 | 517 | */ |
| 518 | 518 | function auth_autoriser_modifier_login($auth_methode, $serveur=''){ |
| 519 | - $args = func_get_args(); |
|
| 520 | - return auth_administrer('autoriser_modifier_login',$args); |
|
| 519 | + $args = func_get_args(); |
|
| 520 | + return auth_administrer('autoriser_modifier_login',$args); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -532,8 +532,8 @@ discard block |
||
| 532 | 532 | * message d'erreur ou chaine vide si pas d'erreur |
| 533 | 533 | */ |
| 534 | 534 | function auth_verifier_login($auth_methode, $new_login, $id_auteur=0, $serveur=''){ |
| 535 | - $args = func_get_args(); |
|
| 536 | - return auth_administrer('verifier_login',$args,''); |
|
| 535 | + $args = func_get_args(); |
|
| 536 | + return auth_administrer('verifier_login',$args,''); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | /** |
@@ -546,8 +546,8 @@ discard block |
||
| 546 | 546 | * @return bool |
| 547 | 547 | */ |
| 548 | 548 | function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur=''){ |
| 549 | - $args = func_get_args(); |
|
| 550 | - return auth_administrer('modifier_login',$args); |
|
| 549 | + $args = func_get_args(); |
|
| 550 | + return auth_administrer('modifier_login',$args); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -560,8 +560,8 @@ discard block |
||
| 560 | 560 | * succes ou echec |
| 561 | 561 | */ |
| 562 | 562 | function auth_autoriser_modifier_pass($auth_methode, $serveur=''){ |
| 563 | - $args = func_get_args(); |
|
| 564 | - return auth_administrer('autoriser_modifier_pass',$args); |
|
| 563 | + $args = func_get_args(); |
|
| 564 | + return auth_administrer('autoriser_modifier_pass',$args); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -577,8 +577,8 @@ discard block |
||
| 577 | 577 | * message d'erreur ou chaine vide si pas d'erreur |
| 578 | 578 | */ |
| 579 | 579 | function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur=0, $serveur=''){ |
| 580 | - $args = func_get_args(); |
|
| 581 | - return auth_administrer('verifier_pass',$args,''); |
|
| 580 | + $args = func_get_args(); |
|
| 581 | + return auth_administrer('verifier_pass',$args,''); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -594,8 +594,8 @@ discard block |
||
| 594 | 594 | * succes ou echec |
| 595 | 595 | */ |
| 596 | 596 | function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur=''){ |
| 597 | - $args = func_get_args(); |
|
| 598 | - return auth_administrer('modifier_pass',$args); |
|
| 597 | + $args = func_get_args(); |
|
| 598 | + return auth_administrer('modifier_pass',$args); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -611,18 +611,18 @@ discard block |
||
| 611 | 611 | * @return void |
| 612 | 612 | */ |
| 613 | 613 | function auth_synchroniser_distant($auth_methode=true, $id_auteur=0, $champs=array(), $options = array(), $serveur=''){ |
| 614 | - $args = func_get_args(); |
|
| 615 | - if ($auth_methode===true OR (isset($options['all']) AND $options['all']==true)){ |
|
| 616 | - $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 617 | - $args = array(true, $id_auteur, $champs, $options, $serveur); |
|
| 618 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 619 | - array_shift($args); |
|
| 620 | - array_unshift($args,$methode); |
|
| 621 | - auth_administrer('synchroniser_distant',$args); |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - else |
|
| 625 | - auth_administrer('synchroniser_distant',$args); |
|
| 614 | + $args = func_get_args(); |
|
| 615 | + if ($auth_methode===true OR (isset($options['all']) AND $options['all']==true)){ |
|
| 616 | + $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 617 | + $args = array(true, $id_auteur, $champs, $options, $serveur); |
|
| 618 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 619 | + array_shift($args); |
|
| 620 | + array_unshift($args,$methode); |
|
| 621 | + auth_administrer('synchroniser_distant',$args); |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + else |
|
| 625 | + auth_administrer('synchroniser_distant',$args); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | |
@@ -635,27 +635,27 @@ discard block |
||
| 635 | 635 | */ |
| 636 | 636 | function lire_php_auth($login, $pw, $serveur=''){ |
| 637 | 637 | |
| 638 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login,$serveur,'text'),'','','','',$serveur); |
|
| 639 | - |
|
| 640 | - if (!$row) { |
|
| 641 | - if (spip_connect_ldap($serveur) |
|
| 642 | - AND $auth_ldap = charger_fonction('ldap', 'auth', true)) |
|
| 643 | - return $auth_ldap($login, $pw, $serveur, true); |
|
| 644 | - return false; |
|
| 645 | - } |
|
| 646 | - // su pas de source definie |
|
| 647 | - // ou auth/xxx introuvable, utiliser 'spip' |
|
| 648 | - if (!$auth_methode = $row['source'] |
|
| 649 | - OR !$auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 650 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 651 | - |
|
| 652 | - $auteur=''; |
|
| 653 | - if ($auth) |
|
| 654 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 655 | - // verifier que ce n'est pas un message d'erreur |
|
| 656 | - if (is_array($auteur) AND count($auteur)) |
|
| 657 | - return $auteur; |
|
| 658 | - return false; |
|
| 638 | + $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login,$serveur,'text'),'','','','',$serveur); |
|
| 639 | + |
|
| 640 | + if (!$row) { |
|
| 641 | + if (spip_connect_ldap($serveur) |
|
| 642 | + AND $auth_ldap = charger_fonction('ldap', 'auth', true)) |
|
| 643 | + return $auth_ldap($login, $pw, $serveur, true); |
|
| 644 | + return false; |
|
| 645 | + } |
|
| 646 | + // su pas de source definie |
|
| 647 | + // ou auth/xxx introuvable, utiliser 'spip' |
|
| 648 | + if (!$auth_methode = $row['source'] |
|
| 649 | + OR !$auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 650 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 651 | + |
|
| 652 | + $auteur=''; |
|
| 653 | + if ($auth) |
|
| 654 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 655 | + // verifier que ce n'est pas un message d'erreur |
|
| 656 | + if (is_array($auteur) AND count($auteur)) |
|
| 657 | + return $auteur; |
|
| 658 | + return false; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -669,21 +669,21 @@ discard block |
||
| 669 | 669 | * @param string $lien |
| 670 | 670 | */ |
| 671 | 671 | function ask_php_auth($pb, $raison, $retour='', $url='', $re='', $lien='') { |
| 672 | - @Header("WWW-Authenticate: Basic realm=\"espace prive\""); |
|
| 673 | - @Header("HTTP/1.0 401 Unauthorized"); |
|
| 674 | - $corps = ""; |
|
| 675 | - $public = generer_url_public(); |
|
| 676 | - $ecrire = generer_url_ecrire(); |
|
| 677 | - $retour = $retour?$retour:_T('icone_retour'); |
|
| 678 | - $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 679 | - if ($url) { |
|
| 680 | - $corps .= "[<a href='" . generer_url_action('cookie',"essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - if ($lien) |
|
| 684 | - $corps .= " [<a href='$ecrire'>"._T('login_espace_prive')."</a>]"; |
|
| 685 | - include_spip('inc/minipres'); |
|
| 686 | - echo minipres($pb,$corps); |
|
| 687 | - exit; |
|
| 672 | + @Header("WWW-Authenticate: Basic realm=\"espace prive\""); |
|
| 673 | + @Header("HTTP/1.0 401 Unauthorized"); |
|
| 674 | + $corps = ""; |
|
| 675 | + $public = generer_url_public(); |
|
| 676 | + $ecrire = generer_url_ecrire(); |
|
| 677 | + $retour = $retour?$retour:_T('icone_retour'); |
|
| 678 | + $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 679 | + if ($url) { |
|
| 680 | + $corps .= "[<a href='" . generer_url_action('cookie',"essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + if ($lien) |
|
| 684 | + $corps .= " [<a href='$ecrire'>"._T('login_espace_prive')."</a>]"; |
|
| 685 | + include_spip('inc/minipres'); |
|
| 686 | + echo minipres($pb,$corps); |
|
| 687 | + exit; |
|
| 688 | 688 | } |
| 689 | 689 | ?> |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function inc_auth_dist() { |
| 34 | 34 | |
| 35 | - global $connect_login ; |
|
| 35 | + global $connect_login; |
|
| 36 | 36 | |
| 37 | 37 | $row = auth_mode(); |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | 'site' => generer_url_public('', "action=logout&logout=prive")); |
| 52 | 52 | |
| 53 | 53 | $n = intval(sql_errno()); |
| 54 | - spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 54 | + spip_log("Erreur base de donnees $n ".sql_error()); |
|
| 55 | 55 | return $n ? $n : 1; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | $raison = redirige_formulaire($raison); |
| 76 | 76 | } elseif (is_int($raison)) { |
| 77 | 77 | // erreur SQL a afficher |
| 78 | - $raison = minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'). "<p><tt>".sql_errno()." ".sql_error()."</tt></p>"); |
|
| 78 | + $raison = minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')."<p><tt>".sql_errno()." ".sql_error()."</tt></p>"); |
|
| 79 | 79 | } elseif (@$raison['statut']) { |
| 80 | 80 | // un simple visiteur n'a pas acces a l'espace prive |
| 81 | - spip_log("connexion refusee a " . @$raison['id_auteur']); |
|
| 82 | - $raison = minipres(_T('avis_erreur_connexion'),_T('avis_erreur_visiteur')); |
|
| 81 | + spip_log("connexion refusee a ".@$raison['id_auteur']); |
|
| 82 | + $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 83 | 83 | } else { |
| 84 | 84 | // auteur en fin de droits ... |
| 85 | 85 | $h = $raison['site']; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | function auth_mode() |
| 105 | 105 | { |
| 106 | 106 | global $auth_can_disconnect, $ignore_auth_http, $ignore_remote_user; |
| 107 | - global $connect_login ; |
|
| 107 | + global $connect_login; |
|
| 108 | 108 | |
| 109 | 109 | // |
| 110 | 110 | // Initialiser variables (eviter hacks par URL) |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | if (isset($_COOKIE['spip_session'])) { |
| 123 | 123 | $session = charger_fonction('session', 'inc'); |
| 124 | 124 | if ($id_auteur = $session() |
| 125 | - OR $id_auteur===0 // reprise sur restauration |
|
| 125 | + OR $id_auteur === 0 // reprise sur restauration |
|
| 126 | 126 | ) { |
| 127 | 127 | $auth_can_disconnect = true; |
| 128 | 128 | $connect_login = $GLOBALS['visiteur_session']['login']; |
@@ -166,8 +166,7 @@ discard block |
||
| 166 | 166 | $where = (is_numeric($id_auteur) |
| 167 | 167 | /*AND $id_auteur>0*/ // reprise lors des restaurations |
| 168 | 168 | ) ? |
| 169 | - "id_auteur=$id_auteur" : |
|
| 170 | - (!strlen($connect_login) ? '' : "login=" . sql_quote($connect_login,'','text')); |
|
| 169 | + "id_auteur=$id_auteur" : (!strlen($connect_login) ? '' : "login=".sql_quote($connect_login, '', 'text')); |
|
| 171 | 170 | |
| 172 | 171 | if (!$where) return ''; |
| 173 | 172 | |
@@ -192,7 +191,7 @@ discard block |
||
| 192 | 191 | { |
| 193 | 192 | global $connect_statut, $connect_toutes_rubriques, $connect_id_rubrique, $connect_login, $connect_id_auteur; |
| 194 | 193 | |
| 195 | - if ($row['statut']=='nouveau'){ |
|
| 194 | + if ($row['statut'] == 'nouveau') { |
|
| 196 | 195 | include_spip('action/inscrire_auteur'); |
| 197 | 196 | $row = confirmer_statut_inscription($row); |
| 198 | 197 | } |
@@ -201,7 +200,7 @@ discard block |
||
| 201 | 200 | $connect_login = $row['login']; |
| 202 | 201 | $connect_statut = $row['statut']; |
| 203 | 202 | |
| 204 | - $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 203 | + $GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row); |
|
| 205 | 204 | |
| 206 | 205 | // au cas ou : ne pas memoriser les champs sensibles |
| 207 | 206 | unset($GLOBALS['visiteur_session']['pass']); |
@@ -220,14 +219,14 @@ discard block |
||
| 220 | 219 | $r = @unserialize($row['prefs']); |
| 221 | 220 | $GLOBALS['visiteur_session']['prefs'] = ($r ? $r : array()); |
| 222 | 221 | // si prefs pas definies, les definir par defaut |
| 223 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])){ |
|
| 222 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 224 | 223 | $GLOBALS['visiteur_session']['prefs']['couleur'] = 1; |
| 225 | 224 | $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
| 226 | 225 | $GLOBALS['visiteur_session']['prefs']["display_navigation"] = "navigation_avec_icones"; |
| 227 | 226 | $GLOBALS['visiteur_session']['prefs']["display_outils"] = "oui"; |
| 228 | 227 | } |
| 229 | 228 | |
| 230 | - $GLOBALS['visiteur_session'] = pipeline('preparer_visiteur_session',array('args'=>array('row'=>$row),'data'=>$GLOBALS['visiteur_session'])); |
|
| 229 | + $GLOBALS['visiteur_session'] = pipeline('preparer_visiteur_session', array('args'=>array('row'=>$row), 'data'=>$GLOBALS['visiteur_session'])); |
|
| 231 | 230 | |
| 232 | 231 | // Etablir les droits selon le codage attendu |
| 233 | 232 | // dans ecrire/index.php ecrire/prive.php |
@@ -267,7 +266,7 @@ discard block |
||
| 267 | 266 | function auth_a_loger() |
| 268 | 267 | { |
| 269 | 268 | $redirect = generer_url_public('login', |
| 270 | - "url=" . rawurlencode(self('&',true)), '&'); |
|
| 269 | + "url=".rawurlencode(self('&', true)), '&'); |
|
| 271 | 270 | |
| 272 | 271 | // un echec au "bonjour" (login initial) quand le statut est |
| 273 | 272 | // inconnu signale sans doute un probleme de cookies |
@@ -290,7 +289,7 @@ discard block |
||
| 290 | 289 | * @param array $row |
| 291 | 290 | * @param null|string $date |
| 292 | 291 | */ |
| 293 | -function auth_trace($row, $date=null) |
|
| 292 | +function auth_trace($row, $date = null) |
|
| 294 | 293 | { |
| 295 | 294 | // Indiquer la connexion. A la minute pres ca suffit. |
| 296 | 295 | if (!is_numeric($connect_quand = $row['quand'])) |
@@ -299,12 +298,12 @@ discard block |
||
| 299 | 298 | if (is_null($date)) |
| 300 | 299 | $date = date('Y-m-d H:i:s'); |
| 301 | 300 | |
| 302 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 303 | - sql_updateq("spip_auteurs", array("en_ligne" => $date), "id_auteur=" .$row['id_auteur']); |
|
| 301 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 302 | + sql_updateq("spip_auteurs", array("en_ligne" => $date), "id_auteur=".$row['id_auteur']); |
|
| 304 | 303 | $row['en_ligne'] = $date; |
| 305 | 304 | } |
| 306 | 305 | |
| 307 | - pipeline('trig_auth_trace',array('args'=>array('row'=>$row,'date'=>$date))); |
|
| 306 | + pipeline('trig_auth_trace', array('args'=>array('row'=>$row, 'date'=>$date))); |
|
| 308 | 307 | } |
| 309 | 308 | |
| 310 | 309 | |
@@ -319,16 +318,16 @@ discard block |
||
| 319 | 318 | * @param mixed $defaut |
| 320 | 319 | * @return mixed |
| 321 | 320 | */ |
| 322 | -function auth_administrer($fonction,$args,$defaut=false){ |
|
| 321 | +function auth_administrer($fonction, $args, $defaut = false) { |
|
| 323 | 322 | $auth_methode = array_shift($args); |
| 324 | 323 | $auth_methode = $auth_methode ? $auth_methode : 'spip'; // valeur par defaut au cas ou |
| 325 | - if ($auth = charger_fonction($auth_methode,'auth',true) |
|
| 326 | - AND function_exists($f="auth_{$auth_methode}_$fonction") |
|
| 324 | + if ($auth = charger_fonction($auth_methode, 'auth', true) |
|
| 325 | + AND function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 327 | 326 | ) |
| 328 | 327 | $res = call_user_func_array($f, $args); |
| 329 | 328 | else |
| 330 | 329 | $res = $defaut; |
| 331 | - $res = pipeline('auth_administrer',array( |
|
| 330 | + $res = pipeline('auth_administrer', array( |
|
| 332 | 331 | 'args' => array( |
| 333 | 332 | 'fonction' => $fonction, |
| 334 | 333 | 'methode' => $auth_methode, |
@@ -345,9 +344,9 @@ discard block |
||
| 345 | 344 | * @param array $flux |
| 346 | 345 | * @return array |
| 347 | 346 | */ |
| 348 | -function auth_formulaire_login($flux){ |
|
| 347 | +function auth_formulaire_login($flux) { |
|
| 349 | 348 | foreach ($GLOBALS['liste_des_authentifications'] as $methode) |
| 350 | - $flux = auth_administrer('formulaire_login',array($methode,$flux),$flux); |
|
| 349 | + $flux = auth_administrer('formulaire_login', array($methode, $flux), $flux); |
|
| 351 | 350 | return $flux; |
| 352 | 351 | } |
| 353 | 352 | |
@@ -362,7 +361,7 @@ discard block |
||
| 362 | 361 | * @param string $serveur |
| 363 | 362 | * @return string/bool |
| 364 | 363 | */ |
| 365 | -function auth_retrouver_login($login, $serveur=''){ |
|
| 364 | +function auth_retrouver_login($login, $serveur = '') { |
|
| 366 | 365 | if (!spip_connect($serveur)) { |
| 367 | 366 | include_spip('inc/minipres'); |
| 368 | 367 | echo minipres(_T('info_travaux_titre'), |
@@ -371,7 +370,7 @@ discard block |
||
| 371 | 370 | } |
| 372 | 371 | |
| 373 | 372 | foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
| 374 | - if ($auteur = auth_administrer('retrouver_login',array($methode, $login, $serveur))) { |
|
| 373 | + if ($auteur = auth_administrer('retrouver_login', array($methode, $login, $serveur))) { |
|
| 375 | 374 | return $auteur; |
| 376 | 375 | } |
| 377 | 376 | } |
@@ -390,10 +389,10 @@ discard block |
||
| 390 | 389 | * @param string $serveur |
| 391 | 390 | * @return array |
| 392 | 391 | */ |
| 393 | -function auth_informer_login($login, $serveur=''){ |
|
| 392 | +function auth_informer_login($login, $serveur = '') { |
|
| 394 | 393 | if (!$login |
| 395 | 394 | OR !$login = auth_retrouver_login($login, $serveur) |
| 396 | - OR !$row = sql_fetsel('*','spip_auteurs','login='.sql_quote($login,$serveur,'text'),'','','','',$serveur) |
|
| 395 | + OR !$row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 397 | 396 | ) |
| 398 | 397 | return array(); |
| 399 | 398 | |
@@ -406,13 +405,13 @@ discard block |
||
| 406 | 405 | ); |
| 407 | 406 | |
| 408 | 407 | // desactiver le hash md5 si pas auteur spip ? |
| 409 | - if ($row['source']!=='spip'){ |
|
| 410 | - $row['alea_actuel']= ''; |
|
| 411 | - $row['alea_futur']= ''; |
|
| 408 | + if ($row['source'] !== 'spip') { |
|
| 409 | + $row['alea_actuel'] = ''; |
|
| 410 | + $row['alea_futur'] = ''; |
|
| 412 | 411 | } |
| 413 | 412 | verifier_visiteur(); |
| 414 | 413 | |
| 415 | - return auth_administrer('informer_login',array($row['source'],$infos, $row, $serveur),$infos); |
|
| 414 | + return auth_administrer('informer_login', array($row['source'], $infos, $row, $serveur), $infos); |
|
| 416 | 415 | } |
| 417 | 416 | |
| 418 | 417 | |
@@ -425,10 +424,10 @@ discard block |
||
| 425 | 424 | * @param string $serveur |
| 426 | 425 | * @return mixed |
| 427 | 426 | */ |
| 428 | -function auth_identifier_login($login, $password, $serveur=''){ |
|
| 427 | +function auth_identifier_login($login, $password, $serveur = '') { |
|
| 429 | 428 | $erreur = ""; |
| 430 | 429 | foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
| 431 | - if ($auth = charger_fonction($methode, 'auth',true)){ |
|
| 430 | + if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 432 | 431 | $auteur = $auth($login, $password, $serveur); |
| 433 | 432 | if (is_array($auteur) AND count($auteur)) { |
| 434 | 433 | spip_log("connexion de $login par methode $methode"); |
@@ -452,14 +451,14 @@ discard block |
||
| 452 | 451 | * @param string $serveur |
| 453 | 452 | * @return string |
| 454 | 453 | */ |
| 455 | -function auth_url_retour_login($auth_methode, $login, $redirect='', $serveur=''){ |
|
| 456 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 454 | +function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') { |
|
| 455 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 457 | 456 | return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
| 458 | 457 | } |
| 459 | 458 | |
| 460 | -function auth_terminer_identifier_login($auth_methode, $login, $serveur=''){ |
|
| 459 | +function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') { |
|
| 461 | 460 | $args = func_get_args(); |
| 462 | - $auteur = auth_administrer('terminer_identifier_login',$args); |
|
| 461 | + $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 463 | 462 | return $auteur; |
| 464 | 463 | } |
| 465 | 464 | |
@@ -469,7 +468,7 @@ discard block |
||
| 469 | 468 | * @param array $auteur |
| 470 | 469 | * @return bool |
| 471 | 470 | */ |
| 472 | -function auth_loger($auteur){ |
|
| 471 | +function auth_loger($auteur) { |
|
| 473 | 472 | if (!is_array($auteur) OR !count($auteur)) |
| 474 | 473 | return false; |
| 475 | 474 | |
@@ -483,7 +482,7 @@ discard block |
||
| 483 | 482 | |
| 484 | 483 | sql_updateq('spip_auteurs', |
| 485 | 484 | array('prefs' => serialize($p)), |
| 486 | - "id_auteur=" . $auteur['id_auteur']); |
|
| 485 | + "id_auteur=".$auteur['id_auteur']); |
|
| 487 | 486 | |
| 488 | 487 | // Si on est admin, poser le cookie de correspondance |
| 489 | 488 | include_spip('inc/cookie'); |
@@ -493,7 +492,7 @@ discard block |
||
| 493 | 492 | } |
| 494 | 493 | // sinon le supprimer ... |
| 495 | 494 | else { |
| 496 | - spip_setcookie('spip_admin', '',1); |
|
| 495 | + spip_setcookie('spip_admin', '', 1); |
|
| 497 | 496 | } |
| 498 | 497 | |
| 499 | 498 | // bloquer ici le visiteur qui tente d'abuser de ses droits |
@@ -502,8 +501,8 @@ discard block |
||
| 502 | 501 | } |
| 503 | 502 | |
| 504 | 503 | |
| 505 | -function auth_deloger(){ |
|
| 506 | - $logout = charger_fonction('logout','action'); |
|
| 504 | +function auth_deloger() { |
|
| 505 | + $logout = charger_fonction('logout', 'action'); |
|
| 507 | 506 | $logout(); |
| 508 | 507 | } |
| 509 | 508 | |
@@ -515,9 +514,9 @@ discard block |
||
| 515 | 514 | * @param string $serveur |
| 516 | 515 | * @return bool |
| 517 | 516 | */ |
| 518 | -function auth_autoriser_modifier_login($auth_methode, $serveur=''){ |
|
| 517 | +function auth_autoriser_modifier_login($auth_methode, $serveur = '') { |
|
| 519 | 518 | $args = func_get_args(); |
| 520 | - return auth_administrer('autoriser_modifier_login',$args); |
|
| 519 | + return auth_administrer('autoriser_modifier_login', $args); |
|
| 521 | 520 | } |
| 522 | 521 | |
| 523 | 522 | /** |
@@ -531,9 +530,9 @@ discard block |
||
| 531 | 530 | * @return string |
| 532 | 531 | * message d'erreur ou chaine vide si pas d'erreur |
| 533 | 532 | */ |
| 534 | -function auth_verifier_login($auth_methode, $new_login, $id_auteur=0, $serveur=''){ |
|
| 533 | +function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') { |
|
| 535 | 534 | $args = func_get_args(); |
| 536 | - return auth_administrer('verifier_login',$args,''); |
|
| 535 | + return auth_administrer('verifier_login', $args, ''); |
|
| 537 | 536 | } |
| 538 | 537 | |
| 539 | 538 | /** |
@@ -545,9 +544,9 @@ discard block |
||
| 545 | 544 | * @param string $serveur |
| 546 | 545 | * @return bool |
| 547 | 546 | */ |
| 548 | -function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur=''){ |
|
| 547 | +function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') { |
|
| 549 | 548 | $args = func_get_args(); |
| 550 | - return auth_administrer('modifier_login',$args); |
|
| 549 | + return auth_administrer('modifier_login', $args); |
|
| 551 | 550 | } |
| 552 | 551 | |
| 553 | 552 | /** |
@@ -559,9 +558,9 @@ discard block |
||
| 559 | 558 | * @return bool |
| 560 | 559 | * succes ou echec |
| 561 | 560 | */ |
| 562 | -function auth_autoriser_modifier_pass($auth_methode, $serveur=''){ |
|
| 561 | +function auth_autoriser_modifier_pass($auth_methode, $serveur = '') { |
|
| 563 | 562 | $args = func_get_args(); |
| 564 | - return auth_administrer('autoriser_modifier_pass',$args); |
|
| 563 | + return auth_administrer('autoriser_modifier_pass', $args); |
|
| 565 | 564 | } |
| 566 | 565 | |
| 567 | 566 | /** |
@@ -576,9 +575,9 @@ discard block |
||
| 576 | 575 | * @return string |
| 577 | 576 | * message d'erreur ou chaine vide si pas d'erreur |
| 578 | 577 | */ |
| 579 | -function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur=0, $serveur=''){ |
|
| 578 | +function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur = 0, $serveur = '') { |
|
| 580 | 579 | $args = func_get_args(); |
| 581 | - return auth_administrer('verifier_pass',$args,''); |
|
| 580 | + return auth_administrer('verifier_pass', $args, ''); |
|
| 582 | 581 | } |
| 583 | 582 | |
| 584 | 583 | /** |
@@ -593,9 +592,9 @@ discard block |
||
| 593 | 592 | * @return bool |
| 594 | 593 | * succes ou echec |
| 595 | 594 | */ |
| 596 | -function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur=''){ |
|
| 595 | +function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur = '') { |
|
| 597 | 596 | $args = func_get_args(); |
| 598 | - return auth_administrer('modifier_pass',$args); |
|
| 597 | + return auth_administrer('modifier_pass', $args); |
|
| 599 | 598 | } |
| 600 | 599 | |
| 601 | 600 | /** |
@@ -610,19 +609,19 @@ discard block |
||
| 610 | 609 | * @param string $serveur |
| 611 | 610 | * @return void |
| 612 | 611 | */ |
| 613 | -function auth_synchroniser_distant($auth_methode=true, $id_auteur=0, $champs=array(), $options = array(), $serveur=''){ |
|
| 612 | +function auth_synchroniser_distant($auth_methode = true, $id_auteur = 0, $champs = array(), $options = array(), $serveur = '') { |
|
| 614 | 613 | $args = func_get_args(); |
| 615 | - if ($auth_methode===true OR (isset($options['all']) AND $options['all']==true)){ |
|
| 614 | + if ($auth_methode === true OR (isset($options['all']) AND $options['all'] == true)) { |
|
| 616 | 615 | $options['all'] = true; // ajouter une option all=>true pour chaque auth |
| 617 | 616 | $args = array(true, $id_auteur, $champs, $options, $serveur); |
| 618 | 617 | foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
| 619 | 618 | array_shift($args); |
| 620 | - array_unshift($args,$methode); |
|
| 621 | - auth_administrer('synchroniser_distant',$args); |
|
| 619 | + array_unshift($args, $methode); |
|
| 620 | + auth_administrer('synchroniser_distant', $args); |
|
| 622 | 621 | } |
| 623 | 622 | } |
| 624 | 623 | else |
| 625 | - auth_administrer('synchroniser_distant',$args); |
|
| 624 | + auth_administrer('synchroniser_distant', $args); |
|
| 626 | 625 | } |
| 627 | 626 | |
| 628 | 627 | |
@@ -633,9 +632,9 @@ discard block |
||
| 633 | 632 | * @param string $serveur |
| 634 | 633 | * @return array |
| 635 | 634 | */ |
| 636 | -function lire_php_auth($login, $pw, $serveur=''){ |
|
| 635 | +function lire_php_auth($login, $pw, $serveur = '') { |
|
| 637 | 636 | |
| 638 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login,$serveur,'text'),'','','','',$serveur); |
|
| 637 | + $row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 639 | 638 | |
| 640 | 639 | if (!$row) { |
| 641 | 640 | if (spip_connect_ldap($serveur) |
@@ -649,7 +648,7 @@ discard block |
||
| 649 | 648 | OR !$auth = charger_fonction($auth_methode, 'auth', true)) |
| 650 | 649 | $auth = charger_fonction('spip', 'auth', true); |
| 651 | 650 | |
| 652 | - $auteur=''; |
|
| 651 | + $auteur = ''; |
|
| 653 | 652 | if ($auth) |
| 654 | 653 | $auteur = $auth($login, $pw, $serveur, true); |
| 655 | 654 | // verifier que ce n'est pas un message d'erreur |
@@ -668,22 +667,22 @@ discard block |
||
| 668 | 667 | * @param string $re |
| 669 | 668 | * @param string $lien |
| 670 | 669 | */ |
| 671 | -function ask_php_auth($pb, $raison, $retour='', $url='', $re='', $lien='') { |
|
| 670 | +function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') { |
|
| 672 | 671 | @Header("WWW-Authenticate: Basic realm=\"espace prive\""); |
| 673 | 672 | @Header("HTTP/1.0 401 Unauthorized"); |
| 674 | 673 | $corps = ""; |
| 675 | 674 | $public = generer_url_public(); |
| 676 | 675 | $ecrire = generer_url_ecrire(); |
| 677 | - $retour = $retour?$retour:_T('icone_retour'); |
|
| 676 | + $retour = $retour ? $retour : _T('icone_retour'); |
|
| 678 | 677 | $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
| 679 | 678 | if ($url) { |
| 680 | - $corps .= "[<a href='" . generer_url_action('cookie',"essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 679 | + $corps .= "[<a href='".generer_url_action('cookie', "essai_auth_http=oui&$url")."'>$re</a>]"; |
|
| 681 | 680 | } |
| 682 | 681 | |
| 683 | 682 | if ($lien) |
| 684 | 683 | $corps .= " [<a href='$ecrire'>"._T('login_espace_prive')."</a>]"; |
| 685 | 684 | include_spip('inc/minipres'); |
| 686 | - echo minipres($pb,$corps); |
|
| 685 | + echo minipres($pb, $corps); |
|
| 687 | 686 | exit; |
| 688 | 687 | } |
| 689 | 688 | ?> |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('base/abstract_sql'); |
| 16 | 18 | |
@@ -36,9 +38,13 @@ discard block |
||
| 36 | 38 | |
| 37 | 39 | $row = auth_mode(); |
| 38 | 40 | |
| 39 | - if ($row) return auth_init_droits($row); |
|
| 41 | + if ($row) { |
|
| 42 | + return auth_init_droits($row); |
|
| 43 | + } |
|
| 40 | 44 | |
| 41 | - if (!$connect_login) return auth_a_loger(); |
|
| 45 | + if (!$connect_login) { |
|
| 46 | + return auth_a_loger(); |
|
| 47 | + } |
|
| 42 | 48 | |
| 43 | 49 | // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
| 44 | 50 | // C'est soit parce que la base est inutilisable, |
@@ -46,9 +52,10 @@ discard block |
||
| 46 | 52 | // Pas la peine d'insister. |
| 47 | 53 | // Renvoyer le nom fautif et une URL de remise a zero |
| 48 | 54 | |
| 49 | - if (spip_connect()) |
|
| 50 | - return array('login' => $connect_login, |
|
| 55 | + if (spip_connect()) { |
|
| 56 | + return array('login' => $connect_login, |
|
| 51 | 57 | 'site' => generer_url_public('', "action=logout&logout=prive")); |
| 58 | + } |
|
| 52 | 59 | |
| 53 | 60 | $n = intval(sql_errno()); |
| 54 | 61 | spip_log("Erreur base de donnees $n " . sql_error()); |
@@ -126,7 +133,9 @@ discard block |
||
| 126 | 133 | ) { |
| 127 | 134 | $auth_can_disconnect = true; |
| 128 | 135 | $connect_login = $GLOBALS['visiteur_session']['login']; |
| 129 | - } else unset($_COOKIE['spip_session']); |
|
| 136 | + } else { |
|
| 137 | + unset($_COOKIE['spip_session']); |
|
| 138 | + } |
|
| 130 | 139 | } |
| 131 | 140 | |
| 132 | 141 | // Essayer auth http si significatif |
@@ -159,8 +168,9 @@ discard block |
||
| 159 | 168 | } |
| 160 | 169 | // Authentification .htaccess old style, car .htaccess semble |
| 161 | 170 | // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
| 162 | - else if (isset($_SERVER['REMOTE_USER'])) |
|
| 163 | - $connect_login = $_SERVER['REMOTE_USER']; |
|
| 171 | + else if (isset($_SERVER['REMOTE_USER'])) { |
|
| 172 | + $connect_login = $_SERVER['REMOTE_USER']; |
|
| 173 | + } |
|
| 164 | 174 | } |
| 165 | 175 | |
| 166 | 176 | $where = (is_numeric($id_auteur) |
@@ -169,7 +179,9 @@ discard block |
||
| 169 | 179 | "id_auteur=$id_auteur" : |
| 170 | 180 | (!strlen($connect_login) ? '' : "login=" . sql_quote($connect_login,'','text')); |
| 171 | 181 | |
| 172 | - if (!$where) return ''; |
|
| 182 | + if (!$where) { |
|
| 183 | + return ''; |
|
| 184 | + } |
|
| 173 | 185 | |
| 174 | 186 | // Trouver les autres infos dans la table auteurs. |
| 175 | 187 | // le champ 'quand' est utilise par l'agenda |
@@ -238,8 +250,9 @@ discard block |
||
| 238 | 250 | // qui ne figure pas dans le fichier de session |
| 239 | 251 | include_spip('inc/autoriser'); |
| 240 | 252 | |
| 241 | - if (!autoriser('ecrire')) |
|
| 242 | - return $row; |
|
| 253 | + if (!autoriser('ecrire')) { |
|
| 254 | + return $row; |
|
| 255 | + } |
|
| 243 | 256 | |
| 244 | 257 | // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
| 245 | 258 | |
@@ -271,8 +284,8 @@ discard block |
||
| 271 | 284 | |
| 272 | 285 | // un echec au "bonjour" (login initial) quand le statut est |
| 273 | 286 | // inconnu signale sans doute un probleme de cookies |
| 274 | - if (isset($_GET['bonjour'])) |
|
| 275 | - $redirect = parametre_url($redirect, |
|
| 287 | + if (isset($_GET['bonjour'])) { |
|
| 288 | + $redirect = parametre_url($redirect, |
|
| 276 | 289 | 'var_erreur', |
| 277 | 290 | (!isset($GLOBALS['visiteur_session']['statut']) |
| 278 | 291 | ? 'cookie' |
@@ -280,6 +293,7 @@ discard block |
||
| 280 | 293 | ), |
| 281 | 294 | '&' |
| 282 | 295 | ); |
| 296 | + } |
|
| 283 | 297 | return $redirect; |
| 284 | 298 | } |
| 285 | 299 | |
@@ -293,11 +307,13 @@ discard block |
||
| 293 | 307 | function auth_trace($row, $date=null) |
| 294 | 308 | { |
| 295 | 309 | // Indiquer la connexion. A la minute pres ca suffit. |
| 296 | - if (!is_numeric($connect_quand = $row['quand'])) |
|
| 297 | - $connect_quand = strtotime($connect_quand); |
|
| 310 | + if (!is_numeric($connect_quand = $row['quand'])) { |
|
| 311 | + $connect_quand = strtotime($connect_quand); |
|
| 312 | + } |
|
| 298 | 313 | |
| 299 | - if (is_null($date)) |
|
| 300 | - $date = date('Y-m-d H:i:s'); |
|
| 314 | + if (is_null($date)) { |
|
| 315 | + $date = date('Y-m-d H:i:s'); |
|
| 316 | + } |
|
| 301 | 317 | |
| 302 | 318 | if (abs(strtotime($date) - $connect_quand) >= 60) { |
| 303 | 319 | sql_updateq("spip_auteurs", array("en_ligne" => $date), "id_auteur=" .$row['id_auteur']); |
@@ -324,10 +340,11 @@ discard block |
||
| 324 | 340 | $auth_methode = $auth_methode ? $auth_methode : 'spip'; // valeur par defaut au cas ou |
| 325 | 341 | if ($auth = charger_fonction($auth_methode,'auth',true) |
| 326 | 342 | AND function_exists($f="auth_{$auth_methode}_$fonction") |
| 327 | - ) |
|
| 328 | - $res = call_user_func_array($f, $args); |
|
| 329 | - else |
|
| 330 | - $res = $defaut; |
|
| 343 | + ) { |
|
| 344 | + $res = call_user_func_array($f, $args); |
|
| 345 | + } else { |
|
| 346 | + $res = $defaut; |
|
| 347 | + } |
|
| 331 | 348 | $res = pipeline('auth_administrer',array( |
| 332 | 349 | 'args' => array( |
| 333 | 350 | 'fonction' => $fonction, |
@@ -346,8 +363,9 @@ discard block |
||
| 346 | 363 | * @return array |
| 347 | 364 | */ |
| 348 | 365 | function auth_formulaire_login($flux){ |
| 349 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) |
|
| 350 | - $flux = auth_administrer('formulaire_login',array($methode,$flux),$flux); |
|
| 366 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 367 | + $flux = auth_administrer('formulaire_login',array($methode,$flux),$flux); |
|
| 368 | + } |
|
| 351 | 369 | return $flux; |
| 352 | 370 | } |
| 353 | 371 | |
@@ -394,8 +412,9 @@ discard block |
||
| 394 | 412 | if (!$login |
| 395 | 413 | OR !$login = auth_retrouver_login($login, $serveur) |
| 396 | 414 | OR !$row = sql_fetsel('*','spip_auteurs','login='.sql_quote($login,$serveur,'text'),'','','','',$serveur) |
| 397 | - ) |
|
| 398 | - return array(); |
|
| 415 | + ) { |
|
| 416 | + return array(); |
|
| 417 | + } |
|
| 399 | 418 | |
| 400 | 419 | $prefs = unserialize($row['prefs']); |
| 401 | 420 | $infos = array( |
@@ -434,9 +453,9 @@ discard block |
||
| 434 | 453 | spip_log("connexion de $login par methode $methode"); |
| 435 | 454 | $auteur['auth'] = $methode; |
| 436 | 455 | return $auteur; |
| 456 | + } elseif (is_string($auteur)) { |
|
| 457 | + $erreur .= "$auteur "; |
|
| 437 | 458 | } |
| 438 | - elseif (is_string($auteur)) |
|
| 439 | - $erreur .= "$auteur "; |
|
| 440 | 459 | } |
| 441 | 460 | } |
| 442 | 461 | return $erreur; |
@@ -470,8 +489,9 @@ discard block |
||
| 470 | 489 | * @return bool |
| 471 | 490 | */ |
| 472 | 491 | function auth_loger($auteur){ |
| 473 | - if (!is_array($auteur) OR !count($auteur)) |
|
| 474 | - return false; |
|
| 492 | + if (!is_array($auteur) OR !count($auteur)) { |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 475 | 495 | |
| 476 | 496 | // initialiser et poser le cookie de session |
| 477 | 497 | unset($_COOKIE['spip_session']); |
@@ -620,10 +640,10 @@ discard block |
||
| 620 | 640 | array_unshift($args,$methode); |
| 621 | 641 | auth_administrer('synchroniser_distant',$args); |
| 622 | 642 | } |
| 643 | + } else { |
|
| 644 | + auth_administrer('synchroniser_distant',$args); |
|
| 645 | + } |
|
| 623 | 646 | } |
| 624 | - else |
|
| 625 | - auth_administrer('synchroniser_distant',$args); |
|
| 626 | -} |
|
| 627 | 647 | |
| 628 | 648 | |
| 629 | 649 | /** |
@@ -639,22 +659,26 @@ discard block |
||
| 639 | 659 | |
| 640 | 660 | if (!$row) { |
| 641 | 661 | if (spip_connect_ldap($serveur) |
| 642 | - AND $auth_ldap = charger_fonction('ldap', 'auth', true)) |
|
| 643 | - return $auth_ldap($login, $pw, $serveur, true); |
|
| 662 | + AND $auth_ldap = charger_fonction('ldap', 'auth', true)) { |
|
| 663 | + return $auth_ldap($login, $pw, $serveur, true); |
|
| 664 | + } |
|
| 644 | 665 | return false; |
| 645 | 666 | } |
| 646 | 667 | // su pas de source definie |
| 647 | 668 | // ou auth/xxx introuvable, utiliser 'spip' |
| 648 | 669 | if (!$auth_methode = $row['source'] |
| 649 | - OR !$auth = charger_fonction($auth_methode, 'auth', true)) |
|
| 650 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 670 | + OR !$auth = charger_fonction($auth_methode, 'auth', true)) { |
|
| 671 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 672 | + } |
|
| 651 | 673 | |
| 652 | 674 | $auteur=''; |
| 653 | - if ($auth) |
|
| 654 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 675 | + if ($auth) { |
|
| 676 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 677 | + } |
|
| 655 | 678 | // verifier que ce n'est pas un message d'erreur |
| 656 | - if (is_array($auteur) AND count($auteur)) |
|
| 657 | - return $auteur; |
|
| 679 | + if (is_array($auteur) AND count($auteur)) { |
|
| 680 | + return $auteur; |
|
| 681 | + } |
|
| 658 | 682 | return false; |
| 659 | 683 | } |
| 660 | 684 | |
@@ -680,8 +704,9 @@ discard block |
||
| 680 | 704 | $corps .= "[<a href='" . generer_url_action('cookie',"essai_auth_http=oui&$url") . "'>$re</a>]"; |
| 681 | 705 | } |
| 682 | 706 | |
| 683 | - if ($lien) |
|
| 684 | - $corps .= " [<a href='$ecrire'>"._T('login_espace_prive')."</a>]"; |
|
| 707 | + if ($lien) { |
|
| 708 | + $corps .= " [<a href='$ecrire'>"._T('login_espace_prive')."</a>]"; |
|
| 709 | + } |
|
| 685 | 710 | include_spip('inc/minipres'); |
| 686 | 711 | echo minipres($pb,$corps); |
| 687 | 712 | exit; |
@@ -132,9 +132,6 @@ |
||
| 132 | 132 | /** |
| 133 | 133 | * Construire tout le bandeau superieur de l'espace prive |
| 134 | 134 | * |
| 135 | - * @param unknown_type $rubrique |
|
| 136 | - * @param unknown_type $sous_rubrique |
|
| 137 | - * @param unknown_type $largeur |
|
| 138 | 135 | * @return unknown |
| 139 | 136 | */ |
| 140 | 137 | function inc_bandeau_dist() { |
@@ -15,27 +15,27 @@ discard block |
||
| 15 | 15 | include_spip('inc/boutons'); |
| 16 | 16 | |
| 17 | 17 | function definir_barre_contexte($contexte = null){ |
| 18 | - if (is_null($contexte)) |
|
| 19 | - $contexte = $_GET; |
|
| 20 | - elseif(is_string($contexte)) |
|
| 21 | - $contexte = unserialize($contexte); |
|
| 22 | - if (!isset($contexte['id_rubrique']) AND isset($contexte['exec'])){ |
|
| 23 | - if (!function_exists('trouver_objet_exec')) |
|
| 24 | - include_spip('inc/pipelines_ecrire'); |
|
| 25 | - if ($e=trouver_objet_exec($contexte['exec'])){ |
|
| 26 | - $_id = $e['id_table_objet']; |
|
| 27 | - if (isset($contexte[$_id]) AND $id=intval($contexte[$_id])){ |
|
| 28 | - $table = $e['table_objet_sql']; |
|
| 29 | - $row = sql_fetsel('*',$table,"$_id=".intval($id)); |
|
| 30 | - if (isset($row['id_rubrique'])){ |
|
| 31 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 32 | - if (isset($row['id_secteur'])) |
|
| 33 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - return $contexte; |
|
| 18 | + if (is_null($contexte)) |
|
| 19 | + $contexte = $_GET; |
|
| 20 | + elseif(is_string($contexte)) |
|
| 21 | + $contexte = unserialize($contexte); |
|
| 22 | + if (!isset($contexte['id_rubrique']) AND isset($contexte['exec'])){ |
|
| 23 | + if (!function_exists('trouver_objet_exec')) |
|
| 24 | + include_spip('inc/pipelines_ecrire'); |
|
| 25 | + if ($e=trouver_objet_exec($contexte['exec'])){ |
|
| 26 | + $_id = $e['id_table_objet']; |
|
| 27 | + if (isset($contexte[$_id]) AND $id=intval($contexte[$_id])){ |
|
| 28 | + $table = $e['table_objet_sql']; |
|
| 29 | + $row = sql_fetsel('*',$table,"$_id=".intval($id)); |
|
| 30 | + if (isset($row['id_rubrique'])){ |
|
| 31 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 32 | + if (isset($row['id_secteur'])) |
|
| 33 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + return $contexte; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -51,55 +51,55 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function definir_barre_boutons($contexte=array(),$icones = true, $autorise = true) { |
| 53 | 53 | include_spip('inc/autoriser'); |
| 54 | - $boutons_admin=array(); |
|
| 54 | + $boutons_admin=array(); |
|
| 55 | 55 | |
| 56 | - // les boutons du core, issus de prive/navigation.xml |
|
| 57 | - $liste_boutons = array(); |
|
| 56 | + // les boutons du core, issus de prive/navigation.xml |
|
| 57 | + $liste_boutons = array(); |
|
| 58 | 58 | |
| 59 | - // ajouter les boutons issus des plugin via plugin.xml |
|
| 60 | - if (function_exists('boutons_plugins') |
|
| 61 | - AND is_array($liste_boutons_plugins = boutons_plugins())) |
|
| 62 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 59 | + // ajouter les boutons issus des plugin via plugin.xml |
|
| 60 | + if (function_exists('boutons_plugins') |
|
| 61 | + AND is_array($liste_boutons_plugins = boutons_plugins())) |
|
| 62 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 63 | 63 | |
| 64 | - foreach($liste_boutons as $id => $infos){ |
|
| 65 | - $parent = ""; |
|
| 66 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 67 | - if (!isset($infos['parent']) OR !($parent = $infos['parent']) OR !$autorise OR autoriser('menu',"_$id",0,NULL,array('contexte'=>$contexte))){ |
|
| 68 | - if ($parent |
|
| 69 | - AND $parent = preg_replace(',^bando_,','menu_',$parent) |
|
| 70 | - AND isset($boutons_admin[$parent])){ |
|
| 71 | - if (!is_array($boutons_admin[$parent]->sousmenu)) |
|
| 72 | - $boutons_admin[$parent]->sousmenu = array(); |
|
| 73 | - $position = (isset($infos['position']) AND strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 74 | - if ($position<0) $position = count($boutons_admin[$parent]->sousmenu)+1+$position; |
|
| 75 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu,0,$position) |
|
| 76 | - + array($id=> new Bouton( |
|
| 77 | - ($icones AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 78 | - $infos['titre'], // titre |
|
| 79 | - (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 80 | - (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 81 | - )) |
|
| 82 | - + array_slice($boutons_admin[$parent]->sousmenu,$position,100); |
|
| 83 | - } |
|
| 84 | - if (!$parent |
|
| 85 | - // provisoire, eviter les vieux boutons |
|
| 86 | - AND (!in_array($id,array('forum','statistiques_visites'))) |
|
| 64 | + foreach($liste_boutons as $id => $infos){ |
|
| 65 | + $parent = ""; |
|
| 66 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 67 | + if (!isset($infos['parent']) OR !($parent = $infos['parent']) OR !$autorise OR autoriser('menu',"_$id",0,NULL,array('contexte'=>$contexte))){ |
|
| 68 | + if ($parent |
|
| 69 | + AND $parent = preg_replace(',^bando_,','menu_',$parent) |
|
| 70 | + AND isset($boutons_admin[$parent])){ |
|
| 71 | + if (!is_array($boutons_admin[$parent]->sousmenu)) |
|
| 72 | + $boutons_admin[$parent]->sousmenu = array(); |
|
| 73 | + $position = (isset($infos['position']) AND strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 74 | + if ($position<0) $position = count($boutons_admin[$parent]->sousmenu)+1+$position; |
|
| 75 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu,0,$position) |
|
| 76 | + + array($id=> new Bouton( |
|
| 77 | + ($icones AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 78 | + $infos['titre'], // titre |
|
| 79 | + (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 80 | + (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 81 | + )) |
|
| 82 | + + array_slice($boutons_admin[$parent]->sousmenu,$position,100); |
|
| 83 | + } |
|
| 84 | + if (!$parent |
|
| 85 | + // provisoire, eviter les vieux boutons |
|
| 86 | + AND (!in_array($id,array('forum','statistiques_visites'))) |
|
| 87 | 87 | |
| 88 | - ) { |
|
| 89 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 90 | - $boutons_admin = array_slice($boutons_admin,0,$position) |
|
| 91 | - +array($id=> new Bouton( |
|
| 92 | - ($icones AND isset($infos['icone']) AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 93 | - $infos['titre'], // titre |
|
| 94 | - (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 95 | - (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 96 | - )) |
|
| 97 | - + array_slice($boutons_admin,$position,100); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 88 | + ) { |
|
| 89 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 90 | + $boutons_admin = array_slice($boutons_admin,0,$position) |
|
| 91 | + +array($id=> new Bouton( |
|
| 92 | + ($icones AND isset($infos['icone']) AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 93 | + $infos['titre'], // titre |
|
| 94 | + (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 95 | + (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 96 | + )) |
|
| 97 | + + array_slice($boutons_admin,$position,100); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return pipeline('ajouter_menus', $boutons_admin); |
|
| 102 | + return pipeline('ajouter_menus', $boutons_admin); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | // http://doc.spip.org/@bandeau_creer_url |
| 113 | 113 | function bandeau_creer_url($url, $args="", $contexte=null){ |
| 114 | - if (!preg_match(',[\/\?],',$url)) { |
|
| 115 | - $url = generer_url_ecrire($url,$args,true); |
|
| 116 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 117 | - // &truc=@machin@ |
|
| 118 | - // @machin@ etant remplace par _request('machin') |
|
| 119 | - $url = str_replace('&','&',$url); |
|
| 120 | - while (preg_match(",[&?]([a-z_]+)=@([a-z_]+)@,i",$url,$matches)){ |
|
| 121 | - if ($matches[2]=='id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) |
|
| 122 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur','spip_rubriques','id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 123 | - $val = _request($matches[2],$contexte); |
|
| 124 | - $url = parametre_url($url,$matches[1],$val?$val:'','&'); |
|
| 125 | - } |
|
| 126 | - $url = str_replace('&','&',$url); |
|
| 127 | - } |
|
| 128 | - return $url; |
|
| 114 | + if (!preg_match(',[\/\?],',$url)) { |
|
| 115 | + $url = generer_url_ecrire($url,$args,true); |
|
| 116 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 117 | + // &truc=@machin@ |
|
| 118 | + // @machin@ etant remplace par _request('machin') |
|
| 119 | + $url = str_replace('&','&',$url); |
|
| 120 | + while (preg_match(",[&?]([a-z_]+)=@([a-z_]+)@,i",$url,$matches)){ |
|
| 121 | + if ($matches[2]=='id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) |
|
| 122 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur','spip_rubriques','id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 123 | + $val = _request($matches[2],$contexte); |
|
| 124 | + $url = parametre_url($url,$matches[1],$val?$val:'','&'); |
|
| 125 | + } |
|
| 126 | + $url = str_replace('&','&',$url); |
|
| 127 | + } |
|
| 128 | + return $url; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return unknown |
| 139 | 139 | */ |
| 140 | 140 | function inc_bandeau_dist() { |
| 141 | - return recuperer_fond('prive/squelettes/inclure/barre-nav',$_GET); |
|
| 141 | + return recuperer_fond('prive/squelettes/inclure/barre-nav',$_GET); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | ?> |
@@ -10,18 +10,22 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/boutons'); |
| 16 | 18 | |
| 17 | 19 | function definir_barre_contexte($contexte = null){ |
| 18 | - if (is_null($contexte)) |
|
| 19 | - $contexte = $_GET; |
|
| 20 | - elseif(is_string($contexte)) |
|
| 21 | - $contexte = unserialize($contexte); |
|
| 20 | + if (is_null($contexte)) { |
|
| 21 | + $contexte = $_GET; |
|
| 22 | + } elseif(is_string($contexte)) { |
|
| 23 | + $contexte = unserialize($contexte); |
|
| 24 | + } |
|
| 22 | 25 | if (!isset($contexte['id_rubrique']) AND isset($contexte['exec'])){ |
| 23 | - if (!function_exists('trouver_objet_exec')) |
|
| 24 | - include_spip('inc/pipelines_ecrire'); |
|
| 26 | + if (!function_exists('trouver_objet_exec')) { |
|
| 27 | + include_spip('inc/pipelines_ecrire'); |
|
| 28 | + } |
|
| 25 | 29 | if ($e=trouver_objet_exec($contexte['exec'])){ |
| 26 | 30 | $_id = $e['id_table_objet']; |
| 27 | 31 | if (isset($contexte[$_id]) AND $id=intval($contexte[$_id])){ |
@@ -29,8 +33,9 @@ discard block |
||
| 29 | 33 | $row = sql_fetsel('*',$table,"$_id=".intval($id)); |
| 30 | 34 | if (isset($row['id_rubrique'])){ |
| 31 | 35 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 32 | - if (isset($row['id_secteur'])) |
|
| 33 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 36 | + if (isset($row['id_secteur'])) { |
|
| 37 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 38 | + } |
|
| 34 | 39 | } |
| 35 | 40 | } |
| 36 | 41 | } |
@@ -58,8 +63,9 @@ discard block |
||
| 58 | 63 | |
| 59 | 64 | // ajouter les boutons issus des plugin via plugin.xml |
| 60 | 65 | if (function_exists('boutons_plugins') |
| 61 | - AND is_array($liste_boutons_plugins = boutons_plugins())) |
|
| 62 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 66 | + AND is_array($liste_boutons_plugins = boutons_plugins())) { |
|
| 67 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | foreach($liste_boutons as $id => $infos){ |
| 65 | 71 | $parent = ""; |
@@ -68,10 +74,13 @@ discard block |
||
| 68 | 74 | if ($parent |
| 69 | 75 | AND $parent = preg_replace(',^bando_,','menu_',$parent) |
| 70 | 76 | AND isset($boutons_admin[$parent])){ |
| 71 | - if (!is_array($boutons_admin[$parent]->sousmenu)) |
|
| 72 | - $boutons_admin[$parent]->sousmenu = array(); |
|
| 77 | + if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 78 | + $boutons_admin[$parent]->sousmenu = array(); |
|
| 79 | + } |
|
| 73 | 80 | $position = (isset($infos['position']) AND strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
| 74 | - if ($position<0) $position = count($boutons_admin[$parent]->sousmenu)+1+$position; |
|
| 81 | + if ($position<0) { |
|
| 82 | + $position = count($boutons_admin[$parent]->sousmenu)+1+$position; |
|
| 83 | + } |
|
| 75 | 84 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu,0,$position) |
| 76 | 85 | + array($id=> new Bouton( |
| 77 | 86 | ($icones AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
@@ -118,8 +127,9 @@ discard block |
||
| 118 | 127 | // @machin@ etant remplace par _request('machin') |
| 119 | 128 | $url = str_replace('&','&',$url); |
| 120 | 129 | while (preg_match(",[&?]([a-z_]+)=@([a-z_]+)@,i",$url,$matches)){ |
| 121 | - if ($matches[2]=='id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) |
|
| 122 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur','spip_rubriques','id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 130 | + if ($matches[2]=='id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) { |
|
| 131 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur','spip_rubriques','id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 132 | + } |
|
| 123 | 133 | $val = _request($matches[2],$contexte); |
| 124 | 134 | $url = parametre_url($url,$matches[1],$val?$val:'','&'); |
| 125 | 135 | } |
@@ -14,20 +14,20 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | include_spip('inc/boutons'); |
| 16 | 16 | |
| 17 | -function definir_barre_contexte($contexte = null){ |
|
| 17 | +function definir_barre_contexte($contexte = null) { |
|
| 18 | 18 | if (is_null($contexte)) |
| 19 | 19 | $contexte = $_GET; |
| 20 | - elseif(is_string($contexte)) |
|
| 20 | + elseif (is_string($contexte)) |
|
| 21 | 21 | $contexte = unserialize($contexte); |
| 22 | - if (!isset($contexte['id_rubrique']) AND isset($contexte['exec'])){ |
|
| 22 | + if (!isset($contexte['id_rubrique']) AND isset($contexte['exec'])) { |
|
| 23 | 23 | if (!function_exists('trouver_objet_exec')) |
| 24 | 24 | include_spip('inc/pipelines_ecrire'); |
| 25 | - if ($e=trouver_objet_exec($contexte['exec'])){ |
|
| 25 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 26 | 26 | $_id = $e['id_table_objet']; |
| 27 | - if (isset($contexte[$_id]) AND $id=intval($contexte[$_id])){ |
|
| 27 | + if (isset($contexte[$_id]) AND $id = intval($contexte[$_id])) { |
|
| 28 | 28 | $table = $e['table_objet_sql']; |
| 29 | - $row = sql_fetsel('*',$table,"$_id=".intval($id)); |
|
| 30 | - if (isset($row['id_rubrique'])){ |
|
| 29 | + $row = sql_fetsel('*', $table, "$_id=".intval($id)); |
|
| 30 | + if (isset($row['id_rubrique'])) { |
|
| 31 | 31 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 32 | 32 | if (isset($row['id_secteur'])) |
| 33 | 33 | $contexte['id_secteur'] = $row['id_secteur']; |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @param bool $autorise // ne renvoyer que les boutons autorises |
| 50 | 50 | * @return array |
| 51 | 51 | */ |
| 52 | -function definir_barre_boutons($contexte=array(),$icones = true, $autorise = true) { |
|
| 52 | +function definir_barre_boutons($contexte = array(), $icones = true, $autorise = true) { |
|
| 53 | 53 | include_spip('inc/autoriser'); |
| 54 | - $boutons_admin=array(); |
|
| 54 | + $boutons_admin = array(); |
|
| 55 | 55 | |
| 56 | 56 | // les boutons du core, issus de prive/navigation.xml |
| 57 | 57 | $liste_boutons = array(); |
@@ -61,40 +61,40 @@ discard block |
||
| 61 | 61 | AND is_array($liste_boutons_plugins = boutons_plugins())) |
| 62 | 62 | $liste_boutons = &$liste_boutons_plugins; |
| 63 | 63 | |
| 64 | - foreach($liste_boutons as $id => $infos){ |
|
| 64 | + foreach ($liste_boutons as $id => $infos) { |
|
| 65 | 65 | $parent = ""; |
| 66 | 66 | // les boutons principaux ne sont pas soumis a autorisation |
| 67 | - if (!isset($infos['parent']) OR !($parent = $infos['parent']) OR !$autorise OR autoriser('menu',"_$id",0,NULL,array('contexte'=>$contexte))){ |
|
| 67 | + if (!isset($infos['parent']) OR !($parent = $infos['parent']) OR !$autorise OR autoriser('menu', "_$id", 0, NULL, array('contexte'=>$contexte))) { |
|
| 68 | 68 | if ($parent |
| 69 | - AND $parent = preg_replace(',^bando_,','menu_',$parent) |
|
| 70 | - AND isset($boutons_admin[$parent])){ |
|
| 69 | + AND $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 70 | + AND isset($boutons_admin[$parent])) { |
|
| 71 | 71 | if (!is_array($boutons_admin[$parent]->sousmenu)) |
| 72 | 72 | $boutons_admin[$parent]->sousmenu = array(); |
| 73 | 73 | $position = (isset($infos['position']) AND strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
| 74 | - if ($position<0) $position = count($boutons_admin[$parent]->sousmenu)+1+$position; |
|
| 75 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu,0,$position) |
|
| 74 | + if ($position < 0) $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 75 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 76 | 76 | + array($id=> new Bouton( |
| 77 | - ($icones AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 78 | - $infos['titre'], // titre |
|
| 79 | - (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 80 | - (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 77 | + ($icones AND $infos['icone']) ?find_in_theme($infos['icone']) : '', // icone |
|
| 78 | + $infos['titre'], // titre |
|
| 79 | + (isset($infos['action']) AND $infos['action']) ? $infos['action'] : null, |
|
| 80 | + (isset($infos['parametres']) AND $infos['parametres']) ? $infos['parametres'] : null |
|
| 81 | 81 | )) |
| 82 | - + array_slice($boutons_admin[$parent]->sousmenu,$position,100); |
|
| 82 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 83 | 83 | } |
| 84 | 84 | if (!$parent |
| 85 | 85 | // provisoire, eviter les vieux boutons |
| 86 | - AND (!in_array($id,array('forum','statistiques_visites'))) |
|
| 86 | + AND (!in_array($id, array('forum', 'statistiques_visites'))) |
|
| 87 | 87 | |
| 88 | 88 | ) { |
| 89 | 89 | $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
| 90 | - $boutons_admin = array_slice($boutons_admin,0,$position) |
|
| 90 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 91 | 91 | +array($id=> new Bouton( |
| 92 | - ($icones AND isset($infos['icone']) AND $infos['icone'])?find_in_theme($infos['icone']):'', // icone |
|
| 93 | - $infos['titre'], // titre |
|
| 94 | - (isset($infos['action']) AND $infos['action'])?$infos['action']:null, |
|
| 95 | - (isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:null |
|
| 92 | + ($icones AND isset($infos['icone']) AND $infos['icone']) ?find_in_theme($infos['icone']) : '', // icone |
|
| 93 | + $infos['titre'], // titre |
|
| 94 | + (isset($infos['action']) AND $infos['action']) ? $infos['action'] : null, |
|
| 95 | + (isset($infos['parametres']) AND $infos['parametres']) ? $infos['parametres'] : null |
|
| 96 | 96 | )) |
| 97 | - + array_slice($boutons_admin,$position,100); |
|
| 97 | + + array_slice($boutons_admin, $position, 100); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -110,20 +110,20 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | // http://doc.spip.org/@bandeau_creer_url |
| 113 | -function bandeau_creer_url($url, $args="", $contexte=null){ |
|
| 114 | - if (!preg_match(',[\/\?],',$url)) { |
|
| 115 | - $url = generer_url_ecrire($url,$args,true); |
|
| 113 | +function bandeau_creer_url($url, $args = "", $contexte = null) { |
|
| 114 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 115 | + $url = generer_url_ecrire($url, $args, true); |
|
| 116 | 116 | // recuperer les parametres du contexte demande par l'url sous la forme |
| 117 | 117 | // &truc=@machin@ |
| 118 | 118 | // @machin@ etant remplace par _request('machin') |
| 119 | - $url = str_replace('&','&',$url); |
|
| 120 | - while (preg_match(",[&?]([a-z_]+)=@([a-z_]+)@,i",$url,$matches)){ |
|
| 121 | - if ($matches[2]=='id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) |
|
| 122 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur','spip_rubriques','id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 123 | - $val = _request($matches[2],$contexte); |
|
| 124 | - $url = parametre_url($url,$matches[1],$val?$val:'','&'); |
|
| 119 | + $url = str_replace('&', '&', $url); |
|
| 120 | + while (preg_match(",[&?]([a-z_]+)=@([a-z_]+)@,i", $url, $matches)) { |
|
| 121 | + if ($matches[2] == 'id_secteur' AND !isset($contexte['id_secteur']) AND isset($contexte['id_rubrique'])) |
|
| 122 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 123 | + $val = _request($matches[2], $contexte); |
|
| 124 | + $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 125 | 125 | } |
| 126 | - $url = str_replace('&','&',$url); |
|
| 126 | + $url = str_replace('&', '&', $url); |
|
| 127 | 127 | } |
| 128 | 128 | return $url; |
| 129 | 129 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return unknown |
| 139 | 139 | */ |
| 140 | 140 | function inc_bandeau_dist() { |
| 141 | - return recuperer_fond('prive/squelettes/inclure/barre-nav',$_GET); |
|
| 141 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | ?> |
@@ -73,6 +73,10 @@ |
||
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | // http://doc.spip.org/@barre_onglets |
| 76 | +/** |
|
| 77 | + * @param string $rubrique |
|
| 78 | + * @param string $ongletCourant |
|
| 79 | + */ |
|
| 76 | 80 | function barre_onglets($rubrique, $ongletCourant, $class="barre_onglet"){ |
| 77 | 81 | include_spip('inc/presentation'); |
| 78 | 82 | |
@@ -18,24 +18,24 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | // http://doc.spip.org/@Bouton |
| 20 | 20 | class Bouton { |
| 21 | - var $icone; /* l'icone a mettre dans le bouton */ |
|
| 22 | - var $libelle; /* le nom de l'entree d'i18n associe */ |
|
| 23 | - var $url= null; /* l'url de la page (null => ?exec=nom) */ |
|
| 24 | - var $urlArg= null; /* arguments supplementaires de l'url */ |
|
| 25 | - var $url2= null; /* url jscript */ |
|
| 26 | - var $target= null; /* pour ouvrir dans une fenetre a part */ |
|
| 27 | - var $sousmenu= null;/* sous barre de boutons / onglets */ |
|
| 21 | + var $icone; /* l'icone a mettre dans le bouton */ |
|
| 22 | + var $libelle; /* le nom de l'entree d'i18n associe */ |
|
| 23 | + var $url= null; /* l'url de la page (null => ?exec=nom) */ |
|
| 24 | + var $urlArg= null; /* arguments supplementaires de l'url */ |
|
| 25 | + var $url2= null; /* url jscript */ |
|
| 26 | + var $target= null; /* pour ouvrir dans une fenetre a part */ |
|
| 27 | + var $sousmenu= null;/* sous barre de boutons / onglets */ |
|
| 28 | 28 | |
| 29 | 29 | // http://doc.spip.org/@Bouton |
| 30 | - function Bouton($icone, $libelle, $url=null, $urlArg=null, |
|
| 31 | - $url2=null, $target=null) { |
|
| 32 | - $this->icone = $icone; |
|
| 33 | - $this->libelle= $libelle; |
|
| 34 | - $this->url = $url; |
|
| 35 | - $this->urlArg = $urlArg; |
|
| 36 | - $this->url2 = $url2; |
|
| 37 | - $this->target = $target; |
|
| 38 | - } |
|
| 30 | + function Bouton($icone, $libelle, $url=null, $urlArg=null, |
|
| 31 | + $url2=null, $target=null) { |
|
| 32 | + $this->icone = $icone; |
|
| 33 | + $this->libelle= $libelle; |
|
| 34 | + $this->url = $url; |
|
| 35 | + $this->urlArg = $urlArg; |
|
| 36 | + $this->url2 = $url2; |
|
| 37 | + $this->target = $target; |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -46,44 +46,44 @@ discard block |
||
| 46 | 46 | // http://doc.spip.org/@definir_barre_onglets |
| 47 | 47 | function definir_barre_onglets($script) { |
| 48 | 48 | |
| 49 | - $onglets=array(); |
|
| 50 | - $liste_onglets = array(); |
|
| 51 | - |
|
| 52 | - // ajouter les onglets issus des plugin via plugin.xml |
|
| 53 | - if (function_exists('onglets_plugins')) |
|
| 54 | - $liste_onglets = onglets_plugins(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - foreach($liste_onglets as $id => $infos){ |
|
| 58 | - if (($parent = $infos['parent']) |
|
| 59 | - && $parent == $script |
|
| 60 | - && autoriser('onglet',"_$id")) { |
|
| 61 | - $onglets[$id] = new Bouton( |
|
| 62 | - find_in_theme($infos['icone']), // icone |
|
| 63 | - $infos['titre'], // titre |
|
| 64 | - (isset($infos['action']) and $infos['action']) |
|
| 65 | - ? generer_url_ecrire($infos['action'],(isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:'') |
|
| 66 | - : null |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return pipeline('ajouter_onglets', array('data'=>$onglets,'args'=>$script)); |
|
| 49 | + $onglets=array(); |
|
| 50 | + $liste_onglets = array(); |
|
| 51 | + |
|
| 52 | + // ajouter les onglets issus des plugin via plugin.xml |
|
| 53 | + if (function_exists('onglets_plugins')) |
|
| 54 | + $liste_onglets = onglets_plugins(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + foreach($liste_onglets as $id => $infos){ |
|
| 58 | + if (($parent = $infos['parent']) |
|
| 59 | + && $parent == $script |
|
| 60 | + && autoriser('onglet',"_$id")) { |
|
| 61 | + $onglets[$id] = new Bouton( |
|
| 62 | + find_in_theme($infos['icone']), // icone |
|
| 63 | + $infos['titre'], // titre |
|
| 64 | + (isset($infos['action']) and $infos['action']) |
|
| 65 | + ? generer_url_ecrire($infos['action'],(isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:'') |
|
| 66 | + : null |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return pipeline('ajouter_onglets', array('data'=>$onglets,'args'=>$script)); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | // http://doc.spip.org/@barre_onglets |
| 76 | 76 | function barre_onglets($rubrique, $ongletCourant, $class="barre_onglet"){ |
| 77 | - include_spip('inc/presentation'); |
|
| 77 | + include_spip('inc/presentation'); |
|
| 78 | 78 | |
| 79 | - $res = ''; |
|
| 79 | + $res = ''; |
|
| 80 | 80 | |
| 81 | - foreach(definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 82 | - $url= $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 83 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 84 | - } |
|
| 81 | + foreach(definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 82 | + $url= $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 83 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 86 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | // http://doc.spip.org/@Bouton |
| 20 | 20 | class Bouton { |
| 21 | - var $icone; /* l'icone a mettre dans le bouton */ |
|
| 22 | - var $libelle; /* le nom de l'entree d'i18n associe */ |
|
| 23 | - var $url= null; /* l'url de la page (null => ?exec=nom) */ |
|
| 24 | - var $urlArg= null; /* arguments supplementaires de l'url */ |
|
| 25 | - var $url2= null; /* url jscript */ |
|
| 26 | - var $target= null; /* pour ouvrir dans une fenetre a part */ |
|
| 27 | - var $sousmenu= null;/* sous barre de boutons / onglets */ |
|
| 21 | + var $icone; /* l'icone a mettre dans le bouton */ |
|
| 22 | + var $libelle; /* le nom de l'entree d'i18n associe */ |
|
| 23 | + var $url = null; /* l'url de la page (null => ?exec=nom) */ |
|
| 24 | + var $urlArg = null; /* arguments supplementaires de l'url */ |
|
| 25 | + var $url2 = null; /* url jscript */ |
|
| 26 | + var $target = null; /* pour ouvrir dans une fenetre a part */ |
|
| 27 | + var $sousmenu = null; /* sous barre de boutons / onglets */ |
|
| 28 | 28 | |
| 29 | 29 | // http://doc.spip.org/@Bouton |
| 30 | - function Bouton($icone, $libelle, $url=null, $urlArg=null, |
|
| 31 | - $url2=null, $target=null) { |
|
| 30 | + function Bouton($icone, $libelle, $url = null, $urlArg = null, |
|
| 31 | + $url2 = null, $target = null) { |
|
| 32 | 32 | $this->icone = $icone; |
| 33 | - $this->libelle= $libelle; |
|
| 33 | + $this->libelle = $libelle; |
|
| 34 | 34 | $this->url = $url; |
| 35 | 35 | $this->urlArg = $urlArg; |
| 36 | 36 | $this->url2 = $url2; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // http://doc.spip.org/@definir_barre_onglets |
| 47 | 47 | function definir_barre_onglets($script) { |
| 48 | 48 | |
| 49 | - $onglets=array(); |
|
| 49 | + $onglets = array(); |
|
| 50 | 50 | $liste_onglets = array(); |
| 51 | 51 | |
| 52 | 52 | // ajouter les onglets issus des plugin via plugin.xml |
@@ -54,36 +54,36 @@ discard block |
||
| 54 | 54 | $liste_onglets = onglets_plugins(); |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - foreach($liste_onglets as $id => $infos){ |
|
| 57 | + foreach ($liste_onglets as $id => $infos) { |
|
| 58 | 58 | if (($parent = $infos['parent']) |
| 59 | 59 | && $parent == $script |
| 60 | - && autoriser('onglet',"_$id")) { |
|
| 60 | + && autoriser('onglet', "_$id")) { |
|
| 61 | 61 | $onglets[$id] = new Bouton( |
| 62 | - find_in_theme($infos['icone']), // icone |
|
| 63 | - $infos['titre'], // titre |
|
| 62 | + find_in_theme($infos['icone']), // icone |
|
| 63 | + $infos['titre'], // titre |
|
| 64 | 64 | (isset($infos['action']) and $infos['action']) |
| 65 | - ? generer_url_ecrire($infos['action'],(isset($infos['parametres']) AND $infos['parametres'])?$infos['parametres']:'') |
|
| 65 | + ? generer_url_ecrire($infos['action'], (isset($infos['parametres']) AND $infos['parametres']) ? $infos['parametres'] : '') |
|
| 66 | 66 | : null |
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - return pipeline('ajouter_onglets', array('data'=>$onglets,'args'=>$script)); |
|
| 71 | + return pipeline('ajouter_onglets', array('data'=>$onglets, 'args'=>$script)); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | // http://doc.spip.org/@barre_onglets |
| 76 | -function barre_onglets($rubrique, $ongletCourant, $class="barre_onglet"){ |
|
| 76 | +function barre_onglets($rubrique, $ongletCourant, $class = "barre_onglet") { |
|
| 77 | 77 | include_spip('inc/presentation'); |
| 78 | 78 | |
| 79 | 79 | $res = ''; |
| 80 | 80 | |
| 81 | - foreach(definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 82 | - $url= $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 81 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 82 | + $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 83 | 83 | $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 86 | + return !$res ? '' : (debut_onglet($class).$res.fin_onglet()); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * une classe definissant un bouton dans la barre du haut de l'interface |
@@ -50,8 +52,9 @@ discard block |
||
| 50 | 52 | $liste_onglets = array(); |
| 51 | 53 | |
| 52 | 54 | // ajouter les onglets issus des plugin via plugin.xml |
| 53 | - if (function_exists('onglets_plugins')) |
|
| 54 | - $liste_onglets = onglets_plugins(); |
|
| 55 | + if (function_exists('onglets_plugins')) { |
|
| 56 | + $liste_onglets = onglets_plugins(); |
|
| 57 | + } |
|
| 55 | 58 | |
| 56 | 59 | |
| 57 | 60 | foreach($liste_onglets as $id => $infos){ |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * @param string $cfg |
| 136 | 136 | * @param mixed $def |
| 137 | 137 | * @param bool $unserialize |
| 138 | - * @return mixed |
|
| 138 | + * @return string |
|
| 139 | 139 | */ |
| 140 | 140 | function lire_config_metapack_dist($cfg='', $def=null, $unserialize=true) { |
| 141 | 141 | return lire_config($cfg, $def, $unserialize); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | // http://doc.spip.org/@inc_config_dist |
| 23 | 23 | function inc_config_dist() { |
| 24 | - actualise_metas(liste_metas()); |
|
| 24 | + actualise_metas(liste_metas()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -32,27 +32,27 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function expliquer_config($cfg){ |
| 35 | - // par defaut, sur la table des meta |
|
| 36 | - $table = 'meta'; |
|
| 37 | - $casier = null; |
|
| 38 | - $sous_casier = array(); |
|
| 39 | - if (strlen($cfg)){ |
|
| 40 | - $cfg = explode('/',$cfg); |
|
| 41 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 42 | - if (!reset($cfg) AND count($cfg)>1) { |
|
| 43 | - array_shift($cfg); |
|
| 44 | - $table = array_shift($cfg); |
|
| 45 | - if (!isset($GLOBALS[$table])) |
|
| 46 | - lire_metas($table); |
|
| 47 | - } |
|
| 48 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 49 | - if (count($cfg)) |
|
| 50 | - $casier = array_shift($cfg); |
|
| 51 | - |
|
| 52 | - if (count($cfg)) |
|
| 53 | - $sous_casier = $cfg; |
|
| 54 | - } |
|
| 55 | - return array($table,$casier,$sous_casier); |
|
| 35 | + // par defaut, sur la table des meta |
|
| 36 | + $table = 'meta'; |
|
| 37 | + $casier = null; |
|
| 38 | + $sous_casier = array(); |
|
| 39 | + if (strlen($cfg)){ |
|
| 40 | + $cfg = explode('/',$cfg); |
|
| 41 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 42 | + if (!reset($cfg) AND count($cfg)>1) { |
|
| 43 | + array_shift($cfg); |
|
| 44 | + $table = array_shift($cfg); |
|
| 45 | + if (!isset($GLOBALS[$table])) |
|
| 46 | + lire_metas($table); |
|
| 47 | + } |
|
| 48 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 49 | + if (count($cfg)) |
|
| 50 | + $casier = array_shift($cfg); |
|
| 51 | + |
|
| 52 | + if (count($cfg)) |
|
| 53 | + $sous_casier = $cfg; |
|
| 54 | + } |
|
| 55 | + return array($table,$casier,$sous_casier); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -75,56 +75,56 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | 77 | function lire_config($cfg='', $def=null, $unserialize=true) { |
| 78 | - // lire le stockage sous la forme /table/valeur |
|
| 79 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 80 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 81 | - |
|
| 82 | - // traiter en priorite le cas simple et frequent |
|
| 83 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 84 | - if ($cfg AND strpbrk($cfg,'/:')===false){ |
|
| 85 | - $r = isset($GLOBALS['meta'][$cfg])? |
|
| 86 | - ((!$unserialize |
|
| 87 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 88 | - OR !is_string($GLOBALS['meta'][$cfg]) |
|
| 89 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 90 | - OR strpos($GLOBALS['meta'][$cfg],':')===false |
|
| 91 | - OR ($t=unserialize($GLOBALS['meta'][$cfg]))===false)?$GLOBALS['meta'][$cfg]:$t) |
|
| 92 | - :$def; |
|
| 93 | - return $r; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Brancher sur methodes externes si besoin |
|
| 97 | - if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 98 | - $methode = substr($cfg,0,$p); |
|
| 99 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 100 | - return $lire_config(substr($cfg,$p+2),$def,$unserialize); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 104 | - |
|
| 105 | - if (!isset($GLOBALS[$table])) |
|
| 106 | - return $def; |
|
| 107 | - |
|
| 108 | - $r = $GLOBALS[$table]; |
|
| 109 | - |
|
| 110 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 111 | - if (!$casier) |
|
| 112 | - return $unserialize ? $r : serialize($r); |
|
| 113 | - |
|
| 114 | - // casier principal : |
|
| 115 | - // le deserializer si demande |
|
| 116 | - // ou si on a besoin |
|
| 117 | - // d'un sous casier |
|
| 118 | - $r = isset($r[$casier])?$r[$casier]:null; |
|
| 119 | - if (($unserialize OR count($sous_casier)) AND $r AND is_string($r)) |
|
| 120 | - $r = (($t=unserialize($r))===false?$r:$t); |
|
| 121 | - |
|
| 122 | - // aller chercher le sous_casier |
|
| 123 | - while(!is_null($r) AND $casier = array_shift($sous_casier)) |
|
| 124 | - $r = isset($r[$casier])?$r[$casier]:null; |
|
| 125 | - |
|
| 126 | - if (is_null($r)) return $def; |
|
| 127 | - return $r; |
|
| 78 | + // lire le stockage sous la forme /table/valeur |
|
| 79 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 80 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 81 | + |
|
| 82 | + // traiter en priorite le cas simple et frequent |
|
| 83 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 84 | + if ($cfg AND strpbrk($cfg,'/:')===false){ |
|
| 85 | + $r = isset($GLOBALS['meta'][$cfg])? |
|
| 86 | + ((!$unserialize |
|
| 87 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 88 | + OR !is_string($GLOBALS['meta'][$cfg]) |
|
| 89 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 90 | + OR strpos($GLOBALS['meta'][$cfg],':')===false |
|
| 91 | + OR ($t=unserialize($GLOBALS['meta'][$cfg]))===false)?$GLOBALS['meta'][$cfg]:$t) |
|
| 92 | + :$def; |
|
| 93 | + return $r; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Brancher sur methodes externes si besoin |
|
| 97 | + if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 98 | + $methode = substr($cfg,0,$p); |
|
| 99 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 100 | + return $lire_config(substr($cfg,$p+2),$def,$unserialize); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 104 | + |
|
| 105 | + if (!isset($GLOBALS[$table])) |
|
| 106 | + return $def; |
|
| 107 | + |
|
| 108 | + $r = $GLOBALS[$table]; |
|
| 109 | + |
|
| 110 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 111 | + if (!$casier) |
|
| 112 | + return $unserialize ? $r : serialize($r); |
|
| 113 | + |
|
| 114 | + // casier principal : |
|
| 115 | + // le deserializer si demande |
|
| 116 | + // ou si on a besoin |
|
| 117 | + // d'un sous casier |
|
| 118 | + $r = isset($r[$casier])?$r[$casier]:null; |
|
| 119 | + if (($unserialize OR count($sous_casier)) AND $r AND is_string($r)) |
|
| 120 | + $r = (($t=unserialize($r))===false?$r:$t); |
|
| 121 | + |
|
| 122 | + // aller chercher le sous_casier |
|
| 123 | + while(!is_null($r) AND $casier = array_shift($sous_casier)) |
|
| 124 | + $r = isset($r[$casier])?$r[$casier]:null; |
|
| 125 | + |
|
| 126 | + if (is_null($r)) return $def; |
|
| 127 | + return $r; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return mixed |
| 139 | 139 | */ |
| 140 | 140 | function lire_config_metapack_dist($cfg='', $def=null, $unserialize=true) { |
| 141 | - return lire_config($cfg, $def, $unserialize); |
|
| 141 | + return lire_config($cfg, $def, $unserialize); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -150,93 +150,93 @@ discard block |
||
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | 152 | function ecrire_config($cfg,$store) { |
| 153 | - // Brancher sur methodes externes si besoin |
|
| 154 | - if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 155 | - $methode = substr($cfg,0,$p); |
|
| 156 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 157 | - return $ecrire_config(substr($cfg,$p+2),$store); |
|
| 158 | - } |
|
| 153 | + // Brancher sur methodes externes si besoin |
|
| 154 | + if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 155 | + $methode = substr($cfg,0,$p); |
|
| 156 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 157 | + return $ecrire_config(substr($cfg,$p+2),$store); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 161 | - // il faut au moins un casier pour ecrire |
|
| 162 | - if (!$casier) return false; |
|
| 163 | - |
|
| 164 | - // trouvons ou creons le pointeur sur le casier |
|
| 165 | - $st = isset($GLOBALS[$table][$casier])?$GLOBALS[$table][$casier]:null; |
|
| 166 | - if (!is_array($st) AND ($sous_casier OR is_array($store))) { |
|
| 167 | - $st = unserialize($st); |
|
| 168 | - if ($st===false) { |
|
| 169 | - // ne rien creer si c'est une demande d'effacement |
|
| 170 | - if (is_null($store)) |
|
| 171 | - return false; |
|
| 172 | - $st=array(); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // si on a affaire a un sous caiser |
|
| 177 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 178 | - if ($c = $sous_casier) { |
|
| 179 | - $sc = &$st; |
|
| 180 | - $pointeurs = array(); |
|
| 181 | - while (count($c) AND $cc=array_shift($c)) { |
|
| 182 | - // creer l'entree si elle n'existe pas |
|
| 183 | - if (!isset($sc[$cc])) { |
|
| 184 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 185 | - // ne rien creer mais sortir |
|
| 186 | - if (is_null($store)) |
|
| 187 | - return false; |
|
| 188 | - $sc[$cc] = array(); |
|
| 189 | - } |
|
| 190 | - $pointeurs[$cc] = &$sc; |
|
| 191 | - $sc = &$sc[$cc]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // si c'est une demande d'effacement |
|
| 195 | - if (is_null($store)){ |
|
| 196 | - $c = $sous_casier; |
|
| 197 | - $sous = array_pop($c); |
|
| 198 | - // effacer, et remonter pour effacer les parents vides |
|
| 199 | - do { |
|
| 200 | - unset($pointeurs[$sous][$sous]); |
|
| 201 | - } while ($sous = array_pop($c) AND !count($pointeurs[$sous][$sous])); |
|
| 160 | + list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 161 | + // il faut au moins un casier pour ecrire |
|
| 162 | + if (!$casier) return false; |
|
| 163 | + |
|
| 164 | + // trouvons ou creons le pointeur sur le casier |
|
| 165 | + $st = isset($GLOBALS[$table][$casier])?$GLOBALS[$table][$casier]:null; |
|
| 166 | + if (!is_array($st) AND ($sous_casier OR is_array($store))) { |
|
| 167 | + $st = unserialize($st); |
|
| 168 | + if ($st===false) { |
|
| 169 | + // ne rien creer si c'est une demande d'effacement |
|
| 170 | + if (is_null($store)) |
|
| 171 | + return false; |
|
| 172 | + $st=array(); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // si on a affaire a un sous caiser |
|
| 177 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 178 | + if ($c = $sous_casier) { |
|
| 179 | + $sc = &$st; |
|
| 180 | + $pointeurs = array(); |
|
| 181 | + while (count($c) AND $cc=array_shift($c)) { |
|
| 182 | + // creer l'entree si elle n'existe pas |
|
| 183 | + if (!isset($sc[$cc])) { |
|
| 184 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 185 | + // ne rien creer mais sortir |
|
| 186 | + if (is_null($store)) |
|
| 187 | + return false; |
|
| 188 | + $sc[$cc] = array(); |
|
| 189 | + } |
|
| 190 | + $pointeurs[$cc] = &$sc; |
|
| 191 | + $sc = &$sc[$cc]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // si c'est une demande d'effacement |
|
| 195 | + if (is_null($store)){ |
|
| 196 | + $c = $sous_casier; |
|
| 197 | + $sous = array_pop($c); |
|
| 198 | + // effacer, et remonter pour effacer les parents vides |
|
| 199 | + do { |
|
| 200 | + unset($pointeurs[$sous][$sous]); |
|
| 201 | + } while ($sous = array_pop($c) AND !count($pointeurs[$sous][$sous])); |
|
| 202 | 202 | |
| 203 | - // si on a vide tous les sous casiers, |
|
| 204 | - // et que le casier est vide |
|
| 205 | - // vider aussi la meta |
|
| 206 | - if (!$sous AND !count($st)) |
|
| 207 | - $st = null; |
|
| 208 | - } |
|
| 209 | - // dans tous les autres cas, on ecrase |
|
| 210 | - else |
|
| 211 | - $sc = $store; |
|
| 212 | - |
|
| 213 | - // Maintenant que $st est modifiee |
|
| 214 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 215 | - $store = $st; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if (is_null($store)) { |
|
| 219 | - if (is_null($st) AND !$sous_casier) |
|
| 220 | - return false; // la config n'existait deja pas ! |
|
| 221 | - effacer_meta ($casier, $table); |
|
| 222 | - if (!count($GLOBALS[$table]) |
|
| 223 | - OR count($GLOBALS[$table])==1 AND isset($GLOBALS[$table]['charset'])) { |
|
| 224 | - effacer_meta('charset', $table); // enlevons cette meta |
|
| 225 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 229 | - else { |
|
| 230 | - if (!isset($GLOBALS[$table])) |
|
| 231 | - installer_table_meta($table); |
|
| 232 | - // si ce n'est pas une chaine |
|
| 233 | - // il faut serializer |
|
| 234 | - if (!is_string($store)) |
|
| 235 | - $store=serialize($store); |
|
| 236 | - ecrire_meta($casier, $store, null, $table); |
|
| 237 | - } |
|
| 238 | - // verifier que lire_config($cfg)==$store ? |
|
| 239 | - return true; |
|
| 203 | + // si on a vide tous les sous casiers, |
|
| 204 | + // et que le casier est vide |
|
| 205 | + // vider aussi la meta |
|
| 206 | + if (!$sous AND !count($st)) |
|
| 207 | + $st = null; |
|
| 208 | + } |
|
| 209 | + // dans tous les autres cas, on ecrase |
|
| 210 | + else |
|
| 211 | + $sc = $store; |
|
| 212 | + |
|
| 213 | + // Maintenant que $st est modifiee |
|
| 214 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 215 | + $store = $st; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if (is_null($store)) { |
|
| 219 | + if (is_null($st) AND !$sous_casier) |
|
| 220 | + return false; // la config n'existait deja pas ! |
|
| 221 | + effacer_meta ($casier, $table); |
|
| 222 | + if (!count($GLOBALS[$table]) |
|
| 223 | + OR count($GLOBALS[$table])==1 AND isset($GLOBALS[$table]['charset'])) { |
|
| 224 | + effacer_meta('charset', $table); // enlevons cette meta |
|
| 225 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 229 | + else { |
|
| 230 | + if (!isset($GLOBALS[$table])) |
|
| 231 | + installer_table_meta($table); |
|
| 232 | + // si ce n'est pas une chaine |
|
| 233 | + // il faut serializer |
|
| 234 | + if (!is_string($store)) |
|
| 235 | + $store=serialize($store); |
|
| 236 | + ecrire_meta($casier, $store, null, $table); |
|
| 237 | + } |
|
| 238 | + // verifier que lire_config($cfg)==$store ? |
|
| 239 | + return true; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -250,12 +250,12 @@ discard block |
||
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | 252 | function ecrire_config_metapack_dist($cfg,$store) { |
| 253 | - // cas particulier en metapack:: |
|
| 254 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 255 | - // intacte en sortie ... |
|
| 256 | - if (is_string($store) AND strpos($store,':') AND unserialize($store)) |
|
| 257 | - $store = serialize($store); |
|
| 258 | - return ecrire_config($cfg, $store); |
|
| 253 | + // cas particulier en metapack:: |
|
| 254 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 255 | + // intacte en sortie ... |
|
| 256 | + if (is_string($store) AND strpos($store,':') AND unserialize($store)) |
|
| 257 | + $store = serialize($store); |
|
| 258 | + return ecrire_config($cfg, $store); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -264,75 +264,75 @@ discard block |
||
| 264 | 264 | * @return bool |
| 265 | 265 | */ |
| 266 | 266 | function effacer_config($cfg){ |
| 267 | - ecrire_config($cfg, null); |
|
| 268 | - return true; |
|
| 267 | + ecrire_config($cfg, null); |
|
| 268 | + return true; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | function lister_configurer($exclure = array()){ |
| 273 | - return array(); |
|
| 273 | + return array(); |
|
| 274 | 274 | |
| 275 | - // lister les pages de config deja dans les menus |
|
| 276 | - $deja = array(); |
|
| 277 | - foreach($exclure as $id=>$b) { |
|
| 278 | - $url = ($b['url'] ? $b['url'] : $id); |
|
| 279 | - if (!$b['url'] or !isset($exclure[$url])) { |
|
| 280 | - if (strncmp($url,'configurer_',11)==0) { |
|
| 281 | - $deja[$url] = $b; |
|
| 282 | - } elseif($b['url']=='configurer' AND preg_match(',cfg=([a-z0-9_]+),i',$b['args'],$match)) { |
|
| 283 | - $deja["configurer_".$match[1]] = $b; |
|
| 284 | - } |
|
| 285 | - } |
|
| 275 | + // lister les pages de config deja dans les menus |
|
| 276 | + $deja = array(); |
|
| 277 | + foreach($exclure as $id=>$b) { |
|
| 278 | + $url = ($b['url'] ? $b['url'] : $id); |
|
| 279 | + if (!$b['url'] or !isset($exclure[$url])) { |
|
| 280 | + if (strncmp($url,'configurer_',11)==0) { |
|
| 281 | + $deja[$url] = $b; |
|
| 282 | + } elseif($b['url']=='configurer' AND preg_match(',cfg=([a-z0-9_]+),i',$b['args'],$match)) { |
|
| 283 | + $deja["configurer_".$match[1]] = $b; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - } |
|
| 288 | - $exclure = $exclure + $deja; |
|
| 289 | - |
|
| 290 | - $icone_defaut = "images/configuration-16.png"; |
|
| 291 | - $liste = array(); |
|
| 292 | - $skels = array(); |
|
| 293 | - $forms = array(); |
|
| 294 | - |
|
| 295 | - // trouver toutes les pages configurer_xxx de l'espace prive |
|
| 296 | - // et construire un tableau des entrees qui ne sont pas dans $deja |
|
| 297 | - $pages = find_all_in_path("prive/squelettes/contenu/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
|
| 298 | - |
|
| 299 | - foreach($pages as $page) { |
|
| 300 | - $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 301 | - if (!isset($exclure[$configurer])) { |
|
| 302 | - $liste[$configurer] = array( |
|
| 303 | - 'parent' => 'bando_configuration', |
|
| 304 | - 'url' => $configurer, |
|
| 305 | - 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 306 | - 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - $skels[$configurer] = $page; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // analyser la liste des $skels pour voir les #FORMULAIRE_CONFIGURER_ inclus |
|
| 313 | - foreach($skels as $file) { |
|
| 314 | - $forms = array_merge($forms, lister_formulaires_configurer($file)); |
|
| 315 | - } |
|
| 316 | - $forms = array_flip($forms); |
|
| 317 | - |
|
| 318 | - // trouver tous les formulaires/configurer_ |
|
| 319 | - // et construire un tableau des entrees |
|
| 320 | - $pages = find_all_in_path("formulaires/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
|
| 321 | - foreach($pages as $page) { |
|
| 322 | - $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 323 | - if (!isset($forms[$configurer]) |
|
| 324 | - AND !isset($liste[$configurer]) |
|
| 325 | - AND !isset($exclure[$configurer])) |
|
| 326 | - $liste[$configurer] = array( |
|
| 327 | - 'parent' => 'bando_configuration', |
|
| 328 | - 'url' => 'configurer', |
|
| 329 | - 'args' => 'cfg='.substr($configurer,11), |
|
| 330 | - 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 331 | - 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $liste; |
|
| 287 | + } |
|
| 288 | + $exclure = $exclure + $deja; |
|
| 289 | + |
|
| 290 | + $icone_defaut = "images/configuration-16.png"; |
|
| 291 | + $liste = array(); |
|
| 292 | + $skels = array(); |
|
| 293 | + $forms = array(); |
|
| 294 | + |
|
| 295 | + // trouver toutes les pages configurer_xxx de l'espace prive |
|
| 296 | + // et construire un tableau des entrees qui ne sont pas dans $deja |
|
| 297 | + $pages = find_all_in_path("prive/squelettes/contenu/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
|
| 298 | + |
|
| 299 | + foreach($pages as $page) { |
|
| 300 | + $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 301 | + if (!isset($exclure[$configurer])) { |
|
| 302 | + $liste[$configurer] = array( |
|
| 303 | + 'parent' => 'bando_configuration', |
|
| 304 | + 'url' => $configurer, |
|
| 305 | + 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 306 | + 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + $skels[$configurer] = $page; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // analyser la liste des $skels pour voir les #FORMULAIRE_CONFIGURER_ inclus |
|
| 313 | + foreach($skels as $file) { |
|
| 314 | + $forms = array_merge($forms, lister_formulaires_configurer($file)); |
|
| 315 | + } |
|
| 316 | + $forms = array_flip($forms); |
|
| 317 | + |
|
| 318 | + // trouver tous les formulaires/configurer_ |
|
| 319 | + // et construire un tableau des entrees |
|
| 320 | + $pages = find_all_in_path("formulaires/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
|
| 321 | + foreach($pages as $page) { |
|
| 322 | + $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 323 | + if (!isset($forms[$configurer]) |
|
| 324 | + AND !isset($liste[$configurer]) |
|
| 325 | + AND !isset($exclure[$configurer])) |
|
| 326 | + $liste[$configurer] = array( |
|
| 327 | + 'parent' => 'bando_configuration', |
|
| 328 | + 'url' => 'configurer', |
|
| 329 | + 'args' => 'cfg='.substr($configurer,11), |
|
| 330 | + 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 331 | + 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $liste; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -344,92 +344,92 @@ discard block |
||
| 344 | 344 | * @return array liste des formulaires trouves |
| 345 | 345 | **/ |
| 346 | 346 | function lister_formulaires_configurer($file) { |
| 347 | - $forms = array(); |
|
| 347 | + $forms = array(); |
|
| 348 | 348 | |
| 349 | - lire_fichier($file, $skel); |
|
| 350 | - if (preg_match_all(",#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),", $skel, $matches,PREG_SET_ORDER)) { |
|
| 351 | - $matches = array_map('end',$matches); |
|
| 352 | - $matches = array_map('strtolower',$matches); |
|
| 353 | - $forms = array_merge($forms,$matches); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // evaluer le fond en lui passant un exec coherent pour que les pipelines le reconnaissent |
|
| 357 | - // et reperer les formulaires CVT configurer_xx insereres par les plugins via pipeline |
|
| 358 | - $config = basename(substr($file,0,-strlen("."._EXTENSION_SQUELETTES))); |
|
| 359 | - spip_log('Calcul de '."prive/squelettes/contenu/$config"); |
|
| 360 | - $fond = recuperer_fond("prive/squelettes/contenu/$config", array("exec" => $config)); |
|
| 349 | + lire_fichier($file, $skel); |
|
| 350 | + if (preg_match_all(",#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),", $skel, $matches,PREG_SET_ORDER)) { |
|
| 351 | + $matches = array_map('end',$matches); |
|
| 352 | + $matches = array_map('strtolower',$matches); |
|
| 353 | + $forms = array_merge($forms,$matches); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // evaluer le fond en lui passant un exec coherent pour que les pipelines le reconnaissent |
|
| 357 | + // et reperer les formulaires CVT configurer_xx insereres par les plugins via pipeline |
|
| 358 | + $config = basename(substr($file,0,-strlen("."._EXTENSION_SQUELETTES))); |
|
| 359 | + spip_log('Calcul de '."prive/squelettes/contenu/$config"); |
|
| 360 | + $fond = recuperer_fond("prive/squelettes/contenu/$config", array("exec" => $config)); |
|
| 361 | 361 | |
| 362 | - // passer dans le pipeline affiche_milieu pour que les plugins puissent ajouter leur formulaires... |
|
| 363 | - // et donc que l'on puisse les referencer aussi ! |
|
| 364 | - $fond = pipeline('affiche_milieu', array('args'=>array("exec" => $config),'data'=>$fond)); |
|
| 365 | - |
|
| 366 | - // recuperer les noms des formulaires presents. |
|
| 367 | - if (is_array($inputs = extraire_balises($fond,"input"))) { |
|
| 368 | - foreach($inputs as $i) { |
|
| 369 | - if (extraire_attribut($i,'name')=='formulaire_action') { |
|
| 370 | - $forms[] = ($c=extraire_attribut($i,'value')); |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - return $forms; |
|
| 362 | + // passer dans le pipeline affiche_milieu pour que les plugins puissent ajouter leur formulaires... |
|
| 363 | + // et donc que l'on puisse les referencer aussi ! |
|
| 364 | + $fond = pipeline('affiche_milieu', array('args'=>array("exec" => $config),'data'=>$fond)); |
|
| 365 | + |
|
| 366 | + // recuperer les noms des formulaires presents. |
|
| 367 | + if (is_array($inputs = extraire_balises($fond,"input"))) { |
|
| 368 | + foreach($inputs as $i) { |
|
| 369 | + if (extraire_attribut($i,'name')=='formulaire_action') { |
|
| 370 | + $forms[] = ($c=extraire_attribut($i,'value')); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + return $forms; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | |
| 378 | 378 | // http://doc.spip.org/@liste_metas |
| 379 | 379 | function liste_metas() |
| 380 | 380 | { |
| 381 | - return pipeline('configurer_liste_metas', array( |
|
| 382 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 383 | - 'slogan_site' => '', |
|
| 384 | - 'adresse_site' => preg_replace(",/$,", "", url_de_base()), |
|
| 385 | - 'descriptif_site' => '', |
|
| 386 | - 'activer_logos' => 'oui', |
|
| 387 | - 'activer_logos_survol' => 'non', |
|
| 388 | - 'articles_surtitre' => 'non', |
|
| 389 | - 'articles_soustitre' => 'non', |
|
| 390 | - 'articles_descriptif' => 'non', |
|
| 391 | - 'articles_chapeau' => 'non', |
|
| 392 | - 'articles_texte' => 'oui', |
|
| 393 | - 'articles_ps' => 'non', |
|
| 394 | - 'articles_redac' => 'non', |
|
| 395 | - 'post_dates' => 'non', |
|
| 396 | - 'articles_urlref' => 'non', |
|
| 397 | - 'articles_redirection' => 'non', |
|
| 398 | - 'creer_preview' => 'non', |
|
| 399 | - 'taille_preview' => 150, |
|
| 400 | - 'articles_modif' => 'non', |
|
| 401 | - |
|
| 402 | - 'rubriques_descriptif' => 'non', |
|
| 403 | - 'rubriques_texte' => 'oui', |
|
| 404 | - |
|
| 405 | - 'accepter_inscriptions' => 'non', |
|
| 406 | - 'accepter_visiteurs' => 'non', |
|
| 407 | - 'prevenir_auteurs' => 'non', |
|
| 408 | - 'suivi_edito' => 'non', |
|
| 409 | - 'adresse_suivi' =>'', |
|
| 410 | - 'adresse_suivi_inscription' =>'', |
|
| 411 | - 'adresse_neuf' => '', |
|
| 412 | - 'jours_neuf' => '', |
|
| 413 | - 'quoi_de_neuf' => 'non', |
|
| 414 | - 'preview' => ',0minirezo,1comite,', |
|
| 415 | - |
|
| 416 | - 'syndication_integrale' => 'oui', |
|
| 417 | - 'charset' => _DEFAULT_CHARSET, |
|
| 418 | - 'dir_img' => substr(_DIR_IMG,strlen(_DIR_RACINE)), |
|
| 419 | - |
|
| 420 | - 'multi_rubriques' => 'non', |
|
| 421 | - 'multi_secteurs' => 'non', |
|
| 422 | - 'gerer_trad' => 'non', |
|
| 423 | - 'langues_multilingue' => '', |
|
| 424 | - |
|
| 425 | - 'version_html_max' => 'html4', |
|
| 426 | - |
|
| 427 | - 'type_urls' => 'page', |
|
| 428 | - |
|
| 429 | - 'email_envoi' => '', |
|
| 430 | - 'email_webmaster' => '', |
|
| 431 | - 'auto_compress_http'=>'non', |
|
| 432 | - )); |
|
| 381 | + return pipeline('configurer_liste_metas', array( |
|
| 382 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 383 | + 'slogan_site' => '', |
|
| 384 | + 'adresse_site' => preg_replace(",/$,", "", url_de_base()), |
|
| 385 | + 'descriptif_site' => '', |
|
| 386 | + 'activer_logos' => 'oui', |
|
| 387 | + 'activer_logos_survol' => 'non', |
|
| 388 | + 'articles_surtitre' => 'non', |
|
| 389 | + 'articles_soustitre' => 'non', |
|
| 390 | + 'articles_descriptif' => 'non', |
|
| 391 | + 'articles_chapeau' => 'non', |
|
| 392 | + 'articles_texte' => 'oui', |
|
| 393 | + 'articles_ps' => 'non', |
|
| 394 | + 'articles_redac' => 'non', |
|
| 395 | + 'post_dates' => 'non', |
|
| 396 | + 'articles_urlref' => 'non', |
|
| 397 | + 'articles_redirection' => 'non', |
|
| 398 | + 'creer_preview' => 'non', |
|
| 399 | + 'taille_preview' => 150, |
|
| 400 | + 'articles_modif' => 'non', |
|
| 401 | + |
|
| 402 | + 'rubriques_descriptif' => 'non', |
|
| 403 | + 'rubriques_texte' => 'oui', |
|
| 404 | + |
|
| 405 | + 'accepter_inscriptions' => 'non', |
|
| 406 | + 'accepter_visiteurs' => 'non', |
|
| 407 | + 'prevenir_auteurs' => 'non', |
|
| 408 | + 'suivi_edito' => 'non', |
|
| 409 | + 'adresse_suivi' =>'', |
|
| 410 | + 'adresse_suivi_inscription' =>'', |
|
| 411 | + 'adresse_neuf' => '', |
|
| 412 | + 'jours_neuf' => '', |
|
| 413 | + 'quoi_de_neuf' => 'non', |
|
| 414 | + 'preview' => ',0minirezo,1comite,', |
|
| 415 | + |
|
| 416 | + 'syndication_integrale' => 'oui', |
|
| 417 | + 'charset' => _DEFAULT_CHARSET, |
|
| 418 | + 'dir_img' => substr(_DIR_IMG,strlen(_DIR_RACINE)), |
|
| 419 | + |
|
| 420 | + 'multi_rubriques' => 'non', |
|
| 421 | + 'multi_secteurs' => 'non', |
|
| 422 | + 'gerer_trad' => 'non', |
|
| 423 | + 'langues_multilingue' => '', |
|
| 424 | + |
|
| 425 | + 'version_html_max' => 'html4', |
|
| 426 | + |
|
| 427 | + 'type_urls' => 'page', |
|
| 428 | + |
|
| 429 | + 'email_envoi' => '', |
|
| 430 | + 'email_webmaster' => '', |
|
| 431 | + 'auto_compress_http'=>'non', |
|
| 432 | + )); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // mets les meta a des valeurs conventionnelles quand elles sont vides |
@@ -438,21 +438,21 @@ discard block |
||
| 438 | 438 | // http://doc.spip.org/@actualise_metas |
| 439 | 439 | function actualise_metas($liste_meta) |
| 440 | 440 | { |
| 441 | - $meta_serveur = |
|
| 442 | - array('version_installee','adresse_site','alea_ephemere_ancien','alea_ephemere','alea_ephemere_date','langue_site','langues_proposees','date_calcul_rubriques','derniere_modif','optimiser_table','drapeau_edition','creer_preview','taille_preview','creer_htpasswd','creer_htaccess','gd_formats_read','gd_formats', |
|
| 443 | - 'netpbm_formats','formats_graphiques','image_process','plugin_header','plugin'); |
|
| 444 | - // verifier le impt=non |
|
| 445 | - sql_updateq('spip_meta',array('impt'=>'non'),sql_in('nom',$meta_serveur)); |
|
| 446 | - |
|
| 447 | - while (list($nom, $valeur) = each($liste_meta)) { |
|
| 448 | - if (!$GLOBALS['meta'][$nom]) { |
|
| 449 | - ecrire_meta($nom, $valeur); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - include_spip('inc/rubriques'); |
|
| 454 | - $langues = calculer_langues_utilisees(); |
|
| 455 | - ecrire_meta('langues_utilisees', $langues); |
|
| 441 | + $meta_serveur = |
|
| 442 | + array('version_installee','adresse_site','alea_ephemere_ancien','alea_ephemere','alea_ephemere_date','langue_site','langues_proposees','date_calcul_rubriques','derniere_modif','optimiser_table','drapeau_edition','creer_preview','taille_preview','creer_htpasswd','creer_htaccess','gd_formats_read','gd_formats', |
|
| 443 | + 'netpbm_formats','formats_graphiques','image_process','plugin_header','plugin'); |
|
| 444 | + // verifier le impt=non |
|
| 445 | + sql_updateq('spip_meta',array('impt'=>'non'),sql_in('nom',$meta_serveur)); |
|
| 446 | + |
|
| 447 | + while (list($nom, $valeur) = each($liste_meta)) { |
|
| 448 | + if (!$GLOBALS['meta'][$nom]) { |
|
| 449 | + ecrire_meta($nom, $valeur); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + include_spip('inc/rubriques'); |
|
| 454 | + $langues = calculer_langues_utilisees(); |
|
| 455 | + ecrire_meta('langues_utilisees', $langues); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | |
@@ -464,17 +464,17 @@ discard block |
||
| 464 | 464 | // http://doc.spip.org/@appliquer_modifs_config |
| 465 | 465 | function appliquer_modifs_config($purger_skel=false) { |
| 466 | 466 | |
| 467 | - foreach(liste_metas() as $i => $v) { |
|
| 468 | - if (($x =_request($i))!==NULL) |
|
| 469 | - ecrire_meta($i, $x); |
|
| 470 | - elseif (!isset($GLOBALS['meta'][$i])) |
|
| 471 | - ecrire_meta($i, $v); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - if ($purger_skel) { |
|
| 475 | - include_spip('inc/invalideur'); |
|
| 476 | - purger_repertoire(_DIR_SKELS); |
|
| 477 | - } |
|
| 467 | + foreach(liste_metas() as $i => $v) { |
|
| 468 | + if (($x =_request($i))!==NULL) |
|
| 469 | + ecrire_meta($i, $x); |
|
| 470 | + elseif (!isset($GLOBALS['meta'][$i])) |
|
| 471 | + ecrire_meta($i, $v); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + if ($purger_skel) { |
|
| 475 | + include_spip('inc/invalideur'); |
|
| 476 | + purger_repertoire(_DIR_SKELS); |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -485,16 +485,16 @@ discard block |
||
| 485 | 485 | * @return void |
| 486 | 486 | */ |
| 487 | 487 | function appliquer_adresse_site($adresse_site){ |
| 488 | - if ($adresse_site!==NULL){ |
|
| 489 | - if (!strlen($adresse_site)) {$GLOBALS['profondeur_url']=_DIR_RESTREINT?0:1;$adresse_site = url_de_base();} |
|
| 490 | - $adresse_site = preg_replace(",/?\s*$,", "", $adresse_site); |
|
| 488 | + if ($adresse_site!==NULL){ |
|
| 489 | + if (!strlen($adresse_site)) {$GLOBALS['profondeur_url']=_DIR_RESTREINT?0:1;$adresse_site = url_de_base();} |
|
| 490 | + $adresse_site = preg_replace(",/?\s*$,", "", $adresse_site); |
|
| 491 | 491 | |
| 492 | - if (!preg_match(",^[\w]+://,Uims",$adresse_site)) |
|
| 493 | - $adresse_site = "http://$adresse_site"; |
|
| 492 | + if (!preg_match(",^[\w]+://,Uims",$adresse_site)) |
|
| 493 | + $adresse_site = "http://$adresse_site"; |
|
| 494 | 494 | |
| 495 | - ecrire_meta('adresse_site',$adresse_site); |
|
| 496 | - } |
|
| 497 | - return $adresse_site; |
|
| 495 | + ecrire_meta('adresse_site',$adresse_site); |
|
| 496 | + } |
|
| 497 | + return $adresse_site; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | ?> |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | * @param string $cfg |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | -function expliquer_config($cfg){ |
|
| 34 | +function expliquer_config($cfg) { |
|
| 35 | 35 | // par defaut, sur la table des meta |
| 36 | 36 | $table = 'meta'; |
| 37 | 37 | $casier = null; |
| 38 | 38 | $sous_casier = array(); |
| 39 | - if (strlen($cfg)){ |
|
| 40 | - $cfg = explode('/',$cfg); |
|
| 39 | + if (strlen($cfg)) { |
|
| 40 | + $cfg = explode('/', $cfg); |
|
| 41 | 41 | // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
| 42 | - if (!reset($cfg) AND count($cfg)>1) { |
|
| 42 | + if (!reset($cfg) AND count($cfg) > 1) { |
|
| 43 | 43 | array_shift($cfg); |
| 44 | 44 | $table = array_shift($cfg); |
| 45 | 45 | if (!isset($GLOBALS[$table])) |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | if (count($cfg)) |
| 53 | 53 | $sous_casier = $cfg; |
| 54 | 54 | } |
| 55 | - return array($table,$casier,$sous_casier); |
|
| 55 | + return array($table, $casier, $sous_casier); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -74,33 +74,33 @@ discard block |
||
| 74 | 74 | * @param boolean $unserialize n'affecte que le dépôt 'meta' |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | -function lire_config($cfg='', $def=null, $unserialize=true) { |
|
| 77 | +function lire_config($cfg = '', $def = null, $unserialize = true) { |
|
| 78 | 78 | // lire le stockage sous la forme /table/valeur |
| 79 | 79 | // ou valeur qui est en fait implicitement /meta/valeur |
| 80 | 80 | // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
| 81 | 81 | |
| 82 | 82 | // traiter en priorite le cas simple et frequent |
| 83 | 83 | // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
| 84 | - if ($cfg AND strpbrk($cfg,'/:')===false){ |
|
| 85 | - $r = isset($GLOBALS['meta'][$cfg])? |
|
| 84 | + if ($cfg AND strpbrk($cfg, '/:') === false) { |
|
| 85 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 86 | 86 | ((!$unserialize |
| 87 | 87 | // ne pas essayer de deserialiser autre chose qu'une chaine |
| 88 | 88 | OR !is_string($GLOBALS['meta'][$cfg]) |
| 89 | 89 | // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
| 90 | - OR strpos($GLOBALS['meta'][$cfg],':')===false |
|
| 91 | - OR ($t=unserialize($GLOBALS['meta'][$cfg]))===false)?$GLOBALS['meta'][$cfg]:$t) |
|
| 90 | + OR strpos($GLOBALS['meta'][$cfg], ':') === false |
|
| 91 | + OR ($t = unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 92 | 92 | :$def; |
| 93 | 93 | return $r; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Brancher sur methodes externes si besoin |
| 97 | - if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 98 | - $methode = substr($cfg,0,$p); |
|
| 97 | + if ($cfg AND $p = strpos($cfg, '::')) { |
|
| 98 | + $methode = substr($cfg, 0, $p); |
|
| 99 | 99 | $lire_config = charger_fonction($methode, 'lire_config'); |
| 100 | - return $lire_config(substr($cfg,$p+2),$def,$unserialize); |
|
| 100 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 103 | + list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 104 | 104 | |
| 105 | 105 | if (!isset($GLOBALS[$table])) |
| 106 | 106 | return $def; |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | // le deserializer si demande |
| 116 | 116 | // ou si on a besoin |
| 117 | 117 | // d'un sous casier |
| 118 | - $r = isset($r[$casier])?$r[$casier]:null; |
|
| 118 | + $r = isset($r[$casier]) ? $r[$casier] : null; |
|
| 119 | 119 | if (($unserialize OR count($sous_casier)) AND $r AND is_string($r)) |
| 120 | - $r = (($t=unserialize($r))===false?$r:$t); |
|
| 120 | + $r = (($t = unserialize($r)) === false ? $r : $t); |
|
| 121 | 121 | |
| 122 | 122 | // aller chercher le sous_casier |
| 123 | - while(!is_null($r) AND $casier = array_shift($sous_casier)) |
|
| 124 | - $r = isset($r[$casier])?$r[$casier]:null; |
|
| 123 | + while (!is_null($r) AND $casier = array_shift($sous_casier)) |
|
| 124 | + $r = isset($r[$casier]) ? $r[$casier] : null; |
|
| 125 | 125 | |
| 126 | 126 | if (is_null($r)) return $def; |
| 127 | 127 | return $r; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param bool $unserialize |
| 138 | 138 | * @return mixed |
| 139 | 139 | */ |
| 140 | -function lire_config_metapack_dist($cfg='', $def=null, $unserialize=true) { |
|
| 140 | +function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
|
| 141 | 141 | return lire_config($cfg, $def, $unserialize); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -149,27 +149,27 @@ discard block |
||
| 149 | 149 | * @param mixed $store |
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | -function ecrire_config($cfg,$store) { |
|
| 152 | +function ecrire_config($cfg, $store) { |
|
| 153 | 153 | // Brancher sur methodes externes si besoin |
| 154 | - if ($cfg AND $p=strpos($cfg,'::')){ |
|
| 155 | - $methode = substr($cfg,0,$p); |
|
| 154 | + if ($cfg AND $p = strpos($cfg, '::')) { |
|
| 155 | + $methode = substr($cfg, 0, $p); |
|
| 156 | 156 | $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
| 157 | - return $ecrire_config(substr($cfg,$p+2),$store); |
|
| 157 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - list($table,$casier,$sous_casier) = expliquer_config($cfg); |
|
| 160 | + list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 161 | 161 | // il faut au moins un casier pour ecrire |
| 162 | 162 | if (!$casier) return false; |
| 163 | 163 | |
| 164 | 164 | // trouvons ou creons le pointeur sur le casier |
| 165 | - $st = isset($GLOBALS[$table][$casier])?$GLOBALS[$table][$casier]:null; |
|
| 165 | + $st = isset($GLOBALS[$table][$casier]) ? $GLOBALS[$table][$casier] : null; |
|
| 166 | 166 | if (!is_array($st) AND ($sous_casier OR is_array($store))) { |
| 167 | 167 | $st = unserialize($st); |
| 168 | - if ($st===false) { |
|
| 168 | + if ($st === false) { |
|
| 169 | 169 | // ne rien creer si c'est une demande d'effacement |
| 170 | 170 | if (is_null($store)) |
| 171 | 171 | return false; |
| 172 | - $st=array(); |
|
| 172 | + $st = array(); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | if ($c = $sous_casier) { |
| 179 | 179 | $sc = &$st; |
| 180 | 180 | $pointeurs = array(); |
| 181 | - while (count($c) AND $cc=array_shift($c)) { |
|
| 181 | + while (count($c) AND $cc = array_shift($c)) { |
|
| 182 | 182 | // creer l'entree si elle n'existe pas |
| 183 | 183 | if (!isset($sc[$cc])) { |
| 184 | 184 | // si on essaye d'effacer une config qui n'existe pas |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // si c'est une demande d'effacement |
| 195 | - if (is_null($store)){ |
|
| 195 | + if (is_null($store)) { |
|
| 196 | 196 | $c = $sous_casier; |
| 197 | 197 | $sous = array_pop($c); |
| 198 | 198 | // effacer, et remonter pour effacer les parents vides |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | if (is_null($store)) { |
| 219 | 219 | if (is_null($st) AND !$sous_casier) |
| 220 | 220 | return false; // la config n'existait deja pas ! |
| 221 | - effacer_meta ($casier, $table); |
|
| 221 | + effacer_meta($casier, $table); |
|
| 222 | 222 | if (!count($GLOBALS[$table]) |
| 223 | - OR count($GLOBALS[$table])==1 AND isset($GLOBALS[$table]['charset'])) { |
|
| 223 | + OR count($GLOBALS[$table]) == 1 AND isset($GLOBALS[$table]['charset'])) { |
|
| 224 | 224 | effacer_meta('charset', $table); // enlevons cette meta |
| 225 | 225 | supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
| 226 | 226 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | // si ce n'est pas une chaine |
| 233 | 233 | // il faut serializer |
| 234 | 234 | if (!is_string($store)) |
| 235 | - $store=serialize($store); |
|
| 235 | + $store = serialize($store); |
|
| 236 | 236 | ecrire_meta($casier, $store, null, $table); |
| 237 | 237 | } |
| 238 | 238 | // verifier que lire_config($cfg)==$store ? |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | * @param mixed $store |
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | -function ecrire_config_metapack_dist($cfg,$store) { |
|
| 252 | +function ecrire_config_metapack_dist($cfg, $store) { |
|
| 253 | 253 | // cas particulier en metapack:: |
| 254 | 254 | // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
| 255 | 255 | // intacte en sortie ... |
| 256 | - if (is_string($store) AND strpos($store,':') AND unserialize($store)) |
|
| 256 | + if (is_string($store) AND strpos($store, ':') AND unserialize($store)) |
|
| 257 | 257 | $store = serialize($store); |
| 258 | 258 | return ecrire_config($cfg, $store); |
| 259 | 259 | } |
@@ -263,23 +263,23 @@ discard block |
||
| 263 | 263 | * @param string $cfg |
| 264 | 264 | * @return bool |
| 265 | 265 | */ |
| 266 | -function effacer_config($cfg){ |
|
| 266 | +function effacer_config($cfg) { |
|
| 267 | 267 | ecrire_config($cfg, null); |
| 268 | 268 | return true; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
| 272 | -function lister_configurer($exclure = array()){ |
|
| 272 | +function lister_configurer($exclure = array()) { |
|
| 273 | 273 | return array(); |
| 274 | 274 | |
| 275 | 275 | // lister les pages de config deja dans les menus |
| 276 | 276 | $deja = array(); |
| 277 | - foreach($exclure as $id=>$b) { |
|
| 277 | + foreach ($exclure as $id=>$b) { |
|
| 278 | 278 | $url = ($b['url'] ? $b['url'] : $id); |
| 279 | 279 | if (!$b['url'] or !isset($exclure[$url])) { |
| 280 | - if (strncmp($url,'configurer_',11)==0) { |
|
| 280 | + if (strncmp($url, 'configurer_', 11) == 0) { |
|
| 281 | 281 | $deja[$url] = $b; |
| 282 | - } elseif($b['url']=='configurer' AND preg_match(',cfg=([a-z0-9_]+),i',$b['args'],$match)) { |
|
| 282 | + } elseif ($b['url'] == 'configurer' AND preg_match(',cfg=([a-z0-9_]+),i', $b['args'], $match)) { |
|
| 283 | 283 | $deja["configurer_".$match[1]] = $b; |
| 284 | 284 | } |
| 285 | 285 | } |
@@ -296,21 +296,21 @@ discard block |
||
| 296 | 296 | // et construire un tableau des entrees qui ne sont pas dans $deja |
| 297 | 297 | $pages = find_all_in_path("prive/squelettes/contenu/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
| 298 | 298 | |
| 299 | - foreach($pages as $page) { |
|
| 300 | - $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 299 | + foreach ($pages as $page) { |
|
| 300 | + $configurer = basename($page, "."._EXTENSION_SQUELETTES); |
|
| 301 | 301 | if (!isset($exclure[$configurer])) { |
| 302 | 302 | $liste[$configurer] = array( |
| 303 | 303 | 'parent' => 'bando_configuration', |
| 304 | 304 | 'url' => $configurer, |
| 305 | 305 | 'titre' => _T("configurer:{$configurer}_titre"), |
| 306 | - 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 306 | + 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 307 | 307 | ); |
| 308 | 308 | } |
| 309 | 309 | $skels[$configurer] = $page; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // analyser la liste des $skels pour voir les #FORMULAIRE_CONFIGURER_ inclus |
| 313 | - foreach($skels as $file) { |
|
| 313 | + foreach ($skels as $file) { |
|
| 314 | 314 | $forms = array_merge($forms, lister_formulaires_configurer($file)); |
| 315 | 315 | } |
| 316 | 316 | $forms = array_flip($forms); |
@@ -318,17 +318,17 @@ discard block |
||
| 318 | 318 | // trouver tous les formulaires/configurer_ |
| 319 | 319 | // et construire un tableau des entrees |
| 320 | 320 | $pages = find_all_in_path("formulaires/", "configurer_.*[.]"._EXTENSION_SQUELETTES.'$'); |
| 321 | - foreach($pages as $page) { |
|
| 322 | - $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
|
| 321 | + foreach ($pages as $page) { |
|
| 322 | + $configurer = basename($page, "."._EXTENSION_SQUELETTES); |
|
| 323 | 323 | if (!isset($forms[$configurer]) |
| 324 | 324 | AND !isset($liste[$configurer]) |
| 325 | 325 | AND !isset($exclure[$configurer])) |
| 326 | 326 | $liste[$configurer] = array( |
| 327 | 327 | 'parent' => 'bando_configuration', |
| 328 | 328 | 'url' => 'configurer', |
| 329 | - 'args' => 'cfg='.substr($configurer,11), |
|
| 329 | + 'args' => 'cfg='.substr($configurer, 11), |
|
| 330 | 330 | 'titre' => _T("configurer:{$configurer}_titre"), |
| 331 | - 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
|
| 331 | + 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 332 | 332 | ); |
| 333 | 333 | } |
| 334 | 334 | |
@@ -347,27 +347,27 @@ discard block |
||
| 347 | 347 | $forms = array(); |
| 348 | 348 | |
| 349 | 349 | lire_fichier($file, $skel); |
| 350 | - if (preg_match_all(",#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),", $skel, $matches,PREG_SET_ORDER)) { |
|
| 351 | - $matches = array_map('end',$matches); |
|
| 352 | - $matches = array_map('strtolower',$matches); |
|
| 353 | - $forms = array_merge($forms,$matches); |
|
| 350 | + if (preg_match_all(",#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),", $skel, $matches, PREG_SET_ORDER)) { |
|
| 351 | + $matches = array_map('end', $matches); |
|
| 352 | + $matches = array_map('strtolower', $matches); |
|
| 353 | + $forms = array_merge($forms, $matches); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // evaluer le fond en lui passant un exec coherent pour que les pipelines le reconnaissent |
| 357 | 357 | // et reperer les formulaires CVT configurer_xx insereres par les plugins via pipeline |
| 358 | - $config = basename(substr($file,0,-strlen("."._EXTENSION_SQUELETTES))); |
|
| 358 | + $config = basename(substr($file, 0, -strlen("."._EXTENSION_SQUELETTES))); |
|
| 359 | 359 | spip_log('Calcul de '."prive/squelettes/contenu/$config"); |
| 360 | 360 | $fond = recuperer_fond("prive/squelettes/contenu/$config", array("exec" => $config)); |
| 361 | 361 | |
| 362 | 362 | // passer dans le pipeline affiche_milieu pour que les plugins puissent ajouter leur formulaires... |
| 363 | 363 | // et donc que l'on puisse les referencer aussi ! |
| 364 | - $fond = pipeline('affiche_milieu', array('args'=>array("exec" => $config),'data'=>$fond)); |
|
| 364 | + $fond = pipeline('affiche_milieu', array('args'=>array("exec" => $config), 'data'=>$fond)); |
|
| 365 | 365 | |
| 366 | 366 | // recuperer les noms des formulaires presents. |
| 367 | - if (is_array($inputs = extraire_balises($fond,"input"))) { |
|
| 368 | - foreach($inputs as $i) { |
|
| 369 | - if (extraire_attribut($i,'name')=='formulaire_action') { |
|
| 370 | - $forms[] = ($c=extraire_attribut($i,'value')); |
|
| 367 | + if (is_array($inputs = extraire_balises($fond, "input"))) { |
|
| 368 | + foreach ($inputs as $i) { |
|
| 369 | + if (extraire_attribut($i, 'name') == 'formulaire_action') { |
|
| 370 | + $forms[] = ($c = extraire_attribut($i, 'value')); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | |
| 416 | 416 | 'syndication_integrale' => 'oui', |
| 417 | 417 | 'charset' => _DEFAULT_CHARSET, |
| 418 | - 'dir_img' => substr(_DIR_IMG,strlen(_DIR_RACINE)), |
|
| 418 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 419 | 419 | |
| 420 | 420 | 'multi_rubriques' => 'non', |
| 421 | 421 | 'multi_secteurs' => 'non', |
@@ -439,10 +439,10 @@ discard block |
||
| 439 | 439 | function actualise_metas($liste_meta) |
| 440 | 440 | { |
| 441 | 441 | $meta_serveur = |
| 442 | - array('version_installee','adresse_site','alea_ephemere_ancien','alea_ephemere','alea_ephemere_date','langue_site','langues_proposees','date_calcul_rubriques','derniere_modif','optimiser_table','drapeau_edition','creer_preview','taille_preview','creer_htpasswd','creer_htaccess','gd_formats_read','gd_formats', |
|
| 443 | - 'netpbm_formats','formats_graphiques','image_process','plugin_header','plugin'); |
|
| 442 | + array('version_installee', 'adresse_site', 'alea_ephemere_ancien', 'alea_ephemere', 'alea_ephemere_date', 'langue_site', 'langues_proposees', 'date_calcul_rubriques', 'derniere_modif', 'optimiser_table', 'drapeau_edition', 'creer_preview', 'taille_preview', 'creer_htpasswd', 'creer_htaccess', 'gd_formats_read', 'gd_formats', |
|
| 443 | + 'netpbm_formats', 'formats_graphiques', 'image_process', 'plugin_header', 'plugin'); |
|
| 444 | 444 | // verifier le impt=non |
| 445 | - sql_updateq('spip_meta',array('impt'=>'non'),sql_in('nom',$meta_serveur)); |
|
| 445 | + sql_updateq('spip_meta', array('impt'=>'non'), sql_in('nom', $meta_serveur)); |
|
| 446 | 446 | |
| 447 | 447 | while (list($nom, $valeur) = each($liste_meta)) { |
| 448 | 448 | if (!$GLOBALS['meta'][$nom]) { |
@@ -462,12 +462,12 @@ discard block |
||
| 462 | 462 | // |
| 463 | 463 | |
| 464 | 464 | // http://doc.spip.org/@appliquer_modifs_config |
| 465 | -function appliquer_modifs_config($purger_skel=false) { |
|
| 465 | +function appliquer_modifs_config($purger_skel = false) { |
|
| 466 | 466 | |
| 467 | - foreach(liste_metas() as $i => $v) { |
|
| 468 | - if (($x =_request($i))!==NULL) |
|
| 467 | + foreach (liste_metas() as $i => $v) { |
|
| 468 | + if (($x = _request($i)) !== NULL) |
|
| 469 | 469 | ecrire_meta($i, $x); |
| 470 | - elseif (!isset($GLOBALS['meta'][$i])) |
|
| 470 | + elseif (!isset($GLOBALS['meta'][$i])) |
|
| 471 | 471 | ecrire_meta($i, $v); |
| 472 | 472 | } |
| 473 | 473 | |
@@ -484,15 +484,15 @@ discard block |
||
| 484 | 484 | * @param $adresse_site |
| 485 | 485 | * @return void |
| 486 | 486 | */ |
| 487 | -function appliquer_adresse_site($adresse_site){ |
|
| 488 | - if ($adresse_site!==NULL){ |
|
| 489 | - if (!strlen($adresse_site)) {$GLOBALS['profondeur_url']=_DIR_RESTREINT?0:1;$adresse_site = url_de_base();} |
|
| 487 | +function appliquer_adresse_site($adresse_site) { |
|
| 488 | + if ($adresse_site !== NULL) { |
|
| 489 | + if (!strlen($adresse_site)) {$GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; $adresse_site = url_de_base(); } |
|
| 490 | 490 | $adresse_site = preg_replace(",/?\s*$,", "", $adresse_site); |
| 491 | 491 | |
| 492 | - if (!preg_match(",^[\w]+://,Uims",$adresse_site)) |
|
| 492 | + if (!preg_match(",^[\w]+://,Uims", $adresse_site)) |
|
| 493 | 493 | $adresse_site = "http://$adresse_site"; |
| 494 | 494 | |
| 495 | - ecrire_meta('adresse_site',$adresse_site); |
|
| 495 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 496 | 496 | } |
| 497 | 497 | return $adresse_site; |
| 498 | 498 | } |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | |
| 16 | 18 | /** |
@@ -42,15 +44,18 @@ discard block |
||
| 42 | 44 | if (!reset($cfg) AND count($cfg)>1) { |
| 43 | 45 | array_shift($cfg); |
| 44 | 46 | $table = array_shift($cfg); |
| 45 | - if (!isset($GLOBALS[$table])) |
|
| 46 | - lire_metas($table); |
|
| 47 | + if (!isset($GLOBALS[$table])) { |
|
| 48 | + lire_metas($table); |
|
| 49 | + } |
|
| 47 | 50 | } |
| 48 | 51 | // si on a demande #CONFIG{/meta,'',0} |
| 49 | - if (count($cfg)) |
|
| 50 | - $casier = array_shift($cfg); |
|
| 52 | + if (count($cfg)) { |
|
| 53 | + $casier = array_shift($cfg); |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | - if (count($cfg)) |
|
| 53 | - $sous_casier = $cfg; |
|
| 56 | + if (count($cfg)) { |
|
| 57 | + $sous_casier = $cfg; |
|
| 58 | + } |
|
| 54 | 59 | } |
| 55 | 60 | return array($table,$casier,$sous_casier); |
| 56 | 61 | } |
@@ -102,28 +107,34 @@ discard block |
||
| 102 | 107 | |
| 103 | 108 | list($table,$casier,$sous_casier) = expliquer_config($cfg); |
| 104 | 109 | |
| 105 | - if (!isset($GLOBALS[$table])) |
|
| 106 | - return $def; |
|
| 110 | + if (!isset($GLOBALS[$table])) { |
|
| 111 | + return $def; |
|
| 112 | + } |
|
| 107 | 113 | |
| 108 | 114 | $r = $GLOBALS[$table]; |
| 109 | 115 | |
| 110 | 116 | // si on a demande #CONFIG{/meta,'',0} |
| 111 | - if (!$casier) |
|
| 112 | - return $unserialize ? $r : serialize($r); |
|
| 117 | + if (!$casier) { |
|
| 118 | + return $unserialize ? $r : serialize($r); |
|
| 119 | + } |
|
| 113 | 120 | |
| 114 | 121 | // casier principal : |
| 115 | 122 | // le deserializer si demande |
| 116 | 123 | // ou si on a besoin |
| 117 | 124 | // d'un sous casier |
| 118 | 125 | $r = isset($r[$casier])?$r[$casier]:null; |
| 119 | - if (($unserialize OR count($sous_casier)) AND $r AND is_string($r)) |
|
| 120 | - $r = (($t=unserialize($r))===false?$r:$t); |
|
| 126 | + if (($unserialize OR count($sous_casier)) AND $r AND is_string($r)) { |
|
| 127 | + $r = (($t=unserialize($r))===false?$r:$t); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | // aller chercher le sous_casier |
| 123 | - while(!is_null($r) AND $casier = array_shift($sous_casier)) |
|
| 124 | - $r = isset($r[$casier])?$r[$casier]:null; |
|
| 131 | + while(!is_null($r) AND $casier = array_shift($sous_casier)) { |
|
| 132 | + $r = isset($r[$casier])?$r[$casier]:null; |
|
| 133 | + } |
|
| 125 | 134 | |
| 126 | - if (is_null($r)) return $def; |
|
| 135 | + if (is_null($r)) { |
|
| 136 | + return $def; |
|
| 137 | + } |
|
| 127 | 138 | return $r; |
| 128 | 139 | } |
| 129 | 140 | |
@@ -159,7 +170,9 @@ discard block |
||
| 159 | 170 | |
| 160 | 171 | list($table,$casier,$sous_casier) = expliquer_config($cfg); |
| 161 | 172 | // il faut au moins un casier pour ecrire |
| 162 | - if (!$casier) return false; |
|
| 173 | + if (!$casier) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 163 | 176 | |
| 164 | 177 | // trouvons ou creons le pointeur sur le casier |
| 165 | 178 | $st = isset($GLOBALS[$table][$casier])?$GLOBALS[$table][$casier]:null; |
@@ -167,8 +180,9 @@ discard block |
||
| 167 | 180 | $st = unserialize($st); |
| 168 | 181 | if ($st===false) { |
| 169 | 182 | // ne rien creer si c'est une demande d'effacement |
| 170 | - if (is_null($store)) |
|
| 171 | - return false; |
|
| 183 | + if (is_null($store)) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 172 | 186 | $st=array(); |
| 173 | 187 | } |
| 174 | 188 | } |
@@ -183,8 +197,9 @@ discard block |
||
| 183 | 197 | if (!isset($sc[$cc])) { |
| 184 | 198 | // si on essaye d'effacer une config qui n'existe pas |
| 185 | 199 | // ne rien creer mais sortir |
| 186 | - if (is_null($store)) |
|
| 187 | - return false; |
|
| 200 | + if (is_null($store)) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 188 | 203 | $sc[$cc] = array(); |
| 189 | 204 | } |
| 190 | 205 | $pointeurs[$cc] = &$sc; |
@@ -203,12 +218,14 @@ discard block |
||
| 203 | 218 | // si on a vide tous les sous casiers, |
| 204 | 219 | // et que le casier est vide |
| 205 | 220 | // vider aussi la meta |
| 206 | - if (!$sous AND !count($st)) |
|
| 207 | - $st = null; |
|
| 221 | + if (!$sous AND !count($st)) { |
|
| 222 | + $st = null; |
|
| 223 | + } |
|
| 208 | 224 | } |
| 209 | 225 | // dans tous les autres cas, on ecrase |
| 210 | - else |
|
| 211 | - $sc = $store; |
|
| 226 | + else { |
|
| 227 | + $sc = $store; |
|
| 228 | + } |
|
| 212 | 229 | |
| 213 | 230 | // Maintenant que $st est modifiee |
| 214 | 231 | // reprenons la comme valeur a stocker dans le casier principal |
@@ -216,8 +233,10 @@ discard block |
||
| 216 | 233 | } |
| 217 | 234 | |
| 218 | 235 | if (is_null($store)) { |
| 219 | - if (is_null($st) AND !$sous_casier) |
|
| 220 | - return false; // la config n'existait deja pas ! |
|
| 236 | + if (is_null($st) AND !$sous_casier) { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | + // la config n'existait deja pas ! |
|
| 221 | 240 | effacer_meta ($casier, $table); |
| 222 | 241 | if (!count($GLOBALS[$table]) |
| 223 | 242 | OR count($GLOBALS[$table])==1 AND isset($GLOBALS[$table]['charset'])) { |
@@ -227,12 +246,14 @@ discard block |
||
| 227 | 246 | } |
| 228 | 247 | // les meta ne peuvent etre que des chaines : il faut serializer le reste |
| 229 | 248 | else { |
| 230 | - if (!isset($GLOBALS[$table])) |
|
| 231 | - installer_table_meta($table); |
|
| 249 | + if (!isset($GLOBALS[$table])) { |
|
| 250 | + installer_table_meta($table); |
|
| 251 | + } |
|
| 232 | 252 | // si ce n'est pas une chaine |
| 233 | 253 | // il faut serializer |
| 234 | - if (!is_string($store)) |
|
| 235 | - $store=serialize($store); |
|
| 254 | + if (!is_string($store)) { |
|
| 255 | + $store=serialize($store); |
|
| 256 | + } |
|
| 236 | 257 | ecrire_meta($casier, $store, null, $table); |
| 237 | 258 | } |
| 238 | 259 | // verifier que lire_config($cfg)==$store ? |
@@ -253,8 +274,9 @@ discard block |
||
| 253 | 274 | // cas particulier en metapack:: |
| 254 | 275 | // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
| 255 | 276 | // intacte en sortie ... |
| 256 | - if (is_string($store) AND strpos($store,':') AND unserialize($store)) |
|
| 257 | - $store = serialize($store); |
|
| 277 | + if (is_string($store) AND strpos($store,':') AND unserialize($store)) { |
|
| 278 | + $store = serialize($store); |
|
| 279 | + } |
|
| 258 | 280 | return ecrire_config($cfg, $store); |
| 259 | 281 | } |
| 260 | 282 | |
@@ -322,14 +344,15 @@ discard block |
||
| 322 | 344 | $configurer = basename($page,"."._EXTENSION_SQUELETTES); |
| 323 | 345 | if (!isset($forms[$configurer]) |
| 324 | 346 | AND !isset($liste[$configurer]) |
| 325 | - AND !isset($exclure[$configurer])) |
|
| 326 | - $liste[$configurer] = array( |
|
| 347 | + AND !isset($exclure[$configurer])) { |
|
| 348 | + $liste[$configurer] = array( |
|
| 327 | 349 | 'parent' => 'bando_configuration', |
| 328 | 350 | 'url' => 'configurer', |
| 329 | 351 | 'args' => 'cfg='.substr($configurer,11), |
| 330 | 352 | 'titre' => _T("configurer:{$configurer}_titre"), |
| 331 | 353 | 'icone' => find_in_theme($i="images/{$configurer}-16.png")?$i:$icone_defaut, |
| 332 | 354 | ); |
| 355 | + } |
|
| 333 | 356 | } |
| 334 | 357 | |
| 335 | 358 | return $liste; |
@@ -465,10 +488,11 @@ discard block |
||
| 465 | 488 | function appliquer_modifs_config($purger_skel=false) { |
| 466 | 489 | |
| 467 | 490 | foreach(liste_metas() as $i => $v) { |
| 468 | - if (($x =_request($i))!==NULL) |
|
| 469 | - ecrire_meta($i, $x); |
|
| 470 | - elseif (!isset($GLOBALS['meta'][$i])) |
|
| 471 | - ecrire_meta($i, $v); |
|
| 491 | + if (($x =_request($i))!==NULL) { |
|
| 492 | + ecrire_meta($i, $x); |
|
| 493 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 494 | + ecrire_meta($i, $v); |
|
| 495 | + } |
|
| 472 | 496 | } |
| 473 | 497 | |
| 474 | 498 | if ($purger_skel) { |
@@ -489,8 +513,9 @@ discard block |
||
| 489 | 513 | if (!strlen($adresse_site)) {$GLOBALS['profondeur_url']=_DIR_RESTREINT?0:1;$adresse_site = url_de_base();} |
| 490 | 514 | $adresse_site = preg_replace(",/?\s*$,", "", $adresse_site); |
| 491 | 515 | |
| 492 | - if (!preg_match(",^[\w]+://,Uims",$adresse_site)) |
|
| 493 | - $adresse_site = "http://$adresse_site"; |
|
| 516 | + if (!preg_match(",^[\w]+://,Uims",$adresse_site)) { |
|
| 517 | + $adresse_site = "http://$adresse_site"; |
|
| 518 | + } |
|
| 494 | 519 | |
| 495 | 520 | ecrire_meta('adresse_site',$adresse_site); |
| 496 | 521 | } |
@@ -110,6 +110,9 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // http://doc.spip.org/@prepare_donnees_post |
| 113 | +/** |
|
| 114 | + * @param string $donnees |
|
| 115 | + */ |
|
| 113 | 116 | function prepare_donnees_post($donnees, $boundary = '') { |
| 114 | 117 | |
| 115 | 118 | // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
@@ -211,6 +214,9 @@ discard block |
||
| 211 | 214 | // dans lequel on ecrit directement la page |
| 212 | 215 | // * si c'est true/null ca correspond a une demande d'encodage/charset |
| 213 | 216 | // http://doc.spip.org/@recuperer_page |
| 217 | +/** |
|
| 218 | + * @param integer $taille_max |
|
| 219 | + */ |
|
| 214 | 220 | function recuperer_page($url, $trans = false, $get_headers = false, |
| 215 | 221 | $taille_max = null, $datas = '', $boundary = '', $refuser_gz = false, |
| 216 | 222 | $date_verif = '', $uri_referer = ''){ |
@@ -655,6 +661,9 @@ discard block |
||
| 655 | 661 | // retourne le descripteur sur lequel lire la reponse |
| 656 | 662 | // |
| 657 | 663 | // http://doc.spip.org/@init_http |
| 664 | +/** |
|
| 665 | + * @param string $method |
|
| 666 | + */ |
|
| 658 | 667 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
| 659 | 668 | $user = $via_proxy = $proxy_user = ''; |
| 660 | 669 | $fopen = false; |
@@ -699,6 +708,9 @@ discard block |
||
| 699 | 708 | } |
| 700 | 709 | |
| 701 | 710 | // http://doc.spip.org/@lance_requete |
| 711 | +/** |
|
| 712 | + * @param string $noproxy |
|
| 713 | + */ |
|
| 702 | 714 | function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
| 703 | 715 | |
| 704 | 716 | $proxy_user = ''; |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
| 25 | 25 | |
| 26 | 26 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 27 | - preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) |
|
| 28 | - . "/?spip.php[?]action=acceder_document.*file=(.*)$,"); |
|
| 27 | + preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) |
|
| 28 | + . "/?spip.php[?]action=acceder_document.*file=(.*)$,"); |
|
| 29 | 29 | |
| 30 | 30 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 31 | 31 | |
@@ -51,62 +51,62 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function copie_locale($source, $mode='auto', $local=null, $taille_max=null){ |
| 53 | 53 | |
| 54 | - // si c'est la protection de soi-meme, retourner le path |
|
| 55 | - if ($mode !== 'force' AND preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 56 | - $source = substr(_DIR_IMG,strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 57 | - return @file_exists($source) ? $source : false; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (is_null($local)) |
|
| 61 | - $local = fichier_copie_locale($source); |
|
| 62 | - else { |
|
| 63 | - if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE))==0) { |
|
| 64 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 69 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 70 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 71 | - if (!$local) return false; |
|
| 72 | - |
|
| 73 | - $localrac = _DIR_RACINE.$local; |
|
| 74 | - $t = ($mode=='force') ? false : @file_exists($localrac); |
|
| 75 | - |
|
| 76 | - // test d'existence du fichier |
|
| 77 | - if ($mode=='test') return $t ? $local : ''; |
|
| 78 | - |
|
| 79 | - // sinon voir si on doit/peut le telecharger |
|
| 80 | - if ($local==$source OR !preg_match(',^\w+://,', $source)) |
|
| 81 | - return $local; |
|
| 82 | - |
|
| 83 | - if ($mode=='modif' OR !$t){ |
|
| 84 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 85 | - // et des eventuelles recuperations concurantes |
|
| 86 | - include_spip("inc/acces"); |
|
| 87 | - if (!$taille_max) $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 88 | - $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : ''); |
|
| 89 | - if (!$res) { |
|
| 90 | - if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 91 | - spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE); |
|
| 92 | - return $t ? $local : false; |
|
| 93 | - } |
|
| 94 | - spip_log("copie_locale : recuperation $source sur $localrac taille $res OK"); |
|
| 95 | - |
|
| 96 | - // pour une eventuelle indexation |
|
| 97 | - pipeline('post_edition', |
|
| 98 | - array( |
|
| 99 | - 'args' => array( |
|
| 100 | - 'operation' => 'copie_locale', |
|
| 101 | - 'source' => $source, |
|
| 102 | - 'fichier' => $local |
|
| 103 | - ), |
|
| 104 | - 'data' => null |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $local; |
|
| 54 | + // si c'est la protection de soi-meme, retourner le path |
|
| 55 | + if ($mode !== 'force' AND preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 56 | + $source = substr(_DIR_IMG,strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 57 | + return @file_exists($source) ? $source : false; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (is_null($local)) |
|
| 61 | + $local = fichier_copie_locale($source); |
|
| 62 | + else { |
|
| 63 | + if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE))==0) { |
|
| 64 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 69 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 70 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 71 | + if (!$local) return false; |
|
| 72 | + |
|
| 73 | + $localrac = _DIR_RACINE.$local; |
|
| 74 | + $t = ($mode=='force') ? false : @file_exists($localrac); |
|
| 75 | + |
|
| 76 | + // test d'existence du fichier |
|
| 77 | + if ($mode=='test') return $t ? $local : ''; |
|
| 78 | + |
|
| 79 | + // sinon voir si on doit/peut le telecharger |
|
| 80 | + if ($local==$source OR !preg_match(',^\w+://,', $source)) |
|
| 81 | + return $local; |
|
| 82 | + |
|
| 83 | + if ($mode=='modif' OR !$t){ |
|
| 84 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 85 | + // et des eventuelles recuperations concurantes |
|
| 86 | + include_spip("inc/acces"); |
|
| 87 | + if (!$taille_max) $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 88 | + $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : ''); |
|
| 89 | + if (!$res) { |
|
| 90 | + if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 91 | + spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE); |
|
| 92 | + return $t ? $local : false; |
|
| 93 | + } |
|
| 94 | + spip_log("copie_locale : recuperation $source sur $localrac taille $res OK"); |
|
| 95 | + |
|
| 96 | + // pour une eventuelle indexation |
|
| 97 | + pipeline('post_edition', |
|
| 98 | + array( |
|
| 99 | + 'args' => array( |
|
| 100 | + 'operation' => 'copie_locale', |
|
| 101 | + 'source' => $source, |
|
| 102 | + 'fichier' => $local |
|
| 103 | + ), |
|
| 104 | + 'data' => null |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $local; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -121,173 +121,173 @@ discard block |
||
| 121 | 121 | * url ou false en cas d'echec |
| 122 | 122 | */ |
| 123 | 123 | function valider_url_distante($url, $known_hosts = array()) { |
| 124 | - if (!function_exists('protocole_verifier')){ |
|
| 125 | - include_spip('inc/filtres_mini'); |
|
| 126 | - } |
|
| 124 | + if (!function_exists('protocole_verifier')){ |
|
| 125 | + include_spip('inc/filtres_mini'); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 129 | - return false; |
|
| 130 | - } |
|
| 128 | + if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 129 | + return false; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - $parsed_url = parse_url($url); |
|
| 133 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if (!is_array($known_hosts)) { |
|
| 146 | - $known_hosts = array($known_hosts); |
|
| 147 | - } |
|
| 148 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 149 | - $known_hosts[] = url_de_base(); |
|
| 150 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 151 | - |
|
| 152 | - $is_known_host = false; |
|
| 153 | - foreach ($known_hosts as $known_host) { |
|
| 154 | - $parse_known = parse_url($known_host); |
|
| 155 | - if ($parse_known |
|
| 156 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 157 | - $is_known_host = true; |
|
| 158 | - break; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (!$is_known_host) { |
|
| 163 | - $host = trim($parsed_url['host'], '.'); |
|
| 164 | - if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 165 | - $ip = $host; |
|
| 166 | - } else { |
|
| 167 | - $ip = gethostbyname($host); |
|
| 168 | - if ($ip === $host) { |
|
| 169 | - // Error condition for gethostbyname() |
|
| 170 | - $ip = false; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - if ($ip) { |
|
| 174 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 175 | - if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 176 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 177 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 178 | - ) { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (empty($parsed_url['port'])) { |
|
| 185 | - return $url; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $port = $parsed_url['port']; |
|
| 189 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 190 | - return $url; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($is_known_host) { |
|
| 194 | - foreach ($known_hosts as $known_host) { |
|
| 195 | - $parse_known = parse_url($known_host); |
|
| 196 | - if ($parse_known |
|
| 197 | - and !empty($parse_known['port']) |
|
| 198 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 199 | - and $parse_known['port'] == $port) { |
|
| 200 | - return $url; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return false; |
|
| 132 | + $parsed_url = parse_url($url); |
|
| 133 | + if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if (!is_array($known_hosts)) { |
|
| 146 | + $known_hosts = array($known_hosts); |
|
| 147 | + } |
|
| 148 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 149 | + $known_hosts[] = url_de_base(); |
|
| 150 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 151 | + |
|
| 152 | + $is_known_host = false; |
|
| 153 | + foreach ($known_hosts as $known_host) { |
|
| 154 | + $parse_known = parse_url($known_host); |
|
| 155 | + if ($parse_known |
|
| 156 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 157 | + $is_known_host = true; |
|
| 158 | + break; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (!$is_known_host) { |
|
| 163 | + $host = trim($parsed_url['host'], '.'); |
|
| 164 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 165 | + $ip = $host; |
|
| 166 | + } else { |
|
| 167 | + $ip = gethostbyname($host); |
|
| 168 | + if ($ip === $host) { |
|
| 169 | + // Error condition for gethostbyname() |
|
| 170 | + $ip = false; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + if ($ip) { |
|
| 174 | + $parts = array_map('intval', explode( '.', $ip )); |
|
| 175 | + if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 176 | + or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 177 | + or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 178 | + ) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (empty($parsed_url['port'])) { |
|
| 185 | + return $url; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $port = $parsed_url['port']; |
|
| 189 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 190 | + return $url; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($is_known_host) { |
|
| 194 | + foreach ($known_hosts as $known_host) { |
|
| 195 | + $parse_known = parse_url($known_host); |
|
| 196 | + if ($parse_known |
|
| 197 | + and !empty($parse_known['port']) |
|
| 198 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 199 | + and $parse_known['port'] == $port) { |
|
| 200 | + return $url; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return false; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // http://doc.spip.org/@prepare_donnees_post |
| 209 | 209 | function prepare_donnees_post($donnees, $boundary = '') { |
| 210 | 210 | |
| 211 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 212 | - // pour un appel soap par exemple |
|
| 213 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 214 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 215 | - if (is_string($donnees) && strlen($donnees)){ |
|
| 216 | - $entete = ""; |
|
| 217 | - // on repasse tous les \r\n et \r en simples \n |
|
| 218 | - $donnees = str_replace("\r\n","\n",$donnees); |
|
| 219 | - $donnees = str_replace("\r","\n",$donnees); |
|
| 220 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 221 | - $p = strpos($donnees, "\n\n"); |
|
| 222 | - if ($p!==FALSE){ |
|
| 223 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p+1)); |
|
| 224 | - $donnees = substr($donnees, $p+2); |
|
| 225 | - } |
|
| 226 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 227 | - } |
|
| 228 | - else { |
|
| 229 | - /* boundary automatique */ |
|
| 230 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 231 | - if ($boundary===''){ |
|
| 232 | - $taille = 0; |
|
| 233 | - foreach ($donnees as $cle => $valeur){ |
|
| 234 | - if (is_array($valeur)){ |
|
| 235 | - foreach ($valeur as $val2){ |
|
| 236 | - $taille += strlen($val2); |
|
| 237 | - } |
|
| 238 | - } else { |
|
| 239 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 240 | - $taille += strlen($valeur); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - if ($taille>500){ |
|
| 244 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if (is_string($boundary) and strlen($boundary)){ |
|
| 249 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 250 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 251 | - $chaine = ''; |
|
| 252 | - if (is_array($donnees)) { |
|
| 253 | - foreach ($donnees as $cle => $valeur) { |
|
| 254 | - if (is_array($valeur)) { |
|
| 255 | - foreach ($valeur as $val2) { |
|
| 256 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 257 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 258 | - $chaine .= "\r\n"; |
|
| 259 | - $chaine .= $val2; |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 263 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 264 | - $chaine .= "\r\n"; |
|
| 265 | - $chaine .= $valeur; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 269 | - } |
|
| 270 | - } else { |
|
| 271 | - // fabrique une chaine HTTP simple pour un POST |
|
| 272 | - $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 273 | - $chaine = array(); |
|
| 274 | - if (is_array($donnees)) { |
|
| 275 | - foreach ($donnees as $cle => $valeur) { |
|
| 276 | - if (is_array($valeur)) { |
|
| 277 | - foreach ($valeur as $val2) { |
|
| 278 | - $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 279 | - } |
|
| 280 | - } else { |
|
| 281 | - $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - $chaine = implode('&', $chaine); |
|
| 285 | - } else { |
|
| 286 | - $chaine = $donnees; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - return array($entete, $chaine); |
|
| 211 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 212 | + // pour un appel soap par exemple |
|
| 213 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 214 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 215 | + if (is_string($donnees) && strlen($donnees)){ |
|
| 216 | + $entete = ""; |
|
| 217 | + // on repasse tous les \r\n et \r en simples \n |
|
| 218 | + $donnees = str_replace("\r\n","\n",$donnees); |
|
| 219 | + $donnees = str_replace("\r","\n",$donnees); |
|
| 220 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 221 | + $p = strpos($donnees, "\n\n"); |
|
| 222 | + if ($p!==FALSE){ |
|
| 223 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p+1)); |
|
| 224 | + $donnees = substr($donnees, $p+2); |
|
| 225 | + } |
|
| 226 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 227 | + } |
|
| 228 | + else { |
|
| 229 | + /* boundary automatique */ |
|
| 230 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 231 | + if ($boundary===''){ |
|
| 232 | + $taille = 0; |
|
| 233 | + foreach ($donnees as $cle => $valeur){ |
|
| 234 | + if (is_array($valeur)){ |
|
| 235 | + foreach ($valeur as $val2){ |
|
| 236 | + $taille += strlen($val2); |
|
| 237 | + } |
|
| 238 | + } else { |
|
| 239 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 240 | + $taille += strlen($valeur); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + if ($taille>500){ |
|
| 244 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if (is_string($boundary) and strlen($boundary)){ |
|
| 249 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 250 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 251 | + $chaine = ''; |
|
| 252 | + if (is_array($donnees)) { |
|
| 253 | + foreach ($donnees as $cle => $valeur) { |
|
| 254 | + if (is_array($valeur)) { |
|
| 255 | + foreach ($valeur as $val2) { |
|
| 256 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 257 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 258 | + $chaine .= "\r\n"; |
|
| 259 | + $chaine .= $val2; |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 263 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 264 | + $chaine .= "\r\n"; |
|
| 265 | + $chaine .= $valeur; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 269 | + } |
|
| 270 | + } else { |
|
| 271 | + // fabrique une chaine HTTP simple pour un POST |
|
| 272 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 273 | + $chaine = array(); |
|
| 274 | + if (is_array($donnees)) { |
|
| 275 | + foreach ($donnees as $cle => $valeur) { |
|
| 276 | + if (is_array($valeur)) { |
|
| 277 | + foreach ($valeur as $val2) { |
|
| 278 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 279 | + } |
|
| 280 | + } else { |
|
| 281 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + $chaine = implode('&', $chaine); |
|
| 285 | + } else { |
|
| 286 | + $chaine = $donnees; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + return array($entete, $chaine); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -301,18 +301,18 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | function url_to_ascii($url_idn) { |
| 303 | 303 | |
| 304 | - if ($parts = parse_url($url_idn)) { |
|
| 305 | - $host = $parts['host']; |
|
| 306 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 307 | - include_spip('inc/idna_convert.class'); |
|
| 308 | - $IDN = new idna_convert(); |
|
| 309 | - $host_ascii = $IDN->encode($host); |
|
| 310 | - $url_idn = explode($host, $url_idn, 2); |
|
| 311 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $url_idn; |
|
| 304 | + if ($parts = parse_url($url_idn)) { |
|
| 305 | + $host = $parts['host']; |
|
| 306 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 307 | + include_spip('inc/idna_convert.class'); |
|
| 308 | + $IDN = new idna_convert(); |
|
| 309 | + $host_ascii = $IDN->encode($host); |
|
| 310 | + $url_idn = explode($host, $url_idn, 2); |
|
| 311 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $url_idn; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // |
@@ -335,39 +335,39 @@ discard block |
||
| 335 | 335 | function recuperer_page($url, $trans = false, $get_headers = false, |
| 336 | 336 | $taille_max = null, $datas = '', $boundary = '', $refuser_gz = false, |
| 337 | 337 | $date_verif = '', $uri_referer = ''){ |
| 338 | - $gz = false; |
|
| 339 | - |
|
| 340 | - // $copy = copier le fichier ? |
|
| 341 | - $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 342 | - |
|
| 343 | - if (is_null($taille_max)) |
|
| 344 | - $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 345 | - |
|
| 346 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// |
|
| 347 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 348 | - if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url; |
|
| 349 | - $url = url_to_ascii($url); |
|
| 350 | - |
|
| 351 | - if ($taille_max==0) |
|
| 352 | - $get = 'HEAD'; |
|
| 353 | - else |
|
| 354 | - $get = 'GET'; |
|
| 355 | - |
|
| 356 | - if (!empty($datas)) { |
|
| 357 | - $get = 'POST'; |
|
| 358 | - list($type, $postdata) = prepare_donnees_post($datas, $boundary); |
|
| 359 | - $datas = $type . 'Content-Length: ' . strlen($postdata) . "\r\n\r\n" . $postdata; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - // dix tentatives maximum en cas d'entetes 301... |
|
| 363 | - for ($i = 0; $i<10; $i++){ |
|
| 364 | - $url = recuperer_lapage($url, $trans, $get, $taille_max, $datas, $refuser_gz, $date_verif, $uri_referer); |
|
| 365 | - if (!$url) return false; |
|
| 366 | - if (is_array($url)){ |
|
| 367 | - list($headers, $result) = $url; |
|
| 368 | - return ($get_headers ? $headers . "\n" : '') . $result; |
|
| 369 | - } else spip_log("recuperer page recommence sur $url"); |
|
| 370 | - } |
|
| 338 | + $gz = false; |
|
| 339 | + |
|
| 340 | + // $copy = copier le fichier ? |
|
| 341 | + $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 342 | + |
|
| 343 | + if (is_null($taille_max)) |
|
| 344 | + $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 345 | + |
|
| 346 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// |
|
| 347 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 348 | + if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url; |
|
| 349 | + $url = url_to_ascii($url); |
|
| 350 | + |
|
| 351 | + if ($taille_max==0) |
|
| 352 | + $get = 'HEAD'; |
|
| 353 | + else |
|
| 354 | + $get = 'GET'; |
|
| 355 | + |
|
| 356 | + if (!empty($datas)) { |
|
| 357 | + $get = 'POST'; |
|
| 358 | + list($type, $postdata) = prepare_donnees_post($datas, $boundary); |
|
| 359 | + $datas = $type . 'Content-Length: ' . strlen($postdata) . "\r\n\r\n" . $postdata; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + // dix tentatives maximum en cas d'entetes 301... |
|
| 363 | + for ($i = 0; $i<10; $i++){ |
|
| 364 | + $url = recuperer_lapage($url, $trans, $get, $taille_max, $datas, $refuser_gz, $date_verif, $uri_referer); |
|
| 365 | + if (!$url) return false; |
|
| 366 | + if (is_array($url)){ |
|
| 367 | + list($headers, $result) = $url; |
|
| 368 | + return ($get_headers ? $headers . "\n" : '') . $result; |
|
| 369 | + } else spip_log("recuperer page recommence sur $url"); |
|
| 370 | + } |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // args comme ci-dessus (presque) |
@@ -376,118 +376,118 @@ discard block |
||
| 376 | 376 | // si $trans est une chaine, c'est un nom de fichier pour ecrire directement dedans |
| 377 | 377 | // http://doc.spip.org/@recuperer_lapage |
| 378 | 378 | function recuperer_lapage($url, $trans = false, $get = 'GET', $taille_max = _INC_DISTANT_MAX_SIZE, $datas = '', $refuser_gz = false, $date_verif = '', $uri_referer = ''){ |
| 379 | - // $copy = copier le fichier ? |
|
| 380 | - $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 381 | - |
|
| 382 | - // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 383 | - // en memoire refuser gz |
|
| 384 | - if ($copy) |
|
| 385 | - $refuser_gz = true; |
|
| 386 | - |
|
| 387 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 388 | - list($f, $fopen) = init_http($get, $url, $refuser_gz, $uri_referer, $datas, _INC_DISTANT_VERSION_HTTP, $date_verif); |
|
| 389 | - if (!$f){ |
|
| 390 | - spip_log("ECHEC init_http $url"); |
|
| 391 | - return false; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - $result = ''; |
|
| 395 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 396 | - // et recuperer les en-tetes de reponses |
|
| 397 | - if ($fopen) |
|
| 398 | - $headers = ''; |
|
| 399 | - else { |
|
| 400 | - $headers = recuperer_entetes($f, $date_verif); |
|
| 401 | - if (is_numeric($headers)){ |
|
| 402 | - fclose($f); |
|
| 403 | - // Chinoisierie inexplicable pour contrer |
|
| 404 | - // les actions liberticides de l'empire du milieu |
|
| 405 | - if ($headers){ |
|
| 406 | - spip_log("HTTP status $headers pour $url"); |
|
| 407 | - return false; |
|
| 408 | - } |
|
| 409 | - $t = @parse_url($url); |
|
| 410 | - $host = $t['host']; |
|
| 411 | - if (!need_proxy($host) |
|
| 412 | - AND $result = @file_get_contents($url)){ |
|
| 413 | - // on peuple les headers de vide et on continue |
|
| 414 | - $headers = array(''); |
|
| 415 | - } |
|
| 416 | - else |
|
| 417 | - return false; |
|
| 418 | - } |
|
| 419 | - if (!is_array($headers)){ // cas Location |
|
| 420 | - fclose($f); |
|
| 421 | - include_spip('inc/filtres'); |
|
| 422 | - return suivre_lien($url, $headers); |
|
| 423 | - } |
|
| 424 | - $headers = join('', $headers); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if ($trans===NULL) return array($headers, ''); |
|
| 428 | - |
|
| 429 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 430 | - // sinon la memoire explose pour les gros flux |
|
| 431 | - |
|
| 432 | - $gz = preg_match(",\bContent-Encoding: .*gzip,is", $headers) ? |
|
| 433 | - (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz') : ''; |
|
| 379 | + // $copy = copier le fichier ? |
|
| 380 | + $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 381 | + |
|
| 382 | + // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 383 | + // en memoire refuser gz |
|
| 384 | + if ($copy) |
|
| 385 | + $refuser_gz = true; |
|
| 386 | + |
|
| 387 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 388 | + list($f, $fopen) = init_http($get, $url, $refuser_gz, $uri_referer, $datas, _INC_DISTANT_VERSION_HTTP, $date_verif); |
|
| 389 | + if (!$f){ |
|
| 390 | + spip_log("ECHEC init_http $url"); |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + $result = ''; |
|
| 395 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 396 | + // et recuperer les en-tetes de reponses |
|
| 397 | + if ($fopen) |
|
| 398 | + $headers = ''; |
|
| 399 | + else { |
|
| 400 | + $headers = recuperer_entetes($f, $date_verif); |
|
| 401 | + if (is_numeric($headers)){ |
|
| 402 | + fclose($f); |
|
| 403 | + // Chinoisierie inexplicable pour contrer |
|
| 404 | + // les actions liberticides de l'empire du milieu |
|
| 405 | + if ($headers){ |
|
| 406 | + spip_log("HTTP status $headers pour $url"); |
|
| 407 | + return false; |
|
| 408 | + } |
|
| 409 | + $t = @parse_url($url); |
|
| 410 | + $host = $t['host']; |
|
| 411 | + if (!need_proxy($host) |
|
| 412 | + AND $result = @file_get_contents($url)){ |
|
| 413 | + // on peuple les headers de vide et on continue |
|
| 414 | + $headers = array(''); |
|
| 415 | + } |
|
| 416 | + else |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 419 | + if (!is_array($headers)){ // cas Location |
|
| 420 | + fclose($f); |
|
| 421 | + include_spip('inc/filtres'); |
|
| 422 | + return suivre_lien($url, $headers); |
|
| 423 | + } |
|
| 424 | + $headers = join('', $headers); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if ($trans===NULL) return array($headers, ''); |
|
| 428 | + |
|
| 429 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 430 | + // sinon la memoire explose pour les gros flux |
|
| 431 | + |
|
| 432 | + $gz = preg_match(",\bContent-Encoding: .*gzip,is", $headers) ? |
|
| 433 | + (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz') : ''; |
|
| 434 | 434 | |
| 435 | 435 | # spip_log("entete ($trans $copy $gz)\n$headers"); |
| 436 | - if (!$result){ |
|
| 437 | - $result = recuperer_body($f, $taille_max, $gz ? $gz : ($copy ? $trans : '')); |
|
| 438 | - fclose($f); |
|
| 439 | - } |
|
| 440 | - if (!$result) |
|
| 441 | - return array($headers, $result); |
|
| 442 | - |
|
| 443 | - // Decompresser au besoin |
|
| 444 | - if ($gz){ |
|
| 445 | - $result = join('', gzfile($gz)); |
|
| 446 | - supprimer_fichier($gz); |
|
| 447 | - } |
|
| 448 | - // Faut-il l'importer dans notre charset local ? |
|
| 449 | - if ($trans===true){ |
|
| 450 | - include_spip('inc/charsets'); |
|
| 451 | - $result = transcoder_page($result, $headers); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return array($headers, $result); |
|
| 436 | + if (!$result){ |
|
| 437 | + $result = recuperer_body($f, $taille_max, $gz ? $gz : ($copy ? $trans : '')); |
|
| 438 | + fclose($f); |
|
| 439 | + } |
|
| 440 | + if (!$result) |
|
| 441 | + return array($headers, $result); |
|
| 442 | + |
|
| 443 | + // Decompresser au besoin |
|
| 444 | + if ($gz){ |
|
| 445 | + $result = join('', gzfile($gz)); |
|
| 446 | + supprimer_fichier($gz); |
|
| 447 | + } |
|
| 448 | + // Faut-il l'importer dans notre charset local ? |
|
| 449 | + if ($trans===true){ |
|
| 450 | + include_spip('inc/charsets'); |
|
| 451 | + $result = transcoder_page($result, $headers); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return array($headers, $result); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // http://doc.spip.org/@recuperer_body |
| 458 | 458 | function recuperer_body($f, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = ''){ |
| 459 | - $taille = 0; |
|
| 460 | - $result = ''; |
|
| 461 | - $fp = false; |
|
| 462 | - if ($fichier){ |
|
| 463 | - include_spip("inc/acces"); |
|
| 464 | - $tmpfile = "$fichier.".creer_uniqid().".tmp"; |
|
| 465 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 466 | - if (!$fp AND file_exists($fichier)){ |
|
| 467 | - return filesize($fichier); |
|
| 468 | - } |
|
| 469 | - if (!$fp) |
|
| 470 | - return false; |
|
| 471 | - $result = 0; // on renvoie la taille du fichier |
|
| 472 | - } |
|
| 473 | - while (!feof($f) AND $taille<$taille_max){ |
|
| 474 | - $res = fread($f, 16384); |
|
| 475 | - $taille += strlen($res); |
|
| 476 | - if ($fp){ |
|
| 477 | - fwrite($fp, $res); |
|
| 478 | - $result = $taille; |
|
| 479 | - } |
|
| 480 | - else |
|
| 481 | - $result .= $res; |
|
| 482 | - } |
|
| 483 | - if ($fp){ |
|
| 484 | - spip_fclose_unlock($fp); |
|
| 485 | - spip_unlink($fichier); |
|
| 486 | - @rename($tmpfile, $fichier); |
|
| 487 | - if (!file_exists($fichier)) |
|
| 488 | - return false; |
|
| 489 | - } |
|
| 490 | - return $result; |
|
| 459 | + $taille = 0; |
|
| 460 | + $result = ''; |
|
| 461 | + $fp = false; |
|
| 462 | + if ($fichier){ |
|
| 463 | + include_spip("inc/acces"); |
|
| 464 | + $tmpfile = "$fichier.".creer_uniqid().".tmp"; |
|
| 465 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 466 | + if (!$fp AND file_exists($fichier)){ |
|
| 467 | + return filesize($fichier); |
|
| 468 | + } |
|
| 469 | + if (!$fp) |
|
| 470 | + return false; |
|
| 471 | + $result = 0; // on renvoie la taille du fichier |
|
| 472 | + } |
|
| 473 | + while (!feof($f) AND $taille<$taille_max){ |
|
| 474 | + $res = fread($f, 16384); |
|
| 475 | + $taille += strlen($res); |
|
| 476 | + if ($fp){ |
|
| 477 | + fwrite($fp, $res); |
|
| 478 | + $result = $taille; |
|
| 479 | + } |
|
| 480 | + else |
|
| 481 | + $result .= $res; |
|
| 482 | + } |
|
| 483 | + if ($fp){ |
|
| 484 | + spip_fclose_unlock($fp); |
|
| 485 | + spip_unlink($fichier); |
|
| 486 | + @rename($tmpfile, $fichier); |
|
| 487 | + if (!file_exists($fichier)) |
|
| 488 | + return false; |
|
| 489 | + } |
|
| 490 | + return $result; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | // Lit les entetes de reponse HTTP sur la socket $f et retourne: |
@@ -497,35 +497,35 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | // http://doc.spip.org/@recuperer_entetes |
| 499 | 499 | function recuperer_entetes($f, $date_verif = ''){ |
| 500 | - $s = @trim(fgets($f, 16384)); |
|
| 501 | - |
|
| 502 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)){ |
|
| 503 | - return 0; |
|
| 504 | - } |
|
| 505 | - $status = intval($r[1]); |
|
| 506 | - $headers = array(); |
|
| 507 | - $not_modif = $location = false; |
|
| 508 | - while ($s = trim(fgets($f, 16384))){ |
|
| 509 | - $headers[] = $s . "\n"; |
|
| 510 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 511 | - list(, $d, $v) = $r; |
|
| 512 | - if (strtolower(trim($d))=='location' AND $status>=300 AND $status<400){ |
|
| 513 | - $location = $v; |
|
| 514 | - } |
|
| 515 | - elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 516 | - if ($date_verif>=strtotime($v)){ |
|
| 517 | - //Cas ou la page distante n'a pas bouge depuis |
|
| 518 | - //la derniere visite |
|
| 519 | - $not_modif = true; |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - if ($location) |
|
| 525 | - return $location; |
|
| 526 | - if ($status!=200 or $not_modif) |
|
| 527 | - return $status; |
|
| 528 | - return $headers; |
|
| 500 | + $s = @trim(fgets($f, 16384)); |
|
| 501 | + |
|
| 502 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)){ |
|
| 503 | + return 0; |
|
| 504 | + } |
|
| 505 | + $status = intval($r[1]); |
|
| 506 | + $headers = array(); |
|
| 507 | + $not_modif = $location = false; |
|
| 508 | + while ($s = trim(fgets($f, 16384))){ |
|
| 509 | + $headers[] = $s . "\n"; |
|
| 510 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 511 | + list(, $d, $v) = $r; |
|
| 512 | + if (strtolower(trim($d))=='location' AND $status>=300 AND $status<400){ |
|
| 513 | + $location = $v; |
|
| 514 | + } |
|
| 515 | + elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 516 | + if ($date_verif>=strtotime($v)){ |
|
| 517 | + //Cas ou la page distante n'a pas bouge depuis |
|
| 518 | + //la derniere visite |
|
| 519 | + $not_modif = true; |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + if ($location) |
|
| 525 | + return $location; |
|
| 526 | + if ($status!=200 or $not_modif) |
|
| 527 | + return $status; |
|
| 528 | + return $headers; |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | // Si on doit conserver une copie locale des fichiers distants, autant que ca |
@@ -534,21 +534,21 @@ discard block |
||
| 534 | 534 | // des filesystems |
| 535 | 535 | // http://doc.spip.org/@nom_fichier_copie_locale |
| 536 | 536 | function nom_fichier_copie_locale($source, $extension){ |
| 537 | - include_spip('inc/documents'); |
|
| 537 | + include_spip('inc/documents'); |
|
| 538 | 538 | |
| 539 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 540 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 539 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 540 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 541 | 541 | |
| 542 | - // on se place tout le temps comme si on etait a la racine |
|
| 543 | - if (_DIR_RACINE) |
|
| 544 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 542 | + // on se place tout le temps comme si on etait a la racine |
|
| 543 | + if (_DIR_RACINE) |
|
| 544 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 545 | 545 | |
| 546 | - $m = md5($source); |
|
| 546 | + $m = md5($source); |
|
| 547 | 547 | |
| 548 | - return $d |
|
| 549 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 550 | - . substr($m, 0, 4) |
|
| 551 | - . ".$extension"; |
|
| 548 | + return $d |
|
| 549 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 550 | + . substr($m, 0, 4) |
|
| 551 | + . ".$extension"; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | // |
@@ -556,61 +556,61 @@ discard block |
||
| 556 | 556 | // |
| 557 | 557 | // http://doc.spip.org/@fichier_copie_locale |
| 558 | 558 | function fichier_copie_locale($source){ |
| 559 | - // Si c'est deja local pas de souci |
|
| 560 | - if (!preg_match(',^\w+://,', $source)){ |
|
| 561 | - if (_DIR_RACINE) |
|
| 562 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 563 | - return $source; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 567 | - // a deja ete copie en local avec cette extension |
|
| 568 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 569 | - $path_parts = pathinfo($source); |
|
| 570 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 571 | - if ($ext |
|
| 572 | - AND preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 573 | - AND $f = nom_fichier_copie_locale($source, $ext) |
|
| 574 | - AND file_exists(_DIR_RACINE . $f) |
|
| 575 | - ) |
|
| 576 | - return $f; |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - // Si c'est deja dans la table des documents, |
|
| 580 | - // ramener le nom de sa copie potentielle |
|
| 581 | - |
|
| 582 | - $ext = sql_getfetsel("extension", "spip_documents", "fichier=" . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - if ($ext) return nom_fichier_copie_locale($source, $ext); |
|
| 586 | - |
|
| 587 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 588 | - // et si il n'aurait pas deja ete rapatrie |
|
| 589 | - |
|
| 590 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 591 | - |
|
| 592 | - if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 593 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 594 | - if (file_exists(_DIR_RACINE . $f)) |
|
| 595 | - return $f; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // Ping pour voir si son extension est connue et autorisee |
|
| 599 | - // avec mise en cache du resultat du ping |
|
| 600 | - |
|
| 601 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 602 | - if (!@file_exists($cache) |
|
| 603 | - OR !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 604 | - OR _request('var_mode')=='recalcul' |
|
| 605 | - ){ |
|
| 606 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 607 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 608 | - } |
|
| 609 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 610 | - if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 611 | - return nom_fichier_copie_locale($source, $ext); |
|
| 612 | - } |
|
| 613 | - spip_log("pas de copie locale pour $source"); |
|
| 559 | + // Si c'est deja local pas de souci |
|
| 560 | + if (!preg_match(',^\w+://,', $source)){ |
|
| 561 | + if (_DIR_RACINE) |
|
| 562 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 563 | + return $source; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 567 | + // a deja ete copie en local avec cette extension |
|
| 568 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 569 | + $path_parts = pathinfo($source); |
|
| 570 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 571 | + if ($ext |
|
| 572 | + AND preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 573 | + AND $f = nom_fichier_copie_locale($source, $ext) |
|
| 574 | + AND file_exists(_DIR_RACINE . $f) |
|
| 575 | + ) |
|
| 576 | + return $f; |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + // Si c'est deja dans la table des documents, |
|
| 580 | + // ramener le nom de sa copie potentielle |
|
| 581 | + |
|
| 582 | + $ext = sql_getfetsel("extension", "spip_documents", "fichier=" . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + if ($ext) return nom_fichier_copie_locale($source, $ext); |
|
| 586 | + |
|
| 587 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 588 | + // et si il n'aurait pas deja ete rapatrie |
|
| 589 | + |
|
| 590 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 591 | + |
|
| 592 | + if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 593 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 594 | + if (file_exists(_DIR_RACINE . $f)) |
|
| 595 | + return $f; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // Ping pour voir si son extension est connue et autorisee |
|
| 599 | + // avec mise en cache du resultat du ping |
|
| 600 | + |
|
| 601 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 602 | + if (!@file_exists($cache) |
|
| 603 | + OR !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 604 | + OR _request('var_mode')=='recalcul' |
|
| 605 | + ){ |
|
| 606 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 607 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 608 | + } |
|
| 609 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 610 | + if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 611 | + return nom_fichier_copie_locale($source, $ext); |
|
| 612 | + } |
|
| 613 | + spip_log("pas de copie locale pour $source"); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | |
@@ -628,133 +628,133 @@ discard block |
||
| 628 | 628 | // http://doc.spip.org/@recuperer_infos_distantes |
| 629 | 629 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true){ |
| 630 | 630 | |
| 631 | - // pas la peine de perdre son temps |
|
| 632 | - if (!tester_url_absolue($source)) { |
|
| 633 | - return false; |
|
| 634 | - } |
|
| 631 | + // pas la peine de perdre son temps |
|
| 632 | + if (!tester_url_absolue($source)) { |
|
| 633 | + return false; |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | - # charger les alias des types mime |
|
| 637 | - include_spip('base/typedoc'); |
|
| 638 | - global $mime_alias; |
|
| 639 | - |
|
| 640 | - $a = array(); |
|
| 641 | - $mime_type = ''; |
|
| 642 | - // On va directement charger le debut des images et des fichiers html, |
|
| 643 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 644 | - // ca echoue l'utilisateur devra les entrer... |
|
| 645 | - if ($headers = recuperer_page($source, false, true, $max, '', '', true)){ |
|
| 646 | - list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 647 | - |
|
| 648 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) |
|
| 649 | - $mime_type = (trim($regs[1])); |
|
| 650 | - else |
|
| 651 | - $mime_type = ''; // inconnu |
|
| 652 | - |
|
| 653 | - // Appliquer les alias |
|
| 654 | - while (isset($mime_alias[$mime_type])) |
|
| 655 | - $mime_type = $mime_alias[$mime_type]; |
|
| 656 | - |
|
| 657 | - // Si on a un mime-type insignifiant |
|
| 658 | - // text/plain,application/octet-stream ou vide |
|
| 659 | - // c'est peut-etre que le serveur ne sait pas |
|
| 660 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 661 | - // ou le Content-Disposition: attachment; filename=... |
|
| 662 | - $t = null; |
|
| 663 | - if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))){ |
|
| 664 | - if (!$t |
|
| 665 | - AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 666 | - ){ |
|
| 667 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 668 | - } |
|
| 669 | - if (!$t |
|
| 670 | - AND preg_match(",^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims", $headers, $m) |
|
| 671 | - AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 672 | - ){ |
|
| 673 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 678 | - if (!$t) |
|
| 679 | - $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 680 | - |
|
| 681 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 682 | - // On essaie de nouveau avec l'extension |
|
| 683 | - if (!$t |
|
| 684 | - AND $mime_type!='text/plain' |
|
| 685 | - AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 686 | - ){ |
|
| 687 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - if ($t){ |
|
| 692 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 693 | - $a['extension'] = $t['extension']; |
|
| 694 | - } else { |
|
| 695 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 696 | - spip_log("mime-type $mime_type inconnu"); |
|
| 697 | - $t = sql_fetsel("extension", "spip_types_documents", "extension='bin'"); |
|
| 698 | - if (!$t) return false; |
|
| 699 | - $a['extension'] = $t['extension']; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", |
|
| 703 | - "\n$headers", $regs) |
|
| 704 | - ) |
|
| 705 | - $a['taille'] = intval($regs[1]); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - // Echec avec HEAD, on tente avec GET |
|
| 709 | - if (!$a AND !$max){ |
|
| 710 | - spip_log("tenter GET $source"); |
|
| 711 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // si on a rien trouve pas la peine d'insister |
|
| 715 | - if (!$a) { |
|
| 716 | - return false; |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 720 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 721 | - if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)){ |
|
| 722 | - if ($max==0 |
|
| 723 | - AND $a['taille']<_INC_DISTANT_MAX_SIZE |
|
| 724 | - AND (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension'])!==false) |
|
| 725 | - AND $charger_si_petite_image |
|
| 726 | - ){ |
|
| 727 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 728 | - } |
|
| 729 | - else if ($a['body']){ |
|
| 730 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 731 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 732 | - $size_image = @getimagesize($a['fichier']); |
|
| 733 | - $a['largeur'] = intval($size_image[0]); |
|
| 734 | - $a['hauteur'] = intval($size_image[1]); |
|
| 735 | - $a['type_image'] = true; |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 740 | - // ce sera mieux que 0x0 |
|
| 741 | - if ($a AND $a['extension']=='swf' |
|
| 742 | - AND !$a['largeur'] |
|
| 743 | - ){ |
|
| 744 | - $a['largeur'] = 425; |
|
| 745 | - $a['hauteur'] = 350; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ($mime_type=='text/html'){ |
|
| 749 | - include_spip('inc/filtres'); |
|
| 750 | - $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 751 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) |
|
| 752 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 753 | - if (!$a['taille']) $a['taille'] = strlen($page); # a peu pres |
|
| 754 | - } |
|
| 755 | - $a['mime_type']=$mime_type; |
|
| 756 | - |
|
| 757 | - return $a; |
|
| 636 | + # charger les alias des types mime |
|
| 637 | + include_spip('base/typedoc'); |
|
| 638 | + global $mime_alias; |
|
| 639 | + |
|
| 640 | + $a = array(); |
|
| 641 | + $mime_type = ''; |
|
| 642 | + // On va directement charger le debut des images et des fichiers html, |
|
| 643 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 644 | + // ca echoue l'utilisateur devra les entrer... |
|
| 645 | + if ($headers = recuperer_page($source, false, true, $max, '', '', true)){ |
|
| 646 | + list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 647 | + |
|
| 648 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) |
|
| 649 | + $mime_type = (trim($regs[1])); |
|
| 650 | + else |
|
| 651 | + $mime_type = ''; // inconnu |
|
| 652 | + |
|
| 653 | + // Appliquer les alias |
|
| 654 | + while (isset($mime_alias[$mime_type])) |
|
| 655 | + $mime_type = $mime_alias[$mime_type]; |
|
| 656 | + |
|
| 657 | + // Si on a un mime-type insignifiant |
|
| 658 | + // text/plain,application/octet-stream ou vide |
|
| 659 | + // c'est peut-etre que le serveur ne sait pas |
|
| 660 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 661 | + // ou le Content-Disposition: attachment; filename=... |
|
| 662 | + $t = null; |
|
| 663 | + if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))){ |
|
| 664 | + if (!$t |
|
| 665 | + AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 666 | + ){ |
|
| 667 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 668 | + } |
|
| 669 | + if (!$t |
|
| 670 | + AND preg_match(",^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims", $headers, $m) |
|
| 671 | + AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 672 | + ){ |
|
| 673 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 678 | + if (!$t) |
|
| 679 | + $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 680 | + |
|
| 681 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 682 | + // On essaie de nouveau avec l'extension |
|
| 683 | + if (!$t |
|
| 684 | + AND $mime_type!='text/plain' |
|
| 685 | + AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 686 | + ){ |
|
| 687 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + if ($t){ |
|
| 692 | + spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 693 | + $a['extension'] = $t['extension']; |
|
| 694 | + } else { |
|
| 695 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 696 | + spip_log("mime-type $mime_type inconnu"); |
|
| 697 | + $t = sql_fetsel("extension", "spip_types_documents", "extension='bin'"); |
|
| 698 | + if (!$t) return false; |
|
| 699 | + $a['extension'] = $t['extension']; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", |
|
| 703 | + "\n$headers", $regs) |
|
| 704 | + ) |
|
| 705 | + $a['taille'] = intval($regs[1]); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + // Echec avec HEAD, on tente avec GET |
|
| 709 | + if (!$a AND !$max){ |
|
| 710 | + spip_log("tenter GET $source"); |
|
| 711 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // si on a rien trouve pas la peine d'insister |
|
| 715 | + if (!$a) { |
|
| 716 | + return false; |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 720 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 721 | + if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)){ |
|
| 722 | + if ($max==0 |
|
| 723 | + AND $a['taille']<_INC_DISTANT_MAX_SIZE |
|
| 724 | + AND (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension'])!==false) |
|
| 725 | + AND $charger_si_petite_image |
|
| 726 | + ){ |
|
| 727 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 728 | + } |
|
| 729 | + else if ($a['body']){ |
|
| 730 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 731 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 732 | + $size_image = @getimagesize($a['fichier']); |
|
| 733 | + $a['largeur'] = intval($size_image[0]); |
|
| 734 | + $a['hauteur'] = intval($size_image[1]); |
|
| 735 | + $a['type_image'] = true; |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 740 | + // ce sera mieux que 0x0 |
|
| 741 | + if ($a AND $a['extension']=='swf' |
|
| 742 | + AND !$a['largeur'] |
|
| 743 | + ){ |
|
| 744 | + $a['largeur'] = 425; |
|
| 745 | + $a['hauteur'] = 350; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ($mime_type=='text/html'){ |
|
| 749 | + include_spip('inc/filtres'); |
|
| 750 | + $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 751 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) |
|
| 752 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 753 | + if (!$a['taille']) $a['taille'] = strlen($page); # a peu pres |
|
| 754 | + } |
|
| 755 | + $a['mime_type']=$mime_type; |
|
| 756 | + |
|
| 757 | + return $a; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | |
@@ -769,17 +769,17 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | */ |
| 771 | 771 | function need_proxy($host, $http_proxy = null, $http_noproxy = null){ |
| 772 | - if (is_null($http_proxy)) |
|
| 773 | - $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 774 | - if (is_null($http_noproxy)) |
|
| 775 | - $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 772 | + if (is_null($http_proxy)) |
|
| 773 | + $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 774 | + if (is_null($http_noproxy)) |
|
| 775 | + $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 776 | 776 | |
| 777 | - $domain = substr($host, strpos($host, '.')); |
|
| 777 | + $domain = substr($host, strpos($host, '.')); |
|
| 778 | 778 | |
| 779 | - return ($http_proxy |
|
| 780 | - AND (strpos(" $http_noproxy ", " $host ")===false |
|
| 781 | - AND (strpos(" $http_noproxy ", " $domain ")===false))) |
|
| 782 | - ? $http_proxy : ''; |
|
| 779 | + return ($http_proxy |
|
| 780 | + AND (strpos(" $http_noproxy ", " $host ")===false |
|
| 781 | + AND (strpos(" $http_noproxy ", " $domain ")===false))) |
|
| 782 | + ? $http_proxy : ''; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | // |
@@ -788,124 +788,124 @@ discard block |
||
| 788 | 788 | // |
| 789 | 789 | // http://doc.spip.org/@init_http |
| 790 | 790 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
| 791 | - $user = $via_proxy = $proxy_user = ''; |
|
| 792 | - $fopen = false; |
|
| 793 | - |
|
| 794 | - $t = @parse_url($url); |
|
| 795 | - $host = $t['host']; |
|
| 796 | - if ($t['scheme']=='http'){ |
|
| 797 | - $scheme = 'http'; |
|
| 798 | - $noproxy = ''; |
|
| 799 | - } elseif ($t['scheme']=='https') { |
|
| 800 | - $scheme = 'ssl'; |
|
| 801 | - $noproxy = 'ssl://'; |
|
| 802 | - if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; |
|
| 803 | - } |
|
| 804 | - else { |
|
| 805 | - $scheme = $t['scheme']; |
|
| 806 | - $noproxy = $scheme . '://'; |
|
| 807 | - } |
|
| 808 | - if (isset($t['user'])) |
|
| 809 | - $user = array($t['user'], $t['pass']); |
|
| 810 | - |
|
| 811 | - if (!isset($t['port']) || !($port = $t['port'])) $port = 80; |
|
| 812 | - if (!isset($t['path']) || !($path = $t['path'])) $path = "/"; |
|
| 813 | - if (@$t['query']) $path .= "?" . $t['query']; |
|
| 814 | - |
|
| 815 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 816 | - if (!$f){ |
|
| 817 | - // fallback : fopen |
|
| 818 | - if (!need_proxy($host) |
|
| 819 | - AND !_request('tester_proxy') |
|
| 820 | - AND (!isset($GLOBALS['inc_distant_allow_fopen']) OR $GLOBALS['inc_distant_allow_fopen'])){ |
|
| 821 | - $f = @fopen($url, "rb"); |
|
| 822 | - spip_log("connexion vers $url par simple fopen"); |
|
| 823 | - $fopen = true; |
|
| 824 | - } |
|
| 825 | - else |
|
| 826 | - $f = false; |
|
| 827 | - // echec total |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return array($f, $fopen); |
|
| 791 | + $user = $via_proxy = $proxy_user = ''; |
|
| 792 | + $fopen = false; |
|
| 793 | + |
|
| 794 | + $t = @parse_url($url); |
|
| 795 | + $host = $t['host']; |
|
| 796 | + if ($t['scheme']=='http'){ |
|
| 797 | + $scheme = 'http'; |
|
| 798 | + $noproxy = ''; |
|
| 799 | + } elseif ($t['scheme']=='https') { |
|
| 800 | + $scheme = 'ssl'; |
|
| 801 | + $noproxy = 'ssl://'; |
|
| 802 | + if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; |
|
| 803 | + } |
|
| 804 | + else { |
|
| 805 | + $scheme = $t['scheme']; |
|
| 806 | + $noproxy = $scheme . '://'; |
|
| 807 | + } |
|
| 808 | + if (isset($t['user'])) |
|
| 809 | + $user = array($t['user'], $t['pass']); |
|
| 810 | + |
|
| 811 | + if (!isset($t['port']) || !($port = $t['port'])) $port = 80; |
|
| 812 | + if (!isset($t['path']) || !($path = $t['path'])) $path = "/"; |
|
| 813 | + if (@$t['query']) $path .= "?" . $t['query']; |
|
| 814 | + |
|
| 815 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 816 | + if (!$f){ |
|
| 817 | + // fallback : fopen |
|
| 818 | + if (!need_proxy($host) |
|
| 819 | + AND !_request('tester_proxy') |
|
| 820 | + AND (!isset($GLOBALS['inc_distant_allow_fopen']) OR $GLOBALS['inc_distant_allow_fopen'])){ |
|
| 821 | + $f = @fopen($url, "rb"); |
|
| 822 | + spip_log("connexion vers $url par simple fopen"); |
|
| 823 | + $fopen = true; |
|
| 824 | + } |
|
| 825 | + else |
|
| 826 | + $f = false; |
|
| 827 | + // echec total |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return array($f, $fopen); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | // http://doc.spip.org/@lance_requete |
| 834 | 834 | function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
| 835 | 835 | |
| 836 | - $proxy_user = ''; |
|
| 837 | - $http_proxy = need_proxy($host); |
|
| 838 | - if ($user) $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 839 | - |
|
| 840 | - $connect = ''; |
|
| 841 | - if ($http_proxy) { |
|
| 842 | - if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 843 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 844 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 845 | - . "Host: $path_host\r\n" |
|
| 846 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 847 | - } else { |
|
| 848 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 849 | - . (!$user ? '' : "$user@") |
|
| 850 | - . "$host" . (($port!=80) ? ":$port" : "") . $path; |
|
| 851 | - } |
|
| 852 | - $t2 = @parse_url($http_proxy); |
|
| 853 | - $first_host = $t2['host']; |
|
| 854 | - if (!($port = $t2['port'])) $port = 80; |
|
| 855 | - if ($t2['user']) |
|
| 856 | - $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 857 | - } |
|
| 858 | - else |
|
| 859 | - $first_host = $noproxy . $host; |
|
| 860 | - |
|
| 861 | - if ($connect){ |
|
| 862 | - $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); |
|
| 863 | - $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
|
| 864 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); |
|
| 865 | - if (!$f) return false; |
|
| 866 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 867 | - |
|
| 868 | - fputs($f, $connect); |
|
| 869 | - fputs($f, "\r\n"); |
|
| 870 | - $res = fread($f, 1024); |
|
| 871 | - if (!$res |
|
| 872 | - OR !count($res = explode(' ',$res)) |
|
| 873 | - OR $res[1]!=='200'){ |
|
| 874 | - spip_log("Echec CONNECT sur $first_host:$port","connect"._LOG_INFO_IMPORTANTE); |
|
| 875 | - fclose($f); |
|
| 876 | - return false; |
|
| 877 | - } |
|
| 878 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 879 | - stream_set_blocking($f, true); |
|
| 880 | - // envoyer le handshake |
|
| 881 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 882 | - spip_log("OK CONNECT sur $first_host:$port","connect"); |
|
| 883 | - } |
|
| 884 | - else { |
|
| 885 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 886 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 887 | - if (!$f) { |
|
| 888 | - spip_log("Erreur connexion $errno $errstr",_LOG_ERREUR); |
|
| 889 | - return false; |
|
| 890 | - } |
|
| 891 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - $site = $GLOBALS['meta']["adresse_site"]; |
|
| 895 | - |
|
| 896 | - $req = "$method $path $vers\r\n" |
|
| 897 | - . "Host: $host\r\n" |
|
| 898 | - . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 899 | - . ($refuse_gz ? '' : ("Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 900 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 901 | - . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) . " GMT\r\n")) |
|
| 902 | - . (!$user ? '' : ("Authorization: Basic " . base64_encode($user) . "\r\n")) |
|
| 903 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 904 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 836 | + $proxy_user = ''; |
|
| 837 | + $http_proxy = need_proxy($host); |
|
| 838 | + if ($user) $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 839 | + |
|
| 840 | + $connect = ''; |
|
| 841 | + if ($http_proxy) { |
|
| 842 | + if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 843 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 844 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 845 | + . "Host: $path_host\r\n" |
|
| 846 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 847 | + } else { |
|
| 848 | + $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 849 | + . (!$user ? '' : "$user@") |
|
| 850 | + . "$host" . (($port!=80) ? ":$port" : "") . $path; |
|
| 851 | + } |
|
| 852 | + $t2 = @parse_url($http_proxy); |
|
| 853 | + $first_host = $t2['host']; |
|
| 854 | + if (!($port = $t2['port'])) $port = 80; |
|
| 855 | + if ($t2['user']) |
|
| 856 | + $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 857 | + } |
|
| 858 | + else |
|
| 859 | + $first_host = $noproxy . $host; |
|
| 860 | + |
|
| 861 | + if ($connect){ |
|
| 862 | + $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); |
|
| 863 | + $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
|
| 864 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); |
|
| 865 | + if (!$f) return false; |
|
| 866 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 867 | + |
|
| 868 | + fputs($f, $connect); |
|
| 869 | + fputs($f, "\r\n"); |
|
| 870 | + $res = fread($f, 1024); |
|
| 871 | + if (!$res |
|
| 872 | + OR !count($res = explode(' ',$res)) |
|
| 873 | + OR $res[1]!=='200'){ |
|
| 874 | + spip_log("Echec CONNECT sur $first_host:$port","connect"._LOG_INFO_IMPORTANTE); |
|
| 875 | + fclose($f); |
|
| 876 | + return false; |
|
| 877 | + } |
|
| 878 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 879 | + stream_set_blocking($f, true); |
|
| 880 | + // envoyer le handshake |
|
| 881 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 882 | + spip_log("OK CONNECT sur $first_host:$port","connect"); |
|
| 883 | + } |
|
| 884 | + else { |
|
| 885 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 886 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 887 | + if (!$f) { |
|
| 888 | + spip_log("Erreur connexion $errno $errstr",_LOG_ERREUR); |
|
| 889 | + return false; |
|
| 890 | + } |
|
| 891 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + $site = $GLOBALS['meta']["adresse_site"]; |
|
| 895 | + |
|
| 896 | + $req = "$method $path $vers\r\n" |
|
| 897 | + . "Host: $host\r\n" |
|
| 898 | + . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 899 | + . ($refuse_gz ? '' : ("Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 900 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 901 | + . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) . " GMT\r\n")) |
|
| 902 | + . (!$user ? '' : ("Authorization: Basic " . base64_encode($user) . "\r\n")) |
|
| 903 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 904 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 905 | 905 | |
| 906 | 906 | # spip_log("Requete\n$req"); |
| 907 | - fputs($f, $req); |
|
| 908 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 909 | - return $f; |
|
| 907 | + fputs($f, $req); |
|
| 908 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 909 | + return $f; |
|
| 910 | 910 | } |
| 911 | 911 | |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | if (!defined('_INC_DISTANT_VERSION_HTTP')) define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0"); |
| 21 | 21 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); |
| 22 | -if (!defined('_INC_DISTANT_USER_AGENT')) define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); |
|
| 23 | -if (!defined('_INC_DISTANT_MAX_SIZE')) define('_INC_DISTANT_MAX_SIZE',2097152); |
|
| 24 | -if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
|
| 22 | +if (!defined('_INC_DISTANT_USER_AGENT')) define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee']." (".$GLOBALS['home_server'].")"); |
|
| 23 | +if (!defined('_INC_DISTANT_MAX_SIZE')) define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 24 | +if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 25 | 25 | |
| 26 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 26 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 27 | 27 | preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) |
| 28 | 28 | . "/?spip.php[?]action=acceder_document.*file=(.*)$,"); |
| 29 | 29 | |
@@ -49,18 +49,18 @@ discard block |
||
| 49 | 49 | * taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE |
| 50 | 50 | * @return bool|string |
| 51 | 51 | */ |
| 52 | -function copie_locale($source, $mode='auto', $local=null, $taille_max=null){ |
|
| 52 | +function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
|
| 53 | 53 | |
| 54 | 54 | // si c'est la protection de soi-meme, retourner le path |
| 55 | 55 | if ($mode !== 'force' AND preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 56 | - $source = substr(_DIR_IMG,strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 56 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 57 | 57 | return @file_exists($source) ? $source : false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if (is_null($local)) |
| 61 | 61 | $local = fichier_copie_locale($source); |
| 62 | 62 | else { |
| 63 | - if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE))==0) { |
|
| 63 | + if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 64 | 64 | $local = substr($local, strlen(_DIR_RACINE)); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | if (!$local) return false; |
| 72 | 72 | |
| 73 | 73 | $localrac = _DIR_RACINE.$local; |
| 74 | - $t = ($mode=='force') ? false : @file_exists($localrac); |
|
| 74 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 75 | 75 | |
| 76 | 76 | // test d'existence du fichier |
| 77 | - if ($mode=='test') return $t ? $local : ''; |
|
| 77 | + if ($mode == 'test') return $t ? $local : ''; |
|
| 78 | 78 | |
| 79 | 79 | // sinon voir si on doit/peut le telecharger |
| 80 | - if ($local==$source OR !preg_match(',^\w+://,', $source)) |
|
| 80 | + if ($local == $source OR !preg_match(',^\w+://,', $source)) |
|
| 81 | 81 | return $local; |
| 82 | 82 | |
| 83 | - if ($mode=='modif' OR !$t){ |
|
| 83 | + if ($mode == 'modif' OR !$t) { |
|
| 84 | 84 | // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
| 85 | 85 | // et des eventuelles recuperations concurantes |
| 86 | 86 | include_spip("inc/acces"); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : ''); |
| 89 | 89 | if (!$res) { |
| 90 | 90 | if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
| 91 | - spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE); |
|
| 91 | + spip_log("copie_locale : Echec recuperation $source sur $localrac", _LOG_INFO_IMPORTANTE); |
|
| 92 | 92 | return $t ? $local : false; |
| 93 | 93 | } |
| 94 | 94 | spip_log("copie_locale : recuperation $source sur $localrac taille $res OK"); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * url ou false en cas d'echec |
| 122 | 122 | */ |
| 123 | 123 | function valider_url_distante($url, $known_hosts = array()) { |
| 124 | - if (!function_exists('protocole_verifier')){ |
|
| 124 | + if (!function_exists('protocole_verifier')) { |
|
| 125 | 125 | include_spip('inc/filtres_mini'); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $parsed_url = parse_url($url); |
| 133 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 133 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 134 | 134 | return false; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | if ($ip) { |
| 174 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 174 | + $parts = array_map('intval', explode('.', $ip)); |
|
| 175 | 175 | if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
| 176 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 177 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 176 | + or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1]) |
|
| 177 | + or (192 === $parts[0] && 168 === $parts[1]) |
|
| 178 | 178 | ) { |
| 179 | 179 | return false; |
| 180 | 180 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | $port = $parsed_url['port']; |
| 189 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 189 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 190 | 190 | return $url; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -212,27 +212,27 @@ discard block |
||
| 212 | 212 | // pour un appel soap par exemple |
| 213 | 213 | // l'entete est separe des donnees par un double retour a la ligne |
| 214 | 214 | // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
| 215 | - if (is_string($donnees) && strlen($donnees)){ |
|
| 215 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 216 | 216 | $entete = ""; |
| 217 | 217 | // on repasse tous les \r\n et \r en simples \n |
| 218 | - $donnees = str_replace("\r\n","\n",$donnees); |
|
| 219 | - $donnees = str_replace("\r","\n",$donnees); |
|
| 218 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 219 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 220 | 220 | // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
| 221 | 221 | $p = strpos($donnees, "\n\n"); |
| 222 | - if ($p!==FALSE){ |
|
| 223 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p+1)); |
|
| 224 | - $donnees = substr($donnees, $p+2); |
|
| 222 | + if ($p !== FALSE) { |
|
| 223 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 224 | + $donnees = substr($donnees, $p + 2); |
|
| 225 | 225 | } |
| 226 | 226 | $chaine = str_replace("\n", "\r\n", $donnees); |
| 227 | 227 | } |
| 228 | 228 | else { |
| 229 | 229 | /* boundary automatique */ |
| 230 | 230 | // Si on a plus de 500 octects de donnees, on "boundarise" |
| 231 | - if ($boundary===''){ |
|
| 231 | + if ($boundary === '') { |
|
| 232 | 232 | $taille = 0; |
| 233 | - foreach ($donnees as $cle => $valeur){ |
|
| 234 | - if (is_array($valeur)){ |
|
| 235 | - foreach ($valeur as $val2){ |
|
| 233 | + foreach ($donnees as $cle => $valeur) { |
|
| 234 | + if (is_array($valeur)) { |
|
| 235 | + foreach ($valeur as $val2) { |
|
| 236 | 236 | $taille += strlen($val2); |
| 237 | 237 | } |
| 238 | 238 | } else { |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | $taille += strlen($valeur); |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | - if ($taille>500){ |
|
| 244 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 243 | + if ($taille > 500) { |
|
| 244 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if (is_string($boundary) and strlen($boundary)){ |
|
| 248 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 249 | 249 | // fabrique une chaine HTTP pour un POST avec boundary |
| 250 | 250 | $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
| 251 | 251 | $chaine = ''; |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | // http://doc.spip.org/@recuperer_page |
| 335 | 335 | function recuperer_page($url, $trans = false, $get_headers = false, |
| 336 | 336 | $taille_max = null, $datas = '', $boundary = '', $refuser_gz = false, |
| 337 | - $date_verif = '', $uri_referer = ''){ |
|
| 337 | + $date_verif = '', $uri_referer = '') { |
|
| 338 | 338 | $gz = false; |
| 339 | 339 | |
| 340 | 340 | // $copy = copier le fichier ? |
| 341 | - $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 341 | + $copy = (is_string($trans) AND strlen($trans) > 5); // eviter "false" :-) |
|
| 342 | 342 | |
| 343 | 343 | if (is_null($taille_max)) |
| 344 | 344 | $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
| 345 | 345 | |
| 346 | 346 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// |
| 347 | 347 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 348 | - if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url; |
|
| 348 | + if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://'.$url; |
|
| 349 | 349 | $url = url_to_ascii($url); |
| 350 | 350 | |
| 351 | - if ($taille_max==0) |
|
| 351 | + if ($taille_max == 0) |
|
| 352 | 352 | $get = 'HEAD'; |
| 353 | 353 | else |
| 354 | 354 | $get = 'GET'; |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | if (!empty($datas)) { |
| 357 | 357 | $get = 'POST'; |
| 358 | 358 | list($type, $postdata) = prepare_donnees_post($datas, $boundary); |
| 359 | - $datas = $type . 'Content-Length: ' . strlen($postdata) . "\r\n\r\n" . $postdata; |
|
| 359 | + $datas = $type.'Content-Length: '.strlen($postdata)."\r\n\r\n".$postdata; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // dix tentatives maximum en cas d'entetes 301... |
| 363 | - for ($i = 0; $i<10; $i++){ |
|
| 363 | + for ($i = 0; $i < 10; $i++) { |
|
| 364 | 364 | $url = recuperer_lapage($url, $trans, $get, $taille_max, $datas, $refuser_gz, $date_verif, $uri_referer); |
| 365 | 365 | if (!$url) return false; |
| 366 | - if (is_array($url)){ |
|
| 366 | + if (is_array($url)) { |
|
| 367 | 367 | list($headers, $result) = $url; |
| 368 | - return ($get_headers ? $headers . "\n" : '') . $result; |
|
| 368 | + return ($get_headers ? $headers."\n" : '').$result; |
|
| 369 | 369 | } else spip_log("recuperer page recommence sur $url"); |
| 370 | 370 | } |
| 371 | 371 | } |
@@ -375,9 +375,9 @@ discard block |
||
| 375 | 375 | // si $trans est null -> on ne veut que les headers |
| 376 | 376 | // si $trans est une chaine, c'est un nom de fichier pour ecrire directement dedans |
| 377 | 377 | // http://doc.spip.org/@recuperer_lapage |
| 378 | -function recuperer_lapage($url, $trans = false, $get = 'GET', $taille_max = _INC_DISTANT_MAX_SIZE, $datas = '', $refuser_gz = false, $date_verif = '', $uri_referer = ''){ |
|
| 378 | +function recuperer_lapage($url, $trans = false, $get = 'GET', $taille_max = _INC_DISTANT_MAX_SIZE, $datas = '', $refuser_gz = false, $date_verif = '', $uri_referer = '') { |
|
| 379 | 379 | // $copy = copier le fichier ? |
| 380 | - $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
|
| 380 | + $copy = (is_string($trans) AND strlen($trans) > 5); // eviter "false" :-) |
|
| 381 | 381 | |
| 382 | 382 | // si on ecrit directement dans un fichier, pour ne pas manipuler |
| 383 | 383 | // en memoire refuser gz |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | |
| 387 | 387 | // ouvrir la connexion et envoyer la requete et ses en-tetes |
| 388 | 388 | list($f, $fopen) = init_http($get, $url, $refuser_gz, $uri_referer, $datas, _INC_DISTANT_VERSION_HTTP, $date_verif); |
| 389 | - if (!$f){ |
|
| 389 | + if (!$f) { |
|
| 390 | 390 | spip_log("ECHEC init_http $url"); |
| 391 | 391 | return false; |
| 392 | 392 | } |
@@ -398,25 +398,25 @@ discard block |
||
| 398 | 398 | $headers = ''; |
| 399 | 399 | else { |
| 400 | 400 | $headers = recuperer_entetes($f, $date_verif); |
| 401 | - if (is_numeric($headers)){ |
|
| 401 | + if (is_numeric($headers)) { |
|
| 402 | 402 | fclose($f); |
| 403 | 403 | // Chinoisierie inexplicable pour contrer |
| 404 | 404 | // les actions liberticides de l'empire du milieu |
| 405 | - if ($headers){ |
|
| 405 | + if ($headers) { |
|
| 406 | 406 | spip_log("HTTP status $headers pour $url"); |
| 407 | 407 | return false; |
| 408 | 408 | } |
| 409 | 409 | $t = @parse_url($url); |
| 410 | 410 | $host = $t['host']; |
| 411 | 411 | if (!need_proxy($host) |
| 412 | - AND $result = @file_get_contents($url)){ |
|
| 412 | + AND $result = @file_get_contents($url)) { |
|
| 413 | 413 | // on peuple les headers de vide et on continue |
| 414 | 414 | $headers = array(''); |
| 415 | 415 | } |
| 416 | 416 | else |
| 417 | 417 | return false; |
| 418 | 418 | } |
| 419 | - if (!is_array($headers)){ // cas Location |
|
| 419 | + if (!is_array($headers)) { // cas Location |
|
| 420 | 420 | fclose($f); |
| 421 | 421 | include_spip('inc/filtres'); |
| 422 | 422 | return suivre_lien($url, $headers); |
@@ -424,16 +424,16 @@ discard block |
||
| 424 | 424 | $headers = join('', $headers); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - if ($trans===NULL) return array($headers, ''); |
|
| 427 | + if ($trans === NULL) return array($headers, ''); |
|
| 428 | 428 | |
| 429 | 429 | // s'il faut deballer, le faire via un fichier temporaire |
| 430 | 430 | // sinon la memoire explose pour les gros flux |
| 431 | 431 | |
| 432 | 432 | $gz = preg_match(",\bContent-Encoding: .*gzip,is", $headers) ? |
| 433 | - (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz') : ''; |
|
| 433 | + (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz') : ''; |
|
| 434 | 434 | |
| 435 | 435 | # spip_log("entete ($trans $copy $gz)\n$headers"); |
| 436 | - if (!$result){ |
|
| 436 | + if (!$result) { |
|
| 437 | 437 | $result = recuperer_body($f, $taille_max, $gz ? $gz : ($copy ? $trans : '')); |
| 438 | 438 | fclose($f); |
| 439 | 439 | } |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | return array($headers, $result); |
| 442 | 442 | |
| 443 | 443 | // Decompresser au besoin |
| 444 | - if ($gz){ |
|
| 444 | + if ($gz) { |
|
| 445 | 445 | $result = join('', gzfile($gz)); |
| 446 | 446 | supprimer_fichier($gz); |
| 447 | 447 | } |
| 448 | 448 | // Faut-il l'importer dans notre charset local ? |
| 449 | - if ($trans===true){ |
|
| 449 | + if ($trans === true) { |
|
| 450 | 450 | include_spip('inc/charsets'); |
| 451 | 451 | $result = transcoder_page($result, $headers); |
| 452 | 452 | } |
@@ -455,32 +455,32 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // http://doc.spip.org/@recuperer_body |
| 458 | -function recuperer_body($f, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = ''){ |
|
| 458 | +function recuperer_body($f, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
|
| 459 | 459 | $taille = 0; |
| 460 | 460 | $result = ''; |
| 461 | 461 | $fp = false; |
| 462 | - if ($fichier){ |
|
| 462 | + if ($fichier) { |
|
| 463 | 463 | include_spip("inc/acces"); |
| 464 | 464 | $tmpfile = "$fichier.".creer_uniqid().".tmp"; |
| 465 | 465 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 466 | - if (!$fp AND file_exists($fichier)){ |
|
| 466 | + if (!$fp AND file_exists($fichier)) { |
|
| 467 | 467 | return filesize($fichier); |
| 468 | 468 | } |
| 469 | 469 | if (!$fp) |
| 470 | 470 | return false; |
| 471 | 471 | $result = 0; // on renvoie la taille du fichier |
| 472 | 472 | } |
| 473 | - while (!feof($f) AND $taille<$taille_max){ |
|
| 473 | + while (!feof($f) AND $taille < $taille_max) { |
|
| 474 | 474 | $res = fread($f, 16384); |
| 475 | 475 | $taille += strlen($res); |
| 476 | - if ($fp){ |
|
| 476 | + if ($fp) { |
|
| 477 | 477 | fwrite($fp, $res); |
| 478 | 478 | $result = $taille; |
| 479 | 479 | } |
| 480 | 480 | else |
| 481 | 481 | $result .= $res; |
| 482 | 482 | } |
| 483 | - if ($fp){ |
|
| 483 | + if ($fp) { |
|
| 484 | 484 | spip_fclose_unlock($fp); |
| 485 | 485 | spip_unlink($fichier); |
| 486 | 486 | @rename($tmpfile, $fichier); |
@@ -496,24 +496,24 @@ discard block |
||
| 496 | 496 | // le tableau des entetes dans tous les autres cas |
| 497 | 497 | |
| 498 | 498 | // http://doc.spip.org/@recuperer_entetes |
| 499 | -function recuperer_entetes($f, $date_verif = ''){ |
|
| 499 | +function recuperer_entetes($f, $date_verif = '') { |
|
| 500 | 500 | $s = @trim(fgets($f, 16384)); |
| 501 | 501 | |
| 502 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)){ |
|
| 502 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 503 | 503 | return 0; |
| 504 | 504 | } |
| 505 | 505 | $status = intval($r[1]); |
| 506 | 506 | $headers = array(); |
| 507 | 507 | $not_modif = $location = false; |
| 508 | - while ($s = trim(fgets($f, 16384))){ |
|
| 509 | - $headers[] = $s . "\n"; |
|
| 508 | + while ($s = trim(fgets($f, 16384))) { |
|
| 509 | + $headers[] = $s."\n"; |
|
| 510 | 510 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 511 | 511 | list(, $d, $v) = $r; |
| 512 | - if (strtolower(trim($d))=='location' AND $status>=300 AND $status<400){ |
|
| 512 | + if (strtolower(trim($d)) == 'location' AND $status >= 300 AND $status < 400) { |
|
| 513 | 513 | $location = $v; |
| 514 | 514 | } |
| 515 | - elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 516 | - if ($date_verif>=strtotime($v)){ |
|
| 515 | + elseif ($date_verif AND ($d == 'Last-Modified')) { |
|
| 516 | + if ($date_verif >= strtotime($v)) { |
|
| 517 | 517 | //Cas ou la page distante n'a pas bouge depuis |
| 518 | 518 | //la derniere visite |
| 519 | 519 | $not_modif = true; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | if ($location) |
| 525 | 525 | return $location; |
| 526 | - if ($status!=200 or $not_modif) |
|
| 526 | + if ($status != 200 or $not_modif) |
|
| 527 | 527 | return $status; |
| 528 | 528 | return $headers; |
| 529 | 529 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | // mais la tout de suite je ne trouve pas l'idee, etant donne les limitations |
| 534 | 534 | // des filesystems |
| 535 | 535 | // http://doc.spip.org/@nom_fichier_copie_locale |
| 536 | -function nom_fichier_copie_locale($source, $extension){ |
|
| 536 | +function nom_fichier_copie_locale($source, $extension) { |
|
| 537 | 537 | include_spip('inc/documents'); |
| 538 | 538 | |
| 539 | 539 | $d = creer_repertoire_documents('distant'); # IMG/distant/ |
@@ -541,12 +541,12 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | // on se place tout le temps comme si on etait a la racine |
| 543 | 543 | if (_DIR_RACINE) |
| 544 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 544 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 545 | 545 | |
| 546 | 546 | $m = md5($source); |
| 547 | 547 | |
| 548 | 548 | return $d |
| 549 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 549 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 550 | 550 | . substr($m, 0, 4) |
| 551 | 551 | . ".$extension"; |
| 552 | 552 | } |
@@ -555,11 +555,11 @@ discard block |
||
| 555 | 555 | // Donne le nom de la copie locale de la source |
| 556 | 556 | // |
| 557 | 557 | // http://doc.spip.org/@fichier_copie_locale |
| 558 | -function fichier_copie_locale($source){ |
|
| 558 | +function fichier_copie_locale($source) { |
|
| 559 | 559 | // Si c'est deja local pas de souci |
| 560 | - if (!preg_match(',^\w+://,', $source)){ |
|
| 560 | + if (!preg_match(',^\w+://,', $source)) { |
|
| 561 | 561 | if (_DIR_RACINE) |
| 562 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 562 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 563 | 563 | return $source; |
| 564 | 564 | } |
| 565 | 565 | |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | if ($ext |
| 572 | 572 | AND preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 573 | 573 | AND $f = nom_fichier_copie_locale($source, $ext) |
| 574 | - AND file_exists(_DIR_RACINE . $f) |
|
| 574 | + AND file_exists(_DIR_RACINE.$f) |
|
| 575 | 575 | ) |
| 576 | 576 | return $f; |
| 577 | 577 | |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | // Si c'est deja dans la table des documents, |
| 580 | 580 | // ramener le nom de sa copie potentielle |
| 581 | 581 | |
| 582 | - $ext = sql_getfetsel("extension", "spip_documents", "fichier=" . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 582 | + $ext = sql_getfetsel("extension", "spip_documents", "fichier=".sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | if ($ext) return nom_fichier_copie_locale($source, $ext); |
@@ -589,25 +589,25 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 591 | 591 | |
| 592 | - if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 592 | + if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=".sql_quote($ext))) { |
|
| 593 | 593 | $f = nom_fichier_copie_locale($source, $ext); |
| 594 | - if (file_exists(_DIR_RACINE . $f)) |
|
| 594 | + if (file_exists(_DIR_RACINE.$f)) |
|
| 595 | 595 | return $f; |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | // Ping pour voir si son extension est connue et autorisee |
| 599 | 599 | // avec mise en cache du resultat du ping |
| 600 | 600 | |
| 601 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 601 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 602 | 602 | if (!@file_exists($cache) |
| 603 | 603 | OR !$path_parts = @unserialize(spip_file_get_contents($cache)) |
| 604 | - OR _request('var_mode')=='recalcul' |
|
| 605 | - ){ |
|
| 604 | + OR _request('var_mode') == 'recalcul' |
|
| 605 | + ) { |
|
| 606 | 606 | $path_parts = recuperer_infos_distantes($source, 0, false); |
| 607 | 607 | ecrire_fichier($cache, serialize($path_parts)); |
| 608 | 608 | } |
| 609 | 609 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 610 | - if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
|
| 610 | + if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=".sql_quote($ext))) { |
|
| 611 | 611 | return nom_fichier_copie_locale($source, $ext); |
| 612 | 612 | } |
| 613 | 613 | spip_log("pas de copie locale pour $source"); |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | #$a['mime_type'] = chaine |
| 627 | 627 | |
| 628 | 628 | // http://doc.spip.org/@recuperer_infos_distantes |
| 629 | -function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true){ |
|
| 629 | +function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
|
| 630 | 630 | |
| 631 | 631 | // pas la peine de perdre son temps |
| 632 | 632 | if (!tester_url_absolue($source)) { |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | // On va directement charger le debut des images et des fichiers html, |
| 643 | 643 | // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
| 644 | 644 | // ca echoue l'utilisateur devra les entrer... |
| 645 | - if ($headers = recuperer_page($source, false, true, $max, '', '', true)){ |
|
| 645 | + if ($headers = recuperer_page($source, false, true, $max, '', '', true)) { |
|
| 646 | 646 | list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
| 647 | 647 | |
| 648 | 648 | if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) |
@@ -660,36 +660,36 @@ discard block |
||
| 660 | 660 | // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
| 661 | 661 | // ou le Content-Disposition: attachment; filename=... |
| 662 | 662 | $t = null; |
| 663 | - if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))){ |
|
| 663 | + if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 664 | 664 | if (!$t |
| 665 | 665 | AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 666 | - ){ |
|
| 667 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 666 | + ) { |
|
| 667 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=".sql_quote($rext[1], '', 'text')); |
|
| 668 | 668 | } |
| 669 | 669 | if (!$t |
| 670 | 670 | AND preg_match(",^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims", $headers, $m) |
| 671 | 671 | AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 672 | - ){ |
|
| 673 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); |
|
| 672 | + ) { |
|
| 673 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=".sql_quote($rext[1], '', 'text')); |
|
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 678 | 678 | if (!$t) |
| 679 | - $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 679 | + $t = sql_fetsel("extension", "spip_types_documents", "mime_type=".sql_quote($mime_type)); |
|
| 680 | 680 | |
| 681 | 681 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
| 682 | 682 | // On essaie de nouveau avec l'extension |
| 683 | 683 | if (!$t |
| 684 | - AND $mime_type!='text/plain' |
|
| 684 | + AND $mime_type != 'text/plain' |
|
| 685 | 685 | AND preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 686 | - ){ |
|
| 687 | - $t = sql_fetsel("extension", "spip_types_documents", "extension=" . sql_quote($rext[1],'','text')); # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 686 | + ) { |
|
| 687 | + $t = sql_fetsel("extension", "spip_types_documents", "extension=".sql_quote($rext[1], '', 'text')); # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
| 691 | - if ($t){ |
|
| 692 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 691 | + if ($t) { |
|
| 692 | + spip_log("mime-type $mime_type ok, extension ".$t['extension']); |
|
| 693 | 693 | $a['extension'] = $t['extension']; |
| 694 | 694 | } else { |
| 695 | 695 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // Echec avec HEAD, on tente avec GET |
| 709 | - if (!$a AND !$max){ |
|
| 709 | + if (!$a AND !$max) { |
|
| 710 | 710 | spip_log("tenter GET $source"); |
| 711 | 711 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 712 | 712 | } |
@@ -718,16 +718,16 @@ discard block |
||
| 718 | 718 | |
| 719 | 719 | // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
| 720 | 720 | // recharger le document en GET et recuperer des donnees supplementaires... |
| 721 | - if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)){ |
|
| 722 | - if ($max==0 |
|
| 723 | - AND $a['taille']<_INC_DISTANT_MAX_SIZE |
|
| 724 | - AND (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension'])!==false) |
|
| 721 | + if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)) { |
|
| 722 | + if ($max == 0 |
|
| 723 | + AND $a['taille'] < _INC_DISTANT_MAX_SIZE |
|
| 724 | + AND (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension']) !== false) |
|
| 725 | 725 | AND $charger_si_petite_image |
| 726 | - ){ |
|
| 726 | + ) { |
|
| 727 | 727 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 728 | 728 | } |
| 729 | - else if ($a['body']){ |
|
| 730 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 729 | + else if ($a['body']) { |
|
| 730 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $a['extension']); |
|
| 731 | 731 | ecrire_fichier($a['fichier'], $a['body']); |
| 732 | 732 | $size_image = @getimagesize($a['fichier']); |
| 733 | 733 | $a['largeur'] = intval($size_image[0]); |
@@ -738,21 +738,21 @@ discard block |
||
| 738 | 738 | |
| 739 | 739 | // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
| 740 | 740 | // ce sera mieux que 0x0 |
| 741 | - if ($a AND $a['extension']=='swf' |
|
| 741 | + if ($a AND $a['extension'] == 'swf' |
|
| 742 | 742 | AND !$a['largeur'] |
| 743 | - ){ |
|
| 743 | + ) { |
|
| 744 | 744 | $a['largeur'] = 425; |
| 745 | 745 | $a['hauteur'] = 350; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - if ($mime_type=='text/html'){ |
|
| 748 | + if ($mime_type == 'text/html') { |
|
| 749 | 749 | include_spip('inc/filtres'); |
| 750 | 750 | $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
| 751 | 751 | if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) |
| 752 | 752 | $a['titre'] = corriger_caracteres(trim($regs[1])); |
| 753 | 753 | if (!$a['taille']) $a['taille'] = strlen($page); # a peu pres |
| 754 | 754 | } |
| 755 | - $a['mime_type']=$mime_type; |
|
| 755 | + $a['mime_type'] = $mime_type; |
|
| 756 | 756 | |
| 757 | 757 | return $a; |
| 758 | 758 | } |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | * @param string $http_noproxy |
| 769 | 769 | * @return string |
| 770 | 770 | */ |
| 771 | -function need_proxy($host, $http_proxy = null, $http_noproxy = null){ |
|
| 771 | +function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
|
| 772 | 772 | if (is_null($http_proxy)) |
| 773 | 773 | $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
| 774 | 774 | if (is_null($http_noproxy)) |
@@ -777,8 +777,8 @@ discard block |
||
| 777 | 777 | $domain = substr($host, strpos($host, '.')); |
| 778 | 778 | |
| 779 | 779 | return ($http_proxy |
| 780 | - AND (strpos(" $http_noproxy ", " $host ")===false |
|
| 781 | - AND (strpos(" $http_noproxy ", " $domain ")===false))) |
|
| 780 | + AND (strpos(" $http_noproxy ", " $host ") === false |
|
| 781 | + AND (strpos(" $http_noproxy ", " $domain ") === false))) |
|
| 782 | 782 | ? $http_proxy : ''; |
| 783 | 783 | } |
| 784 | 784 | |
@@ -787,37 +787,37 @@ discard block |
||
| 787 | 787 | // retourne le descripteur sur lequel lire la reponse |
| 788 | 788 | // |
| 789 | 789 | // http://doc.spip.org/@init_http |
| 790 | -function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
|
| 790 | +function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = '') { |
|
| 791 | 791 | $user = $via_proxy = $proxy_user = ''; |
| 792 | 792 | $fopen = false; |
| 793 | 793 | |
| 794 | 794 | $t = @parse_url($url); |
| 795 | 795 | $host = $t['host']; |
| 796 | - if ($t['scheme']=='http'){ |
|
| 796 | + if ($t['scheme'] == 'http') { |
|
| 797 | 797 | $scheme = 'http'; |
| 798 | 798 | $noproxy = ''; |
| 799 | - } elseif ($t['scheme']=='https') { |
|
| 799 | + } elseif ($t['scheme'] == 'https') { |
|
| 800 | 800 | $scheme = 'ssl'; |
| 801 | 801 | $noproxy = 'ssl://'; |
| 802 | 802 | if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; |
| 803 | 803 | } |
| 804 | 804 | else { |
| 805 | 805 | $scheme = $t['scheme']; |
| 806 | - $noproxy = $scheme . '://'; |
|
| 806 | + $noproxy = $scheme.'://'; |
|
| 807 | 807 | } |
| 808 | 808 | if (isset($t['user'])) |
| 809 | 809 | $user = array($t['user'], $t['pass']); |
| 810 | 810 | |
| 811 | 811 | if (!isset($t['port']) || !($port = $t['port'])) $port = 80; |
| 812 | 812 | if (!isset($t['path']) || !($path = $t['path'])) $path = "/"; |
| 813 | - if (@$t['query']) $path .= "?" . $t['query']; |
|
| 813 | + if (@$t['query']) $path .= "?".$t['query']; |
|
| 814 | 814 | |
| 815 | 815 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
| 816 | - if (!$f){ |
|
| 816 | + if (!$f) { |
|
| 817 | 817 | // fallback : fopen |
| 818 | 818 | if (!need_proxy($host) |
| 819 | 819 | AND !_request('tester_proxy') |
| 820 | - AND (!isset($GLOBALS['inc_distant_allow_fopen']) OR $GLOBALS['inc_distant_allow_fopen'])){ |
|
| 820 | + AND (!isset($GLOBALS['inc_distant_allow_fopen']) OR $GLOBALS['inc_distant_allow_fopen'])) { |
|
| 821 | 821 | $f = @fopen($url, "rb"); |
| 822 | 822 | spip_log("connexion vers $url par simple fopen"); |
| 823 | 823 | $fopen = true; |
@@ -831,37 +831,37 @@ discard block |
||
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | // http://doc.spip.org/@lance_requete |
| 834 | -function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = ''){ |
|
| 834 | +function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = '') { |
|
| 835 | 835 | |
| 836 | 836 | $proxy_user = ''; |
| 837 | 837 | $http_proxy = need_proxy($host); |
| 838 | - if ($user) $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 838 | + if ($user) $user = urlencode($user[0]).":".urlencode($user[1]); |
|
| 839 | 839 | |
| 840 | 840 | $connect = ''; |
| 841 | 841 | if ($http_proxy) { |
| 842 | - if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 843 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 844 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 842 | + if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) { |
|
| 843 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 844 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 845 | 845 | . "Host: $path_host\r\n" |
| 846 | 846 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 847 | 847 | } else { |
| 848 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 848 | + $path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://") |
|
| 849 | 849 | . (!$user ? '' : "$user@") |
| 850 | - . "$host" . (($port!=80) ? ":$port" : "") . $path; |
|
| 850 | + . "$host".(($port != 80) ? ":$port" : "").$path; |
|
| 851 | 851 | } |
| 852 | 852 | $t2 = @parse_url($http_proxy); |
| 853 | 853 | $first_host = $t2['host']; |
| 854 | 854 | if (!($port = $t2['port'])) $port = 80; |
| 855 | 855 | if ($t2['user']) |
| 856 | - $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 856 | + $proxy_user = base64_encode($t2['user'].":".$t2['pass']); |
|
| 857 | 857 | } |
| 858 | 858 | else |
| 859 | - $first_host = $noproxy . $host; |
|
| 859 | + $first_host = $noproxy.$host; |
|
| 860 | 860 | |
| 861 | - if ($connect){ |
|
| 861 | + if ($connect) { |
|
| 862 | 862 | $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); |
| 863 | 863 | $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
| 864 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); |
|
| 864 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", "connect"); |
|
| 865 | 865 | if (!$f) return false; |
| 866 | 866 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
| 867 | 867 | |
@@ -869,23 +869,23 @@ discard block |
||
| 869 | 869 | fputs($f, "\r\n"); |
| 870 | 870 | $res = fread($f, 1024); |
| 871 | 871 | if (!$res |
| 872 | - OR !count($res = explode(' ',$res)) |
|
| 873 | - OR $res[1]!=='200'){ |
|
| 874 | - spip_log("Echec CONNECT sur $first_host:$port","connect"._LOG_INFO_IMPORTANTE); |
|
| 872 | + OR !count($res = explode(' ', $res)) |
|
| 873 | + OR $res[1] !== '200') { |
|
| 874 | + spip_log("Echec CONNECT sur $first_host:$port", "connect"._LOG_INFO_IMPORTANTE); |
|
| 875 | 875 | fclose($f); |
| 876 | 876 | return false; |
| 877 | 877 | } |
| 878 | 878 | // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
| 879 | 879 | stream_set_blocking($f, true); |
| 880 | 880 | // envoyer le handshake |
| 881 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 882 | - spip_log("OK CONNECT sur $first_host:$port","connect"); |
|
| 881 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 882 | + spip_log("OK CONNECT sur $first_host:$port", "connect"); |
|
| 883 | 883 | } |
| 884 | 884 | else { |
| 885 | 885 | $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
| 886 | 886 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 887 | 887 | if (!$f) { |
| 888 | - spip_log("Erreur connexion $errno $errstr",_LOG_ERREUR); |
|
| 888 | + spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 889 | 889 | return false; |
| 890 | 890 | } |
| 891 | 891 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -895,11 +895,11 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | $req = "$method $path $vers\r\n" |
| 897 | 897 | . "Host: $host\r\n" |
| 898 | - . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 899 | - . ($refuse_gz ? '' : ("Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 898 | + . "User-Agent: "._INC_DISTANT_USER_AGENT."\r\n" |
|
| 899 | + . ($refuse_gz ? '' : ("Accept-Encoding: "._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 900 | 900 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 901 | - . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) . " GMT\r\n")) |
|
| 902 | - . (!$user ? '' : ("Authorization: Basic " . base64_encode($user) . "\r\n")) |
|
| 901 | + . (!$date ? '' : "If-Modified-Since: ".(gmdate("D, d M Y H:i:s", $date)." GMT\r\n")) |
|
| 902 | + . (!$user ? '' : ("Authorization: Basic ".base64_encode($user)."\r\n")) |
|
| 903 | 903 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 904 | 904 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 905 | 905 | |
@@ -15,13 +15,25 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 18 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 19 | + return; |
|
| 20 | +} |
|
| 19 | 21 | |
| 20 | -if (!defined('_INC_DISTANT_VERSION_HTTP')) define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0"); |
|
| 21 | -if (!defined('_INC_DISTANT_CONTENT_ENCODING')) define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); |
|
| 22 | -if (!defined('_INC_DISTANT_USER_AGENT')) define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); |
|
| 23 | -if (!defined('_INC_DISTANT_MAX_SIZE')) define('_INC_DISTANT_MAX_SIZE',2097152); |
|
| 24 | -if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
|
| 22 | +if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0"); |
|
| 24 | +} |
|
| 25 | +if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); |
|
| 27 | +} |
|
| 28 | +if (!defined('_INC_DISTANT_USER_AGENT')) { |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); |
|
| 30 | +} |
|
| 31 | +if (!defined('_INC_DISTANT_MAX_SIZE')) { |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE',2097152); |
|
| 33 | +} |
|
| 34 | +if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
|
| 36 | +} |
|
| 25 | 37 | |
| 26 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 27 | 39 | preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) |
@@ -57,9 +69,9 @@ discard block |
||
| 57 | 69 | return @file_exists($source) ? $source : false; |
| 58 | 70 | } |
| 59 | 71 | |
| 60 | - if (is_null($local)) |
|
| 61 | - $local = fichier_copie_locale($source); |
|
| 62 | - else { |
|
| 72 | + if (is_null($local)) { |
|
| 73 | + $local = fichier_copie_locale($source); |
|
| 74 | + } else { |
|
| 63 | 75 | if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE))==0) { |
| 64 | 76 | $local = substr($local, strlen(_DIR_RACINE)); |
| 65 | 77 | } |
@@ -68,27 +80,36 @@ discard block |
||
| 68 | 80 | // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
| 69 | 81 | // par exemple un fichier qui ne figure pas dans nos documents ; |
| 70 | 82 | // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
| 71 | - if (!$local) return false; |
|
| 83 | + if (!$local) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 72 | 86 | |
| 73 | 87 | $localrac = _DIR_RACINE.$local; |
| 74 | 88 | $t = ($mode=='force') ? false : @file_exists($localrac); |
| 75 | 89 | |
| 76 | 90 | // test d'existence du fichier |
| 77 | - if ($mode=='test') return $t ? $local : ''; |
|
| 91 | + if ($mode=='test') { |
|
| 92 | + return $t ? $local : ''; |
|
| 93 | + } |
|
| 78 | 94 | |
| 79 | 95 | // sinon voir si on doit/peut le telecharger |
| 80 | - if ($local==$source OR !preg_match(',^\w+://,', $source)) |
|
| 81 | - return $local; |
|
| 96 | + if ($local==$source OR !preg_match(',^\w+://,', $source)) { |
|
| 97 | + return $local; |
|
| 98 | + } |
|
| 82 | 99 | |
| 83 | 100 | if ($mode=='modif' OR !$t){ |
| 84 | 101 | // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
| 85 | 102 | // et des eventuelles recuperations concurantes |
| 86 | 103 | include_spip("inc/acces"); |
| 87 | - if (!$taille_max) $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 104 | + if (!$taille_max) { |
|
| 105 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 106 | + } |
|
| 88 | 107 | $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : ''); |
| 89 | 108 | if (!$res) { |
| 90 | - if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 109 | + if (!$t) { |
|
| 110 | + // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 91 | 111 | spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE); |
| 112 | + } |
|
| 92 | 113 | return $t ? $local : false; |
| 93 | 114 | } |
| 94 | 115 | spip_log("copie_locale : recuperation $source sur $localrac taille $res OK"); |
@@ -224,8 +245,7 @@ discard block |
||
| 224 | 245 | $donnees = substr($donnees, $p+2); |
| 225 | 246 | } |
| 226 | 247 | $chaine = str_replace("\n", "\r\n", $donnees); |
| 227 | - } |
|
| 228 | - else { |
|
| 248 | + } else { |
|
| 229 | 249 | /* boundary automatique */ |
| 230 | 250 | // Si on a plus de 500 octects de donnees, on "boundarise" |
| 231 | 251 | if ($boundary===''){ |
@@ -340,18 +360,22 @@ discard block |
||
| 340 | 360 | // $copy = copier le fichier ? |
| 341 | 361 | $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
| 342 | 362 | |
| 343 | - if (is_null($taille_max)) |
|
| 344 | - $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 363 | + if (is_null($taille_max)) { |
|
| 364 | + $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 365 | + } |
|
| 345 | 366 | |
| 346 | 367 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// |
| 347 | 368 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 348 | - if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url; |
|
| 369 | + if (!preg_match(',^[a-z]+://,i', $url)) { |
|
| 370 | + $url = 'http://' . $url; |
|
| 371 | + } |
|
| 349 | 372 | $url = url_to_ascii($url); |
| 350 | 373 | |
| 351 | - if ($taille_max==0) |
|
| 352 | - $get = 'HEAD'; |
|
| 353 | - else |
|
| 354 | - $get = 'GET'; |
|
| 374 | + if ($taille_max==0) { |
|
| 375 | + $get = 'HEAD'; |
|
| 376 | + } else { |
|
| 377 | + $get = 'GET'; |
|
| 378 | + } |
|
| 355 | 379 | |
| 356 | 380 | if (!empty($datas)) { |
| 357 | 381 | $get = 'POST'; |
@@ -362,11 +386,15 @@ discard block |
||
| 362 | 386 | // dix tentatives maximum en cas d'entetes 301... |
| 363 | 387 | for ($i = 0; $i<10; $i++){ |
| 364 | 388 | $url = recuperer_lapage($url, $trans, $get, $taille_max, $datas, $refuser_gz, $date_verif, $uri_referer); |
| 365 | - if (!$url) return false; |
|
| 389 | + if (!$url) { |
|
| 390 | + return false; |
|
| 391 | + } |
|
| 366 | 392 | if (is_array($url)){ |
| 367 | 393 | list($headers, $result) = $url; |
| 368 | 394 | return ($get_headers ? $headers . "\n" : '') . $result; |
| 369 | - } else spip_log("recuperer page recommence sur $url"); |
|
| 395 | + } else { |
|
| 396 | + spip_log("recuperer page recommence sur $url"); |
|
| 397 | + } |
|
| 370 | 398 | } |
| 371 | 399 | } |
| 372 | 400 | |
@@ -381,8 +409,9 @@ discard block |
||
| 381 | 409 | |
| 382 | 410 | // si on ecrit directement dans un fichier, pour ne pas manipuler |
| 383 | 411 | // en memoire refuser gz |
| 384 | - if ($copy) |
|
| 385 | - $refuser_gz = true; |
|
| 412 | + if ($copy) { |
|
| 413 | + $refuser_gz = true; |
|
| 414 | + } |
|
| 386 | 415 | |
| 387 | 416 | // ouvrir la connexion et envoyer la requete et ses en-tetes |
| 388 | 417 | list($f, $fopen) = init_http($get, $url, $refuser_gz, $uri_referer, $datas, _INC_DISTANT_VERSION_HTTP, $date_verif); |
@@ -394,9 +423,9 @@ discard block |
||
| 394 | 423 | $result = ''; |
| 395 | 424 | // Sauf en fopen, envoyer le flux d'entree |
| 396 | 425 | // et recuperer les en-tetes de reponses |
| 397 | - if ($fopen) |
|
| 398 | - $headers = ''; |
|
| 399 | - else { |
|
| 426 | + if ($fopen) { |
|
| 427 | + $headers = ''; |
|
| 428 | + } else { |
|
| 400 | 429 | $headers = recuperer_entetes($f, $date_verif); |
| 401 | 430 | if (is_numeric($headers)){ |
| 402 | 431 | fclose($f); |
@@ -412,9 +441,9 @@ discard block |
||
| 412 | 441 | AND $result = @file_get_contents($url)){ |
| 413 | 442 | // on peuple les headers de vide et on continue |
| 414 | 443 | $headers = array(''); |
| 444 | + } else { |
|
| 445 | + return false; |
|
| 415 | 446 | } |
| 416 | - else |
|
| 417 | - return false; |
|
| 418 | 447 | } |
| 419 | 448 | if (!is_array($headers)){ // cas Location |
| 420 | 449 | fclose($f); |
@@ -424,7 +453,9 @@ discard block |
||
| 424 | 453 | $headers = join('', $headers); |
| 425 | 454 | } |
| 426 | 455 | |
| 427 | - if ($trans===NULL) return array($headers, ''); |
|
| 456 | + if ($trans===NULL) { |
|
| 457 | + return array($headers, ''); |
|
| 458 | + } |
|
| 428 | 459 | |
| 429 | 460 | // s'il faut deballer, le faire via un fichier temporaire |
| 430 | 461 | // sinon la memoire explose pour les gros flux |
@@ -437,8 +468,9 @@ discard block |
||
| 437 | 468 | $result = recuperer_body($f, $taille_max, $gz ? $gz : ($copy ? $trans : '')); |
| 438 | 469 | fclose($f); |
| 439 | 470 | } |
| 440 | - if (!$result) |
|
| 441 | - return array($headers, $result); |
|
| 471 | + if (!$result) { |
|
| 472 | + return array($headers, $result); |
|
| 473 | + } |
|
| 442 | 474 | |
| 443 | 475 | // Decompresser au besoin |
| 444 | 476 | if ($gz){ |
@@ -466,8 +498,9 @@ discard block |
||
| 466 | 498 | if (!$fp AND file_exists($fichier)){ |
| 467 | 499 | return filesize($fichier); |
| 468 | 500 | } |
| 469 | - if (!$fp) |
|
| 470 | - return false; |
|
| 501 | + if (!$fp) { |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 471 | 504 | $result = 0; // on renvoie la taille du fichier |
| 472 | 505 | } |
| 473 | 506 | while (!feof($f) AND $taille<$taille_max){ |
@@ -476,16 +509,17 @@ discard block |
||
| 476 | 509 | if ($fp){ |
| 477 | 510 | fwrite($fp, $res); |
| 478 | 511 | $result = $taille; |
| 512 | + } else { |
|
| 513 | + $result .= $res; |
|
| 479 | 514 | } |
| 480 | - else |
|
| 481 | - $result .= $res; |
|
| 482 | 515 | } |
| 483 | 516 | if ($fp){ |
| 484 | 517 | spip_fclose_unlock($fp); |
| 485 | 518 | spip_unlink($fichier); |
| 486 | 519 | @rename($tmpfile, $fichier); |
| 487 | - if (!file_exists($fichier)) |
|
| 488 | - return false; |
|
| 520 | + if (!file_exists($fichier)) { |
|
| 521 | + return false; |
|
| 522 | + } |
|
| 489 | 523 | } |
| 490 | 524 | return $result; |
| 491 | 525 | } |
@@ -511,8 +545,7 @@ discard block |
||
| 511 | 545 | list(, $d, $v) = $r; |
| 512 | 546 | if (strtolower(trim($d))=='location' AND $status>=300 AND $status<400){ |
| 513 | 547 | $location = $v; |
| 514 | - } |
|
| 515 | - elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 548 | + } elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 516 | 549 | if ($date_verif>=strtotime($v)){ |
| 517 | 550 | //Cas ou la page distante n'a pas bouge depuis |
| 518 | 551 | //la derniere visite |
@@ -521,10 +554,12 @@ discard block |
||
| 521 | 554 | } |
| 522 | 555 | } |
| 523 | 556 | |
| 524 | - if ($location) |
|
| 525 | - return $location; |
|
| 526 | - if ($status!=200 or $not_modif) |
|
| 527 | - return $status; |
|
| 557 | + if ($location) { |
|
| 558 | + return $location; |
|
| 559 | + } |
|
| 560 | + if ($status!=200 or $not_modif) { |
|
| 561 | + return $status; |
|
| 562 | + } |
|
| 528 | 563 | return $headers; |
| 529 | 564 | } |
| 530 | 565 | |
@@ -540,8 +575,9 @@ discard block |
||
| 540 | 575 | $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
| 541 | 576 | |
| 542 | 577 | // on se place tout le temps comme si on etait a la racine |
| 543 | - if (_DIR_RACINE) |
|
| 544 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 578 | + if (_DIR_RACINE) { |
|
| 579 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 580 | + } |
|
| 545 | 581 | |
| 546 | 582 | $m = md5($source); |
| 547 | 583 | |
@@ -558,8 +594,9 @@ discard block |
||
| 558 | 594 | function fichier_copie_locale($source){ |
| 559 | 595 | // Si c'est deja local pas de souci |
| 560 | 596 | if (!preg_match(',^\w+://,', $source)){ |
| 561 | - if (_DIR_RACINE) |
|
| 562 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 597 | + if (_DIR_RACINE) { |
|
| 598 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 599 | + } |
|
| 563 | 600 | return $source; |
| 564 | 601 | } |
| 565 | 602 | |
@@ -572,8 +609,9 @@ discard block |
||
| 572 | 609 | AND preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 573 | 610 | AND $f = nom_fichier_copie_locale($source, $ext) |
| 574 | 611 | AND file_exists(_DIR_RACINE . $f) |
| 575 | - ) |
|
| 576 | - return $f; |
|
| 612 | + ) { |
|
| 613 | + return $f; |
|
| 614 | + } |
|
| 577 | 615 | |
| 578 | 616 | |
| 579 | 617 | // Si c'est deja dans la table des documents, |
@@ -582,7 +620,9 @@ discard block |
||
| 582 | 620 | $ext = sql_getfetsel("extension", "spip_documents", "fichier=" . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
| 583 | 621 | |
| 584 | 622 | |
| 585 | - if ($ext) return nom_fichier_copie_locale($source, $ext); |
|
| 623 | + if ($ext) { |
|
| 624 | + return nom_fichier_copie_locale($source, $ext); |
|
| 625 | + } |
|
| 586 | 626 | |
| 587 | 627 | // voir si l'extension indiquee dans le nom du fichier est ok |
| 588 | 628 | // et si il n'aurait pas deja ete rapatrie |
@@ -591,8 +631,9 @@ discard block |
||
| 591 | 631 | |
| 592 | 632 | if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
| 593 | 633 | $f = nom_fichier_copie_locale($source, $ext); |
| 594 | - if (file_exists(_DIR_RACINE . $f)) |
|
| 595 | - return $f; |
|
| 634 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 635 | + return $f; |
|
| 636 | + } |
|
| 596 | 637 | } |
| 597 | 638 | |
| 598 | 639 | // Ping pour voir si son extension est connue et autorisee |
@@ -645,14 +686,17 @@ discard block |
||
| 645 | 686 | if ($headers = recuperer_page($source, false, true, $max, '', '', true)){ |
| 646 | 687 | list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
| 647 | 688 | |
| 648 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) |
|
| 649 | - $mime_type = (trim($regs[1])); |
|
| 650 | - else |
|
| 651 | - $mime_type = ''; // inconnu |
|
| 689 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 690 | + $mime_type = (trim($regs[1])); |
|
| 691 | + } else { |
|
| 692 | + $mime_type = ''; |
|
| 693 | + } |
|
| 694 | + // inconnu |
|
| 652 | 695 | |
| 653 | 696 | // Appliquer les alias |
| 654 | - while (isset($mime_alias[$mime_type])) |
|
| 655 | - $mime_type = $mime_alias[$mime_type]; |
|
| 697 | + while (isset($mime_alias[$mime_type])) { |
|
| 698 | + $mime_type = $mime_alias[$mime_type]; |
|
| 699 | + } |
|
| 656 | 700 | |
| 657 | 701 | // Si on a un mime-type insignifiant |
| 658 | 702 | // text/plain,application/octet-stream ou vide |
@@ -675,8 +719,9 @@ discard block |
||
| 675 | 719 | } |
| 676 | 720 | |
| 677 | 721 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 678 | - if (!$t) |
|
| 679 | - $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 722 | + if (!$t) { |
|
| 723 | + $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 724 | + } |
|
| 680 | 725 | |
| 681 | 726 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
| 682 | 727 | // On essaie de nouveau avec l'extension |
@@ -695,14 +740,17 @@ discard block |
||
| 695 | 740 | # par defaut on retombe sur '.bin' si c'est autorise |
| 696 | 741 | spip_log("mime-type $mime_type inconnu"); |
| 697 | 742 | $t = sql_fetsel("extension", "spip_types_documents", "extension='bin'"); |
| 698 | - if (!$t) return false; |
|
| 743 | + if (!$t) { |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 699 | 746 | $a['extension'] = $t['extension']; |
| 700 | 747 | } |
| 701 | 748 | |
| 702 | 749 | if (preg_match(",\nContent-Length: *([^[:space:]]*),i", |
| 703 | 750 | "\n$headers", $regs) |
| 704 | - ) |
|
| 705 | - $a['taille'] = intval($regs[1]); |
|
| 751 | + ) { |
|
| 752 | + $a['taille'] = intval($regs[1]); |
|
| 753 | + } |
|
| 706 | 754 | } |
| 707 | 755 | |
| 708 | 756 | // Echec avec HEAD, on tente avec GET |
@@ -725,8 +773,7 @@ discard block |
||
| 725 | 773 | AND $charger_si_petite_image |
| 726 | 774 | ){ |
| 727 | 775 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 728 | - } |
|
| 729 | - else if ($a['body']){ |
|
| 776 | + } else if ($a['body']){ |
|
| 730 | 777 | $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
| 731 | 778 | ecrire_fichier($a['fichier'], $a['body']); |
| 732 | 779 | $size_image = @getimagesize($a['fichier']); |
@@ -748,9 +795,13 @@ discard block |
||
| 748 | 795 | if ($mime_type=='text/html'){ |
| 749 | 796 | include_spip('inc/filtres'); |
| 750 | 797 | $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
| 751 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) |
|
| 752 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 753 | - if (!$a['taille']) $a['taille'] = strlen($page); # a peu pres |
|
| 798 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 799 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 800 | + } |
|
| 801 | + if (!$a['taille']) { |
|
| 802 | + $a['taille'] = strlen($page); |
|
| 803 | + } |
|
| 804 | + # a peu pres |
|
| 754 | 805 | } |
| 755 | 806 | $a['mime_type']=$mime_type; |
| 756 | 807 | |
@@ -769,10 +820,12 @@ discard block |
||
| 769 | 820 | * @return string |
| 770 | 821 | */ |
| 771 | 822 | function need_proxy($host, $http_proxy = null, $http_noproxy = null){ |
| 772 | - if (is_null($http_proxy)) |
|
| 773 | - $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 774 | - if (is_null($http_noproxy)) |
|
| 775 | - $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 823 | + if (is_null($http_proxy)) { |
|
| 824 | + $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 825 | + } |
|
| 826 | + if (is_null($http_noproxy)) { |
|
| 827 | + $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 828 | + } |
|
| 776 | 829 | |
| 777 | 830 | $domain = substr($host, strpos($host, '.')); |
| 778 | 831 | |
@@ -799,18 +852,26 @@ discard block |
||
| 799 | 852 | } elseif ($t['scheme']=='https') { |
| 800 | 853 | $scheme = 'ssl'; |
| 801 | 854 | $noproxy = 'ssl://'; |
| 802 | - if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; |
|
| 803 | - } |
|
| 804 | - else { |
|
| 855 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 856 | + $t['port'] = 443; |
|
| 857 | + } |
|
| 858 | + } else { |
|
| 805 | 859 | $scheme = $t['scheme']; |
| 806 | 860 | $noproxy = $scheme . '://'; |
| 807 | 861 | } |
| 808 | - if (isset($t['user'])) |
|
| 809 | - $user = array($t['user'], $t['pass']); |
|
| 862 | + if (isset($t['user'])) { |
|
| 863 | + $user = array($t['user'], $t['pass']); |
|
| 864 | + } |
|
| 810 | 865 | |
| 811 | - if (!isset($t['port']) || !($port = $t['port'])) $port = 80; |
|
| 812 | - if (!isset($t['path']) || !($path = $t['path'])) $path = "/"; |
|
| 813 | - if (@$t['query']) $path .= "?" . $t['query']; |
|
| 866 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 867 | + $port = 80; |
|
| 868 | + } |
|
| 869 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 870 | + $path = "/"; |
|
| 871 | + } |
|
| 872 | + if (@$t['query']) { |
|
| 873 | + $path .= "?" . $t['query']; |
|
| 874 | + } |
|
| 814 | 875 | |
| 815 | 876 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
| 816 | 877 | if (!$f){ |
@@ -821,9 +882,9 @@ discard block |
||
| 821 | 882 | $f = @fopen($url, "rb"); |
| 822 | 883 | spip_log("connexion vers $url par simple fopen"); |
| 823 | 884 | $fopen = true; |
| 885 | + } else { |
|
| 886 | + $f = false; |
|
| 824 | 887 | } |
| 825 | - else |
|
| 826 | - $f = false; |
|
| 827 | 888 | // echec total |
| 828 | 889 | } |
| 829 | 890 | |
@@ -835,7 +896,9 @@ discard block |
||
| 835 | 896 | |
| 836 | 897 | $proxy_user = ''; |
| 837 | 898 | $http_proxy = need_proxy($host); |
| 838 | - if ($user) $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 899 | + if ($user) { |
|
| 900 | + $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 901 | + } |
|
| 839 | 902 | |
| 840 | 903 | $connect = ''; |
| 841 | 904 | if ($http_proxy) { |
@@ -851,18 +914,23 @@ discard block |
||
| 851 | 914 | } |
| 852 | 915 | $t2 = @parse_url($http_proxy); |
| 853 | 916 | $first_host = $t2['host']; |
| 854 | - if (!($port = $t2['port'])) $port = 80; |
|
| 855 | - if ($t2['user']) |
|
| 856 | - $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 917 | + if (!($port = $t2['port'])) { |
|
| 918 | + $port = 80; |
|
| 919 | + } |
|
| 920 | + if ($t2['user']) { |
|
| 921 | + $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 922 | + } |
|
| 923 | + } else { |
|
| 924 | + $first_host = $noproxy . $host; |
|
| 857 | 925 | } |
| 858 | - else |
|
| 859 | - $first_host = $noproxy . $host; |
|
| 860 | 926 | |
| 861 | 927 | if ($connect){ |
| 862 | 928 | $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); |
| 863 | 929 | $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
| 864 | 930 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); |
| 865 | - if (!$f) return false; |
|
| 931 | + if (!$f) { |
|
| 932 | + return false; |
|
| 933 | + } |
|
| 866 | 934 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
| 867 | 935 | |
| 868 | 936 | fputs($f, $connect); |
@@ -880,8 +948,7 @@ discard block |
||
| 880 | 948 | // envoyer le handshake |
| 881 | 949 | stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
| 882 | 950 | spip_log("OK CONNECT sur $first_host:$port","connect"); |
| 883 | - } |
|
| 884 | - else { |
|
| 951 | + } else { |
|
| 885 | 952 | $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
| 886 | 953 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 887 | 954 | if (!$f) { |