@@ -11,65 +11,65 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function formulaires_rediriger_article_charger_dist($id_article, $retour = '') { |
| 18 | 18 | |
| 19 | - include_spip('inc/autoriser'); |
|
| 20 | - if (!autoriser('modifier', 'article', $id_article)) { |
|
| 21 | - return false; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - $row = sql_fetsel('id_article,virtuel', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 25 | - if (!$row['id_article']) { |
|
| 26 | - return false; |
|
| 27 | - } |
|
| 28 | - include_spip('inc/lien'); |
|
| 29 | - $redirection = virtuel_redirige($row['virtuel']); |
|
| 30 | - |
|
| 31 | - if ( |
|
| 32 | - !$redirection |
|
| 33 | - and $GLOBALS['meta']['articles_redirection'] != 'oui' |
|
| 34 | - ) { |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - include_spip('inc/texte'); |
|
| 40 | - $valeurs = [ |
|
| 41 | - 'redirection' => $redirection, |
|
| 42 | - 'id' => $id_article, |
|
| 43 | - '_afficher_url' => ($redirection ? propre("[->$redirection]") : ''), |
|
| 44 | - ]; |
|
| 45 | - |
|
| 46 | - return $valeurs; |
|
| 19 | + include_spip('inc/autoriser'); |
|
| 20 | + if (!autoriser('modifier', 'article', $id_article)) { |
|
| 21 | + return false; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + $row = sql_fetsel('id_article,virtuel', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 25 | + if (!$row['id_article']) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 28 | + include_spip('inc/lien'); |
|
| 29 | + $redirection = virtuel_redirige($row['virtuel']); |
|
| 30 | + |
|
| 31 | + if ( |
|
| 32 | + !$redirection |
|
| 33 | + and $GLOBALS['meta']['articles_redirection'] != 'oui' |
|
| 34 | + ) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + include_spip('inc/texte'); |
|
| 40 | + $valeurs = [ |
|
| 41 | + 'redirection' => $redirection, |
|
| 42 | + 'id' => $id_article, |
|
| 43 | + '_afficher_url' => ($redirection ? propre("[->$redirection]") : ''), |
|
| 44 | + ]; |
|
| 45 | + |
|
| 46 | + return $valeurs; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function formulaires_rediriger_article_verifier_dist($id_article, $retour = '') { |
| 50 | - $erreurs = []; |
|
| 50 | + $erreurs = []; |
|
| 51 | 51 | |
| 52 | - if (($redirection = _request('redirection')) == $id_article || $redirection == 'art' . $id_article) { |
|
| 53 | - $erreurs['redirection'] = _T('info_redirection_boucle'); |
|
| 54 | - } |
|
| 52 | + if (($redirection = _request('redirection')) == $id_article || $redirection == 'art' . $id_article) { |
|
| 53 | + $erreurs['redirection'] = _T('info_redirection_boucle'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $erreurs; |
|
| 56 | + return $erreurs; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function formulaires_rediriger_article_traiter_dist($id_article, $retour = '') { |
| 60 | 60 | |
| 61 | - $url = preg_replace(',^\s*https?://$,i', '', rtrim(_request('redirection'))); |
|
| 62 | - if ($url) { |
|
| 63 | - $url = corriger_caracteres($url); |
|
| 64 | - } |
|
| 61 | + $url = preg_replace(',^\s*https?://$,i', '', rtrim(_request('redirection'))); |
|
| 62 | + if ($url) { |
|
| 63 | + $url = corriger_caracteres($url); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - include_spip('action/editer_article'); |
|
| 67 | - article_modifier($id_article, ['virtuel' => $url]); |
|
| 66 | + include_spip('action/editer_article'); |
|
| 67 | + article_modifier($id_article, ['virtuel' => $url]); |
|
| 68 | 68 | |
| 69 | - $js = _AJAX ? '<script type="text/javascript">if (window.ajaxReload) ajaxReload("wysiwyg");</script>' : ''; |
|
| 69 | + $js = _AJAX ? '<script type="text/javascript">if (window.ajaxReload) ajaxReload("wysiwyg");</script>' : ''; |
|
| 70 | 70 | |
| 71 | - return [ |
|
| 72 | - 'message_ok' => ($url ? _T('info_redirection_activee') : _T('info_redirection_desactivee')) . $js, |
|
| 73 | - 'editable' => true |
|
| 74 | - ]; |
|
| 71 | + return [ |
|
| 72 | + 'message_ok' => ($url ? _T('info_redirection_activee') : _T('info_redirection_desactivee')) . $js, |
|
| 73 | + 'editable' => true |
|
| 74 | + ]; |
|
| 75 | 75 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/editer'); |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function lister_statuts_proposes($desc, $publiable = true) { |
| 35 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 35 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $l = $desc['statut_textes_instituer']; |
|
| 40 | - if (!$publiable) { |
|
| 41 | - unset($l['publie']); |
|
| 42 | - unset($l['refuse']); |
|
| 43 | - } |
|
| 39 | + $l = $desc['statut_textes_instituer']; |
|
| 40 | + if (!$publiable) { |
|
| 41 | + unset($l['publie']); |
|
| 42 | + unset($l['refuse']); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $l; |
|
| 45 | + return $l; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -64,54 +64,54 @@ discard block |
||
| 64 | 64 | * Environnement du formulaire ou false si aucun affichage à faire. |
| 65 | 65 | */ |
| 66 | 66 | function formulaires_instituer_objet_charger_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 67 | - $editable = ($editable ? true : false); |
|
| 68 | - |
|
| 69 | - $table = table_objet_sql($objet); |
|
| 70 | - $desc = lister_tables_objets_sql($table); |
|
| 71 | - |
|
| 72 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | - $editable = false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le contenu de l'objet |
|
| 81 | - // dont son champ statut |
|
| 82 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | - |
|
| 84 | - $publiable = true; |
|
| 85 | - $statuts = lister_statuts_proposes($desc); |
|
| 86 | - // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | - if (isset($statuts['publie'])) { |
|
| 88 | - if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | - if ($v['statut'] == 'publie') { |
|
| 90 | - $editable = false; |
|
| 91 | - } else { |
|
| 92 | - $publiable = false; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | - if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | - $editable = false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $valeurs = [ |
|
| 102 | - 'editable' => $editable, |
|
| 103 | - 'statut' => $v['statut'], |
|
| 104 | - '_objet' => $objet, |
|
| 105 | - '_id_objet' => $id_objet, |
|
| 106 | - '_statuts' => $statuts, |
|
| 107 | - '_publiable' => $publiable, |
|
| 108 | - '_label' => isset($desc['texte_changer_statut']) ? $desc['texte_changer_statut'] : 'texte_article_statut', |
|
| 109 | - '_aide' => isset($desc['aide_changer_statut']) ? $desc['aide_changer_statut'] : '', |
|
| 110 | - '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | - ]; |
|
| 112 | - |
|
| 113 | - #if (!count($valeurs['statuts'])) |
|
| 114 | - return $valeurs; |
|
| 67 | + $editable = ($editable ? true : false); |
|
| 68 | + |
|
| 69 | + $table = table_objet_sql($objet); |
|
| 70 | + $desc = lister_tables_objets_sql($table); |
|
| 71 | + |
|
| 72 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | + $editable = false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le contenu de l'objet |
|
| 81 | + // dont son champ statut |
|
| 82 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | + |
|
| 84 | + $publiable = true; |
|
| 85 | + $statuts = lister_statuts_proposes($desc); |
|
| 86 | + // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | + if (isset($statuts['publie'])) { |
|
| 88 | + if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | + if ($v['statut'] == 'publie') { |
|
| 90 | + $editable = false; |
|
| 91 | + } else { |
|
| 92 | + $publiable = false; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | + if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | + $editable = false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $valeurs = [ |
|
| 102 | + 'editable' => $editable, |
|
| 103 | + 'statut' => $v['statut'], |
|
| 104 | + '_objet' => $objet, |
|
| 105 | + '_id_objet' => $id_objet, |
|
| 106 | + '_statuts' => $statuts, |
|
| 107 | + '_publiable' => $publiable, |
|
| 108 | + '_label' => isset($desc['texte_changer_statut']) ? $desc['texte_changer_statut'] : 'texte_article_statut', |
|
| 109 | + '_aide' => isset($desc['aide_changer_statut']) ? $desc['aide_changer_statut'] : '', |
|
| 110 | + '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | + ]; |
|
| 112 | + |
|
| 113 | + #if (!count($valeurs['statuts'])) |
|
| 114 | + return $valeurs; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -131,35 +131,35 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | */ |
| 133 | 133 | function formulaires_instituer_objet_verifier_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 134 | - $erreurs = []; |
|
| 135 | - // charger le contenu de l'objet |
|
| 136 | - // dont son champ statut |
|
| 137 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | - |
|
| 139 | - if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | - $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | - } else { |
|
| 142 | - $table = table_objet_sql($objet); |
|
| 143 | - $desc = lister_tables_objets_sql($table); |
|
| 144 | - |
|
| 145 | - $publiable = true; |
|
| 146 | - if ( |
|
| 147 | - isset($v['id_rubrique']) |
|
| 148 | - and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | - ) { |
|
| 150 | - $publiable = false; |
|
| 151 | - } |
|
| 152 | - $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | - $statut = _request('statut'); |
|
| 154 | - if ( |
|
| 155 | - !isset($l[$statut]) |
|
| 156 | - or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | - ) { |
|
| 158 | - $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + // charger le contenu de l'objet |
|
| 136 | + // dont son champ statut |
|
| 137 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | + |
|
| 139 | + if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | + $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | + } else { |
|
| 142 | + $table = table_objet_sql($objet); |
|
| 143 | + $desc = lister_tables_objets_sql($table); |
|
| 144 | + |
|
| 145 | + $publiable = true; |
|
| 146 | + if ( |
|
| 147 | + isset($v['id_rubrique']) |
|
| 148 | + and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | + ) { |
|
| 150 | + $publiable = false; |
|
| 151 | + } |
|
| 152 | + $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | + $statut = _request('statut'); |
|
| 154 | + if ( |
|
| 155 | + !isset($l[$statut]) |
|
| 156 | + or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | + ) { |
|
| 158 | + $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $erreurs; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -178,25 +178,25 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | function formulaires_instituer_objet_traiter_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 180 | 180 | |
| 181 | - $c = ['statut' => _request('statut')]; |
|
| 182 | - // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | - // todo dans le HTML |
|
| 184 | - if ($d = _request('date_posterieure')) { |
|
| 185 | - $c['date'] = $d; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - include_spip('action/editer_objet'); |
|
| 190 | - if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | - $res = ['message_erreur' => $err]; |
|
| 192 | - } else { |
|
| 193 | - $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | - if ($retour) { |
|
| 195 | - $res['redirect'] = $retour; |
|
| 196 | - } |
|
| 197 | - set_request('statut'); |
|
| 198 | - set_request('date_posterieure'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $res; |
|
| 181 | + $c = ['statut' => _request('statut')]; |
|
| 182 | + // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | + // todo dans le HTML |
|
| 184 | + if ($d = _request('date_posterieure')) { |
|
| 185 | + $c['date'] = $d; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + include_spip('action/editer_objet'); |
|
| 190 | + if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | + $res = ['message_erreur' => $err]; |
|
| 192 | + } else { |
|
| 193 | + $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | + if ($retour) { |
|
| 195 | + $res['redirect'] = $retour; |
|
| 196 | + } |
|
| 197 | + set_request('statut'); |
|
| 198 | + set_request('date_posterieure'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $res; |
|
| 202 | 202 | } |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | * Environnement du formulaire |
| 31 | 31 | **/ |
| 32 | 32 | function formulaires_configurer_preferences_menus_charger_dist() { |
| 33 | - // travailler sur des meta fraîches |
|
| 34 | - include_spip('inc/meta'); |
|
| 35 | - lire_metas(); |
|
| 36 | - $valeurs = []; |
|
| 37 | - $valeurs['activer_menudev'] = table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev', 'non'); |
|
| 38 | - $valeurs['menus_favoris'] = obtenir_menus_favoris(); |
|
| 39 | - return $valeurs; |
|
| 33 | + // travailler sur des meta fraîches |
|
| 34 | + include_spip('inc/meta'); |
|
| 35 | + lire_metas(); |
|
| 36 | + $valeurs = []; |
|
| 37 | + $valeurs['activer_menudev'] = table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev', 'non'); |
|
| 38 | + $valeurs['menus_favoris'] = obtenir_menus_favoris(); |
|
| 39 | + return $valeurs; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -47,32 +47,32 @@ discard block |
||
| 47 | 47 | **/ |
| 48 | 48 | function formulaires_configurer_preferences_menus_traiter_dist() { |
| 49 | 49 | |
| 50 | - $activer_menudev = _request('activer_menudev'); |
|
| 51 | - $menus_favoris = _request('menus_favoris'); |
|
| 52 | - $menus_favoris = array_filter($menus_favoris); |
|
| 53 | - $menus_favoris = array_map('intval', $menus_favoris); |
|
| 50 | + $activer_menudev = _request('activer_menudev'); |
|
| 51 | + $menus_favoris = _request('menus_favoris'); |
|
| 52 | + $menus_favoris = array_filter($menus_favoris); |
|
| 53 | + $menus_favoris = array_map('intval', $menus_favoris); |
|
| 54 | 54 | |
| 55 | - if (_request('reset')) { |
|
| 56 | - $menus_favoris = []; |
|
| 57 | - set_request('menus_favoris', null); |
|
| 58 | - } |
|
| 55 | + if (_request('reset')) { |
|
| 56 | + $menus_favoris = []; |
|
| 57 | + set_request('menus_favoris', null); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - // si le menu dev change, ou les menus favoris, on recharge toute la page. |
|
| 61 | - if ( |
|
| 62 | - table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev') != $activer_menudev |
|
| 63 | - or $menus_favoris != obtenir_menus_favoris() |
|
| 64 | - ) { |
|
| 65 | - refuser_traiter_formulaire_ajax(); |
|
| 60 | + // si le menu dev change, ou les menus favoris, on recharge toute la page. |
|
| 61 | + if ( |
|
| 62 | + table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev') != $activer_menudev |
|
| 63 | + or $menus_favoris != obtenir_menus_favoris() |
|
| 64 | + ) { |
|
| 65 | + refuser_traiter_formulaire_ajax(); |
|
| 66 | 66 | |
| 67 | - $GLOBALS['visiteur_session']['prefs']['activer_menudev'] = $activer_menudev; |
|
| 68 | - $GLOBALS['visiteur_session']['prefs']['menus_favoris'] = $menus_favoris; |
|
| 67 | + $GLOBALS['visiteur_session']['prefs']['activer_menudev'] = $activer_menudev; |
|
| 68 | + $GLOBALS['visiteur_session']['prefs']['menus_favoris'] = $menus_favoris; |
|
| 69 | 69 | |
| 70 | - if (intval($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 71 | - include_spip('action/editer_auteur'); |
|
| 72 | - $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])]; |
|
| 73 | - auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c); |
|
| 74 | - } |
|
| 75 | - } |
|
| 70 | + if (intval($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 71 | + include_spip('action/editer_auteur'); |
|
| 72 | + $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])]; |
|
| 73 | + auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return ['message_ok' => _T('config_info_enregistree'), 'editable' => true]; |
|
| 77 | + return ['message_ok' => _T('config_info_enregistree'), 'editable' => true]; |
|
| 78 | 78 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -31,28 +31,28 @@ discard block |
||
| 31 | 31 | * Environnement du formulaire |
| 32 | 32 | **/ |
| 33 | 33 | function formulaires_configurer_preferences_charger_dist() { |
| 34 | - // travailler sur des meta fraiches |
|
| 35 | - include_spip('inc/meta'); |
|
| 36 | - lire_metas(); |
|
| 34 | + // travailler sur des meta fraiches |
|
| 35 | + include_spip('inc/meta'); |
|
| 36 | + lire_metas(); |
|
| 37 | 37 | |
| 38 | - $valeurs = []; |
|
| 39 | - $valeurs['display_navigation'] = isset($GLOBALS['visiteur_session']['prefs']['display_navigation']) ? $GLOBALS['visiteur_session']['prefs']['display_navigation'] : 'navigation_avec_icones'; |
|
| 40 | - $valeurs['display_outils'] = isset($GLOBALS['visiteur_session']['prefs']['display_outils']) ? $GLOBALS['visiteur_session']['prefs']['display_outils'] : 'oui'; |
|
| 41 | - $valeurs['display'] = (isset($GLOBALS['visiteur_session']['prefs']['display']) and $GLOBALS['visiteur_session']['prefs']['display'] > 0) ? $GLOBALS['visiteur_session']['prefs']['display'] : 2; |
|
| 42 | - $valeurs['couleur'] = (isset($GLOBALS['visiteur_session']['prefs']['couleur']) and $GLOBALS['visiteur_session']['prefs']['couleur'] > 0) ? $GLOBALS['visiteur_session']['prefs']['couleur'] : 1; |
|
| 38 | + $valeurs = []; |
|
| 39 | + $valeurs['display_navigation'] = isset($GLOBALS['visiteur_session']['prefs']['display_navigation']) ? $GLOBALS['visiteur_session']['prefs']['display_navigation'] : 'navigation_avec_icones'; |
|
| 40 | + $valeurs['display_outils'] = isset($GLOBALS['visiteur_session']['prefs']['display_outils']) ? $GLOBALS['visiteur_session']['prefs']['display_outils'] : 'oui'; |
|
| 41 | + $valeurs['display'] = (isset($GLOBALS['visiteur_session']['prefs']['display']) and $GLOBALS['visiteur_session']['prefs']['display'] > 0) ? $GLOBALS['visiteur_session']['prefs']['display'] : 2; |
|
| 42 | + $valeurs['couleur'] = (isset($GLOBALS['visiteur_session']['prefs']['couleur']) and $GLOBALS['visiteur_session']['prefs']['couleur'] > 0) ? $GLOBALS['visiteur_session']['prefs']['couleur'] : 1; |
|
| 43 | 43 | |
| 44 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 45 | - $les_couleurs = $couleurs(); |
|
| 46 | - foreach ($les_couleurs as $k => $c) { |
|
| 47 | - $valeurs['_couleurs_url'][$k] = generer_url_public('style_prive.css', 'ltr=' |
|
| 48 | - . $GLOBALS['spip_lang_left'] . '&' |
|
| 49 | - . $couleurs($k)); |
|
| 50 | - $valeurs['couleurs'][$k] = $c; |
|
| 51 | - } |
|
| 44 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 45 | + $les_couleurs = $couleurs(); |
|
| 46 | + foreach ($les_couleurs as $k => $c) { |
|
| 47 | + $valeurs['_couleurs_url'][$k] = generer_url_public('style_prive.css', 'ltr=' |
|
| 48 | + . $GLOBALS['spip_lang_left'] . '&' |
|
| 49 | + . $couleurs($k)); |
|
| 50 | + $valeurs['couleurs'][$k] = $c; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $valeurs['imessage'] = $GLOBALS['visiteur_session']['imessage']; |
|
| 53 | + $valeurs['imessage'] = $GLOBALS['visiteur_session']['imessage']; |
|
| 54 | 54 | |
| 55 | - return $valeurs; |
|
| 55 | + return $valeurs; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -63,36 +63,36 @@ discard block |
||
| 63 | 63 | **/ |
| 64 | 64 | function formulaires_configurer_preferences_traiter_dist() { |
| 65 | 65 | |
| 66 | - if ($couleur = _request('couleur')) { |
|
| 67 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 68 | - $les_couleurs = $couleurs([], true); |
|
| 69 | - if (isset($les_couleurs[$couleur])) { |
|
| 70 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = $couleur; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - if ($display = intval(_request('display'))) { |
|
| 74 | - $GLOBALS['visiteur_session']['prefs']['display'] = $display; |
|
| 75 | - } |
|
| 76 | - if ( |
|
| 77 | - $display_navigation = _request('display_navigation') |
|
| 78 | - and in_array($display_navigation, ['navigation_sans_icone', 'navigation_avec_icones']) |
|
| 79 | - ) { |
|
| 80 | - $GLOBALS['visiteur_session']['prefs']['display_navigation'] = $display_navigation; |
|
| 81 | - } |
|
| 82 | - if (!is_null($display_outils = _request('display_outils'))) { |
|
| 83 | - $GLOBALS['visiteur_session']['prefs']['display_outils'] = ($display_outils ? 'oui' : ''); |
|
| 84 | - } |
|
| 66 | + if ($couleur = _request('couleur')) { |
|
| 67 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 68 | + $les_couleurs = $couleurs([], true); |
|
| 69 | + if (isset($les_couleurs[$couleur])) { |
|
| 70 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = $couleur; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + if ($display = intval(_request('display'))) { |
|
| 74 | + $GLOBALS['visiteur_session']['prefs']['display'] = $display; |
|
| 75 | + } |
|
| 76 | + if ( |
|
| 77 | + $display_navigation = _request('display_navigation') |
|
| 78 | + and in_array($display_navigation, ['navigation_sans_icone', 'navigation_avec_icones']) |
|
| 79 | + ) { |
|
| 80 | + $GLOBALS['visiteur_session']['prefs']['display_navigation'] = $display_navigation; |
|
| 81 | + } |
|
| 82 | + if (!is_null($display_outils = _request('display_outils'))) { |
|
| 83 | + $GLOBALS['visiteur_session']['prefs']['display_outils'] = ($display_outils ? 'oui' : ''); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if (intval($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 87 | - include_spip('action/editer_auteur'); |
|
| 88 | - $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])]; |
|
| 86 | + if (intval($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 87 | + include_spip('action/editer_auteur'); |
|
| 88 | + $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])]; |
|
| 89 | 89 | |
| 90 | - if ($imessage = _request('imessage') and in_array($imessage, ['oui', 'non'])) { |
|
| 91 | - $c['imessage'] = $imessage; |
|
| 92 | - } |
|
| 90 | + if ($imessage = _request('imessage') and in_array($imessage, ['oui', 'non'])) { |
|
| 91 | + $c['imessage'] = $imessage; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c); |
|
| 95 | - } |
|
| 94 | + auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return ['message_ok' => _T('config_info_enregistree'), 'editable' => true]; |
|
| 97 | + return ['message_ok' => _T('config_info_enregistree'), 'editable' => true]; |
|
| 98 | 98 | } |
@@ -11,74 +11,74 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Correction typographique francaise |
| 18 | 18 | |
| 19 | 19 | function typographie_fr_dist($letexte) { |
| 20 | 20 | |
| 21 | - static $trans; |
|
| 21 | + static $trans; |
|
| 22 | 22 | |
| 23 | - // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 24 | - // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 25 | - if (!$trans) { |
|
| 26 | - $trans = [ |
|
| 27 | - "'" => '’', |
|
| 28 | - ' ' => '~', |
|
| 29 | - '»' => '»', |
|
| 30 | - '«' => '«', |
|
| 31 | - '”' => '”', |
|
| 32 | - '“' => '“', |
|
| 33 | - '°' => '°' |
|
| 34 | - ]; |
|
| 35 | - $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 36 | - $chars_trans = array_keys($chars); |
|
| 37 | - $chars = array_values($chars); |
|
| 38 | - $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 39 | - $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 40 | - $chars_trans = explode(' ', $chars_trans); |
|
| 41 | - foreach ($chars as $k => $r) { |
|
| 42 | - $trans[$chars_trans[$k]] = $r; |
|
| 43 | - } |
|
| 44 | - } |
|
| 23 | + // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 24 | + // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 25 | + if (!$trans) { |
|
| 26 | + $trans = [ |
|
| 27 | + "'" => '’', |
|
| 28 | + ' ' => '~', |
|
| 29 | + '»' => '»', |
|
| 30 | + '«' => '«', |
|
| 31 | + '”' => '”', |
|
| 32 | + '“' => '“', |
|
| 33 | + '°' => '°' |
|
| 34 | + ]; |
|
| 35 | + $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 36 | + $chars_trans = array_keys($chars); |
|
| 37 | + $chars = array_values($chars); |
|
| 38 | + $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 39 | + $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 40 | + $chars_trans = explode(' ', $chars_trans); |
|
| 41 | + foreach ($chars as $k => $r) { |
|
| 42 | + $trans[$chars_trans[$k]] = $r; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $letexte = strtr($letexte, $trans); |
|
| 46 | + $letexte = strtr($letexte, $trans); |
|
| 47 | 47 | |
| 48 | - $cherche1 = [ |
|
| 49 | - /* 1 */ |
|
| 50 | - '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 51 | - /* 2 */ |
|
| 52 | - '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 53 | - /* 3 */ |
|
| 54 | - '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 55 | - /* 4 */ |
|
| 56 | - '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 57 | - ]; |
|
| 58 | - $remplace1 = [ |
|
| 59 | - /* 1 */ |
|
| 60 | - '\1~;', |
|
| 61 | - /* 2 */ |
|
| 62 | - '~\0', |
|
| 63 | - /* 3 */ |
|
| 64 | - '\1~\2', |
|
| 65 | - /* 4 */ |
|
| 66 | - '\0~' |
|
| 67 | - ]; |
|
| 68 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 69 | - $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 48 | + $cherche1 = [ |
|
| 49 | + /* 1 */ |
|
| 50 | + '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 51 | + /* 2 */ |
|
| 52 | + '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 53 | + /* 3 */ |
|
| 54 | + '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 55 | + /* 4 */ |
|
| 56 | + '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 57 | + ]; |
|
| 58 | + $remplace1 = [ |
|
| 59 | + /* 1 */ |
|
| 60 | + '\1~;', |
|
| 61 | + /* 2 */ |
|
| 62 | + '~\0', |
|
| 63 | + /* 3 */ |
|
| 64 | + '\1~\2', |
|
| 65 | + /* 4 */ |
|
| 66 | + '\0~' |
|
| 67 | + ]; |
|
| 68 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 69 | + $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 70 | 70 | |
| 71 | - $cherche2 = [ |
|
| 72 | - '/([^-\n]|^)--([^-]|$)/S', |
|
| 73 | - ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 74 | - '/~/' |
|
| 75 | - ]; |
|
| 76 | - $remplace2 = [ |
|
| 77 | - '\1—\2', |
|
| 78 | - '\1\3\4', |
|
| 79 | - ' ' |
|
| 80 | - ]; |
|
| 81 | - $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 71 | + $cherche2 = [ |
|
| 72 | + '/([^-\n]|^)--([^-]|$)/S', |
|
| 73 | + ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 74 | + '/~/' |
|
| 75 | + ]; |
|
| 76 | + $remplace2 = [ |
|
| 77 | + '\1—\2', |
|
| 78 | + '\1\3\4', |
|
| 79 | + ' ' |
|
| 80 | + ]; |
|
| 81 | + $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 82 | 82 | |
| 83 | - return $letexte; |
|
| 83 | + return $letexte; |
|
| 84 | 84 | } |
@@ -11,37 +11,37 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // rien sauf les "~" et "-," |
| 18 | 18 | |
| 19 | 19 | function typographie_en_dist($letexte) { |
| 20 | 20 | |
| 21 | - // zouli apostrophe |
|
| 22 | - $letexte = str_replace("'", '’', $letexte); |
|
| 21 | + // zouli apostrophe |
|
| 22 | + $letexte = str_replace("'", '’', $letexte); |
|
| 23 | 23 | |
| 24 | - $cherche1 = [ |
|
| 25 | - '/ --?,/S' |
|
| 26 | - ]; |
|
| 27 | - $remplace1 = [ |
|
| 28 | - '~\0' |
|
| 29 | - ]; |
|
| 30 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 24 | + $cherche1 = [ |
|
| 25 | + '/ --?,/S' |
|
| 26 | + ]; |
|
| 27 | + $remplace1 = [ |
|
| 28 | + '~\0' |
|
| 29 | + ]; |
|
| 30 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 31 | 31 | |
| 32 | - $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | - $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 32 | + $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | + $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 34 | 34 | |
| 35 | - $cherche2 = [ |
|
| 36 | - '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | - '/~/' |
|
| 38 | - ]; |
|
| 39 | - $remplace2 = [ |
|
| 40 | - '\1—\2', |
|
| 41 | - ' ' |
|
| 42 | - ]; |
|
| 35 | + $cherche2 = [ |
|
| 36 | + '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | + '/~/' |
|
| 38 | + ]; |
|
| 39 | + $remplace2 = [ |
|
| 40 | + '\1—\2', |
|
| 41 | + ' ' |
|
| 42 | + ]; |
|
| 43 | 43 | |
| 44 | - $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 44 | + $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 45 | 45 | |
| 46 | - return $letexte; |
|
| 46 | + return $letexte; |
|
| 47 | 47 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, $connect = '') { |
| 60 | - static $cache_quete = []; |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if ( |
|
| 66 | - !$desc = $trouver_table( |
|
| 67 | - $table, |
|
| 68 | - $connect |
|
| 69 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | - ) { |
|
| 71 | - // pas de parent rubrique, on passe |
|
| 72 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | - } else { |
|
| 74 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | - $cache_quete[$connect][$table]['_select'], |
|
| 83 | - $table, |
|
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - '', |
|
| 89 | - $connect |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 60 | + static $cache_quete = []; |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if ( |
|
| 66 | + !$desc = $trouver_table( |
|
| 67 | + $table, |
|
| 68 | + $connect |
|
| 69 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | + ) { |
|
| 71 | + // pas de parent rubrique, on passe |
|
| 72 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | + } else { |
|
| 74 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | + $cache_quete[$connect][$table]['_select'], |
|
| 83 | + $table, |
|
| 84 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + '', |
|
| 89 | + $connect |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | function quete_parent($id_rubrique, $connect = '') { |
| 111 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | - return 0; |
|
| 113 | - } |
|
| 114 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 111 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | function quete_rubrique($id_article, $serveur) { |
| 131 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 132 | 132 | |
| 133 | - return $id_parent['id_rubrique']; |
|
| 133 | + return $id_parent['id_rubrique']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * @return int |
| 145 | 145 | */ |
| 146 | 146 | function quete_profondeur($id, $connect = '') { |
| 147 | - $n = 0; |
|
| 148 | - while ($id) { |
|
| 149 | - $n++; |
|
| 150 | - $id = quete_parent($id, $connect); |
|
| 151 | - } |
|
| 147 | + $n = 0; |
|
| 148 | + while ($id) { |
|
| 149 | + $n++; |
|
| 150 | + $id = quete_parent($id, $connect); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $n; |
|
| 153 | + return $n; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * Morceau de la requête SQL testant la date |
| 167 | 167 | */ |
| 168 | 168 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 169 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | - return '1=1'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return |
|
| 174 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | - : '1=1'; |
|
| 169 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | + return '1=1'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return |
|
| 174 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | + : '1=1'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -194,101 +194,101 @@ discard block |
||
| 194 | 194 | * @return array|string |
| 195 | 195 | */ |
| 196 | 196 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 197 | - static $cond = []; |
|
| 198 | - $key = func_get_args(); |
|
| 199 | - $key = implode('-', $key); |
|
| 200 | - if (isset($cond[$key])) { |
|
| 201 | - return $cond[$key]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $liste_statuts = $publie; |
|
| 205 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | - $liste_statuts = $previsu; |
|
| 207 | - } |
|
| 208 | - $not = false; |
|
| 209 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | - $not = true; |
|
| 211 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | - } |
|
| 213 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | - if (!strlen($liste_statuts)) { |
|
| 215 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | - $where = []; |
|
| 220 | - foreach ($liste_statuts as $k => $v) { |
|
| 221 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | - // a ceux de l'auteur identifie |
|
| 223 | - if (strpos($v, '/') !== false) { |
|
| 224 | - $v = explode('/', $v); |
|
| 225 | - $filtre = end($v); |
|
| 226 | - $v = reset($v); |
|
| 227 | - $v = preg_replace(',\W,', '', $v); |
|
| 228 | - if ( |
|
| 229 | - $filtre == 'auteur' |
|
| 230 | - and (strpos($mstatut, '.') !== false) |
|
| 231 | - and $objet = explode('.', $mstatut) |
|
| 232 | - and $id_table = reset($objet) |
|
| 233 | - and $objet = objet_type($id_table) |
|
| 234 | - ) { |
|
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | - |
|
| 237 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | - // sinon l’auteur en session |
|
| 239 | - include_spip('inc/securiser_action'); |
|
| 240 | - if ($desc = decrire_token_previsu()) { |
|
| 241 | - $id_auteur = $desc['id_auteur']; |
|
| 242 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | - } else { |
|
| 245 | - $id_auteur = null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | - if (!$id_auteur) { |
|
| 252 | - $where[] = $w; |
|
| 253 | - } else { |
|
| 254 | - $primary = id_table_objet($objet); |
|
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | - 'ssss.id_objet', |
|
| 257 | - 'spip_auteurs_liens AS ssss', |
|
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - '', |
|
| 263 | - $serveur |
|
| 264 | - ) . '))'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | - else { |
|
| 269 | - $v = ''; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // securite |
|
| 273 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | - } |
|
| 275 | - $liste_statuts = array_filter($liste_statuts); |
|
| 276 | - if (count($liste_statuts) == 1) { |
|
| 277 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | - } else { |
|
| 279 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - while (count($where) > 1) { |
|
| 283 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | - $where[] = $and; |
|
| 285 | - } |
|
| 286 | - $cond[$key] = reset($where); |
|
| 287 | - if ($not) { |
|
| 288 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $cond[$key]; |
|
| 197 | + static $cond = []; |
|
| 198 | + $key = func_get_args(); |
|
| 199 | + $key = implode('-', $key); |
|
| 200 | + if (isset($cond[$key])) { |
|
| 201 | + return $cond[$key]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $liste_statuts = $publie; |
|
| 205 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | + $liste_statuts = $previsu; |
|
| 207 | + } |
|
| 208 | + $not = false; |
|
| 209 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | + $not = true; |
|
| 211 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | + } |
|
| 213 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | + if (!strlen($liste_statuts)) { |
|
| 215 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | + $where = []; |
|
| 220 | + foreach ($liste_statuts as $k => $v) { |
|
| 221 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | + // a ceux de l'auteur identifie |
|
| 223 | + if (strpos($v, '/') !== false) { |
|
| 224 | + $v = explode('/', $v); |
|
| 225 | + $filtre = end($v); |
|
| 226 | + $v = reset($v); |
|
| 227 | + $v = preg_replace(',\W,', '', $v); |
|
| 228 | + if ( |
|
| 229 | + $filtre == 'auteur' |
|
| 230 | + and (strpos($mstatut, '.') !== false) |
|
| 231 | + and $objet = explode('.', $mstatut) |
|
| 232 | + and $id_table = reset($objet) |
|
| 233 | + and $objet = objet_type($id_table) |
|
| 234 | + ) { |
|
| 235 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | + |
|
| 237 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | + // sinon l’auteur en session |
|
| 239 | + include_spip('inc/securiser_action'); |
|
| 240 | + if ($desc = decrire_token_previsu()) { |
|
| 241 | + $id_auteur = $desc['id_auteur']; |
|
| 242 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | + } else { |
|
| 245 | + $id_auteur = null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | + if (!$id_auteur) { |
|
| 252 | + $where[] = $w; |
|
| 253 | + } else { |
|
| 254 | + $primary = id_table_objet($objet); |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | + 'ssss.id_objet', |
|
| 257 | + 'spip_auteurs_liens AS ssss', |
|
| 258 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + '', |
|
| 263 | + $serveur |
|
| 264 | + ) . '))'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | + else { |
|
| 269 | + $v = ''; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // securite |
|
| 273 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | + } |
|
| 275 | + $liste_statuts = array_filter($liste_statuts); |
|
| 276 | + if (count($liste_statuts) == 1) { |
|
| 277 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | + } else { |
|
| 279 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + while (count($where) > 1) { |
|
| 283 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | + $where[] = $and; |
|
| 285 | + } |
|
| 286 | + $cond[$key] = reset($where); |
|
| 287 | + if ($not) { |
|
| 288 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $cond[$key]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -347,66 +347,66 @@ discard block |
||
| 347 | 347 | * Retourne soit un tableau, soit le chemin du fichier. |
| 348 | 348 | */ |
| 349 | 349 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 350 | - include_spip('base/objets'); |
|
| 351 | - $nom = strtolower($onoff); |
|
| 352 | - |
|
| 353 | - $cle_objet = id_table_objet($cle_objet); |
|
| 354 | - |
|
| 355 | - while (1) { |
|
| 356 | - $objet = objet_type($cle_objet); |
|
| 357 | - |
|
| 358 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | - |
|
| 360 | - if ($on) { |
|
| 361 | - if ($flag) { |
|
| 362 | - return basename($on['chemin']); |
|
| 363 | - } else { |
|
| 364 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | - |
|
| 366 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | - // alors on ne cherche pas du tout le survol ici |
|
| 369 | - if ($onoff != 'ON') { |
|
| 370 | - $off = ''; |
|
| 371 | - } else { |
|
| 372 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | - // qui permet de distinguer le changement de logo |
|
| 378 | - // et placer un expire sur le dossier IMG/ |
|
| 379 | - $res = [ |
|
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | - ]; |
|
| 384 | - $res['src'] = $res[0]; |
|
| 385 | - $res['logo_on'] = $res[0]; |
|
| 386 | - $res['logo_off'] = $res[1]; |
|
| 387 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | - |
|
| 390 | - return $res; |
|
| 391 | - } |
|
| 392 | - } else { |
|
| 393 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | - return ''; |
|
| 395 | - } else { |
|
| 396 | - if ($id_rubrique) { |
|
| 397 | - $cle_objet = 'id_rubrique'; |
|
| 398 | - $id = $id_rubrique; |
|
| 399 | - $id_rubrique = 0; |
|
| 400 | - } else { |
|
| 401 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | - $id = quete_parent($id); |
|
| 403 | - } else { |
|
| 404 | - return ''; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 350 | + include_spip('base/objets'); |
|
| 351 | + $nom = strtolower($onoff); |
|
| 352 | + |
|
| 353 | + $cle_objet = id_table_objet($cle_objet); |
|
| 354 | + |
|
| 355 | + while (1) { |
|
| 356 | + $objet = objet_type($cle_objet); |
|
| 357 | + |
|
| 358 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | + |
|
| 360 | + if ($on) { |
|
| 361 | + if ($flag) { |
|
| 362 | + return basename($on['chemin']); |
|
| 363 | + } else { |
|
| 364 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | + |
|
| 366 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | + // alors on ne cherche pas du tout le survol ici |
|
| 369 | + if ($onoff != 'ON') { |
|
| 370 | + $off = ''; |
|
| 371 | + } else { |
|
| 372 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | + // qui permet de distinguer le changement de logo |
|
| 378 | + // et placer un expire sur le dossier IMG/ |
|
| 379 | + $res = [ |
|
| 380 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | + ]; |
|
| 384 | + $res['src'] = $res[0]; |
|
| 385 | + $res['logo_on'] = $res[0]; |
|
| 386 | + $res['logo_off'] = $res[1]; |
|
| 387 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | + |
|
| 390 | + return $res; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | + return ''; |
|
| 395 | + } else { |
|
| 396 | + if ($id_rubrique) { |
|
| 397 | + $cle_objet = 'id_rubrique'; |
|
| 398 | + $id = $id_rubrique; |
|
| 399 | + $id_rubrique = 0; |
|
| 400 | + } else { |
|
| 401 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | + $id = quete_parent($id); |
|
| 403 | + } else { |
|
| 404 | + return ''; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,37 +420,37 @@ discard block |
||
| 420 | 420 | * "on" ou "off" suivant le logo normal ou survol |
| 421 | 421 | **/ |
| 422 | 422 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 423 | - static $chercher_logo; |
|
| 424 | - if (is_null($chercher_logo)) { |
|
| 425 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | - } |
|
| 427 | - $cle_objet = id_table_objet($objet); |
|
| 428 | - |
|
| 429 | - // On cherche pas la méthode classique |
|
| 430 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | - if (!empty($infos_logo)) { |
|
| 433 | - $infos_logo = [ |
|
| 434 | - 'chemin' => $infos_logo[0], |
|
| 435 | - 'timestamp' => $infos_logo[4], |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // On passe cette recherche de logo dans un pipeline |
|
| 440 | - $infos_logo = pipeline( |
|
| 441 | - 'quete_logo_objet', |
|
| 442 | - [ |
|
| 443 | - 'args' => [ |
|
| 444 | - 'id_objet' => $id_objet, |
|
| 445 | - 'objet' => $objet, |
|
| 446 | - 'cle_objet' => $cle_objet, |
|
| 447 | - 'mode' => $mode, |
|
| 448 | - ], |
|
| 449 | - 'data' => $infos_logo, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - return $infos_logo; |
|
| 423 | + static $chercher_logo; |
|
| 424 | + if (is_null($chercher_logo)) { |
|
| 425 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | + } |
|
| 427 | + $cle_objet = id_table_objet($objet); |
|
| 428 | + |
|
| 429 | + // On cherche pas la méthode classique |
|
| 430 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | + if (!empty($infos_logo)) { |
|
| 433 | + $infos_logo = [ |
|
| 434 | + 'chemin' => $infos_logo[0], |
|
| 435 | + 'timestamp' => $infos_logo[4], |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // On passe cette recherche de logo dans un pipeline |
|
| 440 | + $infos_logo = pipeline( |
|
| 441 | + 'quete_logo_objet', |
|
| 442 | + [ |
|
| 443 | + 'args' => [ |
|
| 444 | + 'id_objet' => $id_objet, |
|
| 445 | + 'objet' => $objet, |
|
| 446 | + 'cle_objet' => $cle_objet, |
|
| 447 | + 'mode' => $mode, |
|
| 448 | + ], |
|
| 449 | + 'data' => $infos_logo, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + return $infos_logo; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @return bool|string |
| 464 | 464 | */ |
| 465 | 465 | function quete_logo_file($row, $connect = null) { |
| 466 | - include_spip('inc/documents'); |
|
| 467 | - $logo = vignette_logo_document($row, $connect); |
|
| 468 | - if (!$logo) { |
|
| 469 | - $logo = image_du_document($row, $connect); |
|
| 470 | - } |
|
| 471 | - if (!$logo) { |
|
| 472 | - $f = charger_fonction('vignette', 'inc'); |
|
| 473 | - $logo = $f($row['extension'], false); |
|
| 474 | - } |
|
| 475 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | - if ( |
|
| 477 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | - ) { |
|
| 481 | - return $logo; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return get_spip_doc($logo); |
|
| 466 | + include_spip('inc/documents'); |
|
| 467 | + $logo = vignette_logo_document($row, $connect); |
|
| 468 | + if (!$logo) { |
|
| 469 | + $logo = image_du_document($row, $connect); |
|
| 470 | + } |
|
| 471 | + if (!$logo) { |
|
| 472 | + $f = charger_fonction('vignette', 'inc'); |
|
| 473 | + $logo = $f($row['extension'], false); |
|
| 474 | + } |
|
| 475 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | + if ( |
|
| 477 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | + ) { |
|
| 481 | + return $logo; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return get_spip_doc($logo); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) { |
| 511 | 511 | |
| 512 | - include_spip('inc/documents'); |
|
| 513 | - $logo = ''; |
|
| 514 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | - $logo = vignette_logo_document($row, $connect); |
|
| 516 | - } |
|
| 517 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | - return ''; |
|
| 520 | - } |
|
| 521 | - if ($mode_logo == 'icone') { |
|
| 522 | - $row['fichier'] = ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 512 | + include_spip('inc/documents'); |
|
| 513 | + $logo = ''; |
|
| 514 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | + $logo = vignette_logo_document($row, $connect); |
|
| 516 | + } |
|
| 517 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | + return ''; |
|
| 520 | + } |
|
| 521 | + if ($mode_logo == 'icone') { |
|
| 522 | + $row['fichier'] = ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function quete_html_logo($logo, $align, $lien) { |
| 536 | 536 | |
| 537 | - if (!is_array($logo)) { |
|
| 538 | - return ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - $contexte = []; |
|
| 542 | - foreach ($logo as $k => $v) { |
|
| 543 | - if (!is_numeric($k)) { |
|
| 544 | - $contexte[$k] = $v; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - $contexte['align'] = $align; |
|
| 548 | - $contexte['lien'] = $lien; |
|
| 549 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 537 | + if (!is_array($logo)) { |
|
| 538 | + return ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + $contexte = []; |
|
| 542 | + foreach ($logo as $k => $v) { |
|
| 543 | + if (!is_numeric($k)) { |
|
| 544 | + $contexte[$k] = $v; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + $contexte['align'] = $align; |
|
| 548 | + $contexte['lien'] = $lien; |
|
| 549 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return string|false |
| 561 | 561 | */ |
| 562 | 562 | function document_spip_externe($fichier, $connect) { |
| 563 | - if ($connect) { |
|
| 564 | - $site = quete_meta('adresse_site', $connect); |
|
| 565 | - if ($site) { |
|
| 566 | - $dir = quete_meta('dir_img', $connect); |
|
| 567 | - return "$site/$dir$fichier"; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 563 | + if ($connect) { |
|
| 564 | + $site = quete_meta('adresse_site', $connect); |
|
| 565 | + if ($site) { |
|
| 566 | + $dir = quete_meta('dir_img', $connect); |
|
| 567 | + return "$site/$dir$fichier"; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -580,23 +580,23 @@ discard block |
||
| 580 | 580 | * @return string |
| 581 | 581 | */ |
| 582 | 582 | function vignette_logo_document($row, $connect = '') { |
| 583 | - if (!$row['id_vignette']) { |
|
| 584 | - return ''; |
|
| 585 | - } |
|
| 586 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | - return $url; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - $f = get_spip_doc($fichier); |
|
| 592 | - if ($f and @file_exists($f)) { |
|
| 593 | - return $f; |
|
| 594 | - } |
|
| 595 | - if ($row['mode'] !== 'vignette') { |
|
| 596 | - return ''; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 583 | + if (!$row['id_vignette']) { |
|
| 584 | + return ''; |
|
| 585 | + } |
|
| 586 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | + return $url; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + $f = get_spip_doc($fichier); |
|
| 592 | + if ($f and @file_exists($f)) { |
|
| 593 | + return $f; |
|
| 594 | + } |
|
| 595 | + if ($row['mode'] !== 'vignette') { |
|
| 596 | + return ''; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -612,69 +612,69 @@ discard block |
||
| 612 | 612 | * @return bool|string |
| 613 | 613 | */ |
| 614 | 614 | function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') { |
| 615 | - static $exposer = []; |
|
| 616 | - |
|
| 617 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | - // en static. |
|
| 621 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | - (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | - // il n'est donc pas utile |
|
| 628 | - $parent = 0; |
|
| 629 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | - if (isset($enfants[$type])) { |
|
| 632 | - foreach ($enfants[$type] as $t) { |
|
| 633 | - if ( |
|
| 634 | - isset($reference[$t]) |
|
| 635 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | - or isset($reference["@$t"]) |
|
| 637 | - ) { |
|
| 638 | - $type = $t; |
|
| 639 | - $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | - continue; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - $exposer[$m][$type] = []; |
|
| 646 | - if ($principal) { |
|
| 647 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | - foreach ($principaux as $principal) { |
|
| 649 | - $exposer[$m][$type][$principal] = true; |
|
| 650 | - if ($type == 'id_mot') { |
|
| 651 | - if (!$parent) { |
|
| 652 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | - } |
|
| 654 | - if ($parent) { |
|
| 655 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | - } |
|
| 657 | - } else { |
|
| 658 | - if ($type != 'id_groupe') { |
|
| 659 | - if (!$parent) { |
|
| 660 | - if ($type == 'id_rubrique') { |
|
| 661 | - $parent = $principal; |
|
| 662 | - } |
|
| 663 | - if ($type == 'id_article') { |
|
| 664 | - $parent = quete_rubrique($principal, $connect); |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - do { |
|
| 668 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // And the winner is... |
|
| 677 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 615 | + static $exposer = []; |
|
| 616 | + |
|
| 617 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | + // en static. |
|
| 621 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | + $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | + (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | + // il n'est donc pas utile |
|
| 628 | + $parent = 0; |
|
| 629 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | + if (isset($enfants[$type])) { |
|
| 632 | + foreach ($enfants[$type] as $t) { |
|
| 633 | + if ( |
|
| 634 | + isset($reference[$t]) |
|
| 635 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | + or isset($reference["@$t"]) |
|
| 637 | + ) { |
|
| 638 | + $type = $t; |
|
| 639 | + $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | + continue; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + $exposer[$m][$type] = []; |
|
| 646 | + if ($principal) { |
|
| 647 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | + foreach ($principaux as $principal) { |
|
| 649 | + $exposer[$m][$type][$principal] = true; |
|
| 650 | + if ($type == 'id_mot') { |
|
| 651 | + if (!$parent) { |
|
| 652 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | + } |
|
| 654 | + if ($parent) { |
|
| 655 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | + } |
|
| 657 | + } else { |
|
| 658 | + if ($type != 'id_groupe') { |
|
| 659 | + if (!$parent) { |
|
| 660 | + if ($type == 'id_rubrique') { |
|
| 661 | + $parent = $principal; |
|
| 662 | + } |
|
| 663 | + if ($type == 'id_article') { |
|
| 664 | + $parent = quete_rubrique($principal, $connect); |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + do { |
|
| 668 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + // And the winner is... |
|
| 677 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -689,21 +689,21 @@ discard block |
||
| 689 | 689 | * @return int |
| 690 | 690 | */ |
| 691 | 691 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 692 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | - // ou composee, mais verifions |
|
| 694 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | - return 0; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $pos = 0; |
|
| 699 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | - $pos++; |
|
| 701 | - } |
|
| 702 | - // si on a pas trouve |
|
| 703 | - if (!$row or $row[$primary] != $valeur) { |
|
| 704 | - return 0; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - // sinon, calculer le bon numero de page |
|
| 708 | - return floor($pos / $pas) * $pas; |
|
| 692 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | + // ou composee, mais verifions |
|
| 694 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | + return 0; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $pos = 0; |
|
| 699 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | + $pos++; |
|
| 701 | + } |
|
| 702 | + // si on a pas trouve |
|
| 703 | + if (!$row or $row[$primary] != $valeur) { |
|
| 704 | + return 0; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + // sinon, calculer le bon numero de page |
|
| 708 | + return floor($pos / $pas) * $pas; |
|
| 709 | 709 | } |
@@ -11,130 +11,130 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 31 | - |
|
| 32 | - if ($struct->jointures_explicites) { |
|
| 33 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 34 | - } |
|
| 35 | - if ($struct->table_optionnelle) { |
|
| 36 | - $type .= '?'; |
|
| 37 | - } |
|
| 38 | - // Revoir le cas de la boucle recursive |
|
| 39 | - |
|
| 40 | - $crit = $struct->param; |
|
| 41 | - if ($crit and !is_array($crit[0])) { |
|
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 43 | - } |
|
| 44 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | - |
|
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 47 | - |
|
| 48 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | + $struct->table_optionnelle); |
|
| 31 | + |
|
| 32 | + if ($struct->jointures_explicites) { |
|
| 33 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 34 | + } |
|
| 35 | + if ($struct->table_optionnelle) { |
|
| 36 | + $type .= '?'; |
|
| 37 | + } |
|
| 38 | + // Revoir le cas de la boucle recursive |
|
| 39 | + |
|
| 40 | + $crit = $struct->param; |
|
| 41 | + if ($crit and !is_array($crit[0])) { |
|
| 42 | + $type = strtolower($type) . array_shift($crit); |
|
| 43 | + } |
|
| 44 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | + |
|
| 46 | + $f = 'format_boucle_' . $fmt; |
|
| 47 | + |
|
| 48 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 52 | - $res = []; |
|
| 53 | - foreach ($struct->param ? $struct->param : [] as $couple) { |
|
| 54 | - array_shift($couple); |
|
| 55 | - foreach ($couple as $v) { |
|
| 56 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 62 | - |
|
| 63 | - return $f($file, $res, $prof); |
|
| 52 | + $res = []; |
|
| 53 | + foreach ($struct->param ? $struct->param : [] as $couple) { |
|
| 54 | + array_shift($couple); |
|
| 55 | + foreach ($couple as $v) { |
|
| 56 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | + $f = 'format_inclure_' . $fmt; |
|
| 62 | + |
|
| 63 | + return $f($file, $res, $prof); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 67 | + $f = 'format_texte_' . $fmt; |
|
| 68 | 68 | |
| 69 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 73 | + $f = 'format_polyglotte_' . $fmt; |
|
| 74 | 74 | |
| 75 | - return $f($struct->traductions, $prof); |
|
| 75 | + return $f($struct->traductions, $prof); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 79 | - $args = []; |
|
| 80 | - foreach ($struct->arg as $k => $v) { |
|
| 81 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | - } |
|
| 79 | + $args = []; |
|
| 80 | + foreach ($struct->arg as $k => $v) { |
|
| 81 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 85 | 85 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 86 | + $f = 'format_idiome_' . $fmt; |
|
| 87 | 87 | |
| 88 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 92 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | - $args = $filtres = ''; |
|
| 95 | - if ($p = $struct->param) { |
|
| 96 | - if ($p[0][0] === '') { |
|
| 97 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 98 | - } |
|
| 99 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | - } |
|
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 102 | - |
|
| 103 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 92 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | + $args = $filtres = ''; |
|
| 95 | + if ($p = $struct->param) { |
|
| 96 | + if ($p[0][0] === '') { |
|
| 97 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 98 | + } |
|
| 99 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | + } |
|
| 101 | + $f = 'format_champ_' . $fmt; |
|
| 102 | + |
|
| 103 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 107 | - if (!is_array($sources)) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 111 | - $res = ''; |
|
| 112 | - foreach ($sources as $arg) { |
|
| 113 | - if (!is_array($arg)) { |
|
| 114 | - continue; // ne devrait pas arriver. |
|
| 115 | - } else { |
|
| 116 | - $r = array_shift($arg); |
|
| 117 | - } |
|
| 118 | - $args = []; |
|
| 119 | - foreach ($arg as $v) { |
|
| 120 | - // cas des arguments entoures de ' ou " |
|
| 121 | - if ( |
|
| 122 | - (count($v) == 1) |
|
| 123 | - and $v[0]->type == 'texte' |
|
| 124 | - and (strlen($v[0]->apres) == 1) |
|
| 125 | - and $v[0]->apres == $v[0]->avant |
|
| 126 | - ) { |
|
| 127 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 128 | - } else { |
|
| 129 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - if (($r !== '') or $args) { |
|
| 133 | - $res .= $f($r, $args, $prof); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $res; |
|
| 107 | + if (!is_array($sources)) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + $f = 'format_liste_' . $fmt; |
|
| 111 | + $res = ''; |
|
| 112 | + foreach ($sources as $arg) { |
|
| 113 | + if (!is_array($arg)) { |
|
| 114 | + continue; // ne devrait pas arriver. |
|
| 115 | + } else { |
|
| 116 | + $r = array_shift($arg); |
|
| 117 | + } |
|
| 118 | + $args = []; |
|
| 119 | + foreach ($arg as $v) { |
|
| 120 | + // cas des arguments entoures de ' ou " |
|
| 121 | + if ( |
|
| 122 | + (count($v) == 1) |
|
| 123 | + and $v[0]->type == 'texte' |
|
| 124 | + and (strlen($v[0]->apres) == 1) |
|
| 125 | + and $v[0]->apres == $v[0]->avant |
|
| 126 | + ) { |
|
| 127 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 128 | + } else { |
|
| 129 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + if (($r !== '') or $args) { |
|
| 133 | + $res .= $f($r, $args, $prof); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $res; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Decompilation des criteres: on triche et on deroge: |
@@ -142,93 +142,93 @@ discard block |
||
| 142 | 142 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 143 | 143 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 144 | 144 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 145 | - $sources = $boucle->param; |
|
| 146 | - if (!is_array($sources)) { |
|
| 147 | - return ''; |
|
| 148 | - } |
|
| 149 | - $res = ''; |
|
| 150 | - $f = 'format_critere_' . $fmt; |
|
| 151 | - foreach ($sources as $crit) { |
|
| 152 | - if (!is_array($crit)) { |
|
| 153 | - continue; |
|
| 154 | - } // boucle recursive |
|
| 155 | - array_shift($crit); |
|
| 156 | - $args = []; |
|
| 157 | - foreach ($crit as $i => $v) { |
|
| 158 | - if ( |
|
| 159 | - (count($v) == 1) |
|
| 160 | - and $v[0]->type == 'texte' |
|
| 161 | - and $v[0]->apres |
|
| 162 | - ) { |
|
| 163 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 164 | - } else { |
|
| 165 | - $res2 = []; |
|
| 166 | - foreach ($v as $k => $p) { |
|
| 167 | - if ( |
|
| 168 | - isset($p->type) |
|
| 169 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 170 | - ) { |
|
| 171 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 172 | - $res2[] = [$p->type, $r]; |
|
| 173 | - } else { |
|
| 174 | - spip_log("critere $i / $k mal forme"); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - $args[] = $res2; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - $res .= $f($args); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $res; |
|
| 145 | + $sources = $boucle->param; |
|
| 146 | + if (!is_array($sources)) { |
|
| 147 | + return ''; |
|
| 148 | + } |
|
| 149 | + $res = ''; |
|
| 150 | + $f = 'format_critere_' . $fmt; |
|
| 151 | + foreach ($sources as $crit) { |
|
| 152 | + if (!is_array($crit)) { |
|
| 153 | + continue; |
|
| 154 | + } // boucle recursive |
|
| 155 | + array_shift($crit); |
|
| 156 | + $args = []; |
|
| 157 | + foreach ($crit as $i => $v) { |
|
| 158 | + if ( |
|
| 159 | + (count($v) == 1) |
|
| 160 | + and $v[0]->type == 'texte' |
|
| 161 | + and $v[0]->apres |
|
| 162 | + ) { |
|
| 163 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 164 | + } else { |
|
| 165 | + $res2 = []; |
|
| 166 | + foreach ($v as $k => $p) { |
|
| 167 | + if ( |
|
| 168 | + isset($p->type) |
|
| 169 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 170 | + ) { |
|
| 171 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 172 | + $res2[] = [$p->type, $r]; |
|
| 173 | + } else { |
|
| 174 | + spip_log("critere $i / $k mal forme"); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + $args[] = $res2; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + $res .= $f($args); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $res; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | 187 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 188 | - if (!is_array($liste)) { |
|
| 189 | - return ''; |
|
| 190 | - } |
|
| 191 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 192 | - $contenu = []; |
|
| 193 | - foreach ($liste as $k => $p) { |
|
| 194 | - if (!isset($p->type)) { |
|
| 195 | - continue; |
|
| 196 | - } #?????? |
|
| 197 | - $d = 'decompiler_' . $p->type; |
|
| 198 | - $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 199 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 200 | - // contenait des args et s'il est suivi d'espaces, |
|
| 201 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 202 | - |
|
| 203 | - if ( |
|
| 204 | - $next |
|
| 205 | - and ($next->type == 'texte') |
|
| 206 | - and $p->type == 'champ' |
|
| 207 | - and !$p->apres |
|
| 208 | - and !$p->avant |
|
| 209 | - and $p->fonctions |
|
| 210 | - ) { |
|
| 211 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 212 | - if ($n) { |
|
| 213 | - $champ = new Texte(); |
|
| 214 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 215 | - $champ->ligne = $p->ligne; |
|
| 216 | - $p->apres = [$champ]; |
|
| 217 | - $next->texte = substr($next->texte, $n); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 221 | - } |
|
| 222 | - $f = 'format_suite_' . $fmt; |
|
| 223 | - |
|
| 224 | - return $f($contenu); |
|
| 188 | + if (!is_array($liste)) { |
|
| 189 | + return ''; |
|
| 190 | + } |
|
| 191 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 192 | + $contenu = []; |
|
| 193 | + foreach ($liste as $k => $p) { |
|
| 194 | + if (!isset($p->type)) { |
|
| 195 | + continue; |
|
| 196 | + } #?????? |
|
| 197 | + $d = 'decompiler_' . $p->type; |
|
| 198 | + $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 199 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 200 | + // contenait des args et s'il est suivi d'espaces, |
|
| 201 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 202 | + |
|
| 203 | + if ( |
|
| 204 | + $next |
|
| 205 | + and ($next->type == 'texte') |
|
| 206 | + and $p->type == 'champ' |
|
| 207 | + and !$p->apres |
|
| 208 | + and !$p->avant |
|
| 209 | + and $p->fonctions |
|
| 210 | + ) { |
|
| 211 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 212 | + if ($n) { |
|
| 213 | + $champ = new Texte(); |
|
| 214 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 215 | + $champ->ligne = $p->ligne; |
|
| 216 | + $p->apres = [$champ]; |
|
| 217 | + $next->texte = substr($next->texte, $n); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 221 | + } |
|
| 222 | + $f = 'format_suite_' . $fmt; |
|
| 223 | + |
|
| 224 | + return $f($contenu); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 228 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 229 | - return "'$fmt'?"; |
|
| 230 | - } |
|
| 231 | - $f = 'decompiler_' . $quoi; |
|
| 228 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 229 | + return "'$fmt'?"; |
|
| 230 | + } |
|
| 231 | + $f = 'decompiler_' . $quoi; |
|
| 232 | 232 | |
| 233 | - return $f($liste, $fmt, $prof); |
|
| 233 | + return $f($liste, $fmt, $prof); |
|
| 234 | 234 | } |
@@ -11,190 +11,190 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // https://code.spip.net/@trace_query_start |
| 18 | 18 | function trace_query_start() { |
| 19 | - static $trace = '?'; |
|
| 20 | - if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 21 | - if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 22 | - $trace = true; |
|
| 23 | - } |
|
| 24 | - else { |
|
| 25 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 26 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 27 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 28 | - // ou une requete SQL faite avant chargement de la session |
|
| 29 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 30 | - } |
|
| 31 | - else { |
|
| 32 | - include_spip('inc/autoriser'); |
|
| 33 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 34 | - // A fortiori quand on demande une trace |
|
| 35 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 36 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return $trace ? microtime() : 0; |
|
| 19 | + static $trace = '?'; |
|
| 20 | + if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 21 | + if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 22 | + $trace = true; |
|
| 23 | + } |
|
| 24 | + else { |
|
| 25 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 26 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 27 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 28 | + // ou une requete SQL faite avant chargement de la session |
|
| 29 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 30 | + } |
|
| 31 | + else { |
|
| 32 | + include_spip('inc/autoriser'); |
|
| 33 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 34 | + // A fortiori quand on demande une trace |
|
| 35 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 36 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return $trace ? microtime() : 0; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // https://code.spip.net/@trace_query_end |
| 45 | 45 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 46 | - static $trace = '?'; |
|
| 47 | - if ($trace === '?') { |
|
| 48 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 49 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 50 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 51 | - // ou une requete SQL faite avant chargement de la session |
|
| 52 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 53 | - } |
|
| 54 | - else { |
|
| 55 | - include_spip('inc/autoriser'); |
|
| 56 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 57 | - // A fortiori quand on demande une trace |
|
| 58 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 59 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - if ($start) { |
|
| 63 | - $end = microtime(); |
|
| 64 | - list($usec, $sec) = explode(' ', $start); |
|
| 65 | - list($usec2, $sec2) = explode(' ', $end); |
|
| 66 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 67 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 68 | - if ($trace) { |
|
| 69 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 73 | - if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 74 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $result; |
|
| 46 | + static $trace = '?'; |
|
| 47 | + if ($trace === '?') { |
|
| 48 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 49 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 50 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 51 | + // ou une requete SQL faite avant chargement de la session |
|
| 52 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 53 | + } |
|
| 54 | + else { |
|
| 55 | + include_spip('inc/autoriser'); |
|
| 56 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 57 | + // A fortiori quand on demande une trace |
|
| 58 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 59 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + if ($start) { |
|
| 63 | + $end = microtime(); |
|
| 64 | + list($usec, $sec) = explode(' ', $start); |
|
| 65 | + list($usec2, $sec2) = explode(' ', $end); |
|
| 66 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 67 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 68 | + if ($trace) { |
|
| 69 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 73 | + if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 74 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $result; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // https://code.spip.net/@trace_query_chrono |
| 81 | 81 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 82 | - include_spip('inc/filtres_mini'); |
|
| 83 | - static $tt = 0, $nb = 0; |
|
| 84 | - |
|
| 85 | - $x = _request('var_mode_objet'); |
|
| 86 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 87 | - list(, $boucle, $serveur, $contexte) = $GLOBALS['debug']['aucasou']; |
|
| 88 | - if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - if ($serveur) { |
|
| 92 | - $boucle .= " ($serveur)"; |
|
| 93 | - } |
|
| 94 | - $boucle = "<b>$boucle</b>"; |
|
| 95 | - } else { |
|
| 96 | - if ($x) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - $boucle = $contexte = ''; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $tt += $dt; |
|
| 103 | - $nb++; |
|
| 104 | - |
|
| 105 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 106 | - $e = sql_explain($query, $serveur); |
|
| 107 | - $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 108 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 82 | + include_spip('inc/filtres_mini'); |
|
| 83 | + static $tt = 0, $nb = 0; |
|
| 84 | + |
|
| 85 | + $x = _request('var_mode_objet'); |
|
| 86 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 87 | + list(, $boucle, $serveur, $contexte) = $GLOBALS['debug']['aucasou']; |
|
| 88 | + if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + if ($serveur) { |
|
| 92 | + $boucle .= " ($serveur)"; |
|
| 93 | + } |
|
| 94 | + $boucle = "<b>$boucle</b>"; |
|
| 95 | + } else { |
|
| 96 | + if ($x) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + $boucle = $contexte = ''; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $tt += $dt; |
|
| 103 | + $nb++; |
|
| 104 | + |
|
| 105 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 106 | + $e = sql_explain($query, $serveur); |
|
| 107 | + $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 108 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | function chrono_requete($temps) { |
| 113 | - $total = 0; |
|
| 114 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 115 | - $t = $q = $n = $d = []; |
|
| 116 | - // Totaliser les temps et completer le Explain |
|
| 117 | - foreach ($temps as $key => $v) { |
|
| 118 | - list($dt, $nb, $boucle, $query, $explain, $res, $contexte) = $v; |
|
| 119 | - if (is_array($contexte)) { |
|
| 120 | - $k = ($contexte[0] . " $boucle"); |
|
| 121 | - include_spip('public/compiler'); |
|
| 122 | - $env = reconstruire_contexte_compil($contexte); |
|
| 123 | - } else { |
|
| 124 | - $k = $env = $boucle; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $total += $dt; |
|
| 128 | - $t[$key] = $dt; |
|
| 129 | - $q[$key] = $nb; |
|
| 130 | - if (!isset($d[$k])) { |
|
| 131 | - $d[$k] = 0; |
|
| 132 | - $n[$k] = 0; |
|
| 133 | - } |
|
| 134 | - $d[$k] += $dt; |
|
| 135 | - ++$n[$k]; |
|
| 136 | - |
|
| 137 | - if (!is_array($explain)) { |
|
| 138 | - $explain = []; |
|
| 139 | - } |
|
| 140 | - foreach ($explain as $j => $v) { |
|
| 141 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 142 | - . str_replace(';', '<br />', $v) |
|
| 143 | - . '</td></tr>'; |
|
| 144 | - } |
|
| 145 | - $e = "<table class='explain'>" |
|
| 146 | - . '<caption>' |
|
| 147 | - . $query |
|
| 148 | - . '</caption>' |
|
| 149 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 150 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 151 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 152 | - . join('', $explain) |
|
| 153 | - . '</table>'; |
|
| 154 | - |
|
| 155 | - $temps[$key] = [$e, $env, $k]; |
|
| 156 | - } |
|
| 157 | - // Trier par temps d'execution decroissant |
|
| 158 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 159 | - arsort($d); |
|
| 160 | - $i = 1; |
|
| 161 | - $t = []; |
|
| 162 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 163 | - foreach ($temps as $k => $v) { |
|
| 164 | - $titre = strip_tags($v[2]); |
|
| 165 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 166 | - $href = str_replace("\\'", ''', $href); |
|
| 167 | - |
|
| 168 | - if (!isset($t[$v[2]])) { |
|
| 169 | - $t[$v[2]] = []; |
|
| 170 | - } |
|
| 171 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 172 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 173 | - . '</span>' |
|
| 174 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 175 | - $i++; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($d['']) { |
|
| 179 | - $d[$hors] = $d['']; |
|
| 180 | - $n[$hors] = $n['']; |
|
| 181 | - $t[$hors] = $t['']; |
|
| 182 | - } |
|
| 183 | - unset($d['']); |
|
| 184 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 185 | - foreach ($d as $k => $v) { |
|
| 186 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 187 | - . join('', $t[$k]); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $navigation = [ |
|
| 191 | - _T('zbug_statistiques'), |
|
| 192 | - '<tr><td>' |
|
| 193 | - . join("</td></tr>\n<tr><td>", $d) |
|
| 194 | - . "</td></tr>\n" |
|
| 195 | - . (# _request('var_mode_objet') ? '' : |
|
| 196 | - ('<tr><td>' . count($temps) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 197 | - ]; |
|
| 198 | - |
|
| 199 | - return [$temps, $navigation]; |
|
| 113 | + $total = 0; |
|
| 114 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 115 | + $t = $q = $n = $d = []; |
|
| 116 | + // Totaliser les temps et completer le Explain |
|
| 117 | + foreach ($temps as $key => $v) { |
|
| 118 | + list($dt, $nb, $boucle, $query, $explain, $res, $contexte) = $v; |
|
| 119 | + if (is_array($contexte)) { |
|
| 120 | + $k = ($contexte[0] . " $boucle"); |
|
| 121 | + include_spip('public/compiler'); |
|
| 122 | + $env = reconstruire_contexte_compil($contexte); |
|
| 123 | + } else { |
|
| 124 | + $k = $env = $boucle; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $total += $dt; |
|
| 128 | + $t[$key] = $dt; |
|
| 129 | + $q[$key] = $nb; |
|
| 130 | + if (!isset($d[$k])) { |
|
| 131 | + $d[$k] = 0; |
|
| 132 | + $n[$k] = 0; |
|
| 133 | + } |
|
| 134 | + $d[$k] += $dt; |
|
| 135 | + ++$n[$k]; |
|
| 136 | + |
|
| 137 | + if (!is_array($explain)) { |
|
| 138 | + $explain = []; |
|
| 139 | + } |
|
| 140 | + foreach ($explain as $j => $v) { |
|
| 141 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 142 | + . str_replace(';', '<br />', $v) |
|
| 143 | + . '</td></tr>'; |
|
| 144 | + } |
|
| 145 | + $e = "<table class='explain'>" |
|
| 146 | + . '<caption>' |
|
| 147 | + . $query |
|
| 148 | + . '</caption>' |
|
| 149 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 150 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 151 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 152 | + . join('', $explain) |
|
| 153 | + . '</table>'; |
|
| 154 | + |
|
| 155 | + $temps[$key] = [$e, $env, $k]; |
|
| 156 | + } |
|
| 157 | + // Trier par temps d'execution decroissant |
|
| 158 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 159 | + arsort($d); |
|
| 160 | + $i = 1; |
|
| 161 | + $t = []; |
|
| 162 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 163 | + foreach ($temps as $k => $v) { |
|
| 164 | + $titre = strip_tags($v[2]); |
|
| 165 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 166 | + $href = str_replace("\\'", ''', $href); |
|
| 167 | + |
|
| 168 | + if (!isset($t[$v[2]])) { |
|
| 169 | + $t[$v[2]] = []; |
|
| 170 | + } |
|
| 171 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 172 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 173 | + . '</span>' |
|
| 174 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 175 | + $i++; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($d['']) { |
|
| 179 | + $d[$hors] = $d['']; |
|
| 180 | + $n[$hors] = $n['']; |
|
| 181 | + $t[$hors] = $t['']; |
|
| 182 | + } |
|
| 183 | + unset($d['']); |
|
| 184 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 185 | + foreach ($d as $k => $v) { |
|
| 186 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 187 | + . join('', $t[$k]); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $navigation = [ |
|
| 191 | + _T('zbug_statistiques'), |
|
| 192 | + '<tr><td>' |
|
| 193 | + . join("</td></tr>\n<tr><td>", $d) |
|
| 194 | + . "</td></tr>\n" |
|
| 195 | + . (# _request('var_mode_objet') ? '' : |
|
| 196 | + ('<tr><td>' . count($temps) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 197 | + ]; |
|
| 198 | + |
|
| 199 | + return [$temps, $navigation]; |
|
| 200 | 200 | } |