@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/texte'); |
@@ -19,105 +19,105 @@ discard block |
||
| 19 | 19 | // https://code.spip.net/@inc_plonger_dist |
| 20 | 20 | function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') { |
| 21 | 21 | |
| 22 | - if ($list) { |
|
| 23 | - $id_rubrique = $list[$col - 1]; |
|
| 24 | - } |
|
| 22 | + if ($list) { |
|
| 23 | + $id_rubrique = $list[$col - 1]; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $ret = ''; |
|
| 26 | + $ret = ''; |
|
| 27 | 27 | |
| 28 | - # recherche les filles et petites-filles de la rubrique donnee |
|
| 29 | - # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 30 | - # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 31 | - # racine... sauf vers elle-meme ou sa propre branche) |
|
| 32 | - $ordre = []; |
|
| 33 | - $rub = []; |
|
| 28 | + # recherche les filles et petites-filles de la rubrique donnee |
|
| 29 | + # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 30 | + # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 31 | + # racine... sauf vers elle-meme ou sa propre branche) |
|
| 32 | + $ordre = []; |
|
| 33 | + $rub = []; |
|
| 34 | 34 | |
| 35 | - $res = sql_select( |
|
| 36 | - 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 37 | - 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 38 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 35 | + $res = sql_select( |
|
| 36 | + 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 37 | + 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 38 | + 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 39 | 39 | AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
| 40 | 40 | AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
| 41 | - '', |
|
| 42 | - '0+rub1.titre,rub1.titre' |
|
| 43 | - ); |
|
| 41 | + '', |
|
| 42 | + '0+rub1.titre,rub1.titre' |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - while ($row = sql_fetch($res)) { |
|
| 46 | - if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 47 | - $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 48 | - if ($row['id_parent'] == $id_rubrique) { |
|
| 49 | - $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 50 | - if ($row['langue_choisie'] != 'oui') { |
|
| 51 | - $t .= ' <small title="' |
|
| 52 | - . traduire_nom_langue($row['lang']) |
|
| 53 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 54 | - } |
|
| 55 | - $ordre[$row['id_rubrique']] = $t; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $next = $list[$col] ?? 0; |
|
| 60 | - if ($ordre) { |
|
| 61 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 62 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 63 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 45 | + while ($row = sql_fetch($res)) { |
|
| 46 | + if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 47 | + $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 48 | + if ($row['id_parent'] == $id_rubrique) { |
|
| 49 | + $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 50 | + if ($row['langue_choisie'] != 'oui') { |
|
| 51 | + $t .= ' <small title="' |
|
| 52 | + . traduire_nom_langue($row['lang']) |
|
| 53 | + . '">[' . $row['lang'] . ']</small>'; |
|
| 54 | + } |
|
| 55 | + $ordre[$row['id_rubrique']] = $t; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $next = $list[$col] ?? 0; |
|
| 60 | + if ($ordre) { |
|
| 61 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 62 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 63 | + $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 64 | 64 | |
| 65 | - foreach ($ordre as $id => $titrebrut) { |
|
| 66 | - $titre = supprimer_numero($titrebrut); |
|
| 65 | + foreach ($ordre as $id => $titrebrut) { |
|
| 66 | + $titre = supprimer_numero($titrebrut); |
|
| 67 | 67 | |
| 68 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | - if (isset($rub[$id]['enfants'])) { |
|
| 70 | - $classe2 = " class='rub-ouverte'"; |
|
| 71 | - $url = "\nhref='$rec&id=$id'"; |
|
| 72 | - } else { |
|
| 73 | - $classe2 = $url = ''; |
|
| 74 | - $url = "\nhref='javascript:void(0)'"; |
|
| 75 | - } |
|
| 68 | + $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | + if (isset($rub[$id]['enfants'])) { |
|
| 70 | + $classe2 = " class='rub-ouverte'"; |
|
| 71 | + $url = "\nhref='$rec&id=$id'"; |
|
| 72 | + } else { |
|
| 73 | + $classe2 = $url = ''; |
|
| 74 | + $url = "\nhref='javascript:void(0)'"; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $js_func = $do . '_selection_titre'; |
|
| 78 | - $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 79 | - . (!is_array($list) ? ' false' |
|
| 80 | - : "aff_selection_provisoire($id,$args)") |
|
| 77 | + $js_func = $do . '_selection_titre'; |
|
| 78 | + $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 79 | + . (!is_array($list) ? ' false' |
|
| 80 | + : "aff_selection_provisoire($id,$args)") |
|
| 81 | 81 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 82 | 82 | # et l'affichage de son titre dans le bandeau |
| 83 | - . "\"\nondblclick=\"" |
|
| 84 | - . "$js_func(this." |
|
| 85 | - . 'firstChild.nodeValue,' |
|
| 86 | - . $id |
|
| 87 | - . ",'selection_rubrique','id_parent');" |
|
| 88 | - . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 89 | - . '"'; |
|
| 83 | + . "\"\nondblclick=\"" |
|
| 84 | + . "$js_func(this." |
|
| 85 | + . 'firstChild.nodeValue,' |
|
| 86 | + . $id |
|
| 87 | + . ",'selection_rubrique','id_parent');" |
|
| 88 | + . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 89 | + . '"'; |
|
| 90 | 90 | |
| 91 | - $ret .= "<div class='" |
|
| 92 | - . (($id == $next) ? 'item on' : 'item') |
|
| 93 | - . "'><div class='" |
|
| 94 | - . $classe1 |
|
| 95 | - . "'><div$classe2><a" |
|
| 96 | - . $url |
|
| 97 | - . $click |
|
| 98 | - . '>' |
|
| 99 | - . $titre |
|
| 100 | - . '</a></div></div></div>'; |
|
| 101 | - } |
|
| 102 | - } |
|
| 91 | + $ret .= "<div class='" |
|
| 92 | + . (($id == $next) ? 'item on' : 'item') |
|
| 93 | + . "'><div class='" |
|
| 94 | + . $classe1 |
|
| 95 | + . "'><div$classe2><a" |
|
| 96 | + . $url |
|
| 97 | + . $click |
|
| 98 | + . '>' |
|
| 99 | + . $titre |
|
| 100 | + . '</a></div></div></div>'; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 105 | - $left = ($col * 250); |
|
| 104 | + $idom2 = $idom . '_col_' . ($col + 1); |
|
| 105 | + $left = ($col * 250); |
|
| 106 | 106 | |
| 107 | - return http_img_pack( |
|
| 108 | - 'loader.svg', |
|
| 109 | - '', |
|
| 110 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 111 | - . ($left - 30) |
|
| 112 | - . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 113 | - ) |
|
| 114 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 115 | - . ($left - 250) |
|
| 116 | - . "px;'>" |
|
| 117 | - . $ret |
|
| 118 | - . "\n</div>\n<div id='$idom2'>" |
|
| 119 | - . ($next |
|
| 120 | - ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 121 | - : '') |
|
| 122 | - . "\n</div>"; |
|
| 107 | + return http_img_pack( |
|
| 108 | + 'loader.svg', |
|
| 109 | + '', |
|
| 110 | + "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 111 | + . ($left - 30) |
|
| 112 | + . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 113 | + ) |
|
| 114 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 115 | + . ($left - 250) |
|
| 116 | + . "px;'>" |
|
| 117 | + . $ret |
|
| 118 | + . "\n</div>\n<div id='$idom2'>" |
|
| 119 | + . ($next |
|
| 120 | + ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 121 | + : '') |
|
| 122 | + . "\n</div>"; |
|
| 123 | 123 | } |
@@ -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 ['', '']; |
|
| 37 | + return ['', '']; |
|
| 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,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,39 +415,39 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (!$t) { |
|
| 431 | - return strval($t); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | - // avant echappement des balises <html> |
|
| 436 | - // https://core.spip.net/issues/3371 |
|
| 437 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | - // https://core.spip.net/issues/4166 |
|
| 439 | - if ( |
|
| 440 | - $interdire_script |
|
| 441 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - ) { |
|
| 445 | - $t = echapper_html_suspect($t, false); |
|
| 446 | - } |
|
| 447 | - $t = echappe_html($t); |
|
| 448 | - $t = expanser_liens($t, $connect, $env); |
|
| 449 | - $t = traiter_raccourcis($t); |
|
| 450 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | - |
|
| 452 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (!$t) { |
|
| 431 | + return strval($t); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | + // avant echappement des balises <html> |
|
| 436 | + // https://core.spip.net/issues/3371 |
|
| 437 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | + // https://core.spip.net/issues/4166 |
|
| 439 | + if ( |
|
| 440 | + $interdire_script |
|
| 441 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + ) { |
|
| 445 | + $t = echapper_html_suspect($t, false); |
|
| 446 | + } |
|
| 447 | + $t = echappe_html($t); |
|
| 448 | + $t = expanser_liens($t, $connect, $env); |
|
| 449 | + $t = traiter_raccourcis($t); |
|
| 450 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | + |
|
| 452 | + return $t; |
|
| 453 | 453 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,103 +50,103 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = [], |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = [], |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = [ |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ]; |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel( |
|
| 96 | - 'id_job', |
|
| 97 | - 'spip_jobs', |
|
| 98 | - $duplicate_where = |
|
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | - ) |
|
| 103 | - ) { |
|
| 104 | - return $id_job; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | - // doit s'effacer |
|
| 111 | - if ( |
|
| 112 | - $no_duplicate |
|
| 113 | - and |
|
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | - ) { |
|
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | - |
|
| 118 | - return $id_prev; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | - |
|
| 124 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | - // qui coupe la valeur |
|
| 127 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | - if ($args !== $arguments) { |
|
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | - $arguments, |
|
| 132 | - true |
|
| 133 | - ), 'queue'); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($id_job) { |
|
| 138 | - queue_update_next_job_time($time); |
|
| 139 | - } |
|
| 140 | - // si la mise en file d'attente du job echoue, |
|
| 141 | - // il ne faut pas perdre l'execution de la fonction |
|
| 142 | - // on la lance immediatement, c'est un fallback |
|
| 143 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | - $set_job['id_job'] = 0; |
|
| 146 | - queue_start_job($set_job); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = [ |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ]; |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel( |
|
| 96 | + 'id_job', |
|
| 97 | + 'spip_jobs', |
|
| 98 | + $duplicate_where = |
|
| 99 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | + ) |
|
| 103 | + ) { |
|
| 104 | + return $id_job; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | + // doit s'effacer |
|
| 111 | + if ( |
|
| 112 | + $no_duplicate |
|
| 113 | + and |
|
| 114 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | + ) { |
|
| 116 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | + |
|
| 118 | + return $id_prev; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | + |
|
| 124 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | + // qui coupe la valeur |
|
| 127 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | + if ($args !== $arguments) { |
|
| 130 | + spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | + $arguments, |
|
| 132 | + true |
|
| 133 | + ), 'queue'); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($id_job) { |
|
| 138 | + queue_update_next_job_time($time); |
|
| 139 | + } |
|
| 140 | + // si la mise en file d'attente du job echoue, |
|
| 141 | + // il ne faut pas perdre l'execution de la fonction |
|
| 142 | + // on la lance immediatement, c'est un fallback |
|
| 143 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | + $set_job['id_job'] = 0; |
|
| 146 | + queue_start_job($set_job); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $id_job; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | 157 | function queue_purger() { |
| 158 | - include_spip('base/abstract_sql'); |
|
| 159 | - sql_delete('spip_jobs'); |
|
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | - include_spip('inc/genie'); |
|
| 162 | - genie_queue_watch_dist(); |
|
| 158 | + include_spip('base/abstract_sql'); |
|
| 159 | + sql_delete('spip_jobs'); |
|
| 160 | + sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | + include_spip('inc/genie'); |
|
| 162 | + genie_queue_watch_dist(); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,25 +170,25 @@ discard block |
||
| 170 | 170 | * @return int|bool |
| 171 | 171 | */ |
| 172 | 172 | function queue_remove_job($id_job) { |
| 173 | - include_spip('base/abstract_sql'); |
|
| 174 | - |
|
| 175 | - if ( |
|
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | - ) { |
|
| 179 | - queue_unlink_job($id_job); |
|
| 180 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | - // relancer avec les nouveaux arguments de temps |
|
| 183 | - include_spip('inc/genie'); |
|
| 184 | - // relancer avec la periode prevue |
|
| 185 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | - } |
|
| 187 | - queue_update_next_job_time(); |
|
| 188 | - return $res; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 173 | + include_spip('base/abstract_sql'); |
|
| 174 | + |
|
| 175 | + if ( |
|
| 176 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | + ) { |
|
| 179 | + queue_unlink_job($id_job); |
|
| 180 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | + // relancer avec les nouveaux arguments de temps |
|
| 183 | + include_spip('inc/genie'); |
|
| 184 | + // relancer avec la periode prevue |
|
| 185 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | + } |
|
| 187 | + queue_update_next_job_time(); |
|
| 188 | + return $res; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,18 +201,18 @@ discard block |
||
| 201 | 201 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 202 | 202 | */ |
| 203 | 203 | function queue_link_job($id_job, $objets) { |
| 204 | - include_spip('base/abstract_sql'); |
|
| 205 | - |
|
| 206 | - if (is_array($objets) and count($objets)) { |
|
| 207 | - if (is_array(reset($objets))) { |
|
| 208 | - foreach ($objets as $k => $o) { |
|
| 209 | - $objets[$k]['id_job'] = $id_job; |
|
| 210 | - } |
|
| 211 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | - } else { |
|
| 213 | - sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | - } |
|
| 215 | - } |
|
| 204 | + include_spip('base/abstract_sql'); |
|
| 205 | + |
|
| 206 | + if (is_array($objets) and count($objets)) { |
|
| 207 | + if (is_array(reset($objets))) { |
|
| 208 | + foreach ($objets as $k => $o) { |
|
| 209 | + $objets[$k]['id_job'] = $id_job; |
|
| 210 | + } |
|
| 211 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | + } else { |
|
| 213 | + sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * resultat du sql_delete |
| 225 | 225 | */ |
| 226 | 226 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 227 | + return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,84 +237,84 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function queue_start_job($row) { |
| 239 | 239 | |
| 240 | - // deserialiser les arguments |
|
| 241 | - $args = unserialize($row['args']); |
|
| 242 | - if ($args === false) { |
|
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | - $args = []; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $fonction = $row['fonction']; |
|
| 248 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | - if ($f) { |
|
| 252 | - $fonction = $f; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - include_spip($inclure); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (!function_exists($fonction)) { |
|
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | - |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | - switch (is_countable($args) ? count($args) : 0) { |
|
| 267 | - case 0: |
|
| 268 | - $res = $fonction(); |
|
| 269 | - break; |
|
| 270 | - case 1: |
|
| 271 | - $res = $fonction($args[0]); |
|
| 272 | - break; |
|
| 273 | - case 2: |
|
| 274 | - $res = $fonction($args[0], $args[1]); |
|
| 275 | - break; |
|
| 276 | - case 3: |
|
| 277 | - $res = $fonction($args[0], $args[1], $args[2]); |
|
| 278 | - break; |
|
| 279 | - case 4: |
|
| 280 | - $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 281 | - break; |
|
| 282 | - case 5: |
|
| 283 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 284 | - break; |
|
| 285 | - case 6: |
|
| 286 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 287 | - break; |
|
| 288 | - case 7: |
|
| 289 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 290 | - break; |
|
| 291 | - case 8: |
|
| 292 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 293 | - break; |
|
| 294 | - case 9: |
|
| 295 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 296 | - break; |
|
| 297 | - case 10: |
|
| 298 | - $res = $fonction( |
|
| 299 | - $args[0], |
|
| 300 | - $args[1], |
|
| 301 | - $args[2], |
|
| 302 | - $args[3], |
|
| 303 | - $args[4], |
|
| 304 | - $args[5], |
|
| 305 | - $args[6], |
|
| 306 | - $args[7], |
|
| 307 | - $args[8], |
|
| 308 | - $args[9] |
|
| 309 | - ); |
|
| 310 | - break; |
|
| 311 | - default: |
|
| 312 | - # plus lent mais completement generique |
|
| 313 | - $res = call_user_func_array($fonction, $args); |
|
| 314 | - } |
|
| 315 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 316 | - |
|
| 317 | - return $res; |
|
| 240 | + // deserialiser les arguments |
|
| 241 | + $args = unserialize($row['args']); |
|
| 242 | + if ($args === false) { |
|
| 243 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | + $args = []; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $fonction = $row['fonction']; |
|
| 248 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | + if ($f) { |
|
| 252 | + $fonction = $f; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + include_spip($inclure); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (!function_exists($fonction)) { |
|
| 260 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | + |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | + switch (is_countable($args) ? count($args) : 0) { |
|
| 267 | + case 0: |
|
| 268 | + $res = $fonction(); |
|
| 269 | + break; |
|
| 270 | + case 1: |
|
| 271 | + $res = $fonction($args[0]); |
|
| 272 | + break; |
|
| 273 | + case 2: |
|
| 274 | + $res = $fonction($args[0], $args[1]); |
|
| 275 | + break; |
|
| 276 | + case 3: |
|
| 277 | + $res = $fonction($args[0], $args[1], $args[2]); |
|
| 278 | + break; |
|
| 279 | + case 4: |
|
| 280 | + $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 281 | + break; |
|
| 282 | + case 5: |
|
| 283 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 284 | + break; |
|
| 285 | + case 6: |
|
| 286 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 287 | + break; |
|
| 288 | + case 7: |
|
| 289 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 290 | + break; |
|
| 291 | + case 8: |
|
| 292 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 293 | + break; |
|
| 294 | + case 9: |
|
| 295 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 296 | + break; |
|
| 297 | + case 10: |
|
| 298 | + $res = $fonction( |
|
| 299 | + $args[0], |
|
| 300 | + $args[1], |
|
| 301 | + $args[2], |
|
| 302 | + $args[3], |
|
| 303 | + $args[4], |
|
| 304 | + $args[5], |
|
| 305 | + $args[6], |
|
| 306 | + $args[7], |
|
| 307 | + $args[8], |
|
| 308 | + $args[9] |
|
| 309 | + ); |
|
| 310 | + break; |
|
| 311 | + default: |
|
| 312 | + # plus lent mais completement generique |
|
| 313 | + $res = call_user_func_array($fonction, $args); |
|
| 314 | + } |
|
| 315 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 316 | + |
|
| 317 | + return $res; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -341,89 +341,89 @@ discard block |
||
| 341 | 341 | * - true : une planification a été faite. |
| 342 | 342 | */ |
| 343 | 343 | function queue_schedule($force_jobs = null) { |
| 344 | - $time = time(); |
|
| 345 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 346 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 347 | - |
|
| 348 | - return; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // rien a faire si le prochain job est encore dans le futur |
|
| 352 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 353 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 354 | - |
|
| 355 | - return; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - include_spip('base/abstract_sql'); |
|
| 359 | - // on ne peut rien faire si pas de connexion SQL |
|
| 360 | - if (!spip_connect()) { |
|
| 361 | - return false; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 365 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 366 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 367 | - if (!$max_time) { |
|
| 368 | - $max_time = 5; |
|
| 369 | - } |
|
| 370 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 371 | - } |
|
| 372 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 373 | - |
|
| 374 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 375 | - |
|
| 376 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 377 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 378 | - } |
|
| 379 | - $nbj = 0; |
|
| 380 | - // attraper les jobs |
|
| 381 | - // dont la date est passee (echus en attente), |
|
| 382 | - // par ordre : |
|
| 383 | - // - de priorite |
|
| 384 | - // - de date |
|
| 385 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 386 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 387 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 388 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 389 | - } else { |
|
| 390 | - $now = date('Y-m-d H:i:s', $time); |
|
| 391 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 395 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 396 | - do { |
|
| 397 | - if ($row = array_shift($res)) { |
|
| 398 | - $nbj++; |
|
| 399 | - // il faut un verrou, a base de sql_delete |
|
| 400 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 401 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 402 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 403 | - $row['status'] = _JQ_PENDING; |
|
| 404 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 405 | - sql_insertq('spip_jobs', $row); |
|
| 406 | - |
|
| 407 | - // on a la main sur le job : |
|
| 408 | - // l'executer |
|
| 409 | - $result = queue_start_job($row); |
|
| 410 | - |
|
| 411 | - $time = time(); |
|
| 412 | - queue_close_job($row, $time, $result); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 416 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 417 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 418 | - |
|
| 419 | - if ($row = array_shift($res)) { |
|
| 420 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 421 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 422 | - } else { |
|
| 423 | - queue_update_next_job_time(); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return true; |
|
| 344 | + $time = time(); |
|
| 345 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 346 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 347 | + |
|
| 348 | + return; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // rien a faire si le prochain job est encore dans le futur |
|
| 352 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 353 | + spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 354 | + |
|
| 355 | + return; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + include_spip('base/abstract_sql'); |
|
| 359 | + // on ne peut rien faire si pas de connexion SQL |
|
| 360 | + if (!spip_connect()) { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 365 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 366 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 367 | + if (!$max_time) { |
|
| 368 | + $max_time = 5; |
|
| 369 | + } |
|
| 370 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 371 | + } |
|
| 372 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 373 | + |
|
| 374 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 375 | + |
|
| 376 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 377 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 378 | + } |
|
| 379 | + $nbj = 0; |
|
| 380 | + // attraper les jobs |
|
| 381 | + // dont la date est passee (echus en attente), |
|
| 382 | + // par ordre : |
|
| 383 | + // - de priorite |
|
| 384 | + // - de date |
|
| 385 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 386 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 387 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 388 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 389 | + } else { |
|
| 390 | + $now = date('Y-m-d H:i:s', $time); |
|
| 391 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 395 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 396 | + do { |
|
| 397 | + if ($row = array_shift($res)) { |
|
| 398 | + $nbj++; |
|
| 399 | + // il faut un verrou, a base de sql_delete |
|
| 400 | + if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 401 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 402 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 403 | + $row['status'] = _JQ_PENDING; |
|
| 404 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 405 | + sql_insertq('spip_jobs', $row); |
|
| 406 | + |
|
| 407 | + // on a la main sur le job : |
|
| 408 | + // l'executer |
|
| 409 | + $result = queue_start_job($row); |
|
| 410 | + |
|
| 411 | + $time = time(); |
|
| 412 | + queue_close_job($row, $time, $result); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 416 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 417 | + spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 418 | + |
|
| 419 | + if ($row = array_shift($res)) { |
|
| 420 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 421 | + spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 422 | + } else { |
|
| 423 | + queue_update_next_job_time(); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return true; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -441,21 +441,21 @@ discard block |
||
| 441 | 441 | * @param int $result |
| 442 | 442 | */ |
| 443 | 443 | function queue_close_job(&$row, $time, $result = 0) { |
| 444 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 445 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 446 | - // relancer avec les nouveaux arguments de temps |
|
| 447 | - include_spip('inc/genie'); |
|
| 448 | - if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 449 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 450 | - } else // relancer avec la periode prevue |
|
| 451 | - { |
|
| 452 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - // purger ses liens eventuels avec des objets |
|
| 456 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 457 | - // supprimer le job fini |
|
| 458 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 444 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 445 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 446 | + // relancer avec les nouveaux arguments de temps |
|
| 447 | + include_spip('inc/genie'); |
|
| 448 | + if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 449 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 450 | + } else // relancer avec la periode prevue |
|
| 451 | + { |
|
| 452 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + // purger ses liens eventuels avec des objets |
|
| 456 | + sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 457 | + // supprimer le job fini |
|
| 458 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | * @uses queue_update_next_job_time() |
| 466 | 466 | */ |
| 467 | 467 | function queue_error_handler() { |
| 468 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 469 | - chdir(_ROOT_CWD); |
|
| 468 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 469 | + chdir(_ROOT_CWD); |
|
| 470 | 470 | |
| 471 | - queue_update_next_job_time(); |
|
| 471 | + queue_update_next_job_time(); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | |
@@ -485,18 +485,18 @@ discard block |
||
| 485 | 485 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 486 | 486 | */ |
| 487 | 487 | function queue_is_cron_job($function, $inclure) { |
| 488 | - static $taches = null; |
|
| 489 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 490 | - if (is_null($taches)) { |
|
| 491 | - include_spip('inc/genie'); |
|
| 492 | - $taches = taches_generales(); |
|
| 493 | - } |
|
| 494 | - if (isset($taches[$function])) { |
|
| 495 | - return $taches[$function]; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - return false; |
|
| 488 | + static $taches = null; |
|
| 489 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 490 | + if (is_null($taches)) { |
|
| 491 | + include_spip('inc/genie'); |
|
| 492 | + $taches = taches_generales(); |
|
| 493 | + } |
|
| 494 | + if (isset($taches[$function])) { |
|
| 495 | + return $taches[$function]; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + return false; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -510,62 +510,62 @@ discard block |
||
| 510 | 510 | * temps de la tache ajoutee ou 0 pour ASAP |
| 511 | 511 | */ |
| 512 | 512 | function queue_update_next_job_time($next_time = null) { |
| 513 | - static $nb_jobs_scheduled = null; |
|
| 514 | - static $deja_la = false; |
|
| 515 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 516 | - static $next = null; |
|
| 517 | - // queue_close_job peut etre reentrant ici |
|
| 518 | - if ($deja_la) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - $deja_la = true; |
|
| 522 | - |
|
| 523 | - include_spip('base/abstract_sql'); |
|
| 524 | - $time = time(); |
|
| 525 | - |
|
| 526 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 527 | - // pour cause de timeout ou autre erreur fatale |
|
| 528 | - $res = sql_allfetsel( |
|
| 529 | - '*', |
|
| 530 | - 'spip_jobs', |
|
| 531 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 532 | - ); |
|
| 533 | - if (is_array($res)) { |
|
| 534 | - foreach ($res as $row) { |
|
| 535 | - queue_close_job($row, $time); |
|
| 536 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // chercher la date du prochain job si pas connu |
|
| 541 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 542 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 543 | - $next = strtotime($date); |
|
| 544 | - } |
|
| 545 | - if (!is_null($next_time)) { |
|
| 546 | - if (is_null($next) or $next > $next_time) { |
|
| 547 | - $next = $next_time; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - if ($next) { |
|
| 552 | - if (is_null($nb_jobs_scheduled)) { |
|
| 553 | - $nb_jobs_scheduled = sql_countsel( |
|
| 554 | - 'spip_jobs', |
|
| 555 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 556 | - ); |
|
| 557 | - } elseif ($next <= $time) { |
|
| 558 | - $nb_jobs_scheduled++; |
|
| 559 | - } |
|
| 560 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 561 | - // pour assurer le coup |
|
| 562 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 563 | - define('_DIRECT_CRON_FORCE', true); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - queue_set_next_job_time($next); |
|
| 568 | - $deja_la = false; |
|
| 513 | + static $nb_jobs_scheduled = null; |
|
| 514 | + static $deja_la = false; |
|
| 515 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 516 | + static $next = null; |
|
| 517 | + // queue_close_job peut etre reentrant ici |
|
| 518 | + if ($deja_la) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + $deja_la = true; |
|
| 522 | + |
|
| 523 | + include_spip('base/abstract_sql'); |
|
| 524 | + $time = time(); |
|
| 525 | + |
|
| 526 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 527 | + // pour cause de timeout ou autre erreur fatale |
|
| 528 | + $res = sql_allfetsel( |
|
| 529 | + '*', |
|
| 530 | + 'spip_jobs', |
|
| 531 | + 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 532 | + ); |
|
| 533 | + if (is_array($res)) { |
|
| 534 | + foreach ($res as $row) { |
|
| 535 | + queue_close_job($row, $time); |
|
| 536 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // chercher la date du prochain job si pas connu |
|
| 541 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 542 | + $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 543 | + $next = strtotime($date); |
|
| 544 | + } |
|
| 545 | + if (!is_null($next_time)) { |
|
| 546 | + if (is_null($next) or $next > $next_time) { |
|
| 547 | + $next = $next_time; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if ($next) { |
|
| 552 | + if (is_null($nb_jobs_scheduled)) { |
|
| 553 | + $nb_jobs_scheduled = sql_countsel( |
|
| 554 | + 'spip_jobs', |
|
| 555 | + 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 556 | + ); |
|
| 557 | + } elseif ($next <= $time) { |
|
| 558 | + $nb_jobs_scheduled++; |
|
| 559 | + } |
|
| 560 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 561 | + // pour assurer le coup |
|
| 562 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 563 | + define('_DIRECT_CRON_FORCE', true); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + queue_set_next_job_time($next); |
|
| 568 | + $deja_la = false; |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -576,26 +576,26 @@ discard block |
||
| 576 | 576 | */ |
| 577 | 577 | function queue_set_next_job_time($next) { |
| 578 | 578 | |
| 579 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 580 | - $time = time(); |
|
| 581 | - |
|
| 582 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 583 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 584 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 585 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 586 | - if ( |
|
| 587 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 588 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 589 | - ) { |
|
| 590 | - if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 591 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 592 | - } else { |
|
| 593 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 594 | - } |
|
| 595 | - queue_sleep_time_to_next_job($next); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return queue_sleep_time_to_next_job(); |
|
| 579 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 580 | + $time = time(); |
|
| 581 | + |
|
| 582 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 583 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 584 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 585 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 586 | + if ( |
|
| 587 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 588 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 589 | + ) { |
|
| 590 | + if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 591 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 592 | + } else { |
|
| 593 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 594 | + } |
|
| 595 | + queue_sleep_time_to_next_job($next); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return queue_sleep_time_to_next_job(); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -612,60 +612,60 @@ discard block |
||
| 612 | 612 | * @return string |
| 613 | 613 | */ |
| 614 | 614 | function queue_affichage_cron() { |
| 615 | - $texte = ''; |
|
| 616 | - |
|
| 617 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 618 | - // rien a faire si le prochain job est encore dans le futur |
|
| 619 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 620 | - return $texte; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 624 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 625 | - return $texte; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - @touch($lock); |
|
| 629 | - |
|
| 630 | - // il y a des taches en attentes |
|
| 631 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 632 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 633 | - $urgent = false; |
|
| 634 | - if ($time_to_next < -300) { |
|
| 635 | - $urgent = true; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 639 | - |
|
| 640 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 641 | - if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 642 | - return $texte; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // si deja force, on retourne sans rien |
|
| 647 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 648 | - return $texte; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // si c'est un bot |
|
| 652 | - // inutile de faire un appel par image background, |
|
| 653 | - // on force un appel direct en fin de hit |
|
| 654 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 655 | - define('_DIRECT_CRON_FORCE', true); |
|
| 656 | - |
|
| 657 | - return $texte; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 661 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 662 | - $url_cron = generer_url_action('cron'); |
|
| 663 | - $texte = '<!-- SPIP-CRON -->' |
|
| 664 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 665 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - return $texte; |
|
| 615 | + $texte = ''; |
|
| 616 | + |
|
| 617 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 618 | + // rien a faire si le prochain job est encore dans le futur |
|
| 619 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 620 | + return $texte; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 624 | + if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 625 | + return $texte; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + @touch($lock); |
|
| 629 | + |
|
| 630 | + // il y a des taches en attentes |
|
| 631 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 632 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 633 | + $urgent = false; |
|
| 634 | + if ($time_to_next < -300) { |
|
| 635 | + $urgent = true; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 639 | + |
|
| 640 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 641 | + if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 642 | + return $texte; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // si deja force, on retourne sans rien |
|
| 647 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 648 | + return $texte; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // si c'est un bot |
|
| 652 | + // inutile de faire un appel par image background, |
|
| 653 | + // on force un appel direct en fin de hit |
|
| 654 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 655 | + define('_DIRECT_CRON_FORCE', true); |
|
| 656 | + |
|
| 657 | + return $texte; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 661 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 662 | + $url_cron = generer_url_action('cron'); |
|
| 663 | + $texte = '<!-- SPIP-CRON -->' |
|
| 664 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 665 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + return $texte; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -674,73 +674,73 @@ discard block |
||
| 674 | 674 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 675 | 675 | */ |
| 676 | 676 | function queue_lancer_url_http_async($url_cron) { |
| 677 | - // methode la plus rapide : |
|
| 678 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 679 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 680 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 681 | - // mais on renvoie false direct |
|
| 682 | - if (function_exists('fsockopen')) { |
|
| 683 | - $parts = parse_url($url_cron); |
|
| 684 | - |
|
| 685 | - switch ($parts['scheme']) { |
|
| 686 | - case 'https': |
|
| 687 | - $scheme = 'ssl://'; |
|
| 688 | - $port = 443; |
|
| 689 | - break; |
|
| 690 | - case 'http': |
|
| 691 | - default: |
|
| 692 | - $scheme = ''; |
|
| 693 | - $port = 80; |
|
| 694 | - } |
|
| 695 | - $fp = @fsockopen( |
|
| 696 | - $scheme . $parts['host'], |
|
| 697 | - $parts['port'] ?? $port, |
|
| 698 | - $errno, |
|
| 699 | - $errstr, |
|
| 700 | - 1 |
|
| 701 | - ); |
|
| 702 | - |
|
| 703 | - if ($fp) { |
|
| 704 | - $host_sent = $parts['host']; |
|
| 705 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 706 | - $host_sent .= ':' . $parts['port']; |
|
| 707 | - } |
|
| 708 | - $timeout = 200; // ms |
|
| 709 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 710 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 711 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 712 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 713 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 714 | - fwrite($fp, $out); |
|
| 715 | - spip_timer('read'); |
|
| 716 | - $t = 0; |
|
| 717 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 718 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 719 | - while (!feof($fp) and $t < $timeout) { |
|
| 720 | - @fgets($fp, 1024); |
|
| 721 | - $t += spip_timer('read', true); |
|
| 722 | - spip_timer('read'); |
|
| 723 | - } |
|
| 724 | - fclose($fp); |
|
| 725 | - return true; |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 729 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 730 | - elseif (function_exists('curl_init')) { |
|
| 731 | - //setting the curl parameters. |
|
| 732 | - $ch = curl_init($url_cron); |
|
| 733 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 734 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 735 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 736 | - // valeur mini pour que la requete soit lancee |
|
| 737 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 738 | - // lancer |
|
| 739 | - curl_exec($ch); |
|
| 740 | - // fermer |
|
| 741 | - curl_close($ch); |
|
| 742 | - return true; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return false; |
|
| 677 | + // methode la plus rapide : |
|
| 678 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 679 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 680 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 681 | + // mais on renvoie false direct |
|
| 682 | + if (function_exists('fsockopen')) { |
|
| 683 | + $parts = parse_url($url_cron); |
|
| 684 | + |
|
| 685 | + switch ($parts['scheme']) { |
|
| 686 | + case 'https': |
|
| 687 | + $scheme = 'ssl://'; |
|
| 688 | + $port = 443; |
|
| 689 | + break; |
|
| 690 | + case 'http': |
|
| 691 | + default: |
|
| 692 | + $scheme = ''; |
|
| 693 | + $port = 80; |
|
| 694 | + } |
|
| 695 | + $fp = @fsockopen( |
|
| 696 | + $scheme . $parts['host'], |
|
| 697 | + $parts['port'] ?? $port, |
|
| 698 | + $errno, |
|
| 699 | + $errstr, |
|
| 700 | + 1 |
|
| 701 | + ); |
|
| 702 | + |
|
| 703 | + if ($fp) { |
|
| 704 | + $host_sent = $parts['host']; |
|
| 705 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 706 | + $host_sent .= ':' . $parts['port']; |
|
| 707 | + } |
|
| 708 | + $timeout = 200; // ms |
|
| 709 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 710 | + $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 711 | + $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 712 | + $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 713 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 714 | + fwrite($fp, $out); |
|
| 715 | + spip_timer('read'); |
|
| 716 | + $t = 0; |
|
| 717 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 718 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 719 | + while (!feof($fp) and $t < $timeout) { |
|
| 720 | + @fgets($fp, 1024); |
|
| 721 | + $t += spip_timer('read', true); |
|
| 722 | + spip_timer('read'); |
|
| 723 | + } |
|
| 724 | + fclose($fp); |
|
| 725 | + return true; |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 729 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 730 | + elseif (function_exists('curl_init')) { |
|
| 731 | + //setting the curl parameters. |
|
| 732 | + $ch = curl_init($url_cron); |
|
| 733 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 734 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 735 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 736 | + // valeur mini pour que la requete soit lancee |
|
| 737 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 738 | + // lancer |
|
| 739 | + curl_exec($ch); |
|
| 740 | + // fermer |
|
| 741 | + curl_close($ch); |
|
| 742 | + return true; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return false; |
|
| 746 | 746 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -36,37 +36,37 @@ discard block |
||
| 36 | 36 | * @return string Contenu complété des scripts javascripts, dont jQuery |
| 37 | 37 | **/ |
| 38 | 38 | function f_jQuery_prive($texte) { |
| 39 | - $x = ''; |
|
| 40 | - $jquery_plugins = pipeline( |
|
| 41 | - 'jquery_plugins', |
|
| 42 | - [ |
|
| 43 | - 'prive/javascript/jquery.js', |
|
| 44 | - 'prive/javascript/jquery.form.js', |
|
| 45 | - 'prive/javascript/jquery.autosave.js', |
|
| 46 | - 'prive/javascript/jquery.placeholder-label.js', |
|
| 47 | - 'prive/javascript/ajaxCallback.js', |
|
| 48 | - 'prive/javascript/js.cookie.js', |
|
| 49 | - 'prive/javascript/jquery.cookie.js', |
|
| 50 | - 'prive/javascript/spip_barre.js', |
|
| 51 | - ] |
|
| 52 | - ); |
|
| 53 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 54 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 55 | - $script = timestamp($script); |
|
| 56 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - // inserer avant le premier script externe ou a la fin |
|
| 60 | - if ( |
|
| 61 | - preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 62 | - and $p = strpos($texte, (string) $match[0]) |
|
| 63 | - ) { |
|
| 64 | - $texte = substr_replace($texte, $x, $p, 0); |
|
| 65 | - } else { |
|
| 66 | - $texte .= $x; |
|
| 67 | - } |
|
| 39 | + $x = ''; |
|
| 40 | + $jquery_plugins = pipeline( |
|
| 41 | + 'jquery_plugins', |
|
| 42 | + [ |
|
| 43 | + 'prive/javascript/jquery.js', |
|
| 44 | + 'prive/javascript/jquery.form.js', |
|
| 45 | + 'prive/javascript/jquery.autosave.js', |
|
| 46 | + 'prive/javascript/jquery.placeholder-label.js', |
|
| 47 | + 'prive/javascript/ajaxCallback.js', |
|
| 48 | + 'prive/javascript/js.cookie.js', |
|
| 49 | + 'prive/javascript/jquery.cookie.js', |
|
| 50 | + 'prive/javascript/spip_barre.js', |
|
| 51 | + ] |
|
| 52 | + ); |
|
| 53 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 54 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 55 | + $script = timestamp($script); |
|
| 56 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + // inserer avant le premier script externe ou a la fin |
|
| 60 | + if ( |
|
| 61 | + preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 62 | + and $p = strpos($texte, (string) $match[0]) |
|
| 63 | + ) { |
|
| 64 | + $texte = substr_replace($texte, $x, $p, 0); |
|
| 65 | + } else { |
|
| 66 | + $texte .= $x; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return $texte; |
|
| 69 | + return $texte; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -79,43 +79,43 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function affichage_final_prive_title_auto($texte) { |
| 82 | - if ( |
|
| 83 | - strpos($texte, '<title>') === false |
|
| 84 | - and |
|
| 85 | - (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 86 | - or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 87 | - and $match = textebrut(trim($match[1])) |
|
| 88 | - and ($p = strpos($texte, '<head>')) !== false |
|
| 89 | - ) { |
|
| 90 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 91 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 92 | - } |
|
| 82 | + if ( |
|
| 83 | + strpos($texte, '<title>') === false |
|
| 84 | + and |
|
| 85 | + (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 86 | + or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 87 | + and $match = textebrut(trim($match[1])) |
|
| 88 | + and ($p = strpos($texte, '<head>')) !== false |
|
| 89 | + ) { |
|
| 90 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 91 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $titre = '<title>[' |
|
| 95 | - . $nom_site_spip |
|
| 96 | - . '] ' . $match |
|
| 97 | - . '</title>'; |
|
| 94 | + $titre = '<title>[' |
|
| 95 | + . $nom_site_spip |
|
| 96 | + . '] ' . $match |
|
| 97 | + . '</title>'; |
|
| 98 | 98 | |
| 99 | - $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 100 | - } |
|
| 99 | + $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return $texte; |
|
| 102 | + return $texte; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | // Fonction standard pour le pipeline 'boite_infos' |
| 107 | 107 | // https://code.spip.net/@f_boite_infos |
| 108 | 108 | function f_boite_infos($flux) { |
| 109 | - $args = $flux['args']; |
|
| 110 | - $type = $args['type']; |
|
| 111 | - unset($args['row']); |
|
| 112 | - if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 113 | - $type = 'objet'; |
|
| 114 | - } |
|
| 115 | - $args['espace_prive'] = 1; |
|
| 116 | - $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 109 | + $args = $flux['args']; |
|
| 110 | + $type = $args['type']; |
|
| 111 | + unset($args['row']); |
|
| 112 | + if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 113 | + $type = 'objet'; |
|
| 114 | + } |
|
| 115 | + $args['espace_prive'] = 1; |
|
| 116 | + $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 117 | 117 | |
| 118 | - return $flux; |
|
| 118 | + return $flux; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -134,97 +134,97 @@ discard block |
||
| 134 | 134 | * @return array Données du pipeline |
| 135 | 135 | */ |
| 136 | 136 | function f_afficher_blocs_ecrire($flux) { |
| 137 | - static $o = []; |
|
| 138 | - if (is_string($fond = $flux['args']['fond'])) { |
|
| 139 | - $exec = $flux['args']['contexte']['exec'] ?? _request('exec'); |
|
| 140 | - if (!isset($o[$exec])) { |
|
| 141 | - $o[$exec] = trouver_objet_exec($exec); |
|
| 142 | - } |
|
| 143 | - // cas particulier |
|
| 144 | - if ($exec == 'infos_perso') { |
|
| 145 | - $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 146 | - } |
|
| 147 | - $typepage = ($flux['args']['contexte']['type-page'] ?? $exec); |
|
| 148 | - if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 149 | - $flux['data']['texte'] = pipeline( |
|
| 150 | - 'affiche_gauche', |
|
| 151 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 152 | - ); |
|
| 153 | - } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 154 | - include_spip('inc/presentation_mini'); |
|
| 155 | - $flux['data']['texte'] = pipeline( |
|
| 156 | - 'affiche_droite', |
|
| 157 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 158 | - ) . liste_objets_bloques( |
|
| 159 | - $exec, |
|
| 160 | - $flux['args']['contexte'] |
|
| 161 | - ); |
|
| 162 | - } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 163 | - // id non defini sur les formulaire de nouveaux objets |
|
| 164 | - $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 165 | - $flux['data']['texte'] = pipeline( |
|
| 166 | - 'affiche_hierarchie', |
|
| 167 | - ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 168 | - ); |
|
| 169 | - } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 170 | - // Préparation du marqueur affiche_milieu |
|
| 171 | - // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 172 | - $est_page_objet = !empty($o[$exec]['type']); |
|
| 173 | - $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 174 | - $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 175 | - $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 176 | - $flux['data']['texte'], |
|
| 177 | - '<!--affiche_milieu-->', |
|
| 178 | - '<div id=["\']wysiwyg', |
|
| 179 | - $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 180 | - $encapsuler_milieu ? '</div>' : '' |
|
| 181 | - ); |
|
| 182 | - if ( |
|
| 183 | - $o[$exec] |
|
| 184 | - and $objet = $o[$exec]['type'] |
|
| 185 | - and $o[$exec]['edition'] == false |
|
| 186 | - and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 187 | - and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 188 | - ) { |
|
| 189 | - // inserer le formulaire de traduction |
|
| 190 | - $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 191 | - 'prive/objets/editer/traductions', |
|
| 192 | - ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 193 | - ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | - $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 195 | - 'args' => [ |
|
| 196 | - 'contexte' => $flux['args']['contexte'], |
|
| 197 | - 'type' => $objet, |
|
| 198 | - 'id' => $id |
|
| 199 | - ], |
|
| 200 | - 'data' => $flux['data']['texte'] |
|
| 201 | - ]); |
|
| 202 | - } |
|
| 203 | - $flux['data']['texte'] = pipeline( |
|
| 204 | - 'affiche_milieu', |
|
| 205 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 206 | - ); |
|
| 207 | - } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 208 | - $flux['data']['texte'] = pipeline( |
|
| 209 | - 'affiche_pied', |
|
| 210 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 211 | - ); |
|
| 212 | - } elseif ( |
|
| 213 | - strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 214 | - and $objet = basename($fond) |
|
| 215 | - and $objet == substr($fond, 21) |
|
| 216 | - and isset($o[$objet]) |
|
| 217 | - and $o[$objet] |
|
| 218 | - ) { |
|
| 219 | - $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 220 | - $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 221 | - 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 222 | - 'data' => $flux['data']['texte'] |
|
| 223 | - ]); |
|
| 224 | - } |
|
| 225 | - } |
|
| 137 | + static $o = []; |
|
| 138 | + if (is_string($fond = $flux['args']['fond'])) { |
|
| 139 | + $exec = $flux['args']['contexte']['exec'] ?? _request('exec'); |
|
| 140 | + if (!isset($o[$exec])) { |
|
| 141 | + $o[$exec] = trouver_objet_exec($exec); |
|
| 142 | + } |
|
| 143 | + // cas particulier |
|
| 144 | + if ($exec == 'infos_perso') { |
|
| 145 | + $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 146 | + } |
|
| 147 | + $typepage = ($flux['args']['contexte']['type-page'] ?? $exec); |
|
| 148 | + if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 149 | + $flux['data']['texte'] = pipeline( |
|
| 150 | + 'affiche_gauche', |
|
| 151 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 152 | + ); |
|
| 153 | + } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 154 | + include_spip('inc/presentation_mini'); |
|
| 155 | + $flux['data']['texte'] = pipeline( |
|
| 156 | + 'affiche_droite', |
|
| 157 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 158 | + ) . liste_objets_bloques( |
|
| 159 | + $exec, |
|
| 160 | + $flux['args']['contexte'] |
|
| 161 | + ); |
|
| 162 | + } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 163 | + // id non defini sur les formulaire de nouveaux objets |
|
| 164 | + $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 165 | + $flux['data']['texte'] = pipeline( |
|
| 166 | + 'affiche_hierarchie', |
|
| 167 | + ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 168 | + ); |
|
| 169 | + } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 170 | + // Préparation du marqueur affiche_milieu |
|
| 171 | + // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 172 | + $est_page_objet = !empty($o[$exec]['type']); |
|
| 173 | + $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 174 | + $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 175 | + $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 176 | + $flux['data']['texte'], |
|
| 177 | + '<!--affiche_milieu-->', |
|
| 178 | + '<div id=["\']wysiwyg', |
|
| 179 | + $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 180 | + $encapsuler_milieu ? '</div>' : '' |
|
| 181 | + ); |
|
| 182 | + if ( |
|
| 183 | + $o[$exec] |
|
| 184 | + and $objet = $o[$exec]['type'] |
|
| 185 | + and $o[$exec]['edition'] == false |
|
| 186 | + and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 187 | + and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 188 | + ) { |
|
| 189 | + // inserer le formulaire de traduction |
|
| 190 | + $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 191 | + 'prive/objets/editer/traductions', |
|
| 192 | + ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 193 | + ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | + $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 195 | + 'args' => [ |
|
| 196 | + 'contexte' => $flux['args']['contexte'], |
|
| 197 | + 'type' => $objet, |
|
| 198 | + 'id' => $id |
|
| 199 | + ], |
|
| 200 | + 'data' => $flux['data']['texte'] |
|
| 201 | + ]); |
|
| 202 | + } |
|
| 203 | + $flux['data']['texte'] = pipeline( |
|
| 204 | + 'affiche_milieu', |
|
| 205 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 206 | + ); |
|
| 207 | + } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 208 | + $flux['data']['texte'] = pipeline( |
|
| 209 | + 'affiche_pied', |
|
| 210 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 211 | + ); |
|
| 212 | + } elseif ( |
|
| 213 | + strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 214 | + and $objet = basename($fond) |
|
| 215 | + and $objet == substr($fond, 21) |
|
| 216 | + and isset($o[$objet]) |
|
| 217 | + and $o[$objet] |
|
| 218 | + ) { |
|
| 219 | + $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 220 | + $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 221 | + 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 222 | + 'data' => $flux['data']['texte'] |
|
| 223 | + ]); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - return $flux; |
|
| 227 | + return $flux; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -252,36 +252,36 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string { |
| 254 | 254 | |
| 255 | - if ($texte) { |
|
| 256 | - $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 257 | - $marqueur_pos = strpos($texte, $marqueur); |
|
| 258 | - $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 255 | + if ($texte) { |
|
| 256 | + $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 257 | + $marqueur_pos = strpos($texte, $marqueur); |
|
| 258 | + $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 259 | 259 | |
| 260 | - // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 261 | - if ($marqueur_pos === false) { |
|
| 262 | - $texte = preg_replace( |
|
| 263 | - ",$inserer_avant,", |
|
| 264 | - "$full_marqueur\\0", |
|
| 265 | - $texte |
|
| 266 | - ); |
|
| 267 | - // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 268 | - // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 269 | - // Il ne faut donc aucun espace blanc en trop. |
|
| 270 | - } elseif ( |
|
| 271 | - $marqueur_pos !== false |
|
| 272 | - and $encapsuler |
|
| 273 | - and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 274 | - ) { |
|
| 275 | - $texte = substr_replace( |
|
| 276 | - $texte, |
|
| 277 | - $full_marqueur, |
|
| 278 | - $marqueur_pos, |
|
| 279 | - strlen($marqueur) |
|
| 280 | - ); |
|
| 281 | - } |
|
| 282 | - } |
|
| 260 | + // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 261 | + if ($marqueur_pos === false) { |
|
| 262 | + $texte = preg_replace( |
|
| 263 | + ",$inserer_avant,", |
|
| 264 | + "$full_marqueur\\0", |
|
| 265 | + $texte |
|
| 266 | + ); |
|
| 267 | + // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 268 | + // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 269 | + // Il ne faut donc aucun espace blanc en trop. |
|
| 270 | + } elseif ( |
|
| 271 | + $marqueur_pos !== false |
|
| 272 | + and $encapsuler |
|
| 273 | + and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 274 | + ) { |
|
| 275 | + $texte = substr_replace( |
|
| 276 | + $texte, |
|
| 277 | + $full_marqueur, |
|
| 278 | + $marqueur_pos, |
|
| 279 | + strlen($marqueur) |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - return $texte; |
|
| 284 | + return $texte; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -292,23 +292,23 @@ discard block |
||
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | 294 | function f_queue_affiche_milieu($flux) { |
| 295 | - $args = $flux['args']; |
|
| 296 | - $res = ''; |
|
| 297 | - foreach ($args as $key => $arg) { |
|
| 298 | - if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 299 | - $objet = preg_replace(',^id_,', '', $key); |
|
| 300 | - $res .= recuperer_fond( |
|
| 301 | - 'modeles/object_jobs_list', |
|
| 302 | - ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 303 | - ['ajax' => true] |
|
| 304 | - ); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - if ($res) { |
|
| 308 | - $flux['data'] = $res . $flux['data']; |
|
| 309 | - } |
|
| 295 | + $args = $flux['args']; |
|
| 296 | + $res = ''; |
|
| 297 | + foreach ($args as $key => $arg) { |
|
| 298 | + if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 299 | + $objet = preg_replace(',^id_,', '', $key); |
|
| 300 | + $res .= recuperer_fond( |
|
| 301 | + 'modeles/object_jobs_list', |
|
| 302 | + ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 303 | + ['ajax' => true] |
|
| 304 | + ); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + if ($res) { |
|
| 308 | + $flux['data'] = $res . $flux['data']; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - return $flux; |
|
| 311 | + return $flux; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -322,39 +322,39 @@ discard block |
||
| 322 | 322 | * @return array|bool |
| 323 | 323 | */ |
| 324 | 324 | function trouver_objet_exec(string $exec) { |
| 325 | - static $objet_exec = []; |
|
| 326 | - if (!$exec) { |
|
| 327 | - return false; |
|
| 328 | - } |
|
| 329 | - // cas particulier |
|
| 330 | - if ($exec === 'infos_perso') { |
|
| 331 | - $exec = 'auteur'; |
|
| 332 | - set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 333 | - } |
|
| 334 | - if (!isset($objet_exec[$exec])) { |
|
| 335 | - $objet_exec[$exec] = false; |
|
| 336 | - $infos = lister_tables_objets_sql(); |
|
| 337 | - foreach ($infos as $t => $info) { |
|
| 338 | - if ($exec === $info['url_edit'] and $info['editable']) { |
|
| 339 | - return $objet_exec[$exec] = [ |
|
| 340 | - 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 341 | - 'table_objet_sql' => $t, |
|
| 342 | - 'table' => $info['table_objet'], |
|
| 343 | - 'type' => $info['type'], |
|
| 344 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 345 | - ]; |
|
| 346 | - } |
|
| 347 | - if ($exec === $info['url_voir']) { |
|
| 348 | - return $objet_exec[$exec] = [ |
|
| 349 | - 'edition' => false, |
|
| 350 | - 'table_objet_sql' => $t, |
|
| 351 | - 'table' => $info['table_objet'], |
|
| 352 | - 'type' => $info['type'], |
|
| 353 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 354 | - ]; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - } |
|
| 325 | + static $objet_exec = []; |
|
| 326 | + if (!$exec) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 329 | + // cas particulier |
|
| 330 | + if ($exec === 'infos_perso') { |
|
| 331 | + $exec = 'auteur'; |
|
| 332 | + set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 333 | + } |
|
| 334 | + if (!isset($objet_exec[$exec])) { |
|
| 335 | + $objet_exec[$exec] = false; |
|
| 336 | + $infos = lister_tables_objets_sql(); |
|
| 337 | + foreach ($infos as $t => $info) { |
|
| 338 | + if ($exec === $info['url_edit'] and $info['editable']) { |
|
| 339 | + return $objet_exec[$exec] = [ |
|
| 340 | + 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 341 | + 'table_objet_sql' => $t, |
|
| 342 | + 'table' => $info['table_objet'], |
|
| 343 | + 'type' => $info['type'], |
|
| 344 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 345 | + ]; |
|
| 346 | + } |
|
| 347 | + if ($exec === $info['url_voir']) { |
|
| 348 | + return $objet_exec[$exec] = [ |
|
| 349 | + 'edition' => false, |
|
| 350 | + 'table_objet_sql' => $t, |
|
| 351 | + 'table' => $info['table_objet'], |
|
| 352 | + 'type' => $info['type'], |
|
| 353 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 354 | + ]; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - return $objet_exec[$exec]; |
|
| 359 | + return $objet_exec[$exec]; |
|
| 360 | 360 | } |
@@ -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 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,55 +198,55 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 206 | 206 | |
| 207 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | - $types = [ |
|
| 209 | - 'notice', |
|
| 210 | - 'error', |
|
| 211 | - 'success', |
|
| 212 | - 'info', |
|
| 213 | - ]; |
|
| 214 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | - $type = reset($type); |
|
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 207 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | + $types = [ |
|
| 209 | + 'notice', |
|
| 210 | + 'error', |
|
| 211 | + 'success', |
|
| 212 | + 'info', |
|
| 213 | + ]; |
|
| 214 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | + $type = reset($type); |
|
| 216 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 217 | 217 | |
| 218 | - // Classes |
|
| 219 | - $class_racine = 'msg-alert'; |
|
| 220 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | - $class_alerte = "$class_racine $class"; |
|
| 222 | - $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | - $class_titre = "${class_racine}__heading"; |
|
| 218 | + // Classes |
|
| 219 | + $class_racine = 'msg-alert'; |
|
| 220 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | + $class_alerte = "$class_racine $class"; |
|
| 222 | + $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | + $class_titre = "${class_racine}__heading"; |
|
| 224 | 224 | |
| 225 | - // Titre : markup |
|
| 226 | - $titre = trim($titre); |
|
| 227 | - if (strlen($titre)) { |
|
| 228 | - include_spip('inc/filtres'); |
|
| 229 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | - $titre = wrap($titre, $wrap_tag); |
|
| 234 | - } |
|
| 235 | - // puis on ajoute la classe |
|
| 236 | - $titre = ajouter_class($titre, $class_titre); |
|
| 237 | - } |
|
| 225 | + // Titre : markup |
|
| 226 | + $titre = trim($titre); |
|
| 227 | + if (strlen($titre)) { |
|
| 228 | + include_spip('inc/filtres'); |
|
| 229 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | + $titre = wrap($titre, $wrap_tag); |
|
| 234 | + } |
|
| 235 | + // puis on ajoute la classe |
|
| 236 | + $titre = ajouter_class($titre, $class_titre); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - // Attributs |
|
| 240 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 239 | + // Attributs |
|
| 240 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 243 | 243 | |
| 244 | - $message = |
|
| 245 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | - . $titre |
|
| 247 | - . "<div class=\"$class_texte\">"; |
|
| 244 | + $message = |
|
| 245 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | + . $titre |
|
| 247 | + . "<div class=\"$class_texte\">"; |
|
| 248 | 248 | |
| 249 | - return $message; |
|
| 249 | + return $message; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -260,5 +260,5 @@ discard block |
||
| 260 | 260 | * HTML de fin de l'alerte |
| 261 | 261 | */ |
| 262 | 262 | function message_alerte_fermer(): string { |
| 263 | - return '</div></div>'; |
|
| 263 | + return '</div></div>'; |
|
| 264 | 264 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/config'); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function cvtconf_formulaire_charger($flux) { |
| 35 | - if ( |
|
| 36 | - $form = $flux['args']['form'] |
|
| 37 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | - ) { |
|
| 39 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | - include_spip('inc/autoriser'); |
|
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 35 | + if ( |
|
| 36 | + $form = $flux['args']['form'] |
|
| 37 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | + ) { |
|
| 39 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | + include_spip('inc/autoriser'); |
|
| 41 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | - $flux['data']['editable'] = true; |
|
| 49 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | - if (!_AJAX) { |
|
| 51 | - var_dump($flux['data']); |
|
| 52 | - } |
|
| 53 | - // reinjecter pour la trace au traitement |
|
| 54 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 45 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | + $flux['data']['editable'] = true; |
|
| 49 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | + if (!_AJAX) { |
|
| 51 | + var_dump($flux['data']); |
|
| 52 | + } |
|
| 53 | + // reinjecter pour la trace au traitement |
|
| 54 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $flux; |
|
| 59 | + return $flux; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | function cvtconf_formulaire_traiter($flux) { |
| 69 | - if ( |
|
| 70 | - $form = $flux['args']['form'] |
|
| 71 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | - and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | - ) { |
|
| 74 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | - } |
|
| 69 | + if ( |
|
| 70 | + $form = $flux['args']['form'] |
|
| 71 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | + and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | + ) { |
|
| 74 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $flux; |
|
| 78 | + return $flux; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | 93 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 94 | - $valeurs = []; |
|
| 95 | - // charger les valeurs |
|
| 96 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | - // qui prend alors la main sur l'auto detection |
|
| 98 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | - $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 100 | - } |
|
| 101 | - $valeurs = pipeline( |
|
| 102 | - 'formulaire_charger', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | - 'data' => $valeurs |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - // ne pas stocker editable ! |
|
| 109 | - unset($valeurs['editable']); |
|
| 94 | + $valeurs = []; |
|
| 95 | + // charger les valeurs |
|
| 96 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | + // qui prend alors la main sur l'auto detection |
|
| 98 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | + $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 100 | + } |
|
| 101 | + $valeurs = pipeline( |
|
| 102 | + 'formulaire_charger', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | + 'data' => $valeurs |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + // ne pas stocker editable ! |
|
| 109 | + unset($valeurs['editable']); |
|
| 110 | 110 | |
| 111 | - // recuperer les valeurs postees |
|
| 112 | - $store = []; |
|
| 113 | - foreach ($valeurs as $k => $v) { |
|
| 114 | - if (substr($k, 0, 1) !== '_') { |
|
| 115 | - $store[$k] = _request($k); |
|
| 116 | - } |
|
| 117 | - } |
|
| 111 | + // recuperer les valeurs postees |
|
| 112 | + $store = []; |
|
| 113 | + foreach ($valeurs as $k => $v) { |
|
| 114 | + if (substr($k, 0, 1) !== '_') { |
|
| 115 | + $store[$k] = _request($k); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -132,31 +132,31 @@ discard block |
||
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | 134 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 135 | - // stocker en base |
|
| 136 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | - $casier = substr($form, 11); |
|
| 138 | - $table = 'meta'; |
|
| 139 | - $prefixe = ''; |
|
| 140 | - $stockage = ''; |
|
| 135 | + // stocker en base |
|
| 136 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | + $casier = substr($form, 11); |
|
| 138 | + $table = 'meta'; |
|
| 139 | + $prefixe = ''; |
|
| 140 | + $stockage = ''; |
|
| 141 | 141 | |
| 142 | - if (isset($valeurs['_meta_casier'])) { |
|
| 143 | - $casier = $valeurs['_meta_casier']; |
|
| 144 | - } |
|
| 145 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | - } |
|
| 148 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | - } |
|
| 142 | + if (isset($valeurs['_meta_casier'])) { |
|
| 143 | + $casier = $valeurs['_meta_casier']; |
|
| 144 | + } |
|
| 145 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | + } |
|
| 148 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | - if (isset($valeurs['_meta_table'])) { |
|
| 155 | - $table = $valeurs['_meta_table']; |
|
| 156 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | - } |
|
| 152 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | + if (isset($valeurs['_meta_table'])) { |
|
| 155 | + $table = $valeurs['_meta_table']; |
|
| 156 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,48 +167,48 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function cvtconf_formulaires_configurer_recense($form) { |
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | - and lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | + and lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - $n = extraire_attribut($b, 'name') |
|
| 193 | - and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + $n = extraire_attribut($b, 'name') |
|
| 193 | + and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach ($valeurs as $k => $v) { |
|
| 265 | - if (substr($k, 0, 1) !== '_') { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -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', 2_097_152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 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 | - ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + ($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,89 +68,89 @@ 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 | - ['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 ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - spip_log("copie_locale : recuperation $source sur $localrac OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 122 | - } |
|
| 123 | - if (!$res or !$res['length']) { |
|
| 124 | - // si $t c'est sans doute juste un not-modified-since |
|
| 125 | - return $t ? $local : false; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // si on retrouve l'extension |
|
| 129 | - if ( |
|
| 130 | - !empty($res['headers']) |
|
| 131 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 132 | - ) { |
|
| 133 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 134 | - $sanitizer($localrac); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // pour une eventuelle indexation |
|
| 139 | - pipeline( |
|
| 140 | - 'post_edition', |
|
| 141 | - [ |
|
| 142 | - 'args' => [ |
|
| 143 | - 'operation' => 'copie_locale', |
|
| 144 | - 'source' => $source, |
|
| 145 | - 'fichier' => $local, |
|
| 146 | - 'http_res' => $res['length'], |
|
| 147 | - ], |
|
| 148 | - 'data' => null |
|
| 149 | - ] |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - 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 | + ['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 ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + spip_log("copie_locale : recuperation $source sur $localrac OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 122 | + } |
|
| 123 | + if (!$res or !$res['length']) { |
|
| 124 | + // si $t c'est sans doute juste un not-modified-since |
|
| 125 | + return $t ? $local : false; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // si on retrouve l'extension |
|
| 129 | + if ( |
|
| 130 | + !empty($res['headers']) |
|
| 131 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 132 | + ) { |
|
| 133 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 134 | + $sanitizer($localrac); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // pour une eventuelle indexation |
|
| 139 | + pipeline( |
|
| 140 | + 'post_edition', |
|
| 141 | + [ |
|
| 142 | + 'args' => [ |
|
| 143 | + 'operation' => 'copie_locale', |
|
| 144 | + 'source' => $source, |
|
| 145 | + 'fichier' => $local, |
|
| 146 | + 'http_res' => $res['length'], |
|
| 147 | + ], |
|
| 148 | + 'data' => null |
|
| 149 | + ] |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $local; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,99 +165,99 @@ discard block |
||
| 165 | 165 | * url ou false en cas d'echec |
| 166 | 166 | */ |
| 167 | 167 | function valider_url_distante($url, $known_hosts = []) { |
| 168 | - if (!function_exists('protocole_verifier')) { |
|
| 169 | - include_spip('inc/filtres_mini'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $parsed_url = parse_url($url); |
|
| 177 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 182 | - return false; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 186 | - return false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!is_array($known_hosts)) { |
|
| 190 | - $known_hosts = [$known_hosts]; |
|
| 191 | - } |
|
| 192 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 193 | - $known_hosts[] = url_de_base(); |
|
| 194 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 195 | - |
|
| 196 | - $is_known_host = false; |
|
| 197 | - foreach ($known_hosts as $known_host) { |
|
| 198 | - $parse_known = parse_url($known_host); |
|
| 199 | - if ( |
|
| 200 | - $parse_known |
|
| 201 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 202 | - ) { |
|
| 203 | - $is_known_host = true; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!$is_known_host) { |
|
| 209 | - $host = trim($parsed_url['host'], '.'); |
|
| 210 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 211 | - $ip = gethostbyname($host); |
|
| 212 | - if ($ip === $host) { |
|
| 213 | - // Error condition for gethostbyname() |
|
| 214 | - $ip = false; |
|
| 215 | - } |
|
| 216 | - if ($records = dns_get_record($host)) { |
|
| 217 | - foreach ($records as $record) { |
|
| 218 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 219 | - // se fasse sur la meme IP |
|
| 220 | - if ($record['ttl'] < 10) { |
|
| 221 | - $ip = false; |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - else { |
|
| 227 | - $ip = false; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - if ($ip) { |
|
| 231 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if (empty($parsed_url['port'])) { |
|
| 238 | - return $url; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $port = $parsed_url['port']; |
|
| 242 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 243 | - return $url; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($is_known_host) { |
|
| 247 | - foreach ($known_hosts as $known_host) { |
|
| 248 | - $parse_known = parse_url($known_host); |
|
| 249 | - if ( |
|
| 250 | - $parse_known |
|
| 251 | - and !empty($parse_known['port']) |
|
| 252 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 253 | - and $parse_known['port'] == $port |
|
| 254 | - ) { |
|
| 255 | - return $url; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return false; |
|
| 168 | + if (!function_exists('protocole_verifier')) { |
|
| 169 | + include_spip('inc/filtres_mini'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $parsed_url = parse_url($url); |
|
| 177 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 186 | + return false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!is_array($known_hosts)) { |
|
| 190 | + $known_hosts = [$known_hosts]; |
|
| 191 | + } |
|
| 192 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 193 | + $known_hosts[] = url_de_base(); |
|
| 194 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 195 | + |
|
| 196 | + $is_known_host = false; |
|
| 197 | + foreach ($known_hosts as $known_host) { |
|
| 198 | + $parse_known = parse_url($known_host); |
|
| 199 | + if ( |
|
| 200 | + $parse_known |
|
| 201 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 202 | + ) { |
|
| 203 | + $is_known_host = true; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!$is_known_host) { |
|
| 209 | + $host = trim($parsed_url['host'], '.'); |
|
| 210 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 211 | + $ip = gethostbyname($host); |
|
| 212 | + if ($ip === $host) { |
|
| 213 | + // Error condition for gethostbyname() |
|
| 214 | + $ip = false; |
|
| 215 | + } |
|
| 216 | + if ($records = dns_get_record($host)) { |
|
| 217 | + foreach ($records as $record) { |
|
| 218 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 219 | + // se fasse sur la meme IP |
|
| 220 | + if ($record['ttl'] < 10) { |
|
| 221 | + $ip = false; |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + else { |
|
| 227 | + $ip = false; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + if ($ip) { |
|
| 231 | + if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if (empty($parsed_url['port'])) { |
|
| 238 | + return $url; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $port = $parsed_url['port']; |
|
| 242 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 243 | + return $url; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($is_known_host) { |
|
| 247 | + foreach ($known_hosts as $known_host) { |
|
| 248 | + $parse_known = parse_url($known_host); |
|
| 249 | + if ( |
|
| 250 | + $parse_known |
|
| 251 | + and !empty($parse_known['port']) |
|
| 252 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 253 | + and $parse_known['port'] == $port |
|
| 254 | + ) { |
|
| 255 | + return $url; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return false; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -277,86 +277,86 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function prepare_donnees_post($donnees, $boundary = '') { |
| 279 | 279 | |
| 280 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 281 | - // pour un appel soap par exemple |
|
| 282 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 283 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 284 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 285 | - $entete = ''; |
|
| 286 | - // on repasse tous les \r\n et \r en simples \n |
|
| 287 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 288 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 289 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 290 | - $p = strpos($donnees, "\n\n"); |
|
| 291 | - if ($p !== false) { |
|
| 292 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 293 | - $donnees = substr($donnees, $p + 2); |
|
| 294 | - } |
|
| 295 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 296 | - } else { |
|
| 297 | - /* boundary automatique */ |
|
| 298 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 299 | - if ($boundary === '') { |
|
| 300 | - $taille = 0; |
|
| 301 | - foreach ($donnees as $cle => $valeur) { |
|
| 302 | - if (is_array($valeur)) { |
|
| 303 | - foreach ($valeur as $val2) { |
|
| 304 | - $taille += strlen($val2); |
|
| 305 | - } |
|
| 306 | - } else { |
|
| 307 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 308 | - $taille += strlen($valeur); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - if ($taille > 500) { |
|
| 312 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 317 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 318 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 319 | - $chaine = ''; |
|
| 320 | - if (is_array($donnees)) { |
|
| 321 | - foreach ($donnees as $cle => $valeur) { |
|
| 322 | - if (is_array($valeur)) { |
|
| 323 | - foreach ($valeur as $val2) { |
|
| 324 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 325 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 326 | - $chaine .= "\r\n"; |
|
| 327 | - $chaine .= $val2; |
|
| 328 | - } |
|
| 329 | - } else { |
|
| 330 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 331 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 332 | - $chaine .= "\r\n"; |
|
| 333 | - $chaine .= $valeur; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 337 | - } |
|
| 338 | - } else { |
|
| 339 | - // fabrique une chaine HTTP simple pour un POST |
|
| 340 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 341 | - $chaine = []; |
|
| 342 | - if (is_array($donnees)) { |
|
| 343 | - foreach ($donnees as $cle => $valeur) { |
|
| 344 | - if (is_array($valeur)) { |
|
| 345 | - foreach ($valeur as $val2) { |
|
| 346 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 347 | - } |
|
| 348 | - } else { |
|
| 349 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - $chaine = implode('&', $chaine); |
|
| 353 | - } else { |
|
| 354 | - $chaine = $donnees; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - return [$entete, $chaine]; |
|
| 280 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 281 | + // pour un appel soap par exemple |
|
| 282 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 283 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 284 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 285 | + $entete = ''; |
|
| 286 | + // on repasse tous les \r\n et \r en simples \n |
|
| 287 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 288 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 289 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 290 | + $p = strpos($donnees, "\n\n"); |
|
| 291 | + if ($p !== false) { |
|
| 292 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 293 | + $donnees = substr($donnees, $p + 2); |
|
| 294 | + } |
|
| 295 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 296 | + } else { |
|
| 297 | + /* boundary automatique */ |
|
| 298 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 299 | + if ($boundary === '') { |
|
| 300 | + $taille = 0; |
|
| 301 | + foreach ($donnees as $cle => $valeur) { |
|
| 302 | + if (is_array($valeur)) { |
|
| 303 | + foreach ($valeur as $val2) { |
|
| 304 | + $taille += strlen($val2); |
|
| 305 | + } |
|
| 306 | + } else { |
|
| 307 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 308 | + $taille += strlen($valeur); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + if ($taille > 500) { |
|
| 312 | + $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 317 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 318 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 319 | + $chaine = ''; |
|
| 320 | + if (is_array($donnees)) { |
|
| 321 | + foreach ($donnees as $cle => $valeur) { |
|
| 322 | + if (is_array($valeur)) { |
|
| 323 | + foreach ($valeur as $val2) { |
|
| 324 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 325 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 326 | + $chaine .= "\r\n"; |
|
| 327 | + $chaine .= $val2; |
|
| 328 | + } |
|
| 329 | + } else { |
|
| 330 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 331 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 332 | + $chaine .= "\r\n"; |
|
| 333 | + $chaine .= $valeur; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 337 | + } |
|
| 338 | + } else { |
|
| 339 | + // fabrique une chaine HTTP simple pour un POST |
|
| 340 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 341 | + $chaine = []; |
|
| 342 | + if (is_array($donnees)) { |
|
| 343 | + foreach ($donnees as $cle => $valeur) { |
|
| 344 | + if (is_array($valeur)) { |
|
| 345 | + foreach ($valeur as $val2) { |
|
| 346 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 347 | + } |
|
| 348 | + } else { |
|
| 349 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + $chaine = implode('&', $chaine); |
|
| 353 | + } else { |
|
| 354 | + $chaine = $donnees; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + return [$entete, $chaine]; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | function url_to_ascii($url_idn) { |
| 372 | 372 | |
| 373 | - if ($parts = parse_url($url_idn)) { |
|
| 374 | - $host = $parts['host']; |
|
| 375 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 376 | - include_spip('inc/idna_convert.class'); |
|
| 377 | - $IDN = new idna_convert(); |
|
| 378 | - $host_ascii = $IDN->encode($host); |
|
| 379 | - $url_idn = explode($host, $url_idn, 2); |
|
| 380 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 381 | - } |
|
| 382 | - // et on urlencode les char utf si besoin dans le path |
|
| 383 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - return $url_idn; |
|
| 373 | + if ($parts = parse_url($url_idn)) { |
|
| 374 | + $host = $parts['host']; |
|
| 375 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 376 | + include_spip('inc/idna_convert.class'); |
|
| 377 | + $IDN = new idna_convert(); |
|
| 378 | + $host_ascii = $IDN->encode($host); |
|
| 379 | + $url_idn = explode($host, $url_idn, 2); |
|
| 380 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 381 | + } |
|
| 382 | + // et on urlencode les char utf si besoin dans le path |
|
| 383 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + return $url_idn; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -424,197 +424,197 @@ discard block |
||
| 424 | 424 | * string file : nom du fichier si enregistre dans un fichier |
| 425 | 425 | */ |
| 426 | 426 | function recuperer_url($url, $options = []) { |
| 427 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 428 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 429 | - $default = [ |
|
| 430 | - 'transcoder' => false, |
|
| 431 | - 'methode' => 'GET', |
|
| 432 | - 'taille_max' => null, |
|
| 433 | - 'headers' => [], |
|
| 434 | - 'datas' => '', |
|
| 435 | - 'boundary' => '', |
|
| 436 | - 'refuser_gz' => false, |
|
| 437 | - 'if_modified_since' => '', |
|
| 438 | - 'uri_referer' => '', |
|
| 439 | - 'file' => '', |
|
| 440 | - 'follow_location' => 10, |
|
| 441 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 442 | - ]; |
|
| 443 | - $options = array_merge($default, $options); |
|
| 444 | - // copier directement dans un fichier ? |
|
| 445 | - $copy = $options['file']; |
|
| 446 | - |
|
| 447 | - if ($options['methode'] == 'HEAD') { |
|
| 448 | - $options['taille_max'] = 0; |
|
| 449 | - } |
|
| 450 | - if (is_null($options['taille_max'])) { |
|
| 451 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - // Ajout des en-têtes spécifiques si besoin |
|
| 456 | - $head_add = ''; |
|
| 457 | - if (!empty($options['headers'])) { |
|
| 458 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 459 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 460 | - } |
|
| 461 | - // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 462 | - unset($options['headers']); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - if (!empty($options['datas'])) { |
|
| 466 | - [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 467 | - $head .= $head_add; |
|
| 468 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 469 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 470 | - } |
|
| 471 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 472 | - if ( |
|
| 473 | - strlen($postdata) |
|
| 474 | - and !$methode_demandee |
|
| 475 | - ) { |
|
| 476 | - $options['methode'] = 'POST'; |
|
| 477 | - } |
|
| 478 | - } elseif ($head_add) { |
|
| 479 | - $options['datas'] = $head_add . "\r\n"; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 483 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 484 | - if (!tester_url_absolue($url)) { |
|
| 485 | - $url = 'http://' . $url; |
|
| 486 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 487 | - $url = 'http:' . $url; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $url = url_to_ascii($url); |
|
| 491 | - |
|
| 492 | - $result = [ |
|
| 493 | - 'status' => 0, |
|
| 494 | - 'headers' => '', |
|
| 495 | - 'page' => '', |
|
| 496 | - 'length' => 0, |
|
| 497 | - 'last_modified' => '', |
|
| 498 | - 'location' => '', |
|
| 499 | - 'url' => $url |
|
| 500 | - ]; |
|
| 501 | - |
|
| 502 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 503 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 504 | - |
|
| 505 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 506 | - [$handle, $fopen] = init_http( |
|
| 507 | - $options['methode'], |
|
| 508 | - $url, |
|
| 509 | - $refuser_gz, |
|
| 510 | - $options['uri_referer'], |
|
| 511 | - $options['datas'], |
|
| 512 | - $options['version_http'], |
|
| 513 | - $options['if_modified_since'] |
|
| 514 | - ); |
|
| 515 | - if (!$handle) { |
|
| 516 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 517 | - |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 522 | - // et recuperer les en-tetes de reponses |
|
| 523 | - if (!$fopen) { |
|
| 524 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 525 | - if (!$res) { |
|
| 526 | - fclose($handle); |
|
| 527 | - $t = @parse_url($url); |
|
| 528 | - $host = $t['host']; |
|
| 529 | - // Chinoisierie inexplicable pour contrer |
|
| 530 | - // les actions liberticides de l'empire du milieu |
|
| 531 | - if ( |
|
| 532 | - !need_proxy($host) |
|
| 533 | - and $res = @file_get_contents($url) |
|
| 534 | - ) { |
|
| 535 | - $result['length'] = strlen($res); |
|
| 536 | - if ($copy) { |
|
| 537 | - ecrire_fichier($copy, $res); |
|
| 538 | - $result['file'] = $copy; |
|
| 539 | - } else { |
|
| 540 | - $result['page'] = $res; |
|
| 541 | - } |
|
| 542 | - $res = [ |
|
| 543 | - 'status' => 200, |
|
| 544 | - ]; |
|
| 545 | - } else { |
|
| 546 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 550 | - $options['follow_location']--; |
|
| 551 | - fclose($handle); |
|
| 552 | - include_spip('inc/filtres'); |
|
| 553 | - $url = suivre_lien($url, $res['location']); |
|
| 554 | - spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 555 | - |
|
| 556 | - return recuperer_url($url, $options); |
|
| 557 | - } elseif ($res['status'] !== 200) { |
|
| 558 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 559 | - } |
|
| 560 | - $result['status'] = $res['status']; |
|
| 561 | - if (isset($res['headers'])) { |
|
| 562 | - $result['headers'] = $res['headers']; |
|
| 563 | - } |
|
| 564 | - if (isset($res['last_modified'])) { |
|
| 565 | - $result['last_modified'] = $res['last_modified']; |
|
| 566 | - } |
|
| 567 | - if (isset($res['location'])) { |
|
| 568 | - $result['location'] = $res['location']; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // on ne veut que les entetes |
|
| 573 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 574 | - return $result; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 579 | - // sinon la memoire explose pour les gros flux |
|
| 580 | - |
|
| 581 | - $gz = false; |
|
| 582 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 583 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 587 | - if (!$result['length']) { |
|
| 588 | - $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 589 | - fclose($handle); |
|
| 590 | - if ($copy) { |
|
| 591 | - $result['length'] = $res; |
|
| 592 | - $result['file'] = $copy; |
|
| 593 | - } elseif ($res) { |
|
| 594 | - $result['page'] = &$res; |
|
| 595 | - $result['length'] = strlen($result['page']); |
|
| 596 | - } |
|
| 597 | - if (!$result['status']) { |
|
| 598 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (!$result['page']) { |
|
| 602 | - return $result; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // Decompresser au besoin |
|
| 606 | - if ($gz) { |
|
| 607 | - $result['page'] = implode('', gzfile($gz)); |
|
| 608 | - supprimer_fichier($gz); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - // Faut-il l'importer dans notre charset local ? |
|
| 612 | - if ($options['transcoder']) { |
|
| 613 | - include_spip('inc/charsets'); |
|
| 614 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $result; |
|
| 427 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 428 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 429 | + $default = [ |
|
| 430 | + 'transcoder' => false, |
|
| 431 | + 'methode' => 'GET', |
|
| 432 | + 'taille_max' => null, |
|
| 433 | + 'headers' => [], |
|
| 434 | + 'datas' => '', |
|
| 435 | + 'boundary' => '', |
|
| 436 | + 'refuser_gz' => false, |
|
| 437 | + 'if_modified_since' => '', |
|
| 438 | + 'uri_referer' => '', |
|
| 439 | + 'file' => '', |
|
| 440 | + 'follow_location' => 10, |
|
| 441 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 442 | + ]; |
|
| 443 | + $options = array_merge($default, $options); |
|
| 444 | + // copier directement dans un fichier ? |
|
| 445 | + $copy = $options['file']; |
|
| 446 | + |
|
| 447 | + if ($options['methode'] == 'HEAD') { |
|
| 448 | + $options['taille_max'] = 0; |
|
| 449 | + } |
|
| 450 | + if (is_null($options['taille_max'])) { |
|
| 451 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + // Ajout des en-têtes spécifiques si besoin |
|
| 456 | + $head_add = ''; |
|
| 457 | + if (!empty($options['headers'])) { |
|
| 458 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 459 | + $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 460 | + } |
|
| 461 | + // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 462 | + unset($options['headers']); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + if (!empty($options['datas'])) { |
|
| 466 | + [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 467 | + $head .= $head_add; |
|
| 468 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 469 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 470 | + } |
|
| 471 | + $options['datas'] = $head . "\r\n" . $postdata; |
|
| 472 | + if ( |
|
| 473 | + strlen($postdata) |
|
| 474 | + and !$methode_demandee |
|
| 475 | + ) { |
|
| 476 | + $options['methode'] = 'POST'; |
|
| 477 | + } |
|
| 478 | + } elseif ($head_add) { |
|
| 479 | + $options['datas'] = $head_add . "\r\n"; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 483 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 484 | + if (!tester_url_absolue($url)) { |
|
| 485 | + $url = 'http://' . $url; |
|
| 486 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 487 | + $url = 'http:' . $url; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $url = url_to_ascii($url); |
|
| 491 | + |
|
| 492 | + $result = [ |
|
| 493 | + 'status' => 0, |
|
| 494 | + 'headers' => '', |
|
| 495 | + 'page' => '', |
|
| 496 | + 'length' => 0, |
|
| 497 | + 'last_modified' => '', |
|
| 498 | + 'location' => '', |
|
| 499 | + 'url' => $url |
|
| 500 | + ]; |
|
| 501 | + |
|
| 502 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 503 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 504 | + |
|
| 505 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 506 | + [$handle, $fopen] = init_http( |
|
| 507 | + $options['methode'], |
|
| 508 | + $url, |
|
| 509 | + $refuser_gz, |
|
| 510 | + $options['uri_referer'], |
|
| 511 | + $options['datas'], |
|
| 512 | + $options['version_http'], |
|
| 513 | + $options['if_modified_since'] |
|
| 514 | + ); |
|
| 515 | + if (!$handle) { |
|
| 516 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 517 | + |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 522 | + // et recuperer les en-tetes de reponses |
|
| 523 | + if (!$fopen) { |
|
| 524 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 525 | + if (!$res) { |
|
| 526 | + fclose($handle); |
|
| 527 | + $t = @parse_url($url); |
|
| 528 | + $host = $t['host']; |
|
| 529 | + // Chinoisierie inexplicable pour contrer |
|
| 530 | + // les actions liberticides de l'empire du milieu |
|
| 531 | + if ( |
|
| 532 | + !need_proxy($host) |
|
| 533 | + and $res = @file_get_contents($url) |
|
| 534 | + ) { |
|
| 535 | + $result['length'] = strlen($res); |
|
| 536 | + if ($copy) { |
|
| 537 | + ecrire_fichier($copy, $res); |
|
| 538 | + $result['file'] = $copy; |
|
| 539 | + } else { |
|
| 540 | + $result['page'] = $res; |
|
| 541 | + } |
|
| 542 | + $res = [ |
|
| 543 | + 'status' => 200, |
|
| 544 | + ]; |
|
| 545 | + } else { |
|
| 546 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 550 | + $options['follow_location']--; |
|
| 551 | + fclose($handle); |
|
| 552 | + include_spip('inc/filtres'); |
|
| 553 | + $url = suivre_lien($url, $res['location']); |
|
| 554 | + spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 555 | + |
|
| 556 | + return recuperer_url($url, $options); |
|
| 557 | + } elseif ($res['status'] !== 200) { |
|
| 558 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 559 | + } |
|
| 560 | + $result['status'] = $res['status']; |
|
| 561 | + if (isset($res['headers'])) { |
|
| 562 | + $result['headers'] = $res['headers']; |
|
| 563 | + } |
|
| 564 | + if (isset($res['last_modified'])) { |
|
| 565 | + $result['last_modified'] = $res['last_modified']; |
|
| 566 | + } |
|
| 567 | + if (isset($res['location'])) { |
|
| 568 | + $result['location'] = $res['location']; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // on ne veut que les entetes |
|
| 573 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 574 | + return $result; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 579 | + // sinon la memoire explose pour les gros flux |
|
| 580 | + |
|
| 581 | + $gz = false; |
|
| 582 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 583 | + $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 587 | + if (!$result['length']) { |
|
| 588 | + $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 589 | + fclose($handle); |
|
| 590 | + if ($copy) { |
|
| 591 | + $result['length'] = $res; |
|
| 592 | + $result['file'] = $copy; |
|
| 593 | + } elseif ($res) { |
|
| 594 | + $result['page'] = &$res; |
|
| 595 | + $result['length'] = strlen($result['page']); |
|
| 596 | + } |
|
| 597 | + if (!$result['status']) { |
|
| 598 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (!$result['page']) { |
|
| 602 | + return $result; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // Decompresser au besoin |
|
| 606 | + if ($gz) { |
|
| 607 | + $result['page'] = implode('', gzfile($gz)); |
|
| 608 | + supprimer_fichier($gz); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + // Faut-il l'importer dans notre charset local ? |
|
| 612 | + if ($options['transcoder']) { |
|
| 613 | + include_spip('inc/charsets'); |
|
| 614 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $result; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -630,73 +630,73 @@ discard block |
||
| 630 | 630 | * @return array|bool|mixed |
| 631 | 631 | */ |
| 632 | 632 | function recuperer_url_cache($url, $options = []) { |
| 633 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 634 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 635 | - } |
|
| 636 | - $default = [ |
|
| 637 | - 'transcoder' => false, |
|
| 638 | - 'methode' => 'GET', |
|
| 639 | - 'taille_max' => null, |
|
| 640 | - 'datas' => '', |
|
| 641 | - 'boundary' => '', |
|
| 642 | - 'refuser_gz' => false, |
|
| 643 | - 'if_modified_since' => '', |
|
| 644 | - 'uri_referer' => '', |
|
| 645 | - 'file' => '', |
|
| 646 | - 'follow_location' => 10, |
|
| 647 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 648 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 649 | - ]; |
|
| 650 | - $options = array_merge($default, $options); |
|
| 651 | - |
|
| 652 | - // cas ou il n'est pas possible de cacher |
|
| 653 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 654 | - return recuperer_url($url, $options); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 658 | - static $errors = []; |
|
| 659 | - if (isset($errors[$url])) { |
|
| 660 | - return $errors[$url]; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $sig = $options; |
|
| 664 | - unset($sig['if_modified_since']); |
|
| 665 | - unset($sig['delai_cache']); |
|
| 666 | - $sig['url'] = $url; |
|
| 667 | - |
|
| 668 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 669 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 670 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 671 | - $cache = "$sub$cache"; |
|
| 672 | - |
|
| 673 | - $res = false; |
|
| 674 | - $is_cached = file_exists($cache); |
|
| 675 | - if ( |
|
| 676 | - $is_cached |
|
| 677 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 678 | - ) { |
|
| 679 | - lire_fichier($cache, $res); |
|
| 680 | - if ($res = unserialize($res)) { |
|
| 681 | - // mettre le last_modified et le status=304 ? |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - if (!$res) { |
|
| 685 | - $res = recuperer_url($url, $options); |
|
| 686 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 687 | - if (!$res) { |
|
| 688 | - if ($is_cached) { |
|
| 689 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 690 | - lire_fichier($cache, $res); |
|
| 691 | - $res = unserialize($res); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return $errors[$url] = $res; |
|
| 695 | - } |
|
| 696 | - ecrire_fichier($cache, serialize($res)); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return $res; |
|
| 633 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 634 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 635 | + } |
|
| 636 | + $default = [ |
|
| 637 | + 'transcoder' => false, |
|
| 638 | + 'methode' => 'GET', |
|
| 639 | + 'taille_max' => null, |
|
| 640 | + 'datas' => '', |
|
| 641 | + 'boundary' => '', |
|
| 642 | + 'refuser_gz' => false, |
|
| 643 | + 'if_modified_since' => '', |
|
| 644 | + 'uri_referer' => '', |
|
| 645 | + 'file' => '', |
|
| 646 | + 'follow_location' => 10, |
|
| 647 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 648 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 649 | + ]; |
|
| 650 | + $options = array_merge($default, $options); |
|
| 651 | + |
|
| 652 | + // cas ou il n'est pas possible de cacher |
|
| 653 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 654 | + return recuperer_url($url, $options); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 658 | + static $errors = []; |
|
| 659 | + if (isset($errors[$url])) { |
|
| 660 | + return $errors[$url]; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $sig = $options; |
|
| 664 | + unset($sig['if_modified_since']); |
|
| 665 | + unset($sig['delai_cache']); |
|
| 666 | + $sig['url'] = $url; |
|
| 667 | + |
|
| 668 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 669 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 670 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 671 | + $cache = "$sub$cache"; |
|
| 672 | + |
|
| 673 | + $res = false; |
|
| 674 | + $is_cached = file_exists($cache); |
|
| 675 | + if ( |
|
| 676 | + $is_cached |
|
| 677 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 678 | + ) { |
|
| 679 | + lire_fichier($cache, $res); |
|
| 680 | + if ($res = unserialize($res)) { |
|
| 681 | + // mettre le last_modified et le status=304 ? |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + if (!$res) { |
|
| 685 | + $res = recuperer_url($url, $options); |
|
| 686 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 687 | + if (!$res) { |
|
| 688 | + if ($is_cached) { |
|
| 689 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 690 | + lire_fichier($cache, $res); |
|
| 691 | + $res = unserialize($res); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return $errors[$url] = $res; |
|
| 695 | + } |
|
| 696 | + ecrire_fichier($cache, serialize($res)); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return $res; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -714,42 +714,42 @@ discard block |
||
| 714 | 714 | * string contenu de la resource |
| 715 | 715 | */ |
| 716 | 716 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 717 | - $tmpfile = null; |
|
| 718 | - $taille = 0; |
|
| 719 | - $result = ''; |
|
| 720 | - $fp = false; |
|
| 721 | - if ($fichier) { |
|
| 722 | - include_spip('inc/acces'); |
|
| 723 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 724 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 725 | - if (!$fp and file_exists($fichier)) { |
|
| 726 | - return filesize($fichier); |
|
| 727 | - } |
|
| 728 | - if (!$fp) { |
|
| 729 | - return false; |
|
| 730 | - } |
|
| 731 | - $result = 0; // on renvoie la taille du fichier |
|
| 732 | - } |
|
| 733 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 734 | - $res = fread($handle, 16384); |
|
| 735 | - $taille += strlen($res); |
|
| 736 | - if ($fp) { |
|
| 737 | - fwrite($fp, $res); |
|
| 738 | - $result = $taille; |
|
| 739 | - } else { |
|
| 740 | - $result .= $res; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - if ($fp) { |
|
| 744 | - spip_fclose_unlock($fp); |
|
| 745 | - spip_unlink($fichier); |
|
| 746 | - @rename($tmpfile, $fichier); |
|
| 747 | - if (!file_exists($fichier)) { |
|
| 748 | - return false; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - return $result; |
|
| 717 | + $tmpfile = null; |
|
| 718 | + $taille = 0; |
|
| 719 | + $result = ''; |
|
| 720 | + $fp = false; |
|
| 721 | + if ($fichier) { |
|
| 722 | + include_spip('inc/acces'); |
|
| 723 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 724 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 725 | + if (!$fp and file_exists($fichier)) { |
|
| 726 | + return filesize($fichier); |
|
| 727 | + } |
|
| 728 | + if (!$fp) { |
|
| 729 | + return false; |
|
| 730 | + } |
|
| 731 | + $result = 0; // on renvoie la taille du fichier |
|
| 732 | + } |
|
| 733 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 734 | + $res = fread($handle, 16384); |
|
| 735 | + $taille += strlen($res); |
|
| 736 | + if ($fp) { |
|
| 737 | + fwrite($fp, $res); |
|
| 738 | + $result = $taille; |
|
| 739 | + } else { |
|
| 740 | + $result .= $res; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + if ($fp) { |
|
| 744 | + spip_fclose_unlock($fp); |
|
| 745 | + spip_unlink($fichier); |
|
| 746 | + @rename($tmpfile, $fichier); |
|
| 747 | + if (!file_exists($fichier)) { |
|
| 748 | + return false; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + return $result; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -771,35 +771,35 @@ discard block |
||
| 771 | 771 | * string location |
| 772 | 772 | */ |
| 773 | 773 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 774 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 775 | - |
|
| 776 | - $s = @trim(fgets($handle, 16384)); |
|
| 777 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - $result['status'] = intval($r[1]); |
|
| 781 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 782 | - $result['headers'][] = $s . "\n"; |
|
| 783 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 784 | - [, $d, $v] = $r; |
|
| 785 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 786 | - $result['location'] = $v; |
|
| 787 | - } elseif ($d == 'Last-Modified') { |
|
| 788 | - $result['last_modified'] = strtotime($v); |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - if ( |
|
| 792 | - $if_modified_since |
|
| 793 | - and $result['last_modified'] |
|
| 794 | - and $if_modified_since > $result['last_modified'] |
|
| 795 | - and $result['status'] == 200 |
|
| 796 | - ) { |
|
| 797 | - $result['status'] = 304; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - $result['headers'] = implode('', $result['headers']); |
|
| 801 | - |
|
| 802 | - return $result; |
|
| 774 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 775 | + |
|
| 776 | + $s = @trim(fgets($handle, 16384)); |
|
| 777 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + $result['status'] = intval($r[1]); |
|
| 781 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 782 | + $result['headers'][] = $s . "\n"; |
|
| 783 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 784 | + [, $d, $v] = $r; |
|
| 785 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 786 | + $result['location'] = $v; |
|
| 787 | + } elseif ($d == 'Last-Modified') { |
|
| 788 | + $result['last_modified'] = strtotime($v); |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + if ( |
|
| 792 | + $if_modified_since |
|
| 793 | + and $result['last_modified'] |
|
| 794 | + and $if_modified_since > $result['last_modified'] |
|
| 795 | + and $result['status'] == 200 |
|
| 796 | + ) { |
|
| 797 | + $result['status'] = 304; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + $result['headers'] = implode('', $result['headers']); |
|
| 801 | + |
|
| 802 | + return $result; |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /** |
@@ -821,22 +821,22 @@ discard block |
||
| 821 | 821 | * Nom du fichier pour copie locale |
| 822 | 822 | **/ |
| 823 | 823 | function nom_fichier_copie_locale($source, $extension) { |
| 824 | - include_spip('inc/documents'); |
|
| 824 | + include_spip('inc/documents'); |
|
| 825 | 825 | |
| 826 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 827 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 826 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 827 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 828 | 828 | |
| 829 | - // on se place tout le temps comme si on etait a la racine |
|
| 830 | - if (_DIR_RACINE) { |
|
| 831 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 832 | - } |
|
| 829 | + // on se place tout le temps comme si on etait a la racine |
|
| 830 | + if (_DIR_RACINE) { |
|
| 831 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | - $m = md5($source); |
|
| 834 | + $m = md5($source); |
|
| 835 | 835 | |
| 836 | - return $d |
|
| 837 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 838 | - . substr($m, 0, 4) |
|
| 839 | - . ".$extension"; |
|
| 836 | + return $d |
|
| 837 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 838 | + . substr($m, 0, 4) |
|
| 839 | + . ".$extension"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -854,70 +854,70 @@ discard block |
||
| 854 | 854 | * Nom du fichier calculé |
| 855 | 855 | **/ |
| 856 | 856 | function fichier_copie_locale($source) { |
| 857 | - // Si c'est deja local pas de souci |
|
| 858 | - if (!tester_url_absolue($source)) { |
|
| 859 | - if (_DIR_RACINE) { |
|
| 860 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - return $source; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 867 | - // a deja ete copie en local avec cette extension |
|
| 868 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 869 | - $path_parts = pathinfo($source); |
|
| 870 | - if (!isset($path_parts['extension'])) { |
|
| 871 | - $path_parts['extension'] = ''; |
|
| 872 | - } |
|
| 873 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 874 | - if ( |
|
| 875 | - $ext |
|
| 876 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 877 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 878 | - and file_exists(_DIR_RACINE . $f) |
|
| 879 | - ) { |
|
| 880 | - return $f; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - // Si c'est deja dans la table des documents, |
|
| 885 | - // ramener le nom de sa copie potentielle |
|
| 886 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 887 | - |
|
| 888 | - if ($ext) { |
|
| 889 | - return nom_fichier_copie_locale($source, $ext); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 893 | - // et si il n'aurait pas deja ete rapatrie |
|
| 894 | - |
|
| 895 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 896 | - |
|
| 897 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 898 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 899 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 900 | - return $f; |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - // Ping pour voir si son extension est connue et autorisee |
|
| 905 | - // avec mise en cache du resultat du ping |
|
| 906 | - |
|
| 907 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 908 | - if ( |
|
| 909 | - !@file_exists($cache) |
|
| 910 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 911 | - or _request('var_mode') === 'recalcul' |
|
| 912 | - ) { |
|
| 913 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 914 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 915 | - } |
|
| 916 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 917 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 918 | - return nom_fichier_copie_locale($source, $ext); |
|
| 919 | - } |
|
| 920 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 857 | + // Si c'est deja local pas de souci |
|
| 858 | + if (!tester_url_absolue($source)) { |
|
| 859 | + if (_DIR_RACINE) { |
|
| 860 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + return $source; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 867 | + // a deja ete copie en local avec cette extension |
|
| 868 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 869 | + $path_parts = pathinfo($source); |
|
| 870 | + if (!isset($path_parts['extension'])) { |
|
| 871 | + $path_parts['extension'] = ''; |
|
| 872 | + } |
|
| 873 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 874 | + if ( |
|
| 875 | + $ext |
|
| 876 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 877 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 878 | + and file_exists(_DIR_RACINE . $f) |
|
| 879 | + ) { |
|
| 880 | + return $f; |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + // Si c'est deja dans la table des documents, |
|
| 885 | + // ramener le nom de sa copie potentielle |
|
| 886 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 887 | + |
|
| 888 | + if ($ext) { |
|
| 889 | + return nom_fichier_copie_locale($source, $ext); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 893 | + // et si il n'aurait pas deja ete rapatrie |
|
| 894 | + |
|
| 895 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 896 | + |
|
| 897 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 898 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 899 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 900 | + return $f; |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + // Ping pour voir si son extension est connue et autorisee |
|
| 905 | + // avec mise en cache du resultat du ping |
|
| 906 | + |
|
| 907 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 908 | + if ( |
|
| 909 | + !@file_exists($cache) |
|
| 910 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 911 | + or _request('var_mode') === 'recalcul' |
|
| 912 | + ) { |
|
| 913 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 914 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 915 | + } |
|
| 916 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 917 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 918 | + return nom_fichier_copie_locale($source, $ext); |
|
| 919 | + } |
|
| 920 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | |
@@ -945,97 +945,97 @@ discard block |
||
| 945 | 945 | **/ |
| 946 | 946 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 947 | 947 | |
| 948 | - // pas la peine de perdre son temps |
|
| 949 | - if (!tester_url_absolue($source)) { |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - # charger les alias des types mime |
|
| 954 | - include_spip('base/typedoc'); |
|
| 955 | - |
|
| 956 | - $a = []; |
|
| 957 | - $mime_type = ''; |
|
| 958 | - // On va directement charger le debut des images et des fichiers html, |
|
| 959 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 960 | - // ca echoue l'utilisateur devra les entrer... |
|
| 961 | - $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 962 | - $headers = $reponse['headers'] ?? ''; |
|
| 963 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 964 | - if ($headers) { |
|
| 965 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 966 | - return false; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - $a['extension'] = $extension; |
|
| 970 | - |
|
| 971 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 972 | - $a['taille'] = intval($regs[1]); |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - // Echec avec HEAD, on tente avec GET |
|
| 977 | - if (!$a and !$max) { |
|
| 978 | - spip_log("tenter GET $source", 'distant'); |
|
| 979 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - // si on a rien trouve pas la peine d'insister |
|
| 983 | - if (!$a) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 988 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 989 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 990 | - if ( |
|
| 991 | - strpos($mime_type, 'image/') === 0 |
|
| 992 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 993 | - ) { |
|
| 994 | - if ( |
|
| 995 | - $max == 0 |
|
| 996 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 997 | - and in_array($extension, formats_image_acceptables()) |
|
| 998 | - and $charger_si_petite_image |
|
| 999 | - ) { |
|
| 1000 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1001 | - } else { |
|
| 1002 | - if ($a['body']) { |
|
| 1003 | - $a['extension'] = $extension; |
|
| 1004 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1005 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1006 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1007 | - $a['largeur'] = intval($size_image[0]); |
|
| 1008 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1009 | - $a['type_image'] = true; |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1015 | - // ce sera mieux que 0x0 |
|
| 1016 | - // Flash is dead! |
|
| 1017 | - if ( |
|
| 1018 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1019 | - and empty($a['largeur']) |
|
| 1020 | - ) { |
|
| 1021 | - $a['largeur'] = 425; |
|
| 1022 | - $a['hauteur'] = 350; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - if ($mime_type == 'text/html') { |
|
| 1026 | - include_spip('inc/filtres'); |
|
| 1027 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1028 | - $page = $page['page'] ?? ''; |
|
| 1029 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1030 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1031 | - } |
|
| 1032 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1033 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - $a['mime_type'] = $mime_type; |
|
| 1037 | - |
|
| 1038 | - return $a; |
|
| 948 | + // pas la peine de perdre son temps |
|
| 949 | + if (!tester_url_absolue($source)) { |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + # charger les alias des types mime |
|
| 954 | + include_spip('base/typedoc'); |
|
| 955 | + |
|
| 956 | + $a = []; |
|
| 957 | + $mime_type = ''; |
|
| 958 | + // On va directement charger le debut des images et des fichiers html, |
|
| 959 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 960 | + // ca echoue l'utilisateur devra les entrer... |
|
| 961 | + $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 962 | + $headers = $reponse['headers'] ?? ''; |
|
| 963 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 964 | + if ($headers) { |
|
| 965 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 966 | + return false; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + $a['extension'] = $extension; |
|
| 970 | + |
|
| 971 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 972 | + $a['taille'] = intval($regs[1]); |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + // Echec avec HEAD, on tente avec GET |
|
| 977 | + if (!$a and !$max) { |
|
| 978 | + spip_log("tenter GET $source", 'distant'); |
|
| 979 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + // si on a rien trouve pas la peine d'insister |
|
| 983 | + if (!$a) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 988 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 989 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 990 | + if ( |
|
| 991 | + strpos($mime_type, 'image/') === 0 |
|
| 992 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 993 | + ) { |
|
| 994 | + if ( |
|
| 995 | + $max == 0 |
|
| 996 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 997 | + and in_array($extension, formats_image_acceptables()) |
|
| 998 | + and $charger_si_petite_image |
|
| 999 | + ) { |
|
| 1000 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1001 | + } else { |
|
| 1002 | + if ($a['body']) { |
|
| 1003 | + $a['extension'] = $extension; |
|
| 1004 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1005 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1006 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1007 | + $a['largeur'] = intval($size_image[0]); |
|
| 1008 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1009 | + $a['type_image'] = true; |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1015 | + // ce sera mieux que 0x0 |
|
| 1016 | + // Flash is dead! |
|
| 1017 | + if ( |
|
| 1018 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1019 | + and empty($a['largeur']) |
|
| 1020 | + ) { |
|
| 1021 | + $a['largeur'] = 425; |
|
| 1022 | + $a['hauteur'] = 350; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + if ($mime_type == 'text/html') { |
|
| 1026 | + include_spip('inc/filtres'); |
|
| 1027 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1028 | + $page = $page['page'] ?? ''; |
|
| 1029 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1030 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1031 | + } |
|
| 1032 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1033 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + $a['mime_type'] = $mime_type; |
|
| 1037 | + |
|
| 1038 | + return $a; |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1044,70 +1044,70 @@ discard block |
||
| 1044 | 1044 | * @return false|mixed |
| 1045 | 1045 | */ |
| 1046 | 1046 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1047 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1048 | - $mime_type = (trim($regs[1])); |
|
| 1049 | - } else { |
|
| 1050 | - $mime_type = ''; |
|
| 1051 | - } // inconnu |
|
| 1052 | - |
|
| 1053 | - // Appliquer les alias |
|
| 1054 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1055 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - // pour corriger_extension() |
|
| 1059 | - include_spip('inc/documents'); |
|
| 1060 | - |
|
| 1061 | - // Si on a un mime-type insignifiant |
|
| 1062 | - // text/plain,application/octet-stream ou vide |
|
| 1063 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1064 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1065 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1066 | - $t = null; |
|
| 1067 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1068 | - if ( |
|
| 1069 | - !$t |
|
| 1070 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1071 | - ) { |
|
| 1072 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1073 | - } |
|
| 1074 | - if ( |
|
| 1075 | - !$t |
|
| 1076 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1077 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1078 | - ) { |
|
| 1079 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1084 | - if (!$t) { |
|
| 1085 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1089 | - // On essaie de nouveau avec l'extension |
|
| 1090 | - if ( |
|
| 1091 | - !$t |
|
| 1092 | - and $mime_type != 'text/plain' |
|
| 1093 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1094 | - ) { |
|
| 1095 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1096 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - if ($t) { |
|
| 1100 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1101 | - return $t['extension']; |
|
| 1102 | - } else { |
|
| 1103 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1104 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1105 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1106 | - if (!$t) { |
|
| 1107 | - return false; |
|
| 1108 | - } |
|
| 1109 | - return $t['extension']; |
|
| 1110 | - } |
|
| 1047 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1048 | + $mime_type = (trim($regs[1])); |
|
| 1049 | + } else { |
|
| 1050 | + $mime_type = ''; |
|
| 1051 | + } // inconnu |
|
| 1052 | + |
|
| 1053 | + // Appliquer les alias |
|
| 1054 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1055 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + // pour corriger_extension() |
|
| 1059 | + include_spip('inc/documents'); |
|
| 1060 | + |
|
| 1061 | + // Si on a un mime-type insignifiant |
|
| 1062 | + // text/plain,application/octet-stream ou vide |
|
| 1063 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1064 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1065 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1066 | + $t = null; |
|
| 1067 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1068 | + if ( |
|
| 1069 | + !$t |
|
| 1070 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1071 | + ) { |
|
| 1072 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1073 | + } |
|
| 1074 | + if ( |
|
| 1075 | + !$t |
|
| 1076 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1077 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1078 | + ) { |
|
| 1079 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1084 | + if (!$t) { |
|
| 1085 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1089 | + // On essaie de nouveau avec l'extension |
|
| 1090 | + if ( |
|
| 1091 | + !$t |
|
| 1092 | + and $mime_type != 'text/plain' |
|
| 1093 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1094 | + ) { |
|
| 1095 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1096 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + if ($t) { |
|
| 1100 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1101 | + return $t['extension']; |
|
| 1102 | + } else { |
|
| 1103 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1104 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1105 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1106 | + if (!$t) { |
|
| 1107 | + return false; |
|
| 1108 | + } |
|
| 1109 | + return $t['extension']; |
|
| 1110 | + } |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1123,45 +1123,45 @@ discard block |
||
| 1123 | 1123 | */ |
| 1124 | 1124 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1125 | 1125 | |
| 1126 | - $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1126 | + $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1127 | 1127 | |
| 1128 | - // rien a faire si pas de proxy :) |
|
| 1129 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1130 | - return ''; |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - if (is_null($http_noproxy)) { |
|
| 1134 | - $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1135 | - } |
|
| 1136 | - // si pas d'exception, on retourne le proxy |
|
| 1137 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1138 | - return $http_proxy; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1142 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1143 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1144 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1145 | - $http_noproxy = " $http_noproxy "; |
|
| 1146 | - $domain = $host; |
|
| 1147 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1148 | - if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1149 | - return ''; |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - while (strpos($domain, '.') !== false) { |
|
| 1153 | - $domain = explode('.', $domain); |
|
| 1154 | - array_shift($domain); |
|
| 1155 | - $domain = implode('.', $domain); |
|
| 1156 | - |
|
| 1157 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1158 | - if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1159 | - return ''; |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - // ok c'est pas une exception |
|
| 1164 | - return $http_proxy; |
|
| 1128 | + // rien a faire si pas de proxy :) |
|
| 1129 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1130 | + return ''; |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + if (is_null($http_noproxy)) { |
|
| 1134 | + $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1135 | + } |
|
| 1136 | + // si pas d'exception, on retourne le proxy |
|
| 1137 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1138 | + return $http_proxy; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1142 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1143 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1144 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1145 | + $http_noproxy = " $http_noproxy "; |
|
| 1146 | + $domain = $host; |
|
| 1147 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1148 | + if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1149 | + return ''; |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + while (strpos($domain, '.') !== false) { |
|
| 1153 | + $domain = explode('.', $domain); |
|
| 1154 | + array_shift($domain); |
|
| 1155 | + $domain = implode('.', $domain); |
|
| 1156 | + |
|
| 1157 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1158 | + if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1159 | + return ''; |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + // ok c'est pas une exception |
|
| 1164 | + return $http_proxy; |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | |
@@ -1184,59 +1184,59 @@ discard block |
||
| 1184 | 1184 | * @return array |
| 1185 | 1185 | */ |
| 1186 | 1186 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1187 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1188 | - $fopen = false; |
|
| 1189 | - |
|
| 1190 | - $t = @parse_url($url); |
|
| 1191 | - $host = $t['host']; |
|
| 1192 | - if ($t['scheme'] == 'http') { |
|
| 1193 | - $scheme = 'http'; |
|
| 1194 | - $noproxy = ''; |
|
| 1195 | - } elseif ($t['scheme'] == 'https') { |
|
| 1196 | - $scheme = 'ssl'; |
|
| 1197 | - $noproxy = 'ssl://'; |
|
| 1198 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1199 | - $t['port'] = 443; |
|
| 1200 | - } |
|
| 1201 | - } else { |
|
| 1202 | - $scheme = $t['scheme']; |
|
| 1203 | - $noproxy = $scheme . '://'; |
|
| 1204 | - } |
|
| 1205 | - if (isset($t['user'])) { |
|
| 1206 | - $user = [$t['user'], $t['pass']]; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1210 | - $port = 80; |
|
| 1211 | - } |
|
| 1212 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1213 | - $path = '/'; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - if (!empty($t['query'])) { |
|
| 1217 | - $path .= '?' . $t['query']; |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1221 | - if (!$f or !is_resource($f)) { |
|
| 1222 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1223 | - // ce qui correspond a $f===110 |
|
| 1224 | - if ( |
|
| 1225 | - $f !== 110 |
|
| 1226 | - and !need_proxy($host) |
|
| 1227 | - and !_request('tester_proxy') |
|
| 1228 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1229 | - ) { |
|
| 1230 | - $f = @fopen($url, 'rb'); |
|
| 1231 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1232 | - $fopen = true; |
|
| 1233 | - } else { |
|
| 1234 | - // echec total |
|
| 1235 | - $f = false; |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - return [$f, $fopen]; |
|
| 1187 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1188 | + $fopen = false; |
|
| 1189 | + |
|
| 1190 | + $t = @parse_url($url); |
|
| 1191 | + $host = $t['host']; |
|
| 1192 | + if ($t['scheme'] == 'http') { |
|
| 1193 | + $scheme = 'http'; |
|
| 1194 | + $noproxy = ''; |
|
| 1195 | + } elseif ($t['scheme'] == 'https') { |
|
| 1196 | + $scheme = 'ssl'; |
|
| 1197 | + $noproxy = 'ssl://'; |
|
| 1198 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1199 | + $t['port'] = 443; |
|
| 1200 | + } |
|
| 1201 | + } else { |
|
| 1202 | + $scheme = $t['scheme']; |
|
| 1203 | + $noproxy = $scheme . '://'; |
|
| 1204 | + } |
|
| 1205 | + if (isset($t['user'])) { |
|
| 1206 | + $user = [$t['user'], $t['pass']]; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1210 | + $port = 80; |
|
| 1211 | + } |
|
| 1212 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1213 | + $path = '/'; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + if (!empty($t['query'])) { |
|
| 1217 | + $path .= '?' . $t['query']; |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1221 | + if (!$f or !is_resource($f)) { |
|
| 1222 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1223 | + // ce qui correspond a $f===110 |
|
| 1224 | + if ( |
|
| 1225 | + $f !== 110 |
|
| 1226 | + and !need_proxy($host) |
|
| 1227 | + and !_request('tester_proxy') |
|
| 1228 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1229 | + ) { |
|
| 1230 | + $f = @fopen($url, 'rb'); |
|
| 1231 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1232 | + $fopen = true; |
|
| 1233 | + } else { |
|
| 1234 | + // echec total |
|
| 1235 | + $f = false; |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + return [$f, $fopen]; |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | /** |
@@ -1271,125 +1271,125 @@ discard block |
||
| 1271 | 1271 | * resource socket vers l'url demandee |
| 1272 | 1272 | */ |
| 1273 | 1273 | function lance_requete( |
| 1274 | - $method, |
|
| 1275 | - $scheme, |
|
| 1276 | - $user, |
|
| 1277 | - $host, |
|
| 1278 | - $path, |
|
| 1279 | - $port, |
|
| 1280 | - $noproxy, |
|
| 1281 | - $refuse_gz = false, |
|
| 1282 | - $referer = '', |
|
| 1283 | - $datas = '', |
|
| 1284 | - $vers = 'HTTP/1.0', |
|
| 1285 | - $date = '' |
|
| 1274 | + $method, |
|
| 1275 | + $scheme, |
|
| 1276 | + $user, |
|
| 1277 | + $host, |
|
| 1278 | + $path, |
|
| 1279 | + $port, |
|
| 1280 | + $noproxy, |
|
| 1281 | + $refuse_gz = false, |
|
| 1282 | + $referer = '', |
|
| 1283 | + $datas = '', |
|
| 1284 | + $vers = 'HTTP/1.0', |
|
| 1285 | + $date = '' |
|
| 1286 | 1286 | ) { |
| 1287 | 1287 | |
| 1288 | - $proxy_user = ''; |
|
| 1289 | - $http_proxy = need_proxy($host); |
|
| 1290 | - if ($user) { |
|
| 1291 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - $connect = ''; |
|
| 1295 | - if ($http_proxy) { |
|
| 1296 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1297 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1298 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1299 | - . "Host: $path_host\r\n" |
|
| 1300 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1301 | - } else { |
|
| 1302 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1303 | - . (!$user ? '' : "$user@") |
|
| 1304 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1305 | - } |
|
| 1306 | - $t2 = @parse_url($http_proxy); |
|
| 1307 | - $first_host = $t2['host']; |
|
| 1308 | - if (!($port = $t2['port'])) { |
|
| 1309 | - $port = 80; |
|
| 1310 | - } |
|
| 1311 | - if ($t2['user']) { |
|
| 1312 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1313 | - } |
|
| 1314 | - } else { |
|
| 1315 | - $first_host = $noproxy . $host; |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - if ($connect) { |
|
| 1319 | - $streamContext = stream_context_create([ |
|
| 1320 | - 'ssl' => [ |
|
| 1321 | - 'verify_peer' => false, |
|
| 1322 | - 'allow_self_signed' => true, |
|
| 1323 | - 'SNI_enabled' => true, |
|
| 1324 | - 'peer_name' => $host, |
|
| 1325 | - ] |
|
| 1326 | - ]); |
|
| 1327 | - $f = @stream_socket_client( |
|
| 1328 | - "tcp://$first_host:$port", |
|
| 1329 | - $errno, |
|
| 1330 | - $errstr, |
|
| 1331 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1332 | - STREAM_CLIENT_CONNECT, |
|
| 1333 | - $streamContext |
|
| 1334 | - ); |
|
| 1335 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1336 | - if (!$f) { |
|
| 1337 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1338 | - return $errno; |
|
| 1339 | - } |
|
| 1340 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1341 | - |
|
| 1342 | - fputs($f, $connect); |
|
| 1343 | - fputs($f, "\r\n"); |
|
| 1344 | - $res = fread($f, 1024); |
|
| 1345 | - if ( |
|
| 1346 | - !$res |
|
| 1347 | - or !count($res = explode(' ', $res)) |
|
| 1348 | - or $res[1] !== '200' |
|
| 1349 | - ) { |
|
| 1350 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1351 | - fclose($f); |
|
| 1352 | - |
|
| 1353 | - return false; |
|
| 1354 | - } |
|
| 1355 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1356 | - stream_set_blocking($f, true); |
|
| 1357 | - // envoyer le handshake |
|
| 1358 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1359 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1360 | - } else { |
|
| 1361 | - $ntry = 3; |
|
| 1362 | - do { |
|
| 1363 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1364 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1365 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1366 | - if (!$f) { |
|
| 1367 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1368 | - |
|
| 1369 | - return $errno; |
|
| 1370 | - } |
|
| 1371 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1375 | - |
|
| 1376 | - $host_port = $host; |
|
| 1377 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1378 | - $host_port .= ":$port"; |
|
| 1379 | - } |
|
| 1380 | - $req = "$method $path $vers\r\n" |
|
| 1381 | - . "Host: $host_port\r\n" |
|
| 1382 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1383 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1384 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1385 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1386 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1387 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1388 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1288 | + $proxy_user = ''; |
|
| 1289 | + $http_proxy = need_proxy($host); |
|
| 1290 | + if ($user) { |
|
| 1291 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + $connect = ''; |
|
| 1295 | + if ($http_proxy) { |
|
| 1296 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1297 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1298 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1299 | + . "Host: $path_host\r\n" |
|
| 1300 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1301 | + } else { |
|
| 1302 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1303 | + . (!$user ? '' : "$user@") |
|
| 1304 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1305 | + } |
|
| 1306 | + $t2 = @parse_url($http_proxy); |
|
| 1307 | + $first_host = $t2['host']; |
|
| 1308 | + if (!($port = $t2['port'])) { |
|
| 1309 | + $port = 80; |
|
| 1310 | + } |
|
| 1311 | + if ($t2['user']) { |
|
| 1312 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1313 | + } |
|
| 1314 | + } else { |
|
| 1315 | + $first_host = $noproxy . $host; |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + if ($connect) { |
|
| 1319 | + $streamContext = stream_context_create([ |
|
| 1320 | + 'ssl' => [ |
|
| 1321 | + 'verify_peer' => false, |
|
| 1322 | + 'allow_self_signed' => true, |
|
| 1323 | + 'SNI_enabled' => true, |
|
| 1324 | + 'peer_name' => $host, |
|
| 1325 | + ] |
|
| 1326 | + ]); |
|
| 1327 | + $f = @stream_socket_client( |
|
| 1328 | + "tcp://$first_host:$port", |
|
| 1329 | + $errno, |
|
| 1330 | + $errstr, |
|
| 1331 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1332 | + STREAM_CLIENT_CONNECT, |
|
| 1333 | + $streamContext |
|
| 1334 | + ); |
|
| 1335 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1336 | + if (!$f) { |
|
| 1337 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1338 | + return $errno; |
|
| 1339 | + } |
|
| 1340 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1341 | + |
|
| 1342 | + fputs($f, $connect); |
|
| 1343 | + fputs($f, "\r\n"); |
|
| 1344 | + $res = fread($f, 1024); |
|
| 1345 | + if ( |
|
| 1346 | + !$res |
|
| 1347 | + or !count($res = explode(' ', $res)) |
|
| 1348 | + or $res[1] !== '200' |
|
| 1349 | + ) { |
|
| 1350 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1351 | + fclose($f); |
|
| 1352 | + |
|
| 1353 | + return false; |
|
| 1354 | + } |
|
| 1355 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1356 | + stream_set_blocking($f, true); |
|
| 1357 | + // envoyer le handshake |
|
| 1358 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1359 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1360 | + } else { |
|
| 1361 | + $ntry = 3; |
|
| 1362 | + do { |
|
| 1363 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1364 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1365 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1366 | + if (!$f) { |
|
| 1367 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1368 | + |
|
| 1369 | + return $errno; |
|
| 1370 | + } |
|
| 1371 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1375 | + |
|
| 1376 | + $host_port = $host; |
|
| 1377 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1378 | + $host_port .= ":$port"; |
|
| 1379 | + } |
|
| 1380 | + $req = "$method $path $vers\r\n" |
|
| 1381 | + . "Host: $host_port\r\n" |
|
| 1382 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1383 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1384 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1385 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1386 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1387 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1388 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1389 | 1389 | |
| 1390 | 1390 | # spip_log("Requete\n$req", 'distant'); |
| 1391 | - fputs($f, $req); |
|
| 1392 | - fputs($f, $datas ?: "\r\n"); |
|
| 1391 | + fputs($f, $req); |
|
| 1392 | + fputs($f, $datas ?: "\r\n"); |
|
| 1393 | 1393 | |
| 1394 | - return $f; |
|
| 1394 | + return $f; |
|
| 1395 | 1395 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte |
|
| 49 | - . '?' . '>'; |
|
| 46 | + $texte = '<' . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte |
|
| 49 | + . '?' . '>'; |
|
| 50 | 50 | |
| 51 | - ecrire_fichier($nom, $texte); |
|
| 51 | + ecrire_fichier($nom, $texte); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | **/ |
| 79 | 79 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 80 | - $adr = addcslashes($adr, "'\\"); |
|
| 81 | - $port = addcslashes($port, "'\\"); |
|
| 82 | - $login = addcslashes($login, "'\\"); |
|
| 83 | - $pass = addcslashes($pass, "'\\"); |
|
| 84 | - $base = addcslashes($base, "'\\"); |
|
| 85 | - $type = addcslashes($type, "'\\"); |
|
| 86 | - $pref = addcslashes($pref, "'\\"); |
|
| 87 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | - $charset = addcslashes($charset, "'\\"); |
|
| 89 | - |
|
| 90 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | - . 'spip_connect_db(' |
|
| 92 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 80 | + $adr = addcslashes($adr, "'\\"); |
|
| 81 | + $port = addcslashes($port, "'\\"); |
|
| 82 | + $login = addcslashes($login, "'\\"); |
|
| 83 | + $pass = addcslashes($pass, "'\\"); |
|
| 84 | + $base = addcslashes($base, "'\\"); |
|
| 85 | + $type = addcslashes($type, "'\\"); |
|
| 86 | + $pref = addcslashes($pref, "'\\"); |
|
| 87 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | + $charset = addcslashes($charset, "'\\"); |
|
| 89 | + |
|
| 90 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | + . 'spip_connect_db(' |
|
| 92 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | * Tableau des informations sur la connexion |
| 107 | 107 | **/ |
| 108 | 108 | function analyse_fichier_connection($file) { |
| 109 | - $s = @join('', file($file)); |
|
| 110 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | - array_shift($regs); |
|
| 112 | - |
|
| 113 | - return $regs; |
|
| 114 | - } else { |
|
| 115 | - $ar = '\s*\'([^\']*)\''; |
|
| 116 | - $r = '\s*,' . $ar; |
|
| 117 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | - if (preg_match($r, $s, $regs)) { |
|
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | - array_shift($regs); |
|
| 121 | - array_shift($regs); |
|
| 122 | - |
|
| 123 | - return $regs; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | - |
|
| 128 | - return []; |
|
| 109 | + $s = @join('', file($file)); |
|
| 110 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | + array_shift($regs); |
|
| 112 | + |
|
| 113 | + return $regs; |
|
| 114 | + } else { |
|
| 115 | + $ar = '\s*\'([^\']*)\''; |
|
| 116 | + $r = '\s*,' . $ar; |
|
| 117 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | + if (preg_match($r, $s, $regs)) { |
|
| 119 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | + array_shift($regs); |
|
| 121 | + array_shift($regs); |
|
| 122 | + |
|
| 123 | + return $regs; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | + |
|
| 128 | + return []; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | * Liste des noms de connecteurs |
| 143 | 143 | **/ |
| 144 | 144 | function bases_referencees($exclu = '') { |
| 145 | - $tables = []; |
|
| 146 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | - $tables[] = basename($f, '.php'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $tables; |
|
| 145 | + $tables = []; |
|
| 146 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | + $tables[] = basename($f, '.php'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $tables; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | function install_mode_appel($server_db, $tout = true) { |
| 157 | - return ($server_db != 'mysql') ? '' |
|
| 158 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | - . test_sql_mode_mysql($server_db)); |
|
| 157 | + return ($server_db != 'mysql') ? '' |
|
| 158 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | + . test_sql_mode_mysql($server_db)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // |
@@ -164,52 +164,52 @@ discard block |
||
| 164 | 164 | // (sert a l'etape 1 de l'installation) |
| 165 | 165 | // https://code.spip.net/@tester_compatibilite_hebergement |
| 166 | 166 | function tester_compatibilite_hebergement() { |
| 167 | - $err = []; |
|
| 168 | - |
|
| 169 | - $p = phpversion(); |
|
| 170 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | - if ($err) { |
|
| 176 | - die("<div class='error'>" |
|
| 177 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Il faut une base de donnees tout de meme ... |
|
| 182 | - $serveurs = install_select_serveur(); |
|
| 183 | - if (!$serveurs) { |
|
| 184 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // et il faut preg |
|
| 191 | - if (!function_exists('preg_match_all')) { |
|
| 192 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | - . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // et surtout pas ce mbstring.overload |
|
| 197 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | - $err[] = _T('install_extension_mbstring') |
|
| 199 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($err) { |
|
| 203 | - echo "<div class='error'>" |
|
| 204 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | - foreach ($err as $e) { |
|
| 206 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | - echo "</ul></div>\n"; |
|
| 212 | - } |
|
| 167 | + $err = []; |
|
| 168 | + |
|
| 169 | + $p = phpversion(); |
|
| 170 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | + if ($err) { |
|
| 176 | + die("<div class='error'>" |
|
| 177 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Il faut une base de donnees tout de meme ... |
|
| 182 | + $serveurs = install_select_serveur(); |
|
| 183 | + if (!$serveurs) { |
|
| 184 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // et il faut preg |
|
| 191 | + if (!function_exists('preg_match_all')) { |
|
| 192 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | + . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // et surtout pas ce mbstring.overload |
|
| 197 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | + $err[] = _T('install_extension_mbstring') |
|
| 199 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($err) { |
|
| 203 | + echo "<div class='error'>" |
|
| 204 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | + foreach ($err as $e) { |
|
| 206 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | + echo "</ul></div>\n"; |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | * @note superflu ?? |
| 220 | 220 | */ |
| 221 | 221 | function login_hebergeur() { |
| 222 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 222 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 223 | 223 | |
| 224 | - // Free |
|
| 225 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | - $base_hebergeur = 'sql.free.fr'; |
|
| 227 | - $login_hebergeur = $regs[1]; |
|
| 228 | - } else { |
|
| 229 | - $login_hebergeur = ''; |
|
| 230 | - } |
|
| 224 | + // Free |
|
| 225 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | + $base_hebergeur = 'sql.free.fr'; |
|
| 227 | + $login_hebergeur = $regs[1]; |
|
| 228 | + } else { |
|
| 229 | + $login_hebergeur = ''; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return [$base_hebergeur, $login_hebergeur]; |
|
| 232 | + return [$base_hebergeur, $login_hebergeur]; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | // https://code.spip.net/@info_etape |
| 237 | 237 | function info_etape($titre, $complement = '') { |
| 238 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 239 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 238 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 239 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,157 +246,157 @@ discard block |
||
| 246 | 246 | * @return string Code HTML du bouton |
| 247 | 247 | **/ |
| 248 | 248 | function bouton_suivant($code = '') { |
| 249 | - if ($code == '') { |
|
| 250 | - $code = _T('bouton_suivant'); |
|
| 251 | - } |
|
| 252 | - static $suivant = 0; |
|
| 253 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | - $suivant += 1; |
|
| 255 | - |
|
| 256 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | - $code . |
|
| 258 | - " >>\" /></p>\n"; |
|
| 249 | + if ($code == '') { |
|
| 250 | + $code = _T('bouton_suivant'); |
|
| 251 | + } |
|
| 252 | + static $suivant = 0; |
|
| 253 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | + $suivant += 1; |
|
| 255 | + |
|
| 256 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | + $code . |
|
| 258 | + " >>\" /></p>\n"; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // https://code.spip.net/@info_progression_etape |
| 262 | 262 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | - $intitule_etat = []; |
|
| 264 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 265 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 266 | - $debut = 1; |
|
| 267 | - $etat = 'ok'; |
|
| 268 | - $last = count($liste); |
|
| 263 | + $intitule_etat = []; |
|
| 264 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 265 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 266 | + $debut = 1; |
|
| 267 | + $etat = 'ok'; |
|
| 268 | + $last = count($liste); |
|
| 269 | 269 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 270 | 270 | |
| 271 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 272 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 273 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 274 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 271 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 272 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 273 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 274 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 275 | 275 | |
| 276 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 277 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 278 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 279 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 280 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 276 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 277 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 278 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 279 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 280 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 281 | 281 | |
| 282 | 282 | // $aff_etapes = "<span id='etapes'>"; |
| 283 | 283 | |
| 284 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 285 | - |
|
| 286 | - foreach ($liste as $etape => $fichier) { |
|
| 287 | - if ($debut < $last) { |
|
| 288 | - if ($debut == $en_cours && $erreur) { |
|
| 289 | - $class = 'on erreur'; |
|
| 290 | - } else { |
|
| 291 | - if ($debut == $en_cours) { |
|
| 292 | - $class = 'on'; |
|
| 293 | - } else { |
|
| 294 | - if ($debut > $en_cours) { |
|
| 295 | - $class = 'prochains'; |
|
| 296 | - } else { |
|
| 297 | - $class = 'valides'; |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 303 | - $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 304 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 305 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 306 | - $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 307 | - $aff_etapes .= '</div></li>'; |
|
| 308 | - } |
|
| 309 | - $debut++; |
|
| 310 | - } |
|
| 311 | - $aff_etapes .= '</ul>'; |
|
| 312 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 313 | - |
|
| 314 | - return $aff_etapes; |
|
| 284 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 285 | + |
|
| 286 | + foreach ($liste as $etape => $fichier) { |
|
| 287 | + if ($debut < $last) { |
|
| 288 | + if ($debut == $en_cours && $erreur) { |
|
| 289 | + $class = 'on erreur'; |
|
| 290 | + } else { |
|
| 291 | + if ($debut == $en_cours) { |
|
| 292 | + $class = 'on'; |
|
| 293 | + } else { |
|
| 294 | + if ($debut > $en_cours) { |
|
| 295 | + $class = 'prochains'; |
|
| 296 | + } else { |
|
| 297 | + $class = 'valides'; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 303 | + $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 304 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 305 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 306 | + $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 307 | + $aff_etapes .= '</div></li>'; |
|
| 308 | + } |
|
| 309 | + $debut++; |
|
| 310 | + } |
|
| 311 | + $aff_etapes .= '</ul>'; |
|
| 312 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 313 | + |
|
| 314 | + return $aff_etapes; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | |
| 318 | 318 | // https://code.spip.net/@fieldset |
| 319 | 319 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 320 | - return "<fieldset>\n" . |
|
| 321 | - $avant . |
|
| 322 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | - fieldset_champs($champs) . |
|
| 324 | - $apres . |
|
| 325 | - "</fieldset>\n"; |
|
| 320 | + return "<fieldset>\n" . |
|
| 321 | + $avant . |
|
| 322 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | + fieldset_champs($champs) . |
|
| 324 | + $apres . |
|
| 325 | + "</fieldset>\n"; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | function fieldset_champs($champs = []) { |
| 329 | - $fieldset = ''; |
|
| 330 | - foreach ($champs as $nom => $contenu) { |
|
| 331 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | - if (isset($contenu['alternatives'])) { |
|
| 334 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | - . "/>\n"; |
|
| 340 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | - } |
|
| 342 | - $fieldset .= "<br />\n"; |
|
| 343 | - } else { |
|
| 344 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | - . " />\n"; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return $fieldset; |
|
| 329 | + $fieldset = ''; |
|
| 330 | + foreach ($champs as $nom => $contenu) { |
|
| 331 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | + if (isset($contenu['alternatives'])) { |
|
| 334 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | + . "/>\n"; |
|
| 340 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | + } |
|
| 342 | + $fieldset .= "<br />\n"; |
|
| 343 | + } else { |
|
| 344 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | + . " />\n"; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return $fieldset; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | function install_select_serveur() { |
| 356 | - $options = []; |
|
| 357 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | - $d = opendir($dir); |
|
| 359 | - if (!$d) { |
|
| 360 | - return []; |
|
| 361 | - } |
|
| 362 | - while (($f = readdir($d)) !== false) { |
|
| 363 | - if ( |
|
| 364 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | - and is_readable($f = $dir . $f) |
|
| 366 | - ) { |
|
| 367 | - require_once($f); |
|
| 368 | - $s = $s[1]; |
|
| 369 | - $v = 'spip_versions_' . $s; |
|
| 370 | - if (function_exists($v) and $v()) { |
|
| 371 | - $titre = _T("install_select_type_$s"); |
|
| 372 | - // proposer mysql par defaut si dispo |
|
| 373 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | - } else { |
|
| 377 | - spip_log("$s: portage indisponible"); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - sort($options); |
|
| 382 | - |
|
| 383 | - return $options; |
|
| 356 | + $options = []; |
|
| 357 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | + $d = opendir($dir); |
|
| 359 | + if (!$d) { |
|
| 360 | + return []; |
|
| 361 | + } |
|
| 362 | + while (($f = readdir($d)) !== false) { |
|
| 363 | + if ( |
|
| 364 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | + and is_readable($f = $dir . $f) |
|
| 366 | + ) { |
|
| 367 | + require_once($f); |
|
| 368 | + $s = $s[1]; |
|
| 369 | + $v = 'spip_versions_' . $s; |
|
| 370 | + if (function_exists($v) and $v()) { |
|
| 371 | + $titre = _T("install_select_type_$s"); |
|
| 372 | + // proposer mysql par defaut si dispo |
|
| 373 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | + . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | + } else { |
|
| 377 | + spip_log("$s: portage indisponible"); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + sort($options); |
|
| 382 | + |
|
| 383 | + return $options; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // https://code.spip.net/@install_connexion_form |
| 387 | 387 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 388 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 389 | - |
|
| 390 | - return generer_form_ecrire('install', ( |
|
| 391 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 392 | - . $hidden |
|
| 393 | - . (_request('echec') ? |
|
| 394 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 395 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 396 | - : '') |
|
| 397 | - |
|
| 398 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 399 | - . http_script(' |
|
| 388 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 389 | + |
|
| 390 | + return generer_form_ecrire('install', ( |
|
| 391 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 392 | + . $hidden |
|
| 393 | + . (_request('echec') ? |
|
| 394 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 395 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 396 | + : '') |
|
| 397 | + |
|
| 398 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 399 | + . http_script(' |
|
| 400 | 400 | jQuery(function($) { |
| 401 | 401 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 402 | 402 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -429,70 +429,70 @@ discard block |
||
| 429 | 429 | }); |
| 430 | 430 | });') |
| 431 | 431 | |
| 432 | - . ($server_db |
|
| 433 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 434 | - . (($predef[0]) |
|
| 435 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 436 | - : '') |
|
| 437 | - : ('<fieldset><legend>' |
|
| 438 | - . _T('install_select_type_db') |
|
| 439 | - . '</legend>' |
|
| 440 | - . '<p class="explication">' |
|
| 441 | - . _T('install_types_db_connus') |
|
| 442 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 443 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 444 | - . '</p>' |
|
| 445 | - . "\n<div class='p'>\n<ul>\n" |
|
| 446 | - . join("\n", install_select_serveur()) |
|
| 447 | - . "\n</ul>\n</div></fieldset>") |
|
| 448 | - ) |
|
| 449 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 450 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 451 | - . ($predef[1] |
|
| 452 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 453 | - : fieldset( |
|
| 454 | - _T('entree_base_donnee_1'), |
|
| 455 | - [ |
|
| 456 | - 'adresse_db' => [ |
|
| 457 | - 'label' => $db[1], |
|
| 458 | - 'valeur' => $db[0] |
|
| 459 | - ], |
|
| 460 | - ] |
|
| 461 | - ) |
|
| 462 | - ) |
|
| 463 | - . '</div>' |
|
| 464 | - |
|
| 465 | - . '<div id="install_login_base_hebergeur">' |
|
| 466 | - . ($predef[2] |
|
| 467 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 468 | - : fieldset( |
|
| 469 | - _T('entree_login_connexion_1'), |
|
| 470 | - [ |
|
| 471 | - 'login_db' => [ |
|
| 472 | - 'label' => $login[1], |
|
| 473 | - 'valeur' => $login[0] |
|
| 474 | - ], |
|
| 475 | - ] |
|
| 476 | - ) |
|
| 477 | - ) |
|
| 478 | - . '</div>' |
|
| 479 | - |
|
| 480 | - . '<div id="install_pass_base_hebergeur">' |
|
| 481 | - . ($predef[3] |
|
| 482 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 483 | - : fieldset( |
|
| 484 | - _T('entree_mot_passe_1'), |
|
| 485 | - [ |
|
| 486 | - 'pass_db' => [ |
|
| 487 | - 'label' => $pass[1], |
|
| 488 | - 'valeur' => $pass[0] |
|
| 489 | - ], |
|
| 490 | - ] |
|
| 491 | - ) |
|
| 492 | - ) |
|
| 493 | - . '</div>' |
|
| 494 | - |
|
| 495 | - . bouton_suivant())); |
|
| 432 | + . ($server_db |
|
| 433 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 434 | + . (($predef[0]) |
|
| 435 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 436 | + : '') |
|
| 437 | + : ('<fieldset><legend>' |
|
| 438 | + . _T('install_select_type_db') |
|
| 439 | + . '</legend>' |
|
| 440 | + . '<p class="explication">' |
|
| 441 | + . _T('install_types_db_connus') |
|
| 442 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 443 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 444 | + . '</p>' |
|
| 445 | + . "\n<div class='p'>\n<ul>\n" |
|
| 446 | + . join("\n", install_select_serveur()) |
|
| 447 | + . "\n</ul>\n</div></fieldset>") |
|
| 448 | + ) |
|
| 449 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 450 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 451 | + . ($predef[1] |
|
| 452 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 453 | + : fieldset( |
|
| 454 | + _T('entree_base_donnee_1'), |
|
| 455 | + [ |
|
| 456 | + 'adresse_db' => [ |
|
| 457 | + 'label' => $db[1], |
|
| 458 | + 'valeur' => $db[0] |
|
| 459 | + ], |
|
| 460 | + ] |
|
| 461 | + ) |
|
| 462 | + ) |
|
| 463 | + . '</div>' |
|
| 464 | + |
|
| 465 | + . '<div id="install_login_base_hebergeur">' |
|
| 466 | + . ($predef[2] |
|
| 467 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 468 | + : fieldset( |
|
| 469 | + _T('entree_login_connexion_1'), |
|
| 470 | + [ |
|
| 471 | + 'login_db' => [ |
|
| 472 | + 'label' => $login[1], |
|
| 473 | + 'valeur' => $login[0] |
|
| 474 | + ], |
|
| 475 | + ] |
|
| 476 | + ) |
|
| 477 | + ) |
|
| 478 | + . '</div>' |
|
| 479 | + |
|
| 480 | + . '<div id="install_pass_base_hebergeur">' |
|
| 481 | + . ($predef[3] |
|
| 482 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 483 | + : fieldset( |
|
| 484 | + _T('entree_mot_passe_1'), |
|
| 485 | + [ |
|
| 486 | + 'pass_db' => [ |
|
| 487 | + 'label' => $pass[1], |
|
| 488 | + 'valeur' => $pass[0] |
|
| 489 | + ], |
|
| 490 | + ] |
|
| 491 | + ) |
|
| 492 | + ) |
|
| 493 | + . '</div>' |
|
| 494 | + |
|
| 495 | + . bouton_suivant())); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | // 4 valeurs qu'on reconduit d'un script a l'autre |
@@ -500,76 +500,76 @@ discard block |
||
| 500 | 500 | |
| 501 | 501 | // https://code.spip.net/@predef_ou_cache |
| 502 | 502 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 503 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 504 | - ? '' |
|
| 505 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 506 | - ) |
|
| 507 | - . ((defined('_INSTALL_USER_DB')) |
|
| 508 | - ? '' |
|
| 509 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 510 | - ) |
|
| 511 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 512 | - ? '' |
|
| 513 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 514 | - ) |
|
| 515 | - |
|
| 516 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 517 | - ? '' |
|
| 518 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 519 | - ); |
|
| 503 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 504 | + ? '' |
|
| 505 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 506 | + ) |
|
| 507 | + . ((defined('_INSTALL_USER_DB')) |
|
| 508 | + ? '' |
|
| 509 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 510 | + ) |
|
| 511 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 512 | + ? '' |
|
| 513 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 514 | + ) |
|
| 515 | + |
|
| 516 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 517 | + ? '' |
|
| 518 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 519 | + ); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // presentation des bases existantes |
| 523 | 523 | |
| 524 | 524 | // https://code.spip.net/@install_etape_liste_bases |
| 525 | 525 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 526 | - $bases = $checked = []; |
|
| 527 | - $noms = sql_listdbs($server_db); |
|
| 528 | - if (!$noms) { |
|
| 529 | - return ''; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - foreach ($noms as $nom) { |
|
| 533 | - $id = spip_htmlspecialchars($nom); |
|
| 534 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 535 | - $base = ' name="choix_db" value="' |
|
| 536 | - . $nom |
|
| 537 | - . '"' |
|
| 538 | - . $dis |
|
| 539 | - . " type='radio' id='$id'"; |
|
| 540 | - $label = "<label for='$id'>" |
|
| 541 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 542 | - . '</label>'; |
|
| 543 | - |
|
| 544 | - if ( |
|
| 545 | - !$checked and !$dis and |
|
| 546 | - (($nom == $login_db) or |
|
| 547 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 548 | - ) { |
|
| 549 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 550 | - } else { |
|
| 551 | - $bases[] = "<input$base />\n$label"; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - if (!$bases && !$checked) { |
|
| 556 | - return false; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - if ($checked) { |
|
| 560 | - array_unshift($bases, $checked); |
|
| 561 | - $checked = true; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return [$checked, $bases]; |
|
| 526 | + $bases = $checked = []; |
|
| 527 | + $noms = sql_listdbs($server_db); |
|
| 528 | + if (!$noms) { |
|
| 529 | + return ''; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + foreach ($noms as $nom) { |
|
| 533 | + $id = spip_htmlspecialchars($nom); |
|
| 534 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 535 | + $base = ' name="choix_db" value="' |
|
| 536 | + . $nom |
|
| 537 | + . '"' |
|
| 538 | + . $dis |
|
| 539 | + . " type='radio' id='$id'"; |
|
| 540 | + $label = "<label for='$id'>" |
|
| 541 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 542 | + . '</label>'; |
|
| 543 | + |
|
| 544 | + if ( |
|
| 545 | + !$checked and !$dis and |
|
| 546 | + (($nom == $login_db) or |
|
| 547 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 548 | + ) { |
|
| 549 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 550 | + } else { |
|
| 551 | + $bases[] = "<input$base />\n$label"; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + if (!$bases && !$checked) { |
|
| 556 | + return false; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + if ($checked) { |
|
| 560 | + array_unshift($bases, $checked); |
|
| 561 | + $checked = true; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return [$checked, $bases]; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | function install_propager($hidden) { |
| 568 | - $res = ''; |
|
| 569 | - foreach ($hidden as $k) { |
|
| 570 | - $v = spip_htmlentities(_request($k)); |
|
| 571 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 572 | - } |
|
| 568 | + $res = ''; |
|
| 569 | + foreach ($hidden as $k) { |
|
| 570 | + $v = spip_htmlentities(_request($k)); |
|
| 571 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | - return $res; |
|
| 574 | + return $res; |
|
| 575 | 575 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base${subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base${subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = "^$dir"; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = "^$dir"; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |