@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($query) { |
| 47 | - $url .= '?' . $query; |
|
| 47 | + $url .= '?'.$query; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/'.preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 78 | 78 | $r = array_pad($r, 3, ''); |
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 80 | + return $r[1].resolve_path($r[2]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | # L'url site spip est un lien absolu aussi |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $hash = $regs[5] ?? ''; |
| 98 | 98 | } |
| 99 | 99 | return match (substr($lien, 0, 1)) { |
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 100 | + '/' => $debut.resolve_path($lien), |
|
| 101 | + '#' => $debut.resolve_path($dir.$mot.$get.$lien), |
|
| 102 | + '' => $debut.resolve_path($dir.$mot.$get.$hash), |
|
| 103 | + default => $debut.resolve_path($dir.$lien), |
|
| 104 | 104 | }; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return ''; |
| 130 | 130 | } |
| 131 | 131 | if (!$base) { |
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 132 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | return suivre_lien($base, $url); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param array $protocoles_autorises |
| 153 | 153 | * @return bool |
| 154 | 154 | */ |
| 155 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 155 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 156 | 156 | |
| 157 | 157 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 158 | 158 | $protocole = $m[1]; |
@@ -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 | |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * @return string URL nettoyée |
| 35 | 35 | **/ |
| 36 | 36 | function resolve_path($url) { |
| 37 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | - while ( |
|
| 39 | - preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | - || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | - || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | - ) { |
|
| 43 | - $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | - } |
|
| 37 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | + while ( |
|
| 39 | + preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | + || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | + || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | + ) { |
|
| 43 | + $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ($query) { |
|
| 47 | - $url .= '?' . $query; |
|
| 48 | - } |
|
| 46 | + if ($query) { |
|
| 47 | + $url .= '?' . $query; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | **/ |
| 69 | 69 | function suivre_lien($url, $lien) { |
| 70 | 70 | |
| 71 | - $mot = null; |
|
| 72 | - $get = null; |
|
| 73 | - $hash = null; |
|
| 74 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | - return $lien; |
|
| 76 | - } |
|
| 77 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | - $r = array_pad($r, 3, ''); |
|
| 71 | + $mot = null; |
|
| 72 | + $get = null; |
|
| 73 | + $hash = null; |
|
| 74 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | + return $lien; |
|
| 76 | + } |
|
| 77 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | + $r = array_pad($r, 3, ''); |
|
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 81 | - } |
|
| 80 | + return $r[1] . resolve_path($r[2]); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - # L'url site spip est un lien absolu aussi |
|
| 84 | - if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | - return $lien; |
|
| 86 | - } |
|
| 83 | + # L'url site spip est un lien absolu aussi |
|
| 84 | + if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | + return $lien; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - # lien relatif, il faut verifier l'url de base |
|
| 89 | - # commencer par virer la chaine de get de l'url de base |
|
| 90 | - $dir = '/'; |
|
| 91 | - $debut = ''; |
|
| 92 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | - $debut = $regs[1]; |
|
| 94 | - $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | - $mot = $regs[3]; |
|
| 96 | - $get = $regs[4] ?? ''; |
|
| 97 | - $hash = $regs[5] ?? ''; |
|
| 98 | - } |
|
| 99 | - return match (substr($lien, 0, 1)) { |
|
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 104 | - }; |
|
| 88 | + # lien relatif, il faut verifier l'url de base |
|
| 89 | + # commencer par virer la chaine de get de l'url de base |
|
| 90 | + $dir = '/'; |
|
| 91 | + $debut = ''; |
|
| 92 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | + $debut = $regs[1]; |
|
| 94 | + $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | + $mot = $regs[3]; |
|
| 96 | + $get = $regs[4] ?? ''; |
|
| 97 | + $hash = $regs[5] ?? ''; |
|
| 98 | + } |
|
| 99 | + return match (substr($lien, 0, 1)) { |
|
| 100 | + '/' => $debut . resolve_path($lien), |
|
| 101 | + '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | + '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | + default => $debut . resolve_path($dir . $lien), |
|
| 104 | + }; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -124,15 +124,15 @@ discard block |
||
| 124 | 124 | * @return string texte ou URL (en absolus) |
| 125 | 125 | **/ |
| 126 | 126 | function url_absolue($url, $base = '') { |
| 127 | - $url = trim((string) $url); |
|
| 128 | - if (strlen($url = trim($url)) == 0) { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - if (!$base) { |
|
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | - } |
|
| 127 | + $url = trim((string) $url); |
|
| 128 | + if (strlen($url = trim($url)) == 0) { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + if (!$base) { |
|
| 132 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - return suivre_lien($base, $url); |
|
| 135 | + return suivre_lien($base, $url); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function protocole_implicite($url_absolue) { |
| 146 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 146 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 156 | 156 | |
| 157 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | - $protocole = $m[1]; |
|
| 159 | - if ( |
|
| 160 | - in_array($protocole, $protocoles_autorises) |
|
| 161 | - || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | - ) { |
|
| 163 | - return true; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 157 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | + $protocole = $m[1]; |
|
| 159 | + if ( |
|
| 160 | + in_array($protocole, $protocoles_autorises) |
|
| 161 | + || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | + ) { |
|
| 163 | + return true; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -180,31 +180,31 @@ discard block |
||
| 180 | 180 | * @return string texte avec des URLs absolues |
| 181 | 181 | **/ |
| 182 | 182 | function liens_absolus($texte, $base = '') { |
| 183 | - if ($texte === null || $texte === '') { |
|
| 184 | - return ''; |
|
| 185 | - } |
|
| 186 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | - if (!function_exists('extraire_attribut')) { |
|
| 188 | - include_spip('inc/filtres'); |
|
| 189 | - } |
|
| 190 | - foreach ($liens as $lien) { |
|
| 191 | - foreach (['href', 'src'] as $attr) { |
|
| 192 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | - if ( |
|
| 194 | - strlen((string) $href) > 0 |
|
| 195 | - && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | - ) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 183 | + if ($texte === null || $texte === '') { |
|
| 184 | + return ''; |
|
| 185 | + } |
|
| 186 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | + if (!function_exists('extraire_attribut')) { |
|
| 188 | + include_spip('inc/filtres'); |
|
| 189 | + } |
|
| 190 | + foreach ($liens as $lien) { |
|
| 191 | + foreach (['href', 'src'] as $attr) { |
|
| 192 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | + if ( |
|
| 194 | + strlen((string) $href) > 0 |
|
| 195 | + && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | + ) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $texte; |
|
| 207 | + return $texte; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | * @return string texte ou URL (en absolus) |
| 223 | 223 | **/ |
| 224 | 224 | function abs_url($texte, $base = '') { |
| 225 | - trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | - return url_absolue($texte, $base); |
|
| 228 | - } else { |
|
| 229 | - return liens_absolus($texte, $base); |
|
| 230 | - } |
|
| 225 | + trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | + return url_absolue($texte, $base); |
|
| 228 | + } else { |
|
| 229 | + return liens_absolus($texte, $base); |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | 242 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 243 | - if (is_null($flags)) { |
|
| 244 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | - } |
|
| 243 | + if (is_null($flags)) { |
|
| 244 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 247 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 260 | - if (is_null($flags)) { |
|
| 261 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | - } |
|
| 260 | + if (is_null($flags)) { |
|
| 261 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 264 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 265 | 265 | } |
@@ -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 | } |
@@ -136,7 +136,7 @@ |
||
| 136 | 136 | $p !== false |
| 137 | 137 | && ($morceau = substr($txt, $d, $p - $d)) |
| 138 | 138 | && ($nopen += preg_match_all( |
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 139 | + '{<'.preg_quote((string) $closing_tag).'(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | 140 | $morceau, |
| 141 | 141 | $matches, |
| 142 | 142 | PREG_SET_ORDER |
@@ -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 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | include_spip('inc/texte'); |
| 20 | 20 | $titre = $descriptif = ''; |
| 21 | 21 | if ($type === 'rubrique') { |
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.(int) $id); |
|
| 23 | 23 | if ($row) { |
| 24 | 24 | $titre = typo($row['titre']); |
| 25 | 25 | $descriptif = propre($row['descriptif']); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | include_spip('inc/filtres_images_mini'); |
| 42 | 42 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 43 | 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>"; |
|
| 44 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | ' ' |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do.'_selection_titre'; |
|
| 66 | 66 | |
| 67 | 67 | return "<div style='display: none;'>" |
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 68 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 70 | 70 | . entites_html($titre) |
| 71 | 71 | . '" />' |
| 72 | 72 | . '</div>' |
| 73 | 73 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 74 | 74 | . '<div class="informer__item">' |
| 75 | 75 | . ($res ?: '') |
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 76 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>".safehtml($descriptif).'</div>' : '') |
|
| 78 | 78 | . '</div>' |
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 80 | 80 | . "<input type='submit' class='fondo btn submit' value='" |
| 81 | 81 | . _T('bouton_choisir') |
| 82 | 82 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -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 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
| 143 | 143 | $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
| 144 | 144 | . $data[$root] |
| 145 | - . '</option>' . "\n"; |
|
| 145 | + . '</option>'."\n"; |
|
| 146 | 146 | } else { |
| 147 | 147 | $r = ''; |
| 148 | 148 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // et voila le travail |
| 173 | - return $r . $sous; |
|
| 173 | + return $r.$sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -218,12 +218,12 @@ discard block |
||
| 218 | 218 | while ($r = sql_fetch($q)) { |
| 219 | 219 | if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
| 220 | 220 | // titre largeur maxi a 50 |
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])).' ', 50); |
|
| 222 | 222 | if ( |
| 223 | 223 | $GLOBALS['meta']['multi_rubriques'] == 'oui' |
| 224 | 224 | && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
| 225 | 225 | ) { |
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 226 | + $titre .= ' ['.traduire_nom_langue($r['lang']).']'; |
|
| 227 | 227 | } |
| 228 | 228 | $data[$r['id_rubrique']] = $titre; |
| 229 | 229 | $enfants[$r['id_parent']][] = $r['id_rubrique']; |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
| 251 | 251 | |
| 252 | 252 | if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 253 | + $r = "<input$att type='hidden' value='".$r[1]."' />".$r[2]; |
|
| 254 | 254 | } else { |
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 255 | + $r = '<select'.$att." size='1'>\n$opt</select>\n"; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | # message pour neuneus (a supprimer ?) |
@@ -294,13 +294,13 @@ discard block |
||
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | 296 | if ($id_rubrique) { |
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 298 | 298 | } else { |
| 299 | 299 | $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"".$titre."\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | 305 | $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
| 306 | 306 | . ($idem ? "&exclus=$idem" : '') |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | . " jQuery(this).toggleClass('toggled'); " |
| 350 | 350 | . "return charger_node_url_si_vide('" |
| 351 | 351 | . $url |
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='".attribut_html(_T('titre_image_selecteur'))."'>" |
|
| 353 | 353 | . $img_icone |
| 354 | 354 | . "</a><img src='" |
| 355 | 355 | . chemin_image('loader.svg') |
@@ -313,9 +313,9 @@ |
||
| 313 | 313 | && ($e = $flux['args']['contexte']['_etape']) > 1 |
| 314 | 314 | && ($ext = $flux['args']['ext']) |
| 315 | 315 | && ($f = $flux['data']) |
| 316 | - && file_exists($f . "_$e.$ext") |
|
| 316 | + && file_exists($f."_$e.$ext") |
|
| 317 | 317 | ) { |
| 318 | - $flux['data'] = $f . "_$e"; |
|
| 318 | + $flux['data'] = $f."_$e"; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | return $flux; |
@@ -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 | /** |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | * @return array |
| 160 | 160 | */ |
| 161 | 161 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 162 | - if (!isset($valeurs['_etape'])) { |
|
| 163 | - $form = $args['form']; |
|
| 164 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 165 | - $nb_etapes = $valeurs['_etapes']; |
|
| 166 | - $etape = _request('_etape'); |
|
| 167 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 168 | - set_request('_etape', $etape); |
|
| 169 | - $valeurs['_etape'] = $etape; |
|
| 162 | + if (!isset($valeurs['_etape'])) { |
|
| 163 | + $form = $args['form']; |
|
| 164 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 165 | + $nb_etapes = $valeurs['_etapes']; |
|
| 166 | + $etape = _request('_etape'); |
|
| 167 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 168 | + set_request('_etape', $etape); |
|
| 169 | + $valeurs['_etape'] = $etape; |
|
| 170 | 170 | |
| 171 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 172 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 173 | - } |
|
| 174 | - return $valeurs; |
|
| 171 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 172 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 173 | + } |
|
| 174 | + return $valeurs; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -182,87 +182,87 @@ discard block |
||
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | 184 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 185 | - #var_dump('Pipe verifier'); |
|
| 185 | + #var_dump('Pipe verifier'); |
|
| 186 | 186 | |
| 187 | - if ( |
|
| 188 | - ($form = $args['form']) |
|
| 189 | - && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 190 | - ) { |
|
| 191 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 192 | - [$etape, $etapes] = $e; |
|
| 193 | - $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 187 | + if ( |
|
| 188 | + ($form = $args['form']) |
|
| 189 | + && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 190 | + ) { |
|
| 191 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 192 | + [$etape, $etapes] = $e; |
|
| 193 | + $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 194 | 194 | |
| 195 | - $args['etape_saisie'] = $etape; |
|
| 196 | - $args['etapes'] = $etapes; |
|
| 197 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 198 | - $erreurs_etapes = []; |
|
| 199 | - $derniere_etape_ok = 0; |
|
| 200 | - $e = 0; |
|
| 201 | - while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 202 | - $e++; |
|
| 203 | - $erreurs_etapes[$e] = []; |
|
| 204 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 205 | - $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 206 | - } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 207 | - $a = $args['args']; |
|
| 208 | - array_unshift($a, $e); |
|
| 209 | - $erreurs_etapes[$e] = $verifier(...$a); |
|
| 210 | - } |
|
| 211 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 212 | - $args['etape'] = $e; |
|
| 213 | - $args['etape_demandee'] = $etape_demandee; |
|
| 214 | - $erreurs_etapes[$e] = pipeline( |
|
| 215 | - 'formulaire_verifier_etape', |
|
| 216 | - [ |
|
| 217 | - 'args' => $args, |
|
| 218 | - 'data' => $erreurs_etapes[$e] |
|
| 219 | - ] |
|
| 220 | - ); |
|
| 195 | + $args['etape_saisie'] = $etape; |
|
| 196 | + $args['etapes'] = $etapes; |
|
| 197 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 198 | + $erreurs_etapes = []; |
|
| 199 | + $derniere_etape_ok = 0; |
|
| 200 | + $e = 0; |
|
| 201 | + while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 202 | + $e++; |
|
| 203 | + $erreurs_etapes[$e] = []; |
|
| 204 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 205 | + $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 206 | + } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 207 | + $a = $args['args']; |
|
| 208 | + array_unshift($a, $e); |
|
| 209 | + $erreurs_etapes[$e] = $verifier(...$a); |
|
| 210 | + } |
|
| 211 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 212 | + $args['etape'] = $e; |
|
| 213 | + $args['etape_demandee'] = $etape_demandee; |
|
| 214 | + $erreurs_etapes[$e] = pipeline( |
|
| 215 | + 'formulaire_verifier_etape', |
|
| 216 | + [ |
|
| 217 | + 'args' => $args, |
|
| 218 | + 'data' => $erreurs_etapes[$e] |
|
| 219 | + ] |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 223 | - $derniere_etape_ok = $e; |
|
| 224 | - } |
|
| 225 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 226 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 227 | - $etape_demandee = $e; |
|
| 228 | - } |
|
| 229 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 230 | - if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 231 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 232 | - } |
|
| 233 | - } |
|
| 222 | + if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 223 | + $derniere_etape_ok = $e; |
|
| 224 | + } |
|
| 225 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 226 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 227 | + $etape_demandee = $e; |
|
| 228 | + } |
|
| 229 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 230 | + if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 231 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - // si la derniere etape OK etait la derniere |
|
| 237 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 238 | - if ( |
|
| 239 | - $derniere_etape_ok == $etapes |
|
| 240 | - && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 241 | - ) { |
|
| 242 | - return $erreurs; |
|
| 243 | - } else { |
|
| 244 | - $etape = $derniere_etape_ok + 1; |
|
| 245 | - if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 246 | - $etape = $etape_demandee; |
|
| 247 | - } |
|
| 248 | - $etape = min($etape, $etapes); |
|
| 249 | - #var_dump("prochaine etape $etape"); |
|
| 250 | - // retourner les erreurs de l'etape ciblee |
|
| 251 | - $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 252 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 253 | - if ($erreurs) { |
|
| 254 | - if (!isset($erreurs['message_erreur'])) { |
|
| 255 | - $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 256 | - } |
|
| 257 | - } else { |
|
| 258 | - $erreurs['message_erreur'] = ''; |
|
| 259 | - } |
|
| 260 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 261 | - set_request('_etape', $etape); |
|
| 262 | - } |
|
| 263 | - } |
|
| 236 | + // si la derniere etape OK etait la derniere |
|
| 237 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 238 | + if ( |
|
| 239 | + $derniere_etape_ok == $etapes |
|
| 240 | + && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 241 | + ) { |
|
| 242 | + return $erreurs; |
|
| 243 | + } else { |
|
| 244 | + $etape = $derniere_etape_ok + 1; |
|
| 245 | + if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 246 | + $etape = $etape_demandee; |
|
| 247 | + } |
|
| 248 | + $etape = min($etape, $etapes); |
|
| 249 | + #var_dump("prochaine etape $etape"); |
|
| 250 | + // retourner les erreurs de l'etape ciblee |
|
| 251 | + $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 252 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 253 | + if ($erreurs) { |
|
| 254 | + if (!isset($erreurs['message_erreur'])) { |
|
| 255 | + $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 256 | + } |
|
| 257 | + } else { |
|
| 258 | + $erreurs['message_erreur'] = ''; |
|
| 259 | + } |
|
| 260 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 261 | + set_request('_etape', $etape); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - return $erreurs; |
|
| 265 | + return $erreurs; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -274,17 +274,17 @@ discard block |
||
| 274 | 274 | * @return array |
| 275 | 275 | */ |
| 276 | 276 | function cvtmulti_styliser($flux) { |
| 277 | - if ( |
|
| 278 | - str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 279 | - && isset($flux['args']['contexte']['_etapes']) |
|
| 280 | - && isset($flux['args']['contexte']['_etape']) |
|
| 281 | - && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 282 | - && ($ext = $flux['args']['ext']) |
|
| 283 | - && ($f = $flux['data']) |
|
| 284 | - && file_exists($f . "_$e.$ext") |
|
| 285 | - ) { |
|
| 286 | - $flux['data'] = $f . "_$e"; |
|
| 287 | - } |
|
| 277 | + if ( |
|
| 278 | + str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 279 | + && isset($flux['args']['contexte']['_etapes']) |
|
| 280 | + && isset($flux['args']['contexte']['_etape']) |
|
| 281 | + && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 282 | + && ($ext = $flux['args']['ext']) |
|
| 283 | + && ($f = $flux['data']) |
|
| 284 | + && file_exists($f . "_$e.$ext") |
|
| 285 | + ) { |
|
| 286 | + $flux['data'] = $f . "_$e"; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return $flux; |
|
| 289 | + return $flux; |
|
| 290 | 290 | } |
@@ -267,8 +267,7 @@ discard block |
||
| 267 | 267 | if ($id === '*') { |
| 268 | 268 | unset($GLOBALS['autoriser_exception'][$faire][$type]); |
| 269 | 269 | unset($autorisation[$faire][$type]); |
| 270 | - } |
|
| 271 | - else { |
|
| 270 | + } else { |
|
| 272 | 271 | unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
| 273 | 272 | unset($autorisation[$faire][$type][$id]); |
| 274 | 273 | } |
@@ -635,8 +634,7 @@ discard block |
||
| 635 | 634 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 636 | 635 | if (!empty($opt['id_parent'])) { |
| 637 | 636 | return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
| 638 | - } |
|
| 639 | - else { |
|
| 637 | + } else { |
|
| 640 | 638 | return autoriser('defaut', null, 0, $qui, $opt); |
| 641 | 639 | } |
| 642 | 640 | } |
@@ -791,8 +789,7 @@ discard block |
||
| 791 | 789 | if (!empty($opt['id_parent'])) { |
| 792 | 790 | // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
| 793 | 791 | return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
| 794 | - } |
|
| 795 | - else { |
|
| 792 | + } else { |
|
| 796 | 793 | return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
| 797 | 794 | } |
| 798 | 795 | } |
@@ -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,83 +150,83 @@ 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 | - $logger = spip_logger('autoriser'); |
|
| 176 | - $logger->debug( |
|
| 177 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - $type = autoriser_type($type); |
|
| 181 | - |
|
| 182 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | - if ( |
|
| 184 | - isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | - && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | - ) { |
|
| 187 | - $logger->debug("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception'); |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Chercher une fonction d'autorisation |
|
| 192 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | - $fonctions = $type |
|
| 195 | - ? [ |
|
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 202 | - 'autoriser_defaut', |
|
| 203 | - 'autoriser_defaut_dist' |
|
| 204 | - ] |
|
| 205 | - : [ |
|
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 208 | - 'autoriser_defaut', |
|
| 209 | - 'autoriser_defaut_dist' |
|
| 210 | - ]; |
|
| 211 | - |
|
| 212 | - $a = false; |
|
| 213 | - foreach ($fonctions as $f) { |
|
| 214 | - if (function_exists($f)) { |
|
| 215 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | - break; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $logger->debug( |
|
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | - ); |
|
| 223 | - |
|
| 224 | - if (!is_bool($a)) { |
|
| 225 | - trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 226 | - $a = (bool) $a; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - 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 | + $logger = spip_logger('autoriser'); |
|
| 176 | + $logger->debug( |
|
| 177 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + $type = autoriser_type($type); |
|
| 181 | + |
|
| 182 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | + if ( |
|
| 184 | + isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | + && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | + ) { |
|
| 187 | + $logger->debug("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception'); |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Chercher une fonction d'autorisation |
|
| 192 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | + $fonctions = $type |
|
| 195 | + ? [ |
|
| 196 | + 'autoriser_' . $type . '_' . $faire, |
|
| 197 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | + 'autoriser_' . $type, |
|
| 199 | + 'autoriser_' . $type . '_dist', |
|
| 200 | + 'autoriser_' . $faire, |
|
| 201 | + 'autoriser_' . $faire . '_dist', |
|
| 202 | + 'autoriser_defaut', |
|
| 203 | + 'autoriser_defaut_dist' |
|
| 204 | + ] |
|
| 205 | + : [ |
|
| 206 | + 'autoriser_' . $faire, |
|
| 207 | + 'autoriser_' . $faire . '_dist', |
|
| 208 | + 'autoriser_defaut', |
|
| 209 | + 'autoriser_defaut_dist' |
|
| 210 | + ]; |
|
| 211 | + |
|
| 212 | + $a = false; |
|
| 213 | + foreach ($fonctions as $f) { |
|
| 214 | + if (function_exists($f)) { |
|
| 215 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | + break; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $logger->debug( |
|
| 221 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | + ); |
|
| 223 | + |
|
| 224 | + if (!is_bool($a)) { |
|
| 225 | + trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 226 | + $a = (bool) $a; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $a; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -246,31 +246,31 @@ discard block |
||
| 246 | 246 | * @return bool |
| 247 | 247 | */ |
| 248 | 248 | function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool { |
| 249 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 250 | - static $autorisation; |
|
| 251 | - // Tolérance avec certains appels |
|
| 252 | - if ($id === null) { |
|
| 253 | - $id = 0; |
|
| 254 | - } |
|
| 255 | - $type = autoriser_type($type); |
|
| 256 | - if ($autoriser === 'verifier') { |
|
| 257 | - return isset($autorisation[$faire][$type][$id]); |
|
| 258 | - } |
|
| 259 | - if ($autoriser === true) { |
|
| 260 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 261 | - } |
|
| 262 | - if ($autoriser === false) { |
|
| 263 | - if ($id === '*') { |
|
| 264 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 265 | - unset($autorisation[$faire][$type]); |
|
| 266 | - } |
|
| 267 | - else { |
|
| 268 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 269 | - unset($autorisation[$faire][$type][$id]); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - return false; |
|
| 249 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 250 | + static $autorisation; |
|
| 251 | + // Tolérance avec certains appels |
|
| 252 | + if ($id === null) { |
|
| 253 | + $id = 0; |
|
| 254 | + } |
|
| 255 | + $type = autoriser_type($type); |
|
| 256 | + if ($autoriser === 'verifier') { |
|
| 257 | + return isset($autorisation[$faire][$type][$id]); |
|
| 258 | + } |
|
| 259 | + if ($autoriser === true) { |
|
| 260 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 261 | + } |
|
| 262 | + if ($autoriser === false) { |
|
| 263 | + if ($id === '*') { |
|
| 264 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 265 | + unset($autorisation[$faire][$type]); |
|
| 266 | + } |
|
| 267 | + else { |
|
| 268 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 269 | + unset($autorisation[$faire][$type][$id]); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + return false; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -283,13 +283,13 @@ discard block |
||
| 283 | 283 | * - Les _ sont supprimés |
| 284 | 284 | */ |
| 285 | 285 | function autoriser_type(?string $type = ''): string { |
| 286 | - // passer par objet_type pour avoir les alias |
|
| 287 | - // sauf si _ est le premier caractère. |
|
| 288 | - if ($type && $type[0] !== '_') { |
|
| 289 | - $type = objet_type($type, false); |
|
| 290 | - } |
|
| 291 | - // et supprimer les _ |
|
| 292 | - return str_replace('_', '', (string) $type); |
|
| 286 | + // passer par objet_type pour avoir les alias |
|
| 287 | + // sauf si _ est le premier caractère. |
|
| 288 | + if ($type && $type[0] !== '_') { |
|
| 289 | + $type = objet_type($type, false); |
|
| 290 | + } |
|
| 291 | + // et supprimer les _ |
|
| 292 | + return str_replace('_', '', (string) $type); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * @return bool true s'il a le droit, false sinon |
| 309 | 309 | **/ |
| 310 | 310 | function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 311 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 311 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | * @return bool true s'il a le droit, false sinon |
| 329 | 329 | */ |
| 330 | 330 | function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 331 | - return $qui['statut'] !== '5poubelle'; |
|
| 331 | + return $qui['statut'] !== '5poubelle'; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @return bool true s'il a le droit, false sinon |
| 345 | 345 | **/ |
| 346 | 346 | function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 347 | - return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 347 | + return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * @return bool true s'il a le droit, false sinon |
| 364 | 364 | **/ |
| 365 | 365 | function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 366 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 366 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | **/ |
| 384 | 384 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 385 | 385 | |
| 386 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 387 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 388 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 389 | - } |
|
| 386 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 387 | + if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 388 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - // A-t-on un token de prévisualisation valable ? |
|
| 392 | - include_spip('inc/securiser_action'); |
|
| 393 | - return (bool) decrire_token_previsu(); |
|
| 391 | + // A-t-on un token de prévisualisation valable ? |
|
| 392 | + include_spip('inc/securiser_action'); |
|
| 393 | + return (bool) decrire_token_previsu(); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -419,58 +419,58 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool { |
| 421 | 421 | |
| 422 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 423 | - if (!$type) { |
|
| 424 | - return true; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - include_spip('base/objets'); |
|
| 428 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 429 | - if (isset($infos['statut'])) { |
|
| 430 | - foreach ($infos['statut'] as $c) { |
|
| 431 | - if (isset($c['publie'])) { |
|
| 432 | - if (!isset($c['previsu'])) { |
|
| 433 | - return false; |
|
| 434 | - } // pas de previsu definie => NIET |
|
| 435 | - $champ = $c['champ']; |
|
| 436 | - if (!isset($opt[$champ])) { |
|
| 437 | - return false; |
|
| 438 | - } // pas de champ passe a la demande => NIET |
|
| 439 | - $previsu = explode(',', (string) $c['previsu']); |
|
| 440 | - // regarder si ce statut est autorise pour l'auteur |
|
| 441 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 442 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 443 | - // sinon l’auteur en session |
|
| 444 | - include_spip('inc/securiser_action'); |
|
| 445 | - if ($desc = decrire_token_previsu()) { |
|
| 446 | - $id_auteur = $desc['id_auteur']; |
|
| 447 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 448 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 449 | - } else { |
|
| 450 | - $id_auteur = null; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - if (!$id_auteur) { |
|
| 454 | - return false; |
|
| 455 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 456 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 457 | - } elseif ( |
|
| 458 | - !sql_countsel( |
|
| 459 | - 'spip_auteurs_liens', |
|
| 460 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 461 | - ) |
|
| 462 | - ) { |
|
| 463 | - return false; |
|
| 464 | - } // pas auteur de cet objet => NIET |
|
| 465 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 466 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 467 | - return false; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - return true; |
|
| 422 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 423 | + if (!$type) { |
|
| 424 | + return true; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + include_spip('base/objets'); |
|
| 428 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 429 | + if (isset($infos['statut'])) { |
|
| 430 | + foreach ($infos['statut'] as $c) { |
|
| 431 | + if (isset($c['publie'])) { |
|
| 432 | + if (!isset($c['previsu'])) { |
|
| 433 | + return false; |
|
| 434 | + } // pas de previsu definie => NIET |
|
| 435 | + $champ = $c['champ']; |
|
| 436 | + if (!isset($opt[$champ])) { |
|
| 437 | + return false; |
|
| 438 | + } // pas de champ passe a la demande => NIET |
|
| 439 | + $previsu = explode(',', (string) $c['previsu']); |
|
| 440 | + // regarder si ce statut est autorise pour l'auteur |
|
| 441 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 442 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 443 | + // sinon l’auteur en session |
|
| 444 | + include_spip('inc/securiser_action'); |
|
| 445 | + if ($desc = decrire_token_previsu()) { |
|
| 446 | + $id_auteur = $desc['id_auteur']; |
|
| 447 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 448 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 449 | + } else { |
|
| 450 | + $id_auteur = null; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + if (!$id_auteur) { |
|
| 454 | + return false; |
|
| 455 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 456 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 457 | + } elseif ( |
|
| 458 | + !sql_countsel( |
|
| 459 | + 'spip_auteurs_liens', |
|
| 460 | + 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 461 | + ) |
|
| 462 | + ) { |
|
| 463 | + return false; |
|
| 464 | + } // pas auteur de cet objet => NIET |
|
| 465 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 466 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 467 | + return false; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + return true; |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -486,49 +486,49 @@ discard block |
||
| 486 | 486 | * @return bool true s'il a le droit, false sinon |
| 487 | 487 | **/ |
| 488 | 488 | function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 489 | - $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 490 | - $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 491 | - $table = table_objet_sql($type); |
|
| 492 | - if ( |
|
| 493 | - in_array($table, $multi_objets) |
|
| 494 | - || in_array($table, $gerer_trad_objets) |
|
| 495 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 496 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 497 | - $champs = objet_info($type, 'field'); |
|
| 498 | - if ( |
|
| 499 | - $multi_secteurs === 'oui' |
|
| 500 | - && array_key_exists('id_rubrique', $champs) |
|
| 501 | - ) { |
|
| 502 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 503 | - $primary = id_table_objet($type); |
|
| 504 | - $id_rubrique = $table != 'spip_rubriques' |
|
| 505 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 506 | - : $id; |
|
| 507 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 508 | - if (!$id_secteur > 0) { |
|
| 509 | - $id_secteur = $id_rubrique; |
|
| 510 | - } |
|
| 511 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 512 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 513 | - if ($langue_secteur != $langue_objet) { |
|
| 514 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 515 | - return true; |
|
| 516 | - } |
|
| 517 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 518 | - return false; |
|
| 519 | - } else { |
|
| 520 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 521 | - if ($id_parent != 0) { |
|
| 522 | - // sous-rubriques : pas de choix de langue |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } else { |
|
| 528 | - return false; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 489 | + $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 490 | + $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 491 | + $table = table_objet_sql($type); |
|
| 492 | + if ( |
|
| 493 | + in_array($table, $multi_objets) |
|
| 494 | + || in_array($table, $gerer_trad_objets) |
|
| 495 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 496 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 497 | + $champs = objet_info($type, 'field'); |
|
| 498 | + if ( |
|
| 499 | + $multi_secteurs === 'oui' |
|
| 500 | + && array_key_exists('id_rubrique', $champs) |
|
| 501 | + ) { |
|
| 502 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 503 | + $primary = id_table_objet($type); |
|
| 504 | + $id_rubrique = $table != 'spip_rubriques' |
|
| 505 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 506 | + : $id; |
|
| 507 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 508 | + if (!$id_secteur > 0) { |
|
| 509 | + $id_secteur = $id_rubrique; |
|
| 510 | + } |
|
| 511 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 512 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 513 | + if ($langue_secteur != $langue_objet) { |
|
| 514 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 515 | + return true; |
|
| 516 | + } |
|
| 517 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 518 | + return false; |
|
| 519 | + } else { |
|
| 520 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 521 | + if ($id_parent != 0) { |
|
| 522 | + // sous-rubriques : pas de choix de langue |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } else { |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | * @return bool true s'il a le droit, false sinon |
| 545 | 545 | **/ |
| 546 | 546 | function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 547 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 547 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -560,38 +560,38 @@ discard block |
||
| 560 | 560 | * @return bool true s'il a le droit, false sinon |
| 561 | 561 | **/ |
| 562 | 562 | function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 563 | - $table = table_objet($type); |
|
| 564 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 565 | - $desc = $trouver_table($table); |
|
| 566 | - if (!$desc) { |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (!isset($opt['statut'])) { |
|
| 571 | - if (isset($desc['field']['statut'])) { |
|
| 572 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 573 | - } else { |
|
| 574 | - $statut = 'publie'; |
|
| 575 | - } // pas de statut => publie |
|
| 576 | - } else { |
|
| 577 | - $statut = $opt['statut']; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - // Liste des statuts publiés pour cet objet |
|
| 581 | - // Sinon en dur le statut "publie" |
|
| 582 | - $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 583 | - ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 584 | - : ['publie']; |
|
| 585 | - |
|
| 586 | - if ( |
|
| 587 | - in_array($statut, $statuts_publies) |
|
| 588 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 589 | - || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 590 | - ) { |
|
| 591 | - return autoriser('modifier', $type, $id); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - return false; |
|
| 563 | + $table = table_objet($type); |
|
| 564 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 565 | + $desc = $trouver_table($table); |
|
| 566 | + if (!$desc) { |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (!isset($opt['statut'])) { |
|
| 571 | + if (isset($desc['field']['statut'])) { |
|
| 572 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 573 | + } else { |
|
| 574 | + $statut = 'publie'; |
|
| 575 | + } // pas de statut => publie |
|
| 576 | + } else { |
|
| 577 | + $statut = $opt['statut']; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // Liste des statuts publiés pour cet objet |
|
| 581 | + // Sinon en dur le statut "publie" |
|
| 582 | + $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 583 | + ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 584 | + : ['publie']; |
|
| 585 | + |
|
| 586 | + if ( |
|
| 587 | + in_array($statut, $statuts_publies) |
|
| 588 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 589 | + || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 590 | + ) { |
|
| 591 | + return autoriser('modifier', $type, $id); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + return false; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @return bool true s'il a le droit, false sinon |
| 611 | 611 | **/ |
| 612 | 612 | function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 613 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 613 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -628,9 +628,9 @@ discard block |
||
| 628 | 628 | * @return bool true s'il a le droit, false sinon |
| 629 | 629 | **/ |
| 630 | 630 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 631 | - return |
|
| 632 | - $qui['statut'] === '0minirezo' |
|
| 633 | - && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 631 | + return |
|
| 632 | + $qui['statut'] === '0minirezo' |
|
| 633 | + && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | * @return bool true s'il a le droit, false sinon |
| 649 | 649 | **/ |
| 650 | 650 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 651 | - if (!empty($opt['id_parent'])) { |
|
| 652 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 653 | - } |
|
| 654 | - else { |
|
| 655 | - return autoriser('defaut', null, 0, $qui, $opt); |
|
| 656 | - } |
|
| 651 | + if (!empty($opt['id_parent'])) { |
|
| 652 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 653 | + } |
|
| 654 | + else { |
|
| 655 | + return autoriser('defaut', null, 0, $qui, $opt); |
|
| 656 | + } |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
@@ -671,8 +671,8 @@ discard block |
||
| 671 | 671 | * @return bool true s'il a le droit, false sinon |
| 672 | 672 | **/ |
| 673 | 673 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 674 | - return |
|
| 675 | - ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 674 | + return |
|
| 675 | + ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -690,10 +690,10 @@ discard block |
||
| 690 | 690 | * @return bool true s'il a le droit, false sinon |
| 691 | 691 | **/ |
| 692 | 692 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 693 | - return |
|
| 694 | - $id |
|
| 695 | - && autoriser('voir', 'rubrique', $id) |
|
| 696 | - && autoriser('creer', 'article'); |
|
| 693 | + return |
|
| 694 | + $id |
|
| 695 | + && autoriser('voir', 'rubrique', $id) |
|
| 696 | + && autoriser('creer', 'article'); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * @return bool true s'il a le droit, false sinon |
| 713 | 713 | **/ |
| 714 | 714 | function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 715 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 715 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -730,29 +730,29 @@ discard block |
||
| 730 | 730 | * @return bool true s'il a le droit, false sinon |
| 731 | 731 | **/ |
| 732 | 732 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 733 | - if (!$id = (int) $id) { |
|
| 734 | - return false; |
|
| 735 | - } |
|
| 733 | + if (!$id = (int) $id) { |
|
| 734 | + return false; |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 738 | - return false; |
|
| 739 | - } |
|
| 737 | + if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 738 | + return false; |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 742 | - return false; |
|
| 743 | - } |
|
| 741 | + if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - $compte = pipeline( |
|
| 746 | - 'objet_compte_enfants', |
|
| 747 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 748 | - ); |
|
| 749 | - foreach ($compte as $objet => $n) { |
|
| 750 | - if ($n) { |
|
| 751 | - return false; |
|
| 752 | - } |
|
| 753 | - } |
|
| 745 | + $compte = pipeline( |
|
| 746 | + 'objet_compte_enfants', |
|
| 747 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 748 | + ); |
|
| 749 | + foreach ($compte as $objet => $n) { |
|
| 750 | + if ($n) { |
|
| 751 | + return false; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return autoriser('modifier', 'rubrique', $id); |
|
| 755 | + return autoriser('modifier', 'rubrique', $id); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -772,20 +772,20 @@ discard block |
||
| 772 | 772 | * @return bool true s'il a le droit, false sinon |
| 773 | 773 | **/ |
| 774 | 774 | function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 775 | - if (!$id) { |
|
| 776 | - return false; |
|
| 777 | - } |
|
| 778 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 775 | + if (!$id) { |
|
| 776 | + return false; |
|
| 777 | + } |
|
| 778 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 779 | 779 | |
| 780 | - return $r && ( |
|
| 781 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 782 | - || ( |
|
| 783 | - (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 784 | - && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 785 | - && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 786 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 780 | + return $r && ( |
|
| 781 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 782 | + || ( |
|
| 783 | + (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 784 | + && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 785 | + && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 786 | + && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -803,13 +803,13 @@ discard block |
||
| 803 | 803 | * @return bool true s'il a le droit, false sinon |
| 804 | 804 | **/ |
| 805 | 805 | function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 806 | - if (!empty($opt['id_parent'])) { |
|
| 807 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 808 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 809 | - } |
|
| 810 | - else { |
|
| 811 | - return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 812 | - } |
|
| 806 | + if (!empty($opt['id_parent'])) { |
|
| 807 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 808 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 809 | + } |
|
| 810 | + else { |
|
| 811 | + return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 812 | + } |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
@@ -831,26 +831,26 @@ discard block |
||
| 831 | 831 | * @return bool true s'il a le droit, false sinon |
| 832 | 832 | */ |
| 833 | 833 | function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 834 | - if ($qui['statut'] === '0minirezo') { |
|
| 835 | - return true; |
|
| 836 | - } |
|
| 837 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 838 | - if (isset($opt['statut'])) { |
|
| 839 | - $statut = $opt['statut']; |
|
| 840 | - } else { |
|
| 841 | - if (!$id) { |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 845 | - } |
|
| 834 | + if ($qui['statut'] === '0minirezo') { |
|
| 835 | + return true; |
|
| 836 | + } |
|
| 837 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 838 | + if (isset($opt['statut'])) { |
|
| 839 | + $statut = $opt['statut']; |
|
| 840 | + } else { |
|
| 841 | + if (!$id) { |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return |
|
| 848 | - // si on est pas auteur de l'article, |
|
| 849 | - // seuls les propose et publies sont visibles |
|
| 850 | - in_array($statut, ['prop', 'publie']) |
|
| 851 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 847 | + return |
|
| 848 | + // si on est pas auteur de l'article, |
|
| 849 | + // seuls les propose et publies sont visibles |
|
| 850 | + in_array($statut, ['prop', 'publie']) |
|
| 851 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 852 | 852 | |
| 853 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 853 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | |
@@ -869,24 +869,24 @@ discard block |
||
| 869 | 869 | * @return bool true s'il a le droit, false sinon |
| 870 | 870 | **/ |
| 871 | 871 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 872 | - # securite, mais on aurait pas du arriver ici ! |
|
| 873 | - if ( |
|
| 874 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 875 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 876 | - ) { |
|
| 877 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 878 | - } |
|
| 872 | + # securite, mais on aurait pas du arriver ici ! |
|
| 873 | + if ( |
|
| 874 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 875 | + || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 876 | + ) { |
|
| 877 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - if ($qui['statut'] === '0minirezo') { |
|
| 881 | - return true; |
|
| 882 | - } |
|
| 883 | - // admins et redacteurs peuvent voir un auteur |
|
| 884 | - if ($type === 'auteur') { |
|
| 885 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 886 | - } |
|
| 887 | - // sinon par defaut tout est visible |
|
| 888 | - // sauf cas particuliers traites separemment (ie article) |
|
| 889 | - return true; |
|
| 880 | + if ($qui['statut'] === '0minirezo') { |
|
| 881 | + return true; |
|
| 882 | + } |
|
| 883 | + // admins et redacteurs peuvent voir un auteur |
|
| 884 | + if ($type === 'auteur') { |
|
| 885 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 886 | + } |
|
| 887 | + // sinon par defaut tout est visible |
|
| 888 | + // sauf cas particuliers traites separemment (ie article) |
|
| 889 | + return true; |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | |
@@ -908,10 +908,10 @@ discard block |
||
| 908 | 908 | * @return bool true s'il a le droit, false sinon |
| 909 | 909 | **/ |
| 910 | 910 | function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 911 | - return |
|
| 912 | - $qui['webmestre'] === 'oui' |
|
| 913 | - && $qui['statut'] === '0minirezo' |
|
| 914 | - && !$qui['restreint']; |
|
| 911 | + return |
|
| 912 | + $qui['webmestre'] === 'oui' |
|
| 913 | + && $qui['statut'] === '0minirezo' |
|
| 914 | + && !$qui['restreint']; |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
@@ -929,7 +929,7 @@ discard block |
||
| 929 | 929 | * @return bool true s'il a le droit, false sinon |
| 930 | 930 | **/ |
| 931 | 931 | function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 932 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 932 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | * @return bool true s'il a le droit, false sinon |
| 948 | 948 | **/ |
| 949 | 949 | function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 950 | - return $qui['statut'] === '0minirezo'; |
|
| 950 | + return $qui['statut'] === '0minirezo'; |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | /** |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | * @return bool true s'il a le droit, false sinon |
| 966 | 966 | **/ |
| 967 | 967 | function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 968 | - return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 968 | + return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,23 +984,23 @@ discard block |
||
| 984 | 984 | * @return bool true s'il a le droit, false sinon |
| 985 | 985 | **/ |
| 986 | 986 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 987 | - // les admins peuvent "previsualiser" une page auteur |
|
| 988 | - if ( |
|
| 989 | - $qui['statut'] === '0minirezo' |
|
| 990 | - && !$qui['restreint'] |
|
| 991 | - ) { |
|
| 992 | - return true; |
|
| 993 | - } elseif ($id === 0) { |
|
| 994 | - return false; |
|
| 995 | - } |
|
| 996 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 997 | - $n = sql_fetsel( |
|
| 998 | - 'A.id_article', |
|
| 999 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1000 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1001 | - ); |
|
| 987 | + // les admins peuvent "previsualiser" une page auteur |
|
| 988 | + if ( |
|
| 989 | + $qui['statut'] === '0minirezo' |
|
| 990 | + && !$qui['restreint'] |
|
| 991 | + ) { |
|
| 992 | + return true; |
|
| 993 | + } elseif ($id === 0) { |
|
| 994 | + return false; |
|
| 995 | + } |
|
| 996 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 997 | + $n = sql_fetsel( |
|
| 998 | + 'A.id_article', |
|
| 999 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1000 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1001 | + ); |
|
| 1002 | 1002 | |
| 1003 | - return (bool) $n; |
|
| 1003 | + return (bool) $n; |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
@@ -1029,7 +1029,7 @@ discard block |
||
| 1029 | 1029 | * @return bool true s'il a le droit, false sinon |
| 1030 | 1030 | **/ |
| 1031 | 1031 | function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1032 | - return ($qui['statut'] === '0minirezo'); |
|
| 1032 | + return ($qui['statut'] === '0minirezo'); |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | |
@@ -1050,62 +1050,62 @@ discard block |
||
| 1050 | 1050 | * @return bool true s'il a le droit, false sinon |
| 1051 | 1051 | **/ |
| 1052 | 1052 | function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1053 | - $id = (int) $id; |
|
| 1054 | - |
|
| 1055 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1056 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1057 | - if ($qui['statut'] != '0minirezo') { |
|
| 1058 | - return $id == $qui['id_auteur'] |
|
| 1059 | - && empty($opt['statut']) |
|
| 1060 | - && empty($opt['webmestre']) |
|
| 1061 | - && empty($opt['restreintes']) |
|
| 1062 | - && empty($opt['login']); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1066 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1067 | - if ($qui['restreint']) { |
|
| 1068 | - if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1069 | - return false; |
|
| 1070 | - } elseif ( |
|
| 1071 | - isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1072 | - ) { |
|
| 1073 | - return false; |
|
| 1074 | - } else { |
|
| 1075 | - if ($id == $qui['id_auteur']) { |
|
| 1076 | - if (isset($opt['statut']) && $opt['statut']) { |
|
| 1077 | - return false; |
|
| 1078 | - } else { |
|
| 1079 | - return true; |
|
| 1080 | - } |
|
| 1081 | - } else { |
|
| 1082 | - if ($id_auteur = (int) $id) { |
|
| 1083 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1084 | - if ($t && $t['statut'] != '0minirezo') { |
|
| 1085 | - return true; |
|
| 1086 | - } else { |
|
| 1087 | - return false; |
|
| 1088 | - } |
|
| 1089 | - } else { |
|
| 1090 | - // id = 0 => creation |
|
| 1091 | - return true; |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1098 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1099 | - return false; |
|
| 1100 | - } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1101 | - // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1102 | - return false; |
|
| 1103 | - } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1104 | - // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1105 | - return false; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - return true; |
|
| 1053 | + $id = (int) $id; |
|
| 1054 | + |
|
| 1055 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1056 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1057 | + if ($qui['statut'] != '0minirezo') { |
|
| 1058 | + return $id == $qui['id_auteur'] |
|
| 1059 | + && empty($opt['statut']) |
|
| 1060 | + && empty($opt['webmestre']) |
|
| 1061 | + && empty($opt['restreintes']) |
|
| 1062 | + && empty($opt['login']); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1066 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1067 | + if ($qui['restreint']) { |
|
| 1068 | + if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1069 | + return false; |
|
| 1070 | + } elseif ( |
|
| 1071 | + isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1072 | + ) { |
|
| 1073 | + return false; |
|
| 1074 | + } else { |
|
| 1075 | + if ($id == $qui['id_auteur']) { |
|
| 1076 | + if (isset($opt['statut']) && $opt['statut']) { |
|
| 1077 | + return false; |
|
| 1078 | + } else { |
|
| 1079 | + return true; |
|
| 1080 | + } |
|
| 1081 | + } else { |
|
| 1082 | + if ($id_auteur = (int) $id) { |
|
| 1083 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1084 | + if ($t && $t['statut'] != '0minirezo') { |
|
| 1085 | + return true; |
|
| 1086 | + } else { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1089 | + } else { |
|
| 1090 | + // id = 0 => creation |
|
| 1091 | + return true; |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1098 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1099 | + return false; |
|
| 1100 | + } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1101 | + // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1102 | + return false; |
|
| 1103 | + } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1104 | + // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1105 | + return false; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + return true; |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | * @return bool true s'il a le droit, false sinon |
| 1125 | 1125 | **/ |
| 1126 | 1126 | function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1127 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1127 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
@@ -1143,7 +1143,7 @@ discard block |
||
| 1143 | 1143 | * @return bool true s'il a le droit, false sinon |
| 1144 | 1144 | **/ |
| 1145 | 1145 | function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1146 | - return $qui['statut'] === '0minirezo'; |
|
| 1146 | + return $qui['statut'] === '0minirezo'; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | * @return bool true s'il a le droit, false sinon |
| 1162 | 1162 | **/ |
| 1163 | 1163 | function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1164 | - return $qui['statut'] === '0minirezo'; |
|
| 1164 | + return $qui['statut'] === '0minirezo'; |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | /** |
@@ -1178,53 +1178,53 @@ discard block |
||
| 1178 | 1178 | * @return array Liste des rubriques |
| 1179 | 1179 | **/ |
| 1180 | 1180 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1181 | - static $restreint = []; |
|
| 1182 | - |
|
| 1183 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 1184 | - return []; |
|
| 1185 | - } |
|
| 1186 | - if ($raz) { |
|
| 1187 | - unset($restreint[$id_auteur]); |
|
| 1188 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1189 | - return $restreint[$id_auteur]; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - $rubriques = []; |
|
| 1193 | - if ( |
|
| 1194 | - (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1195 | - && ($r = sql_allfetsel( |
|
| 1196 | - 'id_objet', |
|
| 1197 | - 'spip_auteurs_liens', |
|
| 1198 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1199 | - )) |
|
| 1200 | - && (is_countable($r) ? count($r) : 0) |
|
| 1201 | - ) { |
|
| 1202 | - $r = array_column($r, 'id_objet'); |
|
| 1203 | - |
|
| 1204 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1205 | - include_spip('inc/rubriques'); |
|
| 1206 | - $r = calcul_branche_in($r); |
|
| 1207 | - $r = explode(',', (string) $r); |
|
| 1208 | - |
|
| 1209 | - // passer les rubriques en index, elimine les doublons |
|
| 1210 | - $r = array_flip($r); |
|
| 1211 | - // recuperer les index seuls |
|
| 1212 | - $r = array_keys($r); |
|
| 1213 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1214 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1215 | - $rubriques = array_combine($r, $r); |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - // Affecter l'auteur session le cas echeant |
|
| 1219 | - if ( |
|
| 1220 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1221 | - && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1222 | - ) { |
|
| 1223 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1181 | + static $restreint = []; |
|
| 1182 | + |
|
| 1183 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 1184 | + return []; |
|
| 1185 | + } |
|
| 1186 | + if ($raz) { |
|
| 1187 | + unset($restreint[$id_auteur]); |
|
| 1188 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1189 | + return $restreint[$id_auteur]; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + $rubriques = []; |
|
| 1193 | + if ( |
|
| 1194 | + (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1195 | + && ($r = sql_allfetsel( |
|
| 1196 | + 'id_objet', |
|
| 1197 | + 'spip_auteurs_liens', |
|
| 1198 | + 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1199 | + )) |
|
| 1200 | + && (is_countable($r) ? count($r) : 0) |
|
| 1201 | + ) { |
|
| 1202 | + $r = array_column($r, 'id_objet'); |
|
| 1203 | + |
|
| 1204 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1205 | + include_spip('inc/rubriques'); |
|
| 1206 | + $r = calcul_branche_in($r); |
|
| 1207 | + $r = explode(',', (string) $r); |
|
| 1208 | + |
|
| 1209 | + // passer les rubriques en index, elimine les doublons |
|
| 1210 | + $r = array_flip($r); |
|
| 1211 | + // recuperer les index seuls |
|
| 1212 | + $r = array_keys($r); |
|
| 1213 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1214 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1215 | + $rubriques = array_combine($r, $r); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + // Affecter l'auteur session le cas echeant |
|
| 1219 | + if ( |
|
| 1220 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1221 | + && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1222 | + ) { |
|
| 1223 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | * @return bool true s'il a le droit, false sinon |
| 1243 | 1243 | **/ |
| 1244 | 1244 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1245 | - return autoriser('previsualiser'); |
|
| 1245 | + return autoriser('previsualiser'); |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | /** |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | * @return bool true s'il a le droit, false sinon |
| 1261 | 1261 | **/ |
| 1262 | 1262 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1263 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1263 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | /** |
@@ -1278,8 +1278,8 @@ discard block |
||
| 1278 | 1278 | * @return bool true s'il a le droit, false sinon |
| 1279 | 1279 | **/ |
| 1280 | 1280 | function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1281 | - $id = (int) $id; |
|
| 1282 | - return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1281 | + $id = (int) $id; |
|
| 1282 | + return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | /** |
@@ -1297,8 +1297,8 @@ discard block |
||
| 1297 | 1297 | * @return bool true s'il a le droit, false sinon |
| 1298 | 1298 | **/ |
| 1299 | 1299 | function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1300 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1301 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1300 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1301 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | |
@@ -1318,7 +1318,7 @@ discard block |
||
| 1318 | 1318 | * @return true |
| 1319 | 1319 | **/ |
| 1320 | 1320 | function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1321 | - return true; |
|
| 1321 | + return true; |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | /** |
@@ -1337,7 +1337,7 @@ discard block |
||
| 1337 | 1337 | * @return false |
| 1338 | 1338 | **/ |
| 1339 | 1339 | function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1340 | - return false; |
|
| 1340 | + return false; |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | /** |
@@ -1355,7 +1355,7 @@ discard block |
||
| 1355 | 1355 | * @return bool true s'il a le droit, false sinon |
| 1356 | 1356 | **/ |
| 1357 | 1357 | function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1358 | - return autoriser('detruire') && !_request('reinstall'); |
|
| 1358 | + return autoriser('detruire') && !_request('reinstall'); |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | /** |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | * @return true |
| 1374 | 1374 | **/ |
| 1375 | 1375 | function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1376 | - return true; |
|
| 1376 | + return true; |
|
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | 1379 | /** |
@@ -1391,7 +1391,7 @@ discard block |
||
| 1391 | 1391 | * @return true |
| 1392 | 1392 | **/ |
| 1393 | 1393 | function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1394 | - return true; |
|
| 1394 | + return true; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | * @return bool true s'il a le droit, false sinon |
| 1410 | 1410 | **/ |
| 1411 | 1411 | function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1412 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1412 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | /** |
@@ -1427,7 +1427,7 @@ discard block |
||
| 1427 | 1427 | * @return true |
| 1428 | 1428 | **/ |
| 1429 | 1429 | function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1430 | - return true; |
|
| 1430 | + return true; |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | /** |
@@ -1445,7 +1445,7 @@ discard block |
||
| 1445 | 1445 | * @return bool true s'il a le droit, false sinon |
| 1446 | 1446 | **/ |
| 1447 | 1447 | function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1448 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1448 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | 1451 | /** |
@@ -1463,7 +1463,7 @@ discard block |
||
| 1463 | 1463 | * @return bool true s'il a le droit, false sinon |
| 1464 | 1464 | **/ |
| 1465 | 1465 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1466 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1466 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | /** |
@@ -1482,7 +1482,7 @@ discard block |
||
| 1482 | 1482 | * @return true |
| 1483 | 1483 | **/ |
| 1484 | 1484 | function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1485 | - return true; |
|
| 1485 | + return true; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | /** |
@@ -1500,7 +1500,7 @@ discard block |
||
| 1500 | 1500 | * @return true |
| 1501 | 1501 | **/ |
| 1502 | 1502 | function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1503 | - return true; |
|
| 1503 | + return true; |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | /** |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | * @return bool true s'il a le droit, false sinon |
| 1519 | 1519 | **/ |
| 1520 | 1520 | function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1521 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1521 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | /** |
@@ -1536,7 +1536,7 @@ discard block |
||
| 1536 | 1536 | * @return true |
| 1537 | 1537 | **/ |
| 1538 | 1538 | function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1539 | - return true; |
|
| 1539 | + return true; |
|
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | /** |
@@ -1554,7 +1554,7 @@ discard block |
||
| 1554 | 1554 | * @return bool true s'il a le droit, false sinon |
| 1555 | 1555 | **/ |
| 1556 | 1556 | function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1557 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1557 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1558 | 1558 | } |
| 1559 | 1559 | |
| 1560 | 1560 | /** |
@@ -1572,7 +1572,7 @@ discard block |
||
| 1572 | 1572 | * @return true |
| 1573 | 1573 | **/ |
| 1574 | 1574 | function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1575 | - return true; |
|
| 1575 | + return true; |
|
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | /** |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | * @return bool true s'il a le droit, false sinon |
| 1591 | 1591 | **/ |
| 1592 | 1592 | function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1593 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1593 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | 1596 | /** |
@@ -1608,7 +1608,7 @@ discard block |
||
| 1608 | 1608 | * @return bool true s'il a le droit, false sinon |
| 1609 | 1609 | **/ |
| 1610 | 1610 | function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1611 | - return verifier_table_non_vide(); |
|
| 1611 | + return verifier_table_non_vide(); |
|
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | 1614 | |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | * @return bool true s'il a le droit, false sinon |
| 1630 | 1630 | **/ |
| 1631 | 1631 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1632 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1632 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | 1635 | /** |
@@ -1647,11 +1647,11 @@ discard block |
||
| 1647 | 1647 | * @return bool true s'il a le droit, false sinon |
| 1648 | 1648 | **/ |
| 1649 | 1649 | function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1650 | - include_spip('base/abstract_sql'); |
|
| 1651 | - return |
|
| 1652 | - $qui['statut'] === '0minirezo' |
|
| 1653 | - && !$qui['restreint'] |
|
| 1654 | - && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1650 | + include_spip('base/abstract_sql'); |
|
| 1651 | + return |
|
| 1652 | + $qui['statut'] === '0minirezo' |
|
| 1653 | + && !$qui['restreint'] |
|
| 1654 | + && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | /** |
@@ -1669,7 +1669,7 @@ discard block |
||
| 1669 | 1669 | * @return bool true s'il a le droit, false sinon |
| 1670 | 1670 | **/ |
| 1671 | 1671 | function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1672 | - return $qui['statut'] === '0minirezo'; |
|
| 1672 | + return $qui['statut'] === '0minirezo'; |
|
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | /** |
@@ -1687,7 +1687,7 @@ discard block |
||
| 1687 | 1687 | * @return bool true s'il a le droit, false sinon |
| 1688 | 1688 | **/ |
| 1689 | 1689 | function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1690 | - return $qui['statut'] === '0minirezo'; |
|
| 1690 | + return $qui['statut'] === '0minirezo'; |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | /** |
@@ -1705,7 +1705,7 @@ discard block |
||
| 1705 | 1705 | * @return bool true s'il a le droit, false sinon |
| 1706 | 1706 | **/ |
| 1707 | 1707 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1708 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1708 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | /** |
@@ -1723,7 +1723,7 @@ discard block |
||
| 1723 | 1723 | * @return bool true s'il a le droit, false sinon |
| 1724 | 1724 | **/ |
| 1725 | 1725 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1726 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1726 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1727 | 1727 | } |
| 1728 | 1728 | |
| 1729 | 1729 | /** |
@@ -1741,7 +1741,7 @@ discard block |
||
| 1741 | 1741 | * @return bool true s'il a le droit, false sinon |
| 1742 | 1742 | **/ |
| 1743 | 1743 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1744 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1744 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | /** |
@@ -1759,7 +1759,7 @@ discard block |
||
| 1759 | 1759 | * @return bool true s'il a le droit, false sinon |
| 1760 | 1760 | **/ |
| 1761 | 1761 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1762 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1762 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1763 | 1763 | } |
| 1764 | 1764 | |
| 1765 | 1765 | /** |
@@ -1777,7 +1777,7 @@ discard block |
||
| 1777 | 1777 | * @return bool true s'il a le droit, false sinon |
| 1778 | 1778 | **/ |
| 1779 | 1779 | function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1780 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1780 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | /** |
@@ -1795,7 +1795,7 @@ discard block |
||
| 1795 | 1795 | * @return bool true s'il a le droit, false sinon |
| 1796 | 1796 | **/ |
| 1797 | 1797 | function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1798 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1798 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | 1801 | /** |
@@ -1813,7 +1813,7 @@ discard block |
||
| 1813 | 1813 | * @return bool true s'il a le droit, false sinon |
| 1814 | 1814 | **/ |
| 1815 | 1815 | function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1816 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1816 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1817 | 1817 | } |
| 1818 | 1818 | |
| 1819 | 1819 | /** |
@@ -1831,7 +1831,7 @@ discard block |
||
| 1831 | 1831 | * @return bool true s'il a le droit, false sinon |
| 1832 | 1832 | **/ |
| 1833 | 1833 | function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1834 | - return autoriser('webmestre'); |
|
| 1834 | + return autoriser('webmestre'); |
|
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | |
@@ -1851,11 +1851,11 @@ discard block |
||
| 1851 | 1851 | * @return bool true s'il a le droit, false sinon |
| 1852 | 1852 | **/ |
| 1853 | 1853 | function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1854 | - if (test_espace_prive()) { |
|
| 1855 | - return (bool) (int) $qui['id_auteur']; |
|
| 1856 | - } else { |
|
| 1857 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1858 | - } |
|
| 1854 | + if (test_espace_prive()) { |
|
| 1855 | + return (bool) (int) $qui['id_auteur']; |
|
| 1856 | + } else { |
|
| 1857 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1858 | + } |
|
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | |
@@ -1870,27 +1870,27 @@ discard block |
||
| 1870 | 1870 | * Identifiants d'auteurs |
| 1871 | 1871 | */ |
| 1872 | 1872 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1873 | - $objet = objet_type($objet); |
|
| 1874 | - $where = [ |
|
| 1875 | - 'objet=' . sql_quote($objet), |
|
| 1876 | - 'id_objet=' . (int) $id_objet |
|
| 1877 | - ]; |
|
| 1878 | - if (!empty($cond)) { |
|
| 1879 | - if (is_array($cond)) { |
|
| 1880 | - $where = array_merge($where, $cond); |
|
| 1881 | - } else { |
|
| 1882 | - $where[] = $cond; |
|
| 1883 | - } |
|
| 1884 | - } |
|
| 1885 | - $auteurs = sql_allfetsel( |
|
| 1886 | - 'id_auteur', |
|
| 1887 | - 'spip_auteurs_liens', |
|
| 1888 | - $where |
|
| 1889 | - ); |
|
| 1890 | - if (is_array($auteurs)) { |
|
| 1891 | - return array_column($auteurs, 'id_auteur'); |
|
| 1892 | - } |
|
| 1893 | - return []; |
|
| 1873 | + $objet = objet_type($objet); |
|
| 1874 | + $where = [ |
|
| 1875 | + 'objet=' . sql_quote($objet), |
|
| 1876 | + 'id_objet=' . (int) $id_objet |
|
| 1877 | + ]; |
|
| 1878 | + if (!empty($cond)) { |
|
| 1879 | + if (is_array($cond)) { |
|
| 1880 | + $where = array_merge($where, $cond); |
|
| 1881 | + } else { |
|
| 1882 | + $where[] = $cond; |
|
| 1883 | + } |
|
| 1884 | + } |
|
| 1885 | + $auteurs = sql_allfetsel( |
|
| 1886 | + 'id_auteur', |
|
| 1887 | + 'spip_auteurs_liens', |
|
| 1888 | + $where |
|
| 1889 | + ); |
|
| 1890 | + if (is_array($auteurs)) { |
|
| 1891 | + return array_column($auteurs, 'id_auteur'); |
|
| 1892 | + } |
|
| 1893 | + return []; |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | /** |
@@ -1903,7 +1903,7 @@ discard block |
||
| 1903 | 1903 | */ |
| 1904 | 1904 | function acces_restreint_rubrique($id_rubrique) { |
| 1905 | 1905 | |
| 1906 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1906 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | 1909 | |
@@ -1916,12 +1916,12 @@ discard block |
||
| 1916 | 1916 | * @return bool true si un parent existe |
| 1917 | 1917 | */ |
| 1918 | 1918 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1919 | - static $done = []; |
|
| 1920 | - if (!isset($done[$table])) { |
|
| 1921 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1922 | - } |
|
| 1919 | + static $done = []; |
|
| 1920 | + if (!isset($done[$table])) { |
|
| 1921 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1922 | + } |
|
| 1923 | 1923 | |
| 1924 | - return $done[$table]; |
|
| 1924 | + return $done[$table]; |
|
| 1925 | 1925 | } |
| 1926 | 1926 | |
| 1927 | 1927 | /** |
@@ -1948,12 +1948,12 @@ discard block |
||
| 1948 | 1948 | */ |
| 1949 | 1949 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1950 | 1950 | |
| 1951 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1952 | - return match ($s) { |
|
| 1953 | - 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1954 | - 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1955 | - default => false, |
|
| 1956 | - }; |
|
| 1951 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1952 | + return match ($s) { |
|
| 1953 | + 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1954 | + 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1955 | + default => false, |
|
| 1956 | + }; |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | /** |
@@ -1971,7 +1971,7 @@ discard block |
||
| 1971 | 1971 | * @return bool true s'il a le droit, false sinon |
| 1972 | 1972 | **/ |
| 1973 | 1973 | function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1974 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1974 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | 1977 | /** |
@@ -1989,5 +1989,5 @@ discard block |
||
| 1989 | 1989 | * @return bool true s'il a le droit, false sinon |
| 1990 | 1990 | **/ |
| 1991 | 1991 | function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1992 | - return autoriser('webmestre'); |
|
| 1992 | + return autoriser('webmestre'); |
|
| 1993 | 1993 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | 121 | global $dossier_squelettes; |
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 122 | + include_once(_ROOT_CWD.$f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $qui = $GLOBALS['visiteur_session'] ?: []; |
| 161 | 161 | $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
| 162 | 162 | } elseif (is_numeric($qui)) { |
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 164 | 164 | if (!$qui) { |
| 165 | 165 | return false; |
| 166 | 166 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $logger = spip_logger('autoriser'); |
| 176 | 176 | $logger->debug( |
| 177 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | + "autoriser $faire $type $id (".($qui['nom'] ?? '').') ?', |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | $type = autoriser_type($type); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
| 185 | 185 | && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
| 186 | 186 | ) { |
| 187 | - $logger->debug("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception'); |
|
| 187 | + $logger->debug("autoriser ($faire, $type, $id, ".($qui['nom'] ?? '').') : OK Exception'); |
|
| 188 | 188 | return true; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -193,18 +193,18 @@ discard block |
||
| 193 | 193 | // autoriser_faire[_dist], autoriser_defaut[_dist] |
| 194 | 194 | $fonctions = $type |
| 195 | 195 | ? [ |
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 196 | + 'autoriser_'.$type.'_'.$faire, |
|
| 197 | + 'autoriser_'.$type.'_'.$faire.'_dist', |
|
| 198 | + 'autoriser_'.$type, |
|
| 199 | + 'autoriser_'.$type.'_dist', |
|
| 200 | + 'autoriser_'.$faire, |
|
| 201 | + 'autoriser_'.$faire.'_dist', |
|
| 202 | 202 | 'autoriser_defaut', |
| 203 | 203 | 'autoriser_defaut_dist' |
| 204 | 204 | ] |
| 205 | 205 | : [ |
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 206 | + 'autoriser_'.$faire, |
|
| 207 | + 'autoriser_'.$faire.'_dist', |
|
| 208 | 208 | 'autoriser_defaut', |
| 209 | 209 | 'autoriser_defaut_dist' |
| 210 | 210 | ]; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | $logger->debug( |
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 221 | + "$f($faire, $type, $id, ".($qui['nom'] ?? '').') : '.($a ? 'OK' : 'niet'), |
|
| 222 | 222 | ); |
| 223 | 223 | |
| 224 | 224 | if (!is_bool($a)) { |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 385 | 385 | |
| 386 | 386 | // Le visiteur a-t-il un statut prevu par la config ? |
| 387 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 387 | + if (str_contains((string) $GLOBALS['meta']['preview'], ','.$qui['statut'].',')) { |
|
| 388 | 388 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | } // pas de champ passe a la demande => NIET |
| 439 | 439 | $previsu = explode(',', (string) $c['previsu']); |
| 440 | 440 | // regarder si ce statut est autorise pour l'auteur |
| 441 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 441 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 442 | 442 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 443 | 443 | // sinon l’auteur en session |
| 444 | 444 | include_spip('inc/securiser_action'); |
@@ -452,12 +452,12 @@ discard block |
||
| 452 | 452 | |
| 453 | 453 | if (!$id_auteur) { |
| 454 | 454 | return false; |
| 455 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 455 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) { |
|
| 456 | 456 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 457 | 457 | } elseif ( |
| 458 | 458 | !sql_countsel( |
| 459 | 459 | 'spip_auteurs_liens', |
| 460 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 460 | + 'id_auteur='.(int) $id_auteur.' AND objet='.sql_quote($type).' AND id_objet='.(int) $id |
|
| 461 | 461 | ) |
| 462 | 462 | ) { |
| 463 | 463 | return false; |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 503 | 503 | $primary = id_table_objet($type); |
| 504 | 504 | $id_rubrique = $table != 'spip_rubriques' |
| 505 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 505 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=".(int) $id) |
|
| 506 | 506 | : $id; |
| 507 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 507 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 508 | 508 | if (!$id_secteur > 0) { |
| 509 | 509 | $id_secteur = $id_rubrique; |
| 510 | 510 | } |
| 511 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 512 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 511 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.(int) $id_secteur); |
|
| 512 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".(int) $id); |
|
| 513 | 513 | if ($langue_secteur != $langue_objet) { |
| 514 | 514 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 515 | 515 | return true; |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 518 | 518 | return false; |
| 519 | 519 | } else { |
| 520 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 520 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id); |
|
| 521 | 521 | if ($id_parent != 0) { |
| 522 | 522 | // sous-rubriques : pas de choix de langue |
| 523 | 523 | return false; |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | |
| 570 | 570 | if (!isset($opt['statut'])) { |
| 571 | 571 | if (isset($desc['field']['statut'])) { |
| 572 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 572 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.(int) $id); |
|
| 573 | 573 | } else { |
| 574 | 574 | $statut = 'publie'; |
| 575 | 575 | } // pas de statut => publie |
@@ -734,11 +734,11 @@ discard block |
||
| 734 | 734 | return false; |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 737 | + if (sql_countsel('spip_rubriques', 'id_parent='.(int) $id)) { |
|
| 738 | 738 | return false; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 741 | + if (sql_countsel('spip_articles', 'id_rubrique='.(int) $id." AND (statut<>'poubelle')")) { |
|
| 742 | 742 | return false; |
| 743 | 743 | } |
| 744 | 744 | |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | if (!$id) { |
| 776 | 776 | return false; |
| 777 | 777 | } |
| 778 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 778 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 779 | 779 | |
| 780 | 780 | return $r && ( |
| 781 | 781 | autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
| 784 | 784 | && in_array($qui['statut'], ['0minirezo', '1comite']) |
| 785 | 785 | && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
| 786 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 786 | + && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 787 | 787 | ) |
| 788 | 788 | ); |
| 789 | 789 | } |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | if (!$id) { |
| 842 | 842 | return false; |
| 843 | 843 | } |
| 844 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 844 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.(int) $id); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | return |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | in_array($statut, ['prop', 'publie']) |
| 851 | 851 | // sinon si on est auteur, on a le droit de le voir, evidemment ! |
| 852 | 852 | |
| 853 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 853 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | |
@@ -871,8 +871,8 @@ discard block |
||
| 871 | 871 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 872 | 872 | # securite, mais on aurait pas du arriver ici ! |
| 873 | 873 | if ( |
| 874 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 875 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 874 | + function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 875 | + || function_exists($f = 'autoriser_'.$type.'_voir_dist') |
|
| 876 | 876 | ) { |
| 877 | 877 | return $f($faire, $type, $id, $qui, $opt); |
| 878 | 878 | } |
@@ -997,7 +997,7 @@ discard block |
||
| 997 | 997 | $n = sql_fetsel( |
| 998 | 998 | 'A.id_article', |
| 999 | 999 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 1000 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1000 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 1001 | 1001 | ); |
| 1002 | 1002 | |
| 1003 | 1003 | return (bool) $n; |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | && ($r = sql_allfetsel( |
| 1196 | 1196 | 'id_objet', |
| 1197 | 1197 | 'spip_auteurs_liens', |
| 1198 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1198 | + 'id_auteur='.(int) $id_auteur." AND objet='rubrique' AND id_objet!=0" |
|
| 1199 | 1199 | )) |
| 1200 | 1200 | && (is_countable($r) ? count($r) : 0) |
| 1201 | 1201 | ) { |
@@ -1872,8 +1872,8 @@ discard block |
||
| 1872 | 1872 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1873 | 1873 | $objet = objet_type($objet); |
| 1874 | 1874 | $where = [ |
| 1875 | - 'objet=' . sql_quote($objet), |
|
| 1876 | - 'id_objet=' . (int) $id_objet |
|
| 1875 | + 'objet='.sql_quote($objet), |
|
| 1876 | + 'id_objet='.(int) $id_objet |
|
| 1877 | 1877 | ]; |
| 1878 | 1878 | if (!empty($cond)) { |
| 1879 | 1879 | if (is_array($cond)) { |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $class = ' blocreplie'; |
| 53 | 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() { |
@@ -63,12 +63,12 @@ discard block |
||
| 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); |
|
| 66 | + $bouton_id = 'b'.substr(md5($texte.microtime()), 0, 8); |
|
| 67 | 67 | |
| 68 | 68 | $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
| 69 | 69 | if (strlen((string) $ids)) { |
| 70 | 70 | $cible = explode(',', (string) $ids); |
| 71 | - $cible = '#' . implode(',#', $cible); |
|
| 71 | + $cible = '#'.implode(',#', $cible); |
|
| 72 | 72 | } else { |
| 73 | 73 | $cible = "#$bouton_id + div.bloc_depliable"; |
| 74 | 74 | } |
@@ -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,68 +25,68 @@ 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); |
|
| 28 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 29 | 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(); |
|
| 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); |
|
| 66 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 67 | 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 | - } |
|
| 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 | 75 | |
| 76 | - $b = (str_contains((string) $texte, '<h') ? 'div' : 'h3'); |
|
| 76 | + $b = (str_contains((string) $texte, '<h') ? 'div' : 'h3'); |
|
| 77 | 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 | - : ''); |
|
| 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 | } |
@@ -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 | /** |
@@ -37,70 +37,70 @@ discard block |
||
| 37 | 37 | * @return array|string |
| 38 | 38 | */ |
| 39 | 39 | function inc_couleurs_dist($choix = null, $ajouter = false) { |
| 40 | - static $couleurs_spip = [ |
|
| 41 | - // Violet soutenu |
|
| 42 | - 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | - // Violet rosé |
|
| 44 | - 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | - // Rose interface SPIP |
|
| 46 | - 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | - // Rouge |
|
| 48 | - 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | - // Orange |
|
| 50 | - 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | - // Vert SPIP |
|
| 52 | - 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | - // Vert Troglo |
|
| 54 | - 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | - // Bleu-vert |
|
| 56 | - 12 => ['couleur_theme' => '#269681'], |
|
| 57 | - // Bleu pastel |
|
| 58 | - 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | - // Bleu Kermesse |
|
| 60 | - 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | - // Gris bleuté |
|
| 62 | - 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | - // Gris |
|
| 64 | - 10 => ['couleur_theme' => '#909090'], |
|
| 65 | - ]; |
|
| 40 | + static $couleurs_spip = [ |
|
| 41 | + // Violet soutenu |
|
| 42 | + 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | + // Violet rosé |
|
| 44 | + 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | + // Rose interface SPIP |
|
| 46 | + 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | + // Rouge |
|
| 48 | + 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | + // Orange |
|
| 50 | + 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | + // Vert SPIP |
|
| 52 | + 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | + // Vert Troglo |
|
| 54 | + 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | + // Bleu-vert |
|
| 56 | + 12 => ['couleur_theme' => '#269681'], |
|
| 57 | + // Bleu pastel |
|
| 58 | + 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | + // Bleu Kermesse |
|
| 60 | + 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | + // Gris bleuté |
|
| 62 | + 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | + // Gris |
|
| 64 | + 10 => ['couleur_theme' => '#909090'], |
|
| 65 | + ]; |
|
| 66 | 66 | |
| 67 | - if (is_numeric($choix)) { |
|
| 68 | - $c = $couleurs_spip[$choix]; |
|
| 69 | - // compat < SPIP 3.3 |
|
| 70 | - include_spip('inc/filtres_images_mini'); |
|
| 71 | - $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 67 | + if (is_numeric($choix)) { |
|
| 68 | + $c = $couleurs_spip[$choix]; |
|
| 69 | + // compat < SPIP 3.3 |
|
| 70 | + include_spip('inc/filtres_images_mini'); |
|
| 71 | + $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | + $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | 73 | |
| 74 | - return |
|
| 75 | - 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | - // compat < SPIP 3.3 |
|
| 77 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | - . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | - } else { |
|
| 80 | - if (is_array($choix)) { |
|
| 81 | - // compat < SPIP 3.3 |
|
| 82 | - $compat_spip_33 = function ($c) { |
|
| 83 | - if (!isset($c['couleur_theme'])) { |
|
| 84 | - $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | - unset($c['couleur_foncee']); |
|
| 86 | - unset($c['couleur_claire']); |
|
| 87 | - unset($c['couleur_lien']); |
|
| 88 | - unset($c['couleur_lien_off']); |
|
| 89 | - } |
|
| 90 | - return $c; |
|
| 91 | - }; |
|
| 92 | - if ($ajouter) { |
|
| 93 | - foreach ($choix as $c) { |
|
| 94 | - $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | - } |
|
| 74 | + return |
|
| 75 | + 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | + // compat < SPIP 3.3 |
|
| 77 | + . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | + . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | + } else { |
|
| 80 | + if (is_array($choix)) { |
|
| 81 | + // compat < SPIP 3.3 |
|
| 82 | + $compat_spip_33 = function ($c) { |
|
| 83 | + if (!isset($c['couleur_theme'])) { |
|
| 84 | + $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | + unset($c['couleur_foncee']); |
|
| 86 | + unset($c['couleur_claire']); |
|
| 87 | + unset($c['couleur_lien']); |
|
| 88 | + unset($c['couleur_lien_off']); |
|
| 89 | + } |
|
| 90 | + return $c; |
|
| 91 | + }; |
|
| 92 | + if ($ajouter) { |
|
| 93 | + foreach ($choix as $c) { |
|
| 94 | + $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $couleurs_spip; |
|
| 98 | - } else { |
|
| 99 | - $choix = array_map($compat_spip_33, $choix); |
|
| 100 | - return $couleurs_spip = $choix; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 97 | + return $couleurs_spip; |
|
| 98 | + } else { |
|
| 99 | + $choix = array_map($compat_spip_33, $choix); |
|
| 100 | + return $couleurs_spip = $choix; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $couleurs_spip; |
|
| 105 | + return $couleurs_spip; |
|
| 106 | 106 | } |
@@ -69,17 +69,17 @@ |
||
| 69 | 69 | // compat < SPIP 3.3 |
| 70 | 70 | include_spip('inc/filtres_images_mini'); |
| 71 | 71 | $c['couleur_foncee'] = $c['couleur_theme']; |
| 72 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 72 | + $c['couleur_claire'] = '#'.couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | 73 | |
| 74 | 74 | return |
| 75 | - 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 75 | + 'couleur_theme='.substr((string) $c['couleur_theme'], 1) |
|
| 76 | 76 | // compat < SPIP 3.3 |
| 77 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | - . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 77 | + . '&couleur_claire='.substr($c['couleur_claire'], 1) |
|
| 78 | + . '&couleur_foncee='.substr((string) $c['couleur_foncee'], 1); |
|
| 79 | 79 | } else { |
| 80 | 80 | if (is_array($choix)) { |
| 81 | 81 | // compat < SPIP 3.3 |
| 82 | - $compat_spip_33 = function ($c) { |
|
| 82 | + $compat_spip_33 = function($c) { |
|
| 83 | 83 | if (!isset($c['couleur_theme'])) { |
| 84 | 84 | $c['couleur_theme'] = $c['couleur_foncee']; |
| 85 | 85 | unset($c['couleur_foncee']); |