@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Surligne |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -35,43 +35,43 @@ discard block |
||
| 35 | 35 | * Page HTML |
| 36 | 36 | **/ |
| 37 | 37 | function surligner_mots($page, $surcharge_surligne = '') { |
| 38 | - $surlignejs_engines = [ |
|
| 39 | - [ |
|
| 40 | - ',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i', |
|
| 41 | - ',recherche=([^&]+),i' |
|
| 42 | - ], //SPIP |
|
| 43 | - [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google |
|
| 44 | - [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo |
|
| 45 | - [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN |
|
| 46 | - [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live |
|
| 47 | - [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL |
|
| 48 | - [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com |
|
| 49 | - [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista |
|
| 50 | - [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster |
|
| 51 | - [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos |
|
| 52 | - [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb |
|
| 53 | - [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati |
|
| 54 | - ]; |
|
| 38 | + $surlignejs_engines = [ |
|
| 39 | + [ |
|
| 40 | + ',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i', |
|
| 41 | + ',recherche=([^&]+),i' |
|
| 42 | + ], //SPIP |
|
| 43 | + [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google |
|
| 44 | + [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo |
|
| 45 | + [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN |
|
| 46 | + [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live |
|
| 47 | + [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL |
|
| 48 | + [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com |
|
| 49 | + [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista |
|
| 50 | + [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster |
|
| 51 | + [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos |
|
| 52 | + [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb |
|
| 53 | + [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati |
|
| 54 | + ]; |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - $ref = $_SERVER['HTTP_REFERER'] ?? null; |
|
| 58 | - //avoid a js injection |
|
| 59 | - if ($surcharge_surligne) { |
|
| 60 | - $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne); |
|
| 61 | - $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne); |
|
| 62 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | - include_spip('inc/charsets'); |
|
| 64 | - if (!is_utf8($surcharge_surligne)) { |
|
| 65 | - $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | - } |
|
| 70 | - foreach ($surlignejs_engines as $engine) { |
|
| 71 | - if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 72 | - //good referrer found or var_recherche is not null |
|
| 73 | - include_spip('inc/filtres'); |
|
| 74 | - $script = " |
|
| 57 | + $ref = $_SERVER['HTTP_REFERER'] ?? null; |
|
| 58 | + //avoid a js injection |
|
| 59 | + if ($surcharge_surligne) { |
|
| 60 | + $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne); |
|
| 61 | + $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne); |
|
| 62 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | + include_spip('inc/charsets'); |
|
| 64 | + if (!is_utf8($surcharge_surligne)) { |
|
| 65 | + $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | + } |
|
| 70 | + foreach ($surlignejs_engines as $engine) { |
|
| 71 | + if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 72 | + //good referrer found or var_recherche is not null |
|
| 73 | + include_spip('inc/filtres'); |
|
| 74 | + $script = " |
|
| 75 | 75 | <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script> |
| 76 | 76 | <script type='text/javascript'> |
| 77 | 77 | var highlighter = function() { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i], |
| 84 | 84 | highlight:'.surlignable', |
| 85 | 85 | nohighlight:'.pas_surlignable'" . |
| 86 | - ($surcharge_surligne ? ", |
|
| 86 | + ($surcharge_surligne ? ", |
|
| 87 | 87 | keys:'$surcharge_surligne'" : '') . ', |
| 88 | 88 | min_length: 3 |
| 89 | 89 | }); |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | }; |
| 95 | 95 | </script> |
| 96 | 96 | '; |
| 97 | - // on l'insere juste avant </head>, sinon tout en bas |
|
| 98 | - if (is_null($l = strpos($page, '</head>'))) { |
|
| 99 | - $l = strlen($page); |
|
| 100 | - } |
|
| 101 | - $page = substr_replace($page, $script, $l, 0); |
|
| 102 | - break; |
|
| 103 | - } |
|
| 104 | - } |
|
| 97 | + // on l'insere juste avant </head>, sinon tout en bas |
|
| 98 | + if (is_null($l = strpos($page, '</head>'))) { |
|
| 99 | + $l = strlen($page); |
|
| 100 | + } |
|
| 101 | + $page = substr_replace($page, $script, $l, 0); |
|
| 102 | + break; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - return $page; |
|
| 106 | + return $page; |
|
| 107 | 107 | } |
@@ -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 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | * @return bool|null|void |
| 41 | 41 | */ |
| 42 | 42 | function inc_session_dist($auteur = false) { |
| 43 | - if (is_numeric($auteur)) { |
|
| 44 | - return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | - } else { |
|
| 46 | - if (is_array($auteur)) { |
|
| 47 | - return ajouter_session($auteur); |
|
| 48 | - } else { |
|
| 49 | - return verifier_session($auteur); |
|
| 50 | - } |
|
| 51 | - } |
|
| 43 | + if (is_numeric($auteur)) { |
|
| 44 | + return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | + } else { |
|
| 46 | + if (is_array($auteur)) { |
|
| 47 | + return ajouter_session($auteur); |
|
| 48 | + } else { |
|
| 49 | + return verifier_session($auteur); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,36 +77,36 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function supprimer_sessions($id_auteur, $toutes = true, $actives = true) { |
| 79 | 79 | |
| 80 | - $nb_files = 0; |
|
| 81 | - $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | - spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | - if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | - $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | - while (($f = readdir($dir)) !== false) { |
|
| 89 | - $nb_files++; |
|
| 90 | - if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 92 | - if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | - spip_unlink($f); |
|
| 94 | - } |
|
| 95 | - // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | - // cf http://core.spip.org/issues/3276 |
|
| 97 | - elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | - spip_unlink($f); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - verifier_session(); |
|
| 105 | - spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // forcer le recalcul de la session courante |
|
| 109 | - spip_session(true); |
|
| 80 | + $nb_files = 0; |
|
| 81 | + $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | + spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | + if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | + $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | + while (($f = readdir($dir)) !== false) { |
|
| 89 | + $nb_files++; |
|
| 90 | + if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | + $f = _DIR_SESSIONS . $f; |
|
| 92 | + if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | + spip_unlink($f); |
|
| 94 | + } |
|
| 95 | + // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | + // cf http://core.spip.org/issues/3276 |
|
| 97 | + elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | + spip_unlink($f); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + verifier_session(); |
|
| 105 | + spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // forcer le recalcul de la session courante |
|
| 109 | + spip_session(true); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -124,125 +124,125 @@ discard block |
||
| 124 | 124 | * @return bool|string |
| 125 | 125 | */ |
| 126 | 126 | function ajouter_session($auteur) { |
| 127 | - // Si le client a deja une session valide pour son id_auteur |
|
| 128 | - // on conserve le meme fichier |
|
| 129 | - |
|
| 130 | - // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | - // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | - |
|
| 134 | - // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | - // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | - if (!$id_auteur) { |
|
| 137 | - // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | - $auteur_verif = $auteur; |
|
| 139 | - if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | - unset($auteur_verif['id_auteur']); |
|
| 141 | - } |
|
| 142 | - if (isset($auteur_verif['hash_env'])) { |
|
| 143 | - unset($auteur_verif['hash_env']); |
|
| 144 | - } |
|
| 145 | - if (isset($auteur_verif['ip_change'])) { |
|
| 146 | - unset($auteur_verif['ip_change']); |
|
| 147 | - } |
|
| 148 | - if (isset($auteur_verif['date_session'])) { |
|
| 149 | - unset($auteur_verif['date_session']); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | - foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | - if ($valeur === null) { |
|
| 155 | - unset($auteur_verif[$variable]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | - if (!$auteur_verif) { |
|
| 161 | - if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | - unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | - } |
|
| 164 | - if (isset($_COOKIE['spip_session'])) { |
|
| 165 | - unset($_COOKIE['spip_session']); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ( |
|
| 173 | - !isset($_COOKIE['spip_session']) |
|
| 174 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | - ) { |
|
| 176 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | - // On s'assure d'avoir au moins ces valeurs |
|
| 181 | - $auteur['id_auteur'] = $id_auteur; |
|
| 182 | - if (!isset($auteur['hash_env'])) { |
|
| 183 | - $auteur['hash_env'] = hash_env(); |
|
| 184 | - } |
|
| 185 | - if (!isset($auteur['ip_change'])) { |
|
| 186 | - $auteur['ip_change'] = false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!isset($auteur['date_session'])) { |
|
| 190 | - $auteur['date_session'] = time(); |
|
| 191 | - } |
|
| 192 | - if ( |
|
| 193 | - isset($auteur['prefs']) |
|
| 194 | - and is_string($auteur['prefs']) |
|
| 195 | - and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | - ) { |
|
| 197 | - $auteur['prefs'] = $prefs; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $fichier_session = ''; |
|
| 201 | - |
|
| 202 | - // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | - if (!$id_auteur) { |
|
| 204 | - spip_php_session_start(); |
|
| 205 | - $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | - } else { |
|
| 207 | - $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | - if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | - spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | - include_spip('inc/minipres'); |
|
| 211 | - echo minipres(); |
|
| 212 | - exit; |
|
| 213 | - } |
|
| 214 | - // verifier et limiter le nombre maxi de sessions |
|
| 215 | - // https://core.spip.net/issues/3807 |
|
| 216 | - lister_sessions_auteur($id_auteur); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // poser le cookie de session SPIP |
|
| 220 | - include_spip('inc/cookie'); |
|
| 221 | - $duree = definir_duree_cookie_session($auteur); |
|
| 222 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | - 'expires' => time() + $duree |
|
| 224 | - ]); |
|
| 225 | - spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | - |
|
| 227 | - // Si on est admin, poser le cookie de correspondance |
|
| 228 | - if (!function_exists('autoriser')) { |
|
| 229 | - include_spip('inc/autoriser'); |
|
| 230 | - } |
|
| 231 | - if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | - ]); |
|
| 235 | - } // sinon le supprimer ... |
|
| 236 | - else { |
|
| 237 | - spip_setcookie('spip_admin', '', [ |
|
| 238 | - 'expires' => 1 |
|
| 239 | - ]); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | - # supprimer_sessions(0, true, false); |
|
| 244 | - |
|
| 245 | - return $_COOKIE['spip_session']; |
|
| 127 | + // Si le client a deja une session valide pour son id_auteur |
|
| 128 | + // on conserve le meme fichier |
|
| 129 | + |
|
| 130 | + // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | + // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | + |
|
| 134 | + // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | + // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | + if (!$id_auteur) { |
|
| 137 | + // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | + $auteur_verif = $auteur; |
|
| 139 | + if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | + unset($auteur_verif['id_auteur']); |
|
| 141 | + } |
|
| 142 | + if (isset($auteur_verif['hash_env'])) { |
|
| 143 | + unset($auteur_verif['hash_env']); |
|
| 144 | + } |
|
| 145 | + if (isset($auteur_verif['ip_change'])) { |
|
| 146 | + unset($auteur_verif['ip_change']); |
|
| 147 | + } |
|
| 148 | + if (isset($auteur_verif['date_session'])) { |
|
| 149 | + unset($auteur_verif['date_session']); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | + foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | + if ($valeur === null) { |
|
| 155 | + unset($auteur_verif[$variable]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | + if (!$auteur_verif) { |
|
| 161 | + if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | + unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | + } |
|
| 164 | + if (isset($_COOKIE['spip_session'])) { |
|
| 165 | + unset($_COOKIE['spip_session']); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ( |
|
| 173 | + !isset($_COOKIE['spip_session']) |
|
| 174 | + or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | + ) { |
|
| 176 | + $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | + // On s'assure d'avoir au moins ces valeurs |
|
| 181 | + $auteur['id_auteur'] = $id_auteur; |
|
| 182 | + if (!isset($auteur['hash_env'])) { |
|
| 183 | + $auteur['hash_env'] = hash_env(); |
|
| 184 | + } |
|
| 185 | + if (!isset($auteur['ip_change'])) { |
|
| 186 | + $auteur['ip_change'] = false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!isset($auteur['date_session'])) { |
|
| 190 | + $auteur['date_session'] = time(); |
|
| 191 | + } |
|
| 192 | + if ( |
|
| 193 | + isset($auteur['prefs']) |
|
| 194 | + and is_string($auteur['prefs']) |
|
| 195 | + and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | + ) { |
|
| 197 | + $auteur['prefs'] = $prefs; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $fichier_session = ''; |
|
| 201 | + |
|
| 202 | + // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | + if (!$id_auteur) { |
|
| 204 | + spip_php_session_start(); |
|
| 205 | + $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | + } else { |
|
| 207 | + $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | + if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | + spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | + include_spip('inc/minipres'); |
|
| 211 | + echo minipres(); |
|
| 212 | + exit; |
|
| 213 | + } |
|
| 214 | + // verifier et limiter le nombre maxi de sessions |
|
| 215 | + // https://core.spip.net/issues/3807 |
|
| 216 | + lister_sessions_auteur($id_auteur); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // poser le cookie de session SPIP |
|
| 220 | + include_spip('inc/cookie'); |
|
| 221 | + $duree = definir_duree_cookie_session($auteur); |
|
| 222 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | + 'expires' => time() + $duree |
|
| 224 | + ]); |
|
| 225 | + spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | + |
|
| 227 | + // Si on est admin, poser le cookie de correspondance |
|
| 228 | + if (!function_exists('autoriser')) { |
|
| 229 | + include_spip('inc/autoriser'); |
|
| 230 | + } |
|
| 231 | + if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | + spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | + ]); |
|
| 235 | + } // sinon le supprimer ... |
|
| 236 | + else { |
|
| 237 | + spip_setcookie('spip_admin', '', [ |
|
| 238 | + 'expires' => 1 |
|
| 239 | + ]); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | + # supprimer_sessions(0, true, false); |
|
| 244 | + |
|
| 245 | + return $_COOKIE['spip_session']; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -262,15 +262,15 @@ discard block |
||
| 262 | 262 | * Durée en secondes |
| 263 | 263 | **/ |
| 264 | 264 | function definir_duree_cookie_session($auteur) { |
| 265 | - $coef = 2; |
|
| 266 | - if (isset($auteur['cookie'])) { |
|
| 267 | - if (is_numeric($auteur['cookie'])) { |
|
| 268 | - $coef = $auteur['cookie']; |
|
| 269 | - } else { |
|
| 270 | - $coef = 20; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 265 | + $coef = 2; |
|
| 266 | + if (isset($auteur['cookie'])) { |
|
| 267 | + if (is_numeric($auteur['cookie'])) { |
|
| 268 | + $coef = $auteur['cookie']; |
|
| 269 | + } else { |
|
| 270 | + $coef = 20; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -290,91 +290,91 @@ discard block |
||
| 290 | 290 | * @return bool|int|null |
| 291 | 291 | */ |
| 292 | 292 | function verifier_session($change = false) { |
| 293 | - // si pas de cookie, c'est fichu |
|
| 294 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $fichier_session = ''; |
|
| 299 | - |
|
| 300 | - // est-ce une session anonyme ? |
|
| 301 | - if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | - spip_php_session_start(); |
|
| 303 | - if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | - } else { |
|
| 308 | - // Tester avec alea courant |
|
| 309 | - $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | - if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | - include($fichier_session); |
|
| 312 | - } else { |
|
| 313 | - // Sinon, tester avec alea precedent |
|
| 314 | - $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | - if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Renouveler la session avec l'alea courant |
|
| 320 | - include($fichier_session); |
|
| 321 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | - spip_unlink($fichier_session); |
|
| 323 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | - // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | - // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | - |
|
| 331 | - if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | - // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | - // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | - // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | - // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | - if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | - if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | - define('_SESSION_REJOUER', true); |
|
| 344 | - $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | - } else { |
|
| 347 | - if ($change) { |
|
| 348 | - spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - if ($change) { |
|
| 353 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | - if ($fichier_session) { |
|
| 355 | - spip_unlink($fichier_session); |
|
| 356 | - } |
|
| 357 | - $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | - unset($_COOKIE['spip_session']); |
|
| 359 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | - if ( |
|
| 365 | - isset($GLOBALS['visiteur_session']) |
|
| 366 | - and defined('_AGE_SESSION_MAX') |
|
| 367 | - and _AGE_SESSION_MAX > 0 |
|
| 368 | - and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | - ) { |
|
| 370 | - unset($GLOBALS['visiteur_session']); |
|
| 371 | - |
|
| 372 | - return false; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | - : null; |
|
| 293 | + // si pas de cookie, c'est fichu |
|
| 294 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $fichier_session = ''; |
|
| 299 | + |
|
| 300 | + // est-ce une session anonyme ? |
|
| 301 | + if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | + spip_php_session_start(); |
|
| 303 | + if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | + } else { |
|
| 308 | + // Tester avec alea courant |
|
| 309 | + $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | + if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | + include($fichier_session); |
|
| 312 | + } else { |
|
| 313 | + // Sinon, tester avec alea precedent |
|
| 314 | + $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | + if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Renouveler la session avec l'alea courant |
|
| 320 | + include($fichier_session); |
|
| 321 | + spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | + spip_unlink($fichier_session); |
|
| 323 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | + // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | + // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | + |
|
| 331 | + if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | + // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | + // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | + // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | + // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | + if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | + if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | + define('_SESSION_REJOUER', true); |
|
| 344 | + $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | + } else { |
|
| 347 | + if ($change) { |
|
| 348 | + spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + if ($change) { |
|
| 353 | + spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | + if ($fichier_session) { |
|
| 355 | + spip_unlink($fichier_session); |
|
| 356 | + } |
|
| 357 | + $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | + unset($_COOKIE['spip_session']); |
|
| 359 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | + if ( |
|
| 365 | + isset($GLOBALS['visiteur_session']) |
|
| 366 | + and defined('_AGE_SESSION_MAX') |
|
| 367 | + and _AGE_SESSION_MAX > 0 |
|
| 368 | + and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | + ) { |
|
| 370 | + unset($GLOBALS['visiteur_session']); |
|
| 371 | + |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | + : null; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * Valeur, si trouvée, `null` sinon. |
| 390 | 390 | */ |
| 391 | 391 | function session_get($nom) { |
| 392 | - return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 392 | + return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -405,32 +405,32 @@ discard block |
||
| 405 | 405 | * @return void|array |
| 406 | 406 | */ |
| 407 | 407 | function session_set($nom, $val = null) { |
| 408 | - static $remove = []; |
|
| 409 | - static $actualiser_sessions = false; |
|
| 410 | - if ($nom === false) { |
|
| 411 | - return $remove; |
|
| 412 | - } |
|
| 413 | - if (is_null($val)) { |
|
| 414 | - // rien a faire |
|
| 415 | - if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | - return; |
|
| 417 | - } |
|
| 418 | - unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | - $remove[] = $nom; |
|
| 420 | - } else { |
|
| 421 | - // On ajoute la valeur dans la globale |
|
| 422 | - $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | - if ($remove) { |
|
| 424 | - $remove = array_diff($remove, [$nom]); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - if (!$actualiser_sessions) { |
|
| 428 | - // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | - // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | - register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | - $actualiser_sessions = true; |
|
| 433 | - } |
|
| 408 | + static $remove = []; |
|
| 409 | + static $actualiser_sessions = false; |
|
| 410 | + if ($nom === false) { |
|
| 411 | + return $remove; |
|
| 412 | + } |
|
| 413 | + if (is_null($val)) { |
|
| 414 | + // rien a faire |
|
| 415 | + if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | + $remove[] = $nom; |
|
| 420 | + } else { |
|
| 421 | + // On ajoute la valeur dans la globale |
|
| 422 | + $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | + if ($remove) { |
|
| 424 | + $remove = array_diff($remove, [$nom]); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + if (!$actualiser_sessions) { |
|
| 428 | + // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | + // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | + register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | + $actualiser_sessions = true; |
|
| 433 | + } |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | * @uses actualiser_sessions() |
| 440 | 440 | */ |
| 441 | 441 | function terminer_actualiser_sessions() { |
| 442 | - // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | - chdir(_ROOT_CWD); |
|
| 444 | - // recuperer les variables a effacer |
|
| 445 | - $remove = session_set(false); |
|
| 446 | - // mettre a jour toutes les sessions |
|
| 447 | - actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 442 | + // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | + chdir(_ROOT_CWD); |
|
| 444 | + // recuperer les variables a effacer |
|
| 445 | + $remove = session_set(false); |
|
| 446 | + // mettre a jour toutes les sessions |
|
| 447 | + actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -469,83 +469,83 @@ discard block |
||
| 469 | 469 | */ |
| 470 | 470 | function actualiser_sessions($auteur, $supprimer_cles = []) { |
| 471 | 471 | |
| 472 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | - $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | - |
|
| 475 | - // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | - $fichier_session_courante = ''; |
|
| 477 | - if ($id_auteur == $id_auteur_courant) { |
|
| 478 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | - ajouter_session($auteur); |
|
| 480 | - if ($id_auteur) { |
|
| 481 | - $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | - if (!$id_auteur) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - // les préférences sont désérialisées, toujours. |
|
| 491 | - // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | - if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | - $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | - if (!is_array($auteur['prefs'])) { |
|
| 495 | - $auteur['prefs'] = []; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | - $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | - |
|
| 502 | - // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | - // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | - // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | - $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | - |
|
| 507 | - // 1ere passe : lire et fusionner les sessions |
|
| 508 | - foreach ($sessions as $session) { |
|
| 509 | - $GLOBALS['visiteur_session'] = []; |
|
| 510 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | - if ( |
|
| 512 | - $session !== $fichier_session_courante |
|
| 513 | - and @file_exists($session) |
|
| 514 | - ) { |
|
| 515 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | - |
|
| 517 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | - foreach ($supprimer_cles as $cle) { |
|
| 523 | - unset($auteur[$cle]); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | - |
|
| 528 | - // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | - foreach ($sessions as $session) { |
|
| 530 | - $GLOBALS['visiteur_session'] = []; |
|
| 531 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | - if (@file_exists($session)) { |
|
| 533 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | - |
|
| 535 | - // est-ce que cette session est a mettre a jour ? |
|
| 536 | - if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | - ecrire_fichier_session($session, $auteur); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if ($id_auteur == $id_auteur_courant) { |
|
| 543 | - $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | - } else { |
|
| 546 | - // restaurer l'auteur courant |
|
| 547 | - $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | - } |
|
| 472 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | + $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | + |
|
| 475 | + // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | + $fichier_session_courante = ''; |
|
| 477 | + if ($id_auteur == $id_auteur_courant) { |
|
| 478 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | + ajouter_session($auteur); |
|
| 480 | + if ($id_auteur) { |
|
| 481 | + $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | + if (!$id_auteur) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + // les préférences sont désérialisées, toujours. |
|
| 491 | + // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | + if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | + $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | + if (!is_array($auteur['prefs'])) { |
|
| 495 | + $auteur['prefs'] = []; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | + $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | + |
|
| 502 | + // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | + // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | + // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | + $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | + |
|
| 507 | + // 1ere passe : lire et fusionner les sessions |
|
| 508 | + foreach ($sessions as $session) { |
|
| 509 | + $GLOBALS['visiteur_session'] = []; |
|
| 510 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | + if ( |
|
| 512 | + $session !== $fichier_session_courante |
|
| 513 | + and @file_exists($session) |
|
| 514 | + ) { |
|
| 515 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | + |
|
| 517 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | + foreach ($supprimer_cles as $cle) { |
|
| 523 | + unset($auteur[$cle]); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | + |
|
| 528 | + // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | + foreach ($sessions as $session) { |
|
| 530 | + $GLOBALS['visiteur_session'] = []; |
|
| 531 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | + if (@file_exists($session)) { |
|
| 533 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | + |
|
| 535 | + // est-ce que cette session est a mettre a jour ? |
|
| 536 | + if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | + ecrire_fichier_session($session, $auteur); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if ($id_auteur == $id_auteur_courant) { |
|
| 543 | + $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | + } else { |
|
| 546 | + // restaurer l'auteur courant |
|
| 547 | + $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | + } |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -559,48 +559,48 @@ discard block |
||
| 559 | 559 | */ |
| 560 | 560 | function lister_sessions_auteur($id_auteur, $nb_max = null) { |
| 561 | 561 | |
| 562 | - if (is_null($nb_max)) { |
|
| 563 | - if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | - define('_NB_SESSIONS_MAX', 100); |
|
| 565 | - } |
|
| 566 | - $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // liste des sessions |
|
| 570 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | - |
|
| 572 | - // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | - // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | - if ( |
|
| 575 | - $id_auteur |
|
| 576 | - and count($sessions) > $nb_max |
|
| 577 | - ) { |
|
| 578 | - // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | - // filemtime sur les sessions |
|
| 580 | - $sessions = array_flip($sessions); |
|
| 581 | - |
|
| 582 | - // 1ere passe : lire les filemtime |
|
| 583 | - foreach ($sessions as $session => $z) { |
|
| 584 | - if ( |
|
| 585 | - $d = @filemtime($session) |
|
| 586 | - ) { |
|
| 587 | - $sessions[$session] = $d; |
|
| 588 | - } else { |
|
| 589 | - $sessions[$session] = 0; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - // les plus anciennes en premier |
|
| 594 | - asort($sessions); |
|
| 595 | - |
|
| 596 | - $sessions = array_keys($sessions); |
|
| 597 | - while (count($sessions) > $nb_max) { |
|
| 598 | - $session = array_shift($sessions); |
|
| 599 | - @unlink($session); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - return $sessions; |
|
| 562 | + if (is_null($nb_max)) { |
|
| 563 | + if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | + define('_NB_SESSIONS_MAX', 100); |
|
| 565 | + } |
|
| 566 | + $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // liste des sessions |
|
| 570 | + $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | + |
|
| 572 | + // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | + // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | + if ( |
|
| 575 | + $id_auteur |
|
| 576 | + and count($sessions) > $nb_max |
|
| 577 | + ) { |
|
| 578 | + // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | + // filemtime sur les sessions |
|
| 580 | + $sessions = array_flip($sessions); |
|
| 581 | + |
|
| 582 | + // 1ere passe : lire les filemtime |
|
| 583 | + foreach ($sessions as $session => $z) { |
|
| 584 | + if ( |
|
| 585 | + $d = @filemtime($session) |
|
| 586 | + ) { |
|
| 587 | + $sessions[$session] = $d; |
|
| 588 | + } else { |
|
| 589 | + $sessions[$session] = 0; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + // les plus anciennes en premier |
|
| 594 | + asort($sessions); |
|
| 595 | + |
|
| 596 | + $sessions = array_keys($sessions); |
|
| 597 | + while (count($sessions) > $nb_max) { |
|
| 598 | + $session = array_shift($sessions); |
|
| 599 | + @unlink($session); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + return $sessions; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -614,26 +614,26 @@ discard block |
||
| 614 | 614 | * @return array |
| 615 | 615 | */ |
| 616 | 616 | function preparer_ecriture_session($auteur) { |
| 617 | - $row = $auteur; |
|
| 618 | - |
|
| 619 | - // ne pas enregistrer ces elements de securite |
|
| 620 | - // dans le fichier de session |
|
| 621 | - unset($auteur['pass']); |
|
| 622 | - unset($auteur['htpass']); |
|
| 623 | - unset($auteur['low_sec']); |
|
| 624 | - unset($auteur['alea_actuel']); |
|
| 625 | - unset($auteur['alea_futur']); |
|
| 626 | - |
|
| 627 | - $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | - |
|
| 629 | - // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | - foreach ($auteur as $variable => $valeur) { |
|
| 631 | - if ($valeur === null) { |
|
| 632 | - unset($auteur[$variable]); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return $auteur; |
|
| 617 | + $row = $auteur; |
|
| 618 | + |
|
| 619 | + // ne pas enregistrer ces elements de securite |
|
| 620 | + // dans le fichier de session |
|
| 621 | + unset($auteur['pass']); |
|
| 622 | + unset($auteur['htpass']); |
|
| 623 | + unset($auteur['low_sec']); |
|
| 624 | + unset($auteur['alea_actuel']); |
|
| 625 | + unset($auteur['alea_futur']); |
|
| 626 | + |
|
| 627 | + $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | + |
|
| 629 | + // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | + foreach ($auteur as $variable => $valeur) { |
|
| 631 | + if ($valeur === null) { |
|
| 632 | + unset($auteur[$variable]); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return $auteur; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -645,17 +645,17 @@ discard block |
||
| 645 | 645 | */ |
| 646 | 646 | function ecrire_fichier_session($fichier, $auteur) { |
| 647 | 647 | |
| 648 | - $auteur = preparer_ecriture_session($auteur); |
|
| 648 | + $auteur = preparer_ecriture_session($auteur); |
|
| 649 | 649 | |
| 650 | - // enregistrer les autres donnees du visiteur |
|
| 651 | - $texte = '<' . "?php\n"; |
|
| 652 | - foreach ($auteur as $var => $val) { |
|
| 653 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | - . var_export($val, true) . ";\n"; |
|
| 655 | - } |
|
| 656 | - $texte .= '?' . ">\n"; |
|
| 650 | + // enregistrer les autres donnees du visiteur |
|
| 651 | + $texte = '<' . "?php\n"; |
|
| 652 | + foreach ($auteur as $var => $val) { |
|
| 653 | + $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | + . var_export($val, true) . ";\n"; |
|
| 655 | + } |
|
| 656 | + $texte .= '?' . ">\n"; |
|
| 657 | 657 | |
| 658 | - return ecrire_fichier($fichier, $texte); |
|
| 658 | + return ecrire_fichier($fichier, $texte); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -668,23 +668,23 @@ discard block |
||
| 668 | 668 | */ |
| 669 | 669 | function fichier_session($alea, $tantpis = false) { |
| 670 | 670 | |
| 671 | - include_spip('inc/acces'); |
|
| 672 | - charger_aleas(); |
|
| 671 | + include_spip('inc/acces'); |
|
| 672 | + charger_aleas(); |
|
| 673 | 673 | |
| 674 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | - if (!$tantpis) { |
|
| 676 | - spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | - include_spip('inc/minipres'); |
|
| 678 | - echo minipres(); |
|
| 679 | - } |
|
| 674 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | + if (!$tantpis) { |
|
| 676 | + spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | + include_spip('inc/minipres'); |
|
| 678 | + echo minipres(); |
|
| 679 | + } |
|
| 680 | 680 | |
| 681 | - return ''; // echec mais $tanpis |
|
| 682 | - } else { |
|
| 683 | - $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | - $c = $_COOKIE['spip_session']; |
|
| 681 | + return ''; // echec mais $tanpis |
|
| 682 | + } else { |
|
| 683 | + $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | + $c = $_COOKIE['spip_session']; |
|
| 685 | 685 | |
| 686 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | - } |
|
| 686 | + return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | + } |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | */ |
| 703 | 703 | function rejouer_session() { |
| 704 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 704 | + return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * @return string |
| 712 | 712 | */ |
| 713 | 713 | function hash_env() { |
| 714 | - static $res = ''; |
|
| 715 | - if ($res) { |
|
| 716 | - return $res; |
|
| 717 | - } |
|
| 714 | + static $res = ''; |
|
| 715 | + if ($res) { |
|
| 716 | + return $res; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 719 | + return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * @return bool True si une session PHP est ouverte. |
| 729 | 729 | **/ |
| 730 | 730 | function spip_php_session_start() { |
| 731 | - if (!is_php_session_started()) { |
|
| 732 | - return session_start(); |
|
| 733 | - } |
|
| 731 | + if (!is_php_session_started()) { |
|
| 732 | + return session_start(); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | - return true; |
|
| 735 | + return true; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -742,9 +742,9 @@ discard block |
||
| 742 | 742 | * @return bool true si une session PHP est active |
| 743 | 743 | **/ |
| 744 | 744 | function is_php_session_started() { |
| 745 | - if (php_sapi_name() !== 'cli') { |
|
| 746 | - return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | - } |
|
| 745 | + if (php_sapi_name() !== 'cli') { |
|
| 746 | + return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - return false; |
|
| 749 | + return false; |
|
| 750 | 750 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/autoriser'); // necessaire si appel de l'espace public |
@@ -45,70 +45,70 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function precharger_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 47 | 47 | |
| 48 | - $row = []; |
|
| 49 | - $table = table_objet_sql($type); |
|
| 50 | - $_id_objet = id_table_objet($table); |
|
| 51 | - |
|
| 52 | - // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 53 | - if (is_numeric($id_objet)) { |
|
| 54 | - return sql_fetsel('*', $table, "$_id_objet=" . intval($id_objet)); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // ici, on demande une creation. |
|
| 58 | - // on prerempli certains elements : les champs si traduction, |
|
| 59 | - // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 60 | - $desc = lister_tables_objets_sql($table); |
|
| 61 | - # il faudrait calculer $champ_titre ici |
|
| 62 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 63 | - $is_secteur = isset($desc['field']['id_secteur']); |
|
| 64 | - |
|
| 65 | - // si demande de traduction |
|
| 66 | - // on recupere les valeurs de la traduction |
|
| 67 | - if ($lier_trad) { |
|
| 68 | - if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 69 | - $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 70 | - } else { |
|
| 71 | - $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 72 | - } |
|
| 73 | - } else { |
|
| 74 | - $row[$champ_titre] = ''; |
|
| 75 | - if ($is_rubrique) { |
|
| 76 | - $row['id_rubrique'] = $id_rubrique; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // calcul de la rubrique |
|
| 81 | - # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 82 | - if ($is_rubrique) { |
|
| 83 | - // appel du script a la racine, faut choisir |
|
| 84 | - // admin restreint ==> sa premiere rubrique |
|
| 85 | - // autre ==> la derniere rubrique cree |
|
| 86 | - if (!$row['id_rubrique']) { |
|
| 87 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 88 | - $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 89 | - } else { |
|
| 90 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 91 | - $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 92 | - } |
|
| 93 | - if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 94 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 95 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 96 | - while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 97 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // recuperer le secteur, pour affecter les bons champs extras |
|
| 104 | - if ($id_rubrique and $is_secteur) { |
|
| 105 | - if (!$row['id_secteur']) { |
|
| 106 | - $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 107 | - $row['id_secteur'] = $row_rub; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $row; |
|
| 48 | + $row = []; |
|
| 49 | + $table = table_objet_sql($type); |
|
| 50 | + $_id_objet = id_table_objet($table); |
|
| 51 | + |
|
| 52 | + // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 53 | + if (is_numeric($id_objet)) { |
|
| 54 | + return sql_fetsel('*', $table, "$_id_objet=" . intval($id_objet)); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // ici, on demande une creation. |
|
| 58 | + // on prerempli certains elements : les champs si traduction, |
|
| 59 | + // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 60 | + $desc = lister_tables_objets_sql($table); |
|
| 61 | + # il faudrait calculer $champ_titre ici |
|
| 62 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 63 | + $is_secteur = isset($desc['field']['id_secteur']); |
|
| 64 | + |
|
| 65 | + // si demande de traduction |
|
| 66 | + // on recupere les valeurs de la traduction |
|
| 67 | + if ($lier_trad) { |
|
| 68 | + if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 69 | + $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 70 | + } else { |
|
| 71 | + $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 72 | + } |
|
| 73 | + } else { |
|
| 74 | + $row[$champ_titre] = ''; |
|
| 75 | + if ($is_rubrique) { |
|
| 76 | + $row['id_rubrique'] = $id_rubrique; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // calcul de la rubrique |
|
| 81 | + # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 82 | + if ($is_rubrique) { |
|
| 83 | + // appel du script a la racine, faut choisir |
|
| 84 | + // admin restreint ==> sa premiere rubrique |
|
| 85 | + // autre ==> la derniere rubrique cree |
|
| 86 | + if (!$row['id_rubrique']) { |
|
| 87 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 88 | + $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 89 | + } else { |
|
| 90 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 91 | + $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 92 | + } |
|
| 93 | + if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 94 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 95 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 96 | + while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 97 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // recuperer le secteur, pour affecter les bons champs extras |
|
| 104 | + if ($id_rubrique and $is_secteur) { |
|
| 105 | + if (!$row['id_secteur']) { |
|
| 106 | + $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 107 | + $row['id_secteur'] = $row_rub; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $row; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | |
@@ -130,78 +130,78 @@ discard block |
||
| 130 | 130 | * Couples clés / valeurs des champs du formulaire à charger |
| 131 | 131 | **/ |
| 132 | 132 | function precharger_traduction_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 133 | - $table = table_objet_sql($type); |
|
| 134 | - $_id_objet = id_table_objet($table); |
|
| 135 | - |
|
| 136 | - // Recuperer les donnees de l'objet original |
|
| 137 | - $row = sql_fetsel('*', $table, "$_id_objet=" . intval($lier_trad)); |
|
| 138 | - if ($row) { |
|
| 139 | - include_spip('inc/filtres'); |
|
| 140 | - $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 141 | - } else { |
|
| 142 | - $row = []; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // on met l'objet dans une rubrique si l'objet le peut |
|
| 146 | - $desc = lister_tables_objets_sql($table); |
|
| 147 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 148 | - |
|
| 149 | - if ($is_rubrique) { |
|
| 150 | - $langues_dispo = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 151 | - // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 152 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo) and $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 153 | - $row['lang'] = $GLOBALS['spip_lang']; |
|
| 154 | - } |
|
| 155 | - // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 156 | - elseif (count($langues_dispo) == 2) { |
|
| 157 | - $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 158 | - if (count($autre_langue) == 1) { |
|
| 159 | - $row['lang'] = reset($autre_langue); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - else { |
|
| 163 | - $row['lang'] = 'en'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($id_rubrique) { |
|
| 167 | - $row['id_rubrique'] = $id_rubrique; |
|
| 168 | - |
|
| 169 | - return $row; |
|
| 170 | - } |
|
| 171 | - $id_rubrique = $row['id_rubrique']; |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - // Regler la langue, si possible, sur celle du redacteur |
|
| 175 | - // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 176 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 177 | - // Si le menu de langues est autorise sur l'objet, |
|
| 178 | - // on peut changer la langue quelle que soit la rubrique |
|
| 179 | - // donc on reste dans la meme rubrique |
|
| 180 | - if (in_array($table, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 181 | - $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 182 | - |
|
| 183 | - // Sinon, chercher la rubrique la plus adaptee pour |
|
| 184 | - // accueillir l'objet dans la langue du traducteur |
|
| 185 | - } elseif ($is_rubrique and $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 186 | - if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 187 | - $id_parent = 0; |
|
| 188 | - } else { |
|
| 189 | - // on cherche une rubrique soeur dans la bonne langue |
|
| 190 | - $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 191 | - $id_parent = $row_rub['id_parent']; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $row_rub = sql_fetsel( |
|
| 195 | - 'id_rubrique', |
|
| 196 | - 'spip_rubriques', |
|
| 197 | - "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . intval($id_parent) |
|
| 198 | - ); |
|
| 199 | - if ($row_rub) { |
|
| 200 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $row; |
|
| 133 | + $table = table_objet_sql($type); |
|
| 134 | + $_id_objet = id_table_objet($table); |
|
| 135 | + |
|
| 136 | + // Recuperer les donnees de l'objet original |
|
| 137 | + $row = sql_fetsel('*', $table, "$_id_objet=" . intval($lier_trad)); |
|
| 138 | + if ($row) { |
|
| 139 | + include_spip('inc/filtres'); |
|
| 140 | + $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 141 | + } else { |
|
| 142 | + $row = []; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // on met l'objet dans une rubrique si l'objet le peut |
|
| 146 | + $desc = lister_tables_objets_sql($table); |
|
| 147 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 148 | + |
|
| 149 | + if ($is_rubrique) { |
|
| 150 | + $langues_dispo = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 151 | + // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 152 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo) and $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 153 | + $row['lang'] = $GLOBALS['spip_lang']; |
|
| 154 | + } |
|
| 155 | + // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 156 | + elseif (count($langues_dispo) == 2) { |
|
| 157 | + $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 158 | + if (count($autre_langue) == 1) { |
|
| 159 | + $row['lang'] = reset($autre_langue); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + else { |
|
| 163 | + $row['lang'] = 'en'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($id_rubrique) { |
|
| 167 | + $row['id_rubrique'] = $id_rubrique; |
|
| 168 | + |
|
| 169 | + return $row; |
|
| 170 | + } |
|
| 171 | + $id_rubrique = $row['id_rubrique']; |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + // Regler la langue, si possible, sur celle du redacteur |
|
| 175 | + // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 176 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 177 | + // Si le menu de langues est autorise sur l'objet, |
|
| 178 | + // on peut changer la langue quelle que soit la rubrique |
|
| 179 | + // donc on reste dans la meme rubrique |
|
| 180 | + if (in_array($table, explode(',', $GLOBALS['meta']['multi_objets']))) { |
|
| 181 | + $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 182 | + |
|
| 183 | + // Sinon, chercher la rubrique la plus adaptee pour |
|
| 184 | + // accueillir l'objet dans la langue du traducteur |
|
| 185 | + } elseif ($is_rubrique and $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 186 | + if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 187 | + $id_parent = 0; |
|
| 188 | + } else { |
|
| 189 | + // on cherche une rubrique soeur dans la bonne langue |
|
| 190 | + $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 191 | + $id_parent = $row_rub['id_parent']; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $row_rub = sql_fetsel( |
|
| 195 | + 'id_rubrique', |
|
| 196 | + 'spip_rubriques', |
|
| 197 | + "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . intval($id_parent) |
|
| 198 | + ); |
|
| 199 | + if ($row_rub) { |
|
| 200 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $row; |
|
| 207 | 207 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL\Tables |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -68,154 +68,154 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | **/ |
| 70 | 70 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true, array $options = []) { |
| 71 | - $desc_cache = null; |
|
| 72 | - static $nom_cache_desc_sql = []; |
|
| 73 | - |
|
| 74 | - if ( |
|
| 75 | - !spip_connect($serveur) |
|
| 76 | - or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | - ) { |
|
| 78 | - return null; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $options = $options + [ |
|
| 82 | - // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | - 'log_missing' => true, |
|
| 84 | - ]; |
|
| 85 | - |
|
| 86 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | - $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | - |
|
| 89 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | - // de connexion, et tout risque d'ambiguite |
|
| 92 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | - _DIR_CACHE . 'sql_desc_' |
|
| 95 | - . ($serveur ? "{$serveur}_" : '') |
|
| 96 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | - . '.txt'; |
|
| 98 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | - unset($connexion['tables']); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | - if (!$nom) { |
|
| 104 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | - $connexion['tables'] = []; |
|
| 106 | - |
|
| 107 | - return null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $nom_sql = $nom; |
|
| 111 | - if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | - $nom_sql = $s[1]; |
|
| 113 | - } else { |
|
| 114 | - $nom_sql = $nom; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $fdesc = $desc = ''; |
|
| 118 | - $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | - |
|
| 120 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | - if ($connexion['spip_connect_version']) { |
|
| 122 | - if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | - $nom_sql = 'spip_' . $nom; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // si c'est la premiere table qu'on cherche |
|
| 129 | - // et si on est pas explicitement en recalcul |
|
| 130 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | - // dans le fichier cache |
|
| 132 | - if ( |
|
| 133 | - !isset($connexion['tables'][$nom_sql]) |
|
| 134 | - and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | - and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | - ) { |
|
| 137 | - if ( |
|
| 138 | - lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | - and $desc_cache = unserialize($desc_cache) |
|
| 140 | - ) { |
|
| 141 | - $connexion['tables'] = $desc_cache; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | - } |
|
| 148 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | - // si c'est une table principale, |
|
| 150 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | - $nom_sql = 'spip_' . $nom; |
|
| 153 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | - } elseif ( |
|
| 155 | - isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | - ) { |
|
| 158 | - $nom_sql = $n; |
|
| 159 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | - } |
|
| 162 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | - // La *vraie* base a la priorite |
|
| 164 | - $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | - if ( |
|
| 166 | - !$exists |
|
| 167 | - or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | - or !$desc['field'] |
|
| 169 | - ) { |
|
| 170 | - if (!$fdesc) { |
|
| 171 | - $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | - |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - // on ne sait pas lire la structure de la table : |
|
| 177 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | - $desc = $fdesc; |
|
| 179 | - $desc['exist'] = false; |
|
| 180 | - } else { |
|
| 181 | - $desc['exist'] = true; |
|
| 182 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | - if (! $desc['key']) { |
|
| 185 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | - unset($desc['key']); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | - $desc['connexion'] = $serveur; |
|
| 192 | - |
|
| 193 | - // charger les infos declarees pour cette table |
|
| 194 | - // en lui passant les infos connues |
|
| 195 | - // $desc est prioritaire pour la description de la table |
|
| 196 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | - // s'assurer qu'on a toujours un 'key' |
|
| 198 | - if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | - $desc['key'] = $fdesc['key']; |
|
| 200 | - } |
|
| 201 | - if (! isset($desc['key'])) { |
|
| 202 | - $desc['key'] = []; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | - // une nouvelle table a ete decrite |
|
| 209 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | - if (is_writeable(_DIR_CACHE)) { |
|
| 211 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | - } |
|
| 213 | - } else { |
|
| 214 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // toujours retourner $nom dans id_table |
|
| 218 | - $res['id_table'] = $nom; |
|
| 219 | - |
|
| 220 | - return $res; |
|
| 71 | + $desc_cache = null; |
|
| 72 | + static $nom_cache_desc_sql = []; |
|
| 73 | + |
|
| 74 | + if ( |
|
| 75 | + !spip_connect($serveur) |
|
| 76 | + or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | + ) { |
|
| 78 | + return null; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $options = $options + [ |
|
| 82 | + // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | + 'log_missing' => true, |
|
| 84 | + ]; |
|
| 85 | + |
|
| 86 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | + $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | + |
|
| 89 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | + // de connexion, et tout risque d'ambiguite |
|
| 92 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | + _DIR_CACHE . 'sql_desc_' |
|
| 95 | + . ($serveur ? "{$serveur}_" : '') |
|
| 96 | + . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | + . '.txt'; |
|
| 98 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | + unset($connexion['tables']); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | + if (!$nom) { |
|
| 104 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | + $connexion['tables'] = []; |
|
| 106 | + |
|
| 107 | + return null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $nom_sql = $nom; |
|
| 111 | + if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | + $nom_sql = $s[1]; |
|
| 113 | + } else { |
|
| 114 | + $nom_sql = $nom; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $fdesc = $desc = ''; |
|
| 118 | + $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | + |
|
| 120 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | + if ($connexion['spip_connect_version']) { |
|
| 122 | + if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | + $nom_sql = 'spip_' . $nom; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // si c'est la premiere table qu'on cherche |
|
| 129 | + // et si on est pas explicitement en recalcul |
|
| 130 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | + // dans le fichier cache |
|
| 132 | + if ( |
|
| 133 | + !isset($connexion['tables'][$nom_sql]) |
|
| 134 | + and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | + and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | + ) { |
|
| 137 | + if ( |
|
| 138 | + lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | + and $desc_cache = unserialize($desc_cache) |
|
| 140 | + ) { |
|
| 141 | + $connexion['tables'] = $desc_cache; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | + } |
|
| 148 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | + // si c'est une table principale, |
|
| 150 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | + $nom_sql = 'spip_' . $nom; |
|
| 153 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | + } elseif ( |
|
| 155 | + isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | + ) { |
|
| 158 | + $nom_sql = $n; |
|
| 159 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | + } |
|
| 162 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | + // La *vraie* base a la priorite |
|
| 164 | + $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | + if ( |
|
| 166 | + !$exists |
|
| 167 | + or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | + or !$desc['field'] |
|
| 169 | + ) { |
|
| 170 | + if (!$fdesc) { |
|
| 171 | + $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | + |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + // on ne sait pas lire la structure de la table : |
|
| 177 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | + $desc = $fdesc; |
|
| 179 | + $desc['exist'] = false; |
|
| 180 | + } else { |
|
| 181 | + $desc['exist'] = true; |
|
| 182 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | + if (! $desc['key']) { |
|
| 185 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | + unset($desc['key']); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | + $desc['connexion'] = $serveur; |
|
| 192 | + |
|
| 193 | + // charger les infos declarees pour cette table |
|
| 194 | + // en lui passant les infos connues |
|
| 195 | + // $desc est prioritaire pour la description de la table |
|
| 196 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | + // s'assurer qu'on a toujours un 'key' |
|
| 198 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | + $desc['key'] = $fdesc['key']; |
|
| 200 | + } |
|
| 201 | + if (! isset($desc['key'])) { |
|
| 202 | + $desc['key'] = []; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | + // une nouvelle table a ete decrite |
|
| 209 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | + if (is_writeable(_DIR_CACHE)) { |
|
| 211 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // toujours retourner $nom dans id_table |
|
| 218 | + $res['id_table'] = $nom; |
|
| 219 | + |
|
| 220 | + return $res; |
|
| 221 | 221 | } |
@@ -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 | /** |
@@ -29,27 +29,27 @@ discard block |
||
| 29 | 29 | * @param string $titre Inutilisé |
| 30 | 30 | **/ |
| 31 | 31 | function base_delete_all_dist($titre) { |
| 32 | - $delete = _request('delete'); |
|
| 33 | - $res = []; |
|
| 34 | - if (is_array($delete)) { |
|
| 35 | - foreach ($delete as $table) { |
|
| 36 | - if (sql_drop_table($table)) { |
|
| 37 | - $res[] = $table; |
|
| 38 | - } else { |
|
| 39 | - spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 40 | - } |
|
| 41 | - } |
|
| 32 | + $delete = _request('delete'); |
|
| 33 | + $res = []; |
|
| 34 | + if (is_array($delete)) { |
|
| 35 | + foreach ($delete as $table) { |
|
| 36 | + if (sql_drop_table($table)) { |
|
| 37 | + $res[] = $table; |
|
| 38 | + } else { |
|
| 39 | + spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // un pipeline pour detruire les tables installees par les plugins |
|
| 44 | - pipeline('delete_tables', ''); |
|
| 43 | + // un pipeline pour detruire les tables installees par les plugins |
|
| 44 | + pipeline('delete_tables', ''); |
|
| 45 | 45 | |
| 46 | - spip_unlink(_FILE_CONNECT); |
|
| 47 | - spip_unlink(_FILE_CHMOD); |
|
| 48 | - spip_unlink(_FILE_META); |
|
| 49 | - spip_unlink(_ACCESS_FILE_NAME); |
|
| 50 | - spip_unlink(_CACHE_RUBRIQUES); |
|
| 51 | - } |
|
| 52 | - $d = is_countable($delete) ? count($delete) : 0; |
|
| 53 | - $r = count($res); |
|
| 54 | - spip_log("Tables detruites: $r sur $d: " . join(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 46 | + spip_unlink(_FILE_CONNECT); |
|
| 47 | + spip_unlink(_FILE_CHMOD); |
|
| 48 | + spip_unlink(_FILE_META); |
|
| 49 | + spip_unlink(_ACCESS_FILE_NAME); |
|
| 50 | + spip_unlink(_CACHE_RUBRIQUES); |
|
| 51 | + } |
|
| 52 | + $d = is_countable($delete) ? count($delete) : 0; |
|
| 53 | + $r = count($res); |
|
| 54 | + spip_log("Tables detruites: $r sur $d: " . join(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 55 | 55 | } |
@@ -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 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * @return void |
| 33 | 33 | **/ |
| 34 | 34 | function array_set_merge(&$table, $index, $valeur) { |
| 35 | - if (!isset($table[$index])) { |
|
| 36 | - $table[$index] = $valeur; |
|
| 37 | - } else { |
|
| 38 | - $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | - } |
|
| 35 | + if (!isset($table[$index])) { |
|
| 36 | + $table[$index] = $valeur; |
|
| 37 | + } else { |
|
| 38 | + $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -53,440 +53,440 @@ discard block |
||
| 53 | 53 | * @return array|bool |
| 54 | 54 | */ |
| 55 | 55 | function lister_tables_objets_sql(?string $table_sql = null, $desc = []) { |
| 56 | - static $deja_la = false; |
|
| 57 | - static $infos_tables = null; |
|
| 58 | - static $md5 = null; |
|
| 59 | - static $plugin_hash = null; |
|
| 60 | - |
|
| 61 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | - |
|
| 64 | - // prealablement recuperer les tables_principales |
|
| 65 | - if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | - // pas de reentrance (cas base/serial) |
|
| 67 | - if ($deja_la) { |
|
| 68 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | - |
|
| 71 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 72 | - } |
|
| 73 | - $deja_la = true; |
|
| 74 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | - |
|
| 76 | - // recuperer les declarations explicites ancienne mode |
|
| 77 | - // qui servent a completer declarer_tables_objets_sql |
|
| 78 | - base_serial($GLOBALS['tables_principales']); |
|
| 79 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | - $infos_tables = [ |
|
| 81 | - 'spip_articles' => [ |
|
| 82 | - 'page' => 'article', |
|
| 83 | - 'texte_retour' => 'icone_retour_article', |
|
| 84 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | - 'texte_objets' => 'public:articles', |
|
| 87 | - 'texte_objet' => 'public:article', |
|
| 88 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | - 'info_1_objet' => 'info_1_article', |
|
| 91 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | - 'texte_logo_objet' => 'logo_article', |
|
| 93 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | - 'titre' => 'titre, lang', |
|
| 96 | - 'date' => 'date', |
|
| 97 | - 'principale' => 'oui', |
|
| 98 | - 'introduction_longueur' => '500', |
|
| 99 | - 'champs_editables' => [ |
|
| 100 | - 'surtitre', |
|
| 101 | - 'titre', |
|
| 102 | - 'soustitre', |
|
| 103 | - 'descriptif', |
|
| 104 | - 'nom_site', |
|
| 105 | - 'url_site', |
|
| 106 | - 'chapo', |
|
| 107 | - 'texte', |
|
| 108 | - 'ps', |
|
| 109 | - 'virtuel' |
|
| 110 | - ], |
|
| 111 | - 'champs_versionnes' => [ |
|
| 112 | - 'id_rubrique', |
|
| 113 | - 'surtitre', |
|
| 114 | - 'titre', |
|
| 115 | - 'soustitre', |
|
| 116 | - 'jointure_auteurs', |
|
| 117 | - 'descriptif', |
|
| 118 | - 'nom_site', |
|
| 119 | - 'url_site', |
|
| 120 | - 'chapo', |
|
| 121 | - 'texte', |
|
| 122 | - 'ps' |
|
| 123 | - ], |
|
| 124 | - 'field' => [ |
|
| 125 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | - 'maj' => 'TIMESTAMP', |
|
| 138 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | - ], |
|
| 152 | - 'key' => [ |
|
| 153 | - 'PRIMARY KEY' => 'id_article', |
|
| 154 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | - 'KEY id_secteur' => 'id_secteur', |
|
| 156 | - 'KEY id_trad' => 'id_trad', |
|
| 157 | - 'KEY lang' => 'lang', |
|
| 158 | - 'KEY statut' => 'statut, date', |
|
| 159 | - ], |
|
| 160 | - 'join' => [ |
|
| 161 | - 'id_article' => 'id_article', |
|
| 162 | - 'id_rubrique' => 'id_rubrique' |
|
| 163 | - ], |
|
| 164 | - 'parent' => [ |
|
| 165 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | - ], |
|
| 167 | - 'rechercher_champs' => [ |
|
| 168 | - 'surtitre' => 5, |
|
| 169 | - 'titre' => 8, |
|
| 170 | - 'soustitre' => 5, |
|
| 171 | - 'chapo' => 3, |
|
| 172 | - 'texte' => 1, |
|
| 173 | - 'ps' => 1, |
|
| 174 | - 'nom_site' => 1, |
|
| 175 | - 'url_site' => 1, |
|
| 176 | - 'descriptif' => 4 |
|
| 177 | - ], |
|
| 178 | - 'rechercher_jointures' => [ |
|
| 179 | - 'auteur' => ['nom' => 10], |
|
| 180 | - ], |
|
| 181 | - 'statut' => [ |
|
| 182 | - [ |
|
| 183 | - 'champ' => 'statut', |
|
| 184 | - 'publie' => 'publie', |
|
| 185 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | - 'post_date' => 'date', |
|
| 187 | - 'exception' => ['statut', 'tout'] |
|
| 188 | - ] |
|
| 189 | - ], |
|
| 190 | - 'statut_titres' => [ |
|
| 191 | - 'prepa' => 'info_article_redaction', |
|
| 192 | - 'prop' => 'info_article_propose', |
|
| 193 | - 'publie' => 'info_article_publie', |
|
| 194 | - 'refuse' => 'info_article_refuse', |
|
| 195 | - 'poubelle' => 'info_article_supprime' |
|
| 196 | - ], |
|
| 197 | - 'statut_textes_instituer' => [ |
|
| 198 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | - 'publie' => 'texte_statut_publie', |
|
| 201 | - 'refuse' => 'texte_statut_refuse', |
|
| 202 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | - ], |
|
| 204 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | - 'aide_changer_statut' => 'artstatut', |
|
| 206 | - 'tables_jointures' => [ |
|
| 207 | - 'profondeur' => 'rubriques', |
|
| 208 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | - ], |
|
| 210 | - ], |
|
| 211 | - 'spip_auteurs' => [ |
|
| 212 | - 'page' => 'auteur', |
|
| 213 | - 'texte_retour' => 'icone_retour', |
|
| 214 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | - 'texte_objets' => 'icone_auteurs', |
|
| 217 | - 'texte_objet' => 'public:auteur', |
|
| 218 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | - 'info_1_objet' => 'info_1_auteur', |
|
| 220 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | - 'date' => 'date', |
|
| 225 | - 'principale' => 'oui', |
|
| 226 | - 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 227 | - 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 228 | - 'field' => [ |
|
| 229 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | - 'maj' => 'TIMESTAMP', |
|
| 241 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | - 'alea_actuel' => 'tinytext', |
|
| 245 | - 'alea_futur' => 'tinytext', |
|
| 246 | - 'prefs' => 'text', |
|
| 247 | - 'cookie_oubli' => 'tinytext', |
|
| 248 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 251 | - ], |
|
| 252 | - 'key' => [ |
|
| 253 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | - 'KEY login' => 'login', |
|
| 255 | - 'KEY statut' => 'statut', |
|
| 256 | - 'KEY en_ligne' => 'en_ligne', |
|
| 257 | - ], |
|
| 258 | - 'join' => [ |
|
| 259 | - 'id_auteur' => 'id_auteur', |
|
| 260 | - 'login' => 'login' |
|
| 261 | - ], |
|
| 262 | - 'rechercher_champs' => [ |
|
| 263 | - 'nom' => 5, |
|
| 264 | - 'bio' => 1, |
|
| 265 | - 'email' => 1, |
|
| 266 | - 'nom_site' => 1, |
|
| 267 | - 'url_site' => 1, |
|
| 268 | - 'login' => 1 |
|
| 269 | - ], |
|
| 270 | - // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | - // et avoir des articles publies |
|
| 272 | - 'statut' => [ |
|
| 273 | - [ |
|
| 274 | - 'champ' => 'statut', |
|
| 275 | - 'publie' => '!5poubelle', |
|
| 276 | - 'previsu' => '!5poubelle', |
|
| 277 | - 'exception' => 'statut' |
|
| 278 | - ], |
|
| 279 | - [ |
|
| 280 | - 'champ' => [ |
|
| 281 | - ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | - [ |
|
| 283 | - 'spip_articles', |
|
| 284 | - ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | - ], |
|
| 286 | - 'statut' |
|
| 287 | - ], |
|
| 288 | - 'publie' => 'publie', |
|
| 289 | - 'previsu' => '!', |
|
| 290 | - 'post_date' => 'date', |
|
| 291 | - 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | - ], |
|
| 293 | - ], |
|
| 294 | - 'statut_images' => [ |
|
| 295 | - 'auteur-6forum-16.png', |
|
| 296 | - '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | - '1comite' => 'auteur-1comite-16.png', |
|
| 298 | - '6forum' => 'auteur-6forum-16.png', |
|
| 299 | - '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | - 'nouveau' => '' |
|
| 301 | - ], |
|
| 302 | - 'statut_titres' => [ |
|
| 303 | - 'titre_image_visiteur', |
|
| 304 | - '0minirezo' => 'titre_image_administrateur', |
|
| 305 | - '1comite' => 'titre_image_redacteur_02', |
|
| 306 | - '6forum' => 'titre_image_visiteur', |
|
| 307 | - '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | - ], |
|
| 309 | - 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | - ], |
|
| 311 | - ], |
|
| 312 | - 'spip_rubriques' => [ |
|
| 313 | - 'page' => 'rubrique', |
|
| 314 | - 'url_voir' => 'rubrique', |
|
| 315 | - 'url_edit' => 'rubrique_edit', |
|
| 316 | - 'texte_retour' => 'icone_retour', |
|
| 317 | - 'texte_objets' => 'public:rubriques', |
|
| 318 | - 'texte_objet' => 'public:rubrique', |
|
| 319 | - 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | - 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | - 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | - 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | - 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | - 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | - 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | - 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | - 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | - 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | - 'titre' => 'titre, lang', |
|
| 330 | - 'date' => 'date', |
|
| 331 | - 'principale' => 'oui', |
|
| 332 | - 'introduction_longueur' => '600', |
|
| 333 | - 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | - 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | - 'field' => [ |
|
| 336 | - 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | - 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | - 'maj' => 'TIMESTAMP', |
|
| 343 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | - 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | - 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | - 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | - ], |
|
| 351 | - 'key' => [ |
|
| 352 | - 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | - 'KEY lang' => 'lang', |
|
| 354 | - 'KEY id_parent' => 'id_parent', |
|
| 355 | - ], |
|
| 356 | - 'parent' => [ |
|
| 357 | - ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | - ], |
|
| 359 | - 'rechercher_champs' => [ |
|
| 360 | - 'titre' => 8, |
|
| 361 | - 'descriptif' => 5, |
|
| 362 | - 'texte' => 1 |
|
| 363 | - ], |
|
| 364 | - 'statut' => [ |
|
| 365 | - [ |
|
| 366 | - 'champ' => 'statut', |
|
| 367 | - 'publie' => 'publie', |
|
| 368 | - 'previsu' => '!', |
|
| 369 | - 'exception' => ['statut', 'tout'] |
|
| 370 | - ], |
|
| 371 | - ], |
|
| 372 | - 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | - ], |
|
| 374 | - ], |
|
| 375 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | - ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | - ]; |
|
| 378 | - |
|
| 379 | - // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | - // initialiser la signature |
|
| 381 | - $md5 = md5(serialize($infos_tables)); |
|
| 382 | - |
|
| 383 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | - $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | - |
|
| 387 | - // completer les informations manquantes ou implicites |
|
| 388 | - $all = []; |
|
| 389 | - foreach (array_keys($infos_tables) as $t) { |
|
| 390 | - // les cles numeriques servent a declarer |
|
| 391 | - // les proprietes applicables a tous les objets |
|
| 392 | - // on les mets de cote |
|
| 393 | - if (is_numeric($t)) { |
|
| 394 | - $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | - unset($infos_tables[$t]); |
|
| 396 | - } else { |
|
| 397 | - $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // repercuter les proprietes generales communes a tous les objets |
|
| 402 | - foreach (array_keys($infos_tables) as $t) { |
|
| 403 | - foreach ($all as $i => $v) { |
|
| 404 | - if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | - $add = $all[$i]; |
|
| 406 | - // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | - // pour les declarations generiques avec cles numeriques |
|
| 408 | - if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0) { |
|
| 409 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | - foreach ($doublons as $d) { |
|
| 411 | - if ( |
|
| 412 | - is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | - and is_numeric($k = array_search($d, $add)) |
|
| 414 | - ) { |
|
| 415 | - unset($add[$k]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | - } else { |
|
| 421 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | - $infos_tables[$t][$i] ?? [], |
|
| 423 | - $all[$i] |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // completer les tables principales et auxiliaires |
|
| 430 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | - // pour assurer la compat en transition |
|
| 432 | - foreach ($infos_tables as $table => $infos) { |
|
| 433 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | - // qui a ete appelle avant |
|
| 436 | - $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | - // l'ajouter au tableau |
|
| 438 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | - if (isset($infos['field']) and isset($infos['key'])) { |
|
| 440 | - foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | - if (isset($infos_tables[$table][$k])) { |
|
| 442 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } else { |
|
| 446 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | - } |
|
| 450 | - if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | - foreach (array_keys($mem) as $k) { |
|
| 452 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | - $mem[$k] |
|
| 456 | - ); |
|
| 457 | - } else { |
|
| 458 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // recuperer les interfaces (table_titre, table_date) |
|
| 465 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | - // dans le pipeline de declarer_tables_interfaces |
|
| 467 | - include_spip('public/interfaces'); |
|
| 468 | - foreach (array_keys($infos_tables) as $t) { |
|
| 469 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $deja_la = false; |
|
| 473 | - // signature |
|
| 474 | - $md5 = md5(serialize($infos_tables)); |
|
| 475 | - } |
|
| 476 | - if ($table_sql === '::md5') { |
|
| 477 | - return $md5; |
|
| 478 | - } |
|
| 479 | - if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 480 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | - |
|
| 483 | - return $desc; |
|
| 484 | - } |
|
| 485 | - if ($table_sql) { |
|
| 486 | - return $infos_tables[$table_sql] ?? []; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return $infos_tables; |
|
| 56 | + static $deja_la = false; |
|
| 57 | + static $infos_tables = null; |
|
| 58 | + static $md5 = null; |
|
| 59 | + static $plugin_hash = null; |
|
| 60 | + |
|
| 61 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | + |
|
| 64 | + // prealablement recuperer les tables_principales |
|
| 65 | + if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | + // pas de reentrance (cas base/serial) |
|
| 67 | + if ($deja_la) { |
|
| 68 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | + |
|
| 71 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 72 | + } |
|
| 73 | + $deja_la = true; |
|
| 74 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | + |
|
| 76 | + // recuperer les declarations explicites ancienne mode |
|
| 77 | + // qui servent a completer declarer_tables_objets_sql |
|
| 78 | + base_serial($GLOBALS['tables_principales']); |
|
| 79 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | + $infos_tables = [ |
|
| 81 | + 'spip_articles' => [ |
|
| 82 | + 'page' => 'article', |
|
| 83 | + 'texte_retour' => 'icone_retour_article', |
|
| 84 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | + 'texte_objets' => 'public:articles', |
|
| 87 | + 'texte_objet' => 'public:article', |
|
| 88 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | + 'info_1_objet' => 'info_1_article', |
|
| 91 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | + 'texte_logo_objet' => 'logo_article', |
|
| 93 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | + 'titre' => 'titre, lang', |
|
| 96 | + 'date' => 'date', |
|
| 97 | + 'principale' => 'oui', |
|
| 98 | + 'introduction_longueur' => '500', |
|
| 99 | + 'champs_editables' => [ |
|
| 100 | + 'surtitre', |
|
| 101 | + 'titre', |
|
| 102 | + 'soustitre', |
|
| 103 | + 'descriptif', |
|
| 104 | + 'nom_site', |
|
| 105 | + 'url_site', |
|
| 106 | + 'chapo', |
|
| 107 | + 'texte', |
|
| 108 | + 'ps', |
|
| 109 | + 'virtuel' |
|
| 110 | + ], |
|
| 111 | + 'champs_versionnes' => [ |
|
| 112 | + 'id_rubrique', |
|
| 113 | + 'surtitre', |
|
| 114 | + 'titre', |
|
| 115 | + 'soustitre', |
|
| 116 | + 'jointure_auteurs', |
|
| 117 | + 'descriptif', |
|
| 118 | + 'nom_site', |
|
| 119 | + 'url_site', |
|
| 120 | + 'chapo', |
|
| 121 | + 'texte', |
|
| 122 | + 'ps' |
|
| 123 | + ], |
|
| 124 | + 'field' => [ |
|
| 125 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | + 'maj' => 'TIMESTAMP', |
|
| 138 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | + ], |
|
| 152 | + 'key' => [ |
|
| 153 | + 'PRIMARY KEY' => 'id_article', |
|
| 154 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | + 'KEY id_secteur' => 'id_secteur', |
|
| 156 | + 'KEY id_trad' => 'id_trad', |
|
| 157 | + 'KEY lang' => 'lang', |
|
| 158 | + 'KEY statut' => 'statut, date', |
|
| 159 | + ], |
|
| 160 | + 'join' => [ |
|
| 161 | + 'id_article' => 'id_article', |
|
| 162 | + 'id_rubrique' => 'id_rubrique' |
|
| 163 | + ], |
|
| 164 | + 'parent' => [ |
|
| 165 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | + ], |
|
| 167 | + 'rechercher_champs' => [ |
|
| 168 | + 'surtitre' => 5, |
|
| 169 | + 'titre' => 8, |
|
| 170 | + 'soustitre' => 5, |
|
| 171 | + 'chapo' => 3, |
|
| 172 | + 'texte' => 1, |
|
| 173 | + 'ps' => 1, |
|
| 174 | + 'nom_site' => 1, |
|
| 175 | + 'url_site' => 1, |
|
| 176 | + 'descriptif' => 4 |
|
| 177 | + ], |
|
| 178 | + 'rechercher_jointures' => [ |
|
| 179 | + 'auteur' => ['nom' => 10], |
|
| 180 | + ], |
|
| 181 | + 'statut' => [ |
|
| 182 | + [ |
|
| 183 | + 'champ' => 'statut', |
|
| 184 | + 'publie' => 'publie', |
|
| 185 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | + 'post_date' => 'date', |
|
| 187 | + 'exception' => ['statut', 'tout'] |
|
| 188 | + ] |
|
| 189 | + ], |
|
| 190 | + 'statut_titres' => [ |
|
| 191 | + 'prepa' => 'info_article_redaction', |
|
| 192 | + 'prop' => 'info_article_propose', |
|
| 193 | + 'publie' => 'info_article_publie', |
|
| 194 | + 'refuse' => 'info_article_refuse', |
|
| 195 | + 'poubelle' => 'info_article_supprime' |
|
| 196 | + ], |
|
| 197 | + 'statut_textes_instituer' => [ |
|
| 198 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | + 'publie' => 'texte_statut_publie', |
|
| 201 | + 'refuse' => 'texte_statut_refuse', |
|
| 202 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | + ], |
|
| 204 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | + 'aide_changer_statut' => 'artstatut', |
|
| 206 | + 'tables_jointures' => [ |
|
| 207 | + 'profondeur' => 'rubriques', |
|
| 208 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | + ], |
|
| 210 | + ], |
|
| 211 | + 'spip_auteurs' => [ |
|
| 212 | + 'page' => 'auteur', |
|
| 213 | + 'texte_retour' => 'icone_retour', |
|
| 214 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | + 'texte_objets' => 'icone_auteurs', |
|
| 217 | + 'texte_objet' => 'public:auteur', |
|
| 218 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | + 'info_1_objet' => 'info_1_auteur', |
|
| 220 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | + 'date' => 'date', |
|
| 225 | + 'principale' => 'oui', |
|
| 226 | + 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 227 | + 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 228 | + 'field' => [ |
|
| 229 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | + 'maj' => 'TIMESTAMP', |
|
| 241 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | + 'alea_actuel' => 'tinytext', |
|
| 245 | + 'alea_futur' => 'tinytext', |
|
| 246 | + 'prefs' => 'text', |
|
| 247 | + 'cookie_oubli' => 'tinytext', |
|
| 248 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL" |
|
| 251 | + ], |
|
| 252 | + 'key' => [ |
|
| 253 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | + 'KEY login' => 'login', |
|
| 255 | + 'KEY statut' => 'statut', |
|
| 256 | + 'KEY en_ligne' => 'en_ligne', |
|
| 257 | + ], |
|
| 258 | + 'join' => [ |
|
| 259 | + 'id_auteur' => 'id_auteur', |
|
| 260 | + 'login' => 'login' |
|
| 261 | + ], |
|
| 262 | + 'rechercher_champs' => [ |
|
| 263 | + 'nom' => 5, |
|
| 264 | + 'bio' => 1, |
|
| 265 | + 'email' => 1, |
|
| 266 | + 'nom_site' => 1, |
|
| 267 | + 'url_site' => 1, |
|
| 268 | + 'login' => 1 |
|
| 269 | + ], |
|
| 270 | + // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | + // et avoir des articles publies |
|
| 272 | + 'statut' => [ |
|
| 273 | + [ |
|
| 274 | + 'champ' => 'statut', |
|
| 275 | + 'publie' => '!5poubelle', |
|
| 276 | + 'previsu' => '!5poubelle', |
|
| 277 | + 'exception' => 'statut' |
|
| 278 | + ], |
|
| 279 | + [ |
|
| 280 | + 'champ' => [ |
|
| 281 | + ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | + [ |
|
| 283 | + 'spip_articles', |
|
| 284 | + ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | + ], |
|
| 286 | + 'statut' |
|
| 287 | + ], |
|
| 288 | + 'publie' => 'publie', |
|
| 289 | + 'previsu' => '!', |
|
| 290 | + 'post_date' => 'date', |
|
| 291 | + 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | + ], |
|
| 293 | + ], |
|
| 294 | + 'statut_images' => [ |
|
| 295 | + 'auteur-6forum-16.png', |
|
| 296 | + '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | + '1comite' => 'auteur-1comite-16.png', |
|
| 298 | + '6forum' => 'auteur-6forum-16.png', |
|
| 299 | + '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | + 'nouveau' => '' |
|
| 301 | + ], |
|
| 302 | + 'statut_titres' => [ |
|
| 303 | + 'titre_image_visiteur', |
|
| 304 | + '0minirezo' => 'titre_image_administrateur', |
|
| 305 | + '1comite' => 'titre_image_redacteur_02', |
|
| 306 | + '6forum' => 'titre_image_visiteur', |
|
| 307 | + '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | + ], |
|
| 309 | + 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | + ], |
|
| 311 | + ], |
|
| 312 | + 'spip_rubriques' => [ |
|
| 313 | + 'page' => 'rubrique', |
|
| 314 | + 'url_voir' => 'rubrique', |
|
| 315 | + 'url_edit' => 'rubrique_edit', |
|
| 316 | + 'texte_retour' => 'icone_retour', |
|
| 317 | + 'texte_objets' => 'public:rubriques', |
|
| 318 | + 'texte_objet' => 'public:rubrique', |
|
| 319 | + 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | + 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | + 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | + 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | + 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | + 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | + 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | + 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | + 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | + 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | + 'titre' => 'titre, lang', |
|
| 330 | + 'date' => 'date', |
|
| 331 | + 'principale' => 'oui', |
|
| 332 | + 'introduction_longueur' => '600', |
|
| 333 | + 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | + 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | + 'field' => [ |
|
| 336 | + 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | + 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | + 'maj' => 'TIMESTAMP', |
|
| 343 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | + 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | + 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | + 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | + ], |
|
| 351 | + 'key' => [ |
|
| 352 | + 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | + 'KEY lang' => 'lang', |
|
| 354 | + 'KEY id_parent' => 'id_parent', |
|
| 355 | + ], |
|
| 356 | + 'parent' => [ |
|
| 357 | + ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | + ], |
|
| 359 | + 'rechercher_champs' => [ |
|
| 360 | + 'titre' => 8, |
|
| 361 | + 'descriptif' => 5, |
|
| 362 | + 'texte' => 1 |
|
| 363 | + ], |
|
| 364 | + 'statut' => [ |
|
| 365 | + [ |
|
| 366 | + 'champ' => 'statut', |
|
| 367 | + 'publie' => 'publie', |
|
| 368 | + 'previsu' => '!', |
|
| 369 | + 'exception' => ['statut', 'tout'] |
|
| 370 | + ], |
|
| 371 | + ], |
|
| 372 | + 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | + ], |
|
| 374 | + ], |
|
| 375 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | + ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | + ]; |
|
| 378 | + |
|
| 379 | + // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | + // initialiser la signature |
|
| 381 | + $md5 = md5(serialize($infos_tables)); |
|
| 382 | + |
|
| 383 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | + |
|
| 387 | + // completer les informations manquantes ou implicites |
|
| 388 | + $all = []; |
|
| 389 | + foreach (array_keys($infos_tables) as $t) { |
|
| 390 | + // les cles numeriques servent a declarer |
|
| 391 | + // les proprietes applicables a tous les objets |
|
| 392 | + // on les mets de cote |
|
| 393 | + if (is_numeric($t)) { |
|
| 394 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | + unset($infos_tables[$t]); |
|
| 396 | + } else { |
|
| 397 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // repercuter les proprietes generales communes a tous les objets |
|
| 402 | + foreach (array_keys($infos_tables) as $t) { |
|
| 403 | + foreach ($all as $i => $v) { |
|
| 404 | + if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | + $add = $all[$i]; |
|
| 406 | + // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | + // pour les declarations generiques avec cles numeriques |
|
| 408 | + if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0) { |
|
| 409 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | + foreach ($doublons as $d) { |
|
| 411 | + if ( |
|
| 412 | + is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | + and is_numeric($k = array_search($d, $add)) |
|
| 414 | + ) { |
|
| 415 | + unset($add[$k]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | + } else { |
|
| 421 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | + $infos_tables[$t][$i] ?? [], |
|
| 423 | + $all[$i] |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // completer les tables principales et auxiliaires |
|
| 430 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | + // pour assurer la compat en transition |
|
| 432 | + foreach ($infos_tables as $table => $infos) { |
|
| 433 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | + // qui a ete appelle avant |
|
| 436 | + $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | + // l'ajouter au tableau |
|
| 438 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | + if (isset($infos['field']) and isset($infos['key'])) { |
|
| 440 | + foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | + if (isset($infos_tables[$table][$k])) { |
|
| 442 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } else { |
|
| 446 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | + } |
|
| 450 | + if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | + foreach (array_keys($mem) as $k) { |
|
| 452 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | + $mem[$k] |
|
| 456 | + ); |
|
| 457 | + } else { |
|
| 458 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // recuperer les interfaces (table_titre, table_date) |
|
| 465 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | + // dans le pipeline de declarer_tables_interfaces |
|
| 467 | + include_spip('public/interfaces'); |
|
| 468 | + foreach (array_keys($infos_tables) as $t) { |
|
| 469 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $deja_la = false; |
|
| 473 | + // signature |
|
| 474 | + $md5 = md5(serialize($infos_tables)); |
|
| 475 | + } |
|
| 476 | + if ($table_sql === '::md5') { |
|
| 477 | + return $md5; |
|
| 478 | + } |
|
| 479 | + if ($table_sql and !isset($infos_tables[$table_sql])) { |
|
| 480 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | + |
|
| 483 | + return $desc; |
|
| 484 | + } |
|
| 485 | + if ($table_sql) { |
|
| 486 | + return $infos_tables[$table_sql] ?? []; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return $infos_tables; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -501,27 +501,27 @@ discard block |
||
| 501 | 501 | **/ |
| 502 | 502 | function base_serial(&$tables_principales) { |
| 503 | 503 | |
| 504 | - $spip_jobs = [ |
|
| 505 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | - ]; |
|
| 515 | - |
|
| 516 | - $spip_jobs_key = [ |
|
| 517 | - 'PRIMARY KEY' => 'id_job', |
|
| 518 | - 'KEY date' => 'date', |
|
| 519 | - 'KEY status' => 'status', |
|
| 520 | - ]; |
|
| 521 | - |
|
| 522 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | - $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 504 | + $spip_jobs = [ |
|
| 505 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | + ]; |
|
| 515 | + |
|
| 516 | + $spip_jobs_key = [ |
|
| 517 | + 'PRIMARY KEY' => 'id_job', |
|
| 518 | + 'KEY date' => 'date', |
|
| 519 | + 'KEY status' => 'status', |
|
| 520 | + ]; |
|
| 521 | + |
|
| 522 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | + $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,71 +533,71 @@ discard block |
||
| 533 | 533 | * @return void |
| 534 | 534 | **/ |
| 535 | 535 | function base_auxiliaires(&$tables_auxiliaires) { |
| 536 | - $spip_resultats = [ |
|
| 537 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | - 'maj' => 'TIMESTAMP' |
|
| 543 | - ]; |
|
| 544 | - |
|
| 545 | - $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | - ]; |
|
| 547 | - |
|
| 548 | - $spip_auteurs_liens = [ |
|
| 549 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | - ]; |
|
| 554 | - |
|
| 555 | - $spip_auteurs_liens_key = [ |
|
| 556 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | - 'KEY id_auteur' => 'id_auteur', |
|
| 558 | - 'KEY id_objet' => 'id_objet', |
|
| 559 | - 'KEY objet' => 'objet', |
|
| 560 | - ]; |
|
| 561 | - |
|
| 562 | - $spip_meta = [ |
|
| 563 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | - 'valeur' => "text DEFAULT ''", |
|
| 565 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | - 'maj' => 'TIMESTAMP' |
|
| 567 | - ]; |
|
| 568 | - |
|
| 569 | - $spip_meta_key = [ |
|
| 570 | - 'PRIMARY KEY' => 'nom' |
|
| 571 | - ]; |
|
| 572 | - |
|
| 573 | - $spip_jobs_liens = [ |
|
| 574 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | - ]; |
|
| 578 | - |
|
| 579 | - $spip_jobs_liens_key = [ |
|
| 580 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | - 'KEY id_job' => 'id_job' |
|
| 582 | - ]; |
|
| 583 | - |
|
| 584 | - $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | - 'field' => &$spip_auteurs_liens, |
|
| 586 | - 'key' => &$spip_auteurs_liens_key |
|
| 587 | - ]; |
|
| 588 | - |
|
| 589 | - $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | - 'field' => &$spip_meta, |
|
| 591 | - 'key' => &$spip_meta_key |
|
| 592 | - ]; |
|
| 593 | - $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | - 'field' => &$spip_resultats, |
|
| 595 | - 'key' => &$spip_resultats_key |
|
| 596 | - ]; |
|
| 597 | - $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | - 'field' => &$spip_jobs_liens, |
|
| 599 | - 'key' => &$spip_jobs_liens_key |
|
| 600 | - ]; |
|
| 536 | + $spip_resultats = [ |
|
| 537 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | + 'maj' => 'TIMESTAMP' |
|
| 543 | + ]; |
|
| 544 | + |
|
| 545 | + $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | + ]; |
|
| 547 | + |
|
| 548 | + $spip_auteurs_liens = [ |
|
| 549 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | + ]; |
|
| 554 | + |
|
| 555 | + $spip_auteurs_liens_key = [ |
|
| 556 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | + 'KEY id_auteur' => 'id_auteur', |
|
| 558 | + 'KEY id_objet' => 'id_objet', |
|
| 559 | + 'KEY objet' => 'objet', |
|
| 560 | + ]; |
|
| 561 | + |
|
| 562 | + $spip_meta = [ |
|
| 563 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | + 'valeur' => "text DEFAULT ''", |
|
| 565 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | + 'maj' => 'TIMESTAMP' |
|
| 567 | + ]; |
|
| 568 | + |
|
| 569 | + $spip_meta_key = [ |
|
| 570 | + 'PRIMARY KEY' => 'nom' |
|
| 571 | + ]; |
|
| 572 | + |
|
| 573 | + $spip_jobs_liens = [ |
|
| 574 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | + ]; |
|
| 578 | + |
|
| 579 | + $spip_jobs_liens_key = [ |
|
| 580 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | + 'KEY id_job' => 'id_job' |
|
| 582 | + ]; |
|
| 583 | + |
|
| 584 | + $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | + 'field' => &$spip_auteurs_liens, |
|
| 586 | + 'key' => &$spip_auteurs_liens_key |
|
| 587 | + ]; |
|
| 588 | + |
|
| 589 | + $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | + 'field' => &$spip_meta, |
|
| 591 | + 'key' => &$spip_meta_key |
|
| 592 | + ]; |
|
| 593 | + $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | + 'field' => &$spip_resultats, |
|
| 595 | + 'key' => &$spip_resultats_key |
|
| 596 | + ]; |
|
| 597 | + $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | + 'field' => &$spip_jobs_liens, |
|
| 599 | + 'key' => &$spip_jobs_liens_key |
|
| 600 | + ]; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | |
@@ -654,129 +654,129 @@ discard block |
||
| 654 | 654 | * @return array |
| 655 | 655 | */ |
| 656 | 656 | function renseigner_table_objet_sql($table_sql, &$infos) { |
| 657 | - if (!isset($infos['type'])) { |
|
| 658 | - // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | - // s'en servir pour extrapoler le type |
|
| 660 | - if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | - $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | - $primary = explode(',', $primary); |
|
| 663 | - $primary = reset($primary); |
|
| 664 | - $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | - } else { |
|
| 666 | - $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - if (!isset($infos['type_surnoms'])) { |
|
| 670 | - $infos['type_surnoms'] = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - if (!isset($infos['table_objet'])) { |
|
| 674 | - $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | - } |
|
| 676 | - if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | - $infos['table_objet_surnoms'] = []; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - if (!isset($infos['principale'])) { |
|
| 681 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | - // et dans une boucle {principale=oui} |
|
| 686 | - $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | - |
|
| 688 | - // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | - // et dans une boucle {editable=oui} |
|
| 690 | - if (!isset($infos['editable'])) { |
|
| 691 | - $infos['editable'] = 'oui'; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | - |
|
| 696 | - // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | - // seules les exceptions sont donc a declarer |
|
| 698 | - if (!isset($infos['page'])) { |
|
| 699 | - $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - if (!isset($infos['url_voir'])) { |
|
| 703 | - $infos['url_voir'] = $infos['type']; |
|
| 704 | - } |
|
| 705 | - if (!isset($infos['url_edit'])) { |
|
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | - } |
|
| 708 | - if (!isset($infos['icone_objet'])) { |
|
| 709 | - $infos['icone_objet'] = $infos['type']; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // chaines de langue |
|
| 713 | - // par defaut : objet:icone_xxx_objet |
|
| 714 | - if (!isset($infos['texte_retour'])) { |
|
| 715 | - $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | - } |
|
| 717 | - if (!isset($infos['texte_modifier'])) { |
|
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | - } |
|
| 720 | - if (!isset($infos['texte_creer'])) { |
|
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | - } |
|
| 723 | - if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | - } |
|
| 726 | - if (!isset($infos['texte_ajouter'])) { |
|
| 727 | - // Ajouter un X |
|
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | - } |
|
| 730 | - if (!isset($infos['texte_objets'])) { |
|
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | - } |
|
| 733 | - if (!isset($infos['texte_objet'])) { |
|
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | - } |
|
| 736 | - if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | - // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | - } |
|
| 740 | - if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | - // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | - } |
|
| 744 | - if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | - // "Ce X est une traduction du X numéro :" |
|
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // objet:info_aucun_objet |
|
| 750 | - if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | - } |
|
| 753 | - // objet:info_1_objet |
|
| 754 | - if (!isset($infos['info_1_objet'])) { |
|
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | - } |
|
| 757 | - // objet:info_nb_objets |
|
| 758 | - if (!isset($infos['info_nb_objets'])) { |
|
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - if (!isset($infos['champs_editables'])) { |
|
| 763 | - $infos['champs_editables'] = []; |
|
| 764 | - } |
|
| 765 | - if (!isset($infos['champs_versionnes'])) { |
|
| 766 | - $infos['champs_versionnes'] = []; |
|
| 767 | - } |
|
| 768 | - if (!isset($infos['rechercher_champs'])) { |
|
| 769 | - $infos['rechercher_champs'] = []; |
|
| 770 | - } |
|
| 771 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | - $infos['rechercher_jointures'] = []; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if (!isset($infos['modeles'])) { |
|
| 776 | - $infos['modeles'] = [$infos['type']]; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return $infos; |
|
| 657 | + if (!isset($infos['type'])) { |
|
| 658 | + // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | + // s'en servir pour extrapoler le type |
|
| 660 | + if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | + $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | + $primary = explode(',', $primary); |
|
| 663 | + $primary = reset($primary); |
|
| 664 | + $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | + } else { |
|
| 666 | + $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + if (!isset($infos['type_surnoms'])) { |
|
| 670 | + $infos['type_surnoms'] = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + if (!isset($infos['table_objet'])) { |
|
| 674 | + $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | + } |
|
| 676 | + if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | + $infos['table_objet_surnoms'] = []; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + if (!isset($infos['principale'])) { |
|
| 681 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | + // et dans une boucle {principale=oui} |
|
| 686 | + $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | + |
|
| 688 | + // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | + // et dans une boucle {editable=oui} |
|
| 690 | + if (!isset($infos['editable'])) { |
|
| 691 | + $infos['editable'] = 'oui'; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | + |
|
| 696 | + // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | + // seules les exceptions sont donc a declarer |
|
| 698 | + if (!isset($infos['page'])) { |
|
| 699 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + if (!isset($infos['url_voir'])) { |
|
| 703 | + $infos['url_voir'] = $infos['type']; |
|
| 704 | + } |
|
| 705 | + if (!isset($infos['url_edit'])) { |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | + } |
|
| 708 | + if (!isset($infos['icone_objet'])) { |
|
| 709 | + $infos['icone_objet'] = $infos['type']; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // chaines de langue |
|
| 713 | + // par defaut : objet:icone_xxx_objet |
|
| 714 | + if (!isset($infos['texte_retour'])) { |
|
| 715 | + $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | + } |
|
| 717 | + if (!isset($infos['texte_modifier'])) { |
|
| 718 | + $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | + } |
|
| 720 | + if (!isset($infos['texte_creer'])) { |
|
| 721 | + $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | + } |
|
| 723 | + if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | + } |
|
| 726 | + if (!isset($infos['texte_ajouter'])) { |
|
| 727 | + // Ajouter un X |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | + } |
|
| 730 | + if (!isset($infos['texte_objets'])) { |
|
| 731 | + $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | + } |
|
| 733 | + if (!isset($infos['texte_objet'])) { |
|
| 734 | + $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | + } |
|
| 736 | + if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | + // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | + } |
|
| 740 | + if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | + // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | + } |
|
| 744 | + if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | + // "Ce X est une traduction du X numéro :" |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // objet:info_aucun_objet |
|
| 750 | + if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | + } |
|
| 753 | + // objet:info_1_objet |
|
| 754 | + if (!isset($infos['info_1_objet'])) { |
|
| 755 | + $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | + } |
|
| 757 | + // objet:info_nb_objets |
|
| 758 | + if (!isset($infos['info_nb_objets'])) { |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + if (!isset($infos['champs_editables'])) { |
|
| 763 | + $infos['champs_editables'] = []; |
|
| 764 | + } |
|
| 765 | + if (!isset($infos['champs_versionnes'])) { |
|
| 766 | + $infos['champs_versionnes'] = []; |
|
| 767 | + } |
|
| 768 | + if (!isset($infos['rechercher_champs'])) { |
|
| 769 | + $infos['rechercher_champs'] = []; |
|
| 770 | + } |
|
| 771 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | + $infos['rechercher_jointures'] = []; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if (!isset($infos['modeles'])) { |
|
| 776 | + $infos['modeles'] = [$infos['type']]; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $infos; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -793,30 +793,30 @@ discard block |
||
| 793 | 793 | * @return array |
| 794 | 794 | */ |
| 795 | 795 | function renseigner_table_objet_interfaces($table_sql, &$infos) { |
| 796 | - if (!isset($infos['titre'])) { |
|
| 797 | - if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | - $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | - } else { |
|
| 800 | - $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | - $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (!isset($infos['date'])) { |
|
| 805 | - if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | - $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | - } else { |
|
| 808 | - $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | - $infos['tables_jointures'] ??= []; |
|
| 814 | - |
|
| 815 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | + $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | + } else { |
|
| 800 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (!isset($infos['date'])) { |
|
| 805 | + if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | + $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | + } else { |
|
| 808 | + $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | + $infos['tables_jointures'] ??= []; |
|
| 814 | + |
|
| 815 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return $infos; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | * Liste et descriptions des tables principales |
| 828 | 828 | **/ |
| 829 | 829 | function lister_tables_principales() { |
| 830 | - static $done = false; |
|
| 831 | - if (!$done or !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | - lister_tables_objets_sql(); |
|
| 833 | - $done = true; |
|
| 834 | - } |
|
| 830 | + static $done = false; |
|
| 831 | + if (!$done or !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | + lister_tables_objets_sql(); |
|
| 833 | + $done = true; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - return $GLOBALS['tables_principales']; |
|
| 836 | + return $GLOBALS['tables_principales']; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -844,13 +844,13 @@ discard block |
||
| 844 | 844 | * Liste et descriptions des tables auxiliaires |
| 845 | 845 | **/ |
| 846 | 846 | function lister_tables_auxiliaires() { |
| 847 | - static $done = false; |
|
| 848 | - if (!$done or !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | - lister_tables_objets_sql(); |
|
| 850 | - $done = true; |
|
| 851 | - } |
|
| 847 | + static $done = false; |
|
| 848 | + if (!$done or !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | + lister_tables_objets_sql(); |
|
| 850 | + $done = true; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - return $GLOBALS['tables_auxiliaires']; |
|
| 853 | + return $GLOBALS['tables_auxiliaires']; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -859,45 +859,45 @@ discard block |
||
| 859 | 859 | * @return array |
| 860 | 860 | */ |
| 861 | 861 | function lister_tables_objets_surnoms() { |
| 862 | - static $surnoms = null; |
|
| 863 | - static $md5 = null; |
|
| 864 | - if ( |
|
| 865 | - !$surnoms |
|
| 866 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 867 | - ) { |
|
| 868 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 869 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 870 | - // declarer_table_objets_sql |
|
| 871 | - $surnoms = pipeline( |
|
| 872 | - 'declarer_tables_objets_surnoms', |
|
| 873 | - [ |
|
| 874 | - # pour les modeles |
|
| 875 | - # a enlever ? |
|
| 876 | - 'doc' => 'documents', |
|
| 877 | - 'img' => 'documents', |
|
| 878 | - 'emb' => 'documents', |
|
| 879 | - ] |
|
| 880 | - ); |
|
| 881 | - $infos_tables = lister_tables_objets_sql(); |
|
| 882 | - foreach ($infos_tables as $t => $infos) { |
|
| 883 | - // cas de base type=>table |
|
| 884 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 885 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 886 | - // optimisations pour table_objet |
|
| 887 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 888 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 889 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 890 | - if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 891 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 892 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - return $surnoms; |
|
| 862 | + static $surnoms = null; |
|
| 863 | + static $md5 = null; |
|
| 864 | + if ( |
|
| 865 | + !$surnoms |
|
| 866 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 867 | + ) { |
|
| 868 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 869 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 870 | + // declarer_table_objets_sql |
|
| 871 | + $surnoms = pipeline( |
|
| 872 | + 'declarer_tables_objets_surnoms', |
|
| 873 | + [ |
|
| 874 | + # pour les modeles |
|
| 875 | + # a enlever ? |
|
| 876 | + 'doc' => 'documents', |
|
| 877 | + 'img' => 'documents', |
|
| 878 | + 'emb' => 'documents', |
|
| 879 | + ] |
|
| 880 | + ); |
|
| 881 | + $infos_tables = lister_tables_objets_sql(); |
|
| 882 | + foreach ($infos_tables as $t => $infos) { |
|
| 883 | + // cas de base type=>table |
|
| 884 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 885 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 886 | + // optimisations pour table_objet |
|
| 887 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 888 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 889 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 890 | + if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 891 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 892 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + return $surnoms; |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -906,35 +906,35 @@ discard block |
||
| 906 | 906 | * @return array |
| 907 | 907 | */ |
| 908 | 908 | function lister_types_surnoms() { |
| 909 | - static $surnoms = null; |
|
| 910 | - static $md5 = null; |
|
| 911 | - if ( |
|
| 912 | - !$surnoms |
|
| 913 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 914 | - ) { |
|
| 915 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 916 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 917 | - // declarer_table_objets_sql |
|
| 918 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 919 | - $infos_tables = lister_tables_objets_sql(); |
|
| 920 | - foreach ($infos_tables as $t => $infos) { |
|
| 921 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 922 | - // optimisations pour objet_type |
|
| 923 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 924 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 925 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 926 | - // surnoms declares |
|
| 927 | - if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 928 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 929 | - $surnoms[$surnom] = $infos['type']; |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - return $surnoms; |
|
| 909 | + static $surnoms = null; |
|
| 910 | + static $md5 = null; |
|
| 911 | + if ( |
|
| 912 | + !$surnoms |
|
| 913 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 914 | + ) { |
|
| 915 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 916 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 917 | + // declarer_table_objets_sql |
|
| 918 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 919 | + $infos_tables = lister_tables_objets_sql(); |
|
| 920 | + foreach ($infos_tables as $t => $infos) { |
|
| 921 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 922 | + // optimisations pour objet_type |
|
| 923 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 924 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 925 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 926 | + // surnoms declares |
|
| 927 | + if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 928 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 929 | + $surnoms[$surnom] = $infos['type']; |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + return $surnoms; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -948,22 +948,22 @@ discard block |
||
| 948 | 948 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 949 | 949 | **/ |
| 950 | 950 | function lister_tables_spip($serveur = '') { |
| 951 | - static $tables = []; |
|
| 952 | - if (!isset($tables[$serveur])) { |
|
| 953 | - $tables[$serveur] = []; |
|
| 954 | - if (!function_exists('sql_alltable')) { |
|
| 955 | - include_spip('base/abstract_sql'); |
|
| 956 | - } |
|
| 957 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 958 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 959 | - $spip = $connexion['prefixe'] . '_'; |
|
| 960 | - foreach ($ts as $t) { |
|
| 961 | - $t = substr($t, strlen($spip)); |
|
| 962 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - return $tables[$serveur]; |
|
| 951 | + static $tables = []; |
|
| 952 | + if (!isset($tables[$serveur])) { |
|
| 953 | + $tables[$serveur] = []; |
|
| 954 | + if (!function_exists('sql_alltable')) { |
|
| 955 | + include_spip('base/abstract_sql'); |
|
| 956 | + } |
|
| 957 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 958 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 959 | + $spip = $connexion['prefixe'] . '_'; |
|
| 960 | + foreach ($ts as $t) { |
|
| 961 | + $t = substr($t, strlen($spip)); |
|
| 962 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + return $tables[$serveur]; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | |
@@ -978,18 +978,18 @@ discard block |
||
| 978 | 978 | * Couples (nom de la table SQL => même nom) |
| 979 | 979 | **/ |
| 980 | 980 | function lister_toutes_tables($serveur) { |
| 981 | - static $tables = []; |
|
| 982 | - if (!isset($tables[$serveur])) { |
|
| 983 | - $tables[$serveur] = []; |
|
| 984 | - if (!function_exists('sql_alltable')) { |
|
| 985 | - include_spip('base/abstract_sql'); |
|
| 986 | - } |
|
| 987 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 988 | - foreach ($ts as $t) { |
|
| 989 | - $tables[$serveur][$t] = $t; |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - return $tables[$serveur]; |
|
| 981 | + static $tables = []; |
|
| 982 | + if (!isset($tables[$serveur])) { |
|
| 983 | + $tables[$serveur] = []; |
|
| 984 | + if (!function_exists('sql_alltable')) { |
|
| 985 | + include_spip('base/abstract_sql'); |
|
| 986 | + } |
|
| 987 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 988 | + foreach ($ts as $t) { |
|
| 989 | + $tables[$serveur][$t] = $t; |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + return $tables[$serveur]; |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | /** |
@@ -1010,39 +1010,39 @@ discard block |
||
| 1010 | 1010 | **/ |
| 1011 | 1011 | function table_objet(string $type, string $serveur = ''): string { |
| 1012 | 1012 | |
| 1013 | - if ($type) { |
|
| 1014 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1015 | - } |
|
| 1016 | - if (!strlen($type)) { |
|
| 1017 | - return ''; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1021 | - if (isset($surnoms[$type])) { |
|
| 1022 | - return $surnoms[$type]; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - if ($serveur !== false) { |
|
| 1026 | - $t = lister_tables_spip($serveur); |
|
| 1027 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1028 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1029 | - if ( |
|
| 1030 | - (isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1031 | - and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1032 | - ) { |
|
| 1033 | - return $desc['id_table']; |
|
| 1034 | - } elseif ( |
|
| 1035 | - (isset($t[$type]) or in_array($type, $t)) |
|
| 1036 | - and ($desc = $trouver_table($type, $serveur)) |
|
| 1037 | - ) { |
|
| 1038 | - return $desc['id_table']; |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1042 | - #spip_log(debug_backtrace(),'db'); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1013 | + if ($type) { |
|
| 1014 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1015 | + } |
|
| 1016 | + if (!strlen($type)) { |
|
| 1017 | + return ''; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1021 | + if (isset($surnoms[$type])) { |
|
| 1022 | + return $surnoms[$type]; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + if ($serveur !== false) { |
|
| 1026 | + $t = lister_tables_spip($serveur); |
|
| 1027 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1028 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1029 | + if ( |
|
| 1030 | + (isset($t[$typetrim]) or in_array($typetrim, $t)) |
|
| 1031 | + and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1032 | + ) { |
|
| 1033 | + return $desc['id_table']; |
|
| 1034 | + } elseif ( |
|
| 1035 | + (isset($t[$type]) or in_array($type, $t)) |
|
| 1036 | + and ($desc = $trouver_table($type, $serveur)) |
|
| 1037 | + ) { |
|
| 1038 | + return $desc['id_table']; |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1042 | + #spip_log(debug_backtrace(),'db'); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1063,33 +1063,33 @@ discard block |
||
| 1063 | 1063 | **/ |
| 1064 | 1064 | function table_objet_sql(string $type, string $serveur = ''): string { |
| 1065 | 1065 | |
| 1066 | - $nom = table_objet($type, $serveur); |
|
| 1067 | - if (!strlen($nom)) { |
|
| 1068 | - return ''; |
|
| 1069 | - } |
|
| 1070 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1071 | - // eviter de multiples inclusions |
|
| 1072 | - include_spip('public/interfaces'); |
|
| 1073 | - } |
|
| 1074 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1075 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1076 | - $nom = "spip_$nom"; |
|
| 1077 | - } else { |
|
| 1078 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1079 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1080 | - $nom = "spip_$nom"; |
|
| 1081 | - } elseif ($serveur !== false) { |
|
| 1082 | - $t = lister_tables_spip($serveur); |
|
| 1083 | - if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1084 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1085 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1086 | - return $desc['table_sql']; |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - return $nom; |
|
| 1066 | + $nom = table_objet($type, $serveur); |
|
| 1067 | + if (!strlen($nom)) { |
|
| 1068 | + return ''; |
|
| 1069 | + } |
|
| 1070 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1071 | + // eviter de multiples inclusions |
|
| 1072 | + include_spip('public/interfaces'); |
|
| 1073 | + } |
|
| 1074 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1075 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1076 | + $nom = "spip_$nom"; |
|
| 1077 | + } else { |
|
| 1078 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1079 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1080 | + $nom = "spip_$nom"; |
|
| 1081 | + } elseif ($serveur !== false) { |
|
| 1082 | + $t = lister_tables_spip($serveur); |
|
| 1083 | + if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1084 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1085 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1086 | + return $desc['table_sql']; |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + return $nom; |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1108,35 +1108,35 @@ discard block |
||
| 1108 | 1108 | * Nom de la clé primaire |
| 1109 | 1109 | **/ |
| 1110 | 1110 | function id_table_objet($type, $serveur = '') { |
| 1111 | - static $trouver_table = null; |
|
| 1112 | - $type = objet_type($type, $serveur); |
|
| 1113 | - if (!$type) { |
|
| 1114 | - return; |
|
| 1115 | - } |
|
| 1116 | - $t = table_objet($type); |
|
| 1117 | - if (!$trouver_table) { |
|
| 1118 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - $ts = lister_tables_spip($serveur); |
|
| 1122 | - if ( |
|
| 1123 | - in_array($t, $ts) |
|
| 1124 | - or in_array($t, lister_toutes_tables($serveur)) |
|
| 1125 | - ) { |
|
| 1126 | - $desc = $trouver_table($t, $serveur); |
|
| 1127 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1128 | - return $desc['key']['PRIMARY KEY']; |
|
| 1129 | - } |
|
| 1130 | - if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1131 | - return "id_$type"; |
|
| 1132 | - } |
|
| 1133 | - // sinon renvoyer le premier champ de la table... |
|
| 1134 | - $keys = array_keys($desc['field']); |
|
| 1135 | - |
|
| 1136 | - return array_shift($keys); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - return "id_$type"; |
|
| 1111 | + static $trouver_table = null; |
|
| 1112 | + $type = objet_type($type, $serveur); |
|
| 1113 | + if (!$type) { |
|
| 1114 | + return; |
|
| 1115 | + } |
|
| 1116 | + $t = table_objet($type); |
|
| 1117 | + if (!$trouver_table) { |
|
| 1118 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + $ts = lister_tables_spip($serveur); |
|
| 1122 | + if ( |
|
| 1123 | + in_array($t, $ts) |
|
| 1124 | + or in_array($t, lister_toutes_tables($serveur)) |
|
| 1125 | + ) { |
|
| 1126 | + $desc = $trouver_table($t, $serveur); |
|
| 1127 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1128 | + return $desc['key']['PRIMARY KEY']; |
|
| 1129 | + } |
|
| 1130 | + if (!$desc or isset($desc['field']["id_$type"])) { |
|
| 1131 | + return "id_$type"; |
|
| 1132 | + } |
|
| 1133 | + // sinon renvoyer le premier champ de la table... |
|
| 1134 | + $keys = array_keys($desc['field']); |
|
| 1135 | + |
|
| 1136 | + return array_shift($keys); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + return "id_$type"; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | /** |
@@ -1155,60 +1155,60 @@ discard block |
||
| 1155 | 1155 | * Type de l'objet |
| 1156 | 1156 | **/ |
| 1157 | 1157 | function objet_type(string $table_objet, string $serveur = '') : ?string { |
| 1158 | - if (!$table_objet) { |
|
| 1159 | - return null; |
|
| 1160 | - } |
|
| 1161 | - $surnoms = lister_types_surnoms(); |
|
| 1162 | - |
|
| 1163 | - // scenario de base |
|
| 1164 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1165 | - // et la marque du pluriel |
|
| 1166 | - // on accepte id_xx en entree aussi |
|
| 1167 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1168 | - if (isset($surnoms[$type])) { |
|
| 1169 | - return $surnoms[$type]; |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - // securite : eliminer les caracteres non \w |
|
| 1173 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1174 | - |
|
| 1175 | - // si le type redonne bien la table c'est bon |
|
| 1176 | - // oui si table_objet ressemblait deja a un type |
|
| 1177 | - if ( |
|
| 1178 | - $type == $table_objet |
|
| 1179 | - or (table_objet($type, $serveur) == $table_objet) |
|
| 1180 | - or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1181 | - ) { |
|
| 1182 | - return $type; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - // si on ne veut pas chercher en base |
|
| 1186 | - if ($serveur === false) { |
|
| 1187 | - return $type; |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1191 | - // car le s a la fin est incertain |
|
| 1192 | - // notamment en cas de pluriel derogatoire |
|
| 1193 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1194 | - // une declaration jeu => jeux, journal => journaux |
|
| 1195 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1196 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1197 | - $ts = lister_tables_spip($serveur); |
|
| 1198 | - $desc = false; |
|
| 1199 | - if (in_array($table_objet, $ts)) { |
|
| 1200 | - $desc = $trouver_table($table_objet); |
|
| 1201 | - } |
|
| 1202 | - if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1203 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1204 | - } |
|
| 1205 | - // si le type est declare : bingo ! |
|
| 1206 | - if ($desc and isset($desc['type'])) { |
|
| 1207 | - return $desc['type']; |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - // on a fait ce qu'on a pu |
|
| 1211 | - return $type; |
|
| 1158 | + if (!$table_objet) { |
|
| 1159 | + return null; |
|
| 1160 | + } |
|
| 1161 | + $surnoms = lister_types_surnoms(); |
|
| 1162 | + |
|
| 1163 | + // scenario de base |
|
| 1164 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1165 | + // et la marque du pluriel |
|
| 1166 | + // on accepte id_xx en entree aussi |
|
| 1167 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1168 | + if (isset($surnoms[$type])) { |
|
| 1169 | + return $surnoms[$type]; |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + // securite : eliminer les caracteres non \w |
|
| 1173 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1174 | + |
|
| 1175 | + // si le type redonne bien la table c'est bon |
|
| 1176 | + // oui si table_objet ressemblait deja a un type |
|
| 1177 | + if ( |
|
| 1178 | + $type == $table_objet |
|
| 1179 | + or (table_objet($type, $serveur) == $table_objet) |
|
| 1180 | + or (table_objet_sql($type, $serveur) == $table_objet) |
|
| 1181 | + ) { |
|
| 1182 | + return $type; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + // si on ne veut pas chercher en base |
|
| 1186 | + if ($serveur === false) { |
|
| 1187 | + return $type; |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1191 | + // car le s a la fin est incertain |
|
| 1192 | + // notamment en cas de pluriel derogatoire |
|
| 1193 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1194 | + // une declaration jeu => jeux, journal => journaux |
|
| 1195 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1196 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1197 | + $ts = lister_tables_spip($serveur); |
|
| 1198 | + $desc = false; |
|
| 1199 | + if (in_array($table_objet, $ts)) { |
|
| 1200 | + $desc = $trouver_table($table_objet); |
|
| 1201 | + } |
|
| 1202 | + if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1203 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1204 | + } |
|
| 1205 | + // si le type est declare : bingo ! |
|
| 1206 | + if ($desc and isset($desc['type'])) { |
|
| 1207 | + return $desc['type']; |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + // on a fait ce qu'on a pu |
|
| 1211 | + return $type; |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | /** |
@@ -1224,62 +1224,62 @@ discard block |
||
| 1224 | 1224 | * @return bool |
| 1225 | 1225 | */ |
| 1226 | 1226 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1227 | - // voir si une fonction est definie pour faire le boulot |
|
| 1228 | - // elle a la priorite dans ce cas |
|
| 1229 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1230 | - return $f($objet, $id_objet, $serveur); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1234 | - $id_table = $table_objet = table_objet($objet); |
|
| 1235 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1236 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1237 | - if ( |
|
| 1238 | - $desc = $trouver_table($table_objet, $serveur) |
|
| 1239 | - and isset($desc['statut']) |
|
| 1240 | - and $desc['statut'] |
|
| 1241 | - ) { |
|
| 1242 | - $boucle = new Boucle(); |
|
| 1243 | - $boucle->show = $desc; |
|
| 1244 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1245 | - $boucle->id_boucle = $id_table; |
|
| 1246 | - $boucle->id_table = $id_table; |
|
| 1247 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1248 | - $boucle->sql_serveur = $serveur; |
|
| 1249 | - $boucle->select[] = $id_table_objet; |
|
| 1250 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1251 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1252 | - |
|
| 1253 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1254 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1255 | - $boucle->descr['gram'] = 'html'; |
|
| 1256 | - |
|
| 1257 | - include_spip('public/compiler'); |
|
| 1258 | - include_spip('public/composer'); |
|
| 1259 | - instituer_boucle($boucle, false, true); |
|
| 1260 | - $res = calculer_select( |
|
| 1261 | - $boucle->select, |
|
| 1262 | - $boucle->from, |
|
| 1263 | - $boucle->from_type, |
|
| 1264 | - $boucle->where, |
|
| 1265 | - $boucle->join, |
|
| 1266 | - $boucle->group, |
|
| 1267 | - $boucle->order, |
|
| 1268 | - $boucle->limit, |
|
| 1269 | - $boucle->having, |
|
| 1270 | - $table_objet, |
|
| 1271 | - $id_table, |
|
| 1272 | - $serveur |
|
| 1273 | - ); |
|
| 1274 | - if (sql_fetch($res)) { |
|
| 1275 | - return true; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - return false; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1282 | - return true; |
|
| 1227 | + // voir si une fonction est definie pour faire le boulot |
|
| 1228 | + // elle a la priorite dans ce cas |
|
| 1229 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1230 | + return $f($objet, $id_objet, $serveur); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1234 | + $id_table = $table_objet = table_objet($objet); |
|
| 1235 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1236 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1237 | + if ( |
|
| 1238 | + $desc = $trouver_table($table_objet, $serveur) |
|
| 1239 | + and isset($desc['statut']) |
|
| 1240 | + and $desc['statut'] |
|
| 1241 | + ) { |
|
| 1242 | + $boucle = new Boucle(); |
|
| 1243 | + $boucle->show = $desc; |
|
| 1244 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1245 | + $boucle->id_boucle = $id_table; |
|
| 1246 | + $boucle->id_table = $id_table; |
|
| 1247 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1248 | + $boucle->sql_serveur = $serveur; |
|
| 1249 | + $boucle->select[] = $id_table_objet; |
|
| 1250 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1251 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet); |
|
| 1252 | + |
|
| 1253 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1254 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1255 | + $boucle->descr['gram'] = 'html'; |
|
| 1256 | + |
|
| 1257 | + include_spip('public/compiler'); |
|
| 1258 | + include_spip('public/composer'); |
|
| 1259 | + instituer_boucle($boucle, false, true); |
|
| 1260 | + $res = calculer_select( |
|
| 1261 | + $boucle->select, |
|
| 1262 | + $boucle->from, |
|
| 1263 | + $boucle->from_type, |
|
| 1264 | + $boucle->where, |
|
| 1265 | + $boucle->join, |
|
| 1266 | + $boucle->group, |
|
| 1267 | + $boucle->order, |
|
| 1268 | + $boucle->limit, |
|
| 1269 | + $boucle->having, |
|
| 1270 | + $table_objet, |
|
| 1271 | + $id_table, |
|
| 1272 | + $serveur |
|
| 1273 | + ); |
|
| 1274 | + if (sql_fetch($res)) { |
|
| 1275 | + return true; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + return false; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1282 | + return true; |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | |
@@ -1314,124 +1314,124 @@ discard block |
||
| 1314 | 1314 | * Retourne un tableau décrivant les parents trouvés |
| 1315 | 1315 | */ |
| 1316 | 1316 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1317 | - $parents = []; |
|
| 1318 | - |
|
| 1319 | - // Si on trouve une ou des méthodes de parent |
|
| 1320 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1321 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1322 | - include_spip('base/abstract_sql'); |
|
| 1323 | - $table_objet = table_objet_sql($objet); |
|
| 1324 | - $cle_objet = id_table_objet($objet); |
|
| 1325 | - $id_objet = intval($id_objet); |
|
| 1326 | - |
|
| 1327 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1328 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1329 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1330 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1331 | - // de celle de l'objet source |
|
| 1332 | - $select = []; |
|
| 1333 | - if (isset($parent_methode['champ'])) { |
|
| 1334 | - $select[] = $parent_methode['champ']; |
|
| 1335 | - } |
|
| 1336 | - if (isset($parent_methode['champ_type'])) { |
|
| 1337 | - $select[] = $parent_methode['champ_type']; |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1341 | - $condition_objet_invalide = false; |
|
| 1342 | - $where = []; |
|
| 1343 | - if (!isset($parent_methode['table'])) { |
|
| 1344 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1345 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1346 | - $table = $table_objet; |
|
| 1347 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1348 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1349 | - if (isset($parent_methode['condition'])) { |
|
| 1350 | - $where[] = $parent_methode['condition']; |
|
| 1351 | - } |
|
| 1352 | - } elseif (!$parent_direct_seulement) { |
|
| 1353 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1354 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1355 | - // Si non, on peut arrêter le traitement. |
|
| 1356 | - if (isset($parent_methode['condition'])) { |
|
| 1357 | - $where = [ |
|
| 1358 | - "$cle_objet = $id_objet", |
|
| 1359 | - $parent_methode['condition'] |
|
| 1360 | - ]; |
|
| 1361 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1362 | - $condition_objet_invalide = true; |
|
| 1363 | - } |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1367 | - // la requête sur la table qui accueille le parent. |
|
| 1368 | - if (!$condition_objet_invalide) { |
|
| 1369 | - $table = $parent_methode['table']; |
|
| 1370 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1371 | - $where = []; |
|
| 1372 | - // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1373 | - // le même que celui de l'objet source. |
|
| 1374 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1375 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1376 | - : "${cle_objet} = $id_objet"; |
|
| 1377 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1378 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1379 | - } |
|
| 1380 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1381 | - if (isset($parent_methode['table_condition'])) { |
|
| 1382 | - $where[] = $parent_methode['table_condition']; |
|
| 1383 | - } |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - // On lance la requête de récupération du parent |
|
| 1388 | - $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1389 | - if ( |
|
| 1390 | - !$condition_objet_invalide |
|
| 1391 | - and $where |
|
| 1392 | - and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1393 | - ) { |
|
| 1394 | - foreach ($lignes as $ligne) { |
|
| 1395 | - // Si le type est fixe |
|
| 1396 | - if (isset($parent_methode['type'])) { |
|
| 1397 | - $parent = [ |
|
| 1398 | - 'objet' => $parent_methode['type'], |
|
| 1399 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1400 | - 'champ' => $parent_methode['champ'], |
|
| 1401 | - 'table' => $table, |
|
| 1402 | - ]; |
|
| 1403 | - } |
|
| 1404 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1405 | - $parent = [ |
|
| 1406 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1407 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1408 | - 'champ' => $parent_methode['champ'], |
|
| 1409 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1410 | - 'table' => $table, |
|
| 1411 | - ]; |
|
| 1412 | - } |
|
| 1413 | - if ($is_table_lien) { |
|
| 1414 | - $parent['lien'] = $ligne; |
|
| 1415 | - } |
|
| 1416 | - $parents[] = $parent; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - // On passe par un pipeline avant de retourner |
|
| 1423 | - $parents = pipeline( |
|
| 1424 | - 'objet_lister_parents', |
|
| 1425 | - [ |
|
| 1426 | - 'args' => [ |
|
| 1427 | - 'objet' => $objet, |
|
| 1428 | - 'id_objet' => $id_objet, |
|
| 1429 | - ], |
|
| 1430 | - 'data' => $parents, |
|
| 1431 | - ] |
|
| 1432 | - ); |
|
| 1433 | - |
|
| 1434 | - return $parents; |
|
| 1317 | + $parents = []; |
|
| 1318 | + |
|
| 1319 | + // Si on trouve une ou des méthodes de parent |
|
| 1320 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1321 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1322 | + include_spip('base/abstract_sql'); |
|
| 1323 | + $table_objet = table_objet_sql($objet); |
|
| 1324 | + $cle_objet = id_table_objet($objet); |
|
| 1325 | + $id_objet = intval($id_objet); |
|
| 1326 | + |
|
| 1327 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1328 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1329 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1330 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1331 | + // de celle de l'objet source |
|
| 1332 | + $select = []; |
|
| 1333 | + if (isset($parent_methode['champ'])) { |
|
| 1334 | + $select[] = $parent_methode['champ']; |
|
| 1335 | + } |
|
| 1336 | + if (isset($parent_methode['champ_type'])) { |
|
| 1337 | + $select[] = $parent_methode['champ_type']; |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1341 | + $condition_objet_invalide = false; |
|
| 1342 | + $where = []; |
|
| 1343 | + if (!isset($parent_methode['table'])) { |
|
| 1344 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1345 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1346 | + $table = $table_objet; |
|
| 1347 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1348 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1349 | + if (isset($parent_methode['condition'])) { |
|
| 1350 | + $where[] = $parent_methode['condition']; |
|
| 1351 | + } |
|
| 1352 | + } elseif (!$parent_direct_seulement) { |
|
| 1353 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1354 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1355 | + // Si non, on peut arrêter le traitement. |
|
| 1356 | + if (isset($parent_methode['condition'])) { |
|
| 1357 | + $where = [ |
|
| 1358 | + "$cle_objet = $id_objet", |
|
| 1359 | + $parent_methode['condition'] |
|
| 1360 | + ]; |
|
| 1361 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1362 | + $condition_objet_invalide = true; |
|
| 1363 | + } |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1367 | + // la requête sur la table qui accueille le parent. |
|
| 1368 | + if (!$condition_objet_invalide) { |
|
| 1369 | + $table = $parent_methode['table']; |
|
| 1370 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1371 | + $where = []; |
|
| 1372 | + // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1373 | + // le même que celui de l'objet source. |
|
| 1374 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1375 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1376 | + : "${cle_objet} = $id_objet"; |
|
| 1377 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1378 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1379 | + } |
|
| 1380 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1381 | + if (isset($parent_methode['table_condition'])) { |
|
| 1382 | + $where[] = $parent_methode['table_condition']; |
|
| 1383 | + } |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + // On lance la requête de récupération du parent |
|
| 1388 | + $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1389 | + if ( |
|
| 1390 | + !$condition_objet_invalide |
|
| 1391 | + and $where |
|
| 1392 | + and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1393 | + ) { |
|
| 1394 | + foreach ($lignes as $ligne) { |
|
| 1395 | + // Si le type est fixe |
|
| 1396 | + if (isset($parent_methode['type'])) { |
|
| 1397 | + $parent = [ |
|
| 1398 | + 'objet' => $parent_methode['type'], |
|
| 1399 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1400 | + 'champ' => $parent_methode['champ'], |
|
| 1401 | + 'table' => $table, |
|
| 1402 | + ]; |
|
| 1403 | + } |
|
| 1404 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1405 | + $parent = [ |
|
| 1406 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1407 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1408 | + 'champ' => $parent_methode['champ'], |
|
| 1409 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1410 | + 'table' => $table, |
|
| 1411 | + ]; |
|
| 1412 | + } |
|
| 1413 | + if ($is_table_lien) { |
|
| 1414 | + $parent['lien'] = $ligne; |
|
| 1415 | + } |
|
| 1416 | + $parents[] = $parent; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + // On passe par un pipeline avant de retourner |
|
| 1423 | + $parents = pipeline( |
|
| 1424 | + 'objet_lister_parents', |
|
| 1425 | + [ |
|
| 1426 | + 'args' => [ |
|
| 1427 | + 'objet' => $objet, |
|
| 1428 | + 'id_objet' => $id_objet, |
|
| 1429 | + ], |
|
| 1430 | + 'data' => $parents, |
|
| 1431 | + ] |
|
| 1432 | + ); |
|
| 1433 | + |
|
| 1434 | + return $parents; |
|
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | /** |
@@ -1443,17 +1443,17 @@ discard block |
||
| 1443 | 1443 | * @return array |
| 1444 | 1444 | */ |
| 1445 | 1445 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1446 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1446 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1447 | 1447 | |
| 1448 | - $parents_par_type = []; |
|
| 1449 | - foreach ($parents as $parent) { |
|
| 1450 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1451 | - $parents_par_type[$parent['objet']] = []; |
|
| 1452 | - } |
|
| 1453 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1454 | - } |
|
| 1448 | + $parents_par_type = []; |
|
| 1449 | + foreach ($parents as $parent) { |
|
| 1450 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1451 | + $parents_par_type[$parent['objet']] = []; |
|
| 1452 | + } |
|
| 1453 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1454 | + } |
|
| 1455 | 1455 | |
| 1456 | - return $parents_par_type; |
|
| 1456 | + return $parents_par_type; |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | |
@@ -1486,85 +1486,85 @@ discard block |
||
| 1486 | 1486 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1487 | 1487 | */ |
| 1488 | 1488 | function objet_lister_enfants($objet, $id_objet) { |
| 1489 | - $enfants = []; |
|
| 1490 | - |
|
| 1491 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1492 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1493 | - include_spip('base/abstract_sql'); |
|
| 1494 | - $id_objet = intval($id_objet); |
|
| 1495 | - |
|
| 1496 | - // On parcourt tous les types d'enfants trouvés |
|
| 1497 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1498 | - // On construit les conditions d'identification du parent |
|
| 1499 | - $where = []; |
|
| 1500 | - // -- L'identifiant du parent |
|
| 1501 | - if (isset($_methode_parent['champ'])) { |
|
| 1502 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1503 | - } |
|
| 1504 | - // -- Si le parent est variable |
|
| 1505 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1506 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1510 | - if (!isset($_methode_parent['table'])) { |
|
| 1511 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1512 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1513 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1514 | - |
|
| 1515 | - // S'il y a une condition supplémentaire |
|
| 1516 | - if (isset($_methode_parent['condition'])) { |
|
| 1517 | - $where[] = $_methode_parent['condition']; |
|
| 1518 | - } |
|
| 1519 | - } else { |
|
| 1520 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1521 | - $table_enfant = $_methode_parent['table']; |
|
| 1522 | - $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1523 | - |
|
| 1524 | - // S'il y a une condition supplémentaire |
|
| 1525 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1526 | - $where[] = $_methode_parent['table_condition']; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - // On lance la requête |
|
| 1531 | - $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1532 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1533 | - $enfant = [ |
|
| 1534 | - 'objet' => $objet_enfant, |
|
| 1535 | - 'id_objet' => 0, |
|
| 1536 | - 'table' => $table_enfant |
|
| 1537 | - ]; |
|
| 1538 | - if (isset($_methode_parent['champ'])) { |
|
| 1539 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1540 | - } |
|
| 1541 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1542 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1543 | - } |
|
| 1544 | - foreach ($rows as $row) { |
|
| 1545 | - $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1546 | - if ($is_table_lien) { |
|
| 1547 | - $enfant['lien'] = $row; |
|
| 1548 | - } |
|
| 1549 | - $enfants[] = $enfant; |
|
| 1550 | - } |
|
| 1551 | - } |
|
| 1552 | - } |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - // On passe par un pipeline avant de retourner |
|
| 1556 | - $enfants = pipeline( |
|
| 1557 | - 'objet_lister_enfants', |
|
| 1558 | - [ |
|
| 1559 | - 'args' => [ |
|
| 1560 | - 'objet' => $objet, |
|
| 1561 | - 'id_objet' => $id_objet, |
|
| 1562 | - ], |
|
| 1563 | - 'data' => $enfants, |
|
| 1564 | - ] |
|
| 1565 | - ); |
|
| 1566 | - |
|
| 1567 | - return $enfants; |
|
| 1489 | + $enfants = []; |
|
| 1490 | + |
|
| 1491 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1492 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1493 | + include_spip('base/abstract_sql'); |
|
| 1494 | + $id_objet = intval($id_objet); |
|
| 1495 | + |
|
| 1496 | + // On parcourt tous les types d'enfants trouvés |
|
| 1497 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1498 | + // On construit les conditions d'identification du parent |
|
| 1499 | + $where = []; |
|
| 1500 | + // -- L'identifiant du parent |
|
| 1501 | + if (isset($_methode_parent['champ'])) { |
|
| 1502 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1503 | + } |
|
| 1504 | + // -- Si le parent est variable |
|
| 1505 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1506 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1510 | + if (!isset($_methode_parent['table'])) { |
|
| 1511 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1512 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1513 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1514 | + |
|
| 1515 | + // S'il y a une condition supplémentaire |
|
| 1516 | + if (isset($_methode_parent['condition'])) { |
|
| 1517 | + $where[] = $_methode_parent['condition']; |
|
| 1518 | + } |
|
| 1519 | + } else { |
|
| 1520 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1521 | + $table_enfant = $_methode_parent['table']; |
|
| 1522 | + $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1523 | + |
|
| 1524 | + // S'il y a une condition supplémentaire |
|
| 1525 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1526 | + $where[] = $_methode_parent['table_condition']; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + // On lance la requête |
|
| 1531 | + $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1532 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1533 | + $enfant = [ |
|
| 1534 | + 'objet' => $objet_enfant, |
|
| 1535 | + 'id_objet' => 0, |
|
| 1536 | + 'table' => $table_enfant |
|
| 1537 | + ]; |
|
| 1538 | + if (isset($_methode_parent['champ'])) { |
|
| 1539 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1540 | + } |
|
| 1541 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1542 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1543 | + } |
|
| 1544 | + foreach ($rows as $row) { |
|
| 1545 | + $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1546 | + if ($is_table_lien) { |
|
| 1547 | + $enfant['lien'] = $row; |
|
| 1548 | + } |
|
| 1549 | + $enfants[] = $enfant; |
|
| 1550 | + } |
|
| 1551 | + } |
|
| 1552 | + } |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + // On passe par un pipeline avant de retourner |
|
| 1556 | + $enfants = pipeline( |
|
| 1557 | + 'objet_lister_enfants', |
|
| 1558 | + [ |
|
| 1559 | + 'args' => [ |
|
| 1560 | + 'objet' => $objet, |
|
| 1561 | + 'id_objet' => $id_objet, |
|
| 1562 | + ], |
|
| 1563 | + 'data' => $enfants, |
|
| 1564 | + ] |
|
| 1565 | + ); |
|
| 1566 | + |
|
| 1567 | + return $enfants; |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | 1570 | /** |
@@ -1576,17 +1576,17 @@ discard block |
||
| 1576 | 1576 | * @return array |
| 1577 | 1577 | */ |
| 1578 | 1578 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1579 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1579 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1580 | 1580 | |
| 1581 | - $enfants_par_type = []; |
|
| 1582 | - foreach ($enfants as $enfant) { |
|
| 1583 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1584 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1585 | - } |
|
| 1586 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1587 | - } |
|
| 1581 | + $enfants_par_type = []; |
|
| 1582 | + foreach ($enfants as $enfant) { |
|
| 1583 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1584 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1585 | + } |
|
| 1586 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1587 | + } |
|
| 1588 | 1588 | |
| 1589 | - return $enfants_par_type; |
|
| 1589 | + return $enfants_par_type; |
|
| 1590 | 1590 | } |
| 1591 | 1591 | |
| 1592 | 1592 | /** |
@@ -1598,35 +1598,35 @@ discard block |
||
| 1598 | 1598 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1599 | 1599 | */ |
| 1600 | 1600 | function objet_type_decrire_infos_parents($objet) { |
| 1601 | - static $parents = []; |
|
| 1602 | - |
|
| 1603 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1604 | - if (!isset($parents[$objet])) { |
|
| 1605 | - $parents[$objet] = false; |
|
| 1606 | - $table = table_objet_sql($objet); |
|
| 1607 | - |
|
| 1608 | - // Si on trouve bien la description de cet objet |
|
| 1609 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1610 | - if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1611 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1612 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1613 | - // de description |
|
| 1614 | - if (!isset($infos['parent'][0])) { |
|
| 1615 | - $parents[$objet] = [$infos['parent']]; |
|
| 1616 | - } else { |
|
| 1617 | - $parents[$objet] = $infos['parent']; |
|
| 1618 | - } |
|
| 1619 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1620 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1621 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1622 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1623 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1624 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1625 | - } |
|
| 1626 | - } |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - return $parents[$objet]; |
|
| 1601 | + static $parents = []; |
|
| 1602 | + |
|
| 1603 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1604 | + if (!isset($parents[$objet])) { |
|
| 1605 | + $parents[$objet] = false; |
|
| 1606 | + $table = table_objet_sql($objet); |
|
| 1607 | + |
|
| 1608 | + // Si on trouve bien la description de cet objet |
|
| 1609 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1610 | + if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1611 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1612 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1613 | + // de description |
|
| 1614 | + if (!isset($infos['parent'][0])) { |
|
| 1615 | + $parents[$objet] = [$infos['parent']]; |
|
| 1616 | + } else { |
|
| 1617 | + $parents[$objet] = $infos['parent']; |
|
| 1618 | + } |
|
| 1619 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1620 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1621 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1622 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1623 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1624 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1625 | + } |
|
| 1626 | + } |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + return $parents[$objet]; |
|
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | 1632 | /** |
@@ -1638,36 +1638,36 @@ discard block |
||
| 1638 | 1638 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1639 | 1639 | */ |
| 1640 | 1640 | function objet_type_decrire_infos_enfants($objet) { |
| 1641 | - static $enfants = []; |
|
| 1642 | - |
|
| 1643 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1644 | - if (!isset($enfants[$objet])) { |
|
| 1645 | - $enfants[$objet] = []; |
|
| 1646 | - $tables = lister_tables_objets_sql(); |
|
| 1647 | - |
|
| 1648 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1649 | - foreach ($tables as $table => $infos) { |
|
| 1650 | - $objet_enfant = objet_type($table); |
|
| 1651 | - |
|
| 1652 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1653 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1654 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1655 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1656 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1657 | - if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1658 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1659 | - if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1660 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1661 | - } |
|
| 1662 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1663 | - elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1664 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1665 | - } |
|
| 1666 | - } |
|
| 1667 | - } |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - return $enfants[$objet]; |
|
| 1641 | + static $enfants = []; |
|
| 1642 | + |
|
| 1643 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1644 | + if (!isset($enfants[$objet])) { |
|
| 1645 | + $enfants[$objet] = []; |
|
| 1646 | + $tables = lister_tables_objets_sql(); |
|
| 1647 | + |
|
| 1648 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1649 | + foreach ($tables as $table => $infos) { |
|
| 1650 | + $objet_enfant = objet_type($table); |
|
| 1651 | + |
|
| 1652 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1653 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1654 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1655 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1656 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1657 | + if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1658 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1659 | + if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1660 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1661 | + } |
|
| 1662 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1663 | + elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1664 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1665 | + } |
|
| 1666 | + } |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + return $enfants[$objet]; |
|
| 1673 | 1673 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 28 | - return; |
|
| 28 | + return; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** Version de l'API SQL */ |
@@ -45,39 +45,39 @@ discard block |
||
| 45 | 45 | * contexte de l'erreur |
| 46 | 46 | **/ |
| 47 | 47 | function sql_error_backtrace($compil_info = false) { |
| 48 | - $trace = debug_backtrace(); |
|
| 49 | - $caller = array_shift($trace); |
|
| 50 | - while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | - array_shift($trace); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($compil_info) { |
|
| 55 | - $contexte_compil = [ |
|
| 56 | - $trace[0]['file'],// sourcefile |
|
| 57 | - '', //nom |
|
| 58 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | - . $trace[0]['function'] . '();' |
|
| 60 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | - $trace[0]['line'], // ligne |
|
| 62 | - $GLOBALS['spip_lang'], // lang |
|
| 63 | - ]; |
|
| 64 | - |
|
| 65 | - return $contexte_compil; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | - $f = []; |
|
| 70 | - while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - $f[] = $t['function']; |
|
| 75 | - } |
|
| 76 | - if (count($f)) { |
|
| 77 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $message; |
|
| 48 | + $trace = debug_backtrace(); |
|
| 49 | + $caller = array_shift($trace); |
|
| 50 | + while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | + array_shift($trace); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($compil_info) { |
|
| 55 | + $contexte_compil = [ |
|
| 56 | + $trace[0]['file'],// sourcefile |
|
| 57 | + '', //nom |
|
| 58 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | + . $trace[0]['function'] . '();' |
|
| 60 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | + $trace[0]['line'], // ligne |
|
| 62 | + $GLOBALS['spip_lang'], // lang |
|
| 63 | + ]; |
|
| 64 | + |
|
| 65 | + return $contexte_compil; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | + $f = []; |
|
| 70 | + while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | + $f[] = $t['function']; |
|
| 75 | + } |
|
| 76 | + if (count($f)) { |
|
| 77 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $message; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | **/ |
| 104 | 104 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 105 | - static $sql_serveur = []; |
|
| 106 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | - if (!is_string($f) or !$f) { |
|
| 109 | - return $f; |
|
| 110 | - } |
|
| 111 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 105 | + static $sql_serveur = []; |
|
| 106 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | + if (!is_string($f) or !$f) { |
|
| 109 | + return $f; |
|
| 110 | + } |
|
| 111 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -133,23 +133,23 @@ discard block |
||
| 133 | 133 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 134 | 134 | **/ |
| 135 | 135 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 136 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | - $desc = sql_serveur('', $serveur, true); |
|
| 138 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | - $c = $desc['charsets'][$charset]; |
|
| 140 | - if ($c) { |
|
| 141 | - if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | - if ($f($c, $serveur, $option !== false)) { |
|
| 143 | - return $c; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - spip_log( |
|
| 148 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | - _LOG_AVERTISSEMENT |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - return false; |
|
| 136 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | + $desc = sql_serveur('', $serveur, true); |
|
| 138 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | + $c = $desc['charsets'][$charset]; |
|
| 140 | + if ($c) { |
|
| 141 | + if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | + if ($f($c, $serveur, $option !== false)) { |
|
| 143 | + return $c; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + spip_log( |
|
| 148 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | + _LOG_AVERTISSEMENT |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + return false; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | * Retourne true si elle reussie. |
| 176 | 176 | **/ |
| 177 | 177 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 178 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | - if (!is_string($f) or !$f) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 178 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | + if (!is_string($f) or !$f) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $f($charset, $serveur, $option !== false); |
|
| 183 | + return $f($charset, $serveur, $option !== false); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -231,59 +231,59 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | **/ |
| 233 | 233 | function sql_select( |
| 234 | - $select = [], |
|
| 235 | - $from = [], |
|
| 236 | - $where = [], |
|
| 237 | - $groupby = [], |
|
| 238 | - $orderby = [], |
|
| 239 | - $limit = '', |
|
| 240 | - $having = [], |
|
| 241 | - $serveur = '', |
|
| 242 | - $option = true |
|
| 234 | + $select = [], |
|
| 235 | + $from = [], |
|
| 236 | + $where = [], |
|
| 237 | + $groupby = [], |
|
| 238 | + $orderby = [], |
|
| 239 | + $limit = '', |
|
| 240 | + $having = [], |
|
| 241 | + $serveur = '', |
|
| 242 | + $option = true |
|
| 243 | 243 | ) { |
| 244 | - $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | - if (!is_string($f) or !$f) { |
|
| 246 | - return false; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | - if (($option !== false) and !$debug) { |
|
| 251 | - $res = $f( |
|
| 252 | - $select, |
|
| 253 | - $from, |
|
| 254 | - $where, |
|
| 255 | - $groupby, |
|
| 256 | - $orderby, |
|
| 257 | - $limit, |
|
| 258 | - $having, |
|
| 259 | - $serveur, |
|
| 260 | - is_array($option) ? true : $option |
|
| 261 | - ); |
|
| 262 | - } else { |
|
| 263 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | - if (!$option) { |
|
| 265 | - return $query; |
|
| 266 | - } |
|
| 267 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | - } |
|
| 273 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // en cas d'erreur |
|
| 277 | - if (!is_string($res)) { |
|
| 278 | - return $res; |
|
| 279 | - } |
|
| 280 | - // denoncer l'erreur SQL dans sa version brute |
|
| 281 | - spip_sql_erreur($serveur); |
|
| 282 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | - $contexte_compil = sql_error_backtrace(true); |
|
| 284 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | - |
|
| 286 | - return false; |
|
| 244 | + $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | + if (!is_string($f) or !$f) { |
|
| 246 | + return false; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | + if (($option !== false) and !$debug) { |
|
| 251 | + $res = $f( |
|
| 252 | + $select, |
|
| 253 | + $from, |
|
| 254 | + $where, |
|
| 255 | + $groupby, |
|
| 256 | + $orderby, |
|
| 257 | + $limit, |
|
| 258 | + $having, |
|
| 259 | + $serveur, |
|
| 260 | + is_array($option) ? true : $option |
|
| 261 | + ); |
|
| 262 | + } else { |
|
| 263 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | + if (!$option) { |
|
| 265 | + return $query; |
|
| 266 | + } |
|
| 267 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | + } |
|
| 273 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // en cas d'erreur |
|
| 277 | + if (!is_string($res)) { |
|
| 278 | + return $res; |
|
| 279 | + } |
|
| 280 | + // denoncer l'erreur SQL dans sa version brute |
|
| 281 | + spip_sql_erreur($serveur); |
|
| 282 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | + $contexte_compil = sql_error_backtrace(true); |
|
| 284 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | + |
|
| 286 | + return false; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | **/ |
| 322 | 322 | function sql_get_select( |
| 323 | - $select = [], |
|
| 324 | - $from = [], |
|
| 325 | - $where = [], |
|
| 326 | - $groupby = [], |
|
| 327 | - $orderby = [], |
|
| 328 | - $limit = '', |
|
| 329 | - $having = [], |
|
| 330 | - $serveur = '' |
|
| 323 | + $select = [], |
|
| 324 | + $from = [], |
|
| 325 | + $where = [], |
|
| 326 | + $groupby = [], |
|
| 327 | + $orderby = [], |
|
| 328 | + $limit = '', |
|
| 329 | + $having = [], |
|
| 330 | + $serveur = '' |
|
| 331 | 331 | ) { |
| 332 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 332 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | * |
| 374 | 374 | **/ |
| 375 | 375 | function sql_countsel( |
| 376 | - $from = [], |
|
| 377 | - $where = [], |
|
| 378 | - $groupby = [], |
|
| 379 | - $having = [], |
|
| 380 | - $serveur = '', |
|
| 381 | - $option = true |
|
| 376 | + $from = [], |
|
| 377 | + $where = [], |
|
| 378 | + $groupby = [], |
|
| 379 | + $having = [], |
|
| 380 | + $serveur = '', |
|
| 381 | + $option = true |
|
| 382 | 382 | ) { |
| 383 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | - if (!is_string($f) or !$f) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | - if ($r === false) { |
|
| 389 | - spip_sql_erreur($serveur); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $r; |
|
| 383 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | + if (!is_string($f) or !$f) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | + if ($r === false) { |
|
| 389 | + spip_sql_erreur($serveur); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $r; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -421,16 +421,16 @@ discard block |
||
| 421 | 421 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 422 | 422 | **/ |
| 423 | 423 | function sql_alter($q, $serveur = '', $option = true) { |
| 424 | - $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | - if (!is_string($f) or !$f) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - $r = $f($q, $serveur, $option !== false); |
|
| 429 | - if ($r === false) { |
|
| 430 | - spip_sql_erreur($serveur); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $r; |
|
| 424 | + $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | + if (!is_string($f) or !$f) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + $r = $f($q, $serveur, $option !== false); |
|
| 429 | + if ($r === false) { |
|
| 430 | + spip_sql_erreur($serveur); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $r; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | * presentant une ligne de resultat d'une selection |
| 454 | 454 | */ |
| 455 | 455 | function sql_fetch($res, $serveur = '', $option = true) { |
| 456 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | - if (!is_string($f) or !$f) { |
|
| 458 | - return false; |
|
| 459 | - } |
|
| 456 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | + if (!is_string($f) or !$f) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - return $f($res, null, $serveur, $option !== false); |
|
| 461 | + return $f($res, null, $serveur, $option !== false); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | * presentant une ligne de resultat d'une selection |
| 486 | 486 | */ |
| 487 | 487 | function sql_fetch_all($res, $serveur = '', $option = true) { |
| 488 | - $rows = []; |
|
| 489 | - if (!$res) { |
|
| 490 | - return $rows; |
|
| 491 | - } |
|
| 492 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | - if (!is_string($f) or !$f) { |
|
| 494 | - return []; |
|
| 495 | - } |
|
| 496 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | - $rows[] = $r; |
|
| 498 | - } |
|
| 499 | - sql_free($res, $serveur); |
|
| 500 | - |
|
| 501 | - return $rows; |
|
| 488 | + $rows = []; |
|
| 489 | + if (!$res) { |
|
| 490 | + return $rows; |
|
| 491 | + } |
|
| 492 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | + if (!is_string($f) or !$f) { |
|
| 494 | + return []; |
|
| 495 | + } |
|
| 496 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | + $rows[] = $r; |
|
| 498 | + } |
|
| 499 | + sql_free($res, $serveur); |
|
| 500 | + |
|
| 501 | + return $rows; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -526,16 +526,16 @@ discard block |
||
| 526 | 526 | * Operation effectuée (true), sinon false. |
| 527 | 527 | **/ |
| 528 | 528 | function sql_seek($res, $row_number, $serveur = '', $option = true) { |
| 529 | - $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | - if (!is_string($f) or !$f) { |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | - if ($r === false) { |
|
| 535 | - spip_sql_erreur($serveur); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $r; |
|
| 529 | + $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | + if (!is_string($f) or !$f) { |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | + if ($r === false) { |
|
| 535 | + spip_sql_erreur($serveur); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $r; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | * False en cas d'erreur. |
| 561 | 561 | **/ |
| 562 | 562 | function sql_listdbs($serveur = '', $option = true) { |
| 563 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | - if (!is_string($f) or !$f) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $r = $f($serveur); |
|
| 568 | - if ($r === false) { |
|
| 569 | - spip_sql_erreur($serveur); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $r; |
|
| 563 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | + if (!is_string($f) or !$f) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $r = $f($serveur); |
|
| 568 | + if ($r === false) { |
|
| 569 | + spip_sql_erreur($serveur); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $r; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
@@ -592,16 +592,16 @@ discard block |
||
| 592 | 592 | * - False en cas d'erreur. |
| 593 | 593 | **/ |
| 594 | 594 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 595 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | - if (!is_string($f) or !$f) { |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - $r = $f($nom, $serveur, $option !== false); |
|
| 600 | - if ($r === false) { |
|
| 601 | - spip_sql_erreur($serveur); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return $r; |
|
| 595 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | + if (!is_string($f) or !$f) { |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + $r = $f($nom, $serveur, $option !== false); |
|
| 600 | + if ($r === false) { |
|
| 601 | + spip_sql_erreur($serveur); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return $r; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -626,16 +626,16 @@ discard block |
||
| 626 | 626 | * - false en cas d'erreur. |
| 627 | 627 | **/ |
| 628 | 628 | function sql_count($res, $serveur = '', $option = true) { |
| 629 | - $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | - if (!is_string($f) or !$f) { |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - $r = $f($res, $serveur, $option !== false); |
|
| 634 | - if ($r === false) { |
|
| 635 | - spip_sql_erreur($serveur); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $r; |
|
| 629 | + $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | + if (!is_string($f) or !$f) { |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + $r = $f($res, $serveur, $option !== false); |
|
| 634 | + if ($r === false) { |
|
| 635 | + spip_sql_erreur($serveur); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $r; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * True si réussi |
| 658 | 658 | */ |
| 659 | 659 | function sql_free($res, $serveur = '', $option = true) { |
| 660 | - $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | - if (!is_string($f) or !$f) { |
|
| 662 | - return false; |
|
| 663 | - } |
|
| 660 | + $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | + if (!is_string($f) or !$f) { |
|
| 662 | + return false; |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - return $f($res); |
|
| 665 | + return $f($res); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -700,17 +700,17 @@ discard block |
||
| 700 | 700 | * - False en cas d'erreur. |
| 701 | 701 | **/ |
| 702 | 702 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 703 | - $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | - if (!is_string($f) or !$f) { |
|
| 705 | - return false; |
|
| 706 | - } |
|
| 707 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | - if ($r === false or $r === null) { |
|
| 709 | - spip_sql_erreur($serveur); |
|
| 710 | - $r = false; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - return $r; |
|
| 703 | + $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | + if (!is_string($f) or !$f) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 707 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | + if ($r === false or $r === null) { |
|
| 709 | + spip_sql_erreur($serveur); |
|
| 710 | + $r = false; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + return $r; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -751,17 +751,17 @@ discard block |
||
| 751 | 751 | * - False en cas d'erreur. |
| 752 | 752 | **/ |
| 753 | 753 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 754 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | - if (!is_string($f) or !$f) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 758 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | - if ($r === false or $r === null) { |
|
| 760 | - spip_sql_erreur($serveur); |
|
| 761 | - $r = false; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return $r; |
|
| 754 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | + if (!is_string($f) or !$f) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | + if ($r === false or $r === null) { |
|
| 760 | + spip_sql_erreur($serveur); |
|
| 761 | + $r = false; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return $r; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -796,17 +796,17 @@ discard block |
||
| 796 | 796 | * - False en cas d'erreur. |
| 797 | 797 | **/ |
| 798 | 798 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 799 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | - if (!is_string($f) or !$f) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | - if ($r === false or $r === null) { |
|
| 805 | - spip_sql_erreur($serveur); |
|
| 806 | - $r = false; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $r; |
|
| 799 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | + if (!is_string($f) or !$f) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | + if ($r === false or $r === null) { |
|
| 805 | + spip_sql_erreur($serveur); |
|
| 806 | + $r = false; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $r; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -846,16 +846,16 @@ discard block |
||
| 846 | 846 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 847 | 847 | */ |
| 848 | 848 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 849 | - $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | - if (!is_string($f) or !$f) { |
|
| 851 | - return false; |
|
| 852 | - } |
|
| 853 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | - if ($r === false) { |
|
| 855 | - spip_sql_erreur($serveur); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return $r; |
|
| 849 | + $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | + if (!is_string($f) or !$f) { |
|
| 851 | + return false; |
|
| 852 | + } |
|
| 853 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | + if ($r === false) { |
|
| 855 | + spip_sql_erreur($serveur); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return $r; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | |
@@ -901,16 +901,16 @@ discard block |
||
| 901 | 901 | * - False en cas d'erreur. |
| 902 | 902 | **/ |
| 903 | 903 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 904 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | - if (!is_string($f) or !$f) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | - if ($r === false) { |
|
| 910 | - spip_sql_erreur($serveur); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - return $r; |
|
| 904 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | + if (!is_string($f) or !$f) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | + if ($r === false) { |
|
| 910 | + spip_sql_erreur($serveur); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + return $r; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -941,16 +941,16 @@ discard block |
||
| 941 | 941 | * - False en cas d'erreur. |
| 942 | 942 | **/ |
| 943 | 943 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 944 | - $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | - if (!is_string($f) or !$f) { |
|
| 946 | - return false; |
|
| 947 | - } |
|
| 948 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | - if ($r === false) { |
|
| 950 | - spip_sql_erreur($serveur); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - return $r; |
|
| 944 | + $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | + if (!is_string($f) or !$f) { |
|
| 946 | + return false; |
|
| 947 | + } |
|
| 948 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | + if ($r === false) { |
|
| 950 | + spip_sql_erreur($serveur); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + return $r; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -986,16 +986,16 @@ discard block |
||
| 986 | 986 | * - False en cas d'erreur. |
| 987 | 987 | **/ |
| 988 | 988 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 989 | - $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | - if (!is_string($f) or !$f) { |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | - if ($r === false) { |
|
| 995 | - spip_sql_erreur($serveur); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - return $r; |
|
| 989 | + $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | + if (!is_string($f) or !$f) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | + if ($r === false) { |
|
| 995 | + spip_sql_erreur($serveur); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + return $r; |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | |
@@ -1033,16 +1033,16 @@ discard block |
||
| 1033 | 1033 | * - False en cas d'erreur. |
| 1034 | 1034 | **/ |
| 1035 | 1035 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1036 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | - if (!is_string($f) or !$f) { |
|
| 1038 | - return false; |
|
| 1039 | - } |
|
| 1040 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | - if ($r === false) { |
|
| 1042 | - spip_sql_erreur($serveur); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return $r; |
|
| 1036 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | + if (!is_string($f) or !$f) { |
|
| 1038 | + return false; |
|
| 1039 | + } |
|
| 1040 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | + if ($r === false) { |
|
| 1042 | + spip_sql_erreur($serveur); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return $r; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1070,16 +1070,16 @@ discard block |
||
| 1070 | 1070 | * - False en cas d'erreur. |
| 1071 | 1071 | **/ |
| 1072 | 1072 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1073 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | - if (!is_string($f) or !$f) { |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | - if ($r === false) { |
|
| 1079 | - spip_sql_erreur($serveur); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $r; |
|
| 1073 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | + if (!is_string($f) or !$f) { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | + if ($r === false) { |
|
| 1079 | + spip_sql_erreur($serveur); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $r; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * - true si la requête a réussie, false sinon |
| 1104 | 1104 | */ |
| 1105 | 1105 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1106 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | - if (!is_string($f) or !$f) { |
|
| 1108 | - return false; |
|
| 1109 | - } |
|
| 1110 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | - if ($r === false) { |
|
| 1112 | - spip_sql_erreur($serveur); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - return $r; |
|
| 1106 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | + if (!is_string($f) or !$f) { |
|
| 1108 | + return false; |
|
| 1109 | + } |
|
| 1110 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | + if ($r === false) { |
|
| 1112 | + spip_sql_erreur($serveur); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + return $r; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1136,18 +1136,18 @@ discard block |
||
| 1136 | 1136 | * Ressource à utiliser avec sql_fetch() |
| 1137 | 1137 | **/ |
| 1138 | 1138 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1139 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | - if (!is_string($f) or !$f) { |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | - if ($spip == null) { |
|
| 1146 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - return $f($spip, $serveur, $option !== false); |
|
| 1139 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | + if (!is_string($f) or !$f) { |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | + if ($spip == null) { |
|
| 1146 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + return $f($spip, $serveur, $option !== false); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1170,15 +1170,15 @@ discard block |
||
| 1170 | 1170 | * Liste des tables SQL |
| 1171 | 1171 | **/ |
| 1172 | 1172 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1173 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | - $r = []; |
|
| 1175 | - if ($q) { |
|
| 1176 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | - $r[] = array_shift($t); |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $r; |
|
| 1173 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | + $r = []; |
|
| 1175 | + if ($q) { |
|
| 1176 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | + $r[] = array_shift($t); |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return $r; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1211,31 +1211,31 @@ discard block |
||
| 1211 | 1211 | * - 'join' => array() // jointures, si déclarées. |
| 1212 | 1212 | **/ |
| 1213 | 1213 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1214 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | - if (!is_string($f) or !$f) { |
|
| 1216 | - return false; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | - if ($table_spip) { |
|
| 1221 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | - $prefixe = $connexion['prefixe']; |
|
| 1223 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | - } else { |
|
| 1225 | - $vraie_table = $table; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | - if (!$f) { |
|
| 1230 | - return []; |
|
| 1231 | - } |
|
| 1232 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - return $f; |
|
| 1214 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | + if (!is_string($f) or !$f) { |
|
| 1216 | + return false; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | + if ($table_spip) { |
|
| 1221 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | + $prefixe = $connexion['prefixe']; |
|
| 1223 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | + } else { |
|
| 1225 | + $vraie_table = $table; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | + if (!$f) { |
|
| 1230 | + return []; |
|
| 1231 | + } |
|
| 1232 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + return $f; |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
@@ -1263,21 +1263,21 @@ discard block |
||
| 1263 | 1263 | * - False en cas d'erreur. |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1266 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | - if (!is_string($f) or !$f) { |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | - if ($table_spip) { |
|
| 1273 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | - $prefixe = $connexion['prefixe']; |
|
| 1275 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | - } else { |
|
| 1277 | - $vraie_table = $table; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1266 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | + if (!is_string($f) or !$f) { |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | + if ($table_spip) { |
|
| 1273 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | + $prefixe = $connexion['prefixe']; |
|
| 1275 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | + } else { |
|
| 1277 | + $vraie_table = $table; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | |
@@ -1323,24 +1323,24 @@ discard block |
||
| 1323 | 1323 | * true si succès, false en cas d'echec |
| 1324 | 1324 | **/ |
| 1325 | 1325 | function sql_create( |
| 1326 | - $nom, |
|
| 1327 | - $champs, |
|
| 1328 | - $cles = [], |
|
| 1329 | - $autoinc = false, |
|
| 1330 | - $temporary = false, |
|
| 1331 | - $serveur = '', |
|
| 1332 | - $option = true |
|
| 1326 | + $nom, |
|
| 1327 | + $champs, |
|
| 1328 | + $cles = [], |
|
| 1329 | + $autoinc = false, |
|
| 1330 | + $temporary = false, |
|
| 1331 | + $serveur = '', |
|
| 1332 | + $option = true |
|
| 1333 | 1333 | ) { |
| 1334 | - $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | - if (!is_string($f) or !$f) { |
|
| 1336 | - return false; |
|
| 1337 | - } |
|
| 1338 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | - if ($r === false) { |
|
| 1340 | - spip_sql_erreur($serveur); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - return $r; |
|
| 1334 | + $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | + if (!is_string($f) or !$f) { |
|
| 1336 | + return false; |
|
| 1337 | + } |
|
| 1338 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | + if ($r === false) { |
|
| 1340 | + spip_sql_erreur($serveur); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + return $r; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | /** |
@@ -1358,16 +1358,16 @@ discard block |
||
| 1358 | 1358 | * @return bool true si la base est créee. |
| 1359 | 1359 | **/ |
| 1360 | 1360 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1361 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | - if (!is_string($f) or !$f) { |
|
| 1363 | - return false; |
|
| 1364 | - } |
|
| 1365 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | - if ($r === false) { |
|
| 1367 | - spip_sql_erreur($serveur); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - return $r; |
|
| 1361 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | + if (!is_string($f) or !$f) { |
|
| 1363 | + return false; |
|
| 1364 | + } |
|
| 1365 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | + if ($r === false) { |
|
| 1367 | + spip_sql_erreur($serveur); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + return $r; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | |
@@ -1397,16 +1397,16 @@ discard block |
||
| 1397 | 1397 | * - false en cas d'échec. |
| 1398 | 1398 | **/ |
| 1399 | 1399 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1400 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | - if (!is_string($f) or !$f) { |
|
| 1402 | - return false; |
|
| 1403 | - } |
|
| 1404 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | - if ($r === false) { |
|
| 1406 | - spip_sql_erreur($serveur); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - return $r; |
|
| 1400 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | + if (!is_string($f) or !$f) { |
|
| 1402 | + return false; |
|
| 1403 | + } |
|
| 1404 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | + if ($r === false) { |
|
| 1406 | + spip_sql_erreur($serveur); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + return $r; |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | /** |
@@ -1435,12 +1435,12 @@ discard block |
||
| 1435 | 1435 | * Texte de sélection pour la requête |
| 1436 | 1436 | */ |
| 1437 | 1437 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1438 | - $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | - if (!is_string($f) or !$f) { |
|
| 1440 | - return false; |
|
| 1441 | - } |
|
| 1438 | + $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | + if (!is_string($f) or !$f) { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1442 | 1442 | |
| 1443 | - return $f($sel, $lang); |
|
| 1443 | + return $f($sel, $lang); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1455,12 +1455,12 @@ discard block |
||
| 1455 | 1455 | * False si le serveur est indisponible |
| 1456 | 1456 | */ |
| 1457 | 1457 | function sql_error($serveur = '') { |
| 1458 | - $f = sql_serveur('error', $serveur, 'continue'); |
|
| 1459 | - if (!is_string($f) or !$f) { |
|
| 1460 | - return false; |
|
| 1461 | - } |
|
| 1458 | + $f = sql_serveur('error', $serveur, 'continue'); |
|
| 1459 | + if (!is_string($f) or !$f) { |
|
| 1460 | + return false; |
|
| 1461 | + } |
|
| 1462 | 1462 | |
| 1463 | - return $f('query inconnue', $serveur); |
|
| 1463 | + return $f('query inconnue', $serveur); |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | /** |
@@ -1474,12 +1474,12 @@ discard block |
||
| 1474 | 1474 | * False si le serveur est indisponible |
| 1475 | 1475 | */ |
| 1476 | 1476 | function sql_errno($serveur = '') { |
| 1477 | - $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 1478 | - if (!is_string($f) or !$f) { |
|
| 1479 | - return false; |
|
| 1480 | - } |
|
| 1477 | + $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 1478 | + if (!is_string($f) or !$f) { |
|
| 1479 | + return false; |
|
| 1480 | + } |
|
| 1481 | 1481 | |
| 1482 | - return $f($serveur); |
|
| 1482 | + return $f($serveur); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1497,16 +1497,16 @@ discard block |
||
| 1497 | 1497 | * @return array Tableau de l'explication |
| 1498 | 1498 | */ |
| 1499 | 1499 | function sql_explain($q, $serveur = '', $option = true) { |
| 1500 | - $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 1501 | - if (!is_string($f) or !$f) { |
|
| 1502 | - return false; |
|
| 1503 | - } |
|
| 1504 | - $r = $f($q, $serveur, $option !== false); |
|
| 1505 | - if ($r === false) { |
|
| 1506 | - spip_sql_erreur($serveur); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - return $r; |
|
| 1500 | + $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 1501 | + if (!is_string($f) or !$f) { |
|
| 1502 | + return false; |
|
| 1503 | + } |
|
| 1504 | + $r = $f($q, $serveur, $option !== false); |
|
| 1505 | + if ($r === false) { |
|
| 1506 | + spip_sql_erreur($serveur); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + return $r; |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | /** |
@@ -1524,16 +1524,16 @@ discard block |
||
| 1524 | 1524 | * @return bool Toujours true |
| 1525 | 1525 | */ |
| 1526 | 1526 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1527 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | - if (!is_string($f) or !$f) { |
|
| 1529 | - return false; |
|
| 1530 | - } |
|
| 1531 | - $r = $f($table, $serveur, $option !== false); |
|
| 1532 | - if ($r === false) { |
|
| 1533 | - spip_sql_erreur($serveur); |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - return $r; |
|
| 1527 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | + if (!is_string($f) or !$f) { |
|
| 1529 | + return false; |
|
| 1530 | + } |
|
| 1531 | + $r = $f($table, $serveur, $option !== false); |
|
| 1532 | + if ($r === false) { |
|
| 1533 | + spip_sql_erreur($serveur); |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + return $r; |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1553,16 +1553,16 @@ discard block |
||
| 1553 | 1553 | * - true si la requête a réussie, false sinon |
| 1554 | 1554 | */ |
| 1555 | 1555 | function sql_repair($table, $serveur = '', $option = true) { |
| 1556 | - $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | - if (!is_string($f) or !$f) { |
|
| 1558 | - return false; |
|
| 1559 | - } |
|
| 1560 | - $r = $f($table, $serveur, $option !== false); |
|
| 1561 | - if ($r === false) { |
|
| 1562 | - spip_sql_erreur($serveur); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - return $r; |
|
| 1556 | + $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | + if (!is_string($f) or !$f) { |
|
| 1558 | + return false; |
|
| 1559 | + } |
|
| 1560 | + $r = $f($table, $serveur, $option !== false); |
|
| 1561 | + if ($r === false) { |
|
| 1562 | + spip_sql_erreur($serveur); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + return $r; |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | |
@@ -1587,16 +1587,16 @@ discard block |
||
| 1587 | 1587 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1588 | 1588 | */ |
| 1589 | 1589 | function sql_query($ins, $serveur = '', $option = true) { |
| 1590 | - $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | - if (!is_string($f) or !$f) { |
|
| 1592 | - return false; |
|
| 1593 | - } |
|
| 1594 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | - if ($r === false) { |
|
| 1596 | - spip_sql_erreur($serveur); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return $r; |
|
| 1590 | + $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | + if (!is_string($f) or !$f) { |
|
| 1592 | + return false; |
|
| 1593 | + } |
|
| 1594 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | + if ($r === false) { |
|
| 1596 | + spip_sql_erreur($serveur); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return $r; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1644,27 +1644,27 @@ discard block |
||
| 1644 | 1644 | * |
| 1645 | 1645 | **/ |
| 1646 | 1646 | function sql_fetsel( |
| 1647 | - $select = [], |
|
| 1648 | - $from = [], |
|
| 1649 | - $where = [], |
|
| 1650 | - $groupby = [], |
|
| 1651 | - $orderby = [], |
|
| 1652 | - $limit = '', |
|
| 1653 | - $having = [], |
|
| 1654 | - $serveur = '', |
|
| 1655 | - $option = true |
|
| 1647 | + $select = [], |
|
| 1648 | + $from = [], |
|
| 1649 | + $where = [], |
|
| 1650 | + $groupby = [], |
|
| 1651 | + $orderby = [], |
|
| 1652 | + $limit = '', |
|
| 1653 | + $having = [], |
|
| 1654 | + $serveur = '', |
|
| 1655 | + $option = true |
|
| 1656 | 1656 | ) { |
| 1657 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | - if ($option === false) { |
|
| 1659 | - return $q; |
|
| 1660 | - } |
|
| 1661 | - if (!$q) { |
|
| 1662 | - return []; |
|
| 1663 | - } |
|
| 1664 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | - sql_free($q, $serveur, $option); |
|
| 1666 | - |
|
| 1667 | - return $r; |
|
| 1657 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | + if ($option === false) { |
|
| 1659 | + return $q; |
|
| 1660 | + } |
|
| 1661 | + if (!$q) { |
|
| 1662 | + return []; |
|
| 1663 | + } |
|
| 1664 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | + sql_free($q, $serveur, $option); |
|
| 1666 | + |
|
| 1667 | + return $r; |
|
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | |
@@ -1721,22 +1721,22 @@ discard block |
||
| 1721 | 1721 | * |
| 1722 | 1722 | **/ |
| 1723 | 1723 | function sql_allfetsel( |
| 1724 | - $select = [], |
|
| 1725 | - $from = [], |
|
| 1726 | - $where = [], |
|
| 1727 | - $groupby = [], |
|
| 1728 | - $orderby = [], |
|
| 1729 | - $limit = '', |
|
| 1730 | - $having = [], |
|
| 1731 | - $serveur = '', |
|
| 1732 | - $option = true |
|
| 1724 | + $select = [], |
|
| 1725 | + $from = [], |
|
| 1726 | + $where = [], |
|
| 1727 | + $groupby = [], |
|
| 1728 | + $orderby = [], |
|
| 1729 | + $limit = '', |
|
| 1730 | + $having = [], |
|
| 1731 | + $serveur = '', |
|
| 1732 | + $option = true |
|
| 1733 | 1733 | ) { |
| 1734 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | - if ($option === false) { |
|
| 1736 | - return $q; |
|
| 1737 | - } |
|
| 1734 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | + if ($option === false) { |
|
| 1736 | + return $q; |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1739 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | |
@@ -1783,33 +1783,33 @@ discard block |
||
| 1783 | 1783 | * |
| 1784 | 1784 | **/ |
| 1785 | 1785 | function sql_getfetsel( |
| 1786 | - $select, |
|
| 1787 | - $from = [], |
|
| 1788 | - $where = [], |
|
| 1789 | - $groupby = [], |
|
| 1790 | - $orderby = [], |
|
| 1791 | - $limit = '', |
|
| 1792 | - $having = [], |
|
| 1793 | - $serveur = '', |
|
| 1794 | - $option = true |
|
| 1786 | + $select, |
|
| 1787 | + $from = [], |
|
| 1788 | + $where = [], |
|
| 1789 | + $groupby = [], |
|
| 1790 | + $orderby = [], |
|
| 1791 | + $limit = '', |
|
| 1792 | + $having = [], |
|
| 1793 | + $serveur = '', |
|
| 1794 | + $option = true |
|
| 1795 | 1795 | ) { |
| 1796 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | - $id = $c[1]; |
|
| 1798 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | - $id = $select; |
|
| 1800 | - } else { |
|
| 1801 | - $id = 'n'; |
|
| 1802 | - $select .= ' AS n'; |
|
| 1803 | - } |
|
| 1804 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | - if ($option === false) { |
|
| 1806 | - return $r; |
|
| 1807 | - } |
|
| 1808 | - if (!$r) { |
|
| 1809 | - return null; |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - return $r[$id]; |
|
| 1796 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | + $id = $c[1]; |
|
| 1798 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | + $id = $select; |
|
| 1800 | + } else { |
|
| 1801 | + $id = 'n'; |
|
| 1802 | + $select .= ' AS n'; |
|
| 1803 | + } |
|
| 1804 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | + if ($option === false) { |
|
| 1806 | + return $r; |
|
| 1807 | + } |
|
| 1808 | + if (!$r) { |
|
| 1809 | + return null; |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + return $r[$id]; |
|
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | 1815 | /** |
@@ -1827,9 +1827,9 @@ discard block |
||
| 1827 | 1827 | * Numero de version du serveur SQL |
| 1828 | 1828 | **/ |
| 1829 | 1829 | function sql_version($serveur = '', $option = true) { |
| 1830 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1830 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1831 | 1831 | |
| 1832 | - return ($row['n']); |
|
| 1832 | + return ($row['n']); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /** |
@@ -1865,16 +1865,16 @@ discard block |
||
| 1865 | 1865 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1868 | - $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 1869 | - if (!is_string($f) or !$f) { |
|
| 1870 | - return false; |
|
| 1871 | - } |
|
| 1872 | - $r = $f($serveur, $option !== false); |
|
| 1873 | - if ($r === false) { |
|
| 1874 | - spip_sql_erreur($serveur); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - return $r; |
|
| 1868 | + $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 1869 | + if (!is_string($f) or !$f) { |
|
| 1870 | + return false; |
|
| 1871 | + } |
|
| 1872 | + $r = $f($serveur, $option !== false); |
|
| 1873 | + if ($r === false) { |
|
| 1874 | + spip_sql_erreur($serveur); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + return $r; |
|
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | 1880 | ; |
@@ -1899,16 +1899,16 @@ discard block |
||
| 1899 | 1899 | * false en cas d'erreur |
| 1900 | 1900 | **/ |
| 1901 | 1901 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1902 | - $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1903 | - if (!is_string($f) or !$f) { |
|
| 1904 | - return false; |
|
| 1905 | - } |
|
| 1906 | - $r = $f($serveur, $option !== false); |
|
| 1907 | - if ($r === false) { |
|
| 1908 | - spip_sql_erreur($serveur); |
|
| 1909 | - } |
|
| 1910 | - |
|
| 1911 | - return $r; |
|
| 1902 | + $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1903 | + if (!is_string($f) or !$f) { |
|
| 1904 | + return false; |
|
| 1905 | + } |
|
| 1906 | + $r = $f($serveur, $option !== false); |
|
| 1907 | + if ($r === false) { |
|
| 1908 | + spip_sql_erreur($serveur); |
|
| 1909 | + } |
|
| 1910 | + |
|
| 1911 | + return $r; |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | ; |
@@ -1933,16 +1933,16 @@ discard block |
||
| 1933 | 1933 | * false en cas d'erreur |
| 1934 | 1934 | **/ |
| 1935 | 1935 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1936 | - $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1937 | - if (!is_string($f) or !$f) { |
|
| 1938 | - return false; |
|
| 1939 | - } |
|
| 1940 | - $r = $f($serveur, $option !== false); |
|
| 1941 | - if ($r === false) { |
|
| 1942 | - spip_sql_erreur($serveur); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - return $r; |
|
| 1936 | + $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1937 | + if (!is_string($f) or !$f) { |
|
| 1938 | + return false; |
|
| 1939 | + } |
|
| 1940 | + $r = $f($serveur, $option !== false); |
|
| 1941 | + if ($r === false) { |
|
| 1942 | + spip_sql_erreur($serveur); |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + return $r; |
|
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | ; |
@@ -1969,12 +1969,12 @@ discard block |
||
| 1969 | 1969 | * Valeur hexadécimale attendue par le serveur SQL |
| 1970 | 1970 | **/ |
| 1971 | 1971 | function sql_hex($val, $serveur = '', $option = true) { |
| 1972 | - $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | - if (!is_string($f) or !$f) { |
|
| 1974 | - return false; |
|
| 1975 | - } |
|
| 1972 | + $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | + if (!is_string($f) or !$f) { |
|
| 1974 | + return false; |
|
| 1975 | + } |
|
| 1976 | 1976 | |
| 1977 | - return $f($val); |
|
| 1977 | + return $f($val); |
|
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | 1980 | /** |
@@ -2000,12 +2000,12 @@ discard block |
||
| 2000 | 2000 | * La chaine echappee |
| 2001 | 2001 | **/ |
| 2002 | 2002 | function sql_quote($val, $serveur = '', $type = '') { |
| 2003 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | - if (!is_string($f) or !$f) { |
|
| 2005 | - $f = '_q'; |
|
| 2006 | - } |
|
| 2003 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | + if (!is_string($f) or !$f) { |
|
| 2005 | + $f = '_q'; |
|
| 2006 | + } |
|
| 2007 | 2007 | |
| 2008 | - return $f($val, $type); |
|
| 2008 | + return $f($val, $type); |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | /** |
@@ -2030,12 +2030,12 @@ discard block |
||
| 2030 | 2030 | * - false si le serveur SQL est indisponible |
| 2031 | 2031 | **/ |
| 2032 | 2032 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2033 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | - if (!is_string($f) or !$f) { |
|
| 2035 | - return false; |
|
| 2036 | - } |
|
| 2033 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | + if (!is_string($f) or !$f) { |
|
| 2035 | + return false; |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | - return $f($champ, $interval, $unite); |
|
| 2038 | + return $f($champ, $interval, $unite); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | 2041 | /** |
@@ -2071,26 +2071,26 @@ discard block |
||
| 2071 | 2071 | * Expression de requête SQL |
| 2072 | 2072 | **/ |
| 2073 | 2073 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2074 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | - if (!is_string($quote) or !$quote) { |
|
| 2076 | - return false; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - // sql_quote produit une chaine dans tous les cas |
|
| 2080 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | - $valeurs = array_unique($valeurs); |
|
| 2082 | - $valeurs = $quote($valeurs, $type); |
|
| 2083 | - |
|
| 2084 | - if (!strlen(trim($valeurs))) { |
|
| 2085 | - return ($not ? '0=0' : '0=1'); |
|
| 2086 | - } |
|
| 2087 | - |
|
| 2088 | - $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | - if (!is_string($f) or !$f) { |
|
| 2090 | - return false; |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2074 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | + if (!is_string($quote) or !$quote) { |
|
| 2076 | + return false; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + // sql_quote produit une chaine dans tous les cas |
|
| 2080 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | + $valeurs = array_unique($valeurs); |
|
| 2082 | + $valeurs = $quote($valeurs, $type); |
|
| 2083 | + |
|
| 2084 | + if (!strlen(trim($valeurs))) { |
|
| 2085 | + return ($not ? '0=0' : '0=1'); |
|
| 2086 | + } |
|
| 2087 | + |
|
| 2088 | + $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | + if (!is_string($f) or !$f) { |
|
| 2090 | + return false; |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | 2096 | /** |
@@ -2107,19 +2107,19 @@ discard block |
||
| 2107 | 2107 | * @param bool $option |
| 2108 | 2108 | */ |
| 2109 | 2109 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2110 | - $type = ''; |
|
| 2111 | - if (!is_array($valeurs)) { |
|
| 2112 | - $valeurs = strval($valeurs); |
|
| 2113 | - if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | - $valeurs = substr($valeurs, 1); |
|
| 2115 | - } |
|
| 2116 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | - $valeurs = explode(',', $valeurs); |
|
| 2118 | - // et on force un cast de type int donc |
|
| 2119 | - $type = 'int'; |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2110 | + $type = ''; |
|
| 2111 | + if (!is_array($valeurs)) { |
|
| 2112 | + $valeurs = strval($valeurs); |
|
| 2113 | + if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | + $valeurs = substr($valeurs, 1); |
|
| 2115 | + } |
|
| 2116 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | + $valeurs = explode(',', $valeurs); |
|
| 2118 | + // et on force un cast de type int donc |
|
| 2119 | + $type = 'int'; |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | |
@@ -2160,24 +2160,24 @@ discard block |
||
| 2160 | 2160 | * Expression de requête SQL |
| 2161 | 2161 | **/ |
| 2162 | 2162 | function sql_in_select( |
| 2163 | - $in, |
|
| 2164 | - $select, |
|
| 2165 | - $from = [], |
|
| 2166 | - $where = [], |
|
| 2167 | - $groupby = [], |
|
| 2168 | - $orderby = [], |
|
| 2169 | - $limit = '', |
|
| 2170 | - $having = [], |
|
| 2171 | - $serveur = '' |
|
| 2163 | + $in, |
|
| 2164 | + $select, |
|
| 2165 | + $from = [], |
|
| 2166 | + $where = [], |
|
| 2167 | + $groupby = [], |
|
| 2168 | + $orderby = [], |
|
| 2169 | + $limit = '', |
|
| 2170 | + $having = [], |
|
| 2171 | + $serveur = '' |
|
| 2172 | 2172 | ) { |
| 2173 | - $liste = []; |
|
| 2174 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | - while ($r = sql_fetch($res)) { |
|
| 2176 | - $liste[] = array_shift($r); |
|
| 2177 | - } |
|
| 2178 | - sql_free($res); |
|
| 2179 | - |
|
| 2180 | - return sql_in($in, $liste); |
|
| 2173 | + $liste = []; |
|
| 2174 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | + while ($r = sql_fetch($res)) { |
|
| 2176 | + $liste[] = array_shift($r); |
|
| 2177 | + } |
|
| 2178 | + sql_free($res); |
|
| 2179 | + |
|
| 2180 | + return sql_in($in, $liste); |
|
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | /** |
@@ -2209,29 +2209,29 @@ discard block |
||
| 2209 | 2209 | * Position apres le saut. |
| 2210 | 2210 | */ |
| 2211 | 2211 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2212 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | - if (($saut = intval($saut)) <= 0) { |
|
| 2214 | - return $pos; |
|
| 2215 | - } |
|
| 2216 | - |
|
| 2217 | - $seek = $pos + $saut; |
|
| 2218 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | - // et on sort |
|
| 2220 | - if ($seek >= $count) { |
|
| 2221 | - sql_free($res, $serveur, $option); |
|
| 2222 | - |
|
| 2223 | - return $count; |
|
| 2224 | - } |
|
| 2225 | - |
|
| 2226 | - if (sql_seek($res, $seek)) { |
|
| 2227 | - $pos = $seek; |
|
| 2228 | - } else { |
|
| 2229 | - while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | - $pos++; |
|
| 2231 | - } |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - return $pos; |
|
| 2212 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | + if (($saut = intval($saut)) <= 0) { |
|
| 2214 | + return $pos; |
|
| 2215 | + } |
|
| 2216 | + |
|
| 2217 | + $seek = $pos + $saut; |
|
| 2218 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | + // et on sort |
|
| 2220 | + if ($seek >= $count) { |
|
| 2221 | + sql_free($res, $serveur, $option); |
|
| 2222 | + |
|
| 2223 | + return $count; |
|
| 2224 | + } |
|
| 2225 | + |
|
| 2226 | + if (sql_seek($res, $seek)) { |
|
| 2227 | + $pos = $seek; |
|
| 2228 | + } else { |
|
| 2229 | + while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | + $pos++; |
|
| 2231 | + } |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + return $pos; |
|
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | 2237 | |
@@ -2251,7 +2251,7 @@ discard block |
||
| 2251 | 2251 | * True si le champ est de type entier |
| 2252 | 2252 | */ |
| 2253 | 2253 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2254 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2254 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | /** |
@@ -2270,7 +2270,7 @@ discard block |
||
| 2270 | 2270 | * True si le champ est de type entier |
| 2271 | 2271 | */ |
| 2272 | 2272 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2273 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2273 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | /** |
@@ -2292,19 +2292,19 @@ discard block |
||
| 2292 | 2292 | * La date formatee |
| 2293 | 2293 | */ |
| 2294 | 2294 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2295 | - $annee = sprintf('%04s', $annee); |
|
| 2296 | - $mois = sprintf('%02s', $mois); |
|
| 2297 | - |
|
| 2298 | - if ($annee == '0000') { |
|
| 2299 | - $mois = 0; |
|
| 2300 | - } |
|
| 2301 | - if ($mois == '00') { |
|
| 2302 | - $jour = 0; |
|
| 2303 | - } |
|
| 2304 | - |
|
| 2305 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2295 | + $annee = sprintf('%04s', $annee); |
|
| 2296 | + $mois = sprintf('%02s', $mois); |
|
| 2297 | + |
|
| 2298 | + if ($annee == '0000') { |
|
| 2299 | + $mois = 0; |
|
| 2300 | + } |
|
| 2301 | + if ($mois == '00') { |
|
| 2302 | + $jour = 0; |
|
| 2303 | + } |
|
| 2304 | + |
|
| 2305 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | 2310 | |
@@ -2327,32 +2327,32 @@ discard block |
||
| 2327 | 2327 | **/ |
| 2328 | 2328 | function description_table($nom, $serveur = '') { |
| 2329 | 2329 | |
| 2330 | - static $trouver_table; |
|
| 2330 | + static $trouver_table; |
|
| 2331 | 2331 | |
| 2332 | - /* toujours utiliser trouver_table |
|
| 2332 | + /* toujours utiliser trouver_table |
|
| 2333 | 2333 | qui renverra la description theorique |
| 2334 | 2334 | car sinon on va se comporter differement selon que la table est declaree |
| 2335 | 2335 | ou non |
| 2336 | 2336 | */ |
| 2337 | - if (!$trouver_table) { |
|
| 2338 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | - } |
|
| 2340 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | - return $desc; |
|
| 2342 | - } |
|
| 2343 | - |
|
| 2344 | - // sauf a l'installation : |
|
| 2345 | - include_spip('base/serial'); |
|
| 2346 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - include_spip('base/auxiliaires'); |
|
| 2351 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - return false; |
|
| 2337 | + if (!$trouver_table) { |
|
| 2338 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | + } |
|
| 2340 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | + return $desc; |
|
| 2342 | + } |
|
| 2343 | + |
|
| 2344 | + // sauf a l'installation : |
|
| 2345 | + include_spip('base/serial'); |
|
| 2346 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + include_spip('base/auxiliaires'); |
|
| 2351 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + return false; |
|
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | /** |
@@ -2365,8 +2365,8 @@ discard block |
||
| 2365 | 2365 | * @return string Table sql éventuellement renommée |
| 2366 | 2366 | */ |
| 2367 | 2367 | function prefixer_table_spip($table, $prefixe) { |
| 2368 | - if ($prefixe) { |
|
| 2369 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | - } |
|
| 2371 | - return $table; |
|
| 2368 | + if ($prefixe) { |
|
| 2369 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | + } |
|
| 2371 | + return $table; |
|
| 2372 | 2372 | } |
@@ -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 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | **/ |
| 40 | 40 | function base_dump_meta_name($rub) { |
| 41 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | **/ |
| 55 | 55 | function base_dump_dir($meta) { |
| 56 | - include_spip('inc/documents'); |
|
| 57 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | - $maindir = determine_upload(); |
|
| 59 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | - $maindir = _DIR_DUMP; |
|
| 61 | - } |
|
| 62 | - $dir = sous_repertoire($maindir, $meta); |
|
| 63 | - |
|
| 64 | - return $dir; |
|
| 56 | + include_spip('inc/documents'); |
|
| 57 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | + $maindir = determine_upload(); |
|
| 59 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | + $maindir = _DIR_DUMP; |
|
| 61 | + } |
|
| 62 | + $dir = sous_repertoire($maindir, $meta); |
|
| 63 | + |
|
| 64 | + return $dir; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | function base_lister_toutes_tables( |
| 78 | - $serveur = '', |
|
| 79 | - $tables = [], |
|
| 80 | - $exclude = [], |
|
| 81 | - $affiche_vrai_prefixe = false |
|
| 78 | + $serveur = '', |
|
| 79 | + $tables = [], |
|
| 80 | + $exclude = [], |
|
| 81 | + $affiche_vrai_prefixe = false |
|
| 82 | 82 | ) { |
| 83 | - spip_connect($serveur); |
|
| 84 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | - $prefixe = $connexion['prefixe']; |
|
| 86 | - |
|
| 87 | - $p = '/^' . $prefixe . '/'; |
|
| 88 | - $res = $tables; |
|
| 89 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | - if (preg_match($p, $t)) { |
|
| 91 | - $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | - if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - sort($res); |
|
| 98 | - |
|
| 99 | - return $res; |
|
| 83 | + spip_connect($serveur); |
|
| 84 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | + $prefixe = $connexion['prefixe']; |
|
| 86 | + |
|
| 87 | + $p = '/^' . $prefixe . '/'; |
|
| 88 | + $res = $tables; |
|
| 89 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | + if (preg_match($p, $t)) { |
|
| 91 | + $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | + if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + sort($res); |
|
| 98 | + |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function base_prefixe_tables($serveur = '') { |
| 109 | - spip_connect($serveur); |
|
| 110 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | - $prefixe = $connexion['prefixe']; |
|
| 109 | + spip_connect($serveur); |
|
| 110 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | + $prefixe = $connexion['prefixe']; |
|
| 112 | 112 | |
| 113 | - return $prefixe; |
|
| 113 | + return $prefixe; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -125,31 +125,31 @@ discard block |
||
| 125 | 125 | * @return array |
| 126 | 126 | */ |
| 127 | 127 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - $res = []; |
|
| 130 | - foreach ($tables as $k => $t) { |
|
| 131 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | - if (is_null($post)) { |
|
| 133 | - $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | - } // mais si on a poste une selection, la reprendre |
|
| 135 | - else { |
|
| 136 | - $check = in_array($t, $post); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | - . "[]' id='$name$k'" |
|
| 141 | - . ($check ? " checked='checked'" : '') |
|
| 142 | - . "/>\n" |
|
| 143 | - . "<label for='$name$k'>$t</label>" |
|
| 144 | - . ' (' |
|
| 145 | - . sinon( |
|
| 146 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | - _T('dump:aucune_donnee') |
|
| 148 | - ) |
|
| 149 | - . ')'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $res; |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + $res = []; |
|
| 130 | + foreach ($tables as $k => $t) { |
|
| 131 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | + if (is_null($post)) { |
|
| 133 | + $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | + } // mais si on a poste une selection, la reprendre |
|
| 135 | + else { |
|
| 136 | + $check = in_array($t, $post); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | + . "[]' id='$name$k'" |
|
| 141 | + . ($check ? " checked='checked'" : '') |
|
| 142 | + . "/>\n" |
|
| 143 | + . "<label for='$name$k'>$t</label>" |
|
| 144 | + . ' (' |
|
| 145 | + . sinon( |
|
| 146 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | + _T('dump:aucune_donnee') |
|
| 148 | + ) |
|
| 149 | + . ')'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $res; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | 163 | function lister_tables_noexport() { |
| 164 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | - static $EXPORT_tables_noexport = null; |
|
| 166 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | - return $EXPORT_tables_noexport; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $EXPORT_tables_noexport = [ |
|
| 171 | - 'spip_caches', // plugin invalideur |
|
| 172 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | - 'spip_test', // c'est un test ! |
|
| 174 | - #'spip_referers', |
|
| 175 | - #'spip_referers_articles', |
|
| 176 | - #'spip_visites', |
|
| 177 | - #'spip_visites_articles', |
|
| 178 | - #'spip_versions', |
|
| 179 | - #'spip_versions_fragments' |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | - |
|
| 184 | - return $EXPORT_tables_noexport; |
|
| 164 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | + static $EXPORT_tables_noexport = null; |
|
| 166 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | + return $EXPORT_tables_noexport; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $EXPORT_tables_noexport = [ |
|
| 171 | + 'spip_caches', // plugin invalideur |
|
| 172 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | + 'spip_test', // c'est un test ! |
|
| 174 | + #'spip_referers', |
|
| 175 | + #'spip_referers_articles', |
|
| 176 | + #'spip_visites', |
|
| 177 | + #'spip_visites_articles', |
|
| 178 | + #'spip_versions', |
|
| 179 | + #'spip_versions_fragments' |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | + |
|
| 184 | + return $EXPORT_tables_noexport; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | 194 | function lister_tables_noimport() { |
| 195 | - static $IMPORT_tables_noimport = null; |
|
| 196 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | - return $IMPORT_tables_noimport; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $IMPORT_tables_noimport = []; |
|
| 201 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | - // possibiliter de definir cela tables via la meta |
|
| 203 | - // compatibilite |
|
| 204 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | - include_spip('inc/meta'); |
|
| 208 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | - |
|
| 213 | - return $IMPORT_tables_noimport; |
|
| 195 | + static $IMPORT_tables_noimport = null; |
|
| 196 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | + return $IMPORT_tables_noimport; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $IMPORT_tables_noimport = []; |
|
| 201 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | + // possibiliter de definir cela tables via la meta |
|
| 203 | + // compatibilite |
|
| 204 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | + include_spip('inc/meta'); |
|
| 208 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | + |
|
| 213 | + return $IMPORT_tables_noimport; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | 224 | function lister_tables_noerase() { |
| 225 | - static $IMPORT_tables_noerase = null; |
|
| 226 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | - return $IMPORT_tables_noerase; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $IMPORT_tables_noerase = [ |
|
| 231 | - 'spip_meta', |
|
| 232 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | - 'spip_referers', |
|
| 235 | - 'spip_referers_articles', |
|
| 236 | - 'spip_visites', |
|
| 237 | - 'spip_visites_articles' |
|
| 238 | - ]; |
|
| 239 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | - |
|
| 241 | - return $IMPORT_tables_noerase; |
|
| 225 | + static $IMPORT_tables_noerase = null; |
|
| 226 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | + return $IMPORT_tables_noerase; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $IMPORT_tables_noerase = [ |
|
| 231 | + 'spip_meta', |
|
| 232 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | + 'spip_referers', |
|
| 235 | + 'spip_referers_articles', |
|
| 236 | + 'spip_visites', |
|
| 237 | + 'spip_visites_articles' |
|
| 238 | + ]; |
|
| 239 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | + |
|
| 241 | + return $IMPORT_tables_noerase; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,86 +252,86 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function base_liste_table_for_dump($exclude_tables = []) { |
| 255 | - $tables_for_dump = []; |
|
| 256 | - $tables_pointees = []; |
|
| 257 | - $tables = []; |
|
| 258 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - include_spip('base/objets') |
|
| 264 | - and function_exists('lister_tables_objets_sql') |
|
| 265 | - ) { |
|
| 266 | - $tables = lister_tables_objets_sql(); |
|
| 267 | - foreach ($tables as $t => $infos) { |
|
| 268 | - if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | - $tables_principales[$t] = true; |
|
| 270 | - } |
|
| 271 | - if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | - $tables_auxiliaires[$t] = true; |
|
| 273 | - } |
|
| 274 | - if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | - $tables_jointures[$t] = array_merge( |
|
| 276 | - $tables_jointures[$t] ?? [], |
|
| 277 | - $infos['tables_jointures'] |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // on construit un index des tables de liens |
|
| 284 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | - $tables_for_link = []; |
|
| 286 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | - if (is_array($liste_relations)) { |
|
| 288 | - $nom = $table; |
|
| 289 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | - $nom = "spip_$table"; |
|
| 291 | - } |
|
| 292 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | - foreach ($liste_relations as $link_table) { |
|
| 294 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | - $tables_for_link[$link_table][] = $nom; |
|
| 296 | - } else { |
|
| 297 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | - foreach ($liste_tables as $table) { |
|
| 308 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | - if ( |
|
| 310 | - !isset($tables_pointees[$table]) |
|
| 311 | - && !in_array($table, $exclude_tables) |
|
| 312 | - && !isset($tables_for_link[$table]) |
|
| 313 | - ) { |
|
| 314 | - $tables_for_dump[] = $table; |
|
| 315 | - $tables_pointees[$table] = 1; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | - $connecte = true; |
|
| 320 | - foreach ($liste as $connect_table) { |
|
| 321 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | - $connecte = false; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - if ($connecte) { |
|
| 326 | - # on ajoute les liaisons en premier |
|
| 327 | - # si une restauration est interrompue, |
|
| 328 | - # cela se verra mieux si il manque des objets |
|
| 329 | - # que des liens |
|
| 330 | - array_unshift($tables_for_dump, $link_table); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return [$tables_for_dump, $tables_for_link]; |
|
| 255 | + $tables_for_dump = []; |
|
| 256 | + $tables_pointees = []; |
|
| 257 | + $tables = []; |
|
| 258 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + include_spip('base/objets') |
|
| 264 | + and function_exists('lister_tables_objets_sql') |
|
| 265 | + ) { |
|
| 266 | + $tables = lister_tables_objets_sql(); |
|
| 267 | + foreach ($tables as $t => $infos) { |
|
| 268 | + if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | + $tables_principales[$t] = true; |
|
| 270 | + } |
|
| 271 | + if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | + $tables_auxiliaires[$t] = true; |
|
| 273 | + } |
|
| 274 | + if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | + $tables_jointures[$t] = array_merge( |
|
| 276 | + $tables_jointures[$t] ?? [], |
|
| 277 | + $infos['tables_jointures'] |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // on construit un index des tables de liens |
|
| 284 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | + $tables_for_link = []; |
|
| 286 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | + if (is_array($liste_relations)) { |
|
| 288 | + $nom = $table; |
|
| 289 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | + $nom = "spip_$table"; |
|
| 291 | + } |
|
| 292 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | + foreach ($liste_relations as $link_table) { |
|
| 294 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | + $tables_for_link[$link_table][] = $nom; |
|
| 296 | + } else { |
|
| 297 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | + foreach ($liste_tables as $table) { |
|
| 308 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | + if ( |
|
| 310 | + !isset($tables_pointees[$table]) |
|
| 311 | + && !in_array($table, $exclude_tables) |
|
| 312 | + && !isset($tables_for_link[$table]) |
|
| 313 | + ) { |
|
| 314 | + $tables_for_dump[] = $table; |
|
| 315 | + $tables_pointees[$table] = 1; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | + $connecte = true; |
|
| 320 | + foreach ($liste as $connect_table) { |
|
| 321 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | + $connecte = false; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + if ($connecte) { |
|
| 326 | + # on ajoute les liaisons en premier |
|
| 327 | + # si une restauration est interrompue, |
|
| 328 | + # cela se verra mieux si il manque des objets |
|
| 329 | + # que des liens |
|
| 330 | + array_unshift($tables_for_dump, $link_table); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return [$tables_for_dump, $tables_for_link]; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -346,37 +346,37 @@ discard block |
||
| 346 | 346 | * @param string $serveur |
| 347 | 347 | */ |
| 348 | 348 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 349 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | - |
|
| 351 | - spip_log( |
|
| 352 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | - ); |
|
| 355 | - foreach ($tables as $table) { |
|
| 356 | - if (!in_array($table, $exclure_tables)) { |
|
| 357 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | - if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | - // regarder si il y a au moins un champ impt='non' |
|
| 360 | - $desc = $trouver_table($table, $serveur); |
|
| 361 | - if (isset($desc['field']['impt'])) { |
|
| 362 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | - } elseif ($desc) { |
|
| 364 | - sql_delete($table, '', $serveur); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | - if ( |
|
| 373 | - $serveur == '' |
|
| 374 | - and in_array('spip_auteurs', $tables) |
|
| 375 | - and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | - ) { |
|
| 377 | - base_conserver_copieur(true, $serveur); |
|
| 378 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | - } |
|
| 349 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | + |
|
| 351 | + spip_log( |
|
| 352 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | + ); |
|
| 355 | + foreach ($tables as $table) { |
|
| 356 | + if (!in_array($table, $exclure_tables)) { |
|
| 357 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | + if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | + // regarder si il y a au moins un champ impt='non' |
|
| 360 | + $desc = $trouver_table($table, $serveur); |
|
| 361 | + if (isset($desc['field']['impt'])) { |
|
| 362 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | + } elseif ($desc) { |
|
| 364 | + sql_delete($table, '', $serveur); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | + if ( |
|
| 373 | + $serveur == '' |
|
| 374 | + and in_array('spip_auteurs', $tables) |
|
| 375 | + and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | + ) { |
|
| 377 | + base_conserver_copieur(true, $serveur); |
|
| 378 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -387,36 +387,36 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | 389 | function base_conserver_copieur($move = true, $serveur = '') { |
| 390 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | - spip_log( |
|
| 393 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | - ); |
|
| 396 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | - if ($move) { |
|
| 398 | - sql_updateq( |
|
| 399 | - 'spip_auteurs', |
|
| 400 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | - 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | - [], |
|
| 403 | - $serveur |
|
| 404 | - ); |
|
| 405 | - } else { |
|
| 406 | - $row = sql_fetsel( |
|
| 407 | - '*', |
|
| 408 | - 'spip_auteurs', |
|
| 409 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | - '', |
|
| 411 | - '', |
|
| 412 | - '', |
|
| 413 | - '', |
|
| 414 | - $serveur |
|
| 415 | - ); |
|
| 416 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | - } |
|
| 419 | - } |
|
| 390 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | + spip_log( |
|
| 393 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | + ); |
|
| 396 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | + if ($move) { |
|
| 398 | + sql_updateq( |
|
| 399 | + 'spip_auteurs', |
|
| 400 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | + 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | + [], |
|
| 403 | + $serveur |
|
| 404 | + ); |
|
| 405 | + } else { |
|
| 406 | + $row = sql_fetsel( |
|
| 407 | + '*', |
|
| 408 | + 'spip_auteurs', |
|
| 409 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | + '', |
|
| 411 | + '', |
|
| 412 | + '', |
|
| 413 | + '', |
|
| 414 | + $serveur |
|
| 415 | + ); |
|
| 416 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -431,21 +431,21 @@ discard block |
||
| 431 | 431 | * @param string $serveur |
| 432 | 432 | */ |
| 433 | 433 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 434 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | - if ($serveur == '') { |
|
| 436 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | - } else { |
|
| 440 | - spip_log( |
|
| 441 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | - ); |
|
| 444 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | - } |
|
| 446 | - } else { |
|
| 447 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - } |
|
| 434 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | + if ($serveur == '') { |
|
| 436 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | + } else { |
|
| 440 | + spip_log( |
|
| 441 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | + ); |
|
| 444 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | + } |
|
| 446 | + } else { |
|
| 447 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,40 +460,40 @@ discard block |
||
| 460 | 460 | * @return array |
| 461 | 461 | */ |
| 462 | 462 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 463 | - $upgrade = false; |
|
| 464 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | - if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | - if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | - // faire un simple upgrade a la place |
|
| 469 | - // pour ajouter les champs manquants |
|
| 470 | - $upgrade = true; |
|
| 471 | - // coherence avec le drop sur les autres tables |
|
| 472 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | - if ($table == 'spip_meta') { |
|
| 474 | - // virer les version base qui vont venir avec l'import |
|
| 475 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | - // hum casse la base si pas version_installee a l'import ... |
|
| 477 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - sql_drop_table($table, '', $serveur_dest); |
|
| 481 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | - } |
|
| 483 | - $desc_dest = false; |
|
| 484 | - } |
|
| 485 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | - if (!$desc_dest) { |
|
| 487 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | - include_spip('base/create'); |
|
| 489 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | - } |
|
| 492 | - if (!$desc_dest) { |
|
| 493 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $desc_dest; |
|
| 463 | + $upgrade = false; |
|
| 464 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | + if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | + if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | + // faire un simple upgrade a la place |
|
| 469 | + // pour ajouter les champs manquants |
|
| 470 | + $upgrade = true; |
|
| 471 | + // coherence avec le drop sur les autres tables |
|
| 472 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | + if ($table == 'spip_meta') { |
|
| 474 | + // virer les version base qui vont venir avec l'import |
|
| 475 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | + // hum casse la base si pas version_installee a l'import ... |
|
| 477 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + sql_drop_table($table, '', $serveur_dest); |
|
| 481 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | + } |
|
| 483 | + $desc_dest = false; |
|
| 484 | + } |
|
| 485 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | + if (!$desc_dest) { |
|
| 487 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | + include_spip('base/create'); |
|
| 489 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | + } |
|
| 492 | + if (!$desc_dest) { |
|
| 493 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $desc_dest; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -539,211 +539,211 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 541 | 541 | |
| 542 | - $status = []; |
|
| 543 | - $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | - $max_time = $options['max_time'] ?? 0; |
|
| 545 | - $drop_source = $options['drop_source'] ?? false; |
|
| 546 | - $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | - $where = $options['where'] ?? []; |
|
| 548 | - $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | - $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | - $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | - $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | - |
|
| 553 | - spip_log( |
|
| 554 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | - |
|
| 561 | - return true; // echec mais on a fini, donc true |
|
| 562 | - } |
|
| 563 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | - |
|
| 566 | - return true; // echec mais on a fini, donc true |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if ( |
|
| 570 | - !lire_fichier($status_file, $status) |
|
| 571 | - or !$status = unserialize($status) |
|
| 572 | - ) { |
|
| 573 | - $status = []; |
|
| 574 | - } |
|
| 575 | - $status['etape'] = 'basecopie'; |
|
| 576 | - |
|
| 577 | - // puis relister les tables a importer |
|
| 578 | - // et les vider si besoin, au moment du premier passage ici |
|
| 579 | - $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | - |
|
| 581 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | - if (!$initialisation_copie) { |
|
| 583 | - if ( |
|
| 584 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | - 'vider_tables_destination_copie', |
|
| 586 | - $racine_fonctions, |
|
| 587 | - true |
|
| 588 | - ) |
|
| 589 | - ) { |
|
| 590 | - spip_log( |
|
| 591 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | - ); |
|
| 594 | - |
|
| 595 | - return true; // echec mais on a fini, donc true |
|
| 596 | - } |
|
| 597 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | - $status['dump_status_copie'] = 'ok'; |
|
| 599 | - ecrire_fichier($status_file, serialize($status)); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | - if (in_array('spip_auteurs', $tables)) { |
|
| 604 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | - $tables[] = 'spip_auteurs'; |
|
| 606 | - } |
|
| 607 | - if (in_array('spip_meta', $tables)) { |
|
| 608 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | - $tables[] = 'spip_meta'; |
|
| 610 | - } |
|
| 611 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | - |
|
| 613 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | - |
|
| 615 | - foreach ($tables as $table) { |
|
| 616 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | - // sinon chercher la vraie table |
|
| 618 | - $desc_source = false; |
|
| 619 | - if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | - } |
|
| 622 | - if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // verifier que la table est presente dans la base source |
|
| 627 | - if ($desc_source) { |
|
| 628 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | - $status['tables_copiees'][$table] = 0; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( |
|
| 635 | - is_numeric($status['tables_copiees'][$table]) |
|
| 636 | - and $status['tables_copiees'][$table] >= 0 |
|
| 637 | - and $desc_dest = $preparer_table_dest( |
|
| 638 | - $table, |
|
| 639 | - $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | - $serveur_dest, |
|
| 641 | - $status['tables_copiees'][$table] == 0 |
|
| 642 | - ) |
|
| 643 | - ) { |
|
| 644 | - if ($callback_progression) { |
|
| 645 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | - } |
|
| 647 | - while (true) { |
|
| 648 | - $n = intval($status['tables_copiees'][$table]); |
|
| 649 | - // on copie par lot de 400 |
|
| 650 | - $res = sql_select( |
|
| 651 | - '*', |
|
| 652 | - $table, |
|
| 653 | - $where[$table] ?? '', |
|
| 654 | - '', |
|
| 655 | - '', |
|
| 656 | - "$n,400", |
|
| 657 | - '', |
|
| 658 | - $serveur_source |
|
| 659 | - ); |
|
| 660 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | - $rows = [$row]; |
|
| 662 | - // lire un groupe de donnees si demande en option |
|
| 663 | - // (permet un envoi par lot vers la destination) |
|
| 664 | - if ($data_pool > 0) { |
|
| 665 | - $s = strlen(serialize($row)); |
|
| 666 | - while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | - $s += strlen(serialize($row)); |
|
| 668 | - $rows[] = $row; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | - ecrire_fichier($status_file, serialize($status)); |
|
| 678 | - |
|
| 679 | - // copie finie |
|
| 680 | - return true; |
|
| 681 | - } |
|
| 682 | - $status['tables_copiees'][$table] += count($rows); |
|
| 683 | - if ($max_time and time() > $max_time) { |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | - break; |
|
| 689 | - } |
|
| 690 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | - if ($callback_progression) { |
|
| 692 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | - } |
|
| 694 | - ecrire_fichier($status_file, serialize($status)); |
|
| 695 | - if ($max_time and time() > $max_time) { |
|
| 696 | - return false; |
|
| 697 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | - } |
|
| 699 | - if ($drop_source) { |
|
| 700 | - sql_drop_table($table, '', $serveur_source); |
|
| 701 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | - } |
|
| 703 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | - ecrire_fichier($status_file, serialize($status)); |
|
| 705 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | - if ($callback_progression) { |
|
| 707 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | - } |
|
| 709 | - } else { |
|
| 710 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | - } |
|
| 713 | - if ($callback_progression) { |
|
| 714 | - $callback_progression( |
|
| 715 | - 0, |
|
| 716 | - $status['tables_copiees'][$table], |
|
| 717 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - } else { |
|
| 722 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | - ecrire_fichier($status_file, serialize($status)); |
|
| 724 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | - // abandonner |
|
| 730 | - if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | - spip_log( |
|
| 732 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | - 'dump.' . _LOG_ERREUR |
|
| 734 | - ); |
|
| 735 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | - ecrire_fichier($status_file, serialize($status)); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | - } else { |
|
| 742 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - // OK, copie complete |
|
| 746 | - return true; |
|
| 542 | + $status = []; |
|
| 543 | + $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | + $max_time = $options['max_time'] ?? 0; |
|
| 545 | + $drop_source = $options['drop_source'] ?? false; |
|
| 546 | + $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | + $where = $options['where'] ?? []; |
|
| 548 | + $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | + $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | + $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | + $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | + |
|
| 553 | + spip_log( |
|
| 554 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | + |
|
| 561 | + return true; // echec mais on a fini, donc true |
|
| 562 | + } |
|
| 563 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | + |
|
| 566 | + return true; // echec mais on a fini, donc true |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if ( |
|
| 570 | + !lire_fichier($status_file, $status) |
|
| 571 | + or !$status = unserialize($status) |
|
| 572 | + ) { |
|
| 573 | + $status = []; |
|
| 574 | + } |
|
| 575 | + $status['etape'] = 'basecopie'; |
|
| 576 | + |
|
| 577 | + // puis relister les tables a importer |
|
| 578 | + // et les vider si besoin, au moment du premier passage ici |
|
| 579 | + $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | + |
|
| 581 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | + if (!$initialisation_copie) { |
|
| 583 | + if ( |
|
| 584 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | + 'vider_tables_destination_copie', |
|
| 586 | + $racine_fonctions, |
|
| 587 | + true |
|
| 588 | + ) |
|
| 589 | + ) { |
|
| 590 | + spip_log( |
|
| 591 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | + ); |
|
| 594 | + |
|
| 595 | + return true; // echec mais on a fini, donc true |
|
| 596 | + } |
|
| 597 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | + $status['dump_status_copie'] = 'ok'; |
|
| 599 | + ecrire_fichier($status_file, serialize($status)); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | + if (in_array('spip_auteurs', $tables)) { |
|
| 604 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | + $tables[] = 'spip_auteurs'; |
|
| 606 | + } |
|
| 607 | + if (in_array('spip_meta', $tables)) { |
|
| 608 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | + $tables[] = 'spip_meta'; |
|
| 610 | + } |
|
| 611 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | + |
|
| 613 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | + |
|
| 615 | + foreach ($tables as $table) { |
|
| 616 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | + // sinon chercher la vraie table |
|
| 618 | + $desc_source = false; |
|
| 619 | + if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | + } |
|
| 622 | + if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // verifier que la table est presente dans la base source |
|
| 627 | + if ($desc_source) { |
|
| 628 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | + $status['tables_copiees'][$table] = 0; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( |
|
| 635 | + is_numeric($status['tables_copiees'][$table]) |
|
| 636 | + and $status['tables_copiees'][$table] >= 0 |
|
| 637 | + and $desc_dest = $preparer_table_dest( |
|
| 638 | + $table, |
|
| 639 | + $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | + $serveur_dest, |
|
| 641 | + $status['tables_copiees'][$table] == 0 |
|
| 642 | + ) |
|
| 643 | + ) { |
|
| 644 | + if ($callback_progression) { |
|
| 645 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | + } |
|
| 647 | + while (true) { |
|
| 648 | + $n = intval($status['tables_copiees'][$table]); |
|
| 649 | + // on copie par lot de 400 |
|
| 650 | + $res = sql_select( |
|
| 651 | + '*', |
|
| 652 | + $table, |
|
| 653 | + $where[$table] ?? '', |
|
| 654 | + '', |
|
| 655 | + '', |
|
| 656 | + "$n,400", |
|
| 657 | + '', |
|
| 658 | + $serveur_source |
|
| 659 | + ); |
|
| 660 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | + $rows = [$row]; |
|
| 662 | + // lire un groupe de donnees si demande en option |
|
| 663 | + // (permet un envoi par lot vers la destination) |
|
| 664 | + if ($data_pool > 0) { |
|
| 665 | + $s = strlen(serialize($row)); |
|
| 666 | + while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | + $s += strlen(serialize($row)); |
|
| 668 | + $rows[] = $row; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | + ecrire_fichier($status_file, serialize($status)); |
|
| 678 | + |
|
| 679 | + // copie finie |
|
| 680 | + return true; |
|
| 681 | + } |
|
| 682 | + $status['tables_copiees'][$table] += count($rows); |
|
| 683 | + if ($max_time and time() > $max_time) { |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | + break; |
|
| 689 | + } |
|
| 690 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | + if ($callback_progression) { |
|
| 692 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | + } |
|
| 694 | + ecrire_fichier($status_file, serialize($status)); |
|
| 695 | + if ($max_time and time() > $max_time) { |
|
| 696 | + return false; |
|
| 697 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | + } |
|
| 699 | + if ($drop_source) { |
|
| 700 | + sql_drop_table($table, '', $serveur_source); |
|
| 701 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | + } |
|
| 703 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | + ecrire_fichier($status_file, serialize($status)); |
|
| 705 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | + if ($callback_progression) { |
|
| 707 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | + } |
|
| 709 | + } else { |
|
| 710 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | + } |
|
| 713 | + if ($callback_progression) { |
|
| 714 | + $callback_progression( |
|
| 715 | + 0, |
|
| 716 | + $status['tables_copiees'][$table], |
|
| 717 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + } else { |
|
| 722 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | + ecrire_fichier($status_file, serialize($status)); |
|
| 724 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | + // abandonner |
|
| 730 | + if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | + spip_log( |
|
| 732 | + 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | + 'dump.' . _LOG_ERREUR |
|
| 734 | + ); |
|
| 735 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | + ecrire_fichier($status_file, serialize($status)); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | + } else { |
|
| 742 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + // OK, copie complete |
|
| 746 | + return true; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -757,31 +757,31 @@ discard block |
||
| 757 | 757 | */ |
| 758 | 758 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 759 | 759 | |
| 760 | - // verifier le nombre d'insertion |
|
| 761 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | - if ($nb - $nb1 < count($rows)) { |
|
| 766 | - spip_log( |
|
| 767 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | - ); |
|
| 770 | - foreach ($rows as $row) { |
|
| 771 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | - } |
|
| 774 | - // on reverifie le total |
|
| 775 | - $r = 0; |
|
| 776 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | - if ($nb - $nb1 < count($rows)) { |
|
| 778 | - spip_log( |
|
| 779 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | - 'dump' . _LOG_ERREUR |
|
| 781 | - ); |
|
| 782 | - $r = false; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - return $r; |
|
| 760 | + // verifier le nombre d'insertion |
|
| 761 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | + if ($nb - $nb1 < count($rows)) { |
|
| 766 | + spip_log( |
|
| 767 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | + ); |
|
| 770 | + foreach ($rows as $row) { |
|
| 771 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | + } |
|
| 774 | + // on reverifie le total |
|
| 775 | + $r = 0; |
|
| 776 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | + if ($nb - $nb1 < count($rows)) { |
|
| 778 | + spip_log( |
|
| 779 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | + 'dump' . _LOG_ERREUR |
|
| 781 | + ); |
|
| 782 | + $r = false; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + return $r; |
|
| 787 | 787 | } |