@@ -11,74 +11,74 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Correction typographique francaise |
| 18 | 18 | |
| 19 | 19 | function typographie_fr_dist($letexte) { |
| 20 | 20 | |
| 21 | - static $trans; |
|
| 21 | + static $trans; |
|
| 22 | 22 | |
| 23 | - // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 24 | - // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 25 | - if (!$trans) { |
|
| 26 | - $trans = [ |
|
| 27 | - "'" => '’', |
|
| 28 | - ' ' => '~', |
|
| 29 | - '»' => '»', |
|
| 30 | - '«' => '«', |
|
| 31 | - '”' => '”', |
|
| 32 | - '“' => '“', |
|
| 33 | - '°' => '°' |
|
| 34 | - ]; |
|
| 35 | - $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 36 | - $chars_trans = array_keys($chars); |
|
| 37 | - $chars = array_values($chars); |
|
| 38 | - $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 39 | - $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 40 | - $chars_trans = explode(' ', $chars_trans); |
|
| 41 | - foreach ($chars as $k => $r) { |
|
| 42 | - $trans[$chars_trans[$k]] = $r; |
|
| 43 | - } |
|
| 44 | - } |
|
| 23 | + // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; |
|
| 24 | + // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe |
|
| 25 | + if (!$trans) { |
|
| 26 | + $trans = [ |
|
| 27 | + "'" => '’', |
|
| 28 | + ' ' => '~', |
|
| 29 | + '»' => '»', |
|
| 30 | + '«' => '«', |
|
| 31 | + '”' => '”', |
|
| 32 | + '“' => '“', |
|
| 33 | + '°' => '°' |
|
| 34 | + ]; |
|
| 35 | + $chars = [160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°']; |
|
| 36 | + $chars_trans = array_keys($chars); |
|
| 37 | + $chars = array_values($chars); |
|
| 38 | + $chars_trans = implode(' ', array_map('chr', $chars_trans)); |
|
| 39 | + $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer')); |
|
| 40 | + $chars_trans = explode(' ', $chars_trans); |
|
| 41 | + foreach ($chars as $k => $r) { |
|
| 42 | + $trans[$chars_trans[$k]] = $r; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $letexte = strtr($letexte, $trans); |
|
| 46 | + $letexte = strtr($letexte, $trans); |
|
| 47 | 47 | |
| 48 | - $cherche1 = [ |
|
| 49 | - /* 1 */ |
|
| 50 | - '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 51 | - /* 2 */ |
|
| 52 | - '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 53 | - /* 3 */ |
|
| 54 | - '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 55 | - /* 4 */ |
|
| 56 | - '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 57 | - ]; |
|
| 58 | - $remplace1 = [ |
|
| 59 | - /* 1 */ |
|
| 60 | - '\1~;', |
|
| 61 | - /* 2 */ |
|
| 62 | - '~\0', |
|
| 63 | - /* 3 */ |
|
| 64 | - '\1~\2', |
|
| 65 | - /* 4 */ |
|
| 66 | - '\0~' |
|
| 67 | - ]; |
|
| 68 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 69 | - $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 48 | + $cherche1 = [ |
|
| 49 | + /* 1 */ |
|
| 50 | + '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S', |
|
| 51 | + /* 2 */ |
|
| 52 | + '/»| --?,|(?::(?!:)| %)(?:\W|$)/S', |
|
| 53 | + /* 3 */ |
|
| 54 | + '/([^[<(!?.])([!?][!?\.]*)/iS', |
|
| 55 | + /* 4 */ |
|
| 56 | + '/«|(?:M(?:M?\.|mes?|r\.?)|[MnN]°) /S' |
|
| 57 | + ]; |
|
| 58 | + $remplace1 = [ |
|
| 59 | + /* 1 */ |
|
| 60 | + '\1~;', |
|
| 61 | + /* 2 */ |
|
| 62 | + '~\0', |
|
| 63 | + /* 3 */ |
|
| 64 | + '\1~\2', |
|
| 65 | + /* 4 */ |
|
| 66 | + '\0~' |
|
| 67 | + ]; |
|
| 68 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 69 | + $letexte = preg_replace('/ *~+ */S', '~', $letexte); |
|
| 70 | 70 | |
| 71 | - $cherche2 = [ |
|
| 72 | - '/([^-\n]|^)--([^-]|$)/S', |
|
| 73 | - ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 74 | - '/~/' |
|
| 75 | - ]; |
|
| 76 | - $remplace2 = [ |
|
| 77 | - '\1—\2', |
|
| 78 | - '\1\3\4', |
|
| 79 | - ' ' |
|
| 80 | - ]; |
|
| 81 | - $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 71 | + $cherche2 = [ |
|
| 72 | + '/([^-\n]|^)--([^-]|$)/S', |
|
| 73 | + ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 74 | + '/~/' |
|
| 75 | + ]; |
|
| 76 | + $remplace2 = [ |
|
| 77 | + '\1—\2', |
|
| 78 | + '\1\3\4', |
|
| 79 | + ' ' |
|
| 80 | + ]; |
|
| 81 | + $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 82 | 82 | |
| 83 | - return $letexte; |
|
| 83 | + return $letexte; |
|
| 84 | 84 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | |
| 71 | 71 | $cherche2 = [ |
| 72 | 72 | '/([^-\n]|^)--([^-]|$)/S', |
| 73 | - ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 73 | + ',('._PROTOCOLES_STD.')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', |
|
| 74 | 74 | '/~/' |
| 75 | 75 | ]; |
| 76 | 76 | $remplace2 = [ |
@@ -11,37 +11,37 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // rien sauf les "~" et "-," |
| 18 | 18 | |
| 19 | 19 | function typographie_en_dist($letexte) { |
| 20 | 20 | |
| 21 | - // zouli apostrophe |
|
| 22 | - $letexte = str_replace("'", '’', $letexte); |
|
| 21 | + // zouli apostrophe |
|
| 22 | + $letexte = str_replace("'", '’', $letexte); |
|
| 23 | 23 | |
| 24 | - $cherche1 = [ |
|
| 25 | - '/ --?,/S' |
|
| 26 | - ]; |
|
| 27 | - $remplace1 = [ |
|
| 28 | - '~\0' |
|
| 29 | - ]; |
|
| 30 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 24 | + $cherche1 = [ |
|
| 25 | + '/ --?,/S' |
|
| 26 | + ]; |
|
| 27 | + $remplace1 = [ |
|
| 28 | + '~\0' |
|
| 29 | + ]; |
|
| 30 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 31 | 31 | |
| 32 | - $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | - $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 32 | + $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | + $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 34 | 34 | |
| 35 | - $cherche2 = [ |
|
| 36 | - '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | - '/~/' |
|
| 38 | - ]; |
|
| 39 | - $remplace2 = [ |
|
| 40 | - '\1—\2', |
|
| 41 | - ' ' |
|
| 42 | - ]; |
|
| 35 | + $cherche2 = [ |
|
| 36 | + '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | + '/~/' |
|
| 38 | + ]; |
|
| 39 | + $remplace2 = [ |
|
| 40 | + '\1—\2', |
|
| 41 | + ' ' |
|
| 42 | + ]; |
|
| 43 | 43 | |
| 44 | - $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 44 | + $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 45 | 45 | |
| 46 | - return $letexte; |
|
| 46 | + return $letexte; |
|
| 47 | 47 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, $connect = '') { |
| 60 | - static $cache_quete = []; |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if ( |
|
| 66 | - !$desc = $trouver_table( |
|
| 67 | - $table, |
|
| 68 | - $connect |
|
| 69 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | - ) { |
|
| 71 | - // pas de parent rubrique, on passe |
|
| 72 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | - } else { |
|
| 74 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | - $cache_quete[$connect][$table]['_select'], |
|
| 83 | - $table, |
|
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - '', |
|
| 89 | - $connect |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 60 | + static $cache_quete = []; |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if ( |
|
| 66 | + !$desc = $trouver_table( |
|
| 67 | + $table, |
|
| 68 | + $connect |
|
| 69 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | + ) { |
|
| 71 | + // pas de parent rubrique, on passe |
|
| 72 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | + } else { |
|
| 74 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | + $cache_quete[$connect][$table]['_select'], |
|
| 83 | + $table, |
|
| 84 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + '', |
|
| 89 | + $connect |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | function quete_parent($id_rubrique, $connect = '') { |
| 111 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | - return 0; |
|
| 113 | - } |
|
| 114 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 111 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | function quete_rubrique($id_article, $serveur) { |
| 131 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 132 | 132 | |
| 133 | - return $id_parent['id_rubrique']; |
|
| 133 | + return $id_parent['id_rubrique']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * @return int |
| 145 | 145 | */ |
| 146 | 146 | function quete_profondeur($id, $connect = '') { |
| 147 | - $n = 0; |
|
| 148 | - while ($id) { |
|
| 149 | - $n++; |
|
| 150 | - $id = quete_parent($id, $connect); |
|
| 151 | - } |
|
| 147 | + $n = 0; |
|
| 148 | + while ($id) { |
|
| 149 | + $n++; |
|
| 150 | + $id = quete_parent($id, $connect); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $n; |
|
| 153 | + return $n; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * Morceau de la requête SQL testant la date |
| 167 | 167 | */ |
| 168 | 168 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 169 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | - return '1=1'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return |
|
| 174 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | - : '1=1'; |
|
| 169 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | + return '1=1'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return |
|
| 174 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | + : '1=1'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -194,101 +194,101 @@ discard block |
||
| 194 | 194 | * @return array|string |
| 195 | 195 | */ |
| 196 | 196 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 197 | - static $cond = []; |
|
| 198 | - $key = func_get_args(); |
|
| 199 | - $key = implode('-', $key); |
|
| 200 | - if (isset($cond[$key])) { |
|
| 201 | - return $cond[$key]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $liste_statuts = $publie; |
|
| 205 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | - $liste_statuts = $previsu; |
|
| 207 | - } |
|
| 208 | - $not = false; |
|
| 209 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | - $not = true; |
|
| 211 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | - } |
|
| 213 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | - if (!strlen($liste_statuts)) { |
|
| 215 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | - $where = []; |
|
| 220 | - foreach ($liste_statuts as $k => $v) { |
|
| 221 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | - // a ceux de l'auteur identifie |
|
| 223 | - if (strpos($v, '/') !== false) { |
|
| 224 | - $v = explode('/', $v); |
|
| 225 | - $filtre = end($v); |
|
| 226 | - $v = reset($v); |
|
| 227 | - $v = preg_replace(',\W,', '', $v); |
|
| 228 | - if ( |
|
| 229 | - $filtre == 'auteur' |
|
| 230 | - and (strpos($mstatut, '.') !== false) |
|
| 231 | - and $objet = explode('.', $mstatut) |
|
| 232 | - and $id_table = reset($objet) |
|
| 233 | - and $objet = objet_type($id_table) |
|
| 234 | - ) { |
|
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | - |
|
| 237 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | - // sinon l’auteur en session |
|
| 239 | - include_spip('inc/securiser_action'); |
|
| 240 | - if ($desc = decrire_token_previsu()) { |
|
| 241 | - $id_auteur = $desc['id_auteur']; |
|
| 242 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | - } else { |
|
| 245 | - $id_auteur = null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | - if (!$id_auteur) { |
|
| 252 | - $where[] = $w; |
|
| 253 | - } else { |
|
| 254 | - $primary = id_table_objet($objet); |
|
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | - 'ssss.id_objet', |
|
| 257 | - 'spip_auteurs_liens AS ssss', |
|
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - '', |
|
| 263 | - $serveur |
|
| 264 | - ) . '))'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | - else { |
|
| 269 | - $v = ''; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // securite |
|
| 273 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | - } |
|
| 275 | - $liste_statuts = array_filter($liste_statuts); |
|
| 276 | - if (count($liste_statuts) == 1) { |
|
| 277 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | - } else { |
|
| 279 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - while (count($where) > 1) { |
|
| 283 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | - $where[] = $and; |
|
| 285 | - } |
|
| 286 | - $cond[$key] = reset($where); |
|
| 287 | - if ($not) { |
|
| 288 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $cond[$key]; |
|
| 197 | + static $cond = []; |
|
| 198 | + $key = func_get_args(); |
|
| 199 | + $key = implode('-', $key); |
|
| 200 | + if (isset($cond[$key])) { |
|
| 201 | + return $cond[$key]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $liste_statuts = $publie; |
|
| 205 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | + $liste_statuts = $previsu; |
|
| 207 | + } |
|
| 208 | + $not = false; |
|
| 209 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | + $not = true; |
|
| 211 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | + } |
|
| 213 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | + if (!strlen($liste_statuts)) { |
|
| 215 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | + $where = []; |
|
| 220 | + foreach ($liste_statuts as $k => $v) { |
|
| 221 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | + // a ceux de l'auteur identifie |
|
| 223 | + if (strpos($v, '/') !== false) { |
|
| 224 | + $v = explode('/', $v); |
|
| 225 | + $filtre = end($v); |
|
| 226 | + $v = reset($v); |
|
| 227 | + $v = preg_replace(',\W,', '', $v); |
|
| 228 | + if ( |
|
| 229 | + $filtre == 'auteur' |
|
| 230 | + and (strpos($mstatut, '.') !== false) |
|
| 231 | + and $objet = explode('.', $mstatut) |
|
| 232 | + and $id_table = reset($objet) |
|
| 233 | + and $objet = objet_type($id_table) |
|
| 234 | + ) { |
|
| 235 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | + |
|
| 237 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | + // sinon l’auteur en session |
|
| 239 | + include_spip('inc/securiser_action'); |
|
| 240 | + if ($desc = decrire_token_previsu()) { |
|
| 241 | + $id_auteur = $desc['id_auteur']; |
|
| 242 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | + } else { |
|
| 245 | + $id_auteur = null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | + if (!$id_auteur) { |
|
| 252 | + $where[] = $w; |
|
| 253 | + } else { |
|
| 254 | + $primary = id_table_objet($objet); |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | + 'ssss.id_objet', |
|
| 257 | + 'spip_auteurs_liens AS ssss', |
|
| 258 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + '', |
|
| 263 | + $serveur |
|
| 264 | + ) . '))'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | + else { |
|
| 269 | + $v = ''; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // securite |
|
| 273 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | + } |
|
| 275 | + $liste_statuts = array_filter($liste_statuts); |
|
| 276 | + if (count($liste_statuts) == 1) { |
|
| 277 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | + } else { |
|
| 279 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + while (count($where) > 1) { |
|
| 283 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | + $where[] = $and; |
|
| 285 | + } |
|
| 286 | + $cond[$key] = reset($where); |
|
| 287 | + if ($not) { |
|
| 288 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $cond[$key]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -347,66 +347,66 @@ discard block |
||
| 347 | 347 | * Retourne soit un tableau, soit le chemin du fichier. |
| 348 | 348 | */ |
| 349 | 349 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 350 | - include_spip('base/objets'); |
|
| 351 | - $nom = strtolower($onoff); |
|
| 352 | - |
|
| 353 | - $cle_objet = id_table_objet($cle_objet); |
|
| 354 | - |
|
| 355 | - while (1) { |
|
| 356 | - $objet = objet_type($cle_objet); |
|
| 357 | - |
|
| 358 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | - |
|
| 360 | - if ($on) { |
|
| 361 | - if ($flag) { |
|
| 362 | - return basename($on['chemin']); |
|
| 363 | - } else { |
|
| 364 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | - |
|
| 366 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | - // alors on ne cherche pas du tout le survol ici |
|
| 369 | - if ($onoff != 'ON') { |
|
| 370 | - $off = ''; |
|
| 371 | - } else { |
|
| 372 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | - // qui permet de distinguer le changement de logo |
|
| 378 | - // et placer un expire sur le dossier IMG/ |
|
| 379 | - $res = [ |
|
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | - ]; |
|
| 384 | - $res['src'] = $res[0]; |
|
| 385 | - $res['logo_on'] = $res[0]; |
|
| 386 | - $res['logo_off'] = $res[1]; |
|
| 387 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | - |
|
| 390 | - return $res; |
|
| 391 | - } |
|
| 392 | - } else { |
|
| 393 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | - return ''; |
|
| 395 | - } else { |
|
| 396 | - if ($id_rubrique) { |
|
| 397 | - $cle_objet = 'id_rubrique'; |
|
| 398 | - $id = $id_rubrique; |
|
| 399 | - $id_rubrique = 0; |
|
| 400 | - } else { |
|
| 401 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | - $id = quete_parent($id); |
|
| 403 | - } else { |
|
| 404 | - return ''; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 350 | + include_spip('base/objets'); |
|
| 351 | + $nom = strtolower($onoff); |
|
| 352 | + |
|
| 353 | + $cle_objet = id_table_objet($cle_objet); |
|
| 354 | + |
|
| 355 | + while (1) { |
|
| 356 | + $objet = objet_type($cle_objet); |
|
| 357 | + |
|
| 358 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | + |
|
| 360 | + if ($on) { |
|
| 361 | + if ($flag) { |
|
| 362 | + return basename($on['chemin']); |
|
| 363 | + } else { |
|
| 364 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | + |
|
| 366 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | + // alors on ne cherche pas du tout le survol ici |
|
| 369 | + if ($onoff != 'ON') { |
|
| 370 | + $off = ''; |
|
| 371 | + } else { |
|
| 372 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | + // qui permet de distinguer le changement de logo |
|
| 378 | + // et placer un expire sur le dossier IMG/ |
|
| 379 | + $res = [ |
|
| 380 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | + ]; |
|
| 384 | + $res['src'] = $res[0]; |
|
| 385 | + $res['logo_on'] = $res[0]; |
|
| 386 | + $res['logo_off'] = $res[1]; |
|
| 387 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | + |
|
| 390 | + return $res; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | + return ''; |
|
| 395 | + } else { |
|
| 396 | + if ($id_rubrique) { |
|
| 397 | + $cle_objet = 'id_rubrique'; |
|
| 398 | + $id = $id_rubrique; |
|
| 399 | + $id_rubrique = 0; |
|
| 400 | + } else { |
|
| 401 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | + $id = quete_parent($id); |
|
| 403 | + } else { |
|
| 404 | + return ''; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,37 +420,37 @@ discard block |
||
| 420 | 420 | * "on" ou "off" suivant le logo normal ou survol |
| 421 | 421 | **/ |
| 422 | 422 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 423 | - static $chercher_logo; |
|
| 424 | - if (is_null($chercher_logo)) { |
|
| 425 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | - } |
|
| 427 | - $cle_objet = id_table_objet($objet); |
|
| 428 | - |
|
| 429 | - // On cherche pas la méthode classique |
|
| 430 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | - if (!empty($infos_logo)) { |
|
| 433 | - $infos_logo = [ |
|
| 434 | - 'chemin' => $infos_logo[0], |
|
| 435 | - 'timestamp' => $infos_logo[4], |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // On passe cette recherche de logo dans un pipeline |
|
| 440 | - $infos_logo = pipeline( |
|
| 441 | - 'quete_logo_objet', |
|
| 442 | - [ |
|
| 443 | - 'args' => [ |
|
| 444 | - 'id_objet' => $id_objet, |
|
| 445 | - 'objet' => $objet, |
|
| 446 | - 'cle_objet' => $cle_objet, |
|
| 447 | - 'mode' => $mode, |
|
| 448 | - ], |
|
| 449 | - 'data' => $infos_logo, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - return $infos_logo; |
|
| 423 | + static $chercher_logo; |
|
| 424 | + if (is_null($chercher_logo)) { |
|
| 425 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | + } |
|
| 427 | + $cle_objet = id_table_objet($objet); |
|
| 428 | + |
|
| 429 | + // On cherche pas la méthode classique |
|
| 430 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | + if (!empty($infos_logo)) { |
|
| 433 | + $infos_logo = [ |
|
| 434 | + 'chemin' => $infos_logo[0], |
|
| 435 | + 'timestamp' => $infos_logo[4], |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // On passe cette recherche de logo dans un pipeline |
|
| 440 | + $infos_logo = pipeline( |
|
| 441 | + 'quete_logo_objet', |
|
| 442 | + [ |
|
| 443 | + 'args' => [ |
|
| 444 | + 'id_objet' => $id_objet, |
|
| 445 | + 'objet' => $objet, |
|
| 446 | + 'cle_objet' => $cle_objet, |
|
| 447 | + 'mode' => $mode, |
|
| 448 | + ], |
|
| 449 | + 'data' => $infos_logo, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + return $infos_logo; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @return bool|string |
| 464 | 464 | */ |
| 465 | 465 | function quete_logo_file($row, $connect = null) { |
| 466 | - include_spip('inc/documents'); |
|
| 467 | - $logo = vignette_logo_document($row, $connect); |
|
| 468 | - if (!$logo) { |
|
| 469 | - $logo = image_du_document($row, $connect); |
|
| 470 | - } |
|
| 471 | - if (!$logo) { |
|
| 472 | - $f = charger_fonction('vignette', 'inc'); |
|
| 473 | - $logo = $f($row['extension'], false); |
|
| 474 | - } |
|
| 475 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | - if ( |
|
| 477 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | - ) { |
|
| 481 | - return $logo; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return get_spip_doc($logo); |
|
| 466 | + include_spip('inc/documents'); |
|
| 467 | + $logo = vignette_logo_document($row, $connect); |
|
| 468 | + if (!$logo) { |
|
| 469 | + $logo = image_du_document($row, $connect); |
|
| 470 | + } |
|
| 471 | + if (!$logo) { |
|
| 472 | + $f = charger_fonction('vignette', 'inc'); |
|
| 473 | + $logo = $f($row['extension'], false); |
|
| 474 | + } |
|
| 475 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | + if ( |
|
| 477 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | + ) { |
|
| 481 | + return $logo; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return get_spip_doc($logo); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) { |
| 511 | 511 | |
| 512 | - include_spip('inc/documents'); |
|
| 513 | - $logo = ''; |
|
| 514 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | - $logo = vignette_logo_document($row, $connect); |
|
| 516 | - } |
|
| 517 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | - return ''; |
|
| 520 | - } |
|
| 521 | - if ($mode_logo == 'icone') { |
|
| 522 | - $row['fichier'] = ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 512 | + include_spip('inc/documents'); |
|
| 513 | + $logo = ''; |
|
| 514 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | + $logo = vignette_logo_document($row, $connect); |
|
| 516 | + } |
|
| 517 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | + return ''; |
|
| 520 | + } |
|
| 521 | + if ($mode_logo == 'icone') { |
|
| 522 | + $row['fichier'] = ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function quete_html_logo($logo, $align, $lien) { |
| 536 | 536 | |
| 537 | - if (!is_array($logo)) { |
|
| 538 | - return ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - $contexte = []; |
|
| 542 | - foreach ($logo as $k => $v) { |
|
| 543 | - if (!is_numeric($k)) { |
|
| 544 | - $contexte[$k] = $v; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - $contexte['align'] = $align; |
|
| 548 | - $contexte['lien'] = $lien; |
|
| 549 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 537 | + if (!is_array($logo)) { |
|
| 538 | + return ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + $contexte = []; |
|
| 542 | + foreach ($logo as $k => $v) { |
|
| 543 | + if (!is_numeric($k)) { |
|
| 544 | + $contexte[$k] = $v; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + $contexte['align'] = $align; |
|
| 548 | + $contexte['lien'] = $lien; |
|
| 549 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return string|false |
| 561 | 561 | */ |
| 562 | 562 | function document_spip_externe($fichier, $connect) { |
| 563 | - if ($connect) { |
|
| 564 | - $site = quete_meta('adresse_site', $connect); |
|
| 565 | - if ($site) { |
|
| 566 | - $dir = quete_meta('dir_img', $connect); |
|
| 567 | - return "$site/$dir$fichier"; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 563 | + if ($connect) { |
|
| 564 | + $site = quete_meta('adresse_site', $connect); |
|
| 565 | + if ($site) { |
|
| 566 | + $dir = quete_meta('dir_img', $connect); |
|
| 567 | + return "$site/$dir$fichier"; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -580,23 +580,23 @@ discard block |
||
| 580 | 580 | * @return string |
| 581 | 581 | */ |
| 582 | 582 | function vignette_logo_document($row, $connect = '') { |
| 583 | - if (!$row['id_vignette']) { |
|
| 584 | - return ''; |
|
| 585 | - } |
|
| 586 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | - return $url; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - $f = get_spip_doc($fichier); |
|
| 592 | - if ($f and @file_exists($f)) { |
|
| 593 | - return $f; |
|
| 594 | - } |
|
| 595 | - if ($row['mode'] !== 'vignette') { |
|
| 596 | - return ''; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 583 | + if (!$row['id_vignette']) { |
|
| 584 | + return ''; |
|
| 585 | + } |
|
| 586 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 587 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 588 | + return $url; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + $f = get_spip_doc($fichier); |
|
| 592 | + if ($f and @file_exists($f)) { |
|
| 593 | + return $f; |
|
| 594 | + } |
|
| 595 | + if ($row['mode'] !== 'vignette') { |
|
| 596 | + return ''; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -612,69 +612,69 @@ discard block |
||
| 612 | 612 | * @return bool|string |
| 613 | 613 | */ |
| 614 | 614 | function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') { |
| 615 | - static $exposer = []; |
|
| 616 | - |
|
| 617 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | - // en static. |
|
| 621 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | - (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | - // il n'est donc pas utile |
|
| 628 | - $parent = 0; |
|
| 629 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | - if (isset($enfants[$type])) { |
|
| 632 | - foreach ($enfants[$type] as $t) { |
|
| 633 | - if ( |
|
| 634 | - isset($reference[$t]) |
|
| 635 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | - or isset($reference["@$t"]) |
|
| 637 | - ) { |
|
| 638 | - $type = $t; |
|
| 639 | - $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | - continue; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - $exposer[$m][$type] = []; |
|
| 646 | - if ($principal) { |
|
| 647 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | - foreach ($principaux as $principal) { |
|
| 649 | - $exposer[$m][$type][$principal] = true; |
|
| 650 | - if ($type == 'id_mot') { |
|
| 651 | - if (!$parent) { |
|
| 652 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | - } |
|
| 654 | - if ($parent) { |
|
| 655 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | - } |
|
| 657 | - } else { |
|
| 658 | - if ($type != 'id_groupe') { |
|
| 659 | - if (!$parent) { |
|
| 660 | - if ($type == 'id_rubrique') { |
|
| 661 | - $parent = $principal; |
|
| 662 | - } |
|
| 663 | - if ($type == 'id_article') { |
|
| 664 | - $parent = quete_rubrique($principal, $connect); |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - do { |
|
| 668 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // And the winner is... |
|
| 677 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 615 | + static $exposer = []; |
|
| 616 | + |
|
| 617 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 618 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 619 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 620 | + // en static. |
|
| 621 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 622 | + $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 625 | + (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 626 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 627 | + // il n'est donc pas utile |
|
| 628 | + $parent = 0; |
|
| 629 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 630 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 631 | + if (isset($enfants[$type])) { |
|
| 632 | + foreach ($enfants[$type] as $t) { |
|
| 633 | + if ( |
|
| 634 | + isset($reference[$t]) |
|
| 635 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 636 | + or isset($reference["@$t"]) |
|
| 637 | + ) { |
|
| 638 | + $type = $t; |
|
| 639 | + $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 640 | + continue; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + $exposer[$m][$type] = []; |
|
| 646 | + if ($principal) { |
|
| 647 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 648 | + foreach ($principaux as $principal) { |
|
| 649 | + $exposer[$m][$type][$principal] = true; |
|
| 650 | + if ($type == 'id_mot') { |
|
| 651 | + if (!$parent) { |
|
| 652 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 653 | + } |
|
| 654 | + if ($parent) { |
|
| 655 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 656 | + } |
|
| 657 | + } else { |
|
| 658 | + if ($type != 'id_groupe') { |
|
| 659 | + if (!$parent) { |
|
| 660 | + if ($type == 'id_rubrique') { |
|
| 661 | + $parent = $principal; |
|
| 662 | + } |
|
| 663 | + if ($type == 'id_article') { |
|
| 664 | + $parent = quete_rubrique($principal, $connect); |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + do { |
|
| 668 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 669 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + // And the winner is... |
|
| 677 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -689,21 +689,21 @@ discard block |
||
| 689 | 689 | * @return int |
| 690 | 690 | */ |
| 691 | 691 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 692 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | - // ou composee, mais verifions |
|
| 694 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | - return 0; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $pos = 0; |
|
| 699 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | - $pos++; |
|
| 701 | - } |
|
| 702 | - // si on a pas trouve |
|
| 703 | - if (!$row or $row[$primary] != $valeur) { |
|
| 704 | - return 0; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - // sinon, calculer le bon numero de page |
|
| 708 | - return floor($pos / $pas) * $pas; |
|
| 692 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 693 | + // ou composee, mais verifions |
|
| 694 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 695 | + return 0; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $pos = 0; |
|
| 699 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 700 | + $pos++; |
|
| 701 | + } |
|
| 702 | + // si on a pas trouve |
|
| 703 | + if (!$row or $row[$primary] != $valeur) { |
|
| 704 | + return 0; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + // sinon, calculer le bon numero de page |
|
| 708 | + return floor($pos / $pas) * $pas; |
|
| 709 | 709 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return sql_getfetsel( |
| 37 | 37 | 'virtuel', |
| 38 | 38 | 'spip_articles', |
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 39 | + ['id_article='.intval($id_article), "statut='publie'"], |
|
| 40 | 40 | '', |
| 41 | 41 | '', |
| 42 | 42 | '', |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $cache_quete[$connect][$table][$id] = sql_fetsel( |
| 82 | 82 | $cache_quete[$connect][$table]['_select'], |
| 83 | 83 | $table, |
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 84 | + $cache_quete[$connect][$table]['_id'].'='.intval($id), |
|
| 85 | 85 | '', |
| 86 | 86 | '', |
| 87 | 87 | '', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return |
| 174 | 174 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 175 | 175 | and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 176 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | 177 | : '1=1'; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | and $id_table = reset($objet) |
| 233 | 233 | and $objet = objet_type($id_table) |
| 234 | 234 | ) { |
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 235 | + $w = "$mstatut<>".sql_quote($v); |
|
| 236 | 236 | |
| 237 | 237 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 238 | 238 | // sinon l’auteur en session |
@@ -246,22 +246,22 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 249 | + if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) { |
|
| 250 | 250 | // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
| 251 | 251 | if (!$id_auteur) { |
| 252 | 252 | $where[] = $w; |
| 253 | 253 | } else { |
| 254 | 254 | $primary = id_table_objet($objet); |
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (".sql_get_select( |
|
| 256 | 256 | 'ssss.id_objet', |
| 257 | 257 | 'spip_auteurs_liens AS ssss', |
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 258 | + 'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur), |
|
| 259 | 259 | '', |
| 260 | 260 | '', |
| 261 | 261 | '', |
| 262 | 262 | '', |
| 263 | 263 | $serveur |
| 264 | - ) . '))'; |
|
| 264 | + ).'))'; |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } // ignorer ce statut si on ne sait pas comment le filtrer |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | // qui permet de distinguer le changement de logo |
| 378 | 378 | // et placer un expire sur le dossier IMG/ |
| 379 | 379 | $res = [ |
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 380 | + $on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' '.$taille[3])) |
|
| 383 | 383 | ]; |
| 384 | 384 | $res['src'] = $res[0]; |
| 385 | 385 | $res['logo_on'] = $res[0]; |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if ( |
| 477 | 477 | strcmp($logo, _DIR_PLUGINS) == 0 |
| 478 | 478 | or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE.'prive/') == 0 |
|
| 480 | 480 | ) { |
| 481 | 481 | return $logo; |
| 482 | 482 | } |
@@ -619,8 +619,7 @@ discard block |
||
| 619 | 619 | // qu'une fois (par squelette) et on conserve le resultat |
| 620 | 620 | // en static. |
| 621 | 621 | if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
| 622 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 623 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 622 | + $principal = isset($reference[$type]) ? $reference[$type] : // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 624 | 623 | // et donne la reference dynamique @type=xx dans le contexte |
| 625 | 624 | (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
| 626 | 625 | // le parent fournit en argument est le parent de $id, pas celui de $principal |
@@ -649,7 +648,7 @@ discard block |
||
| 649 | 648 | $exposer[$m][$type][$principal] = true; |
| 650 | 649 | if ($type == 'id_mot') { |
| 651 | 650 | if (!$parent) { |
| 652 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 651 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect); |
|
| 653 | 652 | } |
| 654 | 653 | if ($parent) { |
| 655 | 654 | $exposer[$m]['id_groupe'][$parent] = true; |
@@ -11,130 +11,130 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 31 | - |
|
| 32 | - if ($struct->jointures_explicites) { |
|
| 33 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 34 | - } |
|
| 35 | - if ($struct->table_optionnelle) { |
|
| 36 | - $type .= '?'; |
|
| 37 | - } |
|
| 38 | - // Revoir le cas de la boucle recursive |
|
| 39 | - |
|
| 40 | - $crit = $struct->param; |
|
| 41 | - if ($crit and !is_array($crit[0])) { |
|
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 43 | - } |
|
| 44 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | - |
|
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 47 | - |
|
| 48 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | + $struct->table_optionnelle); |
|
| 31 | + |
|
| 32 | + if ($struct->jointures_explicites) { |
|
| 33 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 34 | + } |
|
| 35 | + if ($struct->table_optionnelle) { |
|
| 36 | + $type .= '?'; |
|
| 37 | + } |
|
| 38 | + // Revoir le cas de la boucle recursive |
|
| 39 | + |
|
| 40 | + $crit = $struct->param; |
|
| 41 | + if ($crit and !is_array($crit[0])) { |
|
| 42 | + $type = strtolower($type) . array_shift($crit); |
|
| 43 | + } |
|
| 44 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | + |
|
| 46 | + $f = 'format_boucle_' . $fmt; |
|
| 47 | + |
|
| 48 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 52 | - $res = []; |
|
| 53 | - foreach ($struct->param ? $struct->param : [] as $couple) { |
|
| 54 | - array_shift($couple); |
|
| 55 | - foreach ($couple as $v) { |
|
| 56 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 62 | - |
|
| 63 | - return $f($file, $res, $prof); |
|
| 52 | + $res = []; |
|
| 53 | + foreach ($struct->param ? $struct->param : [] as $couple) { |
|
| 54 | + array_shift($couple); |
|
| 55 | + foreach ($couple as $v) { |
|
| 56 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | + $f = 'format_inclure_' . $fmt; |
|
| 62 | + |
|
| 63 | + return $f($file, $res, $prof); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 67 | + $f = 'format_texte_' . $fmt; |
|
| 68 | 68 | |
| 69 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 73 | + $f = 'format_polyglotte_' . $fmt; |
|
| 74 | 74 | |
| 75 | - return $f($struct->traductions, $prof); |
|
| 75 | + return $f($struct->traductions, $prof); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 79 | - $args = []; |
|
| 80 | - foreach ($struct->arg as $k => $v) { |
|
| 81 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | - } |
|
| 79 | + $args = []; |
|
| 80 | + foreach ($struct->arg as $k => $v) { |
|
| 81 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 85 | 85 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 86 | + $f = 'format_idiome_' . $fmt; |
|
| 87 | 87 | |
| 88 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 92 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | - $args = $filtres = ''; |
|
| 95 | - if ($p = $struct->param) { |
|
| 96 | - if ($p[0][0] === '') { |
|
| 97 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 98 | - } |
|
| 99 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | - } |
|
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 102 | - |
|
| 103 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 92 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | + $args = $filtres = ''; |
|
| 95 | + if ($p = $struct->param) { |
|
| 96 | + if ($p[0][0] === '') { |
|
| 97 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 98 | + } |
|
| 99 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | + } |
|
| 101 | + $f = 'format_champ_' . $fmt; |
|
| 102 | + |
|
| 103 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 107 | - if (!is_array($sources)) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 111 | - $res = ''; |
|
| 112 | - foreach ($sources as $arg) { |
|
| 113 | - if (!is_array($arg)) { |
|
| 114 | - continue; // ne devrait pas arriver. |
|
| 115 | - } else { |
|
| 116 | - $r = array_shift($arg); |
|
| 117 | - } |
|
| 118 | - $args = []; |
|
| 119 | - foreach ($arg as $v) { |
|
| 120 | - // cas des arguments entoures de ' ou " |
|
| 121 | - if ( |
|
| 122 | - (count($v) == 1) |
|
| 123 | - and $v[0]->type == 'texte' |
|
| 124 | - and (strlen($v[0]->apres) == 1) |
|
| 125 | - and $v[0]->apres == $v[0]->avant |
|
| 126 | - ) { |
|
| 127 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 128 | - } else { |
|
| 129 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - if (($r !== '') or $args) { |
|
| 133 | - $res .= $f($r, $args, $prof); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $res; |
|
| 107 | + if (!is_array($sources)) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + $f = 'format_liste_' . $fmt; |
|
| 111 | + $res = ''; |
|
| 112 | + foreach ($sources as $arg) { |
|
| 113 | + if (!is_array($arg)) { |
|
| 114 | + continue; // ne devrait pas arriver. |
|
| 115 | + } else { |
|
| 116 | + $r = array_shift($arg); |
|
| 117 | + } |
|
| 118 | + $args = []; |
|
| 119 | + foreach ($arg as $v) { |
|
| 120 | + // cas des arguments entoures de ' ou " |
|
| 121 | + if ( |
|
| 122 | + (count($v) == 1) |
|
| 123 | + and $v[0]->type == 'texte' |
|
| 124 | + and (strlen($v[0]->apres) == 1) |
|
| 125 | + and $v[0]->apres == $v[0]->avant |
|
| 126 | + ) { |
|
| 127 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 128 | + } else { |
|
| 129 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + if (($r !== '') or $args) { |
|
| 133 | + $res .= $f($r, $args, $prof); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $res; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Decompilation des criteres: on triche et on deroge: |
@@ -142,93 +142,93 @@ discard block |
||
| 142 | 142 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 143 | 143 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 144 | 144 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 145 | - $sources = $boucle->param; |
|
| 146 | - if (!is_array($sources)) { |
|
| 147 | - return ''; |
|
| 148 | - } |
|
| 149 | - $res = ''; |
|
| 150 | - $f = 'format_critere_' . $fmt; |
|
| 151 | - foreach ($sources as $crit) { |
|
| 152 | - if (!is_array($crit)) { |
|
| 153 | - continue; |
|
| 154 | - } // boucle recursive |
|
| 155 | - array_shift($crit); |
|
| 156 | - $args = []; |
|
| 157 | - foreach ($crit as $i => $v) { |
|
| 158 | - if ( |
|
| 159 | - (count($v) == 1) |
|
| 160 | - and $v[0]->type == 'texte' |
|
| 161 | - and $v[0]->apres |
|
| 162 | - ) { |
|
| 163 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 164 | - } else { |
|
| 165 | - $res2 = []; |
|
| 166 | - foreach ($v as $k => $p) { |
|
| 167 | - if ( |
|
| 168 | - isset($p->type) |
|
| 169 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 170 | - ) { |
|
| 171 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 172 | - $res2[] = [$p->type, $r]; |
|
| 173 | - } else { |
|
| 174 | - spip_log("critere $i / $k mal forme"); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - $args[] = $res2; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - $res .= $f($args); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $res; |
|
| 145 | + $sources = $boucle->param; |
|
| 146 | + if (!is_array($sources)) { |
|
| 147 | + return ''; |
|
| 148 | + } |
|
| 149 | + $res = ''; |
|
| 150 | + $f = 'format_critere_' . $fmt; |
|
| 151 | + foreach ($sources as $crit) { |
|
| 152 | + if (!is_array($crit)) { |
|
| 153 | + continue; |
|
| 154 | + } // boucle recursive |
|
| 155 | + array_shift($crit); |
|
| 156 | + $args = []; |
|
| 157 | + foreach ($crit as $i => $v) { |
|
| 158 | + if ( |
|
| 159 | + (count($v) == 1) |
|
| 160 | + and $v[0]->type == 'texte' |
|
| 161 | + and $v[0]->apres |
|
| 162 | + ) { |
|
| 163 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 164 | + } else { |
|
| 165 | + $res2 = []; |
|
| 166 | + foreach ($v as $k => $p) { |
|
| 167 | + if ( |
|
| 168 | + isset($p->type) |
|
| 169 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 170 | + ) { |
|
| 171 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 172 | + $res2[] = [$p->type, $r]; |
|
| 173 | + } else { |
|
| 174 | + spip_log("critere $i / $k mal forme"); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + $args[] = $res2; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + $res .= $f($args); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $res; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | 187 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 188 | - if (!is_array($liste)) { |
|
| 189 | - return ''; |
|
| 190 | - } |
|
| 191 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 192 | - $contenu = []; |
|
| 193 | - foreach ($liste as $k => $p) { |
|
| 194 | - if (!isset($p->type)) { |
|
| 195 | - continue; |
|
| 196 | - } #?????? |
|
| 197 | - $d = 'decompiler_' . $p->type; |
|
| 198 | - $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 199 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 200 | - // contenait des args et s'il est suivi d'espaces, |
|
| 201 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 202 | - |
|
| 203 | - if ( |
|
| 204 | - $next |
|
| 205 | - and ($next->type == 'texte') |
|
| 206 | - and $p->type == 'champ' |
|
| 207 | - and !$p->apres |
|
| 208 | - and !$p->avant |
|
| 209 | - and $p->fonctions |
|
| 210 | - ) { |
|
| 211 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 212 | - if ($n) { |
|
| 213 | - $champ = new Texte(); |
|
| 214 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 215 | - $champ->ligne = $p->ligne; |
|
| 216 | - $p->apres = [$champ]; |
|
| 217 | - $next->texte = substr($next->texte, $n); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 221 | - } |
|
| 222 | - $f = 'format_suite_' . $fmt; |
|
| 223 | - |
|
| 224 | - return $f($contenu); |
|
| 188 | + if (!is_array($liste)) { |
|
| 189 | + return ''; |
|
| 190 | + } |
|
| 191 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 192 | + $contenu = []; |
|
| 193 | + foreach ($liste as $k => $p) { |
|
| 194 | + if (!isset($p->type)) { |
|
| 195 | + continue; |
|
| 196 | + } #?????? |
|
| 197 | + $d = 'decompiler_' . $p->type; |
|
| 198 | + $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 199 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 200 | + // contenait des args et s'il est suivi d'espaces, |
|
| 201 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 202 | + |
|
| 203 | + if ( |
|
| 204 | + $next |
|
| 205 | + and ($next->type == 'texte') |
|
| 206 | + and $p->type == 'champ' |
|
| 207 | + and !$p->apres |
|
| 208 | + and !$p->avant |
|
| 209 | + and $p->fonctions |
|
| 210 | + ) { |
|
| 211 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 212 | + if ($n) { |
|
| 213 | + $champ = new Texte(); |
|
| 214 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 215 | + $champ->ligne = $p->ligne; |
|
| 216 | + $p->apres = [$champ]; |
|
| 217 | + $next->texte = substr($next->texte, $n); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 221 | + } |
|
| 222 | + $f = 'format_suite_' . $fmt; |
|
| 223 | + |
|
| 224 | + return $f($contenu); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 228 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 229 | - return "'$fmt'?"; |
|
| 230 | - } |
|
| 231 | - $f = 'decompiler_' . $quoi; |
|
| 228 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 229 | + return "'$fmt'?"; |
|
| 230 | + } |
|
| 231 | + $f = 'decompiler_' . $quoi; |
|
| 232 | 232 | |
| 233 | - return $f($liste, $fmt, $prof); |
|
| 233 | + return $f($liste, $fmt, $prof); |
|
| 234 | 234 | } |
@@ -26,11 +26,10 @@ discard block |
||
| 26 | 26 | $postaff = decompiler_($struct->postaff, $fmt, $prof); |
| 27 | 27 | |
| 28 | 28 | $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : $struct->table_optionnelle); |
|
| 31 | 30 | |
| 32 | 31 | if ($struct->jointures_explicites) { |
| 33 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 32 | + $type .= ' '.$struct->jointures_explicites; |
|
| 34 | 33 | } |
| 35 | 34 | if ($struct->table_optionnelle) { |
| 36 | 35 | $type .= '?'; |
@@ -39,11 +38,11 @@ discard block |
||
| 39 | 38 | |
| 40 | 39 | $crit = $struct->param; |
| 41 | 40 | if ($crit and !is_array($crit[0])) { |
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 43 | 42 | } |
| 44 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 45 | 44 | |
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 47 | 46 | |
| 48 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 49 | 48 | } |
@@ -56,21 +55,20 @@ discard block |
||
| 56 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 57 | 56 | } |
| 58 | 57 | } |
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 62 | 60 | |
| 63 | 61 | return $f($file, $res, $prof); |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 68 | 66 | |
| 69 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 74 | 72 | |
| 75 | 73 | return $f($struct->traductions, $prof); |
| 76 | 74 | } |
@@ -83,7 +81,7 @@ discard block |
||
| 83 | 81 | |
| 84 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 85 | 83 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 87 | 85 | |
| 88 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 89 | 87 | } |
@@ -98,7 +96,7 @@ discard block |
||
| 98 | 96 | } |
| 99 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 100 | 98 | } |
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 102 | 100 | |
| 103 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 104 | 102 | } |
@@ -107,7 +105,7 @@ discard block |
||
| 107 | 105 | if (!is_array($sources)) { |
| 108 | 106 | return ''; |
| 109 | 107 | } |
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 111 | 109 | $res = ''; |
| 112 | 110 | foreach ($sources as $arg) { |
| 113 | 111 | if (!is_array($arg)) { |
@@ -124,7 +122,7 @@ discard block |
||
| 124 | 122 | and (strlen($v[0]->apres) == 1) |
| 125 | 123 | and $v[0]->apres == $v[0]->avant |
| 126 | 124 | ) { |
| 127 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 125 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 128 | 126 | } else { |
| 129 | 127 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 130 | 128 | } |
@@ -147,7 +145,7 @@ discard block |
||
| 147 | 145 | return ''; |
| 148 | 146 | } |
| 149 | 147 | $res = ''; |
| 150 | - $f = 'format_critere_' . $fmt; |
|
| 148 | + $f = 'format_critere_'.$fmt; |
|
| 151 | 149 | foreach ($sources as $crit) { |
| 152 | 150 | if (!is_array($crit)) { |
| 153 | 151 | continue; |
@@ -160,13 +158,13 @@ discard block |
||
| 160 | 158 | and $v[0]->type == 'texte' |
| 161 | 159 | and $v[0]->apres |
| 162 | 160 | ) { |
| 163 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 161 | + $args[] = [['texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres)]]; |
|
| 164 | 162 | } else { |
| 165 | 163 | $res2 = []; |
| 166 | 164 | foreach ($v as $k => $p) { |
| 167 | 165 | if ( |
| 168 | 166 | isset($p->type) |
| 169 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 170 | 168 | ) { |
| 171 | 169 | $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
| 172 | 170 | $res2[] = [$p->type, $r]; |
@@ -194,7 +192,7 @@ discard block |
||
| 194 | 192 | if (!isset($p->type)) { |
| 195 | 193 | continue; |
| 196 | 194 | } #?????? |
| 197 | - $d = 'decompiler_' . $p->type; |
|
| 195 | + $d = 'decompiler_'.$p->type; |
|
| 198 | 196 | $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
| 199 | 197 | // Forcer le champ etendu si son source (pas les reecritures) |
| 200 | 198 | // contenait des args et s'il est suivi d'espaces, |
@@ -219,16 +217,16 @@ discard block |
||
| 219 | 217 | } |
| 220 | 218 | $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
| 221 | 219 | } |
| 222 | - $f = 'format_suite_' . $fmt; |
|
| 220 | + $f = 'format_suite_'.$fmt; |
|
| 223 | 221 | |
| 224 | 222 | return $f($contenu); |
| 225 | 223 | } |
| 226 | 224 | |
| 227 | 225 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 228 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 229 | 227 | return "'$fmt'?"; |
| 230 | 228 | } |
| 231 | - $f = 'decompiler_' . $quoi; |
|
| 229 | + $f = 'decompiler_'.$quoi; |
|
| 232 | 230 | |
| 233 | 231 | return $f($liste, $fmt, $prof); |
| 234 | 232 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if ( |
|
| 60 | - !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | - or array_key_exists($champ, $desc['field']) |
|
| 62 | - ) { |
|
| 63 | - return [$champ]; |
|
| 64 | - } |
|
| 65 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | - array_pop($decompose); |
|
| 68 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | - return $decompose; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return [$champ]; |
|
| 59 | + if ( |
|
| 60 | + !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | + or array_key_exists($champ, $desc['field']) |
|
| 62 | + ) { |
|
| 63 | + return [$champ]; |
|
| 64 | + } |
|
| 65 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | + array_pop($decompose); |
|
| 68 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | + return $decompose; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return [$champ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
@@ -100,23 +100,23 @@ discard block |
||
| 100 | 100 | * Alias de la table de jointure (Lx) |
| 101 | 101 | */ |
| 102 | 102 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 103 | - // les jointures minimales sont optimales : |
|
| 104 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | - $max = 1; |
|
| 107 | - $res = false; |
|
| 108 | - $milieu_exclus = ($col ? $col : []); |
|
| 109 | - while ($max <= $max_liens and !$res) { |
|
| 110 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | - $max++; |
|
| 112 | - } |
|
| 113 | - if (!$res) { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - list($nom, $desc) = $depart; |
|
| 118 | - |
|
| 119 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 103 | + // les jointures minimales sont optimales : |
|
| 104 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | + $max = 1; |
|
| 107 | + $res = false; |
|
| 108 | + $milieu_exclus = ($col ? $col : []); |
|
| 109 | + while ($max <= $max_liens and !$res) { |
|
| 110 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | + $max++; |
|
| 112 | + } |
|
| 113 | + if (!$res) { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + list($nom, $desc) = $depart; |
|
| 118 | + |
|
| 119 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -155,79 +155,79 @@ discard block |
||
| 155 | 155 | * Alias de la table de jointure (Lx) |
| 156 | 156 | */ |
| 157 | 157 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 158 | - static $num = []; |
|
| 159 | - $id_table = ''; |
|
| 160 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 161 | - foreach ($res as $cle => $r) { |
|
| 162 | - list($d, $a, $j) = $r; |
|
| 163 | - if (!$id_table) { |
|
| 164 | - $id_table = $d; |
|
| 165 | - } |
|
| 166 | - $n = ++$cpt; |
|
| 167 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 168 | - list($j1, $j2, $obj, $type) = $j; |
|
| 169 | - // trouver de quel cote est (id_objet,objet) |
|
| 170 | - if ($j1 == "id_$obj") { |
|
| 171 | - $obj = "$id_table.$obj"; |
|
| 172 | - } else { |
|
| 173 | - $obj = "L$n.$obj"; |
|
| 174 | - } |
|
| 175 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | - $boucle->where["JOIN-L$n"] = |
|
| 179 | - $echap ? |
|
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | - : |
|
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 183 | - $boucle->join["L$n"] = |
|
| 184 | - $echap ? |
|
| 185 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | - : |
|
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | - } else { |
|
| 189 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | - } |
|
| 191 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - // pas besoin de group by |
|
| 196 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | - // si une seule jointure et sur une table avec primary key formee |
|
| 198 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | - |
|
| 201 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // pas de group by |
|
| 206 | - // si une seule jointure |
|
| 207 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | - if ( |
|
| 209 | - !$pk |
|
| 210 | - and (count($boucle->from) == 2) |
|
| 211 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 213 | - ) { |
|
| 214 | - $pk = true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | - if (!$pk) { |
|
| 220 | - foreach ($groups as $id_prim) { |
|
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 222 | - if (!in_array($id_field, $boucle->group)) { |
|
| 223 | - $boucle->group[] = $id_field; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $boucle->modificateur['lien'] = true; |
|
| 229 | - |
|
| 230 | - return "L$n"; |
|
| 158 | + static $num = []; |
|
| 159 | + $id_table = ''; |
|
| 160 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 161 | + foreach ($res as $cle => $r) { |
|
| 162 | + list($d, $a, $j) = $r; |
|
| 163 | + if (!$id_table) { |
|
| 164 | + $id_table = $d; |
|
| 165 | + } |
|
| 166 | + $n = ++$cpt; |
|
| 167 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 168 | + list($j1, $j2, $obj, $type) = $j; |
|
| 169 | + // trouver de quel cote est (id_objet,objet) |
|
| 170 | + if ($j1 == "id_$obj") { |
|
| 171 | + $obj = "$id_table.$obj"; |
|
| 172 | + } else { |
|
| 173 | + $obj = "L$n.$obj"; |
|
| 174 | + } |
|
| 175 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | + $boucle->where["JOIN-L$n"] = |
|
| 179 | + $echap ? |
|
| 180 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | + : |
|
| 182 | + ['=',"$obj",sql_quote($type)]; |
|
| 183 | + $boucle->join["L$n"] = |
|
| 184 | + $echap ? |
|
| 185 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | + : |
|
| 187 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | + } else { |
|
| 189 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | + } |
|
| 191 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + // pas besoin de group by |
|
| 196 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | + // si une seule jointure et sur une table avec primary key formee |
|
| 198 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | + |
|
| 201 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // pas de group by |
|
| 206 | + // si une seule jointure |
|
| 207 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | + if ( |
|
| 209 | + !$pk |
|
| 210 | + and (count($boucle->from) == 2) |
|
| 211 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 213 | + ) { |
|
| 214 | + $pk = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | + if (!$pk) { |
|
| 220 | + foreach ($groups as $id_prim) { |
|
| 221 | + $id_field = $nom . '.' . $id_prim; |
|
| 222 | + if (!in_array($id_field, $boucle->group)) { |
|
| 223 | + $boucle->group[] = $id_field; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $boucle->modificateur['lien'] = true; |
|
| 229 | + |
|
| 230 | + return "L$n"; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,16 +242,16 @@ discard block |
||
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | 244 | function nogroupby_if($depart, $arrivee, $col) { |
| 245 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 246 | - if (!$pk) { |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 250 | - if (is_array($col)) { |
|
| 251 | - $col = implode(', *', $col); |
|
| 252 | - } // cas id_objet, objet |
|
| 253 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 254 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 245 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 246 | + if (!$pk) { |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 250 | + if (is_array($col)) { |
|
| 251 | + $col = implode(', *', $col); |
|
| 252 | + } // cas id_objet, objet |
|
| 253 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 254 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -269,46 +269,46 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 271 | 271 | |
| 272 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 272 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 273 | 273 | |
| 274 | - // si cle primaire demandee, la privilegier |
|
| 275 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 276 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 277 | - } |
|
| 274 | + // si cle primaire demandee, la privilegier |
|
| 275 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 276 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // les champs declares explicitement pour les jointures |
|
| 280 | - if (isset($desc['join'])) { |
|
| 281 | - return $desc['join']; |
|
| 282 | - } |
|
| 283 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 279 | + // les champs declares explicitement pour les jointures |
|
| 280 | + if (isset($desc['join'])) { |
|
| 281 | + return $desc['join']; |
|
| 282 | + } |
|
| 283 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 284 | 284 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 285 | 285 | |
| 286 | - // si pas de cle, c'est fichu |
|
| 287 | - if (!isset($desc['key'])) { |
|
| 288 | - return []; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // si cle primaire |
|
| 292 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 293 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // ici on se rabat sur les cles secondaires, |
|
| 297 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 298 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 299 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 300 | - |
|
| 301 | - $join = []; |
|
| 302 | - foreach ($desc['key'] as $v) { |
|
| 303 | - $join = split_key($v, $join); |
|
| 304 | - } |
|
| 305 | - foreach ($join as $k) { |
|
| 306 | - if (in_array($k, $nojoin)) { |
|
| 307 | - unset($join[$k]); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return $join; |
|
| 286 | + // si pas de cle, c'est fichu |
|
| 287 | + if (!isset($desc['key'])) { |
|
| 288 | + return []; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // si cle primaire |
|
| 292 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 293 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // ici on se rabat sur les cles secondaires, |
|
| 297 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 298 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 299 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 300 | + |
|
| 301 | + $join = []; |
|
| 302 | + foreach ($desc['key'] as $v) { |
|
| 303 | + $join = split_key($v, $join); |
|
| 304 | + } |
|
| 305 | + foreach ($join as $k) { |
|
| 306 | + if (in_array($k, $nojoin)) { |
|
| 307 | + unset($join[$k]); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return $join; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -319,14 +319,14 @@ discard block |
||
| 319 | 319 | * @return array |
| 320 | 320 | */ |
| 321 | 321 | function split_key($v, $join = []) { |
| 322 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 323 | - if (strpos($k, '(') !== false) { |
|
| 324 | - $k = explode('(', $k); |
|
| 325 | - $k = trim(reset($k)); |
|
| 326 | - } |
|
| 327 | - $join[$k] = $k; |
|
| 328 | - } |
|
| 329 | - return $join; |
|
| 322 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 323 | + if (strpos($k, '(') !== false) { |
|
| 324 | + $k = explode('(', $k); |
|
| 325 | + $k = trim(reset($k)); |
|
| 326 | + } |
|
| 327 | + $join[$k] = $k; |
|
| 328 | + } |
|
| 329 | + return $join; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -349,135 +349,135 @@ discard block |
||
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | 351 | function calculer_chaine_jointures( |
| 352 | - &$boucle, |
|
| 353 | - $depart, |
|
| 354 | - $arrivee, |
|
| 355 | - $vu = [], |
|
| 356 | - $milieu_exclus = [], |
|
| 357 | - $max_liens = 5 |
|
| 352 | + &$boucle, |
|
| 353 | + $depart, |
|
| 354 | + $arrivee, |
|
| 355 | + $vu = [], |
|
| 356 | + $milieu_exclus = [], |
|
| 357 | + $max_liens = 5 |
|
| 358 | 358 | ) { |
| 359 | - static $trouver_table; |
|
| 360 | - if (!$trouver_table) { |
|
| 361 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (is_string($milieu_exclus)) { |
|
| 365 | - $milieu_exclus = [$milieu_exclus]; |
|
| 366 | - } |
|
| 367 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 368 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 369 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 370 | - $milieu_exclus[] = 'objet'; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - list($dnom, $ddesc) = $depart; |
|
| 374 | - list($anom, $adesc) = $arrivee; |
|
| 375 | - if (!count($vu)) { |
|
| 376 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 377 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $akeys = []; |
|
| 381 | - foreach ($adesc['key'] as $k) { |
|
| 382 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 383 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 387 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 388 | - |
|
| 389 | - // cles candidates au depart |
|
| 390 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 391 | - // enlever les cles dde depart exclues par l'appel |
|
| 392 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 393 | - |
|
| 394 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 395 | - |
|
| 396 | - if ($v) { |
|
| 397 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 401 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 402 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 403 | - // id_objet,objet |
|
| 404 | - // si oui on la prend |
|
| 405 | - foreach ($akeys as $key) { |
|
| 406 | - $v = decompose_champ_id_objet($key); |
|
| 407 | - if (is_array($v)) { |
|
| 408 | - $objet = array_shift($v); // objet,'article' |
|
| 409 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 410 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 411 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 416 | - // id_objet,objet a l'arrivee |
|
| 417 | - // si oui on la prend |
|
| 418 | - foreach ($keys as $key) { |
|
| 419 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 420 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 421 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 422 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 423 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 429 | - if ($max_liens <= 1) { |
|
| 430 | - return []; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // sinon essayer de passer par une autre table |
|
| 434 | - $new = $vu; |
|
| 435 | - foreach ($boucle->jointures as $v) { |
|
| 436 | - if ( |
|
| 437 | - $v |
|
| 438 | - and !in_array($v, $vu) |
|
| 439 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 440 | - and !in_array($def['table_sql'], $vu) |
|
| 441 | - ) { |
|
| 442 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 443 | - // ie la cle de la jointure precedente |
|
| 444 | - $test_cles = $milieu_exclus; |
|
| 445 | - $new[] = $v; |
|
| 446 | - $max_iter = 50; // securite |
|
| 447 | - while ( |
|
| 448 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 449 | - $boucle, |
|
| 450 | - $depart, |
|
| 451 | - [$v, $def], |
|
| 452 | - $vu, |
|
| 453 | - $test_cles, |
|
| 454 | - 1 |
|
| 455 | - )) |
|
| 456 | - and $max_iter-- |
|
| 457 | - ) { |
|
| 458 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 459 | - $milieu = end($jointure_directe_possible); |
|
| 460 | - $exclure_fin = $milieu_exclus; |
|
| 461 | - if (is_string($milieu)) { |
|
| 462 | - $exclure_fin[] = $milieu; |
|
| 463 | - $test_cles[] = $milieu; |
|
| 464 | - } else { |
|
| 465 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 466 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 467 | - } |
|
| 468 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 469 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 470 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 471 | - if ($r) { |
|
| 472 | - array_unshift($r, $jointure_directe_possible); |
|
| 473 | - |
|
| 474 | - return $r; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - return []; |
|
| 359 | + static $trouver_table; |
|
| 360 | + if (!$trouver_table) { |
|
| 361 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (is_string($milieu_exclus)) { |
|
| 365 | + $milieu_exclus = [$milieu_exclus]; |
|
| 366 | + } |
|
| 367 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 368 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 369 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 370 | + $milieu_exclus[] = 'objet'; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + list($dnom, $ddesc) = $depart; |
|
| 374 | + list($anom, $adesc) = $arrivee; |
|
| 375 | + if (!count($vu)) { |
|
| 376 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 377 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $akeys = []; |
|
| 381 | + foreach ($adesc['key'] as $k) { |
|
| 382 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 383 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 387 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 388 | + |
|
| 389 | + // cles candidates au depart |
|
| 390 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 391 | + // enlever les cles dde depart exclues par l'appel |
|
| 392 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 393 | + |
|
| 394 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 395 | + |
|
| 396 | + if ($v) { |
|
| 397 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 401 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 402 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 403 | + // id_objet,objet |
|
| 404 | + // si oui on la prend |
|
| 405 | + foreach ($akeys as $key) { |
|
| 406 | + $v = decompose_champ_id_objet($key); |
|
| 407 | + if (is_array($v)) { |
|
| 408 | + $objet = array_shift($v); // objet,'article' |
|
| 409 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 410 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 411 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 416 | + // id_objet,objet a l'arrivee |
|
| 417 | + // si oui on la prend |
|
| 418 | + foreach ($keys as $key) { |
|
| 419 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 420 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 421 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 422 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 423 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 429 | + if ($max_liens <= 1) { |
|
| 430 | + return []; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // sinon essayer de passer par une autre table |
|
| 434 | + $new = $vu; |
|
| 435 | + foreach ($boucle->jointures as $v) { |
|
| 436 | + if ( |
|
| 437 | + $v |
|
| 438 | + and !in_array($v, $vu) |
|
| 439 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 440 | + and !in_array($def['table_sql'], $vu) |
|
| 441 | + ) { |
|
| 442 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 443 | + // ie la cle de la jointure precedente |
|
| 444 | + $test_cles = $milieu_exclus; |
|
| 445 | + $new[] = $v; |
|
| 446 | + $max_iter = 50; // securite |
|
| 447 | + while ( |
|
| 448 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 449 | + $boucle, |
|
| 450 | + $depart, |
|
| 451 | + [$v, $def], |
|
| 452 | + $vu, |
|
| 453 | + $test_cles, |
|
| 454 | + 1 |
|
| 455 | + )) |
|
| 456 | + and $max_iter-- |
|
| 457 | + ) { |
|
| 458 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 459 | + $milieu = end($jointure_directe_possible); |
|
| 460 | + $exclure_fin = $milieu_exclus; |
|
| 461 | + if (is_string($milieu)) { |
|
| 462 | + $exclure_fin[] = $milieu; |
|
| 463 | + $test_cles[] = $milieu; |
|
| 464 | + } else { |
|
| 465 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 466 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 467 | + } |
|
| 468 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 469 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 470 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 471 | + if ($r) { |
|
| 472 | + array_unshift($r, $jointure_directe_possible); |
|
| 473 | + |
|
| 474 | + return $r; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + return []; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -488,18 +488,18 @@ discard block |
||
| 488 | 488 | * @return array |
| 489 | 489 | */ |
| 490 | 490 | function trouver_cles_table($keys) { |
| 491 | - $res = []; |
|
| 492 | - foreach ($keys as $v) { |
|
| 493 | - if (!strpos($v, ',')) { |
|
| 494 | - $res[$v] = 1; |
|
| 495 | - } else { |
|
| 496 | - foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 497 | - $res[$k] = 1; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return array_keys($res); |
|
| 491 | + $res = []; |
|
| 492 | + foreach ($keys as $v) { |
|
| 493 | + if (!strpos($v, ',')) { |
|
| 494 | + $res[$v] = 1; |
|
| 495 | + } else { |
|
| 496 | + foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 497 | + $res[$k] = 1; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return array_keys($res); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | |
@@ -526,34 +526,34 @@ discard block |
||
| 526 | 526 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 527 | 527 | */ |
| 528 | 528 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 529 | - static $trouver_table = ''; |
|
| 530 | - if (!$trouver_table) { |
|
| 531 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - if (!is_array($cle)) { |
|
| 535 | - $cle = [$cle]; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - foreach ($tables as $k => $table) { |
|
| 539 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 540 | - if ( |
|
| 541 | - isset($desc['field']) |
|
| 542 | - // verifier que toutes les cles cherchees sont la |
|
| 543 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 544 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 545 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 546 | - ) { |
|
| 547 | - return [ |
|
| 548 | - 'desc' => $desc, |
|
| 549 | - 'table' => $desc['table'], |
|
| 550 | - 'alias' => $k, |
|
| 551 | - ]; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - return false; |
|
| 529 | + static $trouver_table = ''; |
|
| 530 | + if (!$trouver_table) { |
|
| 531 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + if (!is_array($cle)) { |
|
| 535 | + $cle = [$cle]; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + foreach ($tables as $k => $table) { |
|
| 539 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 540 | + if ( |
|
| 541 | + isset($desc['field']) |
|
| 542 | + // verifier que toutes les cles cherchees sont la |
|
| 543 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 544 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 545 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 546 | + ) { |
|
| 547 | + return [ |
|
| 548 | + 'desc' => $desc, |
|
| 549 | + 'table' => $desc['table'], |
|
| 550 | + 'alias' => $k, |
|
| 551 | + ]; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return false; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -579,52 +579,52 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 581 | 581 | |
| 582 | - // support de la recherche multi champ : |
|
| 583 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 584 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 585 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 586 | - if (!is_array($cle)) { |
|
| 587 | - $cle = [$cle]; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 591 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - // au premier coup, on essaye de decomposer, si possible |
|
| 595 | - if ( |
|
| 596 | - count($cle) == 1 |
|
| 597 | - and $c = reset($cle) |
|
| 598 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 599 | - ) { |
|
| 600 | - $desc = $boucle->show; |
|
| 601 | - |
|
| 602 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 603 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 604 | - if (isset($desc['field'][$c])) { |
|
| 605 | - $cle = []; |
|
| 606 | - $cle[] = array_shift($decompose); // id_objet |
|
| 607 | - $cle[] = array_shift($decompose); // objet |
|
| 608 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 609 | - } |
|
| 610 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 611 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 612 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 613 | - else { |
|
| 614 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 615 | - foreach ($depart as $d) { |
|
| 616 | - $cle = []; |
|
| 617 | - $cle[] = array_shift($decompose); // id_objet |
|
| 618 | - $cle[] = array_shift($decompose); // objet |
|
| 619 | - $cle[] = $d; |
|
| 620 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 621 | - return $ext; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - return ''; |
|
| 582 | + // support de la recherche multi champ : |
|
| 583 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 584 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 585 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 586 | + if (!is_array($cle)) { |
|
| 587 | + $cle = [$cle]; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 591 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + // au premier coup, on essaye de decomposer, si possible |
|
| 595 | + if ( |
|
| 596 | + count($cle) == 1 |
|
| 597 | + and $c = reset($cle) |
|
| 598 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 599 | + ) { |
|
| 600 | + $desc = $boucle->show; |
|
| 601 | + |
|
| 602 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 603 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 604 | + if (isset($desc['field'][$c])) { |
|
| 605 | + $cle = []; |
|
| 606 | + $cle[] = array_shift($decompose); // id_objet |
|
| 607 | + $cle[] = array_shift($decompose); // objet |
|
| 608 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 609 | + } |
|
| 610 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 611 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 612 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 613 | + else { |
|
| 614 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 615 | + foreach ($depart as $d) { |
|
| 616 | + $cle = []; |
|
| 617 | + $cle[] = array_shift($decompose); // id_objet |
|
| 618 | + $cle[] = array_shift($decompose); // objet |
|
| 619 | + $cle[] = $d; |
|
| 620 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 621 | + return $ext; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + return ''; |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -656,21 +656,21 @@ discard block |
||
| 656 | 656 | * @return string |
| 657 | 657 | */ |
| 658 | 658 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 659 | - if ($jointures === false) { |
|
| 660 | - $jointures = $boucle->jointures; |
|
| 661 | - } |
|
| 662 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 663 | - // mais pas poour construire la jointure ensuite |
|
| 664 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 665 | - if ($arrivee) { |
|
| 666 | - $desc = $boucle->show; |
|
| 667 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 668 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 669 | - if ($cle) { |
|
| 670 | - return $cle; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 674 | - |
|
| 675 | - return ''; |
|
| 659 | + if ($jointures === false) { |
|
| 660 | + $jointures = $boucle->jointures; |
|
| 661 | + } |
|
| 662 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 663 | + // mais pas poour construire la jointure ensuite |
|
| 664 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 665 | + if ($arrivee) { |
|
| 666 | + $desc = $boucle->show; |
|
| 667 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 668 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 669 | + if ($cle) { |
|
| 670 | + return $cle; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 674 | + |
|
| 675 | + return ''; |
|
| 676 | 676 | } |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | // sache qu'il peut enlever ce where si il enleve la jointure |
| 178 | 178 | $boucle->where["JOIN-L$n"] = |
| 179 | 179 | $echap ? |
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 180 | + ["'='", "'$obj'", "sql_quote('$type')"] |
|
| 181 | 181 | : |
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 182 | + ['=', "$obj", sql_quote($type)]; |
|
| 183 | 183 | $boucle->join["L$n"] = |
| 184 | 184 | $echap ? |
| 185 | 185 | ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
| 186 | 186 | : |
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 187 | + [$id_table, $j2, $j1, "$obj=".sql_quote($type)]; |
|
| 188 | 188 | } else { |
| 189 | 189 | $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
| 190 | 190 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $groups = liste_champs_jointures($nom, $desc, true); |
| 219 | 219 | if (!$pk) { |
| 220 | 220 | foreach ($groups as $id_prim) { |
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 221 | + $id_field = $nom.'.'.$id_prim; |
|
| 222 | 222 | if (!in_array($id_field, $boucle->group)) { |
| 223 | 223 | $boucle->group[] = $id_field; |
| 224 | 224 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | if (!$fonc) { |
| 149 | 149 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 150 | 150 | } |
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' '.$GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | 152 | } |
| 153 | 153 | if ($message === false) { |
| 154 | 154 | lang_select(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
| 178 | 178 | // une erreur critique sort $message en array |
| 179 | 179 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | + spip_log('Debug: '.$debug.' ('.$fond.')'); |
|
| 181 | 181 | |
| 182 | 182 | return $msg; |
| 183 | 183 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | 187 | if (!empty($erreurs)) { |
| 188 | - $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 188 | + $n = [count($erreurs).' '._T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | 190 | return debusquer_navigation($erreurs, $n); |
| 191 | 191 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -218,25 +218,25 @@ discard block |
||
| 218 | 218 | $valeur_simple = []; |
| 219 | 219 | foreach ($valeur as $v) { |
| 220 | 220 | if (is_array($v)) { |
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 221 | + $valeur_simple[] = 'array:'.count($v); |
|
| 222 | 222 | } elseif (is_object($v)) { |
| 223 | 223 | $valeur_simple[] = get_class($v); |
| 224 | 224 | } elseif (is_string($v)) { |
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | + $valeur_simple[] = "'".$v."'"; |
|
| 226 | 226 | } else { |
| 227 | 227 | $valeur_simple[] = $v; |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | $n = count($valeur); |
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 231 | + $valeur = (($n > 3) ? 'array:'.$n.' ' : ''); |
|
| 232 | + $valeur .= '['.join(', ', $valeur_simple).']'; |
|
| 233 | 233 | } elseif (is_object($valeur)) { |
| 234 | 234 | $valeur = get_class($valeur); |
| 235 | 235 | } elseif (is_string($valeur)) { |
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 236 | + $valeur = "'".$valeur."'"; |
|
| 237 | 237 | } |
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 238 | + $res .= "\n<tr><td><strong>".nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: '.nl2br(entites_html($valeur)) |
|
| 240 | 240 | . "</td></tr>\n"; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | $nom_code = $lieu->descr['nom']; |
| 265 | 265 | $skel = $lieu->descr['sourcefile']; |
| 266 | 266 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 268 | 268 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 269 | 269 | if ($boucle) { |
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 270 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | 271 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Requete erronee |
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 359 | + $err = '<b>'._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 360 | 360 | . spip_htmlspecialchars($msg) |
| 361 | 361 | . "\n<br /><span style='color: red'><b>" |
| 362 | 362 | . spip_htmlspecialchars($query) |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 374 | + $id = $nom.$boucle; |
|
| 375 | 375 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 376 | 376 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 377 | 377 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 421 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 422 | 422 | |
| 423 | 423 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 424 | 424 | if (preg_match($incl, $v)) { |
@@ -434,16 +434,13 @@ discard block |
||
| 434 | 434 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 435 | 435 | |
| 436 | 436 | if (!$boucle) { |
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 437 | + return !$ligne ? '' : (' ('. |
|
| 438 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 441 | 439 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 442 | 440 | } else { |
| 443 | 441 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 444 | 442 | |
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 443 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | 444 | } |
| 448 | 445 | } |
| 449 | 446 | |
@@ -466,14 +463,14 @@ discard block |
||
| 466 | 463 | |
| 467 | 464 | $s = preg_replace( |
| 468 | 465 | ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 466 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 470 | 467 | $s |
| 471 | 468 | ); |
| 472 | 469 | |
| 473 | 470 | |
| 474 | 471 | $tableau = explode('<br />', $s); |
| 475 | 472 | |
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 473 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: ".($nocpt ? 'hidden' : 'visible').";%s' href='#T%s' title=\"%s\">%0".strval(@strlen(count($tableau)))."d</a></span> %s<br />\n"; |
|
| 477 | 474 | |
| 478 | 475 | $format10 = str_replace('white', 'lightgrey', $format); |
| 479 | 476 | $formaterr = 'color: red;'; |
@@ -517,7 +514,7 @@ discard block |
||
| 517 | 514 | . '" style="cursor: pointer;">' |
| 518 | 515 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 519 | 516 | . '</div> |
| 520 | - ' . $res . "</div>\n"; |
|
| 517 | + ' . $res."</div>\n"; |
|
| 521 | 518 | } |
| 522 | 519 | |
| 523 | 520 | // l'environnement graphique du debuggueur |
@@ -538,14 +535,14 @@ discard block |
||
| 538 | 535 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 539 | 536 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 540 | 537 | $texte .= $res2; |
| 541 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | - $legend = _T('zbug_' . $mode); |
|
| 543 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 538 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 539 | + $legend = _T('zbug_'.$mode); |
|
| 540 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 544 | 541 | $texte = ancre_texte($texte, ['', '']); |
| 545 | 542 | } |
| 546 | 543 | } else { |
| 547 | 544 | if (strlen(trim($res))) { |
| 548 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 545 | + return "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | 546 | } else { |
| 550 | 547 | // cas de l'appel sur erreur: montre la page |
| 551 | 548 | return isset($GLOBALS['debug_objets']['resultat']['tout']) |
@@ -555,7 +552,7 @@ discard block |
||
| 555 | 552 | } |
| 556 | 553 | } else { |
| 557 | 554 | $valider = charger_fonction('valider', 'xml'); |
| 558 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 555 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 559 | 556 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 560 | 557 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 561 | 558 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
@@ -566,14 +563,14 @@ discard block |
||
| 566 | 563 | } else { |
| 567 | 564 | $err = ": $err"; |
| 568 | 565 | } |
| 569 | - $legend = _T('validation') . ' ' . $err; |
|
| 566 | + $legend = _T('validation').' '.$err; |
|
| 570 | 567 | $res = $id = ''; |
| 571 | 568 | } |
| 572 | 569 | |
| 573 | 570 | return !trim($texte) ? '' : ( |
| 574 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 571 | + "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | 572 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 576 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 573 | + . "<a href='".$self.'#f_'.substr($fonc, 0, 37)."'> ↑ " |
|
| 577 | 574 | . ($legend ? $legend : $mode) |
| 578 | 575 | . '</a></legend>' |
| 579 | 576 | . $texte |
@@ -585,7 +582,7 @@ discard block |
||
| 585 | 582 | // https://code.spip.net/@emboite_texte |
| 586 | 583 | function emboite_texte($res, $fonc = '', $self = '') { |
| 587 | 584 | $errs = $res->err; |
| 588 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 585 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 589 | 586 | |
| 590 | 587 | if (!$texte and !$errs) { |
| 591 | 588 | return [ancre_texte('', ['', '']), false]; |
@@ -641,7 +638,7 @@ discard block |
||
| 641 | 638 | $err = "<h2 style='text-align: center'>" |
| 642 | 639 | . $i |
| 643 | 640 | . "<a href='#fin_err'>" |
| 644 | - . ' ' . _T('erreur_texte') |
|
| 641 | + . ' '._T('erreur_texte') |
|
| 645 | 642 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 646 | 643 | . $err |
| 647 | 644 | . " </table><a id='fin_err'></a>"; |
@@ -651,9 +648,9 @@ discard block |
||
| 651 | 648 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 652 | 649 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 653 | 650 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 651 | + $err = $msg. |
|
| 652 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 653 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 657 | 654 | |
| 658 | 655 | return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
| 659 | 656 | } |
@@ -687,7 +684,7 @@ discard block |
||
| 687 | 684 | ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
| 688 | 685 | ); |
| 689 | 686 | |
| 690 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 687 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 691 | 688 | . $t_skel |
| 692 | 689 | . ' ' |
| 693 | 690 | . $sourcefile |
@@ -702,7 +699,7 @@ discard block |
||
| 702 | 699 | . "'>" |
| 703 | 700 | . _T('zbug_calcul') |
| 704 | 701 | . '</a></legend>' |
| 705 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 702 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 706 | 703 | . debusquer_contexte($contexte[$sourcefile]) |
| 707 | 704 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 708 | 705 | . "</fieldset>\n"; |
@@ -723,33 +720,33 @@ discard block |
||
| 723 | 720 | $nom = $boucle->id_boucle; |
| 724 | 721 | $req = $boucle->type_requete; |
| 725 | 722 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 726 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | - |
|
| 728 | - $res .= "\n<tr style='background-color: " . |
|
| 729 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | - "'><td align='right'>$i</td><td>\n" . |
|
| 731 | - "<a class='debug_link_boucle' href='" . |
|
| 732 | - $self2 . |
|
| 733 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | - _T('zbug_boucle') . |
|
| 735 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | - $self2 . |
|
| 737 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | - _T('zbug_resultat') . |
|
| 739 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | - $self2 . |
|
| 741 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | - _T('zbug_code') . |
|
| 743 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | - "'>" . |
|
| 746 | - _T('zbug_calcul') . |
|
| 747 | - "</a></td><td>\n" . |
|
| 748 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - $req . |
|
| 751 | - "</td><td>\n" . |
|
| 752 | - spip_htmlspecialchars($crit) . |
|
| 723 | + $self2 = $self.'&var_mode_objet='.$objet; |
|
| 724 | + |
|
| 725 | + $res .= "\n<tr style='background-color: ". |
|
| 726 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 727 | + "'><td align='right'>$i</td><td>\n". |
|
| 728 | + "<a class='debug_link_boucle' href='". |
|
| 729 | + $self2. |
|
| 730 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 731 | + _T('zbug_boucle'). |
|
| 732 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 733 | + $self2. |
|
| 734 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 735 | + _T('zbug_resultat'). |
|
| 736 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 737 | + $self2. |
|
| 738 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 739 | + _T('zbug_code'). |
|
| 740 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 741 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 742 | + "'>". |
|
| 743 | + _T('zbug_calcul'). |
|
| 744 | + "</a></td><td>\n". |
|
| 745 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 746 | + "</td><td>\n". |
|
| 747 | + $req. |
|
| 748 | + "</td><td>\n". |
|
| 749 | + spip_htmlspecialchars($crit). |
|
| 753 | 750 | '</td></tr>'; |
| 754 | 751 | } |
| 755 | 752 | } |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | } |
| 777 | 774 | // permettre le copier/coller facile |
| 778 | 775 | // $res = ancre_texte($req, array(), true); |
| 779 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 776 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 780 | 777 | // formatage et affichage des resultats bruts de la requete |
| 781 | 778 | $ress_req = spip_query($req); |
| 782 | 779 | $brut_sql = ''; |
@@ -786,10 +783,10 @@ discard block |
||
| 786 | 783 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 787 | 784 | while ($retours_sql = sql_fetch($ress_req)) { |
| 788 | 785 | if ($num <= $max_aff) { |
| 789 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 786 | + $brut_sql .= '<h3>'.($num == 1 ? $num.' sur '.sql_count($ress_req) : $num).'</h3>'; |
|
| 790 | 787 | $brut_sql .= '<p>'; |
| 791 | 788 | foreach ($retours_sql as $key => $val) { |
| 792 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 789 | + $brut_sql .= '<strong>'.$key.'</strong> => '.spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 793 | 790 | } |
| 794 | 791 | $brut_sql .= '</p>'; |
| 795 | 792 | } |
@@ -800,14 +797,14 @@ discard block |
||
| 800 | 797 | // ne pas afficher les $contexte_inclus |
| 801 | 798 | $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
| 802 | 799 | if ($view) { |
| 803 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 800 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view).'</fieldset>'; |
|
| 804 | 801 | } |
| 805 | 802 | } |
| 806 | 803 | } elseif ($affiche == 'code') { |
| 807 | 804 | $legend = $nom; |
| 808 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 805 | + $res = ancre_texte('<'."?php\n".$quoi."\n?".'>'); |
|
| 809 | 806 | } elseif ($affiche == 'boucle') { |
| 810 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 807 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 811 | 808 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 812 | 809 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 813 | 810 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -826,23 +823,23 @@ discard block |
||
| 826 | 823 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 827 | 824 | include_spip('inc/texte'); // pour corriger_typo |
| 828 | 825 | |
| 829 | - return _DOCTYPE_ECRIRE . |
|
| 830 | - html_lang_attributes() . |
|
| 831 | - "<head>\n<title>" . |
|
| 832 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | - ")</title>\n" . |
|
| 836 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | - "' />\n" . |
|
| 826 | + return _DOCTYPE_ECRIRE. |
|
| 827 | + html_lang_attributes(). |
|
| 828 | + "<head>\n<title>". |
|
| 829 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 830 | + _T('admin_debug').' '.$titre.' ('. |
|
| 831 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 832 | + ")</title>\n". |
|
| 833 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 834 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 835 | + "' />\n". |
|
| 839 | 836 | http_script('', 'jquery.js') |
| 840 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | - . "' type='text/css' />" . |
|
| 842 | - "</head>\n" . |
|
| 843 | - "<body style='margin:0 10px;'>\n" . |
|
| 844 | - "<div id='spip-debug-header'>" . |
|
| 845 | - $corps . |
|
| 846 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 837 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 838 | + . "' type='text/css' />". |
|
| 839 | + "</head>\n". |
|
| 840 | + "<body style='margin:0 10px;'>\n". |
|
| 841 | + "<div id='spip-debug-header'>". |
|
| 842 | + $corps. |
|
| 843 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 847 | 844 | '</div></body></html>'; |
| 848 | 845 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,136 +66,136 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 69 | - static $tableau_des_erreurs = []; |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = []; |
|
| 78 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if ( |
|
| 119 | - ob_get_length() |
|
| 120 | - and |
|
| 121 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | - ) { |
|
| 123 | - ob_end_clean(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | - $fonc = _request('var_mode_objet'); |
|
| 128 | - $mode = _request('var_mode_affiche'); |
|
| 129 | - $self = str_replace("\\'", ''', self()); |
|
| 130 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | - |
|
| 132 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | - . '<br />' |
|
| 134 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | - |
|
| 136 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | - return $res; |
|
| 138 | - } |
|
| 139 | - if ($tableau_des_erreurs) { |
|
| 140 | - http_response_code(503); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - http_no_cache(); |
|
| 144 | - if (isset($_GET['var_profile'])) { |
|
| 145 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | - } else { |
|
| 148 | - if (!$fonc) { |
|
| 149 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | - } |
|
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | - } |
|
| 153 | - if ($message === false) { |
|
| 154 | - lang_select(); |
|
| 155 | - |
|
| 156 | - return debusquer_entete($titre, $res); |
|
| 157 | - } else { |
|
| 158 | - echo debusquer_entete($titre, $res); |
|
| 159 | - } |
|
| 160 | - exit; |
|
| 69 | + static $tableau_des_erreurs = []; |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = []; |
|
| 78 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if ( |
|
| 119 | + ob_get_length() |
|
| 120 | + and |
|
| 121 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | + ) { |
|
| 123 | + ob_end_clean(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | + $fonc = _request('var_mode_objet'); |
|
| 128 | + $mode = _request('var_mode_affiche'); |
|
| 129 | + $self = str_replace("\\'", ''', self()); |
|
| 130 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | + |
|
| 132 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | + . '<br />' |
|
| 134 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | + |
|
| 136 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | + return $res; |
|
| 138 | + } |
|
| 139 | + if ($tableau_des_erreurs) { |
|
| 140 | + http_response_code(503); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + http_no_cache(); |
|
| 144 | + if (isset($_GET['var_profile'])) { |
|
| 145 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | + } else { |
|
| 148 | + if (!$fonc) { |
|
| 149 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | + } |
|
| 151 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | + } |
|
| 153 | + if ($message === false) { |
|
| 154 | + lang_select(); |
|
| 155 | + |
|
| 156 | + return debusquer_entete($titre, $res); |
|
| 157 | + } else { |
|
| 158 | + echo debusquer_entete($titre, $res); |
|
| 159 | + } |
|
| 160 | + exit; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debusquer_compose_message($msg) { |
| 164 | - if (is_array($msg)) { |
|
| 165 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | - // message avec argument: instancier |
|
| 169 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | - } else { |
|
| 171 | - // message SQL: interpreter |
|
| 172 | - $msg = debusquer_requete($msg); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | - // une erreur critique sort $message en array |
|
| 179 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | - |
|
| 182 | - return $msg; |
|
| 164 | + if (is_array($msg)) { |
|
| 165 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | + // message avec argument: instancier |
|
| 169 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | + } else { |
|
| 171 | + // message SQL: interpreter |
|
| 172 | + $msg = debusquer_requete($msg); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | + // une erreur critique sort $message en array |
|
| 179 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | + |
|
| 182 | + return $msg; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | - if (!empty($erreurs)) { |
|
| 188 | - $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 187 | + if (!empty($erreurs)) { |
|
| 188 | + $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | - return debusquer_navigation($erreurs, $n); |
|
| 191 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | - include_spip('public/tracer'); |
|
| 193 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 190 | + return debusquer_navigation($erreurs, $n); |
|
| 191 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | + include_spip('public/tracer'); |
|
| 193 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 194 | 194 | |
| 195 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | - } else { |
|
| 197 | - return ''; |
|
| 198 | - } |
|
| 195 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | + } else { |
|
| 197 | + return ''; |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -205,42 +205,42 @@ discard block |
||
| 205 | 205 | * @return string Code HTML |
| 206 | 206 | **/ |
| 207 | 207 | function debusquer_contexte($env) { |
| 208 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | - $env = $env_tab; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!$env) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $res = ''; |
|
| 216 | - foreach ($env as $nom => $valeur) { |
|
| 217 | - if (is_array($valeur)) { |
|
| 218 | - $valeur_simple = []; |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - if (is_array($v)) { |
|
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 222 | - } elseif (is_object($v)) { |
|
| 223 | - $valeur_simple[] = get_class($v); |
|
| 224 | - } elseif (is_string($v)) { |
|
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | - } else { |
|
| 227 | - $valeur_simple[] = $v; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - $n = count($valeur); |
|
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | - } elseif (is_object($valeur)) { |
|
| 234 | - $valeur = get_class($valeur); |
|
| 235 | - } elseif (is_string($valeur)) { |
|
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 237 | - } |
|
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | - . "</td></tr>\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | + $env = $env_tab; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!$env) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $res = ''; |
|
| 216 | + foreach ($env as $nom => $valeur) { |
|
| 217 | + if (is_array($valeur)) { |
|
| 218 | + $valeur_simple = []; |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + if (is_array($v)) { |
|
| 221 | + $valeur_simple[] = 'array:' . count($v); |
|
| 222 | + } elseif (is_object($v)) { |
|
| 223 | + $valeur_simple[] = get_class($v); |
|
| 224 | + } elseif (is_string($v)) { |
|
| 225 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | + } else { |
|
| 227 | + $valeur_simple[] = $v; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + $n = count($valeur); |
|
| 231 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | + } elseif (is_object($valeur)) { |
|
| 234 | + $valeur = get_class($valeur); |
|
| 235 | + } elseif (is_string($valeur)) { |
|
| 236 | + $valeur = "'" . $valeur . "'"; |
|
| 237 | + } |
|
| 238 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | + . "</td></tr>\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 250 | 250 | |
| 251 | - if (_request('exec') == 'valider_xml') { |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 254 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | - $res = ''; |
|
| 256 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | - foreach ($tableau as $i => $err) { |
|
| 258 | - $boucle = $ligne = $skel = ''; |
|
| 259 | - list($msg, $lieu) = $err; |
|
| 260 | - if (is_object($lieu)) { |
|
| 261 | - $ligne = $lieu->ligne; |
|
| 262 | - $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | - if (isset($lieu->descr['nom'])) { |
|
| 264 | - $nom_code = $lieu->descr['nom']; |
|
| 265 | - $skel = $lieu->descr['sourcefile']; |
|
| 266 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | - if ($boucle) { |
|
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $j = ($i + 1); |
|
| 277 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | - . $j |
|
| 279 | - . " </td><td style='text-align: left'>" |
|
| 280 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | - . "</td><td style='text-align: left'>" |
|
| 282 | - . ($skel ? $skel : ' / ') |
|
| 283 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | - . ($boucle ? $boucle : ' / ') |
|
| 285 | - . "</td><td style='text-align: right'>" |
|
| 286 | - . $ligne |
|
| 287 | - . "</td></tr>\n"; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return "\n<table id='$id'>" |
|
| 291 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | - . $caption[0] |
|
| 251 | + if (_request('exec') == 'valider_xml') { |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | + $res = ''; |
|
| 256 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | + foreach ($tableau as $i => $err) { |
|
| 258 | + $boucle = $ligne = $skel = ''; |
|
| 259 | + list($msg, $lieu) = $err; |
|
| 260 | + if (is_object($lieu)) { |
|
| 261 | + $ligne = $lieu->ligne; |
|
| 262 | + $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | + if (isset($lieu->descr['nom'])) { |
|
| 264 | + $nom_code = $lieu->descr['nom']; |
|
| 265 | + $skel = $lieu->descr['sourcefile']; |
|
| 266 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | + if ($boucle) { |
|
| 270 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $j = ($i + 1); |
|
| 277 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | + . $j |
|
| 279 | + . " </td><td style='text-align: left'>" |
|
| 280 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | + . "</td><td style='text-align: left'>" |
|
| 282 | + . ($skel ? $skel : ' / ') |
|
| 283 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | + . ($boucle ? $boucle : ' / ') |
|
| 285 | + . "</td><td style='text-align: right'>" |
|
| 286 | + . $ligne |
|
| 287 | + . "</td></tr>\n"; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return "\n<table id='$id'>" |
|
| 291 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | + . $caption[0] |
|
| 293 | 293 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 294 | 294 | # aider('erreur_compilation'), |
| 295 | - . '</caption>' |
|
| 296 | - // fausse caption du chrono (mais vraie nav) |
|
| 297 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | - . '<tr><th>' |
|
| 299 | - . _T('numero') |
|
| 300 | - . '</th><th>' |
|
| 301 | - . _T('public:message') |
|
| 302 | - . '</th><th>' |
|
| 303 | - . _T('squelette') |
|
| 304 | - . '</th><th>' |
|
| 305 | - . _T('zbug_boucle') |
|
| 306 | - . '</th><th>' |
|
| 307 | - . _T('ligne') |
|
| 308 | - . '</th></tr>' |
|
| 309 | - . $res |
|
| 310 | - . '</table>'; |
|
| 295 | + . '</caption>' |
|
| 296 | + // fausse caption du chrono (mais vraie nav) |
|
| 297 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | + . '<tr><th>' |
|
| 299 | + . _T('numero') |
|
| 300 | + . '</th><th>' |
|
| 301 | + . _T('public:message') |
|
| 302 | + . '</th><th>' |
|
| 303 | + . _T('squelette') |
|
| 304 | + . '</th><th>' |
|
| 305 | + . _T('zbug_boucle') |
|
| 306 | + . '</th><th>' |
|
| 307 | + . _T('ligne') |
|
| 308 | + . '</th></tr>' |
|
| 309 | + . $res |
|
| 310 | + . '</table>'; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -327,124 +327,124 @@ discard block |
||
| 327 | 327 | * ou un tableau si l'erreur est critique |
| 328 | 328 | **/ |
| 329 | 329 | function debusquer_requete($message) { |
| 330 | - list($errno, $msg, $query) = $message; |
|
| 331 | - |
|
| 332 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | - $errno = $regs[2]; |
|
| 336 | - } elseif ( |
|
| 337 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | - ) { |
|
| 340 | - $errno = $regs[1]; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Erreur systeme |
|
| 344 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | - $retour = '<tt><br /><br /><blink>' |
|
| 346 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | - . "</blink><br />\n<b>" |
|
| 348 | - . _T( |
|
| 349 | - 'info_erreur_systeme2', |
|
| 350 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | - ) |
|
| 352 | - . '</b><br />'; |
|
| 353 | - spip_log("Erreur systeme $errno"); |
|
| 354 | - |
|
| 355 | - return [$retour, '']; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Requete erronee |
|
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | - . spip_htmlspecialchars($msg) |
|
| 361 | - . "\n<br /><span style='color: red'><b>" |
|
| 362 | - . spip_htmlspecialchars($query) |
|
| 363 | - . '</b></span></tt><br />'; |
|
| 364 | - |
|
| 365 | - //. aider('erreur_mysql'); |
|
| 366 | - |
|
| 367 | - return $err; |
|
| 330 | + list($errno, $msg, $query) = $message; |
|
| 331 | + |
|
| 332 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | + $errno = $regs[2]; |
|
| 336 | + } elseif ( |
|
| 337 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | + ) { |
|
| 340 | + $errno = $regs[1]; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Erreur systeme |
|
| 344 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | + $retour = '<tt><br /><br /><blink>' |
|
| 346 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | + . "</blink><br />\n<b>" |
|
| 348 | + . _T( |
|
| 349 | + 'info_erreur_systeme2', |
|
| 350 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | + ) |
|
| 352 | + . '</b><br />'; |
|
| 353 | + spip_log("Erreur systeme $errno"); |
|
| 354 | + |
|
| 355 | + return [$retour, '']; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Requete erronee |
|
| 359 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | + . spip_htmlspecialchars($msg) |
|
| 361 | + . "\n<br /><span style='color: red'><b>" |
|
| 362 | + . spip_htmlspecialchars($query) |
|
| 363 | + . '</b></span></tt><br />'; |
|
| 364 | + |
|
| 365 | + //. aider('erreur_mysql'); |
|
| 366 | + |
|
| 367 | + return $err; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 375 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | - $y = substr_count($v[0], "\n"); |
|
| 379 | - } else { |
|
| 380 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | - } else // inclusion |
|
| 383 | - { |
|
| 384 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | - } |
|
| 386 | - $y = substr_count($incl, "\n") |
|
| 387 | - + substr_count($r[1], "\n") |
|
| 388 | - + substr_count($r[3], "\n"); |
|
| 389 | - } |
|
| 390 | - if ($n <= ($y + $debut)) { |
|
| 391 | - if ($v[1][0] == '?') { |
|
| 392 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | - } elseif ($v[1][0] == '!') { |
|
| 394 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | - } |
|
| 401 | - $debut += $y; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return [$nom, $boucle, $n - $debut]; |
|
| 374 | + $id = $nom . $boucle; |
|
| 375 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | + $y = substr_count($v[0], "\n"); |
|
| 379 | + } else { |
|
| 380 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | + } else // inclusion |
|
| 383 | + { |
|
| 384 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | + } |
|
| 386 | + $y = substr_count($incl, "\n") |
|
| 387 | + + substr_count($r[1], "\n") |
|
| 388 | + + substr_count($r[3], "\n"); |
|
| 389 | + } |
|
| 390 | + if ($n <= ($y + $debut)) { |
|
| 391 | + if ($v[1][0] == '?') { |
|
| 392 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | + } elseif ($v[1][0] == '!') { |
|
| 394 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | + } |
|
| 401 | + $debut += $y; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return [$nom, $boucle, $n - $debut]; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // https://code.spip.net/@trouve_squelette_inclus |
| 409 | 409 | function trouve_squelette_inclus($script) { |
| 410 | 410 | |
| 411 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | - // si le script X.php n'est pas ecrire/public.php |
|
| 413 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | - $reg[1] = 'inconnu'; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | - |
|
| 423 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | - if (preg_match($incl, $v)) { |
|
| 425 | - return $k; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return ''; |
|
| 411 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | + // si le script X.php n'est pas ecrire/public.php |
|
| 413 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | + $reg[1] = 'inconnu'; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | + |
|
| 423 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | + if (preg_match($incl, $v)) { |
|
| 425 | + return $k; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return ''; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // https://code.spip.net/@reference_boucle_debug |
| 433 | 433 | function reference_boucle_debug($n, $nom, $self) { |
| 434 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | - |
|
| 436 | - if (!$boucle) { |
|
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 441 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | - } else { |
|
| 443 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | - |
|
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | - } |
|
| 434 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | + |
|
| 436 | + if (!$boucle) { |
|
| 437 | + return !$ligne ? '' : |
|
| 438 | + (' (' . |
|
| 439 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | + _T('squelette_ligne')) . |
|
| 441 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | + } else { |
|
| 443 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | + |
|
| 445 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // affiche un texte avec numero de ligne et ancre. |
@@ -452,397 +452,397 @@ discard block |
||
| 452 | 452 | // https://code.spip.net/@ancre_texte |
| 453 | 453 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 454 | 454 | |
| 455 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | - if ($var_mode_ligne) { |
|
| 457 | - $fautifs[] = [$var_mode_ligne]; |
|
| 458 | - } |
|
| 459 | - $res = ''; |
|
| 460 | - |
|
| 461 | - $s = highlight_string($texte, true); |
|
| 462 | - if (substr($s, 0, 6) == '<code>') { |
|
| 463 | - $s = substr($s, 6); |
|
| 464 | - $res = '<code>'; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $s = preg_replace( |
|
| 468 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | - $s |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - $tableau = explode('<br />', $s); |
|
| 475 | - |
|
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | - |
|
| 478 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | - $formaterr = 'color: red;'; |
|
| 480 | - $i = 1; |
|
| 481 | - $flignes = []; |
|
| 482 | - $loc = [0, 0]; |
|
| 483 | - foreach ($fautifs as $lc) { |
|
| 484 | - if (is_array($lc)) { |
|
| 485 | - $l = array_shift($lc); |
|
| 486 | - $flignes[$l] = $lc; |
|
| 487 | - } else { |
|
| 488 | - $flignes[$lc] = $loc; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - $ancre = md5($texte); |
|
| 493 | - foreach ($tableau as $ligne) { |
|
| 494 | - if (isset($flignes[$i])) { |
|
| 495 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | - $indexmesg = $flignes[$i][1]; |
|
| 497 | - $err = textebrut($flignes[$i][2]); |
|
| 498 | - // tentative de pointer sur la colonne fautive; |
|
| 499 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | - // $m = $flignes[$i][0]; |
|
| 501 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | - $bg = $formaterr; |
|
| 504 | - } else { |
|
| 505 | - $indexmesg = $ancre; |
|
| 506 | - $err = $bg = ''; |
|
| 507 | - } |
|
| 508 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | - $i++; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return "<div id='T$ancre'>" |
|
| 513 | - . '<div onclick="' |
|
| 514 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | - . '" title="' |
|
| 516 | - . _T('masquer_colonne') |
|
| 517 | - . '" style="cursor: pointer;">' |
|
| 518 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | - . '</div> |
|
| 455 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | + if ($var_mode_ligne) { |
|
| 457 | + $fautifs[] = [$var_mode_ligne]; |
|
| 458 | + } |
|
| 459 | + $res = ''; |
|
| 460 | + |
|
| 461 | + $s = highlight_string($texte, true); |
|
| 462 | + if (substr($s, 0, 6) == '<code>') { |
|
| 463 | + $s = substr($s, 6); |
|
| 464 | + $res = '<code>'; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $s = preg_replace( |
|
| 468 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | + $s |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + $tableau = explode('<br />', $s); |
|
| 475 | + |
|
| 476 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | + |
|
| 478 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | + $formaterr = 'color: red;'; |
|
| 480 | + $i = 1; |
|
| 481 | + $flignes = []; |
|
| 482 | + $loc = [0, 0]; |
|
| 483 | + foreach ($fautifs as $lc) { |
|
| 484 | + if (is_array($lc)) { |
|
| 485 | + $l = array_shift($lc); |
|
| 486 | + $flignes[$l] = $lc; |
|
| 487 | + } else { |
|
| 488 | + $flignes[$lc] = $loc; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + $ancre = md5($texte); |
|
| 493 | + foreach ($tableau as $ligne) { |
|
| 494 | + if (isset($flignes[$i])) { |
|
| 495 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | + $indexmesg = $flignes[$i][1]; |
|
| 497 | + $err = textebrut($flignes[$i][2]); |
|
| 498 | + // tentative de pointer sur la colonne fautive; |
|
| 499 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | + // $m = $flignes[$i][0]; |
|
| 501 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | + $bg = $formaterr; |
|
| 504 | + } else { |
|
| 505 | + $indexmesg = $ancre; |
|
| 506 | + $err = $bg = ''; |
|
| 507 | + } |
|
| 508 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | + $i++; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return "<div id='T$ancre'>" |
|
| 513 | + . '<div onclick="' |
|
| 514 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | + . '" title="' |
|
| 516 | + . _T('masquer_colonne') |
|
| 517 | + . '" style="cursor: pointer;">' |
|
| 518 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | + . '</div> |
|
| 520 | 520 | ' . $res . "</div>\n"; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | // l'environnement graphique du debuggueur |
| 524 | 524 | |
| 525 | 525 | function debusquer_squelette($fonc, $mode, $self) { |
| 526 | - $texte = ''; |
|
| 527 | - |
|
| 528 | - if ($mode !== 'validation') { |
|
| 529 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | - $res = "<div id='spip-boucles'>\n" |
|
| 531 | - . debusquer_navigation_squelettes($self) |
|
| 532 | - . '</div>'; |
|
| 533 | - } else { |
|
| 534 | - $res = ''; |
|
| 535 | - } |
|
| 536 | - if ($fonc) { |
|
| 537 | - $id = " id='$fonc'"; |
|
| 538 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | - $texte .= $res2; |
|
| 541 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | - $legend = _T('zbug_' . $mode); |
|
| 543 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | - $texte = ancre_texte($texte, ['', '']); |
|
| 545 | - } |
|
| 546 | - } else { |
|
| 547 | - if (strlen(trim($res))) { |
|
| 548 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | - } else { |
|
| 550 | - // cas de l'appel sur erreur: montre la page |
|
| 551 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | - : ''; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } else { |
|
| 557 | - $valider = charger_fonction('valider', 'xml'); |
|
| 558 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | - if ($err === false) { |
|
| 563 | - $err = _T('impossible'); |
|
| 564 | - } elseif ($err === true) { |
|
| 565 | - $err = _T('correcte'); |
|
| 566 | - } else { |
|
| 567 | - $err = ": $err"; |
|
| 568 | - } |
|
| 569 | - $legend = _T('validation') . ' ' . $err; |
|
| 570 | - $res = $id = ''; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return !trim($texte) ? '' : ( |
|
| 574 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | - . ($legend ? $legend : $mode) |
|
| 578 | - . '</a></legend>' |
|
| 579 | - . $texte |
|
| 580 | - . '</fieldset></div>' |
|
| 581 | - . '</div>'); |
|
| 526 | + $texte = ''; |
|
| 527 | + |
|
| 528 | + if ($mode !== 'validation') { |
|
| 529 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | + $res = "<div id='spip-boucles'>\n" |
|
| 531 | + . debusquer_navigation_squelettes($self) |
|
| 532 | + . '</div>'; |
|
| 533 | + } else { |
|
| 534 | + $res = ''; |
|
| 535 | + } |
|
| 536 | + if ($fonc) { |
|
| 537 | + $id = " id='$fonc'"; |
|
| 538 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | + $texte .= $res2; |
|
| 541 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | + $legend = _T('zbug_' . $mode); |
|
| 543 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | + $texte = ancre_texte($texte, ['', '']); |
|
| 545 | + } |
|
| 546 | + } else { |
|
| 547 | + if (strlen(trim($res))) { |
|
| 548 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | + } else { |
|
| 550 | + // cas de l'appel sur erreur: montre la page |
|
| 551 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | + : ''; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } else { |
|
| 557 | + $valider = charger_fonction('valider', 'xml'); |
|
| 558 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | + if ($err === false) { |
|
| 563 | + $err = _T('impossible'); |
|
| 564 | + } elseif ($err === true) { |
|
| 565 | + $err = _T('correcte'); |
|
| 566 | + } else { |
|
| 567 | + $err = ": $err"; |
|
| 568 | + } |
|
| 569 | + $legend = _T('validation') . ' ' . $err; |
|
| 570 | + $res = $id = ''; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return !trim($texte) ? '' : ( |
|
| 574 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | + . ($legend ? $legend : $mode) |
|
| 578 | + . '</a></legend>' |
|
| 579 | + . $texte |
|
| 580 | + . '</fieldset></div>' |
|
| 581 | + . '</div>'); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | // https://code.spip.net/@emboite_texte |
| 586 | 586 | function emboite_texte($res, $fonc = '', $self = '') { |
| 587 | - $errs = $res->err; |
|
| 588 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | - |
|
| 590 | - if (!$texte and !$errs) { |
|
| 591 | - return [ancre_texte('', ['', '']), false]; |
|
| 592 | - } |
|
| 593 | - if (!$errs) { |
|
| 594 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | - $encore = count_occ($errs); |
|
| 600 | - $encore2 = []; |
|
| 601 | - $fautifs = []; |
|
| 602 | - |
|
| 603 | - $err = '<tr><th>' |
|
| 604 | - . _T('numero') |
|
| 605 | - . '</th><th>' |
|
| 606 | - . _T('occurence') |
|
| 607 | - . '</th><th>' |
|
| 608 | - . _T('ligne') |
|
| 609 | - . '</th><th>' |
|
| 610 | - . _T('colonne') |
|
| 611 | - . '</th><th>' |
|
| 612 | - . _T('erreur') |
|
| 613 | - . '</th></tr>'; |
|
| 614 | - |
|
| 615 | - $i = 0; |
|
| 616 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | - foreach ($errs as $r) { |
|
| 618 | - $i++; |
|
| 619 | - list($msg, $ligne, $col) = $r; |
|
| 620 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | - if (isset($encore2[$msg])) { |
|
| 622 | - $ref = ++$encore2[$msg]; |
|
| 623 | - } else { |
|
| 624 | - $encore2[$msg] = $ref = 1; |
|
| 625 | - } |
|
| 626 | - $err .= "<tr style='background-color: " |
|
| 627 | - . $colors[$i % 2] |
|
| 628 | - . "'><td $style><a href='#debut_err'>" |
|
| 629 | - . $i |
|
| 630 | - . "</a></td><td $style>" |
|
| 631 | - . "$ref/$encore[$msg]</td>" |
|
| 632 | - . "<td $style><a href='#L" |
|
| 633 | - . $ligne |
|
| 634 | - . "' id='T$i'>" |
|
| 635 | - . $ligne |
|
| 636 | - . "</a></td><td $style>" |
|
| 637 | - . $col |
|
| 638 | - . "</td><td>$msg</td></tr>\n"; |
|
| 639 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | - } |
|
| 641 | - $err = "<h2 style='text-align: center'>" |
|
| 642 | - . $i |
|
| 643 | - . "<a href='#fin_err'>" |
|
| 644 | - . ' ' . _T('erreur_texte') |
|
| 645 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | - . $err |
|
| 647 | - . " </table><a id='fin_err'></a>"; |
|
| 648 | - |
|
| 649 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | - } else { |
|
| 651 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | - |
|
| 658 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | - } |
|
| 587 | + $errs = $res->err; |
|
| 588 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | + |
|
| 590 | + if (!$texte and !$errs) { |
|
| 591 | + return [ancre_texte('', ['', '']), false]; |
|
| 592 | + } |
|
| 593 | + if (!$errs) { |
|
| 594 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | + $encore = count_occ($errs); |
|
| 600 | + $encore2 = []; |
|
| 601 | + $fautifs = []; |
|
| 602 | + |
|
| 603 | + $err = '<tr><th>' |
|
| 604 | + . _T('numero') |
|
| 605 | + . '</th><th>' |
|
| 606 | + . _T('occurence') |
|
| 607 | + . '</th><th>' |
|
| 608 | + . _T('ligne') |
|
| 609 | + . '</th><th>' |
|
| 610 | + . _T('colonne') |
|
| 611 | + . '</th><th>' |
|
| 612 | + . _T('erreur') |
|
| 613 | + . '</th></tr>'; |
|
| 614 | + |
|
| 615 | + $i = 0; |
|
| 616 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | + foreach ($errs as $r) { |
|
| 618 | + $i++; |
|
| 619 | + list($msg, $ligne, $col) = $r; |
|
| 620 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | + if (isset($encore2[$msg])) { |
|
| 622 | + $ref = ++$encore2[$msg]; |
|
| 623 | + } else { |
|
| 624 | + $encore2[$msg] = $ref = 1; |
|
| 625 | + } |
|
| 626 | + $err .= "<tr style='background-color: " |
|
| 627 | + . $colors[$i % 2] |
|
| 628 | + . "'><td $style><a href='#debut_err'>" |
|
| 629 | + . $i |
|
| 630 | + . "</a></td><td $style>" |
|
| 631 | + . "$ref/$encore[$msg]</td>" |
|
| 632 | + . "<td $style><a href='#L" |
|
| 633 | + . $ligne |
|
| 634 | + . "' id='T$i'>" |
|
| 635 | + . $ligne |
|
| 636 | + . "</a></td><td $style>" |
|
| 637 | + . $col |
|
| 638 | + . "</td><td>$msg</td></tr>\n"; |
|
| 639 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | + } |
|
| 641 | + $err = "<h2 style='text-align: center'>" |
|
| 642 | + . $i |
|
| 643 | + . "<a href='#fin_err'>" |
|
| 644 | + . ' ' . _T('erreur_texte') |
|
| 645 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | + . $err |
|
| 647 | + . " </table><a id='fin_err'></a>"; |
|
| 648 | + |
|
| 649 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | + } else { |
|
| 651 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | + $err = $msg . |
|
| 655 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | + |
|
| 658 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | // https://code.spip.net/@count_occ |
| 663 | 663 | function count_occ($regs) { |
| 664 | - $encore = []; |
|
| 665 | - foreach ($regs as $r) { |
|
| 666 | - if (isset($encore[$r[0]])) { |
|
| 667 | - $encore[$r[0]]++; |
|
| 668 | - } else { |
|
| 669 | - $encore[$r[0]] = 1; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $encore; |
|
| 664 | + $encore = []; |
|
| 665 | + foreach ($regs as $r) { |
|
| 666 | + if (isset($encore[$r[0]])) { |
|
| 667 | + $encore[$r[0]]++; |
|
| 668 | + } else { |
|
| 669 | + $encore[$r[0]] = 1; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $encore; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | function debusquer_navigation_squelettes($self) { |
| 677 | 677 | |
| 678 | - $res = ''; |
|
| 679 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | - $t_skel = _T('squelette'); |
|
| 682 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | - 'zbug_profile', |
|
| 687 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | - ); |
|
| 689 | - |
|
| 690 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | - . $t_skel |
|
| 692 | - . ' ' |
|
| 693 | - . $sourcefile |
|
| 694 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | - . $t_skel |
|
| 696 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | - . _T('zbug_resultat') |
|
| 698 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | - . _T('zbug_code') |
|
| 700 | - . "</a>\n<a href='" |
|
| 701 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | - . "'>" |
|
| 703 | - . _T('zbug_calcul') |
|
| 704 | - . '</a></legend>' |
|
| 705 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | - . "</fieldset>\n"; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - return $res; |
|
| 678 | + $res = ''; |
|
| 679 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | + $t_skel = _T('squelette'); |
|
| 682 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | + 'zbug_profile', |
|
| 687 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | + ); |
|
| 689 | + |
|
| 690 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | + . $t_skel |
|
| 692 | + . ' ' |
|
| 693 | + . $sourcefile |
|
| 694 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | + . $t_skel |
|
| 696 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | + . _T('zbug_resultat') |
|
| 698 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | + . _T('zbug_code') |
|
| 700 | + . "</a>\n<a href='" |
|
| 701 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | + . "'>" |
|
| 703 | + . _T('zbug_calcul') |
|
| 704 | + . '</a></legend>' |
|
| 705 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | + . "</fieldset>\n"; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + return $res; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 715 | - $i = 0; |
|
| 716 | - $res = ''; |
|
| 717 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | - |
|
| 720 | - foreach ($boucles as $objet => $boucle) { |
|
| 721 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | - $i++; |
|
| 723 | - $nom = $boucle->id_boucle; |
|
| 724 | - $req = $boucle->type_requete; |
|
| 725 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | - |
|
| 728 | - $res .= "\n<tr style='background-color: " . |
|
| 729 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | - "'><td align='right'>$i</td><td>\n" . |
|
| 731 | - "<a class='debug_link_boucle' href='" . |
|
| 732 | - $self2 . |
|
| 733 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | - _T('zbug_boucle') . |
|
| 735 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | - $self2 . |
|
| 737 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | - _T('zbug_resultat') . |
|
| 739 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | - $self2 . |
|
| 741 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | - _T('zbug_code') . |
|
| 743 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | - "'>" . |
|
| 746 | - _T('zbug_calcul') . |
|
| 747 | - "</a></td><td>\n" . |
|
| 748 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - $req . |
|
| 751 | - "</td><td>\n" . |
|
| 752 | - spip_htmlspecialchars($crit) . |
|
| 753 | - '</td></tr>'; |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $res; |
|
| 715 | + $i = 0; |
|
| 716 | + $res = ''; |
|
| 717 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | + |
|
| 720 | + foreach ($boucles as $objet => $boucle) { |
|
| 721 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | + $i++; |
|
| 723 | + $nom = $boucle->id_boucle; |
|
| 724 | + $req = $boucle->type_requete; |
|
| 725 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | + |
|
| 728 | + $res .= "\n<tr style='background-color: " . |
|
| 729 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | + "'><td align='right'>$i</td><td>\n" . |
|
| 731 | + "<a class='debug_link_boucle' href='" . |
|
| 732 | + $self2 . |
|
| 733 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | + _T('zbug_boucle') . |
|
| 735 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | + $self2 . |
|
| 737 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | + _T('zbug_resultat') . |
|
| 739 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | + $self2 . |
|
| 741 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | + _T('zbug_code') . |
|
| 743 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | + "'>" . |
|
| 746 | + _T('zbug_calcul') . |
|
| 747 | + "</a></td><td>\n" . |
|
| 748 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | + "</td><td>\n" . |
|
| 750 | + $req . |
|
| 751 | + "</td><td>\n" . |
|
| 752 | + spip_htmlspecialchars($crit) . |
|
| 753 | + '</td></tr>'; |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $res; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | function debusquer_source($objet, $affiche) { |
| 761 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | - } else { |
|
| 765 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | - } |
|
| 767 | - $res2 = ''; |
|
| 768 | - |
|
| 769 | - if ($affiche == 'resultat') { |
|
| 770 | - $legend = $nom; |
|
| 771 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | - if (function_exists('_mysql_traite_query')) { |
|
| 773 | - $c = strtolower(_request('connect')); |
|
| 774 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | - $req = _mysql_traite_query($req, '', $c); |
|
| 776 | - } |
|
| 777 | - // permettre le copier/coller facile |
|
| 778 | - // $res = ancre_texte($req, array(), true); |
|
| 779 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | - // formatage et affichage des resultats bruts de la requete |
|
| 781 | - $ress_req = spip_query($req); |
|
| 782 | - $brut_sql = ''; |
|
| 783 | - $num = 1; |
|
| 784 | - // eviter l'affichage de milliers de lignes |
|
| 785 | - // personnalisation possible dans mes_options |
|
| 786 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | - if ($num <= $max_aff) { |
|
| 789 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | - $brut_sql .= '<p>'; |
|
| 791 | - foreach ($retours_sql as $key => $val) { |
|
| 792 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | - } |
|
| 794 | - $brut_sql .= '</p>'; |
|
| 795 | - } |
|
| 796 | - $num++; |
|
| 797 | - } |
|
| 798 | - $res2 = interdire_scripts($brut_sql); |
|
| 799 | - foreach ($quoi as $view) { |
|
| 800 | - // ne pas afficher les $contexte_inclus |
|
| 801 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | - if ($view) { |
|
| 803 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - } elseif ($affiche == 'code') { |
|
| 807 | - $legend = $nom; |
|
| 808 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | - } elseif ($affiche == 'boucle') { |
|
| 810 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | - } elseif ($affiche == 'squelette') { |
|
| 815 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return [$legend, $res, $res2]; |
|
| 761 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | + } else { |
|
| 765 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | + } |
|
| 767 | + $res2 = ''; |
|
| 768 | + |
|
| 769 | + if ($affiche == 'resultat') { |
|
| 770 | + $legend = $nom; |
|
| 771 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | + if (function_exists('_mysql_traite_query')) { |
|
| 773 | + $c = strtolower(_request('connect')); |
|
| 774 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | + $req = _mysql_traite_query($req, '', $c); |
|
| 776 | + } |
|
| 777 | + // permettre le copier/coller facile |
|
| 778 | + // $res = ancre_texte($req, array(), true); |
|
| 779 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | + // formatage et affichage des resultats bruts de la requete |
|
| 781 | + $ress_req = spip_query($req); |
|
| 782 | + $brut_sql = ''; |
|
| 783 | + $num = 1; |
|
| 784 | + // eviter l'affichage de milliers de lignes |
|
| 785 | + // personnalisation possible dans mes_options |
|
| 786 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | + if ($num <= $max_aff) { |
|
| 789 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | + $brut_sql .= '<p>'; |
|
| 791 | + foreach ($retours_sql as $key => $val) { |
|
| 792 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | + } |
|
| 794 | + $brut_sql .= '</p>'; |
|
| 795 | + } |
|
| 796 | + $num++; |
|
| 797 | + } |
|
| 798 | + $res2 = interdire_scripts($brut_sql); |
|
| 799 | + foreach ($quoi as $view) { |
|
| 800 | + // ne pas afficher les $contexte_inclus |
|
| 801 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | + if ($view) { |
|
| 803 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + } elseif ($affiche == 'code') { |
|
| 807 | + $legend = $nom; |
|
| 808 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | + } elseif ($affiche == 'boucle') { |
|
| 810 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | + } elseif ($affiche == 'squelette') { |
|
| 815 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return [$legend, $res, $res2]; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // https://code.spip.net/@debusquer_entete |
| 823 | 823 | function debusquer_entete($titre, $corps) { |
| 824 | 824 | |
| 825 | - include_spip('balise/formulaire_admin'); |
|
| 826 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | - |
|
| 829 | - return _DOCTYPE_ECRIRE . |
|
| 830 | - html_lang_attributes() . |
|
| 831 | - "<head>\n<title>" . |
|
| 832 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | - ")</title>\n" . |
|
| 836 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | - "' />\n" . |
|
| 839 | - http_script('', 'jquery.js') |
|
| 840 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | - . "' type='text/css' />" . |
|
| 842 | - "</head>\n" . |
|
| 843 | - "<body style='margin:0 10px;'>\n" . |
|
| 844 | - "<div id='spip-debug-header'>" . |
|
| 845 | - $corps . |
|
| 846 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | - '</div></body></html>'; |
|
| 825 | + include_spip('balise/formulaire_admin'); |
|
| 826 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | + |
|
| 829 | + return _DOCTYPE_ECRIRE . |
|
| 830 | + html_lang_attributes() . |
|
| 831 | + "<head>\n<title>" . |
|
| 832 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | + ")</title>\n" . |
|
| 836 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | + "' />\n" . |
|
| 839 | + http_script('', 'jquery.js') |
|
| 840 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | + . "' type='text/css' />" . |
|
| 842 | + "</head>\n" . |
|
| 843 | + "<body style='margin:0 10px;'>\n" . |
|
| 844 | + "<div id='spip-debug-header'>" . |
|
| 845 | + $corps . |
|
| 846 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | + '</div></body></html>'; |
|
| 848 | 848 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | - // (recursion possible a cause des modeles) |
|
| 62 | - if ($debug) { |
|
| 63 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // charger le squelette en specifiant les langages cibles et source |
|
| 68 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | - |
|
| 70 | - if (!$composer) { |
|
| 71 | - $composer = charger_fonction('composer', 'public'); |
|
| 72 | - } |
|
| 73 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | - } else { |
|
| 75 | - $fonc = ''; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | - $page = $fonc; |
|
| 80 | - } else { |
|
| 81 | - // Preparer l'appel de la fonction principale du squelette |
|
| 82 | - |
|
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | - |
|
| 85 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | - // et on enregistre l'etat courant des globales de notes... |
|
| 87 | - if (is_null($notes)) { |
|
| 88 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | - } |
|
| 90 | - if ($notes) { |
|
| 91 | - $notes('', 'empiler'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Rajouter d'office ces deux parametres |
|
| 95 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | - if (!isset($contexte['date'])) { |
|
| 98 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | - $contexte['date_default'] = true; |
|
| 100 | - } else { |
|
| 101 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!isset($contexte['date_redac'])) { |
|
| 105 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | - $contexte['date_redac_default'] = true; |
|
| 107 | - } else { |
|
| 108 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | - try { |
|
| 113 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | - } catch (Throwable $e) { |
|
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | - $corps = "<pre>$msg</pre>"; |
|
| 119 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | - erreur_squelette($full_msg); |
|
| 121 | - unset($msg, $full_msg, $corps); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | - if ($notes) { |
|
| 130 | - $notes('', 'depiler'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // reinjecter en dynamique la pile des notes |
|
| 134 | - // si il y a des inclure dynamiques |
|
| 135 | - // si la pile n'est pas vide |
|
| 136 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | - if ($notes) { |
|
| 139 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // spip_log: un joli contexte |
|
| 143 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | - |
|
| 145 | - $profile = spip_timer($a); |
|
| 146 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | - |
|
| 149 | - if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ($debug) { |
|
| 155 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | - if ( |
|
| 161 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | + // (recursion possible a cause des modeles) |
|
| 62 | + if ($debug) { |
|
| 63 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // charger le squelette en specifiant les langages cibles et source |
|
| 68 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | + |
|
| 70 | + if (!$composer) { |
|
| 71 | + $composer = charger_fonction('composer', 'public'); |
|
| 72 | + } |
|
| 73 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | + } else { |
|
| 75 | + $fonc = ''; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | + $page = $fonc; |
|
| 80 | + } else { |
|
| 81 | + // Preparer l'appel de la fonction principale du squelette |
|
| 82 | + |
|
| 83 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + |
|
| 85 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | + // et on enregistre l'etat courant des globales de notes... |
|
| 87 | + if (is_null($notes)) { |
|
| 88 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | + } |
|
| 90 | + if ($notes) { |
|
| 91 | + $notes('', 'empiler'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Rajouter d'office ces deux parametres |
|
| 95 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | + if (!isset($contexte['date'])) { |
|
| 98 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | + $contexte['date_default'] = true; |
|
| 100 | + } else { |
|
| 101 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!isset($contexte['date_redac'])) { |
|
| 105 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | + $contexte['date_redac_default'] = true; |
|
| 107 | + } else { |
|
| 108 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | + try { |
|
| 113 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | + } catch (Throwable $e) { |
|
| 115 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | + $corps = "<pre>$msg</pre>"; |
|
| 119 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | + erreur_squelette($full_msg); |
|
| 121 | + unset($msg, $full_msg, $corps); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | + if ($notes) { |
|
| 130 | + $notes('', 'depiler'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // reinjecter en dynamique la pile des notes |
|
| 134 | + // si il y a des inclure dynamiques |
|
| 135 | + // si la pile n'est pas vide |
|
| 136 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | + if ($notes) { |
|
| 139 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // spip_log: un joli contexte |
|
| 143 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | + |
|
| 145 | + $profile = spip_timer($a); |
|
| 146 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + |
|
| 149 | + if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ($debug) { |
|
| 155 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | + if ( |
|
| 161 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,33 +210,33 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = []; |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = get_class($val); |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr($val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } |
|
| 237 | - $infos[] = $var . '=' . $val; |
|
| 238 | - } |
|
| 239 | - return join(', ', $infos); |
|
| 213 | + $infos = []; |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = get_class($val); |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr($val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } |
|
| 237 | + $infos[] = $var . '=' . $val; |
|
| 238 | + } |
|
| 239 | + return join(', ', $infos); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @return array|bool |
| 254 | 254 | */ |
| 255 | 255 | function tester_redirection($fond, $contexte, $connect) { |
| 256 | - static $tester_redirection = null; |
|
| 257 | - if (is_null($tester_redirection)) { |
|
| 258 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | - } |
|
| 260 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 256 | + static $tester_redirection = null; |
|
| 257 | + if (is_null($tester_redirection)) { |
|
| 258 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | + } |
|
| 260 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -273,42 +273,42 @@ discard block |
||
| 273 | 273 | * @return array|bool |
| 274 | 274 | */ |
| 275 | 275 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 276 | - if ( |
|
| 277 | - $fond == 'article' |
|
| 278 | - and !empty($contexte['id_article']) |
|
| 279 | - and $id_article = intval($contexte['id_article']) |
|
| 280 | - ) { |
|
| 281 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 282 | - $m = quete_virtuel($id_article, $connect); |
|
| 283 | - if (strlen($m)) { |
|
| 284 | - include_spip('inc/texte'); |
|
| 285 | - // les navigateurs pataugent si l'URL est vide |
|
| 286 | - if ($url = virtuel_redirige($m, true)) { |
|
| 287 | - // passer en url absolue car cette redirection pourra |
|
| 288 | - // etre utilisee dans un contexte d'url qui change |
|
| 289 | - // y compris url arbo |
|
| 290 | - $status = 302; |
|
| 291 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 292 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 293 | - } |
|
| 294 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 295 | - include_spip('inc/filtres_mini'); |
|
| 296 | - $url = url_absolue($url); |
|
| 297 | - } |
|
| 298 | - $url = str_replace('&', '&', $url); |
|
| 299 | - |
|
| 300 | - return [ |
|
| 301 | - 'texte' => '<' |
|
| 302 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 303 | - . texte_script($url) |
|
| 304 | - . "','',$status);" |
|
| 305 | - . '?' . '>', |
|
| 306 | - 'process_ins' => 'php', |
|
| 307 | - 'status' => $status |
|
| 308 | - ]; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return false; |
|
| 276 | + if ( |
|
| 277 | + $fond == 'article' |
|
| 278 | + and !empty($contexte['id_article']) |
|
| 279 | + and $id_article = intval($contexte['id_article']) |
|
| 280 | + ) { |
|
| 281 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 282 | + $m = quete_virtuel($id_article, $connect); |
|
| 283 | + if (strlen($m)) { |
|
| 284 | + include_spip('inc/texte'); |
|
| 285 | + // les navigateurs pataugent si l'URL est vide |
|
| 286 | + if ($url = virtuel_redirige($m, true)) { |
|
| 287 | + // passer en url absolue car cette redirection pourra |
|
| 288 | + // etre utilisee dans un contexte d'url qui change |
|
| 289 | + // y compris url arbo |
|
| 290 | + $status = 302; |
|
| 291 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 292 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 293 | + } |
|
| 294 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 295 | + include_spip('inc/filtres_mini'); |
|
| 296 | + $url = url_absolue($url); |
|
| 297 | + } |
|
| 298 | + $url = str_replace('&', '&', $url); |
|
| 299 | + |
|
| 300 | + return [ |
|
| 301 | + 'texte' => '<' |
|
| 302 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 303 | + . texte_script($url) |
|
| 304 | + . "','',$status);" |
|
| 305 | + . '?' . '>', |
|
| 306 | + 'process_ins' => 'php', |
|
| 307 | + 'status' => $status |
|
| 308 | + ]; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return false; |
|
| 314 | 314 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } else { |
| 81 | 81 | // Preparer l'appel de la fonction principale du squelette |
| 82 | 82 | |
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 83 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 84 | 84 | |
| 85 | 85 | // On cree un marqueur de notes unique lie a cette composition |
| 86 | 86 | // et on enregistre l'etat courant des globales de notes... |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | try { |
| 113 | 113 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 114 | 114 | } catch (Throwable $e) { |
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 116 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 117 | 117 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 118 | 118 | $corps = "<pre>$msg</pre>"; |
| 119 | 119 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $profile = spip_timer($a); |
| 146 | 146 | spip_log("calcul ($profile) [$skel] $infos" |
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 148 | 148 | |
| 149 | 149 | if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
| 150 | 150 | spip_log("calcul ($profile) [$skel] $infos" |
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | + . ' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($debug) { |
| 155 | 155 | // si c'est ce que demande le debusqueur, lui passer la main |
| 156 | 156 | $t = strlen($page['texte']) ? $page['texte'] : ' '; |
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 158 | 158 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 159 | 159 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 160 | 160 | if ( |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 189 | 189 | . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -220,21 +220,21 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | if (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = get_class($val); |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
| 234 | 234 | } elseif (strstr($val, ' ')) { |
| 235 | 235 | $val = "'$val'"; |
| 236 | 236 | } |
| 237 | - $infos[] = $var . '=' . $val; |
|
| 237 | + $infos[] = $var.'='.$val; |
|
| 238 | 238 | } |
| 239 | 239 | return join(', ', $infos); |
| 240 | 240 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 303 | 303 | . texte_script($url) |
| 304 | 304 | . "','',$status);" |
| 305 | - . '?' . '>', |
|
| 305 | + . '?'.'>', |
|
| 306 | 306 | 'process_ins' => 'php', |
| 307 | 307 | 'status' => $status |
| 308 | 308 | ]; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -59,92 +59,92 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // https://code.spip.net/@argumenter_inclure |
| 61 | 61 | function argumenter_inclure( |
| 62 | - $params, |
|
| 63 | - $rejet_filtres, |
|
| 64 | - $p, |
|
| 65 | - &$boucles, |
|
| 66 | - $id_boucle, |
|
| 67 | - $echap = true, |
|
| 68 | - $lang = '', |
|
| 69 | - $fond1 = false |
|
| 62 | + $params, |
|
| 63 | + $rejet_filtres, |
|
| 64 | + $p, |
|
| 65 | + &$boucles, |
|
| 66 | + $id_boucle, |
|
| 67 | + $echap = true, |
|
| 68 | + $lang = '', |
|
| 69 | + $fond1 = false |
|
| 70 | 70 | ) { |
| 71 | - $l = []; |
|
| 72 | - $erreur_p_i_i = ''; |
|
| 73 | - if (!is_array($params)) { |
|
| 74 | - return $l; |
|
| 75 | - } |
|
| 76 | - foreach ($params as $k => $couple) { |
|
| 77 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | - $filtre = array_shift($couple); |
|
| 79 | - if ($filtre) { |
|
| 80 | - break; |
|
| 81 | - } |
|
| 82 | - foreach ($couple as $n => $val) { |
|
| 83 | - $var = $val[0]; |
|
| 84 | - if ($var->type != 'texte') { |
|
| 85 | - if ($n or $k or $fond1) { |
|
| 86 | - $erreur_p_i_i = [ |
|
| 87 | - 'zbug_parametres_inclus_incorrects', |
|
| 88 | - ['param' => $var->nom_champ] |
|
| 89 | - ]; |
|
| 90 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | - break; |
|
| 92 | - } else { |
|
| 93 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | - } |
|
| 95 | - } else { |
|
| 96 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | - $m = array_pad($m, 3, null); |
|
| 98 | - $var = $m[1]; |
|
| 99 | - $auto = false; |
|
| 71 | + $l = []; |
|
| 72 | + $erreur_p_i_i = ''; |
|
| 73 | + if (!is_array($params)) { |
|
| 74 | + return $l; |
|
| 75 | + } |
|
| 76 | + foreach ($params as $k => $couple) { |
|
| 77 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | + $filtre = array_shift($couple); |
|
| 79 | + if ($filtre) { |
|
| 80 | + break; |
|
| 81 | + } |
|
| 82 | + foreach ($couple as $n => $val) { |
|
| 83 | + $var = $val[0]; |
|
| 84 | + if ($var->type != 'texte') { |
|
| 85 | + if ($n or $k or $fond1) { |
|
| 86 | + $erreur_p_i_i = [ |
|
| 87 | + 'zbug_parametres_inclus_incorrects', |
|
| 88 | + ['param' => $var->nom_champ] |
|
| 89 | + ]; |
|
| 90 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | + break; |
|
| 92 | + } else { |
|
| 93 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | + } |
|
| 95 | + } else { |
|
| 96 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | + $m = array_pad($m, 3, null); |
|
| 98 | + $var = $m[1]; |
|
| 99 | + $auto = false; |
|
| 100 | 100 | ; |
| 101 | - if ($m[2]) { |
|
| 102 | - $v = $m[3]; |
|
| 103 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | - $v = $m[1]; |
|
| 105 | - } |
|
| 106 | - $val[0] = new Texte(); |
|
| 107 | - $val[0]->texte = $v; |
|
| 108 | - } elseif ($k or $n or $fond1) { |
|
| 109 | - $auto = true; |
|
| 110 | - } else { |
|
| 111 | - $var = 1; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($var == 'lang') { |
|
| 115 | - $lang = !$auto |
|
| 116 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | - : '$GLOBALS["spip_lang"]'; |
|
| 118 | - } else { |
|
| 119 | - $val = $auto |
|
| 120 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | - if ($var !== 1) { |
|
| 123 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 125 | - } else { |
|
| 126 | - $val = $echap ? "'.$val.'" : $val; |
|
| 127 | - } |
|
| 128 | - $l[$var] = $val; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($erreur_p_i_i) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | - // sauf si on n'en veut pas |
|
| 139 | - if ($lang === false) { |
|
| 140 | - return $l; |
|
| 141 | - } |
|
| 142 | - if (!$lang) { |
|
| 143 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | - } |
|
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | - |
|
| 147 | - return $l; |
|
| 101 | + if ($m[2]) { |
|
| 102 | + $v = $m[3]; |
|
| 103 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | + $v = $m[1]; |
|
| 105 | + } |
|
| 106 | + $val[0] = new Texte(); |
|
| 107 | + $val[0]->texte = $v; |
|
| 108 | + } elseif ($k or $n or $fond1) { |
|
| 109 | + $auto = true; |
|
| 110 | + } else { |
|
| 111 | + $var = 1; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($var == 'lang') { |
|
| 115 | + $lang = !$auto |
|
| 116 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | + : '$GLOBALS["spip_lang"]'; |
|
| 118 | + } else { |
|
| 119 | + $val = $auto |
|
| 120 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | + if ($var !== 1) { |
|
| 123 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | + . $val . ($echap ? ") . '" : ' '); |
|
| 125 | + } else { |
|
| 126 | + $val = $echap ? "'.$val.'" : $val; |
|
| 127 | + } |
|
| 128 | + $l[$var] = $val; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($erreur_p_i_i) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | + // sauf si on n'en veut pas |
|
| 139 | + if ($lang === false) { |
|
| 140 | + return $l; |
|
| 141 | + } |
|
| 142 | + if (!$lang) { |
|
| 143 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | + } |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | + |
|
| 147 | + return $l; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,83 +168,83 @@ discard block |
||
| 168 | 168 | **/ |
| 169 | 169 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 170 | 170 | |
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - '_request("connect")' |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + '_request("connect")' |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,173 +478,173 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $boucle = &$boucles[$id_boucle]; |
|
| 482 | - $return = $boucle->return; |
|
| 483 | - $type_boucle = $boucle->type_requete; |
|
| 484 | - $primary = $boucle->primary; |
|
| 485 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | - $corps = ''; |
|
| 488 | - |
|
| 489 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | - // et puis faire un [] plutot qu'un "','." |
|
| 491 | - if ($boucle->doublons) { |
|
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | - index_pile($id_boucle, $primary, $boucles) |
|
| 494 | - . "; // doublons\n"; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // La boucle doit-elle selectionner la langue ? |
|
| 498 | - // - par defaut, les boucles suivantes le font |
|
| 499 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | - if ( |
|
| 502 | - !$constant && $boucle->lang_select != 'non' && |
|
| 503 | - (($boucle->lang_select == 'oui') || |
|
| 504 | - in_array($type_boucle, [ |
|
| 505 | - 'articles', |
|
| 506 | - 'rubriques', |
|
| 507 | - 'hierarchie', |
|
| 508 | - 'breves' |
|
| 509 | - ])) |
|
| 510 | - ) { |
|
| 511 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | - // afin que le corps de boucle affecte la globale directement |
|
| 513 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | - $fin_lang = "lang_select();\n\t"; |
|
| 515 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | - |
|
| 517 | - $corps .= |
|
| 518 | - "\n\t\tlang_select_public(" |
|
| 519 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 521 | - . (in_array($type_boucle, [ |
|
| 522 | - 'articles', |
|
| 523 | - 'rubriques', |
|
| 524 | - 'hierarchie', |
|
| 525 | - 'breves' |
|
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | - . ');'; |
|
| 528 | - } else { |
|
| 529 | - $init_lang = ''; |
|
| 530 | - $fin_lang = ''; |
|
| 531 | - $fin_lang_select_public = ''; |
|
| 532 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | - if ( |
|
| 534 | - strpos($return, '?php') === false |
|
| 535 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | - ) { |
|
| 537 | - $i = 1; |
|
| 538 | - foreach ($r[1] as $t) { |
|
| 539 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | - $return = str_replace($t, "\$l$i", $return); |
|
| 541 | - $i++; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // gestion optimale des separateurs et des boucles constantes |
|
| 547 | - if (count($boucle->separateur)) { |
|
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $corps .= |
|
| 552 | - ((!$boucle->separateur) ? |
|
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 557 | - ((strpos($return, '$t1.') === 0) ? |
|
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | - |
|
| 563 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | - // souhaite invalider ces elements |
|
| 565 | - if (!$constant and $primary) { |
|
| 566 | - include_spip('inc/invalideur'); |
|
| 567 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // gerer le compteur de boucle |
|
| 571 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | - |
|
| 573 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | - . $boucle->partie |
|
| 576 | - . $corps; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // depiler la lang de la boucle si besoin |
|
| 580 | - $corps .= $fin_lang_select_public; |
|
| 581 | - |
|
| 582 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | - |
|
| 584 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | - if (!$boucle->numrows) { |
|
| 587 | - return "\n\t\$t0 = '';"; |
|
| 588 | - } else { |
|
| 589 | - $corps = ''; |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $boucle->numrows = true; |
|
| 593 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $count = ''; |
|
| 600 | - if (!$boucle->select) { |
|
| 601 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | - $count = '1'; |
|
| 603 | - } else { |
|
| 604 | - $count = 'count(*)'; |
|
| 605 | - } |
|
| 606 | - $boucles[$id_boucle]->select[] = $count; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if ($flag_cpt) { |
|
| 610 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | - } else { |
|
| 613 | - $nums = ''; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | - . $boucle->mode_partie |
|
| 620 | - . "\n\t"; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Ne calculer la requete que maintenant |
|
| 624 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | - |
|
| 626 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | - ? ("\n\t$init = array();") : '') |
|
| 628 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | - |
|
| 630 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | - |
|
| 632 | - $a = sprintf( |
|
| 633 | - CODE_CORPS_BOUCLE, |
|
| 634 | - $init, |
|
| 635 | - $boucle->iterateur, |
|
| 636 | - '$command', |
|
| 637 | - $contexte, |
|
| 638 | - $nums, |
|
| 639 | - $init_lang, |
|
| 640 | - $corps, |
|
| 641 | - $fin_lang, |
|
| 642 | - $trace, |
|
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | - ); |
|
| 481 | + $boucle = &$boucles[$id_boucle]; |
|
| 482 | + $return = $boucle->return; |
|
| 483 | + $type_boucle = $boucle->type_requete; |
|
| 484 | + $primary = $boucle->primary; |
|
| 485 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | + $corps = ''; |
|
| 488 | + |
|
| 489 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | + // et puis faire un [] plutot qu'un "','." |
|
| 491 | + if ($boucle->doublons) { |
|
| 492 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | + index_pile($id_boucle, $primary, $boucles) |
|
| 494 | + . "; // doublons\n"; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // La boucle doit-elle selectionner la langue ? |
|
| 498 | + // - par defaut, les boucles suivantes le font |
|
| 499 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | + if ( |
|
| 502 | + !$constant && $boucle->lang_select != 'non' && |
|
| 503 | + (($boucle->lang_select == 'oui') || |
|
| 504 | + in_array($type_boucle, [ |
|
| 505 | + 'articles', |
|
| 506 | + 'rubriques', |
|
| 507 | + 'hierarchie', |
|
| 508 | + 'breves' |
|
| 509 | + ])) |
|
| 510 | + ) { |
|
| 511 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | + // afin que le corps de boucle affecte la globale directement |
|
| 513 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | + $fin_lang = "lang_select();\n\t"; |
|
| 515 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | + |
|
| 517 | + $corps .= |
|
| 518 | + "\n\t\tlang_select_public(" |
|
| 519 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | + . ", '" . $boucle->lang_select . "'" |
|
| 521 | + . (in_array($type_boucle, [ |
|
| 522 | + 'articles', |
|
| 523 | + 'rubriques', |
|
| 524 | + 'hierarchie', |
|
| 525 | + 'breves' |
|
| 526 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | + . ');'; |
|
| 528 | + } else { |
|
| 529 | + $init_lang = ''; |
|
| 530 | + $fin_lang = ''; |
|
| 531 | + $fin_lang_select_public = ''; |
|
| 532 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | + if ( |
|
| 534 | + strpos($return, '?php') === false |
|
| 535 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | + ) { |
|
| 537 | + $i = 1; |
|
| 538 | + foreach ($r[1] as $t) { |
|
| 539 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | + $return = str_replace($t, "\$l$i", $return); |
|
| 541 | + $i++; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // gestion optimale des separateurs et des boucles constantes |
|
| 547 | + if (count($boucle->separateur)) { |
|
| 548 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $corps .= |
|
| 552 | + ((!$boucle->separateur) ? |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | + (($return === "''") ? '' : |
|
| 555 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | + ("\n\t\t\$t1 " . |
|
| 557 | + ((strpos($return, '$t1.') === 0) ? |
|
| 558 | + ('.=' . substr($return, 4)) : |
|
| 559 | + ('= ' . $return)) . |
|
| 560 | + ";\n\t\t" . |
|
| 561 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | + |
|
| 563 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | + // souhaite invalider ces elements |
|
| 565 | + if (!$constant and $primary) { |
|
| 566 | + include_spip('inc/invalideur'); |
|
| 567 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // gerer le compteur de boucle |
|
| 571 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | + |
|
| 573 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | + . $boucle->partie |
|
| 576 | + . $corps; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // depiler la lang de la boucle si besoin |
|
| 580 | + $corps .= $fin_lang_select_public; |
|
| 581 | + |
|
| 582 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | + |
|
| 584 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | + if (!$boucle->numrows) { |
|
| 587 | + return "\n\t\$t0 = '';"; |
|
| 588 | + } else { |
|
| 589 | + $corps = ''; |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $boucle->numrows = true; |
|
| 593 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $count = ''; |
|
| 600 | + if (!$boucle->select) { |
|
| 601 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | + $count = '1'; |
|
| 603 | + } else { |
|
| 604 | + $count = 'count(*)'; |
|
| 605 | + } |
|
| 606 | + $boucles[$id_boucle]->select[] = $count; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if ($flag_cpt) { |
|
| 610 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | + } else { |
|
| 613 | + $nums = ''; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | + . $boucle->mode_partie |
|
| 620 | + . "\n\t"; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Ne calculer la requete que maintenant |
|
| 624 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | + |
|
| 626 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | + ? ("\n\t$init = array();") : '') |
|
| 628 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | + |
|
| 630 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | + |
|
| 632 | + $a = sprintf( |
|
| 633 | + CODE_CORPS_BOUCLE, |
|
| 634 | + $init, |
|
| 635 | + $boucle->iterateur, |
|
| 636 | + '$command', |
|
| 637 | + $contexte, |
|
| 638 | + $nums, |
|
| 639 | + $init_lang, |
|
| 640 | + $corps, |
|
| 641 | + $fin_lang, |
|
| 642 | + $trace, |
|
| 643 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | + ); |
|
| 645 | 645 | |
| 646 | 646 | # var_dump($a);exit; |
| 647 | - return $a; |
|
| 647 | + return $a; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | |
@@ -660,47 +660,47 @@ discard block |
||
| 660 | 660 | * Code PHP compilé définissant les informations de requête |
| 661 | 661 | **/ |
| 662 | 662 | function calculer_requete_sql($boucle) { |
| 663 | - $init = []; |
|
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | - # En absence de champ c'est un decompte : |
|
| 667 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | - $init[] = calculer_dec( |
|
| 670 | - 'groupby', |
|
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | - ); |
|
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | - $init[] = calculer_dec( |
|
| 678 | - 'limit', |
|
| 679 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 680 | - "'" . $boucle->limit . "'" |
|
| 681 | - : |
|
| 682 | - $boucle->limit) |
|
| 683 | - ); |
|
| 684 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 685 | - $s = $d = ''; |
|
| 686 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 687 | - // ou recalculée à chaque passage (vide) |
|
| 688 | - foreach ($init as $i) { |
|
| 689 | - if (reset($i)) { |
|
| 690 | - $s .= "\n\t\t" . end($i); |
|
| 691 | - } # statique |
|
| 692 | - else { |
|
| 693 | - $d .= "\n\t" . end($i); |
|
| 694 | - } # dynamique |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 698 | - . $boucle->in |
|
| 699 | - . $boucle->hash |
|
| 700 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 701 | - . $s |
|
| 702 | - . "\n\t}" |
|
| 703 | - . $d; |
|
| 663 | + $init = []; |
|
| 664 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | + # En absence de champ c'est un decompte : |
|
| 667 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | + $init[] = calculer_dec( |
|
| 670 | + 'groupby', |
|
| 671 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | + ); |
|
| 673 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | + $init[] = calculer_dec( |
|
| 678 | + 'limit', |
|
| 679 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 680 | + "'" . $boucle->limit . "'" |
|
| 681 | + : |
|
| 682 | + $boucle->limit) |
|
| 683 | + ); |
|
| 684 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 685 | + $s = $d = ''; |
|
| 686 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 687 | + // ou recalculée à chaque passage (vide) |
|
| 688 | + foreach ($init as $i) { |
|
| 689 | + if (reset($i)) { |
|
| 690 | + $s .= "\n\t\t" . end($i); |
|
| 691 | + } # statique |
|
| 692 | + else { |
|
| 693 | + $d .= "\n\t" . end($i); |
|
| 694 | + } # dynamique |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 698 | + . $boucle->in |
|
| 699 | + . $boucle->hash |
|
| 700 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 701 | + . $s |
|
| 702 | + . "\n\t}" |
|
| 703 | + . $d; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
@@ -718,13 +718,13 @@ discard block |
||
| 718 | 718 | * qui peut être utilisé pour la production d'un tableau array() |
| 719 | 719 | **/ |
| 720 | 720 | function memoriser_contexte_compil($p) { |
| 721 | - return join(',', [ |
|
| 722 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 723 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 724 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 725 | - intval($p->ligne), |
|
| 726 | - '$GLOBALS[\'spip_lang\']' |
|
| 727 | - ]); |
|
| 721 | + return join(',', [ |
|
| 722 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 723 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 724 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 725 | + intval($p->ligne), |
|
| 726 | + '$GLOBALS[\'spip_lang\']' |
|
| 727 | + ]); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -742,19 +742,19 @@ discard block |
||
| 742 | 742 | * Objet Contexte |
| 743 | 743 | **/ |
| 744 | 744 | function reconstruire_contexte_compil($context_compil) { |
| 745 | - if (!is_array($context_compil)) { |
|
| 746 | - return $context_compil; |
|
| 747 | - } |
|
| 748 | - $p = new Contexte(); |
|
| 749 | - $p->descr = [ |
|
| 750 | - 'sourcefile' => $context_compil[0], |
|
| 751 | - 'nom' => $context_compil[1] |
|
| 752 | - ]; |
|
| 753 | - $p->id_boucle = $context_compil[2]; |
|
| 754 | - $p->ligne = $context_compil[3]; |
|
| 755 | - $p->lang = $context_compil[4]; |
|
| 756 | - |
|
| 757 | - return $p; |
|
| 745 | + if (!is_array($context_compil)) { |
|
| 746 | + return $context_compil; |
|
| 747 | + } |
|
| 748 | + $p = new Contexte(); |
|
| 749 | + $p->descr = [ |
|
| 750 | + 'sourcefile' => $context_compil[0], |
|
| 751 | + 'nom' => $context_compil[1] |
|
| 752 | + ]; |
|
| 753 | + $p->id_boucle = $context_compil[2]; |
|
| 754 | + $p->ligne = $context_compil[3]; |
|
| 755 | + $p->lang = $context_compil[4]; |
|
| 756 | + |
|
| 757 | + return $p; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
@@ -780,12 +780,12 @@ discard block |
||
| 780 | 780 | * - index 1 : Code de l'affectation |
| 781 | 781 | **/ |
| 782 | 782 | function calculer_dec($nom, $val) { |
| 783 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 784 | - // si une variable apparait dans le calcul de la clause |
|
| 785 | - // il faut la re-evaluer a chaque passage |
|
| 786 | - if ( |
|
| 787 | - strpos($val, '$') !== false |
|
| 788 | - /* |
|
| 783 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 784 | + // si une variable apparait dans le calcul de la clause |
|
| 785 | + // il faut la re-evaluer a chaque passage |
|
| 786 | + if ( |
|
| 787 | + strpos($val, '$') !== false |
|
| 788 | + /* |
|
| 789 | 789 | OR strpos($val, 'sql_') !== false |
| 790 | 790 | OR ( |
| 791 | 791 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 794 | 794 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 795 | 795 | )*/ |
| 796 | - ) { |
|
| 797 | - $static = ''; |
|
| 798 | - } |
|
| 796 | + ) { |
|
| 797 | + $static = ''; |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 800 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -817,33 +817,33 @@ discard block |
||
| 817 | 817 | * Expression PHP décrivant un texte ou un tableau |
| 818 | 818 | **/ |
| 819 | 819 | function calculer_dump_array($a) { |
| 820 | - if (!is_array($a)) { |
|
| 821 | - return $a; |
|
| 822 | - } |
|
| 823 | - $res = ''; |
|
| 824 | - if ($a and $a[0] == "'?'") { |
|
| 825 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 828 | - ')'); |
|
| 829 | - } else { |
|
| 830 | - foreach ($a as $k => $v) { |
|
| 831 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 836 | - } |
|
| 820 | + if (!is_array($a)) { |
|
| 821 | + return $a; |
|
| 822 | + } |
|
| 823 | + $res = ''; |
|
| 824 | + if ($a and $a[0] == "'?'") { |
|
| 825 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 828 | + ')'); |
|
| 829 | + } else { |
|
| 830 | + foreach ($a as $k => $v) { |
|
| 831 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 836 | + } |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | // https://code.spip.net/@calculer_dump_join |
| 840 | 840 | function calculer_dump_join($a) { |
| 841 | - $res = ''; |
|
| 842 | - foreach ($a as $k => $v) { |
|
| 843 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 844 | - } |
|
| 841 | + $res = ''; |
|
| 842 | + foreach ($a as $k => $v) { |
|
| 843 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | - return 'array(' . substr($res, 2) . ')'; |
|
| 846 | + return 'array(' . substr($res, 2) . ')'; |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -855,12 +855,12 @@ discard block |
||
| 855 | 855 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 856 | 856 | **/ |
| 857 | 857 | function calculer_from(&$boucle) { |
| 858 | - $res = ''; |
|
| 859 | - foreach ($boucle->from as $k => $v) { |
|
| 860 | - $res .= ",'$k' => '$v'"; |
|
| 861 | - } |
|
| 858 | + $res = ''; |
|
| 859 | + foreach ($boucle->from as $k => $v) { |
|
| 860 | + $res .= ",'$k' => '$v'"; |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - return 'array(' . substr($res, 1) . ')'; |
|
| 863 | + return 'array(' . substr($res, 1) . ')'; |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | /** |
@@ -873,31 +873,31 @@ discard block |
||
| 873 | 873 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 874 | 874 | **/ |
| 875 | 875 | function calculer_from_type(&$boucle) { |
| 876 | - $res = ''; |
|
| 877 | - foreach ($boucle->from_type as $k => $v) { |
|
| 878 | - $res .= ",'$k' => '$v'"; |
|
| 879 | - } |
|
| 876 | + $res = ''; |
|
| 877 | + foreach ($boucle->from_type as $k => $v) { |
|
| 878 | + $res .= ",'$k' => '$v'"; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - return 'array(' . substr($res, 1) . ')'; |
|
| 881 | + return 'array(' . substr($res, 1) . ')'; |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | // https://code.spip.net/@calculer_order |
| 885 | 885 | function calculer_order(&$boucle) { |
| 886 | - if ( |
|
| 887 | - !$order = $boucle->order |
|
| 888 | - and !$order = $boucle->default_order |
|
| 889 | - ) { |
|
| 890 | - $order = []; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 886 | + if ( |
|
| 887 | + !$order = $boucle->order |
|
| 888 | + and !$order = $boucle->default_order |
|
| 889 | + ) { |
|
| 890 | + $order = []; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 894 | 894 | $col = "." . $boucle->modificateur['collate']; |
| 895 | 895 | foreach($order as $k=>$o) |
| 896 | 896 | if (strpos($order[$k],'COLLATE')===false) |
| 897 | 897 | $order[$k].= $col; |
| 898 | 898 | }*/ |
| 899 | 899 | |
| 900 | - return join(', ', $order); |
|
| 900 | + return join(', ', $order); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -907,62 +907,62 @@ discard block |
||
| 907 | 907 | |
| 908 | 908 | // https://code.spip.net/@calculer_liste |
| 909 | 909 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 910 | - if (!$tableau) { |
|
| 911 | - return "''"; |
|
| 912 | - } |
|
| 913 | - if (is_string($descr)) { |
|
| 914 | - if (isset($boucles[$descr])) { |
|
| 915 | - $idb = $descr; |
|
| 916 | - $descr = []; |
|
| 917 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | - } |
|
| 920 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - else { |
|
| 925 | - $descr = []; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - if (!isset($descr['niv'])) { |
|
| 929 | - $descr['niv'] = 0; |
|
| 930 | - } |
|
| 931 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | - if ($codes === false) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - $n = count($codes); |
|
| 936 | - if (!$n) { |
|
| 937 | - return "''"; |
|
| 938 | - } |
|
| 939 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | - if ($n == 1) { |
|
| 942 | - return $codes[0]; |
|
| 943 | - } else { |
|
| 944 | - $res = ''; |
|
| 945 | - foreach ($codes as $code) { |
|
| 946 | - if ( |
|
| 947 | - !preg_match("/^'[^']*'$/", $code) |
|
| 948 | - or substr($res, -1, 1) !== "'" |
|
| 949 | - ) { |
|
| 950 | - $res .= " .\n$tab$code"; |
|
| 951 | - } else { |
|
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | - } |
|
| 958 | - } else { |
|
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | - |
|
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | - " ,\n$tab", |
|
| 963 | - $codes |
|
| 964 | - ) . ')))'; |
|
| 965 | - } |
|
| 910 | + if (!$tableau) { |
|
| 911 | + return "''"; |
|
| 912 | + } |
|
| 913 | + if (is_string($descr)) { |
|
| 914 | + if (isset($boucles[$descr])) { |
|
| 915 | + $idb = $descr; |
|
| 916 | + $descr = []; |
|
| 917 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | + } |
|
| 920 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + else { |
|
| 925 | + $descr = []; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + if (!isset($descr['niv'])) { |
|
| 929 | + $descr['niv'] = 0; |
|
| 930 | + } |
|
| 931 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | + if ($codes === false) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + $n = count($codes); |
|
| 936 | + if (!$n) { |
|
| 937 | + return "''"; |
|
| 938 | + } |
|
| 939 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | + if ($n == 1) { |
|
| 942 | + return $codes[0]; |
|
| 943 | + } else { |
|
| 944 | + $res = ''; |
|
| 945 | + foreach ($codes as $code) { |
|
| 946 | + if ( |
|
| 947 | + !preg_match("/^'[^']*'$/", $code) |
|
| 948 | + or substr($res, -1, 1) !== "'" |
|
| 949 | + ) { |
|
| 950 | + $res .= " .\n$tab$code"; |
|
| 951 | + } else { |
|
| 952 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | + } |
|
| 958 | + } else { |
|
| 959 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | + |
|
| 961 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | + " ,\n$tab", |
|
| 963 | + $codes |
|
| 964 | + ) . ')))'; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | |
@@ -973,213 +973,213 @@ discard block |
||
| 973 | 973 | // https://code.spip.net/@compile_cas |
| 974 | 974 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 975 | 975 | |
| 976 | - $codes = []; |
|
| 977 | - // cas de la boucle recursive |
|
| 978 | - if (is_array($id_boucle)) { |
|
| 979 | - $id_boucle = $id_boucle[0]; |
|
| 980 | - } |
|
| 981 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 982 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 983 | - $mode = _request('var_mode_affiche'); |
|
| 984 | - $err_e_c = ''; |
|
| 985 | - // chaque commentaire introduit dans le code doit commencer |
|
| 986 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 987 | - foreach ($tableau as $p) { |
|
| 988 | - switch ($p->type) { |
|
| 989 | - // texte seul |
|
| 990 | - case 'texte': |
|
| 991 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 992 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 993 | - $avant = ''; |
|
| 994 | - $apres = ''; |
|
| 995 | - $altern = "''"; |
|
| 996 | - break; |
|
| 997 | - |
|
| 998 | - case 'polyglotte': |
|
| 999 | - $code = ''; |
|
| 1000 | - foreach ($p->traductions as $k => $v) { |
|
| 1001 | - $code .= ",'" . |
|
| 1002 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | - "' => '" . |
|
| 1004 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1005 | - "'"; |
|
| 1006 | - } |
|
| 1007 | - $code = 'choisir_traduction(array(' . |
|
| 1008 | - substr($code, 1) . |
|
| 1009 | - '))'; |
|
| 1010 | - $commentaire = '&'; |
|
| 1011 | - $avant = ''; |
|
| 1012 | - $apres = ''; |
|
| 1013 | - $altern = "''"; |
|
| 1014 | - break; |
|
| 1015 | - |
|
| 1016 | - // inclure |
|
| 1017 | - case 'include': |
|
| 1018 | - $p->descr = $descr; |
|
| 1019 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1020 | - if ($code === false) { |
|
| 1021 | - $err_e_c = true; |
|
| 1022 | - $code = "''"; |
|
| 1023 | - } else { |
|
| 1024 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1025 | - $avant = ''; |
|
| 1026 | - $apres = ''; |
|
| 1027 | - $altern = "''"; |
|
| 1028 | - } |
|
| 1029 | - break; |
|
| 1030 | - |
|
| 1031 | - // boucle |
|
| 1032 | - case TYPE_RECURSIF: |
|
| 1033 | - $nom = $p->id_boucle; |
|
| 1034 | - $newdescr = $descr; |
|
| 1035 | - $newdescr['id_mere'] = $nom; |
|
| 1036 | - $newdescr['niv']++; |
|
| 1037 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1038 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1039 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1040 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1041 | - $newdescr['niv']--; |
|
| 1042 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1043 | - if ( |
|
| 1044 | - $preaff === false |
|
| 1045 | - or $avant === false |
|
| 1046 | - or $apres === false |
|
| 1047 | - or $altern === false |
|
| 1048 | - or $postaff === false |
|
| 1049 | - ) { |
|
| 1050 | - $err_e_c = true; |
|
| 1051 | - $code = "''"; |
|
| 1052 | - } else { |
|
| 1053 | - $code = 'BOUCLE' . |
|
| 1054 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1055 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1056 | - $commentaire = "?$nom"; |
|
| 1057 | - if ( |
|
| 1058 | - !$boucles[$nom]->milieu |
|
| 1059 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1060 | - ) { |
|
| 1061 | - if ($preaff != "''") { |
|
| 1062 | - $code .= "\n. $preaff"; |
|
| 1063 | - } |
|
| 1064 | - if ($altern != "''") { |
|
| 1065 | - $code .= "\n. $altern"; |
|
| 1066 | - } |
|
| 1067 | - if ($postaff != "''") { |
|
| 1068 | - $code .= "\n. $postaff"; |
|
| 1069 | - } |
|
| 1070 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1071 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1072 | - } |
|
| 1073 | - $avant = $apres = $altern = "''"; |
|
| 1074 | - } else { |
|
| 1075 | - if ($preaff != "''") { |
|
| 1076 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1077 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1078 | - } |
|
| 1079 | - if ($postaff != "''") { |
|
| 1080 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1081 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1082 | - } |
|
| 1083 | - if ($altern != "''") { |
|
| 1084 | - $altern = "($altern)"; |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - break; |
|
| 1089 | - |
|
| 1090 | - case 'idiome': |
|
| 1091 | - $l = []; |
|
| 1092 | - $code = ''; |
|
| 1093 | - foreach ($p->arg as $k => $v) { |
|
| 1094 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1095 | - if ($k) { |
|
| 1096 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1097 | - } else { |
|
| 1098 | - $code = $_v; |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1102 | - if ($p->module) { |
|
| 1103 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1104 | - } elseif ($p->nom_champ) { |
|
| 1105 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1106 | - } else { |
|
| 1107 | - $m = ''; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - $code = (!$code ? "'$m'" : |
|
| 1111 | - ($m ? "'$m' . $code" : |
|
| 1112 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1114 | - $code = "_T($code)"; |
|
| 1115 | - if ($p->param) { |
|
| 1116 | - $p->id_boucle = $id_boucle; |
|
| 1117 | - $p->boucles = &$boucles; |
|
| 1118 | - $code = compose_filtres($p, $code); |
|
| 1119 | - } |
|
| 1120 | - $commentaire = ':'; |
|
| 1121 | - $avant = ''; |
|
| 1122 | - $apres = ''; |
|
| 1123 | - $altern = "''"; |
|
| 1124 | - break; |
|
| 1125 | - |
|
| 1126 | - case 'champ': |
|
| 1127 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1128 | - $p->id_boucle = $id_boucle; |
|
| 1129 | - $p->boucles = &$boucles; |
|
| 1130 | - $p->descr = $descr; |
|
| 1131 | - #$p->interdire_scripts = true; |
|
| 1132 | - $p->type_requete = $type; |
|
| 1133 | - |
|
| 1134 | - $code = calculer_champ($p); |
|
| 1135 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1136 | - $avant = calculer_liste( |
|
| 1137 | - $p->avant, |
|
| 1138 | - $descr, |
|
| 1139 | - $boucles, |
|
| 1140 | - $id_boucle |
|
| 1141 | - ); |
|
| 1142 | - $apres = calculer_liste( |
|
| 1143 | - $p->apres, |
|
| 1144 | - $descr, |
|
| 1145 | - $boucles, |
|
| 1146 | - $id_boucle |
|
| 1147 | - ); |
|
| 1148 | - $altern = "''"; |
|
| 1149 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1150 | - // forcer la conversion en une chaine par strval |
|
| 1151 | - // si ca peut etre autre chose qu'une chaine |
|
| 1152 | - if ( |
|
| 1153 | - ($avant != "''" or $apres != "''") |
|
| 1154 | - and $code[0] != "'" |
|
| 976 | + $codes = []; |
|
| 977 | + // cas de la boucle recursive |
|
| 978 | + if (is_array($id_boucle)) { |
|
| 979 | + $id_boucle = $id_boucle[0]; |
|
| 980 | + } |
|
| 981 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 982 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 983 | + $mode = _request('var_mode_affiche'); |
|
| 984 | + $err_e_c = ''; |
|
| 985 | + // chaque commentaire introduit dans le code doit commencer |
|
| 986 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 987 | + foreach ($tableau as $p) { |
|
| 988 | + switch ($p->type) { |
|
| 989 | + // texte seul |
|
| 990 | + case 'texte': |
|
| 991 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 992 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 993 | + $avant = ''; |
|
| 994 | + $apres = ''; |
|
| 995 | + $altern = "''"; |
|
| 996 | + break; |
|
| 997 | + |
|
| 998 | + case 'polyglotte': |
|
| 999 | + $code = ''; |
|
| 1000 | + foreach ($p->traductions as $k => $v) { |
|
| 1001 | + $code .= ",'" . |
|
| 1002 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | + "' => '" . |
|
| 1004 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1005 | + "'"; |
|
| 1006 | + } |
|
| 1007 | + $code = 'choisir_traduction(array(' . |
|
| 1008 | + substr($code, 1) . |
|
| 1009 | + '))'; |
|
| 1010 | + $commentaire = '&'; |
|
| 1011 | + $avant = ''; |
|
| 1012 | + $apres = ''; |
|
| 1013 | + $altern = "''"; |
|
| 1014 | + break; |
|
| 1015 | + |
|
| 1016 | + // inclure |
|
| 1017 | + case 'include': |
|
| 1018 | + $p->descr = $descr; |
|
| 1019 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1020 | + if ($code === false) { |
|
| 1021 | + $err_e_c = true; |
|
| 1022 | + $code = "''"; |
|
| 1023 | + } else { |
|
| 1024 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1025 | + $avant = ''; |
|
| 1026 | + $apres = ''; |
|
| 1027 | + $altern = "''"; |
|
| 1028 | + } |
|
| 1029 | + break; |
|
| 1030 | + |
|
| 1031 | + // boucle |
|
| 1032 | + case TYPE_RECURSIF: |
|
| 1033 | + $nom = $p->id_boucle; |
|
| 1034 | + $newdescr = $descr; |
|
| 1035 | + $newdescr['id_mere'] = $nom; |
|
| 1036 | + $newdescr['niv']++; |
|
| 1037 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1038 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1039 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1040 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1041 | + $newdescr['niv']--; |
|
| 1042 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1043 | + if ( |
|
| 1044 | + $preaff === false |
|
| 1045 | + or $avant === false |
|
| 1046 | + or $apres === false |
|
| 1047 | + or $altern === false |
|
| 1048 | + or $postaff === false |
|
| 1049 | + ) { |
|
| 1050 | + $err_e_c = true; |
|
| 1051 | + $code = "''"; |
|
| 1052 | + } else { |
|
| 1053 | + $code = 'BOUCLE' . |
|
| 1054 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1055 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1056 | + $commentaire = "?$nom"; |
|
| 1057 | + if ( |
|
| 1058 | + !$boucles[$nom]->milieu |
|
| 1059 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1060 | + ) { |
|
| 1061 | + if ($preaff != "''") { |
|
| 1062 | + $code .= "\n. $preaff"; |
|
| 1063 | + } |
|
| 1064 | + if ($altern != "''") { |
|
| 1065 | + $code .= "\n. $altern"; |
|
| 1066 | + } |
|
| 1067 | + if ($postaff != "''") { |
|
| 1068 | + $code .= "\n. $postaff"; |
|
| 1069 | + } |
|
| 1070 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1071 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1072 | + } |
|
| 1073 | + $avant = $apres = $altern = "''"; |
|
| 1074 | + } else { |
|
| 1075 | + if ($preaff != "''") { |
|
| 1076 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1077 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1078 | + } |
|
| 1079 | + if ($postaff != "''") { |
|
| 1080 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1081 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1082 | + } |
|
| 1083 | + if ($altern != "''") { |
|
| 1084 | + $altern = "($altern)"; |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + break; |
|
| 1089 | + |
|
| 1090 | + case 'idiome': |
|
| 1091 | + $l = []; |
|
| 1092 | + $code = ''; |
|
| 1093 | + foreach ($p->arg as $k => $v) { |
|
| 1094 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1095 | + if ($k) { |
|
| 1096 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1097 | + } else { |
|
| 1098 | + $code = $_v; |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1102 | + if ($p->module) { |
|
| 1103 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1104 | + } elseif ($p->nom_champ) { |
|
| 1105 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1106 | + } else { |
|
| 1107 | + $m = ''; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + $code = (!$code ? "'$m'" : |
|
| 1111 | + ($m ? "'$m' . $code" : |
|
| 1112 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1114 | + $code = "_T($code)"; |
|
| 1115 | + if ($p->param) { |
|
| 1116 | + $p->id_boucle = $id_boucle; |
|
| 1117 | + $p->boucles = &$boucles; |
|
| 1118 | + $code = compose_filtres($p, $code); |
|
| 1119 | + } |
|
| 1120 | + $commentaire = ':'; |
|
| 1121 | + $avant = ''; |
|
| 1122 | + $apres = ''; |
|
| 1123 | + $altern = "''"; |
|
| 1124 | + break; |
|
| 1125 | + |
|
| 1126 | + case 'champ': |
|
| 1127 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1128 | + $p->id_boucle = $id_boucle; |
|
| 1129 | + $p->boucles = &$boucles; |
|
| 1130 | + $p->descr = $descr; |
|
| 1131 | + #$p->interdire_scripts = true; |
|
| 1132 | + $p->type_requete = $type; |
|
| 1133 | + |
|
| 1134 | + $code = calculer_champ($p); |
|
| 1135 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1136 | + $avant = calculer_liste( |
|
| 1137 | + $p->avant, |
|
| 1138 | + $descr, |
|
| 1139 | + $boucles, |
|
| 1140 | + $id_boucle |
|
| 1141 | + ); |
|
| 1142 | + $apres = calculer_liste( |
|
| 1143 | + $p->apres, |
|
| 1144 | + $descr, |
|
| 1145 | + $boucles, |
|
| 1146 | + $id_boucle |
|
| 1147 | + ); |
|
| 1148 | + $altern = "''"; |
|
| 1149 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1150 | + // forcer la conversion en une chaine par strval |
|
| 1151 | + // si ca peut etre autre chose qu'une chaine |
|
| 1152 | + if ( |
|
| 1153 | + ($avant != "''" or $apres != "''") |
|
| 1154 | + and $code[0] != "'" |
|
| 1155 | 1155 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1156 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1157 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1158 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1159 | - ) { |
|
| 1160 | - $code = "strval($code)"; |
|
| 1161 | - } |
|
| 1162 | - break; |
|
| 1163 | - |
|
| 1164 | - default: |
|
| 1165 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1166 | - $code = "''"; |
|
| 1167 | - $p->descr = $descr; |
|
| 1168 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1169 | - erreur_squelette($err_e_c, $p); |
|
| 1170 | - } // switch |
|
| 1171 | - |
|
| 1172 | - if ($code != "''") { |
|
| 1173 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1174 | - $codes[] = (($mode == 'validation') ? |
|
| 1175 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1176 | - : (($mode == 'code') ? |
|
| 1177 | - "\n// $commentaire\n$code" : |
|
| 1178 | - $code)); |
|
| 1179 | - } |
|
| 1180 | - } // foreach |
|
| 1181 | - |
|
| 1182 | - return $err_e_c ? false : $codes; |
|
| 1156 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1157 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1158 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1159 | + ) { |
|
| 1160 | + $code = "strval($code)"; |
|
| 1161 | + } |
|
| 1162 | + break; |
|
| 1163 | + |
|
| 1164 | + default: |
|
| 1165 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1166 | + $code = "''"; |
|
| 1167 | + $p->descr = $descr; |
|
| 1168 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1169 | + erreur_squelette($err_e_c, $p); |
|
| 1170 | + } // switch |
|
| 1171 | + |
|
| 1172 | + if ($code != "''") { |
|
| 1173 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1174 | + $codes[] = (($mode == 'validation') ? |
|
| 1175 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1176 | + : (($mode == 'code') ? |
|
| 1177 | + "\n// $commentaire\n$code" : |
|
| 1178 | + $code)); |
|
| 1179 | + } |
|
| 1180 | + } // foreach |
|
| 1181 | + |
|
| 1182 | + return $err_e_c ? false : $codes; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1189,13 +1189,13 @@ discard block |
||
| 1189 | 1189 | * @return string |
| 1190 | 1190 | */ |
| 1191 | 1191 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1192 | - if ($partie1 === "''") { |
|
| 1193 | - return $partie2; |
|
| 1194 | - } |
|
| 1195 | - if ($partie2 === "''") { |
|
| 1196 | - return $partie1; |
|
| 1197 | - } |
|
| 1198 | - return "$partie1\n. $partie2"; |
|
| 1192 | + if ($partie1 === "''") { |
|
| 1193 | + return $partie2; |
|
| 1194 | + } |
|
| 1195 | + if ($partie2 === "''") { |
|
| 1196 | + return $partie1; |
|
| 1197 | + } |
|
| 1198 | + return "$partie1\n. $partie2"; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | |
@@ -1220,56 +1220,56 @@ discard block |
||
| 1220 | 1220 | * @return mixed|string |
| 1221 | 1221 | */ |
| 1222 | 1222 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1223 | - if ($avant === "''") { |
|
| 1224 | - $avant = ''; |
|
| 1225 | - } |
|
| 1226 | - if ($apres === "''") { |
|
| 1227 | - $apres = ''; |
|
| 1228 | - } |
|
| 1229 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1230 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1231 | - $t = $code; |
|
| 1232 | - $cond = ''; |
|
| 1233 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1234 | - $t = $r[2]; |
|
| 1235 | - $cond = '!' . $r[1]; |
|
| 1236 | - } else { |
|
| 1237 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1238 | - $t = $r[2]; |
|
| 1239 | - $cond = $r[1]; |
|
| 1240 | - } else { |
|
| 1241 | - $t = '$t' . $n; |
|
| 1242 | - $cond = "($t = $code)!==''"; |
|
| 1243 | - } |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | - $t . |
|
| 1248 | - (!$apres ? '' : " . $apres"); |
|
| 1249 | - |
|
| 1250 | - if ($res !== $t) { |
|
| 1251 | - $res = "($res)"; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - return $code; |
|
| 1223 | + if ($avant === "''") { |
|
| 1224 | + $avant = ''; |
|
| 1225 | + } |
|
| 1226 | + if ($apres === "''") { |
|
| 1227 | + $apres = ''; |
|
| 1228 | + } |
|
| 1229 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1230 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1231 | + $t = $code; |
|
| 1232 | + $cond = ''; |
|
| 1233 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1234 | + $t = $r[2]; |
|
| 1235 | + $cond = '!' . $r[1]; |
|
| 1236 | + } else { |
|
| 1237 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1238 | + $t = $r[2]; |
|
| 1239 | + $cond = $r[1]; |
|
| 1240 | + } else { |
|
| 1241 | + $t = '$t' . $n; |
|
| 1242 | + $cond = "($t = $code)!==''"; |
|
| 1243 | + } |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | + $t . |
|
| 1248 | + (!$apres ? '' : " . $apres"); |
|
| 1249 | + |
|
| 1250 | + if ($res !== $t) { |
|
| 1251 | + $res = "($res)"; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + return $code; |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | |
| 1261 | 1261 | function compile_inclure_doublons($lexemes) { |
| 1262 | - foreach ($lexemes as $v) { |
|
| 1263 | - if ($v->type === 'include' and $v->param) { |
|
| 1264 | - foreach ($v->param as $r) { |
|
| 1265 | - if (trim($r[0]) === 'doublons') { |
|
| 1266 | - return true; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - return false; |
|
| 1262 | + foreach ($lexemes as $v) { |
|
| 1263 | + if ($v->type === 'include' and $v->param) { |
|
| 1264 | + foreach ($v->param as $r) { |
|
| 1265 | + if (trim($r[0]) === 'doublons') { |
|
| 1266 | + return true; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + return false; |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1289,360 +1289,360 @@ discard block |
||
| 1289 | 1289 | |
| 1290 | 1290 | // https://code.spip.net/@public_compiler_dist |
| 1291 | 1291 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1292 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1293 | - // Bonus : supprime le BOM |
|
| 1294 | - include_spip('inc/charsets'); |
|
| 1295 | - $squelette = transcoder_page($squelette); |
|
| 1296 | - |
|
| 1297 | - // rendre inertes les echappements de #[](){}<> |
|
| 1298 | - $i = 0; |
|
| 1299 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1300 | - $i++; |
|
| 1301 | - } |
|
| 1302 | - $squelette = preg_replace_callback( |
|
| 1303 | - ',\\\\([#[()\]{}<>]),', |
|
| 1304 | - function ($a) use ($inerte) { |
|
| 1305 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1306 | - }, |
|
| 1307 | - $squelette, |
|
| 1308 | - -1, |
|
| 1309 | - $esc |
|
| 1310 | - ); |
|
| 1311 | - |
|
| 1312 | - $descr = [ |
|
| 1313 | - 'nom' => $nom, |
|
| 1314 | - 'gram' => $gram, |
|
| 1315 | - 'sourcefile' => $sourcefile, |
|
| 1316 | - 'squelette' => $squelette |
|
| 1317 | - ]; |
|
| 1318 | - |
|
| 1319 | - // Phraser le squelette, selon sa grammaire |
|
| 1320 | - |
|
| 1321 | - $boucles = []; |
|
| 1322 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1323 | - |
|
| 1324 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1325 | - |
|
| 1326 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1327 | - |
|
| 1328 | - // restituer les echappements |
|
| 1329 | - if ($esc) { |
|
| 1330 | - foreach ($boucles as $i => $boucle) { |
|
| 1331 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1332 | - ",$inerte-(\d+)-,", |
|
| 1333 | - function ($a) { |
|
| 1334 | - return chr($a[1]); |
|
| 1335 | - }, |
|
| 1336 | - $boucle->return |
|
| 1337 | - ); |
|
| 1338 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1339 | - ",$inerte-(\d+)-,", |
|
| 1340 | - function ($a) { |
|
| 1341 | - return '\\\\' . chr($a[1]); |
|
| 1342 | - }, |
|
| 1343 | - $boucle->descr['squelette'] |
|
| 1344 | - ); |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | - if ($debug) { |
|
| 1350 | - include_spip('public/decompiler'); |
|
| 1351 | - foreach ($boucles as $id => $boucle) { |
|
| 1352 | - if ($id) { |
|
| 1353 | - $decomp = "\n/* BOUCLE " . |
|
| 1354 | - $boucle->type_requete . |
|
| 1355 | - ' ' . |
|
| 1356 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | - " */\n"; |
|
| 1359 | - } else { |
|
| 1360 | - $decomp = ("\n/*\n" . |
|
| 1361 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | - . "\n*/"); |
|
| 1363 | - } |
|
| 1364 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - return $boucles; |
|
| 1292 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1293 | + // Bonus : supprime le BOM |
|
| 1294 | + include_spip('inc/charsets'); |
|
| 1295 | + $squelette = transcoder_page($squelette); |
|
| 1296 | + |
|
| 1297 | + // rendre inertes les echappements de #[](){}<> |
|
| 1298 | + $i = 0; |
|
| 1299 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1300 | + $i++; |
|
| 1301 | + } |
|
| 1302 | + $squelette = preg_replace_callback( |
|
| 1303 | + ',\\\\([#[()\]{}<>]),', |
|
| 1304 | + function ($a) use ($inerte) { |
|
| 1305 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1306 | + }, |
|
| 1307 | + $squelette, |
|
| 1308 | + -1, |
|
| 1309 | + $esc |
|
| 1310 | + ); |
|
| 1311 | + |
|
| 1312 | + $descr = [ |
|
| 1313 | + 'nom' => $nom, |
|
| 1314 | + 'gram' => $gram, |
|
| 1315 | + 'sourcefile' => $sourcefile, |
|
| 1316 | + 'squelette' => $squelette |
|
| 1317 | + ]; |
|
| 1318 | + |
|
| 1319 | + // Phraser le squelette, selon sa grammaire |
|
| 1320 | + |
|
| 1321 | + $boucles = []; |
|
| 1322 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1323 | + |
|
| 1324 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1325 | + |
|
| 1326 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1327 | + |
|
| 1328 | + // restituer les echappements |
|
| 1329 | + if ($esc) { |
|
| 1330 | + foreach ($boucles as $i => $boucle) { |
|
| 1331 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1332 | + ",$inerte-(\d+)-,", |
|
| 1333 | + function ($a) { |
|
| 1334 | + return chr($a[1]); |
|
| 1335 | + }, |
|
| 1336 | + $boucle->return |
|
| 1337 | + ); |
|
| 1338 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1339 | + ",$inerte-(\d+)-,", |
|
| 1340 | + function ($a) { |
|
| 1341 | + return '\\\\' . chr($a[1]); |
|
| 1342 | + }, |
|
| 1343 | + $boucle->descr['squelette'] |
|
| 1344 | + ); |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | + if ($debug) { |
|
| 1350 | + include_spip('public/decompiler'); |
|
| 1351 | + foreach ($boucles as $id => $boucle) { |
|
| 1352 | + if ($id) { |
|
| 1353 | + $decomp = "\n/* BOUCLE " . |
|
| 1354 | + $boucle->type_requete . |
|
| 1355 | + ' ' . |
|
| 1356 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | + " */\n"; |
|
| 1359 | + } else { |
|
| 1360 | + $decomp = ("\n/*\n" . |
|
| 1361 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | + . "\n*/"); |
|
| 1363 | + } |
|
| 1364 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + return $boucles; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1373 | 1373 | // Autres specifications comme ci-dessus |
| 1374 | 1374 | |
| 1375 | 1375 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1376 | - static $trouver_table; |
|
| 1377 | - spip_timer('calcul_skel'); |
|
| 1378 | - |
|
| 1379 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | - |
|
| 1383 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - foreach ($boucles as $id => $boucle) { |
|
| 1388 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | - } |
|
| 1390 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | - |
|
| 1392 | - // Demander la description des tables une fois pour toutes |
|
| 1393 | - if (!$trouver_table) { |
|
| 1394 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - // reperer si les doublons sont demandes |
|
| 1398 | - // pour un inclure ou une boucle document |
|
| 1399 | - // c'est utile a la fonction champs_traitements |
|
| 1400 | - foreach ($boucles as $id => $boucle) { |
|
| 1401 | - if (!($type = $boucle->type_requete)) { |
|
| 1402 | - continue; |
|
| 1403 | - } |
|
| 1404 | - if ( |
|
| 1405 | - !$descr['documents'] and ( |
|
| 1406 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | - compile_inclure_doublons($boucle->avant) or |
|
| 1408 | - compile_inclure_doublons($boucle->apres) or |
|
| 1409 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | - compile_inclure_doublons($boucle->altern)) |
|
| 1411 | - ) { |
|
| 1412 | - $descr['documents'] = true; |
|
| 1413 | - } |
|
| 1414 | - if ($type != TYPE_RECURSIF) { |
|
| 1415 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | - if ( |
|
| 1421 | - $g = charger_fonction( |
|
| 1422 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | - 'iterateur', |
|
| 1424 | - true |
|
| 1425 | - ) |
|
| 1426 | - ) { |
|
| 1427 | - $boucles[$id] = $g($boucle); |
|
| 1428 | - |
|
| 1429 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | - // utiliser les informations donnees par le requeteur |
|
| 1431 | - // cas "php:xx" et "data:xx". |
|
| 1432 | - } else { |
|
| 1433 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | - $requeteur($boucles, $boucle, $id); |
|
| 1435 | - |
|
| 1436 | - // utiliser la description des champs transmis |
|
| 1437 | - } else { |
|
| 1438 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | - if ( |
|
| 1443 | - !$show |
|
| 1444 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | - ) { |
|
| 1446 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | - } |
|
| 1448 | - if ($show) { |
|
| 1449 | - $boucles[$id]->show = $show; |
|
| 1450 | - // recopie les infos les plus importantes |
|
| 1451 | - $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1452 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | - |
|
| 1456 | - if (empty($boucles[$id]->descr)) { |
|
| 1457 | - $boucles[$id]->descr = &$descr; |
|
| 1458 | - } |
|
| 1459 | - if ( |
|
| 1460 | - (!$boucles[$id]->jointures) |
|
| 1461 | - and is_array($show['tables_jointures']) |
|
| 1462 | - and count($x = $show['tables_jointures']) |
|
| 1463 | - ) { |
|
| 1464 | - $boucles[$id]->jointures = $x; |
|
| 1465 | - } |
|
| 1466 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | - while ($j = array_pop($jointures)) { |
|
| 1469 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1472 | - } else { |
|
| 1473 | - // Pas une erreur si la table est optionnelle |
|
| 1474 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | - $boucles[$id]->type_requete = ''; |
|
| 1476 | - } else { |
|
| 1477 | - $boucles[$id]->type_requete = false; |
|
| 1478 | - $boucle = $boucles[$id]; |
|
| 1479 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | - ($boucle->sql_serveur . ':')) . |
|
| 1481 | - $type; |
|
| 1482 | - $msg = [ |
|
| 1483 | - 'zbug_table_inconnue', |
|
| 1484 | - ['table' => $x] |
|
| 1485 | - ]; |
|
| 1486 | - erreur_squelette($msg, $boucle); |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | - foreach ($boucles as $id => $boucle) { |
|
| 1497 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | - $boucles[$id]->descr = &$descr; |
|
| 1499 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | - if (!$rec) { |
|
| 1501 | - $msg = [ |
|
| 1502 | - 'zbug_boucle_recursive_undef', |
|
| 1503 | - ['nom' => $boucle->param[0]] |
|
| 1504 | - ]; |
|
| 1505 | - erreur_squelette($msg, $boucle); |
|
| 1506 | - $boucles[$id]->type_requete = false; |
|
| 1507 | - } else { |
|
| 1508 | - $rec->externe = $id; |
|
| 1509 | - $descr['id_mere'] = $id; |
|
| 1510 | - $boucles[$id]->return = |
|
| 1511 | - calculer_liste( |
|
| 1512 | - [$rec], |
|
| 1513 | - $descr, |
|
| 1514 | - $boucles, |
|
| 1515 | - $boucle->param |
|
| 1516 | - ); |
|
| 1517 | - } |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - foreach ($boucles as $id => $boucle) { |
|
| 1521 | - $id = strval($id); // attention au type dans index_pile |
|
| 1522 | - $type = $boucle->type_requete; |
|
| 1523 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | - $res = ''; |
|
| 1525 | - if ($boucle->param) { |
|
| 1526 | - // retourne un tableau en cas d'erreur |
|
| 1527 | - $res = calculer_criteres($id, $boucles); |
|
| 1528 | - } |
|
| 1529 | - $descr['id_mere'] = $id; |
|
| 1530 | - $boucles[$id]->return = |
|
| 1531 | - calculer_liste( |
|
| 1532 | - $boucle->milieu, |
|
| 1533 | - $descr, |
|
| 1534 | - $boucles, |
|
| 1535 | - $id |
|
| 1536 | - ); |
|
| 1537 | - // Si les criteres se sont mal compiles |
|
| 1538 | - // ne pas tenter d'assembler le code final |
|
| 1539 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | - if (is_array($res)) { |
|
| 1541 | - $boucles[$id]->type_requete = false; |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // idem pour la racine |
|
| 1547 | - $descr['id_mere'] = ''; |
|
| 1548 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | - |
|
| 1550 | - |
|
| 1551 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | - // de'terminables seulement maintenant |
|
| 1554 | - |
|
| 1555 | - foreach ($boucles as $id => $boucle) { |
|
| 1556 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | - if ($boucle->return === false) { |
|
| 1558 | - $corps = false; |
|
| 1559 | - continue; |
|
| 1560 | - } |
|
| 1561 | - // appeler la fonction de definition de la boucle |
|
| 1562 | - |
|
| 1563 | - if ($req = $boucle->type_requete) { |
|
| 1564 | - // boucle personnalisée ? |
|
| 1565 | - $table = strtoupper($boucle->type_requete); |
|
| 1566 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | - if ( |
|
| 1568 | - // fonction de boucle avec serveur & table |
|
| 1569 | - (!$serveur or |
|
| 1570 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | - and (!function_exists($f = $f . '_dist')) |
|
| 1572 | - ) |
|
| 1573 | - ) |
|
| 1574 | - // fonction de boucle avec table |
|
| 1575 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | - and (!function_exists($f = $f . '_dist')) |
|
| 1577 | - ) { |
|
| 1578 | - // fonction de boucle standard |
|
| 1579 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | - "static \$connect;\n\t" . |
|
| 1586 | - "\$command['connect'] = \$connect = " . |
|
| 1587 | - _q($boucle->sql_serveur) . |
|
| 1588 | - ';' . |
|
| 1589 | - $f($id, $boucles); |
|
| 1590 | - } else { |
|
| 1591 | - $req = ("\n\treturn '';"); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - $boucles[$id]->return = |
|
| 1595 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | - $req . |
|
| 1598 | - "\n}\n"; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | - // retourner False, sinon inserer leur decompilation |
|
| 1603 | - if (is_bool($corps)) { |
|
| 1604 | - return false; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1376 | + static $trouver_table; |
|
| 1377 | + spip_timer('calcul_skel'); |
|
| 1378 | + |
|
| 1379 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | + |
|
| 1383 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + foreach ($boucles as $id => $boucle) { |
|
| 1388 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | + } |
|
| 1390 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | + |
|
| 1392 | + // Demander la description des tables une fois pour toutes |
|
| 1393 | + if (!$trouver_table) { |
|
| 1394 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + // reperer si les doublons sont demandes |
|
| 1398 | + // pour un inclure ou une boucle document |
|
| 1399 | + // c'est utile a la fonction champs_traitements |
|
| 1400 | + foreach ($boucles as $id => $boucle) { |
|
| 1401 | + if (!($type = $boucle->type_requete)) { |
|
| 1402 | + continue; |
|
| 1403 | + } |
|
| 1404 | + if ( |
|
| 1405 | + !$descr['documents'] and ( |
|
| 1406 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | + compile_inclure_doublons($boucle->avant) or |
|
| 1408 | + compile_inclure_doublons($boucle->apres) or |
|
| 1409 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | + compile_inclure_doublons($boucle->altern)) |
|
| 1411 | + ) { |
|
| 1412 | + $descr['documents'] = true; |
|
| 1413 | + } |
|
| 1414 | + if ($type != TYPE_RECURSIF) { |
|
| 1415 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | + if ( |
|
| 1421 | + $g = charger_fonction( |
|
| 1422 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | + 'iterateur', |
|
| 1424 | + true |
|
| 1425 | + ) |
|
| 1426 | + ) { |
|
| 1427 | + $boucles[$id] = $g($boucle); |
|
| 1428 | + |
|
| 1429 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | + // utiliser les informations donnees par le requeteur |
|
| 1431 | + // cas "php:xx" et "data:xx". |
|
| 1432 | + } else { |
|
| 1433 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | + $requeteur($boucles, $boucle, $id); |
|
| 1435 | + |
|
| 1436 | + // utiliser la description des champs transmis |
|
| 1437 | + } else { |
|
| 1438 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | + if ( |
|
| 1443 | + !$show |
|
| 1444 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | + ) { |
|
| 1446 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | + } |
|
| 1448 | + if ($show) { |
|
| 1449 | + $boucles[$id]->show = $show; |
|
| 1450 | + // recopie les infos les plus importantes |
|
| 1451 | + $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1452 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | + |
|
| 1456 | + if (empty($boucles[$id]->descr)) { |
|
| 1457 | + $boucles[$id]->descr = &$descr; |
|
| 1458 | + } |
|
| 1459 | + if ( |
|
| 1460 | + (!$boucles[$id]->jointures) |
|
| 1461 | + and is_array($show['tables_jointures']) |
|
| 1462 | + and count($x = $show['tables_jointures']) |
|
| 1463 | + ) { |
|
| 1464 | + $boucles[$id]->jointures = $x; |
|
| 1465 | + } |
|
| 1466 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | + while ($j = array_pop($jointures)) { |
|
| 1469 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | + } else { |
|
| 1473 | + // Pas une erreur si la table est optionnelle |
|
| 1474 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | + $boucles[$id]->type_requete = ''; |
|
| 1476 | + } else { |
|
| 1477 | + $boucles[$id]->type_requete = false; |
|
| 1478 | + $boucle = $boucles[$id]; |
|
| 1479 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | + ($boucle->sql_serveur . ':')) . |
|
| 1481 | + $type; |
|
| 1482 | + $msg = [ |
|
| 1483 | + 'zbug_table_inconnue', |
|
| 1484 | + ['table' => $x] |
|
| 1485 | + ]; |
|
| 1486 | + erreur_squelette($msg, $boucle); |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | + foreach ($boucles as $id => $boucle) { |
|
| 1497 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | + $boucles[$id]->descr = &$descr; |
|
| 1499 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | + if (!$rec) { |
|
| 1501 | + $msg = [ |
|
| 1502 | + 'zbug_boucle_recursive_undef', |
|
| 1503 | + ['nom' => $boucle->param[0]] |
|
| 1504 | + ]; |
|
| 1505 | + erreur_squelette($msg, $boucle); |
|
| 1506 | + $boucles[$id]->type_requete = false; |
|
| 1507 | + } else { |
|
| 1508 | + $rec->externe = $id; |
|
| 1509 | + $descr['id_mere'] = $id; |
|
| 1510 | + $boucles[$id]->return = |
|
| 1511 | + calculer_liste( |
|
| 1512 | + [$rec], |
|
| 1513 | + $descr, |
|
| 1514 | + $boucles, |
|
| 1515 | + $boucle->param |
|
| 1516 | + ); |
|
| 1517 | + } |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + foreach ($boucles as $id => $boucle) { |
|
| 1521 | + $id = strval($id); // attention au type dans index_pile |
|
| 1522 | + $type = $boucle->type_requete; |
|
| 1523 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | + $res = ''; |
|
| 1525 | + if ($boucle->param) { |
|
| 1526 | + // retourne un tableau en cas d'erreur |
|
| 1527 | + $res = calculer_criteres($id, $boucles); |
|
| 1528 | + } |
|
| 1529 | + $descr['id_mere'] = $id; |
|
| 1530 | + $boucles[$id]->return = |
|
| 1531 | + calculer_liste( |
|
| 1532 | + $boucle->milieu, |
|
| 1533 | + $descr, |
|
| 1534 | + $boucles, |
|
| 1535 | + $id |
|
| 1536 | + ); |
|
| 1537 | + // Si les criteres se sont mal compiles |
|
| 1538 | + // ne pas tenter d'assembler le code final |
|
| 1539 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | + if (is_array($res)) { |
|
| 1541 | + $boucles[$id]->type_requete = false; |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // idem pour la racine |
|
| 1547 | + $descr['id_mere'] = ''; |
|
| 1548 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | + |
|
| 1550 | + |
|
| 1551 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | + // de'terminables seulement maintenant |
|
| 1554 | + |
|
| 1555 | + foreach ($boucles as $id => $boucle) { |
|
| 1556 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | + if ($boucle->return === false) { |
|
| 1558 | + $corps = false; |
|
| 1559 | + continue; |
|
| 1560 | + } |
|
| 1561 | + // appeler la fonction de definition de la boucle |
|
| 1562 | + |
|
| 1563 | + if ($req = $boucle->type_requete) { |
|
| 1564 | + // boucle personnalisée ? |
|
| 1565 | + $table = strtoupper($boucle->type_requete); |
|
| 1566 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | + if ( |
|
| 1568 | + // fonction de boucle avec serveur & table |
|
| 1569 | + (!$serveur or |
|
| 1570 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | + and (!function_exists($f = $f . '_dist')) |
|
| 1572 | + ) |
|
| 1573 | + ) |
|
| 1574 | + // fonction de boucle avec table |
|
| 1575 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | + and (!function_exists($f = $f . '_dist')) |
|
| 1577 | + ) { |
|
| 1578 | + // fonction de boucle standard |
|
| 1579 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | + "static \$connect;\n\t" . |
|
| 1586 | + "\$command['connect'] = \$connect = " . |
|
| 1587 | + _q($boucle->sql_serveur) . |
|
| 1588 | + ';' . |
|
| 1589 | + $f($id, $boucles); |
|
| 1590 | + } else { |
|
| 1591 | + $req = ("\n\treturn '';"); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + $boucles[$id]->return = |
|
| 1595 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | + $req . |
|
| 1598 | + "\n}\n"; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | + // retourner False, sinon inserer leur decompilation |
|
| 1603 | + if (is_bool($corps)) { |
|
| 1604 | + return false; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1608 | 1608 | ' |
| 1609 | - // reporter de maniere securisee les doublons inclus |
|
| 1610 | - . ' |
|
| 1609 | + // reporter de maniere securisee les doublons inclus |
|
| 1610 | + . ' |
|
| 1611 | 1611 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1612 | 1612 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1613 | 1613 | |
| 1614 | 1614 | $connect = ' . |
| 1615 | - _q($connect) . '; |
|
| 1615 | + _q($connect) . '; |
|
| 1616 | 1616 | $page = ' . |
| 1617 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | - // avant de referencer $Cache |
|
| 1620 | - $corps . '; |
|
| 1617 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | + // avant de referencer $Cache |
|
| 1620 | + $corps . '; |
|
| 1621 | 1621 | |
| 1622 | 1622 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1623 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1623 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1624 | 1624 | }'; |
| 1625 | 1625 | |
| 1626 | - $secondes = spip_timer('calcul_skel'); |
|
| 1627 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | - // $connect n'est pas sûr : on nettoie |
|
| 1629 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1626 | + $secondes = spip_timer('calcul_skel'); |
|
| 1627 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | + // $connect n'est pas sûr : on nettoie |
|
| 1629 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1630 | 1630 | |
| 1631 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | - $code = new Boucle(); |
|
| 1633 | - $code->descr = $descr; |
|
| 1634 | - $code->return = ' |
|
| 1631 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | + $code = new Boucle(); |
|
| 1633 | + $code->descr = $descr; |
|
| 1634 | + $code->return = ' |
|
| 1635 | 1635 | // |
| 1636 | 1636 | // Fonction principale du squelette ' . |
| 1637 | - $sourcefile . |
|
| 1638 | - ($connect ? " pour $connect" : '') . |
|
| 1639 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | - "\n//\n" . |
|
| 1641 | - $principal; |
|
| 1637 | + $sourcefile . |
|
| 1638 | + ($connect ? " pour $connect" : '') . |
|
| 1639 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | + "\n//\n" . |
|
| 1641 | + $principal; |
|
| 1642 | 1642 | |
| 1643 | - $boucles[''] = $code; |
|
| 1643 | + $boucles[''] = $code; |
|
| 1644 | 1644 | |
| 1645 | - return $boucles; |
|
| 1645 | + return $boucles; |
|
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | |
@@ -1659,18 +1659,18 @@ discard block |
||
| 1659 | 1659 | * |
| 1660 | 1660 | **/ |
| 1661 | 1661 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1662 | - if (class_exists($boucle->type_requete)) { |
|
| 1663 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | - } else { |
|
| 1666 | - $x = $boucle->type_requete; |
|
| 1667 | - $boucle->type_requete = false; |
|
| 1668 | - $msg = [ |
|
| 1669 | - 'zbug_iterateur_inconnu', |
|
| 1670 | - ['iterateur' => $x] |
|
| 1671 | - ]; |
|
| 1672 | - erreur_squelette($msg, $boucle); |
|
| 1673 | - } |
|
| 1662 | + if (class_exists($boucle->type_requete)) { |
|
| 1663 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | + } else { |
|
| 1666 | + $x = $boucle->type_requete; |
|
| 1667 | + $boucle->type_requete = false; |
|
| 1668 | + $msg = [ |
|
| 1669 | + 'zbug_iterateur_inconnu', |
|
| 1670 | + ['iterateur' => $x] |
|
| 1671 | + ]; |
|
| 1672 | + erreur_squelette($msg, $boucle); |
|
| 1673 | + } |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | |
@@ -1688,22 +1688,22 @@ discard block |
||
| 1688 | 1688 | * |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1691 | - include_spip('iterateur/data'); |
|
| 1692 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | - $boucles[$id] = $g($boucle); |
|
| 1695 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | - } else { |
|
| 1698 | - $x = $boucle->type_requete; |
|
| 1699 | - $boucle->type_requete = false; |
|
| 1700 | - $msg = [ |
|
| 1701 | - 'zbug_requeteur_inconnu', |
|
| 1702 | - [ |
|
| 1703 | - 'requeteur' => 'data', |
|
| 1704 | - 'type' => $x |
|
| 1705 | - ] |
|
| 1706 | - ]; |
|
| 1707 | - erreur_squelette($msg, $boucle); |
|
| 1708 | - } |
|
| 1691 | + include_spip('iterateur/data'); |
|
| 1692 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | + $boucles[$id] = $g($boucle); |
|
| 1695 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | + } else { |
|
| 1698 | + $x = $boucle->type_requete; |
|
| 1699 | + $boucle->type_requete = false; |
|
| 1700 | + $msg = [ |
|
| 1701 | + 'zbug_requeteur_inconnu', |
|
| 1702 | + [ |
|
| 1703 | + 'requeteur' => 'data', |
|
| 1704 | + 'type' => $x |
|
| 1705 | + ] |
|
| 1706 | + ]; |
|
| 1707 | + erreur_squelette($msg, $boucle); |
|
| 1708 | + } |
|
| 1709 | 1709 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 122 | 122 | if ($var !== 1) { |
| 123 | 123 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + . $val.($echap ? ") . '" : ' '); |
|
| 125 | 125 | } else { |
| 126 | 126 | $val = $echap ? "'.$val.'" : $val; |
| 127 | 127 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (!$lang) { |
| 143 | 143 | $lang = '$GLOBALS["spip_lang"]'; |
| 144 | 144 | } |
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : ' '); |
|
| 146 | 146 | |
| 147 | 147 | return $l; |
| 148 | 148 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 174 | + $code = '"'.str_replace('"', '\"', $fichier).'"'; |
|
| 175 | 175 | } else { |
| 176 | 176 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
| 177 | 177 | if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | return false; |
| 221 | 221 | } // j'aurais voulu toucher le fond ... |
| 222 | 222 | |
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 223 | + $contexte = 'array('.$_contexte.')'; |
|
| 224 | 224 | |
| 225 | 225 | if ($env) { |
| 226 | 226 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | $_options[] = $ajax; |
| 236 | 236 | } |
| 237 | 237 | $code = " ' . argumenter_squelette($code) . '"; |
| 238 | - $code = 'echo ' . sprintf( |
|
| 238 | + $code = 'echo '.sprintf( |
|
| 239 | 239 | CODE_RECUPERER_FOND, |
| 240 | 240 | $code, |
| 241 | 241 | $contexte, |
| 242 | 242 | implode(',', $_options), |
| 243 | 243 | '_request("connect")' |
| 244 | - ) . ';'; |
|
| 244 | + ).';'; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 247 | + return "\n'<'.'".'?php '.$code."\n?'."."'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $id = $id_table; |
| 325 | 325 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 326 | 326 | } |
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 327 | + $mstatut = $id.'.'.$statut; |
|
| 328 | 328 | |
| 329 | 329 | $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
| 330 | 330 | include_spip('public/quete'); |
@@ -332,11 +332,11 @@ discard block |
||
| 332 | 332 | isset($s['post_date']) and $s['post_date'] |
| 333 | 333 | and $GLOBALS['meta']['post_dates'] == 'non' |
| 334 | 334 | ) { |
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 335 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | 336 | array_unshift( |
| 337 | 337 | $boucle->where, |
| 338 | 338 | $echapper ? |
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 339 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 340 | 340 | : |
| 341 | 341 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 342 | 342 | ); |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | $boucle->where, |
| 346 | 346 | $echapper ? |
| 347 | 347 | "\nquete_condition_statut('$mstatut'," |
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 348 | + . _q($s['previsu']).',' |
|
| 349 | + . _q($s['publie']).',' |
|
| 350 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 351 | 351 | : |
| 352 | 352 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 353 | 353 | ); |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | if (_request('var_mode_affiche') != 'resultat') { |
| 382 | 382 | $trace = ''; |
| 383 | 383 | } else { |
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 385 | 385 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 386 | 386 | $trace = " |
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | - $_trace" . '[] = $t0; |
|
| 391 | + $_trace".'[] = $t0; |
|
| 392 | 392 | }'; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | return |
| 423 | 423 | // Numrows[$nom] peut ne pas être encore defini |
| 424 | 424 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 425 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.';' |
|
| 426 | 426 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 427 | 427 | . $trace |
| 428 | 428 | . "\n\treturn \$t0;"; |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 490 | 490 | // et puis faire un [] plutot qu'un "','." |
| 491 | 491 | if ($boucle->doublons) { |
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 492 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 493 | 493 | index_pile($id_boucle, $primary, $boucles) |
| 494 | 494 | . "; // doublons\n"; |
| 495 | 495 | } |
@@ -517,13 +517,13 @@ discard block |
||
| 517 | 517 | $corps .= |
| 518 | 518 | "\n\t\tlang_select_public(" |
| 519 | 519 | . index_pile($id_boucle, 'lang', $boucles) |
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 520 | + . ", '".$boucle->lang_select."'" |
|
| 521 | 521 | . (in_array($type_boucle, [ |
| 522 | 522 | 'articles', |
| 523 | 523 | 'rubriques', |
| 524 | 524 | 'hierarchie', |
| 525 | 525 | 'breves' |
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 526 | + ]) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | 527 | . ');'; |
| 528 | 528 | } else { |
| 529 | 529 | $init_lang = ''; |
@@ -545,20 +545,16 @@ discard block |
||
| 545 | 545 | |
| 546 | 546 | // gestion optimale des separateurs et des boucles constantes |
| 547 | 547 | if (count($boucle->separateur)) { |
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 548 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | $corps .= |
| 552 | 552 | ((!$boucle->separateur) ? |
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.';'))) : ("\n\t\t\$t1 ". |
|
| 557 | 554 | ((strpos($return, '$t1.') === 0) ? |
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 555 | + ('.='.substr($return, 4)) : ('= '.$return)). |
|
| 556 | + ";\n\t\t". |
|
| 557 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 562 | 558 | |
| 563 | 559 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 564 | 560 | // souhaite invalider ces elements |
@@ -640,7 +636,7 @@ discard block |
||
| 640 | 636 | $corps, |
| 641 | 637 | $fin_lang, |
| 642 | 638 | $trace, |
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 639 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 644 | 640 | ); |
| 645 | 641 | |
| 646 | 642 | # var_dump($a);exit; |
@@ -661,23 +657,23 @@ discard block |
||
| 661 | 657 | **/ |
| 662 | 658 | function calculer_requete_sql($boucle) { |
| 663 | 659 | $init = []; |
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 660 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 661 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 666 | 662 | # En absence de champ c'est un decompte : |
| 667 | 663 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 668 | 664 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 669 | 665 | $init[] = calculer_dec( |
| 670 | 666 | 'groupby', |
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 667 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').')' |
|
| 672 | 668 | ); |
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 669 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select).'")'); |
|
| 670 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).')'); |
|
| 675 | 671 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 676 | 672 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 677 | 673 | $init[] = calculer_dec( |
| 678 | 674 | 'limit', |
| 679 | 675 | (strpos($boucle->limit, 'intval') === false ? |
| 680 | - "'" . $boucle->limit . "'" |
|
| 676 | + "'".$boucle->limit."'" |
|
| 681 | 677 | : |
| 682 | 678 | $boucle->limit) |
| 683 | 679 | ); |
@@ -687,17 +683,17 @@ discard block |
||
| 687 | 683 | // ou recalculée à chaque passage (vide) |
| 688 | 684 | foreach ($init as $i) { |
| 689 | 685 | if (reset($i)) { |
| 690 | - $s .= "\n\t\t" . end($i); |
|
| 686 | + $s .= "\n\t\t".end($i); |
|
| 691 | 687 | } # statique |
| 692 | 688 | else { |
| 693 | - $d .= "\n\t" . end($i); |
|
| 689 | + $d .= "\n\t".end($i); |
|
| 694 | 690 | } # dynamique |
| 695 | 691 | } |
| 696 | 692 | |
| 697 | 693 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 698 | 694 | . $boucle->in |
| 699 | 695 | . $boucle->hash |
| 700 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 696 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 701 | 697 | . $s |
| 702 | 698 | . "\n\t}" |
| 703 | 699 | . $d; |
@@ -780,7 +776,7 @@ discard block |
||
| 780 | 776 | * - index 1 : Code de l'affectation |
| 781 | 777 | **/ |
| 782 | 778 | function calculer_dec($nom, $val) { |
| 783 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 779 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 784 | 780 | // si une variable apparait dans le calcul de la clause |
| 785 | 781 | // il faut la re-evaluer a chaque passage |
| 786 | 782 | if ( |
@@ -797,7 +793,7 @@ discard block |
||
| 797 | 793 | $static = ''; |
| 798 | 794 | } |
| 799 | 795 | |
| 800 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 796 | + return [$static, '$command[\''.$nom.'\'] = '.$val.';']; |
|
| 801 | 797 | } |
| 802 | 798 | |
| 803 | 799 | /** |
@@ -822,17 +818,17 @@ discard block |
||
| 822 | 818 | } |
| 823 | 819 | $res = ''; |
| 824 | 820 | if ($a and $a[0] == "'?'") { |
| 825 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 821 | + return ('('.calculer_dump_array($a[1]). |
|
| 822 | + ' ? '.calculer_dump_array($a[2]). |
|
| 823 | + ' : '.calculer_dump_array($a[3]). |
|
| 828 | 824 | ')'); |
| 829 | 825 | } else { |
| 830 | 826 | foreach ($a as $k => $v) { |
| 831 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 827 | + $showk = (is_numeric($k) ? '' : sql_quote($k).' => '); |
|
| 828 | + $res .= ', '.$showk.calculer_dump_array($v); |
|
| 833 | 829 | } |
| 834 | 830 | |
| 835 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 831 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 836 | 832 | } |
| 837 | 833 | } |
| 838 | 834 | |
@@ -840,10 +836,10 @@ discard block |
||
| 840 | 836 | function calculer_dump_join($a) { |
| 841 | 837 | $res = ''; |
| 842 | 838 | foreach ($a as $k => $v) { |
| 843 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 839 | + $res .= ", '$k' => array(".implode(',', $v).')'; |
|
| 844 | 840 | } |
| 845 | 841 | |
| 846 | - return 'array(' . substr($res, 2) . ')'; |
|
| 842 | + return 'array('.substr($res, 2).')'; |
|
| 847 | 843 | } |
| 848 | 844 | |
| 849 | 845 | /** |
@@ -860,7 +856,7 @@ discard block |
||
| 860 | 856 | $res .= ",'$k' => '$v'"; |
| 861 | 857 | } |
| 862 | 858 | |
| 863 | - return 'array(' . substr($res, 1) . ')'; |
|
| 859 | + return 'array('.substr($res, 1).')'; |
|
| 864 | 860 | } |
| 865 | 861 | |
| 866 | 862 | /** |
@@ -878,7 +874,7 @@ discard block |
||
| 878 | 874 | $res .= ",'$k' => '$v'"; |
| 879 | 875 | } |
| 880 | 876 | |
| 881 | - return 'array(' . substr($res, 1) . ')'; |
|
| 877 | + return 'array('.substr($res, 1).')'; |
|
| 882 | 878 | } |
| 883 | 879 | |
| 884 | 880 | // https://code.spip.net/@calculer_order |
@@ -949,19 +945,19 @@ discard block |
||
| 949 | 945 | ) { |
| 950 | 946 | $res .= " .\n$tab$code"; |
| 951 | 947 | } else { |
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 948 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 953 | 949 | } |
| 954 | 950 | } |
| 955 | 951 | |
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 952 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 957 | 953 | } |
| 958 | 954 | } else { |
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 955 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | 956 | |
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 957 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join( |
|
| 962 | 958 | " ,\n$tab", |
| 963 | 959 | $codes |
| 964 | - ) . ')))'; |
|
| 960 | + ).')))'; |
|
| 965 | 961 | } |
| 966 | 962 | } |
| 967 | 963 | |
@@ -989,7 +985,7 @@ discard block |
||
| 989 | 985 | // texte seul |
| 990 | 986 | case 'texte': |
| 991 | 987 | $code = sandbox_composer_texte($p->texte, $p); |
| 992 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 988 | + $commentaire = strlen($p->texte).' signes'; |
|
| 993 | 989 | $avant = ''; |
| 994 | 990 | $apres = ''; |
| 995 | 991 | $altern = "''"; |
@@ -998,14 +994,14 @@ discard block |
||
| 998 | 994 | case 'polyglotte': |
| 999 | 995 | $code = ''; |
| 1000 | 996 | foreach ($p->traductions as $k => $v) { |
| 1001 | - $code .= ",'" . |
|
| 1002 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | - "' => '" . |
|
| 1004 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 997 | + $code .= ",'". |
|
| 998 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k). |
|
| 999 | + "' => '". |
|
| 1000 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v). |
|
| 1005 | 1001 | "'"; |
| 1006 | 1002 | } |
| 1007 | - $code = 'choisir_traduction(array(' . |
|
| 1008 | - substr($code, 1) . |
|
| 1003 | + $code = 'choisir_traduction(array('. |
|
| 1004 | + substr($code, 1). |
|
| 1009 | 1005 | '))'; |
| 1010 | 1006 | $commentaire = '&'; |
| 1011 | 1007 | $avant = ''; |
@@ -1021,7 +1017,7 @@ discard block |
||
| 1021 | 1017 | $err_e_c = true; |
| 1022 | 1018 | $code = "''"; |
| 1023 | 1019 | } else { |
| 1024 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1020 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 1025 | 1021 | $avant = ''; |
| 1026 | 1022 | $apres = ''; |
| 1027 | 1023 | $altern = "''"; |
@@ -1050,8 +1046,8 @@ discard block |
||
| 1050 | 1046 | $err_e_c = true; |
| 1051 | 1047 | $code = "''"; |
| 1052 | 1048 | } else { |
| 1053 | - $code = 'BOUCLE' . |
|
| 1054 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1049 | + $code = 'BOUCLE'. |
|
| 1050 | + str_replace('-', '_', $nom).$descr['nom']. |
|
| 1055 | 1051 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1056 | 1052 | $commentaire = "?$nom"; |
| 1057 | 1053 | if ( |
@@ -1093,24 +1089,22 @@ discard block |
||
| 1093 | 1089 | foreach ($p->arg as $k => $v) { |
| 1094 | 1090 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1095 | 1091 | if ($k) { |
| 1096 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1092 | + $l[] = _q($k).' => '.$_v; |
|
| 1097 | 1093 | } else { |
| 1098 | 1094 | $code = $_v; |
| 1099 | 1095 | } |
| 1100 | 1096 | } |
| 1101 | 1097 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1102 | 1098 | if ($p->module) { |
| 1103 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1099 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1104 | 1100 | } elseif ($p->nom_champ) { |
| 1105 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1101 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1106 | 1102 | } else { |
| 1107 | 1103 | $m = ''; |
| 1108 | 1104 | } |
| 1109 | 1105 | |
| 1110 | - $code = (!$code ? "'$m'" : |
|
| 1111 | - ($m ? "'$m' . $code" : |
|
| 1112 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1106 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1107 | + . (!$l ? '' : (', array('.implode(",\n", $l).')')); |
|
| 1114 | 1108 | $code = "_T($code)"; |
| 1115 | 1109 | if ($p->param) { |
| 1116 | 1110 | $p->id_boucle = $id_boucle; |
@@ -1132,7 +1126,7 @@ discard block |
||
| 1132 | 1126 | $p->type_requete = $type; |
| 1133 | 1127 | |
| 1134 | 1128 | $code = calculer_champ($p); |
| 1135 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1129 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1136 | 1130 | $avant = calculer_liste( |
| 1137 | 1131 | $p->avant, |
| 1138 | 1132 | $descr, |
@@ -1172,10 +1166,9 @@ discard block |
||
| 1172 | 1166 | if ($code != "''") { |
| 1173 | 1167 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1174 | 1168 | $codes[] = (($mode == 'validation') ? |
| 1175 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1169 | + "array($code, '$commentaire', ".$p->ligne.')' |
|
| 1176 | 1170 | : (($mode == 'code') ? |
| 1177 | - "\n// $commentaire\n$code" : |
|
| 1178 | - $code)); |
|
| 1171 | + "\n// $commentaire\n$code" : $code)); |
|
| 1179 | 1172 | } |
| 1180 | 1173 | } // foreach |
| 1181 | 1174 | |
@@ -1232,19 +1225,19 @@ discard block |
||
| 1232 | 1225 | $cond = ''; |
| 1233 | 1226 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1234 | 1227 | $t = $r[2]; |
| 1235 | - $cond = '!' . $r[1]; |
|
| 1228 | + $cond = '!'.$r[1]; |
|
| 1236 | 1229 | } else { |
| 1237 | 1230 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1238 | 1231 | $t = $r[2]; |
| 1239 | 1232 | $cond = $r[1]; |
| 1240 | 1233 | } else { |
| 1241 | - $t = '$t' . $n; |
|
| 1234 | + $t = '$t'.$n; |
|
| 1242 | 1235 | $cond = "($t = $code)!==''"; |
| 1243 | 1236 | } |
| 1244 | 1237 | } |
| 1245 | 1238 | |
| 1246 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | - $t . |
|
| 1239 | + $res = (!$avant ? '' : "$avant . "). |
|
| 1240 | + $t. |
|
| 1248 | 1241 | (!$apres ? '' : " . $apres"); |
| 1249 | 1242 | |
| 1250 | 1243 | if ($res !== $t) { |
@@ -1296,13 +1289,13 @@ discard block |
||
| 1296 | 1289 | |
| 1297 | 1290 | // rendre inertes les echappements de #[](){}<> |
| 1298 | 1291 | $i = 0; |
| 1299 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1292 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1300 | 1293 | $i++; |
| 1301 | 1294 | } |
| 1302 | 1295 | $squelette = preg_replace_callback( |
| 1303 | 1296 | ',\\\\([#[()\]{}<>]),', |
| 1304 | - function ($a) use ($inerte) { |
|
| 1305 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1297 | + function($a) use ($inerte) { |
|
| 1298 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1306 | 1299 | }, |
| 1307 | 1300 | $squelette, |
| 1308 | 1301 | -1, |
@@ -1319,7 +1312,7 @@ discard block |
||
| 1319 | 1312 | // Phraser le squelette, selon sa grammaire |
| 1320 | 1313 | |
| 1321 | 1314 | $boucles = []; |
| 1322 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1315 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1323 | 1316 | |
| 1324 | 1317 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1325 | 1318 | |
@@ -1330,15 +1323,15 @@ discard block |
||
| 1330 | 1323 | foreach ($boucles as $i => $boucle) { |
| 1331 | 1324 | $boucles[$i]->return = preg_replace_callback( |
| 1332 | 1325 | ",$inerte-(\d+)-,", |
| 1333 | - function ($a) { |
|
| 1326 | + function($a) { |
|
| 1334 | 1327 | return chr($a[1]); |
| 1335 | 1328 | }, |
| 1336 | 1329 | $boucle->return |
| 1337 | 1330 | ); |
| 1338 | 1331 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1339 | 1332 | ",$inerte-(\d+)-,", |
| 1340 | - function ($a) { |
|
| 1341 | - return '\\\\' . chr($a[1]); |
|
| 1333 | + function($a) { |
|
| 1334 | + return '\\\\'.chr($a[1]); |
|
| 1342 | 1335 | }, |
| 1343 | 1336 | $boucle->descr['squelette'] |
| 1344 | 1337 | ); |
@@ -1350,19 +1343,19 @@ discard block |
||
| 1350 | 1343 | include_spip('public/decompiler'); |
| 1351 | 1344 | foreach ($boucles as $id => $boucle) { |
| 1352 | 1345 | if ($id) { |
| 1353 | - $decomp = "\n/* BOUCLE " . |
|
| 1354 | - $boucle->type_requete . |
|
| 1355 | - ' ' . |
|
| 1356 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1346 | + $decomp = "\n/* BOUCLE ". |
|
| 1347 | + $boucle->type_requete. |
|
| 1348 | + ' '. |
|
| 1349 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1350 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1358 | 1351 | " */\n"; |
| 1359 | 1352 | } else { |
| 1360 | - $decomp = ("\n/*\n" . |
|
| 1353 | + $decomp = ("\n/*\n". |
|
| 1361 | 1354 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1362 | 1355 | . "\n*/"); |
| 1363 | 1356 | } |
| 1364 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1358 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1366 | 1359 | } |
| 1367 | 1360 | } |
| 1368 | 1361 | |
@@ -1385,7 +1378,7 @@ discard block |
||
| 1385 | 1378 | } |
| 1386 | 1379 | } |
| 1387 | 1380 | foreach ($boucles as $id => $boucle) { |
| 1388 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1381 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1389 | 1382 | } |
| 1390 | 1383 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1391 | 1384 | |
@@ -1476,8 +1469,7 @@ discard block |
||
| 1476 | 1469 | } else { |
| 1477 | 1470 | $boucles[$id]->type_requete = false; |
| 1478 | 1471 | $boucle = $boucles[$id]; |
| 1479 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | - ($boucle->sql_serveur . ':')) . |
|
| 1472 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.':')). |
|
| 1481 | 1473 | $type; |
| 1482 | 1474 | $msg = [ |
| 1483 | 1475 | 'zbug_table_inconnue', |
@@ -1567,13 +1559,13 @@ discard block |
||
| 1567 | 1559 | if ( |
| 1568 | 1560 | // fonction de boucle avec serveur & table |
| 1569 | 1561 | (!$serveur or |
| 1570 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | - and (!function_exists($f = $f . '_dist')) |
|
| 1562 | + ((!function_exists($f = 'boucle_'.$serveur.'_'.$table)) |
|
| 1563 | + and (!function_exists($f = $f.'_dist')) |
|
| 1572 | 1564 | ) |
| 1573 | 1565 | ) |
| 1574 | 1566 | // fonction de boucle avec table |
| 1575 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | - and (!function_exists($f = $f . '_dist')) |
|
| 1567 | + and (!function_exists($f = 'boucle_'.$table)) |
|
| 1568 | + and (!function_exists($f = $f.'_dist')) |
|
| 1577 | 1569 | ) { |
| 1578 | 1570 | // fonction de boucle standard |
| 1579 | 1571 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1581,20 +1573,20 @@ discard block |
||
| 1581 | 1573 | } |
| 1582 | 1574 | } |
| 1583 | 1575 | |
| 1584 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | - "static \$connect;\n\t" . |
|
| 1586 | - "\$command['connect'] = \$connect = " . |
|
| 1587 | - _q($boucle->sql_serveur) . |
|
| 1588 | - ';' . |
|
| 1576 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1577 | + "static \$connect;\n\t". |
|
| 1578 | + "\$command['connect'] = \$connect = ". |
|
| 1579 | + _q($boucle->sql_serveur). |
|
| 1580 | + ';'. |
|
| 1589 | 1581 | $f($id, $boucles); |
| 1590 | 1582 | } else { |
| 1591 | 1583 | $req = ("\n\treturn '';"); |
| 1592 | 1584 | } |
| 1593 | 1585 | |
| 1594 | 1586 | $boucles[$id]->return = |
| 1595 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | - $req . |
|
| 1587 | + "\n\nfunction BOUCLE".strtr($id, '-', '_').$nom. |
|
| 1588 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1589 | + $req. |
|
| 1598 | 1590 | "\n}\n"; |
| 1599 | 1591 | } |
| 1600 | 1592 | |
@@ -1604,7 +1596,7 @@ discard block |
||
| 1604 | 1596 | return false; |
| 1605 | 1597 | } |
| 1606 | 1598 | |
| 1607 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1608 | 1600 | ' |
| 1609 | 1601 | // reporter de maniere securisee les doublons inclus |
| 1610 | 1602 | . ' |
@@ -1612,15 +1604,15 @@ discard block |
||
| 1612 | 1604 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1613 | 1605 | |
| 1614 | 1606 | $connect = ' . |
| 1615 | - _q($connect) . '; |
|
| 1607 | + _q($connect).'; |
|
| 1616 | 1608 | $page = ' . |
| 1617 | 1609 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1618 | 1610 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1619 | 1611 | // avant de referencer $Cache |
| 1620 | - $corps . '; |
|
| 1612 | + $corps.'; |
|
| 1621 | 1613 | |
| 1622 | 1614 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1623 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1615 | + . ', $Cache, $page, '.var_export($sourcefile, true).'); |
|
| 1624 | 1616 | }'; |
| 1625 | 1617 | |
| 1626 | 1618 | $secondes = spip_timer('calcul_skel'); |
@@ -1634,10 +1626,10 @@ discard block |
||
| 1634 | 1626 | $code->return = ' |
| 1635 | 1627 | // |
| 1636 | 1628 | // Fonction principale du squelette ' . |
| 1637 | - $sourcefile . |
|
| 1638 | - ($connect ? " pour $connect" : '') . |
|
| 1639 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | - "\n//\n" . |
|
| 1629 | + $sourcefile. |
|
| 1630 | + ($connect ? " pour $connect" : ''). |
|
| 1631 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1632 | + "\n//\n". |
|
| 1641 | 1633 | $principal; |
| 1642 | 1634 | |
| 1643 | 1635 | $boucles[''] = $code; |
@@ -1689,7 +1681,7 @@ discard block |
||
| 1689 | 1681 | **/ |
| 1690 | 1682 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1691 | 1683 | include_spip('iterateur/data'); |
| 1692 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1693 | 1685 | $g = charger_fonction('data', 'iterateur'); |
| 1694 | 1686 | $boucles[$id] = $g($boucle); |
| 1695 | 1687 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -920,8 +920,7 @@ |
||
| 920 | 920 | if (isset($boucles[$idb]->descr['sourcefile'])) { |
| 921 | 921 | $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
| 922 | 922 | } |
| 923 | - } |
|
| 924 | - else { |
|
| 923 | + } else { |
|
| 925 | 924 | $descr = []; |
| 926 | 925 | } |
| 927 | 926 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** Début de la partie principale d'une boucle */ |
@@ -65,83 +65,83 @@ discard block |
||
| 65 | 65 | // https://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
| 67 | 67 | |
| 68 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | - $match = array_pad($match, 3, null); |
|
| 70 | - $p = strpos($texte, $match[0]); |
|
| 71 | - $debut = substr($texte, 0, $p); |
|
| 72 | - if ($p) { |
|
| 73 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | - } |
|
| 75 | - $ligne += substr_count($debut, "\n"); |
|
| 76 | - $champ = new Inclure(); |
|
| 77 | - $champ->ligne = $ligne; |
|
| 78 | - $ligne += substr_count($match[0], "\n"); |
|
| 79 | - $fichier = $match[2]; |
|
| 80 | - # assurer ici la migration .php3 => .php |
|
| 81 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | - $fichier = $r[1]; |
|
| 84 | - } |
|
| 85 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | - $pos_apres = 0; |
|
| 89 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | - if (!function_exists('normaliser_inclure')) { |
|
| 92 | - include_spip('public/normaliser'); |
|
| 93 | - } |
|
| 94 | - normaliser_inclure($champ); |
|
| 95 | - } |
|
| 96 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | - $result[] = $champ; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 68 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | + $match = array_pad($match, 3, null); |
|
| 70 | + $p = strpos($texte, $match[0]); |
|
| 71 | + $debut = substr($texte, 0, $p); |
|
| 72 | + if ($p) { |
|
| 73 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | + } |
|
| 75 | + $ligne += substr_count($debut, "\n"); |
|
| 76 | + $champ = new Inclure(); |
|
| 77 | + $champ->ligne = $ligne; |
|
| 78 | + $ligne += substr_count($match[0], "\n"); |
|
| 79 | + $fichier = $match[2]; |
|
| 80 | + # assurer ici la migration .php3 => .php |
|
| 81 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | + $fichier = $r[1]; |
|
| 84 | + } |
|
| 85 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | + $pos_apres = 0; |
|
| 89 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | + if (!function_exists('normaliser_inclure')) { |
|
| 92 | + include_spip('public/normaliser'); |
|
| 93 | + } |
|
| 94 | + normaliser_inclure($champ); |
|
| 95 | + } |
|
| 96 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | + $result[] = $champ; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // https://code.spip.net/@phraser_polyglotte |
| 105 | 105 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 106 | |
| 107 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | - foreach ($m as $match) { |
|
| 109 | - $p = strpos($texte, $match[0]); |
|
| 110 | - $debut = substr($texte, 0, $p); |
|
| 111 | - if ($p) { |
|
| 112 | - $champ = new Texte(); |
|
| 113 | - $champ->texte = $debut; |
|
| 114 | - $champ->ligne = $ligne; |
|
| 115 | - $result[] = $champ; |
|
| 116 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $champ = new Polyglotte(); |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $ligne += substr_count($match[0], "\n"); |
|
| 122 | - $lang = ''; |
|
| 123 | - $bloc = $match[1]; |
|
| 124 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | - $trad = $regs[1]; |
|
| 127 | - if ($trad or $lang) { |
|
| 128 | - $champ->traductions[$lang] = $trad; |
|
| 129 | - } |
|
| 130 | - $lang = $regs[2]; |
|
| 131 | - $bloc = $regs[3]; |
|
| 132 | - } |
|
| 133 | - $champ->traductions[$lang] = $bloc; |
|
| 134 | - $result[] = $champ; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if ($texte !== '') { |
|
| 138 | - $champ = new Texte(); |
|
| 139 | - $champ->texte = $texte; |
|
| 140 | - $champ->ligne = $ligne; |
|
| 141 | - $result[] = $champ; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $result; |
|
| 107 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | + foreach ($m as $match) { |
|
| 109 | + $p = strpos($texte, $match[0]); |
|
| 110 | + $debut = substr($texte, 0, $p); |
|
| 111 | + if ($p) { |
|
| 112 | + $champ = new Texte(); |
|
| 113 | + $champ->texte = $debut; |
|
| 114 | + $champ->ligne = $ligne; |
|
| 115 | + $result[] = $champ; |
|
| 116 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $champ = new Polyglotte(); |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $ligne += substr_count($match[0], "\n"); |
|
| 122 | + $lang = ''; |
|
| 123 | + $bloc = $match[1]; |
|
| 124 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | + $trad = $regs[1]; |
|
| 127 | + if ($trad or $lang) { |
|
| 128 | + $champ->traductions[$lang] = $trad; |
|
| 129 | + } |
|
| 130 | + $lang = $regs[2]; |
|
| 131 | + $bloc = $regs[3]; |
|
| 132 | + } |
|
| 133 | + $champ->traductions[$lang] = $bloc; |
|
| 134 | + $result[] = $champ; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if ($texte !== '') { |
|
| 138 | + $champ = new Texte(); |
|
| 139 | + $champ->texte = $texte; |
|
| 140 | + $champ->ligne = $ligne; |
|
| 141 | + $result[] = $champ; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $result; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -163,43 +163,43 @@ discard block |
||
| 163 | 163 | * @return array |
| 164 | 164 | **/ |
| 165 | 165 | function phraser_idiomes($texte, $ligne, $result) { |
| 166 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | - $match = array_pad($match, 8, null); |
|
| 168 | - $p = strpos($texte, $match[0]); |
|
| 169 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | - if ($debut) { |
|
| 172 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | - } |
|
| 174 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | - $ligne += substr_count($debut, "\n"); |
|
| 176 | - if ($ko) { |
|
| 177 | - continue; |
|
| 178 | - } // faux idiome |
|
| 179 | - $champ = new Idiome(); |
|
| 180 | - $champ->ligne = $ligne; |
|
| 181 | - $ligne += substr_count($match[0], "\n"); |
|
| 182 | - // Stocker les arguments de la balise de traduction |
|
| 183 | - $args = []; |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | - $largs = substr($largs, strlen($r[0])); |
|
| 188 | - } |
|
| 189 | - $champ->arg = $args; |
|
| 190 | - $champ->nom_champ = strtolower($match[3]); |
|
| 191 | - $champ->module = $match[2]; |
|
| 192 | - // pas d'imbrication pour les filtres sur langue |
|
| 193 | - $pos_apres = 0; |
|
| 194 | - phraser_args($match[7], ':', '', [], $champ, $pos_apres); |
|
| 195 | - $champ->apres = substr($match[7], $pos_apres); |
|
| 196 | - $result[] = $champ; |
|
| 197 | - } |
|
| 198 | - if ($texte !== '') { |
|
| 199 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $result; |
|
| 166 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | + $match = array_pad($match, 8, null); |
|
| 168 | + $p = strpos($texte, $match[0]); |
|
| 169 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | + if ($debut) { |
|
| 172 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | + } |
|
| 174 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | + $ligne += substr_count($debut, "\n"); |
|
| 176 | + if ($ko) { |
|
| 177 | + continue; |
|
| 178 | + } // faux idiome |
|
| 179 | + $champ = new Idiome(); |
|
| 180 | + $champ->ligne = $ligne; |
|
| 181 | + $ligne += substr_count($match[0], "\n"); |
|
| 182 | + // Stocker les arguments de la balise de traduction |
|
| 183 | + $args = []; |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | + $largs = substr($largs, strlen($r[0])); |
|
| 188 | + } |
|
| 189 | + $champ->arg = $args; |
|
| 190 | + $champ->nom_champ = strtolower($match[3]); |
|
| 191 | + $champ->module = $match[2]; |
|
| 192 | + // pas d'imbrication pour les filtres sur langue |
|
| 193 | + $pos_apres = 0; |
|
| 194 | + phraser_args($match[7], ':', '', [], $champ, $pos_apres); |
|
| 195 | + $champ->apres = substr($match[7], $pos_apres); |
|
| 196 | + $result[] = $champ; |
|
| 197 | + } |
|
| 198 | + if ($texte !== '') { |
|
| 199 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $result; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -217,47 +217,47 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | - $p = strpos($texte, $match[0]); |
|
| 222 | - // texte après la balise |
|
| 223 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | - |
|
| 225 | - $debut = substr($texte, 0, $p); |
|
| 226 | - if ($p) { |
|
| 227 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | - } |
|
| 229 | - $ligne += substr_count($debut, "\n"); |
|
| 230 | - $champ = new Champ(); |
|
| 231 | - $champ->ligne = $ligne; |
|
| 232 | - $ligne += substr_count($match[0], "\n"); |
|
| 233 | - $champ->nom_boucle = $match[2]; |
|
| 234 | - $champ->nom_champ = $match[3]; |
|
| 235 | - $champ->etoile = $match[5]; |
|
| 236 | - |
|
| 237 | - if ($suite and $suite[0] == '{') { |
|
| 238 | - phraser_arg($suite, '', [], $champ); |
|
| 239 | - // ce ltrim est une ereur de conception |
|
| 240 | - // mais on le conserve par souci de compatibilite |
|
| 241 | - $texte = ltrim($suite); |
|
| 242 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 220 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | + $p = strpos($texte, $match[0]); |
|
| 222 | + // texte après la balise |
|
| 223 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | + |
|
| 225 | + $debut = substr($texte, 0, $p); |
|
| 226 | + if ($p) { |
|
| 227 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | + } |
|
| 229 | + $ligne += substr_count($debut, "\n"); |
|
| 230 | + $champ = new Champ(); |
|
| 231 | + $champ->ligne = $ligne; |
|
| 232 | + $ligne += substr_count($match[0], "\n"); |
|
| 233 | + $champ->nom_boucle = $match[2]; |
|
| 234 | + $champ->nom_champ = $match[3]; |
|
| 235 | + $champ->etoile = $match[5]; |
|
| 236 | + |
|
| 237 | + if ($suite and $suite[0] == '{') { |
|
| 238 | + phraser_arg($suite, '', [], $champ); |
|
| 239 | + // ce ltrim est une ereur de conception |
|
| 240 | + // mais on le conserve par souci de compatibilite |
|
| 241 | + $texte = ltrim($suite); |
|
| 242 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 245 | 245 | if ($n = (strlen($suite) - strlen($texte))) { |
| 246 | 246 | $champ->apres = array(new Texte); |
| 247 | 247 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 248 | 248 | } |
| 249 | 249 | */ |
| 250 | - } else { |
|
| 251 | - $texte = $suite; |
|
| 252 | - } |
|
| 253 | - phraser_vieux($champ); |
|
| 254 | - $result[] = $champ; |
|
| 255 | - } |
|
| 256 | - if ($texte !== '') { |
|
| 257 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $result; |
|
| 250 | + } else { |
|
| 251 | + $texte = $suite; |
|
| 252 | + } |
|
| 253 | + phraser_vieux($champ); |
|
| 254 | + $result[] = $champ; |
|
| 255 | + } |
|
| 256 | + if ($texte !== '') { |
|
| 257 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $result; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Gestion des imbrications: |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // https://code.spip.net/@phraser_champs_etendus |
| 269 | 269 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 270 | - if ($texte === '') { |
|
| 271 | - return $result; |
|
| 272 | - } |
|
| 273 | - $sep = '##'; |
|
| 274 | - while (strpos($texte, $sep) !== false) { |
|
| 275 | - $sep .= '#'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 270 | + if ($texte === '') { |
|
| 271 | + return $result; |
|
| 272 | + } |
|
| 273 | + $sep = '##'; |
|
| 274 | + while (strpos($texte, $sep) !== false) { |
|
| 275 | + $sep .= '#'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -296,278 +296,278 @@ discard block |
||
| 296 | 296 | * @return array |
| 297 | 297 | */ |
| 298 | 298 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 299 | - $length = strlen($texte); |
|
| 300 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | - $pos_debut++; |
|
| 302 | - } |
|
| 303 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | - $st = substr($texte, $pos_debut); |
|
| 306 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | - $pos_debut = $length - strlen($st); |
|
| 308 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | - $pos_debut++; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $result; |
|
| 299 | + $length = strlen($texte); |
|
| 300 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | + $pos_debut++; |
|
| 302 | + } |
|
| 303 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | + $st = substr($texte, $pos_debut); |
|
| 306 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | + $pos_debut = $length - strlen($st); |
|
| 308 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | + $pos_debut++; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $result; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // https://code.spip.net/@phraser_arg |
| 317 | 317 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 318 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | - $suite = ltrim($match[2]); |
|
| 320 | - $fonc = trim($match[1]); |
|
| 321 | - if ($fonc && $fonc[0] == '|') { |
|
| 322 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | - } |
|
| 324 | - $res = [$fonc]; |
|
| 325 | - $err_f = ''; |
|
| 326 | - // cas du filtre sans argument ou du critere / |
|
| 327 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | - if (!$match[1]) { |
|
| 330 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | - $texte = ''; |
|
| 333 | - } else { |
|
| 334 | - $texte = $suite; |
|
| 335 | - } |
|
| 336 | - if ($err_f) { |
|
| 337 | - $pointeur_champ->param = false; |
|
| 338 | - } elseif ($fonc !== '') { |
|
| 339 | - $pointeur_champ->param[] = $res; |
|
| 340 | - } |
|
| 341 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | - |
|
| 344 | - return $result; |
|
| 345 | - } |
|
| 346 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | - $collecte = []; |
|
| 348 | - while ($args && $args[0] != '}') { |
|
| 349 | - if ($args[0] == '"') { |
|
| 350 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | - } elseif ($args[0] == "'") { |
|
| 352 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | - } else { |
|
| 354 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | - $champ = new Texte(); |
|
| 359 | - $champ->apres = $champ->avant = $args = ''; |
|
| 360 | - break; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - $arg = $regs[2]; |
|
| 364 | - if (trim($regs[1])) { |
|
| 365 | - $champ = new Texte(); |
|
| 366 | - $champ->texte = $arg; |
|
| 367 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | - $result[] = $champ; |
|
| 369 | - $collecte[] = $champ; |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - } else { |
|
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | - // 0 est un aveu d'impuissance. A completer |
|
| 374 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | - |
|
| 376 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | - $collecte = array_merge($collecte, $arg); |
|
| 378 | - $result = array_merge($result, $arg); |
|
| 379 | - } else { |
|
| 380 | - $n = strpos($args, $r[0]); |
|
| 381 | - $pred = substr($args, 0, $n); |
|
| 382 | - $par = ',}'; |
|
| 383 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | - $pred = $m[1]; |
|
| 385 | - $par = ')'; |
|
| 386 | - } |
|
| 387 | - if ($pred) { |
|
| 388 | - $champ = new Texte(); |
|
| 389 | - $champ->texte = $pred; |
|
| 390 | - $champ->apres = $champ->avant = ''; |
|
| 391 | - $result[] = $champ; |
|
| 392 | - $collecte[] = $champ; |
|
| 393 | - } |
|
| 394 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | - $champ = new Champ(); |
|
| 396 | - $champ->nom_boucle = $r[2]; |
|
| 397 | - $champ->nom_champ = $r[3]; |
|
| 398 | - $champ->etoile = $r[5]; |
|
| 399 | - $next = $r[6]; |
|
| 400 | - while ($next == '{') { |
|
| 401 | - phraser_arg($rec, $sep, [], $champ); |
|
| 402 | - $args = ltrim($rec); |
|
| 403 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | - } |
|
| 405 | - while ($next == '|') { |
|
| 406 | - $pos_apres = 0; |
|
| 407 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | - $args = substr($rec, $pos_apres); |
|
| 409 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | - } |
|
| 411 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | - if ($champ->param === false) { |
|
| 413 | - $err_f = true; |
|
| 414 | - } else { |
|
| 415 | - phraser_vieux($champ); |
|
| 416 | - } |
|
| 417 | - if ($par == ')') { |
|
| 418 | - $args = substr($args, 1); |
|
| 419 | - } |
|
| 420 | - $collecte[] = $champ; |
|
| 421 | - $result[] = $champ; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | - $args = ltrim(substr($args, 1)); |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - if ($collecte) { |
|
| 433 | - $res[] = $collecte; |
|
| 434 | - $collecte = []; |
|
| 435 | - } |
|
| 436 | - $texte = substr($args, 1); |
|
| 437 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | - // propager les erreurs, et ignorer les param vides |
|
| 439 | - if ($pointeur_champ->param !== false) { |
|
| 440 | - if ($err_f) { |
|
| 441 | - $pointeur_champ->param = false; |
|
| 442 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | - $pointeur_champ->param[] = $res; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | - |
|
| 449 | - return $result; |
|
| 318 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | + $suite = ltrim($match[2]); |
|
| 320 | + $fonc = trim($match[1]); |
|
| 321 | + if ($fonc && $fonc[0] == '|') { |
|
| 322 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | + } |
|
| 324 | + $res = [$fonc]; |
|
| 325 | + $err_f = ''; |
|
| 326 | + // cas du filtre sans argument ou du critere / |
|
| 327 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | + if (!$match[1]) { |
|
| 330 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | + $texte = ''; |
|
| 333 | + } else { |
|
| 334 | + $texte = $suite; |
|
| 335 | + } |
|
| 336 | + if ($err_f) { |
|
| 337 | + $pointeur_champ->param = false; |
|
| 338 | + } elseif ($fonc !== '') { |
|
| 339 | + $pointeur_champ->param[] = $res; |
|
| 340 | + } |
|
| 341 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | + |
|
| 344 | + return $result; |
|
| 345 | + } |
|
| 346 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | + $collecte = []; |
|
| 348 | + while ($args && $args[0] != '}') { |
|
| 349 | + if ($args[0] == '"') { |
|
| 350 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | + } elseif ($args[0] == "'") { |
|
| 352 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | + } else { |
|
| 354 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | + $champ = new Texte(); |
|
| 359 | + $champ->apres = $champ->avant = $args = ''; |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + $arg = $regs[2]; |
|
| 364 | + if (trim($regs[1])) { |
|
| 365 | + $champ = new Texte(); |
|
| 366 | + $champ->texte = $arg; |
|
| 367 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | + $result[] = $champ; |
|
| 369 | + $collecte[] = $champ; |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + } else { |
|
| 372 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | + // 0 est un aveu d'impuissance. A completer |
|
| 374 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | + |
|
| 376 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | + $collecte = array_merge($collecte, $arg); |
|
| 378 | + $result = array_merge($result, $arg); |
|
| 379 | + } else { |
|
| 380 | + $n = strpos($args, $r[0]); |
|
| 381 | + $pred = substr($args, 0, $n); |
|
| 382 | + $par = ',}'; |
|
| 383 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | + $pred = $m[1]; |
|
| 385 | + $par = ')'; |
|
| 386 | + } |
|
| 387 | + if ($pred) { |
|
| 388 | + $champ = new Texte(); |
|
| 389 | + $champ->texte = $pred; |
|
| 390 | + $champ->apres = $champ->avant = ''; |
|
| 391 | + $result[] = $champ; |
|
| 392 | + $collecte[] = $champ; |
|
| 393 | + } |
|
| 394 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | + $champ = new Champ(); |
|
| 396 | + $champ->nom_boucle = $r[2]; |
|
| 397 | + $champ->nom_champ = $r[3]; |
|
| 398 | + $champ->etoile = $r[5]; |
|
| 399 | + $next = $r[6]; |
|
| 400 | + while ($next == '{') { |
|
| 401 | + phraser_arg($rec, $sep, [], $champ); |
|
| 402 | + $args = ltrim($rec); |
|
| 403 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | + } |
|
| 405 | + while ($next == '|') { |
|
| 406 | + $pos_apres = 0; |
|
| 407 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | + $args = substr($rec, $pos_apres); |
|
| 409 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | + } |
|
| 411 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | + if ($champ->param === false) { |
|
| 413 | + $err_f = true; |
|
| 414 | + } else { |
|
| 415 | + phraser_vieux($champ); |
|
| 416 | + } |
|
| 417 | + if ($par == ')') { |
|
| 418 | + $args = substr($args, 1); |
|
| 419 | + } |
|
| 420 | + $collecte[] = $champ; |
|
| 421 | + $result[] = $champ; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | + $args = ltrim(substr($args, 1)); |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + if ($collecte) { |
|
| 433 | + $res[] = $collecte; |
|
| 434 | + $collecte = []; |
|
| 435 | + } |
|
| 436 | + $texte = substr($args, 1); |
|
| 437 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | + // propager les erreurs, et ignorer les param vides |
|
| 439 | + if ($pointeur_champ->param !== false) { |
|
| 440 | + if ($err_f) { |
|
| 441 | + $pointeur_champ->param = false; |
|
| 442 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | + $pointeur_champ->param[] = $res; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | + |
|
| 449 | + return $result; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| 453 | 453 | // https://code.spip.net/@phraser_champs_exterieurs |
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | - $res = []; |
|
| 456 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - $debut = substr($texte, 0, $p); |
|
| 461 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | - if ($p) { |
|
| 463 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | - } |
|
| 465 | - $ligne += substr_count($debut, "\n"); |
|
| 466 | - $res[] = $nested[$m[1]]; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 455 | + $res = []; |
|
| 456 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + $debut = substr($texte, 0, $p); |
|
| 461 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | + if ($p) { |
|
| 463 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | + } |
|
| 465 | + $ligne += substr_count($debut, "\n"); |
|
| 466 | + $res[] = $nested[$m[1]]; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // https://code.spip.net/@phraser_champs_interieurs |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,201 +595,201 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = ''; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = ''; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = array_merge($args, $doublons); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = ''; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = ''; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = array_merge($args, $doublons); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | // https://code.spip.net/@phraser_critere_infixe |
| 780 | 780 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 781 | - $args[0] = new Texte(); |
|
| 782 | - $args[0]->texte = $arg1; |
|
| 783 | - $args[0] = [$args[0]]; |
|
| 784 | - $args[1][0] = new Texte(); |
|
| 785 | - $args[1][0]->texte = $arg2; |
|
| 786 | - $crit = new Critere(); |
|
| 787 | - $crit->op = $op; |
|
| 788 | - $crit->not = $not; |
|
| 789 | - $crit->cond = $cond; |
|
| 790 | - $crit->param = $args; |
|
| 791 | - |
|
| 792 | - return $crit; |
|
| 781 | + $args[0] = new Texte(); |
|
| 782 | + $args[0]->texte = $arg1; |
|
| 783 | + $args[0] = [$args[0]]; |
|
| 784 | + $args[1][0] = new Texte(); |
|
| 785 | + $args[1][0]->texte = $arg2; |
|
| 786 | + $crit = new Critere(); |
|
| 787 | + $crit->op = $op; |
|
| 788 | + $crit->not = $not; |
|
| 789 | + $crit->cond = $cond; |
|
| 790 | + $crit->param = $args; |
|
| 791 | + |
|
| 792 | + return $crit; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -800,12 +800,12 @@ discard block |
||
| 800 | 800 | * @return int |
| 801 | 801 | */ |
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | - if (is_null($fin)) { |
|
| 804 | - return substr_count($texte, "\n", $debut); |
|
| 805 | - } |
|
| 806 | - else { |
|
| 807 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | - } |
|
| 803 | + if (is_null($fin)) { |
|
| 804 | + return substr_count($texte, "\n", $debut); |
|
| 805 | + } |
|
| 806 | + else { |
|
| 807 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | + } |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -821,87 +821,87 @@ discard block |
||
| 821 | 821 | * @return array|null |
| 822 | 822 | */ |
| 823 | 823 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 824 | - $premiere_boucle = null; |
|
| 825 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | - |
|
| 827 | - $current_pos = $pos_debut_texte; |
|
| 828 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | - $current_pos = $pos_boucle + 1; |
|
| 830 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | - |
|
| 832 | - $id_boucle = ''; |
|
| 833 | - if ($pos_parent !== false) { |
|
| 834 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | - } |
|
| 836 | - if ( |
|
| 837 | - $pos_parent === false |
|
| 838 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | - ) { |
|
| 840 | - $result = new Boucle(); |
|
| 841 | - $result->id_parent = $id_parent; |
|
| 842 | - $result->descr = $descr; |
|
| 843 | - |
|
| 844 | - // un id_boucle pour l'affichage de l'erreur |
|
| 845 | - if (!strlen($id_boucle)) { |
|
| 846 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | - } |
|
| 848 | - $result->id_boucle = $id_boucle; |
|
| 849 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | - erreur_squelette($err_b, $result); |
|
| 851 | - |
|
| 852 | - continue; |
|
| 853 | - } |
|
| 854 | - else { |
|
| 855 | - $boucle = [ |
|
| 856 | - 'id_boucle' => $id_boucle, |
|
| 857 | - 'id_boucle_err' => $id_boucle, |
|
| 858 | - 'debut_boucle' => $pos_boucle, |
|
| 859 | - 'pos_boucle' => $pos_boucle, |
|
| 860 | - 'pos_parent' => $pos_parent, |
|
| 861 | - 'pos_precond' => false, |
|
| 862 | - 'pos_precond_inside' => false, |
|
| 863 | - 'pos_preaff' => false, |
|
| 864 | - 'pos_preaff_inside' => false, |
|
| 865 | - ]; |
|
| 866 | - |
|
| 867 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | - if (!strlen($id_boucle)) { |
|
| 869 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | - if ( |
|
| 876 | - $pos_precond !== false |
|
| 877 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | - ) { |
|
| 879 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond'] = $pos_precond; |
|
| 881 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | - if ( |
|
| 887 | - $pos_preaff !== false |
|
| 888 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | - ) { |
|
| 890 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | - } |
|
| 894 | - if (!strlen($id_boucle)) { |
|
| 895 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | - $premiere_boucle = $boucle; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $premiere_boucle; |
|
| 824 | + $premiere_boucle = null; |
|
| 825 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | + |
|
| 827 | + $current_pos = $pos_debut_texte; |
|
| 828 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | + $current_pos = $pos_boucle + 1; |
|
| 830 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | + |
|
| 832 | + $id_boucle = ''; |
|
| 833 | + if ($pos_parent !== false) { |
|
| 834 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | + } |
|
| 836 | + if ( |
|
| 837 | + $pos_parent === false |
|
| 838 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | + ) { |
|
| 840 | + $result = new Boucle(); |
|
| 841 | + $result->id_parent = $id_parent; |
|
| 842 | + $result->descr = $descr; |
|
| 843 | + |
|
| 844 | + // un id_boucle pour l'affichage de l'erreur |
|
| 845 | + if (!strlen($id_boucle)) { |
|
| 846 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | + } |
|
| 848 | + $result->id_boucle = $id_boucle; |
|
| 849 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | + erreur_squelette($err_b, $result); |
|
| 851 | + |
|
| 852 | + continue; |
|
| 853 | + } |
|
| 854 | + else { |
|
| 855 | + $boucle = [ |
|
| 856 | + 'id_boucle' => $id_boucle, |
|
| 857 | + 'id_boucle_err' => $id_boucle, |
|
| 858 | + 'debut_boucle' => $pos_boucle, |
|
| 859 | + 'pos_boucle' => $pos_boucle, |
|
| 860 | + 'pos_parent' => $pos_parent, |
|
| 861 | + 'pos_precond' => false, |
|
| 862 | + 'pos_precond_inside' => false, |
|
| 863 | + 'pos_preaff' => false, |
|
| 864 | + 'pos_preaff_inside' => false, |
|
| 865 | + ]; |
|
| 866 | + |
|
| 867 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | + if (!strlen($id_boucle)) { |
|
| 869 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | + if ( |
|
| 876 | + $pos_precond !== false |
|
| 877 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | + ) { |
|
| 879 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond'] = $pos_precond; |
|
| 881 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | + if ( |
|
| 887 | + $pos_preaff !== false |
|
| 888 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | + ) { |
|
| 890 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | + } |
|
| 894 | + if (!strlen($id_boucle)) { |
|
| 895 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | + $premiere_boucle = $boucle; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $premiere_boucle; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -916,68 +916,68 @@ discard block |
||
| 916 | 916 | * @return mixed |
| 917 | 917 | */ |
| 918 | 918 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 919 | - $id_boucle = $boucle['id_boucle']; |
|
| 920 | - $pos_courante = $pos_debut_texte; |
|
| 921 | - |
|
| 922 | - $boucle['pos_postcond'] = false; |
|
| 923 | - $boucle['pos_postcond_inside'] = false; |
|
| 924 | - $boucle['pos_altern'] = false; |
|
| 925 | - $boucle['pos_altern_inside'] = false; |
|
| 926 | - $boucle['pos_postaff'] = false; |
|
| 927 | - $boucle['pos_postaff_inside'] = false; |
|
| 928 | - |
|
| 929 | - $pos_anonyme_next = null; |
|
| 930 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | - if (!strlen($id_boucle)) { |
|
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // |
|
| 936 | - // 1. Recuperer la partie conditionnelle apres |
|
| 937 | - // |
|
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | - if ( |
|
| 941 | - $pos_apres !== false |
|
| 942 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | - ) { |
|
| 944 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | - $pos_apres += strlen($apres_boucle); |
|
| 946 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | - $pos_courante = $pos_apres ; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // |
|
| 951 | - // 2. Récuperer la partie alternative apres |
|
| 952 | - // |
|
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | - if ( |
|
| 956 | - $pos_altern !== false |
|
| 957 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | - ) { |
|
| 959 | - $boucle['pos_altern'] = $pos_altern; |
|
| 960 | - $pos_altern += strlen($altern_boucle); |
|
| 961 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | - $pos_courante = $pos_altern; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - // |
|
| 966 | - // 3. Recuperer la partie footer non alternative |
|
| 967 | - // |
|
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | - if ( |
|
| 971 | - $pos_postaff !== false |
|
| 972 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | - ) { |
|
| 974 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | - $pos_postaff += strlen($postaff_boucle); |
|
| 976 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | - $pos_courante = $pos_postaff ; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - return $boucle; |
|
| 919 | + $id_boucle = $boucle['id_boucle']; |
|
| 920 | + $pos_courante = $pos_debut_texte; |
|
| 921 | + |
|
| 922 | + $boucle['pos_postcond'] = false; |
|
| 923 | + $boucle['pos_postcond_inside'] = false; |
|
| 924 | + $boucle['pos_altern'] = false; |
|
| 925 | + $boucle['pos_altern_inside'] = false; |
|
| 926 | + $boucle['pos_postaff'] = false; |
|
| 927 | + $boucle['pos_postaff_inside'] = false; |
|
| 928 | + |
|
| 929 | + $pos_anonyme_next = null; |
|
| 930 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | + if (!strlen($id_boucle)) { |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // |
|
| 936 | + // 1. Recuperer la partie conditionnelle apres |
|
| 937 | + // |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | + if ( |
|
| 941 | + $pos_apres !== false |
|
| 942 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | + ) { |
|
| 944 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | + $pos_apres += strlen($apres_boucle); |
|
| 946 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | + $pos_courante = $pos_apres ; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // |
|
| 951 | + // 2. Récuperer la partie alternative apres |
|
| 952 | + // |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | + if ( |
|
| 956 | + $pos_altern !== false |
|
| 957 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | + ) { |
|
| 959 | + $boucle['pos_altern'] = $pos_altern; |
|
| 960 | + $pos_altern += strlen($altern_boucle); |
|
| 961 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | + $pos_courante = $pos_altern; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + // |
|
| 966 | + // 3. Recuperer la partie footer non alternative |
|
| 967 | + // |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | + if ( |
|
| 971 | + $pos_postaff !== false |
|
| 972 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | + ) { |
|
| 974 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | + $pos_postaff += strlen($postaff_boucle); |
|
| 976 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | + $pos_courante = $pos_postaff ; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + return $boucle; |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -987,21 +987,21 @@ discard block |
||
| 987 | 987 | * @param null|object $boucle |
| 988 | 988 | */ |
| 989 | 989 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 990 | - static $boucles_connues = []; |
|
| 991 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | - } |
|
| 995 | - else { |
|
| 996 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | - $placeholder = $champ->nom_champ; |
|
| 998 | - $id = reset($champ->param[0][1]); |
|
| 999 | - $id = $id->texte; |
|
| 1000 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 990 | + static $boucles_connues = []; |
|
| 991 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | + } |
|
| 995 | + else { |
|
| 996 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | + $placeholder = $champ->nom_champ; |
|
| 998 | + $id = reset($champ->param[0][1]); |
|
| 999 | + $id = $id->texte; |
|
| 1000 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1014,274 +1014,274 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | - //memoriser la boucle a reinjecter |
|
| 1019 | - $id_boucle = "$id_boucle"; |
|
| 1020 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | - return $placeholder; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | + //memoriser la boucle a reinjecter |
|
| 1019 | + $id_boucle = "$id_boucle"; |
|
| 1020 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | + return $placeholder; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1025 | 1025 | |
| 1026 | - $all_res = []; |
|
| 1027 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | - if (is_null($boucle_placeholder)) { |
|
| 1029 | - do { |
|
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | - $pos_debut_texte = 0; |
|
| 1036 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | - $result = new Boucle(); |
|
| 1039 | - $result->id_parent = $id_parent; |
|
| 1040 | - $result->descr = $descr; |
|
| 1041 | - |
|
| 1042 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | - $pos_parent = $boucle['pos_parent']; |
|
| 1044 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | - |
|
| 1046 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | - |
|
| 1048 | - // boucle anonyme ? |
|
| 1049 | - if (!strlen($id_boucle)) { |
|
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $pos_debut_boucle = $pos_courante; |
|
| 1054 | - |
|
| 1055 | - $pos_milieu = $pos_parent; |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | - if ($boucle['pos_precond'] !== false) { |
|
| 1059 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | - |
|
| 1061 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | - $end_preaff = $pos_debut_boucle; |
|
| 1069 | - |
|
| 1070 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - $result->id_boucle = $id_boucle; |
|
| 1076 | - |
|
| 1077 | - if ( |
|
| 1078 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | - or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | - or $pos_match > $pos_milieu |
|
| 1081 | - ) { |
|
| 1082 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | - erreur_squelette($err_b, $result); |
|
| 1084 | - |
|
| 1085 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | - continue; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $result->type_requete = $match[0]; |
|
| 1091 | - $pos_milieu += strlen($match[0]); |
|
| 1092 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | - |
|
| 1094 | - $type = $match[1]; |
|
| 1095 | - $jointures = trim($match[2]); |
|
| 1096 | - $table_optionnelle = ($match[3]); |
|
| 1097 | - if ($jointures) { |
|
| 1098 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | - // ou elles seront completees des jointures declarees |
|
| 1100 | - $result->jointures_explicites = $jointures; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - if ($table_optionnelle) { |
|
| 1104 | - $result->table_optionnelle = $type; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | - // Resultat mis dans result->param |
|
| 1109 | - $pos_fin_criteres = $pos_milieu; |
|
| 1110 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | - |
|
| 1112 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | - // pour l'instant on met le source (chaine) : |
|
| 1114 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | - $pos_milieu = $pos_fin_criteres; |
|
| 1118 | - |
|
| 1119 | - // |
|
| 1120 | - // Recuperer la fin : |
|
| 1121 | - // |
|
| 1122 | - if ($texte[$pos_milieu] === '/') { |
|
| 1123 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | - $pos_courante += 2; |
|
| 1125 | - $result->milieu = ''; |
|
| 1126 | - } else { |
|
| 1127 | - $pos_milieu += 1; |
|
| 1128 | - |
|
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | - if ($pos_fin === false) { |
|
| 1132 | - $err_b = [ |
|
| 1133 | - 'zbug_erreur_boucle_fermant', |
|
| 1134 | - ['id' => $id_boucle] |
|
| 1135 | - ]; |
|
| 1136 | - erreur_squelette($err_b, $result); |
|
| 1137 | - $pos_courante += strlen($fin_boucle); |
|
| 1138 | - } |
|
| 1139 | - else { |
|
| 1140 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | - $search_from = $pos_milieu; |
|
| 1144 | - $nb_open = 1; |
|
| 1145 | - $nb_close = 1; |
|
| 1146 | - $maxiter = 0; |
|
| 1147 | - do { |
|
| 1148 | - while ( |
|
| 1149 | - $nb_close < $nb_open |
|
| 1150 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | - ) { |
|
| 1152 | - $nb_close++; |
|
| 1153 | - $pos_fin = $p; |
|
| 1154 | - } |
|
| 1155 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | - if ($nb_close < $nb_open) { |
|
| 1157 | - break; |
|
| 1158 | - } |
|
| 1159 | - while ( |
|
| 1160 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | - and $p < $pos_fin |
|
| 1162 | - ) { |
|
| 1163 | - $nb_open++; |
|
| 1164 | - $search_from = $p + 1; |
|
| 1165 | - } |
|
| 1166 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | - |
|
| 1168 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | - } |
|
| 1170 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | - |
|
| 1176 | - // |
|
| 1177 | - // 1. Partie conditionnelle apres ? |
|
| 1178 | - // |
|
| 1179 | - if ($boucle['pos_postcond']) { |
|
| 1180 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - // |
|
| 1187 | - // 2. Partie alternative apres ? |
|
| 1188 | - // |
|
| 1189 | - $ligne_altern = $ligne_suite; |
|
| 1190 | - if ($boucle['pos_altern']) { |
|
| 1191 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // |
|
| 1197 | - // 3. Partie footer non alternative ? |
|
| 1198 | - // |
|
| 1199 | - $ligne_postaff = $ligne_suite; |
|
| 1200 | - if ($boucle['pos_postaff']) { |
|
| 1201 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $result->ligne = $ligne_preaff; |
|
| 1207 | - |
|
| 1208 | - if ($p = strpos($type, ':')) { |
|
| 1209 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | - $type = substr($type, $p + 1); |
|
| 1211 | - } |
|
| 1212 | - $soustype = strtolower($type); |
|
| 1213 | - |
|
| 1214 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | - $soustype = $type; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $result->type_requete = $soustype; |
|
| 1219 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | - if (!is_array($result->param)) { |
|
| 1221 | - $err_b = true; |
|
| 1222 | - } else { |
|
| 1223 | - phraser_criteres($result->param, $result); |
|
| 1224 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | - $args = $result->param; |
|
| 1227 | - array_unshift( |
|
| 1228 | - $args, |
|
| 1229 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | - ); |
|
| 1231 | - $result->param = $args; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | - if (empty($boucles[$id_boucle])) { |
|
| 1241 | - $boucles[$id_boucle] = null; |
|
| 1242 | - } |
|
| 1243 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | - |
|
| 1249 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | - if ($err_b) { |
|
| 1251 | - $result->type_requete = false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // Verifier qu'il n'y a pas double definition |
|
| 1255 | - // apres analyse des sous-parties (pas avant). |
|
| 1256 | - if (!empty($boucles[$id_boucle])) { |
|
| 1257 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | - $err_b_d = [ |
|
| 1259 | - 'zbug_erreur_boucle_double', |
|
| 1260 | - ['id' => $id_boucle] |
|
| 1261 | - ]; |
|
| 1262 | - erreur_squelette($err_b_d, $result); |
|
| 1263 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | - } |
|
| 1266 | - } else { |
|
| 1267 | - $boucles[$id_boucle] = $result; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | - |
|
| 1276 | - // phraser la partie avant le debut de la boucle |
|
| 1277 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | - |
|
| 1280 | - $ligne_debut_texte = $ligne_suite; |
|
| 1281 | - $pos_debut_texte = $pos_courante; |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | - |
|
| 1286 | - return $all_res; |
|
| 1026 | + $all_res = []; |
|
| 1027 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | + if (is_null($boucle_placeholder)) { |
|
| 1029 | + do { |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | + $pos_debut_texte = 0; |
|
| 1036 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | + $result = new Boucle(); |
|
| 1039 | + $result->id_parent = $id_parent; |
|
| 1040 | + $result->descr = $descr; |
|
| 1041 | + |
|
| 1042 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | + $pos_parent = $boucle['pos_parent']; |
|
| 1044 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | + |
|
| 1046 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | + |
|
| 1048 | + // boucle anonyme ? |
|
| 1049 | + if (!strlen($id_boucle)) { |
|
| 1050 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $pos_debut_boucle = $pos_courante; |
|
| 1054 | + |
|
| 1055 | + $pos_milieu = $pos_parent; |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | + if ($boucle['pos_precond'] !== false) { |
|
| 1059 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | + |
|
| 1061 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | + $end_preaff = $pos_debut_boucle; |
|
| 1069 | + |
|
| 1070 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + $result->id_boucle = $id_boucle; |
|
| 1076 | + |
|
| 1077 | + if ( |
|
| 1078 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | + or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | + or $pos_match > $pos_milieu |
|
| 1081 | + ) { |
|
| 1082 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | + erreur_squelette($err_b, $result); |
|
| 1084 | + |
|
| 1085 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | + continue; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $result->type_requete = $match[0]; |
|
| 1091 | + $pos_milieu += strlen($match[0]); |
|
| 1092 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | + |
|
| 1094 | + $type = $match[1]; |
|
| 1095 | + $jointures = trim($match[2]); |
|
| 1096 | + $table_optionnelle = ($match[3]); |
|
| 1097 | + if ($jointures) { |
|
| 1098 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | + // ou elles seront completees des jointures declarees |
|
| 1100 | + $result->jointures_explicites = $jointures; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + if ($table_optionnelle) { |
|
| 1104 | + $result->table_optionnelle = $type; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | + // Resultat mis dans result->param |
|
| 1109 | + $pos_fin_criteres = $pos_milieu; |
|
| 1110 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | + |
|
| 1112 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | + // pour l'instant on met le source (chaine) : |
|
| 1114 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | + $pos_milieu = $pos_fin_criteres; |
|
| 1118 | + |
|
| 1119 | + // |
|
| 1120 | + // Recuperer la fin : |
|
| 1121 | + // |
|
| 1122 | + if ($texte[$pos_milieu] === '/') { |
|
| 1123 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | + $pos_courante += 2; |
|
| 1125 | + $result->milieu = ''; |
|
| 1126 | + } else { |
|
| 1127 | + $pos_milieu += 1; |
|
| 1128 | + |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | + if ($pos_fin === false) { |
|
| 1132 | + $err_b = [ |
|
| 1133 | + 'zbug_erreur_boucle_fermant', |
|
| 1134 | + ['id' => $id_boucle] |
|
| 1135 | + ]; |
|
| 1136 | + erreur_squelette($err_b, $result); |
|
| 1137 | + $pos_courante += strlen($fin_boucle); |
|
| 1138 | + } |
|
| 1139 | + else { |
|
| 1140 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | + $search_from = $pos_milieu; |
|
| 1144 | + $nb_open = 1; |
|
| 1145 | + $nb_close = 1; |
|
| 1146 | + $maxiter = 0; |
|
| 1147 | + do { |
|
| 1148 | + while ( |
|
| 1149 | + $nb_close < $nb_open |
|
| 1150 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | + ) { |
|
| 1152 | + $nb_close++; |
|
| 1153 | + $pos_fin = $p; |
|
| 1154 | + } |
|
| 1155 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | + if ($nb_close < $nb_open) { |
|
| 1157 | + break; |
|
| 1158 | + } |
|
| 1159 | + while ( |
|
| 1160 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | + and $p < $pos_fin |
|
| 1162 | + ) { |
|
| 1163 | + $nb_open++; |
|
| 1164 | + $search_from = $p + 1; |
|
| 1165 | + } |
|
| 1166 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | + |
|
| 1168 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | + } |
|
| 1170 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | + |
|
| 1176 | + // |
|
| 1177 | + // 1. Partie conditionnelle apres ? |
|
| 1178 | + // |
|
| 1179 | + if ($boucle['pos_postcond']) { |
|
| 1180 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + // |
|
| 1187 | + // 2. Partie alternative apres ? |
|
| 1188 | + // |
|
| 1189 | + $ligne_altern = $ligne_suite; |
|
| 1190 | + if ($boucle['pos_altern']) { |
|
| 1191 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // |
|
| 1197 | + // 3. Partie footer non alternative ? |
|
| 1198 | + // |
|
| 1199 | + $ligne_postaff = $ligne_suite; |
|
| 1200 | + if ($boucle['pos_postaff']) { |
|
| 1201 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $result->ligne = $ligne_preaff; |
|
| 1207 | + |
|
| 1208 | + if ($p = strpos($type, ':')) { |
|
| 1209 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | + $type = substr($type, $p + 1); |
|
| 1211 | + } |
|
| 1212 | + $soustype = strtolower($type); |
|
| 1213 | + |
|
| 1214 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | + $soustype = $type; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $result->type_requete = $soustype; |
|
| 1219 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | + if (!is_array($result->param)) { |
|
| 1221 | + $err_b = true; |
|
| 1222 | + } else { |
|
| 1223 | + phraser_criteres($result->param, $result); |
|
| 1224 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | + $args = $result->param; |
|
| 1227 | + array_unshift( |
|
| 1228 | + $args, |
|
| 1229 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | + ); |
|
| 1231 | + $result->param = $args; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | + if (empty($boucles[$id_boucle])) { |
|
| 1241 | + $boucles[$id_boucle] = null; |
|
| 1242 | + } |
|
| 1243 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | + |
|
| 1249 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | + if ($err_b) { |
|
| 1251 | + $result->type_requete = false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // Verifier qu'il n'y a pas double definition |
|
| 1255 | + // apres analyse des sous-parties (pas avant). |
|
| 1256 | + if (!empty($boucles[$id_boucle])) { |
|
| 1257 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | + $err_b_d = [ |
|
| 1259 | + 'zbug_erreur_boucle_double', |
|
| 1260 | + ['id' => $id_boucle] |
|
| 1261 | + ]; |
|
| 1262 | + erreur_squelette($err_b_d, $result); |
|
| 1263 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | + } |
|
| 1266 | + } else { |
|
| 1267 | + $boucles[$id_boucle] = $result; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | + |
|
| 1276 | + // phraser la partie avant le debut de la boucle |
|
| 1277 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | + |
|
| 1280 | + $ligne_debut_texte = $ligne_suite; |
|
| 1281 | + $pos_debut_texte = $pos_courante; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | + |
|
| 1286 | + return $all_res; |
|
| 1287 | 1287 | } |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | * Nom d'une balise #TOTO |
| 49 | 49 | * |
| 50 | 50 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 51 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 51 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 52 | 52 | /** Balise complète [...(#TOTO) ... ] */ |
| 53 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 53 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 54 | 54 | |
| 55 | 55 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 56 | 56 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 57 | 57 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 58 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 58 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 59 | 59 | |
| 60 | 60 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 61 | 61 | define('SQL_ARGS', '(\([^)]*\))'); |
| 62 | 62 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 63 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 63 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 64 | 64 | |
| 65 | 65 | // https://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 220 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 221 | 221 | $p = strpos($texte, $match[0]); |
| 222 | 222 | // texte après la balise |
| 223 | 223 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $collecte[] = $champ; |
| 370 | 370 | $args = ltrim($regs[count($regs) - 1]); |
| 371 | 371 | } else { |
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 372 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 373 | 373 | // 0 est un aveu d'impuissance. A completer |
| 374 | 374 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 375 | 375 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | 455 | $res = []; |
| 456 | 456 | while (($p = strpos($texte, "%$sep")) !== false) { |
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 457 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | 458 | break; |
| 459 | 459 | } |
| 460 | 460 | $debut = substr($texte, 0, $p); |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | $pos_apres = 0; |
| 496 | 496 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 497 | 497 | phraser_vieux($champ); |
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | 499 | $debut = substr($match[7], $pos_apres + 1); |
| 500 | 500 | if (!empty($debut)) { |
| 501 | 501 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 627 | 627 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 628 | 628 | $c = null; |
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 629 | + eval('$c = '.$m[4].';'); |
|
| 630 | 630 | if (isset($c)) { |
| 631 | 631 | $m[4] = $c; |
| 632 | 632 | } |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 707 | 707 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 708 | 708 | } elseif ( |
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 709 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 710 | 710 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 711 | 711 | ) { |
| 712 | 712 | $a2 = trim($m[8]); |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | ); |
| 724 | 724 | $crit->exclus = $m[1]; |
| 725 | 725 | } elseif ( |
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 726 | + preg_match('/^([!]?)\s*('. |
|
| 727 | + CHAMP_SQL_PLUS_FONC. |
|
| 728 | 728 | ')\s*(\??)(.*)$/is', $param, $m) |
| 729 | 729 | ) { |
| 730 | 730 | // contient aussi les comparaisons implicites ! |
@@ -870,7 +870,7 @@ discard block |
||
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 874 | 874 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 875 | 875 | if ( |
| 876 | 876 | $pos_precond !== false |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 885 | 885 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 886 | 886 | if ( |
| 887 | 887 | $pos_preaff !== false |
@@ -929,13 +929,13 @@ discard block |
||
| 929 | 929 | $pos_anonyme_next = null; |
| 930 | 930 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 931 | 931 | if (!strlen($id_boucle)) { |
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | // |
| 936 | 936 | // 1. Recuperer la partie conditionnelle apres |
| 937 | 937 | // |
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 939 | 939 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 940 | 940 | if ( |
| 941 | 941 | $pos_apres !== false |
@@ -944,13 +944,13 @@ discard block |
||
| 944 | 944 | $boucle['pos_postcond'] = $pos_apres; |
| 945 | 945 | $pos_apres += strlen($apres_boucle); |
| 946 | 946 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 947 | - $pos_courante = $pos_apres ; |
|
| 947 | + $pos_courante = $pos_apres; |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | // |
| 951 | 951 | // 2. Récuperer la partie alternative apres |
| 952 | 952 | // |
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 954 | 954 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 955 | 955 | if ( |
| 956 | 956 | $pos_altern !== false |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | // |
| 966 | 966 | // 3. Recuperer la partie footer non alternative |
| 967 | 967 | // |
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 969 | 969 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 970 | 970 | if ( |
| 971 | 971 | $pos_postaff !== false |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | $boucle['pos_postaff'] = $pos_postaff; |
| 975 | 975 | $pos_postaff += strlen($postaff_boucle); |
| 976 | 976 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 977 | - $pos_courante = $pos_postaff ; |
|
| 977 | + $pos_courante = $pos_postaff; |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | return $boucle; |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1018 | 1018 | //memoriser la boucle a reinjecter |
| 1019 | 1019 | $id_boucle = "$id_boucle"; |
| 1020 | 1020 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1028 | 1028 | if (is_null($boucle_placeholder)) { |
| 1029 | 1029 | do { |
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1031 | 1031 | } while (strpos($texte, $boucle_placeholder) !== false); |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | |
| 1048 | 1048 | // boucle anonyme ? |
| 1049 | 1049 | if (!strlen($id_boucle)) { |
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1050 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle)), 0, 8); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | $pos_debut_boucle = $pos_courante; |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | $pos_avant = $boucle['pos_precond_inside']; |
| 1062 | 1062 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1071 | 1071 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | $result->id_boucle = $id_boucle; |
@@ -1126,7 +1126,7 @@ discard block |
||
| 1126 | 1126 | } else { |
| 1127 | 1127 | $pos_milieu += 1; |
| 1128 | 1128 | |
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1130 | 1130 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1131 | 1131 | if ($pos_fin === false) { |
| 1132 | 1132 | $err_b = [ |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | else { |
| 1140 | 1140 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1141 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1143 | 1143 | $search_from = $pos_milieu; |
| 1144 | 1144 | $nb_open = 1; |
| 1145 | 1145 | $nb_close = 1; |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | if ($boucle['pos_postcond']) { |
| 1180 | 1180 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1181 | 1181 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | |
@@ -802,8 +802,7 @@ discard block |
||
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | 803 | if (is_null($fin)) { |
| 804 | 804 | return substr_count($texte, "\n", $debut); |
| 805 | - } |
|
| 806 | - else { |
|
| 805 | + } else { |
|
| 807 | 806 | return substr_count($texte, "\n", $debut, $fin - $debut); |
| 808 | 807 | } |
| 809 | 808 | } |
@@ -850,8 +849,7 @@ discard block |
||
| 850 | 849 | erreur_squelette($err_b, $result); |
| 851 | 850 | |
| 852 | 851 | continue; |
| 853 | - } |
|
| 854 | - else { |
|
| 852 | + } else { |
|
| 855 | 853 | $boucle = [ |
| 856 | 854 | 'id_boucle' => $id_boucle, |
| 857 | 855 | 'id_boucle_err' => $id_boucle, |
@@ -991,8 +989,7 @@ discard block |
||
| 991 | 989 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 992 | 990 | if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
| 993 | 991 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 994 | - } |
|
| 995 | - else { |
|
| 992 | + } else { |
|
| 996 | 993 | if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
| 997 | 994 | $placeholder = $champ->nom_champ; |
| 998 | 995 | $id = reset($champ->param[0][1]); |
@@ -1135,8 +1132,7 @@ discard block |
||
| 1135 | 1132 | ]; |
| 1136 | 1133 | erreur_squelette($err_b, $result); |
| 1137 | 1134 | $pos_courante += strlen($fin_boucle); |
| 1138 | - } |
|
| 1139 | - else { |
|
| 1135 | + } else { |
|
| 1140 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | 1138 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |