@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,25 +157,25 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 160 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 161 | 161 | |
| 162 | - $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | - $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | - $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 162 | + $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | + $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | + $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 166 | 166 | |
| 167 | - $display_class = [ |
|
| 168 | - 0 => 'icones_img_texte' |
|
| 169 | - /*init*/, |
|
| 170 | - 1 => 'icones_texte', |
|
| 171 | - 2 => 'icones_img_texte', |
|
| 172 | - 3 => 'icones_img' |
|
| 173 | - ]; |
|
| 167 | + $display_class = [ |
|
| 168 | + 0 => 'icones_img_texte' |
|
| 169 | + /*init*/, |
|
| 170 | + 1 => 'icones_texte', |
|
| 171 | + 2 => 'icones_img_texte', |
|
| 172 | + 3 => 'icones_img' |
|
| 173 | + ]; |
|
| 174 | 174 | |
| 175 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 175 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | - return spip_sanitize_classname($classes); |
|
| 177 | + $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | + return spip_sanitize_classname($classes); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -186,5 +186,5 @@ discard block |
||
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | 188 | function auteurs_recemment_connectes($id_auteur) { |
| 189 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 189 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 190 | 190 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $couleur = intval($prefs['couleur'] ?? 2); |
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 177 | + $classes = $GLOBALS['spip_ecran']." spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils ".$display_class[$GLOBALS['spip_display']]; |
|
| 178 | 178 | return spip_sanitize_classname($classes); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -257,8 +257,7 @@ discard block |
||
| 257 | 257 | if ($id === '*') { |
| 258 | 258 | unset($GLOBALS['autoriser_exception'][$faire][$type]); |
| 259 | 259 | unset($autorisation[$faire][$type]); |
| 260 | - } |
|
| 261 | - else { |
|
| 260 | + } else { |
|
| 262 | 261 | unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
| 263 | 262 | unset($autorisation[$faire][$type][$id]); |
| 264 | 263 | } |
@@ -617,8 +616,7 @@ discard block |
||
| 617 | 616 | function autoriser_rubrique_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 618 | 617 | if (!empty($opt['id_parent'])) { |
| 619 | 618 | return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
| 620 | - } |
|
| 621 | - else { |
|
| 619 | + } else { |
|
| 622 | 620 | return autoriser('defaut', null, null, $qui, $opt); |
| 623 | 621 | } |
| 624 | 622 | } |
@@ -767,8 +765,7 @@ discard block |
||
| 767 | 765 | if (!empty($opt['id_parent'])) { |
| 768 | 766 | // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
| 769 | 767 | return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
| 770 | - } |
|
| 771 | - else { |
|
| 768 | + } else { |
|
| 772 | 769 | return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
| 773 | 770 | } |
| 774 | 771 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Autorisations |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/abstract_sql'); |
@@ -38,84 +38,84 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | if (!function_exists('autoriser')) { |
| 41 | - /** |
|
| 42 | - * Autoriser une action |
|
| 43 | - * |
|
| 44 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | - * les autorisations. |
|
| 47 | - * |
|
| 48 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | - * dans cet ordre : |
|
| 51 | - * |
|
| 52 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | - * - autoriser_{type}, sinon avec _dist |
|
| 54 | - * - autoriser_{faire}, sinon avec _dist |
|
| 55 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | - * |
|
| 57 | - * Seul le premier argument est obligatoire. |
|
| 58 | - * |
|
| 59 | - * @note |
|
| 60 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | - * cette valeur. |
|
| 63 | - * |
|
| 64 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | - * |
|
| 69 | - * @note |
|
| 70 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | - * quel serait le type, quel serait l'action ? |
|
| 75 | - * |
|
| 76 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | - * |
|
| 80 | - * @api |
|
| 81 | - * @see autoriser_dist() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param ?string $type |
|
| 86 | - * type d'objet ou nom de table ('article') |
|
| 87 | - * @param int $id |
|
| 88 | - * id de l'objet sur lequel on veut agir |
|
| 89 | - * Casté en int si différent. |
|
| 90 | - * @param null|int|array $qui |
|
| 91 | - * - si null on prend alors visiteur_session |
|
| 92 | - * - un id_auteur (on regarde dans la base) |
|
| 93 | - * - un tableau auteur complet, y compris [restreint] |
|
| 94 | - * @param array $opt |
|
| 95 | - * options sous forme de tableau associatif |
|
| 96 | - * @return bool |
|
| 97 | - * true si la personne peut effectuer l'action |
|
| 98 | - */ |
|
| 99 | - function autoriser(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
|
| 100 | - // Charger les fonctions d'autorisation supplementaires |
|
| 101 | - static $pipe; |
|
| 102 | - if (!isset($pipe)) { |
|
| 103 | - $pipe = 1; |
|
| 104 | - pipeline('autoriser'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $args = func_get_args(); |
|
| 108 | - |
|
| 109 | - return call_user_func_array('autoriser_dist', $args); |
|
| 110 | - } |
|
| 41 | + /** |
|
| 42 | + * Autoriser une action |
|
| 43 | + * |
|
| 44 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | + * les autorisations. |
|
| 47 | + * |
|
| 48 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | + * dans cet ordre : |
|
| 51 | + * |
|
| 52 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | + * - autoriser_{type}, sinon avec _dist |
|
| 54 | + * - autoriser_{faire}, sinon avec _dist |
|
| 55 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | + * |
|
| 57 | + * Seul le premier argument est obligatoire. |
|
| 58 | + * |
|
| 59 | + * @note |
|
| 60 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | + * cette valeur. |
|
| 63 | + * |
|
| 64 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | + * |
|
| 69 | + * @note |
|
| 70 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | + * quel serait le type, quel serait l'action ? |
|
| 75 | + * |
|
| 76 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | + * |
|
| 80 | + * @api |
|
| 81 | + * @see autoriser_dist() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param ?string $type |
|
| 86 | + * type d'objet ou nom de table ('article') |
|
| 87 | + * @param int $id |
|
| 88 | + * id de l'objet sur lequel on veut agir |
|
| 89 | + * Casté en int si différent. |
|
| 90 | + * @param null|int|array $qui |
|
| 91 | + * - si null on prend alors visiteur_session |
|
| 92 | + * - un id_auteur (on regarde dans la base) |
|
| 93 | + * - un tableau auteur complet, y compris [restreint] |
|
| 94 | + * @param array $opt |
|
| 95 | + * options sous forme de tableau associatif |
|
| 96 | + * @return bool |
|
| 97 | + * true si la personne peut effectuer l'action |
|
| 98 | + */ |
|
| 99 | + function autoriser(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
|
| 100 | + // Charger les fonctions d'autorisation supplementaires |
|
| 101 | + static $pipe; |
|
| 102 | + if (!isset($pipe)) { |
|
| 103 | + $pipe = 1; |
|
| 104 | + pipeline('autoriser'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $args = func_get_args(); |
|
| 108 | + |
|
| 109 | + return call_user_func_array('autoriser_dist', $args); |
|
| 110 | + } |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 115 | 115 | // mais apres la fonction autoriser() |
| 116 | 116 | if ($f = find_in_path('mes_fonctions.php')) { |
| 117 | - global $dossier_squelettes; |
|
| 118 | - include_once(_ROOT_CWD . $f); |
|
| 117 | + global $dossier_squelettes; |
|
| 118 | + include_once(_ROOT_CWD . $f); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -144,84 +144,84 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function autoriser_dist(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
| 146 | 146 | |
| 147 | - $a = null; |
|
| 148 | - // Tolérance avec certains appels de $id (null, '', 'new', 'oui'). |
|
| 149 | - $id = (int) $id; |
|
| 150 | - if ($type === null) { |
|
| 151 | - $type = ''; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Qui ? visiteur_session ? |
|
| 155 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 156 | - if ($qui === null or $qui === '') { |
|
| 157 | - $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 158 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 159 | - } elseif (is_numeric($qui)) { |
|
| 160 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 164 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 165 | - if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 166 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - spip_log( |
|
| 170 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 171 | - 'autoriser' . _LOG_DEBUG |
|
| 172 | - ); |
|
| 173 | - |
|
| 174 | - // passer par objet_type pour avoir les alias |
|
| 175 | - // sauf si _ est le premier caractère. |
|
| 176 | - if ($type and $type[0] !== '_') { |
|
| 177 | - $type = objet_type($type, false); |
|
| 178 | - } |
|
| 179 | - // et supprimer les _ |
|
| 180 | - $type = str_replace('_', '', (string) $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]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 185 | - or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 186 | - ) { |
|
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 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 | - foreach ($fonctions as $f) { |
|
| 213 | - if (function_exists($f)) { |
|
| 214 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 215 | - break; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - spip_log( |
|
| 220 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 221 | - 'autoriser' . _LOG_DEBUG |
|
| 222 | - ); |
|
| 223 | - |
|
| 224 | - return $a; |
|
| 147 | + $a = null; |
|
| 148 | + // Tolérance avec certains appels de $id (null, '', 'new', 'oui'). |
|
| 149 | + $id = (int) $id; |
|
| 150 | + if ($type === null) { |
|
| 151 | + $type = ''; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Qui ? visiteur_session ? |
|
| 155 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 156 | + if ($qui === null or $qui === '') { |
|
| 157 | + $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 158 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 159 | + } elseif (is_numeric($qui)) { |
|
| 160 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 164 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 165 | + if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 166 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + spip_log( |
|
| 170 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 171 | + 'autoriser' . _LOG_DEBUG |
|
| 172 | + ); |
|
| 173 | + |
|
| 174 | + // passer par objet_type pour avoir les alias |
|
| 175 | + // sauf si _ est le premier caractère. |
|
| 176 | + if ($type and $type[0] !== '_') { |
|
| 177 | + $type = objet_type($type, false); |
|
| 178 | + } |
|
| 179 | + // et supprimer les _ |
|
| 180 | + $type = str_replace('_', '', (string) $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]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 185 | + or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 186 | + ) { |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 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 | + foreach ($fonctions as $f) { |
|
| 213 | + if (function_exists($f)) { |
|
| 214 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 215 | + break; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + spip_log( |
|
| 220 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 221 | + 'autoriser' . _LOG_DEBUG |
|
| 222 | + ); |
|
| 223 | + |
|
| 224 | + return $a; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -239,33 +239,33 @@ discard block |
||
| 239 | 239 | * @return bool |
| 240 | 240 | */ |
| 241 | 241 | function autoriser_exception(string $faire, ?string $type = '', $id = 0, bool $autoriser = true): bool { |
| 242 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 243 | - static $autorisation; |
|
| 244 | - // Tolérance avec certains appels |
|
| 245 | - if ($type === null) { |
|
| 246 | - $type = ''; |
|
| 247 | - } |
|
| 248 | - if ($id === null) { |
|
| 249 | - $id = 0; |
|
| 250 | - } |
|
| 251 | - if ($autoriser === 'verifier') { |
|
| 252 | - return isset($autorisation[$faire][$type][$id]); |
|
| 253 | - } |
|
| 254 | - if ($autoriser === true) { |
|
| 255 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 256 | - } |
|
| 257 | - if ($autoriser === false) { |
|
| 258 | - if ($id === '*') { |
|
| 259 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 260 | - unset($autorisation[$faire][$type]); |
|
| 261 | - } |
|
| 262 | - else { |
|
| 263 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 264 | - unset($autorisation[$faire][$type][$id]); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return false; |
|
| 242 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 243 | + static $autorisation; |
|
| 244 | + // Tolérance avec certains appels |
|
| 245 | + if ($type === null) { |
|
| 246 | + $type = ''; |
|
| 247 | + } |
|
| 248 | + if ($id === null) { |
|
| 249 | + $id = 0; |
|
| 250 | + } |
|
| 251 | + if ($autoriser === 'verifier') { |
|
| 252 | + return isset($autorisation[$faire][$type][$id]); |
|
| 253 | + } |
|
| 254 | + if ($autoriser === true) { |
|
| 255 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 256 | + } |
|
| 257 | + if ($autoriser === false) { |
|
| 258 | + if ($id === '*') { |
|
| 259 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 260 | + unset($autorisation[$faire][$type]); |
|
| 261 | + } |
|
| 262 | + else { |
|
| 263 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 264 | + unset($autorisation[$faire][$type][$id]); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return false; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | * @return bool true s'il a le droit, false sinon |
| 283 | 283 | **/ |
| 284 | 284 | function autoriser_defaut_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 285 | - return |
|
| 286 | - $qui['statut'] == '0minirezo' |
|
| 287 | - and !$qui['restreint']; |
|
| 285 | + return |
|
| 286 | + $qui['statut'] == '0minirezo' |
|
| 287 | + and !$qui['restreint']; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | * @return bool |
| 301 | 301 | */ |
| 302 | 302 | function autoriser_loger_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 303 | - if ($qui['statut'] == '5poubelle') { |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - return true; |
|
| 303 | + if ($qui['statut'] == '5poubelle') { |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + return true; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return bool true s'il a le droit, false sinon |
| 318 | 318 | **/ |
| 319 | 319 | function autoriser_ecrire_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 320 | - return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 320 | + return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | * @return bool true s'il a le droit, false sinon |
| 335 | 335 | **/ |
| 336 | 336 | function autoriser_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 337 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 337 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -352,18 +352,18 @@ discard block |
||
| 352 | 352 | **/ |
| 353 | 353 | function autoriser_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 354 | 354 | |
| 355 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 356 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 357 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 358 | - } |
|
| 355 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 356 | + if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 357 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - // A-t-on un token de prévisualisation valable ? |
|
| 361 | - include_spip('inc/securiser_action'); |
|
| 362 | - if (decrire_token_previsu()) { |
|
| 363 | - return true; |
|
| 364 | - } |
|
| 360 | + // A-t-on un token de prévisualisation valable ? |
|
| 361 | + include_spip('inc/securiser_action'); |
|
| 362 | + if (decrire_token_previsu()) { |
|
| 363 | + return true; |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - return false; |
|
| 366 | + return false; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -391,58 +391,58 @@ discard block |
||
| 391 | 391 | */ |
| 392 | 392 | function test_previsualiser_objet_champ(string $type = '', int $id = 0, array $qui = [], array $opt = []): bool { |
| 393 | 393 | |
| 394 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 395 | - if (!$type) { |
|
| 396 | - return true; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - include_spip('base/objets'); |
|
| 400 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 401 | - if (isset($infos['statut'])) { |
|
| 402 | - foreach ($infos['statut'] as $c) { |
|
| 403 | - if (isset($c['publie'])) { |
|
| 404 | - if (!isset($c['previsu'])) { |
|
| 405 | - return false; |
|
| 406 | - } // pas de previsu definie => NIET |
|
| 407 | - $champ = $c['champ']; |
|
| 408 | - if (!isset($opt[$champ])) { |
|
| 409 | - return false; |
|
| 410 | - } // pas de champ passe a la demande => NIET |
|
| 411 | - $previsu = explode(',', $c['previsu']); |
|
| 412 | - // regarder si ce statut est autorise pour l'auteur |
|
| 413 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 414 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 415 | - // sinon l’auteur en session |
|
| 416 | - include_spip('inc/securiser_action'); |
|
| 417 | - if ($desc = decrire_token_previsu()) { |
|
| 418 | - $id_auteur = $desc['id_auteur']; |
|
| 419 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 420 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 421 | - } else { |
|
| 422 | - $id_auteur = null; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (!$id_auteur) { |
|
| 426 | - return false; |
|
| 427 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 428 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 429 | - } elseif ( |
|
| 430 | - !sql_countsel( |
|
| 431 | - 'spip_auteurs_liens', |
|
| 432 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 433 | - ) |
|
| 434 | - ) { |
|
| 435 | - return false; |
|
| 436 | - } // pas auteur de cet objet => NIET |
|
| 437 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 438 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 439 | - return false; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - return true; |
|
| 394 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 395 | + if (!$type) { |
|
| 396 | + return true; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + include_spip('base/objets'); |
|
| 400 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 401 | + if (isset($infos['statut'])) { |
|
| 402 | + foreach ($infos['statut'] as $c) { |
|
| 403 | + if (isset($c['publie'])) { |
|
| 404 | + if (!isset($c['previsu'])) { |
|
| 405 | + return false; |
|
| 406 | + } // pas de previsu definie => NIET |
|
| 407 | + $champ = $c['champ']; |
|
| 408 | + if (!isset($opt[$champ])) { |
|
| 409 | + return false; |
|
| 410 | + } // pas de champ passe a la demande => NIET |
|
| 411 | + $previsu = explode(',', $c['previsu']); |
|
| 412 | + // regarder si ce statut est autorise pour l'auteur |
|
| 413 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 414 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 415 | + // sinon l’auteur en session |
|
| 416 | + include_spip('inc/securiser_action'); |
|
| 417 | + if ($desc = decrire_token_previsu()) { |
|
| 418 | + $id_auteur = $desc['id_auteur']; |
|
| 419 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 420 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 421 | + } else { |
|
| 422 | + $id_auteur = null; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (!$id_auteur) { |
|
| 426 | + return false; |
|
| 427 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 428 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 429 | + } elseif ( |
|
| 430 | + !sql_countsel( |
|
| 431 | + 'spip_auteurs_liens', |
|
| 432 | + 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 433 | + ) |
|
| 434 | + ) { |
|
| 435 | + return false; |
|
| 436 | + } // pas auteur de cet objet => NIET |
|
| 437 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 438 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 439 | + return false; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + return true; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
@@ -456,51 +456,51 @@ discard block |
||
| 456 | 456 | * @return bool true s'il a le droit, false sinon |
| 457 | 457 | **/ |
| 458 | 458 | function autoriser_changerlangue_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 459 | - $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 460 | - $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 461 | - $table = table_objet_sql($type); |
|
| 462 | - if ( |
|
| 463 | - in_array($table, $multi_objets) |
|
| 464 | - or in_array($table, $gerer_trad_objets) |
|
| 465 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 466 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 467 | - $champs = objet_info($type, 'field'); |
|
| 468 | - if ( |
|
| 469 | - $multi_secteurs == 'oui' |
|
| 470 | - and array_key_exists('id_rubrique', $champs) |
|
| 471 | - ) { |
|
| 472 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 473 | - $primary = id_table_objet($type); |
|
| 474 | - if ($table != 'spip_rubriques') { |
|
| 475 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 476 | - } else { |
|
| 477 | - $id_rubrique = $id; |
|
| 478 | - } |
|
| 479 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 480 | - if (!$id_secteur > 0) { |
|
| 481 | - $id_secteur = $id_rubrique; |
|
| 482 | - } |
|
| 483 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 484 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 485 | - if ($langue_secteur != $langue_objet) { |
|
| 486 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 487 | - return true; |
|
| 488 | - } |
|
| 489 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 490 | - return false; |
|
| 491 | - } else { |
|
| 492 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 493 | - if ($id_parent != 0) { |
|
| 494 | - // sous-rubriques : pas de choix de langue |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } else { |
|
| 500 | - return false; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 459 | + $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 460 | + $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 461 | + $table = table_objet_sql($type); |
|
| 462 | + if ( |
|
| 463 | + in_array($table, $multi_objets) |
|
| 464 | + or in_array($table, $gerer_trad_objets) |
|
| 465 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 466 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 467 | + $champs = objet_info($type, 'field'); |
|
| 468 | + if ( |
|
| 469 | + $multi_secteurs == 'oui' |
|
| 470 | + and array_key_exists('id_rubrique', $champs) |
|
| 471 | + ) { |
|
| 472 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 473 | + $primary = id_table_objet($type); |
|
| 474 | + if ($table != 'spip_rubriques') { |
|
| 475 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 476 | + } else { |
|
| 477 | + $id_rubrique = $id; |
|
| 478 | + } |
|
| 479 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 480 | + if (!$id_secteur > 0) { |
|
| 481 | + $id_secteur = $id_rubrique; |
|
| 482 | + } |
|
| 483 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 484 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 485 | + if ($langue_secteur != $langue_objet) { |
|
| 486 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 487 | + return true; |
|
| 488 | + } |
|
| 489 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 490 | + return false; |
|
| 491 | + } else { |
|
| 492 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 493 | + if ($id_parent != 0) { |
|
| 494 | + // sous-rubriques : pas de choix de langue |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } else { |
|
| 500 | + return false; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | * @return bool true s'il a le droit, false sinon |
| 515 | 515 | **/ |
| 516 | 516 | function autoriser_changertraduction_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 517 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 517 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -528,41 +528,41 @@ discard block |
||
| 528 | 528 | * @return bool true s'il a le droit, false sinon |
| 529 | 529 | **/ |
| 530 | 530 | function autoriser_dater_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 531 | - $table = table_objet($type); |
|
| 532 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | - $desc = $trouver_table($table); |
|
| 534 | - if (!$desc) { |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - if (!isset($opt['statut'])) { |
|
| 539 | - if (isset($desc['field']['statut'])) { |
|
| 540 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 541 | - } else { |
|
| 542 | - $statut = 'publie'; |
|
| 543 | - } // pas de statut => publie |
|
| 544 | - } else { |
|
| 545 | - $statut = $opt['statut']; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // Liste des statuts publiés pour cet objet |
|
| 549 | - if (isset($desc['statut'][0]['publie'])) { |
|
| 550 | - $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 551 | - } |
|
| 552 | - // Sinon en dur le statut "publie" |
|
| 553 | - else { |
|
| 554 | - $statuts_publies = ['publie']; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - if ( |
|
| 558 | - in_array($statut, $statuts_publies) |
|
| 559 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 560 | - or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 561 | - ) { |
|
| 562 | - return autoriser('modifier', $type, $id); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - return false; |
|
| 531 | + $table = table_objet($type); |
|
| 532 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | + $desc = $trouver_table($table); |
|
| 534 | + if (!$desc) { |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + if (!isset($opt['statut'])) { |
|
| 539 | + if (isset($desc['field']['statut'])) { |
|
| 540 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 541 | + } else { |
|
| 542 | + $statut = 'publie'; |
|
| 543 | + } // pas de statut => publie |
|
| 544 | + } else { |
|
| 545 | + $statut = $opt['statut']; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // Liste des statuts publiés pour cet objet |
|
| 549 | + if (isset($desc['statut'][0]['publie'])) { |
|
| 550 | + $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 551 | + } |
|
| 552 | + // Sinon en dur le statut "publie" |
|
| 553 | + else { |
|
| 554 | + $statuts_publies = ['publie']; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + if ( |
|
| 558 | + in_array($statut, $statuts_publies) |
|
| 559 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 560 | + or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 561 | + ) { |
|
| 562 | + return autoriser('modifier', $type, $id); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + return false; |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | * @return bool true s'il a le droit, false sinon |
| 580 | 580 | **/ |
| 581 | 581 | function autoriser_instituer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 582 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 582 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -595,12 +595,12 @@ discard block |
||
| 595 | 595 | * @return bool true s'il a le droit, false sinon |
| 596 | 596 | **/ |
| 597 | 597 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 598 | - return |
|
| 599 | - ($qui['statut'] == '0minirezo') |
|
| 600 | - and ( |
|
| 601 | - !$qui['restreint'] or !$id |
|
| 602 | - or in_array($id, $qui['restreint']) |
|
| 603 | - ); |
|
| 598 | + return |
|
| 599 | + ($qui['statut'] == '0minirezo') |
|
| 600 | + and ( |
|
| 601 | + !$qui['restreint'] or !$id |
|
| 602 | + or in_array($id, $qui['restreint']) |
|
| 603 | + ); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -616,12 +616,12 @@ discard block |
||
| 616 | 616 | * @return bool true s'il a le droit, false sinon |
| 617 | 617 | **/ |
| 618 | 618 | function autoriser_rubrique_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 619 | - if (!empty($opt['id_parent'])) { |
|
| 620 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 621 | - } |
|
| 622 | - else { |
|
| 623 | - return autoriser('defaut', null, null, $qui, $opt); |
|
| 624 | - } |
|
| 619 | + if (!empty($opt['id_parent'])) { |
|
| 620 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 621 | + } |
|
| 622 | + else { |
|
| 623 | + return autoriser('defaut', null, null, $qui, $opt); |
|
| 624 | + } |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | /** |
@@ -637,10 +637,10 @@ discard block |
||
| 637 | 637 | * @return bool true s'il a le droit, false sinon |
| 638 | 638 | **/ |
| 639 | 639 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 640 | - return |
|
| 641 | - ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 642 | - and autoriser('voir', 'rubrique', $id) |
|
| 643 | - and autoriser('publierdans', 'rubrique', $id); |
|
| 640 | + return |
|
| 641 | + ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 642 | + and autoriser('voir', 'rubrique', $id) |
|
| 643 | + and autoriser('publierdans', 'rubrique', $id); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -656,10 +656,10 @@ discard block |
||
| 656 | 656 | * @return bool true s'il a le droit, false sinon |
| 657 | 657 | **/ |
| 658 | 658 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 659 | - return |
|
| 660 | - $id |
|
| 661 | - and autoriser('voir', 'rubrique', $id) |
|
| 662 | - and autoriser('creer', 'article'); |
|
| 659 | + return |
|
| 660 | + $id |
|
| 661 | + and autoriser('voir', 'rubrique', $id) |
|
| 662 | + and autoriser('creer', 'article'); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | * @return bool true s'il a le droit, false sinon |
| 677 | 677 | **/ |
| 678 | 678 | function autoriser_rubrique_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 679 | - return |
|
| 680 | - autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 679 | + return |
|
| 680 | + autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -693,29 +693,29 @@ discard block |
||
| 693 | 693 | * @return bool true s'il a le droit, false sinon |
| 694 | 694 | **/ |
| 695 | 695 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 696 | - if (!$id = intval($id)) { |
|
| 697 | - return false; |
|
| 698 | - } |
|
| 696 | + if (!$id = intval($id)) { |
|
| 697 | + return false; |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 701 | - return false; |
|
| 702 | - } |
|
| 700 | + if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 701 | + return false; |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 705 | - return false; |
|
| 706 | - } |
|
| 704 | + if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - $compte = pipeline( |
|
| 709 | - 'objet_compte_enfants', |
|
| 710 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 711 | - ); |
|
| 712 | - foreach ($compte as $objet => $n) { |
|
| 713 | - if ($n) { |
|
| 714 | - return false; |
|
| 715 | - } |
|
| 716 | - } |
|
| 708 | + $compte = pipeline( |
|
| 709 | + 'objet_compte_enfants', |
|
| 710 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 711 | + ); |
|
| 712 | + foreach ($compte as $objet => $n) { |
|
| 713 | + if ($n) { |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - return autoriser('modifier', 'rubrique', $id); |
|
| 718 | + return autoriser('modifier', 'rubrique', $id); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | |
@@ -733,23 +733,23 @@ discard block |
||
| 733 | 733 | * @return bool true s'il a le droit, false sinon |
| 734 | 734 | **/ |
| 735 | 735 | function autoriser_article_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 736 | - if (!$id) { |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 740 | - |
|
| 741 | - return |
|
| 742 | - $r |
|
| 743 | - and |
|
| 744 | - ( |
|
| 745 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 746 | - or ( |
|
| 747 | - (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 748 | - and in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 749 | - and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 750 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 751 | - ) |
|
| 752 | - ); |
|
| 736 | + if (!$id) { |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 740 | + |
|
| 741 | + return |
|
| 742 | + $r |
|
| 743 | + and |
|
| 744 | + ( |
|
| 745 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 746 | + or ( |
|
| 747 | + (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 748 | + and in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 749 | + and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 750 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 751 | + ) |
|
| 752 | + ); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -765,13 +765,13 @@ discard block |
||
| 765 | 765 | * @return bool true s'il a le droit, false sinon |
| 766 | 766 | **/ |
| 767 | 767 | function autoriser_article_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 768 | - if (!empty($opt['id_parent'])) { |
|
| 769 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 770 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 771 | - } |
|
| 772 | - else { |
|
| 773 | - return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 774 | - } |
|
| 768 | + if (!empty($opt['id_parent'])) { |
|
| 769 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 770 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 771 | + } |
|
| 772 | + else { |
|
| 773 | + return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 774 | + } |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /** |
@@ -791,28 +791,28 @@ discard block |
||
| 791 | 791 | * @return bool true s'il a le droit, false sinon |
| 792 | 792 | */ |
| 793 | 793 | function autoriser_article_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 794 | - if ($qui['statut'] == '0minirezo') { |
|
| 795 | - return true; |
|
| 796 | - } |
|
| 797 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 798 | - if (isset($opt['statut'])) { |
|
| 799 | - $statut = $opt['statut']; |
|
| 800 | - } else { |
|
| 801 | - if (!$id) { |
|
| 802 | - return false; |
|
| 803 | - } |
|
| 804 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - return |
|
| 808 | - // si on est pas auteur de l'article, |
|
| 809 | - // seuls les propose et publies sont visibles |
|
| 810 | - in_array($statut, ['prop', 'publie']) |
|
| 811 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 812 | - or |
|
| 813 | - ($id |
|
| 814 | - and $qui['id_auteur'] |
|
| 815 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 794 | + if ($qui['statut'] == '0minirezo') { |
|
| 795 | + return true; |
|
| 796 | + } |
|
| 797 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 798 | + if (isset($opt['statut'])) { |
|
| 799 | + $statut = $opt['statut']; |
|
| 800 | + } else { |
|
| 801 | + if (!$id) { |
|
| 802 | + return false; |
|
| 803 | + } |
|
| 804 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + return |
|
| 808 | + // si on est pas auteur de l'article, |
|
| 809 | + // seuls les propose et publies sont visibles |
|
| 810 | + in_array($statut, ['prop', 'publie']) |
|
| 811 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 812 | + or |
|
| 813 | + ($id |
|
| 814 | + and $qui['id_auteur'] |
|
| 815 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -829,24 +829,24 @@ discard block |
||
| 829 | 829 | * @return bool true s'il a le droit, false sinon |
| 830 | 830 | **/ |
| 831 | 831 | function autoriser_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 832 | - # securite, mais on aurait pas du arriver ici ! |
|
| 833 | - if ( |
|
| 834 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 835 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 836 | - ) { |
|
| 837 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 838 | - } |
|
| 832 | + # securite, mais on aurait pas du arriver ici ! |
|
| 833 | + if ( |
|
| 834 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 835 | + or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 836 | + ) { |
|
| 837 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - if ($qui['statut'] == '0minirezo') { |
|
| 841 | - return true; |
|
| 842 | - } |
|
| 843 | - // admins et redacteurs peuvent voir un auteur |
|
| 844 | - if ($type == 'auteur') { |
|
| 845 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 846 | - } |
|
| 847 | - // sinon par defaut tout est visible |
|
| 848 | - // sauf cas particuliers traites separemment (ie article) |
|
| 849 | - return true; |
|
| 840 | + if ($qui['statut'] == '0minirezo') { |
|
| 841 | + return true; |
|
| 842 | + } |
|
| 843 | + // admins et redacteurs peuvent voir un auteur |
|
| 844 | + if ($type == 'auteur') { |
|
| 845 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 846 | + } |
|
| 847 | + // sinon par defaut tout est visible |
|
| 848 | + // sauf cas particuliers traites separemment (ie article) |
|
| 849 | + return true; |
|
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | |
@@ -867,12 +867,12 @@ discard block |
||
| 867 | 867 | * @return bool true s'il a le droit, false sinon |
| 868 | 868 | **/ |
| 869 | 869 | function autoriser_webmestre_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 870 | - return |
|
| 871 | - (defined('_ID_WEBMESTRES') ? |
|
| 872 | - in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 873 | - : $qui['webmestre'] == 'oui') |
|
| 874 | - and $qui['statut'] == '0minirezo' |
|
| 875 | - and !$qui['restreint']; |
|
| 870 | + return |
|
| 871 | + (defined('_ID_WEBMESTRES') ? |
|
| 872 | + in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 873 | + : $qui['webmestre'] == 'oui') |
|
| 874 | + and $qui['statut'] == '0minirezo' |
|
| 875 | + and !$qui['restreint']; |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -888,9 +888,9 @@ discard block |
||
| 888 | 888 | * @return bool true s'il a le droit, false sinon |
| 889 | 889 | **/ |
| 890 | 890 | function autoriser_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 891 | - return |
|
| 892 | - $qui['statut'] == '0minirezo' |
|
| 893 | - and !$qui['restreint']; |
|
| 891 | + return |
|
| 892 | + $qui['statut'] == '0minirezo' |
|
| 893 | + and !$qui['restreint']; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | /** |
@@ -906,8 +906,8 @@ discard block |
||
| 906 | 906 | * @return bool true s'il a le droit, false sinon |
| 907 | 907 | **/ |
| 908 | 908 | function autoriser_sauvegarder_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 909 | - return |
|
| 910 | - $qui['statut'] == '0minirezo'; |
|
| 909 | + return |
|
| 910 | + $qui['statut'] == '0minirezo'; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | * @return bool true s'il a le droit, false sinon |
| 924 | 924 | **/ |
| 925 | 925 | function autoriser_detruire_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 926 | - return autoriser('webmestre', null, null, $qui, $opt); |
|
| 926 | + return autoriser('webmestre', null, null, $qui, $opt); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -940,23 +940,23 @@ discard block |
||
| 940 | 940 | * @return bool true s'il a le droit, false sinon |
| 941 | 941 | **/ |
| 942 | 942 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 943 | - // les admins peuvent "previsualiser" une page auteur |
|
| 944 | - if ( |
|
| 945 | - $qui['statut'] == '0minirezo' |
|
| 946 | - and !$qui['restreint'] |
|
| 947 | - ) { |
|
| 948 | - return true; |
|
| 949 | - } elseif ($id === 0) { |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 953 | - $n = sql_fetsel( |
|
| 954 | - 'A.id_article', |
|
| 955 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 956 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 957 | - ); |
|
| 943 | + // les admins peuvent "previsualiser" une page auteur |
|
| 944 | + if ( |
|
| 945 | + $qui['statut'] == '0minirezo' |
|
| 946 | + and !$qui['restreint'] |
|
| 947 | + ) { |
|
| 948 | + return true; |
|
| 949 | + } elseif ($id === 0) { |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 953 | + $n = sql_fetsel( |
|
| 954 | + 'A.id_article', |
|
| 955 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 956 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 957 | + ); |
|
| 958 | 958 | |
| 959 | - return $n ? true : false; |
|
| 959 | + return $n ? true : false; |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | * @return bool true s'il a le droit, false sinon |
| 985 | 985 | **/ |
| 986 | 986 | function autoriser_auteur_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 987 | - return ($qui['statut'] == '0minirezo'); |
|
| 987 | + return ($qui['statut'] == '0minirezo'); |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | |
@@ -1004,73 +1004,73 @@ discard block |
||
| 1004 | 1004 | **/ |
| 1005 | 1005 | function autoriser_auteur_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1006 | 1006 | |
| 1007 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1008 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1009 | - if (!in_array($qui['statut'], ['0minirezo'])) { |
|
| 1010 | - if ( |
|
| 1011 | - $id == $qui['id_auteur'] |
|
| 1012 | - && empty($opt['statut']) |
|
| 1013 | - && empty($opt['webmestre']) |
|
| 1014 | - && empty($opt['restreintes']) |
|
| 1015 | - && empty($opt['login']) |
|
| 1016 | - ) { |
|
| 1017 | - return true; |
|
| 1018 | - } |
|
| 1019 | - return false; |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1023 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1024 | - if ($qui['restreint']) { |
|
| 1025 | - if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 1026 | - return false; |
|
| 1027 | - } elseif ( |
|
| 1028 | - (isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 1029 | - or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 1030 | - ) { |
|
| 1031 | - return false; |
|
| 1032 | - } else { |
|
| 1033 | - if ($id == $qui['id_auteur']) { |
|
| 1034 | - if (isset($opt['statut']) and $opt['statut']) { |
|
| 1035 | - return false; |
|
| 1036 | - } else { |
|
| 1037 | - return true; |
|
| 1038 | - } |
|
| 1039 | - } else { |
|
| 1040 | - if ($id_auteur = intval($id)) { |
|
| 1041 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1042 | - if ($t and $t['statut'] != '0minirezo') { |
|
| 1043 | - return true; |
|
| 1044 | - } else { |
|
| 1045 | - return false; |
|
| 1046 | - } |
|
| 1047 | - } // id = 0 => creation |
|
| 1048 | - else { |
|
| 1049 | - return true; |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - // Un admin complet fait ce qu'il veut |
|
| 1056 | - // sauf se degrader |
|
| 1057 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1058 | - return false; |
|
| 1059 | - } elseif ( |
|
| 1060 | - isset($opt['webmestre']) |
|
| 1061 | - and $opt['webmestre'] |
|
| 1062 | - and (defined('_ID_WEBMESTRES') |
|
| 1063 | - or !autoriser('webmestre')) |
|
| 1064 | - ) { |
|
| 1065 | - // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1066 | - // ou si les webmestres sont fixes par constante (securite) |
|
| 1067 | - return false; |
|
| 1068 | - } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1069 | - elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1070 | - return false; |
|
| 1071 | - } else { |
|
| 1072 | - return true; |
|
| 1073 | - } |
|
| 1007 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1008 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1009 | + if (!in_array($qui['statut'], ['0minirezo'])) { |
|
| 1010 | + if ( |
|
| 1011 | + $id == $qui['id_auteur'] |
|
| 1012 | + && empty($opt['statut']) |
|
| 1013 | + && empty($opt['webmestre']) |
|
| 1014 | + && empty($opt['restreintes']) |
|
| 1015 | + && empty($opt['login']) |
|
| 1016 | + ) { |
|
| 1017 | + return true; |
|
| 1018 | + } |
|
| 1019 | + return false; |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1023 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1024 | + if ($qui['restreint']) { |
|
| 1025 | + if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 1026 | + return false; |
|
| 1027 | + } elseif ( |
|
| 1028 | + (isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 1029 | + or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 1030 | + ) { |
|
| 1031 | + return false; |
|
| 1032 | + } else { |
|
| 1033 | + if ($id == $qui['id_auteur']) { |
|
| 1034 | + if (isset($opt['statut']) and $opt['statut']) { |
|
| 1035 | + return false; |
|
| 1036 | + } else { |
|
| 1037 | + return true; |
|
| 1038 | + } |
|
| 1039 | + } else { |
|
| 1040 | + if ($id_auteur = intval($id)) { |
|
| 1041 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1042 | + if ($t and $t['statut'] != '0minirezo') { |
|
| 1043 | + return true; |
|
| 1044 | + } else { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 1047 | + } // id = 0 => creation |
|
| 1048 | + else { |
|
| 1049 | + return true; |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + // Un admin complet fait ce qu'il veut |
|
| 1056 | + // sauf se degrader |
|
| 1057 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1058 | + return false; |
|
| 1059 | + } elseif ( |
|
| 1060 | + isset($opt['webmestre']) |
|
| 1061 | + and $opt['webmestre'] |
|
| 1062 | + and (defined('_ID_WEBMESTRES') |
|
| 1063 | + or !autoriser('webmestre')) |
|
| 1064 | + ) { |
|
| 1065 | + // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1066 | + // ou si les webmestres sont fixes par constante (securite) |
|
| 1067 | + return false; |
|
| 1068 | + } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1069 | + elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1070 | + return false; |
|
| 1071 | + } else { |
|
| 1072 | + return true; |
|
| 1073 | + } |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | |
@@ -1087,7 +1087,7 @@ discard block |
||
| 1087 | 1087 | * @return bool true s'il a le droit, false sinon |
| 1088 | 1088 | **/ |
| 1089 | 1089 | function autoriser_associerauteurs_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1090 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1090 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | * @return bool true s'il a le droit, false sinon |
| 1105 | 1105 | **/ |
| 1106 | 1106 | function autoriser_chargerftp_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1107 | - return $qui['statut'] == '0minirezo'; |
|
| 1107 | + return $qui['statut'] == '0minirezo'; |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | /** |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | * @return bool true s'il a le droit, false sinon |
| 1121 | 1121 | **/ |
| 1122 | 1122 | function autoriser_debug_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1123 | - return $qui['statut'] == '0minirezo'; |
|
| 1123 | + return $qui['statut'] == '0minirezo'; |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | /** |
@@ -1137,54 +1137,54 @@ discard block |
||
| 1137 | 1137 | * @return array Liste des rubriques |
| 1138 | 1138 | **/ |
| 1139 | 1139 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1140 | - static $restreint = []; |
|
| 1141 | - |
|
| 1142 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 1143 | - return []; |
|
| 1144 | - } |
|
| 1145 | - if ($raz) { |
|
| 1146 | - unset($restreint[$id_auteur]); |
|
| 1147 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1148 | - return $restreint[$id_auteur]; |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - $rubriques = []; |
|
| 1152 | - if ( |
|
| 1153 | - (!isset($GLOBALS['meta']['version_installee']) |
|
| 1154 | - or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1155 | - and $r = sql_allfetsel( |
|
| 1156 | - 'id_objet', |
|
| 1157 | - 'spip_auteurs_liens', |
|
| 1158 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1159 | - ) |
|
| 1160 | - and is_countable($r) ? count($r) : 0 |
|
| 1161 | - ) { |
|
| 1162 | - $r = array_column($r, 'id_objet'); |
|
| 1163 | - |
|
| 1164 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1165 | - include_spip('inc/rubriques'); |
|
| 1166 | - $r = calcul_branche_in($r); |
|
| 1167 | - $r = explode(',', $r); |
|
| 1168 | - |
|
| 1169 | - // passer les rubriques en index, elimine les doublons |
|
| 1170 | - $r = array_flip($r); |
|
| 1171 | - // recuperer les index seuls |
|
| 1172 | - $r = array_keys($r); |
|
| 1173 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1174 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1175 | - $rubriques = array_combine($r, $r); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - // Affecter l'auteur session le cas echeant |
|
| 1179 | - if ( |
|
| 1180 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1181 | - and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1182 | - ) { |
|
| 1183 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1140 | + static $restreint = []; |
|
| 1141 | + |
|
| 1142 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 1143 | + return []; |
|
| 1144 | + } |
|
| 1145 | + if ($raz) { |
|
| 1146 | + unset($restreint[$id_auteur]); |
|
| 1147 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1148 | + return $restreint[$id_auteur]; |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + $rubriques = []; |
|
| 1152 | + if ( |
|
| 1153 | + (!isset($GLOBALS['meta']['version_installee']) |
|
| 1154 | + or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1155 | + and $r = sql_allfetsel( |
|
| 1156 | + 'id_objet', |
|
| 1157 | + 'spip_auteurs_liens', |
|
| 1158 | + 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1159 | + ) |
|
| 1160 | + and is_countable($r) ? count($r) : 0 |
|
| 1161 | + ) { |
|
| 1162 | + $r = array_column($r, 'id_objet'); |
|
| 1163 | + |
|
| 1164 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1165 | + include_spip('inc/rubriques'); |
|
| 1166 | + $r = calcul_branche_in($r); |
|
| 1167 | + $r = explode(',', $r); |
|
| 1168 | + |
|
| 1169 | + // passer les rubriques en index, elimine les doublons |
|
| 1170 | + $r = array_flip($r); |
|
| 1171 | + // recuperer les index seuls |
|
| 1172 | + $r = array_keys($r); |
|
| 1173 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1174 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1175 | + $rubriques = array_combine($r, $r); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + // Affecter l'auteur session le cas echeant |
|
| 1179 | + if ( |
|
| 1180 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1181 | + and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1182 | + ) { |
|
| 1183 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | * @return bool true s'il a le droit, false sinon |
| 1201 | 1201 | **/ |
| 1202 | 1202 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1203 | - return autoriser('previsualiser'); |
|
| 1203 | + return autoriser('previsualiser'); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | /** |
@@ -1216,7 +1216,7 @@ discard block |
||
| 1216 | 1216 | * @return bool true s'il a le droit, false sinon |
| 1217 | 1217 | **/ |
| 1218 | 1218 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1219 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1219 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | /** |
@@ -1232,8 +1232,8 @@ discard block |
||
| 1232 | 1232 | * @return bool true s'il a le droit, false sinon |
| 1233 | 1233 | **/ |
| 1234 | 1234 | function autoriser_auteur_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1235 | - return (($id == $qui['id_auteur']) or |
|
| 1236 | - (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1235 | + return (($id == $qui['id_auteur']) or |
|
| 1236 | + (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | /** |
@@ -1249,8 +1249,8 @@ discard block |
||
| 1249 | 1249 | * @return bool true s'il a le droit, false sinon |
| 1250 | 1250 | **/ |
| 1251 | 1251 | function autoriser_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1252 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1253 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1252 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1253 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1268,7 +1268,7 @@ discard block |
||
| 1268 | 1268 | * @return bool true |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function autoriser_ok_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1271 | - return true; |
|
| 1271 | + return true; |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | /** |
@@ -1285,7 +1285,7 @@ discard block |
||
| 1285 | 1285 | * @return bool false |
| 1286 | 1286 | **/ |
| 1287 | 1287 | function autoriser_niet_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1288 | - return false; |
|
| 1288 | + return false; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1301,11 +1301,11 @@ discard block |
||
| 1301 | 1301 | * @return bool false |
| 1302 | 1302 | **/ |
| 1303 | 1303 | function autoriser_base_reparer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1304 | - if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1305 | - return false; |
|
| 1306 | - } |
|
| 1304 | + if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1305 | + return false; |
|
| 1306 | + } |
|
| 1307 | 1307 | |
| 1308 | - return true; |
|
| 1308 | + return true; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | /** |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | * @return bool true s'il a le droit, false sinon |
| 1322 | 1322 | **/ |
| 1323 | 1323 | function autoriser_infosperso_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1324 | - return true; |
|
| 1324 | + return true; |
|
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | /** |
@@ -1337,7 +1337,7 @@ discard block |
||
| 1337 | 1337 | * @return bool true s'il a le droit, false sinon |
| 1338 | 1338 | **/ |
| 1339 | 1339 | function autoriser_langage_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1340 | - return true; |
|
| 1340 | + return true; |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | /** |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | * @return bool true s'il a le droit, false sinon |
| 1354 | 1354 | **/ |
| 1355 | 1355 | function autoriser_configurerlangage_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1356 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1356 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | /** |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | * @return bool true s'il a le droit, false sinon |
| 1370 | 1370 | **/ |
| 1371 | 1371 | function autoriser_preferences_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1372 | - return true; |
|
| 1372 | + return true; |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | /** |
@@ -1385,7 +1385,7 @@ discard block |
||
| 1385 | 1385 | * @return bool true s'il a le droit, false sinon |
| 1386 | 1386 | **/ |
| 1387 | 1387 | function autoriser_configurerpreferences_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1388 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1388 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | /** |
@@ -1401,8 +1401,8 @@ discard block |
||
| 1401 | 1401 | * @return bool true s'il a le droit, false sinon |
| 1402 | 1402 | **/ |
| 1403 | 1403 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1404 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1405 | - and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1404 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1405 | + and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | /** |
@@ -1419,7 +1419,7 @@ discard block |
||
| 1419 | 1419 | * @return bool true s'il a le droit, false sinon |
| 1420 | 1420 | **/ |
| 1421 | 1421 | function autoriser_menugrandeentree_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1422 | - return true; |
|
| 1422 | + return true; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1435,7 +1435,7 @@ discard block |
||
| 1435 | 1435 | * @return bool true s'il a le droit, false sinon |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function autoriser_auteurs_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1438 | - return true; |
|
| 1438 | + return true; |
|
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | /** |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | * @return bool true s'il a le droit, false sinon |
| 1452 | 1452 | **/ |
| 1453 | 1453 | function autoriser_auteurs_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1454 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1454 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1467,7 +1467,7 @@ discard block |
||
| 1467 | 1467 | * @return bool true s'il a le droit, false sinon |
| 1468 | 1468 | **/ |
| 1469 | 1469 | function autoriser_articles_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1470 | - return true; |
|
| 1470 | + return true; |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | /** |
@@ -1483,7 +1483,7 @@ discard block |
||
| 1483 | 1483 | * @return bool true s'il a le droit, false sinon |
| 1484 | 1484 | **/ |
| 1485 | 1485 | function autoriser_articles_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1486 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1486 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | /** |
@@ -1499,7 +1499,7 @@ discard block |
||
| 1499 | 1499 | * @return bool true s'il a le droit, false sinon |
| 1500 | 1500 | **/ |
| 1501 | 1501 | function autoriser_rubriques_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1502 | - return true; |
|
| 1502 | + return true; |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | /** |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | * @return bool true s'il a le droit, false sinon |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function autoriser_rubriques_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1518 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1518 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | /** |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | * @return bool true s'il a le droit, false sinon |
| 1532 | 1532 | **/ |
| 1533 | 1533 | function autoriser_articlecreer_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1534 | - return verifier_table_non_vide(); |
|
| 1534 | + return verifier_table_non_vide(); |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | * @return bool true s'il a le droit, false sinon |
| 1551 | 1551 | **/ |
| 1552 | 1552 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1553 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1553 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | /** |
@@ -1566,13 +1566,13 @@ discard block |
||
| 1566 | 1566 | * @return bool true s'il a le droit, false sinon |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function autoriser_visiteurs_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1569 | - include_spip('base/abstract_sql'); |
|
| 1570 | - return |
|
| 1571 | - $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1572 | - and ( |
|
| 1573 | - $GLOBALS['meta']['accepter_visiteurs'] != 'non' |
|
| 1574 | - or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1575 | - ); |
|
| 1569 | + include_spip('base/abstract_sql'); |
|
| 1570 | + return |
|
| 1571 | + $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1572 | + and ( |
|
| 1573 | + $GLOBALS['meta']['accepter_visiteurs'] != 'non' |
|
| 1574 | + or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1575 | + ); |
|
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | /** |
@@ -1588,7 +1588,7 @@ discard block |
||
| 1588 | 1588 | * @return bool true s'il a le droit, false sinon |
| 1589 | 1589 | **/ |
| 1590 | 1590 | function autoriser_suiviedito_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1591 | - return $qui['statut'] == '0minirezo'; |
|
| 1591 | + return $qui['statut'] == '0minirezo'; |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | /** |
@@ -1604,7 +1604,7 @@ discard block |
||
| 1604 | 1604 | * @return bool true s'il a le droit, false sinon |
| 1605 | 1605 | **/ |
| 1606 | 1606 | function autoriser_synchro_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1607 | - return $qui['statut'] == '0minirezo'; |
|
| 1607 | + return $qui['statut'] == '0minirezo'; |
|
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | /** |
@@ -1620,7 +1620,7 @@ discard block |
||
| 1620 | 1620 | * @return bool true s'il a le droit, false sinon |
| 1621 | 1621 | **/ |
| 1622 | 1622 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1623 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1623 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | 1626 | /** |
@@ -1636,7 +1636,7 @@ discard block |
||
| 1636 | 1636 | * @return bool true s'il a le droit, false sinon |
| 1637 | 1637 | **/ |
| 1638 | 1638 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1639 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1639 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | /** |
@@ -1652,7 +1652,7 @@ discard block |
||
| 1652 | 1652 | * @return bool true s'il a le droit, false sinon |
| 1653 | 1653 | **/ |
| 1654 | 1654 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1655 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1655 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | /** |
@@ -1668,7 +1668,7 @@ discard block |
||
| 1668 | 1668 | * @return bool true s'il a le droit, false sinon |
| 1669 | 1669 | **/ |
| 1670 | 1670 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1671 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1671 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1672 | 1672 | } |
| 1673 | 1673 | |
| 1674 | 1674 | /** |
@@ -1684,7 +1684,7 @@ discard block |
||
| 1684 | 1684 | * @return bool true s'il a le droit, false sinon |
| 1685 | 1685 | **/ |
| 1686 | 1686 | function autoriser_configureravancees_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1687 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1687 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | /** |
@@ -1700,7 +1700,7 @@ discard block |
||
| 1700 | 1700 | * @return bool true s'il a le droit, false sinon |
| 1701 | 1701 | **/ |
| 1702 | 1702 | function autoriser_adminplugin_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1703 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1703 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | /** |
@@ -1716,7 +1716,7 @@ discard block |
||
| 1716 | 1716 | * @return bool true s'il a le droit, false sinon |
| 1717 | 1717 | **/ |
| 1718 | 1718 | function autoriser_admintech_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1719 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1719 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1720 | 1720 | } |
| 1721 | 1721 | |
| 1722 | 1722 | /** |
@@ -1732,7 +1732,7 @@ discard block |
||
| 1732 | 1732 | * @return bool true s'il a le droit, false sinon |
| 1733 | 1733 | **/ |
| 1734 | 1734 | function autoriser_queue_purger_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1735 | - return autoriser('webmestre'); |
|
| 1735 | + return autoriser('webmestre'); |
|
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | 1738 | |
@@ -1750,11 +1750,11 @@ discard block |
||
| 1750 | 1750 | * @return bool true s'il a le droit, false sinon |
| 1751 | 1751 | **/ |
| 1752 | 1752 | function autoriser_echafauder_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1753 | - if (test_espace_prive()) { |
|
| 1754 | - return intval($qui['id_auteur']) ? true : false; |
|
| 1755 | - } else { |
|
| 1756 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1757 | - } |
|
| 1753 | + if (test_espace_prive()) { |
|
| 1754 | + return intval($qui['id_auteur']) ? true : false; |
|
| 1755 | + } else { |
|
| 1756 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1757 | + } |
|
| 1758 | 1758 | } |
| 1759 | 1759 | |
| 1760 | 1760 | |
@@ -1769,27 +1769,27 @@ discard block |
||
| 1769 | 1769 | * Identifiants d'auteurs |
| 1770 | 1770 | */ |
| 1771 | 1771 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1772 | - $objet = objet_type($objet); |
|
| 1773 | - $where = [ |
|
| 1774 | - 'objet=' . sql_quote($objet), |
|
| 1775 | - 'id_objet=' . intval($id_objet) |
|
| 1776 | - ]; |
|
| 1777 | - if (!empty($cond)) { |
|
| 1778 | - if (is_array($cond)) { |
|
| 1779 | - $where = array_merge($where, $cond); |
|
| 1780 | - } else { |
|
| 1781 | - $where[] = $cond; |
|
| 1782 | - } |
|
| 1783 | - } |
|
| 1784 | - $auteurs = sql_allfetsel( |
|
| 1785 | - 'id_auteur', |
|
| 1786 | - 'spip_auteurs_liens', |
|
| 1787 | - $where |
|
| 1788 | - ); |
|
| 1789 | - if (is_array($auteurs)) { |
|
| 1790 | - return array_column($auteurs, 'id_auteur'); |
|
| 1791 | - } |
|
| 1792 | - return []; |
|
| 1772 | + $objet = objet_type($objet); |
|
| 1773 | + $where = [ |
|
| 1774 | + 'objet=' . sql_quote($objet), |
|
| 1775 | + 'id_objet=' . intval($id_objet) |
|
| 1776 | + ]; |
|
| 1777 | + if (!empty($cond)) { |
|
| 1778 | + if (is_array($cond)) { |
|
| 1779 | + $where = array_merge($where, $cond); |
|
| 1780 | + } else { |
|
| 1781 | + $where[] = $cond; |
|
| 1782 | + } |
|
| 1783 | + } |
|
| 1784 | + $auteurs = sql_allfetsel( |
|
| 1785 | + 'id_auteur', |
|
| 1786 | + 'spip_auteurs_liens', |
|
| 1787 | + $where |
|
| 1788 | + ); |
|
| 1789 | + if (is_array($auteurs)) { |
|
| 1790 | + return array_column($auteurs, 'id_auteur'); |
|
| 1791 | + } |
|
| 1792 | + return []; |
|
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | 1795 | /** |
@@ -1804,11 +1804,11 @@ discard block |
||
| 1804 | 1804 | * - false : serveur SQL indisponible |
| 1805 | 1805 | */ |
| 1806 | 1806 | function auteurs_article($id_article, $cond = '') { |
| 1807 | - return sql_allfetsel( |
|
| 1808 | - 'id_auteur', |
|
| 1809 | - 'spip_auteurs_liens', |
|
| 1810 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1811 | - ); |
|
| 1807 | + return sql_allfetsel( |
|
| 1808 | + 'id_auteur', |
|
| 1809 | + 'spip_auteurs_liens', |
|
| 1810 | + "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1811 | + ); |
|
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | 1814 | |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | */ |
| 1823 | 1823 | function acces_restreint_rubrique($id_rubrique) { |
| 1824 | 1824 | |
| 1825 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1825 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1826 | 1826 | } |
| 1827 | 1827 | |
| 1828 | 1828 | |
@@ -1835,12 +1835,12 @@ discard block |
||
| 1835 | 1835 | * @return bool true si un parent existe |
| 1836 | 1836 | */ |
| 1837 | 1837 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1838 | - static $done = []; |
|
| 1839 | - if (!isset($done[$table])) { |
|
| 1840 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1841 | - } |
|
| 1838 | + static $done = []; |
|
| 1839 | + if (!isset($done[$table])) { |
|
| 1840 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1841 | + } |
|
| 1842 | 1842 | |
| 1843 | - return $done[$table]; |
|
| 1843 | + return $done[$table]; |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | /** |
@@ -1865,15 +1865,15 @@ discard block |
||
| 1865 | 1865 | */ |
| 1866 | 1866 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1867 | 1867 | |
| 1868 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1869 | - switch ($s) { |
|
| 1870 | - case 'info_redacteurs': |
|
| 1871 | - return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1872 | - case 'info_visiteurs': |
|
| 1873 | - return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1874 | - } |
|
| 1868 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1869 | + switch ($s) { |
|
| 1870 | + case 'info_redacteurs': |
|
| 1871 | + return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1872 | + case 'info_visiteurs': |
|
| 1873 | + return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1874 | + } |
|
| 1875 | 1875 | |
| 1876 | - return false; |
|
| 1876 | + return false; |
|
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | /** |
@@ -1889,7 +1889,7 @@ discard block |
||
| 1889 | 1889 | * @return bool false |
| 1890 | 1890 | **/ |
| 1891 | 1891 | function autoriser_inscription_relancer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1892 | - return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1892 | + return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1893 | 1893 | } |
| 1894 | 1894 | |
| 1895 | 1895 | /** |
@@ -1905,5 +1905,5 @@ discard block |
||
| 1905 | 1905 | * @return bool true s'il a le droit, false sinon |
| 1906 | 1906 | **/ |
| 1907 | 1907 | function autoriser_phpinfos_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1908 | - return autoriser('webmestre'); |
|
| 1908 | + return autoriser('webmestre'); |
|
| 1909 | 1909 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | // mais apres la fonction autoriser() |
| 116 | 116 | if ($f = find_in_path('mes_fonctions.php')) { |
| 117 | 117 | global $dossier_squelettes; |
| 118 | - include_once(_ROOT_CWD . $f); |
|
| 118 | + include_once(_ROOT_CWD.$f); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $qui = $GLOBALS['visiteur_session'] ?: []; |
| 158 | 158 | $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
| 159 | 159 | } elseif (is_numeric($qui)) { |
| 160 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 160 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Admins restreints, on construit ici (pas generique mais...) |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | spip_log( |
| 170 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 171 | - 'autoriser' . _LOG_DEBUG |
|
| 170 | + "autoriser $faire $type $id (".($qui['nom'] ?? '').') ?', |
|
| 171 | + 'autoriser'._LOG_DEBUG |
|
| 172 | 172 | ); |
| 173 | 173 | |
| 174 | 174 | // passer par objet_type pour avoir les alias |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
| 185 | 185 | or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
| 186 | 186 | ) { |
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, ".($qui['nom'] ?? '').') : OK Exception', 'autoriser'._LOG_DEBUG); |
|
| 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 | ]; |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | spip_log( |
| 220 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 221 | - 'autoriser' . _LOG_DEBUG |
|
| 220 | + "$f($faire, $type, $id, ".($qui['nom'] ?? '').') : '.($a ? 'OK' : 'niet'), |
|
| 221 | + 'autoriser'._LOG_DEBUG |
|
| 222 | 222 | ); |
| 223 | 223 | |
| 224 | 224 | return $a; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | function autoriser_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 354 | 354 | |
| 355 | 355 | // Le visiteur a-t-il un statut prevu par la config ? |
| 356 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 356 | + if (strpos($GLOBALS['meta']['preview'], ','.$qui['statut'].',') !== false) { |
|
| 357 | 357 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 358 | 358 | } |
| 359 | 359 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | } // pas de champ passe a la demande => NIET |
| 411 | 411 | $previsu = explode(',', $c['previsu']); |
| 412 | 412 | // regarder si ce statut est autorise pour l'auteur |
| 413 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 413 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 414 | 414 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 415 | 415 | // sinon l’auteur en session |
| 416 | 416 | include_spip('inc/securiser_action'); |
@@ -424,12 +424,12 @@ discard block |
||
| 424 | 424 | |
| 425 | 425 | if (!$id_auteur) { |
| 426 | 426 | return false; |
| 427 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 427 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) { |
|
| 428 | 428 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 429 | 429 | } elseif ( |
| 430 | 430 | !sql_countsel( |
| 431 | 431 | 'spip_auteurs_liens', |
| 432 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 432 | + 'id_auteur='.intval($id_auteur).' AND objet='.sql_quote($type).' AND id_objet='.intval($id) |
|
| 433 | 433 | ) |
| 434 | 434 | ) { |
| 435 | 435 | return false; |
@@ -472,16 +472,16 @@ discard block |
||
| 472 | 472 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 473 | 473 | $primary = id_table_objet($type); |
| 474 | 474 | if ($table != 'spip_rubriques') { |
| 475 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 475 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=".intval($id)); |
|
| 476 | 476 | } else { |
| 477 | 477 | $id_rubrique = $id; |
| 478 | 478 | } |
| 479 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 479 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 480 | 480 | if (!$id_secteur > 0) { |
| 481 | 481 | $id_secteur = $id_rubrique; |
| 482 | 482 | } |
| 483 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 484 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 483 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.intval($id_secteur)); |
|
| 484 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".intval($id)); |
|
| 485 | 485 | if ($langue_secteur != $langue_objet) { |
| 486 | 486 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 487 | 487 | return true; |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 490 | 490 | return false; |
| 491 | 491 | } else { |
| 492 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 492 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id)); |
|
| 493 | 493 | if ($id_parent != 0) { |
| 494 | 494 | // sous-rubriques : pas de choix de langue |
| 495 | 495 | return false; |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | |
| 538 | 538 | if (!isset($opt['statut'])) { |
| 539 | 539 | if (isset($desc['field']['statut'])) { |
| 540 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 540 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.intval($id)); |
|
| 541 | 541 | } else { |
| 542 | 542 | $statut = 'publie'; |
| 543 | 543 | } // pas de statut => publie |
@@ -697,11 +697,11 @@ discard block |
||
| 697 | 697 | return false; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 700 | + if (sql_countsel('spip_rubriques', 'id_parent='.intval($id))) { |
|
| 701 | 701 | return false; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 704 | + if (sql_countsel('spip_articles', 'id_rubrique='.intval($id)." AND (statut<>'poubelle')")) { |
|
| 705 | 705 | return false; |
| 706 | 706 | } |
| 707 | 707 | |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | if (!$id) { |
| 737 | 737 | return false; |
| 738 | 738 | } |
| 739 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 739 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 740 | 740 | |
| 741 | 741 | return |
| 742 | 742 | $r |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
| 748 | 748 | and in_array($qui['statut'], ['0minirezo', '1comite']) |
| 749 | 749 | and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
| 750 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 750 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 751 | 751 | ) |
| 752 | 752 | ); |
| 753 | 753 | } |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | if (!$id) { |
| 802 | 802 | return false; |
| 803 | 803 | } |
| 804 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 804 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id)); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | return |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | or |
| 813 | 813 | ($id |
| 814 | 814 | and $qui['id_auteur'] |
| 815 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 815 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -831,8 +831,8 @@ discard block |
||
| 831 | 831 | function autoriser_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 832 | 832 | # securite, mais on aurait pas du arriver ici ! |
| 833 | 833 | if ( |
| 834 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 835 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 834 | + function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 835 | + or function_exists($f = 'autoriser_'.$type.'_voir_dist') |
|
| 836 | 836 | ) { |
| 837 | 837 | return $f($faire, $type, $id, $qui, $opt); |
| 838 | 838 | } |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | $n = sql_fetsel( |
| 954 | 954 | 'A.id_article', |
| 955 | 955 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 956 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 956 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 957 | 957 | ); |
| 958 | 958 | |
| 959 | 959 | return $n ? true : false; |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | and $r = sql_allfetsel( |
| 1156 | 1156 | 'id_objet', |
| 1157 | 1157 | 'spip_auteurs_liens', |
| 1158 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1158 | + 'id_auteur='.intval($id_auteur)." AND objet='rubrique' AND id_objet!=0" |
|
| 1159 | 1159 | ) |
| 1160 | 1160 | and is_countable($r) ? count($r) : 0 |
| 1161 | 1161 | ) { |
@@ -1771,8 +1771,8 @@ discard block |
||
| 1771 | 1771 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1772 | 1772 | $objet = objet_type($objet); |
| 1773 | 1773 | $where = [ |
| 1774 | - 'objet=' . sql_quote($objet), |
|
| 1775 | - 'id_objet=' . intval($id_objet) |
|
| 1774 | + 'objet='.sql_quote($objet), |
|
| 1775 | + 'id_objet='.intval($id_objet) |
|
| 1776 | 1776 | ]; |
| 1777 | 1777 | if (!empty($cond)) { |
| 1778 | 1778 | if (is_array($cond)) { |
@@ -1807,7 +1807,7 @@ discard block |
||
| 1807 | 1807 | return sql_allfetsel( |
| 1808 | 1808 | 'id_auteur', |
| 1809 | 1809 | 'spip_auteurs_liens', |
| 1810 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1810 | + "objet='article' AND id_objet=".intval($id_article).($cond ? " AND $cond" : '') |
|
| 1811 | 1811 | ); |
| 1812 | 1812 | } |
| 1813 | 1813 | |
@@ -21,193 +21,193 @@ |
||
| 21 | 21 | // par souci de compatiilite). |
| 22 | 22 | |
| 23 | 23 | if (isset($GLOBALS['_INC_PUBLIC']) and $GLOBALS['_INC_PUBLIC']) { |
| 24 | - echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 24 | + echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 25 | 25 | } else { |
| 26 | - $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | - define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | - |
|
| 29 | - // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | - if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | - if ( |
|
| 32 | - defined('_DIR_RESTREINT') |
|
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | - ) { |
|
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | - } else { |
|
| 37 | - die('inc_version absent ?'); |
|
| 38 | - } |
|
| 39 | - } // $fond defini dans le fichier d'appel ? |
|
| 40 | - |
|
| 41 | - else { |
|
| 42 | - if (isset($fond) and !_request('fond')) { |
|
| 43 | - } // fond demande dans l'url par page=xxxx ? |
|
| 44 | - else { |
|
| 45 | - if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | - |
|
| 48 | - // Securite |
|
| 49 | - if ( |
|
| 50 | - strstr($fond, '/') |
|
| 51 | - and !( |
|
| 52 | - isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | - and include_spip('inc/autoriser') |
|
| 54 | - and autoriser('webmestre')) |
|
| 55 | - ) { |
|
| 56 | - include_spip('inc/minipres'); |
|
| 57 | - echo minipres(); |
|
| 58 | - exit; |
|
| 59 | - } |
|
| 60 | - // l'argument Page a priorite sur l'argument action |
|
| 61 | - // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | - // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | - // mais pas d'en retirer un en conservant les autres. |
|
| 64 | - if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | - unset($_GET['action']); |
|
| 66 | - } |
|
| 67 | - # sinon, fond par defaut |
|
| 68 | - } else { |
|
| 69 | - // sinon fond par defaut (cf. assembler.php) |
|
| 70 | - $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $tableau_des_temps = []; |
|
| 76 | - |
|
| 77 | - // Particularites de certains squelettes |
|
| 78 | - if ($fond == 'login') { |
|
| 79 | - $forcer_lang = true; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ( |
|
| 83 | - isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | - and !_request('action') |
|
| 85 | - and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | - ) { |
|
| 87 | - include_spip('inc/lang'); |
|
| 88 | - verifier_lang_url(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | - |
|
| 93 | - // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | - // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | - if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | - include_spip('public/aiguiller'); |
|
| 97 | - if ( |
|
| 98 | - // cas des appels actions ?action=xxx |
|
| 99 | - traiter_appels_actions() |
|
| 100 | - or |
|
| 101 | - // cas des hits ajax sur les inclusions ajax |
|
| 102 | - traiter_appels_inclusions_ajax() |
|
| 103 | - or |
|
| 104 | - // cas des formulaires charger/verifier/traiter |
|
| 105 | - traiter_formulaires_dynamiques() |
|
| 106 | - ) { |
|
| 107 | - // lancer les taches sur affichage final, comme le cron |
|
| 108 | - // mais sans rien afficher |
|
| 109 | - $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | - exit; // le hit est fini ! |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Il y a du texte a produire, charger le metteur en page |
|
| 116 | - include_spip('public/assembler'); |
|
| 117 | - $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | - |
|
| 119 | - if (isset($page['status'])) { |
|
| 120 | - include_spip('inc/headers'); |
|
| 121 | - http_response_code($page['status']); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Content-Type ? |
|
| 125 | - if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | - $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | - $html = true; |
|
| 129 | - } else { |
|
| 130 | - $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | - // type tableau pour y mettre des choses au besoin. |
|
| 135 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | - |
|
| 137 | - // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | - $affiche_boutons_admin = ($html and ( |
|
| 139 | - (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | - or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | - or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | - )); |
|
| 143 | - |
|
| 144 | - if ($affiche_boutons_admin) { |
|
| 145 | - include_spip('balise/formulaire_admin'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - // Execution de la page calculee |
|
| 150 | - |
|
| 151 | - // traitements sur les entetes avant envoi |
|
| 152 | - // peut servir pour le plugin de stats |
|
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - // eval $page et affecte $res |
|
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | - envoyer_entetes($page['entetes']); |
|
| 159 | - if ($res === false) { |
|
| 160 | - include_spip('inc/autoriser'); |
|
| 161 | - $err = _T('zbug_erreur_execution_page'); |
|
| 162 | - if (autoriser('webmestre')) { |
|
| 163 | - $err .= "\n<hr />\n" |
|
| 164 | - . highlight_string($page['codephp'], true) |
|
| 165 | - . "\n<hr />\n"; |
|
| 166 | - } |
|
| 167 | - $msg = [$err]; |
|
| 168 | - erreur_squelette($msg); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // |
|
| 172 | - // Envoyer le resultat apres post-traitements |
|
| 173 | - // |
|
| 174 | - // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | - // cf. public/assembler.php) |
|
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | - |
|
| 178 | - if ($lang) { |
|
| 179 | - lang_select(); |
|
| 180 | - } |
|
| 181 | - // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | - // il faut tester a nouveau |
|
| 183 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | - |
|
| 185 | - // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | - // at last |
|
| 187 | - if ($debug) { |
|
| 188 | - // en cas d'erreur, retester l'affichage |
|
| 189 | - if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | - $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | - echo erreur_squelette(false); |
|
| 194 | - } |
|
| 195 | - } else { |
|
| 196 | - if ( |
|
| 197 | - isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | - and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | - ) { |
|
| 200 | - include_spip('inc/rubriques'); |
|
| 201 | - calculer_prochain_postdate(true); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Effectuer une tache de fond ? |
|
| 205 | - // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | - cron(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // sauver le cache chemin si necessaire |
|
| 211 | - save_path_cache(); |
|
| 212 | - } |
|
| 26 | + $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | + define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | + |
|
| 29 | + // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | + if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | + if ( |
|
| 32 | + defined('_DIR_RESTREINT') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | + ) { |
|
| 35 | + include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | + } else { |
|
| 37 | + die('inc_version absent ?'); |
|
| 38 | + } |
|
| 39 | + } // $fond defini dans le fichier d'appel ? |
|
| 40 | + |
|
| 41 | + else { |
|
| 42 | + if (isset($fond) and !_request('fond')) { |
|
| 43 | + } // fond demande dans l'url par page=xxxx ? |
|
| 44 | + else { |
|
| 45 | + if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | + $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | + |
|
| 48 | + // Securite |
|
| 49 | + if ( |
|
| 50 | + strstr($fond, '/') |
|
| 51 | + and !( |
|
| 52 | + isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | + and include_spip('inc/autoriser') |
|
| 54 | + and autoriser('webmestre')) |
|
| 55 | + ) { |
|
| 56 | + include_spip('inc/minipres'); |
|
| 57 | + echo minipres(); |
|
| 58 | + exit; |
|
| 59 | + } |
|
| 60 | + // l'argument Page a priorite sur l'argument action |
|
| 61 | + // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | + // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | + // mais pas d'en retirer un en conservant les autres. |
|
| 64 | + if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | + unset($_GET['action']); |
|
| 66 | + } |
|
| 67 | + # sinon, fond par defaut |
|
| 68 | + } else { |
|
| 69 | + // sinon fond par defaut (cf. assembler.php) |
|
| 70 | + $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $tableau_des_temps = []; |
|
| 76 | + |
|
| 77 | + // Particularites de certains squelettes |
|
| 78 | + if ($fond == 'login') { |
|
| 79 | + $forcer_lang = true; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ( |
|
| 83 | + isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | + and !_request('action') |
|
| 85 | + and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | + ) { |
|
| 87 | + include_spip('inc/lang'); |
|
| 88 | + verifier_lang_url(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | + |
|
| 93 | + // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | + // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | + if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | + include_spip('public/aiguiller'); |
|
| 97 | + if ( |
|
| 98 | + // cas des appels actions ?action=xxx |
|
| 99 | + traiter_appels_actions() |
|
| 100 | + or |
|
| 101 | + // cas des hits ajax sur les inclusions ajax |
|
| 102 | + traiter_appels_inclusions_ajax() |
|
| 103 | + or |
|
| 104 | + // cas des formulaires charger/verifier/traiter |
|
| 105 | + traiter_formulaires_dynamiques() |
|
| 106 | + ) { |
|
| 107 | + // lancer les taches sur affichage final, comme le cron |
|
| 108 | + // mais sans rien afficher |
|
| 109 | + $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | + pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | + exit; // le hit est fini ! |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Il y a du texte a produire, charger le metteur en page |
|
| 116 | + include_spip('public/assembler'); |
|
| 117 | + $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | + |
|
| 119 | + if (isset($page['status'])) { |
|
| 120 | + include_spip('inc/headers'); |
|
| 121 | + http_response_code($page['status']); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Content-Type ? |
|
| 125 | + if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | + $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | + $html = true; |
|
| 129 | + } else { |
|
| 130 | + $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | + // type tableau pour y mettre des choses au besoin. |
|
| 135 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | + |
|
| 137 | + // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | + $affiche_boutons_admin = ($html and ( |
|
| 139 | + (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | + or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | + or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | + )); |
|
| 143 | + |
|
| 144 | + if ($affiche_boutons_admin) { |
|
| 145 | + include_spip('balise/formulaire_admin'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + // Execution de la page calculee |
|
| 150 | + |
|
| 151 | + // traitements sur les entetes avant envoi |
|
| 152 | + // peut servir pour le plugin de stats |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + // eval $page et affecte $res |
|
| 157 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | + envoyer_entetes($page['entetes']); |
|
| 159 | + if ($res === false) { |
|
| 160 | + include_spip('inc/autoriser'); |
|
| 161 | + $err = _T('zbug_erreur_execution_page'); |
|
| 162 | + if (autoriser('webmestre')) { |
|
| 163 | + $err .= "\n<hr />\n" |
|
| 164 | + . highlight_string($page['codephp'], true) |
|
| 165 | + . "\n<hr />\n"; |
|
| 166 | + } |
|
| 167 | + $msg = [$err]; |
|
| 168 | + erreur_squelette($msg); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // |
|
| 172 | + // Envoyer le resultat apres post-traitements |
|
| 173 | + // |
|
| 174 | + // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | + // cf. public/assembler.php) |
|
| 176 | + echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | + |
|
| 178 | + if ($lang) { |
|
| 179 | + lang_select(); |
|
| 180 | + } |
|
| 181 | + // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | + // il faut tester a nouveau |
|
| 183 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | + |
|
| 185 | + // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | + // at last |
|
| 187 | + if ($debug) { |
|
| 188 | + // en cas d'erreur, retester l'affichage |
|
| 189 | + if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | + $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | + echo erreur_squelette(false); |
|
| 194 | + } |
|
| 195 | + } else { |
|
| 196 | + if ( |
|
| 197 | + isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | + and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | + ) { |
|
| 200 | + include_spip('inc/rubriques'); |
|
| 201 | + calculer_prochain_postdate(true); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Effectuer une tache de fond ? |
|
| 205 | + // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | + cron(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // sauver le cache chemin si necessaire |
|
| 211 | + save_path_cache(); |
|
| 212 | + } |
|
| 213 | 213 | } |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 31 | 31 | if ( |
| 32 | 32 | defined('_DIR_RESTREINT') |
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT.'inc_version.php') |
|
| 34 | 34 | ) { |
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | + include_once _ROOT_RESTREINT.'inc_version.php'; |
|
| 36 | 36 | } else { |
| 37 | 37 | die('inc_version absent ?'); |
| 38 | 38 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } // fond demande dans l'url par page=xxxx ? |
| 44 | 44 | else { |
| 45 | 45 | if (isset($_GET[_SPIP_PAGE])) { |
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | + $fond = (string) $_GET[_SPIP_PAGE]; |
|
| 47 | 47 | |
| 48 | 48 | // Securite |
| 49 | 49 | if ( |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // lancer les taches sur affichage final, comme le cron |
| 108 | 108 | // mais sans rien afficher |
| 109 | 109 | $GLOBALS['html'] = false; // ne rien afficher |
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 110 | + pipeline('affichage_final'._PIPELINE_SUFFIX, ''); |
|
| 111 | 111 | exit; // le hit est fini ! |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | // Content-Type ? |
| 125 | 125 | if (!isset($page['entetes']['Content-Type'])) { |
| 126 | 126 | $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset='.$charset; |
|
| 128 | 128 | $html = true; |
| 129 | 129 | } else { |
| 130 | 130 | $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | // traitements sur les entetes avant envoi |
| 152 | 152 | // peut servir pour le plugin de stats |
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final'._PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | // eval $page et affecte $res |
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 157 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 158 | 158 | envoyer_entetes($page['entetes']); |
| 159 | 159 | if ($res === false) { |
| 160 | 160 | include_spip('inc/autoriser'); |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | // |
| 174 | 174 | // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
| 175 | 175 | // cf. public/assembler.php) |
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 176 | + echo pipeline('affichage_final'._PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | 177 | |
| 178 | 178 | if ($lang) { |
| 179 | 179 | lang_select(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | if ($html and ($affiche_boutons_admin or $debug)) { |
| 190 | 190 | $var_mode_affiche = _request('var_mode_affiche'); |
| 191 | 191 | $var_mode_objet = _request('var_mode_objet'); |
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet.'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | 193 | echo erreur_squelette(false); |
| 194 | 194 | } |
| 195 | 195 | } else { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // Si a ce stade on n'a pas de table, il y a un bug |
| 235 | 235 | if (!is_array($this->tableau)) { |
| 236 | 236 | $this->err = true; |
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 237 | + spip_log('erreur datasource '.var_export($command, true)); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // {datapath query.results} |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | isset($this->command['sourcemode']) |
| 277 | 277 | and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
| 278 | 278 | ) { |
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 279 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | # le premier argument peut etre un array, une URL etc. |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | # avons-nous un cache dispo ? |
| 286 | 286 | $cle = null; |
| 287 | 287 | if (is_string($src)) { |
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 288 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $cache = $this->cache_get($cle); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | if ( |
| 346 | 346 | !$this->err |
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 348 | 348 | ) { |
| 349 | 349 | $args = $this->command['source']; |
| 350 | 350 | $args[0] = $data; |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | $tv = '%s'; |
| 485 | 485 | } # {par valeur/xx/yy} ?? |
| 486 | 486 | else { |
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 487 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 488 | 488 | } |
| 489 | 489 | $sortfunc .= ' |
| 490 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 491 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 490 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 491 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 492 | 492 | if ($a <> $b) |
| 493 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 493 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | 644 | # sortir le connecteur de $data |
| 645 | 645 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 646 | - $serveur = (string)$v[1]; |
|
| 646 | + $serveur = (string) $v[1]; |
|
| 647 | 647 | $req = trim($v[2]); |
| 648 | 648 | if ($s = sql_query($req, $serveur)) { |
| 649 | 649 | $r = []; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 669 | 669 | } catch (JsonException $e) { |
| 670 | 670 | $json = null; |
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 671 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 672 | 672 | } |
| 673 | 673 | return is_array($json) ? (array) $json : []; |
| 674 | 674 | } |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | $i = 1; |
| 689 | 689 | foreach ($entete as $k => $v) { |
| 690 | 690 | if (trim($v) == '') { |
| 691 | - $v = 'col' . $i; |
|
| 691 | + $v = 'col'.$i; |
|
| 692 | 692 | } // reperer des eventuelles cases vides |
| 693 | 693 | if (is_numeric($v) and $v < 0) { |
| 694 | - $v = '__' . $v; |
|
| 694 | + $v = '__'.$v; |
|
| 695 | 695 | } // ne pas risquer d'ecraser une cle numerique |
| 696 | 696 | if (is_numeric($v)) { |
| 697 | - $v = '_' . $v; |
|
| 697 | + $v = '_'.$v; |
|
| 698 | 698 | } // ne pas risquer d'ecraser une cle numerique |
| 699 | 699 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 700 | 700 | foreach ($csv as &$item) { |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -795,13 +795,13 @@ discard block |
||
| 795 | 795 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 796 | 796 | $a = $glob_to_array($data); |
| 797 | 797 | foreach ($a as &$v) { |
| 798 | - $b = (array)@stat($v); |
|
| 798 | + $b = (array) @stat($v); |
|
| 799 | 799 | foreach ($b as $k => $ignore) { |
| 800 | 800 | if (is_numeric($k)) { |
| 801 | 801 | unset($b[$k]); |
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 805 | 805 | $v = array_merge( |
| 806 | 806 | pathinfo($v), |
| 807 | 807 | $b |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | $xml_array = []; |
| 822 | 822 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 823 | 823 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 824 | - $key .= '-' . uniqid(); |
|
| 824 | + $key .= '-'.uniqid(); |
|
| 825 | 825 | } |
| 826 | 826 | $vars = get_object_vars($object->current()); |
| 827 | 827 | if (isset($vars['@attributes'])) { |
@@ -17,11 +17,11 @@ 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('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,522 +62,522 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = []; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = []; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = []) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() : void { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = array_key_first($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return ['tableau']; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set( |
|
| 183 | - $cle, |
|
| 184 | - [ |
|
| 185 | - 'data' => $valeur, |
|
| 186 | - 'time' => time(), |
|
| 187 | - 'ttl' => $ttl |
|
| 188 | - ], |
|
| 189 | - 3600 + $ttl |
|
| 190 | - ); |
|
| 191 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Aller chercher les données de la boucle DATA |
|
| 197 | - * |
|
| 198 | - * @throws Exception |
|
| 199 | - * @param array $command |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function select($command) { |
|
| 203 | - |
|
| 204 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | - // le type se retrouve dans la commande 'from' |
|
| 206 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | - if (isset($this->command['from'][0])) { |
|
| 208 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | - } |
|
| 211 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | - // les commandes connues pour l'iterateur DATA |
|
| 216 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | - |
|
| 218 | - // {source format, [URL], [arg2]...} |
|
| 219 | - if ( |
|
| 220 | - isset($this->command['source']) |
|
| 221 | - and isset($this->command['sourcemode']) |
|
| 222 | - ) { |
|
| 223 | - $this->select_source(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Critere {liste X1, X2, X3} |
|
| 227 | - if (isset($this->command['liste'])) { |
|
| 228 | - $this->select_liste(); |
|
| 229 | - } |
|
| 230 | - if (isset($this->command['enum'])) { |
|
| 231 | - $this->select_enum(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | - if (!is_array($this->tableau)) { |
|
| 236 | - $this->err = true; |
|
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // {datapath query.results} |
|
| 241 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | - if ( |
|
| 243 | - !$this->err |
|
| 244 | - and isset($this->command['datapath']) |
|
| 245 | - and is_array($this->command['datapath']) |
|
| 246 | - ) { |
|
| 247 | - $this->select_datapath(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // tri {par x} |
|
| 251 | - if ($this->command['orderby']) { |
|
| 252 | - $this->select_orderby(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | - if ($this->command['groupby']) { |
|
| 257 | - $this->select_groupby(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $this->rewind(); |
|
| 261 | - #var_dump($this->tableau); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Aller chercher les donnees de la boucle DATA |
|
| 267 | - * depuis une source |
|
| 268 | - * {source format, [URL], [arg2]...} |
|
| 269 | - */ |
|
| 270 | - protected function select_source() { |
|
| 271 | - # un peu crado : avant de charger le cache il faut charger |
|
| 272 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | - # l'objet en cache ; cf plugins/icalendar |
|
| 274 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | - if ( |
|
| 276 | - isset($this->command['sourcemode']) |
|
| 277 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | - ) { |
|
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - # le premier argument peut etre un array, une URL etc. |
|
| 283 | - $src = $this->command['source'][0]; |
|
| 284 | - |
|
| 285 | - # avons-nous un cache dispo ? |
|
| 286 | - $cle = null; |
|
| 287 | - if (is_string($src)) { |
|
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $cache = $this->cache_get($cle); |
|
| 292 | - if (isset($this->command['datacache'])) { |
|
| 293 | - $ttl = intval($this->command['datacache']); |
|
| 294 | - } |
|
| 295 | - if ( |
|
| 296 | - $cache |
|
| 297 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | - > time()) |
|
| 299 | - and !(_request('var_mode') === 'recalcul' |
|
| 300 | - and include_spip('inc/autoriser') |
|
| 301 | - and autoriser('recalcul') |
|
| 302 | - ) |
|
| 303 | - ) { |
|
| 304 | - $this->tableau = $cache['data']; |
|
| 305 | - } else { |
|
| 306 | - try { |
|
| 307 | - if ( |
|
| 308 | - isset($this->command['sourcemode']) |
|
| 309 | - and in_array( |
|
| 310 | - $this->command['sourcemode'], |
|
| 311 | - ['table', 'array', 'tableau'] |
|
| 312 | - ) |
|
| 313 | - ) { |
|
| 314 | - if ( |
|
| 315 | - is_array($a = $src) |
|
| 316 | - or (is_string($a) |
|
| 317 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | - and is_array($a = @unserialize($a))) |
|
| 319 | - ) { |
|
| 320 | - $this->tableau = $a; |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - $data = $src; |
|
| 324 | - if (is_string($src)) { |
|
| 325 | - if (tester_url_absolue($src)) { |
|
| 326 | - include_spip('inc/distant'); |
|
| 327 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | - $data = $data['page'] ?? ''; |
|
| 329 | - if (!$data) { |
|
| 330 | - throw new Exception('404'); |
|
| 331 | - } |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 24 * 3600; |
|
| 334 | - } |
|
| 335 | - } elseif (@is_dir($src)) { |
|
| 336 | - $data = $src; |
|
| 337 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | - $data = spip_file_get_contents($src); |
|
| 339 | - } |
|
| 340 | - if (!isset($ttl)) { |
|
| 341 | - $ttl = 10; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( |
|
| 346 | - !$this->err |
|
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | - ) { |
|
| 349 | - $args = $this->command['source']; |
|
| 350 | - $args[0] = $data; |
|
| 351 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | - $this->tableau = $a; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!is_array($this->tableau)) { |
|
| 358 | - $this->err = true; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | - $this->cache_set($cle, $ttl); |
|
| 363 | - } |
|
| 364 | - } catch (Exception $e) { |
|
| 365 | - $e = $e->getMessage(); |
|
| 366 | - $err = sprintf( |
|
| 367 | - "[%s, %s] $e", |
|
| 368 | - $src, |
|
| 369 | - $this->command['sourcemode'] |
|
| 370 | - ); |
|
| 371 | - erreur_squelette([$err, []]); |
|
| 372 | - $this->err = true; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | - if ( |
|
| 378 | - $this->err |
|
| 379 | - and $cache |
|
| 380 | - ) { |
|
| 381 | - $this->tableau = $cache['data']; |
|
| 382 | - $this->err = false; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Retourne un tableau donne depuis un critère liste |
|
| 389 | - * |
|
| 390 | - * Critère `{liste X1, X2, X3}` |
|
| 391 | - * |
|
| 392 | - * @see critere_DATA_liste_dist() |
|
| 393 | - * |
|
| 394 | - **/ |
|
| 395 | - protected function select_liste() { |
|
| 396 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | - if (!isset($this->command['liste'][1])) { |
|
| 398 | - if (!is_array($this->command['liste'][0])) { |
|
| 399 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | - } else { |
|
| 401 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - $this->tableau = $this->command['liste']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Retourne un tableau donne depuis un critere liste |
|
| 409 | - * Critere {enum Xmin, Xmax} |
|
| 410 | - * |
|
| 411 | - **/ |
|
| 412 | - protected function select_enum() { |
|
| 413 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | - if (!isset($this->command['enum'][1])) { |
|
| 415 | - if (!is_array($this->command['enum'][0])) { |
|
| 416 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | - } else { |
|
| 418 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | - $enum = range( |
|
| 423 | - array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum']), |
|
| 425 | - array_shift($this->command['enum']) |
|
| 426 | - ); |
|
| 427 | - } else { |
|
| 428 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | - } |
|
| 430 | - $this->tableau = $enum; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | - * {datapath query.results} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_datapath() { |
|
| 440 | - $base = reset($this->command['datapath']); |
|
| 441 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | - if (!is_array($this->tableau)) { |
|
| 444 | - $this->tableau = []; |
|
| 445 | - $this->err = true; |
|
| 446 | - spip_log("datapath '$base' absent"); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Ordonner les resultats |
|
| 453 | - * {par x} |
|
| 454 | - * |
|
| 455 | - **/ |
|
| 456 | - protected function select_orderby() { |
|
| 457 | - $sortfunc = ''; |
|
| 458 | - $aleas = 0; |
|
| 459 | - foreach ($this->command['orderby'] as $tri) { |
|
| 460 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | - $r = array_pad($r, 3, null); |
|
| 463 | - |
|
| 464 | - // tri par cle |
|
| 465 | - if ($r[1] == 'cle') { |
|
| 466 | - if (isset($r[2]) and $r[2]) { |
|
| 467 | - krsort($this->tableau); |
|
| 468 | - } else { |
|
| 469 | - ksort($this->tableau); |
|
| 470 | - } |
|
| 471 | - } # {par hasard} |
|
| 472 | - else { |
|
| 473 | - if ($r[1] == 'hasard') { |
|
| 474 | - $k = array_keys($this->tableau); |
|
| 475 | - shuffle($k); |
|
| 476 | - $v = []; |
|
| 477 | - foreach ($k as $cle) { |
|
| 478 | - $v[$cle] = $this->tableau[$cle]; |
|
| 479 | - } |
|
| 480 | - $this->tableau = $v; |
|
| 481 | - } else { |
|
| 482 | - # {par valeur} |
|
| 483 | - if ($r[1] == 'valeur') { |
|
| 484 | - $tv = '%s'; |
|
| 485 | - } # {par valeur/xx/yy} ?? |
|
| 486 | - else { |
|
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | - } |
|
| 489 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = []; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = []; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = []) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() : void { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = array_key_first($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return ['tableau']; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set( |
|
| 183 | + $cle, |
|
| 184 | + [ |
|
| 185 | + 'data' => $valeur, |
|
| 186 | + 'time' => time(), |
|
| 187 | + 'ttl' => $ttl |
|
| 188 | + ], |
|
| 189 | + 3600 + $ttl |
|
| 190 | + ); |
|
| 191 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Aller chercher les données de la boucle DATA |
|
| 197 | + * |
|
| 198 | + * @throws Exception |
|
| 199 | + * @param array $command |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function select($command) { |
|
| 203 | + |
|
| 204 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | + // le type se retrouve dans la commande 'from' |
|
| 206 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | + if (isset($this->command['from'][0])) { |
|
| 208 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | + } |
|
| 211 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | + // les commandes connues pour l'iterateur DATA |
|
| 216 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | + |
|
| 218 | + // {source format, [URL], [arg2]...} |
|
| 219 | + if ( |
|
| 220 | + isset($this->command['source']) |
|
| 221 | + and isset($this->command['sourcemode']) |
|
| 222 | + ) { |
|
| 223 | + $this->select_source(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Critere {liste X1, X2, X3} |
|
| 227 | + if (isset($this->command['liste'])) { |
|
| 228 | + $this->select_liste(); |
|
| 229 | + } |
|
| 230 | + if (isset($this->command['enum'])) { |
|
| 231 | + $this->select_enum(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | + if (!is_array($this->tableau)) { |
|
| 236 | + $this->err = true; |
|
| 237 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // {datapath query.results} |
|
| 241 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | + if ( |
|
| 243 | + !$this->err |
|
| 244 | + and isset($this->command['datapath']) |
|
| 245 | + and is_array($this->command['datapath']) |
|
| 246 | + ) { |
|
| 247 | + $this->select_datapath(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // tri {par x} |
|
| 251 | + if ($this->command['orderby']) { |
|
| 252 | + $this->select_orderby(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | + if ($this->command['groupby']) { |
|
| 257 | + $this->select_groupby(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $this->rewind(); |
|
| 261 | + #var_dump($this->tableau); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Aller chercher les donnees de la boucle DATA |
|
| 267 | + * depuis une source |
|
| 268 | + * {source format, [URL], [arg2]...} |
|
| 269 | + */ |
|
| 270 | + protected function select_source() { |
|
| 271 | + # un peu crado : avant de charger le cache il faut charger |
|
| 272 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | + # l'objet en cache ; cf plugins/icalendar |
|
| 274 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | + if ( |
|
| 276 | + isset($this->command['sourcemode']) |
|
| 277 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | + ) { |
|
| 279 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + # le premier argument peut etre un array, une URL etc. |
|
| 283 | + $src = $this->command['source'][0]; |
|
| 284 | + |
|
| 285 | + # avons-nous un cache dispo ? |
|
| 286 | + $cle = null; |
|
| 287 | + if (is_string($src)) { |
|
| 288 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $cache = $this->cache_get($cle); |
|
| 292 | + if (isset($this->command['datacache'])) { |
|
| 293 | + $ttl = intval($this->command['datacache']); |
|
| 294 | + } |
|
| 295 | + if ( |
|
| 296 | + $cache |
|
| 297 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | + > time()) |
|
| 299 | + and !(_request('var_mode') === 'recalcul' |
|
| 300 | + and include_spip('inc/autoriser') |
|
| 301 | + and autoriser('recalcul') |
|
| 302 | + ) |
|
| 303 | + ) { |
|
| 304 | + $this->tableau = $cache['data']; |
|
| 305 | + } else { |
|
| 306 | + try { |
|
| 307 | + if ( |
|
| 308 | + isset($this->command['sourcemode']) |
|
| 309 | + and in_array( |
|
| 310 | + $this->command['sourcemode'], |
|
| 311 | + ['table', 'array', 'tableau'] |
|
| 312 | + ) |
|
| 313 | + ) { |
|
| 314 | + if ( |
|
| 315 | + is_array($a = $src) |
|
| 316 | + or (is_string($a) |
|
| 317 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | + and is_array($a = @unserialize($a))) |
|
| 319 | + ) { |
|
| 320 | + $this->tableau = $a; |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + $data = $src; |
|
| 324 | + if (is_string($src)) { |
|
| 325 | + if (tester_url_absolue($src)) { |
|
| 326 | + include_spip('inc/distant'); |
|
| 327 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | + $data = $data['page'] ?? ''; |
|
| 329 | + if (!$data) { |
|
| 330 | + throw new Exception('404'); |
|
| 331 | + } |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 24 * 3600; |
|
| 334 | + } |
|
| 335 | + } elseif (@is_dir($src)) { |
|
| 336 | + $data = $src; |
|
| 337 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | + $data = spip_file_get_contents($src); |
|
| 339 | + } |
|
| 340 | + if (!isset($ttl)) { |
|
| 341 | + $ttl = 10; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( |
|
| 346 | + !$this->err |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | + ) { |
|
| 349 | + $args = $this->command['source']; |
|
| 350 | + $args[0] = $data; |
|
| 351 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | + $this->tableau = $a; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!is_array($this->tableau)) { |
|
| 358 | + $this->err = true; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | + $this->cache_set($cle, $ttl); |
|
| 363 | + } |
|
| 364 | + } catch (Exception $e) { |
|
| 365 | + $e = $e->getMessage(); |
|
| 366 | + $err = sprintf( |
|
| 367 | + "[%s, %s] $e", |
|
| 368 | + $src, |
|
| 369 | + $this->command['sourcemode'] |
|
| 370 | + ); |
|
| 371 | + erreur_squelette([$err, []]); |
|
| 372 | + $this->err = true; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | + if ( |
|
| 378 | + $this->err |
|
| 379 | + and $cache |
|
| 380 | + ) { |
|
| 381 | + $this->tableau = $cache['data']; |
|
| 382 | + $this->err = false; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Retourne un tableau donne depuis un critère liste |
|
| 389 | + * |
|
| 390 | + * Critère `{liste X1, X2, X3}` |
|
| 391 | + * |
|
| 392 | + * @see critere_DATA_liste_dist() |
|
| 393 | + * |
|
| 394 | + **/ |
|
| 395 | + protected function select_liste() { |
|
| 396 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | + if (!isset($this->command['liste'][1])) { |
|
| 398 | + if (!is_array($this->command['liste'][0])) { |
|
| 399 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | + } else { |
|
| 401 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + $this->tableau = $this->command['liste']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Retourne un tableau donne depuis un critere liste |
|
| 409 | + * Critere {enum Xmin, Xmax} |
|
| 410 | + * |
|
| 411 | + **/ |
|
| 412 | + protected function select_enum() { |
|
| 413 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | + if (!isset($this->command['enum'][1])) { |
|
| 415 | + if (!is_array($this->command['enum'][0])) { |
|
| 416 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | + } else { |
|
| 418 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | + $enum = range( |
|
| 423 | + array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum']), |
|
| 425 | + array_shift($this->command['enum']) |
|
| 426 | + ); |
|
| 427 | + } else { |
|
| 428 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | + } |
|
| 430 | + $this->tableau = $enum; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | + * {datapath query.results} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_datapath() { |
|
| 440 | + $base = reset($this->command['datapath']); |
|
| 441 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | + if (!is_array($this->tableau)) { |
|
| 444 | + $this->tableau = []; |
|
| 445 | + $this->err = true; |
|
| 446 | + spip_log("datapath '$base' absent"); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Ordonner les resultats |
|
| 453 | + * {par x} |
|
| 454 | + * |
|
| 455 | + **/ |
|
| 456 | + protected function select_orderby() { |
|
| 457 | + $sortfunc = ''; |
|
| 458 | + $aleas = 0; |
|
| 459 | + foreach ($this->command['orderby'] as $tri) { |
|
| 460 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | + $r = array_pad($r, 3, null); |
|
| 463 | + |
|
| 464 | + // tri par cle |
|
| 465 | + if ($r[1] == 'cle') { |
|
| 466 | + if (isset($r[2]) and $r[2]) { |
|
| 467 | + krsort($this->tableau); |
|
| 468 | + } else { |
|
| 469 | + ksort($this->tableau); |
|
| 470 | + } |
|
| 471 | + } # {par hasard} |
|
| 472 | + else { |
|
| 473 | + if ($r[1] == 'hasard') { |
|
| 474 | + $k = array_keys($this->tableau); |
|
| 475 | + shuffle($k); |
|
| 476 | + $v = []; |
|
| 477 | + foreach ($k as $cle) { |
|
| 478 | + $v[$cle] = $this->tableau[$cle]; |
|
| 479 | + } |
|
| 480 | + $this->tableau = $v; |
|
| 481 | + } else { |
|
| 482 | + # {par valeur} |
|
| 483 | + if ($r[1] == 'valeur') { |
|
| 484 | + $tv = '%s'; |
|
| 485 | + } # {par valeur/xx/yy} ?? |
|
| 486 | + else { |
|
| 487 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | + } |
|
| 489 | + $sortfunc .= ' |
|
| 490 | 490 | $a = ' . sprintf($tv, '$aa') . '; |
| 491 | 491 | $b = ' . sprintf($tv, '$bb') . '; |
| 492 | 492 | if ($a <> $b) |
| 493 | 493 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if ($sortfunc) { |
|
| 500 | - $sortfunc .= "\n return 0;"; |
|
| 501 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = []; |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid(): bool { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return mixed |
|
| 540 | - */ |
|
| 541 | - #[\ReturnTypeWillChange] |
|
| 542 | - public function current() { |
|
| 543 | - return $this->valeur; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Retourner la cle |
|
| 548 | - * |
|
| 549 | - * @return mixed |
|
| 550 | - */ |
|
| 551 | - #[\ReturnTypeWillChange] |
|
| 552 | - public function key() { |
|
| 553 | - return $this->cle; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Passer a la valeur suivante |
|
| 558 | - * |
|
| 559 | - * @return void |
|
| 560 | - */ |
|
| 561 | - public function next() : void { |
|
| 562 | - if ($this->valid()) { |
|
| 563 | - $this->cle = key($this->tableau); |
|
| 564 | - $this->valeur = current($this->tableau); |
|
| 565 | - next($this->tableau); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Compter le nombre total de resultats |
|
| 571 | - * |
|
| 572 | - * @return int |
|
| 573 | - */ |
|
| 574 | - public function count() { |
|
| 575 | - if (is_null($this->total)) { |
|
| 576 | - $this->total = count($this->tableau); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $this->total; |
|
| 580 | - } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if ($sortfunc) { |
|
| 500 | + $sortfunc .= "\n return 0;"; |
|
| 501 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = []; |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid(): bool { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return mixed |
|
| 540 | + */ |
|
| 541 | + #[\ReturnTypeWillChange] |
|
| 542 | + public function current() { |
|
| 543 | + return $this->valeur; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Retourner la cle |
|
| 548 | + * |
|
| 549 | + * @return mixed |
|
| 550 | + */ |
|
| 551 | + #[\ReturnTypeWillChange] |
|
| 552 | + public function key() { |
|
| 553 | + return $this->cle; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Passer a la valeur suivante |
|
| 558 | + * |
|
| 559 | + * @return void |
|
| 560 | + */ |
|
| 561 | + public function next() : void { |
|
| 562 | + if ($this->valid()) { |
|
| 563 | + $this->cle = key($this->tableau); |
|
| 564 | + $this->valeur = current($this->tableau); |
|
| 565 | + next($this->tableau); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Compter le nombre total de resultats |
|
| 571 | + * |
|
| 572 | + * @return int |
|
| 573 | + */ |
|
| 574 | + public function count() { |
|
| 575 | + if (is_null($this->total)) { |
|
| 576 | + $this->total = count($this->tableau); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $this->total; |
|
| 580 | + } |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /* |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | * @return array |
| 592 | 592 | */ |
| 593 | 593 | function inc_file_to_array_dist($data) { |
| 594 | - return preg_split('/\r?\n/', $data); |
|
| 594 | + return preg_split('/\r?\n/', $data); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,9 +600,9 @@ discard block |
||
| 600 | 600 | * @return array |
| 601 | 601 | */ |
| 602 | 602 | function inc_plugins_to_array_dist() { |
| 603 | - include_spip('inc/plugin'); |
|
| 603 | + include_spip('inc/plugin'); |
|
| 604 | 604 | |
| 605 | - return liste_chemin_plugin_actifs(); |
|
| 605 | + return liste_chemin_plugin_actifs(); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | * @return array |
| 613 | 613 | */ |
| 614 | 614 | function inc_xml_to_array_dist($data) { |
| 615 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 615 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -624,14 +624,14 @@ discard block |
||
| 624 | 624 | * |
| 625 | 625 | */ |
| 626 | 626 | function inc_object_to_array($object) { |
| 627 | - if (!is_object($object) && !is_array($object)) { |
|
| 628 | - return $object; |
|
| 629 | - } |
|
| 630 | - if (is_object($object)) { |
|
| 631 | - $object = get_object_vars($object); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - return array_map('inc_object_to_array', $object); |
|
| 627 | + if (!is_object($object) && !is_array($object)) { |
|
| 628 | + return $object; |
|
| 629 | + } |
|
| 630 | + if (is_object($object)) { |
|
| 631 | + $object = get_object_vars($object); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + return array_map('inc_object_to_array', $object); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -641,20 +641,20 @@ discard block |
||
| 641 | 641 | * @return array|bool |
| 642 | 642 | */ |
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | - # sortir le connecteur de $data |
|
| 645 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | - $serveur = (string)$v[1]; |
|
| 647 | - $req = trim($v[2]); |
|
| 648 | - if ($s = sql_query($req, $serveur)) { |
|
| 649 | - $r = []; |
|
| 650 | - while ($t = sql_fetch($s)) { |
|
| 651 | - $r[] = $t; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $r; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return false; |
|
| 644 | + # sortir le connecteur de $data |
|
| 645 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | + $serveur = (string)$v[1]; |
|
| 647 | + $req = trim($v[2]); |
|
| 648 | + if ($s = sql_query($req, $serveur)) { |
|
| 649 | + $r = []; |
|
| 650 | + while ($t = sql_fetch($s)) { |
|
| 651 | + $r[] = $t; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $r; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return false; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | * @return array|bool |
| 665 | 665 | */ |
| 666 | 666 | function inc_json_to_array_dist($data) { |
| 667 | - try { |
|
| 668 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | - } catch (JsonException $e) { |
|
| 670 | - $json = null; |
|
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | - } |
|
| 673 | - return is_array($json) ? (array) $json : []; |
|
| 667 | + try { |
|
| 668 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | + } catch (JsonException $e) { |
|
| 670 | + $json = null; |
|
| 671 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | + } |
|
| 673 | + return is_array($json) ? (array) $json : []; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
@@ -680,30 +680,30 @@ discard block |
||
| 680 | 680 | * @return array|bool |
| 681 | 681 | */ |
| 682 | 682 | function inc_csv_to_array_dist($data) { |
| 683 | - include_spip('inc/csv'); |
|
| 684 | - [$entete, $csv] = analyse_csv($data); |
|
| 685 | - array_unshift($csv, $entete); |
|
| 686 | - |
|
| 687 | - include_spip('inc/charsets'); |
|
| 688 | - $i = 1; |
|
| 689 | - foreach ($entete as $k => $v) { |
|
| 690 | - if (trim($v) == '') { |
|
| 691 | - $v = 'col' . $i; |
|
| 692 | - } // reperer des eventuelles cases vides |
|
| 693 | - if (is_numeric($v) and $v < 0) { |
|
| 694 | - $v = '__' . $v; |
|
| 695 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | - if (is_numeric($v)) { |
|
| 697 | - $v = '_' . $v; |
|
| 698 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | - foreach ($csv as &$item) { |
|
| 701 | - $item[$v] = &$item[$k]; |
|
| 702 | - } |
|
| 703 | - $i++; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - return $csv; |
|
| 683 | + include_spip('inc/csv'); |
|
| 684 | + [$entete, $csv] = analyse_csv($data); |
|
| 685 | + array_unshift($csv, $entete); |
|
| 686 | + |
|
| 687 | + include_spip('inc/charsets'); |
|
| 688 | + $i = 1; |
|
| 689 | + foreach ($entete as $k => $v) { |
|
| 690 | + if (trim($v) == '') { |
|
| 691 | + $v = 'col' . $i; |
|
| 692 | + } // reperer des eventuelles cases vides |
|
| 693 | + if (is_numeric($v) and $v < 0) { |
|
| 694 | + $v = '__' . $v; |
|
| 695 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | + if (is_numeric($v)) { |
|
| 697 | + $v = '_' . $v; |
|
| 698 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | + foreach ($csv as &$item) { |
|
| 701 | + $item[$v] = &$item[$k]; |
|
| 702 | + } |
|
| 703 | + $i++; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + return $csv; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -713,13 +713,13 @@ discard block |
||
| 713 | 713 | * @return array|bool |
| 714 | 714 | */ |
| 715 | 715 | function inc_rss_to_array_dist($data) { |
| 716 | - $tableau = null; |
|
| 717 | - include_spip('inc/syndic'); |
|
| 718 | - if (is_array($rss = analyser_backend($data))) { |
|
| 719 | - $tableau = $rss; |
|
| 720 | - } |
|
| 716 | + $tableau = null; |
|
| 717 | + include_spip('inc/syndic'); |
|
| 718 | + if (is_array($rss = analyser_backend($data))) { |
|
| 719 | + $tableau = $rss; |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - return $tableau; |
|
| 722 | + return $tableau; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -729,9 +729,9 @@ discard block |
||
| 729 | 729 | * @return array|bool |
| 730 | 730 | */ |
| 731 | 731 | function inc_atom_to_array_dist($data) { |
| 732 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 732 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 733 | 733 | |
| 734 | - return $rss_to_array($data); |
|
| 734 | + return $rss_to_array($data); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -742,12 +742,12 @@ discard block |
||
| 742 | 742 | * @return array|bool |
| 743 | 743 | */ |
| 744 | 744 | function inc_glob_to_array_dist($data) { |
| 745 | - $a = glob( |
|
| 746 | - $data, |
|
| 747 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | - ); |
|
| 745 | + $a = glob( |
|
| 746 | + $data, |
|
| 747 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | + ); |
|
| 749 | 749 | |
| 750 | - return $a ?: []; |
|
| 750 | + return $a ?: []; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | /** |
@@ -758,14 +758,14 @@ discard block |
||
| 758 | 758 | * @throws Exception |
| 759 | 759 | */ |
| 760 | 760 | function inc_yaml_to_array_dist($data) { |
| 761 | - include_spip('inc/yaml-mini'); |
|
| 762 | - if (!function_exists('yaml_decode')) { |
|
| 763 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 761 | + include_spip('inc/yaml-mini'); |
|
| 762 | + if (!function_exists('yaml_decode')) { |
|
| 763 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 764 | 764 | |
| 765 | - return false; |
|
| 766 | - } |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - return yaml_decode($data); |
|
| 768 | + return yaml_decode($data); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -792,23 +792,23 @@ discard block |
||
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
| 794 | 794 | function inc_ls_to_array_dist($data) { |
| 795 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | - $a = $glob_to_array($data); |
|
| 797 | - foreach ($a as &$v) { |
|
| 798 | - $b = (array)@stat($v); |
|
| 799 | - foreach ($b as $k => $ignore) { |
|
| 800 | - if (is_numeric($k)) { |
|
| 801 | - unset($b[$k]); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | - $v = array_merge( |
|
| 806 | - pathinfo($v), |
|
| 807 | - $b |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - return $a; |
|
| 795 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | + $a = $glob_to_array($data); |
|
| 797 | + foreach ($a as &$v) { |
|
| 798 | + $b = (array)@stat($v); |
|
| 799 | + foreach ($b as $k => $ignore) { |
|
| 800 | + if (is_numeric($k)) { |
|
| 801 | + unset($b[$k]); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | + $v = array_merge( |
|
| 806 | + pathinfo($v), |
|
| 807 | + $b |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + return $a; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -818,25 +818,25 @@ discard block |
||
| 818 | 818 | * @return array|bool |
| 819 | 819 | */ |
| 820 | 820 | function XMLObjectToArray($object) { |
| 821 | - $xml_array = []; |
|
| 822 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | - $key .= '-' . uniqid(); |
|
| 825 | - } |
|
| 826 | - $vars = get_object_vars($object->current()); |
|
| 827 | - if (isset($vars['@attributes'])) { |
|
| 828 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | - $xml_array[$key][$k] = $v; |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - if ($object->hasChildren()) { |
|
| 833 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | - $object->current() |
|
| 835 | - ); |
|
| 836 | - } else { |
|
| 837 | - $xml_array[$key][] = strval($object->current()); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - return $xml_array; |
|
| 821 | + $xml_array = []; |
|
| 822 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | + $key .= '-' . uniqid(); |
|
| 825 | + } |
|
| 826 | + $vars = get_object_vars($object->current()); |
|
| 827 | + if (isset($vars['@attributes'])) { |
|
| 828 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | + $xml_array[$key][$k] = $v; |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + if ($object->hasChildren()) { |
|
| 833 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | + $object->current() |
|
| 835 | + ); |
|
| 836 | + } else { |
|
| 837 | + $xml_array[$key][] = strval($object->current()); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + return $xml_array; |
|
| 842 | 842 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -21,28 +21,28 @@ discard block |
||
| 21 | 21 | * @param array $arbre |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_pipelines_dist(&$arbre) { |
| 24 | - $pipes = null; |
|
| 25 | - $tag = null; |
|
| 26 | - $pipeline = []; |
|
| 27 | - if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | - foreach ($pipes as $tag => $p) { |
|
| 29 | - if (!is_array($p[0])) { |
|
| 30 | - [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | - $pipeline[] = $att; |
|
| 32 | - } else { |
|
| 33 | - foreach ($p as $pipe) { |
|
| 34 | - $att = []; |
|
| 35 | - if (is_array($pipe)) { |
|
| 36 | - foreach ($pipe as $k => $t) { |
|
| 37 | - $att[$k] = trim(end($t)); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - $pipeline[] = $att; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - unset($arbre[$tag]); |
|
| 45 | - } |
|
| 24 | + $pipes = null; |
|
| 25 | + $tag = null; |
|
| 26 | + $pipeline = []; |
|
| 27 | + if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | + foreach ($pipes as $tag => $p) { |
|
| 29 | + if (!is_array($p[0])) { |
|
| 30 | + [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | + $pipeline[] = $att; |
|
| 32 | + } else { |
|
| 33 | + foreach ($p as $pipe) { |
|
| 34 | + $att = []; |
|
| 35 | + if (is_array($pipe)) { |
|
| 36 | + foreach ($pipe as $k => $t) { |
|
| 37 | + $att[$k] = trim(end($t)); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + $pipeline[] = $att; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + unset($arbre[$tag]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $pipeline; |
|
| 47 | + return $pipeline; |
|
| 48 | 48 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,31 +21,31 @@ discard block |
||
| 21 | 21 | * @return <type> |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_boutons_dist($arbre) { |
| 24 | - $les_boutons = null; |
|
| 25 | - $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | - // recuperer les boutons et onglets si necessaire |
|
| 27 | - spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | - if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | - $ret['bouton'] = []; |
|
| 30 | - $ret['onglet'] = []; |
|
| 31 | - foreach ($les_boutons as $bouton => $val) { |
|
| 32 | - $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | - $type = reset($bouton); |
|
| 34 | - $bouton = end($bouton); |
|
| 35 | - if (isset($bouton['id'])) { |
|
| 36 | - $id = $bouton['id']; |
|
| 37 | - $val = reset($val); |
|
| 38 | - if (is_array($val)) { |
|
| 39 | - $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | - $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | - $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | - $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | - $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | - $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 24 | + $les_boutons = null; |
|
| 25 | + $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | + // recuperer les boutons et onglets si necessaire |
|
| 27 | + spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | + if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | + $ret['bouton'] = []; |
|
| 30 | + $ret['onglet'] = []; |
|
| 31 | + foreach ($les_boutons as $bouton => $val) { |
|
| 32 | + $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | + $type = reset($bouton); |
|
| 34 | + $bouton = end($bouton); |
|
| 35 | + if (isset($bouton['id'])) { |
|
| 36 | + $id = $bouton['id']; |
|
| 37 | + $val = reset($val); |
|
| 38 | + if (is_array($val)) { |
|
| 39 | + $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | + $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | + $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | + $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | + $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | + $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $ret; |
|
| 50 | + return $ret; |
|
| 51 | 51 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 28 | 28 | ]; |
@@ -23,6 +23,6 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL"], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL"], |
|
| 28 | 28 | ]; |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][16428] = [ |
| 26 | - ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | - ['maj_liens', 'auteur', 'article'], |
|
| 28 | - ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | - ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | - ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | - ['maj_liens', 'auteur', 'message'], |
|
| 32 | - ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 26 | + ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | + ['maj_liens', 'auteur', 'article'], |
|
| 28 | + ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | + ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | + ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | + ['maj_liens', 'auteur', 'message'], |
|
| 32 | + ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,89 +55,89 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function maj_liens($pivot, $l = '') { |
| 57 | 57 | |
| 58 | - @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | - |
|
| 60 | - $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | - |
|
| 62 | - $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | - $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 66 | - // Creer spip_auteurs_liens |
|
| 67 | - global $tables_auxiliaires; |
|
| 68 | - if (!$l) { |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - include_spip('base/create'); |
|
| 71 | - creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | - } else { |
|
| 73 | - // Preparer |
|
| 74 | - $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | - $primary = "id_$l"; |
|
| 76 | - $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | - $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | - $pool = 400; |
|
| 80 | - |
|
| 81 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | - if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // securite pour ne pas perdre de donnees |
|
| 87 | - if (!$trouver_table($liens)) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champs = $desc['field']; |
|
| 92 | - if (isset($champs['maj'])) { |
|
| 93 | - unset($champs['maj']); |
|
| 94 | - } |
|
| 95 | - if (isset($champs[$primary])) { |
|
| 96 | - unset($champs[$primary]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $champs = array_keys($champs); |
|
| 100 | - // ne garder que les champs qui existent sur la table destination |
|
| 101 | - if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | - $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $champs[] = "$primary as id_objet"; |
|
| 106 | - $champs[] = "'$objet' as objet"; |
|
| 107 | - $champs = implode(', ', $champs); |
|
| 108 | - |
|
| 109 | - // Recopier les donnees |
|
| 110 | - $sub_pool = 100; |
|
| 111 | - while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | - $insert = []; |
|
| 113 | - foreach ($ids as $id) { |
|
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | - $n += is_countable($t) ? count($t) : 0; |
|
| 117 | - // empiler en s'assurant a minima de l'unicite |
|
| 118 | - while ($r = array_shift($t)) { |
|
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | - } |
|
| 121 | - if (count($insert) >= $sub_pool) { |
|
| 122 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | - $insert = []; |
|
| 124 | - } |
|
| 125 | - // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | - // et on verifiera/repartira de la |
|
| 127 | - if (time() >= _TIME_OUT) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (time() >= _TIME_OUT) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (count($insert)) { |
|
| 136 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | - } |
|
| 138 | - sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | - } |
|
| 140 | - } |
|
| 58 | + @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | + |
|
| 60 | + $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | + |
|
| 62 | + $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | + $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | + $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | + $id_pivot = 'id_' . $pivot; |
|
| 66 | + // Creer spip_auteurs_liens |
|
| 67 | + global $tables_auxiliaires; |
|
| 68 | + if (!$l) { |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + include_spip('base/create'); |
|
| 71 | + creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | + } else { |
|
| 73 | + // Preparer |
|
| 74 | + $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | + $primary = "id_$l"; |
|
| 76 | + $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | + $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | + $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | + $pool = 400; |
|
| 80 | + |
|
| 81 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | + if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // securite pour ne pas perdre de donnees |
|
| 87 | + if (!$trouver_table($liens)) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champs = $desc['field']; |
|
| 92 | + if (isset($champs['maj'])) { |
|
| 93 | + unset($champs['maj']); |
|
| 94 | + } |
|
| 95 | + if (isset($champs[$primary])) { |
|
| 96 | + unset($champs[$primary]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $champs = array_keys($champs); |
|
| 100 | + // ne garder que les champs qui existent sur la table destination |
|
| 101 | + if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | + $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $champs[] = "$primary as id_objet"; |
|
| 106 | + $champs[] = "'$objet' as objet"; |
|
| 107 | + $champs = implode(', ', $champs); |
|
| 108 | + |
|
| 109 | + // Recopier les donnees |
|
| 110 | + $sub_pool = 100; |
|
| 111 | + while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | + $insert = []; |
|
| 113 | + foreach ($ids as $id) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | + $n += is_countable($t) ? count($t) : 0; |
|
| 117 | + // empiler en s'assurant a minima de l'unicite |
|
| 118 | + while ($r = array_shift($t)) { |
|
| 119 | + $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | + } |
|
| 121 | + if (count($insert) >= $sub_pool) { |
|
| 122 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | + $insert = []; |
|
| 124 | + } |
|
| 125 | + // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | + // et on verifiera/repartira de la |
|
| 127 | + if (time() >= _TIME_OUT) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (time() >= _TIME_OUT) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (count($insert)) { |
|
| 136 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | + } |
|
| 138 | + sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -151,86 +151,86 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | **/ |
| 153 | 153 | function maj_liens_insertq_multi_check($table, $couples, $desc = []) { |
| 154 | - $n_before = sql_countsel($table); |
|
| 155 | - sql_insertq_multi($table, $couples, $desc); |
|
| 156 | - $n_after = sql_countsel($table); |
|
| 157 | - if (($n_after - $n_before) == count($couples)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | - // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | - foreach ($couples as $c) { |
|
| 163 | - sql_insertq($table, $c, $desc); |
|
| 164 | - } |
|
| 154 | + $n_before = sql_countsel($table); |
|
| 155 | + sql_insertq_multi($table, $couples, $desc); |
|
| 156 | + $n_after = sql_countsel($table); |
|
| 157 | + if (($n_after - $n_before) == count($couples)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | + // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | + foreach ($couples as $c) { |
|
| 163 | + sql_insertq($table, $c, $desc); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $GLOBALS['maj'][17311] = [ |
| 168 | - [ |
|
| 169 | - 'ecrire_meta', |
|
| 170 | - 'multi_objets', |
|
| 171 | - implode( |
|
| 172 | - ',', |
|
| 173 | - array_diff( |
|
| 174 | - [ |
|
| 175 | - (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | - ? 'spip_rubriques' : '', |
|
| 177 | - (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | - ? 'spip_articles' : '' |
|
| 179 | - ], |
|
| 180 | - [''] |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'ecrire_meta', |
|
| 186 | - 'gerer_trad_objets', |
|
| 187 | - implode( |
|
| 188 | - ',', |
|
| 189 | - array_diff( |
|
| 190 | - [ |
|
| 191 | - (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | - ? 'spip_articles' : '' |
|
| 193 | - ], |
|
| 194 | - [''] |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ], |
|
| 168 | + [ |
|
| 169 | + 'ecrire_meta', |
|
| 170 | + 'multi_objets', |
|
| 171 | + implode( |
|
| 172 | + ',', |
|
| 173 | + array_diff( |
|
| 174 | + [ |
|
| 175 | + (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | + ? 'spip_rubriques' : '', |
|
| 177 | + (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | + ? 'spip_articles' : '' |
|
| 179 | + ], |
|
| 180 | + [''] |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'ecrire_meta', |
|
| 186 | + 'gerer_trad_objets', |
|
| 187 | + implode( |
|
| 188 | + ',', |
|
| 189 | + array_diff( |
|
| 190 | + [ |
|
| 191 | + (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | + ? 'spip_articles' : '' |
|
| 193 | + ], |
|
| 194 | + [''] |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ], |
|
| 198 | 198 | ]; |
| 199 | 199 | $GLOBALS['maj'][17555] = [ |
| 200 | - ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | - ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 200 | + ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | + ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $GLOBALS['maj'][17563] = [ |
| 205 | - ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | - ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 205 | + ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | + ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $GLOBALS['maj'][17577] = [ |
| 210 | - ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 210 | + ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $GLOBALS['maj'][17743] = [ |
| 214 | - ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 214 | + ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 215 | 215 | ]; |
| 216 | 216 | |
| 217 | 217 | $GLOBALS['maj'][18219] = [ |
| 218 | - ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | - ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 218 | + ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | + ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 220 | 220 | ]; |
| 221 | 221 | |
| 222 | 222 | $GLOBALS['maj'][18310] = [ |
| 223 | - ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 223 | + ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 224 | 224 | ]; |
| 225 | 225 | |
| 226 | 226 | $GLOBALS['maj'][18597] = [ |
| 227 | - ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | - ['maj_propager_les_secteurs'], |
|
| 227 | + ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | + ['maj_propager_les_secteurs'], |
|
| 229 | 229 | ]; |
| 230 | 230 | |
| 231 | 231 | $GLOBALS['maj'][18955] = [ |
| 232 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 232 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 234 | 234 | ]; |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @uses propager_les_secteurs() |
| 240 | 240 | **/ |
| 241 | 241 | function maj_propager_les_secteurs() { |
| 242 | - include_spip('inc/rubriques'); |
|
| 243 | - propager_les_secteurs(); |
|
| 242 | + include_spip('inc/rubriques'); |
|
| 243 | + propager_les_secteurs(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -253,87 +253,87 @@ discard block |
||
| 253 | 253 | function maj_collation_sqlite() { |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - include_spip('base/dump'); |
|
| 257 | - $tables = base_lister_toutes_tables(); |
|
| 258 | - |
|
| 259 | - // rien a faire si base non sqlite |
|
| 260 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | - // forcer le vidage de cache |
|
| 266 | - $trouver_table(''); |
|
| 267 | - |
|
| 268 | - // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | - $desc = $trouver_table('spip_auteurs'); |
|
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | - if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | - spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | - sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | - $trouver_table(''); |
|
| 275 | - $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - foreach ($tables as $table) { |
|
| 280 | - if (time() >= _TIME_OUT) { |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - if ($desc = $trouver_table($table)) { |
|
| 284 | - $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | - if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | - spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | - |
|
| 288 | - // cas particulier spip_urls : |
|
| 289 | - // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | - if ($table == 'spip_urls') { |
|
| 291 | - // par date DESC pour conserver les urls les plus recentes |
|
| 292 | - $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | - $urls = []; |
|
| 294 | - foreach ($data as $d) { |
|
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | - if (!isset($urls[$key])) { |
|
| 297 | - $urls[$key] = true; |
|
| 298 | - } else { |
|
| 299 | - spip_log( |
|
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | - ); |
|
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - foreach ($desc['field'] as $field => $type) { |
|
| 308 | - if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | - $trouver_table(''); |
|
| 312 | - $new_desc = $trouver_table($table); |
|
| 313 | - spip_log( |
|
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | - ); |
|
| 317 | - continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // forcer le vidage de cache |
|
| 325 | - $trouver_table(''); |
|
| 256 | + include_spip('base/dump'); |
|
| 257 | + $tables = base_lister_toutes_tables(); |
|
| 258 | + |
|
| 259 | + // rien a faire si base non sqlite |
|
| 260 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | + // forcer le vidage de cache |
|
| 266 | + $trouver_table(''); |
|
| 267 | + |
|
| 268 | + // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | + $desc = $trouver_table('spip_auteurs'); |
|
| 270 | + spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | + if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | + spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | + sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | + $trouver_table(''); |
|
| 275 | + $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + foreach ($tables as $table) { |
|
| 280 | + if (time() >= _TIME_OUT) { |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + if ($desc = $trouver_table($table)) { |
|
| 284 | + $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | + if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | + spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | + |
|
| 288 | + // cas particulier spip_urls : |
|
| 289 | + // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | + if ($table == 'spip_urls') { |
|
| 291 | + // par date DESC pour conserver les urls les plus recentes |
|
| 292 | + $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | + $urls = []; |
|
| 294 | + foreach ($data as $d) { |
|
| 295 | + $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | + if (!isset($urls[$key])) { |
|
| 297 | + $urls[$key] = true; |
|
| 298 | + } else { |
|
| 299 | + spip_log( |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | + ); |
|
| 303 | + sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + foreach ($desc['field'] as $field => $type) { |
|
| 308 | + if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | + $trouver_table(''); |
|
| 312 | + $new_desc = $trouver_table($table); |
|
| 313 | + spip_log( |
|
| 314 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | + ); |
|
| 317 | + continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // forcer le vidage de cache |
|
| 325 | + $trouver_table(''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | - ['maj_collation_sqlite'], |
|
| 330 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | + ['maj_collation_sqlite'], |
|
| 333 | 333 | ]; |
| 334 | 334 | |
| 335 | 335 | $GLOBALS['maj'][19268] = [ |
| 336 | - ['supprimer_toutes_sessions'], |
|
| 336 | + ['supprimer_toutes_sessions'], |
|
| 337 | 337 | ]; |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | * Obligera tous les auteurs à se reconnecter ! |
| 343 | 343 | **/ |
| 344 | 344 | function supprimer_toutes_sessions() { |
| 345 | - spip_log('supprimer sessions auteur'); |
|
| 346 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | - while (($f = readdir($dir)) !== false) { |
|
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | - if (time() >= _TIME_OUT) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 345 | + spip_log('supprimer sessions auteur'); |
|
| 346 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | + while (($f = readdir($dir)) !== false) { |
|
| 348 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | + if (time() >= _TIME_OUT) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
| 61 | 61 | |
| 62 | 62 | $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
| 63 | - $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 63 | + $pivots = ($exceptions_pluriel[$pivot] ?? $pivot.'s'); |
|
| 64 | + $liens = 'spip_'.$pivots.'_liens'; |
|
| 65 | + $id_pivot = 'id_'.$pivot; |
|
| 66 | 66 | // Creer spip_auteurs_liens |
| 67 | 67 | global $tables_auxiliaires; |
| 68 | 68 | if (!$l) { |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $l = preg_replace(',[^\w],', '', $l); // securite |
| 75 | 75 | $primary = "id_$l"; |
| 76 | 76 | $objet = ($l == 'syndic' ? 'site' : $l); |
| 77 | - $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 77 | + $ls = ($exceptions_pluriel[$l] ?? $l.'s'); |
|
| 78 | + $ancienne_table = 'spip_'.$pivots.'_'.$ls; |
|
| 79 | 79 | $pool = 400; |
| 80 | 80 | |
| 81 | 81 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
| 112 | 112 | $insert = []; |
| 113 | 113 | foreach ($ids as $id) { |
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=".intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=".intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | 116 | $n += is_countable($t) ? count($t) : 0; |
| 117 | 117 | // empiler en s'assurant a minima de l'unicite |
| 118 | 118 | while ($r = array_shift($t)) { |
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 119 | + $insert[$r[$id_pivot].':'.$r['id_objet']] = $r; |
|
| 120 | 120 | } |
| 121 | 121 | if (count($insert) >= $sub_pool) { |
| 122 | 122 | maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // cas particulier spip_auteurs : retablir le collate binary sur le login |
| 269 | 269 | $desc = $trouver_table('spip_auteurs'); |
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 270 | + spip_log('spip_auteurs : '.var_export($desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 271 | 271 | if (stripos($desc['field']['login'], 'BINARY') === false) { |
| 272 | 272 | spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
| 273 | 273 | sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
| 274 | 274 | $trouver_table(''); |
| 275 | 275 | $new_desc = $trouver_table('spip_auteurs'); |
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : '.var_export($new_desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | foreach ($tables as $table) { |
@@ -292,27 +292,27 @@ discard block |
||
| 292 | 292 | $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
| 293 | 293 | $urls = []; |
| 294 | 294 | foreach ($data as $d) { |
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 295 | + $key = $d['id_parent'].'::'.strtolower($d['url']); |
|
| 296 | 296 | if (!isset($urls[$key])) { |
| 297 | 297 | $urls[$key] = true; |
| 298 | 298 | } else { |
| 299 | 299 | spip_log( |
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : '.serialize($d), |
|
| 301 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 302 | 302 | ); |
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 303 | + sql_delete('spip_urls', 'id_parent='.sql_quote($d['id_parent']).' AND url='.sql_quote($d['url'])); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | foreach ($desc['field'] as $field => $type) { |
| 308 | 308 | if ($desc['field'][$field] !== $desc_collate[$field]) { |
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field ".$desc_collate[$field]); |
|
| 311 | 311 | $trouver_table(''); |
| 312 | 312 | $new_desc = $trouver_table($table); |
| 313 | 313 | spip_log( |
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 314 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 315 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 316 | 316 | ); |
| 317 | 317 | continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
| 318 | 318 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | 330 | ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | 332 | ['maj_collation_sqlite'], |
| 333 | 333 | ]; |
| 334 | 334 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | spip_log('supprimer sessions auteur'); |
| 346 | 346 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 347 | 347 | while (($f = readdir($dir)) !== false) { |
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 348 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 349 | 349 | if (time() >= _TIME_OUT) { |
| 350 | 350 | return; |
| 351 | 351 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,41 +37,41 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | - # cf. GROS HACK |
|
| 50 | - # recuperer l'eventuel logo charge avant la creation |
|
| 51 | - # ils ont un id = 0-id_auteur de la session |
|
| 52 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | - foreach (['on', 'off'] as $type) { |
|
| 55 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | - if ($logo = reset($logo)) { |
|
| 57 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Enregistre l'envoi dans la BD |
|
| 65 | - $err = ''; |
|
| 66 | - if ($id_auteur > 0) { |
|
| 67 | - $err = auteur_modifier($id_auteur); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ($err) { |
|
| 71 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$id_auteur, $err]; |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | + # cf. GROS HACK |
|
| 50 | + # recuperer l'eventuel logo charge avant la creation |
|
| 51 | + # ils ont un id = 0-id_auteur de la session |
|
| 52 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | + foreach (['on', 'off'] as $type) { |
|
| 55 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | + if ($logo = reset($logo)) { |
|
| 57 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Enregistre l'envoi dans la BD |
|
| 65 | + $err = ''; |
|
| 66 | + if ($id_auteur > 0) { |
|
| 67 | + $err = auteur_modifier($id_auteur); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ($err) { |
|
| 71 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$id_auteur, $err]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -88,44 +88,44 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function auteur_inserer($source = null, $set = null) { |
| 90 | 90 | |
| 91 | - // Ce qu'on va demander comme modifications |
|
| 92 | - $champs = []; |
|
| 93 | - $champs['source'] = $source ?: 'spip'; |
|
| 94 | - |
|
| 95 | - $champs['login'] = ''; |
|
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | - $champs['webmestre'] = 'non'; |
|
| 98 | - if (empty($champs['imessage'])) { |
|
| 99 | - $champs['imessage'] = 'oui'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($set) { |
|
| 103 | - $champs = array_merge($champs, $set); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Envoyer aux plugins |
|
| 107 | - $champs = pipeline( |
|
| 108 | - 'pre_insertion', |
|
| 109 | - [ |
|
| 110 | - 'args' => [ |
|
| 111 | - 'table' => 'spip_auteurs', |
|
| 112 | - ], |
|
| 113 | - 'data' => $champs |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | - pipeline( |
|
| 118 | - 'post_insertion', |
|
| 119 | - [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'table' => 'spip_auteurs', |
|
| 122 | - 'id_objet' => $id_auteur |
|
| 123 | - ], |
|
| 124 | - 'data' => $champs |
|
| 125 | - ] |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - return $id_auteur; |
|
| 91 | + // Ce qu'on va demander comme modifications |
|
| 92 | + $champs = []; |
|
| 93 | + $champs['source'] = $source ?: 'spip'; |
|
| 94 | + |
|
| 95 | + $champs['login'] = ''; |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | + $champs['webmestre'] = 'non'; |
|
| 98 | + if (empty($champs['imessage'])) { |
|
| 99 | + $champs['imessage'] = 'oui'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($set) { |
|
| 103 | + $champs = array_merge($champs, $set); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Envoyer aux plugins |
|
| 107 | + $champs = pipeline( |
|
| 108 | + 'pre_insertion', |
|
| 109 | + [ |
|
| 110 | + 'args' => [ |
|
| 111 | + 'table' => 'spip_auteurs', |
|
| 112 | + ], |
|
| 113 | + 'data' => $champs |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | + pipeline( |
|
| 118 | + 'post_insertion', |
|
| 119 | + [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'table' => 'spip_auteurs', |
|
| 122 | + 'id_objet' => $id_auteur |
|
| 123 | + ], |
|
| 124 | + 'data' => $champs |
|
| 125 | + ] |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + return $id_auteur; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -150,70 +150,70 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 152 | 152 | |
| 153 | - include_spip('inc/modifier'); |
|
| 154 | - include_spip('inc/filtres'); |
|
| 155 | - $c = collecter_requests( |
|
| 156 | - // white list |
|
| 157 | - objet_info('auteur', 'champs_editables'), |
|
| 158 | - // black list |
|
| 159 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | - // donnees eventuellement fournies |
|
| 161 | - $set |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - if ( |
|
| 165 | - $err = objet_modifier_champs( |
|
| 166 | - 'auteur', |
|
| 167 | - $id_auteur, |
|
| 168 | - [ |
|
| 169 | - 'data' => $set, |
|
| 170 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | - ], |
|
| 172 | - $c |
|
| 173 | - ) |
|
| 174 | - ) { |
|
| 175 | - return $err; |
|
| 176 | - } |
|
| 177 | - $session = $c; |
|
| 178 | - |
|
| 179 | - $err = ''; |
|
| 180 | - if (!$force_update) { |
|
| 181 | - // Modification de statut, changement de rubrique ? |
|
| 182 | - $c = collecter_requests( |
|
| 183 | - // white list |
|
| 184 | - [ |
|
| 185 | - 'statut', |
|
| 186 | - 'new_login', |
|
| 187 | - 'new_pass', |
|
| 188 | - 'login', |
|
| 189 | - 'pass', |
|
| 190 | - 'webmestre', |
|
| 191 | - 'restreintes', |
|
| 192 | - 'id_parent' |
|
| 193 | - ], |
|
| 194 | - // black list |
|
| 195 | - [], |
|
| 196 | - // donnees eventuellement fournies |
|
| 197 | - $set |
|
| 198 | - ); |
|
| 199 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | - $c['login'] = $c['new_login']; |
|
| 201 | - } |
|
| 202 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | - $c['pass'] = $c['new_pass']; |
|
| 204 | - } |
|
| 205 | - $err = auteur_instituer($id_auteur, $c); |
|
| 206 | - $session = array_merge($session, $c); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // .. mettre a jour les sessions de cet auteur |
|
| 210 | - include_spip('inc/session'); |
|
| 211 | - $session['id_auteur'] = $id_auteur; |
|
| 212 | - unset($session['new_login']); |
|
| 213 | - unset($session['new_pass']); |
|
| 214 | - actualiser_sessions($session); |
|
| 215 | - |
|
| 216 | - return $err; |
|
| 153 | + include_spip('inc/modifier'); |
|
| 154 | + include_spip('inc/filtres'); |
|
| 155 | + $c = collecter_requests( |
|
| 156 | + // white list |
|
| 157 | + objet_info('auteur', 'champs_editables'), |
|
| 158 | + // black list |
|
| 159 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | + // donnees eventuellement fournies |
|
| 161 | + $set |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + if ( |
|
| 165 | + $err = objet_modifier_champs( |
|
| 166 | + 'auteur', |
|
| 167 | + $id_auteur, |
|
| 168 | + [ |
|
| 169 | + 'data' => $set, |
|
| 170 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | + ], |
|
| 172 | + $c |
|
| 173 | + ) |
|
| 174 | + ) { |
|
| 175 | + return $err; |
|
| 176 | + } |
|
| 177 | + $session = $c; |
|
| 178 | + |
|
| 179 | + $err = ''; |
|
| 180 | + if (!$force_update) { |
|
| 181 | + // Modification de statut, changement de rubrique ? |
|
| 182 | + $c = collecter_requests( |
|
| 183 | + // white list |
|
| 184 | + [ |
|
| 185 | + 'statut', |
|
| 186 | + 'new_login', |
|
| 187 | + 'new_pass', |
|
| 188 | + 'login', |
|
| 189 | + 'pass', |
|
| 190 | + 'webmestre', |
|
| 191 | + 'restreintes', |
|
| 192 | + 'id_parent' |
|
| 193 | + ], |
|
| 194 | + // black list |
|
| 195 | + [], |
|
| 196 | + // donnees eventuellement fournies |
|
| 197 | + $set |
|
| 198 | + ); |
|
| 199 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | + $c['login'] = $c['new_login']; |
|
| 201 | + } |
|
| 202 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | + $c['pass'] = $c['new_pass']; |
|
| 204 | + } |
|
| 205 | + $err = auteur_instituer($id_auteur, $c); |
|
| 206 | + $session = array_merge($session, $c); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // .. mettre a jour les sessions de cet auteur |
|
| 210 | + include_spip('inc/session'); |
|
| 211 | + $session['id_auteur'] = $id_auteur; |
|
| 212 | + unset($session['new_login']); |
|
| 213 | + unset($session['new_pass']); |
|
| 214 | + actualiser_sessions($session); |
|
| 215 | + |
|
| 216 | + return $err; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 237 | - include_spip('action/editer_liens'); |
|
| 237 | + include_spip('action/editer_liens'); |
|
| 238 | 238 | |
| 239 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 239 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function auteur_dissocier($id_auteur, $objets) { |
| 258 | - include_spip('action/editer_liens'); |
|
| 258 | + include_spip('action/editer_liens'); |
|
| 259 | 259 | |
| 260 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 260 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * @return bool|int |
| 279 | 279 | */ |
| 280 | 280 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 281 | - include_spip('action/editer_liens'); |
|
| 281 | + include_spip('action/editer_liens'); |
|
| 282 | 282 | |
| 283 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 283 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -299,139 +299,139 @@ discard block |
||
| 299 | 299 | * @return bool|string |
| 300 | 300 | */ |
| 301 | 301 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 302 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | - $champs = []; |
|
| 307 | - |
|
| 308 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | - $champs['login'] = $c['login']; |
|
| 311 | - } |
|
| 312 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | - $champs['pass'] = $c['pass']; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | - |
|
| 318 | - if ( |
|
| 319 | - isset($c['statut']) |
|
| 320 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | - ) { |
|
| 322 | - $statut = $champs['statut'] = $c['statut']; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Restreindre avant de declarer l'auteur |
|
| 326 | - // (section critique sur les droits) |
|
| 327 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | - if (is_array($c['restreintes'])) { |
|
| 329 | - $c['restreintes'][] = $c['id_parent']; |
|
| 330 | - } else { |
|
| 331 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( |
|
| 336 | - isset($c['webmestre']) |
|
| 337 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | - ) { |
|
| 339 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - // Envoyer aux plugins |
|
| 348 | - $champs = pipeline( |
|
| 349 | - 'pre_edition', |
|
| 350 | - [ |
|
| 351 | - 'args' => [ |
|
| 352 | - 'table' => 'spip_auteurs', |
|
| 353 | - 'id_objet' => $id_auteur, |
|
| 354 | - 'action' => 'instituer', |
|
| 355 | - 'statut_ancien' => $statut_ancien, |
|
| 356 | - ], |
|
| 357 | - 'data' => $champs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - if ( |
|
| 362 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | - ) { |
|
| 365 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | - $rubriques = array_unique($rubriques); |
|
| 367 | - $rubriques = array_diff($rubriques, [0]); |
|
| 368 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - $flag_ecrire_acces = false; |
|
| 373 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | - // avant les autres ecritures en base |
|
| 375 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | - include_spip('inc/auth'); |
|
| 378 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - unset($champs['login']); |
|
| 390 | - unset($champs['pass']); |
|
| 391 | - $flag_ecrire_acces = true; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | - } |
|
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | - |
|
| 399 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | - if ( |
|
| 401 | - $flag_ecrire_acces |
|
| 402 | - or isset($champs['statut']) |
|
| 403 | - ) { |
|
| 404 | - include_spip('inc/acces'); |
|
| 405 | - ecrire_acces(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // Invalider les caches |
|
| 409 | - include_spip('inc/invalideur'); |
|
| 410 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | - |
|
| 412 | - // Pipeline |
|
| 413 | - pipeline( |
|
| 414 | - 'post_edition', |
|
| 415 | - [ |
|
| 416 | - 'args' => [ |
|
| 417 | - 'table' => 'spip_auteurs', |
|
| 418 | - 'id_objet' => $id_auteur, |
|
| 419 | - 'action' => 'instituer', |
|
| 420 | - 'statut_ancien' => $statut_ancien, |
|
| 421 | - ], |
|
| 422 | - 'data' => $champs |
|
| 423 | - ] |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - // Notifications |
|
| 428 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | - $notifications( |
|
| 430 | - 'instituerauteur', |
|
| 431 | - $id_auteur, |
|
| 432 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 302 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | + $champs = []; |
|
| 307 | + |
|
| 308 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | + $champs['login'] = $c['login']; |
|
| 311 | + } |
|
| 312 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | + $champs['pass'] = $c['pass']; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | + |
|
| 318 | + if ( |
|
| 319 | + isset($c['statut']) |
|
| 320 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | + ) { |
|
| 322 | + $statut = $champs['statut'] = $c['statut']; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Restreindre avant de declarer l'auteur |
|
| 326 | + // (section critique sur les droits) |
|
| 327 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | + if (is_array($c['restreintes'])) { |
|
| 329 | + $c['restreintes'][] = $c['id_parent']; |
|
| 330 | + } else { |
|
| 331 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( |
|
| 336 | + isset($c['webmestre']) |
|
| 337 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | + ) { |
|
| 339 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + // Envoyer aux plugins |
|
| 348 | + $champs = pipeline( |
|
| 349 | + 'pre_edition', |
|
| 350 | + [ |
|
| 351 | + 'args' => [ |
|
| 352 | + 'table' => 'spip_auteurs', |
|
| 353 | + 'id_objet' => $id_auteur, |
|
| 354 | + 'action' => 'instituer', |
|
| 355 | + 'statut_ancien' => $statut_ancien, |
|
| 356 | + ], |
|
| 357 | + 'data' => $champs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + if ( |
|
| 362 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | + ) { |
|
| 365 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | + $rubriques = array_unique($rubriques); |
|
| 367 | + $rubriques = array_diff($rubriques, [0]); |
|
| 368 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + $flag_ecrire_acces = false; |
|
| 373 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | + // avant les autres ecritures en base |
|
| 375 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | + include_spip('inc/auth'); |
|
| 378 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + unset($champs['login']); |
|
| 390 | + unset($champs['pass']); |
|
| 391 | + $flag_ecrire_acces = true; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | + } |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | + |
|
| 399 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | + if ( |
|
| 401 | + $flag_ecrire_acces |
|
| 402 | + or isset($champs['statut']) |
|
| 403 | + ) { |
|
| 404 | + include_spip('inc/acces'); |
|
| 405 | + ecrire_acces(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // Invalider les caches |
|
| 409 | + include_spip('inc/invalideur'); |
|
| 410 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | + |
|
| 412 | + // Pipeline |
|
| 413 | + pipeline( |
|
| 414 | + 'post_edition', |
|
| 415 | + [ |
|
| 416 | + 'args' => [ |
|
| 417 | + 'table' => 'spip_auteurs', |
|
| 418 | + 'id_objet' => $id_auteur, |
|
| 419 | + 'action' => 'instituer', |
|
| 420 | + 'statut_ancien' => $statut_ancien, |
|
| 421 | + ], |
|
| 422 | + 'data' => $champs |
|
| 423 | + ] |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + // Notifications |
|
| 428 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | + $notifications( |
|
| 430 | + 'instituerauteur', |
|
| 431 | + $id_auteur, |
|
| 432 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 437 | 437 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $champs['source'] = $source ?: 'spip'; |
| 94 | 94 | |
| 95 | 95 | $champs['login'] = ''; |
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | 97 | $champs['webmestre'] = 'non'; |
| 98 | 98 | if (empty($champs['imessage'])) { |
| 99 | 99 | $champs['imessage'] = 'oui'; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $champs['pass'] = $c['pass']; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 317 | 317 | |
| 318 | 318 | if ( |
| 319 | 319 | isset($c['statut']) |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | // commencer par traiter les cas particuliers des logins et pass |
| 374 | 374 | // avant les autres ecritures en base |
| 375 | 375 | if (isset($champs['login']) or isset($champs['pass'])) { |
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 377 | 377 | include_spip('inc/auth'); |
| 378 | 378 | if (isset($champs['login']) and strlen($champs['login'])) { |
| 379 | 379 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | if (isset($champs['pass']) and strlen($champs['pass'])) { |
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 385 | 385 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
| 386 | 386 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 387 | 387 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | if (!(is_countable($champs) ? count($champs) : 0)) { |
| 395 | 395 | return implode(' ', array_map('_T', $erreurs)); |
| 396 | 396 | } |
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 398 | 398 | |
| 399 | 399 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 400 | 400 | if ( |