@@ -21,193 +21,193 @@ |
||
| 21 | 21 | // par souci de compatiilite). |
| 22 | 22 | |
| 23 | 23 | if (isset($GLOBALS['_INC_PUBLIC']) and $GLOBALS['_INC_PUBLIC']) { |
| 24 | - echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 24 | + echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 25 | 25 | } else { |
| 26 | - $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | - define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | - |
|
| 29 | - // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | - if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | - if ( |
|
| 32 | - defined('_DIR_RESTREINT') |
|
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | - ) { |
|
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | - } else { |
|
| 37 | - die('inc_version absent ?'); |
|
| 38 | - } |
|
| 39 | - } // $fond defini dans le fichier d'appel ? |
|
| 40 | - |
|
| 41 | - else { |
|
| 42 | - if (isset($fond) and !_request('fond')) { |
|
| 43 | - } // fond demande dans l'url par page=xxxx ? |
|
| 44 | - else { |
|
| 45 | - if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | - |
|
| 48 | - // Securite |
|
| 49 | - if ( |
|
| 50 | - strstr($fond, '/') |
|
| 51 | - and !( |
|
| 52 | - isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | - and include_spip('inc/autoriser') |
|
| 54 | - and autoriser('webmestre')) |
|
| 55 | - ) { |
|
| 56 | - include_spip('inc/minipres'); |
|
| 57 | - echo minipres(); |
|
| 58 | - exit; |
|
| 59 | - } |
|
| 60 | - // l'argument Page a priorite sur l'argument action |
|
| 61 | - // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | - // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | - // mais pas d'en retirer un en conservant les autres. |
|
| 64 | - if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | - unset($_GET['action']); |
|
| 66 | - } |
|
| 67 | - # sinon, fond par defaut |
|
| 68 | - } else { |
|
| 69 | - // sinon fond par defaut (cf. assembler.php) |
|
| 70 | - $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $tableau_des_temps = []; |
|
| 76 | - |
|
| 77 | - // Particularites de certains squelettes |
|
| 78 | - if ($fond == 'login') { |
|
| 79 | - $forcer_lang = true; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ( |
|
| 83 | - isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | - and !_request('action') |
|
| 85 | - and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | - ) { |
|
| 87 | - include_spip('inc/lang'); |
|
| 88 | - verifier_lang_url(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | - |
|
| 93 | - // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | - // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | - if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | - include_spip('public/aiguiller'); |
|
| 97 | - if ( |
|
| 98 | - // cas des appels actions ?action=xxx |
|
| 99 | - traiter_appels_actions() |
|
| 100 | - or |
|
| 101 | - // cas des hits ajax sur les inclusions ajax |
|
| 102 | - traiter_appels_inclusions_ajax() |
|
| 103 | - or |
|
| 104 | - // cas des formulaires charger/verifier/traiter |
|
| 105 | - traiter_formulaires_dynamiques() |
|
| 106 | - ) { |
|
| 107 | - // lancer les taches sur affichage final, comme le cron |
|
| 108 | - // mais sans rien afficher |
|
| 109 | - $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | - exit; // le hit est fini ! |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Il y a du texte a produire, charger le metteur en page |
|
| 116 | - include_spip('public/assembler'); |
|
| 117 | - $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | - |
|
| 119 | - if (isset($page['status'])) { |
|
| 120 | - include_spip('inc/headers'); |
|
| 121 | - http_response_code($page['status']); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Content-Type ? |
|
| 125 | - if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | - $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | - $html = true; |
|
| 129 | - } else { |
|
| 130 | - $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | - // type tableau pour y mettre des choses au besoin. |
|
| 135 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | - |
|
| 137 | - // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | - $affiche_boutons_admin = ($html and ( |
|
| 139 | - (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | - or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | - or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | - )); |
|
| 143 | - |
|
| 144 | - if ($affiche_boutons_admin) { |
|
| 145 | - include_spip('balise/formulaire_admin'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - // Execution de la page calculee |
|
| 150 | - |
|
| 151 | - // traitements sur les entetes avant envoi |
|
| 152 | - // peut servir pour le plugin de stats |
|
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - // eval $page et affecte $res |
|
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | - envoyer_entetes($page['entetes']); |
|
| 159 | - if ($res === false) { |
|
| 160 | - include_spip('inc/autoriser'); |
|
| 161 | - $err = _T('zbug_erreur_execution_page'); |
|
| 162 | - if (autoriser('webmestre')) { |
|
| 163 | - $err .= "\n<hr />\n" |
|
| 164 | - . highlight_string($page['codephp'], true) |
|
| 165 | - . "\n<hr />\n"; |
|
| 166 | - } |
|
| 167 | - $msg = [$err]; |
|
| 168 | - erreur_squelette($msg); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // |
|
| 172 | - // Envoyer le resultat apres post-traitements |
|
| 173 | - // |
|
| 174 | - // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | - // cf. public/assembler.php) |
|
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | - |
|
| 178 | - if ($lang) { |
|
| 179 | - lang_select(); |
|
| 180 | - } |
|
| 181 | - // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | - // il faut tester a nouveau |
|
| 183 | - $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | - |
|
| 185 | - // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | - // at last |
|
| 187 | - if ($debug) { |
|
| 188 | - // en cas d'erreur, retester l'affichage |
|
| 189 | - if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | - $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | - echo erreur_squelette(false); |
|
| 194 | - } |
|
| 195 | - } else { |
|
| 196 | - if ( |
|
| 197 | - isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | - and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | - ) { |
|
| 200 | - include_spip('inc/rubriques'); |
|
| 201 | - calculer_prochain_postdate(true); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Effectuer une tache de fond ? |
|
| 205 | - // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | - cron(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // sauver le cache chemin si necessaire |
|
| 211 | - save_path_cache(); |
|
| 212 | - } |
|
| 26 | + $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 27 | + define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 28 | + |
|
| 29 | + // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 30 | + if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 31 | + if ( |
|
| 32 | + defined('_DIR_RESTREINT') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 34 | + ) { |
|
| 35 | + include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 36 | + } else { |
|
| 37 | + die('inc_version absent ?'); |
|
| 38 | + } |
|
| 39 | + } // $fond defini dans le fichier d'appel ? |
|
| 40 | + |
|
| 41 | + else { |
|
| 42 | + if (isset($fond) and !_request('fond')) { |
|
| 43 | + } // fond demande dans l'url par page=xxxx ? |
|
| 44 | + else { |
|
| 45 | + if (isset($_GET[_SPIP_PAGE])) { |
|
| 46 | + $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 47 | + |
|
| 48 | + // Securite |
|
| 49 | + if ( |
|
| 50 | + strstr($fond, '/') |
|
| 51 | + and !( |
|
| 52 | + isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes |
|
| 53 | + and include_spip('inc/autoriser') |
|
| 54 | + and autoriser('webmestre')) |
|
| 55 | + ) { |
|
| 56 | + include_spip('inc/minipres'); |
|
| 57 | + echo minipres(); |
|
| 58 | + exit; |
|
| 59 | + } |
|
| 60 | + // l'argument Page a priorite sur l'argument action |
|
| 61 | + // le cas se presente a cause des RewriteRule d'Apache |
|
| 62 | + // qui permettent d'ajouter un argument dans la QueryString |
|
| 63 | + // mais pas d'en retirer un en conservant les autres. |
|
| 64 | + if (isset($_GET['action']) and $_GET['action'] === $fond) { |
|
| 65 | + unset($_GET['action']); |
|
| 66 | + } |
|
| 67 | + # sinon, fond par defaut |
|
| 68 | + } else { |
|
| 69 | + // sinon fond par defaut (cf. assembler.php) |
|
| 70 | + $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $tableau_des_temps = []; |
|
| 76 | + |
|
| 77 | + // Particularites de certains squelettes |
|
| 78 | + if ($fond == 'login') { |
|
| 79 | + $forcer_lang = true; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ( |
|
| 83 | + isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non') |
|
| 84 | + and !_request('action') |
|
| 85 | + and $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 86 | + ) { |
|
| 87 | + include_spip('inc/lang'); |
|
| 88 | + verifier_lang_url(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']); |
|
| 92 | + |
|
| 93 | + // Charger l'aiguilleur des traitements derogatoires |
|
| 94 | + // (action en base SQL, formulaires CVT, AJax) |
|
| 95 | + if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
|
| 96 | + include_spip('public/aiguiller'); |
|
| 97 | + if ( |
|
| 98 | + // cas des appels actions ?action=xxx |
|
| 99 | + traiter_appels_actions() |
|
| 100 | + or |
|
| 101 | + // cas des hits ajax sur les inclusions ajax |
|
| 102 | + traiter_appels_inclusions_ajax() |
|
| 103 | + or |
|
| 104 | + // cas des formulaires charger/verifier/traiter |
|
| 105 | + traiter_formulaires_dynamiques() |
|
| 106 | + ) { |
|
| 107 | + // lancer les taches sur affichage final, comme le cron |
|
| 108 | + // mais sans rien afficher |
|
| 109 | + $GLOBALS['html'] = false; // ne rien afficher |
|
| 110 | + pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 111 | + exit; // le hit est fini ! |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Il y a du texte a produire, charger le metteur en page |
|
| 116 | + include_spip('public/assembler'); |
|
| 117 | + $page = assembler($fond, _request('connect') ?? ''); |
|
| 118 | + |
|
| 119 | + if (isset($page['status'])) { |
|
| 120 | + include_spip('inc/headers'); |
|
| 121 | + http_response_code($page['status']); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Content-Type ? |
|
| 125 | + if (!isset($page['entetes']['Content-Type'])) { |
|
| 126 | + $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 128 | + $html = true; |
|
| 129 | + } else { |
|
| 130 | + $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 134 | + // type tableau pour y mettre des choses au besoin. |
|
| 135 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 136 | + |
|
| 137 | + // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 138 | + $affiche_boutons_admin = ($html and ( |
|
| 139 | + (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver)) |
|
| 140 | + or ($debug and include_spip('inc/autoriser') and autoriser('debug')) |
|
| 141 | + or (defined('_VAR_PREVIEW') and _VAR_PREVIEW) |
|
| 142 | + )); |
|
| 143 | + |
|
| 144 | + if ($affiche_boutons_admin) { |
|
| 145 | + include_spip('balise/formulaire_admin'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + // Execution de la page calculee |
|
| 150 | + |
|
| 151 | + // traitements sur les entetes avant envoi |
|
| 152 | + // peut servir pour le plugin de stats |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + // eval $page et affecte $res |
|
| 157 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 158 | + envoyer_entetes($page['entetes']); |
|
| 159 | + if ($res === false) { |
|
| 160 | + include_spip('inc/autoriser'); |
|
| 161 | + $err = _T('zbug_erreur_execution_page'); |
|
| 162 | + if (autoriser('webmestre')) { |
|
| 163 | + $err .= "\n<hr />\n" |
|
| 164 | + . highlight_string($page['codephp'], true) |
|
| 165 | + . "\n<hr />\n"; |
|
| 166 | + } |
|
| 167 | + $msg = [$err]; |
|
| 168 | + erreur_squelette($msg); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // |
|
| 172 | + // Envoyer le resultat apres post-traitements |
|
| 173 | + // |
|
| 174 | + // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 175 | + // cf. public/assembler.php) |
|
| 176 | + echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | + |
|
| 178 | + if ($lang) { |
|
| 179 | + lang_select(); |
|
| 180 | + } |
|
| 181 | + // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 182 | + // il faut tester a nouveau |
|
| 183 | + $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : []; |
|
| 184 | + |
|
| 185 | + // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 186 | + // at last |
|
| 187 | + if ($debug) { |
|
| 188 | + // en cas d'erreur, retester l'affichage |
|
| 189 | + if ($html and ($affiche_boutons_admin or $debug)) { |
|
| 190 | + $var_mode_affiche = _request('var_mode_affiche'); |
|
| 191 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | + echo erreur_squelette(false); |
|
| 194 | + } |
|
| 195 | + } else { |
|
| 196 | + if ( |
|
| 197 | + isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 198 | + and $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 199 | + ) { |
|
| 200 | + include_spip('inc/rubriques'); |
|
| 201 | + calculer_prochain_postdate(true); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Effectuer une tache de fond ? |
|
| 205 | + // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 206 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 207 | + cron(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // sauver le cache chemin si necessaire |
|
| 211 | + save_path_cache(); |
|
| 212 | + } |
|
| 213 | 213 | } |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 31 | 31 | if ( |
| 32 | 32 | defined('_DIR_RESTREINT') |
| 33 | - and @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | + and @file_exists(_ROOT_RESTREINT.'inc_version.php') |
|
| 34 | 34 | ) { |
| 35 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | + include_once _ROOT_RESTREINT.'inc_version.php'; |
|
| 36 | 36 | } else { |
| 37 | 37 | die('inc_version absent ?'); |
| 38 | 38 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } // fond demande dans l'url par page=xxxx ? |
| 44 | 44 | else { |
| 45 | 45 | if (isset($_GET[_SPIP_PAGE])) { |
| 46 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | + $fond = (string) $_GET[_SPIP_PAGE]; |
|
| 47 | 47 | |
| 48 | 48 | // Securite |
| 49 | 49 | if ( |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // lancer les taches sur affichage final, comme le cron |
| 108 | 108 | // mais sans rien afficher |
| 109 | 109 | $GLOBALS['html'] = false; // ne rien afficher |
| 110 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 110 | + pipeline('affichage_final'._PIPELINE_SUFFIX, ''); |
|
| 111 | 111 | exit; // le hit est fini ! |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | // Content-Type ? |
| 125 | 125 | if (!isset($page['entetes']['Content-Type'])) { |
| 126 | 126 | $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
| 127 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 127 | + $page['entetes']['Content-Type'] = 'text/html; charset='.$charset; |
|
| 128 | 128 | $html = true; |
| 129 | 129 | } else { |
| 130 | 130 | $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']); |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | // traitements sur les entetes avant envoi |
| 152 | 152 | // peut servir pour le plugin de stats |
| 153 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 153 | + $page['entetes'] = pipeline('affichage_entetes_final'._PIPELINE_SUFFIX, $page['entetes']); |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | // eval $page et affecte $res |
| 157 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 157 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 158 | 158 | envoyer_entetes($page['entetes']); |
| 159 | 159 | if ($res === false) { |
| 160 | 160 | include_spip('inc/autoriser'); |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | // |
| 174 | 174 | // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
| 175 | 175 | // cf. public/assembler.php) |
| 176 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 176 | + echo pipeline('affichage_final'._PIPELINE_SUFFIX, $page['texte']); |
|
| 177 | 177 | |
| 178 | 178 | if ($lang) { |
| 179 | 179 | lang_select(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | if ($html and ($affiche_boutons_admin or $debug)) { |
| 190 | 190 | $var_mode_affiche = _request('var_mode_affiche'); |
| 191 | 191 | $var_mode_objet = _request('var_mode_objet'); |
| 192 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 192 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet.'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 193 | 193 | echo erreur_squelette(false); |
| 194 | 194 | } |
| 195 | 195 | } else { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // Si a ce stade on n'a pas de table, il y a un bug |
| 235 | 235 | if (!is_array($this->tableau)) { |
| 236 | 236 | $this->err = true; |
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 237 | + spip_log('erreur datasource '.var_export($command, true)); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // {datapath query.results} |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | isset($this->command['sourcemode']) |
| 277 | 277 | and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
| 278 | 278 | ) { |
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 279 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | # le premier argument peut etre un array, une URL etc. |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | # avons-nous un cache dispo ? |
| 286 | 286 | $cle = null; |
| 287 | 287 | if (is_string($src)) { |
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 288 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $cache = $this->cache_get($cle); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | if ( |
| 346 | 346 | !$this->err |
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 348 | 348 | ) { |
| 349 | 349 | $args = $this->command['source']; |
| 350 | 350 | $args[0] = $data; |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | $tv = '%s'; |
| 485 | 485 | } # {par valeur/xx/yy} ?? |
| 486 | 486 | else { |
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 487 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 488 | 488 | } |
| 489 | 489 | $sortfunc .= ' |
| 490 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 491 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 490 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 491 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 492 | 492 | if ($a <> $b) |
| 493 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 493 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | 644 | # sortir le connecteur de $data |
| 645 | 645 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 646 | - $serveur = (string)$v[1]; |
|
| 646 | + $serveur = (string) $v[1]; |
|
| 647 | 647 | $req = trim($v[2]); |
| 648 | 648 | if ($s = sql_query($req, $serveur)) { |
| 649 | 649 | $r = []; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 669 | 669 | } catch (JsonException $e) { |
| 670 | 670 | $json = null; |
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 671 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 672 | 672 | } |
| 673 | 673 | return is_array($json) ? (array) $json : []; |
| 674 | 674 | } |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | $i = 1; |
| 689 | 689 | foreach ($entete as $k => $v) { |
| 690 | 690 | if (trim($v) == '') { |
| 691 | - $v = 'col' . $i; |
|
| 691 | + $v = 'col'.$i; |
|
| 692 | 692 | } // reperer des eventuelles cases vides |
| 693 | 693 | if (is_numeric($v) and $v < 0) { |
| 694 | - $v = '__' . $v; |
|
| 694 | + $v = '__'.$v; |
|
| 695 | 695 | } // ne pas risquer d'ecraser une cle numerique |
| 696 | 696 | if (is_numeric($v)) { |
| 697 | - $v = '_' . $v; |
|
| 697 | + $v = '_'.$v; |
|
| 698 | 698 | } // ne pas risquer d'ecraser une cle numerique |
| 699 | 699 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 700 | 700 | foreach ($csv as &$item) { |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -795,13 +795,13 @@ discard block |
||
| 795 | 795 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 796 | 796 | $a = $glob_to_array($data); |
| 797 | 797 | foreach ($a as &$v) { |
| 798 | - $b = (array)@stat($v); |
|
| 798 | + $b = (array) @stat($v); |
|
| 799 | 799 | foreach ($b as $k => $ignore) { |
| 800 | 800 | if (is_numeric($k)) { |
| 801 | 801 | unset($b[$k]); |
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 805 | 805 | $v = array_merge( |
| 806 | 806 | pathinfo($v), |
| 807 | 807 | $b |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | $xml_array = []; |
| 822 | 822 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 823 | 823 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 824 | - $key .= '-' . uniqid(); |
|
| 824 | + $key .= '-'.uniqid(); |
|
| 825 | 825 | } |
| 826 | 826 | $vars = get_object_vars($object->current()); |
| 827 | 827 | if (isset($vars['@attributes'])) { |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,518 +62,518 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** Tableau de données */ |
|
| 66 | - protected array $tableau = []; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Conditions de filtrage |
|
| 70 | - * ie criteres de selection |
|
| 71 | - */ |
|
| 72 | - protected array $filtre = []; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Cle courante |
|
| 77 | - * |
|
| 78 | - * @var scalar |
|
| 79 | - */ |
|
| 80 | - protected $cle = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Valeur courante |
|
| 84 | - * |
|
| 85 | - * @var mixed |
|
| 86 | - */ |
|
| 87 | - protected $valeur = null; |
|
| 88 | - |
|
| 89 | - protected string $type = 'DATA'; |
|
| 90 | - |
|
| 91 | - protected array $command = []; |
|
| 92 | - |
|
| 93 | - protected array $info = []; |
|
| 94 | - |
|
| 95 | - /** Erreur presente ? */ |
|
| 96 | - public bool $err = false; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Calcul du total des elements |
|
| 100 | - * |
|
| 101 | - * @var int|null |
|
| 102 | - **/ |
|
| 103 | - public $total = null; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Constructeur |
|
| 107 | - * |
|
| 108 | - * @param $command |
|
| 109 | - * @param array $info |
|
| 110 | - */ |
|
| 111 | - public function __construct($command, $info = []) { |
|
| 112 | - $this->type = 'DATA'; |
|
| 113 | - $this->command = $command; |
|
| 114 | - $this->info = $info; |
|
| 115 | - |
|
| 116 | - $this->select($command); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Revenir au depart |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function rewind(): void { |
|
| 125 | - reset($this->tableau); |
|
| 126 | - $this->cle = array_key_first($this->tableau); |
|
| 127 | - $this->valeur = current($this->tableau); |
|
| 128 | - next($this->tableau); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Déclarer les critères exceptions |
|
| 133 | - * |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - public function exception_des_criteres() { |
|
| 137 | - return ['tableau']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Récupérer depuis le cache si possible |
|
| 142 | - * |
|
| 143 | - * @param string $cle |
|
| 144 | - * @return mixed |
|
| 145 | - */ |
|
| 146 | - protected function cache_get($cle) { |
|
| 147 | - if (!$cle) { |
|
| 148 | - return; |
|
| 149 | - } |
|
| 150 | - # utiliser memoization si dispo |
|
| 151 | - if (!function_exists('cache_get')) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return cache_get($cle); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Stocker en cache si possible |
|
| 160 | - * |
|
| 161 | - * @param string $cle |
|
| 162 | - * @param int $ttl |
|
| 163 | - * @param null|mixed $valeur |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | - if (!$cle) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 170 | - if (is_null($valeur)) { |
|
| 171 | - $valeur = $this->tableau; |
|
| 172 | - } |
|
| 173 | - # utiliser memoization si dispo |
|
| 174 | - if (!function_exists('cache_set')) { |
|
| 175 | - return; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return cache_set( |
|
| 179 | - $cle, |
|
| 180 | - [ |
|
| 181 | - 'data' => $valeur, |
|
| 182 | - 'time' => time(), |
|
| 183 | - 'ttl' => $ttl |
|
| 184 | - ], |
|
| 185 | - 3600 + $ttl |
|
| 186 | - ); |
|
| 187 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Aller chercher les données de la boucle DATA |
|
| 193 | - * |
|
| 194 | - * @throws Exception |
|
| 195 | - * @param array $command |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - protected function select($command) { |
|
| 199 | - |
|
| 200 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | - // le type se retrouve dans la commande 'from' |
|
| 202 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | - if (isset($this->command['from'][0])) { |
|
| 204 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | - } |
|
| 207 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | - // les commandes connues pour l'iterateur DATA |
|
| 212 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | - |
|
| 214 | - // {source format, [URL], [arg2]...} |
|
| 215 | - if ( |
|
| 216 | - isset($this->command['source']) |
|
| 217 | - and isset($this->command['sourcemode']) |
|
| 218 | - ) { |
|
| 219 | - $this->select_source(); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Critere {liste X1, X2, X3} |
|
| 223 | - if (isset($this->command['liste'])) { |
|
| 224 | - $this->select_liste(); |
|
| 225 | - } |
|
| 226 | - if (isset($this->command['enum'])) { |
|
| 227 | - $this->select_enum(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | - if (!is_array($this->tableau)) { |
|
| 232 | - $this->err = true; |
|
| 233 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // {datapath query.results} |
|
| 237 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | - if ( |
|
| 239 | - !$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if ( |
|
| 272 | - isset($this->command['sourcemode']) |
|
| 273 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | - ) { |
|
| 275 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - # le premier argument peut etre un array, une URL etc. |
|
| 279 | - $src = $this->command['source'][0]; |
|
| 280 | - |
|
| 281 | - # avons-nous un cache dispo ? |
|
| 282 | - $cle = null; |
|
| 283 | - if (is_string($src)) { |
|
| 284 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $cache = $this->cache_get($cle); |
|
| 288 | - if (isset($this->command['datacache'])) { |
|
| 289 | - $ttl = intval($this->command['datacache']); |
|
| 290 | - } |
|
| 291 | - if ( |
|
| 292 | - $cache |
|
| 293 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | - > time()) |
|
| 295 | - and !(_request('var_mode') === 'recalcul' |
|
| 296 | - and include_spip('inc/autoriser') |
|
| 297 | - and autoriser('recalcul') |
|
| 298 | - ) |
|
| 299 | - ) { |
|
| 300 | - $this->tableau = $cache['data']; |
|
| 301 | - } else { |
|
| 302 | - try { |
|
| 303 | - if ( |
|
| 304 | - isset($this->command['sourcemode']) |
|
| 305 | - and in_array( |
|
| 306 | - $this->command['sourcemode'], |
|
| 307 | - ['table', 'array', 'tableau'] |
|
| 308 | - ) |
|
| 309 | - ) { |
|
| 310 | - if ( |
|
| 311 | - is_array($a = $src) |
|
| 312 | - or (is_string($a) |
|
| 313 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | - and is_array($a = @unserialize($a))) |
|
| 315 | - ) { |
|
| 316 | - $this->tableau = $a; |
|
| 317 | - } |
|
| 318 | - } else { |
|
| 319 | - $data = $src; |
|
| 320 | - if (is_string($src)) { |
|
| 321 | - if (tester_url_absolue($src)) { |
|
| 322 | - include_spip('inc/distant'); |
|
| 323 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | - $data = $data['page'] ?? ''; |
|
| 325 | - if (!$data) { |
|
| 326 | - throw new Exception('404'); |
|
| 327 | - } |
|
| 328 | - if (!isset($ttl)) { |
|
| 329 | - $ttl = 24 * 3600; |
|
| 330 | - } |
|
| 331 | - } elseif (@is_dir($src)) { |
|
| 332 | - $data = $src; |
|
| 333 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | - $data = spip_file_get_contents($src); |
|
| 335 | - } |
|
| 336 | - if (!isset($ttl)) { |
|
| 337 | - $ttl = 10; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - if ( |
|
| 342 | - !$this->err |
|
| 343 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | - ) { |
|
| 345 | - $args = $this->command['source']; |
|
| 346 | - $args[0] = $data; |
|
| 347 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | - $this->tableau = $a; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!is_array($this->tableau)) { |
|
| 354 | - $this->err = true; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | - $this->cache_set($cle, $ttl); |
|
| 359 | - } |
|
| 360 | - } catch (Exception $e) { |
|
| 361 | - $e = $e->getMessage(); |
|
| 362 | - $err = sprintf( |
|
| 363 | - "[%s, %s] $e", |
|
| 364 | - $src, |
|
| 365 | - $this->command['sourcemode'] |
|
| 366 | - ); |
|
| 367 | - erreur_squelette([$err, []]); |
|
| 368 | - $this->err = true; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | - if ( |
|
| 374 | - $this->err |
|
| 375 | - and $cache |
|
| 376 | - ) { |
|
| 377 | - $this->tableau = $cache['data']; |
|
| 378 | - $this->err = false; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Retourne un tableau donne depuis un critère liste |
|
| 385 | - * |
|
| 386 | - * Critère `{liste X1, X2, X3}` |
|
| 387 | - * |
|
| 388 | - * @see critere_DATA_liste_dist() |
|
| 389 | - * |
|
| 390 | - **/ |
|
| 391 | - protected function select_liste() { |
|
| 392 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | - if (!isset($this->command['liste'][1])) { |
|
| 394 | - if (!is_array($this->command['liste'][0])) { |
|
| 395 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | - } else { |
|
| 397 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - $this->tableau = $this->command['liste']; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Retourne un tableau donne depuis un critere liste |
|
| 405 | - * Critere {enum Xmin, Xmax} |
|
| 406 | - * |
|
| 407 | - **/ |
|
| 408 | - protected function select_enum() { |
|
| 409 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | - if (!isset($this->command['enum'][1])) { |
|
| 411 | - if (!is_array($this->command['enum'][0])) { |
|
| 412 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | - } else { |
|
| 414 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | - $enum = range( |
|
| 419 | - array_shift($this->command['enum']), |
|
| 420 | - array_shift($this->command['enum']), |
|
| 421 | - array_shift($this->command['enum']) |
|
| 422 | - ); |
|
| 423 | - } else { |
|
| 424 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | - } |
|
| 426 | - $this->tableau = $enum; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | - * {datapath query.results} |
|
| 433 | - * |
|
| 434 | - **/ |
|
| 435 | - protected function select_datapath() { |
|
| 436 | - $base = reset($this->command['datapath']); |
|
| 437 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | - if (!is_array($this->tableau)) { |
|
| 440 | - $this->tableau = []; |
|
| 441 | - $this->err = true; |
|
| 442 | - spip_log("datapath '$base' absent"); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Ordonner les resultats |
|
| 449 | - * {par x} |
|
| 450 | - * |
|
| 451 | - **/ |
|
| 452 | - protected function select_orderby() { |
|
| 453 | - $sortfunc = ''; |
|
| 454 | - $aleas = 0; |
|
| 455 | - foreach ($this->command['orderby'] as $tri) { |
|
| 456 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | - $r = array_pad($r, 3, null); |
|
| 459 | - |
|
| 460 | - // tri par cle |
|
| 461 | - if ($r[1] == 'cle') { |
|
| 462 | - if (isset($r[2]) and $r[2]) { |
|
| 463 | - krsort($this->tableau); |
|
| 464 | - } else { |
|
| 465 | - ksort($this->tableau); |
|
| 466 | - } |
|
| 467 | - } # {par hasard} |
|
| 468 | - else { |
|
| 469 | - if ($r[1] == 'hasard') { |
|
| 470 | - $k = array_keys($this->tableau); |
|
| 471 | - shuffle($k); |
|
| 472 | - $v = []; |
|
| 473 | - foreach ($k as $cle) { |
|
| 474 | - $v[$cle] = $this->tableau[$cle]; |
|
| 475 | - } |
|
| 476 | - $this->tableau = $v; |
|
| 477 | - } else { |
|
| 478 | - # {par valeur} |
|
| 479 | - if ($r[1] == 'valeur') { |
|
| 480 | - $tv = '%s'; |
|
| 481 | - } # {par valeur/xx/yy} ?? |
|
| 482 | - else { |
|
| 483 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | - } |
|
| 485 | - $sortfunc .= ' |
|
| 65 | + /** Tableau de données */ |
|
| 66 | + protected array $tableau = []; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Conditions de filtrage |
|
| 70 | + * ie criteres de selection |
|
| 71 | + */ |
|
| 72 | + protected array $filtre = []; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Cle courante |
|
| 77 | + * |
|
| 78 | + * @var scalar |
|
| 79 | + */ |
|
| 80 | + protected $cle = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Valeur courante |
|
| 84 | + * |
|
| 85 | + * @var mixed |
|
| 86 | + */ |
|
| 87 | + protected $valeur = null; |
|
| 88 | + |
|
| 89 | + protected string $type = 'DATA'; |
|
| 90 | + |
|
| 91 | + protected array $command = []; |
|
| 92 | + |
|
| 93 | + protected array $info = []; |
|
| 94 | + |
|
| 95 | + /** Erreur presente ? */ |
|
| 96 | + public bool $err = false; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Calcul du total des elements |
|
| 100 | + * |
|
| 101 | + * @var int|null |
|
| 102 | + **/ |
|
| 103 | + public $total = null; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Constructeur |
|
| 107 | + * |
|
| 108 | + * @param $command |
|
| 109 | + * @param array $info |
|
| 110 | + */ |
|
| 111 | + public function __construct($command, $info = []) { |
|
| 112 | + $this->type = 'DATA'; |
|
| 113 | + $this->command = $command; |
|
| 114 | + $this->info = $info; |
|
| 115 | + |
|
| 116 | + $this->select($command); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Revenir au depart |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function rewind(): void { |
|
| 125 | + reset($this->tableau); |
|
| 126 | + $this->cle = array_key_first($this->tableau); |
|
| 127 | + $this->valeur = current($this->tableau); |
|
| 128 | + next($this->tableau); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Déclarer les critères exceptions |
|
| 133 | + * |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + public function exception_des_criteres() { |
|
| 137 | + return ['tableau']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Récupérer depuis le cache si possible |
|
| 142 | + * |
|
| 143 | + * @param string $cle |
|
| 144 | + * @return mixed |
|
| 145 | + */ |
|
| 146 | + protected function cache_get($cle) { |
|
| 147 | + if (!$cle) { |
|
| 148 | + return; |
|
| 149 | + } |
|
| 150 | + # utiliser memoization si dispo |
|
| 151 | + if (!function_exists('cache_get')) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return cache_get($cle); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Stocker en cache si possible |
|
| 160 | + * |
|
| 161 | + * @param string $cle |
|
| 162 | + * @param int $ttl |
|
| 163 | + * @param null|mixed $valeur |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | + if (!$cle) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | + if (is_null($valeur)) { |
|
| 171 | + $valeur = $this->tableau; |
|
| 172 | + } |
|
| 173 | + # utiliser memoization si dispo |
|
| 174 | + if (!function_exists('cache_set')) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return cache_set( |
|
| 179 | + $cle, |
|
| 180 | + [ |
|
| 181 | + 'data' => $valeur, |
|
| 182 | + 'time' => time(), |
|
| 183 | + 'ttl' => $ttl |
|
| 184 | + ], |
|
| 185 | + 3600 + $ttl |
|
| 186 | + ); |
|
| 187 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Aller chercher les données de la boucle DATA |
|
| 193 | + * |
|
| 194 | + * @throws Exception |
|
| 195 | + * @param array $command |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + protected function select($command) { |
|
| 199 | + |
|
| 200 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | + // le type se retrouve dans la commande 'from' |
|
| 202 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | + if (isset($this->command['from'][0])) { |
|
| 204 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | + } |
|
| 207 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | + // les commandes connues pour l'iterateur DATA |
|
| 212 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | + |
|
| 214 | + // {source format, [URL], [arg2]...} |
|
| 215 | + if ( |
|
| 216 | + isset($this->command['source']) |
|
| 217 | + and isset($this->command['sourcemode']) |
|
| 218 | + ) { |
|
| 219 | + $this->select_source(); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Critere {liste X1, X2, X3} |
|
| 223 | + if (isset($this->command['liste'])) { |
|
| 224 | + $this->select_liste(); |
|
| 225 | + } |
|
| 226 | + if (isset($this->command['enum'])) { |
|
| 227 | + $this->select_enum(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | + if (!is_array($this->tableau)) { |
|
| 232 | + $this->err = true; |
|
| 233 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // {datapath query.results} |
|
| 237 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | + if ( |
|
| 239 | + !$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if ( |
|
| 272 | + isset($this->command['sourcemode']) |
|
| 273 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | + ) { |
|
| 275 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + # le premier argument peut etre un array, une URL etc. |
|
| 279 | + $src = $this->command['source'][0]; |
|
| 280 | + |
|
| 281 | + # avons-nous un cache dispo ? |
|
| 282 | + $cle = null; |
|
| 283 | + if (is_string($src)) { |
|
| 284 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $cache = $this->cache_get($cle); |
|
| 288 | + if (isset($this->command['datacache'])) { |
|
| 289 | + $ttl = intval($this->command['datacache']); |
|
| 290 | + } |
|
| 291 | + if ( |
|
| 292 | + $cache |
|
| 293 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | + > time()) |
|
| 295 | + and !(_request('var_mode') === 'recalcul' |
|
| 296 | + and include_spip('inc/autoriser') |
|
| 297 | + and autoriser('recalcul') |
|
| 298 | + ) |
|
| 299 | + ) { |
|
| 300 | + $this->tableau = $cache['data']; |
|
| 301 | + } else { |
|
| 302 | + try { |
|
| 303 | + if ( |
|
| 304 | + isset($this->command['sourcemode']) |
|
| 305 | + and in_array( |
|
| 306 | + $this->command['sourcemode'], |
|
| 307 | + ['table', 'array', 'tableau'] |
|
| 308 | + ) |
|
| 309 | + ) { |
|
| 310 | + if ( |
|
| 311 | + is_array($a = $src) |
|
| 312 | + or (is_string($a) |
|
| 313 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | + and is_array($a = @unserialize($a))) |
|
| 315 | + ) { |
|
| 316 | + $this->tableau = $a; |
|
| 317 | + } |
|
| 318 | + } else { |
|
| 319 | + $data = $src; |
|
| 320 | + if (is_string($src)) { |
|
| 321 | + if (tester_url_absolue($src)) { |
|
| 322 | + include_spip('inc/distant'); |
|
| 323 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | + $data = $data['page'] ?? ''; |
|
| 325 | + if (!$data) { |
|
| 326 | + throw new Exception('404'); |
|
| 327 | + } |
|
| 328 | + if (!isset($ttl)) { |
|
| 329 | + $ttl = 24 * 3600; |
|
| 330 | + } |
|
| 331 | + } elseif (@is_dir($src)) { |
|
| 332 | + $data = $src; |
|
| 333 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | + $data = spip_file_get_contents($src); |
|
| 335 | + } |
|
| 336 | + if (!isset($ttl)) { |
|
| 337 | + $ttl = 10; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + if ( |
|
| 342 | + !$this->err |
|
| 343 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | + ) { |
|
| 345 | + $args = $this->command['source']; |
|
| 346 | + $args[0] = $data; |
|
| 347 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | + $this->tableau = $a; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!is_array($this->tableau)) { |
|
| 354 | + $this->err = true; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | + $this->cache_set($cle, $ttl); |
|
| 359 | + } |
|
| 360 | + } catch (Exception $e) { |
|
| 361 | + $e = $e->getMessage(); |
|
| 362 | + $err = sprintf( |
|
| 363 | + "[%s, %s] $e", |
|
| 364 | + $src, |
|
| 365 | + $this->command['sourcemode'] |
|
| 366 | + ); |
|
| 367 | + erreur_squelette([$err, []]); |
|
| 368 | + $this->err = true; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | + if ( |
|
| 374 | + $this->err |
|
| 375 | + and $cache |
|
| 376 | + ) { |
|
| 377 | + $this->tableau = $cache['data']; |
|
| 378 | + $this->err = false; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Retourne un tableau donne depuis un critère liste |
|
| 385 | + * |
|
| 386 | + * Critère `{liste X1, X2, X3}` |
|
| 387 | + * |
|
| 388 | + * @see critere_DATA_liste_dist() |
|
| 389 | + * |
|
| 390 | + **/ |
|
| 391 | + protected function select_liste() { |
|
| 392 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | + if (!isset($this->command['liste'][1])) { |
|
| 394 | + if (!is_array($this->command['liste'][0])) { |
|
| 395 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | + } else { |
|
| 397 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + $this->tableau = $this->command['liste']; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Retourne un tableau donne depuis un critere liste |
|
| 405 | + * Critere {enum Xmin, Xmax} |
|
| 406 | + * |
|
| 407 | + **/ |
|
| 408 | + protected function select_enum() { |
|
| 409 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | + if (!isset($this->command['enum'][1])) { |
|
| 411 | + if (!is_array($this->command['enum'][0])) { |
|
| 412 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | + } else { |
|
| 414 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | + $enum = range( |
|
| 419 | + array_shift($this->command['enum']), |
|
| 420 | + array_shift($this->command['enum']), |
|
| 421 | + array_shift($this->command['enum']) |
|
| 422 | + ); |
|
| 423 | + } else { |
|
| 424 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | + } |
|
| 426 | + $this->tableau = $enum; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | + * {datapath query.results} |
|
| 433 | + * |
|
| 434 | + **/ |
|
| 435 | + protected function select_datapath() { |
|
| 436 | + $base = reset($this->command['datapath']); |
|
| 437 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | + if (!is_array($this->tableau)) { |
|
| 440 | + $this->tableau = []; |
|
| 441 | + $this->err = true; |
|
| 442 | + spip_log("datapath '$base' absent"); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Ordonner les resultats |
|
| 449 | + * {par x} |
|
| 450 | + * |
|
| 451 | + **/ |
|
| 452 | + protected function select_orderby() { |
|
| 453 | + $sortfunc = ''; |
|
| 454 | + $aleas = 0; |
|
| 455 | + foreach ($this->command['orderby'] as $tri) { |
|
| 456 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | + $r = array_pad($r, 3, null); |
|
| 459 | + |
|
| 460 | + // tri par cle |
|
| 461 | + if ($r[1] == 'cle') { |
|
| 462 | + if (isset($r[2]) and $r[2]) { |
|
| 463 | + krsort($this->tableau); |
|
| 464 | + } else { |
|
| 465 | + ksort($this->tableau); |
|
| 466 | + } |
|
| 467 | + } # {par hasard} |
|
| 468 | + else { |
|
| 469 | + if ($r[1] == 'hasard') { |
|
| 470 | + $k = array_keys($this->tableau); |
|
| 471 | + shuffle($k); |
|
| 472 | + $v = []; |
|
| 473 | + foreach ($k as $cle) { |
|
| 474 | + $v[$cle] = $this->tableau[$cle]; |
|
| 475 | + } |
|
| 476 | + $this->tableau = $v; |
|
| 477 | + } else { |
|
| 478 | + # {par valeur} |
|
| 479 | + if ($r[1] == 'valeur') { |
|
| 480 | + $tv = '%s'; |
|
| 481 | + } # {par valeur/xx/yy} ?? |
|
| 482 | + else { |
|
| 483 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | + } |
|
| 485 | + $sortfunc .= ' |
|
| 486 | 486 | $a = ' . sprintf($tv, '$aa') . '; |
| 487 | 487 | $b = ' . sprintf($tv, '$bb') . '; |
| 488 | 488 | if ($a <> $b) |
| 489 | 489 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($sortfunc) { |
|
| 496 | - $sortfunc .= "\n return 0;"; |
|
| 497 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Grouper les resultats |
|
| 504 | - * {fusion /x/y/z} |
|
| 505 | - * |
|
| 506 | - **/ |
|
| 507 | - protected function select_groupby() { |
|
| 508 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | - $vu = []; |
|
| 511 | - foreach ($this->tableau as $k => $v) { |
|
| 512 | - $val = table_valeur($v, $fusion); |
|
| 513 | - if (isset($vu[$val])) { |
|
| 514 | - unset($this->tableau[$k]); |
|
| 515 | - } else { |
|
| 516 | - $vu[$val] = true; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * L'iterateur est-il encore valide ? |
|
| 525 | - * |
|
| 526 | - * @return bool |
|
| 527 | - */ |
|
| 528 | - public function valid(): bool { |
|
| 529 | - return !is_null($this->cle); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Retourner la valeur |
|
| 534 | - * |
|
| 535 | - * @return mixed |
|
| 536 | - */ |
|
| 537 | - #[\ReturnTypeWillChange] |
|
| 538 | - public function current() { |
|
| 539 | - return $this->valeur; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Retourner la cle |
|
| 544 | - * |
|
| 545 | - * @return mixed |
|
| 546 | - */ |
|
| 547 | - #[\ReturnTypeWillChange] |
|
| 548 | - public function key() { |
|
| 549 | - return $this->cle; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Passer a la valeur suivante |
|
| 554 | - * |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public function next(): void { |
|
| 558 | - if ($this->valid()) { |
|
| 559 | - $this->cle = key($this->tableau); |
|
| 560 | - $this->valeur = current($this->tableau); |
|
| 561 | - next($this->tableau); |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Compter le nombre total de resultats |
|
| 567 | - * |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function count() { |
|
| 571 | - if (is_null($this->total)) { |
|
| 572 | - $this->total = count($this->tableau); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $this->total; |
|
| 576 | - } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($sortfunc) { |
|
| 496 | + $sortfunc .= "\n return 0;"; |
|
| 497 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Grouper les resultats |
|
| 504 | + * {fusion /x/y/z} |
|
| 505 | + * |
|
| 506 | + **/ |
|
| 507 | + protected function select_groupby() { |
|
| 508 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | + $vu = []; |
|
| 511 | + foreach ($this->tableau as $k => $v) { |
|
| 512 | + $val = table_valeur($v, $fusion); |
|
| 513 | + if (isset($vu[$val])) { |
|
| 514 | + unset($this->tableau[$k]); |
|
| 515 | + } else { |
|
| 516 | + $vu[$val] = true; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * L'iterateur est-il encore valide ? |
|
| 525 | + * |
|
| 526 | + * @return bool |
|
| 527 | + */ |
|
| 528 | + public function valid(): bool { |
|
| 529 | + return !is_null($this->cle); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Retourner la valeur |
|
| 534 | + * |
|
| 535 | + * @return mixed |
|
| 536 | + */ |
|
| 537 | + #[\ReturnTypeWillChange] |
|
| 538 | + public function current() { |
|
| 539 | + return $this->valeur; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Retourner la cle |
|
| 544 | + * |
|
| 545 | + * @return mixed |
|
| 546 | + */ |
|
| 547 | + #[\ReturnTypeWillChange] |
|
| 548 | + public function key() { |
|
| 549 | + return $this->cle; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Passer a la valeur suivante |
|
| 554 | + * |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public function next(): void { |
|
| 558 | + if ($this->valid()) { |
|
| 559 | + $this->cle = key($this->tableau); |
|
| 560 | + $this->valeur = current($this->tableau); |
|
| 561 | + next($this->tableau); |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Compter le nombre total de resultats |
|
| 567 | + * |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function count() { |
|
| 571 | + if (is_null($this->total)) { |
|
| 572 | + $this->total = count($this->tableau); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $this->total; |
|
| 576 | + } |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /* |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * @return array |
| 588 | 588 | */ |
| 589 | 589 | function inc_file_to_array_dist($data) { |
| 590 | - return preg_split('/\r?\n/', $data); |
|
| 590 | + return preg_split('/\r?\n/', $data); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -596,9 +596,9 @@ discard block |
||
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | 598 | function inc_plugins_to_array_dist() { |
| 599 | - include_spip('inc/plugin'); |
|
| 599 | + include_spip('inc/plugin'); |
|
| 600 | 600 | |
| 601 | - return liste_chemin_plugin_actifs(); |
|
| 601 | + return liste_chemin_plugin_actifs(); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @return array |
| 609 | 609 | */ |
| 610 | 610 | function inc_xml_to_array_dist($data) { |
| 611 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 611 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -620,14 +620,14 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | */ |
| 622 | 622 | function inc_object_to_array($object) { |
| 623 | - if (!is_object($object) && !is_array($object)) { |
|
| 624 | - return $object; |
|
| 625 | - } |
|
| 626 | - if (is_object($object)) { |
|
| 627 | - $object = get_object_vars($object); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - return array_map('inc_object_to_array', $object); |
|
| 623 | + if (!is_object($object) && !is_array($object)) { |
|
| 624 | + return $object; |
|
| 625 | + } |
|
| 626 | + if (is_object($object)) { |
|
| 627 | + $object = get_object_vars($object); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + return array_map('inc_object_to_array', $object); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -637,20 +637,20 @@ discard block |
||
| 637 | 637 | * @return array|bool |
| 638 | 638 | */ |
| 639 | 639 | function inc_sql_to_array_dist($data) { |
| 640 | - # sortir le connecteur de $data |
|
| 641 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | - $serveur = (string)$v[1]; |
|
| 643 | - $req = trim($v[2]); |
|
| 644 | - if ($s = sql_query($req, $serveur)) { |
|
| 645 | - $r = []; |
|
| 646 | - while ($t = sql_fetch($s)) { |
|
| 647 | - $r[] = $t; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $r; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return false; |
|
| 640 | + # sortir le connecteur de $data |
|
| 641 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | + $serveur = (string)$v[1]; |
|
| 643 | + $req = trim($v[2]); |
|
| 644 | + if ($s = sql_query($req, $serveur)) { |
|
| 645 | + $r = []; |
|
| 646 | + while ($t = sql_fetch($s)) { |
|
| 647 | + $r[] = $t; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $r; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return false; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -660,13 +660,13 @@ discard block |
||
| 660 | 660 | * @return array|bool |
| 661 | 661 | */ |
| 662 | 662 | function inc_json_to_array_dist($data) { |
| 663 | - try { |
|
| 664 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | - } catch (JsonException $e) { |
|
| 666 | - $json = null; |
|
| 667 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | - } |
|
| 669 | - return is_array($json) ? (array) $json : []; |
|
| 663 | + try { |
|
| 664 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | + } catch (JsonException $e) { |
|
| 666 | + $json = null; |
|
| 667 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | + } |
|
| 669 | + return is_array($json) ? (array) $json : []; |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -676,30 +676,30 @@ discard block |
||
| 676 | 676 | * @return array|bool |
| 677 | 677 | */ |
| 678 | 678 | function inc_csv_to_array_dist($data) { |
| 679 | - include_spip('inc/csv'); |
|
| 680 | - [$entete, $csv] = analyse_csv($data); |
|
| 681 | - array_unshift($csv, $entete); |
|
| 682 | - |
|
| 683 | - include_spip('inc/charsets'); |
|
| 684 | - $i = 1; |
|
| 685 | - foreach ($entete as $k => $v) { |
|
| 686 | - if (trim($v) == '') { |
|
| 687 | - $v = 'col' . $i; |
|
| 688 | - } // reperer des eventuelles cases vides |
|
| 689 | - if (is_numeric($v) and $v < 0) { |
|
| 690 | - $v = '__' . $v; |
|
| 691 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | - if (is_numeric($v)) { |
|
| 693 | - $v = '_' . $v; |
|
| 694 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | - foreach ($csv as &$item) { |
|
| 697 | - $item[$v] = &$item[$k]; |
|
| 698 | - } |
|
| 699 | - $i++; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return $csv; |
|
| 679 | + include_spip('inc/csv'); |
|
| 680 | + [$entete, $csv] = analyse_csv($data); |
|
| 681 | + array_unshift($csv, $entete); |
|
| 682 | + |
|
| 683 | + include_spip('inc/charsets'); |
|
| 684 | + $i = 1; |
|
| 685 | + foreach ($entete as $k => $v) { |
|
| 686 | + if (trim($v) == '') { |
|
| 687 | + $v = 'col' . $i; |
|
| 688 | + } // reperer des eventuelles cases vides |
|
| 689 | + if (is_numeric($v) and $v < 0) { |
|
| 690 | + $v = '__' . $v; |
|
| 691 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | + if (is_numeric($v)) { |
|
| 693 | + $v = '_' . $v; |
|
| 694 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | + foreach ($csv as &$item) { |
|
| 697 | + $item[$v] = &$item[$k]; |
|
| 698 | + } |
|
| 699 | + $i++; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return $csv; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -709,13 +709,13 @@ discard block |
||
| 709 | 709 | * @return array|bool |
| 710 | 710 | */ |
| 711 | 711 | function inc_rss_to_array_dist($data) { |
| 712 | - $tableau = null; |
|
| 713 | - include_spip('inc/syndic'); |
|
| 714 | - if (is_array($rss = analyser_backend($data))) { |
|
| 715 | - $tableau = $rss; |
|
| 716 | - } |
|
| 712 | + $tableau = null; |
|
| 713 | + include_spip('inc/syndic'); |
|
| 714 | + if (is_array($rss = analyser_backend($data))) { |
|
| 715 | + $tableau = $rss; |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - return $tableau; |
|
| 718 | + return $tableau; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | * @return array|bool |
| 726 | 726 | */ |
| 727 | 727 | function inc_atom_to_array_dist($data) { |
| 728 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 728 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 729 | 729 | |
| 730 | - return $rss_to_array($data); |
|
| 730 | + return $rss_to_array($data); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -738,12 +738,12 @@ discard block |
||
| 738 | 738 | * @return array|bool |
| 739 | 739 | */ |
| 740 | 740 | function inc_glob_to_array_dist($data) { |
| 741 | - $a = glob( |
|
| 742 | - $data, |
|
| 743 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | - ); |
|
| 741 | + $a = glob( |
|
| 742 | + $data, |
|
| 743 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | + ); |
|
| 745 | 745 | |
| 746 | - return $a ?: []; |
|
| 746 | + return $a ?: []; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -754,14 +754,14 @@ discard block |
||
| 754 | 754 | * @throws Exception |
| 755 | 755 | */ |
| 756 | 756 | function inc_yaml_to_array_dist($data) { |
| 757 | - include_spip('inc/yaml-mini'); |
|
| 758 | - if (!function_exists('yaml_decode')) { |
|
| 759 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 757 | + include_spip('inc/yaml-mini'); |
|
| 758 | + if (!function_exists('yaml_decode')) { |
|
| 759 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 760 | 760 | |
| 761 | - return false; |
|
| 762 | - } |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - return yaml_decode($data); |
|
| 764 | + return yaml_decode($data); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * @return array|bool |
| 777 | 777 | */ |
| 778 | 778 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 779 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 779 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -788,23 +788,23 @@ discard block |
||
| 788 | 788 | * @return array|bool |
| 789 | 789 | */ |
| 790 | 790 | function inc_ls_to_array_dist($data) { |
| 791 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | - $a = $glob_to_array($data); |
|
| 793 | - foreach ($a as &$v) { |
|
| 794 | - $b = (array)@stat($v); |
|
| 795 | - foreach ($b as $k => $ignore) { |
|
| 796 | - if (is_numeric($k)) { |
|
| 797 | - unset($b[$k]); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | - $v = array_merge( |
|
| 802 | - pathinfo($v), |
|
| 803 | - $b |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - return $a; |
|
| 791 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | + $a = $glob_to_array($data); |
|
| 793 | + foreach ($a as &$v) { |
|
| 794 | + $b = (array)@stat($v); |
|
| 795 | + foreach ($b as $k => $ignore) { |
|
| 796 | + if (is_numeric($k)) { |
|
| 797 | + unset($b[$k]); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | + $v = array_merge( |
|
| 802 | + pathinfo($v), |
|
| 803 | + $b |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + return $a; |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
@@ -814,25 +814,25 @@ discard block |
||
| 814 | 814 | * @return array|bool |
| 815 | 815 | */ |
| 816 | 816 | function XMLObjectToArray($object) { |
| 817 | - $xml_array = []; |
|
| 818 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | - $key .= '-' . uniqid(); |
|
| 821 | - } |
|
| 822 | - $vars = get_object_vars($object->current()); |
|
| 823 | - if (isset($vars['@attributes'])) { |
|
| 824 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | - $xml_array[$key][$k] = $v; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - if ($object->hasChildren()) { |
|
| 829 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | - $object->current() |
|
| 831 | - ); |
|
| 832 | - } else { |
|
| 833 | - $xml_array[$key][] = strval($object->current()); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - return $xml_array; |
|
| 817 | + $xml_array = []; |
|
| 818 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | + $key .= '-' . uniqid(); |
|
| 821 | + } |
|
| 822 | + $vars = get_object_vars($object->current()); |
|
| 823 | + if (isset($vars['@attributes'])) { |
|
| 824 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | + $xml_array[$key][$k] = $v; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + if ($object->hasChildren()) { |
|
| 829 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | + $object->current() |
|
| 831 | + ); |
|
| 832 | + } else { |
|
| 833 | + $xml_array[$key][] = strval($object->current()); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + return $xml_array; |
|
| 838 | 838 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -21,28 +21,28 @@ discard block |
||
| 21 | 21 | * @param array $arbre |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_pipelines_dist(&$arbre) { |
| 24 | - $pipes = null; |
|
| 25 | - $tag = null; |
|
| 26 | - $pipeline = []; |
|
| 27 | - if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | - foreach ($pipes as $tag => $p) { |
|
| 29 | - if (!is_array($p[0])) { |
|
| 30 | - [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | - $pipeline[] = $att; |
|
| 32 | - } else { |
|
| 33 | - foreach ($p as $pipe) { |
|
| 34 | - $att = []; |
|
| 35 | - if (is_array($pipe)) { |
|
| 36 | - foreach ($pipe as $k => $t) { |
|
| 37 | - $att[$k] = trim(end($t)); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - $pipeline[] = $att; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - unset($arbre[$tag]); |
|
| 45 | - } |
|
| 24 | + $pipes = null; |
|
| 25 | + $tag = null; |
|
| 26 | + $pipeline = []; |
|
| 27 | + if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | + foreach ($pipes as $tag => $p) { |
|
| 29 | + if (!is_array($p[0])) { |
|
| 30 | + [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | + $pipeline[] = $att; |
|
| 32 | + } else { |
|
| 33 | + foreach ($p as $pipe) { |
|
| 34 | + $att = []; |
|
| 35 | + if (is_array($pipe)) { |
|
| 36 | + foreach ($pipe as $k => $t) { |
|
| 37 | + $att[$k] = trim(end($t)); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + $pipeline[] = $att; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + unset($arbre[$tag]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $pipeline; |
|
| 47 | + return $pipeline; |
|
| 48 | 48 | } |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][16428] = [ |
| 26 | - ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | - ['maj_liens', 'auteur', 'article'], |
|
| 28 | - ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | - ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | - ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | - ['maj_liens', 'auteur', 'message'], |
|
| 32 | - ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 26 | + ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | + ['maj_liens', 'auteur', 'article'], |
|
| 28 | + ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | + ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | + ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | + ['maj_liens', 'auteur', 'message'], |
|
| 32 | + ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,89 +55,89 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function maj_liens($pivot, $l = '') { |
| 57 | 57 | |
| 58 | - @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | - |
|
| 60 | - $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | - |
|
| 62 | - $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | - $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 66 | - // Creer spip_auteurs_liens |
|
| 67 | - global $tables_auxiliaires; |
|
| 68 | - if (!$l) { |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - include_spip('base/create'); |
|
| 71 | - creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | - } else { |
|
| 73 | - // Preparer |
|
| 74 | - $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | - $primary = "id_$l"; |
|
| 76 | - $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | - $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | - $pool = 400; |
|
| 80 | - |
|
| 81 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | - if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // securite pour ne pas perdre de donnees |
|
| 87 | - if (!$trouver_table($liens)) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champs = $desc['field']; |
|
| 92 | - if (isset($champs['maj'])) { |
|
| 93 | - unset($champs['maj']); |
|
| 94 | - } |
|
| 95 | - if (isset($champs[$primary])) { |
|
| 96 | - unset($champs[$primary]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $champs = array_keys($champs); |
|
| 100 | - // ne garder que les champs qui existent sur la table destination |
|
| 101 | - if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | - $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $champs[] = "$primary as id_objet"; |
|
| 106 | - $champs[] = "'$objet' as objet"; |
|
| 107 | - $champs = implode(', ', $champs); |
|
| 108 | - |
|
| 109 | - // Recopier les donnees |
|
| 110 | - $sub_pool = 100; |
|
| 111 | - while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | - $insert = []; |
|
| 113 | - foreach ($ids as $id) { |
|
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | - $n += is_countable($t) ? count($t) : 0; |
|
| 117 | - // empiler en s'assurant a minima de l'unicite |
|
| 118 | - while ($r = array_shift($t)) { |
|
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | - } |
|
| 121 | - if (count($insert) >= $sub_pool) { |
|
| 122 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | - $insert = []; |
|
| 124 | - } |
|
| 125 | - // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | - // et on verifiera/repartira de la |
|
| 127 | - if (time() >= _TIME_OUT) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (time() >= _TIME_OUT) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (count($insert)) { |
|
| 136 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | - } |
|
| 138 | - sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | - } |
|
| 140 | - } |
|
| 58 | + @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | + |
|
| 60 | + $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | + |
|
| 62 | + $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | + $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | + $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | + $id_pivot = 'id_' . $pivot; |
|
| 66 | + // Creer spip_auteurs_liens |
|
| 67 | + global $tables_auxiliaires; |
|
| 68 | + if (!$l) { |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + include_spip('base/create'); |
|
| 71 | + creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | + } else { |
|
| 73 | + // Preparer |
|
| 74 | + $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | + $primary = "id_$l"; |
|
| 76 | + $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | + $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | + $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | + $pool = 400; |
|
| 80 | + |
|
| 81 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | + if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // securite pour ne pas perdre de donnees |
|
| 87 | + if (!$trouver_table($liens)) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champs = $desc['field']; |
|
| 92 | + if (isset($champs['maj'])) { |
|
| 93 | + unset($champs['maj']); |
|
| 94 | + } |
|
| 95 | + if (isset($champs[$primary])) { |
|
| 96 | + unset($champs[$primary]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $champs = array_keys($champs); |
|
| 100 | + // ne garder que les champs qui existent sur la table destination |
|
| 101 | + if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | + $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $champs[] = "$primary as id_objet"; |
|
| 106 | + $champs[] = "'$objet' as objet"; |
|
| 107 | + $champs = implode(', ', $champs); |
|
| 108 | + |
|
| 109 | + // Recopier les donnees |
|
| 110 | + $sub_pool = 100; |
|
| 111 | + while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | + $insert = []; |
|
| 113 | + foreach ($ids as $id) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | + $n += is_countable($t) ? count($t) : 0; |
|
| 117 | + // empiler en s'assurant a minima de l'unicite |
|
| 118 | + while ($r = array_shift($t)) { |
|
| 119 | + $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | + } |
|
| 121 | + if (count($insert) >= $sub_pool) { |
|
| 122 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | + $insert = []; |
|
| 124 | + } |
|
| 125 | + // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | + // et on verifiera/repartira de la |
|
| 127 | + if (time() >= _TIME_OUT) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (time() >= _TIME_OUT) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (count($insert)) { |
|
| 136 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | + } |
|
| 138 | + sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -151,86 +151,86 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | **/ |
| 153 | 153 | function maj_liens_insertq_multi_check($table, $couples, $desc = []) { |
| 154 | - $n_before = sql_countsel($table); |
|
| 155 | - sql_insertq_multi($table, $couples, $desc); |
|
| 156 | - $n_after = sql_countsel($table); |
|
| 157 | - if (($n_after - $n_before) == count($couples)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | - // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | - foreach ($couples as $c) { |
|
| 163 | - sql_insertq($table, $c, $desc); |
|
| 164 | - } |
|
| 154 | + $n_before = sql_countsel($table); |
|
| 155 | + sql_insertq_multi($table, $couples, $desc); |
|
| 156 | + $n_after = sql_countsel($table); |
|
| 157 | + if (($n_after - $n_before) == count($couples)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | + // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | + foreach ($couples as $c) { |
|
| 163 | + sql_insertq($table, $c, $desc); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $GLOBALS['maj'][17311] = [ |
| 168 | - [ |
|
| 169 | - 'ecrire_meta', |
|
| 170 | - 'multi_objets', |
|
| 171 | - implode( |
|
| 172 | - ',', |
|
| 173 | - array_diff( |
|
| 174 | - [ |
|
| 175 | - (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | - ? 'spip_rubriques' : '', |
|
| 177 | - (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | - ? 'spip_articles' : '' |
|
| 179 | - ], |
|
| 180 | - [''] |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'ecrire_meta', |
|
| 186 | - 'gerer_trad_objets', |
|
| 187 | - implode( |
|
| 188 | - ',', |
|
| 189 | - array_diff( |
|
| 190 | - [ |
|
| 191 | - (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | - ? 'spip_articles' : '' |
|
| 193 | - ], |
|
| 194 | - [''] |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ], |
|
| 168 | + [ |
|
| 169 | + 'ecrire_meta', |
|
| 170 | + 'multi_objets', |
|
| 171 | + implode( |
|
| 172 | + ',', |
|
| 173 | + array_diff( |
|
| 174 | + [ |
|
| 175 | + (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | + ? 'spip_rubriques' : '', |
|
| 177 | + (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | + ? 'spip_articles' : '' |
|
| 179 | + ], |
|
| 180 | + [''] |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'ecrire_meta', |
|
| 186 | + 'gerer_trad_objets', |
|
| 187 | + implode( |
|
| 188 | + ',', |
|
| 189 | + array_diff( |
|
| 190 | + [ |
|
| 191 | + (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | + ? 'spip_articles' : '' |
|
| 193 | + ], |
|
| 194 | + [''] |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ], |
|
| 198 | 198 | ]; |
| 199 | 199 | $GLOBALS['maj'][17555] = [ |
| 200 | - ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | - ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 200 | + ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | + ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $GLOBALS['maj'][17563] = [ |
| 205 | - ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | - ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 205 | + ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | + ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $GLOBALS['maj'][17577] = [ |
| 210 | - ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 210 | + ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $GLOBALS['maj'][17743] = [ |
| 214 | - ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 214 | + ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 215 | 215 | ]; |
| 216 | 216 | |
| 217 | 217 | $GLOBALS['maj'][18219] = [ |
| 218 | - ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | - ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 218 | + ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | + ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 220 | 220 | ]; |
| 221 | 221 | |
| 222 | 222 | $GLOBALS['maj'][18310] = [ |
| 223 | - ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 223 | + ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 224 | 224 | ]; |
| 225 | 225 | |
| 226 | 226 | $GLOBALS['maj'][18597] = [ |
| 227 | - ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | - ['maj_propager_les_secteurs'], |
|
| 227 | + ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | + ['maj_propager_les_secteurs'], |
|
| 229 | 229 | ]; |
| 230 | 230 | |
| 231 | 231 | $GLOBALS['maj'][18955] = [ |
| 232 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 232 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 234 | 234 | ]; |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @uses propager_les_secteurs() |
| 240 | 240 | **/ |
| 241 | 241 | function maj_propager_les_secteurs() { |
| 242 | - include_spip('inc/rubriques'); |
|
| 243 | - propager_les_secteurs(); |
|
| 242 | + include_spip('inc/rubriques'); |
|
| 243 | + propager_les_secteurs(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -253,87 +253,87 @@ discard block |
||
| 253 | 253 | function maj_collation_sqlite() { |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - include_spip('base/dump'); |
|
| 257 | - $tables = base_lister_toutes_tables(); |
|
| 258 | - |
|
| 259 | - // rien a faire si base non sqlite |
|
| 260 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | - // forcer le vidage de cache |
|
| 266 | - $trouver_table(''); |
|
| 267 | - |
|
| 268 | - // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | - $desc = $trouver_table('spip_auteurs'); |
|
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | - if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | - spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | - sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | - $trouver_table(''); |
|
| 275 | - $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - foreach ($tables as $table) { |
|
| 280 | - if (time() >= _TIME_OUT) { |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - if ($desc = $trouver_table($table)) { |
|
| 284 | - $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | - if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | - spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | - |
|
| 288 | - // cas particulier spip_urls : |
|
| 289 | - // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | - if ($table == 'spip_urls') { |
|
| 291 | - // par date DESC pour conserver les urls les plus recentes |
|
| 292 | - $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | - $urls = []; |
|
| 294 | - foreach ($data as $d) { |
|
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | - if (!isset($urls[$key])) { |
|
| 297 | - $urls[$key] = true; |
|
| 298 | - } else { |
|
| 299 | - spip_log( |
|
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | - ); |
|
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - foreach ($desc['field'] as $field => $type) { |
|
| 308 | - if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | - $trouver_table(''); |
|
| 312 | - $new_desc = $trouver_table($table); |
|
| 313 | - spip_log( |
|
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | - ); |
|
| 317 | - continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // forcer le vidage de cache |
|
| 325 | - $trouver_table(''); |
|
| 256 | + include_spip('base/dump'); |
|
| 257 | + $tables = base_lister_toutes_tables(); |
|
| 258 | + |
|
| 259 | + // rien a faire si base non sqlite |
|
| 260 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | + // forcer le vidage de cache |
|
| 266 | + $trouver_table(''); |
|
| 267 | + |
|
| 268 | + // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | + $desc = $trouver_table('spip_auteurs'); |
|
| 270 | + spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | + if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | + spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | + sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | + $trouver_table(''); |
|
| 275 | + $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + foreach ($tables as $table) { |
|
| 280 | + if (time() >= _TIME_OUT) { |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + if ($desc = $trouver_table($table)) { |
|
| 284 | + $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | + if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | + spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | + |
|
| 288 | + // cas particulier spip_urls : |
|
| 289 | + // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | + if ($table == 'spip_urls') { |
|
| 291 | + // par date DESC pour conserver les urls les plus recentes |
|
| 292 | + $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | + $urls = []; |
|
| 294 | + foreach ($data as $d) { |
|
| 295 | + $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | + if (!isset($urls[$key])) { |
|
| 297 | + $urls[$key] = true; |
|
| 298 | + } else { |
|
| 299 | + spip_log( |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | + ); |
|
| 303 | + sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + foreach ($desc['field'] as $field => $type) { |
|
| 308 | + if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | + $trouver_table(''); |
|
| 312 | + $new_desc = $trouver_table($table); |
|
| 313 | + spip_log( |
|
| 314 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | + ); |
|
| 317 | + continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // forcer le vidage de cache |
|
| 325 | + $trouver_table(''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | - ['maj_collation_sqlite'], |
|
| 330 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | + ['maj_collation_sqlite'], |
|
| 333 | 333 | ]; |
| 334 | 334 | |
| 335 | 335 | $GLOBALS['maj'][19268] = [ |
| 336 | - ['supprimer_toutes_sessions'], |
|
| 336 | + ['supprimer_toutes_sessions'], |
|
| 337 | 337 | ]; |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | * Obligera tous les auteurs à se reconnecter ! |
| 343 | 343 | **/ |
| 344 | 344 | function supprimer_toutes_sessions() { |
| 345 | - spip_log('supprimer sessions auteur'); |
|
| 346 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | - while (($f = readdir($dir)) !== false) { |
|
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | - if (time() >= _TIME_OUT) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 345 | + spip_log('supprimer sessions auteur'); |
|
| 346 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | + while (($f = readdir($dir)) !== false) { |
|
| 348 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | + if (time() >= _TIME_OUT) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
| 61 | 61 | |
| 62 | 62 | $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
| 63 | - $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 63 | + $pivots = ($exceptions_pluriel[$pivot] ?? $pivot.'s'); |
|
| 64 | + $liens = 'spip_'.$pivots.'_liens'; |
|
| 65 | + $id_pivot = 'id_'.$pivot; |
|
| 66 | 66 | // Creer spip_auteurs_liens |
| 67 | 67 | global $tables_auxiliaires; |
| 68 | 68 | if (!$l) { |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $l = preg_replace(',[^\w],', '', $l); // securite |
| 75 | 75 | $primary = "id_$l"; |
| 76 | 76 | $objet = ($l == 'syndic' ? 'site' : $l); |
| 77 | - $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 77 | + $ls = ($exceptions_pluriel[$l] ?? $l.'s'); |
|
| 78 | + $ancienne_table = 'spip_'.$pivots.'_'.$ls; |
|
| 79 | 79 | $pool = 400; |
| 80 | 80 | |
| 81 | 81 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
| 112 | 112 | $insert = []; |
| 113 | 113 | foreach ($ids as $id) { |
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=".intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=".intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | 116 | $n += is_countable($t) ? count($t) : 0; |
| 117 | 117 | // empiler en s'assurant a minima de l'unicite |
| 118 | 118 | while ($r = array_shift($t)) { |
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 119 | + $insert[$r[$id_pivot].':'.$r['id_objet']] = $r; |
|
| 120 | 120 | } |
| 121 | 121 | if (count($insert) >= $sub_pool) { |
| 122 | 122 | maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // cas particulier spip_auteurs : retablir le collate binary sur le login |
| 269 | 269 | $desc = $trouver_table('spip_auteurs'); |
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 270 | + spip_log('spip_auteurs : '.var_export($desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 271 | 271 | if (stripos($desc['field']['login'], 'BINARY') === false) { |
| 272 | 272 | spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
| 273 | 273 | sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
| 274 | 274 | $trouver_table(''); |
| 275 | 275 | $new_desc = $trouver_table('spip_auteurs'); |
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : '.var_export($new_desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | foreach ($tables as $table) { |
@@ -292,27 +292,27 @@ discard block |
||
| 292 | 292 | $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
| 293 | 293 | $urls = []; |
| 294 | 294 | foreach ($data as $d) { |
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 295 | + $key = $d['id_parent'].'::'.strtolower($d['url']); |
|
| 296 | 296 | if (!isset($urls[$key])) { |
| 297 | 297 | $urls[$key] = true; |
| 298 | 298 | } else { |
| 299 | 299 | spip_log( |
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : '.serialize($d), |
|
| 301 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 302 | 302 | ); |
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 303 | + sql_delete('spip_urls', 'id_parent='.sql_quote($d['id_parent']).' AND url='.sql_quote($d['url'])); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | foreach ($desc['field'] as $field => $type) { |
| 308 | 308 | if ($desc['field'][$field] !== $desc_collate[$field]) { |
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field ".$desc_collate[$field]); |
|
| 311 | 311 | $trouver_table(''); |
| 312 | 312 | $new_desc = $trouver_table($table); |
| 313 | 313 | spip_log( |
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 314 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 315 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 316 | 316 | ); |
| 317 | 317 | continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
| 318 | 318 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | 330 | ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | 332 | ['maj_collation_sqlite'], |
| 333 | 333 | ]; |
| 334 | 334 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | spip_log('supprimer sessions auteur'); |
| 346 | 346 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 347 | 347 | while (($f = readdir($dir)) !== false) { |
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 348 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 349 | 349 | if (time() >= _TIME_OUT) { |
| 350 | 350 | return; |
| 351 | 351 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $champs['source'] = $source ?: 'spip'; |
| 94 | 94 | |
| 95 | 95 | $champs['login'] = ''; |
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | 97 | $champs['webmestre'] = 'non'; |
| 98 | 98 | if (empty($champs['imessage'])) { |
| 99 | 99 | $champs['imessage'] = 'oui'; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $champs['pass'] = $c['pass']; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 317 | 317 | |
| 318 | 318 | if ( |
| 319 | 319 | isset($c['statut']) |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | // commencer par traiter les cas particuliers des logins et pass |
| 374 | 374 | // avant les autres ecritures en base |
| 375 | 375 | if (isset($champs['login']) or isset($champs['pass'])) { |
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 377 | 377 | include_spip('inc/auth'); |
| 378 | 378 | if (isset($champs['login']) and strlen($champs['login'])) { |
| 379 | 379 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | if (isset($champs['pass']) and strlen($champs['pass'])) { |
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 385 | 385 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
| 386 | 386 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 387 | 387 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | if (!(is_countable($champs) ? count($champs) : 0)) { |
| 395 | 395 | return implode(' ', array_map('_T', $erreurs)); |
| 396 | 396 | } |
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 398 | 398 | |
| 399 | 399 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 400 | 400 | if ( |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,41 +37,41 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | - # cf. GROS HACK |
|
| 50 | - # recuperer l'eventuel logo charge avant la creation |
|
| 51 | - # ils ont un id = 0-id_auteur de la session |
|
| 52 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | - foreach (['on', 'off'] as $type) { |
|
| 55 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | - if ($logo = reset($logo)) { |
|
| 57 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Enregistre l'envoi dans la BD |
|
| 65 | - $err = ''; |
|
| 66 | - if ($id_auteur > 0) { |
|
| 67 | - $err = auteur_modifier($id_auteur); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ($err) { |
|
| 71 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$id_auteur, $err]; |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | + # cf. GROS HACK |
|
| 50 | + # recuperer l'eventuel logo charge avant la creation |
|
| 51 | + # ils ont un id = 0-id_auteur de la session |
|
| 52 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | + foreach (['on', 'off'] as $type) { |
|
| 55 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | + if ($logo = reset($logo)) { |
|
| 57 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Enregistre l'envoi dans la BD |
|
| 65 | + $err = ''; |
|
| 66 | + if ($id_auteur > 0) { |
|
| 67 | + $err = auteur_modifier($id_auteur); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ($err) { |
|
| 71 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$id_auteur, $err]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -88,44 +88,44 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function auteur_inserer($source = null, $set = null) { |
| 90 | 90 | |
| 91 | - // Ce qu'on va demander comme modifications |
|
| 92 | - $champs = []; |
|
| 93 | - $champs['source'] = $source ?: 'spip'; |
|
| 94 | - |
|
| 95 | - $champs['login'] = ''; |
|
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | - $champs['webmestre'] = 'non'; |
|
| 98 | - if (empty($champs['imessage'])) { |
|
| 99 | - $champs['imessage'] = 'oui'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($set) { |
|
| 103 | - $champs = array_merge($champs, $set); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Envoyer aux plugins |
|
| 107 | - $champs = pipeline( |
|
| 108 | - 'pre_insertion', |
|
| 109 | - [ |
|
| 110 | - 'args' => [ |
|
| 111 | - 'table' => 'spip_auteurs', |
|
| 112 | - ], |
|
| 113 | - 'data' => $champs |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | - pipeline( |
|
| 118 | - 'post_insertion', |
|
| 119 | - [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'table' => 'spip_auteurs', |
|
| 122 | - 'id_objet' => $id_auteur |
|
| 123 | - ], |
|
| 124 | - 'data' => $champs |
|
| 125 | - ] |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - return $id_auteur; |
|
| 91 | + // Ce qu'on va demander comme modifications |
|
| 92 | + $champs = []; |
|
| 93 | + $champs['source'] = $source ?: 'spip'; |
|
| 94 | + |
|
| 95 | + $champs['login'] = ''; |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | + $champs['webmestre'] = 'non'; |
|
| 98 | + if (empty($champs['imessage'])) { |
|
| 99 | + $champs['imessage'] = 'oui'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($set) { |
|
| 103 | + $champs = array_merge($champs, $set); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Envoyer aux plugins |
|
| 107 | + $champs = pipeline( |
|
| 108 | + 'pre_insertion', |
|
| 109 | + [ |
|
| 110 | + 'args' => [ |
|
| 111 | + 'table' => 'spip_auteurs', |
|
| 112 | + ], |
|
| 113 | + 'data' => $champs |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | + pipeline( |
|
| 118 | + 'post_insertion', |
|
| 119 | + [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'table' => 'spip_auteurs', |
|
| 122 | + 'id_objet' => $id_auteur |
|
| 123 | + ], |
|
| 124 | + 'data' => $champs |
|
| 125 | + ] |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + return $id_auteur; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -150,70 +150,70 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 152 | 152 | |
| 153 | - include_spip('inc/modifier'); |
|
| 154 | - include_spip('inc/filtres'); |
|
| 155 | - $c = collecter_requests( |
|
| 156 | - // include list |
|
| 157 | - objet_info('auteur', 'champs_editables'), |
|
| 158 | - // exclude list |
|
| 159 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | - // donnees eventuellement fournies |
|
| 161 | - $set |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - if ( |
|
| 165 | - $err = objet_modifier_champs( |
|
| 166 | - 'auteur', |
|
| 167 | - $id_auteur, |
|
| 168 | - [ |
|
| 169 | - 'data' => $set, |
|
| 170 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | - ], |
|
| 172 | - $c |
|
| 173 | - ) |
|
| 174 | - ) { |
|
| 175 | - return $err; |
|
| 176 | - } |
|
| 177 | - $session = $c; |
|
| 178 | - |
|
| 179 | - $err = ''; |
|
| 180 | - if (!$force_update) { |
|
| 181 | - // Modification de statut, changement de rubrique ? |
|
| 182 | - $c = collecter_requests( |
|
| 183 | - // include list |
|
| 184 | - [ |
|
| 185 | - 'statut', |
|
| 186 | - 'new_login', |
|
| 187 | - 'new_pass', |
|
| 188 | - 'login', |
|
| 189 | - 'pass', |
|
| 190 | - 'webmestre', |
|
| 191 | - 'restreintes', |
|
| 192 | - 'id_parent' |
|
| 193 | - ], |
|
| 194 | - // exclude list |
|
| 195 | - [], |
|
| 196 | - // donnees eventuellement fournies |
|
| 197 | - $set |
|
| 198 | - ); |
|
| 199 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | - $c['login'] = $c['new_login']; |
|
| 201 | - } |
|
| 202 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | - $c['pass'] = $c['new_pass']; |
|
| 204 | - } |
|
| 205 | - $err = auteur_instituer($id_auteur, $c); |
|
| 206 | - $session = array_merge($session, $c); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // .. mettre a jour les sessions de cet auteur |
|
| 210 | - include_spip('inc/session'); |
|
| 211 | - $session['id_auteur'] = $id_auteur; |
|
| 212 | - unset($session['new_login']); |
|
| 213 | - unset($session['new_pass']); |
|
| 214 | - actualiser_sessions($session); |
|
| 215 | - |
|
| 216 | - return $err; |
|
| 153 | + include_spip('inc/modifier'); |
|
| 154 | + include_spip('inc/filtres'); |
|
| 155 | + $c = collecter_requests( |
|
| 156 | + // include list |
|
| 157 | + objet_info('auteur', 'champs_editables'), |
|
| 158 | + // exclude list |
|
| 159 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | + // donnees eventuellement fournies |
|
| 161 | + $set |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + if ( |
|
| 165 | + $err = objet_modifier_champs( |
|
| 166 | + 'auteur', |
|
| 167 | + $id_auteur, |
|
| 168 | + [ |
|
| 169 | + 'data' => $set, |
|
| 170 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | + ], |
|
| 172 | + $c |
|
| 173 | + ) |
|
| 174 | + ) { |
|
| 175 | + return $err; |
|
| 176 | + } |
|
| 177 | + $session = $c; |
|
| 178 | + |
|
| 179 | + $err = ''; |
|
| 180 | + if (!$force_update) { |
|
| 181 | + // Modification de statut, changement de rubrique ? |
|
| 182 | + $c = collecter_requests( |
|
| 183 | + // include list |
|
| 184 | + [ |
|
| 185 | + 'statut', |
|
| 186 | + 'new_login', |
|
| 187 | + 'new_pass', |
|
| 188 | + 'login', |
|
| 189 | + 'pass', |
|
| 190 | + 'webmestre', |
|
| 191 | + 'restreintes', |
|
| 192 | + 'id_parent' |
|
| 193 | + ], |
|
| 194 | + // exclude list |
|
| 195 | + [], |
|
| 196 | + // donnees eventuellement fournies |
|
| 197 | + $set |
|
| 198 | + ); |
|
| 199 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | + $c['login'] = $c['new_login']; |
|
| 201 | + } |
|
| 202 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | + $c['pass'] = $c['new_pass']; |
|
| 204 | + } |
|
| 205 | + $err = auteur_instituer($id_auteur, $c); |
|
| 206 | + $session = array_merge($session, $c); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // .. mettre a jour les sessions de cet auteur |
|
| 210 | + include_spip('inc/session'); |
|
| 211 | + $session['id_auteur'] = $id_auteur; |
|
| 212 | + unset($session['new_login']); |
|
| 213 | + unset($session['new_pass']); |
|
| 214 | + actualiser_sessions($session); |
|
| 215 | + |
|
| 216 | + return $err; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 237 | - include_spip('action/editer_liens'); |
|
| 237 | + include_spip('action/editer_liens'); |
|
| 238 | 238 | |
| 239 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 239 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function auteur_dissocier($id_auteur, $objets) { |
| 258 | - include_spip('action/editer_liens'); |
|
| 258 | + include_spip('action/editer_liens'); |
|
| 259 | 259 | |
| 260 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 260 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * @return bool|int |
| 279 | 279 | */ |
| 280 | 280 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 281 | - include_spip('action/editer_liens'); |
|
| 281 | + include_spip('action/editer_liens'); |
|
| 282 | 282 | |
| 283 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 283 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -299,139 +299,139 @@ discard block |
||
| 299 | 299 | * @return bool|string |
| 300 | 300 | */ |
| 301 | 301 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 302 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | - $champs = []; |
|
| 307 | - |
|
| 308 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | - $champs['login'] = $c['login']; |
|
| 311 | - } |
|
| 312 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | - $champs['pass'] = $c['pass']; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | - |
|
| 318 | - if ( |
|
| 319 | - isset($c['statut']) |
|
| 320 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | - ) { |
|
| 322 | - $statut = $champs['statut'] = $c['statut']; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Restreindre avant de declarer l'auteur |
|
| 326 | - // (section critique sur les droits) |
|
| 327 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | - if (is_array($c['restreintes'])) { |
|
| 329 | - $c['restreintes'][] = $c['id_parent']; |
|
| 330 | - } else { |
|
| 331 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( |
|
| 336 | - isset($c['webmestre']) |
|
| 337 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | - ) { |
|
| 339 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - // Envoyer aux plugins |
|
| 348 | - $champs = pipeline( |
|
| 349 | - 'pre_edition', |
|
| 350 | - [ |
|
| 351 | - 'args' => [ |
|
| 352 | - 'table' => 'spip_auteurs', |
|
| 353 | - 'id_objet' => $id_auteur, |
|
| 354 | - 'action' => 'instituer', |
|
| 355 | - 'statut_ancien' => $statut_ancien, |
|
| 356 | - ], |
|
| 357 | - 'data' => $champs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - if ( |
|
| 362 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | - ) { |
|
| 365 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | - $rubriques = array_unique($rubriques); |
|
| 367 | - $rubriques = array_diff($rubriques, [0]); |
|
| 368 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - $flag_ecrire_acces = false; |
|
| 373 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | - // avant les autres ecritures en base |
|
| 375 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | - include_spip('inc/auth'); |
|
| 378 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - unset($champs['login']); |
|
| 390 | - unset($champs['pass']); |
|
| 391 | - $flag_ecrire_acces = true; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | - } |
|
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | - |
|
| 399 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | - if ( |
|
| 401 | - $flag_ecrire_acces |
|
| 402 | - or isset($champs['statut']) |
|
| 403 | - ) { |
|
| 404 | - include_spip('inc/acces'); |
|
| 405 | - ecrire_acces(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // Invalider les caches |
|
| 409 | - include_spip('inc/invalideur'); |
|
| 410 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | - |
|
| 412 | - // Pipeline |
|
| 413 | - pipeline( |
|
| 414 | - 'post_edition', |
|
| 415 | - [ |
|
| 416 | - 'args' => [ |
|
| 417 | - 'table' => 'spip_auteurs', |
|
| 418 | - 'id_objet' => $id_auteur, |
|
| 419 | - 'action' => 'instituer', |
|
| 420 | - 'statut_ancien' => $statut_ancien, |
|
| 421 | - ], |
|
| 422 | - 'data' => $champs |
|
| 423 | - ] |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - // Notifications |
|
| 428 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | - $notifications( |
|
| 430 | - 'instituerauteur', |
|
| 431 | - $id_auteur, |
|
| 432 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 302 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | + $champs = []; |
|
| 307 | + |
|
| 308 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | + $champs['login'] = $c['login']; |
|
| 311 | + } |
|
| 312 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | + $champs['pass'] = $c['pass']; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | + |
|
| 318 | + if ( |
|
| 319 | + isset($c['statut']) |
|
| 320 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | + ) { |
|
| 322 | + $statut = $champs['statut'] = $c['statut']; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Restreindre avant de declarer l'auteur |
|
| 326 | + // (section critique sur les droits) |
|
| 327 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | + if (is_array($c['restreintes'])) { |
|
| 329 | + $c['restreintes'][] = $c['id_parent']; |
|
| 330 | + } else { |
|
| 331 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( |
|
| 336 | + isset($c['webmestre']) |
|
| 337 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | + ) { |
|
| 339 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + // Envoyer aux plugins |
|
| 348 | + $champs = pipeline( |
|
| 349 | + 'pre_edition', |
|
| 350 | + [ |
|
| 351 | + 'args' => [ |
|
| 352 | + 'table' => 'spip_auteurs', |
|
| 353 | + 'id_objet' => $id_auteur, |
|
| 354 | + 'action' => 'instituer', |
|
| 355 | + 'statut_ancien' => $statut_ancien, |
|
| 356 | + ], |
|
| 357 | + 'data' => $champs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + if ( |
|
| 362 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | + ) { |
|
| 365 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | + $rubriques = array_unique($rubriques); |
|
| 367 | + $rubriques = array_diff($rubriques, [0]); |
|
| 368 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + $flag_ecrire_acces = false; |
|
| 373 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | + // avant les autres ecritures en base |
|
| 375 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | + include_spip('inc/auth'); |
|
| 378 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + unset($champs['login']); |
|
| 390 | + unset($champs['pass']); |
|
| 391 | + $flag_ecrire_acces = true; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | + } |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | + |
|
| 399 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | + if ( |
|
| 401 | + $flag_ecrire_acces |
|
| 402 | + or isset($champs['statut']) |
|
| 403 | + ) { |
|
| 404 | + include_spip('inc/acces'); |
|
| 405 | + ecrire_acces(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // Invalider les caches |
|
| 409 | + include_spip('inc/invalideur'); |
|
| 410 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | + |
|
| 412 | + // Pipeline |
|
| 413 | + pipeline( |
|
| 414 | + 'post_edition', |
|
| 415 | + [ |
|
| 416 | + 'args' => [ |
|
| 417 | + 'table' => 'spip_auteurs', |
|
| 418 | + 'id_objet' => $id_auteur, |
|
| 419 | + 'action' => 'instituer', |
|
| 420 | + 'statut_ancien' => $statut_ancien, |
|
| 421 | + ], |
|
| 422 | + 'data' => $champs |
|
| 423 | + ] |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + // Notifications |
|
| 428 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | + $notifications( |
|
| 430 | + 'instituerauteur', |
|
| 431 | + $id_auteur, |
|
| 432 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 437 | 437 | } |
@@ -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,24 +29,24 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function action_instituer_objet_dist($arg = null) { |
| 31 | 31 | |
| 32 | - if (is_null($arg)) { |
|
| 33 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | - $arg = $securiser_action(); |
|
| 35 | - } |
|
| 32 | + if (is_null($arg)) { |
|
| 33 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | + $arg = $securiser_action(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | - if (!$statut) { |
|
| 39 | - $statut = _request('statut_nouv'); |
|
| 40 | - } // cas POST |
|
| 41 | - if (!$statut) { |
|
| 42 | - return; |
|
| 43 | - } // impossible mais sait-on jamais |
|
| 37 | + [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | + if (!$statut) { |
|
| 39 | + $statut = _request('statut_nouv'); |
|
| 40 | + } // cas POST |
|
| 41 | + if (!$statut) { |
|
| 42 | + return; |
|
| 43 | + } // impossible mais sait-on jamais |
|
| 44 | 44 | |
| 45 | - if ( |
|
| 46 | - $id_objet = intval($id_objet) |
|
| 47 | - and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | - ) { |
|
| 49 | - include_spip('action/editer_objet'); |
|
| 50 | - objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | - } |
|
| 45 | + if ( |
|
| 46 | + $id_objet = intval($id_objet) |
|
| 47 | + and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | + ) { |
|
| 49 | + include_spip('action/editer_objet'); |
|
| 50 | + objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -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 | /** |
@@ -25,41 +25,41 @@ discard block |
||
| 25 | 25 | **/ |
| 26 | 26 | function action_instituer_langue_rubrique_dist() { |
| 27 | 27 | |
| 28 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | - $arg = $securiser_action(); |
|
| 30 | - $changer_lang = _request('changer_lang'); |
|
| 28 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | + $arg = $securiser_action(); |
|
| 30 | + $changer_lang = _request('changer_lang'); |
|
| 31 | 31 | |
| 32 | - [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 32 | + [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - $changer_lang |
|
| 36 | - and $id_rubrique > 0 |
|
| 37 | - and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | - and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | - ) { |
|
| 40 | - if ($changer_lang != 'herit') { |
|
| 41 | - sql_updateq( |
|
| 42 | - 'spip_rubriques', |
|
| 43 | - ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | - "id_rubrique=$id_rubrique" |
|
| 45 | - ); |
|
| 46 | - } else { |
|
| 47 | - if ($id_parent == 0) { |
|
| 48 | - $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | - } else { |
|
| 50 | - $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | - } |
|
| 52 | - sql_updateq( |
|
| 53 | - 'spip_rubriques', |
|
| 54 | - ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | - "id_rubrique=$id_rubrique" |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - include_spip('inc/rubriques'); |
|
| 59 | - calculer_langues_rubriques(); |
|
| 34 | + if ( |
|
| 35 | + $changer_lang |
|
| 36 | + and $id_rubrique > 0 |
|
| 37 | + and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | + and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | + ) { |
|
| 40 | + if ($changer_lang != 'herit') { |
|
| 41 | + sql_updateq( |
|
| 42 | + 'spip_rubriques', |
|
| 43 | + ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | + "id_rubrique=$id_rubrique" |
|
| 45 | + ); |
|
| 46 | + } else { |
|
| 47 | + if ($id_parent == 0) { |
|
| 48 | + $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | + } else { |
|
| 50 | + $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | + } |
|
| 52 | + sql_updateq( |
|
| 53 | + 'spip_rubriques', |
|
| 54 | + ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | + "id_rubrique=$id_rubrique" |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + include_spip('inc/rubriques'); |
|
| 59 | + calculer_langues_rubriques(); |
|
| 60 | 60 | |
| 61 | - // invalider les caches marques de cette rubrique |
|
| 62 | - include_spip('inc/invalideur'); |
|
| 63 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | - } |
|
| 61 | + // invalider les caches marques de cette rubrique |
|
| 62 | + include_spip('inc/invalideur'); |
|
| 63 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -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 | |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | 37 | function action_supprimer_lien_dist($arg = null) { |
| 38 | - if (is_null($arg)) { |
|
| 39 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | - $arg = $securiser_action(); |
|
| 41 | - } |
|
| 38 | + if (is_null($arg)) { |
|
| 39 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | + $arg = $securiser_action(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $arg = explode('-', $arg); |
|
| 44 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 43 | + $arg = explode('-', $arg); |
|
| 44 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 45 | 45 | |
| 46 | - include_spip('action/editer_liens'); |
|
| 47 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 46 | + include_spip('action/editer_liens'); |
|
| 47 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 48 | 48 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/headers'); |
| 24 | 24 | |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | * Sortie du buffer |
| 36 | 36 | **/ |
| 37 | 37 | function action_tester_taille_error_handler($output) { |
| 38 | - // on est ici, donc echec lors de la creation de l'image |
|
| 39 | - if (!empty($GLOBALS['redirect'])) { |
|
| 40 | - return redirige_formulaire($GLOBALS['redirect']); |
|
| 41 | - } |
|
| 38 | + // on est ici, donc echec lors de la creation de l'image |
|
| 39 | + if (!empty($GLOBALS['redirect'])) { |
|
| 40 | + return redirige_formulaire($GLOBALS['redirect']); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $output; |
|
| 43 | + return $output; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -58,77 +58,77 @@ discard block |
||
| 58 | 58 | **/ |
| 59 | 59 | function action_tester_taille_dist() { |
| 60 | 60 | |
| 61 | - if (!autoriser('configurer')) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $taille = _request('arg'); |
|
| 66 | - $taille = explode('-', $taille); |
|
| 67 | - |
|
| 68 | - $GLOBALS['taille_max'] = end($taille); |
|
| 69 | - $GLOBALS['taille_min'] = 0; |
|
| 70 | - if (count($taille) > 1) { |
|
| 71 | - $GLOBALS['taille_min'] = reset($taille); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // si l'intervalle est assez petit, on garde la valeur min |
|
| 75 | - if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 76 | - $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 77 | - if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 78 | - $t = $t * 0.9; // marge de securite |
|
| 79 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 80 | - } else { |
|
| 81 | - // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 82 | - $t = 0; |
|
| 83 | - echo '∞'; |
|
| 84 | - } |
|
| 85 | - ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 86 | - die(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 90 | - |
|
| 91 | - include_spip('inc/filtres'); |
|
| 92 | - // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 93 | - include_spip('public/assembler'); |
|
| 94 | - include_spip('public/balises'); |
|
| 95 | - include_spip('public/boucles'); |
|
| 96 | - include_spip('public/cacher'); |
|
| 97 | - include_spip('public/compiler'); |
|
| 98 | - include_spip('public/composer'); |
|
| 99 | - include_spip('public/criteres'); |
|
| 100 | - include_spip('public/interfaces'); |
|
| 101 | - include_spip('public/parametrer'); |
|
| 102 | - include_spip('public/phraser_html'); |
|
| 103 | - include_spip('public/references'); |
|
| 104 | - |
|
| 105 | - include_spip('inc/presentation'); |
|
| 106 | - include_spip('inc/charsets'); |
|
| 107 | - include_spip('inc/documents'); |
|
| 108 | - include_spip('inc/header'); |
|
| 109 | - propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 110 | - |
|
| 111 | - $i = _request('i') + 1; |
|
| 112 | - $image_source = chemin_image('test.png'); |
|
| 113 | - $GLOBALS['redirect'] = generer_url_action( |
|
| 114 | - 'tester_taille', |
|
| 115 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - ob_start('action_tester_taille_error_handler'); |
|
| 119 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 120 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 121 | - |
|
| 122 | - // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 123 | - // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 124 | - if ($GLOBALS['taille_min'] == 0) { |
|
| 125 | - $taille = $GLOBALS['taille_max']; |
|
| 126 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 127 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 128 | - } |
|
| 129 | - ob_end_clean(); |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - // on est ici, donc pas de plantage |
|
| 133 | - echo redirige_formulaire($GLOBALS['redirect']); |
|
| 61 | + if (!autoriser('configurer')) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $taille = _request('arg'); |
|
| 66 | + $taille = explode('-', $taille); |
|
| 67 | + |
|
| 68 | + $GLOBALS['taille_max'] = end($taille); |
|
| 69 | + $GLOBALS['taille_min'] = 0; |
|
| 70 | + if (count($taille) > 1) { |
|
| 71 | + $GLOBALS['taille_min'] = reset($taille); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // si l'intervalle est assez petit, on garde la valeur min |
|
| 75 | + if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 76 | + $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 77 | + if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 78 | + $t = $t * 0.9; // marge de securite |
|
| 79 | + echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 80 | + } else { |
|
| 81 | + // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 82 | + $t = 0; |
|
| 83 | + echo '∞'; |
|
| 84 | + } |
|
| 85 | + ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 86 | + die(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 90 | + |
|
| 91 | + include_spip('inc/filtres'); |
|
| 92 | + // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 93 | + include_spip('public/assembler'); |
|
| 94 | + include_spip('public/balises'); |
|
| 95 | + include_spip('public/boucles'); |
|
| 96 | + include_spip('public/cacher'); |
|
| 97 | + include_spip('public/compiler'); |
|
| 98 | + include_spip('public/composer'); |
|
| 99 | + include_spip('public/criteres'); |
|
| 100 | + include_spip('public/interfaces'); |
|
| 101 | + include_spip('public/parametrer'); |
|
| 102 | + include_spip('public/phraser_html'); |
|
| 103 | + include_spip('public/references'); |
|
| 104 | + |
|
| 105 | + include_spip('inc/presentation'); |
|
| 106 | + include_spip('inc/charsets'); |
|
| 107 | + include_spip('inc/documents'); |
|
| 108 | + include_spip('inc/header'); |
|
| 109 | + propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 110 | + |
|
| 111 | + $i = _request('i') + 1; |
|
| 112 | + $image_source = chemin_image('test.png'); |
|
| 113 | + $GLOBALS['redirect'] = generer_url_action( |
|
| 114 | + 'tester_taille', |
|
| 115 | + "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + ob_start('action_tester_taille_error_handler'); |
|
| 119 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 120 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 121 | + |
|
| 122 | + // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 123 | + // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 124 | + if ($GLOBALS['taille_min'] == 0) { |
|
| 125 | + $taille = $GLOBALS['taille_max']; |
|
| 126 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 127 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 128 | + } |
|
| 129 | + ob_end_clean(); |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + // on est ici, donc pas de plantage |
|
| 133 | + echo redirige_formulaire($GLOBALS['redirect']); |
|
| 134 | 134 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
| 77 | 77 | if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
| 78 | 78 | $t = $t * 0.9; // marge de securite |
| 79 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 79 | + echo round($t / 1_000_000, 3).' Mpx'; |
|
| 80 | 80 | } else { |
| 81 | 81 | // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
| 82 | 82 | $t = 0; |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | $image_source = chemin_image('test.png'); |
| 113 | 113 | $GLOBALS['redirect'] = generer_url_action( |
| 114 | 114 | 'tester_taille', |
| 115 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 115 | + "i=$i&arg=".$GLOBALS['taille_min'].'-'.$GLOBALS['taille_test'] |
|
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | ob_start('action_tester_taille_error_handler'); |
| 119 | 119 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 120 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 120 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 121 | 121 | |
| 122 | 122 | // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
| 123 | 123 | // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
| 124 | 124 | if ($GLOBALS['taille_min'] == 0) { |
| 125 | 125 | $taille = $GLOBALS['taille_max']; |
| 126 | 126 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 127 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 127 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 128 | 128 | } |
| 129 | 129 | ob_end_clean(); |
| 130 | 130 | |