@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Fonctions |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -28,29 +28,29 @@ discard block |
||
| 28 | 28 | * @param bool $left |
| 29 | 29 | */ |
| 30 | 30 | function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) { |
| 31 | - $boucle = &$boucles[$idb]; |
|
| 31 | + $boucle = &$boucles[$idb]; |
|
| 32 | 32 | |
| 33 | - $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 33 | + $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 34 | 34 | |
| 35 | - $not = ''; |
|
| 36 | - if ($crit->not) { |
|
| 37 | - $not = ", 'NOT'"; |
|
| 38 | - } |
|
| 39 | - $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 40 | - $boucle->from_type['LAA'] = 'left'; |
|
| 41 | - $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 35 | + $not = ''; |
|
| 36 | + if ($crit->not) { |
|
| 37 | + $not = ", 'NOT'"; |
|
| 38 | + } |
|
| 39 | + $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 40 | + $boucle->from_type['LAA'] = 'left'; |
|
| 41 | + $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 42 | 42 | |
| 43 | - $boucle->from['articles'] = 'spip_articles'; |
|
| 44 | - $boucle->from_type['articles'] = 'left'; |
|
| 45 | - $boucle->join['articles'] = [ |
|
| 46 | - "'LAA'", |
|
| 47 | - "'id_article'", |
|
| 48 | - "'id_objet'", |
|
| 49 | - "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 50 | - ]; |
|
| 43 | + $boucle->from['articles'] = 'spip_articles'; |
|
| 44 | + $boucle->from_type['articles'] = 'left'; |
|
| 45 | + $boucle->join['articles'] = [ |
|
| 46 | + "'LAA'", |
|
| 47 | + "'id_article'", |
|
| 48 | + "'id_objet'", |
|
| 49 | + "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 50 | + ]; |
|
| 51 | 51 | |
| 52 | - $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 53 | - $boucle->group[] = 'auteurs.id_auteur'; |
|
| 52 | + $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 53 | + $boucle->group[] = 'auteurs.id_auteur'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * Pile complétée par le code à générer |
| 69 | 69 | */ |
| 70 | 70 | function balise_COMPTEUR_ARTICLES_dist($p) { |
| 71 | - return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 71 | + return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -84,37 +84,37 @@ discard block |
||
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | 86 | function afficher_initiale($url, $initiale, $compteur, $debut, $pas) { |
| 87 | - static $memo = null; |
|
| 88 | - static $res = []; |
|
| 89 | - $out = ''; |
|
| 90 | - if (!$memo || !$initiale && !$url || $initiale !== $memo['initiale']) { |
|
| 91 | - $newcompt = (int) (floor(($compteur - 1) / $pas) * $pas); |
|
| 92 | - // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 93 | - if (!$initiale && !$url && !$memo['compteur']) { |
|
| 94 | - $memo = null; |
|
| 95 | - } |
|
| 96 | - if ($memo) { |
|
| 97 | - $on = ($memo['compteur'] <= $debut && ($newcompt > $debut || $newcompt == $debut && $newcompt == $memo['compteur'])); |
|
| 98 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 99 | - } |
|
| 100 | - if ($initiale) { |
|
| 101 | - $memo = [ |
|
| 102 | - 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 103 | - 'initiale' => $initiale, |
|
| 104 | - 'url' => parametre_url($url, 'i', $initiale), |
|
| 105 | - 'compteur' => $newcompt |
|
| 106 | - ]; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - if (!$initiale && !$url) { |
|
| 110 | - if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 111 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 112 | - } |
|
| 113 | - $memo = null; |
|
| 114 | - $res = []; |
|
| 115 | - } |
|
| 87 | + static $memo = null; |
|
| 88 | + static $res = []; |
|
| 89 | + $out = ''; |
|
| 90 | + if (!$memo || !$initiale && !$url || $initiale !== $memo['initiale']) { |
|
| 91 | + $newcompt = (int) (floor(($compteur - 1) / $pas) * $pas); |
|
| 92 | + // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 93 | + if (!$initiale && !$url && !$memo['compteur']) { |
|
| 94 | + $memo = null; |
|
| 95 | + } |
|
| 96 | + if ($memo) { |
|
| 97 | + $on = ($memo['compteur'] <= $debut && ($newcompt > $debut || $newcompt == $debut && $newcompt == $memo['compteur'])); |
|
| 98 | + $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 99 | + } |
|
| 100 | + if ($initiale) { |
|
| 101 | + $memo = [ |
|
| 102 | + 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 103 | + 'initiale' => $initiale, |
|
| 104 | + 'url' => parametre_url($url, 'i', $initiale), |
|
| 105 | + 'compteur' => $newcompt |
|
| 106 | + ]; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + if (!$initiale && !$url) { |
|
| 110 | + if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 111 | + $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 112 | + } |
|
| 113 | + $memo = null; |
|
| 114 | + $res = []; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return $out; |
|
| 117 | + return $out; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -133,24 +133,24 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') { |
| 136 | - static $time = null; |
|
| 137 | - if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 138 | - return ''; |
|
| 139 | - } |
|
| 136 | + static $time = null; |
|
| 137 | + if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 138 | + return ''; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - if (is_null($time)) { |
|
| 142 | - $time = time(); |
|
| 143 | - } |
|
| 144 | - $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 141 | + if (is_null($time)) { |
|
| 142 | + $time = time(); |
|
| 143 | + } |
|
| 144 | + $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 145 | 145 | |
| 146 | - if ( |
|
| 147 | - $imessage != 'non' && !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 148 | - && $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 149 | - ) { |
|
| 150 | - return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 151 | - } elseif (strlen($email) && autoriser('voir', 'auteur', $id_auteur)) { |
|
| 152 | - return 'mailto:' . $email; |
|
| 153 | - } else { |
|
| 154 | - return ''; |
|
| 155 | - } |
|
| 146 | + if ( |
|
| 147 | + $imessage != 'non' && !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 148 | + && $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 149 | + ) { |
|
| 150 | + return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 151 | + } elseif (strlen($email) && autoriser('voir', 'auteur', $id_auteur)) { |
|
| 152 | + return 'mailto:' . $email; |
|
| 153 | + } else { |
|
| 154 | + return ''; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | if ($memo) { |
| 97 | 97 | $on = ($memo['compteur'] <= $debut && ($newcompt > $debut || $newcompt == $debut && $newcompt == $memo['compteur'])); |
| 98 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 98 | + $res[] = "<li class='pagination-item'>".lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination').'</li>'; |
|
| 99 | 99 | } |
| 100 | 100 | if ($initiale) { |
| 101 | 101 | $memo = [ |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | if (!$initiale && !$url) { |
| 110 | 110 | if ((is_countable($res) ? count($res) : 0) > 1) { |
| 111 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 111 | + $out = "<ul class='pagination-items'>".implode(' ', $res).'</ul>'; |
|
| 112 | 112 | } |
| 113 | 113 | $memo = null; |
| 114 | 114 | $res = []; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | ) { |
| 150 | 150 | return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
| 151 | 151 | } elseif (strlen($email) && autoriser('voir', 'auteur', $id_auteur)) { |
| 152 | - return 'mailto:' . $email; |
|
| 152 | + return 'mailto:'.$email; |
|
| 153 | 153 | } else { |
| 154 | 154 | return ''; |
| 155 | 155 | } |
@@ -10,24 +10,24 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function lister_traductions($id_trad, $objet) { |
| 17 | - $table_objet_sql = table_objet_sql($objet); |
|
| 18 | - $primary = id_table_objet($objet); |
|
| 17 | + $table_objet_sql = table_objet_sql($objet); |
|
| 18 | + $primary = id_table_objet($objet); |
|
| 19 | 19 | |
| 20 | - $select = "$primary as id,lang"; |
|
| 21 | - $where = 'id_trad=' . (int) $id_trad; |
|
| 22 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 23 | - $desc = $trouver_table($table_objet_sql); |
|
| 24 | - if (isset($desc['field']['statut'])) { |
|
| 25 | - $select .= ',statut'; |
|
| 26 | - $where .= ' AND statut!=' . sql_quote('poubelle'); |
|
| 27 | - } |
|
| 20 | + $select = "$primary as id,lang"; |
|
| 21 | + $where = 'id_trad=' . (int) $id_trad; |
|
| 22 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 23 | + $desc = $trouver_table($table_objet_sql); |
|
| 24 | + if (isset($desc['field']['statut'])) { |
|
| 25 | + $select .= ',statut'; |
|
| 26 | + $where .= ' AND statut!=' . sql_quote('poubelle'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - $rows = sql_allfetsel($select, $table_objet_sql, $where); |
|
| 30 | - lang_select(); |
|
| 29 | + $rows = sql_allfetsel($select, $table_objet_sql, $where); |
|
| 30 | + lang_select(); |
|
| 31 | 31 | |
| 32 | - return $rows; |
|
| 32 | + return $rows; |
|
| 33 | 33 | } |
@@ -18,12 +18,12 @@ |
||
| 18 | 18 | $primary = id_table_objet($objet); |
| 19 | 19 | |
| 20 | 20 | $select = "$primary as id,lang"; |
| 21 | - $where = 'id_trad=' . (int) $id_trad; |
|
| 21 | + $where = 'id_trad='.(int) $id_trad; |
|
| 22 | 22 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 23 | 23 | $desc = $trouver_table($table_objet_sql); |
| 24 | 24 | if (isset($desc['field']['statut'])) { |
| 25 | 25 | $select .= ',statut'; |
| 26 | - $where .= ' AND statut!=' . sql_quote('poubelle'); |
|
| 26 | + $where .= ' AND statut!='.sql_quote('poubelle'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | $rows = sql_allfetsel($select, $table_objet_sql, $where); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | function deplacement_restreint($objet, $statut) { |
| 25 | 25 | |
| 26 | - return match ($objet) { |
|
| 27 | - 'rubrique' => !$GLOBALS['connect_toutes_rubriques'], |
|
| 28 | - 'article', 'site', 'syndic', 'breve' => $statut == 'publie', |
|
| 29 | - default => $statut ? $statut == 'publie' : false, |
|
| 30 | - }; |
|
| 26 | + return match ($objet) { |
|
| 27 | + 'rubrique' => !$GLOBALS['connect_toutes_rubriques'], |
|
| 28 | + 'article', 'site', 'syndic', 'breve' => $statut == 'publie', |
|
| 29 | + default => $statut ? $statut == 'publie' : false, |
|
| 30 | + }; |
|
| 31 | 31 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $checked = false; |
| 45 | 45 | $res = ''; |
| 46 | 46 | if (is_array($info) && $info['count'] > 0) { |
| 47 | - $res .= '<p>' . _T('info_selection_chemin_acces') . '</p>'; |
|
| 47 | + $res .= '<p>'._T('info_selection_chemin_acces').'</p>'; |
|
| 48 | 48 | $res .= '<ul>'; |
| 49 | 49 | $n = 0; |
| 50 | 50 | for ($i = 0; $i < $info['count']; $i++) { |
@@ -52,18 +52,18 @@ discard block |
||
| 52 | 52 | if (is_array($names)) { |
| 53 | 53 | for ($j = 0; $j < $names['count']; $j++) { |
| 54 | 54 | $n++; |
| 55 | - $res .= '<li><input name="base_ldap" value="' . spip_htmlspecialchars($names[$j]) . "\" type='radio' id='tab$n'"; |
|
| 55 | + $res .= '<li><input name="base_ldap" value="'.spip_htmlspecialchars($names[$j])."\" type='radio' id='tab$n'"; |
|
| 56 | 56 | if (!$checked) { |
| 57 | 57 | $res .= ' checked="checked"'; |
| 58 | 58 | $checked = true; |
| 59 | 59 | } |
| 60 | 60 | $res .= ' />'; |
| 61 | - $res .= "<label for='tab$n'>" . spip_htmlspecialchars($names[$j]) . "</label></li>\n"; |
|
| 61 | + $res .= "<label for='tab$n'>".spip_htmlspecialchars($names[$j])."</label></li>\n"; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | $res .= '</ul>'; |
| 66 | - $res .= _T('info_ou') . ' '; |
|
| 66 | + $res .= _T('info_ou').' '; |
|
| 67 | 67 | } |
| 68 | 68 | $res .= "<br />\n<input name=\"base_ldap\" value=\"\" type='radio' id='manuel'"; |
| 69 | 69 | if (!$checked) { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $res .= ' />' |
| 75 | - . "\n<label for='manuel'>" . _T('entree_chemin_acces') . '</label> ' |
|
| 75 | + . "\n<label for='manuel'>"._T('entree_chemin_acces').'</label> ' |
|
| 76 | 76 | . "\n<fieldset>" |
| 77 | 77 | . "<input type='text' name='base_ldap_text' class='text' value=\"$base_ldap_text\" size='40' />" |
| 78 | 78 | . "\n</fieldset>" |
@@ -12,77 +12,77 @@ |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | function install_etape_ldap3_dist() { |
| 19 | - $info = []; |
|
| 20 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | - $login_ldap = _request('login_ldap'); |
|
| 22 | - $pass_ldap = _request('pass_ldap'); |
|
| 23 | - $port_ldap = _request('port_ldap'); |
|
| 19 | + $info = []; |
|
| 20 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | + $login_ldap = _request('login_ldap'); |
|
| 22 | + $pass_ldap = _request('pass_ldap'); |
|
| 23 | + $port_ldap = _request('port_ldap'); |
|
| 24 | 24 | |
| 25 | - $base_ldap_text = defined('_INSTALL_BASE_LDAP') |
|
| 26 | - ? _INSTALL_BASE_LDAP |
|
| 27 | - : 'ou=users, dc=mon-domaine, dc=com'; |
|
| 25 | + $base_ldap_text = defined('_INSTALL_BASE_LDAP') |
|
| 26 | + ? _INSTALL_BASE_LDAP |
|
| 27 | + : 'ou=users, dc=mon-domaine, dc=com'; |
|
| 28 | 28 | |
| 29 | - $minipage = new Installation(); |
|
| 30 | - echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 29 | + $minipage = new Installation(); |
|
| 30 | + echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 31 | 31 | |
| 32 | - echo info_etape( |
|
| 33 | - _T('info_chemin_acces_1'), |
|
| 34 | - info_progression_etape(3, 'etape_ldap', 'install/') |
|
| 35 | - ), |
|
| 36 | - _T('info_chemin_acces_2'); |
|
| 32 | + echo info_etape( |
|
| 33 | + _T('info_chemin_acces_1'), |
|
| 34 | + info_progression_etape(3, 'etape_ldap', 'install/') |
|
| 35 | + ), |
|
| 36 | + _T('info_chemin_acces_2'); |
|
| 37 | 37 | |
| 38 | - $ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap"); |
|
| 39 | - if ($ldap_link) { |
|
| 40 | - @ldap_bind($ldap_link, "$login_ldap", "$pass_ldap"); |
|
| 41 | - $result = @ldap_read($ldap_link, '', 'objectclass=*', ['namingContexts']); |
|
| 42 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 43 | - @ldap_close($ldap_link); |
|
| 44 | - } |
|
| 38 | + $ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap"); |
|
| 39 | + if ($ldap_link) { |
|
| 40 | + @ldap_bind($ldap_link, "$login_ldap", "$pass_ldap"); |
|
| 41 | + $result = @ldap_read($ldap_link, '', 'objectclass=*', ['namingContexts']); |
|
| 42 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 43 | + @ldap_close($ldap_link); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $checked = false; |
|
| 47 | - $res = ''; |
|
| 48 | - if (is_array($info) && $info['count'] > 0) { |
|
| 49 | - $res .= '<p>' . _T('info_selection_chemin_acces') . '</p>'; |
|
| 50 | - $res .= '<ul>'; |
|
| 51 | - $n = 0; |
|
| 52 | - for ($i = 0; $i < $info['count']; $i++) { |
|
| 53 | - $names = $info[$i]['namingcontexts']; |
|
| 54 | - if (is_array($names)) { |
|
| 55 | - for ($j = 0; $j < $names['count']; $j++) { |
|
| 56 | - $n++; |
|
| 57 | - $res .= '<li><input name="base_ldap" value="' . spip_htmlspecialchars($names[$j]) . "\" type='radio' id='tab$n'"; |
|
| 58 | - if (!$checked) { |
|
| 59 | - $res .= ' checked="checked"'; |
|
| 60 | - $checked = true; |
|
| 61 | - } |
|
| 62 | - $res .= ' />'; |
|
| 63 | - $res .= "<label for='tab$n'>" . spip_htmlspecialchars($names[$j]) . "</label></li>\n"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= '</ul>'; |
|
| 68 | - $res .= _T('info_ou') . ' '; |
|
| 69 | - } |
|
| 70 | - $res .= "<br />\n<input name=\"base_ldap\" value=\"\" type='radio' id='manuel'"; |
|
| 71 | - if (!$checked) { |
|
| 72 | - $res .= ' checked="checked"'; |
|
| 73 | - $checked = true; |
|
| 74 | - } |
|
| 46 | + $checked = false; |
|
| 47 | + $res = ''; |
|
| 48 | + if (is_array($info) && $info['count'] > 0) { |
|
| 49 | + $res .= '<p>' . _T('info_selection_chemin_acces') . '</p>'; |
|
| 50 | + $res .= '<ul>'; |
|
| 51 | + $n = 0; |
|
| 52 | + for ($i = 0; $i < $info['count']; $i++) { |
|
| 53 | + $names = $info[$i]['namingcontexts']; |
|
| 54 | + if (is_array($names)) { |
|
| 55 | + for ($j = 0; $j < $names['count']; $j++) { |
|
| 56 | + $n++; |
|
| 57 | + $res .= '<li><input name="base_ldap" value="' . spip_htmlspecialchars($names[$j]) . "\" type='radio' id='tab$n'"; |
|
| 58 | + if (!$checked) { |
|
| 59 | + $res .= ' checked="checked"'; |
|
| 60 | + $checked = true; |
|
| 61 | + } |
|
| 62 | + $res .= ' />'; |
|
| 63 | + $res .= "<label for='tab$n'>" . spip_htmlspecialchars($names[$j]) . "</label></li>\n"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= '</ul>'; |
|
| 68 | + $res .= _T('info_ou') . ' '; |
|
| 69 | + } |
|
| 70 | + $res .= "<br />\n<input name=\"base_ldap\" value=\"\" type='radio' id='manuel'"; |
|
| 71 | + if (!$checked) { |
|
| 72 | + $res .= ' checked="checked"'; |
|
| 73 | + $checked = true; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $res .= ' />' |
|
| 77 | - . "\n<label for='manuel'>" . _T('entree_chemin_acces') . '</label> ' |
|
| 78 | - . "\n<fieldset>" |
|
| 79 | - . "<input type='text' name='base_ldap_text' class='text' value=\"$base_ldap_text\" size='40' />" |
|
| 80 | - . "\n</fieldset>" |
|
| 81 | - . "\n<input type='hidden' name='etape' value='ldap4' />" |
|
| 82 | - . install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 83 | - . bouton_suivant(); |
|
| 76 | + $res .= ' />' |
|
| 77 | + . "\n<label for='manuel'>" . _T('entree_chemin_acces') . '</label> ' |
|
| 78 | + . "\n<fieldset>" |
|
| 79 | + . "<input type='text' name='base_ldap_text' class='text' value=\"$base_ldap_text\" size='40' />" |
|
| 80 | + . "\n</fieldset>" |
|
| 81 | + . "\n<input type='hidden' name='etape' value='ldap4' />" |
|
| 82 | + . install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 83 | + . bouton_suivant(); |
|
| 84 | 84 | |
| 85 | - echo generer_form_ecrire('install', $res); |
|
| 85 | + echo generer_form_ecrire('install', $res); |
|
| 86 | 86 | |
| 87 | - echo $minipage->installFinPage(); |
|
| 87 | + echo $minipage->installFinPage(); |
|
| 88 | 88 | } |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | if ($fail) { |
| 40 | 40 | echo info_etape(_T('info_chemin_acces_annuaire')), |
| 41 | 41 | info_progression_etape(3, 'etape_ldap', 'install/', true), |
| 42 | - "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 43 | - ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 42 | + "<div class='error'><p><b>"._T('avis_operation_echec').'</b></p><p>'._T('avis_chemin_invalide_1'), |
|
| 43 | + ' (<tt>'.spip_htmlspecialchars($base_ldap).'</tt>) '._T('avis_chemin_invalide_2').'</p></div>'; |
|
| 44 | 44 | } else { |
| 45 | 45 | info_etape(_T('info_reglage_ldap')); |
| 46 | 46 | echo info_progression_etape(4, 'etape_ldap', 'install/'); |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
| 55 | 55 | . "<input type='hidden' name='etape' value='ldap5' />" |
| 56 | - . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 56 | + . "<input type='hidden' name='base_ldap' value='".spip_htmlentities($base_ldap)."' />" |
|
| 57 | 57 | . fieldset( |
| 58 | 58 | _T('info_statut_utilisateurs_1'), |
| 59 | 59 | [ |
| 60 | 60 | 'statut_ldap' => [ |
| 61 | - 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 61 | + 'label' => _T('info_statut_utilisateurs_2').'<br />', |
|
| 62 | 62 | 'valeur' => $statut_ldap, |
| 63 | 63 | 'alternatives' => $statuts |
| 64 | 64 | ] |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | function liste_statuts_ldap() { |
| 77 | 77 | $recom = [ |
| 78 | - 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 79 | - 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 80 | - 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 78 | + 'info_administrateurs' => ('<b>'._T('info_administrateur_1').'</b> '._T('info_administrateur_2').'<br />'), |
|
| 79 | + 'info_redacteurs' => ('<b>'._T('info_redacteur_1').'</b> '._T('info_redacteur_2').'<br />'), |
|
| 80 | + 'info_visiteurs' => ('<b>'._T('info_visiteur_1').'</b> '._T('info_visiteur_2').'<br />') |
|
| 81 | 81 | ]; |
| 82 | 82 | |
| 83 | 83 | $res = []; |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | function install_ldap_correspondances() { |
| 94 | 94 | $champs = []; |
| 95 | 95 | foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
| 96 | - $nom = 'ldap_' . $champ; |
|
| 96 | + $nom = 'ldap_'.$champ; |
|
| 97 | 97 | $val = is_array($v) ? implode(',', $v) : (string) $v; |
| 98 | 98 | $champs[$nom] = [ |
| 99 | - 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 99 | + 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]).'<br />', |
|
| 100 | 100 | 'valeur' => $val |
| 101 | 101 | ]; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - return $champs ? fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />') : ''; |
|
| 104 | + return $champs ? fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2').'<br /><br />') : ''; |
|
| 105 | 105 | } |
@@ -12,96 +12,96 @@ |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('auth/ldap'); |
| 19 | 19 | |
| 20 | 20 | function install_etape_ldap4_dist() { |
| 21 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 22 | - $login_ldap = _request('login_ldap'); |
|
| 23 | - $pass_ldap = _request('pass_ldap'); |
|
| 24 | - $port_ldap = _request('port_ldap'); |
|
| 25 | - $base_ldap = _request('base_ldap'); |
|
| 26 | - $base_ldap_text = _request('base_ldap_text'); |
|
| 27 | - if (!$base_ldap) { |
|
| 28 | - $base_ldap = $base_ldap_text; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $minipage = new Installation(); |
|
| 32 | - echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 33 | - |
|
| 34 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 35 | - @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 36 | - |
|
| 37 | - // Essayer de verifier le chemin fourni |
|
| 38 | - $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 39 | - $fail = (ldap_errno($ldap_link) == 32); |
|
| 40 | - |
|
| 41 | - if ($fail) { |
|
| 42 | - echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 43 | - info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 44 | - "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 45 | - ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 46 | - } else { |
|
| 47 | - info_etape(_T('info_reglage_ldap')); |
|
| 48 | - echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 49 | - |
|
| 50 | - $statuts = liste_statuts_ldap(); |
|
| 51 | - $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 52 | - ? _INSTALL_STATUT_LDAP |
|
| 53 | - : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 57 | - . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 58 | - . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 59 | - . fieldset( |
|
| 60 | - _T('info_statut_utilisateurs_1'), |
|
| 61 | - [ |
|
| 62 | - 'statut_ldap' => [ |
|
| 63 | - 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 64 | - 'valeur' => $statut_ldap, |
|
| 65 | - 'alternatives' => $statuts |
|
| 66 | - ] |
|
| 67 | - ] |
|
| 68 | - ) |
|
| 69 | - . install_ldap_correspondances() |
|
| 70 | - . bouton_suivant(); |
|
| 71 | - |
|
| 72 | - echo generer_form_ecrire('install', $res); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - echo $minipage->installFinPage(); |
|
| 21 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 22 | + $login_ldap = _request('login_ldap'); |
|
| 23 | + $pass_ldap = _request('pass_ldap'); |
|
| 24 | + $port_ldap = _request('port_ldap'); |
|
| 25 | + $base_ldap = _request('base_ldap'); |
|
| 26 | + $base_ldap_text = _request('base_ldap_text'); |
|
| 27 | + if (!$base_ldap) { |
|
| 28 | + $base_ldap = $base_ldap_text; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $minipage = new Installation(); |
|
| 32 | + echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 33 | + |
|
| 34 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 35 | + @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 36 | + |
|
| 37 | + // Essayer de verifier le chemin fourni |
|
| 38 | + $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 39 | + $fail = (ldap_errno($ldap_link) == 32); |
|
| 40 | + |
|
| 41 | + if ($fail) { |
|
| 42 | + echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 43 | + info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 44 | + "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 45 | + ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 46 | + } else { |
|
| 47 | + info_etape(_T('info_reglage_ldap')); |
|
| 48 | + echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 49 | + |
|
| 50 | + $statuts = liste_statuts_ldap(); |
|
| 51 | + $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 52 | + ? _INSTALL_STATUT_LDAP |
|
| 53 | + : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 57 | + . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 58 | + . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 59 | + . fieldset( |
|
| 60 | + _T('info_statut_utilisateurs_1'), |
|
| 61 | + [ |
|
| 62 | + 'statut_ldap' => [ |
|
| 63 | + 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 64 | + 'valeur' => $statut_ldap, |
|
| 65 | + 'alternatives' => $statuts |
|
| 66 | + ] |
|
| 67 | + ] |
|
| 68 | + ) |
|
| 69 | + . install_ldap_correspondances() |
|
| 70 | + . bouton_suivant(); |
|
| 71 | + |
|
| 72 | + echo generer_form_ecrire('install', $res); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + echo $minipage->installFinPage(); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function liste_statuts_ldap() { |
| 79 | - $recom = [ |
|
| 80 | - 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 81 | - 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 82 | - 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - $res = []; |
|
| 86 | - foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 87 | - if (isset($recom[$k])) { |
|
| 88 | - $res[$v] = $recom[$k]; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $res; |
|
| 79 | + $recom = [ |
|
| 80 | + 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 81 | + 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 82 | + 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + $res = []; |
|
| 86 | + foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 87 | + if (isset($recom[$k])) { |
|
| 88 | + $res[$v] = $recom[$k]; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $res; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function install_ldap_correspondances() { |
| 96 | - $champs = []; |
|
| 97 | - foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 98 | - $nom = 'ldap_' . $champ; |
|
| 99 | - $val = is_array($v) ? implode(',', $v) : (string) $v; |
|
| 100 | - $champs[$nom] = [ |
|
| 101 | - 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 102 | - 'valeur' => $val |
|
| 103 | - ]; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $champs ? fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />') : ''; |
|
| 96 | + $champs = []; |
|
| 97 | + foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 98 | + $nom = 'ldap_' . $champ; |
|
| 99 | + $val = is_array($v) ? implode(',', $v) : (string) $v; |
|
| 100 | + $champs[$nom] = [ |
|
| 101 | + 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 102 | + 'valeur' => $val |
|
| 103 | + ]; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $champs ? fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />') : ''; |
|
| 107 | 107 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
| 44 | 44 | |
| 45 | 45 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 46 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 46 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 47 | 47 | |
| 48 | 48 | $fquery = sql_serveur('query', $server_db); |
| 49 | 49 | if ($choix_db == 'new_spip') { |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | if (!$ok) { |
| 54 | 54 | $re = "Impossible de creer la base $re"; |
| 55 | 55 | spip_log($re); |
| 56 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 56 | + return '<p>'._T('avis_connexion_erreur_creer_base')."</p><!--\n$re\n-->"; |
|
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | 59 | $re = "Le nom de la base doit correspondre a $re"; |
| 60 | 60 | spip_log($re); |
| 61 | 61 | |
| 62 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 62 | + return '<p>'._T('avis_connexion_erreur_nom_base')."</p><!--\n$re\n-->"; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
| 71 | 71 | |
| 72 | 72 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 73 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 73 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 74 | 74 | |
| 75 | 75 | // Completer le tableau decrivant la connexion |
| 76 | 76 | |
| 77 | 77 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 78 | 78 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 79 | 79 | |
| 80 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 80 | + $old = sql_showbase($table_prefix.'_meta', $server_db); |
|
| 81 | 81 | if ($old) { |
| 82 | 82 | $old = sql_fetch($old, $server_db); |
| 83 | 83 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $charset['charset']; |
| 97 | 97 | $charsetbase = $charset['charset']; |
| 98 | 98 | } else { |
| 99 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 99 | + spip_log(_DEFAULT_CHARSET.' inconnu du serveur SQL'); |
|
| 100 | 100 | $charsetbase = 'standard'; |
| 101 | 101 | } |
| 102 | 102 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | if ($r) { |
| 147 | 147 | $r = sql_fetch($r, $server_db); |
| 148 | 148 | } |
| 149 | - $version_installee = $r ? (double)$r['valeur'] : 0; |
|
| 149 | + $version_installee = $r ? (double) $r['valeur'] : 0; |
|
| 150 | 150 | if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
| 151 | 151 | $fupdateq( |
| 152 | 152 | 'spip_meta', |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | '', |
| 156 | 156 | $server_db |
| 157 | 157 | ); |
| 158 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 158 | + spip_log('nouvelle version installee: '.$GLOBALS['spip_version_base']); |
|
| 159 | 159 | } |
| 160 | 160 | // eliminer la derniere operation d'admin mal terminee |
| 161 | 161 | // notamment la mise a jour |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | if ($chmod_db) { |
| 183 | 183 | install_fichier_connexion( |
| 184 | 184 | _FILE_CHMOD_TMP, |
| 185 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 185 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n" |
|
| 186 | 186 | ); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -245,16 +245,16 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | |
| 247 | 247 | function install_premier_auteur($email, $login, $nom, #[\SensitiveParameter] $pass, $hidden, $auteur_obligatoire) { |
| 248 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 248 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 249 | 249 | info_etape( |
| 250 | 250 | _T('info_informations_personnelles'), |
| 251 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 252 | - aider('install5', true) . |
|
| 253 | - '<p>' . |
|
| 251 | + '<b>'._T('texte_informations_personnelles_1').'</b>'. |
|
| 252 | + aider('install5', true). |
|
| 253 | + '<p>'. |
|
| 254 | 254 | ($auteur_obligatoire ? |
| 255 | 255 | '' |
| 256 | 256 | : |
| 257 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 257 | + _T('texte_informations_personnelles_2').' '._T('info_laisser_champs_vides') |
|
| 258 | 258 | ) |
| 259 | 259 | ) |
| 260 | 260 | . generer_form_ecrire('install', ( |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | _T('info_identification_publique'), |
| 265 | 265 | [ |
| 266 | 266 | 'nom' => [ |
| 267 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 267 | + 'label' => '<b>'._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 268 | 268 | 'valeur' => $nom, |
| 269 | 269 | 'required' => $auteur_obligatoire, |
| 270 | 270 | ], |
| 271 | 271 | 'email' => [ |
| 272 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 272 | + 'label' => '<b>'._T('entree_adresse_email')."</b>\n", |
|
| 273 | 273 | 'valeur' => $email, |
| 274 | 274 | ] |
| 275 | 275 | ] |
@@ -279,23 +279,23 @@ discard block |
||
| 279 | 279 | _T('entree_identifiants_connexion'), |
| 280 | 280 | [ |
| 281 | 281 | 'login' => [ |
| 282 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 282 | + 'label' => '<b>'._T('entree_login')."</b><br />\n"._T( |
|
| 283 | 283 | 'info_login_trop_court_car_pluriel', |
| 284 | 284 | ['nb' => _LOGIN_TROP_COURT] |
| 285 | - ) . "\n", |
|
| 285 | + )."\n", |
|
| 286 | 286 | 'valeur' => $login, |
| 287 | 287 | 'required' => $auteur_obligatoire, |
| 288 | 288 | ], |
| 289 | 289 | 'pass' => [ |
| 290 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 290 | + 'label' => '<b>'._T('entree_mot_passe')."</b><br />\n"._T( |
|
| 291 | 291 | 'info_passe_trop_court_car_pluriel', |
| 292 | 292 | ['nb' => _PASS_LONGUEUR_MINI] |
| 293 | - ) . "\n", |
|
| 293 | + )."\n", |
|
| 294 | 294 | 'valeur' => $pass, |
| 295 | 295 | 'required' => $auteur_obligatoire, |
| 296 | 296 | ], |
| 297 | 297 | 'pass_verif' => [ |
| 298 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 298 | + 'label' => '<b>'._T('info_confirmer_passe')."</b><br />\n", |
|
| 299 | 299 | 'valeur' => $pass, |
| 300 | 300 | 'required' => $auteur_obligatoire, |
| 301 | 301 | ] |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | if ($res) { |
| 341 | 341 | $res = info_progression_etape(2, 'etape_', 'install/', true) |
| 342 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 342 | + . "<div class='error'><h3>"._T('avis_operation_echec').'</h3>' |
|
| 343 | 343 | . $res |
| 344 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 344 | + . '<p>'._T('texte_operation_echec').'</p>' |
|
| 345 | 345 | . '</div>'; |
| 346 | 346 | } |
| 347 | 347 | } else { |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | |
| 366 | 366 | $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
| 367 | 367 | . (defined('_INSTALL_NAME_DB') ? '' |
| 368 | - : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 368 | + : "\n<input type='hidden' name='sel_db' value=\"".spip_htmlspecialchars($sel_db).'" />'); |
|
| 369 | 369 | |
| 370 | 370 | $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
| 371 | 371 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('inc/headers'); |
@@ -20,199 +20,199 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 22 | 22 | |
| 23 | - // Prefix des tables : |
|
| 24 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | - // a partir de ce qui est envoye a l'installation |
|
| 26 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | - ? $GLOBALS['table_prefix'] |
|
| 29 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | - // S'il est vide on remet spip |
|
| 31 | - if (!$table_prefix) { |
|
| 32 | - $table_prefix = 'spip'; |
|
| 33 | - } |
|
| 34 | - } else { |
|
| 35 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (preg_match(',(.*):(.*),', (string) $adresse_db, $r)) { |
|
| 39 | - [, $adresse_db, $port] = $r; |
|
| 40 | - } else { |
|
| 41 | - $port = ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $GLOBALS['connexions'][$server_db] |
|
| 45 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | - |
|
| 47 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | - |
|
| 50 | - $fquery = sql_serveur('query', $server_db); |
|
| 51 | - if ($choix_db == 'new_spip') { |
|
| 52 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | - if (preg_match($re, (string) $sel_db)) { |
|
| 54 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | - if (!$ok) { |
|
| 56 | - $re = "Impossible de creer la base $re"; |
|
| 57 | - spip_log($re); |
|
| 58 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | - } |
|
| 60 | - } else { |
|
| 61 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | - spip_log($re); |
|
| 63 | - |
|
| 64 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | - // un sql_mode |
|
| 70 | - install_mode_appel($server_db, false); |
|
| 71 | - $GLOBALS['connexions'][$server_db] |
|
| 72 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | - |
|
| 74 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | - |
|
| 77 | - // Completer le tableau decrivant la connexion |
|
| 78 | - |
|
| 79 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | - |
|
| 82 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | - if ($old) { |
|
| 84 | - $old = sql_fetch($old, $server_db); |
|
| 85 | - } |
|
| 86 | - if (!$old) { |
|
| 87 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | - // dans le codage std de SPIP, |
|
| 89 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | - |
|
| 91 | - if ($charset) { |
|
| 92 | - sql_set_charset($charset['charset'], $server_db); |
|
| 93 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | - $charset['charset']; |
|
| 95 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | - $charset['collation']; |
|
| 97 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | - $charset['charset']; |
|
| 99 | - $charsetbase = $charset['charset']; |
|
| 100 | - } else { |
|
| 101 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | - $charsetbase = 'standard'; |
|
| 103 | - } |
|
| 104 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | - creer_base($server_db); // AT LAST |
|
| 106 | - // memoriser avec quel charset on l'a creee |
|
| 107 | - |
|
| 108 | - if ($charset) { |
|
| 109 | - $t = [ |
|
| 110 | - 'nom' => 'charset_sql_base', |
|
| 111 | - 'valeur' => $charset['charset'], |
|
| 112 | - 'impt' => 'non' |
|
| 113 | - ]; |
|
| 114 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 115 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | - $t['valeur'] = $charset['collation']; |
|
| 117 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 118 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | - $t['valeur'] = $charset['charset']; |
|
| 120 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 121 | - } |
|
| 122 | - $t = [ |
|
| 123 | - 'nom' => 'version_installee', |
|
| 124 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | - 'impt' => 'non' |
|
| 126 | - ]; |
|
| 127 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 128 | - $t['nom'] = 'nouvelle_install'; |
|
| 129 | - $t['valeur'] = 1; |
|
| 130 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 131 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | - @sql_insertq( |
|
| 134 | - 'spip_meta', |
|
| 135 | - ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 136 | - [], |
|
| 137 | - $server_db |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - // pour recreer les tables disparues au besoin |
|
| 142 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | - creer_base($server_db); |
|
| 144 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | - |
|
| 146 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | - |
|
| 148 | - if ($r) { |
|
| 149 | - $r = sql_fetch($r, $server_db); |
|
| 150 | - } |
|
| 151 | - $version_installee = $r ? (double)$r['valeur'] : 0; |
|
| 152 | - if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 153 | - $fupdateq( |
|
| 154 | - 'spip_meta', |
|
| 155 | - ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 156 | - "nom='version_installee'", |
|
| 157 | - '', |
|
| 158 | - $server_db |
|
| 159 | - ); |
|
| 160 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | - } |
|
| 162 | - // eliminer la derniere operation d'admin mal terminee |
|
| 163 | - // notamment la mise a jour |
|
| 164 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // recuperer le charset de la connexion dans les meta |
|
| 168 | - $charset = ''; |
|
| 169 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | - if ($r) { |
|
| 171 | - $r = sql_fetch($r, $server_db); |
|
| 172 | - } |
|
| 173 | - if ($r) { |
|
| 174 | - $charset = $r['valeur']; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | - |
|
| 179 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | - if (!$result_ok) { |
|
| 181 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($chmod_db) { |
|
| 185 | - install_fichier_connexion( |
|
| 186 | - _FILE_CHMOD_TMP, |
|
| 187 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | - |
|
| 195 | - if (_FILE_CONNECT && file_exists(_FILE_CONNECT)) { |
|
| 196 | - spip_unlink(_FILE_CONNECT); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - install_fichier_connexion( |
|
| 200 | - _FILE_CONNECT_TMP, |
|
| 201 | - $ligne_rappel |
|
| 202 | - . install_connexion( |
|
| 203 | - $adresse_db, |
|
| 204 | - $port, |
|
| 205 | - $login_db, |
|
| 206 | - $pass_db, |
|
| 207 | - $sel_db, |
|
| 208 | - $server_db, |
|
| 209 | - $table_prefix, |
|
| 210 | - '', |
|
| 211 | - $charset |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 23 | + // Prefix des tables : |
|
| 24 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | + // a partir de ce qui est envoye a l'installation |
|
| 26 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | + ? $GLOBALS['table_prefix'] |
|
| 29 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | + // S'il est vide on remet spip |
|
| 31 | + if (!$table_prefix) { |
|
| 32 | + $table_prefix = 'spip'; |
|
| 33 | + } |
|
| 34 | + } else { |
|
| 35 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (preg_match(',(.*):(.*),', (string) $adresse_db, $r)) { |
|
| 39 | + [, $adresse_db, $port] = $r; |
|
| 40 | + } else { |
|
| 41 | + $port = ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $GLOBALS['connexions'][$server_db] |
|
| 45 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | + |
|
| 47 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | + |
|
| 50 | + $fquery = sql_serveur('query', $server_db); |
|
| 51 | + if ($choix_db == 'new_spip') { |
|
| 52 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | + if (preg_match($re, (string) $sel_db)) { |
|
| 54 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | + if (!$ok) { |
|
| 56 | + $re = "Impossible de creer la base $re"; |
|
| 57 | + spip_log($re); |
|
| 58 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | + } |
|
| 60 | + } else { |
|
| 61 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | + spip_log($re); |
|
| 63 | + |
|
| 64 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | + // un sql_mode |
|
| 70 | + install_mode_appel($server_db, false); |
|
| 71 | + $GLOBALS['connexions'][$server_db] |
|
| 72 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | + |
|
| 74 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | + |
|
| 77 | + // Completer le tableau decrivant la connexion |
|
| 78 | + |
|
| 79 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | + |
|
| 82 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | + if ($old) { |
|
| 84 | + $old = sql_fetch($old, $server_db); |
|
| 85 | + } |
|
| 86 | + if (!$old) { |
|
| 87 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | + // dans le codage std de SPIP, |
|
| 89 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | + |
|
| 91 | + if ($charset) { |
|
| 92 | + sql_set_charset($charset['charset'], $server_db); |
|
| 93 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | + $charset['charset']; |
|
| 95 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | + $charset['collation']; |
|
| 97 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | + $charset['charset']; |
|
| 99 | + $charsetbase = $charset['charset']; |
|
| 100 | + } else { |
|
| 101 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | + $charsetbase = 'standard'; |
|
| 103 | + } |
|
| 104 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | + creer_base($server_db); // AT LAST |
|
| 106 | + // memoriser avec quel charset on l'a creee |
|
| 107 | + |
|
| 108 | + if ($charset) { |
|
| 109 | + $t = [ |
|
| 110 | + 'nom' => 'charset_sql_base', |
|
| 111 | + 'valeur' => $charset['charset'], |
|
| 112 | + 'impt' => 'non' |
|
| 113 | + ]; |
|
| 114 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 115 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | + $t['valeur'] = $charset['collation']; |
|
| 117 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 118 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | + $t['valeur'] = $charset['charset']; |
|
| 120 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 121 | + } |
|
| 122 | + $t = [ |
|
| 123 | + 'nom' => 'version_installee', |
|
| 124 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | + 'impt' => 'non' |
|
| 126 | + ]; |
|
| 127 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 128 | + $t['nom'] = 'nouvelle_install'; |
|
| 129 | + $t['valeur'] = 1; |
|
| 130 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 131 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | + @sql_insertq( |
|
| 134 | + 'spip_meta', |
|
| 135 | + ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 136 | + [], |
|
| 137 | + $server_db |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + // pour recreer les tables disparues au besoin |
|
| 142 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | + creer_base($server_db); |
|
| 144 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | + |
|
| 146 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | + |
|
| 148 | + if ($r) { |
|
| 149 | + $r = sql_fetch($r, $server_db); |
|
| 150 | + } |
|
| 151 | + $version_installee = $r ? (double)$r['valeur'] : 0; |
|
| 152 | + if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 153 | + $fupdateq( |
|
| 154 | + 'spip_meta', |
|
| 155 | + ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 156 | + "nom='version_installee'", |
|
| 157 | + '', |
|
| 158 | + $server_db |
|
| 159 | + ); |
|
| 160 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | + } |
|
| 162 | + // eliminer la derniere operation d'admin mal terminee |
|
| 163 | + // notamment la mise a jour |
|
| 164 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // recuperer le charset de la connexion dans les meta |
|
| 168 | + $charset = ''; |
|
| 169 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | + if ($r) { |
|
| 171 | + $r = sql_fetch($r, $server_db); |
|
| 172 | + } |
|
| 173 | + if ($r) { |
|
| 174 | + $charset = $r['valeur']; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | + |
|
| 179 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | + if (!$result_ok) { |
|
| 181 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($chmod_db) { |
|
| 185 | + install_fichier_connexion( |
|
| 186 | + _FILE_CHMOD_TMP, |
|
| 187 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | + |
|
| 195 | + if (_FILE_CONNECT && file_exists(_FILE_CONNECT)) { |
|
| 196 | + spip_unlink(_FILE_CONNECT); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + install_fichier_connexion( |
|
| 200 | + _FILE_CONNECT_TMP, |
|
| 201 | + $ligne_rappel |
|
| 202 | + . install_connexion( |
|
| 203 | + $adresse_db, |
|
| 204 | + $port, |
|
| 205 | + $login_db, |
|
| 206 | + $pass_db, |
|
| 207 | + $sel_db, |
|
| 208 | + $server_db, |
|
| 209 | + $table_prefix, |
|
| 210 | + '', |
|
| 211 | + $charset |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,166 +227,166 @@ discard block |
||
| 227 | 227 | * @return string Le préfixe corrigé |
| 228 | 228 | */ |
| 229 | 229 | function preparer_prefixe_tables($prefixe) { |
| 230 | - return trim(preg_replace(',^\d+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 230 | + return trim(preg_replace(',^\d+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | function install_propose_ldap() { |
| 234 | - return generer_form_ecrire('install', ( |
|
| 235 | - fieldset( |
|
| 236 | - _T('info_authentification_externe'), |
|
| 237 | - [ |
|
| 238 | - 'etape' => [ |
|
| 239 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 240 | - 'valeur' => 'ldap1', |
|
| 241 | - 'hidden' => true |
|
| 242 | - ] |
|
| 243 | - ], |
|
| 244 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 245 | - ))); |
|
| 234 | + return generer_form_ecrire('install', ( |
|
| 235 | + fieldset( |
|
| 236 | + _T('info_authentification_externe'), |
|
| 237 | + [ |
|
| 238 | + 'etape' => [ |
|
| 239 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 240 | + 'valeur' => 'ldap1', |
|
| 241 | + 'hidden' => true |
|
| 242 | + ] |
|
| 243 | + ], |
|
| 244 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 245 | + ))); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | function install_premier_auteur($email, $login, $nom, #[\SensitiveParameter] $pass, $hidden, $auteur_obligatoire) { |
| 250 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 251 | - info_etape( |
|
| 252 | - _T('info_informations_personnelles'), |
|
| 253 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 254 | - aider('install5', true) . |
|
| 255 | - '<p>' . |
|
| 256 | - ($auteur_obligatoire ? |
|
| 257 | - '' |
|
| 258 | - : |
|
| 259 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 260 | - ) |
|
| 261 | - ) |
|
| 262 | - . generer_form_ecrire('install', ( |
|
| 263 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 264 | - . $hidden |
|
| 265 | - . fieldset( |
|
| 266 | - _T('info_identification_publique'), |
|
| 267 | - [ |
|
| 268 | - 'nom' => [ |
|
| 269 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 270 | - 'valeur' => $nom, |
|
| 271 | - 'required' => $auteur_obligatoire, |
|
| 272 | - ], |
|
| 273 | - 'email' => [ |
|
| 274 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 275 | - 'valeur' => $email, |
|
| 276 | - ] |
|
| 277 | - ] |
|
| 278 | - ) |
|
| 279 | - |
|
| 280 | - . fieldset( |
|
| 281 | - _T('entree_identifiants_connexion'), |
|
| 282 | - [ |
|
| 283 | - 'login' => [ |
|
| 284 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 285 | - 'info_login_trop_court_car_pluriel', |
|
| 286 | - ['nb' => _LOGIN_TROP_COURT] |
|
| 287 | - ) . "\n", |
|
| 288 | - 'valeur' => $login, |
|
| 289 | - 'required' => $auteur_obligatoire, |
|
| 290 | - ], |
|
| 291 | - 'pass' => [ |
|
| 292 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 293 | - 'info_passe_trop_court_car_pluriel', |
|
| 294 | - ['nb' => _PASS_LONGUEUR_MINI] |
|
| 295 | - ) . "\n", |
|
| 296 | - 'valeur' => $pass, |
|
| 297 | - 'required' => $auteur_obligatoire, |
|
| 298 | - ], |
|
| 299 | - 'pass_verif' => [ |
|
| 300 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 301 | - 'valeur' => $pass, |
|
| 302 | - 'required' => $auteur_obligatoire, |
|
| 303 | - ] |
|
| 304 | - ] |
|
| 305 | - ) |
|
| 306 | - . bouton_suivant())); |
|
| 250 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 251 | + info_etape( |
|
| 252 | + _T('info_informations_personnelles'), |
|
| 253 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 254 | + aider('install5', true) . |
|
| 255 | + '<p>' . |
|
| 256 | + ($auteur_obligatoire ? |
|
| 257 | + '' |
|
| 258 | + : |
|
| 259 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 260 | + ) |
|
| 261 | + ) |
|
| 262 | + . generer_form_ecrire('install', ( |
|
| 263 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 264 | + . $hidden |
|
| 265 | + . fieldset( |
|
| 266 | + _T('info_identification_publique'), |
|
| 267 | + [ |
|
| 268 | + 'nom' => [ |
|
| 269 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 270 | + 'valeur' => $nom, |
|
| 271 | + 'required' => $auteur_obligatoire, |
|
| 272 | + ], |
|
| 273 | + 'email' => [ |
|
| 274 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 275 | + 'valeur' => $email, |
|
| 276 | + ] |
|
| 277 | + ] |
|
| 278 | + ) |
|
| 279 | + |
|
| 280 | + . fieldset( |
|
| 281 | + _T('entree_identifiants_connexion'), |
|
| 282 | + [ |
|
| 283 | + 'login' => [ |
|
| 284 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 285 | + 'info_login_trop_court_car_pluriel', |
|
| 286 | + ['nb' => _LOGIN_TROP_COURT] |
|
| 287 | + ) . "\n", |
|
| 288 | + 'valeur' => $login, |
|
| 289 | + 'required' => $auteur_obligatoire, |
|
| 290 | + ], |
|
| 291 | + 'pass' => [ |
|
| 292 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 293 | + 'info_passe_trop_court_car_pluriel', |
|
| 294 | + ['nb' => _PASS_LONGUEUR_MINI] |
|
| 295 | + ) . "\n", |
|
| 296 | + 'valeur' => $pass, |
|
| 297 | + 'required' => $auteur_obligatoire, |
|
| 298 | + ], |
|
| 299 | + 'pass_verif' => [ |
|
| 300 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 301 | + 'valeur' => $pass, |
|
| 302 | + 'required' => $auteur_obligatoire, |
|
| 303 | + ] |
|
| 304 | + ] |
|
| 305 | + ) |
|
| 306 | + . bouton_suivant())); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | function install_etape_3_dist() { |
| 310 | - $ldap_present = _request('ldap_present'); |
|
| 311 | - |
|
| 312 | - if (!$ldap_present) { |
|
| 313 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 314 | - ? _INSTALL_HOST_DB |
|
| 315 | - : _request('adresse_db'); |
|
| 316 | - |
|
| 317 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 318 | - ? _INSTALL_USER_DB |
|
| 319 | - : _request('login_db'); |
|
| 320 | - |
|
| 321 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 322 | - ? _INSTALL_PASS_DB |
|
| 323 | - : _request('pass_db'); |
|
| 324 | - |
|
| 325 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 326 | - ? _INSTALL_SERVER_DB |
|
| 327 | - : _request('server_db'); |
|
| 328 | - |
|
| 329 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 330 | - ? _SPIP_CHMOD |
|
| 331 | - : _request('chmod'); |
|
| 332 | - |
|
| 333 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 334 | - ? _INSTALL_NAME_DB |
|
| 335 | - : _request('choix_db'); |
|
| 336 | - |
|
| 337 | - $sel_db = ($choix_db == 'new_spip') |
|
| 338 | - ? _request('table_new') : $choix_db; |
|
| 339 | - |
|
| 340 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 341 | - |
|
| 342 | - if ($res) { |
|
| 343 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 344 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 345 | - . $res |
|
| 346 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 347 | - . '</div>'; |
|
| 348 | - } |
|
| 349 | - } else { |
|
| 350 | - $res = ''; |
|
| 351 | - [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 352 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if (!$res) { |
|
| 356 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 357 | - include(_FILE_CONNECT_TMP); |
|
| 358 | - } else { |
|
| 359 | - redirige_url_ecrire('install'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 363 | - include(_FILE_CHMOD_TMP); |
|
| 364 | - } else { |
|
| 365 | - redirige_url_ecrire('install'); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 369 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 370 | - : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 371 | - |
|
| 372 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 373 | - |
|
| 374 | - $res = "<div class='success'><b>" |
|
| 375 | - . _T('info_base_installee') |
|
| 376 | - . '</b></div>' |
|
| 377 | - . install_premier_auteur( |
|
| 378 | - _request('email'), |
|
| 379 | - _request('login'), |
|
| 380 | - _request('nom'), |
|
| 381 | - _request('pass'), |
|
| 382 | - $hidden, |
|
| 383 | - $auteur_obligatoire |
|
| 384 | - ) |
|
| 385 | - . (($ldap_present || !function_exists('ldap_connect')) |
|
| 386 | - ? '' : install_propose_ldap()); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - $minipage = new Installation(); |
|
| 391 | - echo $minipage->page($res); |
|
| 310 | + $ldap_present = _request('ldap_present'); |
|
| 311 | + |
|
| 312 | + if (!$ldap_present) { |
|
| 313 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 314 | + ? _INSTALL_HOST_DB |
|
| 315 | + : _request('adresse_db'); |
|
| 316 | + |
|
| 317 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 318 | + ? _INSTALL_USER_DB |
|
| 319 | + : _request('login_db'); |
|
| 320 | + |
|
| 321 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 322 | + ? _INSTALL_PASS_DB |
|
| 323 | + : _request('pass_db'); |
|
| 324 | + |
|
| 325 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 326 | + ? _INSTALL_SERVER_DB |
|
| 327 | + : _request('server_db'); |
|
| 328 | + |
|
| 329 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 330 | + ? _SPIP_CHMOD |
|
| 331 | + : _request('chmod'); |
|
| 332 | + |
|
| 333 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 334 | + ? _INSTALL_NAME_DB |
|
| 335 | + : _request('choix_db'); |
|
| 336 | + |
|
| 337 | + $sel_db = ($choix_db == 'new_spip') |
|
| 338 | + ? _request('table_new') : $choix_db; |
|
| 339 | + |
|
| 340 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 341 | + |
|
| 342 | + if ($res) { |
|
| 343 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 344 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 345 | + . $res |
|
| 346 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 347 | + . '</div>'; |
|
| 348 | + } |
|
| 349 | + } else { |
|
| 350 | + $res = ''; |
|
| 351 | + [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 352 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if (!$res) { |
|
| 356 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 357 | + include(_FILE_CONNECT_TMP); |
|
| 358 | + } else { |
|
| 359 | + redirige_url_ecrire('install'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 363 | + include(_FILE_CHMOD_TMP); |
|
| 364 | + } else { |
|
| 365 | + redirige_url_ecrire('install'); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 369 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 370 | + : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 371 | + |
|
| 372 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 373 | + |
|
| 374 | + $res = "<div class='success'><b>" |
|
| 375 | + . _T('info_base_installee') |
|
| 376 | + . '</b></div>' |
|
| 377 | + . install_premier_auteur( |
|
| 378 | + _request('email'), |
|
| 379 | + _request('login'), |
|
| 380 | + _request('nom'), |
|
| 381 | + _request('pass'), |
|
| 382 | + $hidden, |
|
| 383 | + $auteur_obligatoire |
|
| 384 | + ) |
|
| 385 | + . (($ldap_present || !function_exists('ldap_connect')) |
|
| 386 | + ? '' : install_propose_ldap()); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + $minipage = new Installation(); |
|
| 391 | + echo $minipage->page($res); |
|
| 392 | 392 | } |
@@ -282,8 +282,7 @@ discard block |
||
| 282 | 282 | if ($ids) { |
| 283 | 283 | $ids = array_column($ids, 'id_objet'); |
| 284 | 284 | return implode(',', $ids); |
| 285 | - } |
|
| 286 | - else { |
|
| 285 | + } else { |
|
| 287 | 286 | return '0'; |
| 288 | 287 | } |
| 289 | 288 | } |
@@ -651,8 +650,7 @@ discard block |
||
| 651 | 650 | $logo_bg = timestamp($logo_bg); |
| 652 | 651 | $styles .= ".page_login, .page_spip_pass {background-image:url($logo_bg), url($logo_mini);}\n"; |
| 653 | 652 | $Pile[0]['body_class'] = 'fond_image'; |
| 654 | - } |
|
| 655 | - else { |
|
| 653 | + } else { |
|
| 656 | 654 | $Pile[0]['body_class'] = 'sans_fond'; |
| 657 | 655 | } |
| 658 | 656 | if ($styles) { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // public/interfaces definit des traitements sur les champs qui utilisent des fonctions de inc/texte |
@@ -54,75 +54,75 @@ discard block |
||
| 54 | 54 | * Introduction calculée |
| 55 | 55 | **/ |
| 56 | 56 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 57 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 58 | - if (strlen($descriptif)) { |
|
| 59 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // De preference ce qui est marque <intro>...</intro> |
|
| 63 | - $intro = ''; |
|
| 64 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 65 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 66 | - $zone = substr($texte, 0, $fin); |
|
| 67 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 68 | - if (($deb = strpos($zone, '<intro>')) || str_starts_with($zone, '<intro>')) { |
|
| 69 | - $zone = substr($zone, $deb + 7); |
|
| 70 | - } |
|
| 71 | - $intro .= $zone; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 75 | - // qui inclus raccourcis et modeles |
|
| 76 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 77 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 78 | - // des surcharges et enrichissement de propre |
|
| 79 | - // couper doit se faire apres propre |
|
| 80 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 81 | - |
|
| 82 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 83 | - // large et en se mefiant des tableaux #1323 |
|
| 84 | - |
|
| 85 | - if (strlen($intro)) { |
|
| 86 | - $texte = $intro; |
|
| 87 | - } else { |
|
| 88 | - if ( |
|
| 89 | - !str_contains("\n" . $texte, "\n|") |
|
| 90 | - && strlen($texte) > 2.5 * $longueur |
|
| 91 | - ) { |
|
| 92 | - if (str_contains($texte, '<multi')) { |
|
| 93 | - $texte = extraire_multi($texte); |
|
| 94 | - } |
|
| 95 | - $texte = couper($texte, 2 * $longueur); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // ne pas tenir compte des notes |
|
| 100 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 101 | - $notes('', 'empiler'); |
|
| 102 | - } |
|
| 103 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 104 | - // dans l'introduction. |
|
| 105 | - $texte = supprime_img($texte, ''); |
|
| 106 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 107 | - |
|
| 108 | - if ($notes) { |
|
| 109 | - $notes('', 'depiler'); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if (is_null($suite) && defined('_INTRODUCTION_SUITE')) { |
|
| 113 | - $suite = _INTRODUCTION_SUITE; |
|
| 114 | - } |
|
| 115 | - $texte = couper($texte, $longueur, $suite); |
|
| 116 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 117 | - $texte = typo($texte, true, $connect, []); |
|
| 118 | - |
|
| 119 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 120 | - // une introduction a tojours un <p> |
|
| 121 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 122 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $texte; |
|
| 57 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 58 | + if (strlen($descriptif)) { |
|
| 59 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // De preference ce qui est marque <intro>...</intro> |
|
| 63 | + $intro = ''; |
|
| 64 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 65 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 66 | + $zone = substr($texte, 0, $fin); |
|
| 67 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 68 | + if (($deb = strpos($zone, '<intro>')) || str_starts_with($zone, '<intro>')) { |
|
| 69 | + $zone = substr($zone, $deb + 7); |
|
| 70 | + } |
|
| 71 | + $intro .= $zone; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 75 | + // qui inclus raccourcis et modeles |
|
| 76 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 77 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 78 | + // des surcharges et enrichissement de propre |
|
| 79 | + // couper doit se faire apres propre |
|
| 80 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 81 | + |
|
| 82 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 83 | + // large et en se mefiant des tableaux #1323 |
|
| 84 | + |
|
| 85 | + if (strlen($intro)) { |
|
| 86 | + $texte = $intro; |
|
| 87 | + } else { |
|
| 88 | + if ( |
|
| 89 | + !str_contains("\n" . $texte, "\n|") |
|
| 90 | + && strlen($texte) > 2.5 * $longueur |
|
| 91 | + ) { |
|
| 92 | + if (str_contains($texte, '<multi')) { |
|
| 93 | + $texte = extraire_multi($texte); |
|
| 94 | + } |
|
| 95 | + $texte = couper($texte, 2 * $longueur); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // ne pas tenir compte des notes |
|
| 100 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 101 | + $notes('', 'empiler'); |
|
| 102 | + } |
|
| 103 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 104 | + // dans l'introduction. |
|
| 105 | + $texte = supprime_img($texte, ''); |
|
| 106 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 107 | + |
|
| 108 | + if ($notes) { |
|
| 109 | + $notes('', 'depiler'); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if (is_null($suite) && defined('_INTRODUCTION_SUITE')) { |
|
| 113 | + $suite = _INTRODUCTION_SUITE; |
|
| 114 | + } |
|
| 115 | + $texte = couper($texte, $longueur, $suite); |
|
| 116 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 117 | + $texte = typo($texte, true, $connect, []); |
|
| 118 | + |
|
| 119 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 120 | + // une introduction a tojours un <p> |
|
| 121 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 122 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return $texte; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -157,64 +157,64 @@ discard block |
||
| 157 | 157 | * Code HTML de la pagination |
| 158 | 158 | **/ |
| 159 | 159 | function filtre_pagination_dist( |
| 160 | - $total, |
|
| 161 | - $nom, |
|
| 162 | - $position, |
|
| 163 | - $pas, |
|
| 164 | - $liste = true, |
|
| 165 | - $modele = '', |
|
| 166 | - string $connect = '', |
|
| 167 | - $env = [] |
|
| 160 | + $total, |
|
| 161 | + $nom, |
|
| 162 | + $position, |
|
| 163 | + $pas, |
|
| 164 | + $liste = true, |
|
| 165 | + $modele = '', |
|
| 166 | + string $connect = '', |
|
| 167 | + $env = [] |
|
| 168 | 168 | ) { |
| 169 | - static $ancres = []; |
|
| 170 | - if ($pas < 1) { |
|
| 171 | - return ''; |
|
| 172 | - } |
|
| 173 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 174 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 175 | - |
|
| 176 | - // n'afficher l'ancre qu'une fois |
|
| 177 | - $bloc_ancre = isset($ancres[$ancre]) ? '' : ($ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"); |
|
| 178 | - // liste = false : on ne veut que l'ancre |
|
| 179 | - if (!$liste) { |
|
| 180 | - return $ancres[$ancre]; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 184 | - $pagination = [ |
|
| 185 | - 'debut' => $debut, |
|
| 186 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 187 | - 'total' => $total, |
|
| 188 | - 'position' => (int) $position, |
|
| 189 | - 'pas' => $pas, |
|
| 190 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 191 | - 'page_courante' => floor((int) $position / $pas) + 1, |
|
| 192 | - 'ancre' => $ancre, |
|
| 193 | - 'bloc_ancre' => $bloc_ancre |
|
| 194 | - ]; |
|
| 195 | - if (is_array($env)) { |
|
| 196 | - $pagination = array_merge($env, $pagination); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // Pas de pagination |
|
| 200 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 201 | - return ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($modele) { |
|
| 205 | - $pagination['type_pagination'] = $modele; |
|
| 206 | - $modele = trouver_fond('pagination_' . $modele, 'modeles') ? '_' . $modele : ''; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 210 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 211 | - } |
|
| 212 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 213 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 169 | + static $ancres = []; |
|
| 170 | + if ($pas < 1) { |
|
| 171 | + return ''; |
|
| 172 | + } |
|
| 173 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 174 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 175 | + |
|
| 176 | + // n'afficher l'ancre qu'une fois |
|
| 177 | + $bloc_ancre = isset($ancres[$ancre]) ? '' : ($ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"); |
|
| 178 | + // liste = false : on ne veut que l'ancre |
|
| 179 | + if (!$liste) { |
|
| 180 | + return $ancres[$ancre]; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 184 | + $pagination = [ |
|
| 185 | + 'debut' => $debut, |
|
| 186 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 187 | + 'total' => $total, |
|
| 188 | + 'position' => (int) $position, |
|
| 189 | + 'pas' => $pas, |
|
| 190 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 191 | + 'page_courante' => floor((int) $position / $pas) + 1, |
|
| 192 | + 'ancre' => $ancre, |
|
| 193 | + 'bloc_ancre' => $bloc_ancre |
|
| 194 | + ]; |
|
| 195 | + if (is_array($env)) { |
|
| 196 | + $pagination = array_merge($env, $pagination); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // Pas de pagination |
|
| 200 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 201 | + return ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($modele) { |
|
| 205 | + $pagination['type_pagination'] = $modele; |
|
| 206 | + $modele = trouver_fond('pagination_' . $modele, 'modeles') ? '_' . $modele : ''; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 210 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 211 | + } |
|
| 212 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 213 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
@@ -233,38 +233,38 @@ discard block |
||
| 233 | 233 | * Liste (première page, dernière page). |
| 234 | 234 | **/ |
| 235 | 235 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 236 | - if ($max <= 0 || $max >= $nombre) { |
|
| 237 | - return [1, $nombre]; |
|
| 238 | - } |
|
| 239 | - if ($max <= 1) { |
|
| 240 | - return [$courante, $courante]; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 244 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 245 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 246 | - |
|
| 247 | - return [$premiere, $derniere]; |
|
| 236 | + if ($max <= 0 || $max >= $nombre) { |
|
| 237 | + return [1, $nombre]; |
|
| 238 | + } |
|
| 239 | + if ($max <= 1) { |
|
| 240 | + return [$courante, $courante]; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 244 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 245 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 246 | + |
|
| 247 | + return [$premiere, $derniere]; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 251 | - if ($numero_page === 'tous') { |
|
| 252 | - return '∞'; |
|
| 253 | - } |
|
| 254 | - if ($numero_page === 'prev') { |
|
| 255 | - return '<'; |
|
| 256 | - } |
|
| 257 | - if ($numero_page === 'next') { |
|
| 258 | - return '>'; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return match ($type_pagination) { |
|
| 262 | - 'resultats' => $rang_item + 1, // 1 11 21 31... |
|
| 263 | - 'naturel' => $rang_item ?: 1, // 1 10 20 30... |
|
| 264 | - 'rang' => $rang_item, // 0 10 20 30... |
|
| 265 | - 'page', 'prive' => $numero_page, // 1 2 3 4 5... |
|
| 266 | - default => $numero_page, // 1 2 3 4 5... |
|
| 267 | - }; |
|
| 251 | + if ($numero_page === 'tous') { |
|
| 252 | + return '∞'; |
|
| 253 | + } |
|
| 254 | + if ($numero_page === 'prev') { |
|
| 255 | + return '<'; |
|
| 256 | + } |
|
| 257 | + if ($numero_page === 'next') { |
|
| 258 | + return '>'; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return match ($type_pagination) { |
|
| 262 | + 'resultats' => $rang_item + 1, // 1 11 21 31... |
|
| 263 | + 'naturel' => $rang_item ?: 1, // 1 10 20 30... |
|
| 264 | + 'rang' => $rang_item, // 0 10 20 30... |
|
| 265 | + 'page', 'prive' => $numero_page, // 1 2 3 4 5... |
|
| 266 | + default => $numero_page, // 1 2 3 4 5... |
|
| 267 | + }; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -277,15 +277,15 @@ discard block |
||
| 277 | 277 | **/ |
| 278 | 278 | function lister_objets_avec_logos($type) { |
| 279 | 279 | |
| 280 | - $objet = objet_type($type); |
|
| 281 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 282 | - if ($ids) { |
|
| 283 | - $ids = array_column($ids, 'id_objet'); |
|
| 284 | - return implode(',', $ids); |
|
| 285 | - } |
|
| 286 | - else { |
|
| 287 | - return '0'; |
|
| 288 | - } |
|
| 280 | + $objet = objet_type($type); |
|
| 281 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 282 | + if ($ids) { |
|
| 283 | + $ids = array_column($ids, 'id_objet'); |
|
| 284 | + return implode(',', $ids); |
|
| 285 | + } |
|
| 286 | + else { |
|
| 287 | + return '0'; |
|
| 288 | + } |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -301,14 +301,14 @@ discard block |
||
| 301 | 301 | * Code HTML des notes |
| 302 | 302 | **/ |
| 303 | 303 | function calculer_notes() { |
| 304 | - $r = ''; |
|
| 305 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 306 | - $r = $notes([]); |
|
| 307 | - $notes('', 'depiler'); |
|
| 308 | - $notes('', 'empiler'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return $r; |
|
| 304 | + $r = ''; |
|
| 305 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 306 | + $r = $notes([]); |
|
| 307 | + $notes('', 'depiler'); |
|
| 308 | + $notes('', 'empiler'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return $r; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * @return string |
| 326 | 326 | */ |
| 327 | 327 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 328 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 329 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 328 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 329 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 330 | 330 | |
| 331 | - return ($res[$ids] ?? ''); |
|
| 331 | + return ($res[$ids] ?? ''); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -345,19 +345,19 @@ discard block |
||
| 345 | 345 | * @private |
| 346 | 346 | */ |
| 347 | 347 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 348 | - static $liens = []; |
|
| 349 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 350 | - include_spip('action/editer_liens'); |
|
| 351 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 352 | - if ($objet_lien == $objet && $objet_lien !== $objet_source) { |
|
| 353 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 354 | - } else { |
|
| 355 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 359 | - } |
|
| 360 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 348 | + static $liens = []; |
|
| 349 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 350 | + include_spip('action/editer_liens'); |
|
| 351 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 352 | + if ($objet_lien == $objet && $objet_lien !== $objet_source) { |
|
| 353 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 354 | + } else { |
|
| 355 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 359 | + } |
|
| 360 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -371,24 +371,24 @@ discard block |
||
| 371 | 371 | * @return int|string |
| 372 | 372 | */ |
| 373 | 373 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 374 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 375 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 376 | - if ( |
|
| 377 | - isset($env['form']) && $env['form'] |
|
| 378 | - && isset($env['_objet_lien']) && $env['_objet_lien'] |
|
| 379 | - && (function_exists('lien_triables') || include_spip('action/editer_liens')) |
|
| 380 | - && ($r = objet_associable($env['_objet_lien'])) |
|
| 381 | - && ([$p, $table_lien] = $r) |
|
| 382 | - && lien_triables($table_lien) |
|
| 383 | - && isset($env['objet']) && $env['objet'] |
|
| 384 | - && isset($env['id_objet']) && $env['id_objet'] |
|
| 385 | - && $objet_source |
|
| 386 | - && ($id = (int) $id) |
|
| 387 | - ) { |
|
| 388 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 389 | - return ($rang ?: ''); |
|
| 390 | - } |
|
| 391 | - return recuperer_numero($titre); |
|
| 374 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 375 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 376 | + if ( |
|
| 377 | + isset($env['form']) && $env['form'] |
|
| 378 | + && isset($env['_objet_lien']) && $env['_objet_lien'] |
|
| 379 | + && (function_exists('lien_triables') || include_spip('action/editer_liens')) |
|
| 380 | + && ($r = objet_associable($env['_objet_lien'])) |
|
| 381 | + && ([$p, $table_lien] = $r) |
|
| 382 | + && lien_triables($table_lien) |
|
| 383 | + && isset($env['objet']) && $env['objet'] |
|
| 384 | + && isset($env['id_objet']) && $env['id_objet'] |
|
| 385 | + && $objet_source |
|
| 386 | + && ($id = (int) $id) |
|
| 387 | + ) { |
|
| 388 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 389 | + return ($rang ?: ''); |
|
| 390 | + } |
|
| 391 | + return recuperer_numero($titre); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -417,78 +417,78 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | function calculer_balise_tri(string $champ_ou_sens, string $libelle, string $classe, string $tri_nom, string $tri_champ, string $tri_sens, $liste_tri_sens_defaut, string $nom_pagination = ''): string { |
| 419 | 419 | |
| 420 | - $url = self('&'); |
|
| 421 | - $tri_sens = (int) $tri_sens; |
|
| 422 | - $alias_sens = [ |
|
| 423 | - '<' => -1, |
|
| 424 | - '>' => 1, |
|
| 425 | - 'inverse' => -1, |
|
| 426 | - ]; |
|
| 427 | - |
|
| 428 | - // Normaliser la liste des sens de tri par défaut |
|
| 429 | - // On ajoute un jocker pour les champs non présents dans la liste |
|
| 430 | - // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 431 | - if (is_array($liste_tri_sens_defaut)) { |
|
| 432 | - $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 433 | - } else { |
|
| 434 | - $liste_tri_sens_defaut = [ |
|
| 435 | - '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Les sens de tri actuel et nouveau : |
|
| 440 | - // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 441 | - $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 442 | - if ($is_sens_fixe) { |
|
| 443 | - $tri_sens_actuel = $tri_sens; |
|
| 444 | - $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 445 | - // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 446 | - } elseif ($champ_ou_sens === $tri_champ) { |
|
| 447 | - $tri_sens_actuel = $tri_sens; |
|
| 448 | - $tri_sens_nouveau = $tri_sens * -1; |
|
| 449 | - // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 450 | - } else { |
|
| 451 | - $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // URL : ajouter le champ sur lequel porte le tri |
|
| 455 | - if (!$is_sens_fixe) { |
|
| 456 | - $param_tri = "tri$tri_nom"; |
|
| 457 | - $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 461 | - // c.à.d différent du sens par défaut pour le champ |
|
| 462 | - $param_sens = "sens$tri_nom"; |
|
| 463 | - $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 464 | - if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 465 | - $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 466 | - } else { |
|
| 467 | - $url = parametre_url($url, $param_sens, ''); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - // Drapeau pour garder en session ? |
|
| 471 | - $param_memo = ($is_sens_fixe ? $param_sens : $param_tri); |
|
| 472 | - $url = parametre_url($url, 'var_memotri', str_starts_with($tri_nom, 'session') ? $param_memo : ''); |
|
| 473 | - |
|
| 474 | - // Classes : on indique le sens de tri et l'item exposé |
|
| 475 | - if (!$is_sens_fixe) { |
|
| 476 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 477 | - } |
|
| 478 | - if ($champ_ou_sens === $tri_champ) { |
|
| 479 | - $classe .= ' item-tri_actif'; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // Si on n'est pas en mode "Tout afficher" de la pagination |
|
| 483 | - if ($nom_pagination && parametre_url($url, 'debut' . $nom_pagination) !== '-1') { |
|
| 484 | - // reset la pagination quand on change de mode ou de sens de tri |
|
| 485 | - $url = parametre_url($url, 'debut' . $nom_pagination, ''); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - // Lien |
|
| 489 | - $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 490 | - |
|
| 491 | - return $balise; |
|
| 420 | + $url = self('&'); |
|
| 421 | + $tri_sens = (int) $tri_sens; |
|
| 422 | + $alias_sens = [ |
|
| 423 | + '<' => -1, |
|
| 424 | + '>' => 1, |
|
| 425 | + 'inverse' => -1, |
|
| 426 | + ]; |
|
| 427 | + |
|
| 428 | + // Normaliser la liste des sens de tri par défaut |
|
| 429 | + // On ajoute un jocker pour les champs non présents dans la liste |
|
| 430 | + // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 431 | + if (is_array($liste_tri_sens_defaut)) { |
|
| 432 | + $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 433 | + } else { |
|
| 434 | + $liste_tri_sens_defaut = [ |
|
| 435 | + '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Les sens de tri actuel et nouveau : |
|
| 440 | + // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 441 | + $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 442 | + if ($is_sens_fixe) { |
|
| 443 | + $tri_sens_actuel = $tri_sens; |
|
| 444 | + $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 445 | + // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 446 | + } elseif ($champ_ou_sens === $tri_champ) { |
|
| 447 | + $tri_sens_actuel = $tri_sens; |
|
| 448 | + $tri_sens_nouveau = $tri_sens * -1; |
|
| 449 | + // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 450 | + } else { |
|
| 451 | + $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // URL : ajouter le champ sur lequel porte le tri |
|
| 455 | + if (!$is_sens_fixe) { |
|
| 456 | + $param_tri = "tri$tri_nom"; |
|
| 457 | + $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 461 | + // c.à.d différent du sens par défaut pour le champ |
|
| 462 | + $param_sens = "sens$tri_nom"; |
|
| 463 | + $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 464 | + if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 465 | + $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 466 | + } else { |
|
| 467 | + $url = parametre_url($url, $param_sens, ''); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + // Drapeau pour garder en session ? |
|
| 471 | + $param_memo = ($is_sens_fixe ? $param_sens : $param_tri); |
|
| 472 | + $url = parametre_url($url, 'var_memotri', str_starts_with($tri_nom, 'session') ? $param_memo : ''); |
|
| 473 | + |
|
| 474 | + // Classes : on indique le sens de tri et l'item exposé |
|
| 475 | + if (!$is_sens_fixe) { |
|
| 476 | + $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 477 | + } |
|
| 478 | + if ($champ_ou_sens === $tri_champ) { |
|
| 479 | + $classe .= ' item-tri_actif'; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // Si on n'est pas en mode "Tout afficher" de la pagination |
|
| 483 | + if ($nom_pagination && parametre_url($url, 'debut' . $nom_pagination) !== '-1') { |
|
| 484 | + // reset la pagination quand on change de mode ou de sens de tri |
|
| 485 | + $url = parametre_url($url, 'debut' . $nom_pagination, ''); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + // Lien |
|
| 489 | + $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 490 | + |
|
| 491 | + return $balise; |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | * @return string |
| 505 | 505 | */ |
| 506 | 506 | function tri_protege_champ($t) { |
| 507 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 507 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -517,39 +517,39 @@ discard block |
||
| 517 | 517 | * @return string |
| 518 | 518 | */ |
| 519 | 519 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 520 | - if (str_starts_with($t, 'multi ')) { |
|
| 521 | - return 'multi' . $senstri; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $champ = $t; |
|
| 525 | - |
|
| 526 | - $prefixe = ''; |
|
| 527 | - foreach (['num ', 'sinum '] as $p) { |
|
| 528 | - if (str_starts_with($t, $p)) { |
|
| 529 | - $champ = substr($t, strlen($p)); |
|
| 530 | - $prefixe = $p; |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 535 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 536 | - |
|
| 537 | - if (is_array($from)) { |
|
| 538 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 539 | - foreach ($from as $idt => $table_sql) { |
|
| 540 | - if ( |
|
| 541 | - ($desc = $trouver_table($table_sql)) && isset($desc['field'][$champ]) |
|
| 542 | - ) { |
|
| 543 | - $champ = "$idt.$champ"; |
|
| 544 | - break; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - return match ($prefixe) { |
|
| 549 | - 'num ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}", |
|
| 550 | - 'sinum ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}", |
|
| 551 | - default => $champ . $senstri, |
|
| 552 | - }; |
|
| 520 | + if (str_starts_with($t, 'multi ')) { |
|
| 521 | + return 'multi' . $senstri; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $champ = $t; |
|
| 525 | + |
|
| 526 | + $prefixe = ''; |
|
| 527 | + foreach (['num ', 'sinum '] as $p) { |
|
| 528 | + if (str_starts_with($t, $p)) { |
|
| 529 | + $champ = substr($t, strlen($p)); |
|
| 530 | + $prefixe = $p; |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 535 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 536 | + |
|
| 537 | + if (is_array($from)) { |
|
| 538 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 539 | + foreach ($from as $idt => $table_sql) { |
|
| 540 | + if ( |
|
| 541 | + ($desc = $trouver_table($table_sql)) && isset($desc['field'][$champ]) |
|
| 542 | + ) { |
|
| 543 | + $champ = "$idt.$champ"; |
|
| 544 | + break; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + return match ($prefixe) { |
|
| 549 | + 'num ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}", |
|
| 550 | + 'sinum ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}", |
|
| 551 | + default => $champ . $senstri, |
|
| 552 | + }; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -563,17 +563,17 @@ discard block |
||
| 563 | 563 | * @return string |
| 564 | 564 | */ |
| 565 | 565 | function tri_champ_select($t) { |
| 566 | - if (str_starts_with($t, 'multi ')) { |
|
| 567 | - $t = substr($t, 6); |
|
| 568 | - $t = preg_replace(',\s,', '', $t); |
|
| 566 | + if (str_starts_with($t, 'multi ')) { |
|
| 567 | + $t = substr($t, 6); |
|
| 568 | + $t = preg_replace(',\s,', '', $t); |
|
| 569 | 569 | |
| 570 | - return sql_multi($t, $GLOBALS['spip_lang']); |
|
| 571 | - } |
|
| 572 | - if (trim($t) == 'hasard') { |
|
| 573 | - return 'rand() AS hasard'; |
|
| 574 | - } |
|
| 570 | + return sql_multi($t, $GLOBALS['spip_lang']); |
|
| 571 | + } |
|
| 572 | + if (trim($t) == 'hasard') { |
|
| 573 | + return 'rand() AS hasard'; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - return "''"; |
|
| 576 | + return "''"; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -585,15 +585,15 @@ discard block |
||
| 585 | 585 | * @return string |
| 586 | 586 | */ |
| 587 | 587 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 588 | - if (!is_array($valeurs)) { |
|
| 589 | - return ''; |
|
| 590 | - } |
|
| 591 | - $f = sql_serveur('quote', $serveur, true); |
|
| 592 | - if (!is_string($f) || !$f) { |
|
| 593 | - return ''; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return implode(',', array_map($f, array_unique($valeurs))); |
|
| 588 | + if (!is_array($valeurs)) { |
|
| 589 | + return ''; |
|
| 590 | + } |
|
| 591 | + $f = sql_serveur('quote', $serveur, true); |
|
| 592 | + if (!is_string($f) || !$f) { |
|
| 593 | + return ''; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return implode(',', array_map($f, array_unique($valeurs))); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -616,22 +616,22 @@ discard block |
||
| 616 | 616 | * Valeur $defaut sinon. |
| 617 | 617 | **/ |
| 618 | 618 | function appliquer_filtre_sinon($arg, $filtre, $args, mixed $defaut = '') { |
| 619 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 620 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 621 | - if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 622 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 623 | - $args[1] = $args[0]; |
|
| 624 | - $args[0] = $filtre; |
|
| 625 | - return image_graver(image_filtrer($args)); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - $f = chercher_filtre($filtre); |
|
| 629 | - if (!$f) { |
|
| 630 | - return $defaut; |
|
| 631 | - } |
|
| 632 | - array_shift($args); // enlever $arg |
|
| 633 | - array_shift($args); // enlever $filtre |
|
| 634 | - return $f($arg, ...$args); |
|
| 619 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 620 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 621 | + if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) { |
|
| 622 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 623 | + $args[1] = $args[0]; |
|
| 624 | + $args[0] = $filtre; |
|
| 625 | + return image_graver(image_filtrer($args)); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + $f = chercher_filtre($filtre); |
|
| 629 | + if (!$f) { |
|
| 630 | + return $defaut; |
|
| 631 | + } |
|
| 632 | + array_shift($args); // enlever $arg |
|
| 633 | + array_shift($args); // enlever $filtre |
|
| 634 | + return $f($arg, ...$args); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -641,30 +641,30 @@ discard block |
||
| 641 | 641 | * @return string |
| 642 | 642 | */ |
| 643 | 643 | function filtre_styles_inline_page_login_pass_dist(&$Pile, ...$dummy) { |
| 644 | - $styles = ''; |
|
| 645 | - include_spip('inc/config'); |
|
| 646 | - if ($couleur = lire_config('couleur_login')) { |
|
| 647 | - include_spip('inc/filtres_images_mini'); |
|
| 648 | - $hs = couleur_hex_to_hsl($couleur, 'h, s'); |
|
| 649 | - $l = couleur_hex_to_hsl($couleur, 'l'); |
|
| 650 | - $styles .= ":root {--spip-login-color-theme--hs: {$hs};--spip-login-color-theme--l: {$l};}\n"; |
|
| 651 | - } |
|
| 652 | - $logo_bg = _DIR_IMG . 'spip_fond_login.jpg'; |
|
| 653 | - if (file_exists($logo_bg)) { |
|
| 654 | - include_spip('inc/filtres_images_mini'); |
|
| 655 | - $logo_mini = image_reduire($logo_bg, 64, 64); |
|
| 656 | - $logo_mini = extraire_attribut($logo_mini, 'src'); |
|
| 657 | - $embarque_fichier = charger_filtre('embarque_fichier'); |
|
| 658 | - $logo_mini = $embarque_fichier($logo_mini); |
|
| 659 | - $logo_bg = timestamp($logo_bg); |
|
| 660 | - $styles .= ".page_login, .page_spip_pass {background-image:url($logo_bg), url($logo_mini);}\n"; |
|
| 661 | - $Pile[0]['body_class'] = 'fond_image'; |
|
| 662 | - } |
|
| 663 | - else { |
|
| 664 | - $Pile[0]['body_class'] = 'sans_fond'; |
|
| 665 | - } |
|
| 666 | - if ($styles) { |
|
| 667 | - $styles = "<style type='text/css'>$styles</style>"; |
|
| 668 | - } |
|
| 669 | - return $styles; |
|
| 644 | + $styles = ''; |
|
| 645 | + include_spip('inc/config'); |
|
| 646 | + if ($couleur = lire_config('couleur_login')) { |
|
| 647 | + include_spip('inc/filtres_images_mini'); |
|
| 648 | + $hs = couleur_hex_to_hsl($couleur, 'h, s'); |
|
| 649 | + $l = couleur_hex_to_hsl($couleur, 'l'); |
|
| 650 | + $styles .= ":root {--spip-login-color-theme--hs: {$hs};--spip-login-color-theme--l: {$l};}\n"; |
|
| 651 | + } |
|
| 652 | + $logo_bg = _DIR_IMG . 'spip_fond_login.jpg'; |
|
| 653 | + if (file_exists($logo_bg)) { |
|
| 654 | + include_spip('inc/filtres_images_mini'); |
|
| 655 | + $logo_mini = image_reduire($logo_bg, 64, 64); |
|
| 656 | + $logo_mini = extraire_attribut($logo_mini, 'src'); |
|
| 657 | + $embarque_fichier = charger_filtre('embarque_fichier'); |
|
| 658 | + $logo_mini = $embarque_fichier($logo_mini); |
|
| 659 | + $logo_bg = timestamp($logo_bg); |
|
| 660 | + $styles .= ".page_login, .page_spip_pass {background-image:url($logo_bg), url($logo_mini);}\n"; |
|
| 661 | + $Pile[0]['body_class'] = 'fond_image'; |
|
| 662 | + } |
|
| 663 | + else { |
|
| 664 | + $Pile[0]['body_class'] = 'sans_fond'; |
|
| 665 | + } |
|
| 666 | + if ($styles) { |
|
| 667 | + $styles = "<style type='text/css'>$styles</style>"; |
|
| 668 | + } |
|
| 669 | + return $styles; |
|
| 670 | 670 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $texte = $intro; |
| 87 | 87 | } else { |
| 88 | 88 | if ( |
| 89 | - !str_contains("\n" . $texte, "\n|") |
|
| 89 | + !str_contains("\n".$texte, "\n|") |
|
| 90 | 90 | && strlen($texte) > 2.5 * $longueur |
| 91 | 91 | ) { |
| 92 | 92 | if (str_contains($texte, '<multi')) { |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | if ($pas < 1) { |
| 171 | 171 | return ''; |
| 172 | 172 | } |
| 173 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 174 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 174 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 175 | 175 | |
| 176 | 176 | // n'afficher l'ancre qu'une fois |
| 177 | - $bloc_ancre = isset($ancres[$ancre]) ? '' : ($ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"); |
|
| 177 | + $bloc_ancre = isset($ancres[$ancre]) ? '' : ($ancres[$ancre] = "<a id='".$ancre."' class='pagination_ancre'></a>"); |
|
| 178 | 178 | // liste = false : on ne veut que l'ancre |
| 179 | 179 | if (!$liste) { |
| 180 | 180 | return $ancres[$ancre]; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | if ($modele) { |
| 205 | 205 | $pagination['type_pagination'] = $modele; |
| 206 | - $modele = trouver_fond('pagination_' . $modele, 'modeles') ? '_' . $modele : ''; |
|
| 206 | + $modele = trouver_fond('pagination_'.$modele, 'modeles') ? '_'.$modele : ''; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | function lister_objets_avec_logos($type) { |
| 279 | 279 | |
| 280 | 280 | $objet = objet_type($type); |
| 281 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 281 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode='.sql_quote('logoon').' AND L.objet='.sql_quote($objet)); |
|
| 282 | 282 | if ($ids) { |
| 283 | 283 | $ids = array_column($ids, 'id_objet'); |
| 284 | 284 | return implode(',', $ids); |
@@ -473,16 +473,16 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | // Classes : on indique le sens de tri et l'item exposé |
| 475 | 475 | if (!$is_sens_fixe) { |
| 476 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 476 | + $classe .= ' item-tri item-tri_'.($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 477 | 477 | } |
| 478 | 478 | if ($champ_ou_sens === $tri_champ) { |
| 479 | 479 | $classe .= ' item-tri_actif'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // Si on n'est pas en mode "Tout afficher" de la pagination |
| 483 | - if ($nom_pagination && parametre_url($url, 'debut' . $nom_pagination) !== '-1') { |
|
| 483 | + if ($nom_pagination && parametre_url($url, 'debut'.$nom_pagination) !== '-1') { |
|
| 484 | 484 | // reset la pagination quand on change de mode ou de sens de tri |
| 485 | - $url = parametre_url($url, 'debut' . $nom_pagination, ''); |
|
| 485 | + $url = parametre_url($url, 'debut'.$nom_pagination, ''); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | // Lien |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | */ |
| 519 | 519 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 520 | 520 | if (str_starts_with($t, 'multi ')) { |
| 521 | - return 'multi' . $senstri; |
|
| 521 | + return 'multi'.$senstri; |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | $champ = $t; |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | return match ($prefixe) { |
| 549 | 549 | 'num ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}", |
| 550 | 550 | 'sinum ' => "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}", |
| 551 | - default => $champ . $senstri, |
|
| 551 | + default => $champ.$senstri, |
|
| 552 | 552 | }; |
| 553 | 553 | } |
| 554 | 554 | |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | $l = couleur_hex_to_hsl($couleur, 'l'); |
| 650 | 650 | $styles .= ":root {--spip-login-color-theme--hs: {$hs};--spip-login-color-theme--l: {$l};}\n"; |
| 651 | 651 | } |
| 652 | - $logo_bg = _DIR_IMG . 'spip_fond_login.jpg'; |
|
| 652 | + $logo_bg = _DIR_IMG.'spip_fond_login.jpg'; |
|
| 653 | 653 | if (file_exists($logo_bg)) { |
| 654 | 654 | include_spip('inc/filtres_images_mini'); |
| 655 | 655 | $logo_mini = image_reduire($logo_bg, 64, 64); |
@@ -379,8 +379,7 @@ |
||
| 379 | 379 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 380 | 380 | if (test_espace_prive()) { |
| 381 | 381 | return executer_balise_dynamique(...$args); |
| 382 | - } |
|
| 383 | - else { |
|
| 382 | + } else { |
|
| 384 | 383 | $str_args = base64_encode(serialize($args)); |
| 385 | 384 | return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
| 386 | 385 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/texte'); |
@@ -42,229 +42,229 @@ 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') && _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') && _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 | - && _request('var_mode_objet') == $nom |
|
| 133 | - && _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') && _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') && _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 | + && _request('var_mode_objet') == $nom |
|
| 133 | + && _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') || !_VAR_NOCACHE) { |
|
| 159 | - ecrire_fichier($phpfile, $code); |
|
| 160 | - } |
|
| 157 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | + if (!defined('_VAR_NOCACHE') || !_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') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | - || !@file_exists($skel) |
|
| 182 | - || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | - || $date_change > $date |
|
| 184 | - ); |
|
| 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') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | + || !@file_exists($skel) |
|
| 182 | + || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | + || $date_change > $date |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - && preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - !str_contains($corps, '<' . '?') |
|
| 227 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | - ) |
|
| 229 | - ? 'html' |
|
| 230 | - : 'php'; |
|
| 231 | - |
|
| 232 | - $skel = [ |
|
| 233 | - 'squelette' => $nom, |
|
| 234 | - 'source' => $source, |
|
| 235 | - 'process_ins' => $process_ins, |
|
| 236 | - 'invalideurs' => $cache, |
|
| 237 | - 'entetes' => $headers, |
|
| 238 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | - ]; |
|
| 240 | - |
|
| 241 | - // traiter #FILTRE{} et filtres |
|
| 242 | - if (!isset($filtres[$nom])) { |
|
| 243 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | - } |
|
| 245 | - $filtres_headers = []; |
|
| 246 | - if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | - unset($headers['X-Spip-Filtre']); |
|
| 249 | - } |
|
| 250 | - if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | - include_spip('public/sandbox'); |
|
| 252 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | - |
|
| 254 | - if ($process_ins == 'html') { |
|
| 255 | - $skel['process_ins'] = ( |
|
| 256 | - !str_contains($corps, '<' . '?') |
|
| 257 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | - ) |
|
| 259 | - ? 'html' |
|
| 260 | - : 'php'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $skel['entetes'] = $headers; |
|
| 265 | - $skel['texte'] = $corps; |
|
| 266 | - |
|
| 267 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + && preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + !str_contains($corps, '<' . '?') |
|
| 227 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | + ) |
|
| 229 | + ? 'html' |
|
| 230 | + : 'php'; |
|
| 231 | + |
|
| 232 | + $skel = [ |
|
| 233 | + 'squelette' => $nom, |
|
| 234 | + 'source' => $source, |
|
| 235 | + 'process_ins' => $process_ins, |
|
| 236 | + 'invalideurs' => $cache, |
|
| 237 | + 'entetes' => $headers, |
|
| 238 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | + ]; |
|
| 240 | + |
|
| 241 | + // traiter #FILTRE{} et filtres |
|
| 242 | + if (!isset($filtres[$nom])) { |
|
| 243 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | + } |
|
| 245 | + $filtres_headers = []; |
|
| 246 | + if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | + unset($headers['X-Spip-Filtre']); |
|
| 249 | + } |
|
| 250 | + if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | + include_spip('public/sandbox'); |
|
| 252 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | + |
|
| 254 | + if ($process_ins == 'html') { |
|
| 255 | + $skel['process_ins'] = ( |
|
| 256 | + !str_contains($corps, '<' . '?') |
|
| 257 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | + ) |
|
| 259 | + ? 'html' |
|
| 260 | + : 'php'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $skel['entetes'] = $headers; |
|
| 265 | + $skel['texte'] = $corps; |
|
| 266 | + |
|
| 267 | + return $skel; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 279 | 279 | if ($lang_select) lang_select(); |
| 280 | 280 | ?' |
| 281 | - . '>'); |
|
| 281 | + . '>'); |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -298,35 +298,35 @@ discard block |
||
| 298 | 298 | * Code PHP pour inclure le squelette de la balise dynamique |
| 299 | 299 | **/ |
| 300 | 300 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 301 | - if ( |
|
| 302 | - !str_starts_with($file, '/') |
|
| 303 | - // pas de lien symbolique sous Windows |
|
| 304 | - && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | - ) { |
|
| 306 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $lang = $context_compil[4]; |
|
| 310 | - if (preg_match(',\W,', $lang)) { |
|
| 311 | - $lang = ''; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $args = array_map('argumenter_squelette', $args); |
|
| 315 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | - } |
|
| 318 | - $args = join(', ', $args); |
|
| 319 | - |
|
| 320 | - $r = sprintf( |
|
| 321 | - CODE_INCLURE_BALISE, |
|
| 322 | - $file, |
|
| 323 | - $lang, |
|
| 324 | - $nom, |
|
| 325 | - $args, |
|
| 326 | - join(', ', array_map('_q', $context_compil)) |
|
| 327 | - ); |
|
| 328 | - |
|
| 329 | - return $r; |
|
| 301 | + if ( |
|
| 302 | + !str_starts_with($file, '/') |
|
| 303 | + // pas de lien symbolique sous Windows |
|
| 304 | + && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | + ) { |
|
| 306 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $lang = $context_compil[4]; |
|
| 310 | + if (preg_match(',\W,', $lang)) { |
|
| 311 | + $lang = ''; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $args = array_map('argumenter_squelette', $args); |
|
| 315 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | + } |
|
| 318 | + $args = join(', ', $args); |
|
| 319 | + |
|
| 320 | + $r = sprintf( |
|
| 321 | + CODE_INCLURE_BALISE, |
|
| 322 | + $file, |
|
| 323 | + $lang, |
|
| 324 | + $nom, |
|
| 325 | + $args, |
|
| 326 | + join(', ', array_map('_q', $context_compil)) |
|
| 327 | + ); |
|
| 328 | + |
|
| 329 | + return $r; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -344,18 +344,18 @@ discard block |
||
| 344 | 344 | **/ |
| 345 | 345 | function argumenter_squelette($v) { |
| 346 | 346 | |
| 347 | - if (is_object($v)) { |
|
| 348 | - return var_export($v, true); |
|
| 349 | - } elseif (!is_array($v)) { |
|
| 350 | - return "'" . texte_script((string) $v) . "'"; |
|
| 351 | - } else { |
|
| 352 | - $out = []; |
|
| 353 | - foreach ($v as $k => $val) { |
|
| 354 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return 'array(' . join(', ', $out) . ')'; |
|
| 358 | - } |
|
| 347 | + if (is_object($v)) { |
|
| 348 | + return var_export($v, true); |
|
| 349 | + } elseif (!is_array($v)) { |
|
| 350 | + return "'" . texte_script((string) $v) . "'"; |
|
| 351 | + } else { |
|
| 352 | + $out = []; |
|
| 353 | + foreach ($v as $k => $val) { |
|
| 354 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return 'array(' . join(', ', $out) . ')'; |
|
| 358 | + } |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -374,13 +374,13 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 377 | - if (test_espace_prive()) { |
|
| 378 | - return executer_balise_dynamique(...$args); |
|
| 379 | - } |
|
| 380 | - else { |
|
| 381 | - $str_args = base64_encode(serialize($args)); |
|
| 382 | - return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | - } |
|
| 377 | + if (test_espace_prive()) { |
|
| 378 | + return executer_balise_dynamique(...$args); |
|
| 379 | + } |
|
| 380 | + else { |
|
| 381 | + $str_args = base64_encode(serialize($args)); |
|
| 382 | + return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -411,87 +411,87 @@ discard block |
||
| 411 | 411 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 412 | 412 | **/ |
| 413 | 413 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 414 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | - $nom_balise = $nom; |
|
| 416 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | - $nom_balise_generique = ''; |
|
| 418 | - |
|
| 419 | - $appel_php_depuis_modele = false; |
|
| 420 | - if ( |
|
| 421 | - is_array($context_compil) |
|
| 422 | - && !is_numeric($context_compil[3]) |
|
| 423 | - && empty($context_compil[0]) |
|
| 424 | - && empty($context_compil[1]) |
|
| 425 | - && empty($context_compil[2]) |
|
| 426 | - && empty($context_compil[3]) |
|
| 427 | - ) { |
|
| 428 | - $appel_php_depuis_modele = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | - // injecter en premier arg le nom de la balise |
|
| 435 | - array_unshift($args, $nom); |
|
| 436 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | - $nom_balise = $nom_balise_generique; |
|
| 439 | - } |
|
| 440 | - unset($balise_generique); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (!$fonction_balise) { |
|
| 444 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | - erreur_squelette($msg, $context_compil); |
|
| 446 | - |
|
| 447 | - return ''; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // retrouver le fichier qui a déclaré la fonction |
|
| 451 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 455 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 456 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | - |
|
| 462 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | - |
|
| 464 | - if (!is_array($r)) { |
|
| 465 | - return $r; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // verifier que la fonction dyn est la, |
|
| 469 | - // sinon se replier sur la generique si elle existe |
|
| 470 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | - if ( |
|
| 472 | - ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | - && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | - && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | - && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | - ) { |
|
| 477 | - // et lui injecter en premier arg le nom de la balise |
|
| 478 | - array_unshift($r, $nom); |
|
| 479 | - $nom_balise = $nom_balise_generique; |
|
| 480 | - if (!_DIR_RESTREINT) { |
|
| 481 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | - erreur_squelette($msg, $context_compil); |
|
| 486 | - |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($appel_php_depuis_modele) { |
|
| 492 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | - } |
|
| 494 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 414 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | + $nom_balise = $nom; |
|
| 416 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | + $nom_balise_generique = ''; |
|
| 418 | + |
|
| 419 | + $appel_php_depuis_modele = false; |
|
| 420 | + if ( |
|
| 421 | + is_array($context_compil) |
|
| 422 | + && !is_numeric($context_compil[3]) |
|
| 423 | + && empty($context_compil[0]) |
|
| 424 | + && empty($context_compil[1]) |
|
| 425 | + && empty($context_compil[2]) |
|
| 426 | + && empty($context_compil[3]) |
|
| 427 | + ) { |
|
| 428 | + $appel_php_depuis_modele = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | + // injecter en premier arg le nom de la balise |
|
| 435 | + array_unshift($args, $nom); |
|
| 436 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | + $nom_balise = $nom_balise_generique; |
|
| 439 | + } |
|
| 440 | + unset($balise_generique); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (!$fonction_balise) { |
|
| 444 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | + erreur_squelette($msg, $context_compil); |
|
| 446 | + |
|
| 447 | + return ''; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // retrouver le fichier qui a déclaré la fonction |
|
| 451 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 455 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 456 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | + |
|
| 462 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | + |
|
| 464 | + if (!is_array($r)) { |
|
| 465 | + return $r; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // verifier que la fonction dyn est la, |
|
| 469 | + // sinon se replier sur la generique si elle existe |
|
| 470 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | + if ( |
|
| 472 | + ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | + && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | + && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | + && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | + ) { |
|
| 477 | + // et lui injecter en premier arg le nom de la balise |
|
| 478 | + array_unshift($r, $nom); |
|
| 479 | + $nom_balise = $nom_balise_generique; |
|
| 480 | + if (!_DIR_RESTREINT) { |
|
| 481 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | + erreur_squelette($msg, $context_compil); |
|
| 486 | + |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($appel_php_depuis_modele) { |
|
| 492 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | + } |
|
| 494 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -506,23 +506,23 @@ discard block |
||
| 506 | 506 | * @return array|null |
| 507 | 507 | */ |
| 508 | 508 | function chercher_balise_generique($nom) { |
| 509 | - if (!str_contains($nom, '_')) { |
|
| 510 | - return null; |
|
| 511 | - } |
|
| 512 | - $nom_generique = $nom; |
|
| 513 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | - if ($fonction_generique) { |
|
| 517 | - return [ |
|
| 518 | - 'nom' => $nom, |
|
| 519 | - 'nom_generique' => $nom_generique, |
|
| 520 | - 'fonction_generique' => $fonction_generique, |
|
| 521 | - ]; |
|
| 522 | - } |
|
| 523 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | - } |
|
| 525 | - return null; |
|
| 509 | + if (!str_contains($nom, '_')) { |
|
| 510 | + return null; |
|
| 511 | + } |
|
| 512 | + $nom_generique = $nom; |
|
| 513 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | + if ($fonction_generique) { |
|
| 517 | + return [ |
|
| 518 | + 'nom' => $nom, |
|
| 519 | + 'nom_generique' => $nom_generique, |
|
| 520 | + 'fonction_generique' => $fonction_generique, |
|
| 521 | + ]; |
|
| 522 | + } |
|
| 523 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | + } |
|
| 525 | + return null; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | |
@@ -546,51 +546,51 @@ discard block |
||
| 546 | 546 | * @return null; |
| 547 | 547 | **/ |
| 548 | 548 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 549 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | - if ( |
|
| 551 | - isset($GLOBALS['forcer_lang']) |
|
| 552 | - && $GLOBALS['forcer_lang'] |
|
| 553 | - && $lang_select !== 'oui' |
|
| 554 | - ) { |
|
| 555 | - $lang = $GLOBALS['spip_lang']; |
|
| 556 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | - elseif (!strlen($lang)) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 3. l'objet est multilingue ! |
|
| 560 | - elseif ( |
|
| 561 | - $lang_select !== 'oui' |
|
| 562 | - && strlen($titre) > 10 |
|
| 563 | - && str_contains($titre, '<multi>') |
|
| 564 | - && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | - ) { |
|
| 566 | - $lang = $GLOBALS['spip_lang']; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | - lang_select($lang); |
|
| 571 | - |
|
| 572 | - return; |
|
| 549 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | + if ( |
|
| 551 | + isset($GLOBALS['forcer_lang']) |
|
| 552 | + && $GLOBALS['forcer_lang'] |
|
| 553 | + && $lang_select !== 'oui' |
|
| 554 | + ) { |
|
| 555 | + $lang = $GLOBALS['spip_lang']; |
|
| 556 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | + elseif (!strlen($lang)) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 3. l'objet est multilingue ! |
|
| 560 | + elseif ( |
|
| 561 | + $lang_select !== 'oui' |
|
| 562 | + && strlen($titre) > 10 |
|
| 563 | + && str_contains($titre, '<multi>') |
|
| 564 | + && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | + ) { |
|
| 566 | + $lang = $GLOBALS['spip_lang']; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | + lang_select($lang); |
|
| 571 | + |
|
| 572 | + return; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
| 576 | 576 | // Si un tableau &doublons[articles] est passe en parametre, |
| 577 | 577 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 578 | 578 | function nettoyer_env_doublons($envd) { |
| 579 | - foreach ($envd as $table => $liste) { |
|
| 580 | - $n = ''; |
|
| 581 | - foreach (explode(',', $liste) as $val) { |
|
| 582 | - if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | - $n .= ',' . $val; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if (strlen($n)) { |
|
| 587 | - $envd[$table] = $n; |
|
| 588 | - } else { |
|
| 589 | - unset($envd[$table]); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return $envd; |
|
| 579 | + foreach ($envd as $table => $liste) { |
|
| 580 | + $n = ''; |
|
| 581 | + foreach (explode(',', $liste) as $val) { |
|
| 582 | + if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | + $n .= ',' . $val; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if (strlen($n)) { |
|
| 587 | + $envd[$table] = $n; |
|
| 588 | + } else { |
|
| 589 | + unset($envd[$table]); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return $envd; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -609,21 +609,21 @@ discard block |
||
| 609 | 609 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 610 | 610 | **/ |
| 611 | 611 | function match_self($w) { |
| 612 | - if (is_string($w)) { |
|
| 613 | - return false; |
|
| 614 | - } |
|
| 615 | - if (is_array($w)) { |
|
| 616 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | - return $w; |
|
| 618 | - } |
|
| 619 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | - if ($m = match_self($sw)) { |
|
| 621 | - return $m; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - return false; |
|
| 612 | + if (is_string($w)) { |
|
| 613 | + return false; |
|
| 614 | + } |
|
| 615 | + if (is_array($w)) { |
|
| 616 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | + return $w; |
|
| 618 | + } |
|
| 619 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | + if ($m = match_self($sw)) { |
|
| 621 | + return $m; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + return false; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -639,16 +639,16 @@ discard block |
||
| 639 | 639 | * est remplacée par son code. |
| 640 | 640 | **/ |
| 641 | 641 | function remplace_sous_requete($w, $sousrequete) { |
| 642 | - if (is_array($w)) { |
|
| 643 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | - return $sousrequete; |
|
| 645 | - } |
|
| 646 | - foreach ($w as $k => $sw) { |
|
| 647 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $w; |
|
| 642 | + if (is_array($w)) { |
|
| 643 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | + return $sousrequete; |
|
| 645 | + } |
|
| 646 | + foreach ($w as $k => $sw) { |
|
| 647 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $w; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -662,17 +662,17 @@ discard block |
||
| 662 | 662 | * - Conditions avec des sous requêtes |
| 663 | 663 | **/ |
| 664 | 664 | function trouver_sous_requetes($where) { |
| 665 | - $where_simples = []; |
|
| 666 | - $where_sous = []; |
|
| 667 | - foreach ($where as $k => $w) { |
|
| 668 | - if (match_self($w)) { |
|
| 669 | - $where_sous[$k] = $w; |
|
| 670 | - } else { |
|
| 671 | - $where_simples[$k] = $w; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return [$where_simples, $where_sous]; |
|
| 665 | + $where_simples = []; |
|
| 666 | + $where_sous = []; |
|
| 667 | + foreach ($where as $k => $w) { |
|
| 668 | + if (match_self($w)) { |
|
| 669 | + $where_sous[$k] = $w; |
|
| 670 | + } else { |
|
| 671 | + $where_simples[$k] = $w; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return [$where_simples, $where_sous]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -698,293 +698,293 @@ discard block |
||
| 698 | 698 | * @return resource |
| 699 | 699 | */ |
| 700 | 700 | function calculer_select( |
| 701 | - $select = [], |
|
| 702 | - $from = [], |
|
| 703 | - $from_type = [], |
|
| 704 | - $where = [], |
|
| 705 | - $join = [], |
|
| 706 | - $groupby = [], |
|
| 707 | - $orderby = [], |
|
| 708 | - $limit = '', |
|
| 709 | - $having = [], |
|
| 710 | - $table = '', |
|
| 711 | - $id = '', |
|
| 712 | - $serveur = '', |
|
| 713 | - $requeter = true |
|
| 701 | + $select = [], |
|
| 702 | + $from = [], |
|
| 703 | + $from_type = [], |
|
| 704 | + $where = [], |
|
| 705 | + $join = [], |
|
| 706 | + $groupby = [], |
|
| 707 | + $orderby = [], |
|
| 708 | + $limit = '', |
|
| 709 | + $having = [], |
|
| 710 | + $table = '', |
|
| 711 | + $id = '', |
|
| 712 | + $serveur = '', |
|
| 713 | + $requeter = true |
|
| 714 | 714 | ) { |
| 715 | 715 | |
| 716 | - // retirer les criteres vides: |
|
| 717 | - // {X ?} avec X absent de l'URL |
|
| 718 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | - $menage = false; |
|
| 721 | - foreach ($where as $k => $v) { |
|
| 722 | - if (is_array($v) && count($v)) { |
|
| 723 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | - $op = false; |
|
| 725 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | - $op = false; |
|
| 727 | - } else { |
|
| 728 | - $op = $v[0] ?: $v; |
|
| 729 | - } |
|
| 730 | - } else { |
|
| 731 | - $op = $v; |
|
| 732 | - } |
|
| 733 | - if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | - unset($where[$k]); |
|
| 735 | - $menage = true; |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | - $groupby = array_diff($groupby, ['']); |
|
| 741 | - |
|
| 742 | - // remplacer les sous requetes recursives au calcul |
|
| 743 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | - foreach ($where_sous as $k => $w) { |
|
| 745 | - $menage = true; |
|
| 746 | - // on recupere la sous requete |
|
| 747 | - $sous = match_self($w); |
|
| 748 | - if ($sous[0] == 'SELF') { |
|
| 749 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | - array_push($where_simples, $sous[2]); |
|
| 751 | - $wheresub = [ |
|
| 752 | - $sous[2], |
|
| 753 | - '0=0' |
|
| 754 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | - $jsub = $join; |
|
| 756 | - // trouver les jointures utiles a |
|
| 757 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | - // ie L1.objet='article' |
|
| 759 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | - $i = 0; |
|
| 761 | - do { |
|
| 762 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | - [$sous[1] . ' AS id'], |
|
| 764 | - $from, |
|
| 765 | - $from_type, |
|
| 766 | - $wheresub, |
|
| 767 | - $jsub, |
|
| 768 | - [], |
|
| 769 | - [], |
|
| 770 | - '', |
|
| 771 | - $having, |
|
| 772 | - $table, |
|
| 773 | - $id, |
|
| 774 | - $serveur, |
|
| 775 | - false |
|
| 776 | - ) . ')'); |
|
| 777 | - if (!$i) { |
|
| 778 | - $i = 1; |
|
| 779 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | - foreach ($join as $cle => $wj) { |
|
| 781 | - if ( |
|
| 782 | - (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | - ) { |
|
| 784 | - $i = 0; |
|
| 785 | - $wheresub[] = $wj[3]; |
|
| 786 | - unset($jsub[$cle][3]); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } while ($i++ < 1); |
|
| 791 | - } |
|
| 792 | - if ($sous[0] == 'SUBSELECT') { |
|
| 793 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | - $sous[1], # select |
|
| 797 | - $sous[2], #from |
|
| 798 | - [], #from_type |
|
| 799 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | - [], #join |
|
| 802 | - $sous[4] ?: [], #groupby |
|
| 803 | - $sous[5] ?: [], #orderby |
|
| 804 | - $sous[6], #limit |
|
| 805 | - $sous[7] ?: [], #having |
|
| 806 | - $table, |
|
| 807 | - $id, |
|
| 808 | - $serveur, |
|
| 809 | - false |
|
| 810 | - ) . ')'); |
|
| 811 | - } |
|
| 812 | - array_pop($where_simples); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - foreach ($having as $k => $v) { |
|
| 816 | - if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | - unset($having[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - // Installer les jointures. |
|
| 822 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | - |
|
| 826 | - $afrom = []; |
|
| 827 | - $equiv = []; |
|
| 828 | - $k = count($join); |
|
| 829 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | - $cle = $cledef; |
|
| 831 | - // le format de join est : |
|
| 832 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | - if (count($join[$cle]) == 2) { |
|
| 835 | - $join[$cle][] = $join[$cle][1]; |
|
| 836 | - } |
|
| 837 | - if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | - $join[$cle][] = ''; |
|
| 839 | - } |
|
| 840 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | - // pour compat avec ancienne convention |
|
| 843 | - if (is_numeric($cle)) { |
|
| 844 | - $cle = "L$k"; |
|
| 845 | - } |
|
| 846 | - $cle_where_lie = "JOIN-$cle"; |
|
| 847 | - if ( |
|
| 848 | - !$menage |
|
| 849 | - || isset($afrom[$cle]) |
|
| 850 | - || calculer_jointnul($cle, $select) |
|
| 851 | - || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | - || calculer_jointnul($cle, $having) |
|
| 853 | - || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | - ) { |
|
| 855 | - // corriger les references non explicites dans select |
|
| 856 | - // ou groupby |
|
| 857 | - foreach ($select as $i => $s) { |
|
| 858 | - if ($s == $c) { |
|
| 859 | - $select[$i] = "$cle.$c AS $c"; |
|
| 860 | - break; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - foreach ($groupby as $i => $g) { |
|
| 864 | - if ($g == $c) { |
|
| 865 | - $groupby[$i] = "$cle.$c"; |
|
| 866 | - break; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | - // sans recours a preg_match |
|
| 871 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | - $afrom[$t][$cle] = [ |
|
| 873 | - "\n" . |
|
| 874 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | - $from[$cle], |
|
| 876 | - "AS $cle", |
|
| 877 | - 'ON (', |
|
| 878 | - "$cle.$c", |
|
| 879 | - '=', |
|
| 880 | - "$t.$carr", |
|
| 881 | - ($and ? 'AND ' . $and : '') . |
|
| 882 | - ')' |
|
| 883 | - ]; |
|
| 884 | - if (isset($afrom[$cle])) { |
|
| 885 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | - unset($afrom[$cle]); |
|
| 887 | - } |
|
| 888 | - $equiv[] = $carr; |
|
| 889 | - } else { |
|
| 890 | - unset($join[$cledef]); |
|
| 891 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | - unset($where_simples[$cle_where_lie]); |
|
| 893 | - unset($where[$cle_where_lie]); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - unset($from[$cle]); |
|
| 897 | - $k--; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - if (count($afrom)) { |
|
| 901 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | - // ou dans |
|
| 906 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | - // qui comporte plusieurs jointures |
|
| 908 | - // ou dans |
|
| 909 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | - |
|
| 916 | - $t = key($from); |
|
| 917 | - $c = current($from); |
|
| 918 | - reset($from); |
|
| 919 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | - if ( |
|
| 921 | - !( |
|
| 922 | - strpos($t, ' ') |
|
| 923 | - // jointure des le depart cf boucle_doc |
|
| 924 | - || calculer_jointnul($t, $select, $e) |
|
| 925 | - || calculer_jointnul($t, $join, $e) |
|
| 926 | - || calculer_jointnul($t, $where, $e) |
|
| 927 | - || calculer_jointnul($t, $orderby, $e) |
|
| 928 | - || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | - ) |
|
| 930 | - && count($afrom[$t]) |
|
| 931 | - ) { |
|
| 932 | - $nfrom = reset($afrom[$t]); |
|
| 933 | - $nt = array_key_first($afrom[$t]); |
|
| 934 | - unset($from[$t]); |
|
| 935 | - $from[$nt] = $nfrom[1]; |
|
| 936 | - unset($afrom[$t][$nt]); |
|
| 937 | - $afrom[$nt] = $afrom[$t]; |
|
| 938 | - unset($afrom[$t]); |
|
| 939 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | - $t = $nfrom[4]; |
|
| 941 | - $alias = ''; |
|
| 942 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | - $oldcle = explode('.', $nfrom[6]); |
|
| 944 | - $oldcle = end($oldcle); |
|
| 945 | - $newcle = explode('.', $nfrom[4]); |
|
| 946 | - $newcle = end($newcle); |
|
| 947 | - if ($newcle != $oldcle) { |
|
| 948 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | - // reprendre simplement ce AS |
|
| 950 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | - $alias = ''; |
|
| 953 | - } else { |
|
| 954 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | - } |
|
| 964 | - $from = reinjecte_joint($afrom, $from); |
|
| 965 | - } |
|
| 966 | - if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | - $GLOBALS['debug'] = []; |
|
| 969 | - if ($wasdebug) { |
|
| 970 | - $GLOBALS['debug']['debug'] = true; |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | - $r = sql_select( |
|
| 975 | - $select, |
|
| 976 | - $from, |
|
| 977 | - $where, |
|
| 978 | - $groupby, |
|
| 979 | - array_filter($orderby), |
|
| 980 | - $limit, |
|
| 981 | - $having, |
|
| 982 | - $serveur, |
|
| 983 | - $requeter |
|
| 984 | - ); |
|
| 985 | - unset($GLOBALS['debug']['aucasou']); |
|
| 986 | - |
|
| 987 | - return $r; |
|
| 716 | + // retirer les criteres vides: |
|
| 717 | + // {X ?} avec X absent de l'URL |
|
| 718 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | + $menage = false; |
|
| 721 | + foreach ($where as $k => $v) { |
|
| 722 | + if (is_array($v) && count($v)) { |
|
| 723 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | + $op = false; |
|
| 725 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | + $op = false; |
|
| 727 | + } else { |
|
| 728 | + $op = $v[0] ?: $v; |
|
| 729 | + } |
|
| 730 | + } else { |
|
| 731 | + $op = $v; |
|
| 732 | + } |
|
| 733 | + if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | + unset($where[$k]); |
|
| 735 | + $menage = true; |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | + $groupby = array_diff($groupby, ['']); |
|
| 741 | + |
|
| 742 | + // remplacer les sous requetes recursives au calcul |
|
| 743 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | + foreach ($where_sous as $k => $w) { |
|
| 745 | + $menage = true; |
|
| 746 | + // on recupere la sous requete |
|
| 747 | + $sous = match_self($w); |
|
| 748 | + if ($sous[0] == 'SELF') { |
|
| 749 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | + array_push($where_simples, $sous[2]); |
|
| 751 | + $wheresub = [ |
|
| 752 | + $sous[2], |
|
| 753 | + '0=0' |
|
| 754 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | + $jsub = $join; |
|
| 756 | + // trouver les jointures utiles a |
|
| 757 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | + // ie L1.objet='article' |
|
| 759 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | + $i = 0; |
|
| 761 | + do { |
|
| 762 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | + [$sous[1] . ' AS id'], |
|
| 764 | + $from, |
|
| 765 | + $from_type, |
|
| 766 | + $wheresub, |
|
| 767 | + $jsub, |
|
| 768 | + [], |
|
| 769 | + [], |
|
| 770 | + '', |
|
| 771 | + $having, |
|
| 772 | + $table, |
|
| 773 | + $id, |
|
| 774 | + $serveur, |
|
| 775 | + false |
|
| 776 | + ) . ')'); |
|
| 777 | + if (!$i) { |
|
| 778 | + $i = 1; |
|
| 779 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | + foreach ($join as $cle => $wj) { |
|
| 781 | + if ( |
|
| 782 | + (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | + ) { |
|
| 784 | + $i = 0; |
|
| 785 | + $wheresub[] = $wj[3]; |
|
| 786 | + unset($jsub[$cle][3]); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } while ($i++ < 1); |
|
| 791 | + } |
|
| 792 | + if ($sous[0] == 'SUBSELECT') { |
|
| 793 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | + $sous[1], # select |
|
| 797 | + $sous[2], #from |
|
| 798 | + [], #from_type |
|
| 799 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | + [], #join |
|
| 802 | + $sous[4] ?: [], #groupby |
|
| 803 | + $sous[5] ?: [], #orderby |
|
| 804 | + $sous[6], #limit |
|
| 805 | + $sous[7] ?: [], #having |
|
| 806 | + $table, |
|
| 807 | + $id, |
|
| 808 | + $serveur, |
|
| 809 | + false |
|
| 810 | + ) . ')'); |
|
| 811 | + } |
|
| 812 | + array_pop($where_simples); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + foreach ($having as $k => $v) { |
|
| 816 | + if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | + unset($having[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + // Installer les jointures. |
|
| 822 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | + |
|
| 826 | + $afrom = []; |
|
| 827 | + $equiv = []; |
|
| 828 | + $k = count($join); |
|
| 829 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | + $cle = $cledef; |
|
| 831 | + // le format de join est : |
|
| 832 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | + if (count($join[$cle]) == 2) { |
|
| 835 | + $join[$cle][] = $join[$cle][1]; |
|
| 836 | + } |
|
| 837 | + if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | + $join[$cle][] = ''; |
|
| 839 | + } |
|
| 840 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | + // pour compat avec ancienne convention |
|
| 843 | + if (is_numeric($cle)) { |
|
| 844 | + $cle = "L$k"; |
|
| 845 | + } |
|
| 846 | + $cle_where_lie = "JOIN-$cle"; |
|
| 847 | + if ( |
|
| 848 | + !$menage |
|
| 849 | + || isset($afrom[$cle]) |
|
| 850 | + || calculer_jointnul($cle, $select) |
|
| 851 | + || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | + || calculer_jointnul($cle, $having) |
|
| 853 | + || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | + ) { |
|
| 855 | + // corriger les references non explicites dans select |
|
| 856 | + // ou groupby |
|
| 857 | + foreach ($select as $i => $s) { |
|
| 858 | + if ($s == $c) { |
|
| 859 | + $select[$i] = "$cle.$c AS $c"; |
|
| 860 | + break; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + foreach ($groupby as $i => $g) { |
|
| 864 | + if ($g == $c) { |
|
| 865 | + $groupby[$i] = "$cle.$c"; |
|
| 866 | + break; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | + // sans recours a preg_match |
|
| 871 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | + $afrom[$t][$cle] = [ |
|
| 873 | + "\n" . |
|
| 874 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | + $from[$cle], |
|
| 876 | + "AS $cle", |
|
| 877 | + 'ON (', |
|
| 878 | + "$cle.$c", |
|
| 879 | + '=', |
|
| 880 | + "$t.$carr", |
|
| 881 | + ($and ? 'AND ' . $and : '') . |
|
| 882 | + ')' |
|
| 883 | + ]; |
|
| 884 | + if (isset($afrom[$cle])) { |
|
| 885 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | + unset($afrom[$cle]); |
|
| 887 | + } |
|
| 888 | + $equiv[] = $carr; |
|
| 889 | + } else { |
|
| 890 | + unset($join[$cledef]); |
|
| 891 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | + unset($where_simples[$cle_where_lie]); |
|
| 893 | + unset($where[$cle_where_lie]); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + unset($from[$cle]); |
|
| 897 | + $k--; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + if (count($afrom)) { |
|
| 901 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | + // ou dans |
|
| 906 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | + // qui comporte plusieurs jointures |
|
| 908 | + // ou dans |
|
| 909 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | + |
|
| 916 | + $t = key($from); |
|
| 917 | + $c = current($from); |
|
| 918 | + reset($from); |
|
| 919 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | + if ( |
|
| 921 | + !( |
|
| 922 | + strpos($t, ' ') |
|
| 923 | + // jointure des le depart cf boucle_doc |
|
| 924 | + || calculer_jointnul($t, $select, $e) |
|
| 925 | + || calculer_jointnul($t, $join, $e) |
|
| 926 | + || calculer_jointnul($t, $where, $e) |
|
| 927 | + || calculer_jointnul($t, $orderby, $e) |
|
| 928 | + || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | + ) |
|
| 930 | + && count($afrom[$t]) |
|
| 931 | + ) { |
|
| 932 | + $nfrom = reset($afrom[$t]); |
|
| 933 | + $nt = array_key_first($afrom[$t]); |
|
| 934 | + unset($from[$t]); |
|
| 935 | + $from[$nt] = $nfrom[1]; |
|
| 936 | + unset($afrom[$t][$nt]); |
|
| 937 | + $afrom[$nt] = $afrom[$t]; |
|
| 938 | + unset($afrom[$t]); |
|
| 939 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | + $t = $nfrom[4]; |
|
| 941 | + $alias = ''; |
|
| 942 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | + $oldcle = explode('.', $nfrom[6]); |
|
| 944 | + $oldcle = end($oldcle); |
|
| 945 | + $newcle = explode('.', $nfrom[4]); |
|
| 946 | + $newcle = end($newcle); |
|
| 947 | + if ($newcle != $oldcle) { |
|
| 948 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | + // reprendre simplement ce AS |
|
| 950 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | + $alias = ''; |
|
| 953 | + } else { |
|
| 954 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | + } |
|
| 964 | + $from = reinjecte_joint($afrom, $from); |
|
| 965 | + } |
|
| 966 | + if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | + $GLOBALS['debug'] = []; |
|
| 969 | + if ($wasdebug) { |
|
| 970 | + $GLOBALS['debug']['debug'] = true; |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | + $r = sql_select( |
|
| 975 | + $select, |
|
| 976 | + $from, |
|
| 977 | + $where, |
|
| 978 | + $groupby, |
|
| 979 | + array_filter($orderby), |
|
| 980 | + $limit, |
|
| 981 | + $having, |
|
| 982 | + $serveur, |
|
| 983 | + $requeter |
|
| 984 | + ); |
|
| 985 | + unset($GLOBALS['debug']['aucasou']); |
|
| 986 | + |
|
| 987 | + return $r; |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -995,79 +995,79 @@ discard block |
||
| 995 | 995 | * @return string |
| 996 | 996 | */ |
| 997 | 997 | function calculer_where_to_string($v, $join = 'AND') { |
| 998 | - if (empty($v)) { |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - if (!is_array($v)) { |
|
| 1003 | - return $v; |
|
| 1004 | - } else { |
|
| 1005 | - $exp = ''; |
|
| 1006 | - if (strtoupper($join) === 'AND') { |
|
| 1007 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | - } else { |
|
| 1009 | - return $exp . join($join, $v); |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 998 | + if (empty($v)) { |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + if (!is_array($v)) { |
|
| 1003 | + return $v; |
|
| 1004 | + } else { |
|
| 1005 | + $exp = ''; |
|
| 1006 | + if (strtoupper($join) === 'AND') { |
|
| 1007 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | + } else { |
|
| 1009 | + return $exp . join($join, $v); |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
| 1015 | 1015 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1016 | 1016 | |
| 1017 | 1017 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1018 | - if (!is_array($exp)) { |
|
| 1019 | - if ($equiv) { |
|
| 1020 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | - } else { |
|
| 1025 | - foreach ($exp as $v) { |
|
| 1026 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | - return true; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - return false; |
|
| 1032 | - } |
|
| 1018 | + if (!is_array($exp)) { |
|
| 1019 | + if ($equiv) { |
|
| 1020 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | + } else { |
|
| 1025 | + foreach ($exp as $v) { |
|
| 1026 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | + return true; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + return false; |
|
| 1032 | + } |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | function reinjecte_joint($afrom, $from) { |
| 1036 | - $from_synth = []; |
|
| 1037 | - foreach ($from as $k => $v) { |
|
| 1038 | - $from_synth[$k] = $from[$k]; |
|
| 1039 | - if (isset($afrom[$k])) { |
|
| 1040 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | - } |
|
| 1043 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | - unset($afrom[$k]); |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - return $from_synth; |
|
| 1036 | + $from_synth = []; |
|
| 1037 | + foreach ($from as $k => $v) { |
|
| 1038 | + $from_synth[$k] = $from[$k]; |
|
| 1039 | + if (isset($afrom[$k])) { |
|
| 1040 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | + } |
|
| 1043 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | + unset($afrom[$k]); |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + return $from_synth; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1052 | - if (!is_array($exp)) { |
|
| 1053 | - return preg_replace($equiv, $cle, $exp); |
|
| 1054 | - } else { |
|
| 1055 | - foreach ($exp as $k => $v) { |
|
| 1056 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - return $exp; |
|
| 1060 | - } |
|
| 1052 | + if (!is_array($exp)) { |
|
| 1053 | + return preg_replace($equiv, $cle, $exp); |
|
| 1054 | + } else { |
|
| 1055 | + foreach ($exp as $k => $v) { |
|
| 1056 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + return $exp; |
|
| 1060 | + } |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | 1063 | // calcul du nom du squelette |
| 1064 | 1064 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1065 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | - if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - return $mime_type |
|
| 1071 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1065 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | + if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + return $mime_type |
|
| 1071 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | 1073 | } |
@@ -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') && _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') || !_VAR_NOCACHE) { |
| 159 | 159 | ecrire_fichier($phpfile, $code); |
| 160 | 160 | } |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 216 | 216 | |
| 217 | 217 | if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 218 | + $headers[$j] .= '|'.$r[3]; |
|
| 219 | 219 | } else { |
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 220 | + $headers[$j] = str_replace(['\\\\', "\\'", '\\"'], ['\\', "'", '"'], $r[3]); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | // S'agit-il d'un resultat constant ou contenant du code php |
| 225 | 225 | $process_ins = ( |
| 226 | - !str_contains($corps, '<' . '?') |
|
| 227 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 226 | + !str_contains($corps, '<'.'?') |
|
| 227 | + || str_contains($corps, '<'.'?xml') && !str_contains(str_replace('<'.'?xml', '', $corps), '<'.'?') |
|
| 228 | 228 | ) |
| 229 | 229 | ? 'html' |
| 230 | 230 | : 'php'; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | if ($process_ins == 'html') { |
| 255 | 255 | $skel['process_ins'] = ( |
| 256 | - !str_contains($corps, '<' . '?') |
|
| 257 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 256 | + !str_contains($corps, '<'.'?') |
|
| 257 | + || str_contains($corps, '<'.'?xml') && !str_contains(str_replace('<'.'?xml', '', $corps), '<'.'?') |
|
| 258 | 258 | ) |
| 259 | 259 | ? 'html' |
| 260 | 260 | : 'php'; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | // |
| 273 | 273 | |
| 274 | 274 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 275 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 275 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 276 | 276 | include_once("%s"); |
| 277 | 277 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 278 | 278 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | // pas de lien symbolique sous Windows |
| 304 | 304 | && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
| 305 | 305 | ) { |
| 306 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 306 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $lang = $context_compil[4]; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | $args = array_map('argumenter_squelette', $args); |
| 315 | 315 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 316 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 316 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 317 | 317 | } |
| 318 | 318 | $args = join(', ', $args); |
| 319 | 319 | |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | if (is_object($v)) { |
| 348 | 348 | return var_export($v, true); |
| 349 | 349 | } elseif (!is_array($v)) { |
| 350 | - return "'" . texte_script((string) $v) . "'"; |
|
| 350 | + return "'".texte_script((string) $v)."'"; |
|
| 351 | 351 | } else { |
| 352 | 352 | $out = []; |
| 353 | 353 | foreach ($v as $k => $val) { |
| 354 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 354 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return 'array(' . join(', ', $out) . ')'; |
|
| 357 | + return 'array('.join(', ', $out).')'; |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | else { |
| 381 | 381 | $str_args = base64_encode(serialize($args)); |
| 382 | - return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 382 | + return '<?'."php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // Y a-t-il une fonction de traitement des arguments ? |
| 460 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 460 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 461 | 461 | |
| 462 | 462 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | // verifier que la fonction dyn est la, |
| 469 | 469 | // sinon se replier sur la generique si elle existe |
| 470 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 470 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 471 | 471 | if ( |
| 472 | 472 | ($balise_generique = chercher_balise_generique($nom)) |
| 473 | 473 | && ($nom_balise_generique = $balise_generique['nom_generique']) |
| 474 | - && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | - && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 474 | + && ($file = include_spip('balise/'.strtolower($nom_balise_generique))) |
|
| 475 | + && function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 476 | 476 | ) { |
| 477 | 477 | // et lui injecter en premier arg le nom de la balise |
| 478 | 478 | array_unshift($r, $nom); |
| 479 | 479 | $nom_balise = $nom_balise_generique; |
| 480 | 480 | if (!_DIR_RESTREINT) { |
| 481 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 481 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | 484 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $n = ''; |
| 581 | 581 | foreach (explode(',', $liste) as $val) { |
| 582 | 582 | if (($a = intval($val)) && $val === strval($a)) { |
| 583 | - $n .= ',' . $val; |
|
| 583 | + $n .= ','.$val; |
|
| 584 | 584 | } |
| 585 | 585 | } |
| 586 | 586 | if (strlen($n)) { |
@@ -759,8 +759,8 @@ discard block |
||
| 759 | 759 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 760 | 760 | $i = 0; |
| 761 | 761 | do { |
| 762 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | - [$sous[1] . ' AS id'], |
|
| 762 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 763 | + [$sous[1].' AS id'], |
|
| 764 | 764 | $from, |
| 765 | 765 | $from_type, |
| 766 | 766 | $wheresub, |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | $id, |
| 774 | 774 | $serveur, |
| 775 | 775 | false |
| 776 | - ) . ')'); |
|
| 776 | + ).')'); |
|
| 777 | 777 | if (!$i) { |
| 778 | 778 | $i = 1; |
| 779 | 779 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | if ($sous[0] == 'SUBSELECT') { |
| 793 | 793 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 794 | 794 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 795 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 795 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 796 | 796 | $sous[1], # select |
| 797 | 797 | $sous[2], #from |
| 798 | 798 | [], #from_type |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | $id, |
| 808 | 808 | $serveur, |
| 809 | 809 | false |
| 810 | - ) . ')'); |
|
| 810 | + ).')'); |
|
| 811 | 811 | } |
| 812 | 812 | array_pop($where_simples); |
| 813 | 813 | } |
@@ -870,15 +870,15 @@ discard block |
||
| 870 | 870 | // sans recours a preg_match |
| 871 | 871 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 872 | 872 | $afrom[$t][$cle] = [ |
| 873 | - "\n" . |
|
| 874 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 873 | + "\n". |
|
| 874 | + ($from_type[$cle] ?? 'INNER').' JOIN', |
|
| 875 | 875 | $from[$cle], |
| 876 | 876 | "AS $cle", |
| 877 | 877 | 'ON (', |
| 878 | 878 | "$cle.$c", |
| 879 | 879 | '=', |
| 880 | 880 | "$t.$carr", |
| 881 | - ($and ? 'AND ' . $and : '') . |
|
| 881 | + ($and ? 'AND '.$and : ''). |
|
| 882 | 882 | ')' |
| 883 | 883 | ]; |
| 884 | 884 | if (isset($afrom[$cle])) { |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | $t = key($from); |
| 917 | 917 | $c = current($from); |
| 918 | 918 | reset($from); |
| 919 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 919 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 920 | 920 | if ( |
| 921 | 921 | !( |
| 922 | 922 | strpos($t, ' ') |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | unset($afrom[$t][$nt]); |
| 937 | 937 | $afrom[$nt] = $afrom[$t]; |
| 938 | 938 | unset($afrom[$t]); |
| 939 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 939 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 940 | 940 | $t = $nfrom[4]; |
| 941 | 941 | $alias = ''; |
| 942 | 942 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -947,14 +947,14 @@ discard block |
||
| 947 | 947 | if ($newcle != $oldcle) { |
| 948 | 948 | // si l'ancienne cle etait deja dans le select avec un AS |
| 949 | 949 | // reprendre simplement ce AS |
| 950 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 950 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 951 | 951 | if (preg_match($as, implode(',', $select), $m)) { |
| 952 | 952 | $alias = ''; |
| 953 | 953 | } else { |
| 954 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 954 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 957 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 958 | 958 | $join = remplacer_jointnul($t, $join, $e); |
| 959 | 959 | $where = remplacer_jointnul($t, $where, $e); |
| 960 | 960 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1004,9 +1004,9 @@ discard block |
||
| 1004 | 1004 | } else { |
| 1005 | 1005 | $exp = ''; |
| 1006 | 1006 | if (strtoupper($join) === 'AND') { |
| 1007 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1007 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | 1008 | } else { |
| 1009 | - return $exp . join($join, $v); |
|
| 1009 | + return $exp.join($join, $v); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | } |
| 1012 | 1012 | } |
@@ -1068,6 +1068,6 @@ discard block |
||
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | return $mime_type |
| 1071 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1071 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1072 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | 1073 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $select = true |
| 127 | 127 | ) { |
| 128 | 128 | if (!is_string($defaut)) { |
| 129 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 129 | + $defaut = '($Pile[0][\''.strtolower($nom_champ).'\'] ?? null)'; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $idb_origine = $idb; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | // renseigner la boucle source de ce champ pour les traitements |
| 161 | 161 | $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
| 162 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 162 | + $champ = '$Pile[$SP'.($i ? "-$i" : '').'][\''.$c.'\']'; |
|
| 163 | 163 | if (!$joker) { |
| 164 | 164 | return index_compose($conditionnel, $champ); |
| 165 | 165 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | function index_compose($conditionnel, $defaut) { |
| 201 | 201 | while ($c = array_pop($conditionnel)) { |
| 202 | 202 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 203 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 203 | + $defaut = "($c:(".($defaut ?: "''").'))'; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | return $defaut; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | if (!$r) { |
| 248 | 248 | $joker = false; // indiquer a l'appelant |
| 249 | 249 | # continuer pour chercher l'erreur suivante |
| 250 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 250 | + return ["'#".$r.':'.$nom_champ."'", '']; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | $desc = $boucles[$idb]->show; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
| 291 | 291 | [, $_table, $_nom_champ] = $r; |
| 292 | 292 | if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
| 293 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 293 | + $_alias = $cle.'_'.$_nom_champ; |
|
| 294 | 294 | return index_exception( |
| 295 | 295 | $boucles[$idb], |
| 296 | 296 | $desc, |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 372 | 372 | } |
| 373 | 373 | if ($t == null) { |
| 374 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 374 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | 376 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 377 | 377 | if (!$j) { |
| 378 | 378 | return ['', '']; |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $l = (preg_split('/\s*,\s*/', $k)); |
| 385 | 385 | $k = $desc['key']['PRIMARY KEY']; |
| 386 | 386 | if (!in_array($k, $l)) { |
| 387 | - spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 387 | + spip_log("jointure impossible $e ".implode(',', $l)); |
|
| 388 | 388 | |
| 389 | 389 | return ['', '']; |
| 390 | 390 | } |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | // demander a SQL de gerer le synonyme |
| 401 | 401 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 402 | 402 | if ($excep != $nom_champ) { |
| 403 | - $excep .= ' AS ' . $nom_champ; |
|
| 403 | + $excep .= ' AS '.$nom_champ; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | return ["$t.$excep", $nom_champ]; |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | implode(',', $collecte), |
| 649 | 649 | ($collecte ? $param : substr($param, 1)), # virer la virgule |
| 650 | 650 | memoriser_contexte_compil($p), |
| 651 | - ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 651 | + ($supp ? ', '.implode(',', $supp) : ('')) |
|
| 652 | 652 | ); |
| 653 | 653 | |
| 654 | 654 | $p->interdire_scripts = false; |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | * @return array |
| 683 | 683 | * Liste des codes PHP d'éxecution des balises collectées |
| 684 | 684 | **/ |
| 685 | -function collecter_balise_dynamique(array $l, Champ &$p, string $nom): array { |
|
| 685 | +function collecter_balise_dynamique(array $l, Champ & $p, string $nom): array { |
|
| 686 | 686 | $args = []; |
| 687 | 687 | foreach ($l as $c) { |
| 688 | 688 | if ($c === null) { |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | $nom = $p->id_boucle; |
| 748 | 748 | |
| 749 | 749 | if ($nom && trouver_nom_serveur_distant($p)) { |
| 750 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 750 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 751 | 751 | |
| 752 | 752 | return false; |
| 753 | 753 | } |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | && $p->descr['documents'] |
| 824 | 824 | && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
| 825 | 825 | ) { |
| 826 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 826 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | // La protection des champs par |safehtml est assuree par les extensions |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | function compose_filtres_args($p, $args, $sep) { |
| 928 | 928 | $arglist = ''; |
| 929 | 929 | foreach ($args as $arg) { |
| 930 | - $arglist .= $sep . |
|
| 930 | + $arglist .= $sep. |
|
| 931 | 931 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 932 | 932 | } |
| 933 | 933 | |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | while ($b != '') { |
| 978 | 978 | foreach ($p->boucles[$b]->criteres as $critere) { |
| 979 | 979 | if ($critere->op == $motif) { |
| 980 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | + $p->code = '$Pile[$SP'.(($n == 0) ? '' : "-$n"). |
|
| 981 | 981 | "]['$champ']"; |
| 982 | 982 | $b = ''; |
| 983 | 983 | break 2; |
@@ -1005,6 +1005,6 @@ discard block |
||
| 1005 | 1005 | */ |
| 1006 | 1006 | function zbug_presenter_champ($p, $champ = '') { |
| 1007 | 1007 | $balise = $champ ?: $p->nom_champ; |
| 1008 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | + $explicite = $p->nom_boucle ? $p->nom_boucle.':' : ''; |
|
| 1009 | 1009 | return "#{$explicite}{$balise}"; |
| 1010 | 1010 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\Compilateur\References |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | * - '' si une référence explicite incorrecte est envoyée |
| 44 | 44 | */ |
| 45 | 45 | function index_boucle($p) { |
| 46 | - if (strlen($p->nom_boucle)) { |
|
| 47 | - // retourne l’index explicite demandé s’il existe |
|
| 48 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 49 | - return $p->nom_boucle; |
|
| 50 | - } |
|
| 51 | - return ''; |
|
| 52 | - } |
|
| 53 | - return $p->id_boucle; |
|
| 46 | + if (strlen($p->nom_boucle)) { |
|
| 47 | + // retourne l’index explicite demandé s’il existe |
|
| 48 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 49 | + return $p->nom_boucle; |
|
| 50 | + } |
|
| 51 | + return ''; |
|
| 52 | + } |
|
| 53 | + return $p->id_boucle; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | * - '' si une référence explicite incorrecte est envoyée |
| 74 | 74 | */ |
| 75 | 75 | function index_boucle_mere($p) { |
| 76 | - if (strlen($p->nom_boucle)) { |
|
| 77 | - // retourne l’index explicite demandé s’il existe |
|
| 78 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 79 | - return $p->nom_boucle; |
|
| 80 | - } |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 83 | - if (!empty($p->descr['id_mere'])) { |
|
| 84 | - return $p->descr['id_mere']; |
|
| 85 | - } |
|
| 86 | - return ''; |
|
| 76 | + if (strlen($p->nom_boucle)) { |
|
| 77 | + // retourne l’index explicite demandé s’il existe |
|
| 78 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 79 | + return $p->nom_boucle; |
|
| 80 | + } |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | + if (!empty($p->descr['id_mere'])) { |
|
| 84 | + return $p->descr['id_mere']; |
|
| 85 | + } |
|
| 86 | + return ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -117,74 +117,74 @@ discard block |
||
| 117 | 117 | * Code PHP pour obtenir le champ SQL |
| 118 | 118 | */ |
| 119 | 119 | function index_pile( |
| 120 | - $idb, |
|
| 121 | - $nom_champ, |
|
| 122 | - &$boucles, |
|
| 123 | - $explicite = '', |
|
| 124 | - $defaut = null, |
|
| 125 | - $remonte_pile = true, |
|
| 126 | - $select = true |
|
| 120 | + $idb, |
|
| 121 | + $nom_champ, |
|
| 122 | + &$boucles, |
|
| 123 | + $explicite = '', |
|
| 124 | + $defaut = null, |
|
| 125 | + $remonte_pile = true, |
|
| 126 | + $select = true |
|
| 127 | 127 | ) { |
| 128 | - if (!is_string($defaut)) { |
|
| 129 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $idb_origine = $idb; |
|
| 133 | - $nom_champ_origine = $nom_champ; |
|
| 134 | - |
|
| 135 | - $i = 0; |
|
| 136 | - if (strlen($explicite)) { |
|
| 137 | - // Recherche d'un champ dans un etage superieur |
|
| 138 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 139 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 140 | - $i++; |
|
| 141 | - $idb = $boucles[$idb]->id_parent; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 146 | - $nom_champ = strtolower($nom_champ); |
|
| 147 | - $conditionnel = []; |
|
| 148 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 149 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 150 | - while (isset($boucles[$idb])) { |
|
| 151 | - $joker = true; |
|
| 152 | - // modifie $joker si tous les champs sont autorisés. |
|
| 153 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 154 | - // $c = le nom du champ demandé |
|
| 155 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 156 | - if ($t) { |
|
| 157 | - if ($select && !in_array($t, $boucles[$idb]->select)) { |
|
| 158 | - $boucles[$idb]->select[] = $t; |
|
| 159 | - } |
|
| 160 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 161 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 162 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 163 | - if (!$joker) { |
|
| 164 | - return index_compose($conditionnel, $champ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 168 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 169 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 170 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 171 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($remonte_pile) { |
|
| 175 | - # spip_log("On remonte vers $i"); |
|
| 176 | - // Sinon on remonte d'un cran |
|
| 177 | - $idb = $boucles[$idb]->id_parent; |
|
| 178 | - $i++; |
|
| 179 | - } else { |
|
| 180 | - $idb = null; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - # spip_log("Pas vu $nom_champ"); |
|
| 185 | - // esperons qu'il y sera |
|
| 186 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 187 | - return index_compose($conditionnel, $defaut); |
|
| 128 | + if (!is_string($defaut)) { |
|
| 129 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $idb_origine = $idb; |
|
| 133 | + $nom_champ_origine = $nom_champ; |
|
| 134 | + |
|
| 135 | + $i = 0; |
|
| 136 | + if (strlen($explicite)) { |
|
| 137 | + // Recherche d'un champ dans un etage superieur |
|
| 138 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 139 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 140 | + $i++; |
|
| 141 | + $idb = $boucles[$idb]->id_parent; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 146 | + $nom_champ = strtolower($nom_champ); |
|
| 147 | + $conditionnel = []; |
|
| 148 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 149 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 150 | + while (isset($boucles[$idb])) { |
|
| 151 | + $joker = true; |
|
| 152 | + // modifie $joker si tous les champs sont autorisés. |
|
| 153 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 154 | + // $c = le nom du champ demandé |
|
| 155 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 156 | + if ($t) { |
|
| 157 | + if ($select && !in_array($t, $boucles[$idb]->select)) { |
|
| 158 | + $boucles[$idb]->select[] = $t; |
|
| 159 | + } |
|
| 160 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 161 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 162 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 163 | + if (!$joker) { |
|
| 164 | + return index_compose($conditionnel, $champ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 168 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 169 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 170 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 171 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($remonte_pile) { |
|
| 175 | + # spip_log("On remonte vers $i"); |
|
| 176 | + // Sinon on remonte d'un cran |
|
| 177 | + $idb = $boucles[$idb]->id_parent; |
|
| 178 | + $i++; |
|
| 179 | + } else { |
|
| 180 | + $idb = null; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + # spip_log("Pas vu $nom_champ"); |
|
| 185 | + // esperons qu'il y sera |
|
| 186 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 187 | + return index_compose($conditionnel, $defaut); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -198,12 +198,12 @@ discard block |
||
| 198 | 198 | * @return string Code PHP complet de recherche d'un champ |
| 199 | 199 | */ |
| 200 | 200 | function index_compose($conditionnel, $defaut) { |
| 201 | - while ($c = array_pop($conditionnel)) { |
|
| 202 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 203 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 204 | - } |
|
| 201 | + while ($c = array_pop($conditionnel)) { |
|
| 202 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 203 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - return $defaut; |
|
| 206 | + return $defaut; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -239,98 +239,98 @@ discard block |
||
| 239 | 239 | **/ |
| 240 | 240 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 241 | 241 | |
| 242 | - $r = $boucles[$idb]->type_requete; |
|
| 243 | - // boucle recursive, c'est foutu... |
|
| 244 | - if ($r == TYPE_RECURSIF) { |
|
| 245 | - return []; |
|
| 246 | - } |
|
| 247 | - if (!$r) { |
|
| 248 | - $joker = false; // indiquer a l'appelant |
|
| 249 | - # continuer pour chercher l'erreur suivante |
|
| 250 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $desc = $boucles[$idb]->show; |
|
| 254 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 255 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 256 | - if ($excep) { |
|
| 257 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // il y a un alias connu pour ce champ |
|
| 261 | - if ($excep) { |
|
| 262 | - $joker = false; // indiquer a l'appelant |
|
| 263 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // le champ existe dans la table, on le prend. |
|
| 267 | - if (isset($desc['field'][$nom_champ])) { |
|
| 268 | - $t = $boucles[$idb]->id_table ?? ''; |
|
| 269 | - $joker = false; // indiquer a l'appelant |
|
| 270 | - // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 271 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Tous les champs sont-ils acceptés ? |
|
| 275 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 276 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 277 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 278 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 279 | - if ( |
|
| 280 | - /*$joker AND */ |
|
| 281 | - isset($desc['field']['*']) |
|
| 282 | - ) { |
|
| 283 | - $joker = true; // indiquer a l'appelant |
|
| 284 | - return [$nom_champ, $nom_champ]; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $joker = false; // indiquer a l'appelant |
|
| 288 | - |
|
| 289 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 290 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 291 | - [, $_table, $_nom_champ] = $r; |
|
| 292 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 293 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 294 | - return index_exception( |
|
| 295 | - $boucles[$idb], |
|
| 296 | - $desc, |
|
| 297 | - $_alias, |
|
| 298 | - [$_table, $_nom_champ] |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - return ['', '']; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // pas d'alias, pas de champ, pas de joker... |
|
| 305 | - // tenter via une jointure... |
|
| 306 | - |
|
| 307 | - // regarder si le champ est deja dans une jointure existante |
|
| 308 | - // sinon, si il y a des joitures explicites, la construire |
|
| 309 | - if ( |
|
| 310 | - !($t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) |
|
| 311 | - && $boucles[$idb]->jointures_explicites |
|
| 312 | - ) { |
|
| 313 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 314 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 315 | - // mais est-ce ce qu'on veut ? |
|
| 316 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 317 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 318 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if ($t) { |
|
| 323 | - // si on a trouvé une jointure possible, on fait comme |
|
| 324 | - // si c'était une exception pour le champ demandé |
|
| 325 | - return index_exception( |
|
| 326 | - $boucles[$idb], |
|
| 327 | - $desc, |
|
| 328 | - $nom_champ, |
|
| 329 | - [$t[1]['id_table'], reset($t[2])] |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - return ['', '']; |
|
| 242 | + $r = $boucles[$idb]->type_requete; |
|
| 243 | + // boucle recursive, c'est foutu... |
|
| 244 | + if ($r == TYPE_RECURSIF) { |
|
| 245 | + return []; |
|
| 246 | + } |
|
| 247 | + if (!$r) { |
|
| 248 | + $joker = false; // indiquer a l'appelant |
|
| 249 | + # continuer pour chercher l'erreur suivante |
|
| 250 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $desc = $boucles[$idb]->show; |
|
| 254 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 255 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 256 | + if ($excep) { |
|
| 257 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // il y a un alias connu pour ce champ |
|
| 261 | + if ($excep) { |
|
| 262 | + $joker = false; // indiquer a l'appelant |
|
| 263 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // le champ existe dans la table, on le prend. |
|
| 267 | + if (isset($desc['field'][$nom_champ])) { |
|
| 268 | + $t = $boucles[$idb]->id_table ?? ''; |
|
| 269 | + $joker = false; // indiquer a l'appelant |
|
| 270 | + // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 271 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Tous les champs sont-ils acceptés ? |
|
| 275 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 276 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 277 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 278 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 279 | + if ( |
|
| 280 | + /*$joker AND */ |
|
| 281 | + isset($desc['field']['*']) |
|
| 282 | + ) { |
|
| 283 | + $joker = true; // indiquer a l'appelant |
|
| 284 | + return [$nom_champ, $nom_champ]; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $joker = false; // indiquer a l'appelant |
|
| 288 | + |
|
| 289 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 290 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 291 | + [, $_table, $_nom_champ] = $r; |
|
| 292 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 293 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 294 | + return index_exception( |
|
| 295 | + $boucles[$idb], |
|
| 296 | + $desc, |
|
| 297 | + $_alias, |
|
| 298 | + [$_table, $_nom_champ] |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + return ['', '']; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // pas d'alias, pas de champ, pas de joker... |
|
| 305 | + // tenter via une jointure... |
|
| 306 | + |
|
| 307 | + // regarder si le champ est deja dans une jointure existante |
|
| 308 | + // sinon, si il y a des joitures explicites, la construire |
|
| 309 | + if ( |
|
| 310 | + !($t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) |
|
| 311 | + && $boucles[$idb]->jointures_explicites |
|
| 312 | + ) { |
|
| 313 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 314 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 315 | + // mais est-ce ce qu'on veut ? |
|
| 316 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 317 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 318 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if ($t) { |
|
| 323 | + // si on a trouvé une jointure possible, on fait comme |
|
| 324 | + // si c'était une exception pour le champ demandé |
|
| 325 | + return index_exception( |
|
| 326 | + $boucles[$idb], |
|
| 327 | + $desc, |
|
| 328 | + $nom_champ, |
|
| 329 | + [$t[1]['id_table'], reset($t[2])] |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + return ['', '']; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | |
@@ -358,52 +358,52 @@ discard block |
||
| 358 | 358 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 359 | 359 | **/ |
| 360 | 360 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_array($excep)) { |
|
| 367 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | - $t = null; |
|
| 369 | - if (count($excep) == 3) { |
|
| 370 | - $index_exception_derogatoire = array_pop($excep); |
|
| 371 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | - } |
|
| 373 | - if ($t == null) { |
|
| 374 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | - if (!$j) { |
|
| 378 | - return ['', '']; |
|
| 379 | - } |
|
| 380 | - $e = $j['table']; |
|
| 381 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | - $k = $j['key']['PRIMARY KEY']; |
|
| 383 | - if (strpos($k, ',')) { |
|
| 384 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | - if (!in_array($k, $l)) { |
|
| 387 | - spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 388 | - |
|
| 389 | - return ['', '']; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | - fabrique_jointures($boucle, [$k]); |
|
| 394 | - $t = array_search($e, $boucle->from); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - $t = $boucle->id_table; |
|
| 399 | - } |
|
| 400 | - // demander a SQL de gerer le synonyme |
|
| 401 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | - if ($excep != $nom_champ) { |
|
| 403 | - $excep .= ' AS ' . $nom_champ; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return ["$t.$excep", $nom_champ]; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_array($excep)) { |
|
| 367 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | + $t = null; |
|
| 369 | + if (count($excep) == 3) { |
|
| 370 | + $index_exception_derogatoire = array_pop($excep); |
|
| 371 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | + } |
|
| 373 | + if ($t == null) { |
|
| 374 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | + if (!$j) { |
|
| 378 | + return ['', '']; |
|
| 379 | + } |
|
| 380 | + $e = $j['table']; |
|
| 381 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | + $k = $j['key']['PRIMARY KEY']; |
|
| 383 | + if (strpos($k, ',')) { |
|
| 384 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | + if (!in_array($k, $l)) { |
|
| 387 | + spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 388 | + |
|
| 389 | + return ['', '']; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | + fabrique_jointures($boucle, [$k]); |
|
| 394 | + $t = array_search($e, $boucle->from); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + $t = $boucle->id_table; |
|
| 399 | + } |
|
| 400 | + // demander a SQL de gerer le synonyme |
|
| 401 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | + if ($excep != $nom_champ) { |
|
| 403 | + $excep .= ' AS ' . $nom_champ; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return ["$t.$excep", $nom_champ]; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * Code PHP pour retrouver le champ |
| 429 | 429 | */ |
| 430 | 430 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 431 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 431 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -448,9 +448,9 @@ discard block |
||
| 448 | 448 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 449 | 449 | **/ |
| 450 | 450 | function calculer_champ($p) { |
| 451 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 451 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 452 | 452 | |
| 453 | - return applique_filtres($p); |
|
| 453 | + return applique_filtres($p); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function calculer_balise(string $nom, Champ $p): Champ { |
| 489 | 489 | |
| 490 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | - $p->balise_calculee = true; |
|
| 493 | - $res = $f($p); |
|
| 494 | - if ($res !== null && is_object($res)) { |
|
| 495 | - return $res; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Certaines des balises comportant un _ sont generiques |
|
| 500 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | - $res = $balise_generique['fonction_generique']($p); |
|
| 502 | - if ($res !== null && is_object($res)) { |
|
| 503 | - return $res; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | - |
|
| 509 | - return $f($nom, $p); |
|
| 490 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | + $p->balise_calculee = true; |
|
| 493 | + $res = $f($p); |
|
| 494 | + if ($res !== null && is_object($res)) { |
|
| 495 | + return $res; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Certaines des balises comportant un _ sont generiques |
|
| 500 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | + $res = $balise_generique['fonction_generique']($p); |
|
| 502 | + if ($res !== null && is_object($res)) { |
|
| 503 | + return $res; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | + |
|
| 509 | + return $f($nom, $p); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | |
@@ -534,33 +534,33 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 536 | 536 | |
| 537 | - // ca pourrait etre un champ SQL homonyme, |
|
| 538 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | - |
|
| 540 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | - if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 543 | - $code = addslashes($p->fonctions[0][1]); |
|
| 544 | - $p->code .= " . '$code'"; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | - if (str_starts_with($nom, 'ID_')) { |
|
| 549 | - $p->interdire_scripts = false; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | - // SI le champ SQL n'est pas trouve |
|
| 554 | - // ET si la balise a une forme de couleur |
|
| 555 | - // ET s'il n'y a ni filtre ni etoile |
|
| 556 | - // ALORS retourner la couleur. |
|
| 557 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | - if (preg_match('/^[A-F]{1,6}$/i', $nom) && !$p->etoile && !$p->fonctions) { |
|
| 559 | - $p->code = "'#$nom'"; |
|
| 560 | - $p->interdire_scripts = false; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return $p; |
|
| 537 | + // ca pourrait etre un champ SQL homonyme, |
|
| 538 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | + |
|
| 540 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | + if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 543 | + $code = addslashes($p->fonctions[0][1]); |
|
| 544 | + $p->code .= " . '$code'"; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | + if (str_starts_with($nom, 'ID_')) { |
|
| 549 | + $p->interdire_scripts = false; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | + // SI le champ SQL n'est pas trouve |
|
| 554 | + // ET si la balise a une forme de couleur |
|
| 555 | + // ET s'il n'y a ni filtre ni etoile |
|
| 556 | + // ALORS retourner la couleur. |
|
| 557 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | + if (preg_match('/^[A-F]{1,6}$/i', $nom) && !$p->etoile && !$p->fonctions) { |
|
| 559 | + $p->code = "'#$nom'"; |
|
| 560 | + $p->interdire_scripts = false; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return $p; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -608,52 +608,52 @@ discard block |
||
| 608 | 608 | **/ |
| 609 | 609 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 610 | 610 | |
| 611 | - if (!balise_distante_interdite($p)) { |
|
| 612 | - $p->code = "''"; |
|
| 613 | - |
|
| 614 | - return $p; |
|
| 615 | - } |
|
| 616 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 617 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 618 | - if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 619 | - $p->fonctions = []; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - if ($p->param && ($c = $p->param[0])) { |
|
| 623 | - // liste d'arguments commence toujours par la chaine vide |
|
| 624 | - array_shift($c); |
|
| 625 | - // construire la liste d'arguments comme pour un filtre |
|
| 626 | - $param = compose_filtres_args($p, $c, ','); |
|
| 627 | - } else { |
|
| 628 | - $param = ''; |
|
| 629 | - } |
|
| 630 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 631 | - |
|
| 632 | - $dans_un_modele = false; |
|
| 633 | - if ( |
|
| 634 | - !empty($p->descr['sourcefile']) && ($f = $p->descr['sourcefile']) && basename(dirname($f)) === 'modeles' |
|
| 635 | - ) { |
|
| 636 | - $dans_un_modele = true; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // un modele est toujours inséré en texte dans son contenant |
|
| 640 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 641 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 642 | - // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 643 | - // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 644 | - // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 645 | - $p->code = sprintf( |
|
| 646 | - $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 647 | - $nom, |
|
| 648 | - implode(',', $collecte), |
|
| 649 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 650 | - memoriser_contexte_compil($p), |
|
| 651 | - ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 652 | - ); |
|
| 653 | - |
|
| 654 | - $p->interdire_scripts = false; |
|
| 655 | - |
|
| 656 | - return $p; |
|
| 611 | + if (!balise_distante_interdite($p)) { |
|
| 612 | + $p->code = "''"; |
|
| 613 | + |
|
| 614 | + return $p; |
|
| 615 | + } |
|
| 616 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 617 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 618 | + if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 619 | + $p->fonctions = []; |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + if ($p->param && ($c = $p->param[0])) { |
|
| 623 | + // liste d'arguments commence toujours par la chaine vide |
|
| 624 | + array_shift($c); |
|
| 625 | + // construire la liste d'arguments comme pour un filtre |
|
| 626 | + $param = compose_filtres_args($p, $c, ','); |
|
| 627 | + } else { |
|
| 628 | + $param = ''; |
|
| 629 | + } |
|
| 630 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 631 | + |
|
| 632 | + $dans_un_modele = false; |
|
| 633 | + if ( |
|
| 634 | + !empty($p->descr['sourcefile']) && ($f = $p->descr['sourcefile']) && basename(dirname($f)) === 'modeles' |
|
| 635 | + ) { |
|
| 636 | + $dans_un_modele = true; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // un modele est toujours inséré en texte dans son contenant |
|
| 640 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 641 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 642 | + // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 643 | + // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 644 | + // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 645 | + $p->code = sprintf( |
|
| 646 | + $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 647 | + $nom, |
|
| 648 | + implode(',', $collecte), |
|
| 649 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 650 | + memoriser_contexte_compil($p), |
|
| 651 | + ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 652 | + ); |
|
| 653 | + |
|
| 654 | + $p->interdire_scripts = false; |
|
| 655 | + |
|
| 656 | + return $p; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
@@ -683,17 +683,17 @@ discard block |
||
| 683 | 683 | * Liste des codes PHP d'éxecution des balises collectées |
| 684 | 684 | **/ |
| 685 | 685 | function collecter_balise_dynamique(array $l, Champ &$p, string $nom): array { |
| 686 | - $args = []; |
|
| 687 | - foreach ($l as $c) { |
|
| 688 | - if ($c === null) { |
|
| 689 | - $args[] = 'null'; |
|
| 690 | - } else { |
|
| 691 | - $x = calculer_balise($c, $p); |
|
| 692 | - $args[] = $x->code; |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $args; |
|
| 686 | + $args = []; |
|
| 687 | + foreach ($l as $c) { |
|
| 688 | + if ($c === null) { |
|
| 689 | + $args[] = 'null'; |
|
| 690 | + } else { |
|
| 691 | + $x = calculer_balise($c, $p); |
|
| 692 | + $args[] = $x->code; |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $args; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -708,19 +708,19 @@ discard block |
||
| 708 | 708 | * Nom de la connexion |
| 709 | 709 | **/ |
| 710 | 710 | function trouver_nom_serveur_distant($p) { |
| 711 | - $nom = $p->id_boucle; |
|
| 712 | - if ( |
|
| 713 | - $nom && isset($p->boucles[$nom]) |
|
| 714 | - ) { |
|
| 715 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 716 | - if ( |
|
| 717 | - strlen($s) && strlen($serveur = strtolower($s)) && !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 718 | - ) { |
|
| 719 | - return $serveur; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - return ''; |
|
| 711 | + $nom = $p->id_boucle; |
|
| 712 | + if ( |
|
| 713 | + $nom && isset($p->boucles[$nom]) |
|
| 714 | + ) { |
|
| 715 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 716 | + if ( |
|
| 717 | + strlen($s) && strlen($serveur = strtolower($s)) && !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 718 | + ) { |
|
| 719 | + return $serveur; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + return ''; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
@@ -744,15 +744,15 @@ discard block |
||
| 744 | 744 | * - false : La balise est interdite car le serveur est distant |
| 745 | 745 | **/ |
| 746 | 746 | function balise_distante_interdite($p) { |
| 747 | - $nom = $p->id_boucle; |
|
| 747 | + $nom = $p->id_boucle; |
|
| 748 | 748 | |
| 749 | - if ($nom && trouver_nom_serveur_distant($p)) { |
|
| 750 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 749 | + if ($nom && trouver_nom_serveur_distant($p)) { |
|
| 750 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 751 | 751 | |
| 752 | - return false; |
|
| 753 | - } |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return true; |
|
| 755 | + return true; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -762,75 +762,75 @@ discard block |
||
| 762 | 762 | // |
| 763 | 763 | function champs_traitements($p) { |
| 764 | 764 | |
| 765 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 766 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 767 | - } else { |
|
| 768 | - // quand on utilise un traitement catch-all * |
|
| 769 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 770 | - // leur propre securite |
|
| 771 | - $ps = $p->balise_calculee ? false : $GLOBALS['table_des_traitements']['*']; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - if (is_array($ps)) { |
|
| 775 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 776 | - $idb = index_boucle($p); |
|
| 777 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 778 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 779 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 783 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 784 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 785 | - |
|
| 786 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 787 | - if ($type_requete && isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 788 | - $type_alias = $type_requete; |
|
| 789 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 790 | - } else { |
|
| 791 | - $type_alias = false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 795 | - if ($table_sql && isset($ps[$table_sql])) { |
|
| 796 | - $ps = $ps[$table_sql]; |
|
| 797 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 798 | - elseif ($type_requete && isset($ps[$type_requete])) { |
|
| 799 | - $ps = $ps[$type_requete]; |
|
| 800 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 801 | - elseif ($type_alias && isset($ps[$type_alias])) { |
|
| 802 | - $ps = $ps[$type_alias]; |
|
| 803 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 804 | - elseif (isset($ps[0])) { |
|
| 805 | - $ps = $ps[0]; |
|
| 806 | - } else { |
|
| 807 | - $ps = false; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - if (!$ps) { |
|
| 812 | - return $p->code; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 816 | - // ou si in INCLURE contient {doublons} |
|
| 817 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 818 | - // dans les filtres propre() ou typo() |
|
| 819 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 820 | - |
|
| 821 | - if ( |
|
| 822 | - isset($p->descr['documents']) |
|
| 823 | - && $p->descr['documents'] |
|
| 824 | - && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
|
| 825 | - ) { |
|
| 826 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 830 | - // dans la declaration des traitements des champs sensibles |
|
| 831 | - |
|
| 832 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 833 | - return str_replace('%s', $p->code, $ps); |
|
| 765 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 766 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 767 | + } else { |
|
| 768 | + // quand on utilise un traitement catch-all * |
|
| 769 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 770 | + // leur propre securite |
|
| 771 | + $ps = $p->balise_calculee ? false : $GLOBALS['table_des_traitements']['*']; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + if (is_array($ps)) { |
|
| 775 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 776 | + $idb = index_boucle($p); |
|
| 777 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 778 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 779 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 783 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 784 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 785 | + |
|
| 786 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 787 | + if ($type_requete && isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 788 | + $type_alias = $type_requete; |
|
| 789 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 790 | + } else { |
|
| 791 | + $type_alias = false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 795 | + if ($table_sql && isset($ps[$table_sql])) { |
|
| 796 | + $ps = $ps[$table_sql]; |
|
| 797 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 798 | + elseif ($type_requete && isset($ps[$type_requete])) { |
|
| 799 | + $ps = $ps[$type_requete]; |
|
| 800 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 801 | + elseif ($type_alias && isset($ps[$type_alias])) { |
|
| 802 | + $ps = $ps[$type_alias]; |
|
| 803 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 804 | + elseif (isset($ps[0])) { |
|
| 805 | + $ps = $ps[0]; |
|
| 806 | + } else { |
|
| 807 | + $ps = false; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + if (!$ps) { |
|
| 812 | + return $p->code; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 816 | + // ou si in INCLURE contient {doublons} |
|
| 817 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 818 | + // dans les filtres propre() ou typo() |
|
| 819 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 820 | + |
|
| 821 | + if ( |
|
| 822 | + isset($p->descr['documents']) |
|
| 823 | + && $p->descr['documents'] |
|
| 824 | + && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
|
| 825 | + ) { |
|
| 826 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 830 | + // dans la declaration des traitements des champs sensibles |
|
| 831 | + |
|
| 832 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 833 | + return str_replace('%s', $p->code, $ps); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | |
@@ -842,95 +842,95 @@ discard block |
||
| 842 | 842 | // |
| 843 | 843 | function applique_filtres($p) { |
| 844 | 844 | |
| 845 | - // Traitements standards (cf. supra) |
|
| 846 | - $code = $p->etoile == '' ? champs_traitements($p) : $p->code; |
|
| 845 | + // Traitements standards (cf. supra) |
|
| 846 | + $code = $p->etoile == '' ? champs_traitements($p) : $p->code; |
|
| 847 | 847 | |
| 848 | - // Appliquer les filtres perso |
|
| 849 | - if ($p->param) { |
|
| 850 | - $code = compose_filtres($p, $code); |
|
| 851 | - } |
|
| 848 | + // Appliquer les filtres perso |
|
| 849 | + if ($p->param) { |
|
| 850 | + $code = compose_filtres($p, $code); |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 854 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 855 | - if (isset($p->descr['session'])) { |
|
| 856 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 857 | - } |
|
| 853 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 854 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 855 | + if (isset($p->descr['session'])) { |
|
| 856 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 857 | + } |
|
| 858 | 858 | |
| 859 | - return sandbox_composer_interdire_scripts($code, $p); |
|
| 859 | + return sandbox_composer_interdire_scripts($code, $p); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 863 | 863 | function compose_filtres(&$p, $code) { |
| 864 | 864 | |
| 865 | - $image_miette = false; |
|
| 866 | - foreach ($p->param as $filtre) { |
|
| 867 | - $fonc = array_shift($filtre); |
|
| 868 | - if (!$fonc) { |
|
| 869 | - continue; |
|
| 870 | - } // normalement qu'au premier tour. |
|
| 871 | - $is_filtre_image = (str_starts_with($fonc, 'image_') && $fonc != 'image_graver'); |
|
| 872 | - if ($image_miette && !$is_filtre_image) { |
|
| 873 | - // il faut graver maintenant car apres le filtre en cours |
|
| 874 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | - $code = "filtrer('image_graver', $code)"; |
|
| 876 | - $image_miette = false; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - // recuperer les arguments du filtre, |
|
| 880 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | - if ($fonc !== '?') { |
|
| 883 | - $sep = ','; |
|
| 884 | - } else { |
|
| 885 | - $sep = ':'; |
|
| 886 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | - if ($countfiltre != 2) { |
|
| 888 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | - $countfiltre = 2; |
|
| 890 | - } |
|
| 891 | - } |
|
| 892 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | - if ($logique) { |
|
| 895 | - $code = $logique; |
|
| 896 | - } else { |
|
| 897 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | - if ($is_filtre_image) { |
|
| 899 | - $image_miette = true; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | - if ($image_miette) { |
|
| 905 | - $code = "filtrer('image_graver',$code)"; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - return $code; |
|
| 865 | + $image_miette = false; |
|
| 866 | + foreach ($p->param as $filtre) { |
|
| 867 | + $fonc = array_shift($filtre); |
|
| 868 | + if (!$fonc) { |
|
| 869 | + continue; |
|
| 870 | + } // normalement qu'au premier tour. |
|
| 871 | + $is_filtre_image = (str_starts_with($fonc, 'image_') && $fonc != 'image_graver'); |
|
| 872 | + if ($image_miette && !$is_filtre_image) { |
|
| 873 | + // il faut graver maintenant car apres le filtre en cours |
|
| 874 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | + $code = "filtrer('image_graver', $code)"; |
|
| 876 | + $image_miette = false; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + // recuperer les arguments du filtre, |
|
| 880 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | + if ($fonc !== '?') { |
|
| 883 | + $sep = ','; |
|
| 884 | + } else { |
|
| 885 | + $sep = ':'; |
|
| 886 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | + if ($countfiltre != 2) { |
|
| 888 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | + $countfiltre = 2; |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | + if ($logique) { |
|
| 895 | + $code = $logique; |
|
| 896 | + } else { |
|
| 897 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | + if ($is_filtre_image) { |
|
| 899 | + $image_miette = true; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | + if ($image_miette) { |
|
| 905 | + $code = "filtrer('image_graver',$code)"; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + return $code; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 912 | 912 | // et comparateurs |
| 913 | 913 | function filtre_logique($fonc, $code, $arg) { |
| 914 | - return match (true) { |
|
| 915 | - in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 916 | - $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 917 | - $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 918 | - $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 919 | - $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 920 | - $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 921 | - $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 922 | - default => '', |
|
| 923 | - }; |
|
| 914 | + return match (true) { |
|
| 915 | + in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 916 | + $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 917 | + $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 918 | + $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 919 | + $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 920 | + $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 921 | + $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 922 | + default => '', |
|
| 923 | + }; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | function compose_filtres_args($p, $args, $sep) { |
| 927 | - $arglist = ''; |
|
| 928 | - foreach ($args as $arg) { |
|
| 929 | - $arglist .= $sep . |
|
| 930 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 931 | - } |
|
| 927 | + $arglist = ''; |
|
| 928 | + foreach ($args as $arg) { |
|
| 929 | + $arglist .= $sep . |
|
| 930 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return $arglist; |
|
| 933 | + return $arglist; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | |
@@ -948,15 +948,15 @@ discard block |
||
| 948 | 948 | **/ |
| 949 | 949 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 950 | 950 | |
| 951 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 952 | - if ($boucles[$idb]->externe) { |
|
| 953 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 954 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 955 | - // on ignore le defaut fourni dans ce cas |
|
| 956 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 957 | - } |
|
| 951 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 952 | + if ($boucles[$idb]->externe) { |
|
| 953 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 954 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 955 | + // on ignore le defaut fourni dans ce cas |
|
| 956 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 957 | + } |
|
| 958 | 958 | |
| 959 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 959 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | // |
@@ -970,30 +970,30 @@ discard block |
||
| 970 | 970 | // |
| 971 | 971 | |
| 972 | 972 | function rindex_pile($p, $champ, $motif) { |
| 973 | - $n = 0; |
|
| 974 | - $b = $p->id_boucle; |
|
| 975 | - $p->code = ''; |
|
| 976 | - while ($b != '') { |
|
| 977 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 978 | - if ($critere->op == $motif) { |
|
| 979 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | - "]['$champ']"; |
|
| 981 | - $b = ''; |
|
| 982 | - break 2; |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - $n++; |
|
| 986 | - $b = $p->boucles[$b]->id_parent; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 990 | - if (!$p->code) { |
|
| 991 | - $p->code = "''"; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - $p->interdire_scripts = false; |
|
| 995 | - |
|
| 996 | - return $p; |
|
| 973 | + $n = 0; |
|
| 974 | + $b = $p->id_boucle; |
|
| 975 | + $p->code = ''; |
|
| 976 | + while ($b != '') { |
|
| 977 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 978 | + if ($critere->op == $motif) { |
|
| 979 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | + "]['$champ']"; |
|
| 981 | + $b = ''; |
|
| 982 | + break 2; |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + $n++; |
|
| 986 | + $b = $p->boucles[$b]->id_parent; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 990 | + if (!$p->code) { |
|
| 991 | + $p->code = "''"; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + $p->interdire_scripts = false; |
|
| 995 | + |
|
| 996 | + return $p; |
|
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | /** |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1004 | 1004 | */ |
| 1005 | 1005 | function zbug_presenter_champ($p, $champ = '') { |
| 1006 | - $balise = $champ ?: $p->nom_champ; |
|
| 1007 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | - return "#{$explicite}{$balise}"; |
|
| 1006 | + $balise = $champ ?: $p->nom_champ; |
|
| 1007 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | + return "#{$explicite}{$balise}"; |
|
| 1009 | 1009 | } |