@@ -11,77 +11,77 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 20 | - include_spip('inc/texte'); |
|
| 21 | - $titre = $descriptif = ''; |
|
| 22 | - if ($type === 'rubrique') { |
|
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | - if ($row) { |
|
| 25 | - $titre = typo($row['titre']); |
|
| 26 | - $descriptif = propre($row['descriptif']); |
|
| 27 | - } else { |
|
| 28 | - $titre = _T('info_racine_site'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 20 | + include_spip('inc/texte'); |
|
| 21 | + $titre = $descriptif = ''; |
|
| 22 | + if ($type === 'rubrique') { |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + if ($row) { |
|
| 25 | + $titre = typo($row['titre']); |
|
| 26 | + $descriptif = propre($row['descriptif']); |
|
| 27 | + } else { |
|
| 28 | + $titre = _T('info_racine_site'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $res = ''; |
|
| 33 | - if ( |
|
| 34 | - $type === 'rubrique' |
|
| 35 | - and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | - and isset($GLOBALS['meta']['image_process']) |
|
| 37 | - ) { |
|
| 38 | - if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | - [$fid, $dir, $nom, $format] = $res; |
|
| 42 | - include_spip('inc/filtres_images_mini'); |
|
| 43 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | - if ($res) { |
|
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 32 | + $res = ''; |
|
| 33 | + if ( |
|
| 34 | + $type === 'rubrique' |
|
| 35 | + and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | + and isset($GLOBALS['meta']['image_process']) |
|
| 37 | + ) { |
|
| 38 | + if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | + [$fid, $dir, $nom, $format] = $res; |
|
| 42 | + include_spip('inc/filtres_images_mini'); |
|
| 43 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | + if ($res) { |
|
| 45 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | - $id = intval($id); |
|
| 51 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | + $id = intval($id); |
|
| 54 | 54 | |
| 55 | 55 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 56 | 56 | # et l'affichage de son titre dans le bandeau |
| 57 | - $titre = strtr( |
|
| 58 | - str_replace( |
|
| 59 | - "'", |
|
| 60 | - '’', |
|
| 61 | - str_replace('"', '"', textebrut($titre)) |
|
| 62 | - ), |
|
| 63 | - "\n\r", |
|
| 64 | - ' ' |
|
| 65 | - ); |
|
| 57 | + $titre = strtr( |
|
| 58 | + str_replace( |
|
| 59 | + "'", |
|
| 60 | + '’', |
|
| 61 | + str_replace('"', '"', textebrut($titre)) |
|
| 62 | + ), |
|
| 63 | + "\n\r", |
|
| 64 | + ' ' |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do . '_selection_titre'; |
|
| 68 | 68 | |
| 69 | - return "<div style='display: none;'>" |
|
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | - . entites_html($titre) |
|
| 73 | - . '" />' |
|
| 74 | - . '</div>' |
|
| 75 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | - . '<div class="informer__item">' |
|
| 77 | - . (!$res ? '' : $res) |
|
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | - . '</div>' |
|
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | - . _T('bouton_choisir') |
|
| 84 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | - . '</div>' |
|
| 86 | - . '</div>'; |
|
| 69 | + return "<div style='display: none;'>" |
|
| 70 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | + . entites_html($titre) |
|
| 73 | + . '" />' |
|
| 74 | + . '</div>' |
|
| 75 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | + . '<div class="informer__item">' |
|
| 77 | + . (!$res ? '' : $res) |
|
| 78 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | + . '</div>' |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | + . _T('bouton_choisir') |
|
| 84 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | + . '</div>' |
|
| 86 | + . '</div>'; |
|
| 87 | 87 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | include_spip('inc/texte'); |
| 21 | 21 | $titre = $descriptif = ''; |
| 22 | 22 | if ($type === 'rubrique') { |
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id)); |
|
| 24 | 24 | if ($row) { |
| 25 | 25 | $titre = typo($row['titre']); |
| 26 | 26 | $descriptif = propre($row['descriptif']); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | include_spip('inc/filtres_images_mini'); |
| 43 | 43 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 44 | 44 | if ($res) { |
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | ' ' |
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do.'_selection_titre'; |
|
| 68 | 68 | |
| 69 | 69 | return "<div style='display: none;'>" |
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 72 | 72 | . entites_html($titre) |
| 73 | 73 | . '" />' |
| 74 | 74 | . '</div>' |
| 75 | 75 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 76 | 76 | . '<div class="informer__item">' |
| 77 | 77 | . (!$res ? '' : $res) |
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 78 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>') |
|
| 80 | 80 | . '</div>' |
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 82 | 82 | . "<input type='submit' class='fondo btn submit' value='" |
| 83 | 83 | . _T('bouton_choisir') |
| 84 | 84 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,23 +157,23 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $display_modes = [ |
|
| 161 | - 0 => 'icones_img_texte' // défaut. |
|
| 162 | - /*init*/, |
|
| 163 | - 1 => 'icones_texte', |
|
| 164 | - 2 => 'icones_img_texte', |
|
| 165 | - 3 => 'icones_img' |
|
| 166 | - ]; |
|
| 160 | + $display_modes = [ |
|
| 161 | + 0 => 'icones_img_texte' // défaut. |
|
| 162 | + /*init*/, |
|
| 163 | + 1 => 'icones_texte', |
|
| 164 | + 2 => 'icones_img_texte', |
|
| 165 | + 3 => 'icones_img' |
|
| 166 | + ]; |
|
| 167 | 167 | |
| 168 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 169 | 169 | |
| 170 | - $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 170 | + $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 172 | 172 | |
| 173 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 173 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 174 | 174 | |
| 175 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | - return spip_sanitize_classname($classes); |
|
| 175 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | + return spip_sanitize_classname($classes); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -184,5 +184,5 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | function auteurs_recemment_connectes($id_auteur) { |
| 187 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 188 | 188 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -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 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return [$id, _L('echec enregistrement en base')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return [$id, $err]; |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return [$id, _L('echec enregistrement en base')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return [$id, $err]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,85 +75,85 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if ( |
|
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 85 | - ) { |
|
| 86 | - return $modifier($id, $set); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $table_sql = table_objet_sql($objet); |
|
| 90 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | - $desc = $trouver_table($table_sql); |
|
| 92 | - if (!$desc or !isset($desc['field'])) { |
|
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | - |
|
| 95 | - return _L("Erreur objet $objet inconnu"); |
|
| 96 | - } |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - |
|
| 99 | - $champ_date = ''; |
|
| 100 | - if (isset($desc['date']) and $desc['date']) { |
|
| 101 | - $champ_date = $desc['date']; |
|
| 102 | - } elseif (isset($desc['field']['date'])) { |
|
| 103 | - $champ_date = 'date'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $include_list = array_keys($desc['field']); |
|
| 107 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $include_list = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // include list |
|
| 116 | - $include_list, |
|
| 117 | - // exclude list |
|
| 118 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | - // donnees eventuellement fournies |
|
| 120 | - $set |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | - if (objet_test_si_publie($objet, $id)) { |
|
| 125 | - $invalideur = "id='$objet/$id'"; |
|
| 126 | - $indexation = true; |
|
| 127 | - } else { |
|
| 128 | - $invalideur = ''; |
|
| 129 | - $indexation = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( |
|
| 133 | - $err = objet_modifier_champs( |
|
| 134 | - $objet, |
|
| 135 | - $id, |
|
| 136 | - [ |
|
| 137 | - 'data' => $set, |
|
| 138 | - 'nonvide' => '', |
|
| 139 | - 'invalideur' => $invalideur, |
|
| 140 | - 'indexation' => $indexation, |
|
| 141 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | - ], |
|
| 144 | - $c |
|
| 145 | - ) |
|
| 146 | - ) { |
|
| 147 | - return $err; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Modification de statut, changement de rubrique ? |
|
| 151 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | - $err = objet_instituer($objet, $id, $c); |
|
| 155 | - |
|
| 156 | - return $err; |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if ( |
|
| 83 | + include_spip('action/editer_' . $objet) |
|
| 84 | + and function_exists($modifier = $objet . '_modifier') |
|
| 85 | + ) { |
|
| 86 | + return $modifier($id, $set); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $table_sql = table_objet_sql($objet); |
|
| 90 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | + $desc = $trouver_table($table_sql); |
|
| 92 | + if (!$desc or !isset($desc['field'])) { |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | + |
|
| 95 | + return _L("Erreur objet $objet inconnu"); |
|
| 96 | + } |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + |
|
| 99 | + $champ_date = ''; |
|
| 100 | + if (isset($desc['date']) and $desc['date']) { |
|
| 101 | + $champ_date = $desc['date']; |
|
| 102 | + } elseif (isset($desc['field']['date'])) { |
|
| 103 | + $champ_date = 'date'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $include_list = array_keys($desc['field']); |
|
| 107 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $include_list = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // include list |
|
| 116 | + $include_list, |
|
| 117 | + // exclude list |
|
| 118 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | + // donnees eventuellement fournies |
|
| 120 | + $set |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | + if (objet_test_si_publie($objet, $id)) { |
|
| 125 | + $invalideur = "id='$objet/$id'"; |
|
| 126 | + $indexation = true; |
|
| 127 | + } else { |
|
| 128 | + $invalideur = ''; |
|
| 129 | + $indexation = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( |
|
| 133 | + $err = objet_modifier_champs( |
|
| 134 | + $objet, |
|
| 135 | + $id, |
|
| 136 | + [ |
|
| 137 | + 'data' => $set, |
|
| 138 | + 'nonvide' => '', |
|
| 139 | + 'invalideur' => $invalideur, |
|
| 140 | + 'indexation' => $indexation, |
|
| 141 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | + ], |
|
| 144 | + $c |
|
| 145 | + ) |
|
| 146 | + ) { |
|
| 147 | + return $err; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Modification de statut, changement de rubrique ? |
|
| 151 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | + $err = objet_instituer($objet, $id, $c); |
|
| 155 | + |
|
| 156 | + return $err; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,135 +168,135 @@ discard block |
||
| 168 | 168 | * @return bool|int |
| 169 | 169 | */ |
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | - $d = null; |
|
| 172 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | - $objet = $t; |
|
| 175 | - } |
|
| 176 | - if ( |
|
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 179 | - ) { |
|
| 180 | - return $inserer($id_parent, $set); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $table_sql = table_objet_sql($objet); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $desc = $trouver_table($table_sql); |
|
| 186 | - if (!$desc or !isset($desc['field'])) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $lang_rub = ''; |
|
| 191 | - $champs = []; |
|
| 192 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | - // dans la premiere rubrique racine |
|
| 195 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | - $id_rubrique = $row['id_rubrique']; |
|
| 198 | - } else { |
|
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | - if (isset($desc['field']['id_secteur'])) { |
|
| 204 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | - } |
|
| 206 | - $lang_rub = $row['lang']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | - // ou a defaut celle de la rubrique |
|
| 212 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | - if ( |
|
| 214 | - isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | - $table_sql, |
|
| 216 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | - if ( |
|
| 221 | - in_array( |
|
| 222 | - $GLOBALS['spip_lang'], |
|
| 223 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | - ) |
|
| 225 | - ) { |
|
| 226 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | - $champs['langue_choisie'] = 'oui'; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | - $champs['langue_choisie'] = 'non'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (isset($desc['field']['statut'])) { |
|
| 237 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | - $champs['statut'] = reset($cles_statut); |
|
| 240 | - } else { |
|
| 241 | - $champs['statut'] = 'prepa'; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($set) { |
|
| 251 | - $champs = array_merge($champs, $set); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Envoyer aux plugins |
|
| 255 | - $champs = pipeline( |
|
| 256 | - 'pre_insertion', |
|
| 257 | - [ |
|
| 258 | - 'args' => [ |
|
| 259 | - 'table' => $table_sql, |
|
| 260 | - 'id_parent' => $id_parent, |
|
| 261 | - ], |
|
| 262 | - 'data' => $champs |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - $id = sql_insertq($table_sql, $champs); |
|
| 267 | - |
|
| 268 | - if ($id) { |
|
| 269 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | - // et associer l'auteur sinon |
|
| 271 | - // si la table n'a pas deja un champ id_auteur |
|
| 272 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | - if ( |
|
| 274 | - $id > 0 |
|
| 275 | - and !isset($desc['field']['id_auteur']) |
|
| 276 | - ) { |
|
| 277 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | - : _request('id_auteur')); |
|
| 280 | - if ($id_auteur) { |
|
| 281 | - include_spip('action/editer_auteur'); |
|
| 282 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - pipeline( |
|
| 287 | - 'post_insertion', |
|
| 288 | - [ |
|
| 289 | - 'args' => [ |
|
| 290 | - 'table' => $table_sql, |
|
| 291 | - 'id_parent' => $id_parent, |
|
| 292 | - 'id_objet' => $id, |
|
| 293 | - ], |
|
| 294 | - 'data' => $champs |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $id; |
|
| 171 | + $d = null; |
|
| 172 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | + $objet = $t; |
|
| 175 | + } |
|
| 176 | + if ( |
|
| 177 | + include_spip('action/editer_' . $objet) |
|
| 178 | + and function_exists($inserer = $objet . '_inserer') |
|
| 179 | + ) { |
|
| 180 | + return $inserer($id_parent, $set); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $table_sql = table_objet_sql($objet); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $desc = $trouver_table($table_sql); |
|
| 186 | + if (!$desc or !isset($desc['field'])) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $lang_rub = ''; |
|
| 191 | + $champs = []; |
|
| 192 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | + // dans la premiere rubrique racine |
|
| 195 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | + $id_rubrique = $row['id_rubrique']; |
|
| 198 | + } else { |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | + if (isset($desc['field']['id_secteur'])) { |
|
| 204 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | + } |
|
| 206 | + $lang_rub = $row['lang']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | + // ou a defaut celle de la rubrique |
|
| 212 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | + if ( |
|
| 214 | + isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | + $table_sql, |
|
| 216 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | + if ( |
|
| 221 | + in_array( |
|
| 222 | + $GLOBALS['spip_lang'], |
|
| 223 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | + ) |
|
| 225 | + ) { |
|
| 226 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | + $champs['langue_choisie'] = 'oui'; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | + $champs['langue_choisie'] = 'non'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (isset($desc['field']['statut'])) { |
|
| 237 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | + $champs['statut'] = reset($cles_statut); |
|
| 240 | + } else { |
|
| 241 | + $champs['statut'] = 'prepa'; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($set) { |
|
| 251 | + $champs = array_merge($champs, $set); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // Envoyer aux plugins |
|
| 255 | + $champs = pipeline( |
|
| 256 | + 'pre_insertion', |
|
| 257 | + [ |
|
| 258 | + 'args' => [ |
|
| 259 | + 'table' => $table_sql, |
|
| 260 | + 'id_parent' => $id_parent, |
|
| 261 | + ], |
|
| 262 | + 'data' => $champs |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + $id = sql_insertq($table_sql, $champs); |
|
| 267 | + |
|
| 268 | + if ($id) { |
|
| 269 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | + // et associer l'auteur sinon |
|
| 271 | + // si la table n'a pas deja un champ id_auteur |
|
| 272 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | + if ( |
|
| 274 | + $id > 0 |
|
| 275 | + and !isset($desc['field']['id_auteur']) |
|
| 276 | + ) { |
|
| 277 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | + : _request('id_auteur')); |
|
| 280 | + if ($id_auteur) { |
|
| 281 | + include_spip('action/editer_auteur'); |
|
| 282 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + pipeline( |
|
| 287 | + 'post_insertion', |
|
| 288 | + [ |
|
| 289 | + 'args' => [ |
|
| 290 | + 'table' => $table_sql, |
|
| 291 | + 'id_parent' => $id_parent, |
|
| 292 | + 'id_objet' => $id, |
|
| 293 | + ], |
|
| 294 | + 'data' => $champs |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $id; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -313,138 +313,138 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | - $objet = $t; |
|
| 319 | - } |
|
| 320 | - if ( |
|
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 323 | - ) { |
|
| 324 | - return $instituer($id, $c, $calcul_rub); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $table_sql = table_objet_sql($objet); |
|
| 328 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | - $desc = $trouver_table($table_sql); |
|
| 330 | - if (!$desc or !isset($desc['field'])) { |
|
| 331 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - include_spip('inc/autoriser'); |
|
| 335 | - include_spip('inc/rubriques'); |
|
| 336 | - include_spip('inc/modifier'); |
|
| 337 | - |
|
| 338 | - $sel = []; |
|
| 339 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | - |
|
| 341 | - $champ_date = ''; |
|
| 342 | - if (isset($desc['date']) and $desc['date']) { |
|
| 343 | - $champ_date = $desc['date']; |
|
| 344 | - } elseif (isset($desc['field']['date'])) { |
|
| 345 | - $champ_date = 'date'; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | - |
|
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | - |
|
| 353 | - $id_rubrique = $row['id_rubrique']; |
|
| 354 | - $statut_ancien = $statut = $row['statut']; |
|
| 355 | - $date_ancienne = $date = $row['date']; |
|
| 356 | - $champs = []; |
|
| 357 | - |
|
| 358 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | - |
|
| 361 | - // cf autorisations dans inc/instituer_objet |
|
| 362 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | - if ( |
|
| 364 | - $id_rubrique ? |
|
| 365 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | - : |
|
| 367 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | - ) { |
|
| 369 | - $statut = $champs['statut'] = $s; |
|
| 370 | - } else { |
|
| 371 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | - $statut = $champs['statut'] = $s; |
|
| 373 | - } else { |
|
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // En cas de publication, fixer la date a "maintenant" |
|
| 379 | - // sauf si $c commande autre chose |
|
| 380 | - // ou si l'objet est deja date dans le futur |
|
| 381 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | - if ($champ_date) { |
|
| 383 | - if ( |
|
| 384 | - $champs['statut'] == 'publie' |
|
| 385 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | - or $d |
|
| 387 | - ) { |
|
| 388 | - if ($d or strtotime($d = $date) > time()) { |
|
| 389 | - $champs[$champ_date] = $date = $d; |
|
| 390 | - } else { |
|
| 391 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Verifier que la rubrique demandee existe et est differente |
|
| 398 | - // de la rubrique actuelle |
|
| 399 | - if ( |
|
| 400 | - $id_rubrique |
|
| 401 | - and isset($c['id_parent']) |
|
| 402 | - and $id_parent = $c['id_parent'] |
|
| 403 | - and $id_parent != $id_rubrique |
|
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | - ) { |
|
| 406 | - $champs['id_rubrique'] = $id_parent; |
|
| 407 | - |
|
| 408 | - // si l'objet etait publie |
|
| 409 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | - // repasser l'objet en statut 'propose'. |
|
| 411 | - if ( |
|
| 412 | - $statut == 'publie' |
|
| 413 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | - ) { |
|
| 415 | - $champs['statut'] = 'prop'; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - // Envoyer aux plugins |
|
| 421 | - $champs = pipeline( |
|
| 422 | - 'pre_edition', |
|
| 423 | - [ |
|
| 424 | - 'args' => [ |
|
| 425 | - 'table' => $table_sql, |
|
| 426 | - 'id_objet' => $id, |
|
| 427 | - 'action' => 'instituer', |
|
| 428 | - 'statut_ancien' => $statut_ancien, |
|
| 429 | - 'date_ancienne' => $date_ancienne, |
|
| 430 | - 'id_parent_ancien' => $id_rubrique, |
|
| 431 | - ], |
|
| 432 | - 'data' => $champs |
|
| 433 | - ] |
|
| 434 | - ); |
|
| 435 | - |
|
| 436 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | - return ''; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // Envoyer les modifs. |
|
| 441 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | - |
|
| 443 | - // Invalider les caches |
|
| 444 | - include_spip('inc/invalideur'); |
|
| 445 | - suivre_invalideur("id='$objet/$id'"); |
|
| 446 | - |
|
| 447 | - /* |
|
| 316 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | + $objet = $t; |
|
| 319 | + } |
|
| 320 | + if ( |
|
| 321 | + include_spip('action/editer_' . $objet) |
|
| 322 | + and function_exists($instituer = $objet . '_instituer') |
|
| 323 | + ) { |
|
| 324 | + return $instituer($id, $c, $calcul_rub); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $table_sql = table_objet_sql($objet); |
|
| 328 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | + $desc = $trouver_table($table_sql); |
|
| 330 | + if (!$desc or !isset($desc['field'])) { |
|
| 331 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + include_spip('inc/autoriser'); |
|
| 335 | + include_spip('inc/rubriques'); |
|
| 336 | + include_spip('inc/modifier'); |
|
| 337 | + |
|
| 338 | + $sel = []; |
|
| 339 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | + |
|
| 341 | + $champ_date = ''; |
|
| 342 | + if (isset($desc['date']) and $desc['date']) { |
|
| 343 | + $champ_date = $desc['date']; |
|
| 344 | + } elseif (isset($desc['field']['date'])) { |
|
| 345 | + $champ_date = 'date'; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | + |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | + |
|
| 353 | + $id_rubrique = $row['id_rubrique']; |
|
| 354 | + $statut_ancien = $statut = $row['statut']; |
|
| 355 | + $date_ancienne = $date = $row['date']; |
|
| 356 | + $champs = []; |
|
| 357 | + |
|
| 358 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | + |
|
| 361 | + // cf autorisations dans inc/instituer_objet |
|
| 362 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | + if ( |
|
| 364 | + $id_rubrique ? |
|
| 365 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | + : |
|
| 367 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | + ) { |
|
| 369 | + $statut = $champs['statut'] = $s; |
|
| 370 | + } else { |
|
| 371 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | + $statut = $champs['statut'] = $s; |
|
| 373 | + } else { |
|
| 374 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // En cas de publication, fixer la date a "maintenant" |
|
| 379 | + // sauf si $c commande autre chose |
|
| 380 | + // ou si l'objet est deja date dans le futur |
|
| 381 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | + if ($champ_date) { |
|
| 383 | + if ( |
|
| 384 | + $champs['statut'] == 'publie' |
|
| 385 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | + or $d |
|
| 387 | + ) { |
|
| 388 | + if ($d or strtotime($d = $date) > time()) { |
|
| 389 | + $champs[$champ_date] = $date = $d; |
|
| 390 | + } else { |
|
| 391 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Verifier que la rubrique demandee existe et est differente |
|
| 398 | + // de la rubrique actuelle |
|
| 399 | + if ( |
|
| 400 | + $id_rubrique |
|
| 401 | + and isset($c['id_parent']) |
|
| 402 | + and $id_parent = $c['id_parent'] |
|
| 403 | + and $id_parent != $id_rubrique |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | + ) { |
|
| 406 | + $champs['id_rubrique'] = $id_parent; |
|
| 407 | + |
|
| 408 | + // si l'objet etait publie |
|
| 409 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | + // repasser l'objet en statut 'propose'. |
|
| 411 | + if ( |
|
| 412 | + $statut == 'publie' |
|
| 413 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | + ) { |
|
| 415 | + $champs['statut'] = 'prop'; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + // Envoyer aux plugins |
|
| 421 | + $champs = pipeline( |
|
| 422 | + 'pre_edition', |
|
| 423 | + [ |
|
| 424 | + 'args' => [ |
|
| 425 | + 'table' => $table_sql, |
|
| 426 | + 'id_objet' => $id, |
|
| 427 | + 'action' => 'instituer', |
|
| 428 | + 'statut_ancien' => $statut_ancien, |
|
| 429 | + 'date_ancienne' => $date_ancienne, |
|
| 430 | + 'id_parent_ancien' => $id_rubrique, |
|
| 431 | + ], |
|
| 432 | + 'data' => $champs |
|
| 433 | + ] |
|
| 434 | + ); |
|
| 435 | + |
|
| 436 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | + return ''; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // Envoyer les modifs. |
|
| 441 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | + |
|
| 443 | + // Invalider les caches |
|
| 444 | + include_spip('inc/invalideur'); |
|
| 445 | + suivre_invalideur("id='$objet/$id'"); |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | if ($date) { |
| 449 | 449 | $t = strtotime($date); |
| 450 | 450 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -453,32 +453,32 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | }*/ |
| 455 | 455 | |
| 456 | - // Pipeline |
|
| 457 | - pipeline( |
|
| 458 | - 'post_edition', |
|
| 459 | - [ |
|
| 460 | - 'args' => [ |
|
| 461 | - 'table' => $table_sql, |
|
| 462 | - 'id_objet' => $id, |
|
| 463 | - 'action' => 'instituer', |
|
| 464 | - 'statut_ancien' => $statut_ancien, |
|
| 465 | - 'date_ancienne' => $date_ancienne, |
|
| 466 | - 'id_parent_ancien' => $id_rubrique, |
|
| 467 | - ], |
|
| 468 | - 'data' => $champs |
|
| 469 | - ] |
|
| 470 | - ); |
|
| 471 | - |
|
| 472 | - // Notifications |
|
| 473 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | - $notifications( |
|
| 475 | - "instituer$objet", |
|
| 476 | - $id, |
|
| 477 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return ''; // pas d'erreur |
|
| 456 | + // Pipeline |
|
| 457 | + pipeline( |
|
| 458 | + 'post_edition', |
|
| 459 | + [ |
|
| 460 | + 'args' => [ |
|
| 461 | + 'table' => $table_sql, |
|
| 462 | + 'id_objet' => $id, |
|
| 463 | + 'action' => 'instituer', |
|
| 464 | + 'statut_ancien' => $statut_ancien, |
|
| 465 | + 'date_ancienne' => $date_ancienne, |
|
| 466 | + 'id_parent_ancien' => $id_rubrique, |
|
| 467 | + ], |
|
| 468 | + 'data' => $champs |
|
| 469 | + ] |
|
| 470 | + ); |
|
| 471 | + |
|
| 472 | + // Notifications |
|
| 473 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | + $notifications( |
|
| 475 | + "instituer$objet", |
|
| 476 | + $id, |
|
| 477 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return ''; // pas d'erreur |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -493,51 +493,51 @@ discard block |
||
| 493 | 493 | * @return void |
| 494 | 494 | */ |
| 495 | 495 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 496 | - $table_sql = table_objet_sql($objet); |
|
| 497 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | - $desc = $trouver_table($table_sql); |
|
| 499 | - |
|
| 500 | - // Si on deplace l'objet |
|
| 501 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | - if (isset($champs['id_rubrique'])) { |
|
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | - $langue = $row_rub['lang']; |
|
| 505 | - |
|
| 506 | - if (isset($desc['field']['id_secteur'])) { |
|
| 507 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | - if ( |
|
| 512 | - sql_fetsel( |
|
| 513 | - '1', |
|
| 514 | - $table_sql, |
|
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | - ) |
|
| 517 | - ) { |
|
| 518 | - $champs['lang'] = $langue; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if (!$champs) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | - |
|
| 528 | - // Changer le statut des rubriques concernees |
|
| 529 | - if ($cond) { |
|
| 530 | - include_spip('inc/rubriques'); |
|
| 531 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | - $postdate = false; |
|
| 533 | - // On rajoute les infos de l'objet |
|
| 534 | - $infos = [ |
|
| 535 | - 'objet' => $objet, |
|
| 536 | - 'id_objet' => $id, |
|
| 537 | - 'statut_ancien' => $statut, |
|
| 538 | - ]; |
|
| 539 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | - } |
|
| 496 | + $table_sql = table_objet_sql($objet); |
|
| 497 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | + $desc = $trouver_table($table_sql); |
|
| 499 | + |
|
| 500 | + // Si on deplace l'objet |
|
| 501 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | + if (isset($champs['id_rubrique'])) { |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | + $langue = $row_rub['lang']; |
|
| 505 | + |
|
| 506 | + if (isset($desc['field']['id_secteur'])) { |
|
| 507 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | + if ( |
|
| 512 | + sql_fetsel( |
|
| 513 | + '1', |
|
| 514 | + $table_sql, |
|
| 515 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | + ) |
|
| 517 | + ) { |
|
| 518 | + $champs['lang'] = $langue; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if (!$champs) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | + |
|
| 528 | + // Changer le statut des rubriques concernees |
|
| 529 | + if ($cond) { |
|
| 530 | + include_spip('inc/rubriques'); |
|
| 531 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | + $postdate = false; |
|
| 533 | + // On rajoute les infos de l'objet |
|
| 534 | + $infos = [ |
|
| 535 | + 'objet' => $objet, |
|
| 536 | + 'id_objet' => $id, |
|
| 537 | + 'statut_ancien' => $statut, |
|
| 538 | + ]; |
|
| 539 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | + } |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | |
@@ -566,75 +566,75 @@ discard block |
||
| 566 | 566 | * string|int : valeur du champ demande pour l'objet demande |
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | - $objet = $t; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | - static $descriptions = []; |
|
| 577 | - |
|
| 578 | - // On détermine le nom du champ id de la table. |
|
| 579 | - include_spip('base/objets'); |
|
| 580 | - $primary = id_table_objet($objet); |
|
| 581 | - |
|
| 582 | - // On détermine l'id à utiliser. |
|
| 583 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | - |
|
| 585 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | - if ( |
|
| 587 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | - or (isset($options['force']) and $options['force']) |
|
| 589 | - ) { |
|
| 590 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | - if ( |
|
| 592 | - include_spip('action/editer_' . $objet) |
|
| 593 | - and function_exists($lire = "{$objet}_lire_champs") |
|
| 594 | - ) { |
|
| 595 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | - } else { |
|
| 597 | - // On récupère la table SQL à partir du type d'objet. |
|
| 598 | - $table = table_objet_sql($objet); |
|
| 599 | - |
|
| 600 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | - $where = [ |
|
| 602 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 603 | - ]; |
|
| 604 | - |
|
| 605 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!$valeurs) { |
|
| 610 | - $valeurs = false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | - |
|
| 615 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | - |
|
| 623 | - // On ne retourne maintenant que les champs demandés. |
|
| 624 | - // - on détermine les informations à renvoyer. |
|
| 625 | - if ($retour and !empty($options['champs'])) { |
|
| 626 | - $champs = $options['champs']; |
|
| 627 | - // Extraction des seules informations demandées. |
|
| 628 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | - if (is_array($champs)) { |
|
| 631 | - // Tableau des informations valides |
|
| 632 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | - } else { |
|
| 634 | - // Valeur unique demandée. |
|
| 635 | - $retour = ($retour[$champs] ?? false); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - return $retour; |
|
| 569 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | + $objet = $t; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | + static $descriptions = []; |
|
| 577 | + |
|
| 578 | + // On détermine le nom du champ id de la table. |
|
| 579 | + include_spip('base/objets'); |
|
| 580 | + $primary = id_table_objet($objet); |
|
| 581 | + |
|
| 582 | + // On détermine l'id à utiliser. |
|
| 583 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | + |
|
| 585 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | + if ( |
|
| 587 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | + or (isset($options['force']) and $options['force']) |
|
| 589 | + ) { |
|
| 590 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | + if ( |
|
| 592 | + include_spip('action/editer_' . $objet) |
|
| 593 | + and function_exists($lire = "{$objet}_lire_champs") |
|
| 594 | + ) { |
|
| 595 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | + } else { |
|
| 597 | + // On récupère la table SQL à partir du type d'objet. |
|
| 598 | + $table = table_objet_sql($objet); |
|
| 599 | + |
|
| 600 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | + $where = [ |
|
| 602 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 603 | + ]; |
|
| 604 | + |
|
| 605 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!$valeurs) { |
|
| 610 | + $valeurs = false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | + |
|
| 615 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | + |
|
| 623 | + // On ne retourne maintenant que les champs demandés. |
|
| 624 | + // - on détermine les informations à renvoyer. |
|
| 625 | + if ($retour and !empty($options['champs'])) { |
|
| 626 | + $champs = $options['champs']; |
|
| 627 | + // Extraction des seules informations demandées. |
|
| 628 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | + if (is_array($champs)) { |
|
| 631 | + // Tableau des informations valides |
|
| 632 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | + } else { |
|
| 634 | + // Valeur unique demandée. |
|
| 635 | + $retour = ($retour[$champs] ?? false); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + return $retour; |
|
| 640 | 640 | } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | 78 | if (($t = objet_type($objet)) !== $objet) { |
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 80 | 80 | $objet = $t; |
| 81 | 81 | } |
| 82 | 82 | if ( |
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 83 | + include_spip('action/editer_'.$objet) |
|
| 84 | + and function_exists($modifier = $objet.'_modifier') |
|
| 85 | 85 | ) { |
| 86 | 86 | return $modifier($id, $set); |
| 87 | 87 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 91 | 91 | $desc = $trouver_table($table_sql); |
| 92 | 92 | if (!$desc or !isset($desc['field'])) { |
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer'._LOG_ERREUR); |
|
| 94 | 94 | |
| 95 | 95 | return _L("Erreur objet $objet inconnu"); |
| 96 | 96 | } |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | 171 | $d = null; |
| 172 | 172 | if (($t = objet_type($objet)) !== $objet) { |
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 174 | 174 | $objet = $t; |
| 175 | 175 | } |
| 176 | 176 | if ( |
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 177 | + include_spip('action/editer_'.$objet) |
|
| 178 | + and function_exists($inserer = $objet.'_inserer') |
|
| 179 | 179 | ) { |
| 180 | 180 | return $inserer($id_parent, $set); |
| 181 | 181 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
| 197 | 197 | $id_rubrique = $row['id_rubrique']; |
| 198 | 198 | } else { |
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $champs['id_rubrique'] = $id_rubrique; |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | 316 | if (($t = objet_type($objet)) !== $objet) { |
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 318 | 318 | $objet = $t; |
| 319 | 319 | } |
| 320 | 320 | if ( |
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 321 | + include_spip('action/editer_'.$objet) |
|
| 322 | + and function_exists($instituer = $objet.'_instituer') |
|
| 323 | 323 | ) { |
| 324 | 324 | return $instituer($id, $c, $calcul_rub); |
| 325 | 325 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
| 349 | 349 | $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
| 350 | 350 | |
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 352 | 352 | |
| 353 | 353 | $id_rubrique = $row['id_rubrique']; |
| 354 | 354 | $statut_ancien = $statut = $row['statut']; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
| 372 | 372 | $statut = $champs['statut'] = $s; |
| 373 | 373 | } else { |
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 374 | + spip_log("editer_objet $objet #$id refus ".json_encode($c, JSON_THROW_ON_ERROR), 'editer'._LOG_INFO_IMPORTANTE); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | and isset($c['id_parent']) |
| 402 | 402 | and $id_parent = $c['id_parent'] |
| 403 | 403 | and $id_parent != $id_rubrique |
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.intval($id_parent))) |
|
| 405 | 405 | ) { |
| 406 | 406 | $champs['id_rubrique'] = $id_parent; |
| 407 | 407 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | // Si on deplace l'objet |
| 501 | 501 | // changer aussi son secteur et sa langue (si heritee) |
| 502 | 502 | if (isset($champs['id_rubrique'])) { |
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 504 | 504 | $langue = $row_rub['lang']; |
| 505 | 505 | |
| 506 | 506 | if (isset($desc['field']['id_secteur'])) { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | sql_fetsel( |
| 513 | 513 | '1', |
| 514 | 514 | $table_sql, |
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 515 | + id_table_objet($objet).'='.intval($id)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 516 | 516 | ) |
| 517 | 517 | ) { |
| 518 | 518 | $champs['lang'] = $langue; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | if (!$champs) { |
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 527 | 527 | |
| 528 | 528 | // Changer le statut des rubriques concernees |
| 529 | 529 | if ($cond) { |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | 569 | if (($t = objet_type($objet)) !== $objet) { |
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 571 | 571 | $objet = $t; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | ) { |
| 590 | 590 | // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
| 591 | 591 | if ( |
| 592 | - include_spip('action/editer_' . $objet) |
|
| 592 | + include_spip('action/editer_'.$objet) |
|
| 593 | 593 | and function_exists($lire = "{$objet}_lire_champs") |
| 594 | 594 | ) { |
| 595 | 595 | $valeurs = $lire($objet, $valeur_id, $champ_id); |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | // La condition est appliquée sur le champ désigné par l'utilisateur. |
| 601 | 601 | $where = [ |
| 602 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 602 | + $champ_id.'='.sql_quote($valeur_id) |
|
| 603 | 603 | ]; |
| 604 | 604 | |
| 605 | 605 | // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $_id = $e['id_table_objet']; |
| 51 | 51 | if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
| 52 | 52 | $table = $e['table_objet_sql']; |
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=".intval($id)); |
|
| 54 | 54 | if (isset($row['id_rubrique'])) { |
| 55 | 55 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 56 | 56 | if (isset($row['id_secteur'])) { |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
| 115 | 115 | + [ |
| 116 | 116 | $id => new Bouton( |
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | 119 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 120 | 120 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 121 | 121 | ) |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | $boutons_admin = array_slice($boutons_admin, 0, $position) |
| 133 | 133 | + [ |
| 134 | 134 | $id => new Bouton( |
| 135 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | - $infos['titre'], // titre |
|
| 135 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | + $infos['titre'], // titre |
|
| 137 | 137 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 138 | 138 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 139 | 139 | ) |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $url = str_replace('&', '&', $url); |
| 221 | 221 | while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
| 222 | 222 | if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
| 223 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 223 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 224 | 224 | } |
| 225 | 225 | $val = _request($matches[2], $contexte); |
| 226 | 226 | $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
@@ -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/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,89 +79,89 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | - if ($position < 0) { |
|
| 112 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | - } |
|
| 114 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | - + [ |
|
| 116 | - $id => new Bouton( |
|
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 119 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | - ) |
|
| 122 | - ] |
|
| 123 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | - } |
|
| 125 | - if ( |
|
| 126 | - !$parent |
|
| 127 | - // provisoire, eviter les vieux boutons |
|
| 128 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | - ) { |
|
| 131 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | - + [ |
|
| 134 | - $id => new Bouton( |
|
| 135 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | - $infos['titre'], // titre |
|
| 137 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | - ) |
|
| 140 | - ] |
|
| 141 | - + array_slice($boutons_admin, $position, 100); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | + if ($position < 0) { |
|
| 112 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | + } |
|
| 114 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | + + [ |
|
| 116 | + $id => new Bouton( |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | + ) |
|
| 122 | + ] |
|
| 123 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | + } |
|
| 125 | + if ( |
|
| 126 | + !$parent |
|
| 127 | + // provisoire, eviter les vieux boutons |
|
| 128 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | + ) { |
|
| 131 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | + + [ |
|
| 134 | + $id => new Bouton( |
|
| 135 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | + $infos['titre'], // titre |
|
| 137 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | + ) |
|
| 140 | + ] |
|
| 141 | + + array_slice($boutons_admin, $position, 100); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 146 | 146 | |
| 147 | - // définir les favoris et positions d’origine |
|
| 148 | - if ($boutons_admin) { |
|
| 149 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | - $i = 1; |
|
| 151 | - foreach ($boutons_admin as $key => $menu) { |
|
| 152 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 153 | - $menu->position = $i++; |
|
| 154 | - if ($menu->sousmenu) { |
|
| 155 | - $j = 1; |
|
| 156 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 158 | - $bouton->position = $j++; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 147 | + // définir les favoris et positions d’origine |
|
| 148 | + if ($boutons_admin) { |
|
| 149 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | + $i = 1; |
|
| 151 | + foreach ($boutons_admin as $key => $menu) { |
|
| 152 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 153 | + $menu->position = $i++; |
|
| 154 | + if ($menu->sousmenu) { |
|
| 155 | + $j = 1; |
|
| 156 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 158 | + $bouton->position = $j++; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $boutons_admin; |
|
| 164 | + return $boutons_admin; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return Bouton[] |
| 174 | 174 | */ |
| 175 | 175 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 176 | - foreach ($menus as $menu) { |
|
| 177 | - if ($menu->sousmenu) { |
|
| 178 | - $libelles = $isfavoris = $favoris = []; |
|
| 179 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 182 | - $favoris[$key] = $item->favori; |
|
| 183 | - } |
|
| 184 | - if ($avec_favoris) { |
|
| 185 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | - } else { |
|
| 187 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - return $menus; |
|
| 176 | + foreach ($menus as $menu) { |
|
| 177 | + if ($menu->sousmenu) { |
|
| 178 | + $libelles = $isfavoris = $favoris = []; |
|
| 179 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 182 | + $favoris[$key] = $item->favori; |
|
| 183 | + } |
|
| 184 | + if ($avec_favoris) { |
|
| 185 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | + } else { |
|
| 187 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + return $menus; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Bouton[] |
| 200 | 200 | */ |
| 201 | 201 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 202 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 202 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -212,23 +212,23 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 215 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | - $url = generer_url_ecrire($url, $args, true); |
|
| 217 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | - // &truc=@machin@ |
|
| 219 | - // @machin@ etant remplace par _request('machin') |
|
| 220 | - $url = str_replace('&', '&', $url); |
|
| 221 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | - } |
|
| 225 | - $val = _request($matches[2], $contexte); |
|
| 226 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | - } |
|
| 228 | - $url = str_replace('&', '&', $url); |
|
| 229 | - } |
|
| 215 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | + $url = generer_url_ecrire($url, $args, true); |
|
| 217 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | + // &truc=@machin@ |
|
| 219 | + // @machin@ etant remplace par _request('machin') |
|
| 220 | + $url = str_replace('&', '&', $url); |
|
| 221 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | + } |
|
| 225 | + $val = _request($matches[2], $contexte); |
|
| 226 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | + } |
|
| 228 | + $url = str_replace('&', '&', $url); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - return $url; |
|
| 231 | + return $url; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * Code HTML du bandeau |
| 239 | 239 | */ |
| 240 | 240 | function inc_bandeau_dist() { |
| 241 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 241 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | function obtenir_menus_favoris() { |
| 250 | - if ( |
|
| 251 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | - ) { |
|
| 255 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | - } |
|
| 257 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | - return $definir_menus_favoris(); |
|
| 250 | + if ( |
|
| 251 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | + ) { |
|
| 255 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | + } |
|
| 257 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | + return $definir_menus_favoris(); |
|
| 259 | 259 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | 42 | if (is_null($liste_langues)) { |
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | 44 | } else { |
| 45 | 45 | if (is_array($liste_langues)) { |
| 46 | 46 | $liste_langues = implode(',', $liste_langues); |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + $liste_langues = ','.$liste_langues.','; |
|
| 50 | 50 | |
| 51 | 51 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 52 | 52 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | foreach ($langues as $l) { |
| 194 | 194 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (!test_espace_prive()) { |
@@ -210,23 +210,21 @@ discard block |
||
| 210 | 210 | $base, |
| 211 | 211 | $cible, |
| 212 | 212 | (select_langues($nom_select, $change, $ret) |
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 214 | 214 | " method='post'" |
| 215 | 215 | ); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | 219 | static $cpt = 0; |
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 220 | + $id = 'menu_langues'.$cpt++; |
|
| 221 | 221 | |
| 222 | 222 | return |
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 224 | 224 | "<select name='$nom_select' id='$id' " |
| 225 | 225 | . ((!test_espace_prive()) ? |
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 226 | + ("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ? |
|
| 227 | + ("class='lang_ecrire'") : "class='fondl'")) |
|
| 230 | 228 | . $change |
| 231 | 229 | . ">\n" |
| 232 | 230 | . $options |
@@ -352,7 +350,7 @@ discard block |
||
| 352 | 350 | and (!isset($GLOBALS['spip_lang']) |
| 353 | 351 | or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 354 | 352 | ) { |
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 353 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 356 | 354 | } |
| 357 | 355 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 358 | 356 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -455,7 +453,7 @@ discard block |
||
| 455 | 453 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 456 | 454 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 457 | 455 | $GLOBALS['meta']['langue_site'] = $tout = |
| 458 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 456 | + (!$all_langs or (strpos(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,") !== false)) |
|
| 459 | 457 | ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
| 460 | 458 | ecrire_meta('langue_site', $tout); |
| 461 | 459 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | - } else { |
|
| 45 | - if (is_array($liste_langues)) { |
|
| 46 | - $liste_langues = implode(',', $liste_langues); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | - |
|
| 51 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | - if (!$lang) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 62 | - ) { |
|
| 63 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | - |
|
| 67 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | + } else { |
|
| 45 | + if (is_array($liste_langues)) { |
|
| 46 | + $liste_langues = implode(',', $liste_langues); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + |
|
| 51 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | + if (!$lang) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 62 | + ) { |
|
| 63 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | + |
|
| 67 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 81 | 81 | |
| 82 | 82 | function choisir_traduction($trads, $lang = '') { |
| 83 | - $k = approcher_langue($trads, $lang); |
|
| 83 | + $k = approcher_langue($trads, $lang); |
|
| 84 | 84 | |
| 85 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // retourne son 2e argument si c'est un index du premier |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | // la langue X etant consideree comme une approche de X_Y |
| 91 | 91 | function approcher_langue($trads, $lang = '') { |
| 92 | 92 | |
| 93 | - if (!$lang) { |
|
| 94 | - $lang = $GLOBALS['spip_lang']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (isset($trads[$lang])) { |
|
| 98 | - return $lang; |
|
| 99 | - } // cas des langues xx_yy |
|
| 100 | - else { |
|
| 101 | - $r = explode('_', $lang); |
|
| 102 | - if (isset($trads[$r[0]])) { |
|
| 103 | - return $r[0]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return ''; |
|
| 93 | + if (!$lang) { |
|
| 94 | + $lang = $GLOBALS['spip_lang']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (isset($trads[$lang])) { |
|
| 98 | + return $lang; |
|
| 99 | + } // cas des langues xx_yy |
|
| 100 | + else { |
|
| 101 | + $r = explode('_', $lang); |
|
| 102 | + if (isset($trads[$r[0]])) { |
|
| 103 | + return $r[0]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * Nom de la langue, sinon son code. |
| 120 | 120 | **/ |
| 121 | 121 | function traduire_nom_langue($lang) { |
| 122 | - include_spip('inc/lang_liste'); |
|
| 123 | - include_spip('inc/charsets'); |
|
| 122 | + include_spip('inc/lang_liste'); |
|
| 123 | + include_spip('inc/charsets'); |
|
| 124 | 124 | |
| 125 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | // hebreu a priori), 'droitier' sinon. |
| 136 | 136 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 137 | 137 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 138 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | 139 | |
| 140 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | - $gaucher : $droitier; |
|
| 140 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | + $gaucher : $droitier; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // typo francaise ou anglaise ? |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | // sinon determiner la typo en fonction de la langue courante |
| 148 | 148 | |
| 149 | 149 | function lang_typo($lang = '') { |
| 150 | - if (!$lang) { |
|
| 151 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | - } |
|
| 153 | - if ( |
|
| 154 | - $lang == 'eo' |
|
| 155 | - or $lang == 'fr' |
|
| 156 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | - or $lang == 'cpf' |
|
| 158 | - ) { |
|
| 159 | - return 'fr'; |
|
| 160 | - } else { |
|
| 161 | - return 'en'; |
|
| 162 | - } |
|
| 150 | + if (!$lang) { |
|
| 151 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | + } |
|
| 153 | + if ( |
|
| 154 | + $lang == 'eo' |
|
| 155 | + or $lang == 'fr' |
|
| 156 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | + or $lang == 'cpf' |
|
| 158 | + ) { |
|
| 159 | + return 'fr'; |
|
| 160 | + } else { |
|
| 161 | + return 'en'; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 166 | 166 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 167 | 167 | function changer_typo($lang = '') { |
| 168 | - if ($lang) { |
|
| 169 | - $GLOBALS['lang_objet'] = $lang; |
|
| 170 | - } else { |
|
| 171 | - unset($GLOBALS['lang_objet']); |
|
| 172 | - } |
|
| 168 | + if ($lang) { |
|
| 169 | + $GLOBALS['lang_objet'] = $lang; |
|
| 170 | + } else { |
|
| 171 | + unset($GLOBALS['lang_objet']); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // |
@@ -179,58 +179,58 @@ discard block |
||
| 179 | 179 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 180 | 180 | // |
| 181 | 181 | function menu_langues($nom_select, $default = '') { |
| 182 | - include_spip('inc/actions'); |
|
| 183 | - |
|
| 184 | - $langues = liste_options_langues($nom_select); |
|
| 185 | - $ret = ''; |
|
| 186 | - if (!count($langues)) { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$default) { |
|
| 191 | - $default = $GLOBALS['spip_lang']; |
|
| 192 | - } |
|
| 193 | - foreach ($langues as $l) { |
|
| 194 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (!test_espace_prive()) { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = ''; |
|
| 201 | - } else { |
|
| 202 | - $cible = self(); |
|
| 203 | - $base = spip_connect() ? 'base' : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | - |
|
| 208 | - return generer_action_auteur( |
|
| 209 | - 'converser', |
|
| 210 | - $base, |
|
| 211 | - $cible, |
|
| 212 | - (select_langues($nom_select, $change, $ret) |
|
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | - " method='post'" |
|
| 215 | - ); |
|
| 182 | + include_spip('inc/actions'); |
|
| 183 | + |
|
| 184 | + $langues = liste_options_langues($nom_select); |
|
| 185 | + $ret = ''; |
|
| 186 | + if (!count($langues)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$default) { |
|
| 191 | + $default = $GLOBALS['spip_lang']; |
|
| 192 | + } |
|
| 193 | + foreach ($langues as $l) { |
|
| 194 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (!test_espace_prive()) { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = ''; |
|
| 201 | + } else { |
|
| 202 | + $cible = self(); |
|
| 203 | + $base = spip_connect() ? 'base' : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | + |
|
| 208 | + return generer_action_auteur( |
|
| 209 | + 'converser', |
|
| 210 | + $base, |
|
| 211 | + $cible, |
|
| 212 | + (select_langues($nom_select, $change, $ret) |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | + " method='post'" |
|
| 215 | + ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | - static $cpt = 0; |
|
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 221 | - |
|
| 222 | - return |
|
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | - "<select name='$nom_select' id='$id' " |
|
| 225 | - . ((!test_espace_prive()) ? |
|
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 230 | - . $change |
|
| 231 | - . ">\n" |
|
| 232 | - . $options |
|
| 233 | - . '</select>'; |
|
| 219 | + static $cpt = 0; |
|
| 220 | + $id = 'menu_langues' . $cpt++; |
|
| 221 | + |
|
| 222 | + return |
|
| 223 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | + "<select name='$nom_select' id='$id' " |
|
| 225 | + . ((!test_espace_prive()) ? |
|
| 226 | + ("class='forml menu_langues'") : |
|
| 227 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | + ("class='lang_ecrire'") : |
|
| 229 | + "class='fondl'")) |
|
| 230 | + . $change |
|
| 231 | + . ">\n" |
|
| 232 | + . $options |
|
| 233 | + . '</select>'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function liste_options_langues($nom_select) { |
| 254 | 254 | |
| 255 | - switch ($nom_select) { |
|
| 256 | - # #MENU_LANG |
|
| 257 | - case 'var_lang': |
|
| 258 | - # menu de changement de la langue d'un article |
|
| 259 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | - case 'changer_lang': |
|
| 261 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | - break; |
|
| 263 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | - # les langues presentes sous forme de fichiers de langue |
|
| 265 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | - case 'var_lang_ecrire': |
|
| 267 | - default: |
|
| 268 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | - init_langues(); |
|
| 270 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | - break; |
|
| 255 | + switch ($nom_select) { |
|
| 256 | + # #MENU_LANG |
|
| 257 | + case 'var_lang': |
|
| 258 | + # menu de changement de la langue d'un article |
|
| 259 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | + case 'changer_lang': |
|
| 261 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | + break; |
|
| 263 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | + # les langues presentes sous forme de fichiers de langue |
|
| 265 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | + case 'var_lang_ecrire': |
|
| 267 | + default: |
|
| 268 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | + init_langues(); |
|
| 270 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | + break; |
|
| 272 | 272 | |
| 273 | 273 | # dernier choix possible : toutes les langues = langues_proposees |
| 274 | 274 | # + langues_multilingues ; mais, ne sert pas |
| 275 | 275 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 276 | - } |
|
| 277 | - if (count($langues) <= 1) { |
|
| 278 | - return []; |
|
| 279 | - } |
|
| 280 | - sort($langues); |
|
| 276 | + } |
|
| 277 | + if (count($langues) <= 1) { |
|
| 278 | + return []; |
|
| 279 | + } |
|
| 280 | + sort($langues); |
|
| 281 | 281 | |
| 282 | - return $langues; |
|
| 282 | + return $langues; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -294,39 +294,39 @@ discard block |
||
| 294 | 294 | **/ |
| 295 | 295 | function verifier_lang_url() { |
| 296 | 296 | |
| 297 | - // quelle langue est demandee ? |
|
| 298 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | - } |
|
| 302 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | - } |
|
| 305 | - if (isset($_GET['lang'])) { |
|
| 306 | - $lang_demandee = $_GET['lang']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | - if ( |
|
| 311 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | - and changer_langue($lang_demandee) |
|
| 313 | - and $lang_demandee != @$_GET['lang'] |
|
| 314 | - ) { |
|
| 315 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | - // ici on a besoin des var_truc |
|
| 317 | - foreach ($_GET as $var => $val) { |
|
| 318 | - if (!strncmp('var_', $var, 4)) { |
|
| 319 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - include_spip('inc/headers'); |
|
| 323 | - redirige_par_entete($destination); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | - // (pour criteres {lang}). |
|
| 329 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 297 | + // quelle langue est demandee ? |
|
| 298 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | + } |
|
| 302 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | + } |
|
| 305 | + if (isset($_GET['lang'])) { |
|
| 306 | + $lang_demandee = $_GET['lang']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | + if ( |
|
| 311 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | + and changer_langue($lang_demandee) |
|
| 313 | + and $lang_demandee != @$_GET['lang'] |
|
| 314 | + ) { |
|
| 315 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | + // ici on a besoin des var_truc |
|
| 317 | + foreach ($_GET as $var => $val) { |
|
| 318 | + if (!strncmp('var_', $var, 4)) { |
|
| 319 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + include_spip('inc/headers'); |
|
| 323 | + redirige_par_entete($destination); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | + // (pour criteres {lang}). |
|
| 329 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,22 +344,22 @@ discard block |
||
| 344 | 344 | * La langue sélectionnée |
| 345 | 345 | **/ |
| 346 | 346 | function utiliser_langue_site($liste_langues = null) { |
| 347 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | - if ( |
|
| 349 | - isset($GLOBALS['meta']['langue_site']) |
|
| 350 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | - and (!isset($GLOBALS['spip_lang']) |
|
| 353 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | - ) { |
|
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | - } |
|
| 357 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $GLOBALS['spip_lang']; |
|
| 347 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | + if ( |
|
| 349 | + isset($GLOBALS['meta']['langue_site']) |
|
| 350 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | + and (!isset($GLOBALS['spip_lang']) |
|
| 353 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | + ) { |
|
| 355 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | + } |
|
| 357 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $GLOBALS['spip_lang']; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,35 +378,35 @@ discard block |
||
| 378 | 378 | **/ |
| 379 | 379 | function utiliser_langue_visiteur($liste_langues = null) { |
| 380 | 380 | |
| 381 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | - if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | - if (isset($_COOKIE[$l])) { |
|
| 388 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | - return $l; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | - return $l; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | - return $l; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return utiliser_langue_site($liste_langues); |
|
| 381 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | + if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | + if (isset($_COOKIE[$l])) { |
|
| 388 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | + return $l; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | + return $l; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | + return $l; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return utiliser_langue_site($liste_langues); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return int |
| 417 | 417 | */ |
| 418 | 418 | function match_langue($chaine) { |
| 419 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 419 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -434,36 +434,36 @@ discard block |
||
| 434 | 434 | **/ |
| 435 | 435 | function init_langues() { |
| 436 | 436 | |
| 437 | - // liste des langues dans les meta, sauf a l'install |
|
| 438 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | - |
|
| 440 | - $tout = []; |
|
| 441 | - if (!$all_langs) { |
|
| 442 | - // trouver tous les modules lang/spip_xx.php |
|
| 443 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | - foreach ($modules as $name => $path) { |
|
| 445 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | - if (match_langue($regs[1])) { |
|
| 447 | - $tout[] = $regs[1]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - sort($tout); |
|
| 452 | - $tout = join(',', $tout); |
|
| 453 | - // Si les langues n'ont pas change, ne rien faire |
|
| 454 | - if ($tout != $all_langs) { |
|
| 455 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | - include_spip('inc/meta'); |
|
| 457 | - ecrire_meta('langues_proposees', $tout); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | - ecrire_meta('langue_site', $tout); |
|
| 466 | - } |
|
| 437 | + // liste des langues dans les meta, sauf a l'install |
|
| 438 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | + |
|
| 440 | + $tout = []; |
|
| 441 | + if (!$all_langs) { |
|
| 442 | + // trouver tous les modules lang/spip_xx.php |
|
| 443 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | + foreach ($modules as $name => $path) { |
|
| 445 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | + if (match_langue($regs[1])) { |
|
| 447 | + $tout[] = $regs[1]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + sort($tout); |
|
| 452 | + $tout = join(',', $tout); |
|
| 453 | + // Si les langues n'ont pas change, ne rien faire |
|
| 454 | + if ($tout != $all_langs) { |
|
| 455 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | + include_spip('inc/meta'); |
|
| 457 | + ecrire_meta('langues_proposees', $tout); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | + ecrire_meta('langue_site', $tout); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | * Code html de la balise <html> |
| 478 | 478 | **/ |
| 479 | 479 | function html_lang_attributes() { |
| 480 | - $lang = $GLOBALS['spip_lang']; |
|
| 481 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 480 | + $lang = $GLOBALS['spip_lang']; |
|
| 481 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 482 | 482 | |
| 483 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | 496 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 497 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 497 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -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 | /** |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 39 | 39 | */ |
| 40 | 40 | function find_langs_in_path($file, $dirname = 'lang') { |
| 41 | - static $dirs = []; |
|
| 42 | - $liste = []; |
|
| 43 | - foreach (creer_chemin() as $dir) { |
|
| 44 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | - } |
|
| 47 | - if ($dirs[$a]) { |
|
| 48 | - if (is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 41 | + static $dirs = []; |
|
| 42 | + $liste = []; |
|
| 43 | + foreach (creer_chemin() as $dir) { |
|
| 44 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | + } |
|
| 47 | + if ($dirs[$a]) { |
|
| 48 | + if (is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return array_reverse($liste); |
|
| 54 | + return array_reverse($liste); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -66,23 +66,23 @@ discard block |
||
| 66 | 66 | * Liste des fichiers touvés pour ce module et cette langue. |
| 67 | 67 | **/ |
| 68 | 68 | function chercher_module_lang($module, $lang = '') { |
| 69 | - if ($lang) { |
|
| 70 | - $lang = '_' . $lang; |
|
| 71 | - } |
|
| 69 | + if ($lang) { |
|
| 70 | + $lang = '_' . $lang; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | - if ( |
|
| 75 | - $f = ($module == 'local' |
|
| 76 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | - ) { |
|
| 79 | - return is_array($f) ? $f : [$f]; |
|
| 80 | - } |
|
| 73 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | + if ( |
|
| 75 | + $f = ($module == 'local' |
|
| 76 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | + ) { |
|
| 79 | + return is_array($f) ? $f : [$f]; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | - return (($module == 'local') or strpos($module, '/')) |
|
| 84 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | - : false; |
|
| 82 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | + return (($module == 'local') or strpos($module, '/')) |
|
| 84 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | + : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | **/ |
| 106 | 106 | function charger_langue($lang, $module = 'spip') { |
| 107 | - static $langs = []; |
|
| 108 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | - if (!isset($langs[$lang])) { |
|
| 110 | - $langs[$lang] = []; |
|
| 111 | - if ($lang) { |
|
| 112 | - $langs[$lang][] = $lang; |
|
| 113 | - if (strpos($lang, '_') !== false) { |
|
| 114 | - $l = explode('_', $lang); |
|
| 115 | - $langs[$lang][] = reset($l); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | - } |
|
| 121 | - foreach ($langs[$lang] as $l) { |
|
| 122 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | - surcharger_langue($fichiers_lang); |
|
| 126 | - if ($l !== $lang) { |
|
| 127 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | - } |
|
| 129 | - $GLOBALS['lang_' . $var] = $l; |
|
| 130 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + static $langs = []; |
|
| 108 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | + if (!isset($langs[$lang])) { |
|
| 110 | + $langs[$lang] = []; |
|
| 111 | + if ($lang) { |
|
| 112 | + $langs[$lang][] = $lang; |
|
| 113 | + if (strpos($lang, '_') !== false) { |
|
| 114 | + $l = explode('_', $lang); |
|
| 115 | + $langs[$lang][] = reset($l); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | + } |
|
| 121 | + foreach ($langs[$lang] as $l) { |
|
| 122 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | + surcharger_langue($fichiers_lang); |
|
| 126 | + if ($l !== $lang) { |
|
| 127 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | + } |
|
| 129 | + $GLOBALS['lang_' . $var] = $l; |
|
| 130 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | * @return array<string, string> |
| 144 | 144 | */ |
| 145 | 145 | function lire_fichier_langue(string $fichier): array { |
| 146 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | - $idx_lang = include $fichier; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | - if (!is_array($idx_lang)) { |
|
| 152 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | - } else { |
|
| 155 | - $idx_lang = []; |
|
| 156 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | - } |
|
| 158 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | - } |
|
| 160 | - return $idx_lang; |
|
| 146 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | + $idx_lang = include $fichier; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | + if (!is_array($idx_lang)) { |
|
| 152 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | + } else { |
|
| 155 | + $idx_lang = []; |
|
| 156 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | + } |
|
| 158 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | + } |
|
| 160 | + return $idx_lang; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -177,46 +177,46 @@ discard block |
||
| 177 | 177 | * Liste des chemins de fichiers de langue à surcharger. |
| 178 | 178 | **/ |
| 179 | 179 | function surcharger_langue($fichiers) { |
| 180 | - static $surcharges = []; |
|
| 181 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 180 | + static $surcharges = []; |
|
| 181 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if (!is_array($fichiers)) { |
|
| 186 | - $fichiers = [$fichiers]; |
|
| 187 | - } |
|
| 188 | - if (!count($fichiers)) { |
|
| 189 | - return; |
|
| 190 | - } |
|
| 191 | - foreach ($fichiers as $fichier) { |
|
| 192 | - if (!isset($surcharges[$fichier])) { |
|
| 193 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | - } |
|
| 195 | - if (is_array($surcharges[$fichier])) { |
|
| 196 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | - $surcharges[$fichier] |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 185 | + if (!is_array($fichiers)) { |
|
| 186 | + $fichiers = [$fichiers]; |
|
| 187 | + } |
|
| 188 | + if (!count($fichiers)) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 191 | + foreach ($fichiers as $fichier) { |
|
| 192 | + if (!isset($surcharges[$fichier])) { |
|
| 193 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | + } |
|
| 195 | + if (is_array($surcharges[$fichier])) { |
|
| 196 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | + $surcharges[$fichier] |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | class SPIP_Traductions_Description { |
| 208 | - /** @var string code de langue (hors module) */ |
|
| 209 | - public $code; |
|
| 210 | - /** @var string nom du module de langue */ |
|
| 211 | - public $module; |
|
| 212 | - /** @var string langue de la traduction */ |
|
| 213 | - public $langue; |
|
| 214 | - /** @var string traduction */ |
|
| 215 | - public $texte; |
|
| 216 | - /** @var string var mode particulier appliqué ? */ |
|
| 217 | - public $mode; |
|
| 218 | - /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | - public $corrections = false; |
|
| 208 | + /** @var string code de langue (hors module) */ |
|
| 209 | + public $code; |
|
| 210 | + /** @var string nom du module de langue */ |
|
| 211 | + public $module; |
|
| 212 | + /** @var string langue de la traduction */ |
|
| 213 | + public $langue; |
|
| 214 | + /** @var string traduction */ |
|
| 215 | + public $texte; |
|
| 216 | + /** @var string var mode particulier appliqué ? */ |
|
| 217 | + public $mode; |
|
| 218 | + /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | + public $corrections = false; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | |
@@ -258,99 +258,99 @@ discard block |
||
| 258 | 258 | * - SPIP_Traductions_Description : traduction et description (texte, module, langue) |
| 259 | 259 | **/ |
| 260 | 260 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 261 | - static $deja_vu = []; |
|
| 262 | - static $local = []; |
|
| 261 | + static $deja_vu = []; |
|
| 262 | + static $local = []; |
|
| 263 | 263 | |
| 264 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | - } |
|
| 264 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | - if (strpos($ori, ':')) { |
|
| 270 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | - $modules = explode('|', $modules); |
|
| 272 | - $ori_complet = $ori; |
|
| 273 | - } else { |
|
| 274 | - $modules = ['spip', 'ecrire']; |
|
| 275 | - $code = $ori; |
|
| 276 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | - } |
|
| 268 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | + if (strpos($ori, ':')) { |
|
| 270 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | + $modules = explode('|', $modules); |
|
| 272 | + $ori_complet = $ori; |
|
| 273 | + } else { |
|
| 274 | + $modules = ['spip', 'ecrire']; |
|
| 275 | + $code = $ori; |
|
| 276 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - $desc = new SPIP_Traductions_Description(); |
|
| 279 | + $desc = new SPIP_Traductions_Description(); |
|
| 280 | 280 | |
| 281 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | - foreach ($modules as $module) { |
|
| 283 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 281 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | + foreach ($modules as $module) { |
|
| 283 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 284 | 284 | |
| 285 | - if (empty($GLOBALS[$var])) { |
|
| 286 | - charger_langue($lang, $module); |
|
| 287 | - // surcharges persos -- on cherche |
|
| 288 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | - if (!isset($local['local_' . $lang])) { |
|
| 290 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | - $GLOBALS['idx_lang'] = $var; |
|
| 292 | - // ... (lang/)local_xx.php |
|
| 293 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | - } |
|
| 295 | - if ($local['local_' . $lang]) { |
|
| 296 | - surcharger_langue($local['local_' . $lang]); |
|
| 297 | - } |
|
| 298 | - // ... puis (lang/)local.php |
|
| 299 | - if (!isset($local['local'])) { |
|
| 300 | - $local['local'] = chercher_module_lang('local'); |
|
| 301 | - } |
|
| 302 | - if ($local['local']) { |
|
| 303 | - surcharger_langue($local['local']); |
|
| 304 | - } |
|
| 305 | - } |
|
| 285 | + if (empty($GLOBALS[$var])) { |
|
| 286 | + charger_langue($lang, $module); |
|
| 287 | + // surcharges persos -- on cherche |
|
| 288 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | + if (!isset($local['local_' . $lang])) { |
|
| 290 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | + $GLOBALS['idx_lang'] = $var; |
|
| 292 | + // ... (lang/)local_xx.php |
|
| 293 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | + } |
|
| 295 | + if ($local['local_' . $lang]) { |
|
| 296 | + surcharger_langue($local['local_' . $lang]); |
|
| 297 | + } |
|
| 298 | + // ... puis (lang/)local.php |
|
| 299 | + if (!isset($local['local'])) { |
|
| 300 | + $local['local'] = chercher_module_lang('local'); |
|
| 301 | + } |
|
| 302 | + if ($local['local']) { |
|
| 303 | + surcharger_langue($local['local']); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - if (isset($GLOBALS[$var][$code])) { |
|
| 308 | - $desc->code = $code; |
|
| 309 | - $desc->module = $module; |
|
| 310 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | - break; |
|
| 313 | - } |
|
| 314 | - } |
|
| 307 | + if (isset($GLOBALS[$var][$code])) { |
|
| 308 | + $desc->code = $code; |
|
| 309 | + $desc->module = $module; |
|
| 310 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | + break; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - if (!$desc->corrections) { |
|
| 317 | - $desc->corrections = true; |
|
| 318 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | - if ( |
|
| 321 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | - ) { |
|
| 324 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | - } else { |
|
| 327 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | - } |
|
| 329 | - } |
|
| 316 | + if (!$desc->corrections) { |
|
| 317 | + $desc->corrections = true; |
|
| 318 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | + if ( |
|
| 321 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | + ) { |
|
| 324 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | + } else { |
|
| 327 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | - } |
|
| 331 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | - if ( |
|
| 339 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | - ) { |
|
| 342 | - include_spip('inc/charsets'); |
|
| 343 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | - } |
|
| 345 | - } |
|
| 336 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | + if ( |
|
| 339 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | + ) { |
|
| 342 | + include_spip('inc/charsets'); |
|
| 343 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - if (_request('var_mode') == 'traduction') { |
|
| 348 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | - } else { |
|
| 350 | - $deja_vu[$lang][$ori] = $desc; |
|
| 351 | - } |
|
| 347 | + if (_request('var_mode') == 'traduction') { |
|
| 348 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | + } else { |
|
| 350 | + $deja_vu[$lang][$ori] = $desc; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - return $raw ? $desc : $desc->texte; |
|
| 353 | + return $raw ? $desc : $desc->texte; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -362,23 +362,23 @@ discard block |
||
| 362 | 362 | * @return SPIP_Traductions_Description |
| 363 | 363 | */ |
| 364 | 364 | function definir_details_traduction($desc, $modules) { |
| 365 | - if (!$desc->mode and $desc->texte) { |
|
| 366 | - // ne pas modifier 2 fois l'affichage |
|
| 367 | - $desc->mode = 'traduction'; |
|
| 368 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | - $desc->texte = '<span ' |
|
| 370 | - . 'lang=' . $desc->langue |
|
| 371 | - . ' class=' . $classe |
|
| 372 | - . ' data-module=' . $desc->module |
|
| 373 | - . ' data-code=' . $desc->code |
|
| 374 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | - . $desc->texte |
|
| 376 | - . '</span>'; |
|
| 377 | - $desc->texte = str_replace( |
|
| 378 | - ["$desc->module:", "$desc->module|"], |
|
| 379 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | - $desc->texte |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - return $desc; |
|
| 365 | + if (!$desc->mode and $desc->texte) { |
|
| 366 | + // ne pas modifier 2 fois l'affichage |
|
| 367 | + $desc->mode = 'traduction'; |
|
| 368 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | + $desc->texte = '<span ' |
|
| 370 | + . 'lang=' . $desc->langue |
|
| 371 | + . ' class=' . $classe |
|
| 372 | + . ' data-module=' . $desc->module |
|
| 373 | + . ' data-code=' . $desc->code |
|
| 374 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | + . $desc->texte |
|
| 376 | + . '</span>'; |
|
| 377 | + $desc->texte = str_replace( |
|
| 378 | + ["$desc->module:", "$desc->module|"], |
|
| 379 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | + $desc->texte |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + return $desc; |
|
| 384 | 384 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | static $dirs = []; |
| 42 | 42 | $liste = []; |
| 43 | 43 | foreach (creer_chemin() as $dir) { |
| 44 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 44 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 45 | 45 | $dirs[$a] = (is_dir($a) || !$a); |
| 46 | 46 | } |
| 47 | 47 | if ($dirs[$a]) { |
@@ -67,21 +67,21 @@ discard block |
||
| 67 | 67 | **/ |
| 68 | 68 | function chercher_module_lang($module, $lang = '') { |
| 69 | 69 | if ($lang) { |
| 70 | - $lang = '_' . $lang; |
|
| 70 | + $lang = '_'.$lang; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
| 74 | 74 | if ( |
| 75 | 75 | $f = ($module == 'local' |
| 76 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 76 | + ? find_in_path($module.$lang.'.php', 'lang/') |
|
| 77 | + : find_langs_in_path($module.$lang.'.php', 'lang/')) |
|
| 78 | 78 | ) { |
| 79 | 79 | return is_array($f) ? $f : [$f]; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // 2) directement dans le chemin (old style, uniquement pour local) |
| 83 | 83 | return (($module == 'local') or strpos($module, '/')) |
| 84 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 84 | + ? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false) |
|
| 85 | 85 | : false; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | **/ |
| 106 | 106 | function charger_langue($lang, $module = 'spip') { |
| 107 | 107 | static $langs = []; |
| 108 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 108 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 109 | 109 | if (!isset($langs[$lang])) { |
| 110 | 110 | $langs[$lang] = []; |
| 111 | 111 | if ($lang) { |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | foreach ($langs[$lang] as $l) { |
| 122 | 122 | if ($fichiers_lang = chercher_module_lang($module, $l)) { |
| 123 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 123 | + $GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l; |
|
| 124 | 124 | $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
| 125 | 125 | surcharger_langue($fichiers_lang); |
| 126 | 126 | if ($l !== $lang) { |
| 127 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 127 | + $GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l]; |
|
| 128 | 128 | } |
| 129 | - $GLOBALS['lang_' . $var] = $l; |
|
| 129 | + $GLOBALS['lang_'.$var] = $l; |
|
| 130 | 130 | #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
| 131 | 131 | break; |
| 132 | 132 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function lire_fichier_langue(string $fichier): array { |
| 146 | 146 | $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
| 147 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 147 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire'; |
|
| 148 | 148 | $GLOBALS['idx_lang'] = $idx_lang_tmp; |
| 149 | 149 | $idx_lang = include $fichier; |
| 150 | 150 | $GLOBALS['idx_lang'] = $idx_lang_before; |
@@ -273,27 +273,27 @@ discard block |
||
| 273 | 273 | } else { |
| 274 | 274 | $modules = ['spip', 'ecrire']; |
| 275 | 275 | $code = $ori; |
| 276 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 276 | + $ori_complet = implode('|', $modules).':'.$ori; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $desc = new SPIP_Traductions_Description(); |
| 280 | 280 | |
| 281 | 281 | // parcourir tous les modules jusqu'a ce qu'on trouve |
| 282 | 282 | foreach ($modules as $module) { |
| 283 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 283 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 284 | 284 | |
| 285 | 285 | if (empty($GLOBALS[$var])) { |
| 286 | 286 | charger_langue($lang, $module); |
| 287 | 287 | // surcharges persos -- on cherche |
| 288 | 288 | // (lang/)local_xx.php et/ou (lang/)local.php ... |
| 289 | - if (!isset($local['local_' . $lang])) { |
|
| 289 | + if (!isset($local['local_'.$lang])) { |
|
| 290 | 290 | // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
| 291 | 291 | $GLOBALS['idx_lang'] = $var; |
| 292 | 292 | // ... (lang/)local_xx.php |
| 293 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 293 | + $local['local_'.$lang] = chercher_module_lang('local', $lang); |
|
| 294 | 294 | } |
| 295 | - if ($local['local_' . $lang]) { |
|
| 296 | - surcharger_langue($local['local_' . $lang]); |
|
| 295 | + if ($local['local_'.$lang]) { |
|
| 296 | + surcharger_langue($local['local_'.$lang]); |
|
| 297 | 297 | } |
| 298 | 298 | // ... puis (lang/)local.php |
| 299 | 299 | if (!isset($local['local'])) { |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | if (isset($GLOBALS[$var][$code])) { |
| 308 | 308 | $desc->code = $code; |
| 309 | 309 | $desc->module = $module; |
| 310 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 310 | + $desc->langue = $GLOBALS['lang_'.$var] ?? $lang; |
|
| 311 | 311 | $desc->texte = $GLOBALS[$var][$code]; |
| 312 | 312 | break; |
| 313 | 313 | } |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | if (!$desc->mode and $desc->texte) { |
| 366 | 366 | // ne pas modifier 2 fois l'affichage |
| 367 | 367 | $desc->mode = 'traduction'; |
| 368 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 368 | + $classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | 369 | $desc->texte = '<span ' |
| 370 | - . 'lang=' . $desc->langue |
|
| 371 | - . ' class=' . $classe |
|
| 372 | - . ' data-module=' . $desc->module |
|
| 373 | - . ' data-code=' . $desc->code |
|
| 374 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 370 | + . 'lang='.$desc->langue |
|
| 371 | + . ' class='.$classe |
|
| 372 | + . ' data-module='.$desc->module |
|
| 373 | + . ' data-code='.$desc->code |
|
| 374 | + . ' title='.$modules.'('.$desc->langue.')>' |
|
| 375 | 375 | . $desc->texte |
| 376 | 376 | . '</span>'; |
| 377 | 377 | $desc->texte = str_replace( |
@@ -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 | |
@@ -27,215 +27,215 @@ discard block |
||
| 27 | 27 | * Permet d'itérer sur des données en base de données |
| 28 | 28 | */ |
| 29 | 29 | class IterateurSQL implements Iterator { |
| 30 | - /** |
|
| 31 | - * Ressource sql |
|
| 32 | - * |
|
| 33 | - * @var Object|bool |
|
| 34 | - */ |
|
| 35 | - protected $sqlresult = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * row sql courante |
|
| 39 | - * |
|
| 40 | - * @var array|null |
|
| 41 | - */ |
|
| 42 | - protected $row = null; |
|
| 43 | - |
|
| 44 | - protected bool $firstseek = false; |
|
| 45 | - |
|
| 46 | - protected int $pos = -1; |
|
| 47 | - |
|
| 48 | - protected string $type = 'SQL'; |
|
| 49 | - |
|
| 50 | - protected array $command = []; |
|
| 51 | - |
|
| 52 | - protected array $info = []; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** Erreur presente ? **/ |
|
| 56 | - public bool $err = false; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Calcul du total des elements |
|
| 60 | - * |
|
| 61 | - * @var int|null |
|
| 62 | - **/ |
|
| 63 | - public $total = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * selectionner les donnees, ie faire la requete SQL |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - protected function select() { |
|
| 71 | - $this->row = null; |
|
| 72 | - $v = &$this->command; |
|
| 73 | - $this->sqlresult = calculer_select( |
|
| 74 | - $v['select'], |
|
| 75 | - $v['from'], |
|
| 76 | - $v['type'], |
|
| 77 | - $v['where'], |
|
| 78 | - $v['join'], |
|
| 79 | - $v['groupby'], |
|
| 80 | - $v['orderby'], |
|
| 81 | - $v['limit'], |
|
| 82 | - $v['having'], |
|
| 83 | - $v['table'], |
|
| 84 | - $v['id'], |
|
| 85 | - $v['connect'], |
|
| 86 | - $this->info |
|
| 87 | - ); |
|
| 88 | - $this->err = !$this->sqlresult; |
|
| 89 | - $this->firstseek = false; |
|
| 90 | - $this->pos = -1; |
|
| 91 | - |
|
| 92 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | - //$this->total = $this->count(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /* |
|
| 30 | + /** |
|
| 31 | + * Ressource sql |
|
| 32 | + * |
|
| 33 | + * @var Object|bool |
|
| 34 | + */ |
|
| 35 | + protected $sqlresult = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * row sql courante |
|
| 39 | + * |
|
| 40 | + * @var array|null |
|
| 41 | + */ |
|
| 42 | + protected $row = null; |
|
| 43 | + |
|
| 44 | + protected bool $firstseek = false; |
|
| 45 | + |
|
| 46 | + protected int $pos = -1; |
|
| 47 | + |
|
| 48 | + protected string $type = 'SQL'; |
|
| 49 | + |
|
| 50 | + protected array $command = []; |
|
| 51 | + |
|
| 52 | + protected array $info = []; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** Erreur presente ? **/ |
|
| 56 | + public bool $err = false; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Calcul du total des elements |
|
| 60 | + * |
|
| 61 | + * @var int|null |
|
| 62 | + **/ |
|
| 63 | + public $total = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * selectionner les donnees, ie faire la requete SQL |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + protected function select() { |
|
| 71 | + $this->row = null; |
|
| 72 | + $v = &$this->command; |
|
| 73 | + $this->sqlresult = calculer_select( |
|
| 74 | + $v['select'], |
|
| 75 | + $v['from'], |
|
| 76 | + $v['type'], |
|
| 77 | + $v['where'], |
|
| 78 | + $v['join'], |
|
| 79 | + $v['groupby'], |
|
| 80 | + $v['orderby'], |
|
| 81 | + $v['limit'], |
|
| 82 | + $v['having'], |
|
| 83 | + $v['table'], |
|
| 84 | + $v['id'], |
|
| 85 | + $v['connect'], |
|
| 86 | + $this->info |
|
| 87 | + ); |
|
| 88 | + $this->err = !$this->sqlresult; |
|
| 89 | + $this->firstseek = false; |
|
| 90 | + $this->pos = -1; |
|
| 91 | + |
|
| 92 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | + //$this->total = $this->count(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /* |
|
| 97 | 97 | * array command: les commandes d'initialisation |
| 98 | 98 | * array info: les infos sur le squelette |
| 99 | 99 | */ |
| 100 | - public function __construct($command, $info = []) { |
|
| 101 | - $this->type = 'SQL'; |
|
| 102 | - $this->command = $command; |
|
| 103 | - $this->info = $info; |
|
| 104 | - $this->select(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Rembobiner |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function rewind(): void { |
|
| 113 | - if ($this->pos > 0) { |
|
| 114 | - $this->seek(0); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Verifier l'etat de l'iterateur |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function valid(): bool { |
|
| 124 | - if ($this->err) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - if (!$this->firstseek) { |
|
| 128 | - $this->next(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return is_array($this->row); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Valeurs sur la position courante |
|
| 136 | - * |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - #[\ReturnTypeWillChange] |
|
| 140 | - public function current() { |
|
| 141 | - return $this->row; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - #[\ReturnTypeWillChange] |
|
| 145 | - public function key() { |
|
| 146 | - return $this->pos; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Sauter a une position absolue |
|
| 151 | - * |
|
| 152 | - * @param int $n |
|
| 153 | - * @param null|string $continue |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public function seek($n = 0, $continue = null) { |
|
| 157 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | - // si la position courante est apres la position visee |
|
| 160 | - // il faut relancer la requete |
|
| 161 | - if ($this->pos > $n) { |
|
| 162 | - $this->free(); |
|
| 163 | - $this->select(); |
|
| 164 | - $this->valid(); |
|
| 165 | - } |
|
| 166 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | - // (sera fait en cas d'echec de cette fonction) |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | - $this->pos = min($n, $this->count()); |
|
| 172 | - |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Avancer d'un cran |
|
| 178 | - * |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - public function next(): void { |
|
| 182 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | - $this->pos++; |
|
| 184 | - $this->firstseek |= true; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | - * |
|
| 190 | - * @return array|bool|null |
|
| 191 | - */ |
|
| 192 | - public function fetch() { |
|
| 193 | - if ($this->valid()) { |
|
| 194 | - $r = $this->current(); |
|
| 195 | - $this->next(); |
|
| 196 | - } else { |
|
| 197 | - $r = false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $r; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * liberer les ressources |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - public function free() { |
|
| 209 | - if (!$this->sqlresult) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | - $this->sqlresult = null; |
|
| 214 | - |
|
| 215 | - return $a; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Compter le nombre de resultats |
|
| 220 | - * |
|
| 221 | - * @return int |
|
| 222 | - */ |
|
| 223 | - public function count() { |
|
| 224 | - if (is_null($this->total)) { |
|
| 225 | - if (!$this->sqlresult) { |
|
| 226 | - $this->total = 0; |
|
| 227 | - } else { |
|
| 228 | - # cas count(*) |
|
| 229 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | - $this->valid(); |
|
| 231 | - $s = $this->current(); |
|
| 232 | - $this->total = $s['count(*)']; |
|
| 233 | - } else { |
|
| 234 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $this->total; |
|
| 240 | - } |
|
| 100 | + public function __construct($command, $info = []) { |
|
| 101 | + $this->type = 'SQL'; |
|
| 102 | + $this->command = $command; |
|
| 103 | + $this->info = $info; |
|
| 104 | + $this->select(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Rembobiner |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function rewind(): void { |
|
| 113 | + if ($this->pos > 0) { |
|
| 114 | + $this->seek(0); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Verifier l'etat de l'iterateur |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function valid(): bool { |
|
| 124 | + if ($this->err) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + if (!$this->firstseek) { |
|
| 128 | + $this->next(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return is_array($this->row); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Valeurs sur la position courante |
|
| 136 | + * |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + #[\ReturnTypeWillChange] |
|
| 140 | + public function current() { |
|
| 141 | + return $this->row; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + #[\ReturnTypeWillChange] |
|
| 145 | + public function key() { |
|
| 146 | + return $this->pos; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Sauter a une position absolue |
|
| 151 | + * |
|
| 152 | + * @param int $n |
|
| 153 | + * @param null|string $continue |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public function seek($n = 0, $continue = null) { |
|
| 157 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | + // si la position courante est apres la position visee |
|
| 160 | + // il faut relancer la requete |
|
| 161 | + if ($this->pos > $n) { |
|
| 162 | + $this->free(); |
|
| 163 | + $this->select(); |
|
| 164 | + $this->valid(); |
|
| 165 | + } |
|
| 166 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | + // (sera fait en cas d'echec de cette fonction) |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | + $this->pos = min($n, $this->count()); |
|
| 172 | + |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Avancer d'un cran |
|
| 178 | + * |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + public function next(): void { |
|
| 182 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | + $this->pos++; |
|
| 184 | + $this->firstseek |= true; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | + * |
|
| 190 | + * @return array|bool|null |
|
| 191 | + */ |
|
| 192 | + public function fetch() { |
|
| 193 | + if ($this->valid()) { |
|
| 194 | + $r = $this->current(); |
|
| 195 | + $this->next(); |
|
| 196 | + } else { |
|
| 197 | + $r = false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $r; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * liberer les ressources |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + public function free() { |
|
| 209 | + if (!$this->sqlresult) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | + $this->sqlresult = null; |
|
| 214 | + |
|
| 215 | + return $a; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Compter le nombre de resultats |
|
| 220 | + * |
|
| 221 | + * @return int |
|
| 222 | + */ |
|
| 223 | + public function count() { |
|
| 224 | + if (is_null($this->total)) { |
|
| 225 | + if (!$this->sqlresult) { |
|
| 226 | + $this->total = 0; |
|
| 227 | + } else { |
|
| 228 | + # cas count(*) |
|
| 229 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | + $this->valid(); |
|
| 231 | + $s = $this->current(); |
|
| 232 | + $this->total = $s['count(*)']; |
|
| 233 | + } else { |
|
| 234 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $this->total; |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -42,234 +42,234 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 44 | 44 | |
| 45 | - $skel = null; |
|
| 46 | - $boucle = null; |
|
| 47 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | - |
|
| 49 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | - if (function_exists($nom)) { |
|
| 51 | - return $nom; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 55 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | - |
|
| 60 | - // si squelette est deja compile et perenne, le charger |
|
| 61 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | - include_once $phpfile; |
|
| 63 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | - ## eval('?'.'>'.$skel_code); |
|
| 67 | - # spip_log($skel_code, 'comp') |
|
| 68 | - #} |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | - include_once $lib; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | - |
|
| 77 | - if (function_exists($nom)) { |
|
| 78 | - return $nom; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // charger le source, si possible, et compiler |
|
| 82 | - $skel_code = ''; |
|
| 83 | - if (lire_fichier($source, $skel)) { |
|
| 84 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | - if (!$skel_code) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - foreach ($skel_code as $id => $boucle) { |
|
| 94 | - $f = $boucle->return; |
|
| 95 | - try { |
|
| 96 | - eval("return true; $f ;"); |
|
| 97 | - } catch (\ParseError $e) { |
|
| 98 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | - erreur_squelette($msg, $boucle); |
|
| 101 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | - // mais prevenir que c'est mort |
|
| 103 | - $nom = ''; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Contexte de compil inutile a present |
|
| 107 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | - $skel_code[$id] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $code = ''; |
|
| 112 | - if ($nom) { |
|
| 113 | - // Si le code est bon, concatener et mettre en cache |
|
| 114 | - if (function_exists($nom)) { |
|
| 115 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | - } else { |
|
| 117 | - // code semantiquement faux: bug du compilateur |
|
| 118 | - // $boucle est en fait ici la fct principale du squelette |
|
| 119 | - $msg = _T('zbug_erreur_compilation'); |
|
| 120 | - erreur_squelette($msg, $boucle); |
|
| 121 | - $nom = ''; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 126 | - // Tracer ce qui vient d'etre compile |
|
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | - |
|
| 129 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | - if ( |
|
| 131 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | - and (_request('var_mode_objet') == $nom) |
|
| 133 | - and (_request('var_mode_affiche') == 'code') |
|
| 134 | - ) { |
|
| 135 | - erreur_squelette(); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $nom ?: false; |
|
| 45 | + $skel = null; |
|
| 46 | + $boucle = null; |
|
| 47 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | + |
|
| 49 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | + if (function_exists($nom)) { |
|
| 51 | + return $nom; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 55 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | + |
|
| 60 | + // si squelette est deja compile et perenne, le charger |
|
| 61 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | + include_once $phpfile; |
|
| 63 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | + ## eval('?'.'>'.$skel_code); |
|
| 67 | + # spip_log($skel_code, 'comp') |
|
| 68 | + #} |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | + include_once $lib; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | + |
|
| 77 | + if (function_exists($nom)) { |
|
| 78 | + return $nom; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // charger le source, si possible, et compiler |
|
| 82 | + $skel_code = ''; |
|
| 83 | + if (lire_fichier($source, $skel)) { |
|
| 84 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | + if (!$skel_code) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + foreach ($skel_code as $id => $boucle) { |
|
| 94 | + $f = $boucle->return; |
|
| 95 | + try { |
|
| 96 | + eval("return true; $f ;"); |
|
| 97 | + } catch (\ParseError $e) { |
|
| 98 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | + erreur_squelette($msg, $boucle); |
|
| 101 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | + // mais prevenir que c'est mort |
|
| 103 | + $nom = ''; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Contexte de compil inutile a present |
|
| 107 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | + $skel_code[$id] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $code = ''; |
|
| 112 | + if ($nom) { |
|
| 113 | + // Si le code est bon, concatener et mettre en cache |
|
| 114 | + if (function_exists($nom)) { |
|
| 115 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | + } else { |
|
| 117 | + // code semantiquement faux: bug du compilateur |
|
| 118 | + // $boucle est en fait ici la fct principale du squelette |
|
| 119 | + $msg = _T('zbug_erreur_compilation'); |
|
| 120 | + erreur_squelette($msg, $boucle); |
|
| 121 | + $nom = ''; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 126 | + // Tracer ce qui vient d'etre compile |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | + |
|
| 129 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | + if ( |
|
| 131 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | + and (_request('var_mode_objet') == $nom) |
|
| 133 | + and (_request('var_mode_affiche') == 'code') |
|
| 134 | + ) { |
|
| 135 | + erreur_squelette(); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $nom ?: false; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 143 | 143 | |
| 144 | - $code = null; |
|
| 145 | - // Le dernier index est '' (fonction principale) |
|
| 146 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | - if (CODE_COMMENTE) { |
|
| 148 | - $code = " |
|
| 144 | + $code = null; |
|
| 145 | + // Le dernier index est '' (fonction principale) |
|
| 146 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | + if (CODE_COMMENTE) { |
|
| 148 | + $code = " |
|
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | 151 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 152 | 152 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 153 | 153 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 154 | 154 | */ '; |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 159 | - ecrire_fichier($phpfile, $code); |
|
| 160 | - } |
|
| 157 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 159 | + ecrire_fichier($phpfile, $code); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $code; |
|
| 162 | + return $code; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Le squelette compile est-il trop vieux ? |
| 166 | 166 | function squelette_obsolete($skel, $squelette) { |
| 167 | - static $date_change = null; |
|
| 168 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | - // par hit |
|
| 170 | - if (is_null($date_change)) { |
|
| 171 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | - $date_change = @filemtime($fonc); |
|
| 173 | - } # compatibilite |
|
| 174 | - if (defined('_FILE_OPTIONS')) { |
|
| 175 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return ( |
|
| 180 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 181 | - or !@file_exists($skel) |
|
| 182 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 183 | - > ($date = @filemtime($skel))) |
|
| 184 | - or ($date_change > $date) |
|
| 185 | - ); |
|
| 167 | + static $date_change = null; |
|
| 168 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | + // par hit |
|
| 170 | + if (is_null($date_change)) { |
|
| 171 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | + $date_change = @filemtime($fonc); |
|
| 173 | + } # compatibilite |
|
| 174 | + if (defined('_FILE_OPTIONS')) { |
|
| 175 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return ( |
|
| 180 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 181 | + or !@file_exists($skel) |
|
| 182 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 183 | + > ($date = @filemtime($skel))) |
|
| 184 | + or ($date_change > $date) |
|
| 185 | + ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Activer l'invalideur de session |
| 189 | 189 | function invalideur_session(&$Cache, $code = null) { |
| 190 | - $Cache['session'] = spip_session(); |
|
| 190 | + $Cache['session'] = spip_session(); |
|
| 191 | 191 | |
| 192 | - return $code; |
|
| 192 | + return $code; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 197 | - static $filtres = []; |
|
| 198 | - $headers = []; |
|
| 199 | - $corps ??= ''; |
|
| 200 | - |
|
| 201 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | - if ( |
|
| 205 | - stripos($corps, 'header') !== false |
|
| 206 | - and preg_match_all( |
|
| 207 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | - $corps, |
|
| 209 | - $regs, |
|
| 210 | - PREG_SET_ORDER |
|
| 211 | - ) |
|
| 212 | - ) { |
|
| 213 | - foreach ($regs as $r) { |
|
| 214 | - $corps = str_replace($r[0], '', $corps); |
|
| 215 | - # $j = Content-Type, et pas content-TYPE. |
|
| 216 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | - |
|
| 218 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 220 | - } else { |
|
| 221 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | - $process_ins = ( |
|
| 227 | - strpos($corps, '<' . '?') === false |
|
| 228 | - or |
|
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | - ) |
|
| 232 | - ? 'html' |
|
| 233 | - : 'php'; |
|
| 234 | - |
|
| 235 | - $skel = [ |
|
| 236 | - 'squelette' => $nom, |
|
| 237 | - 'source' => $source, |
|
| 238 | - 'process_ins' => $process_ins, |
|
| 239 | - 'invalideurs' => $cache, |
|
| 240 | - 'entetes' => $headers, |
|
| 241 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | - ]; |
|
| 243 | - |
|
| 244 | - // traiter #FILTRE{} et filtres |
|
| 245 | - if (!isset($filtres[$nom])) { |
|
| 246 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | - } |
|
| 248 | - $filtres_headers = []; |
|
| 249 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | - unset($headers['X-Spip-Filtre']); |
|
| 252 | - } |
|
| 253 | - if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 254 | - include_spip('public/sandbox'); |
|
| 255 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | - |
|
| 257 | - if ($process_ins == 'html') { |
|
| 258 | - $skel['process_ins'] = ( |
|
| 259 | - strpos($corps, '<' . '?') === false |
|
| 260 | - or |
|
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | - ) |
|
| 264 | - ? 'html' |
|
| 265 | - : 'php'; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $skel['entetes'] = $headers; |
|
| 270 | - $skel['texte'] = $corps; |
|
| 271 | - |
|
| 272 | - return $skel; |
|
| 197 | + static $filtres = []; |
|
| 198 | + $headers = []; |
|
| 199 | + $corps ??= ''; |
|
| 200 | + |
|
| 201 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | + if ( |
|
| 205 | + stripos($corps, 'header') !== false |
|
| 206 | + and preg_match_all( |
|
| 207 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | + $corps, |
|
| 209 | + $regs, |
|
| 210 | + PREG_SET_ORDER |
|
| 211 | + ) |
|
| 212 | + ) { |
|
| 213 | + foreach ($regs as $r) { |
|
| 214 | + $corps = str_replace($r[0], '', $corps); |
|
| 215 | + # $j = Content-Type, et pas content-TYPE. |
|
| 216 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | + |
|
| 218 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | + $headers[$j] .= '|' . $r[3]; |
|
| 220 | + } else { |
|
| 221 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | + $process_ins = ( |
|
| 227 | + strpos($corps, '<' . '?') === false |
|
| 228 | + or |
|
| 229 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | + ) |
|
| 232 | + ? 'html' |
|
| 233 | + : 'php'; |
|
| 234 | + |
|
| 235 | + $skel = [ |
|
| 236 | + 'squelette' => $nom, |
|
| 237 | + 'source' => $source, |
|
| 238 | + 'process_ins' => $process_ins, |
|
| 239 | + 'invalideurs' => $cache, |
|
| 240 | + 'entetes' => $headers, |
|
| 241 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | + ]; |
|
| 243 | + |
|
| 244 | + // traiter #FILTRE{} et filtres |
|
| 245 | + if (!isset($filtres[$nom])) { |
|
| 246 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | + } |
|
| 248 | + $filtres_headers = []; |
|
| 249 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | + unset($headers['X-Spip-Filtre']); |
|
| 252 | + } |
|
| 253 | + if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 254 | + include_spip('public/sandbox'); |
|
| 255 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | + |
|
| 257 | + if ($process_ins == 'html') { |
|
| 258 | + $skel['process_ins'] = ( |
|
| 259 | + strpos($corps, '<' . '?') === false |
|
| 260 | + or |
|
| 261 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | + ) |
|
| 264 | + ? 'html' |
|
| 265 | + : 'php'; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $skel['entetes'] = $headers; |
|
| 270 | + $skel['texte'] = $corps; |
|
| 271 | + |
|
| 272 | + return $skel; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 284 | 284 | if ($lang_select) lang_select(); |
| 285 | 285 | ?' |
| 286 | - . '>'); |
|
| 286 | + . '>'); |
|
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -303,35 +303,35 @@ discard block |
||
| 303 | 303 | * Code PHP pour inclure le squelette de la balise dynamique |
| 304 | 304 | **/ |
| 305 | 305 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 306 | - if ( |
|
| 307 | - strncmp($file, '/', 1) !== 0 |
|
| 308 | - // pas de lien symbolique sous Windows |
|
| 309 | - and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | - ) { |
|
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $lang = $context_compil[4]; |
|
| 315 | - if (preg_match(',\W,', $lang)) { |
|
| 316 | - $lang = ''; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $args = array_map('argumenter_squelette', $args); |
|
| 320 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | - } |
|
| 323 | - $args = join(', ', $args); |
|
| 324 | - |
|
| 325 | - $r = sprintf( |
|
| 326 | - CODE_INCLURE_BALISE, |
|
| 327 | - $file, |
|
| 328 | - $lang, |
|
| 329 | - $nom, |
|
| 330 | - $args, |
|
| 331 | - join(', ', array_map('_q', $context_compil)) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - return $r; |
|
| 306 | + if ( |
|
| 307 | + strncmp($file, '/', 1) !== 0 |
|
| 308 | + // pas de lien symbolique sous Windows |
|
| 309 | + and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | + ) { |
|
| 311 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $lang = $context_compil[4]; |
|
| 315 | + if (preg_match(',\W,', $lang)) { |
|
| 316 | + $lang = ''; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $args = array_map('argumenter_squelette', $args); |
|
| 320 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | + } |
|
| 323 | + $args = join(', ', $args); |
|
| 324 | + |
|
| 325 | + $r = sprintf( |
|
| 326 | + CODE_INCLURE_BALISE, |
|
| 327 | + $file, |
|
| 328 | + $lang, |
|
| 329 | + $nom, |
|
| 330 | + $args, |
|
| 331 | + join(', ', array_map('_q', $context_compil)) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + return $r; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | **/ |
| 350 | 350 | function argumenter_squelette($v) { |
| 351 | 351 | |
| 352 | - if (is_object($v)) { |
|
| 353 | - return var_export($v, true); |
|
| 354 | - } elseif (!is_array($v)) { |
|
| 355 | - return "'" . texte_script((string) $v) . "'"; |
|
| 356 | - } else { |
|
| 357 | - $out = []; |
|
| 358 | - foreach ($v as $k => $val) { |
|
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 363 | - } |
|
| 352 | + if (is_object($v)) { |
|
| 353 | + return var_export($v, true); |
|
| 354 | + } elseif (!is_array($v)) { |
|
| 355 | + return "'" . texte_script((string) $v) . "'"; |
|
| 356 | + } else { |
|
| 357 | + $out = []; |
|
| 358 | + foreach ($v as $k => $val) { |
|
| 359 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return 'array(' . join(', ', $out) . ')'; |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -379,13 +379,13 @@ discard block |
||
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | 381 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 382 | - if (test_espace_prive()) { |
|
| 383 | - return executer_balise_dynamique(...$args); |
|
| 384 | - } |
|
| 385 | - else { |
|
| 386 | - $str_args = base64_encode(serialize($args)); |
|
| 387 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 388 | - } |
|
| 382 | + if (test_espace_prive()) { |
|
| 383 | + return executer_balise_dynamique(...$args); |
|
| 384 | + } |
|
| 385 | + else { |
|
| 386 | + $str_args = base64_encode(serialize($args)); |
|
| 387 | + return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 388 | + } |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | |
@@ -416,87 +416,87 @@ discard block |
||
| 416 | 416 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 417 | 417 | **/ |
| 418 | 418 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 419 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 420 | - $nom_balise = $nom; |
|
| 421 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 422 | - $nom_balise_generique = ''; |
|
| 423 | - |
|
| 424 | - $appel_php_depuis_modele = false; |
|
| 425 | - if ( |
|
| 426 | - is_array($context_compil) |
|
| 427 | - and !is_numeric($context_compil[3]) |
|
| 428 | - and empty($context_compil[0]) |
|
| 429 | - and empty($context_compil[1]) |
|
| 430 | - and empty($context_compil[2]) |
|
| 431 | - and empty($context_compil[3]) |
|
| 432 | - ) { |
|
| 433 | - $appel_php_depuis_modele = true; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 437 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 438 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 439 | - // injecter en premier arg le nom de la balise |
|
| 440 | - array_unshift($args, $nom); |
|
| 441 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 442 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 443 | - $nom_balise = $nom_balise_generique; |
|
| 444 | - } |
|
| 445 | - unset($balise_generique); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - if (!$fonction_balise) { |
|
| 449 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 450 | - erreur_squelette($msg, $context_compil); |
|
| 451 | - |
|
| 452 | - return ''; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // retrouver le fichier qui a déclaré la fonction |
|
| 456 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 457 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 458 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 459 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 460 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 461 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 465 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 466 | - |
|
| 467 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 468 | - |
|
| 469 | - if (!is_array($r)) { |
|
| 470 | - return $r; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // verifier que la fonction dyn est la, |
|
| 474 | - // sinon se replier sur la generique si elle existe |
|
| 475 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 476 | - if ( |
|
| 477 | - $balise_generique = chercher_balise_generique($nom) |
|
| 478 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 479 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 480 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 481 | - ) { |
|
| 482 | - // et lui injecter en premier arg le nom de la balise |
|
| 483 | - array_unshift($r, $nom); |
|
| 484 | - $nom_balise = $nom_balise_generique; |
|
| 485 | - if (!_DIR_RESTREINT) { |
|
| 486 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 487 | - } |
|
| 488 | - } else { |
|
| 489 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 490 | - erreur_squelette($msg, $context_compil); |
|
| 491 | - |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if ($appel_php_depuis_modele) { |
|
| 497 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 498 | - } |
|
| 499 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 419 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 420 | + $nom_balise = $nom; |
|
| 421 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 422 | + $nom_balise_generique = ''; |
|
| 423 | + |
|
| 424 | + $appel_php_depuis_modele = false; |
|
| 425 | + if ( |
|
| 426 | + is_array($context_compil) |
|
| 427 | + and !is_numeric($context_compil[3]) |
|
| 428 | + and empty($context_compil[0]) |
|
| 429 | + and empty($context_compil[1]) |
|
| 430 | + and empty($context_compil[2]) |
|
| 431 | + and empty($context_compil[3]) |
|
| 432 | + ) { |
|
| 433 | + $appel_php_depuis_modele = true; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 437 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 438 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 439 | + // injecter en premier arg le nom de la balise |
|
| 440 | + array_unshift($args, $nom); |
|
| 441 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 442 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 443 | + $nom_balise = $nom_balise_generique; |
|
| 444 | + } |
|
| 445 | + unset($balise_generique); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + if (!$fonction_balise) { |
|
| 449 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 450 | + erreur_squelette($msg, $context_compil); |
|
| 451 | + |
|
| 452 | + return ''; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // retrouver le fichier qui a déclaré la fonction |
|
| 456 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 457 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 458 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 459 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 460 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 461 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 465 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 466 | + |
|
| 467 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 468 | + |
|
| 469 | + if (!is_array($r)) { |
|
| 470 | + return $r; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // verifier que la fonction dyn est la, |
|
| 474 | + // sinon se replier sur la generique si elle existe |
|
| 475 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 476 | + if ( |
|
| 477 | + $balise_generique = chercher_balise_generique($nom) |
|
| 478 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 479 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 480 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 481 | + ) { |
|
| 482 | + // et lui injecter en premier arg le nom de la balise |
|
| 483 | + array_unshift($r, $nom); |
|
| 484 | + $nom_balise = $nom_balise_generique; |
|
| 485 | + if (!_DIR_RESTREINT) { |
|
| 486 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 487 | + } |
|
| 488 | + } else { |
|
| 489 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 490 | + erreur_squelette($msg, $context_compil); |
|
| 491 | + |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if ($appel_php_depuis_modele) { |
|
| 497 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 498 | + } |
|
| 499 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -511,23 +511,23 @@ discard block |
||
| 511 | 511 | * @return array|null |
| 512 | 512 | */ |
| 513 | 513 | function chercher_balise_generique($nom) { |
| 514 | - if (false === strpos($nom, '_')) { |
|
| 515 | - return null; |
|
| 516 | - } |
|
| 517 | - $nom_generique = $nom; |
|
| 518 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 519 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 520 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 521 | - if ($fonction_generique) { |
|
| 522 | - return [ |
|
| 523 | - 'nom' => $nom, |
|
| 524 | - 'nom_generique' => $nom_generique, |
|
| 525 | - 'fonction_generique' => $fonction_generique, |
|
| 526 | - ]; |
|
| 527 | - } |
|
| 528 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 529 | - } |
|
| 530 | - return null; |
|
| 514 | + if (false === strpos($nom, '_')) { |
|
| 515 | + return null; |
|
| 516 | + } |
|
| 517 | + $nom_generique = $nom; |
|
| 518 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 519 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 520 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 521 | + if ($fonction_generique) { |
|
| 522 | + return [ |
|
| 523 | + 'nom' => $nom, |
|
| 524 | + 'nom_generique' => $nom_generique, |
|
| 525 | + 'fonction_generique' => $fonction_generique, |
|
| 526 | + ]; |
|
| 527 | + } |
|
| 528 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 529 | + } |
|
| 530 | + return null; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | |
@@ -551,50 +551,50 @@ discard block |
||
| 551 | 551 | * @return null; |
| 552 | 552 | **/ |
| 553 | 553 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 554 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 555 | - if ( |
|
| 556 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 557 | - and $lang_select !== 'oui' |
|
| 558 | - ) { |
|
| 559 | - $lang = $GLOBALS['spip_lang']; |
|
| 560 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 561 | - elseif (!strlen($lang)) { |
|
| 562 | - $lang = $GLOBALS['spip_lang']; |
|
| 563 | - } // Cas 3. l'objet est multilingue ! |
|
| 564 | - elseif ( |
|
| 565 | - $lang_select !== 'oui' |
|
| 566 | - and strlen($titre) > 10 |
|
| 567 | - and strpos($titre, '<multi>') !== false |
|
| 568 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 569 | - ) { |
|
| 570 | - $lang = $GLOBALS['spip_lang']; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 574 | - lang_select($lang); |
|
| 575 | - |
|
| 576 | - return; |
|
| 554 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 555 | + if ( |
|
| 556 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 557 | + and $lang_select !== 'oui' |
|
| 558 | + ) { |
|
| 559 | + $lang = $GLOBALS['spip_lang']; |
|
| 560 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 561 | + elseif (!strlen($lang)) { |
|
| 562 | + $lang = $GLOBALS['spip_lang']; |
|
| 563 | + } // Cas 3. l'objet est multilingue ! |
|
| 564 | + elseif ( |
|
| 565 | + $lang_select !== 'oui' |
|
| 566 | + and strlen($titre) > 10 |
|
| 567 | + and strpos($titre, '<multi>') !== false |
|
| 568 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 569 | + ) { |
|
| 570 | + $lang = $GLOBALS['spip_lang']; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 574 | + lang_select($lang); |
|
| 575 | + |
|
| 576 | + return; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
| 580 | 580 | // Si un tableau &doublons[articles] est passe en parametre, |
| 581 | 581 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 582 | 582 | function nettoyer_env_doublons($envd) { |
| 583 | - foreach ($envd as $table => $liste) { |
|
| 584 | - $n = ''; |
|
| 585 | - foreach (explode(',', $liste) as $val) { |
|
| 586 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 587 | - $n .= ',' . $val; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if (strlen($n)) { |
|
| 591 | - $envd[$table] = $n; |
|
| 592 | - } else { |
|
| 593 | - unset($envd[$table]); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return $envd; |
|
| 583 | + foreach ($envd as $table => $liste) { |
|
| 584 | + $n = ''; |
|
| 585 | + foreach (explode(',', $liste) as $val) { |
|
| 586 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 587 | + $n .= ',' . $val; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if (strlen($n)) { |
|
| 591 | + $envd[$table] = $n; |
|
| 592 | + } else { |
|
| 593 | + unset($envd[$table]); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return $envd; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -613,21 +613,21 @@ discard block |
||
| 613 | 613 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 614 | 614 | **/ |
| 615 | 615 | function match_self($w) { |
| 616 | - if (is_string($w)) { |
|
| 617 | - return false; |
|
| 618 | - } |
|
| 619 | - if (is_array($w)) { |
|
| 620 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 621 | - return $w; |
|
| 622 | - } |
|
| 623 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 624 | - if ($m = match_self($sw)) { |
|
| 625 | - return $m; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - return false; |
|
| 616 | + if (is_string($w)) { |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 619 | + if (is_array($w)) { |
|
| 620 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 621 | + return $w; |
|
| 622 | + } |
|
| 623 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 624 | + if ($m = match_self($sw)) { |
|
| 625 | + return $m; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + return false; |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -643,16 +643,16 @@ discard block |
||
| 643 | 643 | * est remplacée par son code. |
| 644 | 644 | **/ |
| 645 | 645 | function remplace_sous_requete($w, $sousrequete) { |
| 646 | - if (is_array($w)) { |
|
| 647 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 648 | - return $sousrequete; |
|
| 649 | - } |
|
| 650 | - foreach ($w as $k => $sw) { |
|
| 651 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return $w; |
|
| 646 | + if (is_array($w)) { |
|
| 647 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 648 | + return $sousrequete; |
|
| 649 | + } |
|
| 650 | + foreach ($w as $k => $sw) { |
|
| 651 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return $w; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -666,17 +666,17 @@ discard block |
||
| 666 | 666 | * - Conditions avec des sous requêtes |
| 667 | 667 | **/ |
| 668 | 668 | function trouver_sous_requetes($where) { |
| 669 | - $where_simples = []; |
|
| 670 | - $where_sous = []; |
|
| 671 | - foreach ($where as $k => $w) { |
|
| 672 | - if (match_self($w)) { |
|
| 673 | - $where_sous[$k] = $w; |
|
| 674 | - } else { |
|
| 675 | - $where_simples[$k] = $w; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return [$where_simples, $where_sous]; |
|
| 669 | + $where_simples = []; |
|
| 670 | + $where_sous = []; |
|
| 671 | + foreach ($where as $k => $w) { |
|
| 672 | + if (match_self($w)) { |
|
| 673 | + $where_sous[$k] = $w; |
|
| 674 | + } else { |
|
| 675 | + $where_simples[$k] = $w; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return [$where_simples, $where_sous]; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
@@ -702,292 +702,292 @@ discard block |
||
| 702 | 702 | * @return resource |
| 703 | 703 | */ |
| 704 | 704 | function calculer_select( |
| 705 | - $select = [], |
|
| 706 | - $from = [], |
|
| 707 | - $from_type = [], |
|
| 708 | - $where = [], |
|
| 709 | - $join = [], |
|
| 710 | - $groupby = [], |
|
| 711 | - $orderby = [], |
|
| 712 | - $limit = '', |
|
| 713 | - $having = [], |
|
| 714 | - $table = '', |
|
| 715 | - $id = '', |
|
| 716 | - $serveur = '', |
|
| 717 | - $requeter = true |
|
| 705 | + $select = [], |
|
| 706 | + $from = [], |
|
| 707 | + $from_type = [], |
|
| 708 | + $where = [], |
|
| 709 | + $join = [], |
|
| 710 | + $groupby = [], |
|
| 711 | + $orderby = [], |
|
| 712 | + $limit = '', |
|
| 713 | + $having = [], |
|
| 714 | + $table = '', |
|
| 715 | + $id = '', |
|
| 716 | + $serveur = '', |
|
| 717 | + $requeter = true |
|
| 718 | 718 | ) { |
| 719 | 719 | |
| 720 | - // retirer les criteres vides: |
|
| 721 | - // {X ?} avec X absent de l'URL |
|
| 722 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 723 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 724 | - $menage = false; |
|
| 725 | - foreach ($where as $k => $v) { |
|
| 726 | - if (is_array($v) and count($v)) { |
|
| 727 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 728 | - $op = false; |
|
| 729 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 730 | - $op = false; |
|
| 731 | - } else { |
|
| 732 | - $op = $v[0] ?: $v; |
|
| 733 | - } |
|
| 734 | - } else { |
|
| 735 | - $op = $v; |
|
| 736 | - } |
|
| 737 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 738 | - unset($where[$k]); |
|
| 739 | - $menage = true; |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 744 | - $groupby = array_diff($groupby, ['']); |
|
| 745 | - |
|
| 746 | - // remplacer les sous requetes recursives au calcul |
|
| 747 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 748 | - foreach ($where_sous as $k => $w) { |
|
| 749 | - $menage = true; |
|
| 750 | - // on recupere la sous requete |
|
| 751 | - $sous = match_self($w); |
|
| 752 | - if ($sous[0] == 'SELF') { |
|
| 753 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 754 | - array_push($where_simples, $sous[2]); |
|
| 755 | - $wheresub = [ |
|
| 756 | - $sous[2], |
|
| 757 | - '0=0' |
|
| 758 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 759 | - $jsub = $join; |
|
| 760 | - // trouver les jointures utiles a |
|
| 761 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 762 | - // ie L1.objet='article' |
|
| 763 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 764 | - $i = 0; |
|
| 765 | - do { |
|
| 766 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 767 | - [$sous[1] . ' AS id'], |
|
| 768 | - $from, |
|
| 769 | - $from_type, |
|
| 770 | - $wheresub, |
|
| 771 | - $jsub, |
|
| 772 | - [], |
|
| 773 | - [], |
|
| 774 | - '', |
|
| 775 | - $having, |
|
| 776 | - $table, |
|
| 777 | - $id, |
|
| 778 | - $serveur, |
|
| 779 | - false |
|
| 780 | - ) . ')'); |
|
| 781 | - if (!$i) { |
|
| 782 | - $i = 1; |
|
| 783 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 784 | - foreach ($join as $cle => $wj) { |
|
| 785 | - if ( |
|
| 786 | - (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 787 | - and strpos($wherestring, (string) "{$cle}.") !== false |
|
| 788 | - ) { |
|
| 789 | - $i = 0; |
|
| 790 | - $wheresub[] = $wj[3]; |
|
| 791 | - unset($jsub[$cle][3]); |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - } while ($i++ < 1); |
|
| 796 | - } |
|
| 797 | - if ($sous[0] == 'SUBSELECT') { |
|
| 798 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 799 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 800 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 801 | - $sous[1], # select |
|
| 802 | - $sous[2], #from |
|
| 803 | - [], #from_type |
|
| 804 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 805 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 806 | - [], #join |
|
| 807 | - $sous[4] ?: [], #groupby |
|
| 808 | - $sous[5] ?: [], #orderby |
|
| 809 | - $sous[6], #limit |
|
| 810 | - $sous[7] ?: [], #having |
|
| 811 | - $table, |
|
| 812 | - $id, |
|
| 813 | - $serveur, |
|
| 814 | - false |
|
| 815 | - ) . ')'); |
|
| 816 | - } |
|
| 817 | - array_pop($where_simples); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - foreach ($having as $k => $v) { |
|
| 821 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 822 | - unset($having[$k]); |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - // Installer les jointures. |
|
| 827 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 828 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 829 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 830 | - |
|
| 831 | - $afrom = []; |
|
| 832 | - $equiv = []; |
|
| 833 | - $k = count($join); |
|
| 834 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 835 | - $cle = $cledef; |
|
| 836 | - // le format de join est : |
|
| 837 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 838 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 839 | - if (count($join[$cle]) == 2) { |
|
| 840 | - $join[$cle][] = $join[$cle][1]; |
|
| 841 | - } |
|
| 842 | - if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 843 | - $join[$cle][] = ''; |
|
| 844 | - } |
|
| 845 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 846 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 847 | - // pour compat avec ancienne convention |
|
| 848 | - if (is_numeric($cle)) { |
|
| 849 | - $cle = "L$k"; |
|
| 850 | - } |
|
| 851 | - $cle_where_lie = "JOIN-$cle"; |
|
| 852 | - if ( |
|
| 853 | - !$menage |
|
| 854 | - or isset($afrom[$cle]) |
|
| 855 | - or calculer_jointnul($cle, $select) |
|
| 856 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 857 | - or calculer_jointnul($cle, $having) |
|
| 858 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 859 | - ) { |
|
| 860 | - // corriger les references non explicites dans select |
|
| 861 | - // ou groupby |
|
| 862 | - foreach ($select as $i => $s) { |
|
| 863 | - if ($s == $c) { |
|
| 864 | - $select[$i] = "$cle.$c AS $c"; |
|
| 865 | - break; |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - foreach ($groupby as $i => $g) { |
|
| 869 | - if ($g == $c) { |
|
| 870 | - $groupby[$i] = "$cle.$c"; |
|
| 871 | - break; |
|
| 872 | - } |
|
| 873 | - } |
|
| 874 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 875 | - // sans recours a preg_match |
|
| 876 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 877 | - $afrom[$t][$cle] = [ |
|
| 878 | - "\n" . |
|
| 879 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 880 | - $from[$cle], |
|
| 881 | - "AS $cle", |
|
| 882 | - 'ON (', |
|
| 883 | - "$cle.$c", |
|
| 884 | - '=', |
|
| 885 | - "$t.$carr", |
|
| 886 | - ($and ? 'AND ' . $and : '') . |
|
| 887 | - ')' |
|
| 888 | - ]; |
|
| 889 | - if (isset($afrom[$cle])) { |
|
| 890 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 891 | - unset($afrom[$cle]); |
|
| 892 | - } |
|
| 893 | - $equiv[] = $carr; |
|
| 894 | - } else { |
|
| 895 | - unset($join[$cledef]); |
|
| 896 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 897 | - unset($where_simples[$cle_where_lie]); |
|
| 898 | - unset($where[$cle_where_lie]); |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - unset($from[$cle]); |
|
| 902 | - $k--; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - if (count($afrom)) { |
|
| 906 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 907 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 908 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 909 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 910 | - // ou dans |
|
| 911 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 912 | - // qui comporte plusieurs jointures |
|
| 913 | - // ou dans |
|
| 914 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 915 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 916 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 917 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 918 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 919 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 920 | - |
|
| 921 | - $t = key($from); |
|
| 922 | - $c = current($from); |
|
| 923 | - reset($from); |
|
| 924 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 925 | - if ( |
|
| 926 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 927 | - calculer_jointnul($t, $select, $e) or |
|
| 928 | - calculer_jointnul($t, $join, $e) or |
|
| 929 | - calculer_jointnul($t, $where, $e) or |
|
| 930 | - calculer_jointnul($t, $orderby, $e) or |
|
| 931 | - calculer_jointnul($t, $groupby, $e) or |
|
| 932 | - calculer_jointnul($t, $having, $e)) |
|
| 933 | - && count($afrom[$t]) |
|
| 934 | - ) { |
|
| 935 | - $nfrom = reset($afrom[$t]); |
|
| 936 | - $nt = array_key_first($afrom[$t]); |
|
| 937 | - unset($from[$t]); |
|
| 938 | - $from[$nt] = $nfrom[1]; |
|
| 939 | - unset($afrom[$t][$nt]); |
|
| 940 | - $afrom[$nt] = $afrom[$t]; |
|
| 941 | - unset($afrom[$t]); |
|
| 942 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 943 | - $t = $nfrom[4]; |
|
| 944 | - $alias = ''; |
|
| 945 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 946 | - $oldcle = explode('.', $nfrom[6]); |
|
| 947 | - $oldcle = end($oldcle); |
|
| 948 | - $newcle = explode('.', $nfrom[4]); |
|
| 949 | - $newcle = end($newcle); |
|
| 950 | - if ($newcle != $oldcle) { |
|
| 951 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 952 | - // reprendre simplement ce AS |
|
| 953 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 954 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 955 | - $alias = ''; |
|
| 956 | - } else { |
|
| 957 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 961 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 962 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 963 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 964 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 965 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 966 | - } |
|
| 967 | - $from = reinjecte_joint($afrom, $from); |
|
| 968 | - } |
|
| 969 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 970 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 971 | - $GLOBALS['debug'] = []; |
|
| 972 | - if ($wasdebug) { |
|
| 973 | - $GLOBALS['debug']['debug'] = true; |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 977 | - $r = sql_select( |
|
| 978 | - $select, |
|
| 979 | - $from, |
|
| 980 | - $where, |
|
| 981 | - $groupby, |
|
| 982 | - array_filter($orderby), |
|
| 983 | - $limit, |
|
| 984 | - $having, |
|
| 985 | - $serveur, |
|
| 986 | - $requeter |
|
| 987 | - ); |
|
| 988 | - unset($GLOBALS['debug']['aucasou']); |
|
| 989 | - |
|
| 990 | - return $r; |
|
| 720 | + // retirer les criteres vides: |
|
| 721 | + // {X ?} avec X absent de l'URL |
|
| 722 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 723 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 724 | + $menage = false; |
|
| 725 | + foreach ($where as $k => $v) { |
|
| 726 | + if (is_array($v) and count($v)) { |
|
| 727 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 728 | + $op = false; |
|
| 729 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 730 | + $op = false; |
|
| 731 | + } else { |
|
| 732 | + $op = $v[0] ?: $v; |
|
| 733 | + } |
|
| 734 | + } else { |
|
| 735 | + $op = $v; |
|
| 736 | + } |
|
| 737 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 738 | + unset($where[$k]); |
|
| 739 | + $menage = true; |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 744 | + $groupby = array_diff($groupby, ['']); |
|
| 745 | + |
|
| 746 | + // remplacer les sous requetes recursives au calcul |
|
| 747 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 748 | + foreach ($where_sous as $k => $w) { |
|
| 749 | + $menage = true; |
|
| 750 | + // on recupere la sous requete |
|
| 751 | + $sous = match_self($w); |
|
| 752 | + if ($sous[0] == 'SELF') { |
|
| 753 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 754 | + array_push($where_simples, $sous[2]); |
|
| 755 | + $wheresub = [ |
|
| 756 | + $sous[2], |
|
| 757 | + '0=0' |
|
| 758 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 759 | + $jsub = $join; |
|
| 760 | + // trouver les jointures utiles a |
|
| 761 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 762 | + // ie L1.objet='article' |
|
| 763 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 764 | + $i = 0; |
|
| 765 | + do { |
|
| 766 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 767 | + [$sous[1] . ' AS id'], |
|
| 768 | + $from, |
|
| 769 | + $from_type, |
|
| 770 | + $wheresub, |
|
| 771 | + $jsub, |
|
| 772 | + [], |
|
| 773 | + [], |
|
| 774 | + '', |
|
| 775 | + $having, |
|
| 776 | + $table, |
|
| 777 | + $id, |
|
| 778 | + $serveur, |
|
| 779 | + false |
|
| 780 | + ) . ')'); |
|
| 781 | + if (!$i) { |
|
| 782 | + $i = 1; |
|
| 783 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 784 | + foreach ($join as $cle => $wj) { |
|
| 785 | + if ( |
|
| 786 | + (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 787 | + and strpos($wherestring, (string) "{$cle}.") !== false |
|
| 788 | + ) { |
|
| 789 | + $i = 0; |
|
| 790 | + $wheresub[] = $wj[3]; |
|
| 791 | + unset($jsub[$cle][3]); |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + } while ($i++ < 1); |
|
| 796 | + } |
|
| 797 | + if ($sous[0] == 'SUBSELECT') { |
|
| 798 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 799 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 800 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 801 | + $sous[1], # select |
|
| 802 | + $sous[2], #from |
|
| 803 | + [], #from_type |
|
| 804 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 805 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 806 | + [], #join |
|
| 807 | + $sous[4] ?: [], #groupby |
|
| 808 | + $sous[5] ?: [], #orderby |
|
| 809 | + $sous[6], #limit |
|
| 810 | + $sous[7] ?: [], #having |
|
| 811 | + $table, |
|
| 812 | + $id, |
|
| 813 | + $serveur, |
|
| 814 | + false |
|
| 815 | + ) . ')'); |
|
| 816 | + } |
|
| 817 | + array_pop($where_simples); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + foreach ($having as $k => $v) { |
|
| 821 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 822 | + unset($having[$k]); |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + // Installer les jointures. |
|
| 827 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 828 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 829 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 830 | + |
|
| 831 | + $afrom = []; |
|
| 832 | + $equiv = []; |
|
| 833 | + $k = count($join); |
|
| 834 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 835 | + $cle = $cledef; |
|
| 836 | + // le format de join est : |
|
| 837 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 838 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 839 | + if (count($join[$cle]) == 2) { |
|
| 840 | + $join[$cle][] = $join[$cle][1]; |
|
| 841 | + } |
|
| 842 | + if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 843 | + $join[$cle][] = ''; |
|
| 844 | + } |
|
| 845 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 846 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 847 | + // pour compat avec ancienne convention |
|
| 848 | + if (is_numeric($cle)) { |
|
| 849 | + $cle = "L$k"; |
|
| 850 | + } |
|
| 851 | + $cle_where_lie = "JOIN-$cle"; |
|
| 852 | + if ( |
|
| 853 | + !$menage |
|
| 854 | + or isset($afrom[$cle]) |
|
| 855 | + or calculer_jointnul($cle, $select) |
|
| 856 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 857 | + or calculer_jointnul($cle, $having) |
|
| 858 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 859 | + ) { |
|
| 860 | + // corriger les references non explicites dans select |
|
| 861 | + // ou groupby |
|
| 862 | + foreach ($select as $i => $s) { |
|
| 863 | + if ($s == $c) { |
|
| 864 | + $select[$i] = "$cle.$c AS $c"; |
|
| 865 | + break; |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + foreach ($groupby as $i => $g) { |
|
| 869 | + if ($g == $c) { |
|
| 870 | + $groupby[$i] = "$cle.$c"; |
|
| 871 | + break; |
|
| 872 | + } |
|
| 873 | + } |
|
| 874 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 875 | + // sans recours a preg_match |
|
| 876 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 877 | + $afrom[$t][$cle] = [ |
|
| 878 | + "\n" . |
|
| 879 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 880 | + $from[$cle], |
|
| 881 | + "AS $cle", |
|
| 882 | + 'ON (', |
|
| 883 | + "$cle.$c", |
|
| 884 | + '=', |
|
| 885 | + "$t.$carr", |
|
| 886 | + ($and ? 'AND ' . $and : '') . |
|
| 887 | + ')' |
|
| 888 | + ]; |
|
| 889 | + if (isset($afrom[$cle])) { |
|
| 890 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 891 | + unset($afrom[$cle]); |
|
| 892 | + } |
|
| 893 | + $equiv[] = $carr; |
|
| 894 | + } else { |
|
| 895 | + unset($join[$cledef]); |
|
| 896 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 897 | + unset($where_simples[$cle_where_lie]); |
|
| 898 | + unset($where[$cle_where_lie]); |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + unset($from[$cle]); |
|
| 902 | + $k--; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + if (count($afrom)) { |
|
| 906 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 907 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 908 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 909 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 910 | + // ou dans |
|
| 911 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 912 | + // qui comporte plusieurs jointures |
|
| 913 | + // ou dans |
|
| 914 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 915 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 916 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 917 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 918 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 919 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 920 | + |
|
| 921 | + $t = key($from); |
|
| 922 | + $c = current($from); |
|
| 923 | + reset($from); |
|
| 924 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 925 | + if ( |
|
| 926 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 927 | + calculer_jointnul($t, $select, $e) or |
|
| 928 | + calculer_jointnul($t, $join, $e) or |
|
| 929 | + calculer_jointnul($t, $where, $e) or |
|
| 930 | + calculer_jointnul($t, $orderby, $e) or |
|
| 931 | + calculer_jointnul($t, $groupby, $e) or |
|
| 932 | + calculer_jointnul($t, $having, $e)) |
|
| 933 | + && count($afrom[$t]) |
|
| 934 | + ) { |
|
| 935 | + $nfrom = reset($afrom[$t]); |
|
| 936 | + $nt = array_key_first($afrom[$t]); |
|
| 937 | + unset($from[$t]); |
|
| 938 | + $from[$nt] = $nfrom[1]; |
|
| 939 | + unset($afrom[$t][$nt]); |
|
| 940 | + $afrom[$nt] = $afrom[$t]; |
|
| 941 | + unset($afrom[$t]); |
|
| 942 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 943 | + $t = $nfrom[4]; |
|
| 944 | + $alias = ''; |
|
| 945 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 946 | + $oldcle = explode('.', $nfrom[6]); |
|
| 947 | + $oldcle = end($oldcle); |
|
| 948 | + $newcle = explode('.', $nfrom[4]); |
|
| 949 | + $newcle = end($newcle); |
|
| 950 | + if ($newcle != $oldcle) { |
|
| 951 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 952 | + // reprendre simplement ce AS |
|
| 953 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 954 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 955 | + $alias = ''; |
|
| 956 | + } else { |
|
| 957 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 961 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 962 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 963 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 964 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 965 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 966 | + } |
|
| 967 | + $from = reinjecte_joint($afrom, $from); |
|
| 968 | + } |
|
| 969 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 970 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 971 | + $GLOBALS['debug'] = []; |
|
| 972 | + if ($wasdebug) { |
|
| 973 | + $GLOBALS['debug']['debug'] = true; |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 977 | + $r = sql_select( |
|
| 978 | + $select, |
|
| 979 | + $from, |
|
| 980 | + $where, |
|
| 981 | + $groupby, |
|
| 982 | + array_filter($orderby), |
|
| 983 | + $limit, |
|
| 984 | + $having, |
|
| 985 | + $serveur, |
|
| 986 | + $requeter |
|
| 987 | + ); |
|
| 988 | + unset($GLOBALS['debug']['aucasou']); |
|
| 989 | + |
|
| 990 | + return $r; |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -998,79 +998,79 @@ discard block |
||
| 998 | 998 | * @return string |
| 999 | 999 | */ |
| 1000 | 1000 | function calculer_where_to_string($v, $join = 'AND') { |
| 1001 | - if (empty($v)) { |
|
| 1002 | - return ''; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - if (!is_array($v)) { |
|
| 1006 | - return $v; |
|
| 1007 | - } else { |
|
| 1008 | - $exp = ''; |
|
| 1009 | - if (strtoupper($join) === 'AND') { |
|
| 1010 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1011 | - } else { |
|
| 1012 | - return $exp . join($join, $v); |
|
| 1013 | - } |
|
| 1014 | - } |
|
| 1001 | + if (empty($v)) { |
|
| 1002 | + return ''; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + if (!is_array($v)) { |
|
| 1006 | + return $v; |
|
| 1007 | + } else { |
|
| 1008 | + $exp = ''; |
|
| 1009 | + if (strtoupper($join) === 'AND') { |
|
| 1010 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1011 | + } else { |
|
| 1012 | + return $exp . join($join, $v); |
|
| 1013 | + } |
|
| 1014 | + } |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | |
| 1018 | 1018 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1019 | 1019 | |
| 1020 | 1020 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1021 | - if (!is_array($exp)) { |
|
| 1022 | - if ($equiv) { |
|
| 1023 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1027 | - } else { |
|
| 1028 | - foreach ($exp as $v) { |
|
| 1029 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1030 | - return true; |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - return false; |
|
| 1035 | - } |
|
| 1021 | + if (!is_array($exp)) { |
|
| 1022 | + if ($equiv) { |
|
| 1023 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1027 | + } else { |
|
| 1028 | + foreach ($exp as $v) { |
|
| 1029 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1030 | + return true; |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + return false; |
|
| 1035 | + } |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | 1038 | function reinjecte_joint($afrom, $from) { |
| 1039 | - $from_synth = []; |
|
| 1040 | - foreach ($from as $k => $v) { |
|
| 1041 | - $from_synth[$k] = $from[$k]; |
|
| 1042 | - if (isset($afrom[$k])) { |
|
| 1043 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1044 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1045 | - } |
|
| 1046 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1047 | - unset($afrom[$k]); |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - return $from_synth; |
|
| 1039 | + $from_synth = []; |
|
| 1040 | + foreach ($from as $k => $v) { |
|
| 1041 | + $from_synth[$k] = $from[$k]; |
|
| 1042 | + if (isset($afrom[$k])) { |
|
| 1043 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1044 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1045 | + } |
|
| 1046 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1047 | + unset($afrom[$k]); |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + return $from_synth; |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1055 | - if (!is_array($exp)) { |
|
| 1056 | - return preg_replace($equiv, $cle, $exp); |
|
| 1057 | - } else { |
|
| 1058 | - foreach ($exp as $k => $v) { |
|
| 1059 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $exp; |
|
| 1063 | - } |
|
| 1055 | + if (!is_array($exp)) { |
|
| 1056 | + return preg_replace($equiv, $cle, $exp); |
|
| 1057 | + } else { |
|
| 1058 | + foreach ($exp as $k => $v) { |
|
| 1059 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $exp; |
|
| 1063 | + } |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | // calcul du nom du squelette |
| 1067 | 1067 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1068 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1069 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1070 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $mime_type |
|
| 1074 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1075 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1068 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1069 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1070 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $mime_type |
|
| 1074 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1075 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1076 | 1076 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 59 | 59 | |
| 60 | 60 | // si squelette est deja compile et perenne, le charger |
| 61 | 61 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | #} |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 72 | 72 | include_once $lib; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | eval("return true; $f ;"); |
| 97 | 97 | } catch (\ParseError $e) { |
| 98 | 98 | // Code syntaxiquement faux (critere etc mal programme') |
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 100 | 100 | erreur_squelette($msg, $boucle); |
| 101 | 101 | // continuer pour trouver d'autres fautes eventuelles |
| 102 | 102 | // mais prevenir que c'est mort |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 126 | 126 | // Tracer ce qui vient d'etre compile |
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 128 | 128 | |
| 129 | 129 | // si c'est ce que demande le debusqueur, lui passer la main |
| 130 | 130 | if ( |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | $code = " |
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 152 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 153 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 151 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 152 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 153 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 154 | 154 | */ '; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | + $code = '<'."?php\n".$code.join('', $boucles)."\n"; |
|
| 158 | 158 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 159 | 159 | ecrire_fichier($phpfile, $code); |
| 160 | 160 | } |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 217 | 217 | |
| 218 | 218 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | + $headers[$j] .= '|'.$r[3]; |
|
| 220 | 220 | } else { |
| 221 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + $headers[$j] = str_replace(['\\\\', "\\'", '\\"'], ['\\', "'", '"'], $r[3]); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | // S'agit-il d'un resultat constant ou contenant du code php |
| 226 | 226 | $process_ins = ( |
| 227 | - strpos($corps, '<' . '?') === false |
|
| 227 | + strpos($corps, '<'.'?') === false |
|
| 228 | 228 | or |
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 229 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 230 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 231 | 231 | ) |
| 232 | 232 | ? 'html' |
| 233 | 233 | : 'php'; |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | if ($process_ins == 'html') { |
| 258 | 258 | $skel['process_ins'] = ( |
| 259 | - strpos($corps, '<' . '?') === false |
|
| 259 | + strpos($corps, '<'.'?') === false |
|
| 260 | 260 | or |
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 261 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 262 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 263 | 263 | ) |
| 264 | 264 | ? 'html' |
| 265 | 265 | : 'php'; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | // |
| 278 | 278 | |
| 279 | 279 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 280 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 280 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 281 | 281 | include_once("%s"); |
| 282 | 282 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | // pas de lien symbolique sous Windows |
| 309 | 309 | and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
| 310 | 310 | ) { |
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $lang = $context_compil[4]; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | $args = array_map('argumenter_squelette', $args); |
| 320 | 320 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 322 | 322 | } |
| 323 | 323 | $args = join(', ', $args); |
| 324 | 324 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | if (is_object($v)) { |
| 353 | 353 | return var_export($v, true); |
| 354 | 354 | } elseif (!is_array($v)) { |
| 355 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + return "'".texte_script((string) $v)."'"; |
|
| 356 | 356 | } else { |
| 357 | 357 | $out = []; |
| 358 | 358 | foreach ($v as $k => $val) { |
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + return 'array('.join(', ', $out).')'; |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | else { |
| 386 | 386 | $str_args = base64_encode(serialize($args)); |
| 387 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | + return "<?"."php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // Y a-t-il une fonction de traitement des arguments ? |
| 465 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 466 | 466 | |
| 467 | 467 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 468 | 468 | |
@@ -472,18 +472,18 @@ discard block |
||
| 472 | 472 | |
| 473 | 473 | // verifier que la fonction dyn est la, |
| 474 | 474 | // sinon se replier sur la generique si elle existe |
| 475 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 476 | 476 | if ( |
| 477 | 477 | $balise_generique = chercher_balise_generique($nom) |
| 478 | 478 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 479 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 480 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 479 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 480 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 481 | 481 | ) { |
| 482 | 482 | // et lui injecter en premier arg le nom de la balise |
| 483 | 483 | array_unshift($r, $nom); |
| 484 | 484 | $nom_balise = $nom_balise_generique; |
| 485 | 485 | if (!_DIR_RESTREINT) { |
| 486 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 487 | 487 | } |
| 488 | 488 | } else { |
| 489 | 489 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | $n = ''; |
| 585 | 585 | foreach (explode(',', $liste) as $val) { |
| 586 | 586 | if ($a = intval($val) and $val === strval($a)) { |
| 587 | - $n .= ',' . $val; |
|
| 587 | + $n .= ','.$val; |
|
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | if (strlen($n)) { |
@@ -763,8 +763,8 @@ discard block |
||
| 763 | 763 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 764 | 764 | $i = 0; |
| 765 | 765 | do { |
| 766 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 767 | - [$sous[1] . ' AS id'], |
|
| 766 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 767 | + [$sous[1].' AS id'], |
|
| 768 | 768 | $from, |
| 769 | 769 | $from_type, |
| 770 | 770 | $wheresub, |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | $id, |
| 778 | 778 | $serveur, |
| 779 | 779 | false |
| 780 | - ) . ')'); |
|
| 780 | + ).')'); |
|
| 781 | 781 | if (!$i) { |
| 782 | 782 | $i = 1; |
| 783 | 783 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | if ($sous[0] == 'SUBSELECT') { |
| 798 | 798 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 799 | 799 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 800 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 801 | 801 | $sous[1], # select |
| 802 | 802 | $sous[2], #from |
| 803 | 803 | [], #from_type |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | $id, |
| 813 | 813 | $serveur, |
| 814 | 814 | false |
| 815 | - ) . ')'); |
|
| 815 | + ).')'); |
|
| 816 | 816 | } |
| 817 | 817 | array_pop($where_simples); |
| 818 | 818 | } |
@@ -875,15 +875,15 @@ discard block |
||
| 875 | 875 | // sans recours a preg_match |
| 876 | 876 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 877 | 877 | $afrom[$t][$cle] = [ |
| 878 | - "\n" . |
|
| 879 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 878 | + "\n". |
|
| 879 | + ($from_type[$cle] ?? 'INNER').' JOIN', |
|
| 880 | 880 | $from[$cle], |
| 881 | 881 | "AS $cle", |
| 882 | 882 | 'ON (', |
| 883 | 883 | "$cle.$c", |
| 884 | 884 | '=', |
| 885 | 885 | "$t.$carr", |
| 886 | - ($and ? 'AND ' . $and : '') . |
|
| 886 | + ($and ? 'AND '.$and : ''). |
|
| 887 | 887 | ')' |
| 888 | 888 | ]; |
| 889 | 889 | if (isset($afrom[$cle])) { |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | $t = key($from); |
| 922 | 922 | $c = current($from); |
| 923 | 923 | reset($from); |
| 924 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 925 | 925 | if ( |
| 926 | 926 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 927 | 927 | calculer_jointnul($t, $select, $e) or |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | unset($afrom[$t][$nt]); |
| 940 | 940 | $afrom[$nt] = $afrom[$t]; |
| 941 | 941 | unset($afrom[$t]); |
| 942 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 943 | 943 | $t = $nfrom[4]; |
| 944 | 944 | $alias = ''; |
| 945 | 945 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -950,14 +950,14 @@ discard block |
||
| 950 | 950 | if ($newcle != $oldcle) { |
| 951 | 951 | // si l'ancienne cle etait deja dans le select avec un AS |
| 952 | 952 | // reprendre simplement ce AS |
| 953 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 954 | 954 | if (preg_match($as, implode(',', $select), $m)) { |
| 955 | 955 | $alias = ''; |
| 956 | 956 | } else { |
| 957 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 958 | 958 | } |
| 959 | 959 | } |
| 960 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 961 | 961 | $join = remplacer_jointnul($t, $join, $e); |
| 962 | 962 | $where = remplacer_jointnul($t, $where, $e); |
| 963 | 963 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1007,9 +1007,9 @@ discard block |
||
| 1007 | 1007 | } else { |
| 1008 | 1008 | $exp = ''; |
| 1009 | 1009 | if (strtoupper($join) === 'AND') { |
| 1010 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1011 | 1011 | } else { |
| 1012 | - return $exp . join($join, $v); |
|
| 1012 | + return $exp.join($join, $v); |
|
| 1013 | 1013 | } |
| 1014 | 1014 | } |
| 1015 | 1015 | } |
@@ -1071,6 +1071,6 @@ discard block |
||
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | return $mime_type |
| 1074 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1075 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1074 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1075 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1076 | 1076 | } |
@@ -381,8 +381,7 @@ |
||
| 381 | 381 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 382 | 382 | if (test_espace_prive()) { |
| 383 | 383 | return executer_balise_dynamique(...$args); |
| 384 | - } |
|
| 385 | - else { |
|
| 384 | + } else { |
|
| 386 | 385 | $str_args = base64_encode(serialize($args)); |
| 387 | 386 | return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
| 388 | 387 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | if (!$fonc) { |
| 148 | 148 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 149 | 149 | } |
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 150 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' '.$GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | 151 | } |
| 152 | 152 | if ($message === false) { |
| 153 | 153 | lang_select(); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $fond = $GLOBALS['fond'] ?? ''; |
| 177 | 177 | // une erreur critique sort $message en array |
| 178 | 178 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 179 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 179 | + spip_log('Debug: '.$debug.' ('.$fond.')'); |
|
| 180 | 180 | |
| 181 | 181 | return $msg; |
| 182 | 182 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | 186 | if (!empty($erreurs)) { |
| 187 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 187 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0).' '._T('zbug_erreur_squelette')]; |
|
| 188 | 188 | |
| 189 | 189 | return debusquer_navigation($erreurs, $n); |
| 190 | 190 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -217,25 +217,25 @@ discard block |
||
| 217 | 217 | $valeur_simple = []; |
| 218 | 218 | foreach ($valeur as $v) { |
| 219 | 219 | if (is_array($v)) { |
| 220 | - $valeur_simple[] = 'array:' . count($v); |
|
| 220 | + $valeur_simple[] = 'array:'.count($v); |
|
| 221 | 221 | } elseif (is_object($v)) { |
| 222 | 222 | $valeur_simple[] = get_class($v); |
| 223 | 223 | } elseif (is_string($v)) { |
| 224 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 224 | + $valeur_simple[] = "'".$v."'"; |
|
| 225 | 225 | } else { |
| 226 | 226 | $valeur_simple[] = $v; |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | $n = count($valeur); |
| 230 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 230 | + $valeur = (($n > 3) ? 'array:'.$n.' ' : ''); |
|
| 231 | + $valeur .= '['.join(', ', $valeur_simple).']'; |
|
| 232 | 232 | } elseif (is_object($valeur)) { |
| 233 | 233 | $valeur = get_class($valeur); |
| 234 | 234 | } elseif (is_string($valeur)) { |
| 235 | - $valeur = "'" . $valeur . "'"; |
|
| 235 | + $valeur = "'".$valeur."'"; |
|
| 236 | 236 | } |
| 237 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 238 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 237 | + $res .= "\n<tr><td><strong>".nl2br((string) entites_html($nom)) |
|
| 238 | + . '</strong></td><td>: '.nl2br((string) entites_html($valeur)) |
|
| 239 | 239 | . "</td></tr>\n"; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | if ($ligne) { |
| 261 | 261 | $msg .= " L$ligne"; |
| 262 | 262 | } |
| 263 | - spip_log($msg, "debusquer" . _LOG_ERREUR); |
|
| 263 | + spip_log($msg, "debusquer"._LOG_ERREUR); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | $nom_code = $lieu->descr['nom']; |
| 286 | 286 | $skel = $lieu->descr['sourcefile']; |
| 287 | 287 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 288 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 288 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 289 | 289 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 290 | 290 | if ($boucle) { |
| 291 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 291 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 292 | 292 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 293 | 293 | } |
| 294 | 294 | } |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | // Requete erronee |
| 380 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 380 | + $err = '<b>'._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 381 | 381 | . spip_htmlspecialchars($msg) |
| 382 | 382 | . "\n<br /><span style='color: red'><b>" |
| 383 | 383 | . spip_htmlspecialchars($query) |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 393 | 393 | |
| 394 | - $id = $nom . $boucle; |
|
| 394 | + $id = $nom.$boucle; |
|
| 395 | 395 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 396 | 396 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 397 | 397 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 440 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 441 | 441 | |
| 442 | 442 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 443 | 443 | if (preg_match($incl, $v)) { |
@@ -452,16 +452,13 @@ discard block |
||
| 452 | 452 | [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
| 453 | 453 | |
| 454 | 454 | if (!$boucle) { |
| 455 | - return !$ligne ? '' : |
|
| 456 | - (' (' . |
|
| 457 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 458 | - _T('squelette_ligne')) . |
|
| 455 | + return !$ligne ? '' : (' ('. |
|
| 456 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 459 | 457 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 460 | 458 | } else { |
| 461 | 459 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 462 | 460 | |
| 463 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 464 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 461 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 465 | 462 | } |
| 466 | 463 | } |
| 467 | 464 | |
@@ -483,14 +480,14 @@ discard block |
||
| 483 | 480 | |
| 484 | 481 | $s = preg_replace( |
| 485 | 482 | ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 486 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 483 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 487 | 484 | $s |
| 488 | 485 | ); |
| 489 | 486 | |
| 490 | 487 | |
| 491 | 488 | $tableau = explode('<br />', $s); |
| 492 | 489 | |
| 493 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 490 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: ".($nocpt ? 'hidden' : 'visible').";%s' href='#T%s' title=\"%s\">%0".strval(@strlen(count($tableau)))."d</a></span> %s<br />\n"; |
|
| 494 | 491 | |
| 495 | 492 | $format10 = str_replace('white', 'lightgrey', $format); |
| 496 | 493 | $formaterr = 'color: red;'; |
@@ -534,7 +531,7 @@ discard block |
||
| 534 | 531 | . '" style="cursor: pointer;">' |
| 535 | 532 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 536 | 533 | . '</div> |
| 537 | - ' . $res . "</div>\n"; |
|
| 534 | + ' . $res."</div>\n"; |
|
| 538 | 535 | } |
| 539 | 536 | |
| 540 | 537 | // l'environnement graphique du debuggueur |
@@ -556,14 +553,14 @@ discard block |
||
| 556 | 553 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 557 | 554 | [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
| 558 | 555 | $texte .= $res2; |
| 559 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 560 | - $legend = _T('zbug_' . $mode); |
|
| 561 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 556 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 557 | + $legend = _T('zbug_'.$mode); |
|
| 558 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 562 | 559 | $texte = ancre_texte($texte, ['', '']); |
| 563 | 560 | } |
| 564 | 561 | } else { |
| 565 | 562 | if (strlen(trim($res))) { |
| 566 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 563 | + return "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 567 | 564 | } else { |
| 568 | 565 | // cas de l'appel sur erreur: montre la page |
| 569 | 566 | return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
@@ -571,7 +568,7 @@ discard block |
||
| 571 | 568 | } |
| 572 | 569 | } else { |
| 573 | 570 | $valider = charger_fonction('valider', 'xml'); |
| 574 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 571 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 575 | 572 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 576 | 573 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 577 | 574 | [$texte, $err] = emboite_texte($val, $fonc, $self); |
@@ -582,14 +579,14 @@ discard block |
||
| 582 | 579 | } else { |
| 583 | 580 | $err = ": $err"; |
| 584 | 581 | } |
| 585 | - $legend = _T('validation') . ' ' . $err; |
|
| 582 | + $legend = _T('validation').' '.$err; |
|
| 586 | 583 | $res = $id = ''; |
| 587 | 584 | } |
| 588 | 585 | |
| 589 | 586 | return !trim($texte) ? '' : ( |
| 590 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 587 | + "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 591 | 588 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 592 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 589 | + . "<a href='".$self.'#f_'.substr($fonc, 0, 37)."'> ↑ " |
|
| 593 | 590 | . ($legend ?: $mode) |
| 594 | 591 | . '</a></legend>' |
| 595 | 592 | . $texte |
@@ -600,7 +597,7 @@ discard block |
||
| 600 | 597 | |
| 601 | 598 | function emboite_texte($res, $fonc = '', $self = '') { |
| 602 | 599 | $errs = $res->err; |
| 603 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 600 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 604 | 601 | |
| 605 | 602 | if (!$texte and !$errs) { |
| 606 | 603 | return [ancre_texte('', ['', '']), false]; |
@@ -656,7 +653,7 @@ discard block |
||
| 656 | 653 | $err = "<h2 style='text-align: center'>" |
| 657 | 654 | . $i |
| 658 | 655 | . "<a href='#fin_err'>" |
| 659 | - . ' ' . _T('erreur_texte') |
|
| 656 | + . ' '._T('erreur_texte') |
|
| 660 | 657 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 661 | 658 | . $err |
| 662 | 659 | . " </table><a id='fin_err'></a>"; |
@@ -666,9 +663,9 @@ discard block |
||
| 666 | 663 | [$msg, $fermant, $ouvrant] = $errs[0]; |
| 667 | 664 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 668 | 665 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 669 | - $err = $msg . |
|
| 670 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 671 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 666 | + $err = $msg. |
|
| 667 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 668 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 672 | 669 | |
| 673 | 670 | return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
| 674 | 671 | } |
@@ -701,7 +698,7 @@ discard block |
||
| 701 | 698 | ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
| 702 | 699 | ); |
| 703 | 700 | |
| 704 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 701 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 705 | 702 | . $t_skel |
| 706 | 703 | . ' ' |
| 707 | 704 | . $sourcefile |
@@ -716,7 +713,7 @@ discard block |
||
| 716 | 713 | . "'>" |
| 717 | 714 | . _T('zbug_calcul') |
| 718 | 715 | . '</a></legend>' |
| 719 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 716 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 720 | 717 | . debusquer_contexte($contexte[$sourcefile]) |
| 721 | 718 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 722 | 719 | . "</fieldset>\n"; |
@@ -737,33 +734,33 @@ discard block |
||
| 737 | 734 | $nom = $boucle->id_boucle; |
| 738 | 735 | $req = $boucle->type_requete; |
| 739 | 736 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 740 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 741 | - |
|
| 742 | - $res .= "\n<tr style='background-color: " . |
|
| 743 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 744 | - "'><td align='right'>$i</td><td>\n" . |
|
| 745 | - "<a class='debug_link_boucle' href='" . |
|
| 746 | - $self2 . |
|
| 747 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 748 | - _T('zbug_boucle') . |
|
| 749 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 750 | - $self2 . |
|
| 751 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 752 | - _T('zbug_resultat') . |
|
| 753 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 754 | - $self2 . |
|
| 755 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 756 | - _T('zbug_code') . |
|
| 757 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 758 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 759 | - "'>" . |
|
| 760 | - _T('zbug_calcul') . |
|
| 761 | - "</a></td><td>\n" . |
|
| 762 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 763 | - "</td><td>\n" . |
|
| 764 | - $req . |
|
| 765 | - "</td><td>\n" . |
|
| 766 | - spip_htmlspecialchars($crit) . |
|
| 737 | + $self2 = $self.'&var_mode_objet='.$objet; |
|
| 738 | + |
|
| 739 | + $res .= "\n<tr style='background-color: ". |
|
| 740 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 741 | + "'><td align='right'>$i</td><td>\n". |
|
| 742 | + "<a class='debug_link_boucle' href='". |
|
| 743 | + $self2. |
|
| 744 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 745 | + _T('zbug_boucle'). |
|
| 746 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 747 | + $self2. |
|
| 748 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 749 | + _T('zbug_resultat'). |
|
| 750 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 751 | + $self2. |
|
| 752 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 753 | + _T('zbug_code'). |
|
| 754 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 755 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 756 | + "'>". |
|
| 757 | + _T('zbug_calcul'). |
|
| 758 | + "</a></td><td>\n". |
|
| 759 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 760 | + "</td><td>\n". |
|
| 761 | + $req. |
|
| 762 | + "</td><td>\n". |
|
| 763 | + spip_htmlspecialchars($crit). |
|
| 767 | 764 | '</td></tr>'; |
| 768 | 765 | } |
| 769 | 766 | } |
@@ -790,7 +787,7 @@ discard block |
||
| 790 | 787 | } |
| 791 | 788 | // permettre le copier/coller facile |
| 792 | 789 | // $res = ancre_texte($req, array(), true); |
| 793 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 790 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 794 | 791 | // formatage et affichage des resultats bruts de la requete |
| 795 | 792 | $ress_req = spip_query($req); |
| 796 | 793 | $brut_sql = ''; |
@@ -800,10 +797,10 @@ discard block |
||
| 800 | 797 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 801 | 798 | while ($retours_sql = sql_fetch($ress_req)) { |
| 802 | 799 | if ($num <= $max_aff) { |
| 803 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 800 | + $brut_sql .= '<h3>'.($num == 1 ? $num.' sur '.sql_count($ress_req) : $num).'</h3>'; |
|
| 804 | 801 | $brut_sql .= '<p>'; |
| 805 | 802 | foreach ($retours_sql as $key => $val) { |
| 806 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 803 | + $brut_sql .= '<strong>'.$key.'</strong> => '.spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 807 | 804 | } |
| 808 | 805 | $brut_sql .= '</p>'; |
| 809 | 806 | } |
@@ -814,14 +811,14 @@ discard block |
||
| 814 | 811 | // ne pas afficher les $contexte_inclus |
| 815 | 812 | $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
| 816 | 813 | if ($view) { |
| 817 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 814 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view).'</fieldset>'; |
|
| 818 | 815 | } |
| 819 | 816 | } |
| 820 | 817 | } elseif ($affiche == 'code') { |
| 821 | 818 | $legend = $nom; |
| 822 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 819 | + $res = ancre_texte('<'."?php\n".$quoi."\n?".'>'); |
|
| 823 | 820 | } elseif ($affiche == 'boucle') { |
| 824 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 821 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 825 | 822 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 826 | 823 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 827 | 824 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -839,23 +836,23 @@ discard block |
||
| 839 | 836 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 840 | 837 | include_spip('inc/texte'); // pour corriger_typo |
| 841 | 838 | |
| 842 | - return _DOCTYPE_ECRIRE . |
|
| 843 | - html_lang_attributes() . |
|
| 844 | - "<head>\n<title>" . |
|
| 845 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 846 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 847 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 848 | - ")</title>\n" . |
|
| 849 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 850 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 851 | - "' />\n" . |
|
| 839 | + return _DOCTYPE_ECRIRE. |
|
| 840 | + html_lang_attributes(). |
|
| 841 | + "<head>\n<title>". |
|
| 842 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 843 | + _T('admin_debug').' '.spip_htmlspecialchars($titre).' ('. |
|
| 844 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 845 | + ")</title>\n". |
|
| 846 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 847 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 848 | + "' />\n". |
|
| 852 | 849 | http_script('', 'jquery.js') |
| 853 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 854 | - . "' type='text/css' />" . |
|
| 855 | - "</head>\n" . |
|
| 856 | - "<body style='margin:0 10px;'>\n" . |
|
| 857 | - "<div id='spip-debug-header'>" . |
|
| 858 | - $corps . |
|
| 859 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 850 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | + . "' type='text/css' />". |
|
| 852 | + "</head>\n". |
|
| 853 | + "<body style='margin:0 10px;'>\n". |
|
| 854 | + "<div id='spip-debug-header'>". |
|
| 855 | + $corps. |
|
| 856 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 860 | 857 | '</div></body></html>'; |
| 861 | 858 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -68,133 +68,133 @@ discard block |
||
| 68 | 68 | * - true si $opt 'erreurs' = 'reset' |
| 69 | 69 | **/ |
| 70 | 70 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 71 | - static $should_log; |
|
| 72 | - static $tableau_des_erreurs = []; |
|
| 73 | - |
|
| 74 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 75 | - if (isset($opt['erreurs'])) { |
|
| 76 | - if ($opt['erreurs'] == 'get') { |
|
| 77 | - return $tableau_des_erreurs; |
|
| 78 | - } |
|
| 79 | - if ($opt['erreurs'] == 'reset') { |
|
| 80 | - $tableau_des_erreurs = []; |
|
| 81 | - |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (is_null($should_log)) { |
|
| 87 | - $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Erreur ou appel final ? |
|
| 91 | - if ($message) { |
|
| 92 | - $message = debusquer_compose_message($message); |
|
| 93 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 94 | - set_request('var_mode', 'debug'); |
|
| 95 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 96 | - // Permettre a la compil de continuer |
|
| 97 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 98 | - $lieu->code = "''"; |
|
| 99 | - } |
|
| 100 | - // loger si personne ne verra l'erreur |
|
| 101 | - if ($should_log) { |
|
| 102 | - debusquer_loger_erreur($message, $lieu); |
|
| 103 | - } |
|
| 104 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 105 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 106 | - if (!$urgence) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 111 | - // espace public ? |
|
| 112 | - if (isset($GLOBALS['fond'])) { |
|
| 113 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - include_spip('inc/autoriser'); |
|
| 118 | - if (!autoriser('debug')) { |
|
| 119 | - return; |
|
| 120 | - } |
|
| 121 | - include_spip('inc/headers'); |
|
| 122 | - include_spip('inc/filtres'); |
|
| 123 | - |
|
| 124 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 125 | - $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 126 | - $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 127 | - |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_response_code(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 71 | + static $should_log; |
|
| 72 | + static $tableau_des_erreurs = []; |
|
| 73 | + |
|
| 74 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 75 | + if (isset($opt['erreurs'])) { |
|
| 76 | + if ($opt['erreurs'] == 'get') { |
|
| 77 | + return $tableau_des_erreurs; |
|
| 78 | + } |
|
| 79 | + if ($opt['erreurs'] == 'reset') { |
|
| 80 | + $tableau_des_erreurs = []; |
|
| 81 | + |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (is_null($should_log)) { |
|
| 87 | + $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Erreur ou appel final ? |
|
| 91 | + if ($message) { |
|
| 92 | + $message = debusquer_compose_message($message); |
|
| 93 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 94 | + set_request('var_mode', 'debug'); |
|
| 95 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 96 | + // Permettre a la compil de continuer |
|
| 97 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 98 | + $lieu->code = "''"; |
|
| 99 | + } |
|
| 100 | + // loger si personne ne verra l'erreur |
|
| 101 | + if ($should_log) { |
|
| 102 | + debusquer_loger_erreur($message, $lieu); |
|
| 103 | + } |
|
| 104 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 105 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 106 | + if (!$urgence) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 111 | + // espace public ? |
|
| 112 | + if (isset($GLOBALS['fond'])) { |
|
| 113 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + include_spip('inc/autoriser'); |
|
| 118 | + if (!autoriser('debug')) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | + include_spip('inc/headers'); |
|
| 122 | + include_spip('inc/filtres'); |
|
| 123 | + |
|
| 124 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 125 | + $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 126 | + $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 127 | + |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_response_code(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = $GLOBALS['fond'] ?? ''; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = $GLOBALS['fond'] ?? ''; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -204,63 +204,63 @@ discard block |
||
| 204 | 204 | * @return string Code HTML |
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | - $env = $env_tab; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!$env) { |
|
| 212 | - return ''; |
|
| 213 | - } |
|
| 214 | - $res = ''; |
|
| 215 | - foreach ($env as $nom => $valeur) { |
|
| 216 | - if (is_array($valeur)) { |
|
| 217 | - $valeur_simple = []; |
|
| 218 | - foreach ($valeur as $v) { |
|
| 219 | - if (is_array($v)) { |
|
| 220 | - $valeur_simple[] = 'array:' . count($v); |
|
| 221 | - } elseif (is_object($v)) { |
|
| 222 | - $valeur_simple[] = get_class($v); |
|
| 223 | - } elseif (is_string($v)) { |
|
| 224 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | - } else { |
|
| 226 | - $valeur_simple[] = $v; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - $n = count($valeur); |
|
| 230 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | - } elseif (is_object($valeur)) { |
|
| 233 | - $valeur = get_class($valeur); |
|
| 234 | - } elseif (is_string($valeur)) { |
|
| 235 | - $valeur = "'" . $valeur . "'"; |
|
| 236 | - } |
|
| 237 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 238 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 239 | - . "</td></tr>\n"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 207 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | + $env = $env_tab; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!$env) { |
|
| 212 | + return ''; |
|
| 213 | + } |
|
| 214 | + $res = ''; |
|
| 215 | + foreach ($env as $nom => $valeur) { |
|
| 216 | + if (is_array($valeur)) { |
|
| 217 | + $valeur_simple = []; |
|
| 218 | + foreach ($valeur as $v) { |
|
| 219 | + if (is_array($v)) { |
|
| 220 | + $valeur_simple[] = 'array:' . count($v); |
|
| 221 | + } elseif (is_object($v)) { |
|
| 222 | + $valeur_simple[] = get_class($v); |
|
| 223 | + } elseif (is_string($v)) { |
|
| 224 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | + } else { |
|
| 226 | + $valeur_simple[] = $v; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + $n = count($valeur); |
|
| 230 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | + } elseif (is_object($valeur)) { |
|
| 233 | + $valeur = get_class($valeur); |
|
| 234 | + } elseif (is_string($valeur)) { |
|
| 235 | + $valeur = "'" . $valeur . "'"; |
|
| 236 | + } |
|
| 237 | + $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 238 | + . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 239 | + . "</td></tr>\n"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | function debusquer_loger_erreur($msg, $lieu) { |
| 247 | - $boucle = $ligne = $skel = ''; |
|
| 248 | - if (is_object($lieu)) { |
|
| 249 | - $ligne = ($lieu->ligne ?? ''); |
|
| 250 | - $boucle = ($lieu->id_boucle ?? ''); |
|
| 251 | - $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 252 | - } |
|
| 253 | - $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 254 | - if ($skel) { |
|
| 255 | - $msg .= " Squelette $skel"; |
|
| 256 | - } |
|
| 257 | - if ($boucle) { |
|
| 258 | - $msg .= " Boucle $boucle"; |
|
| 259 | - } |
|
| 260 | - if ($ligne) { |
|
| 261 | - $msg .= " L$ligne"; |
|
| 262 | - } |
|
| 263 | - spip_log($msg, "debusquer" . _LOG_ERREUR); |
|
| 247 | + $boucle = $ligne = $skel = ''; |
|
| 248 | + if (is_object($lieu)) { |
|
| 249 | + $ligne = ($lieu->ligne ?? ''); |
|
| 250 | + $boucle = ($lieu->id_boucle ?? ''); |
|
| 251 | + $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 252 | + } |
|
| 253 | + $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 254 | + if ($skel) { |
|
| 255 | + $msg .= " Squelette $skel"; |
|
| 256 | + } |
|
| 257 | + if ($boucle) { |
|
| 258 | + $msg .= " Boucle $boucle"; |
|
| 259 | + } |
|
| 260 | + if ($ligne) { |
|
| 261 | + $msg .= " L$ligne"; |
|
| 262 | + } |
|
| 263 | + spip_log($msg, "debusquer" . _LOG_ERREUR); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -269,66 +269,66 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 271 | 271 | |
| 272 | - if (_request('exec') == 'valider_xml') { |
|
| 273 | - return ''; |
|
| 274 | - } |
|
| 275 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 276 | - $res = ''; |
|
| 277 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 278 | - foreach ($tableau as $i => $err) { |
|
| 279 | - $boucle = $ligne = $skel = ''; |
|
| 280 | - [$msg, $lieu] = $err; |
|
| 281 | - if (is_object($lieu)) { |
|
| 282 | - $ligne = $lieu->ligne; |
|
| 283 | - $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 284 | - if (isset($lieu->descr['nom'])) { |
|
| 285 | - $nom_code = $lieu->descr['nom']; |
|
| 286 | - $skel = $lieu->descr['sourcefile']; |
|
| 287 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 288 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 289 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 290 | - if ($boucle) { |
|
| 291 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 292 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $j = ($i + 1); |
|
| 298 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 299 | - . $j |
|
| 300 | - . " </td><td style='text-align: left'>" |
|
| 301 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 302 | - . "</td><td style='text-align: left'>" |
|
| 303 | - . ($skel ?: ' / ') |
|
| 304 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 305 | - . ($boucle ?: ' / ') |
|
| 306 | - . "</td><td style='text-align: right'>" |
|
| 307 | - . $ligne |
|
| 308 | - . "</td></tr>\n"; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return "\n<table id='$id'>" |
|
| 312 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 313 | - . $caption[0] |
|
| 272 | + if (_request('exec') == 'valider_xml') { |
|
| 273 | + return ''; |
|
| 274 | + } |
|
| 275 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 276 | + $res = ''; |
|
| 277 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 278 | + foreach ($tableau as $i => $err) { |
|
| 279 | + $boucle = $ligne = $skel = ''; |
|
| 280 | + [$msg, $lieu] = $err; |
|
| 281 | + if (is_object($lieu)) { |
|
| 282 | + $ligne = $lieu->ligne; |
|
| 283 | + $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 284 | + if (isset($lieu->descr['nom'])) { |
|
| 285 | + $nom_code = $lieu->descr['nom']; |
|
| 286 | + $skel = $lieu->descr['sourcefile']; |
|
| 287 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 288 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 289 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 290 | + if ($boucle) { |
|
| 291 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 292 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $j = ($i + 1); |
|
| 298 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 299 | + . $j |
|
| 300 | + . " </td><td style='text-align: left'>" |
|
| 301 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 302 | + . "</td><td style='text-align: left'>" |
|
| 303 | + . ($skel ?: ' / ') |
|
| 304 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 305 | + . ($boucle ?: ' / ') |
|
| 306 | + . "</td><td style='text-align: right'>" |
|
| 307 | + . $ligne |
|
| 308 | + . "</td></tr>\n"; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return "\n<table id='$id'>" |
|
| 312 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 313 | + . $caption[0] |
|
| 314 | 314 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 315 | 315 | # aider('erreur_compilation'), |
| 316 | - . '</caption>' |
|
| 317 | - // fausse caption du chrono (mais vraie nav) |
|
| 318 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 319 | - . '<tr><th>' |
|
| 320 | - . _T('numero') |
|
| 321 | - . '</th><th>' |
|
| 322 | - . _T('public:message') |
|
| 323 | - . '</th><th>' |
|
| 324 | - . _T('squelette') |
|
| 325 | - . '</th><th>' |
|
| 326 | - . _T('zbug_boucle') |
|
| 327 | - . '</th><th>' |
|
| 328 | - . _T('ligne') |
|
| 329 | - . '</th></tr>' |
|
| 330 | - . $res |
|
| 331 | - . '</table>'; |
|
| 316 | + . '</caption>' |
|
| 317 | + // fausse caption du chrono (mais vraie nav) |
|
| 318 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 319 | + . '<tr><th>' |
|
| 320 | + . _T('numero') |
|
| 321 | + . '</th><th>' |
|
| 322 | + . _T('public:message') |
|
| 323 | + . '</th><th>' |
|
| 324 | + . _T('squelette') |
|
| 325 | + . '</th><th>' |
|
| 326 | + . _T('zbug_boucle') |
|
| 327 | + . '</th><th>' |
|
| 328 | + . _T('ligne') |
|
| 329 | + . '</th></tr>' |
|
| 330 | + . $res |
|
| 331 | + . '</table>'; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -348,514 +348,514 @@ discard block |
||
| 348 | 348 | * ou un tableau si l'erreur est critique |
| 349 | 349 | **/ |
| 350 | 350 | function debusquer_requete($message) { |
| 351 | - [$errno, $msg, $query] = $message; |
|
| 352 | - |
|
| 353 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 354 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 355 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 356 | - $errno = $regs[2]; |
|
| 357 | - } elseif ( |
|
| 358 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 359 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 360 | - ) { |
|
| 361 | - $errno = $regs[1]; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // Erreur systeme |
|
| 365 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 366 | - $retour = '<tt><br /><br /><blink>' |
|
| 367 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 368 | - . "</blink><br />\n<b>" |
|
| 369 | - . _T( |
|
| 370 | - 'info_erreur_systeme2', |
|
| 371 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 372 | - ) |
|
| 373 | - . '</b><br />'; |
|
| 374 | - spip_log("Erreur systeme $errno"); |
|
| 375 | - |
|
| 376 | - return [$retour, '']; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // Requete erronee |
|
| 380 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 381 | - . spip_htmlspecialchars($msg) |
|
| 382 | - . "\n<br /><span style='color: red'><b>" |
|
| 383 | - . spip_htmlspecialchars($query) |
|
| 384 | - . '</b></span></tt><br />'; |
|
| 385 | - |
|
| 386 | - //. aider('erreur_mysql'); |
|
| 387 | - |
|
| 388 | - return $err; |
|
| 351 | + [$errno, $msg, $query] = $message; |
|
| 352 | + |
|
| 353 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 354 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 355 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 356 | + $errno = $regs[2]; |
|
| 357 | + } elseif ( |
|
| 358 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 359 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 360 | + ) { |
|
| 361 | + $errno = $regs[1]; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // Erreur systeme |
|
| 365 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 366 | + $retour = '<tt><br /><br /><blink>' |
|
| 367 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 368 | + . "</blink><br />\n<b>" |
|
| 369 | + . _T( |
|
| 370 | + 'info_erreur_systeme2', |
|
| 371 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 372 | + ) |
|
| 373 | + . '</b><br />'; |
|
| 374 | + spip_log("Erreur systeme $errno"); |
|
| 375 | + |
|
| 376 | + return [$retour, '']; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // Requete erronee |
|
| 380 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 381 | + . spip_htmlspecialchars($msg) |
|
| 382 | + . "\n<br /><span style='color: red'><b>" |
|
| 383 | + . spip_htmlspecialchars($query) |
|
| 384 | + . '</b></span></tt><br />'; |
|
| 385 | + |
|
| 386 | + //. aider('erreur_mysql'); |
|
| 387 | + |
|
| 388 | + return $err; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | |
| 392 | 392 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 393 | 393 | |
| 394 | - $id = $nom . $boucle; |
|
| 395 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 396 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 397 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 398 | - $y = substr_count($v[0], "\n"); |
|
| 399 | - } else { |
|
| 400 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 401 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 402 | - } else // inclusion |
|
| 403 | - { |
|
| 404 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 405 | - } |
|
| 406 | - $y = substr_count($incl, "\n") |
|
| 407 | - + substr_count($r[1], "\n") |
|
| 408 | - + substr_count($r[3], "\n"); |
|
| 409 | - } |
|
| 410 | - if ($n <= ($y + $debut)) { |
|
| 411 | - if ($v[1][0] == '?') { |
|
| 412 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 413 | - } elseif ($v[1][0] == '!') { |
|
| 414 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 415 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 420 | - } |
|
| 421 | - $debut += $y; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return [$nom, $boucle, $n - $debut]; |
|
| 394 | + $id = $nom . $boucle; |
|
| 395 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 396 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 397 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 398 | + $y = substr_count($v[0], "\n"); |
|
| 399 | + } else { |
|
| 400 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 401 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 402 | + } else // inclusion |
|
| 403 | + { |
|
| 404 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 405 | + } |
|
| 406 | + $y = substr_count($incl, "\n") |
|
| 407 | + + substr_count($r[1], "\n") |
|
| 408 | + + substr_count($r[3], "\n"); |
|
| 409 | + } |
|
| 410 | + if ($n <= ($y + $debut)) { |
|
| 411 | + if ($v[1][0] == '?') { |
|
| 412 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 413 | + } elseif ($v[1][0] == '!') { |
|
| 414 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 415 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 420 | + } |
|
| 421 | + $debut += $y; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return [$nom, $boucle, $n - $debut]; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | function trouve_squelette_inclus($script) { |
| 429 | 429 | |
| 430 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 431 | - // si le script X.php n'est pas ecrire/public.php |
|
| 432 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 433 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 434 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 435 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 436 | - $reg[1] = 'inconnu'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 441 | - |
|
| 442 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 443 | - if (preg_match($incl, $v)) { |
|
| 444 | - return $k; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return ''; |
|
| 430 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 431 | + // si le script X.php n'est pas ecrire/public.php |
|
| 432 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 433 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 434 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 435 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 436 | + $reg[1] = 'inconnu'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 441 | + |
|
| 442 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 443 | + if (preg_match($incl, $v)) { |
|
| 444 | + return $k; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return ''; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | function reference_boucle_debug($n, $nom, $self) { |
| 452 | - [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 453 | - |
|
| 454 | - if (!$boucle) { |
|
| 455 | - return !$ligne ? '' : |
|
| 456 | - (' (' . |
|
| 457 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 458 | - _T('squelette_ligne')) . |
|
| 459 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 460 | - } else { |
|
| 461 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 462 | - |
|
| 463 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 464 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 465 | - } |
|
| 452 | + [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 453 | + |
|
| 454 | + if (!$boucle) { |
|
| 455 | + return !$ligne ? '' : |
|
| 456 | + (' (' . |
|
| 457 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 458 | + _T('squelette_ligne')) . |
|
| 459 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 460 | + } else { |
|
| 461 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 462 | + |
|
| 463 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 464 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // affiche un texte avec numero de ligne et ancre. |
| 469 | 469 | |
| 470 | 470 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 471 | 471 | |
| 472 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 473 | - if ($var_mode_ligne) { |
|
| 474 | - $fautifs[] = [$var_mode_ligne]; |
|
| 475 | - } |
|
| 476 | - $res = ''; |
|
| 477 | - |
|
| 478 | - $s = highlight_string($texte, true); |
|
| 479 | - if (substr($s, 0, 6) == '<code>') { |
|
| 480 | - $s = substr($s, 6); |
|
| 481 | - $res = '<code>'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $s = preg_replace( |
|
| 485 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 486 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 487 | - $s |
|
| 488 | - ); |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - $tableau = explode('<br />', $s); |
|
| 492 | - |
|
| 493 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 494 | - |
|
| 495 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 496 | - $formaterr = 'color: red;'; |
|
| 497 | - $i = 1; |
|
| 498 | - $flignes = []; |
|
| 499 | - $loc = [0, 0]; |
|
| 500 | - foreach ($fautifs as $lc) { |
|
| 501 | - if (is_array($lc)) { |
|
| 502 | - $l = array_shift($lc); |
|
| 503 | - $flignes[$l] = $lc; |
|
| 504 | - } else { |
|
| 505 | - $flignes[$lc] = $loc; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - $ancre = md5($texte); |
|
| 510 | - foreach ($tableau as $ligne) { |
|
| 511 | - if (isset($flignes[$i])) { |
|
| 512 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 513 | - $indexmesg = $flignes[$i][1]; |
|
| 514 | - $err = textebrut($flignes[$i][2]); |
|
| 515 | - // tentative de pointer sur la colonne fautive; |
|
| 516 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 517 | - // $m = $flignes[$i][0]; |
|
| 518 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 519 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 520 | - $bg = $formaterr; |
|
| 521 | - } else { |
|
| 522 | - $indexmesg = $ancre; |
|
| 523 | - $err = $bg = ''; |
|
| 524 | - } |
|
| 525 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 526 | - $i++; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return "<div id='T$ancre'>" |
|
| 530 | - . '<div onclick="' |
|
| 531 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 532 | - . '" title="' |
|
| 533 | - . _T('masquer_colonne') |
|
| 534 | - . '" style="cursor: pointer;">' |
|
| 535 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 536 | - . '</div> |
|
| 472 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 473 | + if ($var_mode_ligne) { |
|
| 474 | + $fautifs[] = [$var_mode_ligne]; |
|
| 475 | + } |
|
| 476 | + $res = ''; |
|
| 477 | + |
|
| 478 | + $s = highlight_string($texte, true); |
|
| 479 | + if (substr($s, 0, 6) == '<code>') { |
|
| 480 | + $s = substr($s, 6); |
|
| 481 | + $res = '<code>'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $s = preg_replace( |
|
| 485 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 486 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 487 | + $s |
|
| 488 | + ); |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + $tableau = explode('<br />', $s); |
|
| 492 | + |
|
| 493 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 494 | + |
|
| 495 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 496 | + $formaterr = 'color: red;'; |
|
| 497 | + $i = 1; |
|
| 498 | + $flignes = []; |
|
| 499 | + $loc = [0, 0]; |
|
| 500 | + foreach ($fautifs as $lc) { |
|
| 501 | + if (is_array($lc)) { |
|
| 502 | + $l = array_shift($lc); |
|
| 503 | + $flignes[$l] = $lc; |
|
| 504 | + } else { |
|
| 505 | + $flignes[$lc] = $loc; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + $ancre = md5($texte); |
|
| 510 | + foreach ($tableau as $ligne) { |
|
| 511 | + if (isset($flignes[$i])) { |
|
| 512 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 513 | + $indexmesg = $flignes[$i][1]; |
|
| 514 | + $err = textebrut($flignes[$i][2]); |
|
| 515 | + // tentative de pointer sur la colonne fautive; |
|
| 516 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 517 | + // $m = $flignes[$i][0]; |
|
| 518 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 519 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 520 | + $bg = $formaterr; |
|
| 521 | + } else { |
|
| 522 | + $indexmesg = $ancre; |
|
| 523 | + $err = $bg = ''; |
|
| 524 | + } |
|
| 525 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 526 | + $i++; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return "<div id='T$ancre'>" |
|
| 530 | + . '<div onclick="' |
|
| 531 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 532 | + . '" title="' |
|
| 533 | + . _T('masquer_colonne') |
|
| 534 | + . '" style="cursor: pointer;">' |
|
| 535 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 536 | + . '</div> |
|
| 537 | 537 | ' . $res . "</div>\n"; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // l'environnement graphique du debuggueur |
| 541 | 541 | |
| 542 | 542 | function debusquer_squelette($fonc, $mode, $self) { |
| 543 | - $legend = null; |
|
| 544 | - $texte = ''; |
|
| 545 | - |
|
| 546 | - if ($mode !== 'validation') { |
|
| 547 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 548 | - $res = "<div id='spip-boucles'>\n" |
|
| 549 | - . debusquer_navigation_squelettes($self) |
|
| 550 | - . '</div>'; |
|
| 551 | - } else { |
|
| 552 | - $res = ''; |
|
| 553 | - } |
|
| 554 | - if ($fonc) { |
|
| 555 | - $id = " id='$fonc'"; |
|
| 556 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 557 | - [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 558 | - $texte .= $res2; |
|
| 559 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 560 | - $legend = _T('zbug_' . $mode); |
|
| 561 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 562 | - $texte = ancre_texte($texte, ['', '']); |
|
| 563 | - } |
|
| 564 | - } else { |
|
| 565 | - if (strlen(trim($res))) { |
|
| 566 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 567 | - } else { |
|
| 568 | - // cas de l'appel sur erreur: montre la page |
|
| 569 | - return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } else { |
|
| 573 | - $valider = charger_fonction('valider', 'xml'); |
|
| 574 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 575 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 576 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 577 | - [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 578 | - if ($err === false) { |
|
| 579 | - $err = _T('impossible'); |
|
| 580 | - } elseif ($err === true) { |
|
| 581 | - $err = _T('correcte'); |
|
| 582 | - } else { |
|
| 583 | - $err = ": $err"; |
|
| 584 | - } |
|
| 585 | - $legend = _T('validation') . ' ' . $err; |
|
| 586 | - $res = $id = ''; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return !trim($texte) ? '' : ( |
|
| 590 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 591 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 592 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 593 | - . ($legend ?: $mode) |
|
| 594 | - . '</a></legend>' |
|
| 595 | - . $texte |
|
| 596 | - . '</fieldset></div>' |
|
| 597 | - . '</div>'); |
|
| 543 | + $legend = null; |
|
| 544 | + $texte = ''; |
|
| 545 | + |
|
| 546 | + if ($mode !== 'validation') { |
|
| 547 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 548 | + $res = "<div id='spip-boucles'>\n" |
|
| 549 | + . debusquer_navigation_squelettes($self) |
|
| 550 | + . '</div>'; |
|
| 551 | + } else { |
|
| 552 | + $res = ''; |
|
| 553 | + } |
|
| 554 | + if ($fonc) { |
|
| 555 | + $id = " id='$fonc'"; |
|
| 556 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 557 | + [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 558 | + $texte .= $res2; |
|
| 559 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 560 | + $legend = _T('zbug_' . $mode); |
|
| 561 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 562 | + $texte = ancre_texte($texte, ['', '']); |
|
| 563 | + } |
|
| 564 | + } else { |
|
| 565 | + if (strlen(trim($res))) { |
|
| 566 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 567 | + } else { |
|
| 568 | + // cas de l'appel sur erreur: montre la page |
|
| 569 | + return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | + $valider = charger_fonction('valider', 'xml'); |
|
| 574 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 575 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 576 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 577 | + [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 578 | + if ($err === false) { |
|
| 579 | + $err = _T('impossible'); |
|
| 580 | + } elseif ($err === true) { |
|
| 581 | + $err = _T('correcte'); |
|
| 582 | + } else { |
|
| 583 | + $err = ": $err"; |
|
| 584 | + } |
|
| 585 | + $legend = _T('validation') . ' ' . $err; |
|
| 586 | + $res = $id = ''; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return !trim($texte) ? '' : ( |
|
| 590 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 591 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 592 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 593 | + . ($legend ?: $mode) |
|
| 594 | + . '</a></legend>' |
|
| 595 | + . $texte |
|
| 596 | + . '</fieldset></div>' |
|
| 597 | + . '</div>'); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
| 601 | 601 | function emboite_texte($res, $fonc = '', $self = '') { |
| 602 | - $errs = $res->err; |
|
| 603 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 604 | - |
|
| 605 | - if (!$texte and !$errs) { |
|
| 606 | - return [ancre_texte('', ['', '']), false]; |
|
| 607 | - } |
|
| 608 | - if (!$errs) { |
|
| 609 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 613 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 614 | - $encore = count_occ($errs); |
|
| 615 | - $encore2 = []; |
|
| 616 | - $fautifs = []; |
|
| 617 | - |
|
| 618 | - $err = '<tr><th>' |
|
| 619 | - . _T('numero') |
|
| 620 | - . '</th><th>' |
|
| 621 | - . _T('occurence') |
|
| 622 | - . '</th><th>' |
|
| 623 | - . _T('ligne') |
|
| 624 | - . '</th><th>' |
|
| 625 | - . _T('colonne') |
|
| 626 | - . '</th><th>' |
|
| 627 | - . _T('erreur') |
|
| 628 | - . '</th></tr>'; |
|
| 629 | - |
|
| 630 | - $i = 0; |
|
| 631 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 632 | - foreach ($errs as $r) { |
|
| 633 | - $i++; |
|
| 634 | - [$msg, $ligne, $col] = $r; |
|
| 635 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 636 | - if (isset($encore2[$msg])) { |
|
| 637 | - $ref = ++$encore2[$msg]; |
|
| 638 | - } else { |
|
| 639 | - $encore2[$msg] = $ref = 1; |
|
| 640 | - } |
|
| 641 | - $err .= "<tr style='background-color: " |
|
| 642 | - . $colors[$i % 2] |
|
| 643 | - . "'><td $style><a href='#debut_err'>" |
|
| 644 | - . $i |
|
| 645 | - . "</a></td><td $style>" |
|
| 646 | - . "$ref/$encore[$msg]</td>" |
|
| 647 | - . "<td $style><a href='#L" |
|
| 648 | - . $ligne |
|
| 649 | - . "' id='T$i'>" |
|
| 650 | - . $ligne |
|
| 651 | - . "</a></td><td $style>" |
|
| 652 | - . $col |
|
| 653 | - . "</td><td>$msg</td></tr>\n"; |
|
| 654 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 655 | - } |
|
| 656 | - $err = "<h2 style='text-align: center'>" |
|
| 657 | - . $i |
|
| 658 | - . "<a href='#fin_err'>" |
|
| 659 | - . ' ' . _T('erreur_texte') |
|
| 660 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 661 | - . $err |
|
| 662 | - . " </table><a id='fin_err'></a>"; |
|
| 663 | - |
|
| 664 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 665 | - } else { |
|
| 666 | - [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 667 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 668 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 669 | - $err = $msg . |
|
| 670 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 671 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 672 | - |
|
| 673 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 674 | - } |
|
| 602 | + $errs = $res->err; |
|
| 603 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 604 | + |
|
| 605 | + if (!$texte and !$errs) { |
|
| 606 | + return [ancre_texte('', ['', '']), false]; |
|
| 607 | + } |
|
| 608 | + if (!$errs) { |
|
| 609 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 613 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 614 | + $encore = count_occ($errs); |
|
| 615 | + $encore2 = []; |
|
| 616 | + $fautifs = []; |
|
| 617 | + |
|
| 618 | + $err = '<tr><th>' |
|
| 619 | + . _T('numero') |
|
| 620 | + . '</th><th>' |
|
| 621 | + . _T('occurence') |
|
| 622 | + . '</th><th>' |
|
| 623 | + . _T('ligne') |
|
| 624 | + . '</th><th>' |
|
| 625 | + . _T('colonne') |
|
| 626 | + . '</th><th>' |
|
| 627 | + . _T('erreur') |
|
| 628 | + . '</th></tr>'; |
|
| 629 | + |
|
| 630 | + $i = 0; |
|
| 631 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 632 | + foreach ($errs as $r) { |
|
| 633 | + $i++; |
|
| 634 | + [$msg, $ligne, $col] = $r; |
|
| 635 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 636 | + if (isset($encore2[$msg])) { |
|
| 637 | + $ref = ++$encore2[$msg]; |
|
| 638 | + } else { |
|
| 639 | + $encore2[$msg] = $ref = 1; |
|
| 640 | + } |
|
| 641 | + $err .= "<tr style='background-color: " |
|
| 642 | + . $colors[$i % 2] |
|
| 643 | + . "'><td $style><a href='#debut_err'>" |
|
| 644 | + . $i |
|
| 645 | + . "</a></td><td $style>" |
|
| 646 | + . "$ref/$encore[$msg]</td>" |
|
| 647 | + . "<td $style><a href='#L" |
|
| 648 | + . $ligne |
|
| 649 | + . "' id='T$i'>" |
|
| 650 | + . $ligne |
|
| 651 | + . "</a></td><td $style>" |
|
| 652 | + . $col |
|
| 653 | + . "</td><td>$msg</td></tr>\n"; |
|
| 654 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 655 | + } |
|
| 656 | + $err = "<h2 style='text-align: center'>" |
|
| 657 | + . $i |
|
| 658 | + . "<a href='#fin_err'>" |
|
| 659 | + . ' ' . _T('erreur_texte') |
|
| 660 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 661 | + . $err |
|
| 662 | + . " </table><a id='fin_err'></a>"; |
|
| 663 | + |
|
| 664 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 665 | + } else { |
|
| 666 | + [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 667 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 668 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 669 | + $err = $msg . |
|
| 670 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 671 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 672 | + |
|
| 673 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 674 | + } |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | function count_occ($regs) { |
| 678 | - $encore = []; |
|
| 679 | - foreach ($regs as $r) { |
|
| 680 | - if (isset($encore[$r[0]])) { |
|
| 681 | - $encore[$r[0]]++; |
|
| 682 | - } else { |
|
| 683 | - $encore[$r[0]] = 1; |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - return $encore; |
|
| 678 | + $encore = []; |
|
| 679 | + foreach ($regs as $r) { |
|
| 680 | + if (isset($encore[$r[0]])) { |
|
| 681 | + $encore[$r[0]]++; |
|
| 682 | + } else { |
|
| 683 | + $encore[$r[0]] = 1; |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + return $encore; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | function debusquer_navigation_squelettes($self) { |
| 691 | 691 | |
| 692 | - $res = ''; |
|
| 693 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 694 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 695 | - $t_skel = _T('squelette'); |
|
| 696 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 697 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 698 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 699 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 700 | - 'zbug_profile', |
|
| 701 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 705 | - . $t_skel |
|
| 706 | - . ' ' |
|
| 707 | - . $sourcefile |
|
| 708 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 709 | - . $t_skel |
|
| 710 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 711 | - . _T('zbug_resultat') |
|
| 712 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 713 | - . _T('zbug_code') |
|
| 714 | - . "</a>\n<a href='" |
|
| 715 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 716 | - . "'>" |
|
| 717 | - . _T('zbug_calcul') |
|
| 718 | - . '</a></legend>' |
|
| 719 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 720 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 721 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 722 | - . "</fieldset>\n"; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - return $res; |
|
| 692 | + $res = ''; |
|
| 693 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 694 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 695 | + $t_skel = _T('squelette'); |
|
| 696 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 697 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 698 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 699 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 700 | + 'zbug_profile', |
|
| 701 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 705 | + . $t_skel |
|
| 706 | + . ' ' |
|
| 707 | + . $sourcefile |
|
| 708 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 709 | + . $t_skel |
|
| 710 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 711 | + . _T('zbug_resultat') |
|
| 712 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 713 | + . _T('zbug_code') |
|
| 714 | + . "</a>\n<a href='" |
|
| 715 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 716 | + . "'>" |
|
| 717 | + . _T('zbug_calcul') |
|
| 718 | + . '</a></legend>' |
|
| 719 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 720 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 721 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 722 | + . "</fieldset>\n"; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + return $res; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 729 | - $i = 0; |
|
| 730 | - $res = ''; |
|
| 731 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 732 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 733 | - |
|
| 734 | - foreach ($boucles as $objet => $boucle) { |
|
| 735 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 736 | - $i++; |
|
| 737 | - $nom = $boucle->id_boucle; |
|
| 738 | - $req = $boucle->type_requete; |
|
| 739 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 740 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 741 | - |
|
| 742 | - $res .= "\n<tr style='background-color: " . |
|
| 743 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 744 | - "'><td align='right'>$i</td><td>\n" . |
|
| 745 | - "<a class='debug_link_boucle' href='" . |
|
| 746 | - $self2 . |
|
| 747 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 748 | - _T('zbug_boucle') . |
|
| 749 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 750 | - $self2 . |
|
| 751 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 752 | - _T('zbug_resultat') . |
|
| 753 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 754 | - $self2 . |
|
| 755 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 756 | - _T('zbug_code') . |
|
| 757 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 758 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 759 | - "'>" . |
|
| 760 | - _T('zbug_calcul') . |
|
| 761 | - "</a></td><td>\n" . |
|
| 762 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 763 | - "</td><td>\n" . |
|
| 764 | - $req . |
|
| 765 | - "</td><td>\n" . |
|
| 766 | - spip_htmlspecialchars($crit) . |
|
| 767 | - '</td></tr>'; |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - return $res; |
|
| 729 | + $i = 0; |
|
| 730 | + $res = ''; |
|
| 731 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 732 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 733 | + |
|
| 734 | + foreach ($boucles as $objet => $boucle) { |
|
| 735 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 736 | + $i++; |
|
| 737 | + $nom = $boucle->id_boucle; |
|
| 738 | + $req = $boucle->type_requete; |
|
| 739 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 740 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 741 | + |
|
| 742 | + $res .= "\n<tr style='background-color: " . |
|
| 743 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 744 | + "'><td align='right'>$i</td><td>\n" . |
|
| 745 | + "<a class='debug_link_boucle' href='" . |
|
| 746 | + $self2 . |
|
| 747 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 748 | + _T('zbug_boucle') . |
|
| 749 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 750 | + $self2 . |
|
| 751 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 752 | + _T('zbug_resultat') . |
|
| 753 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 754 | + $self2 . |
|
| 755 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 756 | + _T('zbug_code') . |
|
| 757 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 758 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 759 | + "'>" . |
|
| 760 | + _T('zbug_calcul') . |
|
| 761 | + "</a></td><td>\n" . |
|
| 762 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 763 | + "</td><td>\n" . |
|
| 764 | + $req . |
|
| 765 | + "</td><td>\n" . |
|
| 766 | + spip_htmlspecialchars($crit) . |
|
| 767 | + '</td></tr>'; |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + return $res; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | function debusquer_source($objet, $affiche) { |
| 775 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 776 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 777 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 778 | - } else { |
|
| 779 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 780 | - } |
|
| 781 | - $res2 = ''; |
|
| 782 | - |
|
| 783 | - if ($affiche == 'resultat') { |
|
| 784 | - $legend = $nom; |
|
| 785 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 786 | - if (function_exists('_mysql_traite_query')) { |
|
| 787 | - $c = strtolower(_request('connect') ?? ''); |
|
| 788 | - $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 789 | - $req = _mysql_traite_query($req, '', $c); |
|
| 790 | - } |
|
| 791 | - // permettre le copier/coller facile |
|
| 792 | - // $res = ancre_texte($req, array(), true); |
|
| 793 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 794 | - // formatage et affichage des resultats bruts de la requete |
|
| 795 | - $ress_req = spip_query($req); |
|
| 796 | - $brut_sql = ''; |
|
| 797 | - $num = 1; |
|
| 798 | - // eviter l'affichage de milliers de lignes |
|
| 799 | - // personnalisation possible dans mes_options |
|
| 800 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 801 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 802 | - if ($num <= $max_aff) { |
|
| 803 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 804 | - $brut_sql .= '<p>'; |
|
| 805 | - foreach ($retours_sql as $key => $val) { |
|
| 806 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 807 | - } |
|
| 808 | - $brut_sql .= '</p>'; |
|
| 809 | - } |
|
| 810 | - $num++; |
|
| 811 | - } |
|
| 812 | - $res2 = interdire_scripts($brut_sql); |
|
| 813 | - foreach ($quoi as $view) { |
|
| 814 | - // ne pas afficher les $contexte_inclus |
|
| 815 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 816 | - if ($view) { |
|
| 817 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - } elseif ($affiche == 'code') { |
|
| 821 | - $legend = $nom; |
|
| 822 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 823 | - } elseif ($affiche == 'boucle') { |
|
| 824 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 825 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 826 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 827 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 828 | - } elseif ($affiche == 'squelette') { |
|
| 829 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 830 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return [$legend, $res, $res2]; |
|
| 775 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 776 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 777 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 778 | + } else { |
|
| 779 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 780 | + } |
|
| 781 | + $res2 = ''; |
|
| 782 | + |
|
| 783 | + if ($affiche == 'resultat') { |
|
| 784 | + $legend = $nom; |
|
| 785 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 786 | + if (function_exists('_mysql_traite_query')) { |
|
| 787 | + $c = strtolower(_request('connect') ?? ''); |
|
| 788 | + $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 789 | + $req = _mysql_traite_query($req, '', $c); |
|
| 790 | + } |
|
| 791 | + // permettre le copier/coller facile |
|
| 792 | + // $res = ancre_texte($req, array(), true); |
|
| 793 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 794 | + // formatage et affichage des resultats bruts de la requete |
|
| 795 | + $ress_req = spip_query($req); |
|
| 796 | + $brut_sql = ''; |
|
| 797 | + $num = 1; |
|
| 798 | + // eviter l'affichage de milliers de lignes |
|
| 799 | + // personnalisation possible dans mes_options |
|
| 800 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 801 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 802 | + if ($num <= $max_aff) { |
|
| 803 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 804 | + $brut_sql .= '<p>'; |
|
| 805 | + foreach ($retours_sql as $key => $val) { |
|
| 806 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 807 | + } |
|
| 808 | + $brut_sql .= '</p>'; |
|
| 809 | + } |
|
| 810 | + $num++; |
|
| 811 | + } |
|
| 812 | + $res2 = interdire_scripts($brut_sql); |
|
| 813 | + foreach ($quoi as $view) { |
|
| 814 | + // ne pas afficher les $contexte_inclus |
|
| 815 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 816 | + if ($view) { |
|
| 817 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + } elseif ($affiche == 'code') { |
|
| 821 | + $legend = $nom; |
|
| 822 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 823 | + } elseif ($affiche == 'boucle') { |
|
| 824 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 825 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 826 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 827 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 828 | + } elseif ($affiche == 'squelette') { |
|
| 829 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 830 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return [$legend, $res, $res2]; |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | function debusquer_entete($titre, $corps) { |
| 837 | 837 | |
| 838 | - include_spip('balise/formulaire_admin'); |
|
| 839 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 840 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 841 | - |
|
| 842 | - return _DOCTYPE_ECRIRE . |
|
| 843 | - html_lang_attributes() . |
|
| 844 | - "<head>\n<title>" . |
|
| 845 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 846 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 847 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 848 | - ")</title>\n" . |
|
| 849 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 850 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 851 | - "' />\n" . |
|
| 852 | - http_script('', 'jquery.js') |
|
| 853 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 854 | - . "' type='text/css' />" . |
|
| 855 | - "</head>\n" . |
|
| 856 | - "<body style='margin:0 10px;'>\n" . |
|
| 857 | - "<div id='spip-debug-header'>" . |
|
| 858 | - $corps . |
|
| 859 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 860 | - '</div></body></html>'; |
|
| 838 | + include_spip('balise/formulaire_admin'); |
|
| 839 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 840 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 841 | + |
|
| 842 | + return _DOCTYPE_ECRIRE . |
|
| 843 | + html_lang_attributes() . |
|
| 844 | + "<head>\n<title>" . |
|
| 845 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 846 | + _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 847 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 848 | + ")</title>\n" . |
|
| 849 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 850 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 851 | + "' />\n" . |
|
| 852 | + http_script('', 'jquery.js') |
|
| 853 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 854 | + . "' type='text/css' />" . |
|
| 855 | + "</head>\n" . |
|
| 856 | + "<body style='margin:0 10px;'>\n" . |
|
| 857 | + "<div id='spip-debug-header'>" . |
|
| 858 | + $corps . |
|
| 859 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 860 | + '</div></body></html>'; |
|
| 861 | 861 | } |