@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -45,130 +45,130 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function formulaires_dater_charger_dist($objet, $id_objet, $retour = '', $options = array()) { |
| 47 | 47 | |
| 48 | - $objet = objet_type($objet); |
|
| 49 | - if (!$objet or !intval($id_objet)) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (!is_array($options)) { |
|
| 54 | - $options = unserialize($options); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $_id_objet = id_table_objet($objet); |
|
| 58 | - $table = table_objet($objet); |
|
| 59 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 60 | - $desc = $trouver_table($table); |
|
| 61 | - |
|
| 62 | - if (!$desc) { |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $champ_date = $desc['date'] ? $desc['date'] : 'date'; |
|
| 67 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 68 | - $champ_date = $options['champ_date']; |
|
| 69 | - } |
|
| 70 | - if (!isset($desc['field'][$champ_date])) { |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $valeurs = array( |
|
| 75 | - 'objet' => $objet, |
|
| 76 | - 'id_objet' => $id_objet, |
|
| 77 | - 'id' => $id_objet, |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - $select = "$champ_date as date"; |
|
| 82 | - $champ_date_redac = 'date_redac'; |
|
| 83 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 84 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 85 | - } |
|
| 86 | - if (isset($desc['field'][$champ_date_redac])) { |
|
| 87 | - $select .= ",$champ_date_redac as date_redac"; |
|
| 88 | - } |
|
| 89 | - if (isset($desc['field']['statut'])) { |
|
| 90 | - $select .= ",statut"; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 95 | - $statut = isset($row['statut']) ? $row['statut'] : 'publie'; // pas de statut => publie |
|
| 96 | - |
|
| 97 | - $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, array('statut' => $statut)); |
|
| 98 | - |
|
| 99 | - $possedeDateRedac = false; |
|
| 100 | - |
|
| 101 | - if (isset($row['date_redac']) and |
|
| 102 | - $regs = recup_date($row['date_redac'], false) |
|
| 103 | - ) { |
|
| 104 | - $annee_redac = $regs[0]; |
|
| 105 | - $mois_redac = $regs[1]; |
|
| 106 | - $jour_redac = $regs[2]; |
|
| 107 | - $heure_redac = $regs[3]; |
|
| 108 | - $minute_redac = $regs[4]; |
|
| 109 | - $possedeDateRedac = true; |
|
| 110 | - // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 111 | - // mais reviennent ici en annee 1 par recup_date |
|
| 112 | - // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 113 | - // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 114 | - // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 115 | - if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 116 | - $possedeDateRedac = false; |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if ($regs = recup_date($row['date'], false)) { |
|
| 123 | - $annee = $regs[0]; |
|
| 124 | - $mois = $regs[1]; |
|
| 125 | - $jour = $regs[2]; |
|
| 126 | - $heure = $regs[3]; |
|
| 127 | - $minute = $regs[4]; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 131 | - // la normaliser, ce qu'on ne veut pas ici. |
|
| 132 | - $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 133 | - $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 134 | - $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 135 | - |
|
| 136 | - $valeurs['afficher_date'] = $row['date']; |
|
| 137 | - $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 138 | - $valeurs['date_heure'] = "$heure:$minute"; |
|
| 139 | - |
|
| 140 | - $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 141 | - |
|
| 142 | - if (isset($options['date_redac'])) { |
|
| 143 | - $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 144 | - } else { |
|
| 145 | - $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 146 | - } |
|
| 147 | - $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 148 | - _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 149 | - if (isset($options['label_date']) and $options['label_date']) { |
|
| 150 | - $valeurs['_label_date'] = $options['label_date']; |
|
| 151 | - } |
|
| 152 | - if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 153 | - $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 154 | - } |
|
| 155 | - if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 156 | - $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 157 | - } |
|
| 158 | - if (isset($options['class']) and $options['class']) { |
|
| 159 | - $valeurs['_class'] = $options['class']; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 163 | - |
|
| 164 | - // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 165 | - // https://core.spip.net/issues/3494 |
|
| 166 | - $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 167 | - if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 168 | - $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $valeurs; |
|
| 48 | + $objet = objet_type($objet); |
|
| 49 | + if (!$objet or !intval($id_objet)) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (!is_array($options)) { |
|
| 54 | + $options = unserialize($options); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $_id_objet = id_table_objet($objet); |
|
| 58 | + $table = table_objet($objet); |
|
| 59 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 60 | + $desc = $trouver_table($table); |
|
| 61 | + |
|
| 62 | + if (!$desc) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $champ_date = $desc['date'] ? $desc['date'] : 'date'; |
|
| 67 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 68 | + $champ_date = $options['champ_date']; |
|
| 69 | + } |
|
| 70 | + if (!isset($desc['field'][$champ_date])) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $valeurs = array( |
|
| 75 | + 'objet' => $objet, |
|
| 76 | + 'id_objet' => $id_objet, |
|
| 77 | + 'id' => $id_objet, |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + $select = "$champ_date as date"; |
|
| 82 | + $champ_date_redac = 'date_redac'; |
|
| 83 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 84 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 85 | + } |
|
| 86 | + if (isset($desc['field'][$champ_date_redac])) { |
|
| 87 | + $select .= ",$champ_date_redac as date_redac"; |
|
| 88 | + } |
|
| 89 | + if (isset($desc['field']['statut'])) { |
|
| 90 | + $select .= ",statut"; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 95 | + $statut = isset($row['statut']) ? $row['statut'] : 'publie'; // pas de statut => publie |
|
| 96 | + |
|
| 97 | + $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, array('statut' => $statut)); |
|
| 98 | + |
|
| 99 | + $possedeDateRedac = false; |
|
| 100 | + |
|
| 101 | + if (isset($row['date_redac']) and |
|
| 102 | + $regs = recup_date($row['date_redac'], false) |
|
| 103 | + ) { |
|
| 104 | + $annee_redac = $regs[0]; |
|
| 105 | + $mois_redac = $regs[1]; |
|
| 106 | + $jour_redac = $regs[2]; |
|
| 107 | + $heure_redac = $regs[3]; |
|
| 108 | + $minute_redac = $regs[4]; |
|
| 109 | + $possedeDateRedac = true; |
|
| 110 | + // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 111 | + // mais reviennent ici en annee 1 par recup_date |
|
| 112 | + // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 113 | + // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 114 | + // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 115 | + if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 116 | + $possedeDateRedac = false; |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if ($regs = recup_date($row['date'], false)) { |
|
| 123 | + $annee = $regs[0]; |
|
| 124 | + $mois = $regs[1]; |
|
| 125 | + $jour = $regs[2]; |
|
| 126 | + $heure = $regs[3]; |
|
| 127 | + $minute = $regs[4]; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 131 | + // la normaliser, ce qu'on ne veut pas ici. |
|
| 132 | + $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 133 | + $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 134 | + $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 135 | + |
|
| 136 | + $valeurs['afficher_date'] = $row['date']; |
|
| 137 | + $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 138 | + $valeurs['date_heure'] = "$heure:$minute"; |
|
| 139 | + |
|
| 140 | + $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 141 | + |
|
| 142 | + if (isset($options['date_redac'])) { |
|
| 143 | + $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 144 | + } else { |
|
| 145 | + $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 146 | + } |
|
| 147 | + $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 148 | + _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 149 | + if (isset($options['label_date']) and $options['label_date']) { |
|
| 150 | + $valeurs['_label_date'] = $options['label_date']; |
|
| 151 | + } |
|
| 152 | + if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 153 | + $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 154 | + } |
|
| 155 | + if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 156 | + $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 157 | + } |
|
| 158 | + if (isset($options['class']) and $options['class']) { |
|
| 159 | + $valeurs['_class'] = $options['class']; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 163 | + |
|
| 164 | + // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 165 | + // https://core.spip.net/issues/3494 |
|
| 166 | + $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 167 | + if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 168 | + $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $valeurs; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -186,20 +186,20 @@ discard block |
||
| 186 | 186 | * Date formatée tel que `02/10/2012` |
| 187 | 187 | **/ |
| 188 | 188 | function dater_formater_saisie_jour($jour, $mois, $annee, $sep = '/') { |
| 189 | - $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 190 | - if (intval($jour)) { |
|
| 191 | - $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 192 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 189 | + $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 190 | + if (intval($jour)) { |
|
| 191 | + $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 192 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 193 | 193 | |
| 194 | - return "$jour$sep$mois$sep$annee"; |
|
| 195 | - } |
|
| 196 | - if (intval($mois)) { |
|
| 197 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 194 | + return "$jour$sep$mois$sep$annee"; |
|
| 195 | + } |
|
| 196 | + if (intval($mois)) { |
|
| 197 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 198 | 198 | |
| 199 | - return "$mois$sep$annee"; |
|
| 200 | - } |
|
| 199 | + return "$mois$sep$annee"; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $annee; |
|
| 202 | + return $annee; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * Hash du formulaire |
| 219 | 219 | **/ |
| 220 | 220 | function formulaires_dater_identifier_dist($objet, $id_objet, $retour = '', $options = array()) { |
| 221 | - return serialize(array($objet, $id_objet)); |
|
| 221 | + return serialize(array($objet, $id_objet)); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -236,30 +236,30 @@ discard block |
||
| 236 | 236 | * Tableau des erreurs |
| 237 | 237 | */ |
| 238 | 238 | function formulaires_dater_verifier_dist($objet, $id_objet, $retour = '', $options = array()) { |
| 239 | - $erreurs = array(); |
|
| 240 | - |
|
| 241 | - // ouvrir le formulaire en edition ? |
|
| 242 | - if (_request('_saisie_en_cours')) { |
|
| 243 | - $erreurs['message_erreur'] = ''; |
|
| 244 | - |
|
| 245 | - return $erreurs; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if (_request('changer')) { |
|
| 249 | - foreach (array('date', 'date_redac') as $k) { |
|
| 250 | - if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 251 | - $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 252 | - } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 253 | - $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if (!_request('date_jour')) { |
|
| 258 | - $erreurs['date'] = _T('info_obligatoire'); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return $erreurs; |
|
| 239 | + $erreurs = array(); |
|
| 240 | + |
|
| 241 | + // ouvrir le formulaire en edition ? |
|
| 242 | + if (_request('_saisie_en_cours')) { |
|
| 243 | + $erreurs['message_erreur'] = ''; |
|
| 244 | + |
|
| 245 | + return $erreurs; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if (_request('changer')) { |
|
| 249 | + foreach (array('date', 'date_redac') as $k) { |
|
| 250 | + if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 251 | + $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 252 | + } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 253 | + $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if (!_request('date_jour')) { |
|
| 258 | + $erreurs['date'] = _T('info_obligatoire'); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return $erreurs; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -277,79 +277,79 @@ discard block |
||
| 277 | 277 | * Retours des traitements |
| 278 | 278 | */ |
| 279 | 279 | function formulaires_dater_traiter_dist($objet, $id_objet, $retour = '', $options = array()) { |
| 280 | - $res = array('editable' => ' '); |
|
| 281 | - |
|
| 282 | - if (_request('changer')) { |
|
| 283 | - $table = table_objet($objet); |
|
| 284 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 285 | - $desc = $trouver_table($table); |
|
| 286 | - |
|
| 287 | - if (!$desc) { |
|
| 288 | - return array('message_erreur' => _L('erreur')); |
|
| 289 | - } #impossible en principe |
|
| 290 | - |
|
| 291 | - $champ_date = $desc['date'] ? $desc['date'] : 'date'; |
|
| 292 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 293 | - $champ_date = $options['champ_date']; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $set = array(); |
|
| 297 | - |
|
| 298 | - $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 299 | - $v = $charger($objet, $id_objet, $retour, $options); |
|
| 300 | - |
|
| 301 | - if ($v['_editer_date']) { |
|
| 302 | - if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 303 | - $d = array(date('Y'), date('m'), date('d')); |
|
| 304 | - } |
|
| 305 | - if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 306 | - $h = array(0, 0); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $champ_date_redac = 'date_redac'; |
|
| 313 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 314 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 315 | - } |
|
| 316 | - if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 317 | - if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 318 | - $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 319 | - } else { |
|
| 320 | - if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 321 | - $d = array(date('Y'), date('m'), date('d')); |
|
| 322 | - } |
|
| 323 | - if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 324 | - $h = array(0, 0); |
|
| 325 | - } |
|
| 326 | - $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if (count($set)) { |
|
| 331 | - $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 332 | - include_spip('action/editer_objet'); |
|
| 333 | - objet_modifier($objet, $id_objet, $set); |
|
| 334 | - $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 335 | - if ($publie_avant !== $publie_apres) { |
|
| 336 | - // on refuse ajax pour forcer le rechargement de la page ici |
|
| 337 | - // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 338 | - refuser_traiter_formulaire_ajax(); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - if ($retour) { |
|
| 344 | - $res['redirect'] = $retour; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - set_request('date_jour'); |
|
| 348 | - set_request('date_redac_jour'); |
|
| 349 | - set_request('date_heure'); |
|
| 350 | - set_request('date_redac_heure'); |
|
| 351 | - |
|
| 352 | - return $res; |
|
| 280 | + $res = array('editable' => ' '); |
|
| 281 | + |
|
| 282 | + if (_request('changer')) { |
|
| 283 | + $table = table_objet($objet); |
|
| 284 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 285 | + $desc = $trouver_table($table); |
|
| 286 | + |
|
| 287 | + if (!$desc) { |
|
| 288 | + return array('message_erreur' => _L('erreur')); |
|
| 289 | + } #impossible en principe |
|
| 290 | + |
|
| 291 | + $champ_date = $desc['date'] ? $desc['date'] : 'date'; |
|
| 292 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 293 | + $champ_date = $options['champ_date']; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $set = array(); |
|
| 297 | + |
|
| 298 | + $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 299 | + $v = $charger($objet, $id_objet, $retour, $options); |
|
| 300 | + |
|
| 301 | + if ($v['_editer_date']) { |
|
| 302 | + if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 303 | + $d = array(date('Y'), date('m'), date('d')); |
|
| 304 | + } |
|
| 305 | + if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 306 | + $h = array(0, 0); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $champ_date_redac = 'date_redac'; |
|
| 313 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 314 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 315 | + } |
|
| 316 | + if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 317 | + if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 318 | + $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 319 | + } else { |
|
| 320 | + if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 321 | + $d = array(date('Y'), date('m'), date('d')); |
|
| 322 | + } |
|
| 323 | + if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 324 | + $h = array(0, 0); |
|
| 325 | + } |
|
| 326 | + $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if (count($set)) { |
|
| 331 | + $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 332 | + include_spip('action/editer_objet'); |
|
| 333 | + objet_modifier($objet, $id_objet, $set); |
|
| 334 | + $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 335 | + if ($publie_avant !== $publie_apres) { |
|
| 336 | + // on refuse ajax pour forcer le rechargement de la page ici |
|
| 337 | + // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 338 | + refuser_traiter_formulaire_ajax(); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + if ($retour) { |
|
| 344 | + $res['redirect'] = $retour; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + set_request('date_jour'); |
|
| 348 | + set_request('date_redac_jour'); |
|
| 349 | + set_request('date_heure'); |
|
| 350 | + set_request('date_redac_heure'); |
|
| 351 | + |
|
| 352 | + return $res; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -360,24 +360,24 @@ discard block |
||
| 360 | 360 | * @return array|string Chaîne vide si date invalide, tableau (année, mois, jour) sinon. |
| 361 | 361 | */ |
| 362 | 362 | function dater_recuperer_date_saisie($post, $quoi = 'date') { |
| 363 | - if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 364 | - return ''; |
|
| 365 | - } |
|
| 366 | - if ($quoi == 'date_redac') { |
|
| 367 | - if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 368 | - $regs[3] += 9000; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return array($regs[3], $regs[2], $regs[1]); |
|
| 372 | - } else { |
|
| 373 | - if ( |
|
| 374 | - checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 375 | - and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 376 | - ) { |
|
| 377 | - return array(date('Y', $t), date('m', $t), date('d', $t)); |
|
| 378 | - } |
|
| 379 | - return ''; |
|
| 380 | - } |
|
| 363 | + if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 364 | + return ''; |
|
| 365 | + } |
|
| 366 | + if ($quoi == 'date_redac') { |
|
| 367 | + if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 368 | + $regs[3] += 9000; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return array($regs[3], $regs[2], $regs[1]); |
|
| 372 | + } else { |
|
| 373 | + if ( |
|
| 374 | + checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 375 | + and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 376 | + ) { |
|
| 377 | + return array(date('Y', $t), date('m', $t), date('d', $t)); |
|
| 378 | + } |
|
| 379 | + return ''; |
|
| 380 | + } |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | * @return array |
| 388 | 388 | */ |
| 389 | 389 | function dater_recuperer_heure_saisie($post) { |
| 390 | - if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 391 | - return ''; |
|
| 392 | - } |
|
| 393 | - if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - return array($regs[1], $regs[2]); |
|
| 390 | + if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 391 | + return ''; |
|
| 392 | + } |
|
| 393 | + if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + return array($regs[1], $regs[2]); |
|
| 398 | 398 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
| 94 | - $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 94 | + $row = sql_fetsel($select, $desc['table'], "$_id_objet=".intval($id_objet)); |
|
| 95 | 95 | $statut = isset($row['statut']) ? $row['statut'] : 'publie'; // pas de statut => publie |
| 96 | 96 | |
| 97 | 97 | $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, array('statut' => $statut)); |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | if (_request('changer')) { |
| 249 | 249 | foreach (array('date', 'date_redac') as $k) { |
| 250 | - if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 250 | + if ($v = _request($k.'_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 251 | 251 | $erreurs[$k] = _T('format_date_incorrecte'); |
| 252 | - } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 252 | + } elseif ($v = _request($k.'_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 253 | 253 | $erreurs[$k] = _T('format_heure_incorrecte'); |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -36,55 +36,55 @@ discard block |
||
| 36 | 36 | * ``` |
| 37 | 37 | **/ |
| 38 | 38 | function action_redirect_dist() { |
| 39 | - $type = _request('type'); |
|
| 40 | - $id = intval(_request('id')); |
|
| 41 | - $page = false; |
|
| 39 | + $type = _request('type'); |
|
| 40 | + $id = intval(_request('id')); |
|
| 41 | + $page = false; |
|
| 42 | 42 | |
| 43 | - // verifier le type ou page transmis |
|
| 44 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 45 | - $page = _request('page'); |
|
| 46 | - if (!preg_match('/^\w+$/', $page)) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - } |
|
| 43 | + // verifier le type ou page transmis |
|
| 44 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 45 | + $page = _request('page'); |
|
| 46 | + if (!preg_match('/^\w+$/', $page)) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if ($var_mode = _request('var_mode')) { |
|
| 52 | - // forcer la mise a jour de l'url de cet objet ! |
|
| 53 | - if (!defined('_VAR_URLS')) { |
|
| 54 | - define('_VAR_URLS', true); |
|
| 55 | - } |
|
| 56 | - } |
|
| 51 | + if ($var_mode = _request('var_mode')) { |
|
| 52 | + // forcer la mise a jour de l'url de cet objet ! |
|
| 53 | + if (!defined('_VAR_URLS')) { |
|
| 54 | + define('_VAR_URLS', true); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if ($page) { |
|
| 59 | - $url = generer_url_public($page, '', true); |
|
| 60 | - } else { |
|
| 61 | - $url = calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 62 | - } |
|
| 58 | + if ($page) { |
|
| 59 | + $url = generer_url_public($page, '', true); |
|
| 60 | + } else { |
|
| 61 | + $url = calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $status = '302'; |
|
| 65 | - if ($url) { |
|
| 66 | - if ($var_mode) { |
|
| 67 | - $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 68 | - } |
|
| 64 | + $status = '302'; |
|
| 65 | + if ($url) { |
|
| 66 | + if ($var_mode) { |
|
| 67 | + $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if ($var_mode == 'preview' |
|
| 71 | - and defined('_PREVIEW_TOKEN') |
|
| 72 | - and _PREVIEW_TOKEN |
|
| 73 | - and autoriser('previsualiser') |
|
| 74 | - ) { |
|
| 75 | - include_spip('inc/securiser_action'); |
|
| 76 | - $token = calculer_token_previsu($url); |
|
| 77 | - $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 78 | - } |
|
| 70 | + if ($var_mode == 'preview' |
|
| 71 | + and defined('_PREVIEW_TOKEN') |
|
| 72 | + and _PREVIEW_TOKEN |
|
| 73 | + and autoriser('previsualiser') |
|
| 74 | + ) { |
|
| 75 | + include_spip('inc/securiser_action'); |
|
| 76 | + $token = calculer_token_previsu($url); |
|
| 77 | + $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if (_request('status') and _request('status') == '301') { |
|
| 81 | - $status = '301'; |
|
| 82 | - } |
|
| 83 | - } else { |
|
| 84 | - $url = generer_url_public('404', '', true); |
|
| 85 | - } |
|
| 80 | + if (_request('status') and _request('status') == '301') { |
|
| 81 | + $status = '301'; |
|
| 82 | + } |
|
| 83 | + } else { |
|
| 84 | + $url = generer_url_public('404', '', true); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - redirige_par_entete(str_replace('&', '&', $url), '', $status); |
|
| 87 | + redirige_par_entete(str_replace('&', '&', $url), '', $status); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -99,32 +99,32 @@ discard block |
||
| 99 | 99 | * @return string|null |
| 100 | 100 | */ |
| 101 | 101 | function calculer_url_redirect_entite($type, $id, $var_mode) { |
| 102 | - // invalider le cache à chaque modif en bdd |
|
| 103 | - $date = 0; |
|
| 104 | - if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 105 | - $date = $GLOBALS['meta']['derniere_modif']; |
|
| 106 | - } |
|
| 107 | - $key = "url-$date-$type-$id"; |
|
| 102 | + // invalider le cache à chaque modif en bdd |
|
| 103 | + $date = 0; |
|
| 104 | + if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 105 | + $date = $GLOBALS['meta']['derniere_modif']; |
|
| 106 | + } |
|
| 107 | + $key = "url-$date-$type-$id"; |
|
| 108 | 108 | |
| 109 | - // Obtenir l’url et si elle est publié du cache memoization |
|
| 110 | - if (function_exists('cache_get') and $desc = cache_get($key)) { |
|
| 111 | - list($url, $publie) = $desc; |
|
| 112 | - } |
|
| 113 | - // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 114 | - if (empty($desc) or $var_mode) { |
|
| 115 | - $publie = objet_test_si_publie($type, $id); |
|
| 116 | - $url = generer_url_entite_absolue($id, $type, '', '', true); |
|
| 117 | - if (function_exists('cache_set')) { |
|
| 118 | - cache_set($key, array($url, $publie), 3600); |
|
| 119 | - } |
|
| 120 | - } |
|
| 109 | + // Obtenir l’url et si elle est publié du cache memoization |
|
| 110 | + if (function_exists('cache_get') and $desc = cache_get($key)) { |
|
| 111 | + list($url, $publie) = $desc; |
|
| 112 | + } |
|
| 113 | + // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 114 | + if (empty($desc) or $var_mode) { |
|
| 115 | + $publie = objet_test_si_publie($type, $id); |
|
| 116 | + $url = generer_url_entite_absolue($id, $type, '', '', true); |
|
| 117 | + if (function_exists('cache_set')) { |
|
| 118 | + cache_set($key, array($url, $publie), 3600); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 123 | - if ($publie) { |
|
| 124 | - return $url; |
|
| 125 | - } elseif (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id)) { |
|
| 126 | - return $url; |
|
| 127 | - } |
|
| 122 | + // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 123 | + if ($publie) { |
|
| 124 | + return $url; |
|
| 125 | + } elseif (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id)) { |
|
| 126 | + return $url; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return; |
|
| 129 | + return; |
|
| 130 | 130 | } |
| 131 | 131 | \ No newline at end of file |
@@ -4,118 +4,118 @@ |
||
| 4 | 4 | // ** ne pas modifier le fichier ** |
| 5 | 5 | |
| 6 | 6 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 7 | - return; |
|
| 7 | + return; |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $GLOBALS[$GLOBALS['idx_lang']] = array( |
| 11 | 11 | |
| 12 | - // A |
|
| 13 | - 'accueil_site' => 'ホーム', |
|
| 14 | - 'article' => '記事', |
|
| 15 | - 'articles' => '記事', |
|
| 16 | - 'articles_auteur' => 'この著者の記事', |
|
| 17 | - 'articles_populaires' => '人気のある記事', |
|
| 18 | - 'articles_rubrique' => 'このセクションにある記事', |
|
| 19 | - 'aucun_article' => 'このアドレスに記事はありません', |
|
| 20 | - 'aucun_auteur' => 'このアドレスに著者はいません', |
|
| 21 | - 'aucun_site' => 'このアドレスにサイトはありません', |
|
| 22 | - 'aucune_breve' => 'このアドレスにニュースはありません', |
|
| 23 | - 'aucune_rubrique' => 'このアドレスにセクションはありません', |
|
| 24 | - 'auteur' => '著者', |
|
| 25 | - 'autres' => 'その他', |
|
| 26 | - 'autres_breves' => '他のニュース', |
|
| 27 | - 'autres_groupes_mots_clefs' => 'キーワードの他のグループ', |
|
| 28 | - 'autres_sites' => '他のサイト', |
|
| 29 | - |
|
| 30 | - // B |
|
| 31 | - 'bonjour' => 'こんにちは', |
|
| 32 | - |
|
| 33 | - // C |
|
| 34 | - 'commenter_site' => 'このサイトについてコメントして下さい', |
|
| 35 | - 'contact' => '連絡先', |
|
| 36 | - 'copie_document_impossible' => 'ファイルのコーピは不可能です', |
|
| 37 | - |
|
| 38 | - // D |
|
| 39 | - 'date' => '日付', |
|
| 40 | - 'dernier_ajout' => '最新の追加', |
|
| 41 | - 'dernieres_breves' => '最新のニュース', |
|
| 42 | - 'derniers_articles' => '最新の記事', |
|
| 43 | - 'derniers_commentaires' => '最新のコメント', |
|
| 44 | - 'derniers_messages_forum' => 'フォーラムで投稿された最新のメッセージ', |
|
| 45 | - |
|
| 46 | - // E |
|
| 47 | - 'edition_mode_texte' => 'テキストモード編集', |
|
| 48 | - 'en_reponse' => '返事として:', |
|
| 49 | - 'en_resume' => 'まとめとして', |
|
| 50 | - 'envoyer_message' => 'メッセージを送る', |
|
| 51 | - 'espace_prive' => '管理エリア', |
|
| 52 | - |
|
| 53 | - // F |
|
| 54 | - 'formats_acceptes' => '受け入れるファイルのフォーマット: @formats@です。', |
|
| 55 | - |
|
| 56 | - // H |
|
| 57 | - 'hierarchie_site' => 'サイトの階層', |
|
| 58 | - |
|
| 59 | - // J |
|
| 60 | - 'jours' => '日付', |
|
| 61 | - |
|
| 62 | - // L |
|
| 63 | - 'lien_connecter' => 'ログイン', |
|
| 64 | - |
|
| 65 | - // M |
|
| 66 | - 'meme_auteur' => '同じ著者', |
|
| 67 | - 'meme_rubrique' => '同じセクションの中で', |
|
| 68 | - 'memes_auteurs' => '同じ著者', |
|
| 69 | - 'message' => 'フォーラムのメッセージ', |
|
| 70 | - 'messages_forum' => 'フォーラムのメッセージ', |
|
| 71 | - 'messages_recents' => '最新のフォーラムのメッセージ', |
|
| 72 | - 'mots_clef' => 'キーワード', |
|
| 73 | - 'mots_clefs' => 'キーワード', |
|
| 74 | - 'mots_clefs_meme_groupe' => '同じグループのキーワード', |
|
| 75 | - |
|
| 76 | - // N |
|
| 77 | - 'navigation' => 'ナビゲーション', |
|
| 78 | - 'nom' => 'お名前', |
|
| 79 | - 'nouveautes' => '最新刊', |
|
| 80 | - 'nouveautes_web' => 'ウェブに関する最新刊', |
|
| 81 | - 'nouveaux_articles' => '新しい記事', |
|
| 82 | - 'nouvelles_breves' => '新しいニュース', |
|
| 83 | - |
|
| 84 | - // P |
|
| 85 | - 'page_precedente' => '前のページ', |
|
| 86 | - 'page_suivante' => '次のページ', |
|
| 87 | - 'par_auteur' => '著者:', |
|
| 88 | - 'participer_site' => 'サインアップすると、サイトにご自分の記事を書くことが出来ます。申し込みしてから、管理エリアへのアクセスコードがメールで届きます。', |
|
| 89 | - 'plan_site' => 'サイトマップ', |
|
| 90 | - 'popularite' => '人気', |
|
| 91 | - 'poster_message' => 'メッセージを投稿する', |
|
| 92 | - 'proposer_site' => '追加するサイトを提案できるセクション:', |
|
| 93 | - |
|
| 94 | - // R |
|
| 95 | - 'repondre_article' => 'この記事に返信する', |
|
| 96 | - 'repondre_breve' => 'このニュースに返信する', |
|
| 97 | - 'resultats_recherche' => '検索結果', |
|
| 98 | - 'retour_debut_forums' => 'フォーラムの最初のページに戻る', |
|
| 99 | - 'rubrique' => 'セクション', |
|
| 100 | - 'rubriques' => 'セクション', |
|
| 101 | - |
|
| 102 | - // S |
|
| 103 | - 'signatures_petition' => '署名', |
|
| 104 | - 'site_realise_avec_spip' => 'SPIPで創造されたサイトです', |
|
| 105 | - 'sites_web' => 'ウェブサイト', |
|
| 106 | - 'sous_rubriques' => 'サブセクション', |
|
| 107 | - 'spam' => '迷惑メール', |
|
| 108 | - 'suite' => '次へ', |
|
| 109 | - 'sur_web' => 'ウェブ上', |
|
| 110 | - 'syndiquer_rubrique' => 'このセクションを供給する', |
|
| 111 | - 'syndiquer_site' => '全サイトを供給する', |
|
| 112 | - |
|
| 113 | - // T |
|
| 114 | - 'texte_lettre_information' => 'サイトのニュースレター', |
|
| 115 | - 'texte_lettre_information_2' => '最新刊をまとめるニュースレター', |
|
| 116 | - |
|
| 117 | - // V |
|
| 118 | - 'ver_imprimer' => '印刷用のバージョン', |
|
| 119 | - 'voir_en_ligne' => 'オンラインで見る', |
|
| 120 | - 'voir_squelette' => 'ページのテンプレートを見る' |
|
| 12 | + // A |
|
| 13 | + 'accueil_site' => 'ホーム', |
|
| 14 | + 'article' => '記事', |
|
| 15 | + 'articles' => '記事', |
|
| 16 | + 'articles_auteur' => 'この著者の記事', |
|
| 17 | + 'articles_populaires' => '人気のある記事', |
|
| 18 | + 'articles_rubrique' => 'このセクションにある記事', |
|
| 19 | + 'aucun_article' => 'このアドレスに記事はありません', |
|
| 20 | + 'aucun_auteur' => 'このアドレスに著者はいません', |
|
| 21 | + 'aucun_site' => 'このアドレスにサイトはありません', |
|
| 22 | + 'aucune_breve' => 'このアドレスにニュースはありません', |
|
| 23 | + 'aucune_rubrique' => 'このアドレスにセクションはありません', |
|
| 24 | + 'auteur' => '著者', |
|
| 25 | + 'autres' => 'その他', |
|
| 26 | + 'autres_breves' => '他のニュース', |
|
| 27 | + 'autres_groupes_mots_clefs' => 'キーワードの他のグループ', |
|
| 28 | + 'autres_sites' => '他のサイト', |
|
| 29 | + |
|
| 30 | + // B |
|
| 31 | + 'bonjour' => 'こんにちは', |
|
| 32 | + |
|
| 33 | + // C |
|
| 34 | + 'commenter_site' => 'このサイトについてコメントして下さい', |
|
| 35 | + 'contact' => '連絡先', |
|
| 36 | + 'copie_document_impossible' => 'ファイルのコーピは不可能です', |
|
| 37 | + |
|
| 38 | + // D |
|
| 39 | + 'date' => '日付', |
|
| 40 | + 'dernier_ajout' => '最新の追加', |
|
| 41 | + 'dernieres_breves' => '最新のニュース', |
|
| 42 | + 'derniers_articles' => '最新の記事', |
|
| 43 | + 'derniers_commentaires' => '最新のコメント', |
|
| 44 | + 'derniers_messages_forum' => 'フォーラムで投稿された最新のメッセージ', |
|
| 45 | + |
|
| 46 | + // E |
|
| 47 | + 'edition_mode_texte' => 'テキストモード編集', |
|
| 48 | + 'en_reponse' => '返事として:', |
|
| 49 | + 'en_resume' => 'まとめとして', |
|
| 50 | + 'envoyer_message' => 'メッセージを送る', |
|
| 51 | + 'espace_prive' => '管理エリア', |
|
| 52 | + |
|
| 53 | + // F |
|
| 54 | + 'formats_acceptes' => '受け入れるファイルのフォーマット: @formats@です。', |
|
| 55 | + |
|
| 56 | + // H |
|
| 57 | + 'hierarchie_site' => 'サイトの階層', |
|
| 58 | + |
|
| 59 | + // J |
|
| 60 | + 'jours' => '日付', |
|
| 61 | + |
|
| 62 | + // L |
|
| 63 | + 'lien_connecter' => 'ログイン', |
|
| 64 | + |
|
| 65 | + // M |
|
| 66 | + 'meme_auteur' => '同じ著者', |
|
| 67 | + 'meme_rubrique' => '同じセクションの中で', |
|
| 68 | + 'memes_auteurs' => '同じ著者', |
|
| 69 | + 'message' => 'フォーラムのメッセージ', |
|
| 70 | + 'messages_forum' => 'フォーラムのメッセージ', |
|
| 71 | + 'messages_recents' => '最新のフォーラムのメッセージ', |
|
| 72 | + 'mots_clef' => 'キーワード', |
|
| 73 | + 'mots_clefs' => 'キーワード', |
|
| 74 | + 'mots_clefs_meme_groupe' => '同じグループのキーワード', |
|
| 75 | + |
|
| 76 | + // N |
|
| 77 | + 'navigation' => 'ナビゲーション', |
|
| 78 | + 'nom' => 'お名前', |
|
| 79 | + 'nouveautes' => '最新刊', |
|
| 80 | + 'nouveautes_web' => 'ウェブに関する最新刊', |
|
| 81 | + 'nouveaux_articles' => '新しい記事', |
|
| 82 | + 'nouvelles_breves' => '新しいニュース', |
|
| 83 | + |
|
| 84 | + // P |
|
| 85 | + 'page_precedente' => '前のページ', |
|
| 86 | + 'page_suivante' => '次のページ', |
|
| 87 | + 'par_auteur' => '著者:', |
|
| 88 | + 'participer_site' => 'サインアップすると、サイトにご自分の記事を書くことが出来ます。申し込みしてから、管理エリアへのアクセスコードがメールで届きます。', |
|
| 89 | + 'plan_site' => 'サイトマップ', |
|
| 90 | + 'popularite' => '人気', |
|
| 91 | + 'poster_message' => 'メッセージを投稿する', |
|
| 92 | + 'proposer_site' => '追加するサイトを提案できるセクション:', |
|
| 93 | + |
|
| 94 | + // R |
|
| 95 | + 'repondre_article' => 'この記事に返信する', |
|
| 96 | + 'repondre_breve' => 'このニュースに返信する', |
|
| 97 | + 'resultats_recherche' => '検索結果', |
|
| 98 | + 'retour_debut_forums' => 'フォーラムの最初のページに戻る', |
|
| 99 | + 'rubrique' => 'セクション', |
|
| 100 | + 'rubriques' => 'セクション', |
|
| 101 | + |
|
| 102 | + // S |
|
| 103 | + 'signatures_petition' => '署名', |
|
| 104 | + 'site_realise_avec_spip' => 'SPIPで創造されたサイトです', |
|
| 105 | + 'sites_web' => 'ウェブサイト', |
|
| 106 | + 'sous_rubriques' => 'サブセクション', |
|
| 107 | + 'spam' => '迷惑メール', |
|
| 108 | + 'suite' => '次へ', |
|
| 109 | + 'sur_web' => 'ウェブ上', |
|
| 110 | + 'syndiquer_rubrique' => 'このセクションを供給する', |
|
| 111 | + 'syndiquer_site' => '全サイトを供給する', |
|
| 112 | + |
|
| 113 | + // T |
|
| 114 | + 'texte_lettre_information' => 'サイトのニュースレター', |
|
| 115 | + 'texte_lettre_information_2' => '最新刊をまとめるニュースレター', |
|
| 116 | + |
|
| 117 | + // V |
|
| 118 | + 'ver_imprimer' => '印刷用のバージョン', |
|
| 119 | + 'voir_en_ligne' => 'オンラインで見る', |
|
| 120 | + 'voir_squelette' => 'ページのテンプレートを見る' |
|
| 121 | 121 | ); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -33,105 +33,105 @@ discard block |
||
| 33 | 33 | **/ |
| 34 | 34 | function analyse_csv($t) { |
| 35 | 35 | |
| 36 | - // Quel est le séparateur ? |
|
| 37 | - $virg = substr_count($t, ','); |
|
| 38 | - $pvirg = substr_count($t, ';'); |
|
| 39 | - $tab = substr_count($t, "\t"); |
|
| 40 | - if ($virg > $pvirg) { |
|
| 41 | - $sep = ','; |
|
| 42 | - $hs = ','; |
|
| 43 | - } else { |
|
| 44 | - $sep = ';'; |
|
| 45 | - $hs = ';'; |
|
| 46 | - $virg = $pvirg; |
|
| 47 | - } |
|
| 48 | - // un certain nombre de tab => le séparateur est tab |
|
| 49 | - if ($tab > $virg / 10) { |
|
| 50 | - $sep = "\t"; |
|
| 51 | - $hs = "\t"; |
|
| 52 | - } |
|
| 36 | + // Quel est le séparateur ? |
|
| 37 | + $virg = substr_count($t, ','); |
|
| 38 | + $pvirg = substr_count($t, ';'); |
|
| 39 | + $tab = substr_count($t, "\t"); |
|
| 40 | + if ($virg > $pvirg) { |
|
| 41 | + $sep = ','; |
|
| 42 | + $hs = ','; |
|
| 43 | + } else { |
|
| 44 | + $sep = ';'; |
|
| 45 | + $hs = ';'; |
|
| 46 | + $virg = $pvirg; |
|
| 47 | + } |
|
| 48 | + // un certain nombre de tab => le séparateur est tab |
|
| 49 | + if ($tab > $virg / 10) { |
|
| 50 | + $sep = "\t"; |
|
| 51 | + $hs = "\t"; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // un separateur suivi de 3 guillemets attention ! |
|
| 55 | - // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 56 | - // on substitue un # et on remplacera a la fin |
|
| 57 | - $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 58 | - $t = str_replace('""', '"#', $t); |
|
| 59 | - preg_match_all('/"[^"]*"/', $t, $r); |
|
| 60 | - foreach ($r[0] as $cell) { |
|
| 61 | - $t = str_replace($cell, |
|
| 62 | - str_replace($sep, $hs, |
|
| 63 | - str_replace("\n", "``**``", // échapper les saut de lignes, on les remettra après. |
|
| 64 | - substr($cell, 1, -1))), |
|
| 65 | - $t); |
|
| 66 | - } |
|
| 54 | + // un separateur suivi de 3 guillemets attention ! |
|
| 55 | + // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 56 | + // on substitue un # et on remplacera a la fin |
|
| 57 | + $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 58 | + $t = str_replace('""', '"#', $t); |
|
| 59 | + preg_match_all('/"[^"]*"/', $t, $r); |
|
| 60 | + foreach ($r[0] as $cell) { |
|
| 61 | + $t = str_replace($cell, |
|
| 62 | + str_replace($sep, $hs, |
|
| 63 | + str_replace("\n", "``**``", // échapper les saut de lignes, on les remettra après. |
|
| 64 | + substr($cell, 1, -1))), |
|
| 65 | + $t); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $t = preg_replace('/\r?\n/', "\n", |
|
| 69 | - preg_replace('/[\r\n]+/', "\n", $t)); |
|
| 68 | + $t = preg_replace('/\r?\n/', "\n", |
|
| 69 | + preg_replace('/[\r\n]+/', "\n", $t)); |
|
| 70 | 70 | |
| 71 | - list($entete, $corps) = explode("\n", $t, 2); |
|
| 72 | - $caption = ''; |
|
| 73 | - // sauter la ligne de tete formee seulement de separateurs |
|
| 74 | - if (substr_count($entete, $sep) == strlen($entete)) { |
|
| 75 | - list($entete, $corps) = explode("\n", $corps, 2); |
|
| 76 | - } |
|
| 77 | - // si une seule colonne, en faire le titre |
|
| 78 | - if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 79 | - $caption = "\n||" . $l[1] . "|"; |
|
| 80 | - list($entete, $corps) = explode("\n", $corps, 2); |
|
| 81 | - } |
|
| 82 | - // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 83 | - if ($entete[0] == $sep) { |
|
| 84 | - $entete = ' ' . $entete; |
|
| 85 | - } |
|
| 71 | + list($entete, $corps) = explode("\n", $t, 2); |
|
| 72 | + $caption = ''; |
|
| 73 | + // sauter la ligne de tete formee seulement de separateurs |
|
| 74 | + if (substr_count($entete, $sep) == strlen($entete)) { |
|
| 75 | + list($entete, $corps) = explode("\n", $corps, 2); |
|
| 76 | + } |
|
| 77 | + // si une seule colonne, en faire le titre |
|
| 78 | + if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 79 | + $caption = "\n||" . $l[1] . "|"; |
|
| 80 | + list($entete, $corps) = explode("\n", $corps, 2); |
|
| 81 | + } |
|
| 82 | + // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 83 | + if ($entete[0] == $sep) { |
|
| 84 | + $entete = ' ' . $entete; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - $lignes = explode("\n", $corps); |
|
| 87 | + $lignes = explode("\n", $corps); |
|
| 88 | 88 | |
| 89 | - // retrait des lignes vides finales |
|
| 90 | - while (count($lignes) > 0 |
|
| 91 | - and preg_match("/^$sep*$/", $lignes[count($lignes) - 1])) { |
|
| 92 | - unset($lignes[count($lignes) - 1]); |
|
| 93 | - } |
|
| 94 | - // calcul du nombre de colonne a chaque ligne |
|
| 95 | - $nbcols = array(); |
|
| 96 | - $max = $mil = substr_count($entete, $sep); |
|
| 97 | - foreach ($lignes as $k => $v) { |
|
| 98 | - if ($max <> ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 99 | - if ($max > $nbcols[$k]) { |
|
| 100 | - $mil = $nbcols[$k]; |
|
| 101 | - } else { |
|
| 102 | - $mil = $max; |
|
| 103 | - $max = $nbcols[$k]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - // Si pas le meme nombre, cadrer au nombre max |
|
| 108 | - if ($mil <> $max) { |
|
| 109 | - foreach ($nbcols as $k => $v) { |
|
| 110 | - if ($v < $max) { |
|
| 111 | - $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - // et retirer les colonnes integralement vides |
|
| 116 | - while (true) { |
|
| 117 | - $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 118 | - foreach ($lignes as $v) { |
|
| 119 | - $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 120 | - } |
|
| 121 | - if (!$nbcols) { |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - $entete = substr($entete, 0, -1); |
|
| 125 | - foreach ($lignes as $k => $v) { |
|
| 126 | - $lignes[$k] = substr($v, 0, -1); |
|
| 127 | - } |
|
| 128 | - } |
|
| 89 | + // retrait des lignes vides finales |
|
| 90 | + while (count($lignes) > 0 |
|
| 91 | + and preg_match("/^$sep*$/", $lignes[count($lignes) - 1])) { |
|
| 92 | + unset($lignes[count($lignes) - 1]); |
|
| 93 | + } |
|
| 94 | + // calcul du nombre de colonne a chaque ligne |
|
| 95 | + $nbcols = array(); |
|
| 96 | + $max = $mil = substr_count($entete, $sep); |
|
| 97 | + foreach ($lignes as $k => $v) { |
|
| 98 | + if ($max <> ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 99 | + if ($max > $nbcols[$k]) { |
|
| 100 | + $mil = $nbcols[$k]; |
|
| 101 | + } else { |
|
| 102 | + $mil = $max; |
|
| 103 | + $max = $nbcols[$k]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + // Si pas le meme nombre, cadrer au nombre max |
|
| 108 | + if ($mil <> $max) { |
|
| 109 | + foreach ($nbcols as $k => $v) { |
|
| 110 | + if ($v < $max) { |
|
| 111 | + $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + // et retirer les colonnes integralement vides |
|
| 116 | + while (true) { |
|
| 117 | + $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 118 | + foreach ($lignes as $v) { |
|
| 119 | + $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 120 | + } |
|
| 121 | + if (!$nbcols) { |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + $entete = substr($entete, 0, -1); |
|
| 125 | + foreach ($lignes as $k => $v) { |
|
| 126 | + $lignes[$k] = substr($v, 0, -1); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - foreach ($lignes as &$l) { |
|
| 131 | - $l = str_replace('"#','"',$l); |
|
| 132 | - $l = str_replace('``**``',"\n",$l); |
|
| 133 | - $l = explode($sep, $l); |
|
| 134 | - } |
|
| 130 | + foreach ($lignes as &$l) { |
|
| 131 | + $l = str_replace('"#','"',$l); |
|
| 132 | + $l = str_replace('``**``',"\n",$l); |
|
| 133 | + $l = explode($sep, $l); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return array(explode($sep, $entete), $lignes, $caption); |
|
| 136 | + return array(explode($sep, $entete), $lignes, $caption); |
|
| 137 | 137 | } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | // si une seule colonne, en faire le titre |
| 78 | 78 | if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
| 79 | - $caption = "\n||" . $l[1] . "|"; |
|
| 79 | + $caption = "\n||".$l[1]."|"; |
|
| 80 | 80 | list($entete, $corps) = explode("\n", $corps, 2); |
| 81 | 81 | } |
| 82 | 82 | // si premiere colonne vide, le raccourci doit quand meme produire <th... |
| 83 | 83 | if ($entete[0] == $sep) { |
| 84 | - $entete = ' ' . $entete; |
|
| 84 | + $entete = ' '.$entete; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $lignes = explode("\n", $corps); |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | foreach ($lignes as &$l) { |
| 131 | - $l = str_replace('"#','"',$l); |
|
| 132 | - $l = str_replace('``**``',"\n",$l); |
|
| 131 | + $l = str_replace('"#', '"', $l); |
|
| 132 | + $l = str_replace('``**``', "\n", $l); |
|
| 133 | 133 | $l = explode($sep, $l); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -4,118 +4,118 @@ |
||
| 4 | 4 | // ** ne pas modifier le fichier ** |
| 5 | 5 | |
| 6 | 6 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 7 | - return; |
|
| 7 | + return; |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $GLOBALS[$GLOBALS['idx_lang']] = array( |
| 11 | 11 | |
| 12 | - // A |
|
| 13 | - 'accueil_site' => 'Homepagina', |
|
| 14 | - 'article' => 'Artikel', |
|
| 15 | - 'articles' => 'Artikelen', |
|
| 16 | - 'articles_auteur' => 'Artikelen van deze auteur', |
|
| 17 | - 'articles_populaires' => 'Meest bekeken artikelen', |
|
| 18 | - 'articles_rubrique' => 'Artikelen in deze rubriek', |
|
| 19 | - 'aucun_article' => 'Op dit adres is geen artikel te vinden', |
|
| 20 | - 'aucun_auteur' => 'Op dit adres is geen auteur te vinden', |
|
| 21 | - 'aucun_site' => 'Op dit adres is geen site te vinden', |
|
| 22 | - 'aucune_breve' => 'Op dit adres is geen nieuwsflits te vinden', |
|
| 23 | - 'aucune_rubrique' => 'Op dit adres is geen rubriek te vinden', |
|
| 24 | - 'auteur' => 'Auteur', |
|
| 25 | - 'autres' => 'Anderen', |
|
| 26 | - 'autres_breves' => 'Andere nieuwsflitsen', |
|
| 27 | - 'autres_groupes_mots_clefs' => 'Andere groepen trefwoorden', |
|
| 28 | - 'autres_sites' => 'Andere sites', |
|
| 29 | - |
|
| 30 | - // B |
|
| 31 | - 'bonjour' => 'Hallo', |
|
| 32 | - |
|
| 33 | - // C |
|
| 34 | - 'commenter_site' => 'Reageren op de site', |
|
| 35 | - 'contact' => 'Contact', |
|
| 36 | - 'copie_document_impossible' => 'Het is niet mogelijk het document te kopiëren', |
|
| 37 | - |
|
| 38 | - // D |
|
| 39 | - 'date' => 'Datum', |
|
| 40 | - 'dernier_ajout' => 'Laatste toevoeging', |
|
| 41 | - 'dernieres_breves' => 'Laatste nieuwsflitsen', |
|
| 42 | - 'derniers_articles' => 'Laatste artikelen', |
|
| 43 | - 'derniers_commentaires' => 'Laatste commentaren', |
|
| 44 | - 'derniers_messages_forum' => 'Laatst gepubliceerde berichten in het forum', |
|
| 45 | - |
|
| 46 | - // E |
|
| 47 | - 'edition_mode_texte' => 'Uitgave in tekstmodus van', |
|
| 48 | - 'en_reponse' => 'Als antwoord op:', |
|
| 49 | - 'en_resume' => 'Samengevat', |
|
| 50 | - 'envoyer_message' => 'Een bericht sturen', |
|
| 51 | - 'espace_prive' => 'Privé gedeelte', |
|
| 52 | - |
|
| 53 | - // F |
|
| 54 | - 'formats_acceptes' => 'Toegelaten formaten: @formats@.', |
|
| 55 | - |
|
| 56 | - // H |
|
| 57 | - 'hierarchie_site' => 'Structuur van de site', |
|
| 58 | - |
|
| 59 | - // J |
|
| 60 | - 'jours' => 'dagen', |
|
| 61 | - |
|
| 62 | - // L |
|
| 63 | - 'lien_connecter' => 'Aanmelden', |
|
| 64 | - |
|
| 65 | - // M |
|
| 66 | - 'meme_auteur' => 'Van dezelfde auteur', |
|
| 67 | - 'meme_rubrique' => 'In dezelfde rubriek', |
|
| 68 | - 'memes_auteurs' => 'Van dezelfde auteurs', |
|
| 69 | - 'message' => 'Bericht', |
|
| 70 | - 'messages_forum' => 'Berichten', |
|
| 71 | - 'messages_recents' => 'Meest recente forumberichten', |
|
| 72 | - 'mots_clef' => 'Trefwoord', |
|
| 73 | - 'mots_clefs' => 'Trefwoorden', |
|
| 74 | - 'mots_clefs_meme_groupe' => 'Trefwoorden van dezelfde groep', |
|
| 75 | - |
|
| 76 | - // N |
|
| 77 | - 'navigation' => 'Navigatie', |
|
| 78 | - 'nom' => 'Naam', |
|
| 79 | - 'nouveautes' => 'Nieuwigheden', |
|
| 80 | - 'nouveautes_web' => 'Nieuwigheden op het Web', |
|
| 81 | - 'nouveaux_articles' => 'Nieuwe artikelen', |
|
| 82 | - 'nouvelles_breves' => 'Nieuwe nieuwsflitsen', |
|
| 83 | - |
|
| 84 | - // P |
|
| 85 | - 'page_precedente' => 'vorige pagina', |
|
| 86 | - 'page_suivante' => 'volgende pagina', |
|
| 87 | - 'par_auteur' => 'door ', |
|
| 88 | - 'participer_site' => 'Wanneer je je hieronder inschrijft, kun je zelf een bijdrage leveren aan deze site door je eigen artikelen voor te stellen. Je ontvangt meteen een e-mail met daarin de toegangscode voor het privé-gedeelte van de site.', |
|
| 89 | - 'plan_site' => 'Overzicht van de site', |
|
| 90 | - 'popularite' => 'Populariteit', |
|
| 91 | - 'poster_message' => 'Een bericht plaatsen', |
|
| 92 | - 'proposer_site' => 'Je kan voorstellen een site in deze rubriek op te nemen:', |
|
| 93 | - |
|
| 94 | - // R |
|
| 95 | - 'repondre_article' => 'Dit artikel beantwoorden', |
|
| 96 | - 'repondre_breve' => 'Op deze nieuwsflits reageren', |
|
| 97 | - 'resultats_recherche' => 'Resultaten van de zoekopdracht', |
|
| 98 | - 'retour_debut_forums' => 'Terug naar de startpagina van de forums', |
|
| 99 | - 'rubrique' => 'Rubriek', |
|
| 100 | - 'rubriques' => 'Rubrieken', |
|
| 101 | - |
|
| 102 | - // S |
|
| 103 | - 'signatures_petition' => 'Ondertekeningen', |
|
| 104 | - 'site_realise_avec_spip' => 'Site gebouwd met SPIP', |
|
| 105 | - 'sites_web' => 'Websites', |
|
| 106 | - 'sous_rubriques' => 'Subrubrieken', |
|
| 107 | - 'spam' => 'Spam', |
|
| 108 | - 'suite' => 'vervolg', |
|
| 109 | - 'sur_web' => 'Op het web', |
|
| 110 | - 'syndiquer_rubrique' => 'Nieuws overnemen uit deze rubriek', |
|
| 111 | - 'syndiquer_site' => 'Nieuws overnemen van de hele site', |
|
| 112 | - |
|
| 113 | - // T |
|
| 114 | - 'texte_lettre_information' => 'Dit is de nieuwsbrief van de site', |
|
| 115 | - 'texte_lettre_information_2' => 'Deze nieuwsbrief toont de publicaties vanaf', |
|
| 116 | - |
|
| 117 | - // V |
|
| 118 | - 'ver_imprimer' => 'Afdrukversie', |
|
| 119 | - 'voir_en_ligne' => 'Online bekijken', |
|
| 120 | - 'voir_squelette' => 'het skelet van deze bladzijde bekijken' |
|
| 12 | + // A |
|
| 13 | + 'accueil_site' => 'Homepagina', |
|
| 14 | + 'article' => 'Artikel', |
|
| 15 | + 'articles' => 'Artikelen', |
|
| 16 | + 'articles_auteur' => 'Artikelen van deze auteur', |
|
| 17 | + 'articles_populaires' => 'Meest bekeken artikelen', |
|
| 18 | + 'articles_rubrique' => 'Artikelen in deze rubriek', |
|
| 19 | + 'aucun_article' => 'Op dit adres is geen artikel te vinden', |
|
| 20 | + 'aucun_auteur' => 'Op dit adres is geen auteur te vinden', |
|
| 21 | + 'aucun_site' => 'Op dit adres is geen site te vinden', |
|
| 22 | + 'aucune_breve' => 'Op dit adres is geen nieuwsflits te vinden', |
|
| 23 | + 'aucune_rubrique' => 'Op dit adres is geen rubriek te vinden', |
|
| 24 | + 'auteur' => 'Auteur', |
|
| 25 | + 'autres' => 'Anderen', |
|
| 26 | + 'autres_breves' => 'Andere nieuwsflitsen', |
|
| 27 | + 'autres_groupes_mots_clefs' => 'Andere groepen trefwoorden', |
|
| 28 | + 'autres_sites' => 'Andere sites', |
|
| 29 | + |
|
| 30 | + // B |
|
| 31 | + 'bonjour' => 'Hallo', |
|
| 32 | + |
|
| 33 | + // C |
|
| 34 | + 'commenter_site' => 'Reageren op de site', |
|
| 35 | + 'contact' => 'Contact', |
|
| 36 | + 'copie_document_impossible' => 'Het is niet mogelijk het document te kopiëren', |
|
| 37 | + |
|
| 38 | + // D |
|
| 39 | + 'date' => 'Datum', |
|
| 40 | + 'dernier_ajout' => 'Laatste toevoeging', |
|
| 41 | + 'dernieres_breves' => 'Laatste nieuwsflitsen', |
|
| 42 | + 'derniers_articles' => 'Laatste artikelen', |
|
| 43 | + 'derniers_commentaires' => 'Laatste commentaren', |
|
| 44 | + 'derniers_messages_forum' => 'Laatst gepubliceerde berichten in het forum', |
|
| 45 | + |
|
| 46 | + // E |
|
| 47 | + 'edition_mode_texte' => 'Uitgave in tekstmodus van', |
|
| 48 | + 'en_reponse' => 'Als antwoord op:', |
|
| 49 | + 'en_resume' => 'Samengevat', |
|
| 50 | + 'envoyer_message' => 'Een bericht sturen', |
|
| 51 | + 'espace_prive' => 'Privé gedeelte', |
|
| 52 | + |
|
| 53 | + // F |
|
| 54 | + 'formats_acceptes' => 'Toegelaten formaten: @formats@.', |
|
| 55 | + |
|
| 56 | + // H |
|
| 57 | + 'hierarchie_site' => 'Structuur van de site', |
|
| 58 | + |
|
| 59 | + // J |
|
| 60 | + 'jours' => 'dagen', |
|
| 61 | + |
|
| 62 | + // L |
|
| 63 | + 'lien_connecter' => 'Aanmelden', |
|
| 64 | + |
|
| 65 | + // M |
|
| 66 | + 'meme_auteur' => 'Van dezelfde auteur', |
|
| 67 | + 'meme_rubrique' => 'In dezelfde rubriek', |
|
| 68 | + 'memes_auteurs' => 'Van dezelfde auteurs', |
|
| 69 | + 'message' => 'Bericht', |
|
| 70 | + 'messages_forum' => 'Berichten', |
|
| 71 | + 'messages_recents' => 'Meest recente forumberichten', |
|
| 72 | + 'mots_clef' => 'Trefwoord', |
|
| 73 | + 'mots_clefs' => 'Trefwoorden', |
|
| 74 | + 'mots_clefs_meme_groupe' => 'Trefwoorden van dezelfde groep', |
|
| 75 | + |
|
| 76 | + // N |
|
| 77 | + 'navigation' => 'Navigatie', |
|
| 78 | + 'nom' => 'Naam', |
|
| 79 | + 'nouveautes' => 'Nieuwigheden', |
|
| 80 | + 'nouveautes_web' => 'Nieuwigheden op het Web', |
|
| 81 | + 'nouveaux_articles' => 'Nieuwe artikelen', |
|
| 82 | + 'nouvelles_breves' => 'Nieuwe nieuwsflitsen', |
|
| 83 | + |
|
| 84 | + // P |
|
| 85 | + 'page_precedente' => 'vorige pagina', |
|
| 86 | + 'page_suivante' => 'volgende pagina', |
|
| 87 | + 'par_auteur' => 'door ', |
|
| 88 | + 'participer_site' => 'Wanneer je je hieronder inschrijft, kun je zelf een bijdrage leveren aan deze site door je eigen artikelen voor te stellen. Je ontvangt meteen een e-mail met daarin de toegangscode voor het privé-gedeelte van de site.', |
|
| 89 | + 'plan_site' => 'Overzicht van de site', |
|
| 90 | + 'popularite' => 'Populariteit', |
|
| 91 | + 'poster_message' => 'Een bericht plaatsen', |
|
| 92 | + 'proposer_site' => 'Je kan voorstellen een site in deze rubriek op te nemen:', |
|
| 93 | + |
|
| 94 | + // R |
|
| 95 | + 'repondre_article' => 'Dit artikel beantwoorden', |
|
| 96 | + 'repondre_breve' => 'Op deze nieuwsflits reageren', |
|
| 97 | + 'resultats_recherche' => 'Resultaten van de zoekopdracht', |
|
| 98 | + 'retour_debut_forums' => 'Terug naar de startpagina van de forums', |
|
| 99 | + 'rubrique' => 'Rubriek', |
|
| 100 | + 'rubriques' => 'Rubrieken', |
|
| 101 | + |
|
| 102 | + // S |
|
| 103 | + 'signatures_petition' => 'Ondertekeningen', |
|
| 104 | + 'site_realise_avec_spip' => 'Site gebouwd met SPIP', |
|
| 105 | + 'sites_web' => 'Websites', |
|
| 106 | + 'sous_rubriques' => 'Subrubrieken', |
|
| 107 | + 'spam' => 'Spam', |
|
| 108 | + 'suite' => 'vervolg', |
|
| 109 | + 'sur_web' => 'Op het web', |
|
| 110 | + 'syndiquer_rubrique' => 'Nieuws overnemen uit deze rubriek', |
|
| 111 | + 'syndiquer_site' => 'Nieuws overnemen van de hele site', |
|
| 112 | + |
|
| 113 | + // T |
|
| 114 | + 'texte_lettre_information' => 'Dit is de nieuwsbrief van de site', |
|
| 115 | + 'texte_lettre_information_2' => 'Deze nieuwsbrief toont de publicaties vanaf', |
|
| 116 | + |
|
| 117 | + // V |
|
| 118 | + 'ver_imprimer' => 'Afdrukversie', |
|
| 119 | + 'voir_en_ligne' => 'Online bekijken', |
|
| 120 | + 'voir_squelette' => 'het skelet van deze bladzijde bekijken' |
|
| 121 | 121 | ); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $test_dir .= '/'; |
| 82 | 82 | } |
| 83 | 83 | if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
| 84 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 84 | + $GLOBALS['test_dirs'][] = _DIR_RACINE.$test_dir; |
|
| 85 | 85 | } |
| 86 | 86 | } else { |
| 87 | 87 | if (!_FILE_CONNECT) { |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
| 97 | 97 | $test = test_ecrire($my_dir); |
| 98 | 98 | if (!$test) { |
| 99 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 99 | + $m = preg_replace(',^'._DIR_RACINE.',', '', $my_dir); |
|
| 100 | 100 | if (@file_exists($my_dir)) { |
| 101 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 101 | + $bad_dirs['<li>'.$m.'</li>'] = 1; |
|
| 102 | 102 | } else { |
| 103 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 103 | + $absent_dirs['<li>'.$m.'</li>'] = 1; |
|
| 104 | 104 | } |
| 105 | 105 | } else { |
| 106 | 106 | $chmod = max($chmod, $test); |
@@ -110,21 +110,21 @@ discard block |
||
| 110 | 110 | if ($bad_dirs or $absent_dirs) { |
| 111 | 111 | if (!_FILE_CONNECT) { |
| 112 | 112 | $titre = _T('dirs_preliminaire'); |
| 113 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 113 | + $continuer = ' '._T('dirs_commencer').'.'; |
|
| 114 | 114 | } else { |
| 115 | 115 | $titre = _T('dirs_probleme_droits'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 119 | + $res = "<div align='right'>".menu_langues('var_lang_ecrire')."</div>\n"; |
|
| 120 | 120 | |
| 121 | 121 | if ($bad_dirs) { |
| 122 | 122 | $res .= |
| 123 | 123 | _T( |
| 124 | 124 | 'dirs_repertoires_suivants', |
| 125 | 125 | array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
| 126 | - ) . |
|
| 127 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 126 | + ). |
|
| 127 | + '<b>'._T('login_recharger').'</b>.'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ($absent_dirs) { |
@@ -132,22 +132,21 @@ discard block |
||
| 132 | 132 | _T( |
| 133 | 133 | 'dirs_repertoires_absents', |
| 134 | 134 | array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
| 135 | - ) . |
|
| 136 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 135 | + ). |
|
| 136 | + '<b>'._T('login_recharger').'</b>.'; |
|
| 137 | 137 | } |
| 138 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 138 | + $res = '<p>'.$continuer.$res.aider('install0', true).'</p>'; |
|
| 139 | 139 | |
| 140 | 140 | $t = _T('login_recharger'); |
| 141 | - $t = (!$test_dir ? '' : |
|
| 142 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 141 | + $t = (!$test_dir ? '' : "<input type='hidden' name='test_dir' value='".spip_htmlspecialchars($test_dir, ENT_QUOTES)."' />") |
|
| 143 | 142 | . "<input type='hidden' name='etape' value='chmod' />" |
| 144 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 143 | + . "<div style='text-align: right'><input type='submit' value='".attribut_html($t)."' /></div>"; |
|
| 145 | 144 | |
| 146 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 145 | + echo minipres($titre, $res.generer_form_ecrire('install', $t)); |
|
| 147 | 146 | } else { |
| 148 | 147 | $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
| 149 | 148 | if (!$deja) { |
| 150 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 149 | + redirige_url_ecrire('install', 'etape=1&chmod='.$chmod); |
|
| 151 | 150 | } else { |
| 152 | 151 | redirige_url_ecrire(); |
| 153 | 152 | } |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | if (defined('_TEST_DIRS')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | define('_TEST_DIRS', '1'); |
| 21 | 21 | |
@@ -27,42 +27,42 @@ discard block |
||
| 27 | 27 | // |
| 28 | 28 | // https://code.spip.net/@test_ecrire |
| 29 | 29 | function test_ecrire($my_dir) { |
| 30 | - static $chmod = 0; |
|
| 31 | - |
|
| 32 | - $ok = false; |
|
| 33 | - $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | - $self = basename($script); |
|
| 35 | - $uid = @fileowner('.'); |
|
| 36 | - $uid2 = @fileowner($self); |
|
| 37 | - $gid = @filegroup('.'); |
|
| 38 | - $gid2 = @filegroup($self); |
|
| 39 | - $perms = @fileperms($self); |
|
| 40 | - |
|
| 41 | - // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | - // avec celle du script et du repertoire courant |
|
| 43 | - if (!$chmod) { |
|
| 44 | - @rmdir('test'); |
|
| 45 | - spip_unlink('test'); // effacer au cas ou |
|
| 46 | - @touch('test'); |
|
| 47 | - if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | - $chmod = 0700; |
|
| 49 | - } else { |
|
| 50 | - if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | - $chmod = 0770; |
|
| 52 | - } else { |
|
| 53 | - $chmod = 0777; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - // Appliquer de plus les droits d'acces du script |
|
| 57 | - if ($perms > 0) { |
|
| 58 | - $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | - $chmod |= $perms; |
|
| 60 | - } |
|
| 61 | - spip_unlink('test'); |
|
| 62 | - } |
|
| 63 | - $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | - |
|
| 65 | - return $ok ? $chmod : false; |
|
| 30 | + static $chmod = 0; |
|
| 31 | + |
|
| 32 | + $ok = false; |
|
| 33 | + $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF']; |
|
| 34 | + $self = basename($script); |
|
| 35 | + $uid = @fileowner('.'); |
|
| 36 | + $uid2 = @fileowner($self); |
|
| 37 | + $gid = @filegroup('.'); |
|
| 38 | + $gid2 = @filegroup($self); |
|
| 39 | + $perms = @fileperms($self); |
|
| 40 | + |
|
| 41 | + // Comparer l'appartenance d'un fichier cree par PHP |
|
| 42 | + // avec celle du script et du repertoire courant |
|
| 43 | + if (!$chmod) { |
|
| 44 | + @rmdir('test'); |
|
| 45 | + spip_unlink('test'); // effacer au cas ou |
|
| 46 | + @touch('test'); |
|
| 47 | + if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) { |
|
| 48 | + $chmod = 0700; |
|
| 49 | + } else { |
|
| 50 | + if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) { |
|
| 51 | + $chmod = 0770; |
|
| 52 | + } else { |
|
| 53 | + $chmod = 0777; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + // Appliquer de plus les droits d'acces du script |
|
| 57 | + if ($perms > 0) { |
|
| 58 | + $perms = ($perms & 0777) | (($perms & 0444) >> 2); |
|
| 59 | + $chmod |= $perms; |
|
| 60 | + } |
|
| 61 | + spip_unlink('test'); |
|
| 62 | + } |
|
| 63 | + $ok = is_dir($my_dir) && is_writable($my_dir); |
|
| 64 | + |
|
| 65 | + return $ok ? $chmod : false; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // |
@@ -73,83 +73,83 @@ discard block |
||
| 73 | 73 | // https://code.spip.net/@install_etape_chmod_dist |
| 74 | 74 | function install_etape_chmod_dist() { |
| 75 | 75 | |
| 76 | - $test_dir = _request('test_dir'); |
|
| 77 | - $chmod = 0; |
|
| 78 | - |
|
| 79 | - if ($test_dir) { |
|
| 80 | - if (substr($test_dir, -1) !== '/') { |
|
| 81 | - $test_dir .= '/'; |
|
| 82 | - } |
|
| 83 | - if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | - $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - if (!_FILE_CONNECT) { |
|
| 88 | - $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | - $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $bad_dirs = array(); |
|
| 94 | - $absent_dirs = array(); |
|
| 95 | - |
|
| 96 | - foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | - $test = test_ecrire($my_dir); |
|
| 98 | - if (!$test) { |
|
| 99 | - $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | - if (@file_exists($my_dir)) { |
|
| 101 | - $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | - } else { |
|
| 103 | - $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | - } |
|
| 105 | - } else { |
|
| 106 | - $chmod = max($chmod, $test); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($bad_dirs or $absent_dirs) { |
|
| 111 | - if (!_FILE_CONNECT) { |
|
| 112 | - $titre = _T('dirs_preliminaire'); |
|
| 113 | - $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | - } else { |
|
| 115 | - $titre = _T('dirs_probleme_droits'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | - |
|
| 121 | - if ($bad_dirs) { |
|
| 122 | - $res .= |
|
| 123 | - _T( |
|
| 124 | - 'dirs_repertoires_suivants', |
|
| 125 | - array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | - ) . |
|
| 127 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($absent_dirs) { |
|
| 131 | - $res .= |
|
| 132 | - _T( |
|
| 133 | - 'dirs_repertoires_absents', |
|
| 134 | - array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | - ) . |
|
| 136 | - '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | - } |
|
| 138 | - $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | - |
|
| 140 | - $t = _T('login_recharger'); |
|
| 141 | - $t = (!$test_dir ? '' : |
|
| 142 | - "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | - . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | - . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | - |
|
| 146 | - echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | - } else { |
|
| 148 | - $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | - if (!$deja) { |
|
| 150 | - redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | - } else { |
|
| 152 | - redirige_url_ecrire(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 76 | + $test_dir = _request('test_dir'); |
|
| 77 | + $chmod = 0; |
|
| 78 | + |
|
| 79 | + if ($test_dir) { |
|
| 80 | + if (substr($test_dir, -1) !== '/') { |
|
| 81 | + $test_dir .= '/'; |
|
| 82 | + } |
|
| 83 | + if (!in_array($test_dir, $GLOBALS['test_dirs'])) { |
|
| 84 | + $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir; |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + if (!_FILE_CONNECT) { |
|
| 88 | + $GLOBALS['test_dirs'][] = _DIR_CONNECT; |
|
| 89 | + $GLOBALS['test_dirs'][] = _DIR_CHMOD; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $bad_dirs = array(); |
|
| 94 | + $absent_dirs = array(); |
|
| 95 | + |
|
| 96 | + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { |
|
| 97 | + $test = test_ecrire($my_dir); |
|
| 98 | + if (!$test) { |
|
| 99 | + $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); |
|
| 100 | + if (@file_exists($my_dir)) { |
|
| 101 | + $bad_dirs['<li>' . $m . '</li>'] = 1; |
|
| 102 | + } else { |
|
| 103 | + $absent_dirs['<li>' . $m . '</li>'] = 1; |
|
| 104 | + } |
|
| 105 | + } else { |
|
| 106 | + $chmod = max($chmod, $test); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($bad_dirs or $absent_dirs) { |
|
| 111 | + if (!_FILE_CONNECT) { |
|
| 112 | + $titre = _T('dirs_preliminaire'); |
|
| 113 | + $continuer = ' ' . _T('dirs_commencer') . '.'; |
|
| 114 | + } else { |
|
| 115 | + $titre = _T('dirs_probleme_droits'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n"; |
|
| 120 | + |
|
| 121 | + if ($bad_dirs) { |
|
| 122 | + $res .= |
|
| 123 | + _T( |
|
| 124 | + 'dirs_repertoires_suivants', |
|
| 125 | + array('bad_dirs' => join("\n", array_keys($bad_dirs))) |
|
| 126 | + ) . |
|
| 127 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($absent_dirs) { |
|
| 131 | + $res .= |
|
| 132 | + _T( |
|
| 133 | + 'dirs_repertoires_absents', |
|
| 134 | + array('bad_dirs' => join("\n", array_keys($absent_dirs))) |
|
| 135 | + ) . |
|
| 136 | + '<b>' . _T('login_recharger') . '</b>.'; |
|
| 137 | + } |
|
| 138 | + $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>'; |
|
| 139 | + |
|
| 140 | + $t = _T('login_recharger'); |
|
| 141 | + $t = (!$test_dir ? '' : |
|
| 142 | + "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />") |
|
| 143 | + . "<input type='hidden' name='etape' value='chmod' />" |
|
| 144 | + . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>"; |
|
| 145 | + |
|
| 146 | + echo minipres($titre, $res . generer_form_ecrire('install', $t)); |
|
| 147 | + } else { |
|
| 148 | + $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT)); |
|
| 149 | + if (!$deja) { |
|
| 150 | + redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod); |
|
| 151 | + } else { |
|
| 152 | + redirige_url_ecrire(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return array('', ''); |
|
| 37 | + return array('', ''); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (array('script', 'iframe') as $tag) { |
|
| 106 | - if (stripos($t, "<$tag") !== false |
|
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | - ) { |
|
| 109 | - foreach ($r as $regs) { |
|
| 110 | - $t = str_replace($regs[0], |
|
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | - $t); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $t; |
|
| 105 | + foreach (array('script', 'iframe') as $tag) { |
|
| 106 | + if (stripos($t, "<$tag") !== false |
|
| 107 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + ) { |
|
| 109 | + foreach ($r as $regs) { |
|
| 110 | + $t = str_replace($regs[0], |
|
| 111 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | + $t); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $t; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -143,55 +143,55 @@ discard block |
||
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | 145 | function interdire_scripts($arg, $mode_filtre=null) { |
| 146 | - // on memorise le resultat sur les arguments non triviaux |
|
| 147 | - static $dejavu = array(); |
|
| 148 | - |
|
| 149 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | - return $arg; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | - return $dejavu[$mode_filtre][$arg]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // echapper les tags asp/php |
|
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | - |
|
| 165 | - // echapper le php |
|
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | - |
|
| 168 | - // echapper le < script language=php > |
|
| 169 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | - |
|
| 171 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | - switch ($mode_filtre) { |
|
| 173 | - case 0: |
|
| 174 | - if (!_DIR_RESTREINT) { |
|
| 175 | - $t = echappe_js($t); |
|
| 176 | - } |
|
| 177 | - break; |
|
| 178 | - case -1: |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - break; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // pas de <base href /> svp ! |
|
| 184 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | - |
|
| 186 | - // Reinserer les echappements des modeles |
|
| 187 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | - } |
|
| 190 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 146 | + // on memorise le resultat sur les arguments non triviaux |
|
| 147 | + static $dejavu = array(); |
|
| 148 | + |
|
| 149 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | + return $arg; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | + return $dejavu[$mode_filtre][$arg]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // echapper les tags asp/php |
|
| 163 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | + |
|
| 165 | + // echapper le php |
|
| 166 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | + |
|
| 168 | + // echapper le < script language=php > |
|
| 169 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | + |
|
| 171 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | + switch ($mode_filtre) { |
|
| 173 | + case 0: |
|
| 174 | + if (!_DIR_RESTREINT) { |
|
| 175 | + $t = echappe_js($t); |
|
| 176 | + } |
|
| 177 | + break; |
|
| 178 | + case -1: |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + break; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // pas de <base href /> svp ! |
|
| 184 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | + |
|
| 186 | + // Reinserer les echappements des modeles |
|
| 187 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | + $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | + } |
|
| 190 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -220,64 +220,64 @@ discard block |
||
| 220 | 220 | * Texte transformé |
| 221 | 221 | **/ |
| 222 | 222 | function typo($letexte, $echapper = true, $connect = null, $env = array()) { |
| 223 | - // Plus vite ! |
|
| 224 | - if (!$letexte) { |
|
| 225 | - return $letexte; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | - // prive etant historiquement ecrit sans argment $connect |
|
| 230 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | - // ou il faut passer interdire_script explicitement |
|
| 232 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | - // ne seront pas perturbes |
|
| 234 | - $interdire_script = false; |
|
| 235 | - if (is_null($connect)) { |
|
| 236 | - $connect = ''; |
|
| 237 | - $interdire_script = true; |
|
| 238 | - $env['espace_prive'] = test_espace_prive(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Echapper les codes <html> etc |
|
| 242 | - if ($echapper) { |
|
| 243 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // |
|
| 247 | - // Installer les modeles, notamment images et documents ; |
|
| 248 | - // |
|
| 249 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | - // cf. inc/lien |
|
| 251 | - |
|
| 252 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | - if ($letexte != $mem) { |
|
| 254 | - $echapper = true; |
|
| 255 | - } |
|
| 256 | - unset($mem); |
|
| 257 | - |
|
| 258 | - $letexte = corriger_typo($letexte); |
|
| 259 | - $letexte = echapper_faux_tags($letexte); |
|
| 260 | - |
|
| 261 | - // reintegrer les echappements |
|
| 262 | - if ($echapper) { |
|
| 263 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | - if ($interdire_script) { |
|
| 268 | - $letexte = interdire_scripts($letexte); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | - // https://core.spip.net/issues/3371 |
|
| 273 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | - // https://core.spip.net/issues/4166 |
|
| 275 | - if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | - $letexte = echapper_html_suspect($letexte); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $letexte; |
|
| 223 | + // Plus vite ! |
|
| 224 | + if (!$letexte) { |
|
| 225 | + return $letexte; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | + // prive etant historiquement ecrit sans argment $connect |
|
| 230 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | + // ou il faut passer interdire_script explicitement |
|
| 232 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | + // ne seront pas perturbes |
|
| 234 | + $interdire_script = false; |
|
| 235 | + if (is_null($connect)) { |
|
| 236 | + $connect = ''; |
|
| 237 | + $interdire_script = true; |
|
| 238 | + $env['espace_prive'] = test_espace_prive(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Echapper les codes <html> etc |
|
| 242 | + if ($echapper) { |
|
| 243 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // |
|
| 247 | + // Installer les modeles, notamment images et documents ; |
|
| 248 | + // |
|
| 249 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | + // cf. inc/lien |
|
| 251 | + |
|
| 252 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | + if ($letexte != $mem) { |
|
| 254 | + $echapper = true; |
|
| 255 | + } |
|
| 256 | + unset($mem); |
|
| 257 | + |
|
| 258 | + $letexte = corriger_typo($letexte); |
|
| 259 | + $letexte = echapper_faux_tags($letexte); |
|
| 260 | + |
|
| 261 | + // reintegrer les echappements |
|
| 262 | + if ($echapper) { |
|
| 263 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | + if ($interdire_script) { |
|
| 268 | + $letexte = interdire_scripts($letexte); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | + // https://core.spip.net/issues/3371 |
|
| 273 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | + // https://core.spip.net/issues/4166 |
|
| 275 | + if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | + $letexte = echapper_html_suspect($letexte); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $letexte; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Correcteur typographique |
@@ -302,57 +302,57 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function corriger_typo($letexte, $lang = '') { |
| 304 | 304 | |
| 305 | - // Plus vite ! |
|
| 306 | - if (!$letexte) { |
|
| 307 | - return $letexte; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | - |
|
| 312 | - // Caracteres de controle "illegaux" |
|
| 313 | - $letexte = corriger_caracteres($letexte); |
|
| 314 | - |
|
| 315 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | - foreach ($regs as $reg) { |
|
| 318 | - $insert = $reg[0]; |
|
| 319 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // trouver les blocs idiomes et les traiter à part |
|
| 327 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | - $ei = ($ei !== $letexte); |
|
| 329 | - |
|
| 330 | - // trouver les blocs multi et les traiter a part |
|
| 331 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | - $em = ($em !== $letexte); |
|
| 333 | - |
|
| 334 | - // Charger & appliquer les fonctions de typographie |
|
| 335 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | - $letexte = $typographie($letexte); |
|
| 337 | - |
|
| 338 | - // Les citations en une autre langue, s'il y a lieu |
|
| 339 | - if ($em) { |
|
| 340 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | - } |
|
| 342 | - if ($ei) { |
|
| 343 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Retablir les caracteres proteges |
|
| 347 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | - |
|
| 349 | - // pipeline |
|
| 350 | - $letexte = pipeline('post_typo', $letexte); |
|
| 351 | - |
|
| 352 | - # un message pour abs_url - on est passe en mode texte |
|
| 353 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | - |
|
| 355 | - return $letexte; |
|
| 305 | + // Plus vite ! |
|
| 306 | + if (!$letexte) { |
|
| 307 | + return $letexte; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | + |
|
| 312 | + // Caracteres de controle "illegaux" |
|
| 313 | + $letexte = corriger_caracteres($letexte); |
|
| 314 | + |
|
| 315 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | + foreach ($regs as $reg) { |
|
| 318 | + $insert = $reg[0]; |
|
| 319 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // trouver les blocs idiomes et les traiter à part |
|
| 327 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | + $ei = ($ei !== $letexte); |
|
| 329 | + |
|
| 330 | + // trouver les blocs multi et les traiter a part |
|
| 331 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | + $em = ($em !== $letexte); |
|
| 333 | + |
|
| 334 | + // Charger & appliquer les fonctions de typographie |
|
| 335 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | + $letexte = $typographie($letexte); |
|
| 337 | + |
|
| 338 | + // Les citations en une autre langue, s'il y a lieu |
|
| 339 | + if ($em) { |
|
| 340 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | + } |
|
| 342 | + if ($ei) { |
|
| 343 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Retablir les caracteres proteges |
|
| 347 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | + |
|
| 349 | + // pipeline |
|
| 350 | + $letexte = pipeline('post_typo', $letexte); |
|
| 351 | + |
|
| 352 | + # un message pour abs_url - on est passe en mode texte |
|
| 353 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | + |
|
| 355 | + return $letexte; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function paragrapher($letexte, $forcer = true) { |
| 371 | - return $letexte; |
|
| 371 | + return $letexte; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @return string Texte |
| 381 | 381 | **/ |
| 382 | 382 | function traiter_retours_chariots($letexte) { |
| 383 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | - $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | - $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 383 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | + $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | + $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 386 | 386 | |
| 387 | - return $letexte; |
|
| 387 | + return $letexte; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -410,37 +410,37 @@ discard block |
||
| 410 | 410 | * Texte transformé |
| 411 | 411 | **/ |
| 412 | 412 | function propre($t, $connect = null, $env = array()) { |
| 413 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | - // prive etant historiquement ecrits sans argment $connect |
|
| 415 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | - // ou il faut passer interdire_script explicitement |
|
| 417 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | - // ne seront pas perturbes |
|
| 419 | - $interdire_script = false; |
|
| 420 | - if (is_null($connect)) { |
|
| 421 | - $connect = ''; |
|
| 422 | - $interdire_script = true; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (!$t) { |
|
| 426 | - return strval($t); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | - // avant echappement des balises <html> |
|
| 431 | - // https://core.spip.net/issues/3371 |
|
| 432 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | - // https://core.spip.net/issues/4166 |
|
| 434 | - if ($interdire_script |
|
| 435 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | - $t = echapper_html_suspect($t, false); |
|
| 439 | - } |
|
| 440 | - $t = echappe_html($t); |
|
| 441 | - $t = expanser_liens($t, $connect, $env); |
|
| 442 | - $t = traiter_raccourcis($t); |
|
| 443 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | - |
|
| 445 | - return $t; |
|
| 413 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | + // prive etant historiquement ecrits sans argment $connect |
|
| 415 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | + // ou il faut passer interdire_script explicitement |
|
| 417 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | + // ne seront pas perturbes |
|
| 419 | + $interdire_script = false; |
|
| 420 | + if (is_null($connect)) { |
|
| 421 | + $connect = ''; |
|
| 422 | + $interdire_script = true; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (!$t) { |
|
| 426 | + return strval($t); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | + // avant echappement des balises <html> |
|
| 431 | + // https://core.spip.net/issues/3371 |
|
| 432 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | + // https://core.spip.net/issues/4166 |
|
| 434 | + if ($interdire_script |
|
| 435 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | + $t = echapper_html_suspect($t, false); |
|
| 439 | + } |
|
| 440 | + $t = echappe_html($t); |
|
| 441 | + $t = expanser_liens($t, $connect, $env); |
|
| 442 | + $t = traiter_raccourcis($t); |
|
| 443 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | + |
|
| 445 | + return $t; |
|
| 446 | 446 | } |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | 105 | foreach (array('script', 'iframe') as $tag) { |
| 106 | 106 | if (stripos($t, "<$tag") !== false |
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 107 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | 108 | ) { |
| 109 | 109 | foreach ($r as $regs) { |
| 110 | 110 | $t = str_replace($regs[0], |
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 111 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 112 | 112 | $t); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return string |
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | -function interdire_scripts($arg, $mode_filtre=null) { |
|
| 145 | +function interdire_scripts($arg, $mode_filtre = null) { |
|
| 146 | 146 | // on memorise le resultat sur les arguments non triviaux |
| 147 | 147 | static $dejavu = array(); |
| 148 | 148 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // echapper les tags asp/php |
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 163 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 164 | 164 | |
| 165 | 165 | // echapper le php |
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 166 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le < script language=php > |
| 169 | 169 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // Reinserer les echappements des modeles |
| 187 | 187 | if (defined('_PROTEGE_JS_MODELES')) { |
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 188 | + $t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES); |
|
| 189 | 189 | } |
| 190 | 190 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 191 | + $t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
| 274 | 274 | // https://core.spip.net/issues/4166 |
| 275 | 275 | if ($GLOBALS['filtrer_javascript'] == -1 |
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 277 | 277 | $letexte = echapper_html_suspect($letexte); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 285 | 285 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 286 | 286 | |
| 287 | -define('_TYPO_BALISE', ",</?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS"); |
|
| 287 | +define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS"); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Corrige la typographie |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | // https://core.spip.net/issues/4166 |
| 434 | 434 | if ($interdire_script |
| 435 | 435 | or $GLOBALS['filtrer_javascript'] == -1 |
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 438 | 438 | $t = echapper_html_suspect($t, false); |
| 439 | 439 | } |
| 440 | 440 | $t = echappe_html($t); |
@@ -1256,8 +1256,9 @@ |
||
| 1256 | 1256 | $http_noproxy = " $http_noproxy "; |
| 1257 | 1257 | $domain = $host; |
| 1258 | 1258 | // si le domaine exact www.example.org est dans les exceptions |
| 1259 | - if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1260 | - return ''; |
|
| 1259 | + if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1260 | + return ''; |
|
| 1261 | + } |
|
| 1261 | 1262 | |
| 1262 | 1263 | while (strpos($domain, '.') !== false) { |
| 1263 | 1264 | $domain = explode('.', $domain); |
@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,77 +68,77 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode == 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode == 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | - |
|
| 126 | - // pour une eventuelle indexation |
|
| 127 | - pipeline( |
|
| 128 | - 'post_edition', |
|
| 129 | - array( |
|
| 130 | - 'args' => array( |
|
| 131 | - 'operation' => 'copie_locale', |
|
| 132 | - 'source' => $source, |
|
| 133 | - 'fichier' => $local, |
|
| 134 | - 'http_res' => $res['length'], |
|
| 135 | - ), |
|
| 136 | - 'data' => null |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode == 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode == 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | + |
|
| 126 | + // pour une eventuelle indexation |
|
| 127 | + pipeline( |
|
| 128 | + 'post_edition', |
|
| 129 | + array( |
|
| 130 | + 'args' => array( |
|
| 131 | + 'operation' => 'copie_locale', |
|
| 132 | + 'source' => $source, |
|
| 133 | + 'fichier' => $local, |
|
| 134 | + 'http_res' => $res['length'], |
|
| 135 | + ), |
|
| 136 | + 'data' => null |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $local; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -153,88 +153,88 @@ discard block |
||
| 153 | 153 | * url ou false en cas d'echec |
| 154 | 154 | */ |
| 155 | 155 | function valider_url_distante($url, $known_hosts = array()) { |
| 156 | - if (!function_exists('protocole_verifier')){ |
|
| 157 | - include_spip('inc/filtres_mini'); |
|
| 158 | - } |
|
| 156 | + if (!function_exists('protocole_verifier')){ |
|
| 157 | + include_spip('inc/filtres_mini'); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 160 | + if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - $parsed_url = parse_url($url); |
|
| 165 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!is_array($known_hosts)) { |
|
| 178 | - $known_hosts = array($known_hosts); |
|
| 179 | - } |
|
| 180 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | - $known_hosts[] = url_de_base(); |
|
| 182 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | - |
|
| 184 | - $is_known_host = false; |
|
| 185 | - foreach ($known_hosts as $known_host) { |
|
| 186 | - $parse_known = parse_url($known_host); |
|
| 187 | - if ($parse_known |
|
| 188 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 189 | - $is_known_host = true; |
|
| 190 | - break; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!$is_known_host) { |
|
| 195 | - $host = trim($parsed_url['host'], '.'); |
|
| 196 | - if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 197 | - $ip = $host; |
|
| 198 | - } else { |
|
| 199 | - $ip = gethostbyname($host); |
|
| 200 | - if ($ip === $host) { |
|
| 201 | - // Error condition for gethostbyname() |
|
| 202 | - $ip = false; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - if ($ip) { |
|
| 206 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 207 | - if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 208 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 210 | - ) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (empty($parsed_url['port'])) { |
|
| 217 | - return $url; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $port = $parsed_url['port']; |
|
| 221 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | - return $url; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - if ($is_known_host) { |
|
| 226 | - foreach ($known_hosts as $known_host) { |
|
| 227 | - $parse_known = parse_url($known_host); |
|
| 228 | - if ($parse_known |
|
| 229 | - and !empty($parse_known['port']) |
|
| 230 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 231 | - and $parse_known['port'] == $port) { |
|
| 232 | - return $url; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return false; |
|
| 164 | + $parsed_url = parse_url($url); |
|
| 165 | + if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!is_array($known_hosts)) { |
|
| 178 | + $known_hosts = array($known_hosts); |
|
| 179 | + } |
|
| 180 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | + $known_hosts[] = url_de_base(); |
|
| 182 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | + |
|
| 184 | + $is_known_host = false; |
|
| 185 | + foreach ($known_hosts as $known_host) { |
|
| 186 | + $parse_known = parse_url($known_host); |
|
| 187 | + if ($parse_known |
|
| 188 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 189 | + $is_known_host = true; |
|
| 190 | + break; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!$is_known_host) { |
|
| 195 | + $host = trim($parsed_url['host'], '.'); |
|
| 196 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 197 | + $ip = $host; |
|
| 198 | + } else { |
|
| 199 | + $ip = gethostbyname($host); |
|
| 200 | + if ($ip === $host) { |
|
| 201 | + // Error condition for gethostbyname() |
|
| 202 | + $ip = false; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + if ($ip) { |
|
| 206 | + $parts = array_map('intval', explode( '.', $ip )); |
|
| 207 | + if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 208 | + or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | + or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 210 | + ) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (empty($parsed_url['port'])) { |
|
| 217 | + return $url; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $port = $parsed_url['port']; |
|
| 221 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | + return $url; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + if ($is_known_host) { |
|
| 226 | + foreach ($known_hosts as $known_host) { |
|
| 227 | + $parse_known = parse_url($known_host); |
|
| 228 | + if ($parse_known |
|
| 229 | + and !empty($parse_known['port']) |
|
| 230 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 231 | + and $parse_known['port'] == $port) { |
|
| 232 | + return $url; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return false; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -254,86 +254,86 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | function prepare_donnees_post($donnees, $boundary = '') { |
| 256 | 256 | |
| 257 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 258 | - // pour un appel soap par exemple |
|
| 259 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 260 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 261 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 262 | - $entete = ''; |
|
| 263 | - // on repasse tous les \r\n et \r en simples \n |
|
| 264 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 265 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 266 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 267 | - $p = strpos($donnees, "\n\n"); |
|
| 268 | - if ($p !== false) { |
|
| 269 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 270 | - $donnees = substr($donnees, $p + 2); |
|
| 271 | - } |
|
| 272 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 273 | - } else { |
|
| 274 | - /* boundary automatique */ |
|
| 275 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 276 | - if ($boundary === '') { |
|
| 277 | - $taille = 0; |
|
| 278 | - foreach ($donnees as $cle => $valeur) { |
|
| 279 | - if (is_array($valeur)) { |
|
| 280 | - foreach ($valeur as $val2) { |
|
| 281 | - $taille += strlen($val2); |
|
| 282 | - } |
|
| 283 | - } else { |
|
| 284 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 285 | - $taille += strlen($valeur); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - if ($taille > 500) { |
|
| 289 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 294 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 295 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 296 | - $chaine = ''; |
|
| 297 | - if (is_array($donnees)) { |
|
| 298 | - foreach ($donnees as $cle => $valeur) { |
|
| 299 | - if (is_array($valeur)) { |
|
| 300 | - foreach ($valeur as $val2) { |
|
| 301 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 302 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 303 | - $chaine .= "\r\n"; |
|
| 304 | - $chaine .= $val2; |
|
| 305 | - } |
|
| 306 | - } else { |
|
| 307 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 308 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 309 | - $chaine .= "\r\n"; |
|
| 310 | - $chaine .= $valeur; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 314 | - } |
|
| 315 | - } else { |
|
| 316 | - // fabrique une chaine HTTP simple pour un POST |
|
| 317 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 318 | - $chaine = array(); |
|
| 319 | - if (is_array($donnees)) { |
|
| 320 | - foreach ($donnees as $cle => $valeur) { |
|
| 321 | - if (is_array($valeur)) { |
|
| 322 | - foreach ($valeur as $val2) { |
|
| 323 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 324 | - } |
|
| 325 | - } else { |
|
| 326 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - $chaine = implode('&', $chaine); |
|
| 330 | - } else { |
|
| 331 | - $chaine = $donnees; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return array($entete, $chaine); |
|
| 257 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 258 | + // pour un appel soap par exemple |
|
| 259 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 260 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 261 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 262 | + $entete = ''; |
|
| 263 | + // on repasse tous les \r\n et \r en simples \n |
|
| 264 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 265 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 266 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 267 | + $p = strpos($donnees, "\n\n"); |
|
| 268 | + if ($p !== false) { |
|
| 269 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 270 | + $donnees = substr($donnees, $p + 2); |
|
| 271 | + } |
|
| 272 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 273 | + } else { |
|
| 274 | + /* boundary automatique */ |
|
| 275 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 276 | + if ($boundary === '') { |
|
| 277 | + $taille = 0; |
|
| 278 | + foreach ($donnees as $cle => $valeur) { |
|
| 279 | + if (is_array($valeur)) { |
|
| 280 | + foreach ($valeur as $val2) { |
|
| 281 | + $taille += strlen($val2); |
|
| 282 | + } |
|
| 283 | + } else { |
|
| 284 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 285 | + $taille += strlen($valeur); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + if ($taille > 500) { |
|
| 289 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 294 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 295 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 296 | + $chaine = ''; |
|
| 297 | + if (is_array($donnees)) { |
|
| 298 | + foreach ($donnees as $cle => $valeur) { |
|
| 299 | + if (is_array($valeur)) { |
|
| 300 | + foreach ($valeur as $val2) { |
|
| 301 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 302 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 303 | + $chaine .= "\r\n"; |
|
| 304 | + $chaine .= $val2; |
|
| 305 | + } |
|
| 306 | + } else { |
|
| 307 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 308 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 309 | + $chaine .= "\r\n"; |
|
| 310 | + $chaine .= $valeur; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 314 | + } |
|
| 315 | + } else { |
|
| 316 | + // fabrique une chaine HTTP simple pour un POST |
|
| 317 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 318 | + $chaine = array(); |
|
| 319 | + if (is_array($donnees)) { |
|
| 320 | + foreach ($donnees as $cle => $valeur) { |
|
| 321 | + if (is_array($valeur)) { |
|
| 322 | + foreach ($valeur as $val2) { |
|
| 323 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 324 | + } |
|
| 325 | + } else { |
|
| 326 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + $chaine = implode('&', $chaine); |
|
| 330 | + } else { |
|
| 331 | + $chaine = $donnees; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return array($entete, $chaine); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -347,20 +347,20 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | function url_to_ascii($url_idn) { |
| 349 | 349 | |
| 350 | - if ($parts = parse_url($url_idn)) { |
|
| 351 | - $host = $parts['host']; |
|
| 352 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 353 | - include_spip('inc/idna_convert.class'); |
|
| 354 | - $IDN = new idna_convert(); |
|
| 355 | - $host_ascii = $IDN->encode($host); |
|
| 356 | - $url_idn = explode($host, $url_idn, 2); |
|
| 357 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 358 | - } |
|
| 359 | - // et on urlencode les char utf si besoin dans le path |
|
| 360 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $url_idn; |
|
| 350 | + if ($parts = parse_url($url_idn)) { |
|
| 351 | + $host = $parts['host']; |
|
| 352 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 353 | + include_spip('inc/idna_convert.class'); |
|
| 354 | + $IDN = new idna_convert(); |
|
| 355 | + $host_ascii = $IDN->encode($host); |
|
| 356 | + $url_idn = explode($host, $url_idn, 2); |
|
| 357 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 358 | + } |
|
| 359 | + // et on urlencode les char utf si besoin dans le path |
|
| 360 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $url_idn; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -401,196 +401,196 @@ discard block |
||
| 401 | 401 | * string file : nom du fichier si enregistre dans un fichier |
| 402 | 402 | */ |
| 403 | 403 | function recuperer_url($url, $options = array()) { |
| 404 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 405 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 406 | - $default = array( |
|
| 407 | - 'transcoder' => false, |
|
| 408 | - 'methode' => 'GET', |
|
| 409 | - 'taille_max' => null, |
|
| 410 | - 'headers' => [], |
|
| 411 | - 'datas' => '', |
|
| 412 | - 'boundary' => '', |
|
| 413 | - 'refuser_gz' => false, |
|
| 414 | - 'if_modified_since' => '', |
|
| 415 | - 'uri_referer' => '', |
|
| 416 | - 'file' => '', |
|
| 417 | - 'follow_location' => 10, |
|
| 418 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 419 | - ); |
|
| 420 | - $options = array_merge($default, $options); |
|
| 421 | - // copier directement dans un fichier ? |
|
| 422 | - $copy = $options['file']; |
|
| 423 | - |
|
| 424 | - if ($options['methode'] == 'HEAD') { |
|
| 425 | - $options['taille_max'] = 0; |
|
| 426 | - } |
|
| 427 | - if (is_null($options['taille_max'])) { |
|
| 428 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - // Ajout des en-têtes spécifiques si besoin |
|
| 433 | - $head_add = ''; |
|
| 434 | - if (!empty($options['headers'])) { |
|
| 435 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 436 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 437 | - } |
|
| 438 | - // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 439 | - unset($options['entetes']); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - if (!empty($options['datas'])) { |
|
| 443 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 444 | - $head .= $head_add; |
|
| 445 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 446 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 447 | - } |
|
| 448 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 449 | - if ( |
|
| 450 | - strlen($postdata) |
|
| 451 | - and !$methode_demandee |
|
| 452 | - ) { |
|
| 453 | - $options['methode'] = 'POST'; |
|
| 454 | - } |
|
| 455 | - } elseif ($head_add) { |
|
| 456 | - $options['datas'] = $head_add . "\r\n"; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 460 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 461 | - if (!tester_url_absolue($url)) { |
|
| 462 | - $url = 'http://' . $url; |
|
| 463 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 464 | - $url = 'http:' . $url; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $url = url_to_ascii($url); |
|
| 468 | - |
|
| 469 | - $result = array( |
|
| 470 | - 'status' => 0, |
|
| 471 | - 'headers' => '', |
|
| 472 | - 'page' => '', |
|
| 473 | - 'length' => 0, |
|
| 474 | - 'last_modified' => '', |
|
| 475 | - 'location' => '', |
|
| 476 | - 'url' => $url |
|
| 477 | - ); |
|
| 478 | - |
|
| 479 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 480 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 481 | - |
|
| 482 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 483 | - list($handle, $fopen) = init_http( |
|
| 484 | - $options['methode'], |
|
| 485 | - $url, |
|
| 486 | - $refuser_gz, |
|
| 487 | - $options['uri_referer'], |
|
| 488 | - $options['datas'], |
|
| 489 | - $options['version_http'], |
|
| 490 | - $options['if_modified_since'] |
|
| 491 | - ); |
|
| 492 | - if (!$handle) { |
|
| 493 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 494 | - |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 499 | - // et recuperer les en-tetes de reponses |
|
| 500 | - if (!$fopen) { |
|
| 501 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 502 | - if (!$res) { |
|
| 503 | - fclose($handle); |
|
| 504 | - $t = @parse_url($url); |
|
| 505 | - $host = $t['host']; |
|
| 506 | - // Chinoisierie inexplicable pour contrer |
|
| 507 | - // les actions liberticides de l'empire du milieu |
|
| 508 | - if (!need_proxy($host) |
|
| 509 | - and $res = @file_get_contents($url) |
|
| 510 | - ) { |
|
| 511 | - $result['length'] = strlen($res); |
|
| 512 | - if ($copy) { |
|
| 513 | - ecrire_fichier($copy, $res); |
|
| 514 | - $result['file'] = $copy; |
|
| 515 | - } else { |
|
| 516 | - $result['page'] = $res; |
|
| 517 | - } |
|
| 518 | - $res = array( |
|
| 519 | - 'status' => 200, |
|
| 520 | - ); |
|
| 521 | - } else { |
|
| 522 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 526 | - $options['follow_location']--; |
|
| 527 | - fclose($handle); |
|
| 528 | - include_spip('inc/filtres'); |
|
| 529 | - $url = suivre_lien($url, $res['location']); |
|
| 530 | - spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 531 | - |
|
| 532 | - return recuperer_url($url, $options); |
|
| 533 | - } elseif ($res['status'] !== 200) { |
|
| 534 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 535 | - } |
|
| 536 | - $result['status'] = $res['status']; |
|
| 537 | - if (isset($res['headers'])) { |
|
| 538 | - $result['headers'] = $res['headers']; |
|
| 539 | - } |
|
| 540 | - if (isset($res['last_modified'])) { |
|
| 541 | - $result['last_modified'] = $res['last_modified']; |
|
| 542 | - } |
|
| 543 | - if (isset($res['location'])) { |
|
| 544 | - $result['location'] = $res['location']; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // on ne veut que les entetes |
|
| 549 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 550 | - return $result; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 555 | - // sinon la memoire explose pour les gros flux |
|
| 556 | - |
|
| 557 | - $gz = false; |
|
| 558 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 559 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 563 | - if (!$result['length']) { |
|
| 564 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 565 | - fclose($handle); |
|
| 566 | - if ($copy) { |
|
| 567 | - $result['length'] = $res; |
|
| 568 | - $result['file'] = $copy; |
|
| 569 | - } elseif ($res) { |
|
| 570 | - $result['page'] = &$res; |
|
| 571 | - $result['length'] = strlen($result['page']); |
|
| 572 | - } |
|
| 573 | - if (!$result['status']) { |
|
| 574 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - if (!$result['page']) { |
|
| 578 | - return $result; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // Decompresser au besoin |
|
| 582 | - if ($gz) { |
|
| 583 | - $result['page'] = implode('', gzfile($gz)); |
|
| 584 | - supprimer_fichier($gz); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // Faut-il l'importer dans notre charset local ? |
|
| 588 | - if ($options['transcoder']) { |
|
| 589 | - include_spip('inc/charsets'); |
|
| 590 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return $result; |
|
| 404 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 405 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 406 | + $default = array( |
|
| 407 | + 'transcoder' => false, |
|
| 408 | + 'methode' => 'GET', |
|
| 409 | + 'taille_max' => null, |
|
| 410 | + 'headers' => [], |
|
| 411 | + 'datas' => '', |
|
| 412 | + 'boundary' => '', |
|
| 413 | + 'refuser_gz' => false, |
|
| 414 | + 'if_modified_since' => '', |
|
| 415 | + 'uri_referer' => '', |
|
| 416 | + 'file' => '', |
|
| 417 | + 'follow_location' => 10, |
|
| 418 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 419 | + ); |
|
| 420 | + $options = array_merge($default, $options); |
|
| 421 | + // copier directement dans un fichier ? |
|
| 422 | + $copy = $options['file']; |
|
| 423 | + |
|
| 424 | + if ($options['methode'] == 'HEAD') { |
|
| 425 | + $options['taille_max'] = 0; |
|
| 426 | + } |
|
| 427 | + if (is_null($options['taille_max'])) { |
|
| 428 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + // Ajout des en-têtes spécifiques si besoin |
|
| 433 | + $head_add = ''; |
|
| 434 | + if (!empty($options['headers'])) { |
|
| 435 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 436 | + $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 437 | + } |
|
| 438 | + // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 439 | + unset($options['entetes']); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + if (!empty($options['datas'])) { |
|
| 443 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 444 | + $head .= $head_add; |
|
| 445 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 446 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 447 | + } |
|
| 448 | + $options['datas'] = $head . "\r\n" . $postdata; |
|
| 449 | + if ( |
|
| 450 | + strlen($postdata) |
|
| 451 | + and !$methode_demandee |
|
| 452 | + ) { |
|
| 453 | + $options['methode'] = 'POST'; |
|
| 454 | + } |
|
| 455 | + } elseif ($head_add) { |
|
| 456 | + $options['datas'] = $head_add . "\r\n"; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 460 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 461 | + if (!tester_url_absolue($url)) { |
|
| 462 | + $url = 'http://' . $url; |
|
| 463 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 464 | + $url = 'http:' . $url; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $url = url_to_ascii($url); |
|
| 468 | + |
|
| 469 | + $result = array( |
|
| 470 | + 'status' => 0, |
|
| 471 | + 'headers' => '', |
|
| 472 | + 'page' => '', |
|
| 473 | + 'length' => 0, |
|
| 474 | + 'last_modified' => '', |
|
| 475 | + 'location' => '', |
|
| 476 | + 'url' => $url |
|
| 477 | + ); |
|
| 478 | + |
|
| 479 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 480 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 481 | + |
|
| 482 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 483 | + list($handle, $fopen) = init_http( |
|
| 484 | + $options['methode'], |
|
| 485 | + $url, |
|
| 486 | + $refuser_gz, |
|
| 487 | + $options['uri_referer'], |
|
| 488 | + $options['datas'], |
|
| 489 | + $options['version_http'], |
|
| 490 | + $options['if_modified_since'] |
|
| 491 | + ); |
|
| 492 | + if (!$handle) { |
|
| 493 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 494 | + |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 499 | + // et recuperer les en-tetes de reponses |
|
| 500 | + if (!$fopen) { |
|
| 501 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 502 | + if (!$res) { |
|
| 503 | + fclose($handle); |
|
| 504 | + $t = @parse_url($url); |
|
| 505 | + $host = $t['host']; |
|
| 506 | + // Chinoisierie inexplicable pour contrer |
|
| 507 | + // les actions liberticides de l'empire du milieu |
|
| 508 | + if (!need_proxy($host) |
|
| 509 | + and $res = @file_get_contents($url) |
|
| 510 | + ) { |
|
| 511 | + $result['length'] = strlen($res); |
|
| 512 | + if ($copy) { |
|
| 513 | + ecrire_fichier($copy, $res); |
|
| 514 | + $result['file'] = $copy; |
|
| 515 | + } else { |
|
| 516 | + $result['page'] = $res; |
|
| 517 | + } |
|
| 518 | + $res = array( |
|
| 519 | + 'status' => 200, |
|
| 520 | + ); |
|
| 521 | + } else { |
|
| 522 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 526 | + $options['follow_location']--; |
|
| 527 | + fclose($handle); |
|
| 528 | + include_spip('inc/filtres'); |
|
| 529 | + $url = suivre_lien($url, $res['location']); |
|
| 530 | + spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 531 | + |
|
| 532 | + return recuperer_url($url, $options); |
|
| 533 | + } elseif ($res['status'] !== 200) { |
|
| 534 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 535 | + } |
|
| 536 | + $result['status'] = $res['status']; |
|
| 537 | + if (isset($res['headers'])) { |
|
| 538 | + $result['headers'] = $res['headers']; |
|
| 539 | + } |
|
| 540 | + if (isset($res['last_modified'])) { |
|
| 541 | + $result['last_modified'] = $res['last_modified']; |
|
| 542 | + } |
|
| 543 | + if (isset($res['location'])) { |
|
| 544 | + $result['location'] = $res['location']; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // on ne veut que les entetes |
|
| 549 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 550 | + return $result; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 555 | + // sinon la memoire explose pour les gros flux |
|
| 556 | + |
|
| 557 | + $gz = false; |
|
| 558 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 559 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 563 | + if (!$result['length']) { |
|
| 564 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 565 | + fclose($handle); |
|
| 566 | + if ($copy) { |
|
| 567 | + $result['length'] = $res; |
|
| 568 | + $result['file'] = $copy; |
|
| 569 | + } elseif ($res) { |
|
| 570 | + $result['page'] = &$res; |
|
| 571 | + $result['length'] = strlen($result['page']); |
|
| 572 | + } |
|
| 573 | + if (!$result['status']) { |
|
| 574 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + if (!$result['page']) { |
|
| 578 | + return $result; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + // Decompresser au besoin |
|
| 582 | + if ($gz) { |
|
| 583 | + $result['page'] = implode('', gzfile($gz)); |
|
| 584 | + supprimer_fichier($gz); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // Faut-il l'importer dans notre charset local ? |
|
| 588 | + if ($options['transcoder']) { |
|
| 589 | + include_spip('inc/charsets'); |
|
| 590 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return $result; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -606,72 +606,72 @@ discard block |
||
| 606 | 606 | * @return array|bool|mixed |
| 607 | 607 | */ |
| 608 | 608 | function recuperer_url_cache($url, $options = array()) { |
| 609 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 610 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 611 | - } |
|
| 612 | - $default = array( |
|
| 613 | - 'transcoder' => false, |
|
| 614 | - 'methode' => 'GET', |
|
| 615 | - 'taille_max' => null, |
|
| 616 | - 'datas' => '', |
|
| 617 | - 'boundary' => '', |
|
| 618 | - 'refuser_gz' => false, |
|
| 619 | - 'if_modified_since' => '', |
|
| 620 | - 'uri_referer' => '', |
|
| 621 | - 'file' => '', |
|
| 622 | - 'follow_location' => 10, |
|
| 623 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 624 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 625 | - ); |
|
| 626 | - $options = array_merge($default, $options); |
|
| 627 | - |
|
| 628 | - // cas ou il n'est pas possible de cacher |
|
| 629 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 630 | - return recuperer_url($url, $options); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 634 | - static $errors = array(); |
|
| 635 | - if (isset($errors[$url])) { |
|
| 636 | - return $errors[$url]; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $sig = $options; |
|
| 640 | - unset($sig['if_modified_since']); |
|
| 641 | - unset($sig['delai_cache']); |
|
| 642 | - $sig['url'] = $url; |
|
| 643 | - |
|
| 644 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 645 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 646 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 647 | - $cache = "$sub$cache"; |
|
| 648 | - |
|
| 649 | - $res = false; |
|
| 650 | - $is_cached = file_exists($cache); |
|
| 651 | - if ($is_cached |
|
| 652 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 653 | - ) { |
|
| 654 | - lire_fichier($cache, $res); |
|
| 655 | - if ($res = unserialize($res)) { |
|
| 656 | - // mettre le last_modified et le status=304 ? |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - if (!$res) { |
|
| 660 | - $res = recuperer_url($url, $options); |
|
| 661 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 662 | - if (!$res) { |
|
| 663 | - if ($is_cached) { |
|
| 664 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 665 | - lire_fichier($cache, $res); |
|
| 666 | - $res = unserialize($res); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - return $errors[$url] = $res; |
|
| 670 | - } |
|
| 671 | - ecrire_fichier($cache, serialize($res)); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return $res; |
|
| 609 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 610 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 611 | + } |
|
| 612 | + $default = array( |
|
| 613 | + 'transcoder' => false, |
|
| 614 | + 'methode' => 'GET', |
|
| 615 | + 'taille_max' => null, |
|
| 616 | + 'datas' => '', |
|
| 617 | + 'boundary' => '', |
|
| 618 | + 'refuser_gz' => false, |
|
| 619 | + 'if_modified_since' => '', |
|
| 620 | + 'uri_referer' => '', |
|
| 621 | + 'file' => '', |
|
| 622 | + 'follow_location' => 10, |
|
| 623 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 624 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 625 | + ); |
|
| 626 | + $options = array_merge($default, $options); |
|
| 627 | + |
|
| 628 | + // cas ou il n'est pas possible de cacher |
|
| 629 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 630 | + return recuperer_url($url, $options); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 634 | + static $errors = array(); |
|
| 635 | + if (isset($errors[$url])) { |
|
| 636 | + return $errors[$url]; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $sig = $options; |
|
| 640 | + unset($sig['if_modified_since']); |
|
| 641 | + unset($sig['delai_cache']); |
|
| 642 | + $sig['url'] = $url; |
|
| 643 | + |
|
| 644 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 645 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 646 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 647 | + $cache = "$sub$cache"; |
|
| 648 | + |
|
| 649 | + $res = false; |
|
| 650 | + $is_cached = file_exists($cache); |
|
| 651 | + if ($is_cached |
|
| 652 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 653 | + ) { |
|
| 654 | + lire_fichier($cache, $res); |
|
| 655 | + if ($res = unserialize($res)) { |
|
| 656 | + // mettre le last_modified et le status=304 ? |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + if (!$res) { |
|
| 660 | + $res = recuperer_url($url, $options); |
|
| 661 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 662 | + if (!$res) { |
|
| 663 | + if ($is_cached) { |
|
| 664 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 665 | + lire_fichier($cache, $res); |
|
| 666 | + $res = unserialize($res); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + return $errors[$url] = $res; |
|
| 670 | + } |
|
| 671 | + ecrire_fichier($cache, serialize($res)); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return $res; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -689,41 +689,41 @@ discard block |
||
| 689 | 689 | * string contenu de la resource |
| 690 | 690 | */ |
| 691 | 691 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 692 | - $taille = 0; |
|
| 693 | - $result = ''; |
|
| 694 | - $fp = false; |
|
| 695 | - if ($fichier) { |
|
| 696 | - include_spip('inc/acces'); |
|
| 697 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 698 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 699 | - if (!$fp and file_exists($fichier)) { |
|
| 700 | - return filesize($fichier); |
|
| 701 | - } |
|
| 702 | - if (!$fp) { |
|
| 703 | - return false; |
|
| 704 | - } |
|
| 705 | - $result = 0; // on renvoie la taille du fichier |
|
| 706 | - } |
|
| 707 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 708 | - $res = fread($handle, 16384); |
|
| 709 | - $taille += strlen($res); |
|
| 710 | - if ($fp) { |
|
| 711 | - fwrite($fp, $res); |
|
| 712 | - $result = $taille; |
|
| 713 | - } else { |
|
| 714 | - $result .= $res; |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - if ($fp) { |
|
| 718 | - spip_fclose_unlock($fp); |
|
| 719 | - spip_unlink($fichier); |
|
| 720 | - @rename($tmpfile, $fichier); |
|
| 721 | - if (!file_exists($fichier)) { |
|
| 722 | - return false; |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - return $result; |
|
| 692 | + $taille = 0; |
|
| 693 | + $result = ''; |
|
| 694 | + $fp = false; |
|
| 695 | + if ($fichier) { |
|
| 696 | + include_spip('inc/acces'); |
|
| 697 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 698 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 699 | + if (!$fp and file_exists($fichier)) { |
|
| 700 | + return filesize($fichier); |
|
| 701 | + } |
|
| 702 | + if (!$fp) { |
|
| 703 | + return false; |
|
| 704 | + } |
|
| 705 | + $result = 0; // on renvoie la taille du fichier |
|
| 706 | + } |
|
| 707 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 708 | + $res = fread($handle, 16384); |
|
| 709 | + $taille += strlen($res); |
|
| 710 | + if ($fp) { |
|
| 711 | + fwrite($fp, $res); |
|
| 712 | + $result = $taille; |
|
| 713 | + } else { |
|
| 714 | + $result .= $res; |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + if ($fp) { |
|
| 718 | + spip_fclose_unlock($fp); |
|
| 719 | + spip_unlink($fichier); |
|
| 720 | + @rename($tmpfile, $fichier); |
|
| 721 | + if (!file_exists($fichier)) { |
|
| 722 | + return false; |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + return $result; |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** |
@@ -745,34 +745,34 @@ discard block |
||
| 745 | 745 | * string location |
| 746 | 746 | */ |
| 747 | 747 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 748 | - $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 749 | - |
|
| 750 | - $s = @trim(fgets($handle, 16384)); |
|
| 751 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 754 | - $result['status'] = intval($r[1]); |
|
| 755 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 756 | - $result['headers'][] = $s . "\n"; |
|
| 757 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 758 | - list(, $d, $v) = $r; |
|
| 759 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 760 | - $result['location'] = $v; |
|
| 761 | - } elseif ($d == 'Last-Modified') { |
|
| 762 | - $result['last_modified'] = strtotime($v); |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - if ($if_modified_since |
|
| 766 | - and $result['last_modified'] |
|
| 767 | - and $if_modified_since > $result['last_modified'] |
|
| 768 | - and $result['status'] == 200 |
|
| 769 | - ) { |
|
| 770 | - $result['status'] = 304; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - $result['headers'] = implode('', $result['headers']); |
|
| 774 | - |
|
| 775 | - return $result; |
|
| 748 | + $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 749 | + |
|
| 750 | + $s = @trim(fgets($handle, 16384)); |
|
| 751 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | + $result['status'] = intval($r[1]); |
|
| 755 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 756 | + $result['headers'][] = $s . "\n"; |
|
| 757 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 758 | + list(, $d, $v) = $r; |
|
| 759 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 760 | + $result['location'] = $v; |
|
| 761 | + } elseif ($d == 'Last-Modified') { |
|
| 762 | + $result['last_modified'] = strtotime($v); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + if ($if_modified_since |
|
| 766 | + and $result['last_modified'] |
|
| 767 | + and $if_modified_since > $result['last_modified'] |
|
| 768 | + and $result['status'] == 200 |
|
| 769 | + ) { |
|
| 770 | + $result['status'] = 304; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + $result['headers'] = implode('', $result['headers']); |
|
| 774 | + |
|
| 775 | + return $result; |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | /** |
@@ -794,22 +794,22 @@ discard block |
||
| 794 | 794 | * Nom du fichier pour copie locale |
| 795 | 795 | **/ |
| 796 | 796 | function nom_fichier_copie_locale($source, $extension) { |
| 797 | - include_spip('inc/documents'); |
|
| 797 | + include_spip('inc/documents'); |
|
| 798 | 798 | |
| 799 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 800 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 799 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 800 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 801 | 801 | |
| 802 | - // on se place tout le temps comme si on etait a la racine |
|
| 803 | - if (_DIR_RACINE) { |
|
| 804 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 805 | - } |
|
| 802 | + // on se place tout le temps comme si on etait a la racine |
|
| 803 | + if (_DIR_RACINE) { |
|
| 804 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 805 | + } |
|
| 806 | 806 | |
| 807 | - $m = md5($source); |
|
| 807 | + $m = md5($source); |
|
| 808 | 808 | |
| 809 | - return $d |
|
| 810 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 811 | - . substr($m, 0, 4) |
|
| 812 | - . ".$extension"; |
|
| 809 | + return $d |
|
| 810 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 811 | + . substr($m, 0, 4) |
|
| 812 | + . ".$extension"; |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
@@ -827,68 +827,68 @@ discard block |
||
| 827 | 827 | * Nom du fichier calculé |
| 828 | 828 | **/ |
| 829 | 829 | function fichier_copie_locale($source) { |
| 830 | - // Si c'est deja local pas de souci |
|
| 831 | - if (!tester_url_absolue($source)) { |
|
| 832 | - if (_DIR_RACINE) { |
|
| 833 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - return $source; |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 840 | - // a deja ete copie en local avec cette extension |
|
| 841 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 842 | - $path_parts = pathinfo($source); |
|
| 843 | - if (!isset($path_parts['extension'])) { |
|
| 844 | - $path_parts['extension'] = ''; |
|
| 845 | - } |
|
| 846 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 847 | - if ($ext |
|
| 848 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 849 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 850 | - and file_exists(_DIR_RACINE . $f) |
|
| 851 | - ) { |
|
| 852 | - return $f; |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - // Si c'est deja dans la table des documents, |
|
| 857 | - // ramener le nom de sa copie potentielle |
|
| 858 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 859 | - |
|
| 860 | - if ($ext) { |
|
| 861 | - return nom_fichier_copie_locale($source, $ext); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 865 | - // et si il n'aurait pas deja ete rapatrie |
|
| 866 | - |
|
| 867 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 868 | - |
|
| 869 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 870 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 871 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 872 | - return $f; |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - // Ping pour voir si son extension est connue et autorisee |
|
| 877 | - // avec mise en cache du resultat du ping |
|
| 878 | - |
|
| 879 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 880 | - if (!@file_exists($cache) |
|
| 881 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 882 | - or _request('var_mode') == 'recalcul' |
|
| 883 | - ) { |
|
| 884 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 885 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 886 | - } |
|
| 887 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 888 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 889 | - return nom_fichier_copie_locale($source, $ext); |
|
| 890 | - } |
|
| 891 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 830 | + // Si c'est deja local pas de souci |
|
| 831 | + if (!tester_url_absolue($source)) { |
|
| 832 | + if (_DIR_RACINE) { |
|
| 833 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + return $source; |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 840 | + // a deja ete copie en local avec cette extension |
|
| 841 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 842 | + $path_parts = pathinfo($source); |
|
| 843 | + if (!isset($path_parts['extension'])) { |
|
| 844 | + $path_parts['extension'] = ''; |
|
| 845 | + } |
|
| 846 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 847 | + if ($ext |
|
| 848 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 849 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 850 | + and file_exists(_DIR_RACINE . $f) |
|
| 851 | + ) { |
|
| 852 | + return $f; |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + // Si c'est deja dans la table des documents, |
|
| 857 | + // ramener le nom de sa copie potentielle |
|
| 858 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 859 | + |
|
| 860 | + if ($ext) { |
|
| 861 | + return nom_fichier_copie_locale($source, $ext); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 865 | + // et si il n'aurait pas deja ete rapatrie |
|
| 866 | + |
|
| 867 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 868 | + |
|
| 869 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 870 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 871 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 872 | + return $f; |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + // Ping pour voir si son extension est connue et autorisee |
|
| 877 | + // avec mise en cache du resultat du ping |
|
| 878 | + |
|
| 879 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 880 | + if (!@file_exists($cache) |
|
| 881 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 882 | + or _request('var_mode') == 'recalcul' |
|
| 883 | + ) { |
|
| 884 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 885 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 886 | + } |
|
| 887 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 888 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 889 | + return nom_fichier_copie_locale($source, $ext); |
|
| 890 | + } |
|
| 891 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | |
@@ -916,146 +916,146 @@ discard block |
||
| 916 | 916 | **/ |
| 917 | 917 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 918 | 918 | |
| 919 | - // pas la peine de perdre son temps |
|
| 920 | - if (!tester_url_absolue($source)) { |
|
| 921 | - return false; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - # charger les alias des types mime |
|
| 925 | - include_spip('base/typedoc'); |
|
| 926 | - |
|
| 927 | - $a = array(); |
|
| 928 | - $mime_type = ''; |
|
| 929 | - // On va directement charger le debut des images et des fichiers html, |
|
| 930 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 931 | - // ca echoue l'utilisateur devra les entrer... |
|
| 932 | - $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 933 | - $headers = $reponse['headers'] ?? ''; |
|
| 934 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 935 | - if ($headers) { |
|
| 936 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 937 | - $mime_type = (trim($regs[1])); |
|
| 938 | - } else { |
|
| 939 | - $mime_type = ''; |
|
| 940 | - } // inconnu |
|
| 941 | - |
|
| 942 | - // Appliquer les alias |
|
| 943 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 944 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - // Si on a un mime-type insignifiant |
|
| 948 | - // text/plain,application/octet-stream ou vide |
|
| 949 | - // c'est peut-etre que le serveur ne sait pas |
|
| 950 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 951 | - // ou le Content-Disposition: attachment; filename=... |
|
| 952 | - $t = null; |
|
| 953 | - if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 954 | - if (!$t |
|
| 955 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 956 | - ) { |
|
| 957 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 958 | - } |
|
| 959 | - if (!$t |
|
| 960 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 961 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 962 | - ) { |
|
| 963 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 968 | - if (!$t) { |
|
| 969 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 973 | - // On essaie de nouveau avec l'extension |
|
| 974 | - if (!$t |
|
| 975 | - and $mime_type != 'text/plain' |
|
| 976 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 977 | - ) { |
|
| 978 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 979 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - if ($t) { |
|
| 983 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 984 | - $a['extension'] = $t['extension']; |
|
| 985 | - } else { |
|
| 986 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 987 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 988 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 989 | - if (!$t) { |
|
| 990 | - return false; |
|
| 991 | - } |
|
| 992 | - $a['extension'] = $t['extension']; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 996 | - $a['taille'] = intval($regs[1]); |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - // Echec avec HEAD, on tente avec GET |
|
| 1001 | - if (!$a and !$max) { |
|
| 1002 | - spip_log("tenter GET $source", 'distant'); |
|
| 1003 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - // si on a rien trouve pas la peine d'insister |
|
| 1007 | - if (!$a) { |
|
| 1008 | - return false; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1012 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1013 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1014 | - if (strpos($mime_type, "image/") === 0 |
|
| 1015 | - and $extension = _image_trouver_extension_depuis_mime($mime_type)) { |
|
| 1016 | - if ($max == 0 |
|
| 1017 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1018 | - and in_array($extension, formats_image_acceptables()) |
|
| 1019 | - and $charger_si_petite_image |
|
| 1020 | - ) { |
|
| 1021 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1022 | - } else { |
|
| 1023 | - if ($a['body']) { |
|
| 1024 | - $a['extension'] = $extension; |
|
| 1025 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1026 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1027 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1028 | - $a['largeur'] = intval($size_image[0]); |
|
| 1029 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1030 | - $a['type_image'] = true; |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1036 | - // ce sera mieux que 0x0 |
|
| 1037 | - // Flash is dead! |
|
| 1038 | - if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1039 | - and empty($a['largeur']) |
|
| 1040 | - ) { |
|
| 1041 | - $a['largeur'] = 425; |
|
| 1042 | - $a['hauteur'] = 350; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - if ($mime_type == 'text/html') { |
|
| 1046 | - include_spip('inc/filtres'); |
|
| 1047 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1048 | - $page = $page['page'] ?? ''; |
|
| 1049 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1050 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1051 | - } |
|
| 1052 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1053 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1054 | - } |
|
| 1055 | - } |
|
| 1056 | - $a['mime_type'] = $mime_type; |
|
| 1057 | - |
|
| 1058 | - return $a; |
|
| 919 | + // pas la peine de perdre son temps |
|
| 920 | + if (!tester_url_absolue($source)) { |
|
| 921 | + return false; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + # charger les alias des types mime |
|
| 925 | + include_spip('base/typedoc'); |
|
| 926 | + |
|
| 927 | + $a = array(); |
|
| 928 | + $mime_type = ''; |
|
| 929 | + // On va directement charger le debut des images et des fichiers html, |
|
| 930 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 931 | + // ca echoue l'utilisateur devra les entrer... |
|
| 932 | + $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 933 | + $headers = $reponse['headers'] ?? ''; |
|
| 934 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 935 | + if ($headers) { |
|
| 936 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 937 | + $mime_type = (trim($regs[1])); |
|
| 938 | + } else { |
|
| 939 | + $mime_type = ''; |
|
| 940 | + } // inconnu |
|
| 941 | + |
|
| 942 | + // Appliquer les alias |
|
| 943 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 944 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + // Si on a un mime-type insignifiant |
|
| 948 | + // text/plain,application/octet-stream ou vide |
|
| 949 | + // c'est peut-etre que le serveur ne sait pas |
|
| 950 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 951 | + // ou le Content-Disposition: attachment; filename=... |
|
| 952 | + $t = null; |
|
| 953 | + if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 954 | + if (!$t |
|
| 955 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 956 | + ) { |
|
| 957 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 958 | + } |
|
| 959 | + if (!$t |
|
| 960 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 961 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 962 | + ) { |
|
| 963 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 968 | + if (!$t) { |
|
| 969 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 973 | + // On essaie de nouveau avec l'extension |
|
| 974 | + if (!$t |
|
| 975 | + and $mime_type != 'text/plain' |
|
| 976 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 977 | + ) { |
|
| 978 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 979 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + if ($t) { |
|
| 983 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 984 | + $a['extension'] = $t['extension']; |
|
| 985 | + } else { |
|
| 986 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 987 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 988 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 989 | + if (!$t) { |
|
| 990 | + return false; |
|
| 991 | + } |
|
| 992 | + $a['extension'] = $t['extension']; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 996 | + $a['taille'] = intval($regs[1]); |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + // Echec avec HEAD, on tente avec GET |
|
| 1001 | + if (!$a and !$max) { |
|
| 1002 | + spip_log("tenter GET $source", 'distant'); |
|
| 1003 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + // si on a rien trouve pas la peine d'insister |
|
| 1007 | + if (!$a) { |
|
| 1008 | + return false; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1012 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1013 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1014 | + if (strpos($mime_type, "image/") === 0 |
|
| 1015 | + and $extension = _image_trouver_extension_depuis_mime($mime_type)) { |
|
| 1016 | + if ($max == 0 |
|
| 1017 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1018 | + and in_array($extension, formats_image_acceptables()) |
|
| 1019 | + and $charger_si_petite_image |
|
| 1020 | + ) { |
|
| 1021 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1022 | + } else { |
|
| 1023 | + if ($a['body']) { |
|
| 1024 | + $a['extension'] = $extension; |
|
| 1025 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1026 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1027 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1028 | + $a['largeur'] = intval($size_image[0]); |
|
| 1029 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1030 | + $a['type_image'] = true; |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1036 | + // ce sera mieux que 0x0 |
|
| 1037 | + // Flash is dead! |
|
| 1038 | + if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1039 | + and empty($a['largeur']) |
|
| 1040 | + ) { |
|
| 1041 | + $a['largeur'] = 425; |
|
| 1042 | + $a['hauteur'] = 350; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + if ($mime_type == 'text/html') { |
|
| 1046 | + include_spip('inc/filtres'); |
|
| 1047 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1048 | + $page = $page['page'] ?? ''; |
|
| 1049 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1050 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1051 | + } |
|
| 1052 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1053 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1054 | + } |
|
| 1055 | + } |
|
| 1056 | + $a['mime_type'] = $mime_type; |
|
| 1057 | + |
|
| 1058 | + return $a; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | |
@@ -1071,45 +1071,45 @@ discard block |
||
| 1071 | 1071 | * @return string |
| 1072 | 1072 | */ |
| 1073 | 1073 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1074 | - if (is_null($http_proxy)) { |
|
| 1075 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1076 | - } |
|
| 1077 | - // rien a faire si pas de proxy :) |
|
| 1078 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1079 | - return ''; |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - if (is_null($http_noproxy)) { |
|
| 1083 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1084 | - } |
|
| 1085 | - // si pas d'exception, on retourne le proxy |
|
| 1086 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1087 | - return $http_proxy; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1091 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1092 | - $http_noproxy = str_replace("\n", " ", $http_noproxy); |
|
| 1093 | - $http_noproxy = str_replace("\r", " ", $http_noproxy); |
|
| 1094 | - $http_noproxy = " $http_noproxy "; |
|
| 1095 | - $domain = $host; |
|
| 1096 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1097 | - if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1098 | - return ''; |
|
| 1099 | - |
|
| 1100 | - while (strpos($domain, '.') !== false) { |
|
| 1101 | - $domain = explode('.', $domain); |
|
| 1102 | - array_shift($domain); |
|
| 1103 | - $domain = implode('.', $domain); |
|
| 1104 | - |
|
| 1105 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1106 | - if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1107 | - return ''; |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - // ok c'est pas une exception |
|
| 1112 | - return $http_proxy; |
|
| 1074 | + if (is_null($http_proxy)) { |
|
| 1075 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1076 | + } |
|
| 1077 | + // rien a faire si pas de proxy :) |
|
| 1078 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1079 | + return ''; |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + if (is_null($http_noproxy)) { |
|
| 1083 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1084 | + } |
|
| 1085 | + // si pas d'exception, on retourne le proxy |
|
| 1086 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1087 | + return $http_proxy; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1091 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1092 | + $http_noproxy = str_replace("\n", " ", $http_noproxy); |
|
| 1093 | + $http_noproxy = str_replace("\r", " ", $http_noproxy); |
|
| 1094 | + $http_noproxy = " $http_noproxy "; |
|
| 1095 | + $domain = $host; |
|
| 1096 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1097 | + if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1098 | + return ''; |
|
| 1099 | + |
|
| 1100 | + while (strpos($domain, '.') !== false) { |
|
| 1101 | + $domain = explode('.', $domain); |
|
| 1102 | + array_shift($domain); |
|
| 1103 | + $domain = implode('.', $domain); |
|
| 1104 | + |
|
| 1105 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1106 | + if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1107 | + return ''; |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + // ok c'est pas une exception |
|
| 1112 | + return $http_proxy; |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | |
@@ -1132,58 +1132,58 @@ discard block |
||
| 1132 | 1132 | * @return array |
| 1133 | 1133 | */ |
| 1134 | 1134 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1135 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1136 | - $fopen = false; |
|
| 1137 | - |
|
| 1138 | - $t = @parse_url($url); |
|
| 1139 | - $host = $t['host']; |
|
| 1140 | - if ($t['scheme'] == 'http') { |
|
| 1141 | - $scheme = 'http'; |
|
| 1142 | - $noproxy = ''; |
|
| 1143 | - } elseif ($t['scheme'] == 'https') { |
|
| 1144 | - $scheme = 'ssl'; |
|
| 1145 | - $noproxy = 'ssl://'; |
|
| 1146 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1147 | - $t['port'] = 443; |
|
| 1148 | - } |
|
| 1149 | - } else { |
|
| 1150 | - $scheme = $t['scheme']; |
|
| 1151 | - $noproxy = $scheme . '://'; |
|
| 1152 | - } |
|
| 1153 | - if (isset($t['user'])) { |
|
| 1154 | - $user = array($t['user'], $t['pass']); |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1158 | - $port = 80; |
|
| 1159 | - } |
|
| 1160 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1161 | - $path = '/'; |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - if (!empty($t['query'])) { |
|
| 1165 | - $path .= '?' . $t['query']; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1169 | - if (!$f or !is_resource($f)) { |
|
| 1170 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1171 | - // ce qui correspond a $f===110 |
|
| 1172 | - if ($f !== 110 |
|
| 1173 | - and !need_proxy($host) |
|
| 1174 | - and !_request('tester_proxy') |
|
| 1175 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1176 | - ) { |
|
| 1177 | - $f = @fopen($url, 'rb'); |
|
| 1178 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1179 | - $fopen = true; |
|
| 1180 | - } else { |
|
| 1181 | - // echec total |
|
| 1182 | - $f = false; |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - return array($f, $fopen); |
|
| 1135 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1136 | + $fopen = false; |
|
| 1137 | + |
|
| 1138 | + $t = @parse_url($url); |
|
| 1139 | + $host = $t['host']; |
|
| 1140 | + if ($t['scheme'] == 'http') { |
|
| 1141 | + $scheme = 'http'; |
|
| 1142 | + $noproxy = ''; |
|
| 1143 | + } elseif ($t['scheme'] == 'https') { |
|
| 1144 | + $scheme = 'ssl'; |
|
| 1145 | + $noproxy = 'ssl://'; |
|
| 1146 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1147 | + $t['port'] = 443; |
|
| 1148 | + } |
|
| 1149 | + } else { |
|
| 1150 | + $scheme = $t['scheme']; |
|
| 1151 | + $noproxy = $scheme . '://'; |
|
| 1152 | + } |
|
| 1153 | + if (isset($t['user'])) { |
|
| 1154 | + $user = array($t['user'], $t['pass']); |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1158 | + $port = 80; |
|
| 1159 | + } |
|
| 1160 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1161 | + $path = '/'; |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + if (!empty($t['query'])) { |
|
| 1165 | + $path .= '?' . $t['query']; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1169 | + if (!$f or !is_resource($f)) { |
|
| 1170 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1171 | + // ce qui correspond a $f===110 |
|
| 1172 | + if ($f !== 110 |
|
| 1173 | + and !need_proxy($host) |
|
| 1174 | + and !_request('tester_proxy') |
|
| 1175 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1176 | + ) { |
|
| 1177 | + $f = @fopen($url, 'rb'); |
|
| 1178 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1179 | + $fopen = true; |
|
| 1180 | + } else { |
|
| 1181 | + // echec total |
|
| 1182 | + $f = false; |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + return array($f, $fopen); |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1218,124 +1218,124 @@ discard block |
||
| 1218 | 1218 | * resource socket vers l'url demandee |
| 1219 | 1219 | */ |
| 1220 | 1220 | function lance_requete( |
| 1221 | - $method, |
|
| 1222 | - $scheme, |
|
| 1223 | - $user, |
|
| 1224 | - $host, |
|
| 1225 | - $path, |
|
| 1226 | - $port, |
|
| 1227 | - $noproxy, |
|
| 1228 | - $refuse_gz = false, |
|
| 1229 | - $referer = '', |
|
| 1230 | - $datas = '', |
|
| 1231 | - $vers = 'HTTP/1.0', |
|
| 1232 | - $date = '' |
|
| 1221 | + $method, |
|
| 1222 | + $scheme, |
|
| 1223 | + $user, |
|
| 1224 | + $host, |
|
| 1225 | + $path, |
|
| 1226 | + $port, |
|
| 1227 | + $noproxy, |
|
| 1228 | + $refuse_gz = false, |
|
| 1229 | + $referer = '', |
|
| 1230 | + $datas = '', |
|
| 1231 | + $vers = 'HTTP/1.0', |
|
| 1232 | + $date = '' |
|
| 1233 | 1233 | ) { |
| 1234 | 1234 | |
| 1235 | - $proxy_user = ''; |
|
| 1236 | - $http_proxy = need_proxy($host); |
|
| 1237 | - if ($user) { |
|
| 1238 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - $connect = ''; |
|
| 1242 | - if ($http_proxy) { |
|
| 1243 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1244 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1245 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1246 | - . "Host: $path_host\r\n" |
|
| 1247 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1248 | - } else { |
|
| 1249 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1250 | - . (!$user ? '' : "$user@") |
|
| 1251 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1252 | - } |
|
| 1253 | - $t2 = @parse_url($http_proxy); |
|
| 1254 | - $first_host = $t2['host']; |
|
| 1255 | - if (!($port = $t2['port'])) { |
|
| 1256 | - $port = 80; |
|
| 1257 | - } |
|
| 1258 | - if ($t2['user']) { |
|
| 1259 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1260 | - } |
|
| 1261 | - } else { |
|
| 1262 | - $first_host = $noproxy . $host; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - if ($connect) { |
|
| 1266 | - $streamContext = stream_context_create(array( |
|
| 1267 | - 'ssl' => array( |
|
| 1268 | - 'verify_peer' => false, |
|
| 1269 | - 'allow_self_signed' => true, |
|
| 1270 | - 'SNI_enabled' => true, |
|
| 1271 | - 'peer_name' => $host, |
|
| 1272 | - ) |
|
| 1273 | - )); |
|
| 1274 | - $f = @stream_socket_client( |
|
| 1275 | - "tcp://$first_host:$port", |
|
| 1276 | - $errno, |
|
| 1277 | - $errstr, |
|
| 1278 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1279 | - STREAM_CLIENT_CONNECT, |
|
| 1280 | - $streamContext |
|
| 1281 | - ); |
|
| 1282 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1283 | - if (!$f) { |
|
| 1284 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1285 | - return $errno; |
|
| 1286 | - } |
|
| 1287 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1288 | - |
|
| 1289 | - fputs($f, $connect); |
|
| 1290 | - fputs($f, "\r\n"); |
|
| 1291 | - $res = fread($f, 1024); |
|
| 1292 | - if (!$res |
|
| 1293 | - or !count($res = explode(' ', $res)) |
|
| 1294 | - or $res[1] !== '200' |
|
| 1295 | - ) { |
|
| 1296 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1297 | - fclose($f); |
|
| 1298 | - |
|
| 1299 | - return false; |
|
| 1300 | - } |
|
| 1301 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1302 | - stream_set_blocking($f, true); |
|
| 1303 | - // envoyer le handshake |
|
| 1304 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1305 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1306 | - } else { |
|
| 1307 | - $ntry = 3; |
|
| 1308 | - do { |
|
| 1309 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1310 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1311 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1312 | - if (!$f) { |
|
| 1313 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1314 | - |
|
| 1315 | - return $errno; |
|
| 1316 | - } |
|
| 1317 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1321 | - |
|
| 1322 | - $host_port = $host; |
|
| 1323 | - if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) { |
|
| 1324 | - $host_port .= ":$port"; |
|
| 1325 | - } |
|
| 1326 | - $req = "$method $path $vers\r\n" |
|
| 1327 | - . "Host: $host_port\r\n" |
|
| 1328 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1329 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1330 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1331 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1332 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1333 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1334 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1235 | + $proxy_user = ''; |
|
| 1236 | + $http_proxy = need_proxy($host); |
|
| 1237 | + if ($user) { |
|
| 1238 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + $connect = ''; |
|
| 1242 | + if ($http_proxy) { |
|
| 1243 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1244 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1245 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1246 | + . "Host: $path_host\r\n" |
|
| 1247 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1248 | + } else { |
|
| 1249 | + $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1250 | + . (!$user ? '' : "$user@") |
|
| 1251 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1252 | + } |
|
| 1253 | + $t2 = @parse_url($http_proxy); |
|
| 1254 | + $first_host = $t2['host']; |
|
| 1255 | + if (!($port = $t2['port'])) { |
|
| 1256 | + $port = 80; |
|
| 1257 | + } |
|
| 1258 | + if ($t2['user']) { |
|
| 1259 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1260 | + } |
|
| 1261 | + } else { |
|
| 1262 | + $first_host = $noproxy . $host; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + if ($connect) { |
|
| 1266 | + $streamContext = stream_context_create(array( |
|
| 1267 | + 'ssl' => array( |
|
| 1268 | + 'verify_peer' => false, |
|
| 1269 | + 'allow_self_signed' => true, |
|
| 1270 | + 'SNI_enabled' => true, |
|
| 1271 | + 'peer_name' => $host, |
|
| 1272 | + ) |
|
| 1273 | + )); |
|
| 1274 | + $f = @stream_socket_client( |
|
| 1275 | + "tcp://$first_host:$port", |
|
| 1276 | + $errno, |
|
| 1277 | + $errstr, |
|
| 1278 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1279 | + STREAM_CLIENT_CONNECT, |
|
| 1280 | + $streamContext |
|
| 1281 | + ); |
|
| 1282 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1283 | + if (!$f) { |
|
| 1284 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1285 | + return $errno; |
|
| 1286 | + } |
|
| 1287 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1288 | + |
|
| 1289 | + fputs($f, $connect); |
|
| 1290 | + fputs($f, "\r\n"); |
|
| 1291 | + $res = fread($f, 1024); |
|
| 1292 | + if (!$res |
|
| 1293 | + or !count($res = explode(' ', $res)) |
|
| 1294 | + or $res[1] !== '200' |
|
| 1295 | + ) { |
|
| 1296 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1297 | + fclose($f); |
|
| 1298 | + |
|
| 1299 | + return false; |
|
| 1300 | + } |
|
| 1301 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1302 | + stream_set_blocking($f, true); |
|
| 1303 | + // envoyer le handshake |
|
| 1304 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1305 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1306 | + } else { |
|
| 1307 | + $ntry = 3; |
|
| 1308 | + do { |
|
| 1309 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1310 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1311 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1312 | + if (!$f) { |
|
| 1313 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1314 | + |
|
| 1315 | + return $errno; |
|
| 1316 | + } |
|
| 1317 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1321 | + |
|
| 1322 | + $host_port = $host; |
|
| 1323 | + if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) { |
|
| 1324 | + $host_port .= ":$port"; |
|
| 1325 | + } |
|
| 1326 | + $req = "$method $path $vers\r\n" |
|
| 1327 | + . "Host: $host_port\r\n" |
|
| 1328 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1329 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1330 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1331 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1332 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1333 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1334 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1335 | 1335 | |
| 1336 | 1336 | # spip_log("Requete\n$req", 'distant'); |
| 1337 | - fputs($f, $req); |
|
| 1338 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1337 | + fputs($f, $req); |
|
| 1338 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1339 | 1339 | |
| 1340 | - return $f; |
|
| 1340 | + return $f; |
|
| 1341 | 1341 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode == 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant'); |
|
| 125 | 125 | |
| 126 | 126 | // pour une eventuelle indexation |
| 127 | 127 | pipeline( |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * url ou false en cas d'echec |
| 154 | 154 | */ |
| 155 | 155 | function valider_url_distante($url, $known_hosts = array()) { |
| 156 | - if (!function_exists('protocole_verifier')){ |
|
| 156 | + if (!function_exists('protocole_verifier')) { |
|
| 157 | 157 | include_spip('inc/filtres_mini'); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $parsed_url = parse_url($url); |
| 165 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 165 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 166 | 166 | return false; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | if ($ip) { |
| 206 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 206 | + $parts = array_map('intval', explode('.', $ip)); |
|
| 207 | 207 | if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
| 208 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 208 | + or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1]) |
|
| 209 | + or (192 === $parts[0] && 168 === $parts[1]) |
|
| 210 | 210 | ) { |
| 211 | 211 | return false; |
| 212 | 212 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | $port = $parsed_url['port']; |
| 221 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 221 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | 222 | return $url; |
| 223 | 223 | } |
| 224 | 224 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | if ($taille > 500) { |
| 289 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 289 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
@@ -314,16 +314,16 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | } else { |
| 316 | 316 | // fabrique une chaine HTTP simple pour un POST |
| 317 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 317 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 318 | 318 | $chaine = array(); |
| 319 | 319 | if (is_array($donnees)) { |
| 320 | 320 | foreach ($donnees as $cle => $valeur) { |
| 321 | 321 | if (is_array($valeur)) { |
| 322 | 322 | foreach ($valeur as $val2) { |
| 323 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 323 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 324 | 324 | } |
| 325 | 325 | } else { |
| 326 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 326 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | $chaine = implode('&', $chaine); |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | $head_add = ''; |
| 434 | 434 | if (!empty($options['headers'])) { |
| 435 | 435 | foreach ($options['headers'] as $champ => $valeur) { |
| 436 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 436 | + $head_add .= $champ.': '.$valeur."\r\n"; |
|
| 437 | 437 | } |
| 438 | 438 | // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
| 439 | 439 | unset($options['entetes']); |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 444 | 444 | $head .= $head_add; |
| 445 | 445 | if (stripos($head, 'Content-Length:') === false) { |
| 446 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 446 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 447 | 447 | } |
| 448 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 448 | + $options['datas'] = $head."\r\n".$postdata; |
|
| 449 | 449 | if ( |
| 450 | 450 | strlen($postdata) |
| 451 | 451 | and !$methode_demandee |
@@ -453,15 +453,15 @@ discard block |
||
| 453 | 453 | $options['methode'] = 'POST'; |
| 454 | 454 | } |
| 455 | 455 | } elseif ($head_add) { |
| 456 | - $options['datas'] = $head_add . "\r\n"; |
|
| 456 | + $options['datas'] = $head_add."\r\n"; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 460 | 460 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 461 | 461 | if (!tester_url_absolue($url)) { |
| 462 | - $url = 'http://' . $url; |
|
| 462 | + $url = 'http://'.$url; |
|
| 463 | 463 | } elseif (strncmp($url, '//', 2) == 0) { |
| 464 | - $url = 'http:' . $url; |
|
| 464 | + $url = 'http:'.$url; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $url = url_to_ascii($url); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | $options['if_modified_since'] |
| 491 | 491 | ); |
| 492 | 492 | if (!$handle) { |
| 493 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 493 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 494 | 494 | |
| 495 | 495 | return false; |
| 496 | 496 | } |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | 'status' => 200, |
| 520 | 520 | ); |
| 521 | 521 | } else { |
| 522 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 522 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 523 | 523 | return false; |
| 524 | 524 | } |
| 525 | 525 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | |
| 532 | 532 | return recuperer_url($url, $options); |
| 533 | 533 | } elseif ($res['status'] !== 200) { |
| 534 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 534 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 535 | 535 | } |
| 536 | 536 | $result['status'] = $res['status']; |
| 537 | 537 | if (isset($res['headers'])) { |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | |
| 557 | 557 | $gz = false; |
| 558 | 558 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 559 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 559 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | $sig['url'] = $url; |
| 643 | 643 | |
| 644 | 644 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 645 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 645 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 646 | 646 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 647 | 647 | $cache = "$sub$cache"; |
| 648 | 648 | |
@@ -694,7 +694,7 @@ discard block |
||
| 694 | 694 | $fp = false; |
| 695 | 695 | if ($fichier) { |
| 696 | 696 | include_spip('inc/acces'); |
| 697 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 697 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 698 | 698 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 699 | 699 | if (!$fp and file_exists($fichier)) { |
| 700 | 700 | return filesize($fichier); |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | } |
| 754 | 754 | $result['status'] = intval($r[1]); |
| 755 | 755 | while ($s = trim(fgets($handle, 16384))) { |
| 756 | - $result['headers'][] = $s . "\n"; |
|
| 756 | + $result['headers'][] = $s."\n"; |
|
| 757 | 757 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 758 | 758 | list(, $d, $v) = $r; |
| 759 | 759 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -801,13 +801,13 @@ discard block |
||
| 801 | 801 | |
| 802 | 802 | // on se place tout le temps comme si on etait a la racine |
| 803 | 803 | if (_DIR_RACINE) { |
| 804 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 804 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | $m = md5($source); |
| 808 | 808 | |
| 809 | 809 | return $d |
| 810 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 810 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 811 | 811 | . substr($m, 0, 4) |
| 812 | 812 | . ".$extension"; |
| 813 | 813 | } |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | // Si c'est deja local pas de souci |
| 831 | 831 | if (!tester_url_absolue($source)) { |
| 832 | 832 | if (_DIR_RACINE) { |
| 833 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 833 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | return $source; |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | if ($ext |
| 848 | 848 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 849 | 849 | and $f = nom_fichier_copie_locale($source, $ext) |
| 850 | - and file_exists(_DIR_RACINE . $f) |
|
| 850 | + and file_exists(_DIR_RACINE.$f) |
|
| 851 | 851 | ) { |
| 852 | 852 | return $f; |
| 853 | 853 | } |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | |
| 856 | 856 | // Si c'est deja dans la table des documents, |
| 857 | 857 | // ramener le nom de sa copie potentielle |
| 858 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 858 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 859 | 859 | |
| 860 | 860 | if ($ext) { |
| 861 | 861 | return nom_fichier_copie_locale($source, $ext); |
@@ -866,9 +866,9 @@ discard block |
||
| 866 | 866 | |
| 867 | 867 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 868 | 868 | |
| 869 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 869 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 870 | 870 | $f = nom_fichier_copie_locale($source, $ext); |
| 871 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 871 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 872 | 872 | return $f; |
| 873 | 873 | } |
| 874 | 874 | } |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | // Ping pour voir si son extension est connue et autorisee |
| 877 | 877 | // avec mise en cache du resultat du ping |
| 878 | 878 | |
| 879 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 879 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 880 | 880 | if (!@file_exists($cache) |
| 881 | 881 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
| 882 | 882 | or _request('var_mode') == 'recalcul' |
@@ -885,10 +885,10 @@ discard block |
||
| 885 | 885 | ecrire_fichier($cache, serialize($path_parts)); |
| 886 | 886 | } |
| 887 | 887 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 888 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 888 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 889 | 889 | return nom_fichier_copie_locale($source, $ext); |
| 890 | 890 | } |
| 891 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 891 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | |
@@ -954,19 +954,19 @@ discard block |
||
| 954 | 954 | if (!$t |
| 955 | 955 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 956 | 956 | ) { |
| 957 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 957 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 958 | 958 | } |
| 959 | 959 | if (!$t |
| 960 | 960 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 961 | 961 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 962 | 962 | ) { |
| 963 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 963 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 964 | 964 | } |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 968 | 968 | if (!$t) { |
| 969 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 969 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -976,11 +976,11 @@ discard block |
||
| 976 | 976 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 977 | 977 | ) { |
| 978 | 978 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 979 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 979 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | if ($t) { |
| 983 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 983 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 984 | 984 | $a['extension'] = $t['extension']; |
| 985 | 985 | } else { |
| 986 | 986 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | } else { |
| 1023 | 1023 | if ($a['body']) { |
| 1024 | 1024 | $a['extension'] = $extension; |
| 1025 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1025 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 1026 | 1026 | ecrire_fichier($a['fichier'], $a['body']); |
| 1027 | 1027 | $size_image = @spip_getimagesize($a['fichier']); |
| 1028 | 1028 | $a['largeur'] = intval($size_image[0]); |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | } |
| 1149 | 1149 | } else { |
| 1150 | 1150 | $scheme = $t['scheme']; |
| 1151 | - $noproxy = $scheme . '://'; |
|
| 1151 | + $noproxy = $scheme.'://'; |
|
| 1152 | 1152 | } |
| 1153 | 1153 | if (isset($t['user'])) { |
| 1154 | 1154 | $user = array($t['user'], $t['pass']); |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | if (!empty($t['query'])) { |
| 1165 | - $path .= '?' . $t['query']; |
|
| 1165 | + $path .= '?'.$t['query']; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1235,20 +1235,20 @@ discard block |
||
| 1235 | 1235 | $proxy_user = ''; |
| 1236 | 1236 | $http_proxy = need_proxy($host); |
| 1237 | 1237 | if ($user) { |
| 1238 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1238 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | $connect = ''; |
| 1242 | 1242 | if ($http_proxy) { |
| 1243 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1244 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1245 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1243 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) { |
|
| 1244 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1245 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1246 | 1246 | . "Host: $path_host\r\n" |
| 1247 | 1247 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1248 | 1248 | } else { |
| 1249 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1249 | + $path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://") |
|
| 1250 | 1250 | . (!$user ? '' : "$user@") |
| 1251 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1251 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1252 | 1252 | } |
| 1253 | 1253 | $t2 = @parse_url($http_proxy); |
| 1254 | 1254 | $first_host = $t2['host']; |
@@ -1256,10 +1256,10 @@ discard block |
||
| 1256 | 1256 | $port = 80; |
| 1257 | 1257 | } |
| 1258 | 1258 | if ($t2['user']) { |
| 1259 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1259 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | } else { |
| 1262 | - $first_host = $noproxy . $host; |
|
| 1262 | + $first_host = $noproxy.$host; |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | if ($connect) { |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | ); |
| 1282 | 1282 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
| 1283 | 1283 | if (!$f) { |
| 1284 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1284 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1285 | 1285 | return $errno; |
| 1286 | 1286 | } |
| 1287 | 1287 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1293,7 +1293,7 @@ discard block |
||
| 1293 | 1293 | or !count($res = explode(' ', $res)) |
| 1294 | 1294 | or $res[1] !== '200' |
| 1295 | 1295 | ) { |
| 1296 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1296 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1297 | 1297 | fclose($f); |
| 1298 | 1298 | |
| 1299 | 1299 | return false; |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1311 | 1311 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 1312 | 1312 | if (!$f) { |
| 1313 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1313 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1314 | 1314 | |
| 1315 | 1315 | return $errno; |
| 1316 | 1316 | } |
@@ -1320,16 +1320,16 @@ discard block |
||
| 1320 | 1320 | $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
| 1321 | 1321 | |
| 1322 | 1322 | $host_port = $host; |
| 1323 | - if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) { |
|
| 1323 | + if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) { |
|
| 1324 | 1324 | $host_port .= ":$port"; |
| 1325 | 1325 | } |
| 1326 | 1326 | $req = "$method $path $vers\r\n" |
| 1327 | 1327 | . "Host: $host_port\r\n" |
| 1328 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1329 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1328 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1329 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1330 | 1330 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1331 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1332 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1331 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1332 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1333 | 1333 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1334 | 1334 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1335 | 1335 | |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($query) { |
| 47 | - $url .= '?' . $query; |
|
| 47 | + $url .= '?'.$query; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 50 | + return '/'.preg_replace(',^/,S', '', $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 75 | 75 | $r = array_pad($r, 3, null); |
| 76 | 76 | |
| 77 | - return $r[1] . resolve_path($r[2]); |
|
| 77 | + return $r[1].resolve_path($r[2]); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | # L'url site spip est un lien absolu aussi |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | switch (substr($lien, 0, 1)) { |
| 95 | 95 | case '/': |
| 96 | - return $debut . resolve_path($lien); |
|
| 96 | + return $debut.resolve_path($lien); |
|
| 97 | 97 | case '#': |
| 98 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 98 | + return $debut.resolve_path($dir.$mot.$get.$lien); |
|
| 99 | 99 | case '': |
| 100 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 100 | + return $debut.resolve_path($dir.$mot.$get.$hash); |
|
| 101 | 101 | default: |
| 102 | - return $debut . resolve_path($dir . $lien); |
|
| 102 | + return $debut.resolve_path($dir.$lien); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | return ''; |
| 128 | 128 | } |
| 129 | 129 | if (!$base) { |
| 130 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 130 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | return suivre_lien($base, $url); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param array $protocoles_autorises |
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | -function protocole_verifier($url_absolue, $protocoles_autorises = array('http','https')) { |
|
| 153 | +function protocole_verifier($url_absolue, $protocoles_autorises = array('http', 'https')) { |
|
| 154 | 154 | |
| 155 | 155 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 156 | 156 | $protocole = $m[1]; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 232 | 232 | if (is_null($flags)) { |
| 233 | - $flags = ENT_COMPAT|ENT_HTML401; |
|
| 233 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return htmlspecialchars($string, $flags, $encoding, $double_encode); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 249 | 249 | if (is_null($flags)) { |
| 250 | - $flags = ENT_COMPAT|ENT_HTML401; |
|
| 250 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return htmlentities($string, $flags, $encoding, $double_encode); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while (preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 40 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 41 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 42 | - ) { |
|
| 43 | - $url = str_replace($regs[0], '/', $url); |
|
| 44 | - } |
|
| 38 | + list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while (preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 40 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 41 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 42 | + ) { |
|
| 43 | + $url = str_replace($regs[0], '/', $url); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ($query) { |
|
| 47 | - $url .= '?' . $query; |
|
| 48 | - } |
|
| 46 | + if ($query) { |
|
| 47 | + $url .= '?' . $query; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 50 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -68,41 +68,41 @@ discard block |
||
| 68 | 68 | **/ |
| 69 | 69 | function suivre_lien($url, $lien) { |
| 70 | 70 | |
| 71 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 72 | - return $lien; |
|
| 73 | - } |
|
| 74 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 75 | - $r = array_pad($r, 3, null); |
|
| 71 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 72 | + return $lien; |
|
| 73 | + } |
|
| 74 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 75 | + $r = array_pad($r, 3, null); |
|
| 76 | 76 | |
| 77 | - return $r[1] . resolve_path($r[2]); |
|
| 78 | - } |
|
| 77 | + return $r[1] . resolve_path($r[2]); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - # L'url site spip est un lien absolu aussi |
|
| 81 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 82 | - return $lien; |
|
| 83 | - } |
|
| 80 | + # L'url site spip est un lien absolu aussi |
|
| 81 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 82 | + return $lien; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - # lien relatif, il faut verifier l'url de base |
|
| 86 | - # commencer par virer la chaine de get de l'url de base |
|
| 87 | - $dir = '/'; |
|
| 88 | - $debut = ''; |
|
| 89 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 90 | - $debut = $regs[1]; |
|
| 91 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 92 | - $mot = $regs[3]; |
|
| 93 | - $get = isset($regs[4]) ? $regs[4] : ''; |
|
| 94 | - $hash = isset($regs[5]) ? $regs[5] : ''; |
|
| 95 | - } |
|
| 96 | - switch (substr($lien, 0, 1)) { |
|
| 97 | - case '/': |
|
| 98 | - return $debut . resolve_path($lien); |
|
| 99 | - case '#': |
|
| 100 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 101 | - case '': |
|
| 102 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 103 | - default: |
|
| 104 | - return $debut . resolve_path($dir . $lien); |
|
| 105 | - } |
|
| 85 | + # lien relatif, il faut verifier l'url de base |
|
| 86 | + # commencer par virer la chaine de get de l'url de base |
|
| 87 | + $dir = '/'; |
|
| 88 | + $debut = ''; |
|
| 89 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 90 | + $debut = $regs[1]; |
|
| 91 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 92 | + $mot = $regs[3]; |
|
| 93 | + $get = isset($regs[4]) ? $regs[4] : ''; |
|
| 94 | + $hash = isset($regs[5]) ? $regs[5] : ''; |
|
| 95 | + } |
|
| 96 | + switch (substr($lien, 0, 1)) { |
|
| 97 | + case '/': |
|
| 98 | + return $debut . resolve_path($lien); |
|
| 99 | + case '#': |
|
| 100 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 101 | + case '': |
|
| 102 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 103 | + default: |
|
| 104 | + return $debut . resolve_path($dir . $lien); |
|
| 105 | + } |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | * @return string Texte ou URL (en absolus) |
| 126 | 126 | **/ |
| 127 | 127 | function url_absolue($url, $base = '') { |
| 128 | - if (strlen($url = trim($url)) == 0) { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - if (!$base) { |
|
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | - } |
|
| 128 | + if (strlen($url = trim($url)) == 0) { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + if (!$base) { |
|
| 132 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - return suivre_lien($base, $url); |
|
| 135 | + return suivre_lien($base, $url); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function protocole_implicite($url_absolue) { |
| 146 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 146 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function protocole_verifier($url_absolue, $protocoles_autorises = array('http','https')) { |
| 156 | 156 | |
| 157 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | - $protocole = $m[1]; |
|
| 159 | - if (in_array($protocole, $protocoles_autorises) |
|
| 160 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))) { |
|
| 161 | - return true; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - return false; |
|
| 157 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | + $protocole = $m[1]; |
|
| 159 | + if (in_array($protocole, $protocoles_autorises) |
|
| 160 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))) { |
|
| 161 | + return true; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + return false; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -178,27 +178,27 @@ discard block |
||
| 178 | 178 | * @return string Texte avec des URLs absolues |
| 179 | 179 | **/ |
| 180 | 180 | function liens_absolus($texte, $base = '') { |
| 181 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 182 | - if (!function_exists('extraire_attribut')) { |
|
| 183 | - include_spip('inc/filtres'); |
|
| 184 | - } |
|
| 185 | - foreach ($liens as $lien) { |
|
| 186 | - foreach (array('href', 'src') as $attr) { |
|
| 187 | - $href = extraire_attribut($lien[0], $attr); |
|
| 188 | - if (strlen($href) > 0) { |
|
| 189 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 190 | - $abs = url_absolue($href, $base); |
|
| 191 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 192 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 193 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 181 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 182 | + if (!function_exists('extraire_attribut')) { |
|
| 183 | + include_spip('inc/filtres'); |
|
| 184 | + } |
|
| 185 | + foreach ($liens as $lien) { |
|
| 186 | + foreach (array('href', 'src') as $attr) { |
|
| 187 | + $href = extraire_attribut($lien[0], $attr); |
|
| 188 | + if (strlen($href) > 0) { |
|
| 189 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 190 | + $abs = url_absolue($href, $base); |
|
| 191 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 192 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 193 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return $texte; |
|
| 201 | + return $texte; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | * @return string Texte ou URL (en absolus) |
| 215 | 215 | **/ |
| 216 | 216 | function abs_url($texte, $base = '') { |
| 217 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 218 | - return url_absolue($texte, $base); |
|
| 219 | - } else { |
|
| 220 | - return liens_absolus($texte, $base); |
|
| 221 | - } |
|
| 217 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 218 | + return url_absolue($texte, $base); |
|
| 219 | + } else { |
|
| 220 | + return liens_absolus($texte, $base); |
|
| 221 | + } |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | 233 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 234 | - if (is_null($flags)) { |
|
| 235 | - $flags = ENT_COMPAT|ENT_HTML401; |
|
| 236 | - } |
|
| 234 | + if (is_null($flags)) { |
|
| 235 | + $flags = ENT_COMPAT|ENT_HTML401; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 238 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | 250 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 251 | - if (is_null($flags)) { |
|
| 252 | - $flags = ENT_COMPAT|ENT_HTML401; |
|
| 253 | - } |
|
| 251 | + if (is_null($flags)) { |
|
| 252 | + $flags = ENT_COMPAT|ENT_HTML401; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 255 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 256 | 256 | } |