@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * - false si l'arbre xml ne peut être créé ou est vide |
| 47 | 47 | **/ |
| 48 | 48 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 49 | - $contenu = ''; |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - include_spip('inc/distant'); |
|
| 52 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | - $contenu = $contenu['page'] ?? ''; |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = []; |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 49 | + $contenu = ''; |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + include_spip('inc/distant'); |
|
| 52 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | + $contenu = $contenu['page'] ?? ''; |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = []; |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,150 +82,150 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = []; |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = []; |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ''; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | - if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - && ($nopen += preg_match_all( |
|
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | - $morceau, |
|
| 141 | - $matches, |
|
| 142 | - PREG_SET_ORDER |
|
| 143 | - )) > $nclose |
|
| 144 | - ) { |
|
| 145 | - $nclose++; |
|
| 146 | - $d = $p + $ncclos; |
|
| 147 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if ($p === false) { |
|
| 151 | - if ($strict) { |
|
| 152 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ''; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | + if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + && ($nopen += preg_match_all( |
|
| 139 | + '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | + $morceau, |
|
| 141 | + $matches, |
|
| 142 | + PREG_SET_ORDER |
|
| 143 | + )) > $nclose |
|
| 144 | + ) { |
|
| 145 | + $nclose++; |
|
| 146 | + $d = $p + $ncclos; |
|
| 147 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if ($p === false) { |
|
| 151 | + if ($strict) { |
|
| 152 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 153 | 153 | |
| 154 | - return $out; |
|
| 155 | - } else { |
|
| 156 | - return importer_charset($texte, $charset); |
|
| 157 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | - } |
|
| 159 | - $content = substr($txt, 0, $p); |
|
| 160 | - $txt = substr($txt, $p + $ncclos); |
|
| 161 | - if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | - }//$content; |
|
| 164 | - else { |
|
| 165 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | - } |
|
| 170 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | - return $out; |
|
| 172 | - } else { |
|
| 173 | - return importer_charset($texte, $charset); |
|
| 174 | - }//$texte; |
|
| 154 | + return $out; |
|
| 155 | + } else { |
|
| 156 | + return importer_charset($texte, $charset); |
|
| 157 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | + } |
|
| 159 | + $content = substr($txt, 0, $p); |
|
| 160 | + $txt = substr($txt, $p + $ncclos); |
|
| 161 | + if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | + }//$content; |
|
| 164 | + else { |
|
| 165 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | + } |
|
| 170 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | + return $out; |
|
| 172 | + } else { |
|
| 173 | + return importer_charset($texte, $charset); |
|
| 174 | + }//$texte; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 178 | - $s = ''; |
|
| 179 | - if (is_array($arbre)) { |
|
| 180 | - foreach ($arbre as $tag => $feuille) { |
|
| 181 | - if (is_array($feuille)) { |
|
| 182 | - if ($tag !== (int) $tag) { |
|
| 183 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | - if (strlen((string) $f)) { |
|
| 185 | - $tagf = explode(' ', $tag); |
|
| 186 | - $tagf = $tagf[0]; |
|
| 187 | - $s .= "<$tag>$f</$tagf>"; |
|
| 188 | - } else { |
|
| 189 | - $s .= "<$tag />"; |
|
| 190 | - } |
|
| 191 | - } else { |
|
| 192 | - $s .= spip_xml_aplatit($feuille); |
|
| 193 | - } |
|
| 194 | - $s .= $separateur; |
|
| 195 | - } else { |
|
| 196 | - $s .= "$feuille$separateur"; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 178 | + $s = ''; |
|
| 179 | + if (is_array($arbre)) { |
|
| 180 | + foreach ($arbre as $tag => $feuille) { |
|
| 181 | + if (is_array($feuille)) { |
|
| 182 | + if ($tag !== (int) $tag) { |
|
| 183 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | + if (strlen((string) $f)) { |
|
| 185 | + $tagf = explode(' ', $tag); |
|
| 186 | + $tagf = $tagf[0]; |
|
| 187 | + $s .= "<$tag>$f</$tagf>"; |
|
| 188 | + } else { |
|
| 189 | + $s .= "<$tag />"; |
|
| 190 | + } |
|
| 191 | + } else { |
|
| 192 | + $s .= spip_xml_aplatit($feuille); |
|
| 193 | + } |
|
| 194 | + $s .= $separateur; |
|
| 195 | + } else { |
|
| 196 | + $s .= "$feuille$separateur"; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 201 | + return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function spip_xml_tagname($tag) { |
| 205 | - if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | - return $reg[1]; |
|
| 207 | - } |
|
| 205 | + if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | + return $reg[1]; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return ''; |
|
| 209 | + return ''; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = []; |
|
| 215 | - $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | - $p = strpos($tag, '='); |
|
| 217 | - while ($p !== false) { |
|
| 218 | - $attr = trim(substr($tag, 0, $p)); |
|
| 219 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | - $quote = $tag[0]; |
|
| 221 | - $p = strpos($tag, $quote, 1); |
|
| 222 | - $cont = substr($tag, 1, $p - 1); |
|
| 223 | - $liste[$attr] = $cont; |
|
| 224 | - $tag = substr($tag, $p + 1); |
|
| 225 | - $p = strpos($tag, '='); |
|
| 226 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = []; |
|
| 215 | + $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | + $p = strpos($tag, '='); |
|
| 217 | + while ($p !== false) { |
|
| 218 | + $attr = trim(substr($tag, 0, $p)); |
|
| 219 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | + $quote = $tag[0]; |
|
| 221 | + $p = strpos($tag, $quote, 1); |
|
| 222 | + $cont = substr($tag, 1, $p - 1); |
|
| 223 | + $liste[$attr] = $cont; |
|
| 224 | + $tag = substr($tag, $p + 1); |
|
| 225 | + $p = strpos($tag, '='); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return [$tagname, $liste]; |
|
| 228 | + return [$tagname, $liste]; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -248,21 +248,21 @@ discard block |
||
| 248 | 248 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 251 | - if ($init) { |
|
| 252 | - $matches = []; |
|
| 253 | - } |
|
| 254 | - if (is_array($arbre) && count($arbre)) { |
|
| 255 | - foreach (array_keys($arbre) as $tag) { |
|
| 256 | - if (preg_match($regexp, $tag)) { |
|
| 257 | - $matches[$tag] = &$arbre[$tag]; |
|
| 258 | - } |
|
| 259 | - if (is_array($arbre[$tag])) { |
|
| 260 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 251 | + if ($init) { |
|
| 252 | + $matches = []; |
|
| 253 | + } |
|
| 254 | + if (is_array($arbre) && count($arbre)) { |
|
| 255 | + foreach (array_keys($arbre) as $tag) { |
|
| 256 | + if (preg_match($regexp, $tag)) { |
|
| 257 | + $matches[$tag] = &$arbre[$tag]; |
|
| 258 | + } |
|
| 259 | + if (is_array($arbre[$tag])) { |
|
| 260 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 267 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | 268 | } |
@@ -17,32 +17,32 @@ discard block |
||
| 17 | 17 | * @package SPIP\Core\Distant |
| 18 | 18 | **/ |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 24 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 25 | 25 | } |
| 26 | 26 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 27 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 28 | 28 | } |
| 29 | 29 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 30 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 31 | 31 | } |
| 32 | 32 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 33 | - define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 33 | + define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 34 | 34 | } |
| 35 | 35 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 36 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 40 | - preg_replace( |
|
| 41 | - '@^https?:@', |
|
| 42 | - 'https?:', |
|
| 43 | - ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 44 | - ) |
|
| 45 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 40 | + preg_replace( |
|
| 41 | + '@^https?:@', |
|
| 42 | + 'https?:', |
|
| 43 | + ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 44 | + ) |
|
| 45 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 46 | 46 | |
| 47 | 47 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 48 | 48 | |
@@ -71,106 +71,106 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) { |
| 73 | 73 | |
| 74 | - // si c'est la protection de soi-meme, retourner le path |
|
| 75 | - if ($mode !== 'force' && preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 76 | - $source = substr((string) _DIR_IMG, strlen((string) _DIR_RACINE)) . urldecode($match[1]); |
|
| 77 | - |
|
| 78 | - return @file_exists($source) ? $source : false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (is_null($local)) { |
|
| 82 | - $local = fichier_copie_locale($source); |
|
| 83 | - } else { |
|
| 84 | - if (_DIR_RACINE && strncmp((string) _DIR_RACINE, $local, strlen((string) _DIR_RACINE)) == 0) { |
|
| 85 | - $local = substr($local, strlen((string) _DIR_RACINE)); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 90 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 91 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 92 | - if (!$local) { |
|
| 93 | - return false; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $localrac = _DIR_RACINE . $local; |
|
| 97 | - $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 98 | - |
|
| 99 | - // test d'existence du fichier |
|
| 100 | - if ($mode === 'test') { |
|
| 101 | - return $t ? $local : ''; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // sinon voir si on doit/peut le telecharger |
|
| 105 | - if ($local === $source || !tester_url_absolue($source)) { |
|
| 106 | - return $t ? $local : ''; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($mode === 'modif' || !$t) { |
|
| 110 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 111 | - // et des eventuelles recuperations concurantes |
|
| 112 | - include_spip('inc/acces'); |
|
| 113 | - if (!$taille_max) { |
|
| 114 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 115 | - } |
|
| 116 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 117 | - $res = recuperer_url( |
|
| 118 | - $source, |
|
| 119 | - ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - if (!$res || !$res['length'] && $res['status'] != 304) { |
|
| 123 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 124 | - @unlink($localrac_tmp); |
|
| 125 | - } |
|
| 126 | - else { |
|
| 127 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 128 | - } |
|
| 129 | - if (!$res || !$res['length']) { |
|
| 130 | - // si $t c'est sans doute juste un not-modified-since |
|
| 131 | - return $t ? $local : false; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // si option valider url, verifions que l'URL finale est acceptable |
|
| 135 | - if ( |
|
| 136 | - $callback_valider_url |
|
| 137 | - && is_callable($callback_valider_url) |
|
| 138 | - && !$callback_valider_url($res['url']) |
|
| 139 | - ) { |
|
| 140 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 141 | - @unlink($localrac_tmp); |
|
| 142 | - return $t ? $local : false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // on peut renommer le fichier tmp |
|
| 146 | - @rename($localrac_tmp, $localrac); |
|
| 147 | - |
|
| 148 | - // si on retrouve l'extension |
|
| 149 | - if ( |
|
| 150 | - !empty($res['headers']) |
|
| 151 | - && ($extension = distant_trouver_extension_selon_headers($source, $res['headers'])) |
|
| 152 | - && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 153 | - ) { |
|
| 154 | - $sanitizer($localrac); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // pour une eventuelle indexation |
|
| 158 | - pipeline( |
|
| 159 | - 'post_edition', |
|
| 160 | - [ |
|
| 161 | - 'args' => [ |
|
| 162 | - 'operation' => 'copie_locale', |
|
| 163 | - 'source' => $source, |
|
| 164 | - 'fichier' => $local, |
|
| 165 | - 'http_res' => $res['length'], |
|
| 166 | - 'url' => $res['url'], |
|
| 167 | - ], |
|
| 168 | - 'data' => null |
|
| 169 | - ] |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $local; |
|
| 74 | + // si c'est la protection de soi-meme, retourner le path |
|
| 75 | + if ($mode !== 'force' && preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 76 | + $source = substr((string) _DIR_IMG, strlen((string) _DIR_RACINE)) . urldecode($match[1]); |
|
| 77 | + |
|
| 78 | + return @file_exists($source) ? $source : false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (is_null($local)) { |
|
| 82 | + $local = fichier_copie_locale($source); |
|
| 83 | + } else { |
|
| 84 | + if (_DIR_RACINE && strncmp((string) _DIR_RACINE, $local, strlen((string) _DIR_RACINE)) == 0) { |
|
| 85 | + $local = substr($local, strlen((string) _DIR_RACINE)); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 90 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 91 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 92 | + if (!$local) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $localrac = _DIR_RACINE . $local; |
|
| 97 | + $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 98 | + |
|
| 99 | + // test d'existence du fichier |
|
| 100 | + if ($mode === 'test') { |
|
| 101 | + return $t ? $local : ''; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // sinon voir si on doit/peut le telecharger |
|
| 105 | + if ($local === $source || !tester_url_absolue($source)) { |
|
| 106 | + return $t ? $local : ''; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($mode === 'modif' || !$t) { |
|
| 110 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 111 | + // et des eventuelles recuperations concurantes |
|
| 112 | + include_spip('inc/acces'); |
|
| 113 | + if (!$taille_max) { |
|
| 114 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 115 | + } |
|
| 116 | + $localrac_tmp = $localrac . '.tmp'; |
|
| 117 | + $res = recuperer_url( |
|
| 118 | + $source, |
|
| 119 | + ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + if (!$res || !$res['length'] && $res['status'] != 304) { |
|
| 123 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 124 | + @unlink($localrac_tmp); |
|
| 125 | + } |
|
| 126 | + else { |
|
| 127 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 128 | + } |
|
| 129 | + if (!$res || !$res['length']) { |
|
| 130 | + // si $t c'est sans doute juste un not-modified-since |
|
| 131 | + return $t ? $local : false; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // si option valider url, verifions que l'URL finale est acceptable |
|
| 135 | + if ( |
|
| 136 | + $callback_valider_url |
|
| 137 | + && is_callable($callback_valider_url) |
|
| 138 | + && !$callback_valider_url($res['url']) |
|
| 139 | + ) { |
|
| 140 | + spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 141 | + @unlink($localrac_tmp); |
|
| 142 | + return $t ? $local : false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // on peut renommer le fichier tmp |
|
| 146 | + @rename($localrac_tmp, $localrac); |
|
| 147 | + |
|
| 148 | + // si on retrouve l'extension |
|
| 149 | + if ( |
|
| 150 | + !empty($res['headers']) |
|
| 151 | + && ($extension = distant_trouver_extension_selon_headers($source, $res['headers'])) |
|
| 152 | + && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 153 | + ) { |
|
| 154 | + $sanitizer($localrac); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // pour une eventuelle indexation |
|
| 158 | + pipeline( |
|
| 159 | + 'post_edition', |
|
| 160 | + [ |
|
| 161 | + 'args' => [ |
|
| 162 | + 'operation' => 'copie_locale', |
|
| 163 | + 'source' => $source, |
|
| 164 | + 'fichier' => $local, |
|
| 165 | + 'http_res' => $res['length'], |
|
| 166 | + 'url' => $res['url'], |
|
| 167 | + ], |
|
| 168 | + 'data' => null |
|
| 169 | + ] |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $local; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -185,97 +185,97 @@ discard block |
||
| 185 | 185 | * url ou false en cas d'echec |
| 186 | 186 | */ |
| 187 | 187 | function valider_url_distante($url, $known_hosts = []) { |
| 188 | - if (!function_exists('protocole_verifier')) { |
|
| 189 | - include_spip('inc/filtres_mini'); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $parsed_url = parse_url($url); |
|
| 197 | - if (!$parsed_url || empty($parsed_url['host'])) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if (isset($parsed_url['user']) || isset($parsed_url['pass'])) { |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (!is_array($known_hosts)) { |
|
| 210 | - $known_hosts = [$known_hosts]; |
|
| 211 | - } |
|
| 212 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 213 | - $known_hosts[] = url_de_base(); |
|
| 214 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 215 | - |
|
| 216 | - $is_known_host = false; |
|
| 217 | - foreach ($known_hosts as $known_host) { |
|
| 218 | - $parse_known = parse_url((string) $known_host); |
|
| 219 | - if ( |
|
| 220 | - $parse_known |
|
| 221 | - && strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 222 | - ) { |
|
| 223 | - $is_known_host = true; |
|
| 224 | - break; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if (!$is_known_host) { |
|
| 229 | - $host = trim($parsed_url['host'], '.'); |
|
| 230 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 231 | - $ip = gethostbyname($host); |
|
| 232 | - if ($ip === $host) { |
|
| 233 | - // Error condition for gethostbyname() |
|
| 234 | - $ip = false; |
|
| 235 | - } |
|
| 236 | - if ($records = dns_get_record($host)) { |
|
| 237 | - foreach ($records as $record) { |
|
| 238 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 239 | - // se fasse sur la meme IP |
|
| 240 | - if ($record['ttl'] < 10) { |
|
| 241 | - $ip = false; |
|
| 242 | - break; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - else { |
|
| 247 | - $ip = false; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - if ($ip && ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 251 | - return false; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - if (empty($parsed_url['port'])) { |
|
| 256 | - return $url; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $port = $parsed_url['port']; |
|
| 260 | - if ($port === 80 || $port === 443 || $port === 8080) { |
|
| 261 | - return $url; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($is_known_host) { |
|
| 265 | - foreach ($known_hosts as $known_host) { |
|
| 266 | - $parse_known = parse_url((string) $known_host); |
|
| 267 | - if ( |
|
| 268 | - $parse_known |
|
| 269 | - && !empty($parse_known['port']) |
|
| 270 | - && strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 271 | - && $parse_known['port'] == $port |
|
| 272 | - ) { |
|
| 273 | - return $url; |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return false; |
|
| 188 | + if (!function_exists('protocole_verifier')) { |
|
| 189 | + include_spip('inc/filtres_mini'); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $parsed_url = parse_url($url); |
|
| 197 | + if (!$parsed_url || empty($parsed_url['host'])) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if (isset($parsed_url['user']) || isset($parsed_url['pass'])) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (!is_array($known_hosts)) { |
|
| 210 | + $known_hosts = [$known_hosts]; |
|
| 211 | + } |
|
| 212 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 213 | + $known_hosts[] = url_de_base(); |
|
| 214 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 215 | + |
|
| 216 | + $is_known_host = false; |
|
| 217 | + foreach ($known_hosts as $known_host) { |
|
| 218 | + $parse_known = parse_url((string) $known_host); |
|
| 219 | + if ( |
|
| 220 | + $parse_known |
|
| 221 | + && strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 222 | + ) { |
|
| 223 | + $is_known_host = true; |
|
| 224 | + break; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if (!$is_known_host) { |
|
| 229 | + $host = trim($parsed_url['host'], '.'); |
|
| 230 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 231 | + $ip = gethostbyname($host); |
|
| 232 | + if ($ip === $host) { |
|
| 233 | + // Error condition for gethostbyname() |
|
| 234 | + $ip = false; |
|
| 235 | + } |
|
| 236 | + if ($records = dns_get_record($host)) { |
|
| 237 | + foreach ($records as $record) { |
|
| 238 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 239 | + // se fasse sur la meme IP |
|
| 240 | + if ($record['ttl'] < 10) { |
|
| 241 | + $ip = false; |
|
| 242 | + break; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + else { |
|
| 247 | + $ip = false; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + if ($ip && ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 251 | + return false; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + if (empty($parsed_url['port'])) { |
|
| 256 | + return $url; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $port = $parsed_url['port']; |
|
| 260 | + if ($port === 80 || $port === 443 || $port === 8080) { |
|
| 261 | + return $url; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($is_known_host) { |
|
| 265 | + foreach ($known_hosts as $known_host) { |
|
| 266 | + $parse_known = parse_url((string) $known_host); |
|
| 267 | + if ( |
|
| 268 | + $parse_known |
|
| 269 | + && !empty($parse_known['port']) |
|
| 270 | + && strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 271 | + && $parse_known['port'] == $port |
|
| 272 | + ) { |
|
| 273 | + return $url; |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return false; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -295,86 +295,86 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | function prepare_donnees_post($donnees, $boundary = '') { |
| 297 | 297 | |
| 298 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 299 | - // pour un appel soap par exemple |
|
| 300 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 301 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 302 | - $chaine = ''; |
|
| 303 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 304 | - $entete = ''; |
|
| 305 | - // on repasse tous les \r\n et \r en simples \n |
|
| 306 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 307 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 308 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 309 | - $p = strpos($donnees, "\n\n"); |
|
| 310 | - if ($p !== false) { |
|
| 311 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 312 | - $donnees = substr($donnees, $p + 2); |
|
| 313 | - } |
|
| 314 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 315 | - } else { |
|
| 316 | - /* boundary automatique */ |
|
| 317 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 318 | - if ($boundary === '') { |
|
| 319 | - $taille = 0; |
|
| 320 | - foreach ($donnees as $cle => $valeur) { |
|
| 321 | - if (is_array($valeur)) { |
|
| 322 | - foreach ($valeur as $val2) { |
|
| 323 | - $taille += strlen((string) $val2); |
|
| 324 | - } |
|
| 325 | - } else { |
|
| 326 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 327 | - $taille += strlen((string) $valeur); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - if ($taille > 500) { |
|
| 331 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if (is_string($boundary) && strlen($boundary)) { |
|
| 336 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 337 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 338 | - if (is_array($donnees)) { |
|
| 339 | - foreach ($donnees as $cle => $valeur) { |
|
| 340 | - if (is_array($valeur)) { |
|
| 341 | - foreach ($valeur as $val2) { |
|
| 342 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 343 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 344 | - $chaine .= "\r\n"; |
|
| 345 | - $chaine .= $val2; |
|
| 346 | - } |
|
| 347 | - } else { |
|
| 348 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 349 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 350 | - $chaine .= "\r\n"; |
|
| 351 | - $chaine .= $valeur; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 355 | - } |
|
| 356 | - } else { |
|
| 357 | - // fabrique une chaine HTTP simple pour un POST |
|
| 358 | - $entete = "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 359 | - if (is_array($donnees)) { |
|
| 360 | - $chaine = []; |
|
| 361 | - foreach ($donnees as $cle => $valeur) { |
|
| 362 | - if (is_array($valeur)) { |
|
| 363 | - foreach ($valeur as $val2) { |
|
| 364 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode((string) $val2); |
|
| 365 | - } |
|
| 366 | - } else { |
|
| 367 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode((string) $valeur); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - $chaine = implode('&', $chaine); |
|
| 371 | - } else { |
|
| 372 | - $chaine = $donnees; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return [$entete, $chaine]; |
|
| 298 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 299 | + // pour un appel soap par exemple |
|
| 300 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 301 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 302 | + $chaine = ''; |
|
| 303 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 304 | + $entete = ''; |
|
| 305 | + // on repasse tous les \r\n et \r en simples \n |
|
| 306 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 307 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 308 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 309 | + $p = strpos($donnees, "\n\n"); |
|
| 310 | + if ($p !== false) { |
|
| 311 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 312 | + $donnees = substr($donnees, $p + 2); |
|
| 313 | + } |
|
| 314 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 315 | + } else { |
|
| 316 | + /* boundary automatique */ |
|
| 317 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 318 | + if ($boundary === '') { |
|
| 319 | + $taille = 0; |
|
| 320 | + foreach ($donnees as $cle => $valeur) { |
|
| 321 | + if (is_array($valeur)) { |
|
| 322 | + foreach ($valeur as $val2) { |
|
| 323 | + $taille += strlen((string) $val2); |
|
| 324 | + } |
|
| 325 | + } else { |
|
| 326 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 327 | + $taille += strlen((string) $valeur); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + if ($taille > 500) { |
|
| 331 | + $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if (is_string($boundary) && strlen($boundary)) { |
|
| 336 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 337 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 338 | + if (is_array($donnees)) { |
|
| 339 | + foreach ($donnees as $cle => $valeur) { |
|
| 340 | + if (is_array($valeur)) { |
|
| 341 | + foreach ($valeur as $val2) { |
|
| 342 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 343 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 344 | + $chaine .= "\r\n"; |
|
| 345 | + $chaine .= $val2; |
|
| 346 | + } |
|
| 347 | + } else { |
|
| 348 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 349 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 350 | + $chaine .= "\r\n"; |
|
| 351 | + $chaine .= $valeur; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + // fabrique une chaine HTTP simple pour un POST |
|
| 358 | + $entete = "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 359 | + if (is_array($donnees)) { |
|
| 360 | + $chaine = []; |
|
| 361 | + foreach ($donnees as $cle => $valeur) { |
|
| 362 | + if (is_array($valeur)) { |
|
| 363 | + foreach ($valeur as $val2) { |
|
| 364 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode((string) $val2); |
|
| 365 | + } |
|
| 366 | + } else { |
|
| 367 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode((string) $valeur); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + $chaine = implode('&', $chaine); |
|
| 371 | + } else { |
|
| 372 | + $chaine = $donnees; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return [$entete, $chaine]; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -385,19 +385,19 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function url_to_ascii($url_idn) { |
| 387 | 387 | |
| 388 | - if ($parts = parse_url($url_idn)) { |
|
| 389 | - $host = $parts['host']; |
|
| 390 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 391 | - $converter = new ToIdn(); |
|
| 392 | - $host_ascii = $converter->convert($host); |
|
| 393 | - $url_idn = explode($host, $url_idn, 2); |
|
| 394 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 395 | - } |
|
| 396 | - // et on urlencode les char utf si besoin dans le path |
|
| 397 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode((string) $match[0]), $url_idn); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - return $url_idn; |
|
| 388 | + if ($parts = parse_url($url_idn)) { |
|
| 389 | + $host = $parts['host']; |
|
| 390 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 391 | + $converter = new ToIdn(); |
|
| 392 | + $host_ascii = $converter->convert($host); |
|
| 393 | + $url_idn = explode($host, $url_idn, 2); |
|
| 394 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 395 | + } |
|
| 396 | + // et on urlencode les char utf si besoin dans le path |
|
| 397 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode((string) $match[0]), $url_idn); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + return $url_idn; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -438,209 +438,209 @@ discard block |
||
| 438 | 438 | * string file : nom du fichier si enregistre dans un fichier |
| 439 | 439 | */ |
| 440 | 440 | function recuperer_url($url, $options = []) { |
| 441 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 442 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 443 | - $default = [ |
|
| 444 | - 'transcoder' => false, |
|
| 445 | - 'methode' => 'GET', |
|
| 446 | - 'taille_max' => null, |
|
| 447 | - 'headers' => [], |
|
| 448 | - 'datas' => '', |
|
| 449 | - 'boundary' => '', |
|
| 450 | - 'refuser_gz' => false, |
|
| 451 | - 'if_modified_since' => '', |
|
| 452 | - 'uri_referer' => '', |
|
| 453 | - 'file' => '', |
|
| 454 | - 'follow_location' => 10, |
|
| 455 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 456 | - ]; |
|
| 457 | - $options = array_merge($default, $options); |
|
| 458 | - // copier directement dans un fichier ? |
|
| 459 | - $copy = $options['file']; |
|
| 460 | - |
|
| 461 | - if ($options['methode'] == 'HEAD') { |
|
| 462 | - $options['taille_max'] = 0; |
|
| 463 | - } |
|
| 464 | - if (is_null($options['taille_max'])) { |
|
| 465 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 469 | - |
|
| 470 | - // Ajout des en-têtes spécifiques si besoin |
|
| 471 | - $formatted_data = ''; |
|
| 472 | - if (!empty($options['headers'])) { |
|
| 473 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 474 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if (!empty($options['datas'])) { |
|
| 479 | - [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 480 | - $head .= $formatted_data; |
|
| 481 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 482 | - $head .= 'Content-Length: ' . strlen((string) $postdata) . "\r\n"; |
|
| 483 | - } |
|
| 484 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 485 | - if ( |
|
| 486 | - strlen((string) $postdata) && !$methode_demandee |
|
| 487 | - ) { |
|
| 488 | - $options['methode'] = 'POST'; |
|
| 489 | - } |
|
| 490 | - } elseif ($formatted_data) { |
|
| 491 | - $formatted_data .= "\r\n"; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 495 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 496 | - if (!tester_url_absolue($url)) { |
|
| 497 | - $url = 'http://' . $url; |
|
| 498 | - } elseif (str_starts_with($url, '//')) { |
|
| 499 | - $url = 'http:' . $url; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - $url = url_to_ascii($url); |
|
| 503 | - |
|
| 504 | - $result = [ |
|
| 505 | - 'status' => 0, |
|
| 506 | - 'headers' => '', |
|
| 507 | - 'page' => '', |
|
| 508 | - 'length' => 0, |
|
| 509 | - 'last_modified' => '', |
|
| 510 | - 'location' => '', |
|
| 511 | - 'url' => $url |
|
| 512 | - ]; |
|
| 513 | - |
|
| 514 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 515 | - $refuser_gz = ($options['refuser_gz'] || $copy); |
|
| 516 | - |
|
| 517 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 518 | - [$handle, $fopen] = init_http( |
|
| 519 | - $options['methode'], |
|
| 520 | - $url, |
|
| 521 | - $refuser_gz, |
|
| 522 | - $options['uri_referer'], |
|
| 523 | - $formatted_data, |
|
| 524 | - $options['version_http'], |
|
| 525 | - $options['if_modified_since'] |
|
| 526 | - ); |
|
| 527 | - if (!$handle) { |
|
| 528 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 529 | - |
|
| 530 | - return false; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 534 | - // et recuperer les en-tetes de reponses |
|
| 535 | - if (!$fopen) { |
|
| 536 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 537 | - if (!$res) { |
|
| 538 | - fclose($handle); |
|
| 539 | - $t = @parse_url($url); |
|
| 540 | - $host = $t['host']; |
|
| 541 | - // Chinoisierie inexplicable pour contrer |
|
| 542 | - // les actions liberticides de l'empire du milieu |
|
| 543 | - if ( |
|
| 544 | - !need_proxy($host) |
|
| 545 | - && ($res = @file_get_contents($url)) |
|
| 546 | - ) { |
|
| 547 | - $result['length'] = strlen($res); |
|
| 548 | - if ($copy) { |
|
| 549 | - ecrire_fichier($copy, $res); |
|
| 550 | - $result['file'] = $copy; |
|
| 551 | - } else { |
|
| 552 | - $result['page'] = $res; |
|
| 553 | - } |
|
| 554 | - $res = [ |
|
| 555 | - 'status' => 200, |
|
| 556 | - ]; |
|
| 557 | - } else { |
|
| 558 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - } elseif ($res['location'] && $options['follow_location']) { |
|
| 562 | - $options['follow_location']--; |
|
| 563 | - fclose($handle); |
|
| 564 | - include_spip('inc/filtres'); |
|
| 565 | - $url = suivre_lien($url, $res['location']); |
|
| 566 | - |
|
| 567 | - // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 568 | - if ( |
|
| 569 | - $options['methode'] !== 'GET' |
|
| 570 | - && (empty($res['status']) || !in_array($res['status'], [307, 308])) |
|
| 571 | - ) { |
|
| 572 | - $options['methode'] = 'GET'; |
|
| 573 | - $options['datas'] = ''; |
|
| 574 | - } |
|
| 575 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 576 | - |
|
| 577 | - return recuperer_url($url, $options); |
|
| 578 | - } elseif ($res['status'] !== 200) { |
|
| 579 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 580 | - } |
|
| 581 | - $result['status'] = $res['status']; |
|
| 582 | - if (isset($res['headers'])) { |
|
| 583 | - $result['headers'] = $res['headers']; |
|
| 584 | - } |
|
| 585 | - if (isset($res['last_modified'])) { |
|
| 586 | - $result['last_modified'] = $res['last_modified']; |
|
| 587 | - } |
|
| 588 | - if (isset($res['location'])) { |
|
| 589 | - $result['location'] = $res['location']; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - // on ne veut que les entetes |
|
| 594 | - if (!$options['taille_max'] || $options['methode'] == 'HEAD' || $result['status'] == '304') { |
|
| 595 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result, JSON_THROW_ON_ERROR), 'distant' . _LOG_DEBUG); |
|
| 596 | - return $result; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 601 | - // sinon la memoire explose pour les gros flux |
|
| 602 | - |
|
| 603 | - $gz = false; |
|
| 604 | - if (preg_match(",\bContent-Encoding: .*gzip,is", (string) $result['headers'])) { |
|
| 605 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 609 | - if (!$result['length']) { |
|
| 610 | - $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 611 | - fclose($handle); |
|
| 612 | - if ($copy) { |
|
| 613 | - $result['length'] = $res; |
|
| 614 | - $result['file'] = $copy; |
|
| 615 | - } elseif ($res) { |
|
| 616 | - $result['page'] = &$res; |
|
| 617 | - $result['length'] = strlen($result['page']); |
|
| 618 | - } |
|
| 619 | - if (!$result['status']) { |
|
| 620 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - if (!$result['page']) { |
|
| 624 | - return $result; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - // Decompresser au besoin |
|
| 628 | - if ($gz) { |
|
| 629 | - $result['page'] = implode('', gzfile($gz)); |
|
| 630 | - supprimer_fichier($gz); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // Faut-il l'importer dans notre charset local ? |
|
| 634 | - if ($options['transcoder']) { |
|
| 635 | - include_spip('inc/charsets'); |
|
| 636 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $trace = json_decode(json_encode($result, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); |
|
| 640 | - $trace['page'] = '...'; |
|
| 641 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace, JSON_THROW_ON_ERROR), 'distant' . _LOG_DEBUG); |
|
| 642 | - |
|
| 643 | - return $result; |
|
| 441 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 442 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 443 | + $default = [ |
|
| 444 | + 'transcoder' => false, |
|
| 445 | + 'methode' => 'GET', |
|
| 446 | + 'taille_max' => null, |
|
| 447 | + 'headers' => [], |
|
| 448 | + 'datas' => '', |
|
| 449 | + 'boundary' => '', |
|
| 450 | + 'refuser_gz' => false, |
|
| 451 | + 'if_modified_since' => '', |
|
| 452 | + 'uri_referer' => '', |
|
| 453 | + 'file' => '', |
|
| 454 | + 'follow_location' => 10, |
|
| 455 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 456 | + ]; |
|
| 457 | + $options = array_merge($default, $options); |
|
| 458 | + // copier directement dans un fichier ? |
|
| 459 | + $copy = $options['file']; |
|
| 460 | + |
|
| 461 | + if ($options['methode'] == 'HEAD') { |
|
| 462 | + $options['taille_max'] = 0; |
|
| 463 | + } |
|
| 464 | + if (is_null($options['taille_max'])) { |
|
| 465 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 469 | + |
|
| 470 | + // Ajout des en-têtes spécifiques si besoin |
|
| 471 | + $formatted_data = ''; |
|
| 472 | + if (!empty($options['headers'])) { |
|
| 473 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 474 | + $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if (!empty($options['datas'])) { |
|
| 479 | + [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 480 | + $head .= $formatted_data; |
|
| 481 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 482 | + $head .= 'Content-Length: ' . strlen((string) $postdata) . "\r\n"; |
|
| 483 | + } |
|
| 484 | + $formatted_data = $head . "\r\n" . $postdata; |
|
| 485 | + if ( |
|
| 486 | + strlen((string) $postdata) && !$methode_demandee |
|
| 487 | + ) { |
|
| 488 | + $options['methode'] = 'POST'; |
|
| 489 | + } |
|
| 490 | + } elseif ($formatted_data) { |
|
| 491 | + $formatted_data .= "\r\n"; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 495 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 496 | + if (!tester_url_absolue($url)) { |
|
| 497 | + $url = 'http://' . $url; |
|
| 498 | + } elseif (str_starts_with($url, '//')) { |
|
| 499 | + $url = 'http:' . $url; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + $url = url_to_ascii($url); |
|
| 503 | + |
|
| 504 | + $result = [ |
|
| 505 | + 'status' => 0, |
|
| 506 | + 'headers' => '', |
|
| 507 | + 'page' => '', |
|
| 508 | + 'length' => 0, |
|
| 509 | + 'last_modified' => '', |
|
| 510 | + 'location' => '', |
|
| 511 | + 'url' => $url |
|
| 512 | + ]; |
|
| 513 | + |
|
| 514 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 515 | + $refuser_gz = ($options['refuser_gz'] || $copy); |
|
| 516 | + |
|
| 517 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 518 | + [$handle, $fopen] = init_http( |
|
| 519 | + $options['methode'], |
|
| 520 | + $url, |
|
| 521 | + $refuser_gz, |
|
| 522 | + $options['uri_referer'], |
|
| 523 | + $formatted_data, |
|
| 524 | + $options['version_http'], |
|
| 525 | + $options['if_modified_since'] |
|
| 526 | + ); |
|
| 527 | + if (!$handle) { |
|
| 528 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 529 | + |
|
| 530 | + return false; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 534 | + // et recuperer les en-tetes de reponses |
|
| 535 | + if (!$fopen) { |
|
| 536 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 537 | + if (!$res) { |
|
| 538 | + fclose($handle); |
|
| 539 | + $t = @parse_url($url); |
|
| 540 | + $host = $t['host']; |
|
| 541 | + // Chinoisierie inexplicable pour contrer |
|
| 542 | + // les actions liberticides de l'empire du milieu |
|
| 543 | + if ( |
|
| 544 | + !need_proxy($host) |
|
| 545 | + && ($res = @file_get_contents($url)) |
|
| 546 | + ) { |
|
| 547 | + $result['length'] = strlen($res); |
|
| 548 | + if ($copy) { |
|
| 549 | + ecrire_fichier($copy, $res); |
|
| 550 | + $result['file'] = $copy; |
|
| 551 | + } else { |
|
| 552 | + $result['page'] = $res; |
|
| 553 | + } |
|
| 554 | + $res = [ |
|
| 555 | + 'status' => 200, |
|
| 556 | + ]; |
|
| 557 | + } else { |
|
| 558 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + } elseif ($res['location'] && $options['follow_location']) { |
|
| 562 | + $options['follow_location']--; |
|
| 563 | + fclose($handle); |
|
| 564 | + include_spip('inc/filtres'); |
|
| 565 | + $url = suivre_lien($url, $res['location']); |
|
| 566 | + |
|
| 567 | + // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 568 | + if ( |
|
| 569 | + $options['methode'] !== 'GET' |
|
| 570 | + && (empty($res['status']) || !in_array($res['status'], [307, 308])) |
|
| 571 | + ) { |
|
| 572 | + $options['methode'] = 'GET'; |
|
| 573 | + $options['datas'] = ''; |
|
| 574 | + } |
|
| 575 | + spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 576 | + |
|
| 577 | + return recuperer_url($url, $options); |
|
| 578 | + } elseif ($res['status'] !== 200) { |
|
| 579 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 580 | + } |
|
| 581 | + $result['status'] = $res['status']; |
|
| 582 | + if (isset($res['headers'])) { |
|
| 583 | + $result['headers'] = $res['headers']; |
|
| 584 | + } |
|
| 585 | + if (isset($res['last_modified'])) { |
|
| 586 | + $result['last_modified'] = $res['last_modified']; |
|
| 587 | + } |
|
| 588 | + if (isset($res['location'])) { |
|
| 589 | + $result['location'] = $res['location']; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + // on ne veut que les entetes |
|
| 594 | + if (!$options['taille_max'] || $options['methode'] == 'HEAD' || $result['status'] == '304') { |
|
| 595 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result, JSON_THROW_ON_ERROR), 'distant' . _LOG_DEBUG); |
|
| 596 | + return $result; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 601 | + // sinon la memoire explose pour les gros flux |
|
| 602 | + |
|
| 603 | + $gz = false; |
|
| 604 | + if (preg_match(",\bContent-Encoding: .*gzip,is", (string) $result['headers'])) { |
|
| 605 | + $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 609 | + if (!$result['length']) { |
|
| 610 | + $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 611 | + fclose($handle); |
|
| 612 | + if ($copy) { |
|
| 613 | + $result['length'] = $res; |
|
| 614 | + $result['file'] = $copy; |
|
| 615 | + } elseif ($res) { |
|
| 616 | + $result['page'] = &$res; |
|
| 617 | + $result['length'] = strlen($result['page']); |
|
| 618 | + } |
|
| 619 | + if (!$result['status']) { |
|
| 620 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + if (!$result['page']) { |
|
| 624 | + return $result; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // Decompresser au besoin |
|
| 628 | + if ($gz) { |
|
| 629 | + $result['page'] = implode('', gzfile($gz)); |
|
| 630 | + supprimer_fichier($gz); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + // Faut-il l'importer dans notre charset local ? |
|
| 634 | + if ($options['transcoder']) { |
|
| 635 | + include_spip('inc/charsets'); |
|
| 636 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $trace = json_decode(json_encode($result, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); |
|
| 640 | + $trace['page'] = '...'; |
|
| 641 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace, JSON_THROW_ON_ERROR), 'distant' . _LOG_DEBUG); |
|
| 642 | + |
|
| 643 | + return $result; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -656,73 +656,73 @@ discard block |
||
| 656 | 656 | * @return array|bool|mixed |
| 657 | 657 | */ |
| 658 | 658 | function recuperer_url_cache($url, $options = []) { |
| 659 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 660 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 661 | - } |
|
| 662 | - $default = [ |
|
| 663 | - 'transcoder' => false, |
|
| 664 | - 'methode' => 'GET', |
|
| 665 | - 'taille_max' => null, |
|
| 666 | - 'datas' => '', |
|
| 667 | - 'boundary' => '', |
|
| 668 | - 'refuser_gz' => false, |
|
| 669 | - 'if_modified_since' => '', |
|
| 670 | - 'uri_referer' => '', |
|
| 671 | - 'file' => '', |
|
| 672 | - 'follow_location' => 10, |
|
| 673 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 674 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 675 | - ]; |
|
| 676 | - $options = array_merge($default, $options); |
|
| 677 | - |
|
| 678 | - // cas ou il n'est pas possible de cacher |
|
| 679 | - if (!empty($options['data']) || $options['methode'] == 'POST') { |
|
| 680 | - return recuperer_url($url, $options); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 684 | - static $errors = []; |
|
| 685 | - if (isset($errors[$url])) { |
|
| 686 | - return $errors[$url]; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - $sig = $options; |
|
| 690 | - unset($sig['if_modified_since']); |
|
| 691 | - unset($sig['delai_cache']); |
|
| 692 | - $sig['url'] = $url; |
|
| 693 | - |
|
| 694 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 695 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 696 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 697 | - $cache = "$sub$cache"; |
|
| 698 | - |
|
| 699 | - $res = false; |
|
| 700 | - $is_cached = file_exists($cache); |
|
| 701 | - if ( |
|
| 702 | - $is_cached |
|
| 703 | - && filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'] |
|
| 704 | - ) { |
|
| 705 | - lire_fichier($cache, $res); |
|
| 706 | - if ($res = unserialize($res)) { |
|
| 707 | - // mettre le last_modified et le status=304 ? |
|
| 708 | - } |
|
| 709 | - } |
|
| 710 | - if (!$res) { |
|
| 711 | - $res = recuperer_url($url, $options); |
|
| 712 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 713 | - if (!$res) { |
|
| 714 | - if ($is_cached) { |
|
| 715 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 716 | - lire_fichier($cache, $res); |
|
| 717 | - $res = unserialize($res); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - return $errors[$url] = $res; |
|
| 721 | - } |
|
| 722 | - ecrire_fichier($cache, serialize($res)); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - return $res; |
|
| 659 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 660 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 661 | + } |
|
| 662 | + $default = [ |
|
| 663 | + 'transcoder' => false, |
|
| 664 | + 'methode' => 'GET', |
|
| 665 | + 'taille_max' => null, |
|
| 666 | + 'datas' => '', |
|
| 667 | + 'boundary' => '', |
|
| 668 | + 'refuser_gz' => false, |
|
| 669 | + 'if_modified_since' => '', |
|
| 670 | + 'uri_referer' => '', |
|
| 671 | + 'file' => '', |
|
| 672 | + 'follow_location' => 10, |
|
| 673 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 674 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 675 | + ]; |
|
| 676 | + $options = array_merge($default, $options); |
|
| 677 | + |
|
| 678 | + // cas ou il n'est pas possible de cacher |
|
| 679 | + if (!empty($options['data']) || $options['methode'] == 'POST') { |
|
| 680 | + return recuperer_url($url, $options); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 684 | + static $errors = []; |
|
| 685 | + if (isset($errors[$url])) { |
|
| 686 | + return $errors[$url]; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + $sig = $options; |
|
| 690 | + unset($sig['if_modified_since']); |
|
| 691 | + unset($sig['delai_cache']); |
|
| 692 | + $sig['url'] = $url; |
|
| 693 | + |
|
| 694 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 695 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 696 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 697 | + $cache = "$sub$cache"; |
|
| 698 | + |
|
| 699 | + $res = false; |
|
| 700 | + $is_cached = file_exists($cache); |
|
| 701 | + if ( |
|
| 702 | + $is_cached |
|
| 703 | + && filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'] |
|
| 704 | + ) { |
|
| 705 | + lire_fichier($cache, $res); |
|
| 706 | + if ($res = unserialize($res)) { |
|
| 707 | + // mettre le last_modified et le status=304 ? |
|
| 708 | + } |
|
| 709 | + } |
|
| 710 | + if (!$res) { |
|
| 711 | + $res = recuperer_url($url, $options); |
|
| 712 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 713 | + if (!$res) { |
|
| 714 | + if ($is_cached) { |
|
| 715 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 716 | + lire_fichier($cache, $res); |
|
| 717 | + $res = unserialize($res); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + return $errors[$url] = $res; |
|
| 721 | + } |
|
| 722 | + ecrire_fichier($cache, serialize($res)); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + return $res; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -740,42 +740,42 @@ discard block |
||
| 740 | 740 | * string contenu de la resource |
| 741 | 741 | */ |
| 742 | 742 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 743 | - $tmpfile = null; |
|
| 744 | - $taille = 0; |
|
| 745 | - $result = ''; |
|
| 746 | - $fp = false; |
|
| 747 | - if ($fichier) { |
|
| 748 | - include_spip('inc/acces'); |
|
| 749 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 750 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 751 | - if (!$fp && file_exists($fichier)) { |
|
| 752 | - return filesize($fichier); |
|
| 753 | - } |
|
| 754 | - if (!$fp) { |
|
| 755 | - return false; |
|
| 756 | - } |
|
| 757 | - $result = 0; // on renvoie la taille du fichier |
|
| 758 | - } |
|
| 759 | - while (!feof($handle) && $taille < $taille_max) { |
|
| 760 | - $res = fread($handle, 16384); |
|
| 761 | - $taille += strlen($res); |
|
| 762 | - if ($fp) { |
|
| 763 | - fwrite($fp, $res); |
|
| 764 | - $result = $taille; |
|
| 765 | - } else { |
|
| 766 | - $result .= $res; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - if ($fp) { |
|
| 770 | - spip_fclose_unlock($fp); |
|
| 771 | - spip_unlink($fichier); |
|
| 772 | - @rename($tmpfile, $fichier); |
|
| 773 | - if (!file_exists($fichier)) { |
|
| 774 | - return false; |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - return $result; |
|
| 743 | + $tmpfile = null; |
|
| 744 | + $taille = 0; |
|
| 745 | + $result = ''; |
|
| 746 | + $fp = false; |
|
| 747 | + if ($fichier) { |
|
| 748 | + include_spip('inc/acces'); |
|
| 749 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 750 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 751 | + if (!$fp && file_exists($fichier)) { |
|
| 752 | + return filesize($fichier); |
|
| 753 | + } |
|
| 754 | + if (!$fp) { |
|
| 755 | + return false; |
|
| 756 | + } |
|
| 757 | + $result = 0; // on renvoie la taille du fichier |
|
| 758 | + } |
|
| 759 | + while (!feof($handle) && $taille < $taille_max) { |
|
| 760 | + $res = fread($handle, 16384); |
|
| 761 | + $taille += strlen($res); |
|
| 762 | + if ($fp) { |
|
| 763 | + fwrite($fp, $res); |
|
| 764 | + $result = $taille; |
|
| 765 | + } else { |
|
| 766 | + $result .= $res; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + if ($fp) { |
|
| 770 | + spip_fclose_unlock($fp); |
|
| 771 | + spip_unlink($fichier); |
|
| 772 | + @rename($tmpfile, $fichier); |
|
| 773 | + if (!file_exists($fichier)) { |
|
| 774 | + return false; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + return $result; |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -797,35 +797,35 @@ discard block |
||
| 797 | 797 | * string location |
| 798 | 798 | */ |
| 799 | 799 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 800 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 801 | - |
|
| 802 | - $s = @trim(fgets($handle, 16384)); |
|
| 803 | - if (!preg_match(',^HTTP/\d+\.\d+ (\d+),', $s, $r)) { |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - $result['status'] = (int) $r[1]; |
|
| 807 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 808 | - $result['headers'][] = $s . "\n"; |
|
| 809 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 810 | - [, $d, $v] = $r; |
|
| 811 | - if (strtolower(trim($d)) == 'location' && $result['status'] >= 300 && $result['status'] < 400) { |
|
| 812 | - $result['location'] = $v; |
|
| 813 | - } elseif ($d == 'Last-Modified') { |
|
| 814 | - $result['last_modified'] = strtotime($v); |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - if ( |
|
| 818 | - $if_modified_since |
|
| 819 | - && $result['last_modified'] |
|
| 820 | - && $if_modified_since > $result['last_modified'] |
|
| 821 | - && $result['status'] == 200 |
|
| 822 | - ) { |
|
| 823 | - $result['status'] = 304; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - $result['headers'] = implode('', $result['headers']); |
|
| 827 | - |
|
| 828 | - return $result; |
|
| 800 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 801 | + |
|
| 802 | + $s = @trim(fgets($handle, 16384)); |
|
| 803 | + if (!preg_match(',^HTTP/\d+\.\d+ (\d+),', $s, $r)) { |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + $result['status'] = (int) $r[1]; |
|
| 807 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 808 | + $result['headers'][] = $s . "\n"; |
|
| 809 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 810 | + [, $d, $v] = $r; |
|
| 811 | + if (strtolower(trim($d)) == 'location' && $result['status'] >= 300 && $result['status'] < 400) { |
|
| 812 | + $result['location'] = $v; |
|
| 813 | + } elseif ($d == 'Last-Modified') { |
|
| 814 | + $result['last_modified'] = strtotime($v); |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + if ( |
|
| 818 | + $if_modified_since |
|
| 819 | + && $result['last_modified'] |
|
| 820 | + && $if_modified_since > $result['last_modified'] |
|
| 821 | + && $result['status'] == 200 |
|
| 822 | + ) { |
|
| 823 | + $result['status'] = 304; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + $result['headers'] = implode('', $result['headers']); |
|
| 827 | + |
|
| 828 | + return $result; |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -847,22 +847,22 @@ discard block |
||
| 847 | 847 | * Nom du fichier pour copie locale |
| 848 | 848 | **/ |
| 849 | 849 | function nom_fichier_copie_locale($source, $extension) { |
| 850 | - include_spip('inc/documents'); |
|
| 850 | + include_spip('inc/documents'); |
|
| 851 | 851 | |
| 852 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 853 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 852 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 853 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 854 | 854 | |
| 855 | - // on se place tout le temps comme si on etait a la racine |
|
| 856 | - if (_DIR_RACINE) { |
|
| 857 | - $d = preg_replace(',^' . preg_quote((string) _DIR_RACINE, ',') . ',', '', (string) $d); |
|
| 858 | - } |
|
| 855 | + // on se place tout le temps comme si on etait a la racine |
|
| 856 | + if (_DIR_RACINE) { |
|
| 857 | + $d = preg_replace(',^' . preg_quote((string) _DIR_RACINE, ',') . ',', '', (string) $d); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - $m = md5($source); |
|
| 860 | + $m = md5($source); |
|
| 861 | 861 | |
| 862 | - return $d |
|
| 863 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 864 | - . substr($m, 0, 4) |
|
| 865 | - . ".$extension"; |
|
| 862 | + return $d |
|
| 863 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 864 | + . substr($m, 0, 4) |
|
| 865 | + . ".$extension"; |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
@@ -881,72 +881,72 @@ discard block |
||
| 881 | 881 | * - null: Copie locale impossible |
| 882 | 882 | **/ |
| 883 | 883 | function fichier_copie_locale($source) { |
| 884 | - // Si c'est deja local pas de souci |
|
| 885 | - if (!tester_url_absolue($source)) { |
|
| 886 | - if (_DIR_RACINE) { |
|
| 887 | - $source = preg_replace(',^' . preg_quote((string) _DIR_RACINE, ',') . ',', '', $source); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - return $source; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 894 | - // a deja ete copie en local avec cette extension |
|
| 895 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 896 | - $path_parts = pathinfo($source); |
|
| 897 | - if (!isset($path_parts['extension'])) { |
|
| 898 | - $path_parts['extension'] = ''; |
|
| 899 | - } |
|
| 900 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 901 | - if ( |
|
| 902 | - $ext |
|
| 903 | - && preg_match(',^\w+$,', $ext) |
|
| 904 | - && ($f = nom_fichier_copie_locale($source, $ext)) |
|
| 905 | - && file_exists(_DIR_RACINE . $f) |
|
| 906 | - ) { |
|
| 907 | - return $f; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - // Si c'est deja dans la table des documents, |
|
| 912 | - // ramener le nom de sa copie potentielle |
|
| 913 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 914 | - |
|
| 915 | - if ($ext) { |
|
| 916 | - return nom_fichier_copie_locale($source, $ext); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 920 | - // et si il n'aurait pas deja ete rapatrie |
|
| 921 | - |
|
| 922 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 923 | - |
|
| 924 | - if ($ext && sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 925 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 926 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 927 | - return $f; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - // Ping pour voir si son extension est connue et autorisee |
|
| 932 | - // avec mise en cache du resultat du ping |
|
| 933 | - |
|
| 934 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 935 | - if ( |
|
| 936 | - !@file_exists($cache) |
|
| 937 | - || !($path_parts = @unserialize(spip_file_get_contents($cache))) |
|
| 938 | - || _request('var_mode') === 'recalcul' |
|
| 939 | - ) { |
|
| 940 | - $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 941 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 942 | - } |
|
| 943 | - $ext = empty($path_parts['extension']) ? '' : $path_parts['extension']; |
|
| 944 | - if ($ext && sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 945 | - return nom_fichier_copie_locale($source, $ext); |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 949 | - return null; |
|
| 884 | + // Si c'est deja local pas de souci |
|
| 885 | + if (!tester_url_absolue($source)) { |
|
| 886 | + if (_DIR_RACINE) { |
|
| 887 | + $source = preg_replace(',^' . preg_quote((string) _DIR_RACINE, ',') . ',', '', $source); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + return $source; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 894 | + // a deja ete copie en local avec cette extension |
|
| 895 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 896 | + $path_parts = pathinfo($source); |
|
| 897 | + if (!isset($path_parts['extension'])) { |
|
| 898 | + $path_parts['extension'] = ''; |
|
| 899 | + } |
|
| 900 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 901 | + if ( |
|
| 902 | + $ext |
|
| 903 | + && preg_match(',^\w+$,', $ext) |
|
| 904 | + && ($f = nom_fichier_copie_locale($source, $ext)) |
|
| 905 | + && file_exists(_DIR_RACINE . $f) |
|
| 906 | + ) { |
|
| 907 | + return $f; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + // Si c'est deja dans la table des documents, |
|
| 912 | + // ramener le nom de sa copie potentielle |
|
| 913 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 914 | + |
|
| 915 | + if ($ext) { |
|
| 916 | + return nom_fichier_copie_locale($source, $ext); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 920 | + // et si il n'aurait pas deja ete rapatrie |
|
| 921 | + |
|
| 922 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 923 | + |
|
| 924 | + if ($ext && sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 925 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 926 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 927 | + return $f; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + // Ping pour voir si son extension est connue et autorisee |
|
| 932 | + // avec mise en cache du resultat du ping |
|
| 933 | + |
|
| 934 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 935 | + if ( |
|
| 936 | + !@file_exists($cache) |
|
| 937 | + || !($path_parts = @unserialize(spip_file_get_contents($cache))) |
|
| 938 | + || _request('var_mode') === 'recalcul' |
|
| 939 | + ) { |
|
| 940 | + $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 941 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 942 | + } |
|
| 943 | + $ext = empty($path_parts['extension']) ? '' : $path_parts['extension']; |
|
| 944 | + if ($ext && sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 945 | + return nom_fichier_copie_locale($source, $ext); |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 949 | + return null; |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | |
@@ -975,112 +975,112 @@ discard block |
||
| 975 | 975 | **/ |
| 976 | 976 | function recuperer_infos_distantes($source, $options = []) { |
| 977 | 977 | |
| 978 | - // pas la peine de perdre son temps |
|
| 979 | - if (!tester_url_absolue($source)) { |
|
| 980 | - return false; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - $taille_max = $options['taille_max'] ?? 0; |
|
| 984 | - $charger_si_petite_image = (bool) ($options['charger_si_petite_image'] ?? true); |
|
| 985 | - $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 986 | - |
|
| 987 | - # charger les alias des types mime |
|
| 988 | - include_spip('base/typedoc'); |
|
| 989 | - |
|
| 990 | - $a = []; |
|
| 991 | - $mime_type = ''; |
|
| 992 | - // On va directement charger le debut des images et des fichiers html, |
|
| 993 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 994 | - // ca echoue l'utilisateur devra les entrer... |
|
| 995 | - $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 996 | - if ( |
|
| 997 | - $callback_valider_url |
|
| 998 | - && is_callable($callback_valider_url) |
|
| 999 | - && !$callback_valider_url($reponse['url']) |
|
| 1000 | - ) { |
|
| 1001 | - return false; |
|
| 1002 | - } |
|
| 1003 | - $headers = $reponse['headers'] ?? ''; |
|
| 1004 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 1005 | - if ($headers) { |
|
| 1006 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1007 | - return false; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - $a['extension'] = $extension; |
|
| 1011 | - |
|
| 1012 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1013 | - $a['taille'] = (int) $regs[1]; |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - // Echec avec HEAD, on tente avec GET |
|
| 1018 | - if (!$a && !$taille_max) { |
|
| 1019 | - spip_log("tenter GET $source", 'distant'); |
|
| 1020 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1021 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - // si on a rien trouve pas la peine d'insister |
|
| 1025 | - if (!$a) { |
|
| 1026 | - return false; |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1030 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1031 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1032 | - if ( |
|
| 1033 | - str_starts_with($mime_type, 'image/') |
|
| 1034 | - && ($extension = _image_trouver_extension_depuis_mime($mime_type)) |
|
| 1035 | - ) { |
|
| 1036 | - if ( |
|
| 1037 | - $taille_max == 0 |
|
| 1038 | - && (empty($a['taille']) || $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1039 | - && in_array($extension, formats_image_acceptables()) |
|
| 1040 | - && $charger_si_petite_image |
|
| 1041 | - ) { |
|
| 1042 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1043 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1044 | - } else { |
|
| 1045 | - if ($a['body']) { |
|
| 1046 | - $a['extension'] = $extension; |
|
| 1047 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1048 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1049 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1050 | - $a['largeur'] = (int) $size_image[0]; |
|
| 1051 | - $a['hauteur'] = (int) $size_image[1]; |
|
| 1052 | - $a['type_image'] = true; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1058 | - // ce sera mieux que 0x0 |
|
| 1059 | - // Flash is dead! |
|
| 1060 | - if ( |
|
| 1061 | - $a |
|
| 1062 | - && isset($a['extension']) |
|
| 1063 | - && $a['extension'] == 'swf' |
|
| 1064 | - && empty($a['largeur']) |
|
| 1065 | - ) { |
|
| 1066 | - $a['largeur'] = 425; |
|
| 1067 | - $a['hauteur'] = 350; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - if ($mime_type == 'text/html') { |
|
| 1071 | - include_spip('inc/filtres'); |
|
| 1072 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1073 | - $page = $page['page'] ?? ''; |
|
| 1074 | - if (preg_match(',<title>(.*?)</title>,ims', (string) $page, $regs)) { |
|
| 1075 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1076 | - } |
|
| 1077 | - if (!isset($a['taille']) || !$a['taille']) { |
|
| 1078 | - $a['taille'] = strlen((string) $page); # a peu pres |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - $a['mime_type'] = $mime_type; |
|
| 1082 | - |
|
| 1083 | - return $a; |
|
| 978 | + // pas la peine de perdre son temps |
|
| 979 | + if (!tester_url_absolue($source)) { |
|
| 980 | + return false; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + $taille_max = $options['taille_max'] ?? 0; |
|
| 984 | + $charger_si_petite_image = (bool) ($options['charger_si_petite_image'] ?? true); |
|
| 985 | + $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 986 | + |
|
| 987 | + # charger les alias des types mime |
|
| 988 | + include_spip('base/typedoc'); |
|
| 989 | + |
|
| 990 | + $a = []; |
|
| 991 | + $mime_type = ''; |
|
| 992 | + // On va directement charger le debut des images et des fichiers html, |
|
| 993 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 994 | + // ca echoue l'utilisateur devra les entrer... |
|
| 995 | + $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 996 | + if ( |
|
| 997 | + $callback_valider_url |
|
| 998 | + && is_callable($callback_valider_url) |
|
| 999 | + && !$callback_valider_url($reponse['url']) |
|
| 1000 | + ) { |
|
| 1001 | + return false; |
|
| 1002 | + } |
|
| 1003 | + $headers = $reponse['headers'] ?? ''; |
|
| 1004 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 1005 | + if ($headers) { |
|
| 1006 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1007 | + return false; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + $a['extension'] = $extension; |
|
| 1011 | + |
|
| 1012 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1013 | + $a['taille'] = (int) $regs[1]; |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + // Echec avec HEAD, on tente avec GET |
|
| 1018 | + if (!$a && !$taille_max) { |
|
| 1019 | + spip_log("tenter GET $source", 'distant'); |
|
| 1020 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1021 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + // si on a rien trouve pas la peine d'insister |
|
| 1025 | + if (!$a) { |
|
| 1026 | + return false; |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1030 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1031 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1032 | + if ( |
|
| 1033 | + str_starts_with($mime_type, 'image/') |
|
| 1034 | + && ($extension = _image_trouver_extension_depuis_mime($mime_type)) |
|
| 1035 | + ) { |
|
| 1036 | + if ( |
|
| 1037 | + $taille_max == 0 |
|
| 1038 | + && (empty($a['taille']) || $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1039 | + && in_array($extension, formats_image_acceptables()) |
|
| 1040 | + && $charger_si_petite_image |
|
| 1041 | + ) { |
|
| 1042 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1043 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1044 | + } else { |
|
| 1045 | + if ($a['body']) { |
|
| 1046 | + $a['extension'] = $extension; |
|
| 1047 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1048 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1049 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1050 | + $a['largeur'] = (int) $size_image[0]; |
|
| 1051 | + $a['hauteur'] = (int) $size_image[1]; |
|
| 1052 | + $a['type_image'] = true; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1058 | + // ce sera mieux que 0x0 |
|
| 1059 | + // Flash is dead! |
|
| 1060 | + if ( |
|
| 1061 | + $a |
|
| 1062 | + && isset($a['extension']) |
|
| 1063 | + && $a['extension'] == 'swf' |
|
| 1064 | + && empty($a['largeur']) |
|
| 1065 | + ) { |
|
| 1066 | + $a['largeur'] = 425; |
|
| 1067 | + $a['hauteur'] = 350; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + if ($mime_type == 'text/html') { |
|
| 1071 | + include_spip('inc/filtres'); |
|
| 1072 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1073 | + $page = $page['page'] ?? ''; |
|
| 1074 | + if (preg_match(',<title>(.*?)</title>,ims', (string) $page, $regs)) { |
|
| 1075 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1076 | + } |
|
| 1077 | + if (!isset($a['taille']) || !$a['taille']) { |
|
| 1078 | + $a['taille'] = strlen((string) $page); # a peu pres |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + $a['mime_type'] = $mime_type; |
|
| 1082 | + |
|
| 1083 | + return $a; |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1089,63 +1089,63 @@ discard block |
||
| 1089 | 1089 | * @return false|mixed |
| 1090 | 1090 | */ |
| 1091 | 1091 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1092 | - $mime_type = preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs) ? trim($regs[1]) : ''; // inconnu |
|
| 1093 | - |
|
| 1094 | - // Appliquer les alias |
|
| 1095 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1096 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - // pour corriger_extension() |
|
| 1100 | - include_spip('inc/documents'); |
|
| 1101 | - |
|
| 1102 | - // Si on a un mime-type insignifiant |
|
| 1103 | - // text/plain,application/octet-stream ou vide |
|
| 1104 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1105 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1106 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1107 | - $t = null; |
|
| 1108 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1109 | - if (!$t && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)) { |
|
| 1110 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1111 | - } |
|
| 1112 | - if ( |
|
| 1113 | - !$t |
|
| 1114 | - && preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1115 | - && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1116 | - ) { |
|
| 1117 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1122 | - if (!$t) { |
|
| 1123 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1127 | - // On essaie de nouveau avec l'extension |
|
| 1128 | - if ( |
|
| 1129 | - !$t |
|
| 1130 | - && $mime_type != 'text/plain' |
|
| 1131 | - && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1132 | - ) { |
|
| 1133 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1134 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - if ($t) { |
|
| 1138 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1139 | - return $t['extension']; |
|
| 1140 | - } else { |
|
| 1141 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1142 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1143 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1144 | - if (!$t) { |
|
| 1145 | - return false; |
|
| 1146 | - } |
|
| 1147 | - return $t['extension']; |
|
| 1148 | - } |
|
| 1092 | + $mime_type = preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs) ? trim($regs[1]) : ''; // inconnu |
|
| 1093 | + |
|
| 1094 | + // Appliquer les alias |
|
| 1095 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1096 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + // pour corriger_extension() |
|
| 1100 | + include_spip('inc/documents'); |
|
| 1101 | + |
|
| 1102 | + // Si on a un mime-type insignifiant |
|
| 1103 | + // text/plain,application/octet-stream ou vide |
|
| 1104 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1105 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1106 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1107 | + $t = null; |
|
| 1108 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1109 | + if (!$t && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)) { |
|
| 1110 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1111 | + } |
|
| 1112 | + if ( |
|
| 1113 | + !$t |
|
| 1114 | + && preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1115 | + && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1116 | + ) { |
|
| 1117 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1122 | + if (!$t) { |
|
| 1123 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1127 | + // On essaie de nouveau avec l'extension |
|
| 1128 | + if ( |
|
| 1129 | + !$t |
|
| 1130 | + && $mime_type != 'text/plain' |
|
| 1131 | + && preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1132 | + ) { |
|
| 1133 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1134 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + if ($t) { |
|
| 1138 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1139 | + return $t['extension']; |
|
| 1140 | + } else { |
|
| 1141 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1142 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1143 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1144 | + if (!$t) { |
|
| 1145 | + return false; |
|
| 1146 | + } |
|
| 1147 | + return $t['extension']; |
|
| 1148 | + } |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1161,45 +1161,45 @@ discard block |
||
| 1161 | 1161 | */ |
| 1162 | 1162 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1163 | 1163 | |
| 1164 | - $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1165 | - |
|
| 1166 | - // rien a faire si pas de proxy :) |
|
| 1167 | - if (is_null($http_proxy) || !$http_proxy = trim((string) $http_proxy)) { |
|
| 1168 | - return ''; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - if (is_null($http_noproxy)) { |
|
| 1172 | - $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1173 | - } |
|
| 1174 | - // si pas d'exception, on retourne le proxy |
|
| 1175 | - if (is_null($http_noproxy) || !$http_noproxy = trim((string) $http_noproxy)) { |
|
| 1176 | - return $http_proxy; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1180 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1181 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1182 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1183 | - $http_noproxy = " $http_noproxy "; |
|
| 1184 | - $domain = $host; |
|
| 1185 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1186 | - if (str_contains($http_noproxy, (string) " $domain ")) { |
|
| 1187 | - return ''; |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - while (str_contains($domain, '.')) { |
|
| 1191 | - $domain = explode('.', $domain); |
|
| 1192 | - array_shift($domain); |
|
| 1193 | - $domain = implode('.', $domain); |
|
| 1194 | - |
|
| 1195 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1196 | - if (str_contains($http_noproxy, (string) " .$domain ")) { |
|
| 1197 | - return ''; |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - // ok c'est pas une exception |
|
| 1202 | - return $http_proxy; |
|
| 1164 | + $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1165 | + |
|
| 1166 | + // rien a faire si pas de proxy :) |
|
| 1167 | + if (is_null($http_proxy) || !$http_proxy = trim((string) $http_proxy)) { |
|
| 1168 | + return ''; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + if (is_null($http_noproxy)) { |
|
| 1172 | + $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1173 | + } |
|
| 1174 | + // si pas d'exception, on retourne le proxy |
|
| 1175 | + if (is_null($http_noproxy) || !$http_noproxy = trim((string) $http_noproxy)) { |
|
| 1176 | + return $http_proxy; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1180 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1181 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1182 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1183 | + $http_noproxy = " $http_noproxy "; |
|
| 1184 | + $domain = $host; |
|
| 1185 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1186 | + if (str_contains($http_noproxy, (string) " $domain ")) { |
|
| 1187 | + return ''; |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + while (str_contains($domain, '.')) { |
|
| 1191 | + $domain = explode('.', $domain); |
|
| 1192 | + array_shift($domain); |
|
| 1193 | + $domain = implode('.', $domain); |
|
| 1194 | + |
|
| 1195 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1196 | + if (str_contains($http_noproxy, (string) " .$domain ")) { |
|
| 1197 | + return ''; |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + // ok c'est pas une exception |
|
| 1202 | + return $http_proxy; |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | |
@@ -1222,59 +1222,59 @@ discard block |
||
| 1222 | 1222 | * @return array |
| 1223 | 1223 | */ |
| 1224 | 1224 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1225 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1226 | - $fopen = false; |
|
| 1227 | - |
|
| 1228 | - $t = @parse_url($url); |
|
| 1229 | - $host = $t['host']; |
|
| 1230 | - if ($t['scheme'] == 'http') { |
|
| 1231 | - $scheme = 'http'; |
|
| 1232 | - $noproxy = ''; |
|
| 1233 | - } elseif ($t['scheme'] == 'https') { |
|
| 1234 | - $scheme = 'ssl'; |
|
| 1235 | - $noproxy = 'ssl://'; |
|
| 1236 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1237 | - $t['port'] = 443; |
|
| 1238 | - } |
|
| 1239 | - } else { |
|
| 1240 | - $scheme = $t['scheme']; |
|
| 1241 | - $noproxy = $scheme . '://'; |
|
| 1242 | - } |
|
| 1243 | - if (isset($t['user'])) { |
|
| 1244 | - $user = [$t['user'], $t['pass']]; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1248 | - $port = 80; |
|
| 1249 | - } |
|
| 1250 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1251 | - $path = '/'; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - if (!empty($t['query'])) { |
|
| 1255 | - $path .= '?' . $t['query']; |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1259 | - if (!$f || !is_resource($f)) { |
|
| 1260 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1261 | - // ce qui correspond a $f===110 |
|
| 1262 | - if ( |
|
| 1263 | - $f !== 110 |
|
| 1264 | - && !need_proxy($host) |
|
| 1265 | - && !_request('tester_proxy') |
|
| 1266 | - && (!isset($GLOBALS['inc_distant_allow_fopen']) || $GLOBALS['inc_distant_allow_fopen']) |
|
| 1267 | - ) { |
|
| 1268 | - $f = @fopen($url, 'rb'); |
|
| 1269 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1270 | - $fopen = true; |
|
| 1271 | - } else { |
|
| 1272 | - // echec total |
|
| 1273 | - $f = false; |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - return [$f, $fopen]; |
|
| 1225 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1226 | + $fopen = false; |
|
| 1227 | + |
|
| 1228 | + $t = @parse_url($url); |
|
| 1229 | + $host = $t['host']; |
|
| 1230 | + if ($t['scheme'] == 'http') { |
|
| 1231 | + $scheme = 'http'; |
|
| 1232 | + $noproxy = ''; |
|
| 1233 | + } elseif ($t['scheme'] == 'https') { |
|
| 1234 | + $scheme = 'ssl'; |
|
| 1235 | + $noproxy = 'ssl://'; |
|
| 1236 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1237 | + $t['port'] = 443; |
|
| 1238 | + } |
|
| 1239 | + } else { |
|
| 1240 | + $scheme = $t['scheme']; |
|
| 1241 | + $noproxy = $scheme . '://'; |
|
| 1242 | + } |
|
| 1243 | + if (isset($t['user'])) { |
|
| 1244 | + $user = [$t['user'], $t['pass']]; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1248 | + $port = 80; |
|
| 1249 | + } |
|
| 1250 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1251 | + $path = '/'; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + if (!empty($t['query'])) { |
|
| 1255 | + $path .= '?' . $t['query']; |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1259 | + if (!$f || !is_resource($f)) { |
|
| 1260 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1261 | + // ce qui correspond a $f===110 |
|
| 1262 | + if ( |
|
| 1263 | + $f !== 110 |
|
| 1264 | + && !need_proxy($host) |
|
| 1265 | + && !_request('tester_proxy') |
|
| 1266 | + && (!isset($GLOBALS['inc_distant_allow_fopen']) || $GLOBALS['inc_distant_allow_fopen']) |
|
| 1267 | + ) { |
|
| 1268 | + $f = @fopen($url, 'rb'); |
|
| 1269 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1270 | + $fopen = true; |
|
| 1271 | + } else { |
|
| 1272 | + // echec total |
|
| 1273 | + $f = false; |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + return [$f, $fopen]; |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | /** |
@@ -1309,124 +1309,124 @@ discard block |
||
| 1309 | 1309 | * resource socket vers l'url demandee |
| 1310 | 1310 | */ |
| 1311 | 1311 | function lance_requete( |
| 1312 | - $method, |
|
| 1313 | - $scheme, |
|
| 1314 | - $user, |
|
| 1315 | - $host, |
|
| 1316 | - $path, |
|
| 1317 | - $port, |
|
| 1318 | - $noproxy, |
|
| 1319 | - $refuse_gz = false, |
|
| 1320 | - $referer = '', |
|
| 1321 | - $datas = '', |
|
| 1322 | - $vers = 'HTTP/1.0', |
|
| 1323 | - $date = '' |
|
| 1312 | + $method, |
|
| 1313 | + $scheme, |
|
| 1314 | + $user, |
|
| 1315 | + $host, |
|
| 1316 | + $path, |
|
| 1317 | + $port, |
|
| 1318 | + $noproxy, |
|
| 1319 | + $refuse_gz = false, |
|
| 1320 | + $referer = '', |
|
| 1321 | + $datas = '', |
|
| 1322 | + $vers = 'HTTP/1.0', |
|
| 1323 | + $date = '' |
|
| 1324 | 1324 | ) { |
| 1325 | 1325 | |
| 1326 | - $proxy_user = ''; |
|
| 1327 | - $http_proxy = need_proxy($host); |
|
| 1328 | - if ($user) { |
|
| 1329 | - $user = urlencode((string) $user[0]) . ':' . urlencode((string) $user[1]); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - $connect = ''; |
|
| 1333 | - if ($http_proxy) { |
|
| 1334 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') && in_array($scheme, ['tls','ssl'])) { |
|
| 1335 | - $path_host = ($user ? "$user@" : '') . $host . (($port != 80) ? ":$port" : ''); |
|
| 1336 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1337 | - . "Host: $path_host\r\n" |
|
| 1338 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1339 | - } else { |
|
| 1340 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1341 | - . ($user ? "$user@" : '') |
|
| 1342 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1343 | - } |
|
| 1344 | - $t2 = @parse_url($http_proxy); |
|
| 1345 | - $first_host = $t2['host']; |
|
| 1346 | - $first_port = ($t2['port'] ?? null) ?: 80; |
|
| 1347 | - if ($t2['user'] ?? null) { |
|
| 1348 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1349 | - } |
|
| 1350 | - } else { |
|
| 1351 | - $first_host = $noproxy . $host; |
|
| 1352 | - $first_port = $port; |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - if ($connect) { |
|
| 1356 | - $streamContext = stream_context_create([ |
|
| 1357 | - 'ssl' => [ |
|
| 1358 | - 'verify_peer' => false, |
|
| 1359 | - 'allow_self_signed' => true, |
|
| 1360 | - 'SNI_enabled' => true, |
|
| 1361 | - 'peer_name' => $host, |
|
| 1362 | - ] |
|
| 1363 | - ]); |
|
| 1364 | - $f = @stream_socket_client( |
|
| 1365 | - "tcp://$first_host:$first_port", |
|
| 1366 | - $errno, |
|
| 1367 | - $errstr, |
|
| 1368 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1369 | - STREAM_CLIENT_CONNECT, |
|
| 1370 | - $streamContext |
|
| 1371 | - ); |
|
| 1372 | - spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect'); |
|
| 1373 | - if (!$f) { |
|
| 1374 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1375 | - return $errno; |
|
| 1376 | - } |
|
| 1377 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1378 | - |
|
| 1379 | - fwrite($f, $connect); |
|
| 1380 | - fwrite($f, "\r\n"); |
|
| 1381 | - $res = fread($f, 1024); |
|
| 1382 | - if ( |
|
| 1383 | - !$res |
|
| 1384 | - || ($res = explode(' ', $res)) === [] |
|
| 1385 | - || $res[1] !== '200' |
|
| 1386 | - ) { |
|
| 1387 | - spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1388 | - fclose($f); |
|
| 1389 | - |
|
| 1390 | - return false; |
|
| 1391 | - } |
|
| 1392 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1393 | - stream_set_blocking($f, true); |
|
| 1394 | - // envoyer le handshake |
|
| 1395 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1396 | - spip_log("OK CONNECT sur $first_host:$first_port", 'connect'); |
|
| 1397 | - } else { |
|
| 1398 | - $ntry = 3; |
|
| 1399 | - do { |
|
| 1400 | - $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1401 | - } while (!$f && $ntry-- && $errno !== 110 && sleep(1)); |
|
| 1402 | - spip_log("Recuperer $path sur $first_host:$first_port par $f"); |
|
| 1403 | - if (!$f) { |
|
| 1404 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1405 | - |
|
| 1406 | - return $errno; |
|
| 1407 | - } |
|
| 1408 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1412 | - |
|
| 1413 | - $host_port = $host; |
|
| 1414 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1415 | - $host_port .= ":$port"; |
|
| 1416 | - } |
|
| 1417 | - $req = "$method $path $vers\r\n" |
|
| 1418 | - . "Host: $host_port\r\n" |
|
| 1419 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1420 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1421 | - . ($site ? "Referer: $site/$referer\r\n" : '') |
|
| 1422 | - . ($date ? 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n") : '') |
|
| 1423 | - . ($user ? 'Authorization: Basic ' . base64_encode($user) . "\r\n" : '') |
|
| 1424 | - . ($proxy_user ? "Proxy-Authorization: Basic $proxy_user\r\n" : '') |
|
| 1425 | - . (strpos($vers, '1.1') ? "Keep-Alive: 300\r\nConnection: keep-alive\r\n" : ''); |
|
| 1326 | + $proxy_user = ''; |
|
| 1327 | + $http_proxy = need_proxy($host); |
|
| 1328 | + if ($user) { |
|
| 1329 | + $user = urlencode((string) $user[0]) . ':' . urlencode((string) $user[1]); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + $connect = ''; |
|
| 1333 | + if ($http_proxy) { |
|
| 1334 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') && in_array($scheme, ['tls','ssl'])) { |
|
| 1335 | + $path_host = ($user ? "$user@" : '') . $host . (($port != 80) ? ":$port" : ''); |
|
| 1336 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1337 | + . "Host: $path_host\r\n" |
|
| 1338 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1339 | + } else { |
|
| 1340 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1341 | + . ($user ? "$user@" : '') |
|
| 1342 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1343 | + } |
|
| 1344 | + $t2 = @parse_url($http_proxy); |
|
| 1345 | + $first_host = $t2['host']; |
|
| 1346 | + $first_port = ($t2['port'] ?? null) ?: 80; |
|
| 1347 | + if ($t2['user'] ?? null) { |
|
| 1348 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1349 | + } |
|
| 1350 | + } else { |
|
| 1351 | + $first_host = $noproxy . $host; |
|
| 1352 | + $first_port = $port; |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + if ($connect) { |
|
| 1356 | + $streamContext = stream_context_create([ |
|
| 1357 | + 'ssl' => [ |
|
| 1358 | + 'verify_peer' => false, |
|
| 1359 | + 'allow_self_signed' => true, |
|
| 1360 | + 'SNI_enabled' => true, |
|
| 1361 | + 'peer_name' => $host, |
|
| 1362 | + ] |
|
| 1363 | + ]); |
|
| 1364 | + $f = @stream_socket_client( |
|
| 1365 | + "tcp://$first_host:$first_port", |
|
| 1366 | + $errno, |
|
| 1367 | + $errstr, |
|
| 1368 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1369 | + STREAM_CLIENT_CONNECT, |
|
| 1370 | + $streamContext |
|
| 1371 | + ); |
|
| 1372 | + spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect'); |
|
| 1373 | + if (!$f) { |
|
| 1374 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1375 | + return $errno; |
|
| 1376 | + } |
|
| 1377 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1378 | + |
|
| 1379 | + fwrite($f, $connect); |
|
| 1380 | + fwrite($f, "\r\n"); |
|
| 1381 | + $res = fread($f, 1024); |
|
| 1382 | + if ( |
|
| 1383 | + !$res |
|
| 1384 | + || ($res = explode(' ', $res)) === [] |
|
| 1385 | + || $res[1] !== '200' |
|
| 1386 | + ) { |
|
| 1387 | + spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1388 | + fclose($f); |
|
| 1389 | + |
|
| 1390 | + return false; |
|
| 1391 | + } |
|
| 1392 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1393 | + stream_set_blocking($f, true); |
|
| 1394 | + // envoyer le handshake |
|
| 1395 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1396 | + spip_log("OK CONNECT sur $first_host:$first_port", 'connect'); |
|
| 1397 | + } else { |
|
| 1398 | + $ntry = 3; |
|
| 1399 | + do { |
|
| 1400 | + $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1401 | + } while (!$f && $ntry-- && $errno !== 110 && sleep(1)); |
|
| 1402 | + spip_log("Recuperer $path sur $first_host:$first_port par $f"); |
|
| 1403 | + if (!$f) { |
|
| 1404 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1405 | + |
|
| 1406 | + return $errno; |
|
| 1407 | + } |
|
| 1408 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1412 | + |
|
| 1413 | + $host_port = $host; |
|
| 1414 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1415 | + $host_port .= ":$port"; |
|
| 1416 | + } |
|
| 1417 | + $req = "$method $path $vers\r\n" |
|
| 1418 | + . "Host: $host_port\r\n" |
|
| 1419 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1420 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1421 | + . ($site ? "Referer: $site/$referer\r\n" : '') |
|
| 1422 | + . ($date ? 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n") : '') |
|
| 1423 | + . ($user ? 'Authorization: Basic ' . base64_encode($user) . "\r\n" : '') |
|
| 1424 | + . ($proxy_user ? "Proxy-Authorization: Basic $proxy_user\r\n" : '') |
|
| 1425 | + . (strpos($vers, '1.1') ? "Keep-Alive: 300\r\nConnection: keep-alive\r\n" : ''); |
|
| 1426 | 1426 | |
| 1427 | 1427 | # spip_log("Requete\n$req", 'distant'); |
| 1428 | - fwrite($f, $req); |
|
| 1429 | - fwrite($f, $datas ?: "\r\n"); |
|
| 1428 | + fwrite($f, $req); |
|
| 1429 | + fwrite($f, $datas ?: "\r\n"); |
|
| 1430 | 1430 | |
| 1431 | - return $f; |
|
| 1431 | + return $f; |
|
| 1432 | 1432 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Spip\Texte\Collecteur\Modeles; |
| 14 | 14 | |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', ?Liens $collecteurLiens = null, $env = []) { |
| 28 | 28 | |
| 29 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | - $collecteurModeles = new Modeles(); |
|
| 29 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | + $collecteurModeles = new Modeles(); |
|
| 32 | 32 | |
| 33 | - $options = [ |
|
| 34 | - 'doublons' => $doublons, |
|
| 35 | - 'echap' => $echap, |
|
| 36 | - 'connect' => $connect, |
|
| 37 | - 'collecteurLiens' => $collecteurLiens, |
|
| 38 | - 'env' => $env |
|
| 39 | - ]; |
|
| 40 | - return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 33 | + $options = [ |
|
| 34 | + 'doublons' => $doublons, |
|
| 35 | + 'echap' => $echap, |
|
| 36 | + 'connect' => $connect, |
|
| 37 | + 'collecteurLiens' => $collecteurLiens, |
|
| 38 | + 'env' => $env |
|
| 39 | + ]; |
|
| 40 | + return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 41 | 41 | } |
@@ -10,76 +10,76 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 17 | 17 | |
| 18 | 18 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 19 | - include_spip('inc/texte'); |
|
| 20 | - $titre = $descriptif = ''; |
|
| 21 | - if ($type === 'rubrique') { |
|
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | - if ($row) { |
|
| 24 | - $titre = typo($row['titre']); |
|
| 25 | - $descriptif = propre($row['descriptif']); |
|
| 26 | - } else { |
|
| 27 | - $titre = _T('info_racine_site'); |
|
| 28 | - } |
|
| 29 | - } |
|
| 19 | + include_spip('inc/texte'); |
|
| 20 | + $titre = $descriptif = ''; |
|
| 21 | + if ($type === 'rubrique') { |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | + if ($row) { |
|
| 24 | + $titre = typo($row['titre']); |
|
| 25 | + $descriptif = propre($row['descriptif']); |
|
| 26 | + } else { |
|
| 27 | + $titre = _T('info_racine_site'); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $res = ''; |
|
| 32 | - if ( |
|
| 33 | - $type === 'rubrique' |
|
| 34 | - && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | - && isset($GLOBALS['meta']['image_process']) |
|
| 36 | - && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | - ) { |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | - [$fid, $dir, $nom, $format] = $res; |
|
| 41 | - include_spip('inc/filtres_images_mini'); |
|
| 42 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | - if ($res) { |
|
| 44 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + $res = ''; |
|
| 32 | + if ( |
|
| 33 | + $type === 'rubrique' |
|
| 34 | + && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | + && isset($GLOBALS['meta']['image_process']) |
|
| 36 | + && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | + ) { |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | + [$fid, $dir, $nom, $format] = $res; |
|
| 41 | + include_spip('inc/filtres_images_mini'); |
|
| 42 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | + if ($res) { |
|
| 44 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | - $id = (int) $id; |
|
| 49 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | + $id = (int) $id; |
|
| 52 | 52 | |
| 53 | 53 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 54 | 54 | # et l'affichage de son titre dans le bandeau |
| 55 | - $titre = strtr( |
|
| 56 | - str_replace( |
|
| 57 | - "'", |
|
| 58 | - '’', |
|
| 59 | - str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | - ), |
|
| 61 | - "\n\r", |
|
| 62 | - ' ' |
|
| 63 | - ); |
|
| 55 | + $titre = strtr( |
|
| 56 | + str_replace( |
|
| 57 | + "'", |
|
| 58 | + '’', |
|
| 59 | + str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | + ), |
|
| 61 | + "\n\r", |
|
| 62 | + ' ' |
|
| 63 | + ); |
|
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do . '_selection_titre'; |
|
| 66 | 66 | |
| 67 | - return "<div style='display: none;'>" |
|
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | - . entites_html($titre) |
|
| 71 | - . '" />' |
|
| 72 | - . '</div>' |
|
| 73 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | - . '<div class="informer__item">' |
|
| 75 | - . ($res ?: '') |
|
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | - . '</div>' |
|
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | - . _T('bouton_choisir') |
|
| 82 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | - . '</div>' |
|
| 84 | - . '</div>'; |
|
| 67 | + return "<div style='display: none;'>" |
|
| 68 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . entites_html($titre) |
|
| 71 | + . '" />' |
|
| 72 | + . '</div>' |
|
| 73 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | + . '<div class="informer__item">' |
|
| 75 | + . ($res ?: '') |
|
| 76 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | + . '</div>' |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | + . _T('bouton_choisir') |
|
| 82 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | + . '</div>' |
|
| 84 | + . '</div>'; |
|
| 85 | 85 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -17,16 +17,16 @@ 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('_SPIP_SELECT_RUBRIQUES')) { |
| 24 | - /** |
|
| 25 | - * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | - * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | - * mettre 100000 pour desactiver ajax |
|
| 28 | - */ |
|
| 29 | - define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 24 | + /** |
|
| 25 | + * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | + * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | + * mettre 100000 pour desactiver ajax |
|
| 28 | + */ |
|
| 29 | + define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -54,22 +54,22 @@ discard block |
||
| 54 | 54 | * Code HTML du sélecteur |
| 55 | 55 | **/ |
| 56 | 56 | function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 57 | - if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Mode sans Ajax : |
|
| 62 | - // - soit parce que le cookie ajax n'est pas la |
|
| 63 | - // - soit parce qu'il y a peu de rubriques |
|
| 64 | - if ( |
|
| 65 | - _SPIP_AJAX < 1 |
|
| 66 | - || $type == 'breve' |
|
| 67 | - || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | - ) { |
|
| 69 | - return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | - } else { |
|
| 71 | - return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | - } |
|
| 57 | + if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Mode sans Ajax : |
|
| 62 | + // - soit parce que le cookie ajax n'est pas la |
|
| 63 | + // - soit parce qu'il y a peu de rubriques |
|
| 64 | + if ( |
|
| 65 | + _SPIP_AJAX < 1 |
|
| 66 | + || $type == 'breve' |
|
| 67 | + || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | + ) { |
|
| 69 | + return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | + } else { |
|
| 71 | + return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // compatibilite pour extensions qui utilisaient l'ancien nom |
@@ -86,17 +86,17 @@ discard block |
||
| 86 | 86 | **/ |
| 87 | 87 | function style_menu_rubriques($i) { |
| 88 | 88 | |
| 89 | - $espace = ''; |
|
| 90 | - $style = ''; |
|
| 91 | - for ($count = 1; $count <= $i; $count++) { |
|
| 92 | - $espace .= ' '; |
|
| 93 | - } |
|
| 94 | - if ($i == 1) { |
|
| 95 | - $espace = ''; |
|
| 96 | - } |
|
| 97 | - $class = "niveau_$i"; |
|
| 98 | - |
|
| 99 | - return [$class, $style, $espace]; |
|
| 89 | + $espace = ''; |
|
| 90 | + $style = ''; |
|
| 91 | + for ($count = 1; $count <= $i; $count++) { |
|
| 92 | + $espace .= ' '; |
|
| 93 | + } |
|
| 94 | + if ($i == 1) { |
|
| 95 | + $espace = ''; |
|
| 96 | + } |
|
| 97 | + $class = "niveau_$i"; |
|
| 98 | + |
|
| 99 | + return [$class, $style, $espace]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -120,57 +120,57 @@ discard block |
||
| 120 | 120 | * Code HTML du sélecteur |
| 121 | 121 | **/ |
| 122 | 122 | function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) { |
| 123 | - static $decalage_secteur; |
|
| 124 | - |
|
| 125 | - // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | - if ($exclus > 0 && $root == $exclus) { |
|
| 127 | - return ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | - |
|
| 132 | - // selected ? |
|
| 133 | - $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | - |
|
| 135 | - // le style en fonction de la profondeur |
|
| 136 | - [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | - |
|
| 138 | - $class .= ' selec_rub'; |
|
| 139 | - |
|
| 140 | - // creer l'<option> pour la rubrique $root |
|
| 141 | - |
|
| 142 | - if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | - $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | - . $data[$root] |
|
| 145 | - . '</option>' . "\n"; |
|
| 146 | - } else { |
|
| 147 | - $r = ''; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // et le sous-menu pour ses enfants |
|
| 151 | - $sous = ''; |
|
| 152 | - if (isset($enfants[$root])) { |
|
| 153 | - foreach ($enfants[$root] as $sousrub) { |
|
| 154 | - $sous .= sous_menu_rubriques( |
|
| 155 | - $id_rubrique, |
|
| 156 | - $sousrub, |
|
| 157 | - $niv + 1, |
|
| 158 | - $data, |
|
| 159 | - $enfants, |
|
| 160 | - $exclus, |
|
| 161 | - $restreint, |
|
| 162 | - $type |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | - if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | - return $sous; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // et voila le travail |
|
| 173 | - return $r . $sous; |
|
| 123 | + static $decalage_secteur; |
|
| 124 | + |
|
| 125 | + // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | + if ($exclus > 0 && $root == $exclus) { |
|
| 127 | + return ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | + |
|
| 132 | + // selected ? |
|
| 133 | + $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | + |
|
| 135 | + // le style en fonction de la profondeur |
|
| 136 | + [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | + |
|
| 138 | + $class .= ' selec_rub'; |
|
| 139 | + |
|
| 140 | + // creer l'<option> pour la rubrique $root |
|
| 141 | + |
|
| 142 | + if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | + $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | + . $data[$root] |
|
| 145 | + . '</option>' . "\n"; |
|
| 146 | + } else { |
|
| 147 | + $r = ''; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // et le sous-menu pour ses enfants |
|
| 151 | + $sous = ''; |
|
| 152 | + if (isset($enfants[$root])) { |
|
| 153 | + foreach ($enfants[$root] as $sousrub) { |
|
| 154 | + $sous .= sous_menu_rubriques( |
|
| 155 | + $id_rubrique, |
|
| 156 | + $sousrub, |
|
| 157 | + $niv + 1, |
|
| 158 | + $data, |
|
| 159 | + $enfants, |
|
| 160 | + $exclus, |
|
| 161 | + $restreint, |
|
| 162 | + $type |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | + if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | + return $sous; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // et voila le travail |
|
| 173 | + return $r . $sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -191,75 +191,75 @@ discard block |
||
| 191 | 191 | * Code HTML du sélecteur |
| 192 | 192 | **/ |
| 193 | 193 | function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) { |
| 194 | - $enfants = []; |
|
| 195 | - $data = []; |
|
| 196 | - if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | - $data[0] = _T('info_racine_site'); |
|
| 198 | - } |
|
| 199 | - # premier choix = neant |
|
| 200 | - # si auteur (rubriques restreintes) |
|
| 201 | - # ou si creation avec id_rubrique=0 |
|
| 202 | - elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | - $data[0] = ' '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // |
|
| 207 | - // creer une structure contenant toute l'arborescence |
|
| 208 | - // |
|
| 209 | - |
|
| 210 | - include_spip('base/abstract_sql'); |
|
| 211 | - $q = sql_select( |
|
| 212 | - 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | - 'spip_rubriques', |
|
| 214 | - ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | - '', |
|
| 216 | - '0+titre,titre' |
|
| 217 | - ); |
|
| 218 | - while ($r = sql_fetch($q)) { |
|
| 219 | - if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | - // titre largeur maxi a 50 |
|
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | - if ( |
|
| 223 | - $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | - && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | - ) { |
|
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | - } |
|
| 228 | - $data[$r['id_rubrique']] = $titre; |
|
| 229 | - $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | - if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | - $id_parent = $r['id_parent']; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // si une seule rubrique comme choix possible, |
|
| 237 | - // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | - // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | - if ( |
|
| 240 | - count($data) == 2 |
|
| 241 | - && isset($data[0]) |
|
| 242 | - && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | - && !$id_rubrique |
|
| 244 | - ) { |
|
| 245 | - unset($data[0]); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | - $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | - |
|
| 252 | - if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | - } else { |
|
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - # message pour neuneus (a supprimer ?) |
|
| 194 | + $enfants = []; |
|
| 195 | + $data = []; |
|
| 196 | + if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | + $data[0] = _T('info_racine_site'); |
|
| 198 | + } |
|
| 199 | + # premier choix = neant |
|
| 200 | + # si auteur (rubriques restreintes) |
|
| 201 | + # ou si creation avec id_rubrique=0 |
|
| 202 | + elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | + $data[0] = ' '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // |
|
| 207 | + // creer une structure contenant toute l'arborescence |
|
| 208 | + // |
|
| 209 | + |
|
| 210 | + include_spip('base/abstract_sql'); |
|
| 211 | + $q = sql_select( |
|
| 212 | + 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | + 'spip_rubriques', |
|
| 214 | + ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | + '', |
|
| 216 | + '0+titre,titre' |
|
| 217 | + ); |
|
| 218 | + while ($r = sql_fetch($q)) { |
|
| 219 | + if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | + // titre largeur maxi a 50 |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | + if ( |
|
| 223 | + $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | + && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | + ) { |
|
| 226 | + $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | + } |
|
| 228 | + $data[$r['id_rubrique']] = $titre; |
|
| 229 | + $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | + if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | + $id_parent = $r['id_parent']; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // si une seule rubrique comme choix possible, |
|
| 237 | + // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | + // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | + if ( |
|
| 240 | + count($data) == 2 |
|
| 241 | + && isset($data[0]) |
|
| 242 | + && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | + && !$id_rubrique |
|
| 244 | + ) { |
|
| 245 | + unset($data[0]); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | + $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | + |
|
| 252 | + if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | + $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | + } else { |
|
| 255 | + $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + # message pour neuneus (a supprimer ?) |
|
| 259 | 259 | # if ($type != 'auteur' AND $type != 'breve') |
| 260 | 260 | # $r .= "\n<br />"._T('texte_rappel_selection_champs'); |
| 261 | 261 | |
| 262 | - return $r; |
|
| 262 | + return $r; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -293,22 +293,22 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | - if ($id_rubrique) { |
|
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | - } else { |
|
| 299 | - $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | - } |
|
| 296 | + if ($id_rubrique) { |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | + } else { |
|
| 299 | + $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 302 | + $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | - $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | - . ($idem ? "&exclus=$idem" : '') |
|
| 307 | - . ($restreint ? '' : '&racine=oui') |
|
| 308 | - . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 305 | + $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | + . ($idem ? "&exclus=$idem" : '') |
|
| 307 | + . ($restreint ? '' : '&racine=oui') |
|
| 308 | + . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 311 | + return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -338,30 +338,30 @@ discard block |
||
| 338 | 338 | * Code HTML du sélecteur de rubrique AJAX |
| 339 | 339 | **/ |
| 340 | 340 | function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) { |
| 341 | - $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | - // si icone de recherche on embed le svg |
|
| 343 | - $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | - $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | - |
|
| 346 | - return |
|
| 347 | - "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | - . $js |
|
| 349 | - . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | - . "return charger_node_url_si_vide('" |
|
| 351 | - . $url |
|
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | - . $img_icone |
|
| 354 | - . "</a><img src='" |
|
| 355 | - . chemin_image('loader.svg') |
|
| 356 | - . "' class='loader' id='img_" |
|
| 357 | - . $idom |
|
| 358 | - . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | - . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | - . $init |
|
| 361 | - . ' />' |
|
| 362 | - . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | - . $id |
|
| 364 | - . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | - . $idom |
|
| 366 | - . "'\nstyle='display: none;'></div>"; |
|
| 341 | + $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | + // si icone de recherche on embed le svg |
|
| 343 | + $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | + $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | + |
|
| 346 | + return |
|
| 347 | + "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | + . $js |
|
| 349 | + . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | + . "return charger_node_url_si_vide('" |
|
| 351 | + . $url |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | + . $img_icone |
|
| 354 | + . "</a><img src='" |
|
| 355 | + . chemin_image('loader.svg') |
|
| 356 | + . "' class='loader' id='img_" |
|
| 357 | + . $idom |
|
| 358 | + . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | + . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | + . $init |
|
| 361 | + . ' />' |
|
| 362 | + . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | + . $id |
|
| 364 | + . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | + . $idom |
|
| 366 | + . "'\nstyle='display: none;'></div>"; |
|
| 367 | 367 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | |
| 67 | 67 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 68 | - return; |
|
| 68 | + return; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,46 +76,46 @@ discard block |
||
| 76 | 76 | * @return array|false |
| 77 | 77 | */ |
| 78 | 78 | function cvtmulti_recuperer_post_precedents($form) { |
| 79 | - include_spip('inc/filtres'); |
|
| 80 | - if ( |
|
| 81 | - $form |
|
| 82 | - && ($c = _request('cvtm_prev_post')) |
|
| 83 | - && ($c = decoder_contexte_ajax($c, $form)) |
|
| 84 | - ) { |
|
| 85 | - #var_dump($c); |
|
| 79 | + include_spip('inc/filtres'); |
|
| 80 | + if ( |
|
| 81 | + $form |
|
| 82 | + && ($c = _request('cvtm_prev_post')) |
|
| 83 | + && ($c = decoder_contexte_ajax($c, $form)) |
|
| 84 | + ) { |
|
| 85 | + #var_dump($c); |
|
| 86 | 86 | |
| 87 | - # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | - # toutes les saisies dans un seul tableau |
|
| 89 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | - $store = &$_POST; |
|
| 91 | - } else { |
|
| 92 | - $store = &$_GET; |
|
| 93 | - } |
|
| 87 | + # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | + # toutes les saisies dans un seul tableau |
|
| 89 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | + $store = &$_POST; |
|
| 91 | + } else { |
|
| 92 | + $store = &$_GET; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 96 | - if (!isset($store[$k])) { |
|
| 97 | - $_REQUEST[$k] = $store[$k] = $v; |
|
| 98 | - } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 99 | - elseif ( |
|
| 100 | - is_array($store[$k]) |
|
| 101 | - && is_array($v) |
|
| 102 | - && ($z = array_keys($v)) |
|
| 103 | - && !is_numeric(reset($z)) |
|
| 104 | - && ($z = array_keys($store[$k])) |
|
| 105 | - && !is_numeric(reset($z)) |
|
| 106 | - ) { |
|
| 107 | - $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | - } |
|
| 109 | - } |
|
| 95 | + foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 96 | + if (!isset($store[$k])) { |
|
| 97 | + $_REQUEST[$k] = $store[$k] = $v; |
|
| 98 | + } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 99 | + elseif ( |
|
| 100 | + is_array($store[$k]) |
|
| 101 | + && is_array($v) |
|
| 102 | + && ($z = array_keys($v)) |
|
| 103 | + && !is_numeric(reset($z)) |
|
| 104 | + && ($z = array_keys($store[$k])) |
|
| 105 | + && !is_numeric(reset($z)) |
|
| 106 | + ) { |
|
| 107 | + $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // vider pour eviter un second appel a verifier_n |
|
| 112 | - // en cas de double implementation (unipotence) |
|
| 113 | - set_request('cvtm_prev_post'); |
|
| 111 | + // vider pour eviter un second appel a verifier_n |
|
| 112 | + // en cas de double implementation (unipotence) |
|
| 113 | + set_request('cvtm_prev_post'); |
|
| 114 | 114 | |
| 115 | - return [$c['_etape'], $c['_etapes']]; |
|
| 116 | - } |
|
| 115 | + return [$c['_etape'], $c['_etapes']]; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return false; |
|
| 118 | + return false; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -128,28 +128,28 @@ discard block |
||
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | 130 | function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) { |
| 131 | - if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | - $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 133 | - foreach (array_keys($valeurs) as $champ) { |
|
| 134 | - if ( |
|
| 135 | - !str_starts_with($champ, '_') |
|
| 136 | - && ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) |
|
| 137 | - && ($v = _request($champ)) !== null |
|
| 138 | - ) { |
|
| 139 | - $post[$champ] = $v; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - include_spip('inc/filtres'); |
|
| 143 | - $c = encoder_contexte_ajax($post, $form); |
|
| 144 | - if (!isset($valeurs['_hidden'])) { |
|
| 145 | - $valeurs['_hidden'] = ''; |
|
| 146 | - } |
|
| 147 | - $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | - // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | - $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | - } |
|
| 131 | + if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | + $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 133 | + foreach (array_keys($valeurs) as $champ) { |
|
| 134 | + if ( |
|
| 135 | + !str_starts_with($champ, '_') |
|
| 136 | + && ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) |
|
| 137 | + && ($v = _request($champ)) !== null |
|
| 138 | + ) { |
|
| 139 | + $post[$champ] = $v; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + include_spip('inc/filtres'); |
|
| 143 | + $c = encoder_contexte_ajax($post, $form); |
|
| 144 | + if (!isset($valeurs['_hidden'])) { |
|
| 145 | + $valeurs['_hidden'] = ''; |
|
| 146 | + } |
|
| 147 | + $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | + // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | + $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $valeurs; |
|
| 152 | + return $valeurs; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | * @return array |
| 164 | 164 | */ |
| 165 | 165 | function cvtmulti_formulaire_charger($flux) { |
| 166 | - if (is_array($flux['data']) && isset($flux['data']['_etapes'])) { |
|
| 167 | - $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 168 | - } |
|
| 166 | + if (is_array($flux['data']) && isset($flux['data']['_etapes'])) { |
|
| 167 | + $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - return $flux; |
|
| 170 | + return $flux; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -177,19 +177,19 @@ discard block |
||
| 177 | 177 | * @return array |
| 178 | 178 | */ |
| 179 | 179 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 180 | - if (!isset($valeurs['_etape'])) { |
|
| 181 | - $form = $args['form']; |
|
| 182 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 183 | - $nb_etapes = $valeurs['_etapes']; |
|
| 184 | - $etape = _request('_etape'); |
|
| 185 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 186 | - set_request('_etape', $etape); |
|
| 187 | - $valeurs['_etape'] = $etape; |
|
| 180 | + if (!isset($valeurs['_etape'])) { |
|
| 181 | + $form = $args['form']; |
|
| 182 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 183 | + $nb_etapes = $valeurs['_etapes']; |
|
| 184 | + $etape = _request('_etape'); |
|
| 185 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 186 | + set_request('_etape', $etape); |
|
| 187 | + $valeurs['_etape'] = $etape; |
|
| 188 | 188 | |
| 189 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 190 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 191 | - } |
|
| 192 | - return $valeurs; |
|
| 189 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 190 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 191 | + } |
|
| 192 | + return $valeurs; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | 204 | function cvtmulti_formulaire_verifier($flux) { |
| 205 | - $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 206 | - return $flux; |
|
| 205 | + $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 206 | + return $flux; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -214,87 +214,87 @@ discard block |
||
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | 216 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 217 | - #var_dump('Pipe verifier'); |
|
| 217 | + #var_dump('Pipe verifier'); |
|
| 218 | 218 | |
| 219 | - if ( |
|
| 220 | - ($form = $args['form']) |
|
| 221 | - && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 222 | - ) { |
|
| 223 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 224 | - [$etape, $etapes] = $e; |
|
| 225 | - $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 219 | + if ( |
|
| 220 | + ($form = $args['form']) |
|
| 221 | + && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 222 | + ) { |
|
| 223 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 224 | + [$etape, $etapes] = $e; |
|
| 225 | + $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 226 | 226 | |
| 227 | - $args['etape_saisie'] = $etape; |
|
| 228 | - $args['etapes'] = $etapes; |
|
| 229 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 230 | - $erreurs_etapes = []; |
|
| 231 | - $derniere_etape_ok = 0; |
|
| 232 | - $e = 0; |
|
| 233 | - while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 234 | - $e++; |
|
| 235 | - $erreurs_etapes[$e] = []; |
|
| 236 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 237 | - $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 238 | - } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 239 | - $a = $args['args']; |
|
| 240 | - array_unshift($a, $e); |
|
| 241 | - $erreurs_etapes[$e] = $verifier(...$a); |
|
| 242 | - } |
|
| 243 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 244 | - $args['etape'] = $e; |
|
| 245 | - $args['etape_demandee'] = $etape_demandee; |
|
| 246 | - $erreurs_etapes[$e] = pipeline( |
|
| 247 | - 'formulaire_verifier_etape', |
|
| 248 | - [ |
|
| 249 | - 'args' => $args, |
|
| 250 | - 'data' => $erreurs_etapes[$e] |
|
| 251 | - ] |
|
| 252 | - ); |
|
| 227 | + $args['etape_saisie'] = $etape; |
|
| 228 | + $args['etapes'] = $etapes; |
|
| 229 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 230 | + $erreurs_etapes = []; |
|
| 231 | + $derniere_etape_ok = 0; |
|
| 232 | + $e = 0; |
|
| 233 | + while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 234 | + $e++; |
|
| 235 | + $erreurs_etapes[$e] = []; |
|
| 236 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 237 | + $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 238 | + } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 239 | + $a = $args['args']; |
|
| 240 | + array_unshift($a, $e); |
|
| 241 | + $erreurs_etapes[$e] = $verifier(...$a); |
|
| 242 | + } |
|
| 243 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 244 | + $args['etape'] = $e; |
|
| 245 | + $args['etape_demandee'] = $etape_demandee; |
|
| 246 | + $erreurs_etapes[$e] = pipeline( |
|
| 247 | + 'formulaire_verifier_etape', |
|
| 248 | + [ |
|
| 249 | + 'args' => $args, |
|
| 250 | + 'data' => $erreurs_etapes[$e] |
|
| 251 | + ] |
|
| 252 | + ); |
|
| 253 | 253 | |
| 254 | - if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 255 | - $derniere_etape_ok = $e; |
|
| 256 | - } |
|
| 257 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 258 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 259 | - $etape_demandee = $e; |
|
| 260 | - } |
|
| 261 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 262 | - if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 263 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 264 | - } |
|
| 265 | - } |
|
| 254 | + if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 255 | + $derniere_etape_ok = $e; |
|
| 256 | + } |
|
| 257 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 258 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 259 | + $etape_demandee = $e; |
|
| 260 | + } |
|
| 261 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 262 | + if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 263 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - // si la derniere etape OK etait la derniere |
|
| 269 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 270 | - if ( |
|
| 271 | - $derniere_etape_ok == $etapes |
|
| 272 | - && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 273 | - ) { |
|
| 274 | - return $erreurs; |
|
| 275 | - } else { |
|
| 276 | - $etape = $derniere_etape_ok + 1; |
|
| 277 | - if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 278 | - $etape = $etape_demandee; |
|
| 279 | - } |
|
| 280 | - $etape = min($etape, $etapes); |
|
| 281 | - #var_dump("prochaine etape $etape"); |
|
| 282 | - // retourner les erreurs de l'etape ciblee |
|
| 283 | - $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 284 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 285 | - if ($erreurs) { |
|
| 286 | - if (!isset($erreurs['message_erreur'])) { |
|
| 287 | - $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 288 | - } |
|
| 289 | - } else { |
|
| 290 | - $erreurs['message_erreur'] = ''; |
|
| 291 | - } |
|
| 292 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 293 | - set_request('_etape', $etape); |
|
| 294 | - } |
|
| 295 | - } |
|
| 268 | + // si la derniere etape OK etait la derniere |
|
| 269 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 270 | + if ( |
|
| 271 | + $derniere_etape_ok == $etapes |
|
| 272 | + && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 273 | + ) { |
|
| 274 | + return $erreurs; |
|
| 275 | + } else { |
|
| 276 | + $etape = $derniere_etape_ok + 1; |
|
| 277 | + if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 278 | + $etape = $etape_demandee; |
|
| 279 | + } |
|
| 280 | + $etape = min($etape, $etapes); |
|
| 281 | + #var_dump("prochaine etape $etape"); |
|
| 282 | + // retourner les erreurs de l'etape ciblee |
|
| 283 | + $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 284 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 285 | + if ($erreurs) { |
|
| 286 | + if (!isset($erreurs['message_erreur'])) { |
|
| 287 | + $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 288 | + } |
|
| 289 | + } else { |
|
| 290 | + $erreurs['message_erreur'] = ''; |
|
| 291 | + } |
|
| 292 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 293 | + set_request('_etape', $etape); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - return $erreurs; |
|
| 297 | + return $erreurs; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -306,17 +306,17 @@ discard block |
||
| 306 | 306 | * @return array |
| 307 | 307 | */ |
| 308 | 308 | function cvtmulti_styliser($flux) { |
| 309 | - if ( |
|
| 310 | - str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 311 | - && isset($flux['args']['contexte']['_etapes']) |
|
| 312 | - && isset($flux['args']['contexte']['_etape']) |
|
| 313 | - && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 314 | - && ($ext = $flux['args']['ext']) |
|
| 315 | - && ($f = $flux['data']) |
|
| 316 | - && file_exists($f . "_$e.$ext") |
|
| 317 | - ) { |
|
| 318 | - $flux['data'] = $f . "_$e"; |
|
| 319 | - } |
|
| 309 | + if ( |
|
| 310 | + str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 311 | + && isset($flux['args']['contexte']['_etapes']) |
|
| 312 | + && isset($flux['args']['contexte']['_etape']) |
|
| 313 | + && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 314 | + && ($ext = $flux['args']['ext']) |
|
| 315 | + && ($f = $flux['data']) |
|
| 316 | + && file_exists($f . "_$e.$ext") |
|
| 317 | + ) { |
|
| 318 | + $flux['data'] = $f . "_$e"; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - return $flux; |
|
| 321 | + return $flux; |
|
| 322 | 322 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Autorisations |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('base/abstract_sql'); |
@@ -37,89 +37,89 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | if (!function_exists('autoriser')) { |
| 40 | - /** |
|
| 41 | - * Autoriser une action |
|
| 42 | - * |
|
| 43 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | - * les autorisations. |
|
| 46 | - * |
|
| 47 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | - * dans cet ordre : |
|
| 50 | - * |
|
| 51 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | - * - autoriser_{type}, sinon avec _dist |
|
| 53 | - * - autoriser_{faire}, sinon avec _dist |
|
| 54 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | - * |
|
| 56 | - * Seul le premier argument est obligatoire. |
|
| 57 | - * |
|
| 58 | - * @note |
|
| 59 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | - * cette valeur. |
|
| 62 | - * |
|
| 63 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | - * |
|
| 68 | - * @note |
|
| 69 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | - * quel serait le type, quel serait l'action ? |
|
| 74 | - * |
|
| 75 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | - * |
|
| 79 | - * @api |
|
| 80 | - * @see autoriser_dist() |
|
| 81 | - * @see objet_type() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param string|null $type |
|
| 86 | - * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | - * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | - * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | - * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | - * Les soulignés seront retirés (cf. la note). |
|
| 91 | - * @param string|int|null $id |
|
| 92 | - * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | - * - null: non utile pour l’autorisation |
|
| 94 | - * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | - * - string: identifiant textuel |
|
| 96 | - * @param null|int|array $qui |
|
| 97 | - * - si null on prend alors visiteur_session |
|
| 98 | - * - un id_auteur (on regarde dans la base) |
|
| 99 | - * - un tableau auteur complet, y compris [restreint] |
|
| 100 | - * @param array $opt |
|
| 101 | - * options sous forme de tableau associatif |
|
| 102 | - * @return bool |
|
| 103 | - * true si la personne peut effectuer l'action |
|
| 104 | - */ |
|
| 105 | - function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | - // Charger les fonctions d'autorisation supplementaires |
|
| 107 | - static $pipe; |
|
| 108 | - if (!isset($pipe)) { |
|
| 109 | - $pipe = 1; |
|
| 110 | - pipeline('autoriser'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | - } |
|
| 40 | + /** |
|
| 41 | + * Autoriser une action |
|
| 42 | + * |
|
| 43 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | + * les autorisations. |
|
| 46 | + * |
|
| 47 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | + * dans cet ordre : |
|
| 50 | + * |
|
| 51 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | + * - autoriser_{type}, sinon avec _dist |
|
| 53 | + * - autoriser_{faire}, sinon avec _dist |
|
| 54 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | + * |
|
| 56 | + * Seul le premier argument est obligatoire. |
|
| 57 | + * |
|
| 58 | + * @note |
|
| 59 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | + * cette valeur. |
|
| 62 | + * |
|
| 63 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | + * |
|
| 68 | + * @note |
|
| 69 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | + * quel serait le type, quel serait l'action ? |
|
| 74 | + * |
|
| 75 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | + * |
|
| 79 | + * @api |
|
| 80 | + * @see autoriser_dist() |
|
| 81 | + * @see objet_type() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param string|null $type |
|
| 86 | + * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | + * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | + * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | + * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | + * Les soulignés seront retirés (cf. la note). |
|
| 91 | + * @param string|int|null $id |
|
| 92 | + * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | + * - null: non utile pour l’autorisation |
|
| 94 | + * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | + * - string: identifiant textuel |
|
| 96 | + * @param null|int|array $qui |
|
| 97 | + * - si null on prend alors visiteur_session |
|
| 98 | + * - un id_auteur (on regarde dans la base) |
|
| 99 | + * - un tableau auteur complet, y compris [restreint] |
|
| 100 | + * @param array $opt |
|
| 101 | + * options sous forme de tableau associatif |
|
| 102 | + * @return bool |
|
| 103 | + * true si la personne peut effectuer l'action |
|
| 104 | + */ |
|
| 105 | + function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | + // Charger les fonctions d'autorisation supplementaires |
|
| 107 | + static $pipe; |
|
| 108 | + if (!isset($pipe)) { |
|
| 109 | + $pipe = 1; |
|
| 110 | + pipeline('autoriser'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | - global $dossier_squelettes; |
|
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 121 | + global $dossier_squelettes; |
|
| 122 | + include_once(_ROOT_CWD . $f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -150,85 +150,85 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
| 152 | 152 | |
| 153 | - if ($type === null) { |
|
| 154 | - $type = ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Qui ? visiteur_session ? |
|
| 158 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | - if ($qui === null || $qui === '') { |
|
| 160 | - $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | - } elseif (is_numeric($qui)) { |
|
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | - if (!$qui) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | - if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - spip_log( |
|
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - // passer par objet_type pour avoir les alias |
|
| 181 | - // sauf si _ est le premier caractère. |
|
| 182 | - if ($type && $type[0] !== '_') { |
|
| 183 | - $type = objet_type($type, false); |
|
| 184 | - } |
|
| 185 | - // et supprimer les _ |
|
| 186 | - $type = str_replace('_', '', (string) $type); |
|
| 187 | - |
|
| 188 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 189 | - if ( |
|
| 190 | - isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 191 | - && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 192 | - ) { |
|
| 193 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 194 | - return true; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Chercher une fonction d'autorisation |
|
| 198 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 199 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 200 | - $fonctions = $type |
|
| 201 | - ? [ |
|
| 202 | - 'autoriser_' . $type . '_' . $faire, |
|
| 203 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 204 | - 'autoriser_' . $type, |
|
| 205 | - 'autoriser_' . $type . '_dist', |
|
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 208 | - 'autoriser_defaut', |
|
| 209 | - 'autoriser_defaut_dist' |
|
| 210 | - ] |
|
| 211 | - : [ |
|
| 212 | - 'autoriser_' . $faire, |
|
| 213 | - 'autoriser_' . $faire . '_dist', |
|
| 214 | - 'autoriser_defaut', |
|
| 215 | - 'autoriser_defaut_dist' |
|
| 216 | - ]; |
|
| 217 | - |
|
| 218 | - $a = false; |
|
| 219 | - foreach ($fonctions as $f) { |
|
| 220 | - if (function_exists($f)) { |
|
| 221 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - spip_log( |
|
| 227 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 228 | - 'autoriser' . _LOG_DEBUG |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - return $a; |
|
| 153 | + if ($type === null) { |
|
| 154 | + $type = ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Qui ? visiteur_session ? |
|
| 158 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | + if ($qui === null || $qui === '') { |
|
| 160 | + $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | + } elseif (is_numeric($qui)) { |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | + if (!$qui) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | + if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + spip_log( |
|
| 176 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | + 'autoriser' . _LOG_DEBUG |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + // passer par objet_type pour avoir les alias |
|
| 181 | + // sauf si _ est le premier caractère. |
|
| 182 | + if ($type && $type[0] !== '_') { |
|
| 183 | + $type = objet_type($type, false); |
|
| 184 | + } |
|
| 185 | + // et supprimer les _ |
|
| 186 | + $type = str_replace('_', '', (string) $type); |
|
| 187 | + |
|
| 188 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 189 | + if ( |
|
| 190 | + isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 191 | + && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 192 | + ) { |
|
| 193 | + spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 194 | + return true; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Chercher une fonction d'autorisation |
|
| 198 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 199 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 200 | + $fonctions = $type |
|
| 201 | + ? [ |
|
| 202 | + 'autoriser_' . $type . '_' . $faire, |
|
| 203 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 204 | + 'autoriser_' . $type, |
|
| 205 | + 'autoriser_' . $type . '_dist', |
|
| 206 | + 'autoriser_' . $faire, |
|
| 207 | + 'autoriser_' . $faire . '_dist', |
|
| 208 | + 'autoriser_defaut', |
|
| 209 | + 'autoriser_defaut_dist' |
|
| 210 | + ] |
|
| 211 | + : [ |
|
| 212 | + 'autoriser_' . $faire, |
|
| 213 | + 'autoriser_' . $faire . '_dist', |
|
| 214 | + 'autoriser_defaut', |
|
| 215 | + 'autoriser_defaut_dist' |
|
| 216 | + ]; |
|
| 217 | + |
|
| 218 | + $a = false; |
|
| 219 | + foreach ($fonctions as $f) { |
|
| 220 | + if (function_exists($f)) { |
|
| 221 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + spip_log( |
|
| 227 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 228 | + 'autoriser' . _LOG_DEBUG |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + return $a; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -248,33 +248,33 @@ discard block |
||
| 248 | 248 | * @return bool |
| 249 | 249 | */ |
| 250 | 250 | function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool { |
| 251 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 252 | - static $autorisation; |
|
| 253 | - // Tolérance avec certains appels |
|
| 254 | - if ($type === null) { |
|
| 255 | - $type = ''; |
|
| 256 | - } |
|
| 257 | - if ($id === null) { |
|
| 258 | - $id = 0; |
|
| 259 | - } |
|
| 260 | - if ($autoriser === 'verifier') { |
|
| 261 | - return isset($autorisation[$faire][$type][$id]); |
|
| 262 | - } |
|
| 263 | - if ($autoriser === true) { |
|
| 264 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 265 | - } |
|
| 266 | - if ($autoriser === false) { |
|
| 267 | - if ($id === '*') { |
|
| 268 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 269 | - unset($autorisation[$faire][$type]); |
|
| 270 | - } |
|
| 271 | - else { |
|
| 272 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 273 | - unset($autorisation[$faire][$type][$id]); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return false; |
|
| 251 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 252 | + static $autorisation; |
|
| 253 | + // Tolérance avec certains appels |
|
| 254 | + if ($type === null) { |
|
| 255 | + $type = ''; |
|
| 256 | + } |
|
| 257 | + if ($id === null) { |
|
| 258 | + $id = 0; |
|
| 259 | + } |
|
| 260 | + if ($autoriser === 'verifier') { |
|
| 261 | + return isset($autorisation[$faire][$type][$id]); |
|
| 262 | + } |
|
| 263 | + if ($autoriser === true) { |
|
| 264 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 265 | + } |
|
| 266 | + if ($autoriser === false) { |
|
| 267 | + if ($id === '*') { |
|
| 268 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 269 | + unset($autorisation[$faire][$type]); |
|
| 270 | + } |
|
| 271 | + else { |
|
| 272 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 273 | + unset($autorisation[$faire][$type][$id]); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return false; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * @return bool true s'il a le droit, false sinon |
| 294 | 294 | **/ |
| 295 | 295 | function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 296 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 296 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * @return bool true s'il a le droit, false sinon |
| 314 | 314 | */ |
| 315 | 315 | function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 316 | - return $qui['statut'] !== '5poubelle'; |
|
| 316 | + return $qui['statut'] !== '5poubelle'; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return bool true s'il a le droit, false sinon |
| 330 | 330 | **/ |
| 331 | 331 | function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 332 | - return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 332 | + return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @return bool true s'il a le droit, false sinon |
| 349 | 349 | **/ |
| 350 | 350 | function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 351 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 351 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -368,14 +368,14 @@ discard block |
||
| 368 | 368 | **/ |
| 369 | 369 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 370 | 370 | |
| 371 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 372 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 373 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 374 | - } |
|
| 371 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 372 | + if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 373 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - // A-t-on un token de prévisualisation valable ? |
|
| 377 | - include_spip('inc/securiser_action'); |
|
| 378 | - return (bool) decrire_token_previsu(); |
|
| 376 | + // A-t-on un token de prévisualisation valable ? |
|
| 377 | + include_spip('inc/securiser_action'); |
|
| 378 | + return (bool) decrire_token_previsu(); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -404,58 +404,58 @@ discard block |
||
| 404 | 404 | */ |
| 405 | 405 | function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool { |
| 406 | 406 | |
| 407 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 408 | - if (!$type) { |
|
| 409 | - return true; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - include_spip('base/objets'); |
|
| 413 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 414 | - if (isset($infos['statut'])) { |
|
| 415 | - foreach ($infos['statut'] as $c) { |
|
| 416 | - if (isset($c['publie'])) { |
|
| 417 | - if (!isset($c['previsu'])) { |
|
| 418 | - return false; |
|
| 419 | - } // pas de previsu definie => NIET |
|
| 420 | - $champ = $c['champ']; |
|
| 421 | - if (!isset($opt[$champ])) { |
|
| 422 | - return false; |
|
| 423 | - } // pas de champ passe a la demande => NIET |
|
| 424 | - $previsu = explode(',', (string) $c['previsu']); |
|
| 425 | - // regarder si ce statut est autorise pour l'auteur |
|
| 426 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 427 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 428 | - // sinon l’auteur en session |
|
| 429 | - include_spip('inc/securiser_action'); |
|
| 430 | - if ($desc = decrire_token_previsu()) { |
|
| 431 | - $id_auteur = $desc['id_auteur']; |
|
| 432 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 433 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 434 | - } else { |
|
| 435 | - $id_auteur = null; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if (!$id_auteur) { |
|
| 439 | - return false; |
|
| 440 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 441 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 442 | - } elseif ( |
|
| 443 | - !sql_countsel( |
|
| 444 | - 'spip_auteurs_liens', |
|
| 445 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 446 | - ) |
|
| 447 | - ) { |
|
| 448 | - return false; |
|
| 449 | - } // pas auteur de cet objet => NIET |
|
| 450 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 451 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 452 | - return false; |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return true; |
|
| 407 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 408 | + if (!$type) { |
|
| 409 | + return true; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + include_spip('base/objets'); |
|
| 413 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 414 | + if (isset($infos['statut'])) { |
|
| 415 | + foreach ($infos['statut'] as $c) { |
|
| 416 | + if (isset($c['publie'])) { |
|
| 417 | + if (!isset($c['previsu'])) { |
|
| 418 | + return false; |
|
| 419 | + } // pas de previsu definie => NIET |
|
| 420 | + $champ = $c['champ']; |
|
| 421 | + if (!isset($opt[$champ])) { |
|
| 422 | + return false; |
|
| 423 | + } // pas de champ passe a la demande => NIET |
|
| 424 | + $previsu = explode(',', (string) $c['previsu']); |
|
| 425 | + // regarder si ce statut est autorise pour l'auteur |
|
| 426 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 427 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 428 | + // sinon l’auteur en session |
|
| 429 | + include_spip('inc/securiser_action'); |
|
| 430 | + if ($desc = decrire_token_previsu()) { |
|
| 431 | + $id_auteur = $desc['id_auteur']; |
|
| 432 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 433 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 434 | + } else { |
|
| 435 | + $id_auteur = null; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if (!$id_auteur) { |
|
| 439 | + return false; |
|
| 440 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 441 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 442 | + } elseif ( |
|
| 443 | + !sql_countsel( |
|
| 444 | + 'spip_auteurs_liens', |
|
| 445 | + 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 446 | + ) |
|
| 447 | + ) { |
|
| 448 | + return false; |
|
| 449 | + } // pas auteur de cet objet => NIET |
|
| 450 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 451 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 452 | + return false; |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return true; |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -471,49 +471,49 @@ discard block |
||
| 471 | 471 | * @return bool true s'il a le droit, false sinon |
| 472 | 472 | **/ |
| 473 | 473 | function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 474 | - $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 475 | - $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 476 | - $table = table_objet_sql($type); |
|
| 477 | - if ( |
|
| 478 | - in_array($table, $multi_objets) |
|
| 479 | - || in_array($table, $gerer_trad_objets) |
|
| 480 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 481 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 482 | - $champs = objet_info($type, 'field'); |
|
| 483 | - if ( |
|
| 484 | - $multi_secteurs === 'oui' |
|
| 485 | - && array_key_exists('id_rubrique', $champs) |
|
| 486 | - ) { |
|
| 487 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 488 | - $primary = id_table_objet($type); |
|
| 489 | - $id_rubrique = $table != 'spip_rubriques' |
|
| 490 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 491 | - : $id; |
|
| 492 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 493 | - if (!$id_secteur > 0) { |
|
| 494 | - $id_secteur = $id_rubrique; |
|
| 495 | - } |
|
| 496 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 497 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 498 | - if ($langue_secteur != $langue_objet) { |
|
| 499 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 500 | - return true; |
|
| 501 | - } |
|
| 502 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 503 | - return false; |
|
| 504 | - } else { |
|
| 505 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 506 | - if ($id_parent != 0) { |
|
| 507 | - // sous-rubriques : pas de choix de langue |
|
| 508 | - return false; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - } else { |
|
| 513 | - return false; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 474 | + $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 475 | + $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 476 | + $table = table_objet_sql($type); |
|
| 477 | + if ( |
|
| 478 | + in_array($table, $multi_objets) |
|
| 479 | + || in_array($table, $gerer_trad_objets) |
|
| 480 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 481 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 482 | + $champs = objet_info($type, 'field'); |
|
| 483 | + if ( |
|
| 484 | + $multi_secteurs === 'oui' |
|
| 485 | + && array_key_exists('id_rubrique', $champs) |
|
| 486 | + ) { |
|
| 487 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 488 | + $primary = id_table_objet($type); |
|
| 489 | + $id_rubrique = $table != 'spip_rubriques' |
|
| 490 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 491 | + : $id; |
|
| 492 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 493 | + if (!$id_secteur > 0) { |
|
| 494 | + $id_secteur = $id_rubrique; |
|
| 495 | + } |
|
| 496 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 497 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 498 | + if ($langue_secteur != $langue_objet) { |
|
| 499 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 500 | + return true; |
|
| 501 | + } |
|
| 502 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 503 | + return false; |
|
| 504 | + } else { |
|
| 505 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 506 | + if ($id_parent != 0) { |
|
| 507 | + // sous-rubriques : pas de choix de langue |
|
| 508 | + return false; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + } else { |
|
| 513 | + return false; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * @return bool true s'il a le droit, false sinon |
| 530 | 530 | **/ |
| 531 | 531 | function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 532 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 532 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -545,38 +545,38 @@ discard block |
||
| 545 | 545 | * @return bool true s'il a le droit, false sinon |
| 546 | 546 | **/ |
| 547 | 547 | function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 548 | - $table = table_objet($type); |
|
| 549 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 550 | - $desc = $trouver_table($table); |
|
| 551 | - if (!$desc) { |
|
| 552 | - return false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - if (!isset($opt['statut'])) { |
|
| 556 | - if (isset($desc['field']['statut'])) { |
|
| 557 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 558 | - } else { |
|
| 559 | - $statut = 'publie'; |
|
| 560 | - } // pas de statut => publie |
|
| 561 | - } else { |
|
| 562 | - $statut = $opt['statut']; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // Liste des statuts publiés pour cet objet |
|
| 566 | - // Sinon en dur le statut "publie" |
|
| 567 | - $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 568 | - ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 569 | - : ['publie']; |
|
| 570 | - |
|
| 571 | - if ( |
|
| 572 | - in_array($statut, $statuts_publies) |
|
| 573 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 574 | - || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 575 | - ) { |
|
| 576 | - return autoriser('modifier', $type, $id); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return false; |
|
| 548 | + $table = table_objet($type); |
|
| 549 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 550 | + $desc = $trouver_table($table); |
|
| 551 | + if (!$desc) { |
|
| 552 | + return false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + if (!isset($opt['statut'])) { |
|
| 556 | + if (isset($desc['field']['statut'])) { |
|
| 557 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 558 | + } else { |
|
| 559 | + $statut = 'publie'; |
|
| 560 | + } // pas de statut => publie |
|
| 561 | + } else { |
|
| 562 | + $statut = $opt['statut']; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // Liste des statuts publiés pour cet objet |
|
| 566 | + // Sinon en dur le statut "publie" |
|
| 567 | + $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 568 | + ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 569 | + : ['publie']; |
|
| 570 | + |
|
| 571 | + if ( |
|
| 572 | + in_array($statut, $statuts_publies) |
|
| 573 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 574 | + || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 575 | + ) { |
|
| 576 | + return autoriser('modifier', $type, $id); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return false; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @return bool true s'il a le droit, false sinon |
| 596 | 596 | **/ |
| 597 | 597 | function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 598 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 598 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -613,9 +613,9 @@ discard block |
||
| 613 | 613 | * @return bool true s'il a le droit, false sinon |
| 614 | 614 | **/ |
| 615 | 615 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 616 | - return |
|
| 617 | - $qui['statut'] === '0minirezo' |
|
| 618 | - && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 616 | + return |
|
| 617 | + $qui['statut'] === '0minirezo' |
|
| 618 | + && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -633,12 +633,12 @@ discard block |
||
| 633 | 633 | * @return bool true s'il a le droit, false sinon |
| 634 | 634 | **/ |
| 635 | 635 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 636 | - if (!empty($opt['id_parent'])) { |
|
| 637 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 638 | - } |
|
| 639 | - else { |
|
| 640 | - return autoriser('defaut', null, 0, $qui, $opt); |
|
| 641 | - } |
|
| 636 | + if (!empty($opt['id_parent'])) { |
|
| 637 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 638 | + } |
|
| 639 | + else { |
|
| 640 | + return autoriser('defaut', null, 0, $qui, $opt); |
|
| 641 | + } |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | * @return bool true s'il a le droit, false sinon |
| 657 | 657 | **/ |
| 658 | 658 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 659 | - return |
|
| 660 | - ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 659 | + return |
|
| 660 | + ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -675,10 +675,10 @@ discard block |
||
| 675 | 675 | * @return bool true s'il a le droit, false sinon |
| 676 | 676 | **/ |
| 677 | 677 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 678 | - return |
|
| 679 | - $id |
|
| 680 | - && autoriser('voir', 'rubrique', $id) |
|
| 681 | - && autoriser('creer', 'article'); |
|
| 678 | + return |
|
| 679 | + $id |
|
| 680 | + && autoriser('voir', 'rubrique', $id) |
|
| 681 | + && autoriser('creer', 'article'); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | * @return bool true s'il a le droit, false sinon |
| 698 | 698 | **/ |
| 699 | 699 | function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 700 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 700 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -715,29 +715,29 @@ discard block |
||
| 715 | 715 | * @return bool true s'il a le droit, false sinon |
| 716 | 716 | **/ |
| 717 | 717 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 718 | - if (!$id = (int) $id) { |
|
| 719 | - return false; |
|
| 720 | - } |
|
| 718 | + if (!$id = (int) $id) { |
|
| 719 | + return false; |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 723 | - return false; |
|
| 724 | - } |
|
| 722 | + if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 723 | + return false; |
|
| 724 | + } |
|
| 725 | 725 | |
| 726 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 727 | - return false; |
|
| 728 | - } |
|
| 726 | + if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 727 | + return false; |
|
| 728 | + } |
|
| 729 | 729 | |
| 730 | - $compte = pipeline( |
|
| 731 | - 'objet_compte_enfants', |
|
| 732 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 733 | - ); |
|
| 734 | - foreach ($compte as $objet => $n) { |
|
| 735 | - if ($n) { |
|
| 736 | - return false; |
|
| 737 | - } |
|
| 738 | - } |
|
| 730 | + $compte = pipeline( |
|
| 731 | + 'objet_compte_enfants', |
|
| 732 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 733 | + ); |
|
| 734 | + foreach ($compte as $objet => $n) { |
|
| 735 | + if ($n) { |
|
| 736 | + return false; |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | - return autoriser('modifier', 'rubrique', $id); |
|
| 740 | + return autoriser('modifier', 'rubrique', $id); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
@@ -757,20 +757,20 @@ discard block |
||
| 757 | 757 | * @return bool true s'il a le droit, false sinon |
| 758 | 758 | **/ |
| 759 | 759 | function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 760 | - if (!$id) { |
|
| 761 | - return false; |
|
| 762 | - } |
|
| 763 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 760 | + if (!$id) { |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 764 | 764 | |
| 765 | - return $r && ( |
|
| 766 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 767 | - || ( |
|
| 768 | - (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 769 | - && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 770 | - && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 771 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 772 | - ) |
|
| 773 | - ); |
|
| 765 | + return $r && ( |
|
| 766 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 767 | + || ( |
|
| 768 | + (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 769 | + && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 770 | + && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 771 | + && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 772 | + ) |
|
| 773 | + ); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
@@ -788,13 +788,13 @@ discard block |
||
| 788 | 788 | * @return bool true s'il a le droit, false sinon |
| 789 | 789 | **/ |
| 790 | 790 | function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 791 | - if (!empty($opt['id_parent'])) { |
|
| 792 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 793 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 794 | - } |
|
| 795 | - else { |
|
| 796 | - return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 797 | - } |
|
| 791 | + if (!empty($opt['id_parent'])) { |
|
| 792 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 793 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 794 | + } |
|
| 795 | + else { |
|
| 796 | + return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 797 | + } |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | /** |
@@ -816,26 +816,26 @@ discard block |
||
| 816 | 816 | * @return bool true s'il a le droit, false sinon |
| 817 | 817 | */ |
| 818 | 818 | function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 819 | - if ($qui['statut'] === '0minirezo') { |
|
| 820 | - return true; |
|
| 821 | - } |
|
| 822 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 823 | - if (isset($opt['statut'])) { |
|
| 824 | - $statut = $opt['statut']; |
|
| 825 | - } else { |
|
| 826 | - if (!$id) { |
|
| 827 | - return false; |
|
| 828 | - } |
|
| 829 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 830 | - } |
|
| 819 | + if ($qui['statut'] === '0minirezo') { |
|
| 820 | + return true; |
|
| 821 | + } |
|
| 822 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 823 | + if (isset($opt['statut'])) { |
|
| 824 | + $statut = $opt['statut']; |
|
| 825 | + } else { |
|
| 826 | + if (!$id) { |
|
| 827 | + return false; |
|
| 828 | + } |
|
| 829 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 830 | + } |
|
| 831 | 831 | |
| 832 | - return |
|
| 833 | - // si on est pas auteur de l'article, |
|
| 834 | - // seuls les propose et publies sont visibles |
|
| 835 | - in_array($statut, ['prop', 'publie']) |
|
| 836 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 832 | + return |
|
| 833 | + // si on est pas auteur de l'article, |
|
| 834 | + // seuls les propose et publies sont visibles |
|
| 835 | + in_array($statut, ['prop', 'publie']) |
|
| 836 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 837 | 837 | |
| 838 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 838 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | |
@@ -854,24 +854,24 @@ discard block |
||
| 854 | 854 | * @return bool true s'il a le droit, false sinon |
| 855 | 855 | **/ |
| 856 | 856 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 857 | - # securite, mais on aurait pas du arriver ici ! |
|
| 858 | - if ( |
|
| 859 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 860 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 861 | - ) { |
|
| 862 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 863 | - } |
|
| 857 | + # securite, mais on aurait pas du arriver ici ! |
|
| 858 | + if ( |
|
| 859 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 860 | + || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 861 | + ) { |
|
| 862 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - if ($qui['statut'] === '0minirezo') { |
|
| 866 | - return true; |
|
| 867 | - } |
|
| 868 | - // admins et redacteurs peuvent voir un auteur |
|
| 869 | - if ($type === 'auteur') { |
|
| 870 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 871 | - } |
|
| 872 | - // sinon par defaut tout est visible |
|
| 873 | - // sauf cas particuliers traites separemment (ie article) |
|
| 874 | - return true; |
|
| 865 | + if ($qui['statut'] === '0minirezo') { |
|
| 866 | + return true; |
|
| 867 | + } |
|
| 868 | + // admins et redacteurs peuvent voir un auteur |
|
| 869 | + if ($type === 'auteur') { |
|
| 870 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 871 | + } |
|
| 872 | + // sinon par defaut tout est visible |
|
| 873 | + // sauf cas particuliers traites separemment (ie article) |
|
| 874 | + return true; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | |
@@ -894,12 +894,12 @@ discard block |
||
| 894 | 894 | * @return bool true s'il a le droit, false sinon |
| 895 | 895 | **/ |
| 896 | 896 | function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 897 | - return |
|
| 898 | - (defined('_ID_WEBMESTRES') |
|
| 899 | - ? in_array($qui['id_auteur'], explode(':', (string) _ID_WEBMESTRES)) |
|
| 900 | - : $qui['webmestre'] === 'oui') |
|
| 901 | - && $qui['statut'] === '0minirezo' |
|
| 902 | - && !$qui['restreint']; |
|
| 897 | + return |
|
| 898 | + (defined('_ID_WEBMESTRES') |
|
| 899 | + ? in_array($qui['id_auteur'], explode(':', (string) _ID_WEBMESTRES)) |
|
| 900 | + : $qui['webmestre'] === 'oui') |
|
| 901 | + && $qui['statut'] === '0minirezo' |
|
| 902 | + && !$qui['restreint']; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | * @return bool true s'il a le droit, false sinon |
| 918 | 918 | **/ |
| 919 | 919 | function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 920 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 920 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | * @return bool true s'il a le droit, false sinon |
| 936 | 936 | **/ |
| 937 | 937 | function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 938 | - return $qui['statut'] === '0minirezo'; |
|
| 938 | + return $qui['statut'] === '0minirezo'; |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | * @return bool true s'il a le droit, false sinon |
| 954 | 954 | **/ |
| 955 | 955 | function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 956 | - return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 956 | + return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | /** |
@@ -972,23 +972,23 @@ discard block |
||
| 972 | 972 | * @return bool true s'il a le droit, false sinon |
| 973 | 973 | **/ |
| 974 | 974 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 975 | - // les admins peuvent "previsualiser" une page auteur |
|
| 976 | - if ( |
|
| 977 | - $qui['statut'] === '0minirezo' |
|
| 978 | - && !$qui['restreint'] |
|
| 979 | - ) { |
|
| 980 | - return true; |
|
| 981 | - } elseif ($id === 0) { |
|
| 982 | - return false; |
|
| 983 | - } |
|
| 984 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 985 | - $n = sql_fetsel( |
|
| 986 | - 'A.id_article', |
|
| 987 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 988 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 989 | - ); |
|
| 975 | + // les admins peuvent "previsualiser" une page auteur |
|
| 976 | + if ( |
|
| 977 | + $qui['statut'] === '0minirezo' |
|
| 978 | + && !$qui['restreint'] |
|
| 979 | + ) { |
|
| 980 | + return true; |
|
| 981 | + } elseif ($id === 0) { |
|
| 982 | + return false; |
|
| 983 | + } |
|
| 984 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 985 | + $n = sql_fetsel( |
|
| 986 | + 'A.id_article', |
|
| 987 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 988 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 989 | + ); |
|
| 990 | 990 | |
| 991 | - return (bool) $n; |
|
| 991 | + return (bool) $n; |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | * @return bool true s'il a le droit, false sinon |
| 1018 | 1018 | **/ |
| 1019 | 1019 | function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1020 | - return ($qui['statut'] === '0minirezo'); |
|
| 1020 | + return ($qui['statut'] === '0minirezo'); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | |
@@ -1038,68 +1038,68 @@ discard block |
||
| 1038 | 1038 | * @return bool true s'il a le droit, false sinon |
| 1039 | 1039 | **/ |
| 1040 | 1040 | function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1041 | - $id = (int) $id; |
|
| 1042 | - |
|
| 1043 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1044 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1045 | - if ($qui['statut'] != '0minirezo') { |
|
| 1046 | - return $id == $qui['id_auteur'] |
|
| 1047 | - && empty($opt['statut']) |
|
| 1048 | - && empty($opt['webmestre']) |
|
| 1049 | - && empty($opt['restreintes']) |
|
| 1050 | - && empty($opt['login']); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1054 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1055 | - if ($qui['restreint']) { |
|
| 1056 | - if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1057 | - return false; |
|
| 1058 | - } elseif ( |
|
| 1059 | - isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1060 | - ) { |
|
| 1061 | - return false; |
|
| 1062 | - } else { |
|
| 1063 | - if ($id == $qui['id_auteur']) { |
|
| 1064 | - if (isset($opt['statut']) && $opt['statut']) { |
|
| 1065 | - return false; |
|
| 1066 | - } else { |
|
| 1067 | - return true; |
|
| 1068 | - } |
|
| 1069 | - } else { |
|
| 1070 | - if ($id_auteur = (int) $id) { |
|
| 1071 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1072 | - if ($t && $t['statut'] != '0minirezo') { |
|
| 1073 | - return true; |
|
| 1074 | - } else { |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - } // id = 0 => creation |
|
| 1078 | - else { |
|
| 1079 | - return true; |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - // Un admin complet fait ce qu'il veut |
|
| 1086 | - // sauf se degrader |
|
| 1087 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1088 | - return false; |
|
| 1089 | - } elseif ( |
|
| 1090 | - isset($opt['webmestre']) |
|
| 1091 | - && $opt['webmestre'] |
|
| 1092 | - && (defined('_ID_WEBMESTRES') || !autoriser('webmestre')) |
|
| 1093 | - ) { |
|
| 1094 | - // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1095 | - // ou si les webmestres sont fixes par constante (securite) |
|
| 1096 | - return false; |
|
| 1097 | - } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1098 | - elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1099 | - return false; |
|
| 1100 | - } else { |
|
| 1101 | - return true; |
|
| 1102 | - } |
|
| 1041 | + $id = (int) $id; |
|
| 1042 | + |
|
| 1043 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1044 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1045 | + if ($qui['statut'] != '0minirezo') { |
|
| 1046 | + return $id == $qui['id_auteur'] |
|
| 1047 | + && empty($opt['statut']) |
|
| 1048 | + && empty($opt['webmestre']) |
|
| 1049 | + && empty($opt['restreintes']) |
|
| 1050 | + && empty($opt['login']); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1054 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1055 | + if ($qui['restreint']) { |
|
| 1056 | + if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1057 | + return false; |
|
| 1058 | + } elseif ( |
|
| 1059 | + isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1060 | + ) { |
|
| 1061 | + return false; |
|
| 1062 | + } else { |
|
| 1063 | + if ($id == $qui['id_auteur']) { |
|
| 1064 | + if (isset($opt['statut']) && $opt['statut']) { |
|
| 1065 | + return false; |
|
| 1066 | + } else { |
|
| 1067 | + return true; |
|
| 1068 | + } |
|
| 1069 | + } else { |
|
| 1070 | + if ($id_auteur = (int) $id) { |
|
| 1071 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1072 | + if ($t && $t['statut'] != '0minirezo') { |
|
| 1073 | + return true; |
|
| 1074 | + } else { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + } // id = 0 => creation |
|
| 1078 | + else { |
|
| 1079 | + return true; |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + // Un admin complet fait ce qu'il veut |
|
| 1086 | + // sauf se degrader |
|
| 1087 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1088 | + return false; |
|
| 1089 | + } elseif ( |
|
| 1090 | + isset($opt['webmestre']) |
|
| 1091 | + && $opt['webmestre'] |
|
| 1092 | + && (defined('_ID_WEBMESTRES') || !autoriser('webmestre')) |
|
| 1093 | + ) { |
|
| 1094 | + // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1095 | + // ou si les webmestres sont fixes par constante (securite) |
|
| 1096 | + return false; |
|
| 1097 | + } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1098 | + elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1099 | + return false; |
|
| 1100 | + } else { |
|
| 1101 | + return true; |
|
| 1102 | + } |
|
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | * @return bool true s'il a le droit, false sinon |
| 1119 | 1119 | **/ |
| 1120 | 1120 | function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1121 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1121 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | * @return bool true s'il a le droit, false sinon |
| 1138 | 1138 | **/ |
| 1139 | 1139 | function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1140 | - return $qui['statut'] === '0minirezo'; |
|
| 1140 | + return $qui['statut'] === '0minirezo'; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | * @return bool true s'il a le droit, false sinon |
| 1156 | 1156 | **/ |
| 1157 | 1157 | function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1158 | - return $qui['statut'] === '0minirezo'; |
|
| 1158 | + return $qui['statut'] === '0minirezo'; |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1172,53 +1172,53 @@ discard block |
||
| 1172 | 1172 | * @return array Liste des rubriques |
| 1173 | 1173 | **/ |
| 1174 | 1174 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1175 | - static $restreint = []; |
|
| 1176 | - |
|
| 1177 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 1178 | - return []; |
|
| 1179 | - } |
|
| 1180 | - if ($raz) { |
|
| 1181 | - unset($restreint[$id_auteur]); |
|
| 1182 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1183 | - return $restreint[$id_auteur]; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $rubriques = []; |
|
| 1187 | - if ( |
|
| 1188 | - (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1189 | - && ($r = sql_allfetsel( |
|
| 1190 | - 'id_objet', |
|
| 1191 | - 'spip_auteurs_liens', |
|
| 1192 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1193 | - )) |
|
| 1194 | - && (is_countable($r) ? count($r) : 0) |
|
| 1195 | - ) { |
|
| 1196 | - $r = array_column($r, 'id_objet'); |
|
| 1197 | - |
|
| 1198 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1199 | - include_spip('inc/rubriques'); |
|
| 1200 | - $r = calcul_branche_in($r); |
|
| 1201 | - $r = explode(',', (string) $r); |
|
| 1202 | - |
|
| 1203 | - // passer les rubriques en index, elimine les doublons |
|
| 1204 | - $r = array_flip($r); |
|
| 1205 | - // recuperer les index seuls |
|
| 1206 | - $r = array_keys($r); |
|
| 1207 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1208 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1209 | - $rubriques = array_combine($r, $r); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - // Affecter l'auteur session le cas echeant |
|
| 1213 | - if ( |
|
| 1214 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1215 | - && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1216 | - ) { |
|
| 1217 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1175 | + static $restreint = []; |
|
| 1176 | + |
|
| 1177 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 1178 | + return []; |
|
| 1179 | + } |
|
| 1180 | + if ($raz) { |
|
| 1181 | + unset($restreint[$id_auteur]); |
|
| 1182 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1183 | + return $restreint[$id_auteur]; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + $rubriques = []; |
|
| 1187 | + if ( |
|
| 1188 | + (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1189 | + && ($r = sql_allfetsel( |
|
| 1190 | + 'id_objet', |
|
| 1191 | + 'spip_auteurs_liens', |
|
| 1192 | + 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1193 | + )) |
|
| 1194 | + && (is_countable($r) ? count($r) : 0) |
|
| 1195 | + ) { |
|
| 1196 | + $r = array_column($r, 'id_objet'); |
|
| 1197 | + |
|
| 1198 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1199 | + include_spip('inc/rubriques'); |
|
| 1200 | + $r = calcul_branche_in($r); |
|
| 1201 | + $r = explode(',', (string) $r); |
|
| 1202 | + |
|
| 1203 | + // passer les rubriques en index, elimine les doublons |
|
| 1204 | + $r = array_flip($r); |
|
| 1205 | + // recuperer les index seuls |
|
| 1206 | + $r = array_keys($r); |
|
| 1207 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1208 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1209 | + $rubriques = array_combine($r, $r); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + // Affecter l'auteur session le cas echeant |
|
| 1213 | + if ( |
|
| 1214 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1215 | + && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1216 | + ) { |
|
| 1217 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | /** |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | * @return bool true s'il a le droit, false sinon |
| 1237 | 1237 | **/ |
| 1238 | 1238 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1239 | - return autoriser('previsualiser'); |
|
| 1239 | + return autoriser('previsualiser'); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | /** |
@@ -1254,7 +1254,7 @@ discard block |
||
| 1254 | 1254 | * @return bool true s'il a le droit, false sinon |
| 1255 | 1255 | **/ |
| 1256 | 1256 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1257 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1257 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | /** |
@@ -1272,8 +1272,8 @@ discard block |
||
| 1272 | 1272 | * @return bool true s'il a le droit, false sinon |
| 1273 | 1273 | **/ |
| 1274 | 1274 | function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1275 | - $id = (int) $id; |
|
| 1276 | - return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1275 | + $id = (int) $id; |
|
| 1276 | + return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | /** |
@@ -1291,8 +1291,8 @@ discard block |
||
| 1291 | 1291 | * @return bool true s'il a le droit, false sinon |
| 1292 | 1292 | **/ |
| 1293 | 1293 | function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1294 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1295 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1294 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1295 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | |
@@ -1312,7 +1312,7 @@ discard block |
||
| 1312 | 1312 | * @return true |
| 1313 | 1313 | **/ |
| 1314 | 1314 | function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1315 | - return true; |
|
| 1315 | + return true; |
|
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | /** |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | * @return false |
| 1332 | 1332 | **/ |
| 1333 | 1333 | function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1334 | - return false; |
|
| 1334 | + return false; |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | /** |
@@ -1349,7 +1349,7 @@ discard block |
||
| 1349 | 1349 | * @return bool true s'il a le droit, false sinon |
| 1350 | 1350 | **/ |
| 1351 | 1351 | function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1352 | - return autoriser('detruire') && !_request('reinstall'); |
|
| 1352 | + return autoriser('detruire') && !_request('reinstall'); |
|
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | /** |
@@ -1367,7 +1367,7 @@ discard block |
||
| 1367 | 1367 | * @return true |
| 1368 | 1368 | **/ |
| 1369 | 1369 | function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1370 | - return true; |
|
| 1370 | + return true; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | /** |
@@ -1385,7 +1385,7 @@ discard block |
||
| 1385 | 1385 | * @return true |
| 1386 | 1386 | **/ |
| 1387 | 1387 | function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1388 | - return true; |
|
| 1388 | + return true; |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | /** |
@@ -1403,7 +1403,7 @@ discard block |
||
| 1403 | 1403 | * @return bool true s'il a le droit, false sinon |
| 1404 | 1404 | **/ |
| 1405 | 1405 | function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1406 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1406 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | /** |
@@ -1421,7 +1421,7 @@ discard block |
||
| 1421 | 1421 | * @return true |
| 1422 | 1422 | **/ |
| 1423 | 1423 | function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1424 | - return true; |
|
| 1424 | + return true; |
|
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | 1427 | /** |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | * @return bool true s'il a le droit, false sinon |
| 1440 | 1440 | **/ |
| 1441 | 1441 | function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1442 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1442 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | /** |
@@ -1457,7 +1457,7 @@ discard block |
||
| 1457 | 1457 | * @return bool true s'il a le droit, false sinon |
| 1458 | 1458 | **/ |
| 1459 | 1459 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1460 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1460 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | /** |
@@ -1476,7 +1476,7 @@ discard block |
||
| 1476 | 1476 | * @return true |
| 1477 | 1477 | **/ |
| 1478 | 1478 | function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1479 | - return true; |
|
| 1479 | + return true; |
|
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | 1482 | /** |
@@ -1494,7 +1494,7 @@ discard block |
||
| 1494 | 1494 | * @return true |
| 1495 | 1495 | **/ |
| 1496 | 1496 | function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1497 | - return true; |
|
| 1497 | + return true; |
|
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | 1500 | /** |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | * @return bool true s'il a le droit, false sinon |
| 1513 | 1513 | **/ |
| 1514 | 1514 | function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1515 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1515 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | 1518 | /** |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | * @return true |
| 1531 | 1531 | **/ |
| 1532 | 1532 | function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1533 | - return true; |
|
| 1533 | + return true; |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | /** |
@@ -1548,7 +1548,7 @@ discard block |
||
| 1548 | 1548 | * @return bool true s'il a le droit, false sinon |
| 1549 | 1549 | **/ |
| 1550 | 1550 | function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1551 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1551 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | /** |
@@ -1566,7 +1566,7 @@ discard block |
||
| 1566 | 1566 | * @return true |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1569 | - return true; |
|
| 1569 | + return true; |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
@@ -1584,7 +1584,7 @@ discard block |
||
| 1584 | 1584 | * @return bool true s'il a le droit, false sinon |
| 1585 | 1585 | **/ |
| 1586 | 1586 | function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1587 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1587 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | /** |
@@ -1602,7 +1602,7 @@ discard block |
||
| 1602 | 1602 | * @return bool true s'il a le droit, false sinon |
| 1603 | 1603 | **/ |
| 1604 | 1604 | function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1605 | - return verifier_table_non_vide(); |
|
| 1605 | + return verifier_table_non_vide(); |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | |
@@ -1623,7 +1623,7 @@ discard block |
||
| 1623 | 1623 | * @return bool true s'il a le droit, false sinon |
| 1624 | 1624 | **/ |
| 1625 | 1625 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1626 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1626 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | 1629 | /** |
@@ -1641,11 +1641,11 @@ discard block |
||
| 1641 | 1641 | * @return bool true s'il a le droit, false sinon |
| 1642 | 1642 | **/ |
| 1643 | 1643 | function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1644 | - include_spip('base/abstract_sql'); |
|
| 1645 | - return |
|
| 1646 | - $qui['statut'] === '0minirezo' |
|
| 1647 | - && !$qui['restreint'] |
|
| 1648 | - && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1644 | + include_spip('base/abstract_sql'); |
|
| 1645 | + return |
|
| 1646 | + $qui['statut'] === '0minirezo' |
|
| 1647 | + && !$qui['restreint'] |
|
| 1648 | + && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | /** |
@@ -1663,7 +1663,7 @@ discard block |
||
| 1663 | 1663 | * @return bool true s'il a le droit, false sinon |
| 1664 | 1664 | **/ |
| 1665 | 1665 | function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1666 | - return $qui['statut'] === '0minirezo'; |
|
| 1666 | + return $qui['statut'] === '0minirezo'; |
|
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | /** |
@@ -1681,7 +1681,7 @@ discard block |
||
| 1681 | 1681 | * @return bool true s'il a le droit, false sinon |
| 1682 | 1682 | **/ |
| 1683 | 1683 | function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1684 | - return $qui['statut'] === '0minirezo'; |
|
| 1684 | + return $qui['statut'] === '0minirezo'; |
|
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | /** |
@@ -1699,7 +1699,7 @@ discard block |
||
| 1699 | 1699 | * @return bool true s'il a le droit, false sinon |
| 1700 | 1700 | **/ |
| 1701 | 1701 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1702 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1702 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | /** |
@@ -1717,7 +1717,7 @@ discard block |
||
| 1717 | 1717 | * @return bool true s'il a le droit, false sinon |
| 1718 | 1718 | **/ |
| 1719 | 1719 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1720 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1720 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | 1723 | /** |
@@ -1735,7 +1735,7 @@ discard block |
||
| 1735 | 1735 | * @return bool true s'il a le droit, false sinon |
| 1736 | 1736 | **/ |
| 1737 | 1737 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1738 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1738 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1739 | 1739 | } |
| 1740 | 1740 | |
| 1741 | 1741 | /** |
@@ -1753,7 +1753,7 @@ discard block |
||
| 1753 | 1753 | * @return bool true s'il a le droit, false sinon |
| 1754 | 1754 | **/ |
| 1755 | 1755 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1756 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1756 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | 1759 | /** |
@@ -1771,7 +1771,7 @@ discard block |
||
| 1771 | 1771 | * @return bool true s'il a le droit, false sinon |
| 1772 | 1772 | **/ |
| 1773 | 1773 | function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1774 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1774 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | 1777 | /** |
@@ -1789,7 +1789,7 @@ discard block |
||
| 1789 | 1789 | * @return bool true s'il a le droit, false sinon |
| 1790 | 1790 | **/ |
| 1791 | 1791 | function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1792 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1792 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | 1795 | /** |
@@ -1807,7 +1807,7 @@ discard block |
||
| 1807 | 1807 | * @return bool true s'il a le droit, false sinon |
| 1808 | 1808 | **/ |
| 1809 | 1809 | function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1810 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1810 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | /** |
@@ -1825,7 +1825,7 @@ discard block |
||
| 1825 | 1825 | * @return bool true s'il a le droit, false sinon |
| 1826 | 1826 | **/ |
| 1827 | 1827 | function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1828 | - return autoriser('webmestre'); |
|
| 1828 | + return autoriser('webmestre'); |
|
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | 1831 | |
@@ -1845,11 +1845,11 @@ discard block |
||
| 1845 | 1845 | * @return bool true s'il a le droit, false sinon |
| 1846 | 1846 | **/ |
| 1847 | 1847 | function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1848 | - if (test_espace_prive()) { |
|
| 1849 | - return (bool) (int) $qui['id_auteur']; |
|
| 1850 | - } else { |
|
| 1851 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1852 | - } |
|
| 1848 | + if (test_espace_prive()) { |
|
| 1849 | + return (bool) (int) $qui['id_auteur']; |
|
| 1850 | + } else { |
|
| 1851 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1852 | + } |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | |
@@ -1864,27 +1864,27 @@ discard block |
||
| 1864 | 1864 | * Identifiants d'auteurs |
| 1865 | 1865 | */ |
| 1866 | 1866 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1867 | - $objet = objet_type($objet); |
|
| 1868 | - $where = [ |
|
| 1869 | - 'objet=' . sql_quote($objet), |
|
| 1870 | - 'id_objet=' . (int) $id_objet |
|
| 1871 | - ]; |
|
| 1872 | - if (!empty($cond)) { |
|
| 1873 | - if (is_array($cond)) { |
|
| 1874 | - $where = array_merge($where, $cond); |
|
| 1875 | - } else { |
|
| 1876 | - $where[] = $cond; |
|
| 1877 | - } |
|
| 1878 | - } |
|
| 1879 | - $auteurs = sql_allfetsel( |
|
| 1880 | - 'id_auteur', |
|
| 1881 | - 'spip_auteurs_liens', |
|
| 1882 | - $where |
|
| 1883 | - ); |
|
| 1884 | - if (is_array($auteurs)) { |
|
| 1885 | - return array_column($auteurs, 'id_auteur'); |
|
| 1886 | - } |
|
| 1887 | - return []; |
|
| 1867 | + $objet = objet_type($objet); |
|
| 1868 | + $where = [ |
|
| 1869 | + 'objet=' . sql_quote($objet), |
|
| 1870 | + 'id_objet=' . (int) $id_objet |
|
| 1871 | + ]; |
|
| 1872 | + if (!empty($cond)) { |
|
| 1873 | + if (is_array($cond)) { |
|
| 1874 | + $where = array_merge($where, $cond); |
|
| 1875 | + } else { |
|
| 1876 | + $where[] = $cond; |
|
| 1877 | + } |
|
| 1878 | + } |
|
| 1879 | + $auteurs = sql_allfetsel( |
|
| 1880 | + 'id_auteur', |
|
| 1881 | + 'spip_auteurs_liens', |
|
| 1882 | + $where |
|
| 1883 | + ); |
|
| 1884 | + if (is_array($auteurs)) { |
|
| 1885 | + return array_column($auteurs, 'id_auteur'); |
|
| 1886 | + } |
|
| 1887 | + return []; |
|
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | /** |
@@ -1899,11 +1899,11 @@ discard block |
||
| 1899 | 1899 | * - false : serveur SQL indisponible |
| 1900 | 1900 | */ |
| 1901 | 1901 | function auteurs_article($id_article, $cond = '') { |
| 1902 | - return sql_allfetsel( |
|
| 1903 | - 'id_auteur', |
|
| 1904 | - 'spip_auteurs_liens', |
|
| 1905 | - "objet='article' AND id_objet=" . (int) $id_article . ($cond ? " AND $cond" : '') |
|
| 1906 | - ); |
|
| 1902 | + return sql_allfetsel( |
|
| 1903 | + 'id_auteur', |
|
| 1904 | + 'spip_auteurs_liens', |
|
| 1905 | + "objet='article' AND id_objet=" . (int) $id_article . ($cond ? " AND $cond" : '') |
|
| 1906 | + ); |
|
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | 1909 | |
@@ -1917,7 +1917,7 @@ discard block |
||
| 1917 | 1917 | */ |
| 1918 | 1918 | function acces_restreint_rubrique($id_rubrique) { |
| 1919 | 1919 | |
| 1920 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1920 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1921 | 1921 | } |
| 1922 | 1922 | |
| 1923 | 1923 | |
@@ -1930,12 +1930,12 @@ discard block |
||
| 1930 | 1930 | * @return bool true si un parent existe |
| 1931 | 1931 | */ |
| 1932 | 1932 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1933 | - static $done = []; |
|
| 1934 | - if (!isset($done[$table])) { |
|
| 1935 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1936 | - } |
|
| 1933 | + static $done = []; |
|
| 1934 | + if (!isset($done[$table])) { |
|
| 1935 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1936 | + } |
|
| 1937 | 1937 | |
| 1938 | - return $done[$table]; |
|
| 1938 | + return $done[$table]; |
|
| 1939 | 1939 | } |
| 1940 | 1940 | |
| 1941 | 1941 | /** |
@@ -1962,12 +1962,12 @@ discard block |
||
| 1962 | 1962 | */ |
| 1963 | 1963 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1964 | 1964 | |
| 1965 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1966 | - return match ($s) { |
|
| 1967 | - 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1968 | - 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1969 | - default => false, |
|
| 1970 | - }; |
|
| 1965 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1966 | + return match ($s) { |
|
| 1967 | + 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1968 | + 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1969 | + default => false, |
|
| 1970 | + }; |
|
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | 1973 | /** |
@@ -1985,7 +1985,7 @@ discard block |
||
| 1985 | 1985 | * @return bool true s'il a le droit, false sinon |
| 1986 | 1986 | **/ |
| 1987 | 1987 | function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1988 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1988 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | 1991 | /** |
@@ -2003,5 +2003,5 @@ discard block |
||
| 2003 | 2003 | * @return bool true s'il a le droit, false sinon |
| 2004 | 2004 | **/ |
| 2005 | 2005 | function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 2006 | - return autoriser('webmestre'); |
|
| 2006 | + return autoriser('webmestre'); |
|
| 2007 | 2007 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -25,70 +25,70 @@ discard block |
||
| 25 | 25 | * @return string Code HTML du cadre dépliable |
| 26 | 26 | **/ |
| 27 | 27 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 28 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 29 | - |
|
| 30 | - return |
|
| 31 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 32 | - . debut_block_depliable($deplie, $ids) |
|
| 33 | - . "<div class='cadre_padding'>\n" |
|
| 34 | - . $contenu |
|
| 35 | - . "</div>\n" |
|
| 36 | - . fin_block() |
|
| 37 | - . fin_cadre(); |
|
| 28 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 29 | + |
|
| 30 | + return |
|
| 31 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 32 | + . debut_block_depliable($deplie, $ids) |
|
| 33 | + . "<div class='cadre_padding'>\n" |
|
| 34 | + . $contenu |
|
| 35 | + . "</div>\n" |
|
| 36 | + . fin_block() |
|
| 37 | + . fin_cadre(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 41 | - return "\n" |
|
| 42 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 43 | - . debut_block_depliable($visible, $nom) |
|
| 44 | - . $masque |
|
| 45 | - . fin_block(); |
|
| 41 | + return "\n" |
|
| 42 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 43 | + . debut_block_depliable($visible, $nom) |
|
| 44 | + . $masque |
|
| 45 | + . fin_block(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function debut_block_depliable($deplie, $id = '') { |
| 49 | - $class = ' blocdeplie'; |
|
| 50 | - // si on n'accepte pas js, ne pas fermer |
|
| 51 | - if (!$deplie) { |
|
| 52 | - $class = ' blocreplie'; |
|
| 53 | - } |
|
| 49 | + $class = ' blocdeplie'; |
|
| 50 | + // si on n'accepte pas js, ne pas fermer |
|
| 51 | + if (!$deplie) { |
|
| 52 | + $class = ' blocreplie'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 55 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function fin_block() { |
| 59 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 59 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // $texte : texte du bouton |
| 63 | 63 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 64 | 64 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 65 | 65 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 66 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 67 | - |
|
| 68 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 69 | - if (strlen((string) $ids)) { |
|
| 70 | - $cible = explode(',', (string) $ids); |
|
| 71 | - $cible = '#' . implode(',#', $cible); |
|
| 72 | - } else { |
|
| 73 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $b = (str_contains((string) $texte, '<h') ? 'div' : 'h3'); |
|
| 77 | - |
|
| 78 | - return "<$b " |
|
| 79 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 80 | - . "class='titrem$class'" |
|
| 81 | - . (($deplie === -1) |
|
| 82 | - ? '' |
|
| 83 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 84 | - ) |
|
| 85 | - . '>' |
|
| 86 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 87 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 88 | - . "$texte</$b>" |
|
| 89 | - . http_script(($deplie === 'incertain') |
|
| 90 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 91 | - : ''); |
|
| 66 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 67 | + |
|
| 68 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 69 | + if (strlen((string) $ids)) { |
|
| 70 | + $cible = explode(',', (string) $ids); |
|
| 71 | + $cible = '#' . implode(',#', $cible); |
|
| 72 | + } else { |
|
| 73 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $b = (str_contains((string) $texte, '<h') ? 'div' : 'h3'); |
|
| 77 | + |
|
| 78 | + return "<$b " |
|
| 79 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 80 | + . "class='titrem$class'" |
|
| 81 | + . (($deplie === -1) |
|
| 82 | + ? '' |
|
| 83 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 84 | + ) |
|
| 85 | + . '>' |
|
| 86 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 87 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 88 | + . "$texte</$b>" |
|
| 89 | + . http_script(($deplie === 'incertain') |
|
| 90 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 91 | + : ''); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // |
@@ -96,66 +96,66 @@ discard block |
||
| 96 | 96 | // |
| 97 | 97 | function verif_butineur() { |
| 98 | 98 | |
| 99 | - preg_match(',^([A-Za-z]+)/(\d+\.\d+) (.*)$,', (string) $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 100 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 101 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 102 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 103 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 104 | - $GLOBALS['browser_barre'] = ''; |
|
| 105 | - |
|
| 106 | - if (!preg_match(',opera,i', (string) $GLOBALS['browser_description']) && preg_match(',opera,i', (string) $GLOBALS['browser_name'])) { |
|
| 107 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 108 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 109 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 110 | - } else { |
|
| 111 | - if (preg_match(',opera,i', (string) $GLOBALS['browser_description'])) { |
|
| 112 | - preg_match(',Opera ([^\ ]*),i', (string) $GLOBALS['browser_description'], $match); |
|
| 113 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 115 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | - } else { |
|
| 117 | - if (preg_match(',msie,i', (string) $GLOBALS['browser_description'])) { |
|
| 118 | - preg_match(',MSIE ([^;]*),i', (string) $GLOBALS['browser_description'], $match); |
|
| 119 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 120 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 122 | - } else { |
|
| 123 | - if ( |
|
| 124 | - preg_match(',KHTML,i', (string) $GLOBALS['browser_description']) && |
|
| 125 | - preg_match(',Safari/([^;]*),', (string) $GLOBALS['browser_description'], $match) |
|
| 126 | - ) { |
|
| 127 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 128 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 129 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 130 | - } else { |
|
| 131 | - if (preg_match(',mozilla,i', (string) $GLOBALS['browser_name']) && $GLOBALS['browser_version'] >= 5) { |
|
| 132 | - // Numero de version pour Mozilla "authentique" |
|
| 133 | - if (preg_match(',rv:(\d+\.\d+),', (string) $GLOBALS['browser_description'], $match)) { |
|
| 134 | - $GLOBALS['browser_rev'] = (float) $match[1]; |
|
| 135 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 136 | - else { |
|
| 137 | - if ( |
|
| 138 | - strpos((string) $GLOBALS['browser_description'], 'Gecko') && !strpos( |
|
| 139 | - (string) $GLOBALS['browser_description'], |
|
| 140 | - 'KHTML' |
|
| 141 | - ) |
|
| 142 | - ) { |
|
| 143 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 144 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 145 | - else { |
|
| 146 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (!$GLOBALS['browser_name']) { |
|
| 157 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 158 | - } |
|
| 99 | + preg_match(',^([A-Za-z]+)/(\d+\.\d+) (.*)$,', (string) $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 100 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 101 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 102 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 103 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 104 | + $GLOBALS['browser_barre'] = ''; |
|
| 105 | + |
|
| 106 | + if (!preg_match(',opera,i', (string) $GLOBALS['browser_description']) && preg_match(',opera,i', (string) $GLOBALS['browser_name'])) { |
|
| 107 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 108 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 109 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 110 | + } else { |
|
| 111 | + if (preg_match(',opera,i', (string) $GLOBALS['browser_description'])) { |
|
| 112 | + preg_match(',Opera ([^\ ]*),i', (string) $GLOBALS['browser_description'], $match); |
|
| 113 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 115 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | + } else { |
|
| 117 | + if (preg_match(',msie,i', (string) $GLOBALS['browser_description'])) { |
|
| 118 | + preg_match(',MSIE ([^;]*),i', (string) $GLOBALS['browser_description'], $match); |
|
| 119 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 120 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 122 | + } else { |
|
| 123 | + if ( |
|
| 124 | + preg_match(',KHTML,i', (string) $GLOBALS['browser_description']) && |
|
| 125 | + preg_match(',Safari/([^;]*),', (string) $GLOBALS['browser_description'], $match) |
|
| 126 | + ) { |
|
| 127 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 128 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 129 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 130 | + } else { |
|
| 131 | + if (preg_match(',mozilla,i', (string) $GLOBALS['browser_name']) && $GLOBALS['browser_version'] >= 5) { |
|
| 132 | + // Numero de version pour Mozilla "authentique" |
|
| 133 | + if (preg_match(',rv:(\d+\.\d+),', (string) $GLOBALS['browser_description'], $match)) { |
|
| 134 | + $GLOBALS['browser_rev'] = (float) $match[1]; |
|
| 135 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 136 | + else { |
|
| 137 | + if ( |
|
| 138 | + strpos((string) $GLOBALS['browser_description'], 'Gecko') && !strpos( |
|
| 139 | + (string) $GLOBALS['browser_description'], |
|
| 140 | + 'KHTML' |
|
| 141 | + ) |
|
| 142 | + ) { |
|
| 143 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 144 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 145 | + else { |
|
| 146 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (!$GLOBALS['browser_name']) { |
|
| 157 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 158 | + } |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | verif_butineur(); |